]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/hid/hid-picolcd_core.c
HID: picolcd: Add missing #include <linux/uaccess.h>
[mirror_ubuntu-artful-kernel.git] / drivers / hid / hid-picolcd_core.c
CommitLineData
fabdbf2f
BP
1/***************************************************************************
2 * Copyright (C) 2010-2012 by Bruno Prémont <bonbons@linux-vserver.org> *
3 * *
4 * Based on Logitech G13 driver (v0.4) *
5 * Copyright (C) 2009 by Rick L. Vinyard, Jr. <rvinyard@cs.nmsu.edu> *
6 * *
7 * This program is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, version 2 of the License. *
10 * *
11 * This driver is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this software. If not see <http://www.gnu.org/licenses/>. *
18 ***************************************************************************/
19
20#include <linux/hid.h>
21#include <linux/hid-debug.h>
22#include <linux/input.h>
23#include "hid-ids.h"
24#include "usbhid/usbhid.h"
25#include <linux/usb.h>
26
27#include <linux/fb.h>
28#include <linux/vmalloc.h>
29
30#include <linux/completion.h>
31#include <linux/uaccess.h>
32#include <linux/module.h>
33
34#include "hid-picolcd.h"
35
36
37/* Input device
38 *
39 * The PicoLCD has an IR receiver header, a built-in keypad with 5 keys
40 * and header for 4x4 key matrix. The built-in keys are part of the matrix.
41 */
42static const unsigned short def_keymap[PICOLCD_KEYS] = {
43 KEY_RESERVED, /* none */
44 KEY_BACK, /* col 4 + row 1 */
45 KEY_HOMEPAGE, /* col 3 + row 1 */
46 KEY_RESERVED, /* col 2 + row 1 */
47 KEY_RESERVED, /* col 1 + row 1 */
48 KEY_SCROLLUP, /* col 4 + row 2 */
49 KEY_OK, /* col 3 + row 2 */
50 KEY_SCROLLDOWN, /* col 2 + row 2 */
51 KEY_RESERVED, /* col 1 + row 2 */
52 KEY_RESERVED, /* col 4 + row 3 */
53 KEY_RESERVED, /* col 3 + row 3 */
54 KEY_RESERVED, /* col 2 + row 3 */
55 KEY_RESERVED, /* col 1 + row 3 */
56 KEY_RESERVED, /* col 4 + row 4 */
57 KEY_RESERVED, /* col 3 + row 4 */
58 KEY_RESERVED, /* col 2 + row 4 */
59 KEY_RESERVED, /* col 1 + row 4 */
60};
61
62
63/* Find a given report */
64struct hid_report *picolcd_report(int id, struct hid_device *hdev, int dir)
65{
66 struct list_head *feature_report_list = &hdev->report_enum[dir].report_list;
67 struct hid_report *report = NULL;
68
69 list_for_each_entry(report, feature_report_list, list) {
70 if (report->id == id)
71 return report;
72 }
73 hid_warn(hdev, "No report with id 0x%x found\n", id);
74 return NULL;
75}
76
77/* Submit a report and wait for a reply from device - if device fades away
78 * or does not respond in time, return NULL */
79struct picolcd_pending *picolcd_send_and_wait(struct hid_device *hdev,
80 int report_id, const u8 *raw_data, int size)
81{
82 struct picolcd_data *data = hid_get_drvdata(hdev);
83 struct picolcd_pending *work;
84 struct hid_report *report = picolcd_out_report(report_id, hdev);
85 unsigned long flags;
86 int i, j, k;
87
88 if (!report || !data)
89 return NULL;
90 if (data->status & PICOLCD_FAILED)
91 return NULL;
92 work = kzalloc(sizeof(*work), GFP_KERNEL);
93 if (!work)
94 return NULL;
95
96 init_completion(&work->ready);
97 work->out_report = report;
98 work->in_report = NULL;
99 work->raw_size = 0;
100
101 mutex_lock(&data->mutex);
102 spin_lock_irqsave(&data->lock, flags);
103 for (i = k = 0; i < report->maxfield; i++)
104 for (j = 0; j < report->field[i]->report_count; j++) {
105 hid_set_field(report->field[i], j, k < size ? raw_data[k] : 0);
106 k++;
107 }
a93ab849
BP
108 if (data->status & PICOLCD_FAILED) {
109 kfree(work);
110 work = NULL;
111 } else {
112 data->pending = work;
113 usbhid_submit_report(data->hdev, report, USB_DIR_OUT);
114 spin_unlock_irqrestore(&data->lock, flags);
115 wait_for_completion_interruptible_timeout(&work->ready, HZ*2);
116 spin_lock_irqsave(&data->lock, flags);
117 data->pending = NULL;
118 }
fabdbf2f
BP
119 spin_unlock_irqrestore(&data->lock, flags);
120 mutex_unlock(&data->mutex);
121 return work;
122}
123
124/*
125 * input class device
126 */
127static int picolcd_raw_keypad(struct picolcd_data *data,
128 struct hid_report *report, u8 *raw_data, int size)
129{
130 /*
131 * Keypad event
132 * First and second data bytes list currently pressed keys,
133 * 0x00 means no key and at most 2 keys may be pressed at same time
134 */
135 int i, j;
136
137 /* determine newly pressed keys */
138 for (i = 0; i < size; i++) {
139 unsigned int key_code;
140 if (raw_data[i] == 0)
141 continue;
142 for (j = 0; j < sizeof(data->pressed_keys); j++)
143 if (data->pressed_keys[j] == raw_data[i])
144 goto key_already_down;
145 for (j = 0; j < sizeof(data->pressed_keys); j++)
146 if (data->pressed_keys[j] == 0) {
147 data->pressed_keys[j] = raw_data[i];
148 break;
149 }
150 input_event(data->input_keys, EV_MSC, MSC_SCAN, raw_data[i]);
151 if (raw_data[i] < PICOLCD_KEYS)
152 key_code = data->keycode[raw_data[i]];
153 else
154 key_code = KEY_UNKNOWN;
155 if (key_code != KEY_UNKNOWN) {
156 dbg_hid(PICOLCD_NAME " got key press for %u:%d",
157 raw_data[i], key_code);
158 input_report_key(data->input_keys, key_code, 1);
159 }
160 input_sync(data->input_keys);
161key_already_down:
162 continue;
163 }
164
165 /* determine newly released keys */
166 for (j = 0; j < sizeof(data->pressed_keys); j++) {
167 unsigned int key_code;
168 if (data->pressed_keys[j] == 0)
169 continue;
170 for (i = 0; i < size; i++)
171 if (data->pressed_keys[j] == raw_data[i])
172 goto key_still_down;
173 input_event(data->input_keys, EV_MSC, MSC_SCAN, data->pressed_keys[j]);
174 if (data->pressed_keys[j] < PICOLCD_KEYS)
175 key_code = data->keycode[data->pressed_keys[j]];
176 else
177 key_code = KEY_UNKNOWN;
178 if (key_code != KEY_UNKNOWN) {
179 dbg_hid(PICOLCD_NAME " got key release for %u:%d",
180 data->pressed_keys[j], key_code);
181 input_report_key(data->input_keys, key_code, 0);
182 }
183 input_sync(data->input_keys);
184 data->pressed_keys[j] = 0;
185key_still_down:
186 continue;
187 }
188 return 1;
189}
190
191static int picolcd_check_version(struct hid_device *hdev)
192{
193 struct picolcd_data *data = hid_get_drvdata(hdev);
194 struct picolcd_pending *verinfo;
195 int ret = 0;
196
197 if (!data)
198 return -ENODEV;
199
200 verinfo = picolcd_send_and_wait(hdev, REPORT_VERSION, NULL, 0);
201 if (!verinfo) {
202 hid_err(hdev, "no version response from PicoLCD\n");
203 return -ENODEV;
204 }
205
206 if (verinfo->raw_size == 2) {
207 data->version[0] = verinfo->raw_data[1];
208 data->version[1] = verinfo->raw_data[0];
209 if (data->status & PICOLCD_BOOTLOADER) {
210 hid_info(hdev, "PicoLCD, bootloader version %d.%d\n",
211 verinfo->raw_data[1], verinfo->raw_data[0]);
212 } else {
213 hid_info(hdev, "PicoLCD, firmware version %d.%d\n",
214 verinfo->raw_data[1], verinfo->raw_data[0]);
215 }
216 } else {
217 hid_err(hdev, "confused, got unexpected version response from PicoLCD\n");
218 ret = -EINVAL;
219 }
220 kfree(verinfo);
221 return ret;
222}
223
224/*
225 * Reset our device and wait for answer to VERSION request
226 */
227int picolcd_reset(struct hid_device *hdev)
228{
229 struct picolcd_data *data = hid_get_drvdata(hdev);
230 struct hid_report *report = picolcd_out_report(REPORT_RESET, hdev);
231 unsigned long flags;
232 int error;
233
234 if (!data || !report || report->maxfield != 1)
235 return -ENODEV;
236
237 spin_lock_irqsave(&data->lock, flags);
238 if (hdev->product == USB_DEVICE_ID_PICOLCD_BOOTLOADER)
239 data->status |= PICOLCD_BOOTLOADER;
240
241 /* perform the reset */
242 hid_set_field(report->field[0], 0, 1);
a93ab849
BP
243 if (data->status & PICOLCD_FAILED) {
244 spin_unlock_irqrestore(&data->lock, flags);
245 return -ENODEV;
246 }
fabdbf2f
BP
247 usbhid_submit_report(hdev, report, USB_DIR_OUT);
248 spin_unlock_irqrestore(&data->lock, flags);
249
250 error = picolcd_check_version(hdev);
251 if (error)
252 return error;
253
254 picolcd_resume_lcd(data);
255 picolcd_resume_backlight(data);
256 picolcd_fb_refresh(data);
257 picolcd_leds_set(data);
258 return 0;
259}
260
261/*
262 * The "operation_mode" sysfs attribute
263 */
264static ssize_t picolcd_operation_mode_show(struct device *dev,
265 struct device_attribute *attr, char *buf)
266{
267 struct picolcd_data *data = dev_get_drvdata(dev);
268
269 if (data->status & PICOLCD_BOOTLOADER)
270 return snprintf(buf, PAGE_SIZE, "[bootloader] lcd\n");
271 else
272 return snprintf(buf, PAGE_SIZE, "bootloader [lcd]\n");
273}
274
275static ssize_t picolcd_operation_mode_store(struct device *dev,
276 struct device_attribute *attr, const char *buf, size_t count)
277{
278 struct picolcd_data *data = dev_get_drvdata(dev);
279 struct hid_report *report = NULL;
280 size_t cnt = count;
281 int timeout = data->opmode_delay;
282 unsigned long flags;
283
284 if (cnt >= 3 && strncmp("lcd", buf, 3) == 0) {
285 if (data->status & PICOLCD_BOOTLOADER)
286 report = picolcd_out_report(REPORT_EXIT_FLASHER, data->hdev);
287 buf += 3;
288 cnt -= 3;
289 } else if (cnt >= 10 && strncmp("bootloader", buf, 10) == 0) {
290 if (!(data->status & PICOLCD_BOOTLOADER))
291 report = picolcd_out_report(REPORT_EXIT_KEYBOARD, data->hdev);
292 buf += 10;
293 cnt -= 10;
294 }
295 if (!report)
296 return -EINVAL;
297
298 while (cnt > 0 && (buf[cnt-1] == '\n' || buf[cnt-1] == '\r'))
299 cnt--;
300 if (cnt != 0)
301 return -EINVAL;
302
303 spin_lock_irqsave(&data->lock, flags);
304 hid_set_field(report->field[0], 0, timeout & 0xff);
305 hid_set_field(report->field[0], 1, (timeout >> 8) & 0xff);
306 usbhid_submit_report(data->hdev, report, USB_DIR_OUT);
307 spin_unlock_irqrestore(&data->lock, flags);
308 return count;
309}
310
311static DEVICE_ATTR(operation_mode, 0644, picolcd_operation_mode_show,
312 picolcd_operation_mode_store);
313
314/*
315 * The "operation_mode_delay" sysfs attribute
316 */
317static ssize_t picolcd_operation_mode_delay_show(struct device *dev,
318 struct device_attribute *attr, char *buf)
319{
320 struct picolcd_data *data = dev_get_drvdata(dev);
321
322 return snprintf(buf, PAGE_SIZE, "%hu\n", data->opmode_delay);
323}
324
325static ssize_t picolcd_operation_mode_delay_store(struct device *dev,
326 struct device_attribute *attr, const char *buf, size_t count)
327{
328 struct picolcd_data *data = dev_get_drvdata(dev);
329 unsigned u;
330 if (sscanf(buf, "%u", &u) != 1)
331 return -EINVAL;
332 if (u > 30000)
333 return -EINVAL;
334 else
335 data->opmode_delay = u;
336 return count;
337}
338
339static DEVICE_ATTR(operation_mode_delay, 0644, picolcd_operation_mode_delay_show,
340 picolcd_operation_mode_delay_store);
341
342/*
343 * Handle raw report as sent by device
344 */
345static int picolcd_raw_event(struct hid_device *hdev,
346 struct hid_report *report, u8 *raw_data, int size)
347{
348 struct picolcd_data *data = hid_get_drvdata(hdev);
349 unsigned long flags;
350 int ret = 0;
351
352 if (!data)
353 return 1;
354
355 if (report->id == REPORT_KEY_STATE) {
356 if (data->input_keys)
357 ret = picolcd_raw_keypad(data, report, raw_data+1, size-1);
358 } else if (report->id == REPORT_IR_DATA) {
359 if (data->input_cir)
360 ret = picolcd_raw_cir(data, report, raw_data+1, size-1);
361 } else {
362 spin_lock_irqsave(&data->lock, flags);
363 /*
364 * We let the caller of picolcd_send_and_wait() check if the
365 * report we got is one of the expected ones or not.
366 */
367 if (data->pending) {
368 memcpy(data->pending->raw_data, raw_data+1, size-1);
369 data->pending->raw_size = size-1;
370 data->pending->in_report = report;
371 complete(&data->pending->ready);
372 }
373 spin_unlock_irqrestore(&data->lock, flags);
374 }
375
376 picolcd_debug_raw_event(data, hdev, report, raw_data, size);
377 return 1;
378}
379
380#ifdef CONFIG_PM
381static int picolcd_suspend(struct hid_device *hdev, pm_message_t message)
382{
383 if (PMSG_IS_AUTO(message))
384 return 0;
385
386 picolcd_suspend_backlight(hid_get_drvdata(hdev));
387 dbg_hid(PICOLCD_NAME " device ready for suspend\n");
388 return 0;
389}
390
391static int picolcd_resume(struct hid_device *hdev)
392{
393 int ret;
394 ret = picolcd_resume_backlight(hid_get_drvdata(hdev));
395 if (ret)
396 dbg_hid(PICOLCD_NAME " restoring backlight failed: %d\n", ret);
397 return 0;
398}
399
400static int picolcd_reset_resume(struct hid_device *hdev)
401{
402 int ret;
403 ret = picolcd_reset(hdev);
404 if (ret)
405 dbg_hid(PICOLCD_NAME " resetting our device failed: %d\n", ret);
406 ret = picolcd_fb_reset(hid_get_drvdata(hdev), 0);
407 if (ret)
408 dbg_hid(PICOLCD_NAME " restoring framebuffer content failed: %d\n", ret);
409 ret = picolcd_resume_lcd(hid_get_drvdata(hdev));
410 if (ret)
411 dbg_hid(PICOLCD_NAME " restoring lcd failed: %d\n", ret);
412 ret = picolcd_resume_backlight(hid_get_drvdata(hdev));
413 if (ret)
414 dbg_hid(PICOLCD_NAME " restoring backlight failed: %d\n", ret);
415 picolcd_leds_set(hid_get_drvdata(hdev));
416 return 0;
417}
418#endif
419
420/* initialize keypad input device */
421static int picolcd_init_keys(struct picolcd_data *data,
422 struct hid_report *report)
423{
424 struct hid_device *hdev = data->hdev;
425 struct input_dev *idev;
426 int error, i;
427
428 if (!report)
429 return -ENODEV;
430 if (report->maxfield != 1 || report->field[0]->report_count != 2 ||
431 report->field[0]->report_size != 8) {
432 hid_err(hdev, "unsupported KEY_STATE report\n");
433 return -EINVAL;
434 }
435
436 idev = input_allocate_device();
437 if (idev == NULL) {
438 hid_err(hdev, "failed to allocate input device\n");
439 return -ENOMEM;
440 }
441 input_set_drvdata(idev, hdev);
442 memcpy(data->keycode, def_keymap, sizeof(def_keymap));
443 idev->name = hdev->name;
444 idev->phys = hdev->phys;
445 idev->uniq = hdev->uniq;
446 idev->id.bustype = hdev->bus;
447 idev->id.vendor = hdev->vendor;
448 idev->id.product = hdev->product;
449 idev->id.version = hdev->version;
450 idev->dev.parent = hdev->dev.parent;
451 idev->keycode = &data->keycode;
452 idev->keycodemax = PICOLCD_KEYS;
453 idev->keycodesize = sizeof(data->keycode[0]);
454 input_set_capability(idev, EV_MSC, MSC_SCAN);
455 set_bit(EV_REP, idev->evbit);
456 for (i = 0; i < PICOLCD_KEYS; i++)
457 input_set_capability(idev, EV_KEY, data->keycode[i]);
458 error = input_register_device(idev);
459 if (error) {
460 hid_err(hdev, "error registering the input device\n");
461 input_free_device(idev);
462 return error;
463 }
464 data->input_keys = idev;
465 return 0;
466}
467
468static void picolcd_exit_keys(struct picolcd_data *data)
469{
470 struct input_dev *idev = data->input_keys;
471
472 data->input_keys = NULL;
473 if (idev)
474 input_unregister_device(idev);
475}
476
477static int picolcd_probe_lcd(struct hid_device *hdev, struct picolcd_data *data)
478{
479 int error;
480
481 error = picolcd_check_version(hdev);
482 if (error)
483 return error;
484
485 if (data->version[0] != 0 && data->version[1] != 3)
486 hid_info(hdev, "Device with untested firmware revision, please submit /sys/kernel/debug/hid/%s/rdesc for this device.\n",
487 dev_name(&hdev->dev));
488
489 /* Setup keypad input device */
490 error = picolcd_init_keys(data, picolcd_in_report(REPORT_KEY_STATE, hdev));
491 if (error)
492 goto err;
493
494 /* Setup CIR input device */
495 error = picolcd_init_cir(data, picolcd_in_report(REPORT_IR_DATA, hdev));
496 if (error)
497 goto err;
498
499 /* Set up the framebuffer device */
500 error = picolcd_init_framebuffer(data);
501 if (error)
502 goto err;
503
504 /* Setup lcd class device */
505 error = picolcd_init_lcd(data, picolcd_out_report(REPORT_CONTRAST, hdev));
506 if (error)
507 goto err;
508
509 /* Setup backlight class device */
510 error = picolcd_init_backlight(data, picolcd_out_report(REPORT_BRIGHTNESS, hdev));
511 if (error)
512 goto err;
513
514 /* Setup the LED class devices */
515 error = picolcd_init_leds(data, picolcd_out_report(REPORT_LED_STATE, hdev));
516 if (error)
517 goto err;
518
519 picolcd_init_devfs(data, picolcd_out_report(REPORT_EE_READ, hdev),
520 picolcd_out_report(REPORT_EE_WRITE, hdev),
521 picolcd_out_report(REPORT_READ_MEMORY, hdev),
522 picolcd_out_report(REPORT_WRITE_MEMORY, hdev),
523 picolcd_out_report(REPORT_RESET, hdev));
524 return 0;
525err:
526 picolcd_exit_leds(data);
527 picolcd_exit_backlight(data);
528 picolcd_exit_lcd(data);
529 picolcd_exit_framebuffer(data);
530 picolcd_exit_cir(data);
531 picolcd_exit_keys(data);
532 return error;
533}
534
535static int picolcd_probe_bootloader(struct hid_device *hdev, struct picolcd_data *data)
536{
537 int error;
538
539 error = picolcd_check_version(hdev);
540 if (error)
541 return error;
542
543 if (data->version[0] != 1 && data->version[1] != 0)
544 hid_info(hdev, "Device with untested bootloader revision, please submit /sys/kernel/debug/hid/%s/rdesc for this device.\n",
545 dev_name(&hdev->dev));
546
547 picolcd_init_devfs(data, NULL, NULL,
548 picolcd_out_report(REPORT_BL_READ_MEMORY, hdev),
549 picolcd_out_report(REPORT_BL_WRITE_MEMORY, hdev), NULL);
550 return 0;
551}
552
553static int picolcd_probe(struct hid_device *hdev,
554 const struct hid_device_id *id)
555{
556 struct picolcd_data *data;
557 int error = -ENOMEM;
558
559 dbg_hid(PICOLCD_NAME " hardware probe...\n");
560
561 /*
562 * Let's allocate the picolcd data structure, set some reasonable
563 * defaults, and associate it with the device
564 */
565 data = kzalloc(sizeof(struct picolcd_data), GFP_KERNEL);
566 if (data == NULL) {
567 hid_err(hdev, "can't allocate space for Minibox PicoLCD device data\n");
568 error = -ENOMEM;
569 goto err_no_cleanup;
570 }
571
572 spin_lock_init(&data->lock);
573 mutex_init(&data->mutex);
574 data->hdev = hdev;
575 data->opmode_delay = 5000;
576 if (hdev->product == USB_DEVICE_ID_PICOLCD_BOOTLOADER)
577 data->status |= PICOLCD_BOOTLOADER;
578 hid_set_drvdata(hdev, data);
579
580 /* Parse the device reports and start it up */
581 error = hid_parse(hdev);
582 if (error) {
583 hid_err(hdev, "device report parse failed\n");
584 goto err_cleanup_data;
585 }
586
587 /* We don't use hidinput but hid_hw_start() fails if nothing is
588 * claimed. So spoof claimed input. */
589 hdev->claimed = HID_CLAIMED_INPUT;
590 error = hid_hw_start(hdev, 0);
591 hdev->claimed = 0;
592 if (error) {
593 hid_err(hdev, "hardware start failed\n");
594 goto err_cleanup_data;
595 }
596
597 error = hid_hw_open(hdev);
598 if (error) {
599 hid_err(hdev, "failed to open input interrupt pipe for key and IR events\n");
600 goto err_cleanup_hid_hw;
601 }
602
603 error = device_create_file(&hdev->dev, &dev_attr_operation_mode_delay);
604 if (error) {
605 hid_err(hdev, "failed to create sysfs attributes\n");
606 goto err_cleanup_hid_ll;
607 }
608
609 error = device_create_file(&hdev->dev, &dev_attr_operation_mode);
610 if (error) {
611 hid_err(hdev, "failed to create sysfs attributes\n");
612 goto err_cleanup_sysfs1;
613 }
614
615 if (data->status & PICOLCD_BOOTLOADER)
616 error = picolcd_probe_bootloader(hdev, data);
617 else
618 error = picolcd_probe_lcd(hdev, data);
619 if (error)
620 goto err_cleanup_sysfs2;
621
622 dbg_hid(PICOLCD_NAME " activated and initialized\n");
623 return 0;
624
625err_cleanup_sysfs2:
626 device_remove_file(&hdev->dev, &dev_attr_operation_mode);
627err_cleanup_sysfs1:
628 device_remove_file(&hdev->dev, &dev_attr_operation_mode_delay);
629err_cleanup_hid_ll:
630 hid_hw_close(hdev);
631err_cleanup_hid_hw:
632 hid_hw_stop(hdev);
633err_cleanup_data:
634 kfree(data);
635err_no_cleanup:
636 hid_set_drvdata(hdev, NULL);
637
638 return error;
639}
640
641static void picolcd_remove(struct hid_device *hdev)
642{
643 struct picolcd_data *data = hid_get_drvdata(hdev);
644 unsigned long flags;
645
646 dbg_hid(PICOLCD_NAME " hardware remove...\n");
647 spin_lock_irqsave(&data->lock, flags);
648 data->status |= PICOLCD_FAILED;
649 spin_unlock_irqrestore(&data->lock, flags);
650
651 picolcd_exit_devfs(data);
652 device_remove_file(&hdev->dev, &dev_attr_operation_mode);
653 device_remove_file(&hdev->dev, &dev_attr_operation_mode_delay);
654 hid_hw_close(hdev);
655 hid_hw_stop(hdev);
656 hid_set_drvdata(hdev, NULL);
657
658 /* Shortcut potential pending reply that will never arrive */
659 spin_lock_irqsave(&data->lock, flags);
660 if (data->pending)
661 complete(&data->pending->ready);
662 spin_unlock_irqrestore(&data->lock, flags);
663
664 /* Cleanup LED */
665 picolcd_exit_leds(data);
666 /* Clean up the framebuffer */
667 picolcd_exit_backlight(data);
668 picolcd_exit_lcd(data);
669 picolcd_exit_framebuffer(data);
670 /* Cleanup input */
671 picolcd_exit_cir(data);
672 picolcd_exit_keys(data);
673
674 mutex_destroy(&data->mutex);
675 /* Finally, clean up the picolcd data itself */
676 kfree(data);
677}
678
679static const struct hid_device_id picolcd_devices[] = {
680 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD) },
681 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD_BOOTLOADER) },
682 { }
683};
684MODULE_DEVICE_TABLE(hid, picolcd_devices);
685
686static struct hid_driver picolcd_driver = {
687 .name = "hid-picolcd",
688 .id_table = picolcd_devices,
689 .probe = picolcd_probe,
690 .remove = picolcd_remove,
691 .raw_event = picolcd_raw_event,
692#ifdef CONFIG_PM
693 .suspend = picolcd_suspend,
694 .resume = picolcd_resume,
695 .reset_resume = picolcd_reset_resume,
696#endif
697};
698
699static int __init picolcd_init(void)
700{
701 return hid_register_driver(&picolcd_driver);
702}
703
704static void __exit picolcd_exit(void)
705{
706 hid_unregister_driver(&picolcd_driver);
fabdbf2f
BP
707}
708
709module_init(picolcd_init);
710module_exit(picolcd_exit);
711MODULE_DESCRIPTION("Minibox graphics PicoLCD Driver");
712MODULE_LICENSE("GPL v2");