20 #include <linux/hid.h>
22 #include <linux/input.h>
32 #include <linux/module.h>
73 hid_warn(hdev,
"No report with id 0x%x found\n",
id);
96 init_completion(&work->
ready);
103 for (i = k = 0; i < report->
maxfield; i++)
104 for (j = 0; j < report->
field[
i]->report_count; j++) {
114 spin_unlock_irqrestore(&data->
lock, flags);
119 spin_unlock_irqrestore(&data->
lock, flags);
138 for (i = 0; i <
size; i++) {
139 unsigned int key_code;
140 if (raw_data[i] == 0)
144 goto key_already_down;
152 key_code = data->
keycode[raw_data[
i]];
157 raw_data[i], key_code);
158 input_report_key(data->
input_keys, key_code, 1);
167 unsigned int key_code;
170 for (i = 0; i <
size; i++)
181 input_report_key(data->
input_keys, key_code, 0);
191 static int picolcd_check_version(
struct hid_device *hdev)
202 hid_err(hdev,
"no version response from PicoLCD\n");
210 hid_info(hdev,
"PicoLCD, bootloader version %d.%d\n",
213 hid_info(hdev,
"PicoLCD, firmware version %d.%d\n",
217 hid_err(hdev,
"confused, got unexpected version response from PicoLCD\n");
234 if (!data || !report || report->
maxfield != 1)
244 spin_unlock_irqrestore(&data->
lock, flags);
248 spin_unlock_irqrestore(&data->
lock, flags);
250 error = picolcd_check_version(hdev);
275 static ssize_t picolcd_operation_mode_store(
struct device *dev,
284 if (cnt >= 3 &&
strncmp(
"lcd", buf, 3) == 0) {
289 }
else if (cnt >= 10 &&
strncmp(
"bootloader", buf, 10) == 0) {
298 while (cnt > 0 && (buf[cnt-1] ==
'\n' || buf[cnt-1] ==
'\r'))
307 spin_unlock_irqrestore(&data->
lock, flags);
312 picolcd_operation_mode_store);
317 static ssize_t picolcd_operation_mode_delay_show(
struct device *dev,
325 static ssize_t picolcd_operation_mode_delay_store(
struct device *dev,
330 if (
sscanf(buf,
"%u", &u) != 1)
339 static DEVICE_ATTR(operation_mode_delay, 0644, picolcd_operation_mode_delay_show,
340 picolcd_operation_mode_delay_store);
345 static int picolcd_raw_event(
struct hid_device *hdev,
357 ret = picolcd_raw_keypad(data, report, raw_data+1, size-1);
368 data->
pending->raw_size = size-1;
372 spin_unlock_irqrestore(&data->
lock, flags);
385 picolcd_suspend_backlight(hid_get_drvdata(hdev));
390 static int picolcd_resume(
struct hid_device *hdev)
399 static int picolcd_reset_resume(
struct hid_device *hdev)
424 struct input_dev *
idev;
429 if (report->
maxfield != 1 || report->
field[0]->report_count != 2 ||
430 report->
field[0]->report_size != 8) {
431 hid_err(hdev,
"unsupported KEY_STATE report\n");
435 idev = input_allocate_device();
437 hid_err(hdev,
"failed to allocate input device\n");
440 input_set_drvdata(idev, hdev);
442 idev->name = hdev->
name;
443 idev->phys = hdev->
phys;
444 idev->uniq = hdev->
uniq;
445 idev->id.bustype = hdev->
bus;
446 idev->id.vendor = hdev->
vendor;
447 idev->id.product = hdev->
product;
448 idev->id.version = hdev->
version;
449 idev->dev.parent = &hdev->
dev;
450 idev->keycode = &data->
keycode;
452 idev->keycodesize =
sizeof(data->
keycode[0]);
457 error = input_register_device(idev);
459 hid_err(hdev,
"error registering the input device\n");
460 input_free_device(idev);
467 static void picolcd_exit_keys(
struct picolcd_data *data)
473 input_unregister_device(idev);
522 picolcd_exit_keys(data);
534 static int picolcd_probe(
struct hid_device *hdev,
548 hid_err(hdev,
"can't allocate space for Minibox PicoLCD device data\n");
559 hid_set_drvdata(hdev, data);
562 error = hid_parse(hdev);
564 hid_err(hdev,
"device report parse failed\n");
565 goto err_cleanup_data;
568 error = hid_hw_start(hdev, 0);
570 hid_err(hdev,
"hardware start failed\n");
571 goto err_cleanup_data;
574 error = hid_hw_open(hdev);
576 hid_err(hdev,
"failed to open input interrupt pipe for key and IR events\n");
577 goto err_cleanup_hid_hw;
582 hid_err(hdev,
"failed to create sysfs attributes\n");
583 goto err_cleanup_hid_ll;
588 hid_err(hdev,
"failed to create sysfs attributes\n");
589 goto err_cleanup_sysfs1;
593 error = picolcd_probe_bootloader(hdev, data);
595 error = picolcd_probe_lcd(hdev, data);
597 goto err_cleanup_sysfs2;
613 hid_set_drvdata(hdev,
NULL);
618 static void picolcd_remove(
struct hid_device *hdev)
626 spin_unlock_irqrestore(&data->
lock, flags);
638 spin_unlock_irqrestore(&data->
lock, flags);
648 picolcd_exit_keys(data);
650 hid_set_drvdata(hdev,
NULL);
664 .name =
"hid-picolcd",
665 .id_table = picolcd_devices,
666 .probe = picolcd_probe,
667 .remove = picolcd_remove,
668 .raw_event = picolcd_raw_event,
670 .suspend = picolcd_suspend,
671 .resume = picolcd_resume,
672 .reset_resume = picolcd_reset_resume,
676 static int __init picolcd_init(
void)
681 static void __exit picolcd_exit(
void)