diff options
author | Masaki Ota <masaki.ota@jp.alps.com> | 2016-06-16 05:45:57 -0400 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2016-06-17 17:12:04 -0400 |
commit | 2562756dde550901c224e3805102bdfc17e7d13a (patch) | |
tree | 39158e659c1f4ca9502ab4fd45dcb4bb2cbb63ad | |
parent | dcc4c2f61cdc7e0ab61b25b8d28205302497a8c4 (diff) |
HID: add Alps I2C HID Touchpad-Stick support
Add support Alps I2C HID Touchpad and Stick device.
Signed-off-by: Masaki Ota <masaki.ota@jp.alps.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
-rw-r--r-- | Documentation/hid/hid-alps.txt | 139 | ||||
-rw-r--r-- | drivers/hid/Kconfig | 8 | ||||
-rw-r--r-- | drivers/hid/Makefile | 1 | ||||
-rw-r--r-- | drivers/hid/hid-alps.c | 525 | ||||
-rw-r--r-- | drivers/hid/hid-ids.h | 2 |
5 files changed, 675 insertions, 0 deletions
diff --git a/Documentation/hid/hid-alps.txt b/Documentation/hid/hid-alps.txt new file mode 100644 index 000000000000..6b02a2447c77 --- /dev/null +++ b/Documentation/hid/hid-alps.txt | |||
@@ -0,0 +1,139 @@ | |||
1 | ALPS HID Touchpad Protocol | ||
2 | ---------------------- | ||
3 | |||
4 | Introduction | ||
5 | ------------ | ||
6 | Currently ALPS HID driver supports U1 Touchpad device. | ||
7 | |||
8 | U1 devuce basic information. | ||
9 | Vender ID 0x044E | ||
10 | Product ID 0x120B | ||
11 | Version ID 0x0121 | ||
12 | |||
13 | |||
14 | HID Descriptor | ||
15 | ------------ | ||
16 | Byte Field Value Notes | ||
17 | 0 wHIDDescLength 001E Length of HID Descriptor : 30 bytes | ||
18 | 2 bcdVersion 0100 Compliant with Version 1.00 | ||
19 | 4 wReportDescLength 00B2 Report Descriptor is 178 Bytes (0x00B2) | ||
20 | 6 wReportDescRegister 0002 Identifier to read Report Descriptor | ||
21 | 8 wInputRegister 0003 Identifier to read Input Report | ||
22 | 10 wMaxInputLength 0053 Input Report is 80 Bytes + 2 | ||
23 | 12 wOutputRegister 0000 Identifier to read Output Report | ||
24 | 14 wMaxOutputLength 0000 No Output Reports | ||
25 | 16 wCommandRegister 0005 Identifier for Command Register | ||
26 | 18 wDataRegister 0006 Identifier for Data Register | ||
27 | 20 wVendorID 044E Vendor ID 0x044E | ||
28 | 22 wProductID 120B Product ID 0x120B | ||
29 | 24 wVersionID 0121 Version 01.21 | ||
30 | 26 RESERVED 0000 RESERVED | ||
31 | |||
32 | |||
33 | Report ID | ||
34 | ------------ | ||
35 | ReportID-1 (Input Reports) (HIDUsage-Mouse) for TP&SP | ||
36 | ReportID-2 (Input Reports) (HIDUsage-keyboard) for TP | ||
37 | ReportID-3 (Input Reports) (Vendor Usage: Max 10 finger data) for TP | ||
38 | ReportID-4 (Input Reports) (Vendor Usage: ON bit data) for GP | ||
39 | ReportID-5 (Feature Reports) Feature Reports | ||
40 | ReportID-6 (Input Reports) (Vendor Usage: StickPointer data) for SP | ||
41 | ReportID-7 (Feature Reports) Flash update (Bootloader) | ||
42 | |||
43 | |||
44 | Data pattern | ||
45 | ------------ | ||
46 | Case1 ReportID_1 TP/SP Relative/Relative | ||
47 | Case2 ReportID_3 TP Absolute | ||
48 | ReportID_6 SP Absolute | ||
49 | |||
50 | |||
51 | Command Read/Write | ||
52 | ------------------ | ||
53 | To read/write to RAM, need to send a commands to the device. | ||
54 | The command format is as below. | ||
55 | |||
56 | DataByte(SET_REPORT) | ||
57 | Byte1 Command Byte | ||
58 | Byte2 Address - Byte 0 (LSB) | ||
59 | Byte3 Address - Byte 1 | ||
60 | Byte4 Address - Byte 2 | ||
61 | Byte5 Address - Byte 3 (MSB) | ||
62 | Byte6 Value Byte | ||
63 | Byte7 Checksum | ||
64 | |||
65 | Command Byte is read=0xD1/write=0xD2 . | ||
66 | Address is read/write RAM address. | ||
67 | Value Byte is writing data when you send the write commands. | ||
68 | When you read RAM, there is no meaning. | ||
69 | |||
70 | DataByte(GET_REPORT) | ||
71 | Byte1 Response Byte | ||
72 | Byte2 Address - Byte 0 (LSB) | ||
73 | Byte3 Address - Byte 1 | ||
74 | Byte4 Address - Byte 2 | ||
75 | Byte5 Address - Byte 3 (MSB) | ||
76 | Byte6 Value Byte | ||
77 | Byte7 Checksum | ||
78 | |||
79 | Read value is stored in Value Byte. | ||
80 | |||
81 | |||
82 | Packet Format | ||
83 | Touchpad data byte | ||
84 | ------------------ | ||
85 | b7 b6 b5 b4 b3 b2 b1 b0 | ||
86 | 1 0 0 SW6 SW5 SW4 SW3 SW2 SW1 | ||
87 | 2 0 0 0 Fcv Fn3 Fn2 Fn1 Fn0 | ||
88 | 3 Xa0_7 Xa0_6 Xa0_5 Xa0_4 Xa0_3 Xa0_2 Xa0_1 Xa0_0 | ||
89 | 4 Xa0_15 Xa0_14 Xa0_13 Xa0_12 Xa0_11 Xa0_10 Xa0_9 Xa0_8 | ||
90 | 5 Ya0_7 Ya0_6 Ya0_5 Ya0_4 Ya0_3 Ya0_2 Ya0_1 Ya0_0 | ||
91 | 6 Ya0_15 Ya0_14 Ya0_13 Ya0_12 Ya0_11 Ya0_10 Ya0_9 Ya0_8 | ||
92 | 7 LFB0 Zs0_6 Zs0_5 Zs0_4 Zs0_3 Zs0_2 Zs0_1 Zs0_0 | ||
93 | |||
94 | 8 Xa1_7 Xa1_6 Xa1_5 Xa1_4 Xa1_3 Xa1_2 Xa1_1 Xa1_0 | ||
95 | 9 Xa1_15 Xa1_14 Xa1_13 Xa1_12 Xa1_11 Xa1_10 Xa1_9 Xa1_8 | ||
96 | 10 Ya1_7 Ya1_6 Ya1_5 Ya1_4 Ya1_3 Ya1_2 Ya1_1 Ya1_0 | ||
97 | 11 Ya1_15 Ya1_14 Ya1_13 Ya1_12 Ya1_11 Ya1_10 Ya1_9 Ya1_8 | ||
98 | 12 LFB1 Zs1_6 Zs1_5 Zs1_4 Zs1_3 Zs1_2 Zs1_1 Zs1_0 | ||
99 | |||
100 | 13 Xa2_7 Xa2_6 Xa2_5 Xa2_4 Xa2_3 Xa2_2 Xa2_1 Xa2_0 | ||
101 | 14 Xa2_15 Xa2_14 Xa2_13 Xa2_12 Xa2_11 Xa2_10 Xa2_9 Xa2_8 | ||
102 | 15 Ya2_7 Ya2_6 Ya2_5 Ya2_4 Ya2_3 Ya2_2 Ya2_1 Ya2_0 | ||
103 | 16 Ya2_15 Ya2_14 Ya2_13 Ya2_12 Ya2_11 Ya2_10 Ya2_9 Ya2_8 | ||
104 | 17 LFB2 Zs2_6 Zs2_5 Zs2_4 Zs2_3 Zs2_2 Zs2_1 Zs2_0 | ||
105 | |||
106 | 18 Xa3_7 Xa3_6 Xa3_5 Xa3_4 Xa3_3 Xa3_2 Xa3_1 Xa3_0 | ||
107 | 19 Xa3_15 Xa3_14 Xa3_13 Xa3_12 Xa3_11 Xa3_10 Xa3_9 Xa3_8 | ||
108 | 20 Ya3_7 Ya3_6 Ya3_5 Ya3_4 Ya3_3 Ya3_2 Ya3_1 Ya3_0 | ||
109 | 21 Ya3_15 Ya3_14 Ya3_13 Ya3_12 Ya3_11 Ya3_10 Ya3_9 Ya3_8 | ||
110 | 22 LFB3 Zs3_6 Zs3_5 Zs3_4 Zs3_3 Zs3_2 Zs3_1 Zs3_0 | ||
111 | |||
112 | 23 Xa4_7 Xa4_6 Xa4_5 Xa4_4 Xa4_3 Xa4_2 Xa4_1 Xa4_0 | ||
113 | 24 Xa4_15 Xa4_14 Xa4_13 Xa4_12 Xa4_11 Xa4_10 Xa4_9 Xa4_8 | ||
114 | 25 Ya4_7 Ya4_6 Ya4_5 Ya4_4 Ya4_3 Ya4_2 Ya4_1 Ya4_0 | ||
115 | 26 Ya4_15 Ya4_14 Ya4_13 Ya4_12 Ya4_11 Ya4_10 Ya4_9 Ya4_8 | ||
116 | 27 LFB4 Zs4_6 Zs4_5 Zs4_4 Zs4_3 Zs4_2 Zs4_1 Zs4_0 | ||
117 | |||
118 | |||
119 | SW1-SW6: SW ON/OFF status | ||
120 | Xan_15-0(16bit):X Absolute data of the "n"th finger | ||
121 | Yan_15-0(16bit):Y Absolute data of the "n"th finger | ||
122 | Zsn_6-0(7bit): Operation area of the "n"th finger | ||
123 | |||
124 | |||
125 | StickPointer data byte | ||
126 | ------------------ | ||
127 | b7 b6 b5 b4 b3 b2 b1 b0 | ||
128 | Byte1 1 1 1 0 1 SW3 SW2 SW1 | ||
129 | Byte2 X7 X6 X5 X4 X3 X2 X1 X0 | ||
130 | Byte3 X15 X14 X13 X12 X11 X10 X9 X8 | ||
131 | Byte4 Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 | ||
132 | Byte5 Y15 Y14 Y13 Y12 Y11 Y10 Y9 Y8 | ||
133 | Byte6 Z7 Z6 Z5 Z4 Z3 Z2 Z1 Z0 | ||
134 | Byte7 T&P Z14 Z13 Z12 Z11 Z10 Z9 Z8 | ||
135 | |||
136 | SW1-SW3: SW ON/OFF status | ||
137 | Xn_15-0(16bit):X Absolute data | ||
138 | Yn_15-0(16bit):Y Absolute data | ||
139 | Zn_14-0(15bit):Z | ||
diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index 5646ca4b95de..a8e480849a32 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig | |||
@@ -936,6 +936,14 @@ config HID_SENSOR_CUSTOM_SENSOR | |||
936 | standard sensors. | 936 | standard sensors. |
937 | Select this config option for custom/generic sensor support. | 937 | Select this config option for custom/generic sensor support. |
938 | 938 | ||
939 | config HID_ALPS | ||
940 | tristate "Alps HID device support" | ||
941 | depends on HID | ||
942 | ---help--- | ||
943 | Support for Alps I2C HID touchpads and StickPointer. | ||
944 | Say Y here if you have a Alps touchpads over i2c-hid or usbhid | ||
945 | and want support for its special functionalities. | ||
946 | |||
939 | endmenu | 947 | endmenu |
940 | 948 | ||
941 | endif # HID | 949 | endif # HID |
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile index a2fb562de748..a55ec2988d38 100644 --- a/drivers/hid/Makefile +++ b/drivers/hid/Makefile | |||
@@ -21,6 +21,7 @@ hid-wiimote-y := hid-wiimote-core.o hid-wiimote-modules.o | |||
21 | hid-wiimote-$(CONFIG_DEBUG_FS) += hid-wiimote-debug.o | 21 | hid-wiimote-$(CONFIG_DEBUG_FS) += hid-wiimote-debug.o |
22 | 22 | ||
23 | obj-$(CONFIG_HID_A4TECH) += hid-a4tech.o | 23 | obj-$(CONFIG_HID_A4TECH) += hid-a4tech.o |
24 | obj-$(CONFIG_HID_ALPS) += hid-alps.o | ||
24 | obj-$(CONFIG_HID_ACRUX) += hid-axff.o | 25 | obj-$(CONFIG_HID_ACRUX) += hid-axff.o |
25 | obj-$(CONFIG_HID_APPLE) += hid-apple.o | 26 | obj-$(CONFIG_HID_APPLE) += hid-apple.o |
26 | obj-$(CONFIG_HID_APPLEIR) += hid-appleir.o | 27 | obj-$(CONFIG_HID_APPLEIR) += hid-appleir.o |
diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c new file mode 100644 index 000000000000..b79c318987a3 --- /dev/null +++ b/drivers/hid/hid-alps.c | |||
@@ -0,0 +1,525 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2016 Masaki Ota <masaki.ota@jp.alps.com> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify it | ||
5 | * under the terms of the GNU General Public License as published by the Free | ||
6 | * Software Foundation; either version 2 of the License, or (at your option) | ||
7 | * any later version. | ||
8 | */ | ||
9 | |||
10 | #include <linux/kernel.h> | ||
11 | #include <linux/hid.h> | ||
12 | #include <linux/input.h> | ||
13 | #include <linux/input/mt.h> | ||
14 | #include <linux/module.h> | ||
15 | #include <asm/unaligned.h> | ||
16 | #include "hid-ids.h" | ||
17 | |||
18 | /* ALPS Device Product ID */ | ||
19 | #define HID_PRODUCT_ID_T3_BTNLESS 0xD0C0 | ||
20 | #define HID_PRODUCT_ID_COSMO 0x1202 | ||
21 | #define HID_PRODUCT_ID_U1_PTP_1 0x1207 | ||
22 | #define HID_PRODUCT_ID_U1 0x1209 | ||
23 | #define HID_PRODUCT_ID_U1_PTP_2 0x120A | ||
24 | #define HID_PRODUCT_ID_U1_DUAL 0x120B | ||
25 | #define HID_PRODUCT_ID_T4_BTNLESS 0x120C | ||
26 | |||
27 | #define DEV_SINGLEPOINT 0x01 | ||
28 | #define DEV_DUALPOINT 0x02 | ||
29 | |||
30 | #define U1_MOUSE_REPORT_ID 0x01 /* Mouse data ReportID */ | ||
31 | #define U1_ABSOLUTE_REPORT_ID 0x03 /* Absolute data ReportID */ | ||
32 | #define U1_FEATURE_REPORT_ID 0x05 /* Feature ReportID */ | ||
33 | #define U1_SP_ABSOLUTE_REPORT_ID 0x06 /* Feature ReportID */ | ||
34 | |||
35 | #define U1_FEATURE_REPORT_LEN 0x08 /* Feature Report Length */ | ||
36 | #define U1_FEATURE_REPORT_LEN_ALL 0x0A | ||
37 | #define U1_CMD_REGISTER_READ 0xD1 | ||
38 | #define U1_CMD_REGISTER_WRITE 0xD2 | ||
39 | |||
40 | #define U1_DEVTYPE_SP_SUPPORT 0x10 /* SP Support */ | ||
41 | #define U1_DISABLE_DEV 0x01 | ||
42 | #define U1_TP_ABS_MODE 0x02 | ||
43 | #define U1_SP_ABS_MODE 0x80 | ||
44 | |||
45 | #define ADDRESS_U1_DEV_CTRL_1 0x00800040 | ||
46 | #define ADDRESS_U1_DEVICE_TYP 0x00800043 | ||
47 | #define ADDRESS_U1_NUM_SENS_X 0x00800047 | ||
48 | #define ADDRESS_U1_NUM_SENS_Y 0x00800048 | ||
49 | #define ADDRESS_U1_PITCH_SENS_X 0x00800049 | ||
50 | #define ADDRESS_U1_PITCH_SENS_Y 0x0080004A | ||
51 | #define ADDRESS_U1_RESO_DWN_ABS 0x0080004E | ||
52 | #define ADDRESS_U1_PAD_BTN 0x00800052 | ||
53 | #define ADDRESS_U1_SP_BTN 0x0080009F | ||
54 | |||
55 | #define MAX_TOUCHES 5 | ||
56 | |||
57 | /** | ||
58 | * struct u1_data | ||
59 | * | ||
60 | * @input: pointer to the kernel input device | ||
61 | * @input2: pointer to the kernel input2 device | ||
62 | * @hdev: pointer to the struct hid_device | ||
63 | * | ||
64 | * @dev_ctrl: device control parameter | ||
65 | * @dev_type: device type | ||
66 | * @sen_line_num_x: number of sensor line of X | ||
67 | * @sen_line_num_y: number of sensor line of Y | ||
68 | * @pitch_x: sensor pitch of X | ||
69 | * @pitch_y: sensor pitch of Y | ||
70 | * @resolution: resolution | ||
71 | * @btn_info: button information | ||
72 | * @x_active_len_mm: active area length of X (mm) | ||
73 | * @y_active_len_mm: active area length of Y (mm) | ||
74 | * @x_max: maximum x coordinate value | ||
75 | * @y_max: maximum y coordinate value | ||
76 | * @btn_cnt: number of buttons | ||
77 | * @sp_btn_cnt: number of stick buttons | ||
78 | */ | ||
79 | struct u1_dev { | ||
80 | struct input_dev *input; | ||
81 | struct input_dev *input2; | ||
82 | struct hid_device *hdev; | ||
83 | |||
84 | u8 dev_ctrl; | ||
85 | u8 dev_type; | ||
86 | u8 sen_line_num_x; | ||
87 | u8 sen_line_num_y; | ||
88 | u8 pitch_x; | ||
89 | u8 pitch_y; | ||
90 | u8 resolution; | ||
91 | u8 btn_info; | ||
92 | u8 sp_btn_info; | ||
93 | u32 x_active_len_mm; | ||
94 | u32 y_active_len_mm; | ||
95 | u32 x_max; | ||
96 | u32 y_max; | ||
97 | u32 btn_cnt; | ||
98 | u32 sp_btn_cnt; | ||
99 | }; | ||
100 | |||
101 | struct u1_dev *priv; | ||
102 | |||
103 | static int u1_read_write_register(struct hid_device *hdev, u32 address, | ||
104 | u8 *read_val, u8 write_val, bool read_flag) | ||
105 | { | ||
106 | int ret, i; | ||
107 | u8 check_sum; | ||
108 | u8 *input; | ||
109 | u8 *readbuf; | ||
110 | |||
111 | input = kzalloc(sizeof(u8)*U1_FEATURE_REPORT_LEN, GFP_KERNEL); | ||
112 | if (!input) | ||
113 | return -ENOMEM; | ||
114 | |||
115 | readbuf = kzalloc(sizeof(u8)*U1_FEATURE_REPORT_LEN, GFP_KERNEL); | ||
116 | if (!readbuf) { | ||
117 | kfree(input); | ||
118 | return -ENOMEM; | ||
119 | } | ||
120 | |||
121 | input[0] = U1_FEATURE_REPORT_ID; | ||
122 | if (read_flag) { | ||
123 | input[1] = U1_CMD_REGISTER_READ; | ||
124 | input[6] = 0x00; | ||
125 | } else { | ||
126 | input[1] = U1_CMD_REGISTER_WRITE; | ||
127 | input[6] = write_val; | ||
128 | } | ||
129 | |||
130 | put_unaligned_le32(address, input + 2); | ||
131 | |||
132 | /* Calculate the checksum */ | ||
133 | check_sum = U1_FEATURE_REPORT_LEN_ALL; | ||
134 | for (i = 0; i < U1_FEATURE_REPORT_LEN - 1; i++) | ||
135 | check_sum += input[i]; | ||
136 | |||
137 | input[7] = check_sum; | ||
138 | ret = hid_hw_raw_request(hdev, U1_FEATURE_REPORT_ID, input, | ||
139 | sizeof(input), HID_FEATURE_REPORT, HID_REQ_SET_REPORT); | ||
140 | |||
141 | if (ret < 0) { | ||
142 | dev_err(&hdev->dev, "failed to read command (%d)\n", ret); | ||
143 | goto exit; | ||
144 | } | ||
145 | |||
146 | if (read_flag) { | ||
147 | ret = hid_hw_raw_request(hdev, U1_FEATURE_REPORT_ID, readbuf, | ||
148 | sizeof(readbuf), HID_FEATURE_REPORT, | ||
149 | HID_REQ_GET_REPORT); | ||
150 | |||
151 | if (ret < 0) { | ||
152 | dev_err(&hdev->dev, "failed read register (%d)\n", ret); | ||
153 | goto exit; | ||
154 | } | ||
155 | |||
156 | *read_val = readbuf[6]; | ||
157 | } | ||
158 | |||
159 | kfree(input); | ||
160 | kfree(readbuf); | ||
161 | return 0; | ||
162 | |||
163 | exit: | ||
164 | kfree(input); | ||
165 | kfree(readbuf); | ||
166 | return ret; | ||
167 | } | ||
168 | |||
169 | static int alps_raw_event(struct hid_device *hdev, | ||
170 | struct hid_report *report, u8 *data, int size) | ||
171 | { | ||
172 | int x[MAX_TOUCHES], y[MAX_TOUCHES], z[MAX_TOUCHES]; | ||
173 | int i, left, right, middle; | ||
174 | short sp_x, sp_y, sp_z; | ||
175 | struct u1_dev *hdata = hid_get_drvdata(hdev); | ||
176 | |||
177 | switch (data[0]) { | ||
178 | case U1_MOUSE_REPORT_ID: | ||
179 | break; | ||
180 | case U1_FEATURE_REPORT_ID: | ||
181 | break; | ||
182 | case U1_ABSOLUTE_REPORT_ID: | ||
183 | for (i = 0; i < MAX_TOUCHES; i++) { | ||
184 | x[i] = (data[3+(5*i)] | (data[4+(5*i)] << 8)); | ||
185 | y[i] = (data[5+(5*i)] | (data[6+(5*i)] << 8)); | ||
186 | z[i] = data[7+(5*i)] & 0x7F; | ||
187 | left = data[1] & 0x1; | ||
188 | right = (data[1] & 0x2) >> 1; | ||
189 | middle = (data[1] & 0x4) >> 2; | ||
190 | |||
191 | input_mt_slot(hdata->input, i); | ||
192 | |||
193 | if (z[i] != 0) { | ||
194 | input_mt_report_slot_state(hdata->input, | ||
195 | MT_TOOL_FINGER, 1); | ||
196 | } else { | ||
197 | input_mt_report_slot_state(hdata->input, | ||
198 | MT_TOOL_FINGER, 0); | ||
199 | break; | ||
200 | } | ||
201 | |||
202 | input_event(hdata->input, EV_ABS, | ||
203 | ABS_MT_POSITION_X, x[i]); | ||
204 | input_event(hdata->input, EV_ABS, | ||
205 | ABS_MT_POSITION_Y, y[i]); | ||
206 | input_event(hdata->input, EV_ABS, | ||
207 | ABS_MT_PRESSURE, z[i]); | ||
208 | } | ||
209 | |||
210 | input_mt_sync_frame(hdata->input); | ||
211 | input_sync(hdata->input); | ||
212 | |||
213 | input_event(hdata->input, EV_KEY, BTN_LEFT, left); | ||
214 | input_event(hdata->input, EV_KEY, BTN_RIGHT, right); | ||
215 | input_event(hdata->input, EV_KEY, BTN_MIDDLE, middle); | ||
216 | |||
217 | return 1; | ||
218 | |||
219 | case U1_SP_ABSOLUTE_REPORT_ID: | ||
220 | sp_x = (data[2] | (data[3] << 8)); | ||
221 | sp_y = (data[4] | (data[5] << 8)); | ||
222 | sp_z = (data[6] | data[7]) & 0x7FFF; | ||
223 | left = data[1] & 0x1; | ||
224 | right = (data[1] & 0x2) >> 1; | ||
225 | middle = (data[1] & 0x4) >> 2; | ||
226 | |||
227 | sp_x = sp_x / 8; | ||
228 | sp_y = sp_y / 8; | ||
229 | |||
230 | input_event(priv->input2, EV_REL, REL_X, sp_x); | ||
231 | input_event(priv->input2, EV_REL, REL_Y, sp_y); | ||
232 | |||
233 | input_event(priv->input2, EV_KEY, BTN_LEFT, left); | ||
234 | input_event(priv->input2, EV_KEY, BTN_RIGHT, right); | ||
235 | input_event(priv->input2, EV_KEY, BTN_MIDDLE, middle); | ||
236 | |||
237 | input_sync(priv->input2); | ||
238 | |||
239 | return 1; | ||
240 | } | ||
241 | |||
242 | return 0; | ||
243 | } | ||
244 | |||
245 | #ifdef CONFIG_PM | ||
246 | static int alps_post_reset(struct hid_device *hdev) | ||
247 | { | ||
248 | return u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1, | ||
249 | NULL, U1_TP_ABS_MODE, false); | ||
250 | } | ||
251 | |||
252 | static int alps_post_resume(struct hid_device *hdev) | ||
253 | { | ||
254 | return u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1, | ||
255 | NULL, U1_TP_ABS_MODE, false); | ||
256 | } | ||
257 | #endif /* CONFIG_PM */ | ||
258 | |||
259 | static int alps_input_configured(struct hid_device *hdev, struct hid_input *hi) | ||
260 | { | ||
261 | struct u1_dev *data = hid_get_drvdata(hdev); | ||
262 | struct input_dev *input = hi->input, *input2; | ||
263 | struct u1_dev devInfo; | ||
264 | int ret; | ||
265 | int res_x, res_y, i; | ||
266 | |||
267 | /* Check device product ID */ | ||
268 | switch (hdev->product) { | ||
269 | case HID_PRODUCT_ID_U1: | ||
270 | case HID_PRODUCT_ID_U1_DUAL: | ||
271 | break; | ||
272 | default: | ||
273 | return 0; | ||
274 | } | ||
275 | |||
276 | data->input = input; | ||
277 | |||
278 | hid_dbg(hdev, "Opening low level driver\n"); | ||
279 | ret = hid_hw_open(hdev); | ||
280 | if (ret) | ||
281 | return ret; | ||
282 | |||
283 | /* Allow incoming hid reports */ | ||
284 | hid_device_io_start(hdev); | ||
285 | |||
286 | /* Device initialization */ | ||
287 | ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1, | ||
288 | &devInfo.dev_ctrl, 0, true); | ||
289 | if (ret < 0) { | ||
290 | dev_err(&hdev->dev, "failed U1_DEV_CTRL_1 (%d)\n", ret); | ||
291 | goto exit; | ||
292 | } | ||
293 | |||
294 | devInfo.dev_ctrl &= ~U1_DISABLE_DEV; | ||
295 | devInfo.dev_ctrl |= U1_TP_ABS_MODE; | ||
296 | ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1, | ||
297 | NULL, devInfo.dev_ctrl, false); | ||
298 | if (ret < 0) { | ||
299 | dev_err(&hdev->dev, "failed to change TP mode (%d)\n", ret); | ||
300 | goto exit; | ||
301 | } | ||
302 | |||
303 | ret = u1_read_write_register(hdev, ADDRESS_U1_NUM_SENS_X, | ||
304 | &devInfo.sen_line_num_x, 0, true); | ||
305 | if (ret < 0) { | ||
306 | dev_err(&hdev->dev, "failed U1_NUM_SENS_X (%d)\n", ret); | ||
307 | goto exit; | ||
308 | } | ||
309 | |||
310 | ret = u1_read_write_register(hdev, ADDRESS_U1_NUM_SENS_Y, | ||
311 | &devInfo.sen_line_num_y, 0, true); | ||
312 | if (ret < 0) { | ||
313 | dev_err(&hdev->dev, "failed U1_NUM_SENS_Y (%d)\n", ret); | ||
314 | goto exit; | ||
315 | } | ||
316 | |||
317 | ret = u1_read_write_register(hdev, ADDRESS_U1_PITCH_SENS_X, | ||
318 | &devInfo.pitch_x, 0, true); | ||
319 | if (ret < 0) { | ||
320 | dev_err(&hdev->dev, "failed U1_PITCH_SENS_X (%d)\n", ret); | ||
321 | goto exit; | ||
322 | } | ||
323 | |||
324 | ret = u1_read_write_register(hdev, ADDRESS_U1_PITCH_SENS_Y, | ||
325 | &devInfo.pitch_y, 0, true); | ||
326 | if (ret < 0) { | ||
327 | dev_err(&hdev->dev, "failed U1_PITCH_SENS_Y (%d)\n", ret); | ||
328 | goto exit; | ||
329 | } | ||
330 | |||
331 | ret = u1_read_write_register(hdev, ADDRESS_U1_RESO_DWN_ABS, | ||
332 | &devInfo.resolution, 0, true); | ||
333 | if (ret < 0) { | ||
334 | dev_err(&hdev->dev, "failed U1_RESO_DWN_ABS (%d)\n", ret); | ||
335 | goto exit; | ||
336 | } | ||
337 | |||
338 | ret = u1_read_write_register(hdev, ADDRESS_U1_PAD_BTN, | ||
339 | &devInfo.btn_info, 0, true); | ||
340 | if (ret < 0) { | ||
341 | dev_err(&hdev->dev, "failed U1_PAD_BTN (%d)\n", ret); | ||
342 | goto exit; | ||
343 | } | ||
344 | |||
345 | /* Check StickPointer device */ | ||
346 | ret = u1_read_write_register(hdev, ADDRESS_U1_DEVICE_TYP, | ||
347 | &devInfo.dev_type, 0, true); | ||
348 | if (ret < 0) { | ||
349 | dev_err(&hdev->dev, "failed U1_DEVICE_TYP (%d)\n", ret); | ||
350 | goto exit; | ||
351 | } | ||
352 | |||
353 | devInfo.x_active_len_mm = | ||
354 | (devInfo.pitch_x * (devInfo.sen_line_num_x - 1)) / 10; | ||
355 | devInfo.y_active_len_mm = | ||
356 | (devInfo.pitch_y * (devInfo.sen_line_num_y - 1)) / 10; | ||
357 | |||
358 | devInfo.x_max = | ||
359 | (devInfo.resolution << 2) * (devInfo.sen_line_num_x - 1); | ||
360 | devInfo.y_max = | ||
361 | (devInfo.resolution << 2) * (devInfo.sen_line_num_y - 1); | ||
362 | |||
363 | __set_bit(EV_ABS, input->evbit); | ||
364 | input_set_abs_params(input, ABS_MT_POSITION_X, 1, devInfo.x_max, 0, 0); | ||
365 | input_set_abs_params(input, ABS_MT_POSITION_Y, 1, devInfo.y_max, 0, 0); | ||
366 | |||
367 | if (devInfo.x_active_len_mm && devInfo.y_active_len_mm) { | ||
368 | res_x = (devInfo.x_max - 1) / devInfo.x_active_len_mm; | ||
369 | res_y = (devInfo.y_max - 1) / devInfo.y_active_len_mm; | ||
370 | |||
371 | input_abs_set_res(input, ABS_MT_POSITION_X, res_x); | ||
372 | input_abs_set_res(input, ABS_MT_POSITION_Y, res_y); | ||
373 | } | ||
374 | |||
375 | input_set_abs_params(input, ABS_MT_PRESSURE, 0, 64, 0, 0); | ||
376 | |||
377 | input_mt_init_slots(input, MAX_TOUCHES, INPUT_MT_POINTER); | ||
378 | |||
379 | __set_bit(EV_KEY, input->evbit); | ||
380 | if ((devInfo.btn_info & 0x0F) == (devInfo.btn_info & 0xF0) >> 4) { | ||
381 | devInfo.btn_cnt = (devInfo.btn_info & 0x0F); | ||
382 | } else { | ||
383 | /* Button pad */ | ||
384 | devInfo.btn_cnt = 1; | ||
385 | __set_bit(INPUT_PROP_BUTTONPAD, input->propbit); | ||
386 | } | ||
387 | |||
388 | for (i = 0; i < devInfo.btn_cnt; i++) | ||
389 | __set_bit(BTN_LEFT + i, input->keybit); | ||
390 | |||
391 | |||
392 | /* Stick device initialization */ | ||
393 | if (devInfo.dev_type & U1_DEVTYPE_SP_SUPPORT) { | ||
394 | |||
395 | priv = kzalloc(sizeof(struct u1_dev), GFP_KERNEL); | ||
396 | if (!priv) { | ||
397 | hid_device_io_stop(hdev); | ||
398 | hid_hw_close(hdev); | ||
399 | return -ENOMEM; | ||
400 | } | ||
401 | |||
402 | input2 = input_allocate_device(); | ||
403 | if (!input2) { | ||
404 | input_free_device(input2); | ||
405 | goto exit; | ||
406 | } | ||
407 | |||
408 | priv->input2 = input2; | ||
409 | |||
410 | devInfo.dev_ctrl |= U1_SP_ABS_MODE; | ||
411 | ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1, | ||
412 | NULL, devInfo.dev_ctrl, false); | ||
413 | if (ret < 0) { | ||
414 | dev_err(&hdev->dev, "failed SP mode (%d)\n", ret); | ||
415 | input_free_device(input2); | ||
416 | goto exit; | ||
417 | } | ||
418 | |||
419 | ret = u1_read_write_register(hdev, ADDRESS_U1_SP_BTN, | ||
420 | &devInfo.sp_btn_info, 0, true); | ||
421 | if (ret < 0) { | ||
422 | dev_err(&hdev->dev, "failed U1_SP_BTN (%d)\n", ret); | ||
423 | input_free_device(input2); | ||
424 | goto exit; | ||
425 | } | ||
426 | |||
427 | input2->phys = input->phys; | ||
428 | input2->name = "DualPoint Stick"; | ||
429 | input2->id.bustype = BUS_I2C; | ||
430 | input2->id.vendor = input->id.vendor; | ||
431 | input2->id.product = input->id.product; | ||
432 | input2->id.version = input->id.version; | ||
433 | input2->dev.parent = input->dev.parent; | ||
434 | |||
435 | __set_bit(EV_KEY, input2->evbit); | ||
436 | devInfo.sp_btn_cnt = (devInfo.sp_btn_info & 0x0F); | ||
437 | for (i = 0; i < devInfo.sp_btn_cnt; i++) | ||
438 | __set_bit(BTN_LEFT + i, input2->keybit); | ||
439 | |||
440 | __set_bit(EV_REL, input2->evbit); | ||
441 | __set_bit(REL_X, input2->relbit); | ||
442 | __set_bit(REL_Y, input2->relbit); | ||
443 | __set_bit(INPUT_PROP_POINTER, input2->propbit); | ||
444 | __set_bit(INPUT_PROP_POINTING_STICK, input2->propbit); | ||
445 | |||
446 | if (input_register_device(priv->input2)) { | ||
447 | input_free_device(input2); | ||
448 | goto exit; | ||
449 | } | ||
450 | } | ||
451 | |||
452 | exit: | ||
453 | hid_device_io_stop(hdev); | ||
454 | hid_hw_close(hdev); | ||
455 | return ret; | ||
456 | } | ||
457 | |||
458 | static int alps_input_mapping(struct hid_device *hdev, | ||
459 | struct hid_input *hi, struct hid_field *field, | ||
460 | struct hid_usage *usage, unsigned long **bit, int *max) | ||
461 | { | ||
462 | return -1; | ||
463 | } | ||
464 | |||
465 | static int alps_probe(struct hid_device *hdev, const struct hid_device_id *id) | ||
466 | { | ||
467 | struct u1_dev *data = NULL; | ||
468 | int ret; | ||
469 | |||
470 | data = devm_kzalloc(&hdev->dev, sizeof(struct u1_dev), GFP_KERNEL); | ||
471 | if (!data) | ||
472 | return -ENOMEM; | ||
473 | |||
474 | data->hdev = hdev; | ||
475 | hid_set_drvdata(hdev, data); | ||
476 | |||
477 | hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS; | ||
478 | |||
479 | ret = hid_parse(hdev); | ||
480 | if (ret) { | ||
481 | hid_err(hdev, "parse failed\n"); | ||
482 | return ret; | ||
483 | } | ||
484 | |||
485 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); | ||
486 | if (ret) { | ||
487 | hid_err(hdev, "hw start failed\n"); | ||
488 | return ret; | ||
489 | } | ||
490 | |||
491 | return 0; | ||
492 | } | ||
493 | |||
494 | static void alps_remove(struct hid_device *hdev) | ||
495 | { | ||
496 | hid_hw_stop(hdev); | ||
497 | kfree(priv); | ||
498 | } | ||
499 | |||
500 | static const struct hid_device_id alps_id[] = { | ||
501 | { HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY, | ||
502 | USB_VENDOR_ID_ALPS_JP, HID_ANY_ID) }, | ||
503 | { } | ||
504 | }; | ||
505 | MODULE_DEVICE_TABLE(hid, alps_id); | ||
506 | |||
507 | static struct hid_driver alps_driver = { | ||
508 | .name = "hid-alps", | ||
509 | .id_table = alps_id, | ||
510 | .probe = alps_probe, | ||
511 | .remove = alps_remove, | ||
512 | .raw_event = alps_raw_event, | ||
513 | .input_mapping = alps_input_mapping, | ||
514 | .input_configured = alps_input_configured, | ||
515 | #ifdef CONFIG_PM | ||
516 | .resume = alps_post_resume, | ||
517 | .reset_resume = alps_post_reset, | ||
518 | #endif | ||
519 | }; | ||
520 | |||
521 | module_hid_driver(alps_driver); | ||
522 | |||
523 | MODULE_AUTHOR("Masaki Ota <masaki.ota@jp.alps.com>"); | ||
524 | MODULE_DESCRIPTION("ALPS HID driver"); | ||
525 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h index 3eec09a134cb..a5a429cbf163 100644 --- a/drivers/hid/hid-ids.h +++ b/drivers/hid/hid-ids.h | |||
@@ -70,6 +70,8 @@ | |||
70 | #define USB_VENDOR_ID_ALPS 0x0433 | 70 | #define USB_VENDOR_ID_ALPS 0x0433 |
71 | #define USB_DEVICE_ID_IBM_GAMEPAD 0x1101 | 71 | #define USB_DEVICE_ID_IBM_GAMEPAD 0x1101 |
72 | 72 | ||
73 | #define USB_VENDOR_ID_ALPS_JP 0x044E | ||
74 | |||
73 | #define USB_VENDOR_ID_ANTON 0x1130 | 75 | #define USB_VENDOR_ID_ANTON 0x1130 |
74 | #define USB_DEVICE_ID_ANTON_TOUCH_PAD 0x3101 | 76 | #define USB_DEVICE_ID_ANTON_TOUCH_PAD 0x3101 |
75 | 77 | ||