diff options
author | David Herrmann <dh.herrmann@googlemail.com> | 2011-11-17 14:12:04 +0100 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2011-11-22 23:09:08 +0100 |
commit | c1e51398a14bd74c58a838e9e76e8f726c5643b9 (patch) | |
tree | d3ec6055d7c564570b74d54a8e1d63b0ec28a218 /drivers/hid | |
parent | 492ba955c1f7b8fdc3d87b6e4765c7a5db5f7657 (diff) | |
download | op-kernel-dev-c1e51398a14bd74c58a838e9e76e8f726c5643b9.zip op-kernel-dev-c1e51398a14bd74c58a838e9e76e8f726c5643b9.tar.gz |
HID: wiimote: Add extension sysfs attribute
Add new sysfs attribute "extension" which returns the currently connected and
initialized extensions.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid')
-rw-r--r-- | drivers/hid/hid-wiimote-ext.c | 46 |
1 files changed, 46 insertions, 0 deletions
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); } |