diff options
| -rw-r--r-- | Documentation/hid/hid-transport.txt | 3 | ||||
| -rw-r--r-- | drivers/hid/Kconfig | 9 | ||||
| -rw-r--r-- | drivers/hid/Makefile | 1 | ||||
| -rw-r--r-- | drivers/hid/hid-core.c | 51 | ||||
| -rw-r--r-- | drivers/hid/hid-cp2112.c | 1073 | ||||
| -rw-r--r-- | drivers/hid/hid-hyperv.c | 10 | ||||
| -rw-r--r-- | drivers/hid/hid-ids.h | 1 | ||||
| -rw-r--r-- | drivers/hid/hid-input.c | 10 | ||||
| -rw-r--r-- | drivers/hid/hid-lg.c | 8 | ||||
| -rw-r--r-- | drivers/hid/hid-logitech-dj.c | 21 | ||||
| -rw-r--r-- | drivers/hid/hid-magicmouse.c | 4 | ||||
| -rw-r--r-- | drivers/hid/hid-sony.c | 64 | ||||
| -rw-r--r-- | drivers/hid/hid-thingm.c | 4 | ||||
| -rw-r--r-- | drivers/hid/hid-wacom.c | 26 | ||||
| -rw-r--r-- | drivers/hid/hid-wiimote-core.c | 4 | ||||
| -rw-r--r-- | drivers/hid/hidraw.c | 20 | ||||
| -rw-r--r-- | drivers/hid/i2c-hid/i2c-hid.c | 70 | ||||
| -rw-r--r-- | drivers/hid/uhid.c | 37 | ||||
| -rw-r--r-- | drivers/hid/usbhid/hid-core.c | 21 | ||||
| -rw-r--r-- | include/linux/hid.h | 37 | ||||
| -rw-r--r-- | net/bluetooth/hidp/core.c | 14 |
21 files changed, 1288 insertions, 200 deletions
diff --git a/Documentation/hid/hid-transport.txt b/Documentation/hid/hid-transport.txt index 9dbbceaef4f3..3dcba9fd4a3a 100644 --- a/Documentation/hid/hid-transport.txt +++ b/Documentation/hid/hid-transport.txt | |||
| @@ -283,7 +283,8 @@ The available HID callbacks are: | |||
| 283 | int reqtype) | 283 | int reqtype) |
| 284 | Same as ->request() but provides the report as raw buffer. This request shall | 284 | Same as ->request() but provides the report as raw buffer. This request shall |
| 285 | be synchronous. A transport driver must not use ->wait() to complete such | 285 | be synchronous. A transport driver must not use ->wait() to complete such |
| 286 | requests. | 286 | requests. This request is mandatory and hid core will reject the device if |
| 287 | it is missing. | ||
| 287 | 288 | ||
| 288 | - int (*output_report) (struct hid_device *hdev, __u8 *buf, size_t len) | 289 | - int (*output_report) (struct hid_device *hdev, __u8 *buf, size_t len) |
| 289 | Send raw output report via intr channel. Used by some HID device drivers | 290 | Send raw output report via intr channel. Used by some HID device drivers |
diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index 0c3de7ae6946..7af9d0b5dea1 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig | |||
| @@ -175,6 +175,15 @@ config HID_PRODIKEYS | |||
| 175 | multimedia keyboard, but will lack support for the musical keyboard | 175 | multimedia keyboard, but will lack support for the musical keyboard |
| 176 | and some additional multimedia keys. | 176 | and some additional multimedia keys. |
| 177 | 177 | ||
| 178 | config HID_CP2112 | ||
| 179 | tristate "Silicon Labs CP2112 HID USB-to-SMBus Bridge support" | ||
| 180 | depends on USB_HID && I2C && GPIOLIB | ||
| 181 | ---help--- | ||
| 182 | Support for Silicon Labs CP2112 HID USB to SMBus Master Bridge. | ||
| 183 | This is a HID device driver which registers as an i2c adapter | ||
| 184 | and gpiochip to expose these functions of the CP2112. The | ||
| 185 | customizable USB descriptor fields are exposed as sysfs attributes. | ||
| 186 | |||
| 178 | config HID_CYPRESS | 187 | config HID_CYPRESS |
| 179 | tristate "Cypress mouse and barcode readers" if EXPERT | 188 | tristate "Cypress mouse and barcode readers" if EXPERT |
| 180 | depends on HID | 189 | depends on HID |
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile index 30e44318f87f..fc712dde02a4 100644 --- a/drivers/hid/Makefile +++ b/drivers/hid/Makefile | |||
| @@ -41,6 +41,7 @@ obj-$(CONFIG_HID_AUREAL) += hid-aureal.o | |||
| 41 | obj-$(CONFIG_HID_BELKIN) += hid-belkin.o | 41 | obj-$(CONFIG_HID_BELKIN) += hid-belkin.o |
| 42 | obj-$(CONFIG_HID_CHERRY) += hid-cherry.o | 42 | obj-$(CONFIG_HID_CHERRY) += hid-cherry.o |
| 43 | obj-$(CONFIG_HID_CHICONY) += hid-chicony.o | 43 | obj-$(CONFIG_HID_CHICONY) += hid-chicony.o |
| 44 | obj-$(CONFIG_HID_CP2112) += hid-cp2112.o | ||
| 44 | obj-$(CONFIG_HID_CYPRESS) += hid-cypress.o | 45 | obj-$(CONFIG_HID_CYPRESS) += hid-cypress.o |
| 45 | obj-$(CONFIG_HID_DRAGONRISE) += hid-dr.o | 46 | obj-$(CONFIG_HID_DRAGONRISE) += hid-dr.o |
| 46 | obj-$(CONFIG_HID_EMS_FF) += hid-emsff.o | 47 | obj-$(CONFIG_HID_EMS_FF) += hid-emsff.o |
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index 026ab0fc06f7..ddb981db08bd 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c | |||
| @@ -1248,6 +1248,11 @@ void hid_output_report(struct hid_report *report, __u8 *data) | |||
| 1248 | } | 1248 | } |
| 1249 | EXPORT_SYMBOL_GPL(hid_output_report); | 1249 | EXPORT_SYMBOL_GPL(hid_output_report); |
| 1250 | 1250 | ||
| 1251 | static int hid_report_len(struct hid_report *report) | ||
| 1252 | { | ||
| 1253 | return ((report->size - 1) >> 3) + 1 + (report->id > 0) + 7; | ||
| 1254 | } | ||
| 1255 | |||
| 1251 | /* | 1256 | /* |
| 1252 | * Allocator for buffer that is going to be passed to hid_output_report() | 1257 | * Allocator for buffer that is going to be passed to hid_output_report() |
| 1253 | */ | 1258 | */ |
| @@ -1258,7 +1263,7 @@ u8 *hid_alloc_report_buf(struct hid_report *report, gfp_t flags) | |||
| 1258 | * of implement() working on 8 byte chunks | 1263 | * of implement() working on 8 byte chunks |
| 1259 | */ | 1264 | */ |
| 1260 | 1265 | ||
| 1261 | int len = ((report->size - 1) >> 3) + 1 + (report->id > 0) + 7; | 1266 | int len = hid_report_len(report); |
| 1262 | 1267 | ||
| 1263 | return kmalloc(len, flags); | 1268 | return kmalloc(len, flags); |
| 1264 | } | 1269 | } |
| @@ -1314,6 +1319,41 @@ static struct hid_report *hid_get_report(struct hid_report_enum *report_enum, | |||
| 1314 | return report; | 1319 | return report; |
| 1315 | } | 1320 | } |
| 1316 | 1321 | ||
| 1322 | /* | ||
| 1323 | * Implement a generic .request() callback, using .raw_request() | ||
| 1324 | * DO NOT USE in hid drivers directly, but through hid_hw_request instead. | ||
| 1325 | */ | ||
| 1326 | void __hid_request(struct hid_device *hid, struct hid_report *report, | ||
| 1327 | int reqtype) | ||
| 1328 | { | ||
| 1329 | char *buf; | ||
| 1330 | int ret; | ||
| 1331 | int len; | ||
| 1332 | |||
| 1333 | buf = hid_alloc_report_buf(report, GFP_KERNEL); | ||
| 1334 | if (!buf) | ||
| 1335 | return; | ||
| 1336 | |||
| 1337 | len = hid_report_len(report); | ||
| 1338 | |||
| 1339 | if (reqtype == HID_REQ_SET_REPORT) | ||
| 1340 | hid_output_report(report, buf); | ||
| 1341 | |||
| 1342 | ret = hid->ll_driver->raw_request(hid, report->id, buf, len, | ||
| 1343 | report->type, reqtype); | ||
| 1344 | if (ret < 0) { | ||
| 1345 | dbg_hid("unable to complete request: %d\n", ret); | ||
| 1346 | goto out; | ||
| 1347 | } | ||
| 1348 | |||
| 1349 | if (reqtype == HID_REQ_GET_REPORT) | ||
| 1350 | hid_input_report(hid, report->type, buf, ret, 0); | ||
| 1351 | |||
| 1352 | out: | ||
| 1353 | kfree(buf); | ||
| 1354 | } | ||
| 1355 | EXPORT_SYMBOL_GPL(__hid_request); | ||
| 1356 | |||
| 1317 | int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size, | 1357 | int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size, |
| 1318 | int interrupt) | 1358 | int interrupt) |
| 1319 | { | 1359 | { |
| @@ -1692,6 +1732,7 @@ static const struct hid_device_id hid_have_special_driver[] = { | |||
| 1692 | { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS2) }, | 1732 | { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS2) }, |
| 1693 | { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_AK1D) }, | 1733 | { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_AK1D) }, |
| 1694 | { HID_USB_DEVICE(USB_VENDOR_ID_CREATIVELABS, USB_DEVICE_ID_PRODIKEYS_PCMIDI) }, | 1734 | { HID_USB_DEVICE(USB_VENDOR_ID_CREATIVELABS, USB_DEVICE_ID_PRODIKEYS_PCMIDI) }, |
| 1735 | { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_CP2112) }, | ||
| 1695 | { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1) }, | 1736 | { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1) }, |
| 1696 | { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2) }, | 1737 | { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2) }, |
| 1697 | { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_3) }, | 1738 | { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_3) }, |
| @@ -2429,6 +2470,14 @@ int hid_add_device(struct hid_device *hdev) | |||
| 2429 | return -ENODEV; | 2470 | return -ENODEV; |
| 2430 | 2471 | ||
| 2431 | /* | 2472 | /* |
| 2473 | * Check for the mandatory transport channel. | ||
| 2474 | */ | ||
| 2475 | if (!hdev->ll_driver->raw_request) { | ||
| 2476 | hid_err(hdev, "transport driver missing .raw_request()\n"); | ||
| 2477 | return -EINVAL; | ||
| 2478 | } | ||
| 2479 | |||
| 2480 | /* | ||
| 2432 | * Read the device report descriptor once and use as template | 2481 | * Read the device report descriptor once and use as template |
| 2433 | * for the driver-specific modifications. | 2482 | * for the driver-specific modifications. |
| 2434 | */ | 2483 | */ |
diff --git a/drivers/hid/hid-cp2112.c b/drivers/hid/hid-cp2112.c new file mode 100644 index 000000000000..56be85a9a77c --- /dev/null +++ b/drivers/hid/hid-cp2112.c | |||
| @@ -0,0 +1,1073 @@ | |||
| 1 | /* | ||
| 2 | * hid-cp2112.c - Silicon Labs HID USB to SMBus master bridge | ||
| 3 | * Copyright (c) 2013,2014 Uplogix, Inc. | ||
| 4 | * David Barksdale <dbarksdale@uplogix.com> | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify it | ||
| 7 | * under the terms and conditions of the GNU General Public License, | ||
| 8 | * version 2, as published by the Free Software Foundation. | ||
| 9 | * | ||
| 10 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
| 13 | * more details. | ||
| 14 | */ | ||
| 15 | |||
| 16 | /* | ||
| 17 | * The Silicon Labs CP2112 chip is a USB HID device which provides an | ||
| 18 | * SMBus controller for talking to slave devices and 8 GPIO pins. The | ||
| 19 | * host communicates with the CP2112 via raw HID reports. | ||
| 20 | * | ||
| 21 | * Data Sheet: | ||
| 22 | * http://www.silabs.com/Support%20Documents/TechnicalDocs/CP2112.pdf | ||
| 23 | * Programming Interface Specification: | ||
| 24 | * http://www.silabs.com/Support%20Documents/TechnicalDocs/AN495.pdf | ||
| 25 | */ | ||
| 26 | |||
| 27 | #include <linux/gpio.h> | ||
| 28 | #include <linux/hid.h> | ||
| 29 | #include <linux/i2c.h> | ||
| 30 | #include <linux/module.h> | ||
| 31 | #include <linux/nls.h> | ||
| 32 | #include <linux/usb/ch9.h> | ||
| 33 | #include "hid-ids.h" | ||
| 34 | |||
| 35 | enum { | ||
| 36 | CP2112_GPIO_CONFIG = 0x02, | ||
| 37 | CP2112_GPIO_GET = 0x03, | ||
| 38 | CP2112_GPIO_SET = 0x04, | ||
| 39 | CP2112_GET_VERSION_INFO = 0x05, | ||
| 40 | CP2112_SMBUS_CONFIG = 0x06, | ||
| 41 | CP2112_DATA_READ_REQUEST = 0x10, | ||
| 42 | CP2112_DATA_WRITE_READ_REQUEST = 0x11, | ||
| 43 | CP2112_DATA_READ_FORCE_SEND = 0x12, | ||
| 44 | CP2112_DATA_READ_RESPONSE = 0x13, | ||
| 45 | CP2112_DATA_WRITE_REQUEST = 0x14, | ||
| 46 | CP2112_TRANSFER_STATUS_REQUEST = 0x15, | ||
| 47 | CP2112_TRANSFER_STATUS_RESPONSE = 0x16, | ||
| 48 | CP2112_CANCEL_TRANSFER = 0x17, | ||
| 49 | CP2112_LOCK_BYTE = 0x20, | ||
| 50 | CP2112_USB_CONFIG = 0x21, | ||
| 51 | CP2112_MANUFACTURER_STRING = 0x22, | ||
| 52 | CP2112_PRODUCT_STRING = 0x23, | ||
| 53 | CP2112_SERIAL_STRING = 0x24, | ||
| 54 | }; | ||
| 55 | |||
| 56 | enum { | ||
| 57 | STATUS0_IDLE = 0x00, | ||
| 58 | STATUS0_BUSY = 0x01, | ||
| 59 | STATUS0_COMPLETE = 0x02, | ||
| 60 | STATUS0_ERROR = 0x03, | ||
| 61 | }; | ||
| 62 | |||
| 63 | enum { | ||
| 64 | STATUS1_TIMEOUT_NACK = 0x00, | ||
| 65 | STATUS1_TIMEOUT_BUS = 0x01, | ||
| 66 | STATUS1_ARBITRATION_LOST = 0x02, | ||
| 67 | STATUS1_READ_INCOMPLETE = 0x03, | ||
| 68 | STATUS1_WRITE_INCOMPLETE = 0x04, | ||
| 69 | STATUS1_SUCCESS = 0x05, | ||
| 70 | }; | ||
| 71 | |||
| 72 | struct cp2112_smbus_config_report { | ||
| 73 | u8 report; /* CP2112_SMBUS_CONFIG */ | ||
| 74 | __be32 clock_speed; /* Hz */ | ||
| 75 | u8 device_address; /* Stored in the upper 7 bits */ | ||
| 76 | u8 auto_send_read; /* 1 = enabled, 0 = disabled */ | ||
| 77 | __be16 write_timeout; /* ms, 0 = no timeout */ | ||
| 78 | __be16 read_timeout; /* ms, 0 = no timeout */ | ||
| 79 | u8 scl_low_timeout; /* 1 = enabled, 0 = disabled */ | ||
| 80 | __be16 retry_time; /* # of retries, 0 = no limit */ | ||
| 81 | } __packed; | ||
| 82 | |||
| 83 | struct cp2112_usb_config_report { | ||
| 84 | u8 report; /* CP2112_USB_CONFIG */ | ||
| 85 | __le16 vid; /* Vendor ID */ | ||
| 86 | __le16 pid; /* Product ID */ | ||
| 87 | u8 max_power; /* Power requested in 2mA units */ | ||
| 88 | u8 power_mode; /* 0x00 = bus powered | ||
| 89 | 0x01 = self powered & regulator off | ||
| 90 | 0x02 = self powered & regulator on */ | ||
| 91 | u8 release_major; | ||
| 92 | u8 release_minor; | ||
| 93 | u8 mask; /* What fields to program */ | ||
| 94 | } __packed; | ||
| 95 | |||
| 96 | struct cp2112_read_req_report { | ||
| 97 | u8 report; /* CP2112_DATA_READ_REQUEST */ | ||
| 98 | u8 slave_address; | ||
| 99 | __be16 length; | ||
| 100 | } __packed; | ||
| 101 | |||
| 102 | struct cp2112_write_read_req_report { | ||
| 103 | u8 report; /* CP2112_DATA_WRITE_READ_REQUEST */ | ||
| 104 | u8 slave_address; | ||
| 105 | __be16 length; | ||
| 106 | u8 target_address_length; | ||
| 107 | u8 target_address[16]; | ||
| 108 | } __packed; | ||
| 109 | |||
| 110 | struct cp2112_write_req_report { | ||
| 111 | u8 report; /* CP2112_DATA_WRITE_REQUEST */ | ||
| 112 | u8 slave_address; | ||
| 113 | u8 length; | ||
| 114 | u8 data[61]; | ||
| 115 | } __packed; | ||
| 116 | |||
| 117 | struct cp2112_force_read_report { | ||
| 118 | u8 report; /* CP2112_DATA_READ_FORCE_SEND */ | ||
| 119 | __be16 length; | ||
| 120 | } __packed; | ||
| 121 | |||
| 122 | struct cp2112_xfer_status_report { | ||
| 123 | u8 report; /* CP2112_TRANSFER_STATUS_RESPONSE */ | ||
| 124 | u8 status0; /* STATUS0_* */ | ||
| 125 | u8 status1; /* STATUS1_* */ | ||
| 126 | __be16 retries; | ||
| 127 | __be16 length; | ||
| 128 | } __packed; | ||
| 129 | |||
| 130 | struct cp2112_string_report { | ||
| 131 | u8 dummy; /* force .string to be aligned */ | ||
| 132 | u8 report; /* CP2112_*_STRING */ | ||
| 133 | u8 length; /* length in bytes of everyting after .report */ | ||
| 134 | u8 type; /* USB_DT_STRING */ | ||
| 135 | wchar_t string[30]; /* UTF16_LITTLE_ENDIAN string */ | ||
| 136 | } __packed; | ||
| 137 | |||
| 138 | /* Number of times to request transfer status before giving up waiting for a | ||
| 139 | transfer to complete. This may need to be changed if SMBUS clock, retries, | ||
| 140 | or read/write/scl_low timeout settings are changed. */ | ||
| 141 | static const int XFER_STATUS_RETRIES = 10; | ||
| 142 | |||
| 143 | /* Time in ms to wait for a CP2112_DATA_READ_RESPONSE or | ||
| 144 | CP2112_TRANSFER_STATUS_RESPONSE. */ | ||
| 145 | static const int RESPONSE_TIMEOUT = 50; | ||
| 146 | |||
| 147 | static const struct hid_device_id cp2112_devices[] = { | ||
| 148 | { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_CP2112) }, | ||
| 149 | { } | ||
| 150 | }; | ||
| 151 | MODULE_DEVICE_TABLE(hid, cp2112_devices); | ||
| 152 | |||
| 153 | struct cp2112_device { | ||
| 154 | struct i2c_adapter adap; | ||
| 155 | struct hid_device *hdev; | ||
| 156 | wait_queue_head_t wait; | ||
| 157 | u8 read_data[61]; | ||
| 158 | u8 read_length; | ||
| 159 | int xfer_status; | ||
| 160 | atomic_t read_avail; | ||
| 161 | atomic_t xfer_avail; | ||
| 162 | struct gpio_chip gc; | ||
| 163 | }; | ||
| 164 | |||
| 165 | static int gpio_push_pull = 0xFF; | ||
| 166 | module_param(gpio_push_pull, int, S_IRUGO | S_IWUSR); | ||
| 167 | MODULE_PARM_DESC(gpio_push_pull, "GPIO push-pull configuration bitmask"); | ||
| 168 | |||
| 169 | static int cp2112_gpio_direction_input(struct gpio_chip *chip, unsigned offset) | ||
| 170 | { | ||
| 171 | struct cp2112_device *dev = container_of(chip, struct cp2112_device, | ||
| 172 | gc); | ||
| 173 | struct hid_device *hdev = dev->hdev; | ||
| 174 | u8 buf[5]; | ||
| 175 | int ret; | ||
| 176 | |||
| 177 | ret = hid_hw_raw_request(hdev, CP2112_GPIO_CONFIG, buf, | ||
| 178 | sizeof(buf), HID_FEATURE_REPORT, | ||
| 179 | HID_REQ_GET_REPORT); | ||
| 180 | if (ret != sizeof(buf)) { | ||
| 181 | hid_err(hdev, "error requesting GPIO config: %d\n", ret); | ||
| 182 | return ret; | ||
| 183 | } | ||
| 184 | |||
| 185 | buf[1] &= ~(1 << offset); | ||
| 186 | buf[2] = gpio_push_pull; | ||
| 187 | |||
| 188 | ret = hid_hw_raw_request(hdev, CP2112_GPIO_CONFIG, buf, sizeof(buf), | ||
| 189 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); | ||
| 190 | if (ret < 0) { | ||
| 191 | hid_err(hdev, "error setting GPIO config: %d\n", ret); | ||
| 192 | return ret; | ||
| 193 | } | ||
| 194 | |||
| 195 | return 0; | ||
| 196 | } | ||
| 197 | |||
| 198 | static void cp2112_gpio_set(struct gpio_chip *chip, unsigned offset, int value) | ||
| 199 | { | ||
| 200 | struct cp2112_device *dev = container_of(chip, struct cp2112_device, | ||
| 201 | gc); | ||
| 202 | struct hid_device *hdev = dev->hdev; | ||
| 203 | u8 buf[3]; | ||
| 204 | int ret; | ||
| 205 | |||
| 206 | buf[0] = CP2112_GPIO_SET; | ||
| 207 | buf[1] = value ? 0xff : 0; | ||
| 208 | buf[2] = 1 << offset; | ||
| 209 | |||
| 210 | ret = hid_hw_raw_request(hdev, CP2112_GPIO_SET, buf, sizeof(buf), | ||
| 211 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); | ||
| 212 | if (ret < 0) | ||
| 213 | hid_err(hdev, "error setting GPIO values: %d\n", ret); | ||
| 214 | } | ||
| 215 | |||
| 216 | static int cp2112_gpio_get(struct gpio_chip *chip, unsigned offset) | ||
| 217 | { | ||
| 218 | struct cp2112_device *dev = container_of(chip, struct cp2112_device, | ||
| 219 | gc); | ||
| 220 | struct hid_device *hdev = dev->hdev; | ||
| 221 | u8 buf[2]; | ||
| 222 | int ret; | ||
| 223 | |||
| 224 | ret = hid_hw_raw_request(hdev, CP2112_GPIO_GET, buf, sizeof(buf), | ||
| 225 | HID_FEATURE_REPORT, HID_REQ_GET_REPORT); | ||
| 226 | if (ret != sizeof(buf)) { | ||
| 227 | hid_err(hdev, "error requesting GPIO values: %d\n", ret); | ||
| 228 | return ret; | ||
| 229 | } | ||
| 230 | |||
| 231 | return (buf[1] >> offset) & 1; | ||
| 232 | } | ||
| 233 | |||
| 234 | static int cp2112_gpio_direction_output(struct gpio_chip *chip, | ||
| 235 | unsigned offset, int value) | ||
| 236 | { | ||
| 237 | struct cp2112_device *dev = container_of(chip, struct cp2112_device, | ||
| 238 | gc); | ||
| 239 | struct hid_device *hdev = dev->hdev; | ||
| 240 | u8 buf[5]; | ||
| 241 | int ret; | ||
| 242 | |||
| 243 | cp2112_gpio_set(chip, offset, value); | ||
| 244 | |||
| 245 | ret = hid_hw_raw_request(hdev, CP2112_GPIO_CONFIG, buf, | ||
| 246 | sizeof(buf), HID_FEATURE_REPORT, | ||
| 247 | HID_REQ_GET_REPORT); | ||
| 248 | if (ret != sizeof(buf)) { | ||
| 249 | hid_err(hdev, "error requesting GPIO config: %d\n", ret); | ||
| 250 | return ret; | ||
| 251 | } | ||
| 252 | |||
| 253 | buf[1] |= 1 << offset; | ||
| 254 | buf[2] = gpio_push_pull; | ||
| 255 | |||
| 256 | ret = hid_hw_raw_request(hdev, CP2112_GPIO_CONFIG, buf, sizeof(buf), | ||
| 257 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); | ||
| 258 | if (ret < 0) { | ||
| 259 | hid_err(hdev, "error setting GPIO config: %d\n", ret); | ||
| 260 | return ret; | ||
| 261 | } | ||
| 262 | |||
| 263 | return 0; | ||
| 264 | } | ||
| 265 | |||
| 266 | static int cp2112_hid_get(struct hid_device *hdev, unsigned char report_number, | ||
| 267 | u8 *data, size_t count, unsigned char report_type) | ||
| 268 | { | ||
| 269 | u8 *buf; | ||
| 270 | int ret; | ||
| 271 | |||
| 272 | buf = kmalloc(count, GFP_KERNEL); | ||
| 273 | if (!buf) | ||
| 274 | return -ENOMEM; | ||
| 275 | |||
| 276 | ret = hid_hw_raw_request(hdev, report_number, buf, count, | ||
| 277 | report_type, HID_REQ_GET_REPORT); | ||
| 278 | memcpy(data, buf, count); | ||
| 279 | kfree(buf); | ||
| 280 | return ret; | ||
| 281 | } | ||
| 282 | |||
| 283 | static int cp2112_hid_output(struct hid_device *hdev, u8 *data, size_t count, | ||
| 284 | unsigned char report_type) | ||
| 285 | { | ||
| 286 | u8 *buf; | ||
| 287 | int ret; | ||
| 288 | |||
| 289 | buf = kmemdup(data, count, GFP_KERNEL); | ||
| 290 | if (!buf) | ||
| 291 | return -ENOMEM; | ||
| 292 | |||
| 293 | if (report_type == HID_OUTPUT_REPORT) | ||
| 294 | ret = hid_hw_output_report(hdev, buf, count); | ||
| 295 | else | ||
| 296 | ret = hid_hw_raw_request(hdev, buf[0], buf, count, report_type, | ||
| 297 | HID_REQ_SET_REPORT); | ||
| 298 | |||
| 299 | kfree(buf); | ||
| 300 | return ret; | ||
| 301 | } | ||
| 302 | |||
| 303 | static int cp2112_wait(struct cp2112_device *dev, atomic_t *avail) | ||
| 304 | { | ||
| 305 | int ret = 0; | ||
| 306 | |||
| 307 | /* We have sent either a CP2112_TRANSFER_STATUS_REQUEST or a | ||
| 308 | * CP2112_DATA_READ_FORCE_SEND and we are waiting for the response to | ||
| 309 | * come in cp2112_raw_event or timeout. There will only be one of these | ||
| 310 | * in flight at any one time. The timeout is extremely large and is a | ||
| 311 | * last resort if the CP2112 has died. If we do timeout we don't expect | ||
| 312 | * to receive the response which would cause data races, it's not like | ||
| 313 | * we can do anything about it anyway. | ||
| 314 | */ | ||
| 315 | ret = wait_event_interruptible_timeout(dev->wait, | ||
| 316 | atomic_read(avail), msecs_to_jiffies(RESPONSE_TIMEOUT)); | ||
| 317 | if (-ERESTARTSYS == ret) | ||
| 318 | return ret; | ||
| 319 | if (!ret) | ||
| 320 | return -ETIMEDOUT; | ||
| 321 | |||
| 322 | atomic_set(avail, 0); | ||
| 323 | return 0; | ||
| 324 | } | ||
| 325 | |||
| 326 | static int cp2112_xfer_status(struct cp2112_device *dev) | ||
| 327 | { | ||
| 328 | struct hid_device *hdev = dev->hdev; | ||
| 329 | u8 buf[2]; | ||
| 330 | int ret; | ||
| 331 | |||
| 332 | buf[0] = CP2112_TRANSFER_STATUS_REQUEST; | ||
| 333 | buf[1] = 0x01; | ||
| 334 | atomic_set(&dev->xfer_avail, 0); | ||
| 335 | |||
| 336 | ret = cp2112_hid_output(hdev, buf, 2, HID_OUTPUT_REPORT); | ||
| 337 | if (ret < 0) { | ||
| 338 | hid_warn(hdev, "Error requesting status: %d\n", ret); | ||
| 339 | return ret; | ||
| 340 | } | ||
| 341 | |||
| 342 | ret = cp2112_wait(dev, &dev->xfer_avail); | ||
| 343 | if (ret) | ||
| 344 | return ret; | ||
| 345 | |||
| 346 | return dev->xfer_status; | ||
| 347 | } | ||
| 348 | |||
| 349 | static int cp2112_read(struct cp2112_device *dev, u8 *data, size_t size) | ||
| 350 | { | ||
| 351 | struct hid_device *hdev = dev->hdev; | ||
| 352 | struct cp2112_force_read_report report; | ||
| 353 | int ret; | ||
| 354 | |||
| 355 | report.report = CP2112_DATA_READ_FORCE_SEND; | ||
| 356 | report.length = cpu_to_be16(size); | ||
| 357 | |||
| 358 | atomic_set(&dev->read_avail, 0); | ||
| 359 | |||
| 360 | ret = cp2112_hid_output(hdev, &report.report, sizeof(report), | ||
| 361 | HID_OUTPUT_REPORT); | ||
| 362 | if (ret < 0) { | ||
| 363 | hid_warn(hdev, "Error requesting data: %d\n", ret); | ||
| 364 | return ret; | ||
| 365 | } | ||
| 366 | |||
| 367 | ret = cp2112_wait(dev, &dev->read_avail); | ||
| 368 | if (ret) | ||
| 369 | return ret; | ||
| 370 | |||
| 371 | hid_dbg(hdev, "read %d of %zd bytes requested\n", | ||
| 372 | dev->read_length, size); | ||
| 373 | |||
| 374 | if (size > dev->read_length) | ||
| 375 | size = dev->read_length; | ||
| 376 | |||
| 377 | memcpy(data, dev->read_data, size); | ||
| 378 | return dev->read_length; | ||
| 379 | } | ||
| 380 | |||
| 381 | static int cp2112_read_req(void *buf, u8 slave_address, u16 length) | ||
| 382 | { | ||
| 383 | struct cp2112_read_req_report *report = buf; | ||
| 384 | |||
| 385 | if (length < 1 || length > 512) | ||
| 386 | return -EINVAL; | ||
| 387 | |||
| 388 | report->report = CP2112_DATA_READ_REQUEST; | ||
| 389 | report->slave_address = slave_address << 1; | ||
| 390 | report->length = cpu_to_be16(length); | ||
| 391 | return sizeof(*report); | ||
| 392 | } | ||
| 393 | |||
| 394 | static int cp2112_write_read_req(void *buf, u8 slave_address, u16 length, | ||
| 395 | u8 command, u8 *data, u8 data_length) | ||
| 396 | { | ||
| 397 | struct cp2112_write_read_req_report *report = buf; | ||
| 398 | |||
| 399 | if (length < 1 || length > 512 | ||
| 400 | || data_length > sizeof(report->target_address) - 1) | ||
| 401 | return -EINVAL; | ||
| 402 | |||
| 403 | report->report = CP2112_DATA_WRITE_READ_REQUEST; | ||
| 404 | report->slave_address = slave_address << 1; | ||
| 405 | report->length = cpu_to_be16(length); | ||
| 406 | report->target_address_length = data_length + 1; | ||
| 407 | report->target_address[0] = command; | ||
| 408 | memcpy(&report->target_address[1], data, data_length); | ||
| 409 | return data_length + 6; | ||
| 410 | } | ||
| 411 | |||
| 412 | static int cp2112_write_req(void *buf, u8 slave_address, u8 command, u8 *data, | ||
| 413 | u8 data_length) | ||
| 414 | { | ||
| 415 | struct cp2112_write_req_report *report = buf; | ||
| 416 | |||
| 417 | if (data_length > sizeof(report->data) - 1) | ||
| 418 | return -EINVAL; | ||
| 419 | |||
| 420 | report->report = CP2112_DATA_WRITE_REQUEST; | ||
| 421 | report->slave_address = slave_address << 1; | ||
| 422 | report->length = data_length + 1; | ||
| 423 | report->data[0] = command; | ||
| 424 | memcpy(&report->data[1], data, data_length); | ||
| 425 | return data_length + 4; | ||
| 426 | } | ||
| 427 | |||
| 428 | static int cp2112_xfer(struct i2c_adapter *adap, u16 addr, | ||
| 429 | unsigned short flags, char read_write, u8 command, | ||
| 430 | int size, union i2c_smbus_data *data) | ||
| 431 | { | ||
| 432 | struct cp2112_device *dev = (struct cp2112_device *)adap->algo_data; | ||
| 433 | struct hid_device *hdev = dev->hdev; | ||
| 434 | u8 buf[64]; | ||
| 435 | __be16 word; | ||
| 436 | ssize_t count; | ||
| 437 | size_t read_length = 0; | ||
| 438 | unsigned int retries; | ||
| 439 | int ret; | ||
| 440 | |||
| 441 | hid_dbg(hdev, "%s addr 0x%x flags 0x%x cmd 0x%x size %d\n", | ||
| 442 | read_write == I2C_SMBUS_WRITE ? "write" : "read", | ||
| 443 | addr, flags, command, size); | ||
| 444 | |||
| 445 | switch (size) { | ||
| 446 | case I2C_SMBUS_BYTE: | ||
| 447 | read_length = 1; | ||
| 448 | |||
| 449 | if (I2C_SMBUS_READ == read_write) | ||
| 450 | count = cp2112_read_req(buf, addr, read_length); | ||
| 451 | else | ||
| 452 | count = cp2112_write_req(buf, addr, data->byte, NULL, | ||
| 453 | 0); | ||
| 454 | break; | ||
| 455 | case I2C_SMBUS_BYTE_DATA: | ||
| 456 | read_length = 1; | ||
| 457 | |||
| 458 | if (I2C_SMBUS_READ == read_write) | ||
| 459 | count = cp2112_write_read_req(buf, addr, read_length, | ||
| 460 | command, NULL, 0); | ||
| 461 | else | ||
| 462 | count = cp2112_write_req(buf, addr, command, | ||
| 463 | &data->byte, 1); | ||
| 464 | break; | ||
| 465 | case I2C_SMBUS_WORD_DATA: | ||
| 466 | read_length = 2; | ||
| 467 | word = cpu_to_be16(data->word); | ||
| 468 | |||
| 469 | if (I2C_SMBUS_READ == read_write) | ||
| 470 | count = cp2112_write_read_req(buf, addr, read_length, | ||
| 471 | command, NULL, 0); | ||
| 472 | else | ||
| 473 | count = cp2112_write_req(buf, addr, command, | ||
| 474 | (u8 *)&word, 2); | ||
| 475 | break; | ||
| 476 | case I2C_SMBUS_PROC_CALL: | ||
| 477 | size = I2C_SMBUS_WORD_DATA; | ||
| 478 | read_write = I2C_SMBUS_READ; | ||
| 479 | read_length = 2; | ||
| 480 | word = cpu_to_be16(data->word); | ||
| 481 | |||
| 482 | count = cp2112_write_read_req(buf, addr, read_length, command, | ||
| 483 | (u8 *)&word, 2); | ||
| 484 | break; | ||
| 485 | case I2C_SMBUS_I2C_BLOCK_DATA: | ||
| 486 | size = I2C_SMBUS_BLOCK_DATA; | ||
| 487 | /* fallthrough */ | ||
| 488 | case I2C_SMBUS_BLOCK_DATA: | ||
| 489 | if (I2C_SMBUS_READ == read_write) { | ||
| 490 | count = cp2112_write_read_req(buf, addr, | ||
| 491 | I2C_SMBUS_BLOCK_MAX, | ||
| 492 | command, NULL, 0); | ||
| 493 | } else { | ||
| 494 | count = cp2112_write_req(buf, addr, command, | ||
| 495 | data->block, | ||
| 496 | data->block[0] + 1); | ||
| 497 | } | ||
| 498 | break; | ||
| 499 | case I2C_SMBUS_BLOCK_PROC_CALL: | ||
| 500 | size = I2C_SMBUS_BLOCK_DATA; | ||
| 501 | read_write = I2C_SMBUS_READ; | ||
| 502 | |||
| 503 | count = cp2112_write_read_req(buf, addr, I2C_SMBUS_BLOCK_MAX, | ||
| 504 | command, data->block, | ||
| 505 | data->block[0] + 1); | ||
| 506 | break; | ||
| 507 | default: | ||
| 508 | hid_warn(hdev, "Unsupported transaction %d\n", size); | ||
| 509 | return -EOPNOTSUPP; | ||
| 510 | } | ||
| 511 | |||
| 512 | if (count < 0) | ||
| 513 | return count; | ||
| 514 | |||
| 515 | ret = hid_hw_power(hdev, PM_HINT_FULLON); | ||
| 516 | if (ret < 0) { | ||
| 517 | hid_err(hdev, "power management error: %d\n", ret); | ||
| 518 | return ret; | ||
| 519 | } | ||
| 520 | |||
| 521 | ret = cp2112_hid_output(hdev, buf, count, HID_OUTPUT_REPORT); | ||
| 522 | if (ret < 0) { | ||
| 523 | hid_warn(hdev, "Error starting transaction: %d\n", ret); | ||
| 524 | goto power_normal; | ||
| 525 | } | ||
| 526 | |||
| 527 | for (retries = 0; retries < XFER_STATUS_RETRIES; ++retries) { | ||
| 528 | ret = cp2112_xfer_status(dev); | ||
| 529 | if (-EBUSY == ret) | ||
| 530 | continue; | ||
| 531 | if (ret < 0) | ||
| 532 | goto power_normal; | ||
| 533 | break; | ||
| 534 | } | ||
| 535 | |||
| 536 | if (XFER_STATUS_RETRIES <= retries) { | ||
| 537 | hid_warn(hdev, "Transfer timed out, cancelling.\n"); | ||
| 538 | buf[0] = CP2112_CANCEL_TRANSFER; | ||
| 539 | buf[1] = 0x01; | ||
| 540 | |||
| 541 | ret = cp2112_hid_output(hdev, buf, 2, HID_OUTPUT_REPORT); | ||
| 542 | if (ret < 0) | ||
| 543 | hid_warn(hdev, "Error cancelling transaction: %d\n", | ||
| 544 | ret); | ||
| 545 | |||
| 546 | ret = -ETIMEDOUT; | ||
| 547 | goto power_normal; | ||
| 548 | } | ||
| 549 | |||
| 550 | if (I2C_SMBUS_WRITE == read_write) { | ||
| 551 | ret = 0; | ||
| 552 | goto power_normal; | ||
| 553 | } | ||
| 554 | |||
| 555 | if (I2C_SMBUS_BLOCK_DATA == size) | ||
| 556 | read_length = ret; | ||
| 557 | |||
| 558 | ret = cp2112_read(dev, buf, read_length); | ||
| 559 | if (ret < 0) | ||
| 560 | goto power_normal; | ||
| 561 | if (ret != read_length) { | ||
| 562 | hid_warn(hdev, "short read: %d < %zd\n", ret, read_length); | ||
| 563 | ret = -EIO; | ||
| 564 | goto power_normal; | ||
| 565 | } | ||
| 566 | |||
| 567 | switch (size) { | ||
| 568 | case I2C_SMBUS_BYTE: | ||
| 569 | case I2C_SMBUS_BYTE_DATA: | ||
| 570 | data->byte = buf[0]; | ||
| 571 | break; | ||
| 572 | case I2C_SMBUS_WORD_DATA: | ||
| 573 | data->word = be16_to_cpup((__be16 *)buf); | ||
| 574 | break; | ||
| 575 | case I2C_SMBUS_BLOCK_DATA: | ||
| 576 | if (read_length > I2C_SMBUS_BLOCK_MAX) { | ||
| 577 | ret = -EPROTO; | ||
| 578 | goto power_normal; | ||
| 579 | } | ||
| 580 | |||
| 581 | memcpy(data->block, buf, read_length); | ||
| 582 | break; | ||
| 583 | } | ||
| 584 | |||
| 585 | ret = 0; | ||
| 586 | power_normal: | ||
| 587 | hid_hw_power(hdev, PM_HINT_NORMAL); | ||
| 588 | hid_dbg(hdev, "transfer finished: %d\n", ret); | ||
| 589 | return ret; | ||
| 590 | } | ||
| 591 | |||
| 592 | static u32 cp2112_functionality(struct i2c_adapter *adap) | ||
| 593 | { | ||
| 594 | return I2C_FUNC_SMBUS_BYTE | | ||
| 595 | I2C_FUNC_SMBUS_BYTE_DATA | | ||
| 596 | I2C_FUNC_SMBUS_WORD_DATA | | ||
| 597 | I2C_FUNC_SMBUS_BLOCK_DATA | | ||
| 598 | I2C_FUNC_SMBUS_I2C_BLOCK | | ||
| 599 | I2C_FUNC_SMBUS_PROC_CALL | | ||
| 600 | I2C_FUNC_SMBUS_BLOCK_PROC_CALL; | ||
| 601 | } | ||
| 602 | |||
| 603 | static const struct i2c_algorithm smbus_algorithm = { | ||
| 604 | .smbus_xfer = cp2112_xfer, | ||
| 605 | .functionality = cp2112_functionality, | ||
| 606 | }; | ||
| 607 | |||
| 608 | static int cp2112_get_usb_config(struct hid_device *hdev, | ||
| 609 | struct cp2112_usb_config_report *cfg) | ||
| 610 | { | ||
| 611 | int ret; | ||
| 612 | |||
| 613 | ret = cp2112_hid_get(hdev, CP2112_USB_CONFIG, (u8 *)cfg, sizeof(*cfg), | ||
| 614 | HID_FEATURE_REPORT); | ||
| 615 | if (ret != sizeof(*cfg)) { | ||
| 616 | hid_err(hdev, "error reading usb config: %d\n", ret); | ||
| 617 | if (ret < 0) | ||
| 618 | return ret; | ||
| 619 | return -EIO; | ||
| 620 | } | ||
| 621 | |||
| 622 | return 0; | ||
| 623 | } | ||
| 624 | |||
| 625 | static int cp2112_set_usb_config(struct hid_device *hdev, | ||
| 626 | struct cp2112_usb_config_report *cfg) | ||
| 627 | { | ||
| 628 | int ret; | ||
| 629 | |||
| 630 | BUG_ON(cfg->report != CP2112_USB_CONFIG); | ||
| 631 | |||
| 632 | ret = cp2112_hid_output(hdev, (u8 *)cfg, sizeof(*cfg), | ||
| 633 | HID_FEATURE_REPORT); | ||
| 634 | if (ret != sizeof(*cfg)) { | ||
| 635 | hid_err(hdev, "error writing usb config: %d\n", ret); | ||
| 636 | if (ret < 0) | ||
| 637 | return ret; | ||
| 638 | return -EIO; | ||
| 639 | } | ||
| 640 | |||
| 641 | return 0; | ||
| 642 | } | ||
| 643 | |||
| 644 | static void chmod_sysfs_attrs(struct hid_device *hdev); | ||
| 645 | |||
| 646 | #define CP2112_CONFIG_ATTR(name, store, format, ...) \ | ||
| 647 | static ssize_t name##_store(struct device *kdev, \ | ||
| 648 | struct device_attribute *attr, const char *buf, \ | ||
| 649 | size_t count) \ | ||
| 650 | { \ | ||
| 651 | struct hid_device *hdev = container_of(kdev, struct hid_device, dev); \ | ||
| 652 | struct cp2112_usb_config_report cfg; \ | ||
| 653 | int ret = cp2112_get_usb_config(hdev, &cfg); \ | ||
| 654 | if (ret) \ | ||
| 655 | return ret; \ | ||
| 656 | store; \ | ||
| 657 | ret = cp2112_set_usb_config(hdev, &cfg); \ | ||
| 658 | if (ret) \ | ||
| 659 | return ret; \ | ||
| 660 | chmod_sysfs_attrs(hdev); \ | ||
| 661 | return count; \ | ||
| 662 | } \ | ||
| 663 | static ssize_t name##_show(struct device *kdev, \ | ||
| 664 | struct device_attribute *attr, char *buf) \ | ||
| 665 | { \ | ||
| 666 | struct hid_device *hdev = container_of(kdev, struct hid_device, dev); \ | ||
| 667 | struct cp2112_usb_config_report cfg; \ | ||
| 668 | int ret = cp2112_get_usb_config(hdev, &cfg); \ | ||
| 669 | if (ret) \ | ||
| 670 | return ret; \ | ||
| 671 | return scnprintf(buf, PAGE_SIZE, format, ##__VA_ARGS__); \ | ||
| 672 | } \ | ||
| 673 | static DEVICE_ATTR_RW(name); | ||
| 674 | |||
| 675 | CP2112_CONFIG_ATTR(vendor_id, ({ | ||
| 676 | u16 vid; | ||
| 677 | |||
| 678 | if (sscanf(buf, "%hi", &vid) != 1) | ||
| 679 | return -EINVAL; | ||
| 680 | |||
| 681 | cfg.vid = cpu_to_le16(vid); | ||
| 682 | cfg.mask = 0x01; | ||
| 683 | }), "0x%04x\n", le16_to_cpu(cfg.vid)); | ||
| 684 | |||
| 685 | CP2112_CONFIG_ATTR(product_id, ({ | ||
| 686 | u16 pid; | ||
| 687 | |||
| 688 | if (sscanf(buf, "%hi", &pid) != 1) | ||
| 689 | return -EINVAL; | ||
| 690 | |||
| 691 | cfg.pid = cpu_to_le16(pid); | ||
| 692 | cfg.mask = 0x02; | ||
| 693 | }), "0x%04x\n", le16_to_cpu(cfg.pid)); | ||
| 694 | |||
| 695 | CP2112_CONFIG_ATTR(max_power, ({ | ||
| 696 | int mA; | ||
| 697 | |||
| 698 | if (sscanf(buf, "%i", &mA) != 1) | ||
| 699 | return -EINVAL; | ||
| 700 | |||
| 701 | cfg.max_power = (mA + 1) / 2; | ||
| 702 | cfg.mask = 0x04; | ||
| 703 | }), "%u mA\n", cfg.max_power * 2); | ||
| 704 | |||
| 705 | CP2112_CONFIG_ATTR(power_mode, ({ | ||
| 706 | if (sscanf(buf, "%hhi", &cfg.power_mode) != 1) | ||
| 707 | return -EINVAL; | ||
| 708 | |||
| 709 | cfg.mask = 0x08; | ||
| 710 | }), "%u\n", cfg.power_mode); | ||
| 711 | |||
| 712 | CP2112_CONFIG_ATTR(release_version, ({ | ||
| 713 | if (sscanf(buf, "%hhi.%hhi", &cfg.release_major, &cfg.release_minor) | ||
| 714 | != 2) | ||
| 715 | return -EINVAL; | ||
| 716 | |||
| 717 | cfg.mask = 0x10; | ||
| 718 | }), "%u.%u\n", cfg.release_major, cfg.release_minor); | ||
| 719 | |||
| 720 | #undef CP2112_CONFIG_ATTR | ||
| 721 | |||
| 722 | struct cp2112_pstring_attribute { | ||
| 723 | struct device_attribute attr; | ||
| 724 | unsigned char report; | ||
| 725 | }; | ||
| 726 | |||
| 727 | static ssize_t pstr_store(struct device *kdev, | ||
| 728 | struct device_attribute *kattr, const char *buf, | ||
| 729 | size_t count) | ||
| 730 | { | ||
| 731 | struct hid_device *hdev = container_of(kdev, struct hid_device, dev); | ||
| 732 | struct cp2112_pstring_attribute *attr = | ||
| 733 | container_of(kattr, struct cp2112_pstring_attribute, attr); | ||
| 734 | struct cp2112_string_report report; | ||
| 735 | int ret; | ||
| 736 | |||
| 737 | memset(&report, 0, sizeof(report)); | ||
| 738 | |||
| 739 | ret = utf8s_to_utf16s(buf, count, UTF16_LITTLE_ENDIAN, | ||
| 740 | report.string, ARRAY_SIZE(report.string)); | ||
| 741 | report.report = attr->report; | ||
| 742 | report.length = ret * sizeof(report.string[0]) + 2; | ||
| 743 | report.type = USB_DT_STRING; | ||
| 744 | |||
| 745 | ret = cp2112_hid_output(hdev, &report.report, report.length + 1, | ||
| 746 | HID_FEATURE_REPORT); | ||
| 747 | if (ret != report.length + 1) { | ||
| 748 | hid_err(hdev, "error writing %s string: %d\n", kattr->attr.name, | ||
| 749 | ret); | ||
| 750 | if (ret < 0) | ||
| 751 | return ret; | ||
| 752 | return -EIO; | ||
| 753 | } | ||
| 754 | |||
| 755 | chmod_sysfs_attrs(hdev); | ||
| 756 | return count; | ||
| 757 | } | ||
| 758 | |||
| 759 | static ssize_t pstr_show(struct device *kdev, | ||
| 760 | struct device_attribute *kattr, char *buf) | ||
| 761 | { | ||
| 762 | struct hid_device *hdev = container_of(kdev, struct hid_device, dev); | ||
| 763 | struct cp2112_pstring_attribute *attr = | ||
| 764 | container_of(kattr, struct cp2112_pstring_attribute, attr); | ||
| 765 | struct cp2112_string_report report; | ||
| 766 | u8 length; | ||
| 767 | int ret; | ||
| 768 | |||
| 769 | ret = cp2112_hid_get(hdev, attr->report, &report.report, | ||
| 770 | sizeof(report) - 1, HID_FEATURE_REPORT); | ||
| 771 | if (ret < 3) { | ||
| 772 | hid_err(hdev, "error reading %s string: %d\n", kattr->attr.name, | ||
| 773 | ret); | ||
| 774 | if (ret < 0) | ||
| 775 | return ret; | ||
| 776 | return -EIO; | ||
| 777 | } | ||
| 778 | |||
| 779 | if (report.length < 2) { | ||
| 780 | hid_err(hdev, "invalid %s string length: %d\n", | ||
| 781 | kattr->attr.name, report.length); | ||
| 782 | return -EIO; | ||
| 783 | } | ||
| 784 | |||
| 785 | length = report.length > ret - 1 ? ret - 1 : report.length; | ||
| 786 | length = (length - 2) / sizeof(report.string[0]); | ||
| 787 | ret = utf16s_to_utf8s(report.string, length, UTF16_LITTLE_ENDIAN, buf, | ||
| 788 | PAGE_SIZE - 1); | ||
| 789 | buf[ret++] = '\n'; | ||
| 790 | return ret; | ||
| 791 | } | ||
| 792 | |||
| 793 | #define CP2112_PSTR_ATTR(name, _report) \ | ||
| 794 | static struct cp2112_pstring_attribute dev_attr_##name = { \ | ||
| 795 | .attr = __ATTR(name, (S_IWUSR | S_IRUGO), pstr_show, pstr_store), \ | ||
| 796 | .report = _report, \ | ||
| 797 | }; | ||
| 798 | |||
| 799 | CP2112_PSTR_ATTR(manufacturer, CP2112_MANUFACTURER_STRING); | ||
| 800 | CP2112_PSTR_ATTR(product, CP2112_PRODUCT_STRING); | ||
| 801 | CP2112_PSTR_ATTR(serial, CP2112_SERIAL_STRING); | ||
| 802 | |||
| 803 | #undef CP2112_PSTR_ATTR | ||
| 804 | |||
| 805 | static const struct attribute_group cp2112_attr_group = { | ||
| 806 | .attrs = (struct attribute *[]){ | ||
| 807 | &dev_attr_vendor_id.attr, | ||
| 808 | &dev_attr_product_id.attr, | ||
| 809 | &dev_attr_max_power.attr, | ||
| 810 | &dev_attr_power_mode.attr, | ||
| 811 | &dev_attr_release_version.attr, | ||
| 812 | &dev_attr_manufacturer.attr.attr, | ||
| 813 | &dev_attr_product.attr.attr, | ||
| 814 | &dev_attr_serial.attr.attr, | ||
| 815 | NULL | ||
| 816 | } | ||
| 817 | }; | ||
| 818 | |||
| 819 | /* Chmoding our sysfs attributes is simply a way to expose which fields in the | ||
| 820 | * PROM have already been programmed. We do not depend on this preventing | ||
| 821 | * writing to these attributes since the CP2112 will simply ignore writes to | ||
| 822 | * already-programmed fields. This is why there is no sense in fixing this | ||
| 823 | * racy behaviour. | ||
| 824 | */ | ||
| 825 | static void chmod_sysfs_attrs(struct hid_device *hdev) | ||
| 826 | { | ||
| 827 | struct attribute **attr; | ||
| 828 | u8 buf[2]; | ||
| 829 | int ret; | ||
| 830 | |||
| 831 | ret = cp2112_hid_get(hdev, CP2112_LOCK_BYTE, buf, sizeof(buf), | ||
| 832 | HID_FEATURE_REPORT); | ||
| 833 | if (ret != sizeof(buf)) { | ||
| 834 | hid_err(hdev, "error reading lock byte: %d\n", ret); | ||
| 835 | return; | ||
| 836 | } | ||
| 837 | |||
| 838 | for (attr = cp2112_attr_group.attrs; *attr; ++attr) { | ||
| 839 | umode_t mode = (buf[1] & 1) ? S_IWUSR | S_IRUGO : S_IRUGO; | ||
| 840 | ret = sysfs_chmod_file(&hdev->dev.kobj, *attr, mode); | ||
| 841 | if (ret < 0) | ||
| 842 | hid_err(hdev, "error chmoding sysfs file %s\n", | ||
| 843 | (*attr)->name); | ||
| 844 | buf[1] >>= 1; | ||
| 845 | } | ||
| 846 | } | ||
| 847 | |||
| 848 | static int cp2112_probe(struct hid_device *hdev, const struct hid_device_id *id) | ||
| 849 | { | ||
| 850 | struct cp2112_device *dev; | ||
| 851 | u8 buf[3]; | ||
| 852 | struct cp2112_smbus_config_report config; | ||
| 853 | int ret; | ||
| 854 | |||
| 855 | ret = hid_parse(hdev); | ||
| 856 | if (ret) { | ||
| 857 | hid_err(hdev, "parse failed\n"); | ||
| 858 | return ret; | ||
| 859 | } | ||
| 860 | |||
| 861 | ret = hid_hw_start(hdev, HID_CONNECT_HIDRAW); | ||
| 862 | if (ret) { | ||
| 863 | hid_err(hdev, "hw start failed\n"); | ||
| 864 | return ret; | ||
| 865 | } | ||
| 866 | |||
| 867 | ret = hid_hw_open(hdev); | ||
| 868 | if (ret) { | ||
| 869 | hid_err(hdev, "hw open failed\n"); | ||
| 870 | goto err_hid_stop; | ||
| 871 | } | ||
| 872 | |||
| 873 | ret = hid_hw_power(hdev, PM_HINT_FULLON); | ||
| 874 | if (ret < 0) { | ||
| 875 | hid_err(hdev, "power management error: %d\n", ret); | ||
| 876 | goto err_hid_close; | ||
| 877 | } | ||
| 878 | |||
| 879 | ret = cp2112_hid_get(hdev, CP2112_GET_VERSION_INFO, buf, sizeof(buf), | ||
| 880 | HID_FEATURE_REPORT); | ||
| 881 | if (ret != sizeof(buf)) { | ||
| 882 | hid_err(hdev, "error requesting version\n"); | ||
| 883 | if (ret >= 0) | ||
| 884 | ret = -EIO; | ||
| 885 | goto err_power_normal; | ||
| 886 | } | ||
| 887 | |||
| 888 | hid_info(hdev, "Part Number: 0x%02X Device Version: 0x%02X\n", | ||
| 889 | buf[1], buf[2]); | ||
| 890 | |||
| 891 | ret = cp2112_hid_get(hdev, CP2112_SMBUS_CONFIG, (u8 *)&config, | ||
| 892 | sizeof(config), HID_FEATURE_REPORT); | ||
| 893 | if (ret != sizeof(config)) { | ||
| 894 | hid_err(hdev, "error requesting SMBus config\n"); | ||
| 895 | if (ret >= 0) | ||
| 896 | ret = -EIO; | ||
| 897 | goto err_power_normal; | ||
| 898 | } | ||
| 899 | |||
| 900 | config.retry_time = cpu_to_be16(1); | ||
| 901 | |||
| 902 | ret = cp2112_hid_output(hdev, (u8 *)&config, sizeof(config), | ||
| 903 | HID_FEATURE_REPORT); | ||
| 904 | if (ret != sizeof(config)) { | ||
| 905 | hid_err(hdev, "error setting SMBus config\n"); | ||
| 906 | if (ret >= 0) | ||
| 907 | ret = -EIO; | ||
| 908 | goto err_power_normal; | ||
| 909 | } | ||
| 910 | |||
| 911 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); | ||
| 912 | if (!dev) { | ||
| 913 | ret = -ENOMEM; | ||
| 914 | goto err_power_normal; | ||
| 915 | } | ||
| 916 | |||
| 917 | hid_set_drvdata(hdev, (void *)dev); | ||
| 918 | dev->hdev = hdev; | ||
| 919 | dev->adap.owner = THIS_MODULE; | ||
| 920 | dev->adap.class = I2C_CLASS_HWMON; | ||
| 921 | dev->adap.algo = &smbus_algorithm; | ||
| 922 | dev->adap.algo_data = dev; | ||
| 923 | dev->adap.dev.parent = &hdev->dev; | ||
| 924 | snprintf(dev->adap.name, sizeof(dev->adap.name), | ||
| 925 | "CP2112 SMBus Bridge on hiddev%d", hdev->minor); | ||
| 926 | init_waitqueue_head(&dev->wait); | ||
| 927 | |||
| 928 | hid_device_io_start(hdev); | ||
| 929 | ret = i2c_add_adapter(&dev->adap); | ||
| 930 | hid_device_io_stop(hdev); | ||
| 931 | |||
| 932 | if (ret) { | ||
| 933 | hid_err(hdev, "error registering i2c adapter\n"); | ||
| 934 | goto err_free_dev; | ||
| 935 | } | ||
| 936 | |||
| 937 | hid_dbg(hdev, "adapter registered\n"); | ||
| 938 | |||
| 939 | dev->gc.label = "cp2112_gpio"; | ||
| 940 | dev->gc.direction_input = cp2112_gpio_direction_input; | ||
| 941 | dev->gc.direction_output = cp2112_gpio_direction_output; | ||
| 942 | dev->gc.set = cp2112_gpio_set; | ||
| 943 | dev->gc.get = cp2112_gpio_get; | ||
| 944 | dev->gc.base = -1; | ||
| 945 | dev->gc.ngpio = 8; | ||
| 946 | dev->gc.can_sleep = 1; | ||
| 947 | dev->gc.dev = &hdev->dev; | ||
| 948 | |||
| 949 | ret = gpiochip_add(&dev->gc); | ||
| 950 | if (ret < 0) { | ||
| 951 | hid_err(hdev, "error registering gpio chip\n"); | ||
| 952 | goto err_free_i2c; | ||
| 953 | } | ||
| 954 | |||
| 955 | ret = sysfs_create_group(&hdev->dev.kobj, &cp2112_attr_group); | ||
| 956 | if (ret < 0) { | ||
| 957 | hid_err(hdev, "error creating sysfs attrs\n"); | ||
| 958 | goto err_gpiochip_remove; | ||
| 959 | } | ||
| 960 | |||
| 961 | chmod_sysfs_attrs(hdev); | ||
| 962 | hid_hw_power(hdev, PM_HINT_NORMAL); | ||
| 963 | |||
| 964 | return ret; | ||
| 965 | |||
| 966 | err_gpiochip_remove: | ||
| 967 | if (gpiochip_remove(&dev->gc) < 0) | ||
| 968 | hid_err(hdev, "error removing gpio chip\n"); | ||
| 969 | err_free_i2c: | ||
| 970 | i2c_del_adapter(&dev->adap); | ||
| 971 | err_free_dev: | ||
| 972 | kfree(dev); | ||
| 973 | err_power_normal: | ||
| 974 | hid_hw_power(hdev, PM_HINT_NORMAL); | ||
| 975 | err_hid_close: | ||
| 976 | hid_hw_close(hdev); | ||
| 977 | err_hid_stop: | ||
| 978 | hid_hw_stop(hdev); | ||
| 979 | return ret; | ||
| 980 | } | ||
| 981 | |||
| 982 | static void cp2112_remove(struct hid_device *hdev) | ||
| 983 | { | ||
| 984 | struct cp2112_device *dev = hid_get_drvdata(hdev); | ||
| 985 | |||
| 986 | sysfs_remove_group(&hdev->dev.kobj, &cp2112_attr_group); | ||
| 987 | if (gpiochip_remove(&dev->gc)) | ||
| 988 | hid_err(hdev, "unable to remove gpio chip\n"); | ||
| 989 | i2c_del_adapter(&dev->adap); | ||
| 990 | /* i2c_del_adapter has finished removing all i2c devices from our | ||
| 991 | * adapter. Well behaved devices should no longer call our cp2112_xfer | ||
| 992 | * and should have waited for any pending calls to finish. It has also | ||
| 993 | * waited for device_unregister(&adap->dev) to complete. Therefore we | ||
| 994 | * can safely free our struct cp2112_device. | ||
| 995 | */ | ||
| 996 | hid_hw_close(hdev); | ||
| 997 | hid_hw_stop(hdev); | ||
| 998 | kfree(dev); | ||
| 999 | } | ||
| 1000 | |||
| 1001 | static int cp2112_raw_event(struct hid_device *hdev, struct hid_report *report, | ||
| 1002 | u8 *data, int size) | ||
| 1003 | { | ||
| 1004 | struct cp2112_device *dev = hid_get_drvdata(hdev); | ||
| 1005 | struct cp2112_xfer_status_report *xfer = (void *)data; | ||
| 1006 | |||
| 1007 | switch (data[0]) { | ||
| 1008 | case CP2112_TRANSFER_STATUS_RESPONSE: | ||
| 1009 | hid_dbg(hdev, "xfer status: %02x %02x %04x %04x\n", | ||
| 1010 | xfer->status0, xfer->status1, | ||
| 1011 | be16_to_cpu(xfer->retries), be16_to_cpu(xfer->length)); | ||
| 1012 | |||
| 1013 | switch (xfer->status0) { | ||
| 1014 | case STATUS0_IDLE: | ||
| 1015 | dev->xfer_status = -EAGAIN; | ||
| 1016 | break; | ||
| 1017 | case STATUS0_BUSY: | ||
| 1018 | dev->xfer_status = -EBUSY; | ||
| 1019 | break; | ||
| 1020 | case STATUS0_COMPLETE: | ||
| 1021 | dev->xfer_status = be16_to_cpu(xfer->length); | ||
| 1022 | break; | ||
| 1023 | case STATUS0_ERROR: | ||
| 1024 | switch (xfer->status1) { | ||
| 1025 | case STATUS1_TIMEOUT_NACK: | ||
| 1026 | case STATUS1_TIMEOUT_BUS: | ||
| 1027 | dev->xfer_status = -ETIMEDOUT; | ||
| 1028 | break; | ||
| 1029 | default: | ||
| 1030 | dev->xfer_status = -EIO; | ||
| 1031 | break; | ||
| 1032 | } | ||
| 1033 | break; | ||
| 1034 | default: | ||
| 1035 | dev->xfer_status = -EINVAL; | ||
| 1036 | break; | ||
| 1037 | } | ||
| 1038 | |||
| 1039 | atomic_set(&dev->xfer_avail, 1); | ||
| 1040 | break; | ||
| 1041 | case CP2112_DATA_READ_RESPONSE: | ||
| 1042 | hid_dbg(hdev, "read response: %02x %02x\n", data[1], data[2]); | ||
| 1043 | |||
| 1044 | dev->read_length = data[2]; | ||
| 1045 | if (dev->read_length > sizeof(dev->read_data)) | ||
| 1046 | dev->read_length = sizeof(dev->read_data); | ||
| 1047 | |||
| 1048 | memcpy(dev->read_data, &data[3], dev->read_length); | ||
| 1049 | atomic_set(&dev->read_avail, 1); | ||
| 1050 | break; | ||
| 1051 | default: | ||
| 1052 | hid_err(hdev, "unknown report\n"); | ||
| 1053 | |||
| 1054 | return 0; | ||
| 1055 | } | ||
| 1056 | |||
| 1057 | wake_up_interruptible(&dev->wait); | ||
| 1058 | return 1; | ||
| 1059 | } | ||
| 1060 | |||
| 1061 | static struct hid_driver cp2112_driver = { | ||
| 1062 | .name = "cp2112", | ||
| 1063 | .id_table = cp2112_devices, | ||
| 1064 | .probe = cp2112_probe, | ||
| 1065 | .remove = cp2112_remove, | ||
| 1066 | .raw_event = cp2112_raw_event, | ||
| 1067 | }; | ||
| 1068 | |||
| 1069 | module_hid_driver(cp2112_driver); | ||
| 1070 | MODULE_DESCRIPTION("Silicon Labs HID USB to SMBus master bridge"); | ||
| 1071 | MODULE_AUTHOR("David Barksdale <dbarksdale@uplogix.com>"); | ||
| 1072 | MODULE_LICENSE("GPL"); | ||
| 1073 | |||
diff --git a/drivers/hid/hid-hyperv.c b/drivers/hid/hid-hyperv.c index 8fae6d1414cc..0658cc4578fe 100644 --- a/drivers/hid/hid-hyperv.c +++ b/drivers/hid/hid-hyperv.c | |||
| @@ -455,12 +455,22 @@ static void mousevsc_hid_stop(struct hid_device *hid) | |||
| 455 | { | 455 | { |
| 456 | } | 456 | } |
| 457 | 457 | ||
| 458 | static int mousevsc_hid_raw_request(struct hid_device *hid, | ||
| 459 | unsigned char report_num, | ||
| 460 | __u8 *buf, size_t len, | ||
| 461 | unsigned char rtype, | ||
| 462 | int reqtype) | ||
| 463 | { | ||
| 464 | return 0; | ||
| 465 | } | ||
| 466 | |||
| 458 | static struct hid_ll_driver mousevsc_ll_driver = { | 467 | static struct hid_ll_driver mousevsc_ll_driver = { |
| 459 | .parse = mousevsc_hid_parse, | 468 | .parse = mousevsc_hid_parse, |
| 460 | .open = mousevsc_hid_open, | 469 | .open = mousevsc_hid_open, |
| 461 | .close = mousevsc_hid_close, | 470 | .close = mousevsc_hid_close, |
| 462 | .start = mousevsc_hid_start, | 471 | .start = mousevsc_hid_start, |
| 463 | .stop = mousevsc_hid_stop, | 472 | .stop = mousevsc_hid_stop, |
| 473 | .raw_request = mousevsc_hid_raw_request, | ||
| 464 | }; | 474 | }; |
| 465 | 475 | ||
| 466 | static struct hid_driver mousevsc_hid_driver; | 476 | static struct hid_driver mousevsc_hid_driver; |
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h index 92b40c09d917..239f29c1c85c 100644 --- a/drivers/hid/hid-ids.h +++ b/drivers/hid/hid-ids.h | |||
| @@ -240,6 +240,7 @@ | |||
| 240 | 240 | ||
| 241 | #define USB_VENDOR_ID_CYGNAL 0x10c4 | 241 | #define USB_VENDOR_ID_CYGNAL 0x10c4 |
| 242 | #define USB_DEVICE_ID_CYGNAL_RADIO_SI470X 0x818a | 242 | #define USB_DEVICE_ID_CYGNAL_RADIO_SI470X 0x818a |
| 243 | #define USB_DEVICE_ID_CYGNAL_CP2112 0xea90 | ||
| 243 | 244 | ||
| 244 | #define USB_VENDOR_ID_CYPRESS 0x04b4 | 245 | #define USB_VENDOR_ID_CYPRESS 0x04b4 |
| 245 | #define USB_DEVICE_ID_CYPRESS_MOUSE 0x0001 | 246 | #define USB_DEVICE_ID_CYPRESS_MOUSE 0x0001 |
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c index 15959fbae268..f5aef792f13b 100644 --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c | |||
| @@ -1150,7 +1150,7 @@ static void hidinput_led_worker(struct work_struct *work) | |||
| 1150 | led_work); | 1150 | led_work); |
| 1151 | struct hid_field *field; | 1151 | struct hid_field *field; |
| 1152 | struct hid_report *report; | 1152 | struct hid_report *report; |
| 1153 | int len; | 1153 | int len, ret; |
| 1154 | __u8 *buf; | 1154 | __u8 *buf; |
| 1155 | 1155 | ||
| 1156 | field = hidinput_get_led_field(hid); | 1156 | field = hidinput_get_led_field(hid); |
| @@ -1184,7 +1184,10 @@ static void hidinput_led_worker(struct work_struct *work) | |||
| 1184 | 1184 | ||
| 1185 | hid_output_report(report, buf); | 1185 | hid_output_report(report, buf); |
| 1186 | /* synchronous output report */ | 1186 | /* synchronous output report */ |
| 1187 | hid_output_raw_report(hid, buf, len, HID_OUTPUT_REPORT); | 1187 | ret = hid_hw_output_report(hid, buf, len); |
| 1188 | if (ret == -ENOSYS) | ||
| 1189 | hid_hw_raw_request(hid, report->id, buf, len, HID_OUTPUT_REPORT, | ||
| 1190 | HID_REQ_SET_REPORT); | ||
| 1188 | kfree(buf); | 1191 | kfree(buf); |
| 1189 | } | 1192 | } |
| 1190 | 1193 | ||
| @@ -1263,8 +1266,7 @@ static struct hid_input *hidinput_allocate(struct hid_device *hid) | |||
| 1263 | } | 1266 | } |
| 1264 | 1267 | ||
| 1265 | input_set_drvdata(input_dev, hid); | 1268 | input_set_drvdata(input_dev, hid); |
| 1266 | if (hid->ll_driver->request || hid->hid_output_raw_report) | 1269 | input_dev->event = hidinput_input_event; |
| 1267 | input_dev->event = hidinput_input_event; | ||
| 1268 | input_dev->open = hidinput_open; | 1270 | input_dev->open = hidinput_open; |
| 1269 | input_dev->close = hidinput_close; | 1271 | input_dev->close = hidinput_close; |
| 1270 | input_dev->setkeycode = hidinput_setkeycode; | 1272 | input_dev->setkeycode = hidinput_setkeycode; |
diff --git a/drivers/hid/hid-lg.c b/drivers/hid/hid-lg.c index 76ed7e512dcf..a976f48263f6 100644 --- a/drivers/hid/hid-lg.c +++ b/drivers/hid/hid-lg.c | |||
| @@ -692,8 +692,8 @@ static int lg_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
| 692 | if (hdev->product == USB_DEVICE_ID_LOGITECH_WII_WHEEL) { | 692 | if (hdev->product == USB_DEVICE_ID_LOGITECH_WII_WHEEL) { |
| 693 | unsigned char buf[] = { 0x00, 0xAF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; | 693 | unsigned char buf[] = { 0x00, 0xAF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; |
| 694 | 694 | ||
| 695 | ret = hid_output_raw_report(hdev, buf, sizeof(buf), | 695 | ret = hid_hw_raw_request(hdev, buf[0], buf, sizeof(buf), |
| 696 | HID_FEATURE_REPORT); | 696 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); |
| 697 | 697 | ||
| 698 | if (ret >= 0) { | 698 | if (ret >= 0) { |
| 699 | /* insert a little delay of 10 jiffies ~ 40ms */ | 699 | /* insert a little delay of 10 jiffies ~ 40ms */ |
| @@ -705,8 +705,8 @@ static int lg_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
| 705 | buf[1] = 0xB2; | 705 | buf[1] = 0xB2; |
| 706 | get_random_bytes(&buf[2], 2); | 706 | get_random_bytes(&buf[2], 2); |
| 707 | 707 | ||
| 708 | ret = hid_output_raw_report(hdev, buf, sizeof(buf), | 708 | ret = hid_hw_raw_request(hdev, buf[0], buf, sizeof(buf), |
| 709 | HID_FEATURE_REPORT); | 709 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); |
| 710 | } | 710 | } |
| 711 | } | 711 | } |
| 712 | 712 | ||
diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c index 980ede54782d..486dbde2ba2d 100644 --- a/drivers/hid/hid-logitech-dj.c +++ b/drivers/hid/hid-logitech-dj.c | |||
| @@ -193,9 +193,6 @@ static const u8 hid_reportid_size_map[NUMBER_OF_HID_REPORTS] = { | |||
| 193 | 193 | ||
| 194 | static struct hid_ll_driver logi_dj_ll_driver; | 194 | static struct hid_ll_driver logi_dj_ll_driver; |
| 195 | 195 | ||
| 196 | static int logi_dj_output_hidraw_report(struct hid_device *hid, u8 * buf, | ||
| 197 | size_t count, | ||
| 198 | unsigned char report_type); | ||
| 199 | static int logi_dj_recv_query_paired_devices(struct dj_receiver_dev *djrcv_dev); | 196 | static int logi_dj_recv_query_paired_devices(struct dj_receiver_dev *djrcv_dev); |
| 200 | 197 | ||
| 201 | static void logi_dj_recv_destroy_djhid_device(struct dj_receiver_dev *djrcv_dev, | 198 | static void logi_dj_recv_destroy_djhid_device(struct dj_receiver_dev *djrcv_dev, |
| @@ -262,7 +259,6 @@ static void logi_dj_recv_add_djhid_device(struct dj_receiver_dev *djrcv_dev, | |||
| 262 | } | 259 | } |
| 263 | 260 | ||
| 264 | dj_hiddev->ll_driver = &logi_dj_ll_driver; | 261 | dj_hiddev->ll_driver = &logi_dj_ll_driver; |
| 265 | dj_hiddev->hid_output_raw_report = logi_dj_output_hidraw_report; | ||
| 266 | 262 | ||
| 267 | dj_hiddev->dev.parent = &djrcv_hdev->dev; | 263 | dj_hiddev->dev.parent = &djrcv_hdev->dev; |
| 268 | dj_hiddev->bus = BUS_USB; | 264 | dj_hiddev->bus = BUS_USB; |
| @@ -544,9 +540,10 @@ static void logi_dj_ll_close(struct hid_device *hid) | |||
| 544 | dbg_hid("%s:%s\n", __func__, hid->phys); | 540 | dbg_hid("%s:%s\n", __func__, hid->phys); |
| 545 | } | 541 | } |
| 546 | 542 | ||
| 547 | static int logi_dj_output_hidraw_report(struct hid_device *hid, u8 * buf, | 543 | static int logi_dj_ll_raw_request(struct hid_device *hid, |
| 548 | size_t count, | 544 | unsigned char reportnum, __u8 *buf, |
| 549 | unsigned char report_type) | 545 | size_t count, unsigned char report_type, |
| 546 | int reqtype) | ||
| 550 | { | 547 | { |
| 551 | struct dj_device *djdev = hid->driver_data; | 548 | struct dj_device *djdev = hid->driver_data; |
| 552 | struct dj_receiver_dev *djrcv_dev = djdev->dj_receiver_dev; | 549 | struct dj_receiver_dev *djrcv_dev = djdev->dj_receiver_dev; |
| @@ -567,15 +564,8 @@ static int logi_dj_output_hidraw_report(struct hid_device *hid, u8 * buf, | |||
| 567 | out_buf[1] = djdev->device_index; | 564 | out_buf[1] = djdev->device_index; |
| 568 | memcpy(out_buf + 2, buf, count); | 565 | memcpy(out_buf + 2, buf, count); |
| 569 | 566 | ||
| 570 | /* | ||
| 571 | * hid-generic calls us with hid_output_raw_report(), but the LEDs | ||
| 572 | * are set through a SET_REPORT command. It works for USB-HID devices | ||
| 573 | * because usbhid either calls a SET_REPORT or directly send the output | ||
| 574 | * report depending if the device presents an urbout. | ||
| 575 | * Let be simple, send a SET_REPORT request. | ||
| 576 | */ | ||
| 577 | ret = hid_hw_raw_request(djrcv_dev->hdev, out_buf[0], out_buf, | 567 | ret = hid_hw_raw_request(djrcv_dev->hdev, out_buf[0], out_buf, |
| 578 | DJREPORT_SHORT_LENGTH, report_type, HID_REQ_SET_REPORT); | 568 | DJREPORT_SHORT_LENGTH, report_type, reqtype); |
| 579 | 569 | ||
| 580 | kfree(out_buf); | 570 | kfree(out_buf); |
| 581 | return ret; | 571 | return ret; |
| @@ -662,6 +652,7 @@ static struct hid_ll_driver logi_dj_ll_driver = { | |||
| 662 | .stop = logi_dj_ll_stop, | 652 | .stop = logi_dj_ll_stop, |
| 663 | .open = logi_dj_ll_open, | 653 | .open = logi_dj_ll_open, |
| 664 | .close = logi_dj_ll_close, | 654 | .close = logi_dj_ll_close, |
| 655 | .raw_request = logi_dj_ll_raw_request, | ||
| 665 | }; | 656 | }; |
| 666 | 657 | ||
| 667 | 658 | ||
diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c index cb5db3afc690..ecc2cbf300cc 100644 --- a/drivers/hid/hid-magicmouse.c +++ b/drivers/hid/hid-magicmouse.c | |||
| @@ -538,8 +538,8 @@ static int magicmouse_probe(struct hid_device *hdev, | |||
| 538 | * but there seems to be no other way of switching the mode. | 538 | * but there seems to be no other way of switching the mode. |
| 539 | * Thus the super-ugly hacky success check below. | 539 | * Thus the super-ugly hacky success check below. |
| 540 | */ | 540 | */ |
| 541 | ret = hid_output_raw_report(hdev, feature, sizeof(feature), | 541 | ret = hid_hw_raw_request(hdev, feature[0], feature, sizeof(feature), |
| 542 | HID_FEATURE_REPORT); | 542 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); |
| 543 | if (ret != -EIO && ret != sizeof(feature)) { | 543 | if (ret != -EIO && ret != sizeof(feature)) { |
| 544 | hid_err(hdev, "unable to request touch data (%d)\n", ret); | 544 | hid_err(hdev, "unable to request touch data (%d)\n", ret); |
| 545 | goto err_stop_hw; | 545 | goto err_stop_hw; |
diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c index c364be158ae6..908de2789219 100644 --- a/drivers/hid/hid-sony.c +++ b/drivers/hid/hid-sony.c | |||
| @@ -29,7 +29,6 @@ | |||
| 29 | #include <linux/hid.h> | 29 | #include <linux/hid.h> |
| 30 | #include <linux/module.h> | 30 | #include <linux/module.h> |
| 31 | #include <linux/slab.h> | 31 | #include <linux/slab.h> |
| 32 | #include <linux/usb.h> | ||
| 33 | #include <linux/leds.h> | 32 | #include <linux/leds.h> |
| 34 | #include <linux/power_supply.h> | 33 | #include <linux/power_supply.h> |
| 35 | #include <linux/spinlock.h> | 34 | #include <linux/spinlock.h> |
| @@ -1007,45 +1006,6 @@ static int sony_mapping(struct hid_device *hdev, struct hid_input *hi, | |||
| 1007 | } | 1006 | } |
| 1008 | 1007 | ||
| 1009 | /* | 1008 | /* |
| 1010 | * The Sony Sixaxis does not handle HID Output Reports on the Interrupt EP | ||
| 1011 | * like it should according to usbhid/hid-core.c::usbhid_output_raw_report() | ||
| 1012 | * so we need to override that forcing HID Output Reports on the Control EP. | ||
| 1013 | * | ||
| 1014 | * There is also another issue about HID Output Reports via USB, the Sixaxis | ||
| 1015 | * does not want the report_id as part of the data packet, so we have to | ||
| 1016 | * discard buf[0] when sending the actual control message, even for numbered | ||
| 1017 | * reports, humpf! | ||
| 1018 | */ | ||
| 1019 | static int sixaxis_usb_output_raw_report(struct hid_device *hid, __u8 *buf, | ||
| 1020 | size_t count, unsigned char report_type) | ||
| 1021 | { | ||
| 1022 | struct usb_interface *intf = to_usb_interface(hid->dev.parent); | ||
| 1023 | struct usb_device *dev = interface_to_usbdev(intf); | ||
| 1024 | struct usb_host_interface *interface = intf->cur_altsetting; | ||
| 1025 | int report_id = buf[0]; | ||
| 1026 | int ret; | ||
| 1027 | |||
| 1028 | if (report_type == HID_OUTPUT_REPORT) { | ||
| 1029 | /* Don't send the Report ID */ | ||
| 1030 | buf++; | ||
| 1031 | count--; | ||
| 1032 | } | ||
| 1033 | |||
| 1034 | ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), | ||
| 1035 | HID_REQ_SET_REPORT, | ||
| 1036 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | ||
| 1037 | ((report_type + 1) << 8) | report_id, | ||
| 1038 | interface->desc.bInterfaceNumber, buf, count, | ||
| 1039 | USB_CTRL_SET_TIMEOUT); | ||
| 1040 | |||
| 1041 | /* Count also the Report ID, in case of an Output report. */ | ||
| 1042 | if (ret > 0 && report_type == HID_OUTPUT_REPORT) | ||
| 1043 | ret++; | ||
| 1044 | |||
| 1045 | return ret; | ||
| 1046 | } | ||
| 1047 | |||
| 1048 | /* | ||
| 1049 | * Sending HID_REQ_GET_REPORT changes the operation mode of the ps3 controller | 1009 | * Sending HID_REQ_GET_REPORT changes the operation mode of the ps3 controller |
| 1050 | * to "operational". Without this, the ps3 controller will not report any | 1010 | * to "operational". Without this, the ps3 controller will not report any |
| 1051 | * events. | 1011 | * events. |
| @@ -1072,8 +1032,8 @@ static int sixaxis_set_operational_usb(struct hid_device *hdev) | |||
| 1072 | static int sixaxis_set_operational_bt(struct hid_device *hdev) | 1032 | static int sixaxis_set_operational_bt(struct hid_device *hdev) |
| 1073 | { | 1033 | { |
| 1074 | unsigned char buf[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 }; | 1034 | unsigned char buf[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 }; |
| 1075 | return hid_output_raw_report(hdev, buf, sizeof(buf), | 1035 | return hid_hw_raw_request(hdev, buf[0], buf, sizeof(buf), |
| 1076 | HID_FEATURE_REPORT); | 1036 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); |
| 1077 | } | 1037 | } |
| 1078 | 1038 | ||
| 1079 | /* | 1039 | /* |
| @@ -1305,11 +1265,8 @@ static void sixaxis_state_worker(struct work_struct *work) | |||
| 1305 | buf[10] |= sc->led_state[2] << 3; | 1265 | buf[10] |= sc->led_state[2] << 3; |
| 1306 | buf[10] |= sc->led_state[3] << 4; | 1266 | buf[10] |= sc->led_state[3] << 4; |
| 1307 | 1267 | ||
| 1308 | if (sc->quirks & SIXAXIS_CONTROLLER_USB) | 1268 | hid_hw_raw_request(sc->hdev, 0x01, buf, sizeof(buf), HID_OUTPUT_REPORT, |
| 1309 | hid_output_raw_report(sc->hdev, buf, sizeof(buf), HID_OUTPUT_REPORT); | 1269 | HID_REQ_SET_REPORT); |
| 1310 | else | ||
| 1311 | hid_hw_raw_request(sc->hdev, 0x01, buf, sizeof(buf), | ||
| 1312 | HID_OUTPUT_REPORT, HID_REQ_SET_REPORT); | ||
| 1313 | } | 1270 | } |
| 1314 | 1271 | ||
| 1315 | static void dualshock4_state_worker(struct work_struct *work) | 1272 | static void dualshock4_state_worker(struct work_struct *work) |
| @@ -1659,7 +1616,18 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
| 1659 | } | 1616 | } |
| 1660 | 1617 | ||
| 1661 | if (sc->quirks & SIXAXIS_CONTROLLER_USB) { | 1618 | if (sc->quirks & SIXAXIS_CONTROLLER_USB) { |
| 1662 | hdev->hid_output_raw_report = sixaxis_usb_output_raw_report; | 1619 | /* |
| 1620 | * The Sony Sixaxis does not handle HID Output Reports on the | ||
| 1621 | * Interrupt EP like it could, so we need to force HID Output | ||
| 1622 | * Reports to use HID_REQ_SET_REPORT on the Control EP. | ||
| 1623 | * | ||
| 1624 | * There is also another issue about HID Output Reports via USB, | ||
| 1625 | * the Sixaxis does not want the report_id as part of the data | ||
| 1626 | * packet, so we have to discard buf[0] when sending the actual | ||
| 1627 | * control message, even for numbered reports, humpf! | ||
| 1628 | */ | ||
| 1629 | hdev->quirks |= HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP; | ||
| 1630 | hdev->quirks |= HID_QUIRK_SKIP_OUTPUT_REPORT_ID; | ||
| 1663 | ret = sixaxis_set_operational_usb(hdev); | 1631 | ret = sixaxis_set_operational_usb(hdev); |
| 1664 | sc->worker_initialized = 1; | 1632 | sc->worker_initialized = 1; |
| 1665 | INIT_WORK(&sc->state_worker, sixaxis_state_worker); | 1633 | INIT_WORK(&sc->state_worker, sixaxis_state_worker); |
diff --git a/drivers/hid/hid-thingm.c b/drivers/hid/hid-thingm.c index 7dd3197f3b3e..a97c78845f7b 100644 --- a/drivers/hid/hid-thingm.c +++ b/drivers/hid/hid-thingm.c | |||
| @@ -48,8 +48,8 @@ static int blink1_send_command(struct blink1_data *data, | |||
| 48 | buf[0], buf[1], buf[2], buf[3], buf[4], | 48 | buf[0], buf[1], buf[2], buf[3], buf[4], |
| 49 | buf[5], buf[6], buf[7], buf[8]); | 49 | buf[5], buf[6], buf[7], buf[8]); |
| 50 | 50 | ||
| 51 | ret = hid_output_raw_report(data->hdev, buf, BLINK1_CMD_SIZE, | 51 | ret = hid_hw_raw_request(data->hdev, buf[0], buf, BLINK1_CMD_SIZE, |
| 52 | HID_FEATURE_REPORT); | 52 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); |
| 53 | 53 | ||
| 54 | return ret < 0 ? ret : 0; | 54 | return ret < 0 ? ret : 0; |
| 55 | } | 55 | } |
diff --git a/drivers/hid/hid-wacom.c b/drivers/hid/hid-wacom.c index c720db912edb..902013ec041b 100644 --- a/drivers/hid/hid-wacom.c +++ b/drivers/hid/hid-wacom.c | |||
| @@ -128,7 +128,8 @@ static void wacom_set_image(struct hid_device *hdev, const char *image, | |||
| 128 | 128 | ||
| 129 | rep_data[0] = WAC_CMD_ICON_START_STOP; | 129 | rep_data[0] = WAC_CMD_ICON_START_STOP; |
| 130 | rep_data[1] = 0; | 130 | rep_data[1] = 0; |
| 131 | ret = hid_output_raw_report(hdev, rep_data, 2, HID_FEATURE_REPORT); | 131 | ret = hid_hw_raw_request(hdev, rep_data[0], rep_data, 2, |
| 132 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); | ||
| 132 | if (ret < 0) | 133 | if (ret < 0) |
| 133 | goto err; | 134 | goto err; |
| 134 | 135 | ||
| @@ -142,14 +143,15 @@ static void wacom_set_image(struct hid_device *hdev, const char *image, | |||
| 142 | rep_data[j + 3] = p[(i << 6) + j]; | 143 | rep_data[j + 3] = p[(i << 6) + j]; |
| 143 | 144 | ||
| 144 | rep_data[2] = i; | 145 | rep_data[2] = i; |
| 145 | ret = hid_output_raw_report(hdev, rep_data, 67, | 146 | ret = hid_hw_raw_request(hdev, rep_data[0], rep_data, 67, |
| 146 | HID_FEATURE_REPORT); | 147 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); |
| 147 | } | 148 | } |
| 148 | 149 | ||
| 149 | rep_data[0] = WAC_CMD_ICON_START_STOP; | 150 | rep_data[0] = WAC_CMD_ICON_START_STOP; |
| 150 | rep_data[1] = 0; | 151 | rep_data[1] = 0; |
| 151 | 152 | ||
| 152 | ret = hid_output_raw_report(hdev, rep_data, 2, HID_FEATURE_REPORT); | 153 | ret = hid_hw_raw_request(hdev, rep_data[0], rep_data, 2, |
| 154 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); | ||
| 153 | 155 | ||
| 154 | err: | 156 | err: |
| 155 | return; | 157 | return; |
| @@ -181,7 +183,8 @@ static void wacom_leds_set_brightness(struct led_classdev *led_dev, | |||
| 181 | buf[3] = value; | 183 | buf[3] = value; |
| 182 | /* use fixed brightness for OLEDs */ | 184 | /* use fixed brightness for OLEDs */ |
| 183 | buf[4] = 0x08; | 185 | buf[4] = 0x08; |
| 184 | hid_output_raw_report(hdev, buf, 9, HID_FEATURE_REPORT); | 186 | hid_hw_raw_request(hdev, buf[0], buf, 9, HID_FEATURE_REPORT, |
| 187 | HID_REQ_SET_REPORT); | ||
| 185 | kfree(buf); | 188 | kfree(buf); |
| 186 | } | 189 | } |
| 187 | 190 | ||
| @@ -337,8 +340,8 @@ static void wacom_set_features(struct hid_device *hdev, u8 speed) | |||
| 337 | rep_data[0] = 0x03 ; rep_data[1] = 0x00; | 340 | rep_data[0] = 0x03 ; rep_data[1] = 0x00; |
| 338 | limit = 3; | 341 | limit = 3; |
| 339 | do { | 342 | do { |
| 340 | ret = hid_output_raw_report(hdev, rep_data, 2, | 343 | ret = hid_hw_raw_request(hdev, rep_data[0], rep_data, 2, |
| 341 | HID_FEATURE_REPORT); | 344 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); |
| 342 | } while (ret < 0 && limit-- > 0); | 345 | } while (ret < 0 && limit-- > 0); |
| 343 | 346 | ||
| 344 | if (ret >= 0) { | 347 | if (ret >= 0) { |
| @@ -350,8 +353,9 @@ static void wacom_set_features(struct hid_device *hdev, u8 speed) | |||
| 350 | rep_data[1] = 0x00; | 353 | rep_data[1] = 0x00; |
| 351 | limit = 3; | 354 | limit = 3; |
| 352 | do { | 355 | do { |
| 353 | ret = hid_output_raw_report(hdev, | 356 | ret = hid_hw_raw_request(hdev, rep_data[0], |
| 354 | rep_data, 2, HID_FEATURE_REPORT); | 357 | rep_data, 2, HID_FEATURE_REPORT, |
| 358 | HID_REQ_SET_REPORT); | ||
| 355 | } while (ret < 0 && limit-- > 0); | 359 | } while (ret < 0 && limit-- > 0); |
| 356 | 360 | ||
| 357 | if (ret >= 0) { | 361 | if (ret >= 0) { |
| @@ -376,8 +380,8 @@ static void wacom_set_features(struct hid_device *hdev, u8 speed) | |||
| 376 | rep_data[0] = 0x03; | 380 | rep_data[0] = 0x03; |
| 377 | rep_data[1] = wdata->features; | 381 | rep_data[1] = wdata->features; |
| 378 | 382 | ||
| 379 | ret = hid_output_raw_report(hdev, rep_data, 2, | 383 | ret = hid_hw_raw_request(hdev, rep_data[0], rep_data, 2, |
| 380 | HID_FEATURE_REPORT); | 384 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); |
| 381 | if (ret >= 0) | 385 | if (ret >= 0) |
| 382 | wdata->high_speed = speed; | 386 | wdata->high_speed = speed; |
| 383 | break; | 387 | break; |
diff --git a/drivers/hid/hid-wiimote-core.c b/drivers/hid/hid-wiimote-core.c index d7dc6c5bc244..d00391418d1a 100644 --- a/drivers/hid/hid-wiimote-core.c +++ b/drivers/hid/hid-wiimote-core.c | |||
| @@ -28,14 +28,14 @@ static int wiimote_hid_send(struct hid_device *hdev, __u8 *buffer, | |||
| 28 | __u8 *buf; | 28 | __u8 *buf; |
| 29 | int ret; | 29 | int ret; |
| 30 | 30 | ||
| 31 | if (!hdev->hid_output_raw_report) | 31 | if (!hdev->ll_driver->output_report) |
| 32 | return -ENODEV; | 32 | return -ENODEV; |
| 33 | 33 | ||
| 34 | buf = kmemdup(buffer, count, GFP_KERNEL); | 34 | buf = kmemdup(buffer, count, GFP_KERNEL); |
| 35 | if (!buf) | 35 | if (!buf) |
| 36 | return -ENOMEM; | 36 | return -ENOMEM; |
| 37 | 37 | ||
| 38 | ret = hid_output_raw_report(hdev, buf, count, HID_OUTPUT_REPORT); | 38 | ret = hid_hw_output_report(hdev, buf, count); |
| 39 | 39 | ||
| 40 | kfree(buf); | 40 | kfree(buf); |
| 41 | return ret; | 41 | return ret; |
diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c index f8708c93f85c..ffa648ce002e 100644 --- a/drivers/hid/hidraw.c +++ b/drivers/hid/hidraw.c | |||
| @@ -123,10 +123,6 @@ static ssize_t hidraw_send_report(struct file *file, const char __user *buffer, | |||
| 123 | 123 | ||
| 124 | dev = hidraw_table[minor]->hid; | 124 | dev = hidraw_table[minor]->hid; |
| 125 | 125 | ||
| 126 | if (!dev->hid_output_raw_report) { | ||
| 127 | ret = -ENODEV; | ||
| 128 | goto out; | ||
| 129 | } | ||
| 130 | 126 | ||
| 131 | if (count > HID_MAX_BUFFER_SIZE) { | 127 | if (count > HID_MAX_BUFFER_SIZE) { |
| 132 | hid_warn(dev, "pid %d passed too large report\n", | 128 | hid_warn(dev, "pid %d passed too large report\n", |
| @@ -153,7 +149,21 @@ static ssize_t hidraw_send_report(struct file *file, const char __user *buffer, | |||
| 153 | goto out_free; | 149 | goto out_free; |
| 154 | } | 150 | } |
| 155 | 151 | ||
| 156 | ret = hid_output_raw_report(dev, buf, count, report_type); | 152 | if ((report_type == HID_OUTPUT_REPORT) && |
| 153 | !(dev->quirks & HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP)) { | ||
| 154 | ret = hid_hw_output_report(dev, buf, count); | ||
| 155 | /* | ||
| 156 | * compatibility with old implementation of USB-HID and I2C-HID: | ||
| 157 | * if the device does not support receiving output reports, | ||
| 158 | * on an interrupt endpoint, fallback to SET_REPORT HID command. | ||
| 159 | */ | ||
| 160 | if (ret != -ENOSYS) | ||
| 161 | goto out_free; | ||
| 162 | } | ||
| 163 | |||
| 164 | ret = hid_hw_raw_request(dev, buf[0], buf, count, report_type, | ||
| 165 | HID_REQ_SET_REPORT); | ||
| 166 | |||
| 157 | out_free: | 167 | out_free: |
| 158 | kfree(buf); | 168 | kfree(buf); |
| 159 | out: | 169 | out: |
diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c index f4ea7343e823..2de2b8e22462 100644 --- a/drivers/hid/i2c-hid/i2c-hid.c +++ b/drivers/hid/i2c-hid/i2c-hid.c | |||
| @@ -256,18 +256,27 @@ static int i2c_hid_get_report(struct i2c_client *client, u8 reportType, | |||
| 256 | return 0; | 256 | return 0; |
| 257 | } | 257 | } |
| 258 | 258 | ||
| 259 | static int i2c_hid_set_report(struct i2c_client *client, u8 reportType, | 259 | /** |
| 260 | u8 reportID, unsigned char *buf, size_t data_len) | 260 | * i2c_hid_set_or_send_report: forward an incoming report to the device |
| 261 | * @client: the i2c_client of the device | ||
| 262 | * @reportType: 0x03 for HID_FEATURE_REPORT ; 0x02 for HID_OUTPUT_REPORT | ||
| 263 | * @reportID: the report ID | ||
| 264 | * @buf: the actual data to transfer, without the report ID | ||
| 265 | * @len: size of buf | ||
| 266 | * @use_data: true: use SET_REPORT HID command, false: send plain OUTPUT report | ||
| 267 | */ | ||
| 268 | static int i2c_hid_set_or_send_report(struct i2c_client *client, u8 reportType, | ||
| 269 | u8 reportID, unsigned char *buf, size_t data_len, bool use_data) | ||
| 261 | { | 270 | { |
| 262 | struct i2c_hid *ihid = i2c_get_clientdata(client); | 271 | struct i2c_hid *ihid = i2c_get_clientdata(client); |
| 263 | u8 *args = ihid->argsbuf; | 272 | u8 *args = ihid->argsbuf; |
| 264 | const struct i2c_hid_cmd * hidcmd = &hid_set_report_cmd; | 273 | const struct i2c_hid_cmd *hidcmd; |
| 265 | int ret; | 274 | int ret; |
| 266 | u16 dataRegister = le16_to_cpu(ihid->hdesc.wDataRegister); | 275 | u16 dataRegister = le16_to_cpu(ihid->hdesc.wDataRegister); |
| 267 | u16 outputRegister = le16_to_cpu(ihid->hdesc.wOutputRegister); | 276 | u16 outputRegister = le16_to_cpu(ihid->hdesc.wOutputRegister); |
| 268 | u16 maxOutputLength = le16_to_cpu(ihid->hdesc.wMaxOutputLength); | 277 | u16 maxOutputLength = le16_to_cpu(ihid->hdesc.wMaxOutputLength); |
| 269 | 278 | ||
| 270 | /* hidraw already checked that data_len < HID_MAX_BUFFER_SIZE */ | 279 | /* hid_hw_* already checked that data_len < HID_MAX_BUFFER_SIZE */ |
| 271 | u16 size = 2 /* size */ + | 280 | u16 size = 2 /* size */ + |
| 272 | (reportID ? 1 : 0) /* reportID */ + | 281 | (reportID ? 1 : 0) /* reportID */ + |
| 273 | data_len /* buf */; | 282 | data_len /* buf */; |
| @@ -278,6 +287,9 @@ static int i2c_hid_set_report(struct i2c_client *client, u8 reportType, | |||
| 278 | 287 | ||
| 279 | i2c_hid_dbg(ihid, "%s\n", __func__); | 288 | i2c_hid_dbg(ihid, "%s\n", __func__); |
| 280 | 289 | ||
| 290 | if (!use_data && maxOutputLength == 0) | ||
| 291 | return -ENOSYS; | ||
| 292 | |||
| 281 | if (reportID >= 0x0F) { | 293 | if (reportID >= 0x0F) { |
| 282 | args[index++] = reportID; | 294 | args[index++] = reportID; |
| 283 | reportID = 0x0F; | 295 | reportID = 0x0F; |
| @@ -287,9 +299,10 @@ static int i2c_hid_set_report(struct i2c_client *client, u8 reportType, | |||
| 287 | * use the data register for feature reports or if the device does not | 299 | * use the data register for feature reports or if the device does not |
| 288 | * support the output register | 300 | * support the output register |
| 289 | */ | 301 | */ |
| 290 | if (reportType == 0x03 || maxOutputLength == 0) { | 302 | if (use_data) { |
| 291 | args[index++] = dataRegister & 0xFF; | 303 | args[index++] = dataRegister & 0xFF; |
| 292 | args[index++] = dataRegister >> 8; | 304 | args[index++] = dataRegister >> 8; |
| 305 | hidcmd = &hid_set_report_cmd; | ||
| 293 | } else { | 306 | } else { |
| 294 | args[index++] = outputRegister & 0xFF; | 307 | args[index++] = outputRegister & 0xFF; |
| 295 | args[index++] = outputRegister >> 8; | 308 | args[index++] = outputRegister >> 8; |
| @@ -550,7 +563,7 @@ static int i2c_hid_get_raw_report(struct hid_device *hid, | |||
| 550 | } | 563 | } |
| 551 | 564 | ||
| 552 | static int i2c_hid_output_raw_report(struct hid_device *hid, __u8 *buf, | 565 | static int i2c_hid_output_raw_report(struct hid_device *hid, __u8 *buf, |
| 553 | size_t count, unsigned char report_type) | 566 | size_t count, unsigned char report_type, bool use_data) |
| 554 | { | 567 | { |
| 555 | struct i2c_client *client = hid->driver_data; | 568 | struct i2c_client *client = hid->driver_data; |
| 556 | int report_id = buf[0]; | 569 | int report_id = buf[0]; |
| @@ -564,9 +577,9 @@ static int i2c_hid_output_raw_report(struct hid_device *hid, __u8 *buf, | |||
| 564 | count--; | 577 | count--; |
| 565 | } | 578 | } |
| 566 | 579 | ||
| 567 | ret = i2c_hid_set_report(client, | 580 | ret = i2c_hid_set_or_send_report(client, |
| 568 | report_type == HID_FEATURE_REPORT ? 0x03 : 0x02, | 581 | report_type == HID_FEATURE_REPORT ? 0x03 : 0x02, |
| 569 | report_id, buf, count); | 582 | report_id, buf, count, use_data); |
| 570 | 583 | ||
| 571 | if (report_id && ret >= 0) | 584 | if (report_id && ret >= 0) |
| 572 | ret++; /* add report_id to the number of transfered bytes */ | 585 | ret++; /* add report_id to the number of transfered bytes */ |
| @@ -574,34 +587,27 @@ static int i2c_hid_output_raw_report(struct hid_device *hid, __u8 *buf, | |||
| 574 | return ret; | 587 | return ret; |
| 575 | } | 588 | } |
| 576 | 589 | ||
| 577 | static void i2c_hid_request(struct hid_device *hid, struct hid_report *rep, | 590 | static int i2c_hid_output_report(struct hid_device *hid, __u8 *buf, |
| 578 | int reqtype) | 591 | size_t count) |
| 579 | { | 592 | { |
| 580 | struct i2c_client *client = hid->driver_data; | 593 | return i2c_hid_output_raw_report(hid, buf, count, HID_OUTPUT_REPORT, |
| 581 | char *buf; | 594 | false); |
| 582 | int ret; | 595 | } |
| 583 | int len = i2c_hid_get_report_length(rep) - 2; | ||
| 584 | |||
| 585 | buf = kzalloc(len, GFP_KERNEL); | ||
| 586 | if (!buf) | ||
| 587 | return; | ||
| 588 | 596 | ||
| 597 | static int i2c_hid_raw_request(struct hid_device *hid, unsigned char reportnum, | ||
| 598 | __u8 *buf, size_t len, unsigned char rtype, | ||
| 599 | int reqtype) | ||
| 600 | { | ||
| 589 | switch (reqtype) { | 601 | switch (reqtype) { |
| 590 | case HID_REQ_GET_REPORT: | 602 | case HID_REQ_GET_REPORT: |
| 591 | ret = i2c_hid_get_raw_report(hid, rep->id, buf, len, rep->type); | 603 | return i2c_hid_get_raw_report(hid, reportnum, buf, len, rtype); |
| 592 | if (ret < 0) | ||
| 593 | dev_err(&client->dev, "%s: unable to get report: %d\n", | ||
| 594 | __func__, ret); | ||
| 595 | else | ||
| 596 | hid_input_report(hid, rep->type, buf, ret, 0); | ||
| 597 | break; | ||
| 598 | case HID_REQ_SET_REPORT: | 604 | case HID_REQ_SET_REPORT: |
| 599 | hid_output_report(rep, buf); | 605 | if (buf[0] != reportnum) |
| 600 | i2c_hid_output_raw_report(hid, buf, len, rep->type); | 606 | return -EINVAL; |
| 601 | break; | 607 | return i2c_hid_output_raw_report(hid, buf, len, rtype, true); |
| 608 | default: | ||
| 609 | return -EIO; | ||
| 602 | } | 610 | } |
| 603 | |||
| 604 | kfree(buf); | ||
| 605 | } | 611 | } |
| 606 | 612 | ||
| 607 | static int i2c_hid_parse(struct hid_device *hid) | 613 | static int i2c_hid_parse(struct hid_device *hid) |
| @@ -760,7 +766,8 @@ static struct hid_ll_driver i2c_hid_ll_driver = { | |||
| 760 | .open = i2c_hid_open, | 766 | .open = i2c_hid_open, |
| 761 | .close = i2c_hid_close, | 767 | .close = i2c_hid_close, |
| 762 | .power = i2c_hid_power, | 768 | .power = i2c_hid_power, |
| 763 | .request = i2c_hid_request, | 769 | .output_report = i2c_hid_output_report, |
| 770 | .raw_request = i2c_hid_raw_request, | ||
| 764 | }; | 771 | }; |
| 765 | 772 | ||
| 766 | static int i2c_hid_init_irq(struct i2c_client *client) | 773 | static int i2c_hid_init_irq(struct i2c_client *client) |
| @@ -1005,7 +1012,6 @@ static int i2c_hid_probe(struct i2c_client *client, | |||
| 1005 | 1012 | ||
| 1006 | hid->driver_data = client; | 1013 | hid->driver_data = client; |
| 1007 | hid->ll_driver = &i2c_hid_ll_driver; | 1014 | hid->ll_driver = &i2c_hid_ll_driver; |
| 1008 | hid->hid_output_raw_report = i2c_hid_output_raw_report; | ||
| 1009 | hid->dev.parent = &client->dev; | 1015 | hid->dev.parent = &client->dev; |
| 1010 | ACPI_COMPANION_SET(&hid->dev, ACPI_COMPANION(&client->dev)); | 1016 | ACPI_COMPANION_SET(&hid->dev, ACPI_COMPANION(&client->dev)); |
| 1011 | hid->bus = BUS_I2C; | 1017 | hid->bus = BUS_I2C; |
diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c index 12439e1eeae2..7ed79be2686a 100644 --- a/drivers/hid/uhid.c +++ b/drivers/hid/uhid.c | |||
| @@ -247,27 +247,22 @@ static int uhid_hid_output_raw(struct hid_device *hid, __u8 *buf, size_t count, | |||
| 247 | static int uhid_hid_output_report(struct hid_device *hid, __u8 *buf, | 247 | static int uhid_hid_output_report(struct hid_device *hid, __u8 *buf, |
| 248 | size_t count) | 248 | size_t count) |
| 249 | { | 249 | { |
| 250 | struct uhid_device *uhid = hid->driver_data; | 250 | return uhid_hid_output_raw(hid, buf, count, HID_OUTPUT_REPORT); |
| 251 | unsigned long flags; | 251 | } |
| 252 | struct uhid_event *ev; | ||
| 253 | |||
| 254 | if (count < 1 || count > UHID_DATA_MAX) | ||
| 255 | return -EINVAL; | ||
| 256 | |||
| 257 | ev = kzalloc(sizeof(*ev), GFP_KERNEL); | ||
| 258 | if (!ev) | ||
| 259 | return -ENOMEM; | ||
| 260 | |||
| 261 | ev->type = UHID_OUTPUT; | ||
| 262 | ev->u.output.size = count; | ||
| 263 | ev->u.output.rtype = UHID_OUTPUT_REPORT; | ||
| 264 | memcpy(ev->u.output.data, buf, count); | ||
| 265 | |||
| 266 | spin_lock_irqsave(&uhid->qlock, flags); | ||
| 267 | uhid_queue(uhid, ev); | ||
| 268 | spin_unlock_irqrestore(&uhid->qlock, flags); | ||
| 269 | 252 | ||
| 270 | return count; | 253 | static int uhid_raw_request(struct hid_device *hid, unsigned char reportnum, |
| 254 | __u8 *buf, size_t len, unsigned char rtype, | ||
| 255 | int reqtype) | ||
| 256 | { | ||
| 257 | switch (reqtype) { | ||
| 258 | case HID_REQ_GET_REPORT: | ||
| 259 | return uhid_hid_get_raw(hid, reportnum, buf, len, rtype); | ||
| 260 | case HID_REQ_SET_REPORT: | ||
| 261 | /* TODO: implement proper SET_REPORT functionality */ | ||
| 262 | return -ENOSYS; | ||
| 263 | default: | ||
| 264 | return -EIO; | ||
| 265 | } | ||
| 271 | } | 266 | } |
| 272 | 267 | ||
| 273 | static struct hid_ll_driver uhid_hid_driver = { | 268 | static struct hid_ll_driver uhid_hid_driver = { |
| @@ -277,6 +272,7 @@ static struct hid_ll_driver uhid_hid_driver = { | |||
| 277 | .close = uhid_hid_close, | 272 | .close = uhid_hid_close, |
| 278 | .parse = uhid_hid_parse, | 273 | .parse = uhid_hid_parse, |
| 279 | .output_report = uhid_hid_output_report, | 274 | .output_report = uhid_hid_output_report, |
| 275 | .raw_request = uhid_raw_request, | ||
| 280 | }; | 276 | }; |
| 281 | 277 | ||
| 282 | #ifdef CONFIG_COMPAT | 278 | #ifdef CONFIG_COMPAT |
| @@ -404,7 +400,6 @@ static int uhid_dev_create(struct uhid_device *uhid, | |||
| 404 | hid->uniq[63] = 0; | 400 | hid->uniq[63] = 0; |
| 405 | 401 | ||
| 406 | hid->ll_driver = &uhid_hid_driver; | 402 | hid->ll_driver = &uhid_hid_driver; |
| 407 | hid->hid_output_raw_report = uhid_hid_output_raw; | ||
| 408 | hid->bus = ev->u.create.bus; | 403 | hid->bus = ev->u.create.bus; |
| 409 | hid->vendor = ev->u.create.vendor; | 404 | hid->vendor = ev->u.create.vendor; |
| 410 | hid->product = ev->u.create.product; | 405 | hid->product = ev->u.create.product; |
diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c index b9a770f4d7ae..7b88f4cb9902 100644 --- a/drivers/hid/usbhid/hid-core.c +++ b/drivers/hid/usbhid/hid-core.c | |||
| @@ -894,7 +894,12 @@ static int usbhid_set_raw_report(struct hid_device *hid, unsigned int reportnum, | |||
| 894 | int ret, skipped_report_id = 0; | 894 | int ret, skipped_report_id = 0; |
| 895 | 895 | ||
| 896 | /* Byte 0 is the report number. Report data starts at byte 1.*/ | 896 | /* Byte 0 is the report number. Report data starts at byte 1.*/ |
| 897 | buf[0] = reportnum; | 897 | if ((rtype == HID_OUTPUT_REPORT) && |
| 898 | (hid->quirks & HID_QUIRK_SKIP_OUTPUT_REPORT_ID)) | ||
| 899 | buf[0] = 0; | ||
| 900 | else | ||
| 901 | buf[0] = reportnum; | ||
| 902 | |||
| 898 | if (buf[0] == 0x0) { | 903 | if (buf[0] == 0x0) { |
| 899 | /* Don't send the Report ID */ | 904 | /* Don't send the Report ID */ |
| 900 | buf++; | 905 | buf++; |
| @@ -922,7 +927,7 @@ static int usbhid_output_report(struct hid_device *hid, __u8 *buf, size_t count) | |||
| 922 | int actual_length, skipped_report_id = 0, ret; | 927 | int actual_length, skipped_report_id = 0, ret; |
| 923 | 928 | ||
| 924 | if (!usbhid->urbout) | 929 | if (!usbhid->urbout) |
| 925 | return -EIO; | 930 | return -ENOSYS; |
| 926 | 931 | ||
| 927 | if (buf[0] == 0x0) { | 932 | if (buf[0] == 0x0) { |
| 928 | /* Don't send the Report ID */ | 933 | /* Don't send the Report ID */ |
| @@ -945,17 +950,6 @@ static int usbhid_output_report(struct hid_device *hid, __u8 *buf, size_t count) | |||
| 945 | return ret; | 950 | return ret; |
| 946 | } | 951 | } |
| 947 | 952 | ||
| 948 | static int usbhid_output_raw_report(struct hid_device *hid, __u8 *buf, | ||
| 949 | size_t count, unsigned char report_type) | ||
| 950 | { | ||
| 951 | struct usbhid_device *usbhid = hid->driver_data; | ||
| 952 | |||
| 953 | if (usbhid->urbout && report_type != HID_FEATURE_REPORT) | ||
| 954 | return usbhid_output_report(hid, buf, count); | ||
| 955 | |||
| 956 | return usbhid_set_raw_report(hid, buf[0], buf, count, report_type); | ||
| 957 | } | ||
| 958 | |||
| 959 | static void usbhid_restart_queues(struct usbhid_device *usbhid) | 953 | static void usbhid_restart_queues(struct usbhid_device *usbhid) |
| 960 | { | 954 | { |
| 961 | if (usbhid->urbout && !test_bit(HID_OUT_RUNNING, &usbhid->iofl)) | 955 | if (usbhid->urbout && !test_bit(HID_OUT_RUNNING, &usbhid->iofl)) |
| @@ -1289,7 +1283,6 @@ static int usbhid_probe(struct usb_interface *intf, const struct usb_device_id * | |||
| 1289 | 1283 | ||
| 1290 | usb_set_intfdata(intf, hid); | 1284 | usb_set_intfdata(intf, hid); |
| 1291 | hid->ll_driver = &usb_hid_driver; | 1285 | hid->ll_driver = &usb_hid_driver; |
| 1292 | hid->hid_output_raw_report = usbhid_output_raw_report; | ||
| 1293 | hid->ff_init = hid_pidff_init; | 1286 | hid->ff_init = hid_pidff_init; |
| 1294 | #ifdef CONFIG_USB_HIDDEV | 1287 | #ifdef CONFIG_USB_HIDDEV |
| 1295 | hid->hiddev_connect = hiddev_connect; | 1288 | hid->hiddev_connect = hiddev_connect; |
diff --git a/include/linux/hid.h b/include/linux/hid.h index a837ede65ec6..01a90b8d53bb 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h | |||
| @@ -287,6 +287,8 @@ struct hid_item { | |||
| 287 | #define HID_QUIRK_NO_EMPTY_INPUT 0x00000100 | 287 | #define HID_QUIRK_NO_EMPTY_INPUT 0x00000100 |
| 288 | #define HID_QUIRK_NO_INIT_INPUT_REPORTS 0x00000200 | 288 | #define HID_QUIRK_NO_INIT_INPUT_REPORTS 0x00000200 |
| 289 | #define HID_QUIRK_SKIP_OUTPUT_REPORTS 0x00010000 | 289 | #define HID_QUIRK_SKIP_OUTPUT_REPORTS 0x00010000 |
| 290 | #define HID_QUIRK_SKIP_OUTPUT_REPORT_ID 0x00020000 | ||
| 291 | #define HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP 0x00040000 | ||
| 290 | #define HID_QUIRK_FULLSPEED_INTERVAL 0x10000000 | 292 | #define HID_QUIRK_FULLSPEED_INTERVAL 0x10000000 |
| 291 | #define HID_QUIRK_NO_INIT_REPORTS 0x20000000 | 293 | #define HID_QUIRK_NO_INIT_REPORTS 0x20000000 |
| 292 | #define HID_QUIRK_NO_IGNORE 0x40000000 | 294 | #define HID_QUIRK_NO_IGNORE 0x40000000 |
| @@ -508,9 +510,6 @@ struct hid_device { /* device report descriptor */ | |||
| 508 | struct hid_usage *, __s32); | 510 | struct hid_usage *, __s32); |
| 509 | void (*hiddev_report_event) (struct hid_device *, struct hid_report *); | 511 | void (*hiddev_report_event) (struct hid_device *, struct hid_report *); |
| 510 | 512 | ||
| 511 | /* handler for raw output data, used by hidraw */ | ||
| 512 | int (*hid_output_raw_report) (struct hid_device *, __u8 *, size_t, unsigned char); | ||
| 513 | |||
| 514 | /* debugging support via debugfs */ | 513 | /* debugging support via debugfs */ |
| 515 | unsigned short debug; | 514 | unsigned short debug; |
| 516 | struct dentry *debug_dir; | 515 | struct dentry *debug_dir; |
| @@ -753,6 +752,7 @@ struct hid_field *hidinput_get_led_field(struct hid_device *hid); | |||
| 753 | unsigned int hidinput_count_leds(struct hid_device *hid); | 752 | unsigned int hidinput_count_leds(struct hid_device *hid); |
| 754 | __s32 hidinput_calc_abs_res(const struct hid_field *field, __u16 code); | 753 | __s32 hidinput_calc_abs_res(const struct hid_field *field, __u16 code); |
| 755 | void hid_output_report(struct hid_report *report, __u8 *data); | 754 | void hid_output_report(struct hid_report *report, __u8 *data); |
| 755 | void __hid_request(struct hid_device *hid, struct hid_report *rep, int reqtype); | ||
| 756 | u8 *hid_alloc_report_buf(struct hid_report *report, gfp_t flags); | 756 | u8 *hid_alloc_report_buf(struct hid_report *report, gfp_t flags); |
| 757 | struct hid_device *hid_allocate_device(void); | 757 | struct hid_device *hid_allocate_device(void); |
| 758 | struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id); | 758 | struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id); |
| @@ -965,7 +965,9 @@ static inline void hid_hw_request(struct hid_device *hdev, | |||
| 965 | struct hid_report *report, int reqtype) | 965 | struct hid_report *report, int reqtype) |
| 966 | { | 966 | { |
| 967 | if (hdev->ll_driver->request) | 967 | if (hdev->ll_driver->request) |
| 968 | hdev->ll_driver->request(hdev, report, reqtype); | 968 | return hdev->ll_driver->request(hdev, report, reqtype); |
| 969 | |||
| 970 | __hid_request(hdev, report, reqtype); | ||
| 969 | } | 971 | } |
| 970 | 972 | ||
| 971 | /** | 973 | /** |
| @@ -986,11 +988,11 @@ static inline int hid_hw_raw_request(struct hid_device *hdev, | |||
| 986 | unsigned char reportnum, __u8 *buf, | 988 | unsigned char reportnum, __u8 *buf, |
| 987 | size_t len, unsigned char rtype, int reqtype) | 989 | size_t len, unsigned char rtype, int reqtype) |
| 988 | { | 990 | { |
| 989 | if (hdev->ll_driver->raw_request) | 991 | if (len < 1 || len > HID_MAX_BUFFER_SIZE || !buf) |
| 990 | return hdev->ll_driver->raw_request(hdev, reportnum, buf, len, | 992 | return -EINVAL; |
| 991 | rtype, reqtype); | ||
| 992 | 993 | ||
| 993 | return -ENOSYS; | 994 | return hdev->ll_driver->raw_request(hdev, reportnum, buf, len, |
| 995 | rtype, reqtype); | ||
| 994 | } | 996 | } |
| 995 | 997 | ||
| 996 | /** | 998 | /** |
| @@ -1005,6 +1007,9 @@ static inline int hid_hw_raw_request(struct hid_device *hdev, | |||
| 1005 | static inline int hid_hw_output_report(struct hid_device *hdev, __u8 *buf, | 1007 | static inline int hid_hw_output_report(struct hid_device *hdev, __u8 *buf, |
| 1006 | size_t len) | 1008 | size_t len) |
| 1007 | { | 1009 | { |
| 1010 | if (len < 1 || len > HID_MAX_BUFFER_SIZE || !buf) | ||
| 1011 | return -EINVAL; | ||
| 1012 | |||
| 1008 | if (hdev->ll_driver->output_report) | 1013 | if (hdev->ll_driver->output_report) |
| 1009 | return hdev->ll_driver->output_report(hdev, buf, len); | 1014 | return hdev->ll_driver->output_report(hdev, buf, len); |
| 1010 | 1015 | ||
| @@ -1012,22 +1017,6 @@ static inline int hid_hw_output_report(struct hid_device *hdev, __u8 *buf, | |||
| 1012 | } | 1017 | } |
| 1013 | 1018 | ||
| 1014 | /** | 1019 | /** |
| 1015 | * hid_output_raw_report - send an output or a feature report to the device | ||
| 1016 | * | ||
| 1017 | * @hdev: hid device | ||
| 1018 | * @buf: raw data to transfer | ||
| 1019 | * @len: length of buf | ||
| 1020 | * @report_type: HID_FEATURE_REPORT or HID_OUTPUT_REPORT | ||
| 1021 | * | ||
| 1022 | * @return: count of data transfered, negative if error | ||
| 1023 | */ | ||
| 1024 | static inline int hid_output_raw_report(struct hid_device *hdev, __u8 *buf, | ||
| 1025 | size_t len, unsigned char report_type) | ||
| 1026 | { | ||
| 1027 | return hdev->hid_output_raw_report(hdev, buf, len, report_type); | ||
| 1028 | } | ||
| 1029 | |||
| 1030 | /** | ||
| 1031 | * hid_hw_idle - send idle request to device | 1020 | * hid_hw_idle - send idle request to device |
| 1032 | * | 1021 | * |
| 1033 | * @hdev: hid device | 1022 | * @hdev: hid device |
diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c index 98e4840935e2..514ddb5aef96 100644 --- a/net/bluetooth/hidp/core.c +++ b/net/bluetooth/hidp/core.c | |||
| @@ -382,18 +382,6 @@ static int hidp_output_report(struct hid_device *hid, __u8 *data, size_t count) | |||
| 382 | data, count); | 382 | data, count); |
| 383 | } | 383 | } |
| 384 | 384 | ||
| 385 | static int hidp_output_raw_report(struct hid_device *hid, unsigned char *data, | ||
| 386 | size_t count, unsigned char report_type) | ||
| 387 | { | ||
| 388 | if (report_type == HID_OUTPUT_REPORT) { | ||
| 389 | return hidp_output_report(hid, data, count); | ||
| 390 | } else if (report_type != HID_FEATURE_REPORT) { | ||
| 391 | return -EINVAL; | ||
| 392 | } | ||
| 393 | |||
| 394 | return hidp_set_raw_report(hid, data[0], data, count, report_type); | ||
| 395 | } | ||
| 396 | |||
| 397 | static int hidp_raw_request(struct hid_device *hid, unsigned char reportnum, | 385 | static int hidp_raw_request(struct hid_device *hid, unsigned char reportnum, |
| 398 | __u8 *buf, size_t len, unsigned char rtype, | 386 | __u8 *buf, size_t len, unsigned char rtype, |
| 399 | int reqtype) | 387 | int reqtype) |
| @@ -776,8 +764,6 @@ static int hidp_setup_hid(struct hidp_session *session, | |||
| 776 | hid->dev.parent = &session->conn->hcon->dev; | 764 | hid->dev.parent = &session->conn->hcon->dev; |
| 777 | hid->ll_driver = &hidp_hid_driver; | 765 | hid->ll_driver = &hidp_hid_driver; |
| 778 | 766 | ||
| 779 | hid->hid_output_raw_report = hidp_output_raw_report; | ||
| 780 | |||
| 781 | /* True if device is blacklisted in drivers/hid/hid-core.c */ | 767 | /* True if device is blacklisted in drivers/hid/hid-core.c */ |
| 782 | if (hid_ignore(hid)) { | 768 | if (hid_ignore(hid)) { |
| 783 | hid_destroy_device(session->hid); | 769 | hid_destroy_device(session->hid); |
