HID: ll_driver: Extend the interface with idle requests
authorBenjamin Tissoires <benjamin.tissoires@redhat.com>
Wed, 27 Feb 2013 15:38:17 +0000 (16:38 +0100)
committerJiri Kosina <jkosina@suse.cz>
Thu, 7 Mar 2013 14:58:17 +0000 (15:58 +0100)
Some drivers send the idle command directly to underlying device,
creating an unwanted dependency on the underlying transport layer.
This patch adds hid_hw_idle() to the interface, thereby removing
usbhid from the lion share of the drivers.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
drivers/hid/usbhid/hid-core.c
include/linux/hid.h

index 420466bc481abb508f1f4a7b1167af206672ab32..effcd3d6f5cf6ebf0f638e93b20448edaeb5bc34 100644 (file)
@@ -1253,6 +1253,20 @@ static void usbhid_request(struct hid_device *hid, struct hid_report *rep, int r
        }
 }
 
+static int usbhid_idle(struct hid_device *hid, int report, int idle,
+               int reqtype)
+{
+       struct usb_device *dev = hid_to_usb_dev(hid);
+       struct usb_interface *intf = to_usb_interface(hid->dev.parent);
+       struct usb_host_interface *interface = intf->cur_altsetting;
+       int ifnum = interface->desc.bInterfaceNumber;
+
+       if (reqtype != HID_REQ_SET_IDLE)
+               return -EINVAL;
+
+       return hid_set_idle(dev, ifnum, report, idle);
+}
+
 static struct hid_ll_driver usb_hid_driver = {
        .parse = usbhid_parse,
        .start = usbhid_start,
@@ -1263,6 +1277,7 @@ static struct hid_ll_driver usb_hid_driver = {
        .hidinput_input_event = usb_hidinput_input_event,
        .request = usbhid_request,
        .wait = usbhid_wait_io,
+       .idle = usbhid_idle,
 };
 
 static int usbhid_probe(struct usb_interface *intf, const struct usb_device_id *id)
index 7071eb3d36c76c2e2e1fb433c6fb65f81b4fbe56..863744c38ddc88c2c324c0021a9763b7bab43887 100644 (file)
@@ -664,6 +664,7 @@ struct hid_driver {
  *        shouldn't allocate anything to not leak memory
  * @request: send report request to device (e.g. feature report)
  * @wait: wait for buffered io to complete (send/recv reports)
+ * @idle: send idle request to device
  */
 struct hid_ll_driver {
        int (*start)(struct hid_device *hdev);
@@ -683,6 +684,7 @@ struct hid_ll_driver {
                        struct hid_report *report, int reqtype);
 
        int (*wait)(struct hid_device *hdev);
+       int (*idle)(struct hid_device *hdev, int report, int idle, int reqtype);
 
 };
 
@@ -906,6 +908,23 @@ static inline void hid_hw_request(struct hid_device *hdev,
                hdev->ll_driver->request(hdev, report, reqtype);
 }
 
+/**
+ * hid_hw_idle - send idle request to device
+ *
+ * @hdev: hid device
+ * @report: report to control
+ * @idle: idle state
+ * @reqtype: hid request type
+ */
+static inline int hid_hw_idle(struct hid_device *hdev, int report, int idle,
+               int reqtype)
+{
+       if (hdev->ll_driver->idle)
+               return hdev->ll_driver->idle(hdev, report, idle, reqtype);
+
+       return 0;
+}
+
 /**
  * hid_hw_wait - wait for buffered io to complete
  *