All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Herrmann <dh.herrmann@googlemail.com>
To: linux-input@vger.kernel.org
Cc: jkosina@suse.cz, padovan@profusion.mobi, dh.herrmann@googlemail.com
Subject: [PATCH 14/16] HID: wiimote: Allow userspace to control IR cam
Date: Thu, 28 Jul 2011 18:08:34 +0200	[thread overview]
Message-ID: <1311869316-17128-15-git-send-email-dh.herrmann@googlemail.com> (raw)
In-Reply-To: <1311869316-17128-1-git-send-email-dh.herrmann@googlemail.com>

This adds a new sysfs attribute to wiimotes which allows userspace to enable or
disable the IR cam and set it into the desired mode.

Disabling IR saves lots of energy on the wiimote, so it is not enabled by
default.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
---
 Documentation/ABI/testing/sysfs-driver-hid-wiimote |   10 +++
 drivers/hid/hid-wiimote.c                          |   74 ++++++++++++++++++++
 2 files changed, 84 insertions(+), 0 deletions(-)

diff --git a/Documentation/ABI/testing/sysfs-driver-hid-wiimote b/Documentation/ABI/testing/sysfs-driver-hid-wiimote
index d8ccea8..4ec761d 100644
--- a/Documentation/ABI/testing/sysfs-driver-hid-wiimote
+++ b/Documentation/ABI/testing/sysfs-driver-hid-wiimote
@@ -24,3 +24,13 @@ Contact:	David Herrmann <dh.herrmann@googlemail.com>
 Description:	Writing 1 to this file enables accelerometer data reporting of
 		the wiimote, 0 disables it. Reading from this file returns the
 		current value.
+
+What:		/sys/bus/hid/drivers/wiimote/<dev>/ir
+Date:		July 2011
+KernelVersion:	3.2
+Contact:	David Herrmann <dh.herrmann@googlemail.com>
+Description:	Reading this attribute returns the current status of the IR
+		cam of the wiimote. It can be one of: off, basic, extended or
+		full.
+		Writing one of these strings to the file tries to put the IR
+		cam into the desired state.
diff --git a/drivers/hid/hid-wiimote.c b/drivers/hid/hid-wiimote.c
index bca46ba..69a555a3 100644
--- a/drivers/hid/hid-wiimote.c
+++ b/drivers/hid/hid-wiimote.c
@@ -700,6 +700,75 @@ static ssize_t wiifs_accel_set(struct device *dev,
 static DEVICE_ATTR(accelerometer, S_IRUGO | S_IWUSR, wiifs_accel_show,
 							wiifs_accel_set);
 
+static ssize_t wiifs_ir_show(struct device *dev, struct device_attribute *attr,
+								char *buf)
+{
+	struct wiimote_data *wdata = dev_to_wii(dev);
+	unsigned long flags;
+	const char *mode;
+	__u8 flag;
+
+	if (!atomic_read(&wdata->ready))
+		return -EBUSY;
+
+	spin_lock_irqsave(&wdata->state.lock, flags);
+	flag = wdata->state.flags & WIIPROTO_FLAGS_IR;
+	spin_unlock_irqrestore(&wdata->state.lock, flags);
+
+	switch (flag) {
+		case WIIPROTO_FLAG_IR_FULL:
+			mode = "full";
+			break;
+		case WIIPROTO_FLAG_IR_EXT:
+			mode = "extended";
+			break;
+		case WIIPROTO_FLAG_IR_BASIC:
+			mode = "basic";
+			break;
+		default:
+			mode = "off";
+			break;
+	}
+
+
+	return sprintf(buf, "%s\n", mode);
+}
+
+static ssize_t wiifs_ir_set(struct device *dev, struct device_attribute *attr,
+						const char *buf, size_t count)
+{
+	struct wiimote_data *wdata = dev_to_wii(dev);
+	int ret;
+	__u8 mode;
+
+	if (count == 0)
+		return -EINVAL;
+
+	if (!strncasecmp("basic", buf, 5))
+		mode = WIIPROTO_FLAG_IR_BASIC;
+	else if (!strncasecmp("extended", buf, 8))
+		mode = WIIPROTO_FLAG_IR_EXT;
+	else if (!strncasecmp("full", buf, 4))
+		mode = WIIPROTO_FLAG_IR_FULL;
+	else if (!strncasecmp("off", buf, 3))
+		mode = 0;
+	else
+		return -EINVAL;
+
+	if (!atomic_read(&wdata->ready))
+		return -EBUSY;
+	/* smp_rmb: Make sure wdata->xy is available when wdata->ready is 1 */
+	smp_rmb();
+
+	ret = wiimote_init_ir(wdata, mode);
+	if (ret < 0)
+		return ret;
+
+	return count;
+}
+
+static DEVICE_ATTR(ir, S_IRUGO | S_IWUSR, wiifs_ir_show, wiifs_ir_set);
+
 static int wiimote_input_event(struct input_dev *dev, unsigned int type,
 						unsigned int code, int value)
 {
@@ -1077,6 +1146,9 @@ static int wiimote_hid_probe(struct hid_device *hdev,
 	ret = device_create_file(&hdev->dev, &dev_attr_accelerometer);
 	if (ret)
 		goto err;
+	ret = device_create_file(&hdev->dev, &dev_attr_ir);
+	if (ret)
+		goto err;
 
 	ret = hid_parse(hdev);
 	if (ret) {
@@ -1118,6 +1190,7 @@ err:
 	device_remove_file(&hdev->dev, &dev_attr_led4);
 	device_remove_file(&hdev->dev, &dev_attr_rumble);
 	device_remove_file(&hdev->dev, &dev_attr_accelerometer);
+	device_remove_file(&hdev->dev, &dev_attr_ir);
 	wiimote_destroy(wdata);
 	return ret;
 }
@@ -1134,6 +1207,7 @@ static void wiimote_hid_remove(struct hid_device *hdev)
 	device_remove_file(&hdev->dev, &dev_attr_led4);
 	device_remove_file(&hdev->dev, &dev_attr_rumble);
 	device_remove_file(&hdev->dev, &dev_attr_accelerometer);
+	device_remove_file(&hdev->dev, &dev_attr_ir);
 
 	hid_hw_stop(hdev);
 	input_unregister_device(wdata->input);
-- 
1.7.6


  parent reply	other threads:[~2011-07-28 16:09 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-28 16:08 [PATCH 00/16] Extended wiimote support David Herrmann
2011-07-28 16:08 ` [PATCH 01/16] HID: wiimote: Support rumble device David Herrmann
2011-07-28 16:08 ` [PATCH 02/16] HID: wiimote: Add sysfs rumble attribute David Herrmann
2011-07-28 16:08 ` [PATCH 03/16] HID: wiimote: Add drm request David Herrmann
2011-07-28 18:05   ` Oliver Neukum
2011-07-28 18:41     ` David Herrmann
2011-07-28 18:47       ` Oliver Neukum
2011-07-28 16:08 ` [PATCH 04/16] HID: wiimote: Add status and return request handlers David Herrmann
2011-07-28 16:08 ` [PATCH 05/16] HID: wiimote: Reduce input syncs David Herrmann
2011-07-28 16:08 ` [PATCH 06/16] HID: wiimote: Enable accelerometer on request David Herrmann
2011-07-28 18:08   ` Oliver Neukum
2011-07-28 19:01     ` David Herrmann
2011-07-28 19:32       ` Oliver Neukum
2011-07-28 16:08 ` [PATCH 07/16] HID: wiimote: Parse accelerometer data David Herrmann
2011-07-28 18:12   ` Oliver Neukum
2011-07-28 18:51     ` David Herrmann
2011-08-10 11:55       ` Jiri Kosina
2011-07-28 16:08 ` [PATCH 08/16] HID: wiimote: Parse IR input and report to userspace David Herrmann
2011-07-28 16:08 ` [PATCH 09/16] HID: wiimote: Add missing extension DRM handlers David Herrmann
2011-07-28 16:08 ` [PATCH 10/16] HID: wiimote: Add register/eeprom memory support David Herrmann
2011-07-28 16:08 ` [PATCH 11/16] HID: wiimote: Helper functions for synchronous requests David Herrmann
2011-07-28 16:08 ` [PATCH 12/16] HID: wiimote: Add write-register helpers David Herrmann
2011-07-28 16:08 ` [PATCH 13/16] HID: wiimote: Add IR initializer David Herrmann
2011-07-28 16:08 ` David Herrmann [this message]
2011-07-28 16:08 ` [PATCH 15/16] HID: wiimote: Read wiimote battery charge level David Herrmann
2011-07-28 16:08 ` [PATCH 16/16] HID: wiimote: Allow EEPROM debugfs access David Herrmann

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=1311869316-17128-15-git-send-email-dh.herrmann@googlemail.com \
    --to=dh.herrmann@googlemail.com \
    --cc=jkosina@suse.cz \
    --cc=linux-input@vger.kernel.org \
    --cc=padovan@profusion.mobi \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.