From patchwork Fri Mar 11 07:37:52 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rafi Rubin X-Patchwork-Id: 627471 X-Patchwork-Delegate: jikos@jikos.cz Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p2B7cPeb007543 for ; Fri, 11 Mar 2011 07:38:25 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753567Ab1CKHiX (ORCPT ); Fri, 11 Mar 2011 02:38:23 -0500 Received: from fox.seas.upenn.edu ([158.130.68.12]:54049 "EHLO fox.seas.upenn.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753425Ab1CKHiX (ORCPT ); Fri, 11 Mar 2011 02:38:23 -0500 Received: from hex.seas.upenn.edu (hex.seas.upenn.edu [158.130.62.166]) by fox.seas.upenn.edu (8.14.3/8.14.3) with ESMTP id p2B7bxpK028702; Fri, 11 Mar 2011 02:38:01 -0500 From: Rafi Rubin To: jkosina@suse.cz, linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org, micki@n-trig.com, rydberg@euromail.se, chatty@enac.fr, dmitry.torokhov@gmail.com, Rafi Rubin Subject: [PATCH 2/2] hid-ntrig: calibration Date: Fri, 11 Mar 2011 02:37:52 -0500 Message-Id: <1299829072-19489-2-git-send-email-rafi@seas.upenn.edu> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1299829072-19489-1-git-send-email-rafi@seas.upenn.edu> References: <1299829072-19489-1-git-send-email-rafi@seas.upenn.edu> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.2.15, 1.0.148, 0.0.0000 definitions=2011-03-11_02:2011-03-11, 2011-03-11, 1970-01-01 signatures=0 X-Proofpoint-Spam-Reason: safe Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Fri, 11 Mar 2011 07:38:25 +0000 (UTC) diff --git a/drivers/hid/hid-ntrig.c b/drivers/hid/hid-ntrig.c index 24ab6a5..ddf2c76 100644 --- a/drivers/hid/hid-ntrig.c +++ b/drivers/hid/hid-ntrig.c @@ -490,6 +490,53 @@ static ssize_t store_mode(struct device *dev, } static DEVICE_ATTR(mode, S_IWUSR | S_IRUGO, show_mode, store_mode); +static ssize_t ntrig_calibrate(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct usb_device *usb_dev = hid_to_usb_dev(hdev); + struct usbhid_device *usbhid = hdev->driver_data; + int ret; + unsigned long t; + unsigned char *data; + + if (strict_strtoul(buf, 0, &t)) + return -EINVAL; + + data = kmalloc(4, GFP_KERNEL); + if (!data) + return -ENOMEM; + + spin_lock(&usbhid->lock); + set_bit(HID_DISCONNECTED, &usbhid->iofl); + spin_unlock(&usbhid->lock); + + ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), + USB_REQ_CLEAR_FEATURE, USB_TYPE_CLASS + | USB_RECIP_INTERFACE | USB_DIR_IN, + 0x30b, 1, data, 4, USB_CTRL_GET_TIMEOUT); + if (ret < 0) + goto fail; + + msleep(t); + + ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), + USB_REQ_CLEAR_FEATURE, USB_TYPE_CLASS + | USB_RECIP_INTERFACE | USB_DIR_IN, + 0x311, 1, data, 4, USB_CTRL_GET_TIMEOUT); + +fail: + kfree(data); + spin_lock(&usbhid->lock); + clear_bit(HID_DISCONNECTED, &usbhid->iofl); + spin_unlock(&usbhid->lock); + schedule_work(&usbhid->reset_work); + + return (ret < 0) ? ret : count; +} +static DEVICE_ATTR(calibrate, S_IWUSR, NULL, ntrig_calibrate); + static struct attribute *sysfs_attrs[] = { &dev_attr_sensor_physical_width.attr, &dev_attr_sensor_physical_height.attr, @@ -502,6 +549,7 @@ static struct attribute *sysfs_attrs[] = { &dev_attr_activation_height.attr, &dev_attr_deactivate_slack.attr, &dev_attr_mode.attr, + &dev_attr_calibrate.attr, NULL };