linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Herrmann <dh.herrmann@googlemail.com>
To: linux-input@vger.kernel.org
Cc: jkosina@suse.cz, oneukum@suse.de,
	David Herrmann <dh.herrmann@googlemail.com>
Subject: [PATCH v2 07/17] HID: wiimote: Add extension sysfs attribute
Date: Thu, 17 Nov 2011 14:12:04 +0100	[thread overview]
Message-ID: <1321535534-7950-8-git-send-email-dh.herrmann@googlemail.com> (raw)
In-Reply-To: <1321535534-7950-1-git-send-email-dh.herrmann@googlemail.com>

Add new sysfs attribute "extension" which returns the currently connected and
initialized extensions.

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

diff --git a/Documentation/ABI/testing/sysfs-driver-hid-wiimote b/Documentation/ABI/testing/sysfs-driver-hid-wiimote
index 5d5a16e..3d98009 100644
--- a/Documentation/ABI/testing/sysfs-driver-hid-wiimote
+++ b/Documentation/ABI/testing/sysfs-driver-hid-wiimote
@@ -8,3 +8,15 @@ Contact:	David Herrmann <dh.herrmann@googlemail.com>
 Description:	Make it possible to set/get current led state. Reading from it
 		returns 0 if led is off and 1 if it is on. Writing 0 to it
 		disables the led, writing 1 enables it.
+
+What:		/sys/bus/hid/drivers/wiimote/<dev>/extension
+Date:		August 2011
+KernelVersion:	3.2
+Contact:	David Herrmann <dh.herrmann@googlemail.com>
+Description:	This file contains the currently connected and initialized
+		extensions. It can be one of: none, motionp, nunchuck, classic,
+		motionp+nunchuck, motionp+classic
+		motionp is the official Nintendo Motion+ extension, nunchuck is
+		the official Nintendo Nunchuck extension and classic is the
+		Nintendo Classic Controller extension. The motionp extension can
+		be combined with the other two.
diff --git a/drivers/hid/hid-wiimote-ext.c b/drivers/hid/hid-wiimote-ext.c
index 233bdfe..477513d 100644
--- a/drivers/hid/hid-wiimote-ext.c
+++ b/drivers/hid/hid-wiimote-ext.c
@@ -199,11 +199,47 @@ bool wiiext_active(struct wiimote_data *wdata)
 	return wdata->ext->motionp || wdata->ext->ext_type;
 }
 
+static ssize_t wiiext_show(struct device *dev, struct device_attribute *attr,
+								char *buf)
+{
+	struct wiimote_data *wdata = dev_to_wii(dev);
+	__u8 type = WIIEXT_NONE;
+	bool motionp = false;
+	unsigned long flags;
+
+	spin_lock_irqsave(&wdata->state.lock, flags);
+	if (wdata->ext) {
+		motionp = wdata->ext->motionp;
+		type = wdata->ext->ext_type;
+	}
+	spin_unlock_irqrestore(&wdata->state.lock, flags);
+
+	if (type == WIIEXT_NUNCHUCK) {
+		if (motionp)
+			return sprintf(buf, "motionp+nunchuck\n");
+		else
+			return sprintf(buf, "nunchuck\n");
+	} else if (type == WIIEXT_CLASSIC) {
+		if (motionp)
+			return sprintf(buf, "motionp+classic\n");
+		else
+			return sprintf(buf, "classic\n");
+	} else {
+		if (motionp)
+			return sprintf(buf, "motionp\n");
+		else
+			return sprintf(buf, "none\n");
+	}
+}
+
+static DEVICE_ATTR(extension, S_IRUGO, wiiext_show, NULL);
+
 /* Initializes the extension driver of a wiimote */
 int wiiext_init(struct wiimote_data *wdata)
 {
 	struct wiimote_ext *ext;
 	unsigned long flags;
+	int ret;
 
 	ext = kzalloc(sizeof(*ext), GFP_KERNEL);
 	if (!ext)
@@ -212,11 +248,19 @@ int wiiext_init(struct wiimote_data *wdata)
 	ext->wdata = wdata;
 	INIT_WORK(&ext->worker, wiiext_worker);
 
+	ret = device_create_file(&wdata->hdev->dev, &dev_attr_extension);
+	if (ret)
+		goto err;
+
 	spin_lock_irqsave(&wdata->state.lock, flags);
 	wdata->ext = ext;
 	spin_unlock_irqrestore(&wdata->state.lock, flags);
 
 	return 0;
+
+err:
+	kfree(ext);
+	return ret;
 }
 
 /* Deinitializes the extension driver of a wiimote */
@@ -240,6 +284,8 @@ void wiiext_deinit(struct wiimote_data *wdata)
 	wdata->ext = NULL;
 	spin_unlock_irqrestore(&wdata->state.lock, flags);
 
+	device_remove_file(&wdata->hdev->dev, &dev_attr_extension);
+
 	cancel_work_sync(&ext->worker);
 	kfree(ext);
 }
-- 
1.7.7.3


  parent reply	other threads:[~2011-11-17 13:13 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-17 13:11 [PATCH v2 00/17] HID: Wiimote Extension Support v2 David Herrmann
2011-11-17 13:11 ` [PATCH v2 01/17] HID: wiimote: Rename driver to allow multiple source files David Herrmann
2011-11-17 13:11 ` [PATCH v2 02/17] HID: wiimote: Move common symbols into header David Herrmann
2011-11-17 13:12 ` [PATCH v2 03/17] HID: wiimote: Add read-mem helpers David Herrmann
2011-11-17 13:12 ` [PATCH v2 04/17] HID: wiimote: Add extension support stub David Herrmann
2011-11-17 13:12 ` [PATCH v2 05/17] HID: wiimote: Add extension initializer stubs David Herrmann
2011-11-17 13:12 ` [PATCH v2 06/17] HID: wiimote: Add extension initializers David Herrmann
2011-11-17 13:12 ` David Herrmann [this message]
2011-11-17 13:12 ` [PATCH v2 08/17] HID: wiimote: Register input devices for extensions David Herrmann
2011-11-17 13:12 ` [PATCH v2 09/17] HID: wiimote: Add extension handler stubs David Herrmann
2011-11-17 13:12 ` [PATCH v2 10/17] HID: wiimote: Parse motion+ data David Herrmann
2011-11-17 13:12 ` [PATCH v2 11/17] HID: wiimote: Parse nunchuck data David Herrmann
2011-11-17 13:12 ` [PATCH v2 12/17] HID: wiimote: Parse classic controller data David Herrmann
2011-11-17 13:12 ` [PATCH v2 13/17] HID: wiimote: Add debugfs support stubs David Herrmann
2011-11-17 13:12 ` [PATCH v2 14/17] HID: wiimote: Allow direct eeprom access David Herrmann
2011-11-17 13:12 ` [PATCH v2 15/17] HID: wiimote: Allow direct DRM debug access David Herrmann
2011-11-17 13:12 ` [PATCH v2 16/17] HID: wiimote: Remove module version number David Herrmann
2011-11-17 13:12 ` [PATCH v2 17/17] HID: wiimote: Enable NO_INIT_REPORTS quirk David Herrmann
2011-11-22 22:19 ` [PATCH v2 00/17] HID: Wiimote Extension Support v2 Jiri Kosina

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=1321535534-7950-8-git-send-email-dh.herrmann@googlemail.com \
    --to=dh.herrmann@googlemail.com \
    --cc=jkosina@suse.cz \
    --cc=linux-input@vger.kernel.org \
    --cc=oneukum@suse.de \
    /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;
as well as URLs for NNTP newsgroup(s).