0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/device.h>
0011 #include <linux/hid.h>
0012 #include <linux/module.h>
0013 #include <linux/usb.h>
0014
0015 #include "hid-ids.h"
0016 #include "usbhid/usbhid.h"
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 static __u8 holtek_kbd_rdesc_fixed[] = {
0031
0032 0x05, 0x01,
0033 0x09, 0x80,
0034 0xA1, 0x01,
0035 0x85, 0x01,
0036 0x19, 0x81,
0037 0x29, 0x83,
0038 0x15, 0x00,
0039 0x25, 0x01,
0040 0x95, 0x03,
0041 0x75, 0x01,
0042 0x81, 0x02,
0043 0x95, 0x01,
0044 0x75, 0x05,
0045 0x81, 0x01,
0046 0xC0,
0047 0x05, 0x0C,
0048 0x09, 0x01,
0049 0xA1, 0x01,
0050 0x85, 0x02,
0051 0x19, 0x00,
0052 0x2A, 0xFF, 0x2F,
0053 0x15, 0x00,
0054 0x26, 0xFF, 0x2F,
0055 0x95, 0x01,
0056 0x75, 0x10,
0057 0x81, 0x00,
0058 0xC0,
0059 0x05, 0x01,
0060 0x09, 0x06,
0061 0xA1, 0x01,
0062 0x85, 0x03,
0063 0x95, 0x38,
0064 0x75, 0x01,
0065 0x15, 0x00,
0066 0x25, 0x01,
0067 0x05, 0x07,
0068 0x19, 0xE0,
0069 0x29, 0xE7,
0070 0x19, 0x00,
0071 0x29, 0x2F,
0072 0x81, 0x02,
0073 0xC0,
0074 0x05, 0x01,
0075 0x09, 0x06,
0076 0xA1, 0x01,
0077 0x85, 0x04,
0078 0x95, 0x38,
0079 0x75, 0x01,
0080 0x15, 0x00,
0081 0x25, 0x01,
0082 0x05, 0x07,
0083 0x19, 0x30,
0084 0x29, 0x67,
0085 0x81, 0x02,
0086 0xC0,
0087
0088
0089 0x05, 0x01,
0090 0x09, 0x06,
0091 0xA1, 0x01,
0092 0x05, 0x08,
0093 0x19, 0x01,
0094 0x29, 0x03,
0095 0x15, 0x00,
0096 0x25, 0x01,
0097 0x75, 0x01,
0098 0x95, 0x03,
0099 0x91, 0x02,
0100 0x95, 0x05,
0101 0x91, 0x01,
0102 0xC0,
0103 };
0104
0105 static __u8 *holtek_kbd_report_fixup(struct hid_device *hdev, __u8 *rdesc,
0106 unsigned int *rsize)
0107 {
0108 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
0109
0110 if (intf->cur_altsetting->desc.bInterfaceNumber == 1) {
0111 rdesc = holtek_kbd_rdesc_fixed;
0112 *rsize = sizeof(holtek_kbd_rdesc_fixed);
0113 }
0114 return rdesc;
0115 }
0116
0117 static int holtek_kbd_input_event(struct input_dev *dev, unsigned int type,
0118 unsigned int code,
0119 int value)
0120 {
0121 struct hid_device *hid = input_get_drvdata(dev);
0122 struct usb_device *usb_dev = hid_to_usb_dev(hid);
0123
0124
0125 struct usb_interface *boot_interface = usb_ifnum_to_if(usb_dev, 0);
0126 struct hid_device *boot_hid;
0127 struct hid_input *boot_hid_input;
0128
0129 if (unlikely(boot_interface == NULL))
0130 return -ENODEV;
0131
0132 boot_hid = usb_get_intfdata(boot_interface);
0133 boot_hid_input = list_first_entry(&boot_hid->inputs,
0134 struct hid_input, list);
0135
0136 return boot_hid_input->input->event(boot_hid_input->input, type, code,
0137 value);
0138 }
0139
0140 static int holtek_kbd_probe(struct hid_device *hdev,
0141 const struct hid_device_id *id)
0142 {
0143 struct usb_interface *intf;
0144 int ret;
0145
0146 if (!hid_is_usb(hdev))
0147 return -EINVAL;
0148
0149 ret = hid_parse(hdev);
0150 if (!ret)
0151 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
0152
0153 intf = to_usb_interface(hdev->dev.parent);
0154 if (!ret && intf->cur_altsetting->desc.bInterfaceNumber == 1) {
0155 struct hid_input *hidinput;
0156 list_for_each_entry(hidinput, &hdev->inputs, list) {
0157 hidinput->input->event = holtek_kbd_input_event;
0158 }
0159 }
0160
0161 return ret;
0162 }
0163
0164 static const struct hid_device_id holtek_kbd_devices[] = {
0165 { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
0166 USB_DEVICE_ID_HOLTEK_ALT_KEYBOARD) },
0167 { }
0168 };
0169 MODULE_DEVICE_TABLE(hid, holtek_kbd_devices);
0170
0171 static struct hid_driver holtek_kbd_driver = {
0172 .name = "holtek_kbd",
0173 .id_table = holtek_kbd_devices,
0174 .report_fixup = holtek_kbd_report_fixup,
0175 .probe = holtek_kbd_probe
0176 };
0177 module_hid_driver(holtek_kbd_driver);
0178
0179 MODULE_LICENSE("GPL");