0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <linux/device.h>
0016 #include <linux/input.h>
0017 #include <linux/hid.h>
0018 #include <linux/module.h>
0019 #include <linux/slab.h>
0020
0021 #include "hid-ids.h"
0022
0023 #define A4_2WHEEL_MOUSE_HACK_7 0x01
0024 #define A4_2WHEEL_MOUSE_HACK_B8 0x02
0025
0026 #define A4_WHEEL_ORIENTATION (HID_UP_GENDESK | 0x000000b8)
0027
0028 struct a4tech_sc {
0029 unsigned long quirks;
0030 unsigned int hw_wheel;
0031 __s32 delayed_value;
0032 };
0033
0034 static int a4_input_mapping(struct hid_device *hdev, struct hid_input *hi,
0035 struct hid_field *field, struct hid_usage *usage,
0036 unsigned long **bit, int *max)
0037 {
0038 struct a4tech_sc *a4 = hid_get_drvdata(hdev);
0039
0040 if (a4->quirks & A4_2WHEEL_MOUSE_HACK_B8 &&
0041 usage->hid == A4_WHEEL_ORIENTATION) {
0042
0043
0044
0045
0046
0047
0048
0049 return -1;
0050 }
0051
0052 return 0;
0053
0054 }
0055
0056 static int a4_input_mapped(struct hid_device *hdev, struct hid_input *hi,
0057 struct hid_field *field, struct hid_usage *usage,
0058 unsigned long **bit, int *max)
0059 {
0060 struct a4tech_sc *a4 = hid_get_drvdata(hdev);
0061
0062 if (usage->type == EV_REL && usage->code == REL_WHEEL_HI_RES) {
0063 set_bit(REL_HWHEEL, *bit);
0064 set_bit(REL_HWHEEL_HI_RES, *bit);
0065 }
0066
0067 if ((a4->quirks & A4_2WHEEL_MOUSE_HACK_7) && usage->hid == 0x00090007)
0068 return -1;
0069
0070 return 0;
0071 }
0072
0073 static int a4_event(struct hid_device *hdev, struct hid_field *field,
0074 struct hid_usage *usage, __s32 value)
0075 {
0076 struct a4tech_sc *a4 = hid_get_drvdata(hdev);
0077 struct input_dev *input;
0078
0079 if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput)
0080 return 0;
0081
0082 input = field->hidinput->input;
0083
0084 if (a4->quirks & A4_2WHEEL_MOUSE_HACK_B8) {
0085 if (usage->type == EV_REL && usage->code == REL_WHEEL_HI_RES) {
0086 a4->delayed_value = value;
0087 return 1;
0088 }
0089
0090 if (usage->hid == A4_WHEEL_ORIENTATION) {
0091 input_event(input, EV_REL, value ? REL_HWHEEL :
0092 REL_WHEEL, a4->delayed_value);
0093 input_event(input, EV_REL, value ? REL_HWHEEL_HI_RES :
0094 REL_WHEEL_HI_RES, a4->delayed_value * 120);
0095 return 1;
0096 }
0097 }
0098
0099 if ((a4->quirks & A4_2WHEEL_MOUSE_HACK_7) && usage->hid == 0x00090007) {
0100 a4->hw_wheel = !!value;
0101 return 1;
0102 }
0103
0104 if (usage->code == REL_WHEEL_HI_RES && a4->hw_wheel) {
0105 input_event(input, usage->type, REL_HWHEEL, value);
0106 input_event(input, usage->type, REL_HWHEEL_HI_RES, value * 120);
0107 return 1;
0108 }
0109
0110 return 0;
0111 }
0112
0113 static int a4_probe(struct hid_device *hdev, const struct hid_device_id *id)
0114 {
0115 struct a4tech_sc *a4;
0116 int ret;
0117
0118 a4 = devm_kzalloc(&hdev->dev, sizeof(*a4), GFP_KERNEL);
0119 if (a4 == NULL) {
0120 hid_err(hdev, "can't alloc device descriptor\n");
0121 return -ENOMEM;
0122 }
0123
0124 a4->quirks = id->driver_data;
0125
0126 hid_set_drvdata(hdev, a4);
0127
0128 ret = hid_parse(hdev);
0129 if (ret) {
0130 hid_err(hdev, "parse failed\n");
0131 return ret;
0132 }
0133
0134 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
0135 if (ret) {
0136 hid_err(hdev, "hw start failed\n");
0137 return ret;
0138 }
0139
0140 return 0;
0141 }
0142
0143 static const struct hid_device_id a4_devices[] = {
0144 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU),
0145 .driver_data = A4_2WHEEL_MOUSE_HACK_7 },
0146 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D),
0147 .driver_data = A4_2WHEEL_MOUSE_HACK_B8 },
0148 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_RP_649),
0149 .driver_data = A4_2WHEEL_MOUSE_HACK_B8 },
0150 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_NB_95),
0151 .driver_data = A4_2WHEEL_MOUSE_HACK_B8 },
0152 { }
0153 };
0154 MODULE_DEVICE_TABLE(hid, a4_devices);
0155
0156 static struct hid_driver a4_driver = {
0157 .name = "a4tech",
0158 .id_table = a4_devices,
0159 .input_mapping = a4_input_mapping,
0160 .input_mapped = a4_input_mapped,
0161 .event = a4_event,
0162 .probe = a4_probe,
0163 };
0164 module_hid_driver(a4_driver);
0165
0166 MODULE_LICENSE("GPL");