mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Rafi Rubin <rafi@seas.upenn.edu>
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 <rafi@seas.upenn.edu>
Subject: [PATCH 2/2] hid-ntrig: calibration
Date: Fri, 11 Mar 2011 02:37:52 -0500	[thread overview]
Message-ID: <1299829072-19489-2-git-send-email-rafi@seas.upenn.edu> (raw)
In-Reply-To: <1299829072-19489-1-git-send-email-rafi@seas.upenn.edu>

Adding a function to tell the device to run its calibration routine.
A number written to the sysfs specifies the duration of the calibration
in milliseconds

Signed-off-by: Rafi Rubin <rafi@seas.upenn.edu>
---

The output needs to stay disconnected for the duration for this to work,
otherwise I would have just used submit_report.  Please check to see
that I handled that correctly, I can say it works for me.

Is there a style problem with having wait and sleep in a sysfs call like
this?

Micki: would you care to comment on this?  The windows driver seems to
send extra messages to the device, but in testing they don't seem to
have an effect.  If they do matter, it would be no trouble to put them
back in.  Also can you comment on the difference between "trouble
shooting" and the calibration that your windows tool offers?  As far as
I can tell the actions look very similar.  Is it just a matter of
interpretting the feedback?
---
 drivers/hid/hid-ntrig.c |   48 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 48 insertions(+), 0 deletions(-)

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
 };
 
-- 
1.7.2.3


  reply	other threads:[~2011-03-11  7:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-11  7:37 [PATCH 1/2] hid-ntrig: sysfs nodes for modes Rafi Rubin
2011-03-11  7:37 ` Rafi Rubin [this message]
2011-03-21 17:15   ` [PATCH 2/2] hid-ntrig: calibration Henrik Rydberg
2011-03-21 18:25     ` Rafi Rubin
2011-03-24 14:32     ` Jiri Kosina
2011-03-24 16:52       ` Rafi Rubin
2011-03-11  8:18 ` [PATCH 1/2] hid-ntrig: sysfs nodes for modes Dmitry Torokhov
2011-03-11  9:56   ` Rafi Rubin
2011-03-13  6:27     ` Dmitry Torokhov
2011-03-15  4:30       ` Rafi Rubin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1299829072-19489-2-git-send-email-rafi@seas.upenn.edu \
    --to=rafi@seas.upenn.edu \
    --cc=chatty@enac.fr \
    --cc=dmitry.torokhov@gmail.com \
    --cc=jkosina@suse.cz \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=micki@n-trig.com \
    --cc=rydberg@euromail.se \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®