From: David Herrmann <dh.herrmann@gmail.com>
To: linux-input@vger.kernel.org
Cc: Jiri Kosina <jkosina@suse.cz>, David Herrmann <dh.herrmann@gmail.com>
Subject: [PATCH 20/26] HID: wiimote: add sysfs extension/device-type attrs
Date: Sun, 5 May 2013 23:13:04 +0200 [thread overview]
Message-ID: <1367788390-29835-21-git-send-email-dh.herrmann@gmail.com> (raw)
In-Reply-To: <1367788390-29835-1-git-send-email-dh.herrmann@gmail.com>
Two new attributes, "extension" and "devtype" now allow user-space to read
the extension type and device type. As device detection is asynchronous,
we send a CHANGED event after it is done. This also allows user-space to
wait for a device to settle before opening its input event devices.
The "extension" device is compatible with the old "extension" sysfs field
(which was registered by the static extension support code).
Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
---
Documentation/ABI/testing/sysfs-driver-hid-wiimote | 24 ++++-
drivers/hid/hid-wiimote-core.c | 106 ++++++++++++++++++++-
2 files changed, 128 insertions(+), 2 deletions(-)
diff --git a/Documentation/ABI/testing/sysfs-driver-hid-wiimote b/Documentation/ABI/testing/sysfs-driver-hid-wiimote
index 3d98009..e8f6b16 100644
--- a/Documentation/ABI/testing/sysfs-driver-hid-wiimote
+++ b/Documentation/ABI/testing/sysfs-driver-hid-wiimote
@@ -12,7 +12,7 @@ Description: Make it possible to set/get current led state. Reading from it
What: /sys/bus/hid/drivers/wiimote/<dev>/extension
Date: August 2011
KernelVersion: 3.2
-Contact: David Herrmann <dh.herrmann@googlemail.com>
+Contact: David Herrmann <dh.herrmann@gmail.com>
Description: This file contains the currently connected and initialized
extensions. It can be one of: none, motionp, nunchuck, classic,
motionp+nunchuck, motionp+classic
@@ -20,3 +20,25 @@ Description: This file contains the currently connected and initialized
the official Nintendo Nunchuck extension and classic is the
Nintendo Classic Controller extension. The motionp extension can
be combined with the other two.
+ Starting with kernel-version 3.11 Motion Plus hotplugging is
+ supported and if detected, it's no longer reported as static
+ extension. You will get uevent notifications for the motion-plus
+ device then.
+
+What: /sys/bus/hid/drivers/wiimote/<dev>/devtype
+Date: May 2013
+KernelVersion: 3.11
+Contact: David Herrmann <dh.herrmann@gmail.com>
+Description: While a device is initialized by the wiimote driver, we perform
+ a device detection and signal a "change" uevent after it is
+ done. This file shows the detected device type. "pending" means
+ that the detection is still ongoing, "unknown" means, that the
+ device couldn't be detected or loaded. "generic" means, that the
+ device couldn't be detected but supports basic Wii Remote
+ features and can be used.
+ Other strings for each device-type are available and may be
+ added if new device-specific detections are added.
+ Currently supported are:
+ gen10: First Wii Remote generation
+ gen20: Second Wii Remote Plus generation (builtin MP)
+ balanceboard: Wii Balance Board
diff --git a/drivers/hid/hid-wiimote-core.c b/drivers/hid/hid-wiimote-core.c
index 13963b4..fa58045 100644
--- a/drivers/hid/hid-wiimote-core.c
+++ b/drivers/hid/hid-wiimote-core.c
@@ -1166,11 +1166,18 @@ static void wiimote_init_worker(struct work_struct *work)
{
struct wiimote_data *wdata = container_of(work, struct wiimote_data,
init_worker);
+ bool changed = false;
- if (wdata->state.devtype == WIIMOTE_DEV_PENDING)
+ if (wdata->state.devtype == WIIMOTE_DEV_PENDING) {
wiimote_init_detect(wdata);
+ changed = true;
+ }
+
if (!wiimote_init_check(wdata))
wiimote_init_hotplug(wdata);
+
+ if (changed)
+ kobject_uevent(&wdata->hdev->dev.kobj, KOBJ_CHANGE);
}
void __wiimote_schedule(struct wiimote_data *wdata)
@@ -1591,6 +1598,84 @@ static int wiimote_hid_event(struct hid_device *hdev, struct hid_report *report,
return 0;
}
+static ssize_t wiimote_ext_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct wiimote_data *wdata = dev_to_wii(dev);
+ __u8 type;
+ unsigned long flags;
+
+ spin_lock_irqsave(&wdata->state.lock, flags);
+ type = wdata->state.exttype;
+ spin_unlock_irqrestore(&wdata->state.lock, flags);
+
+ switch (type) {
+ case WIIMOTE_EXT_NONE:
+ return sprintf(buf, "none\n");
+ case WIIMOTE_EXT_NUNCHUK:
+ return sprintf(buf, "nunchuk\n");
+ case WIIMOTE_EXT_CLASSIC_CONTROLLER:
+ return sprintf(buf, "classic\n");
+ case WIIMOTE_EXT_BALANCE_BOARD:
+ return sprintf(buf, "balanceboard\n");
+ case WIIMOTE_EXT_UNKNOWN:
+ /* fallthrough */
+ default:
+ return sprintf(buf, "unknown\n");
+ }
+}
+
+static ssize_t wiimote_ext_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct wiimote_data *wdata = dev_to_wii(dev);
+
+ if (!strcmp(buf, "scan")) {
+ wiimote_schedule(wdata);
+ } else {
+ return -EINVAL;
+ }
+
+ return strnlen(buf, PAGE_SIZE);
+}
+
+static DEVICE_ATTR(extension, S_IRUGO | S_IWUSR | S_IWGRP, wiimote_ext_show,
+ wiimote_ext_store);
+
+static ssize_t wiimote_dev_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct wiimote_data *wdata = dev_to_wii(dev);
+ __u8 type;
+ unsigned long flags;
+
+ spin_lock_irqsave(&wdata->state.lock, flags);
+ type = wdata->state.devtype;
+ spin_unlock_irqrestore(&wdata->state.lock, flags);
+
+ switch (type) {
+ case WIIMOTE_DEV_GENERIC:
+ return sprintf(buf, "generic\n");
+ case WIIMOTE_DEV_GEN10:
+ return sprintf(buf, "gen10\n");
+ case WIIMOTE_DEV_GEN20:
+ return sprintf(buf, "gen20\n");
+ case WIIMOTE_DEV_BALANCE_BOARD:
+ return sprintf(buf, "balanceboard\n");
+ case WIIMOTE_DEV_PENDING:
+ return sprintf(buf, "pending\n");
+ case WIIMOTE_DEV_UNKNOWN:
+ /* fallthrough */
+ default:
+ return sprintf(buf, "unknown\n");
+ }
+}
+
+static DEVICE_ATTR(devtype, S_IRUGO, wiimote_dev_show, NULL);
+
static struct wiimote_data *wiimote_create(struct hid_device *hdev)
{
struct wiimote_data *wdata;
@@ -1631,6 +1716,9 @@ static void wiimote_destroy(struct wiimote_data *wdata)
cancel_work_sync(&wdata->init_worker);
del_timer_sync(&wdata->timer);
+ device_remove_file(&wdata->hdev->dev, &dev_attr_devtype);
+ device_remove_file(&wdata->hdev->dev, &dev_attr_extension);
+
wiimote_mp_unload(wdata);
wiimote_ext_unload(wdata);
wiimote_modules_unload(wdata);
@@ -1673,6 +1761,18 @@ static int wiimote_hid_probe(struct hid_device *hdev,
goto err_stop;
}
+ ret = device_create_file(&hdev->dev, &dev_attr_extension);
+ if (ret) {
+ hid_err(hdev, "cannot create sysfs attribute\n");
+ goto err_close;
+ }
+
+ ret = device_create_file(&hdev->dev, &dev_attr_devtype);
+ if (ret) {
+ hid_err(hdev, "cannot create sysfs attribute\n");
+ goto err_ext;
+ }
+
ret = wiidebug_init(wdata);
if (ret)
goto err_free;
@@ -1688,6 +1788,10 @@ err_free:
wiimote_destroy(wdata);
return ret;
+err_ext:
+ device_remove_file(&wdata->hdev->dev, &dev_attr_extension);
+err_close:
+ hid_hw_close(hdev);
err_stop:
hid_hw_stop(hdev);
err:
--
1.8.2.2
next prev parent reply other threads:[~2013-05-05 21:14 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-05 21:12 [PATCH 00/26] Wii Remote Extension Hotplugging Support David Herrmann
2013-05-05 21:12 ` [PATCH 01/26] HID: wiimote: extend driver description David Herrmann
2013-06-03 9:19 ` Jiri Kosina
2013-06-03 20:28 ` David Herrmann
2013-05-05 21:12 ` [PATCH 02/26] HID: wiimote: move queue handling into separate struct David Herrmann
2013-05-05 21:12 ` [PATCH 03/26] HID: wiimote: keep HID device open David Herrmann
2013-05-05 21:12 ` [PATCH 04/26] HID: wiimote: add device detection David Herrmann
2013-05-05 21:12 ` [PATCH 05/26] HID: wiimote: use cached battery values on I/O failure David Herrmann
2013-05-05 21:12 ` [PATCH 06/26] HID: wiimote: wake up if output queue failed David Herrmann
2013-05-05 21:12 ` [PATCH 07/26] HID: wiimote: add sub-device module infrastructure David Herrmann
2013-05-05 21:12 ` [PATCH 08/26] HID: wiimote: convert KEYS and RUMBLE to modules David Herrmann
2013-05-05 21:12 ` [PATCH 09/26] HID: wiimote: convert BATTERY to module David Herrmann
2013-05-05 21:12 ` [PATCH 10/26] HID: wiimote: convert LEDS to modules David Herrmann
2013-05-05 21:12 ` [PATCH 11/26] HID: wiimote: convert ACCEL to module David Herrmann
2013-05-05 21:12 ` [PATCH 12/26] HID: wiimote: convert IR " David Herrmann
2013-05-05 21:12 ` [PATCH 13/26] HID: wiimote: add extension hotplug support David Herrmann
2013-05-23 10:53 ` David Herrmann
2013-05-23 12:28 ` Jiri Kosina
2013-05-05 21:12 ` [PATCH 14/26] HID: wiimote: add Balance Board support David Herrmann
2013-05-05 21:12 ` [PATCH 15/26] HID: wiimote: add Nunchuk support David Herrmann
2013-05-05 21:13 ` [PATCH 16/26] HID: wiimote: add Classic Controller extension David Herrmann
2013-05-06 0:39 ` Todd Showalter
2013-05-06 5:40 ` David Herrmann
2013-05-06 14:15 ` Todd Showalter
2013-05-05 21:13 ` [PATCH 17/26] HID: wiimote: add Motion Plus extension module David Herrmann
2013-05-05 21:13 ` [PATCH 18/26] HID: wiimote: fix ctx pointer in debugfs DRM-write David Herrmann
2013-05-05 21:13 ` [PATCH 19/26] HID: wiimote: lock DRM mode during debugfs overwrite David Herrmann
2013-05-05 21:13 ` David Herrmann [this message]
2013-05-05 21:13 ` [PATCH 21/26] HID: wiimote: add "bboard_calib" attribute David Herrmann
2013-05-05 21:13 ` [PATCH 22/26] HID: wiimote: remove old static extension support David Herrmann
2013-05-05 21:13 ` [PATCH 23/26] HID: wiimote: add MP quirks David Herrmann
2013-05-05 21:13 ` [RFC 24/26] HID: wiimote: support Nintendo Wii U Pro Controller David Herrmann
2013-05-06 0:43 ` Todd Showalter
2013-05-06 5:49 ` David Herrmann
2013-05-06 14:14 ` Todd Showalter
2013-05-08 15:33 ` David Herrmann
2013-05-08 16:40 ` Todd Showalter
2013-05-08 17:05 ` Dmitry Torokhov
2013-05-08 17:20 ` Todd Showalter
2013-05-08 17:25 ` David Herrmann
2013-05-08 17:26 ` Dmitry Torokhov
2013-05-13 17:03 ` David Herrmann
2013-05-13 17:40 ` Todd Showalter
2013-05-22 12:10 ` David Herrmann
2013-05-22 16:18 ` Todd Showalter
2013-05-05 21:13 ` [PATCH 25/26] HID: wiimote: fix DRM debug-attr to correctly parse input David Herrmann
2013-05-05 21:13 ` [RFC 26/26] HID/ALSA: wiimote: add speaker support David Herrmann
2013-05-26 20:55 ` [PATCH 27/26] HID: wiimote: init EXT/MP during device detection David Herrmann
2013-05-26 20:55 ` [PATCH 28/26] HID: wiimote: discard invalid EXT data reports David Herrmann
2013-05-26 20:55 ` [PATCH 29/26] HID: wiimote: fix classic controller parsing 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=1367788390-29835-21-git-send-email-dh.herrmann@gmail.com \
--to=dh.herrmann@gmail.com \
--cc=jkosina@suse.cz \
--cc=linux-input@vger.kernel.org \
/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).