HID: core: implement generic .request()
authorBenjamin Tissoires <benjamin.tissoires@redhat.com>
Mon, 10 Feb 2014 17:58:48 +0000 (12:58 -0500)
committerJiri Kosina <jkosina@suse.cz>
Mon, 17 Feb 2014 13:52:51 +0000 (14:52 +0100)
.request() can be emulated through .raw_request()
we can implement this emulation in hid-core, and make .request
not mandatory for transport layer 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/hid-core.c
include/linux/hid.h

index 026ab0fc06f75d7671e40fb00bb73c83c815c9e3..b6ae69711d2ae3f9f3b6384abf2c214e8e34fade 100644 (file)
@@ -1248,6 +1248,11 @@ void hid_output_report(struct hid_report *report, __u8 *data)
 }
 EXPORT_SYMBOL_GPL(hid_output_report);
 
+static int hid_report_len(struct hid_report *report)
+{
+       return ((report->size - 1) >> 3) + 1 + (report->id > 0) + 7;
+}
+
 /*
  * Allocator for buffer that is going to be passed to hid_output_report()
  */
@@ -1258,7 +1263,7 @@ u8 *hid_alloc_report_buf(struct hid_report *report, gfp_t flags)
         * of implement() working on 8 byte chunks
         */
 
-       int len = ((report->size - 1) >> 3) + 1 + (report->id > 0) + 7;
+       int len = hid_report_len(report);
 
        return kmalloc(len, flags);
 }
@@ -1314,6 +1319,44 @@ static struct hid_report *hid_get_report(struct hid_report_enum *report_enum,
        return report;
 }
 
+/*
+ * Implement a generic .request() callback, using .raw_request()
+ * DO NOT USE in hid drivers directly, but through hid_hw_request instead.
+ */
+void __hid_request(struct hid_device *hid, struct hid_report *report,
+               int reqtype)
+{
+       char *buf;
+       int ret;
+       int len;
+
+       if (!hid->ll_driver->raw_request)
+               return;
+
+       buf = hid_alloc_report_buf(report, GFP_KERNEL);
+       if (!buf)
+               return;
+
+       len = hid_report_len(report);
+
+       if (reqtype == HID_REQ_SET_REPORT)
+               hid_output_report(report, buf);
+
+       ret = hid->ll_driver->raw_request(hid, report->id, buf, len,
+                                         report->type, reqtype);
+       if (ret < 0) {
+               dbg_hid("unable to complete request: %d\n", ret);
+               goto out;
+       }
+
+       if (reqtype == HID_REQ_GET_REPORT)
+               hid_input_report(hid, report->type, buf, ret, 0);
+
+out:
+       kfree(buf);
+}
+EXPORT_SYMBOL_GPL(__hid_request);
+
 int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size,
                int interrupt)
 {
index a837ede65ec6875044c9ae51642fd52d8d2c2301..09fbbd7fb7848b74914d0aa2688d81e2cd44b0e0 100644 (file)
@@ -753,6 +753,7 @@ struct hid_field *hidinput_get_led_field(struct hid_device *hid);
 unsigned int hidinput_count_leds(struct hid_device *hid);
 __s32 hidinput_calc_abs_res(const struct hid_field *field, __u16 code);
 void hid_output_report(struct hid_report *report, __u8 *data);
+void __hid_request(struct hid_device *hid, struct hid_report *rep, int reqtype);
 u8 *hid_alloc_report_buf(struct hid_report *report, gfp_t flags);
 struct hid_device *hid_allocate_device(void);
 struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id);
@@ -965,7 +966,9 @@ static inline void hid_hw_request(struct hid_device *hdev,
                                  struct hid_report *report, int reqtype)
 {
        if (hdev->ll_driver->request)
-               hdev->ll_driver->request(hdev, report, reqtype);
+               return hdev->ll_driver->request(hdev, report, reqtype);
+
+       __hid_request(hdev, report, reqtype);
 }
 
 /**
This page took 0.029933 seconds and 5 git commands to generate.