diff options
author | Masaki Ota <masaki.ota@jp.alps.com> | 2016-06-22 00:11:08 -0400 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2016-06-23 02:56:36 -0400 |
commit | 819d64e51d6260f8f7ef352cf42fc1ea67a0f7db (patch) | |
tree | 296df27a7463f7fba7cff930ef947cfece46a468 | |
parent | ded69bba564337236a4c0e6b64924b72c86c938d (diff) |
HID: alps: a few cleanups
Remove an unnecessary codes.
Change input_ivent() function to appropriate function.
Add the device ID of "HID_DEVICE_ID_ALPS_U1_DUAL".
[jkosina@suse.cz: removed unnecessary bitshifts of values passed
input_report_key() as spotted by Dmitry]
Signed-off-by: Masaki Ota <masaki.ota@jp.alps.com>
Reviewed-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
-rw-r--r-- | drivers/hid/hid-alps.c | 116 | ||||
-rw-r--r-- | drivers/hid/hid-core.c | 2 | ||||
-rw-r--r-- | drivers/hid/hid-ids.h | 1 |
3 files changed, 50 insertions, 69 deletions
diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c index ff64c92906a6..048befde295a 100644 --- a/drivers/hid/hid-alps.c +++ b/drivers/hid/hid-alps.c | |||
@@ -98,8 +98,6 @@ struct u1_dev { | |||
98 | u32 sp_btn_cnt; | 98 | u32 sp_btn_cnt; |
99 | }; | 99 | }; |
100 | 100 | ||
101 | static struct u1_dev *priv; | ||
102 | |||
103 | static int u1_read_write_register(struct hid_device *hdev, u32 address, | 101 | static int u1_read_write_register(struct hid_device *hdev, u32 address, |
104 | u8 *read_val, u8 write_val, bool read_flag) | 102 | u8 *read_val, u8 write_val, bool read_flag) |
105 | { | 103 | { |
@@ -108,16 +106,10 @@ static int u1_read_write_register(struct hid_device *hdev, u32 address, | |||
108 | u8 *input; | 106 | u8 *input; |
109 | u8 *readbuf; | 107 | u8 *readbuf; |
110 | 108 | ||
111 | input = kzalloc(sizeof(u8)*U1_FEATURE_REPORT_LEN, GFP_KERNEL); | 109 | input = kzalloc(U1_FEATURE_REPORT_LEN, GFP_KERNEL); |
112 | if (!input) | 110 | if (!input) |
113 | return -ENOMEM; | 111 | return -ENOMEM; |
114 | 112 | ||
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; | 113 | input[0] = U1_FEATURE_REPORT_ID; |
122 | if (read_flag) { | 114 | if (read_flag) { |
123 | input[1] = U1_CMD_REGISTER_READ; | 115 | input[1] = U1_CMD_REGISTER_READ; |
@@ -136,8 +128,8 @@ static int u1_read_write_register(struct hid_device *hdev, u32 address, | |||
136 | 128 | ||
137 | input[7] = check_sum; | 129 | input[7] = check_sum; |
138 | ret = hid_hw_raw_request(hdev, U1_FEATURE_REPORT_ID, input, | 130 | ret = hid_hw_raw_request(hdev, U1_FEATURE_REPORT_ID, input, |
139 | sizeof(u8)*U1_FEATURE_REPORT_LEN, HID_FEATURE_REPORT, | 131 | U1_FEATURE_REPORT_LEN, |
140 | HID_REQ_SET_REPORT); | 132 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); |
141 | 133 | ||
142 | if (ret < 0) { | 134 | if (ret < 0) { |
143 | dev_err(&hdev->dev, "failed to read command (%d)\n", ret); | 135 | dev_err(&hdev->dev, "failed to read command (%d)\n", ret); |
@@ -145,8 +137,14 @@ static int u1_read_write_register(struct hid_device *hdev, u32 address, | |||
145 | } | 137 | } |
146 | 138 | ||
147 | if (read_flag) { | 139 | if (read_flag) { |
140 | readbuf = kzalloc(U1_FEATURE_REPORT_LEN, GFP_KERNEL); | ||
141 | if (!readbuf) { | ||
142 | kfree(input); | ||
143 | return -ENOMEM; | ||
144 | } | ||
145 | |||
148 | ret = hid_hw_raw_request(hdev, U1_FEATURE_REPORT_ID, readbuf, | 146 | ret = hid_hw_raw_request(hdev, U1_FEATURE_REPORT_ID, readbuf, |
149 | sizeof(u8)*U1_FEATURE_REPORT_LEN, | 147 | U1_FEATURE_REPORT_LEN, |
150 | HID_FEATURE_REPORT, HID_REQ_GET_REPORT); | 148 | HID_FEATURE_REPORT, HID_REQ_GET_REPORT); |
151 | 149 | ||
152 | if (ret < 0) { | 150 | if (ret < 0) { |
@@ -155,24 +153,23 @@ static int u1_read_write_register(struct hid_device *hdev, u32 address, | |||
155 | } | 153 | } |
156 | 154 | ||
157 | *read_val = readbuf[6]; | 155 | *read_val = readbuf[6]; |
156 | |||
157 | kfree(readbuf); | ||
158 | } | 158 | } |
159 | 159 | ||
160 | kfree(input); | 160 | ret = 0; |
161 | kfree(readbuf); | ||
162 | return 0; | ||
163 | 161 | ||
164 | exit: | 162 | exit: |
165 | kfree(input); | 163 | kfree(input); |
166 | kfree(readbuf); | ||
167 | return ret; | 164 | return ret; |
168 | } | 165 | } |
169 | 166 | ||
170 | static int alps_raw_event(struct hid_device *hdev, | 167 | static int alps_raw_event(struct hid_device *hdev, |
171 | struct hid_report *report, u8 *data, int size) | 168 | struct hid_report *report, u8 *data, int size) |
172 | { | 169 | { |
173 | int x[MAX_TOUCHES], y[MAX_TOUCHES], z[MAX_TOUCHES]; | 170 | unsigned int x, y, z; |
174 | int i, left, right, middle; | 171 | int i; |
175 | short sp_x, sp_y, sp_z; | 172 | short sp_x, sp_y; |
176 | struct u1_dev *hdata = hid_get_drvdata(hdev); | 173 | struct u1_dev *hdata = hid_get_drvdata(hdev); |
177 | 174 | ||
178 | switch (data[0]) { | 175 | switch (data[0]) { |
@@ -182,16 +179,15 @@ static int alps_raw_event(struct hid_device *hdev, | |||
182 | break; | 179 | break; |
183 | case U1_ABSOLUTE_REPORT_ID: | 180 | case U1_ABSOLUTE_REPORT_ID: |
184 | for (i = 0; i < MAX_TOUCHES; i++) { | 181 | for (i = 0; i < MAX_TOUCHES; i++) { |
185 | x[i] = (data[3+(5*i)] | (data[4+(5*i)] << 8)); | 182 | u8 *contact = &data[i * 5]; |
186 | y[i] = (data[5+(5*i)] | (data[6+(5*i)] << 8)); | 183 | |
187 | z[i] = data[7+(5*i)] & 0x7F; | 184 | x = get_unaligned_le16(contact + 3); |
188 | left = data[1] & 0x1; | 185 | y = get_unaligned_le16(contact + 5); |
189 | right = (data[1] & 0x2) >> 1; | 186 | z = contact[7] & 0x7F; |
190 | middle = (data[1] & 0x4) >> 2; | ||
191 | 187 | ||
192 | input_mt_slot(hdata->input, i); | 188 | input_mt_slot(hdata->input, i); |
193 | 189 | ||
194 | if (z[i] != 0) { | 190 | if (z != 0) { |
195 | input_mt_report_slot_state(hdata->input, | 191 | input_mt_report_slot_state(hdata->input, |
196 | MT_TOOL_FINGER, 1); | 192 | MT_TOOL_FINGER, 1); |
197 | } else { | 193 | } else { |
@@ -200,42 +196,43 @@ static int alps_raw_event(struct hid_device *hdev, | |||
200 | break; | 196 | break; |
201 | } | 197 | } |
202 | 198 | ||
203 | input_event(hdata->input, EV_ABS, | 199 | input_report_abs(hdata->input, ABS_MT_POSITION_X, x); |
204 | ABS_MT_POSITION_X, x[i]); | 200 | input_report_abs(hdata->input, ABS_MT_POSITION_Y, y); |
205 | input_event(hdata->input, EV_ABS, | 201 | input_report_abs(hdata->input, ABS_MT_PRESSURE, z); |
206 | ABS_MT_POSITION_Y, y[i]); | 202 | |
207 | input_event(hdata->input, EV_ABS, | ||
208 | ABS_MT_PRESSURE, z[i]); | ||
209 | } | 203 | } |
210 | 204 | ||
211 | input_mt_sync_frame(hdata->input); | 205 | input_mt_sync_frame(hdata->input); |
212 | input_sync(hdata->input); | ||
213 | 206 | ||
214 | input_event(hdata->input, EV_KEY, BTN_LEFT, left); | 207 | input_report_key(hdata->input, BTN_LEFT, |
215 | input_event(hdata->input, EV_KEY, BTN_RIGHT, right); | 208 | data[1] & 0x1); |
216 | input_event(hdata->input, EV_KEY, BTN_MIDDLE, middle); | 209 | input_report_key(hdata->input, BTN_RIGHT, |
210 | (data[1] & 0x2)); | ||
211 | input_report_key(hdata->input, BTN_MIDDLE, | ||
212 | (data[1] & 0x4)); | ||
213 | |||
214 | input_sync(hdata->input); | ||
217 | 215 | ||
218 | return 1; | 216 | return 1; |
219 | 217 | ||
220 | case U1_SP_ABSOLUTE_REPORT_ID: | 218 | case U1_SP_ABSOLUTE_REPORT_ID: |
221 | sp_x = (data[2] | (data[3] << 8)); | 219 | sp_x = get_unaligned_le16(data+2); |
222 | sp_y = (data[4] | (data[5] << 8)); | 220 | sp_y = get_unaligned_le16(data+4); |
223 | sp_z = (data[6] | data[7]) & 0x7FFF; | ||
224 | left = data[1] & 0x1; | ||
225 | right = (data[1] & 0x2) >> 1; | ||
226 | middle = (data[1] & 0x4) >> 2; | ||
227 | 221 | ||
228 | sp_x = sp_x / 8; | 222 | sp_x = sp_x / 8; |
229 | sp_y = sp_y / 8; | 223 | sp_y = sp_y / 8; |
230 | 224 | ||
231 | input_event(priv->input2, EV_REL, REL_X, sp_x); | 225 | input_report_rel(hdata->input2, REL_X, sp_x); |
232 | input_event(priv->input2, EV_REL, REL_Y, sp_y); | 226 | input_report_rel(hdata->input2, REL_Y, sp_y); |
233 | 227 | ||
234 | input_event(priv->input2, EV_KEY, BTN_LEFT, left); | 228 | input_report_key(hdata->input2, BTN_LEFT, |
235 | input_event(priv->input2, EV_KEY, BTN_RIGHT, right); | 229 | data[1] & 0x1); |
236 | input_event(priv->input2, EV_KEY, BTN_MIDDLE, middle); | 230 | input_report_key(hdata->input2, BTN_RIGHT, |
231 | (data[1] & 0x2)); | ||
232 | input_report_key(hdata->input2, BTN_MIDDLE, | ||
233 | (data[1] & 0x4)); | ||
237 | 234 | ||
238 | input_sync(priv->input2); | 235 | input_sync(hdata->input2); |
239 | 236 | ||
240 | return 1; | 237 | return 1; |
241 | } | 238 | } |
@@ -265,15 +262,6 @@ static int alps_input_configured(struct hid_device *hdev, struct hid_input *hi) | |||
265 | int ret; | 262 | int ret; |
266 | int res_x, res_y, i; | 263 | int res_x, res_y, i; |
267 | 264 | ||
268 | /* Check device product ID */ | ||
269 | switch (hdev->product) { | ||
270 | case HID_PRODUCT_ID_U1: | ||
271 | case HID_PRODUCT_ID_U1_DUAL: | ||
272 | break; | ||
273 | default: | ||
274 | return 0; | ||
275 | } | ||
276 | |||
277 | data->input = input; | 265 | data->input = input; |
278 | 266 | ||
279 | hid_dbg(hdev, "Opening low level driver\n"); | 267 | hid_dbg(hdev, "Opening low level driver\n"); |
@@ -393,20 +381,13 @@ static int alps_input_configured(struct hid_device *hdev, struct hid_input *hi) | |||
393 | /* Stick device initialization */ | 381 | /* Stick device initialization */ |
394 | if (devInfo.dev_type & U1_DEVTYPE_SP_SUPPORT) { | 382 | if (devInfo.dev_type & U1_DEVTYPE_SP_SUPPORT) { |
395 | 383 | ||
396 | priv = kzalloc(sizeof(struct u1_dev), GFP_KERNEL); | ||
397 | if (!priv) { | ||
398 | hid_device_io_stop(hdev); | ||
399 | hid_hw_close(hdev); | ||
400 | return -ENOMEM; | ||
401 | } | ||
402 | |||
403 | input2 = input_allocate_device(); | 384 | input2 = input_allocate_device(); |
404 | if (!input2) { | 385 | if (!input2) { |
405 | input_free_device(input2); | 386 | input_free_device(input2); |
406 | goto exit; | 387 | goto exit; |
407 | } | 388 | } |
408 | 389 | ||
409 | priv->input2 = input2; | 390 | data->input2 = input2; |
410 | 391 | ||
411 | devInfo.dev_ctrl |= U1_SP_ABS_MODE; | 392 | devInfo.dev_ctrl |= U1_SP_ABS_MODE; |
412 | ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1, | 393 | ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1, |
@@ -444,7 +425,7 @@ static int alps_input_configured(struct hid_device *hdev, struct hid_input *hi) | |||
444 | __set_bit(INPUT_PROP_POINTER, input2->propbit); | 425 | __set_bit(INPUT_PROP_POINTER, input2->propbit); |
445 | __set_bit(INPUT_PROP_POINTING_STICK, input2->propbit); | 426 | __set_bit(INPUT_PROP_POINTING_STICK, input2->propbit); |
446 | 427 | ||
447 | if (input_register_device(priv->input2)) { | 428 | if (input_register_device(data->input2)) { |
448 | input_free_device(input2); | 429 | input_free_device(input2); |
449 | goto exit; | 430 | goto exit; |
450 | } | 431 | } |
@@ -495,12 +476,11 @@ static int alps_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
495 | static void alps_remove(struct hid_device *hdev) | 476 | static void alps_remove(struct hid_device *hdev) |
496 | { | 477 | { |
497 | hid_hw_stop(hdev); | 478 | hid_hw_stop(hdev); |
498 | kfree(priv); | ||
499 | } | 479 | } |
500 | 480 | ||
501 | static const struct hid_device_id alps_id[] = { | 481 | static const struct hid_device_id alps_id[] = { |
502 | { HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY, | 482 | { HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY, |
503 | USB_VENDOR_ID_ALPS_JP, HID_ANY_ID) }, | 483 | USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1_DUAL) }, |
504 | { } | 484 | { } |
505 | }; | 485 | }; |
506 | MODULE_DEVICE_TABLE(hid, alps_id); | 486 | MODULE_DEVICE_TABLE(hid, alps_id); |
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index 3cdbc4bb7fc6..7f989f696b17 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c | |||
@@ -1772,7 +1772,7 @@ static const struct hid_device_id hid_have_special_driver[] = { | |||
1772 | { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_RP_649) }, | 1772 | { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_RP_649) }, |
1773 | { HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802) }, | 1773 | { HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802) }, |
1774 | { HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0xf705) }, | 1774 | { HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0xf705) }, |
1775 | { HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY, USB_VENDOR_ID_ALPS_JP, HID_ANY_ID) }, | 1775 | { HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY, USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1_DUAL) }, |
1776 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) }, | 1776 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) }, |
1777 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICMOUSE) }, | 1777 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICMOUSE) }, |
1778 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICTRACKPAD) }, | 1778 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICTRACKPAD) }, |
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h index a5a429cbf163..c4f665d4c80c 100644 --- a/drivers/hid/hid-ids.h +++ b/drivers/hid/hid-ids.h | |||
@@ -71,6 +71,7 @@ | |||
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 | 73 | #define USB_VENDOR_ID_ALPS_JP 0x044E |
74 | #define HID_DEVICE_ID_ALPS_U1_DUAL 0x120B | ||
74 | 75 | ||
75 | #define USB_VENDOR_ID_ANTON 0x1130 | 76 | #define USB_VENDOR_ID_ANTON 0x1130 |
76 | #define USB_DEVICE_ID_ANTON_TOUCH_PAD 0x3101 | 77 | #define USB_DEVICE_ID_ANTON_TOUCH_PAD 0x3101 |