Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2013 Andrew Duggan <aduggan@synaptics.com> |
| 4 | * Copyright (c) 2013 Synaptics Incorporated |
| 5 | * Copyright (c) 2014 Benjamin Tissoires <benjamin.tissoires@gmail.com> |
| 6 | * Copyright (c) 2014 Red Hat, Inc |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <linux/kernel.h> |
| 10 | #include <linux/hid.h> |
| 11 | #include <linux/input.h> |
| 12 | #include <linux/input/mt.h> |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 13 | #include <linux/irq.h> |
| 14 | #include <linux/irqdomain.h> |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 15 | #include <linux/module.h> |
| 16 | #include <linux/pm.h> |
| 17 | #include <linux/slab.h> |
| 18 | #include <linux/wait.h> |
| 19 | #include <linux/sched.h> |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 20 | #include <linux/rmi.h> |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 21 | #include "hid-ids.h" |
| 22 | |
| 23 | #define RMI_MOUSE_REPORT_ID 0x01 /* Mouse emulation Report */ |
| 24 | #define RMI_WRITE_REPORT_ID 0x09 /* Output Report */ |
| 25 | #define RMI_READ_ADDR_REPORT_ID 0x0a /* Output Report */ |
| 26 | #define RMI_READ_DATA_REPORT_ID 0x0b /* Input Report */ |
| 27 | #define RMI_ATTN_REPORT_ID 0x0c /* Input Report */ |
| 28 | #define RMI_SET_RMI_MODE_REPORT_ID 0x0f /* Feature Report */ |
| 29 | |
| 30 | /* flags */ |
Dan Carpenter | af43c40 | 2015-05-14 11:32:56 +0300 | [diff] [blame] | 31 | #define RMI_READ_REQUEST_PENDING 0 |
| 32 | #define RMI_READ_DATA_PENDING 1 |
| 33 | #define RMI_STARTED 2 |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 34 | |
Andrew Duggan | 2f43de6 | 2014-12-19 14:45:41 -0800 | [diff] [blame] | 35 | /* device flags */ |
| 36 | #define RMI_DEVICE BIT(0) |
Andrew Duggan | 79364d8 | 2015-01-08 14:51:34 -0800 | [diff] [blame] | 37 | #define RMI_DEVICE_HAS_PHYS_BUTTONS BIT(1) |
Tobias Auerochs | 1023538 | 2019-04-20 21:19:51 +0200 | [diff] [blame] | 38 | #define RMI_DEVICE_OUTPUT_SET_REPORT BIT(2) |
Andrew Duggan | 2f43de6 | 2014-12-19 14:45:41 -0800 | [diff] [blame] | 39 | |
Andrew Duggan | 7035f3a | 2015-07-10 12:48:21 -0700 | [diff] [blame] | 40 | /* |
| 41 | * retrieve the ctrl registers |
| 42 | * the ctrl register has a size of 20 but a fw bug split it into 16 + 4, |
| 43 | * and there is no way to know if the first 20 bytes are here or not. |
| 44 | * We use only the first 12 bytes, so get only them. |
| 45 | */ |
| 46 | #define RMI_F11_CTRL_REG_COUNT 12 |
| 47 | |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 48 | enum rmi_mode_type { |
| 49 | RMI_MODE_OFF = 0, |
| 50 | RMI_MODE_ATTN_REPORTS = 1, |
| 51 | RMI_MODE_NO_PACKED_ATTN_REPORTS = 2, |
| 52 | }; |
| 53 | |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 54 | /** |
| 55 | * struct rmi_data - stores information for hid communication |
| 56 | * |
| 57 | * @page_mutex: Locks current page to avoid changing pages in unexpected ways. |
| 58 | * @page: Keeps track of the current virtual page |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 59 | * @xport: transport device to be registered with the RMI4 core. |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 60 | * |
| 61 | * @wait: Used for waiting for read data |
| 62 | * |
| 63 | * @writeReport: output buffer when writing RMI registers |
| 64 | * @readReport: input buffer when reading RMI registers |
| 65 | * |
| 66 | * @input_report_size: size of an input report (advertised by HID) |
| 67 | * @output_report_size: size of an output report (advertised by HID) |
| 68 | * |
| 69 | * @flags: flags for the current device (started, reading, etc...) |
| 70 | * |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 71 | * @reset_work: worker which will be called in case of a mouse report |
| 72 | * @hdev: pointer to the struct hid_device |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 73 | * |
| 74 | * @device_flags: flags which describe the device |
| 75 | * |
| 76 | * @domain: the IRQ domain allocated for this RMI4 device |
| 77 | * @rmi_irq: the irq that will be used to generate events to rmi-core |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 78 | */ |
| 79 | struct rmi_data { |
| 80 | struct mutex page_mutex; |
| 81 | int page; |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 82 | struct rmi_transport_dev xport; |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 83 | |
| 84 | wait_queue_head_t wait; |
| 85 | |
| 86 | u8 *writeReport; |
| 87 | u8 *readReport; |
| 88 | |
Aaron Ma | 3064a03 | 2018-02-03 23:57:15 +0800 | [diff] [blame] | 89 | u32 input_report_size; |
| 90 | u32 output_report_size; |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 91 | |
| 92 | unsigned long flags; |
| 93 | |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 94 | struct work_struct reset_work; |
| 95 | struct hid_device *hdev; |
Andrew Duggan | 2f43de6 | 2014-12-19 14:45:41 -0800 | [diff] [blame] | 96 | |
| 97 | unsigned long device_flags; |
Andrew Duggan | 0925636 | 2015-07-06 16:48:31 -0700 | [diff] [blame] | 98 | |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 99 | struct irq_domain *domain; |
| 100 | int rmi_irq; |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | #define RMI_PAGE(addr) (((addr) >> 8) & 0xff) |
| 104 | |
| 105 | static int rmi_write_report(struct hid_device *hdev, u8 *report, int len); |
| 106 | |
| 107 | /** |
| 108 | * rmi_set_page - Set RMI page |
| 109 | * @hdev: The pointer to the hid_device struct |
| 110 | * @page: The new page address. |
| 111 | * |
| 112 | * RMI devices have 16-bit addressing, but some of the physical |
| 113 | * implementations (like SMBus) only have 8-bit addressing. So RMI implements |
| 114 | * a page address at 0xff of every page so we can reliable page addresses |
| 115 | * every 256 registers. |
| 116 | * |
| 117 | * The page_mutex lock must be held when this function is entered. |
| 118 | * |
| 119 | * Returns zero on success, non-zero on failure. |
| 120 | */ |
| 121 | static int rmi_set_page(struct hid_device *hdev, u8 page) |
| 122 | { |
| 123 | struct rmi_data *data = hid_get_drvdata(hdev); |
| 124 | int retval; |
| 125 | |
| 126 | data->writeReport[0] = RMI_WRITE_REPORT_ID; |
| 127 | data->writeReport[1] = 1; |
| 128 | data->writeReport[2] = 0xFF; |
| 129 | data->writeReport[4] = page; |
| 130 | |
| 131 | retval = rmi_write_report(hdev, data->writeReport, |
| 132 | data->output_report_size); |
| 133 | if (retval != data->output_report_size) { |
| 134 | dev_err(&hdev->dev, |
| 135 | "%s: set page failed: %d.", __func__, retval); |
| 136 | return retval; |
| 137 | } |
| 138 | |
| 139 | data->page = page; |
| 140 | return 0; |
| 141 | } |
| 142 | |
| 143 | static int rmi_set_mode(struct hid_device *hdev, u8 mode) |
| 144 | { |
| 145 | int ret; |
Benjamin Tissoires | 6dab07d | 2016-11-21 11:48:42 +0100 | [diff] [blame] | 146 | const u8 txbuf[2] = {RMI_SET_RMI_MODE_REPORT_ID, mode}; |
| 147 | u8 *buf; |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 148 | |
Benjamin Tissoires | 6dab07d | 2016-11-21 11:48:42 +0100 | [diff] [blame] | 149 | buf = kmemdup(txbuf, sizeof(txbuf), GFP_KERNEL); |
| 150 | if (!buf) |
| 151 | return -ENOMEM; |
| 152 | |
| 153 | ret = hid_hw_raw_request(hdev, RMI_SET_RMI_MODE_REPORT_ID, buf, |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 154 | sizeof(txbuf), HID_FEATURE_REPORT, HID_REQ_SET_REPORT); |
Benjamin Tissoires | 6dab07d | 2016-11-21 11:48:42 +0100 | [diff] [blame] | 155 | kfree(buf); |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 156 | if (ret < 0) { |
| 157 | dev_err(&hdev->dev, "unable to set rmi mode to %d (%d)\n", mode, |
| 158 | ret); |
| 159 | return ret; |
| 160 | } |
| 161 | |
| 162 | return 0; |
| 163 | } |
| 164 | |
| 165 | static int rmi_write_report(struct hid_device *hdev, u8 *report, int len) |
| 166 | { |
Tobias Auerochs | 1023538 | 2019-04-20 21:19:51 +0200 | [diff] [blame] | 167 | struct rmi_data *data = hid_get_drvdata(hdev); |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 168 | int ret; |
| 169 | |
Tobias Auerochs | 1023538 | 2019-04-20 21:19:51 +0200 | [diff] [blame] | 170 | if (data->device_flags & RMI_DEVICE_OUTPUT_SET_REPORT) { |
| 171 | /* |
| 172 | * Talk to device by using SET_REPORT requests instead. |
| 173 | */ |
| 174 | ret = hid_hw_raw_request(hdev, report[0], report, |
| 175 | len, HID_OUTPUT_REPORT, HID_REQ_SET_REPORT); |
| 176 | } else { |
| 177 | ret = hid_hw_output_report(hdev, (void *)report, len); |
| 178 | } |
| 179 | |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 180 | if (ret < 0) { |
| 181 | dev_err(&hdev->dev, "failed to write hid report (%d)\n", ret); |
| 182 | return ret; |
| 183 | } |
| 184 | |
| 185 | return ret; |
| 186 | } |
| 187 | |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 188 | static int rmi_hid_read_block(struct rmi_transport_dev *xport, u16 addr, |
| 189 | void *buf, size_t len) |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 190 | { |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 191 | struct rmi_data *data = container_of(xport, struct rmi_data, xport); |
| 192 | struct hid_device *hdev = data->hdev; |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 193 | int ret; |
| 194 | int bytes_read; |
| 195 | int bytes_needed; |
| 196 | int retries; |
| 197 | int read_input_count; |
| 198 | |
| 199 | mutex_lock(&data->page_mutex); |
| 200 | |
| 201 | if (RMI_PAGE(addr) != data->page) { |
| 202 | ret = rmi_set_page(hdev, RMI_PAGE(addr)); |
| 203 | if (ret < 0) |
| 204 | goto exit; |
| 205 | } |
| 206 | |
| 207 | for (retries = 5; retries > 0; retries--) { |
| 208 | data->writeReport[0] = RMI_READ_ADDR_REPORT_ID; |
| 209 | data->writeReport[1] = 0; /* old 1 byte read count */ |
| 210 | data->writeReport[2] = addr & 0xFF; |
| 211 | data->writeReport[3] = (addr >> 8) & 0xFF; |
| 212 | data->writeReport[4] = len & 0xFF; |
| 213 | data->writeReport[5] = (len >> 8) & 0xFF; |
| 214 | |
| 215 | set_bit(RMI_READ_REQUEST_PENDING, &data->flags); |
| 216 | |
| 217 | ret = rmi_write_report(hdev, data->writeReport, |
| 218 | data->output_report_size); |
| 219 | if (ret != data->output_report_size) { |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 220 | dev_err(&hdev->dev, |
| 221 | "failed to write request output report (%d)\n", |
| 222 | ret); |
| 223 | goto exit; |
| 224 | } |
| 225 | |
| 226 | bytes_read = 0; |
| 227 | bytes_needed = len; |
| 228 | while (bytes_read < len) { |
| 229 | if (!wait_event_timeout(data->wait, |
| 230 | test_bit(RMI_READ_DATA_PENDING, &data->flags), |
| 231 | msecs_to_jiffies(1000))) { |
| 232 | hid_warn(hdev, "%s: timeout elapsed\n", |
| 233 | __func__); |
| 234 | ret = -EAGAIN; |
| 235 | break; |
| 236 | } |
| 237 | |
| 238 | read_input_count = data->readReport[1]; |
| 239 | memcpy(buf + bytes_read, &data->readReport[2], |
| 240 | read_input_count < bytes_needed ? |
| 241 | read_input_count : bytes_needed); |
| 242 | |
| 243 | bytes_read += read_input_count; |
| 244 | bytes_needed -= read_input_count; |
| 245 | clear_bit(RMI_READ_DATA_PENDING, &data->flags); |
| 246 | } |
| 247 | |
| 248 | if (ret >= 0) { |
| 249 | ret = 0; |
| 250 | break; |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | exit: |
| 255 | clear_bit(RMI_READ_REQUEST_PENDING, &data->flags); |
| 256 | mutex_unlock(&data->page_mutex); |
| 257 | return ret; |
| 258 | } |
| 259 | |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 260 | static int rmi_hid_write_block(struct rmi_transport_dev *xport, u16 addr, |
| 261 | const void *buf, size_t len) |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 262 | { |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 263 | struct rmi_data *data = container_of(xport, struct rmi_data, xport); |
| 264 | struct hid_device *hdev = data->hdev; |
Andrew Duggan | dd8df28 | 2015-02-24 17:36:48 -0800 | [diff] [blame] | 265 | int ret; |
| 266 | |
| 267 | mutex_lock(&data->page_mutex); |
| 268 | |
| 269 | if (RMI_PAGE(addr) != data->page) { |
| 270 | ret = rmi_set_page(hdev, RMI_PAGE(addr)); |
| 271 | if (ret < 0) |
| 272 | goto exit; |
| 273 | } |
| 274 | |
| 275 | data->writeReport[0] = RMI_WRITE_REPORT_ID; |
| 276 | data->writeReport[1] = len; |
| 277 | data->writeReport[2] = addr & 0xFF; |
| 278 | data->writeReport[3] = (addr >> 8) & 0xFF; |
| 279 | memcpy(&data->writeReport[4], buf, len); |
| 280 | |
| 281 | ret = rmi_write_report(hdev, data->writeReport, |
| 282 | data->output_report_size); |
| 283 | if (ret < 0) { |
| 284 | dev_err(&hdev->dev, |
| 285 | "failed to write request output report (%d)\n", |
| 286 | ret); |
| 287 | goto exit; |
| 288 | } |
| 289 | ret = 0; |
| 290 | |
| 291 | exit: |
| 292 | mutex_unlock(&data->page_mutex); |
| 293 | return ret; |
| 294 | } |
| 295 | |
Andrew Duggan | 9a98b33 | 2015-07-16 17:14:00 -0700 | [diff] [blame] | 296 | static int rmi_reset_attn_mode(struct hid_device *hdev) |
| 297 | { |
| 298 | struct rmi_data *data = hid_get_drvdata(hdev); |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 299 | struct rmi_device *rmi_dev = data->xport.rmi_dev; |
Andrew Duggan | 9a98b33 | 2015-07-16 17:14:00 -0700 | [diff] [blame] | 300 | int ret; |
| 301 | |
| 302 | ret = rmi_set_mode(hdev, RMI_MODE_ATTN_REPORTS); |
| 303 | if (ret) |
| 304 | return ret; |
| 305 | |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 306 | if (test_bit(RMI_STARTED, &data->flags)) |
| 307 | ret = rmi_dev->driver->reset_handler(rmi_dev); |
Andrew Duggan | 9a98b33 | 2015-07-16 17:14:00 -0700 | [diff] [blame] | 308 | |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 309 | return ret; |
Andrew Duggan | 9a98b33 | 2015-07-16 17:14:00 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 312 | static void rmi_reset_work(struct work_struct *work) |
| 313 | { |
| 314 | struct rmi_data *hdata = container_of(work, struct rmi_data, |
| 315 | reset_work); |
| 316 | |
| 317 | /* switch the device to RMI if we receive a generic mouse report */ |
Andrew Duggan | 9a98b33 | 2015-07-16 17:14:00 -0700 | [diff] [blame] | 318 | rmi_reset_attn_mode(hdata->hdev); |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 319 | } |
| 320 | |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 321 | static int rmi_input_event(struct hid_device *hdev, u8 *data, int size) |
| 322 | { |
| 323 | struct rmi_data *hdata = hid_get_drvdata(hdev); |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 324 | struct rmi_device *rmi_dev = hdata->xport.rmi_dev; |
| 325 | unsigned long flags; |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 326 | |
| 327 | if (!(test_bit(RMI_STARTED, &hdata->flags))) |
| 328 | return 0; |
| 329 | |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 330 | local_irq_save(flags); |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 331 | |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 332 | rmi_set_attn_data(rmi_dev, data[1], &data[2], size - 2); |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 333 | |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 334 | generic_handle_irq(hdata->rmi_irq); |
| 335 | |
| 336 | local_irq_restore(flags); |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 337 | |
| 338 | return 1; |
| 339 | } |
| 340 | |
| 341 | static int rmi_read_data_event(struct hid_device *hdev, u8 *data, int size) |
| 342 | { |
| 343 | struct rmi_data *hdata = hid_get_drvdata(hdev); |
| 344 | |
| 345 | if (!test_bit(RMI_READ_REQUEST_PENDING, &hdata->flags)) { |
Andrew Duggan | 01a5f8a | 2014-07-11 14:35:51 -0700 | [diff] [blame] | 346 | hid_dbg(hdev, "no read request pending\n"); |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 347 | return 0; |
| 348 | } |
| 349 | |
| 350 | memcpy(hdata->readReport, data, size < hdata->input_report_size ? |
| 351 | size : hdata->input_report_size); |
| 352 | set_bit(RMI_READ_DATA_PENDING, &hdata->flags); |
| 353 | wake_up(&hdata->wait); |
| 354 | |
| 355 | return 1; |
| 356 | } |
| 357 | |
Benjamin Tissoires | 5b65c2a | 2014-09-10 18:02:37 -0700 | [diff] [blame] | 358 | static int rmi_check_sanity(struct hid_device *hdev, u8 *data, int size) |
| 359 | { |
| 360 | int valid_size = size; |
| 361 | /* |
| 362 | * On the Dell XPS 13 9333, the bus sometimes get confused and fills |
| 363 | * the report with a sentinel value "ff". Synaptics told us that such |
| 364 | * behavior does not comes from the touchpad itself, so we filter out |
| 365 | * such reports here. |
| 366 | */ |
| 367 | |
| 368 | while ((data[valid_size - 1] == 0xff) && valid_size > 0) |
| 369 | valid_size--; |
| 370 | |
| 371 | return valid_size; |
| 372 | } |
| 373 | |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 374 | static int rmi_raw_event(struct hid_device *hdev, |
| 375 | struct hid_report *report, u8 *data, int size) |
| 376 | { |
Andrew Duggan | ef14a4bf | 2017-10-17 18:37:36 -0700 | [diff] [blame] | 377 | struct rmi_data *hdata = hid_get_drvdata(hdev); |
| 378 | |
| 379 | if (!(hdata->device_flags & RMI_DEVICE)) |
| 380 | return 0; |
| 381 | |
Benjamin Tissoires | 5b65c2a | 2014-09-10 18:02:37 -0700 | [diff] [blame] | 382 | size = rmi_check_sanity(hdev, data, size); |
| 383 | if (size < 2) |
| 384 | return 0; |
| 385 | |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 386 | switch (data[0]) { |
| 387 | case RMI_READ_DATA_REPORT_ID: |
| 388 | return rmi_read_data_event(hdev, data, size); |
| 389 | case RMI_ATTN_REPORT_ID: |
| 390 | return rmi_input_event(hdev, data, size); |
Andrew Duggan | 2f43de6 | 2014-12-19 14:45:41 -0800 | [diff] [blame] | 391 | default: |
| 392 | return 1; |
| 393 | } |
| 394 | |
| 395 | return 0; |
| 396 | } |
| 397 | |
| 398 | static int rmi_event(struct hid_device *hdev, struct hid_field *field, |
| 399 | struct hid_usage *usage, __s32 value) |
| 400 | { |
| 401 | struct rmi_data *data = hid_get_drvdata(hdev); |
| 402 | |
| 403 | if ((data->device_flags & RMI_DEVICE) && |
| 404 | (field->application == HID_GD_POINTER || |
| 405 | field->application == HID_GD_MOUSE)) { |
Andrew Duggan | 79364d8 | 2015-01-08 14:51:34 -0800 | [diff] [blame] | 406 | if (data->device_flags & RMI_DEVICE_HAS_PHYS_BUTTONS) { |
| 407 | if ((usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON) |
| 408 | return 0; |
| 409 | |
| 410 | if ((usage->hid == HID_GD_X || usage->hid == HID_GD_Y) |
| 411 | && !value) |
| 412 | return 1; |
| 413 | } |
| 414 | |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 415 | schedule_work(&data->reset_work); |
Andrew Duggan | 2f43de6 | 2014-12-19 14:45:41 -0800 | [diff] [blame] | 416 | return 1; |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | return 0; |
| 420 | } |
| 421 | |
Benjamin Tissoires | c94ba06 | 2018-05-25 14:51:06 +0200 | [diff] [blame] | 422 | static void rmi_report(struct hid_device *hid, struct hid_report *report) |
| 423 | { |
| 424 | struct hid_field *field = report->field[0]; |
| 425 | |
| 426 | if (!(hid->claimed & HID_CLAIMED_INPUT)) |
| 427 | return; |
| 428 | |
| 429 | switch (report->id) { |
| 430 | case RMI_READ_DATA_REPORT_ID: |
Benjamin Tissoires | c94ba06 | 2018-05-25 14:51:06 +0200 | [diff] [blame] | 431 | case RMI_ATTN_REPORT_ID: |
| 432 | return; |
| 433 | } |
| 434 | |
| 435 | if (field && field->hidinput && field->hidinput->input) |
| 436 | input_sync(field->hidinput->input); |
| 437 | } |
| 438 | |
Geert Uytterhoeven | a278e26 | 2014-06-11 21:03:18 +0200 | [diff] [blame] | 439 | #ifdef CONFIG_PM |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 440 | static int rmi_suspend(struct hid_device *hdev, pm_message_t message) |
Andrew Duggan | 0925636 | 2015-07-06 16:48:31 -0700 | [diff] [blame] | 441 | { |
| 442 | struct rmi_data *data = hid_get_drvdata(hdev); |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 443 | struct rmi_device *rmi_dev = data->xport.rmi_dev; |
Andrew Duggan | 0925636 | 2015-07-06 16:48:31 -0700 | [diff] [blame] | 444 | int ret; |
Andrew Duggan | 0925636 | 2015-07-06 16:48:31 -0700 | [diff] [blame] | 445 | |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 446 | if (!(data->device_flags & RMI_DEVICE)) |
| 447 | return 0; |
Andrew Duggan | 0925636 | 2015-07-06 16:48:31 -0700 | [diff] [blame] | 448 | |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 449 | ret = rmi_driver_suspend(rmi_dev, false); |
Andrew Duggan | 0925636 | 2015-07-06 16:48:31 -0700 | [diff] [blame] | 450 | if (ret) { |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 451 | hid_warn(hdev, "Failed to suspend device: %d\n", ret); |
Andrew Duggan | 0925636 | 2015-07-06 16:48:31 -0700 | [diff] [blame] | 452 | return ret; |
| 453 | } |
| 454 | |
| 455 | return 0; |
| 456 | } |
| 457 | |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 458 | static int rmi_post_resume(struct hid_device *hdev) |
Andrew Duggan | 0925636 | 2015-07-06 16:48:31 -0700 | [diff] [blame] | 459 | { |
Andrew Duggan | 7035f3a | 2015-07-10 12:48:21 -0700 | [diff] [blame] | 460 | struct rmi_data *data = hid_get_drvdata(hdev); |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 461 | struct rmi_device *rmi_dev = data->xport.rmi_dev; |
Andrew Duggan | 0925636 | 2015-07-06 16:48:31 -0700 | [diff] [blame] | 462 | int ret; |
| 463 | |
Andrew Duggan | b786ae8 | 2016-01-26 15:40:36 -0800 | [diff] [blame] | 464 | if (!(data->device_flags & RMI_DEVICE)) |
| 465 | return 0; |
| 466 | |
Lyude | cac72b9 | 2017-07-22 21:15:09 -0400 | [diff] [blame] | 467 | /* Make sure the HID device is ready to receive events */ |
| 468 | ret = hid_hw_open(hdev); |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 469 | if (ret) |
| 470 | return ret; |
| 471 | |
Lyude | cac72b9 | 2017-07-22 21:15:09 -0400 | [diff] [blame] | 472 | ret = rmi_reset_attn_mode(hdev); |
| 473 | if (ret) |
| 474 | goto out; |
| 475 | |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 476 | ret = rmi_driver_resume(rmi_dev, false); |
Andrew Duggan | 0925636 | 2015-07-06 16:48:31 -0700 | [diff] [blame] | 477 | if (ret) { |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 478 | hid_warn(hdev, "Failed to resume device: %d\n", ret); |
Lyude | cac72b9 | 2017-07-22 21:15:09 -0400 | [diff] [blame] | 479 | goto out; |
Andrew Duggan | 0925636 | 2015-07-06 16:48:31 -0700 | [diff] [blame] | 480 | } |
| 481 | |
Lyude | cac72b9 | 2017-07-22 21:15:09 -0400 | [diff] [blame] | 482 | out: |
| 483 | hid_hw_close(hdev); |
| 484 | return ret; |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 485 | } |
Geert Uytterhoeven | a278e26 | 2014-06-11 21:03:18 +0200 | [diff] [blame] | 486 | #endif /* CONFIG_PM */ |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 487 | |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 488 | static int rmi_hid_reset(struct rmi_transport_dev *xport, u16 reset_addr) |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 489 | { |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 490 | struct rmi_data *data = container_of(xport, struct rmi_data, xport); |
| 491 | struct hid_device *hdev = data->hdev; |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 492 | |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 493 | return rmi_reset_attn_mode(hdev); |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 494 | } |
| 495 | |
Dmitry Torokhov | 9154301 | 2015-09-29 15:52:59 -0700 | [diff] [blame] | 496 | static int rmi_input_configured(struct hid_device *hdev, struct hid_input *hi) |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 497 | { |
| 498 | struct rmi_data *data = hid_get_drvdata(hdev); |
| 499 | struct input_dev *input = hi->input; |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 500 | int ret = 0; |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 501 | |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 502 | if (!(data->device_flags & RMI_DEVICE)) |
| 503 | return 0; |
| 504 | |
| 505 | data->xport.input = input; |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 506 | |
| 507 | hid_dbg(hdev, "Opening low level driver\n"); |
| 508 | ret = hid_hw_open(hdev); |
| 509 | if (ret) |
Dmitry Torokhov | 9154301 | 2015-09-29 15:52:59 -0700 | [diff] [blame] | 510 | return ret; |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 511 | |
| 512 | /* Allow incoming hid reports */ |
| 513 | hid_device_io_start(hdev); |
| 514 | |
| 515 | ret = rmi_set_mode(hdev, RMI_MODE_ATTN_REPORTS); |
| 516 | if (ret < 0) { |
| 517 | dev_err(&hdev->dev, "failed to set rmi mode\n"); |
| 518 | goto exit; |
| 519 | } |
| 520 | |
| 521 | ret = rmi_set_page(hdev, 0); |
| 522 | if (ret < 0) { |
| 523 | dev_err(&hdev->dev, "failed to set page select to 0.\n"); |
| 524 | goto exit; |
| 525 | } |
| 526 | |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 527 | ret = rmi_register_transport_device(&data->xport); |
| 528 | if (ret < 0) { |
| 529 | dev_err(&hdev->dev, "failed to register transport driver\n"); |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 530 | goto exit; |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | set_bit(RMI_STARTED, &data->flags); |
| 534 | |
| 535 | exit: |
| 536 | hid_device_io_stop(hdev); |
| 537 | hid_hw_close(hdev); |
Dmitry Torokhov | 9154301 | 2015-09-29 15:52:59 -0700 | [diff] [blame] | 538 | return ret; |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | static int rmi_input_mapping(struct hid_device *hdev, |
| 542 | struct hid_input *hi, struct hid_field *field, |
| 543 | struct hid_usage *usage, unsigned long **bit, int *max) |
| 544 | { |
Andrew Duggan | 2f43de6 | 2014-12-19 14:45:41 -0800 | [diff] [blame] | 545 | struct rmi_data *data = hid_get_drvdata(hdev); |
| 546 | |
| 547 | /* |
| 548 | * we want to make HID ignore the advertised HID collection |
| 549 | * for RMI deivces |
| 550 | */ |
Andrew Duggan | 79364d8 | 2015-01-08 14:51:34 -0800 | [diff] [blame] | 551 | if (data->device_flags & RMI_DEVICE) { |
| 552 | if ((data->device_flags & RMI_DEVICE_HAS_PHYS_BUTTONS) && |
| 553 | ((usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON)) |
| 554 | return 0; |
| 555 | |
Andrew Duggan | 2f43de6 | 2014-12-19 14:45:41 -0800 | [diff] [blame] | 556 | return -1; |
Andrew Duggan | 79364d8 | 2015-01-08 14:51:34 -0800 | [diff] [blame] | 557 | } |
Andrew Duggan | 2f43de6 | 2014-12-19 14:45:41 -0800 | [diff] [blame] | 558 | |
| 559 | return 0; |
| 560 | } |
| 561 | |
| 562 | static int rmi_check_valid_report_id(struct hid_device *hdev, unsigned type, |
| 563 | unsigned id, struct hid_report **report) |
| 564 | { |
| 565 | int i; |
| 566 | |
| 567 | *report = hdev->report_enum[type].report_id_hash[id]; |
| 568 | if (*report) { |
| 569 | for (i = 0; i < (*report)->maxfield; i++) { |
| 570 | unsigned app = (*report)->field[i]->application; |
| 571 | if ((app & HID_USAGE_PAGE) >= HID_UP_MSVENDOR) |
| 572 | return 1; |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | return 0; |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 577 | } |
| 578 | |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 579 | static struct rmi_device_platform_data rmi_hid_pdata = { |
| 580 | .sensor_pdata = { |
| 581 | .sensor_type = rmi_sensor_touchpad, |
| 582 | .axis_align.flip_y = true, |
| 583 | .dribble = RMI_REG_STATE_ON, |
| 584 | .palm_detect = RMI_REG_STATE_OFF, |
| 585 | }, |
| 586 | }; |
| 587 | |
| 588 | static const struct rmi_transport_ops hid_rmi_ops = { |
| 589 | .write_block = rmi_hid_write_block, |
| 590 | .read_block = rmi_hid_read_block, |
| 591 | .reset = rmi_hid_reset, |
| 592 | }; |
| 593 | |
| 594 | static void rmi_irq_teardown(void *data) |
| 595 | { |
| 596 | struct rmi_data *hdata = data; |
| 597 | struct irq_domain *domain = hdata->domain; |
| 598 | |
| 599 | if (!domain) |
| 600 | return; |
| 601 | |
| 602 | irq_dispose_mapping(irq_find_mapping(domain, 0)); |
| 603 | |
| 604 | irq_domain_remove(domain); |
| 605 | hdata->domain = NULL; |
| 606 | hdata->rmi_irq = 0; |
| 607 | } |
| 608 | |
| 609 | static int rmi_irq_map(struct irq_domain *h, unsigned int virq, |
| 610 | irq_hw_number_t hw_irq_num) |
| 611 | { |
| 612 | irq_set_chip_and_handler(virq, &dummy_irq_chip, handle_simple_irq); |
| 613 | |
| 614 | return 0; |
| 615 | } |
| 616 | |
| 617 | static const struct irq_domain_ops rmi_irq_ops = { |
| 618 | .map = rmi_irq_map, |
| 619 | }; |
| 620 | |
| 621 | static int rmi_setup_irq_domain(struct hid_device *hdev) |
| 622 | { |
| 623 | struct rmi_data *hdata = hid_get_drvdata(hdev); |
| 624 | int ret; |
| 625 | |
| 626 | hdata->domain = irq_domain_create_linear(hdev->dev.fwnode, 1, |
| 627 | &rmi_irq_ops, hdata); |
| 628 | if (!hdata->domain) |
| 629 | return -ENOMEM; |
| 630 | |
| 631 | ret = devm_add_action_or_reset(&hdev->dev, &rmi_irq_teardown, hdata); |
| 632 | if (ret) |
| 633 | return ret; |
| 634 | |
| 635 | hdata->rmi_irq = irq_create_mapping(hdata->domain, 0); |
| 636 | if (hdata->rmi_irq <= 0) { |
| 637 | hid_err(hdev, "Can't allocate an IRQ\n"); |
| 638 | return hdata->rmi_irq < 0 ? hdata->rmi_irq : -ENXIO; |
| 639 | } |
| 640 | |
| 641 | return 0; |
| 642 | } |
| 643 | |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 644 | static int rmi_probe(struct hid_device *hdev, const struct hid_device_id *id) |
| 645 | { |
| 646 | struct rmi_data *data = NULL; |
| 647 | int ret; |
| 648 | size_t alloc_size; |
Andrew Duggan | dd3edeb | 2014-07-17 16:14:44 -0700 | [diff] [blame] | 649 | struct hid_report *input_report; |
| 650 | struct hid_report *output_report; |
Andrew Duggan | 2f43de6 | 2014-12-19 14:45:41 -0800 | [diff] [blame] | 651 | struct hid_report *feature_report; |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 652 | |
| 653 | data = devm_kzalloc(&hdev->dev, sizeof(struct rmi_data), GFP_KERNEL); |
| 654 | if (!data) |
| 655 | return -ENOMEM; |
| 656 | |
| 657 | INIT_WORK(&data->reset_work, rmi_reset_work); |
| 658 | data->hdev = hdev; |
| 659 | |
| 660 | hid_set_drvdata(hdev, data); |
| 661 | |
| 662 | hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS; |
Benjamin Tissoires | c94ba06 | 2018-05-25 14:51:06 +0200 | [diff] [blame] | 663 | hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC; |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 664 | |
| 665 | ret = hid_parse(hdev); |
| 666 | if (ret) { |
| 667 | hid_err(hdev, "parse failed\n"); |
| 668 | return ret; |
| 669 | } |
| 670 | |
Andrew Duggan | 79364d8 | 2015-01-08 14:51:34 -0800 | [diff] [blame] | 671 | if (id->driver_data) |
| 672 | data->device_flags = id->driver_data; |
| 673 | |
Andrew Duggan | 2f43de6 | 2014-12-19 14:45:41 -0800 | [diff] [blame] | 674 | /* |
| 675 | * Check for the RMI specific report ids. If they are misisng |
| 676 | * simply return and let the events be processed by hid-input |
| 677 | */ |
| 678 | if (!rmi_check_valid_report_id(hdev, HID_FEATURE_REPORT, |
| 679 | RMI_SET_RMI_MODE_REPORT_ID, &feature_report)) { |
| 680 | hid_dbg(hdev, "device does not have set mode feature report\n"); |
| 681 | goto start; |
| 682 | } |
| 683 | |
| 684 | if (!rmi_check_valid_report_id(hdev, HID_INPUT_REPORT, |
| 685 | RMI_ATTN_REPORT_ID, &input_report)) { |
| 686 | hid_dbg(hdev, "device does not have attention input report\n"); |
| 687 | goto start; |
Andrew Duggan | dd3edeb | 2014-07-17 16:14:44 -0700 | [diff] [blame] | 688 | } |
| 689 | |
Andrew Duggan | b8aed6e | 2015-01-08 14:51:36 -0800 | [diff] [blame] | 690 | data->input_report_size = hid_report_len(input_report); |
Andrew Duggan | dd3edeb | 2014-07-17 16:14:44 -0700 | [diff] [blame] | 691 | |
Andrew Duggan | 2f43de6 | 2014-12-19 14:45:41 -0800 | [diff] [blame] | 692 | if (!rmi_check_valid_report_id(hdev, HID_OUTPUT_REPORT, |
| 693 | RMI_WRITE_REPORT_ID, &output_report)) { |
| 694 | hid_dbg(hdev, |
| 695 | "device does not have rmi write output report\n"); |
| 696 | goto start; |
Andrew Duggan | dd3edeb | 2014-07-17 16:14:44 -0700 | [diff] [blame] | 697 | } |
| 698 | |
Andrew Duggan | b8aed6e | 2015-01-08 14:51:36 -0800 | [diff] [blame] | 699 | data->output_report_size = hid_report_len(output_report); |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 700 | |
Andrew Duggan | 2f43de6 | 2014-12-19 14:45:41 -0800 | [diff] [blame] | 701 | data->device_flags |= RMI_DEVICE; |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 702 | alloc_size = data->output_report_size + data->input_report_size; |
| 703 | |
| 704 | data->writeReport = devm_kzalloc(&hdev->dev, alloc_size, GFP_KERNEL); |
| 705 | if (!data->writeReport) { |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 706 | hid_err(hdev, "failed to allocate buffer for HID reports\n"); |
| 707 | return -ENOMEM; |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | data->readReport = data->writeReport + data->output_report_size; |
| 711 | |
| 712 | init_waitqueue_head(&data->wait); |
| 713 | |
| 714 | mutex_init(&data->page_mutex); |
| 715 | |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 716 | ret = rmi_setup_irq_domain(hdev); |
| 717 | if (ret) { |
| 718 | hid_err(hdev, "failed to allocate IRQ domain\n"); |
| 719 | return ret; |
| 720 | } |
| 721 | |
| 722 | if (data->device_flags & RMI_DEVICE_HAS_PHYS_BUTTONS) |
Vincent Huang | 261bfb3 | 2020-10-04 19:42:47 -0700 | [diff] [blame] | 723 | rmi_hid_pdata.gpio_data.disable = true; |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 724 | |
| 725 | data->xport.dev = hdev->dev.parent; |
| 726 | data->xport.pdata = rmi_hid_pdata; |
| 727 | data->xport.pdata.irq = data->rmi_irq; |
| 728 | data->xport.proto_name = "hid"; |
| 729 | data->xport.ops = &hid_rmi_ops; |
| 730 | |
Andrew Duggan | 2f43de6 | 2014-12-19 14:45:41 -0800 | [diff] [blame] | 731 | start: |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 732 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); |
| 733 | if (ret) { |
| 734 | hid_err(hdev, "hw start failed\n"); |
| 735 | return ret; |
| 736 | } |
| 737 | |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 738 | return 0; |
| 739 | } |
| 740 | |
| 741 | static void rmi_remove(struct hid_device *hdev) |
| 742 | { |
| 743 | struct rmi_data *hdata = hid_get_drvdata(hdev); |
| 744 | |
Andrew Duggan | 8725aa4 | 2019-10-23 01:24:03 +0000 | [diff] [blame] | 745 | if ((hdata->device_flags & RMI_DEVICE) |
| 746 | && test_bit(RMI_STARTED, &hdata->flags)) { |
Andrew Duggan | ef14a4bf | 2017-10-17 18:37:36 -0700 | [diff] [blame] | 747 | clear_bit(RMI_STARTED, &hdata->flags); |
| 748 | cancel_work_sync(&hdata->reset_work); |
| 749 | rmi_unregister_transport_device(&hdata->xport); |
| 750 | } |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 751 | |
| 752 | hid_hw_stop(hdev); |
| 753 | } |
| 754 | |
| 755 | static const struct hid_device_id rmi_id[] = { |
Andrew Duggan | e928709 | 2015-01-08 14:51:35 -0800 | [diff] [blame] | 756 | { HID_USB_DEVICE(USB_VENDOR_ID_RAZER, USB_DEVICE_ID_RAZER_BLADE_14), |
| 757 | .driver_data = RMI_DEVICE_HAS_PHYS_BUTTONS }, |
Andrew Duggan | c7821d0 | 2017-01-05 09:49:00 +0100 | [diff] [blame] | 758 | { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_X1_COVER) }, |
Andrew Duggan | c529340 | 2017-11-17 17:21:30 -0800 | [diff] [blame] | 759 | { HID_USB_DEVICE(USB_VENDOR_ID_PRIMAX, USB_DEVICE_ID_PRIMAX_REZEL) }, |
Tobias Auerochs | 1023538 | 2019-04-20 21:19:51 +0200 | [diff] [blame] | 760 | { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_ACER_SWITCH5), |
| 761 | .driver_data = RMI_DEVICE_OUTPUT_SET_REPORT }, |
Benjamin Tissoires | ba391e5 | 2014-05-21 11:15:56 -0400 | [diff] [blame] | 762 | { HID_DEVICE(HID_BUS_ANY, HID_GROUP_RMI, HID_ANY_ID, HID_ANY_ID) }, |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 763 | { } |
| 764 | }; |
| 765 | MODULE_DEVICE_TABLE(hid, rmi_id); |
| 766 | |
| 767 | static struct hid_driver rmi_driver = { |
| 768 | .name = "hid-rmi", |
| 769 | .id_table = rmi_id, |
| 770 | .probe = rmi_probe, |
| 771 | .remove = rmi_remove, |
Andrew Duggan | 2f43de6 | 2014-12-19 14:45:41 -0800 | [diff] [blame] | 772 | .event = rmi_event, |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 773 | .raw_event = rmi_raw_event, |
Benjamin Tissoires | c94ba06 | 2018-05-25 14:51:06 +0200 | [diff] [blame] | 774 | .report = rmi_report, |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 775 | .input_mapping = rmi_input_mapping, |
| 776 | .input_configured = rmi_input_configured, |
| 777 | #ifdef CONFIG_PM |
Andrew Duggan | 0925636 | 2015-07-06 16:48:31 -0700 | [diff] [blame] | 778 | .suspend = rmi_suspend, |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 779 | .resume = rmi_post_resume, |
Andrew Duggan | 0b2c7a8 | 2017-01-05 09:48:58 +0100 | [diff] [blame] | 780 | .reset_resume = rmi_post_resume, |
Benjamin Tissoires | 9fb6bf0 | 2014-04-07 13:39:33 -0400 | [diff] [blame] | 781 | #endif |
| 782 | }; |
| 783 | |
| 784 | module_hid_driver(rmi_driver); |
| 785 | |
| 786 | MODULE_AUTHOR("Andrew Duggan <aduggan@synaptics.com>"); |
| 787 | MODULE_DESCRIPTION("RMI HID driver"); |
| 788 | MODULE_LICENSE("GPL"); |