Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 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 | |
Masaki Ota | 73196eb | 2017-10-06 11:53:17 +0900 | [diff] [blame] | 55 | #define T4_INPUT_REPORT_LEN sizeof(struct t4_input_report) |
| 56 | #define T4_FEATURE_REPORT_LEN T4_INPUT_REPORT_LEN |
| 57 | #define T4_FEATURE_REPORT_ID 7 |
| 58 | #define T4_CMD_REGISTER_READ 0x08 |
| 59 | #define T4_CMD_REGISTER_WRITE 0x07 |
| 60 | |
| 61 | #define T4_ADDRESS_BASE 0xC2C0 |
| 62 | #define PRM_SYS_CONFIG_1 (T4_ADDRESS_BASE + 0x0002) |
| 63 | #define T4_PRM_FEED_CONFIG_1 (T4_ADDRESS_BASE + 0x0004) |
| 64 | #define T4_PRM_FEED_CONFIG_4 (T4_ADDRESS_BASE + 0x001A) |
| 65 | #define T4_PRM_ID_CONFIG_3 (T4_ADDRESS_BASE + 0x00B0) |
| 66 | |
| 67 | |
| 68 | #define T4_FEEDCFG4_ADVANCED_ABS_ENABLE 0x01 |
| 69 | #define T4_I2C_ABS 0x78 |
| 70 | |
| 71 | #define T4_COUNT_PER_ELECTRODE 256 |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 72 | #define MAX_TOUCHES 5 |
| 73 | |
Masaki Ota | 73196eb | 2017-10-06 11:53:17 +0900 | [diff] [blame] | 74 | enum dev_num { |
| 75 | U1, |
| 76 | T4, |
| 77 | UNKNOWN, |
| 78 | }; |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 79 | /** |
| 80 | * struct u1_data |
| 81 | * |
| 82 | * @input: pointer to the kernel input device |
| 83 | * @input2: pointer to the kernel input2 device |
| 84 | * @hdev: pointer to the struct hid_device |
| 85 | * |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 86 | * @dev_type: device type |
Masaki Ota | 5992262 | 2017-10-06 11:53:16 +0900 | [diff] [blame] | 87 | * @max_fingers: total number of fingers |
| 88 | * @has_sp: boolean of sp existense |
| 89 | * @sp_btn_info: button information |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 90 | * @x_active_len_mm: active area length of X (mm) |
| 91 | * @y_active_len_mm: active area length of Y (mm) |
| 92 | * @x_max: maximum x coordinate value |
| 93 | * @y_max: maximum y coordinate value |
Masaki Ota | c7083d3 | 2017-10-06 11:53:15 +0900 | [diff] [blame] | 94 | * @x_min: minimum x coordinate value |
| 95 | * @y_min: minimum y coordinate value |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 96 | * @btn_cnt: number of buttons |
| 97 | * @sp_btn_cnt: number of stick buttons |
| 98 | */ |
Masaki Ota | 73196eb | 2017-10-06 11:53:17 +0900 | [diff] [blame] | 99 | struct alps_dev { |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 100 | struct input_dev *input; |
| 101 | struct input_dev *input2; |
| 102 | struct hid_device *hdev; |
| 103 | |
Masaki Ota | 73196eb | 2017-10-06 11:53:17 +0900 | [diff] [blame] | 104 | enum dev_num dev_type; |
Masaki Ota | 5992262 | 2017-10-06 11:53:16 +0900 | [diff] [blame] | 105 | u8 max_fingers; |
| 106 | u8 has_sp; |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 107 | u8 sp_btn_info; |
| 108 | u32 x_active_len_mm; |
| 109 | u32 y_active_len_mm; |
| 110 | u32 x_max; |
| 111 | u32 y_max; |
Masaki Ota | c7083d3 | 2017-10-06 11:53:15 +0900 | [diff] [blame] | 112 | u32 x_min; |
| 113 | u32 y_min; |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 114 | u32 btn_cnt; |
| 115 | u32 sp_btn_cnt; |
| 116 | }; |
| 117 | |
Masaki Ota | 73196eb | 2017-10-06 11:53:17 +0900 | [diff] [blame] | 118 | struct t4_contact_data { |
| 119 | u8 palm; |
| 120 | u8 x_lo; |
| 121 | u8 x_hi; |
| 122 | u8 y_lo; |
| 123 | u8 y_hi; |
| 124 | }; |
| 125 | |
| 126 | struct t4_input_report { |
| 127 | u8 reportID; |
| 128 | u8 numContacts; |
| 129 | struct t4_contact_data contact[5]; |
| 130 | u8 button; |
| 131 | u8 track[5]; |
| 132 | u8 zx[5], zy[5]; |
| 133 | u8 palmTime[5]; |
| 134 | u8 kilroy; |
| 135 | u16 timeStamp; |
| 136 | }; |
| 137 | |
| 138 | static u16 t4_calc_check_sum(u8 *buffer, |
| 139 | unsigned long offset, unsigned long length) |
| 140 | { |
| 141 | u16 sum1 = 0xFF, sum2 = 0xFF; |
| 142 | unsigned long i = 0; |
| 143 | |
| 144 | if (offset + length >= 50) |
| 145 | return 0; |
| 146 | |
| 147 | while (length > 0) { |
| 148 | u32 tlen = length > 20 ? 20 : length; |
| 149 | |
| 150 | length -= tlen; |
| 151 | |
| 152 | do { |
| 153 | sum1 += buffer[offset + i]; |
| 154 | sum2 += sum1; |
| 155 | i++; |
| 156 | } while (--tlen > 0); |
| 157 | |
| 158 | sum1 = (sum1 & 0xFF) + (sum1 >> 8); |
| 159 | sum2 = (sum2 & 0xFF) + (sum2 >> 8); |
| 160 | } |
| 161 | |
| 162 | sum1 = (sum1 & 0xFF) + (sum1 >> 8); |
| 163 | sum2 = (sum2 & 0xFF) + (sum2 >> 8); |
| 164 | |
| 165 | return(sum2 << 8 | sum1); |
| 166 | } |
| 167 | |
| 168 | static int t4_read_write_register(struct hid_device *hdev, u32 address, |
| 169 | u8 *read_val, u8 write_val, bool read_flag) |
| 170 | { |
| 171 | int ret; |
| 172 | u16 check_sum; |
| 173 | u8 *input; |
Christophe JAILLET | edb6cb3 | 2018-03-19 21:53:27 +0100 | [diff] [blame] | 174 | u8 *readbuf = NULL; |
Masaki Ota | 73196eb | 2017-10-06 11:53:17 +0900 | [diff] [blame] | 175 | |
| 176 | input = kzalloc(T4_FEATURE_REPORT_LEN, GFP_KERNEL); |
| 177 | if (!input) |
| 178 | return -ENOMEM; |
| 179 | |
| 180 | input[0] = T4_FEATURE_REPORT_ID; |
| 181 | if (read_flag) { |
| 182 | input[1] = T4_CMD_REGISTER_READ; |
| 183 | input[8] = 0x00; |
| 184 | } else { |
| 185 | input[1] = T4_CMD_REGISTER_WRITE; |
| 186 | input[8] = write_val; |
| 187 | } |
| 188 | put_unaligned_le32(address, input + 2); |
| 189 | input[6] = 1; |
| 190 | input[7] = 0; |
| 191 | |
| 192 | /* Calculate the checksum */ |
| 193 | check_sum = t4_calc_check_sum(input, 1, 8); |
| 194 | input[9] = (u8)check_sum; |
| 195 | input[10] = (u8)(check_sum >> 8); |
| 196 | input[11] = 0; |
| 197 | |
| 198 | ret = hid_hw_raw_request(hdev, T4_FEATURE_REPORT_ID, input, |
| 199 | T4_FEATURE_REPORT_LEN, |
| 200 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); |
| 201 | |
| 202 | if (ret < 0) { |
| 203 | dev_err(&hdev->dev, "failed to read command (%d)\n", ret); |
| 204 | goto exit; |
| 205 | } |
| 206 | |
Masaki Ota | 73196eb | 2017-10-06 11:53:17 +0900 | [diff] [blame] | 207 | if (read_flag) { |
Christophe JAILLET | edb6cb3 | 2018-03-19 21:53:27 +0100 | [diff] [blame] | 208 | readbuf = kzalloc(T4_FEATURE_REPORT_LEN, GFP_KERNEL); |
Masaki Ota | 73196eb | 2017-10-06 11:53:17 +0900 | [diff] [blame] | 209 | if (!readbuf) { |
| 210 | ret = -ENOMEM; |
| 211 | goto exit; |
| 212 | } |
| 213 | |
| 214 | ret = hid_hw_raw_request(hdev, T4_FEATURE_REPORT_ID, readbuf, |
| 215 | T4_FEATURE_REPORT_LEN, |
| 216 | HID_FEATURE_REPORT, HID_REQ_GET_REPORT); |
| 217 | if (ret < 0) { |
| 218 | dev_err(&hdev->dev, "failed read register (%d)\n", ret); |
| 219 | goto exit_readbuf; |
| 220 | } |
| 221 | |
Christophe JAILLET | 605f077 | 2018-03-19 21:53:26 +0100 | [diff] [blame] | 222 | ret = -EINVAL; |
| 223 | |
Masaki Ota | 73196eb | 2017-10-06 11:53:17 +0900 | [diff] [blame] | 224 | if (*(u32 *)&readbuf[6] != address) { |
| 225 | dev_err(&hdev->dev, "read register address error (%x,%x)\n", |
Christophe JAILLET | a317e55 | 2018-03-19 21:53:29 +0100 | [diff] [blame] | 226 | *(u32 *)&readbuf[6], address); |
Masaki Ota | 73196eb | 2017-10-06 11:53:17 +0900 | [diff] [blame] | 227 | goto exit_readbuf; |
| 228 | } |
| 229 | |
| 230 | if (*(u16 *)&readbuf[10] != 1) { |
| 231 | dev_err(&hdev->dev, "read register size error (%x)\n", |
Christophe JAILLET | a317e55 | 2018-03-19 21:53:29 +0100 | [diff] [blame] | 232 | *(u16 *)&readbuf[10]); |
Masaki Ota | 73196eb | 2017-10-06 11:53:17 +0900 | [diff] [blame] | 233 | goto exit_readbuf; |
| 234 | } |
| 235 | |
| 236 | check_sum = t4_calc_check_sum(readbuf, 6, 7); |
| 237 | if (*(u16 *)&readbuf[13] != check_sum) { |
| 238 | dev_err(&hdev->dev, "read register checksum error (%x,%x)\n", |
Christophe JAILLET | a317e55 | 2018-03-19 21:53:29 +0100 | [diff] [blame] | 239 | *(u16 *)&readbuf[13], check_sum); |
Masaki Ota | 73196eb | 2017-10-06 11:53:17 +0900 | [diff] [blame] | 240 | goto exit_readbuf; |
| 241 | } |
| 242 | |
| 243 | *read_val = readbuf[12]; |
| 244 | } |
| 245 | |
| 246 | ret = 0; |
| 247 | |
| 248 | exit_readbuf: |
| 249 | kfree(readbuf); |
| 250 | exit: |
| 251 | kfree(input); |
| 252 | return ret; |
| 253 | } |
| 254 | |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 255 | static int u1_read_write_register(struct hid_device *hdev, u32 address, |
| 256 | u8 *read_val, u8 write_val, bool read_flag) |
| 257 | { |
| 258 | int ret, i; |
| 259 | u8 check_sum; |
| 260 | u8 *input; |
| 261 | u8 *readbuf; |
| 262 | |
Masaki Ota | 819d64e | 2016-06-22 13:11:08 +0900 | [diff] [blame] | 263 | input = kzalloc(U1_FEATURE_REPORT_LEN, GFP_KERNEL); |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 264 | if (!input) |
| 265 | return -ENOMEM; |
| 266 | |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 267 | input[0] = U1_FEATURE_REPORT_ID; |
| 268 | if (read_flag) { |
| 269 | input[1] = U1_CMD_REGISTER_READ; |
| 270 | input[6] = 0x00; |
| 271 | } else { |
| 272 | input[1] = U1_CMD_REGISTER_WRITE; |
| 273 | input[6] = write_val; |
| 274 | } |
| 275 | |
| 276 | put_unaligned_le32(address, input + 2); |
| 277 | |
| 278 | /* Calculate the checksum */ |
| 279 | check_sum = U1_FEATURE_REPORT_LEN_ALL; |
| 280 | for (i = 0; i < U1_FEATURE_REPORT_LEN - 1; i++) |
| 281 | check_sum += input[i]; |
| 282 | |
| 283 | input[7] = check_sum; |
| 284 | ret = hid_hw_raw_request(hdev, U1_FEATURE_REPORT_ID, input, |
Masaki Ota | 819d64e | 2016-06-22 13:11:08 +0900 | [diff] [blame] | 285 | U1_FEATURE_REPORT_LEN, |
| 286 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 287 | |
| 288 | if (ret < 0) { |
| 289 | dev_err(&hdev->dev, "failed to read command (%d)\n", ret); |
| 290 | goto exit; |
| 291 | } |
| 292 | |
| 293 | if (read_flag) { |
Masaki Ota | 819d64e | 2016-06-22 13:11:08 +0900 | [diff] [blame] | 294 | readbuf = kzalloc(U1_FEATURE_REPORT_LEN, GFP_KERNEL); |
| 295 | if (!readbuf) { |
Axel Lin | 7ee2eaa | 2016-09-11 12:09:01 +0800 | [diff] [blame] | 296 | ret = -ENOMEM; |
| 297 | goto exit; |
Masaki Ota | 819d64e | 2016-06-22 13:11:08 +0900 | [diff] [blame] | 298 | } |
| 299 | |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 300 | ret = hid_hw_raw_request(hdev, U1_FEATURE_REPORT_ID, readbuf, |
Masaki Ota | 819d64e | 2016-06-22 13:11:08 +0900 | [diff] [blame] | 301 | U1_FEATURE_REPORT_LEN, |
Jiri Kosina | 63b3a7d | 2016-06-20 11:16:18 +0200 | [diff] [blame] | 302 | HID_FEATURE_REPORT, HID_REQ_GET_REPORT); |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 303 | |
| 304 | if (ret < 0) { |
| 305 | dev_err(&hdev->dev, "failed read register (%d)\n", ret); |
Axel Lin | 7ee2eaa | 2016-09-11 12:09:01 +0800 | [diff] [blame] | 306 | kfree(readbuf); |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 307 | goto exit; |
| 308 | } |
| 309 | |
| 310 | *read_val = readbuf[6]; |
Masaki Ota | 819d64e | 2016-06-22 13:11:08 +0900 | [diff] [blame] | 311 | |
| 312 | kfree(readbuf); |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 313 | } |
| 314 | |
Masaki Ota | 819d64e | 2016-06-22 13:11:08 +0900 | [diff] [blame] | 315 | ret = 0; |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 316 | |
| 317 | exit: |
| 318 | kfree(input); |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 319 | return ret; |
| 320 | } |
| 321 | |
Masaki Ota | 73196eb | 2017-10-06 11:53:17 +0900 | [diff] [blame] | 322 | static int t4_raw_event(struct alps_dev *hdata, u8 *data, int size) |
| 323 | { |
| 324 | unsigned int x, y, z; |
| 325 | int i; |
| 326 | struct t4_input_report *p_report = (struct t4_input_report *)data; |
| 327 | |
| 328 | if (!data) |
| 329 | return 0; |
| 330 | for (i = 0; i < hdata->max_fingers; i++) { |
| 331 | x = p_report->contact[i].x_hi << 8 | p_report->contact[i].x_lo; |
| 332 | y = p_report->contact[i].y_hi << 8 | p_report->contact[i].y_lo; |
| 333 | y = hdata->y_max - y + hdata->y_min; |
| 334 | z = (p_report->contact[i].palm < 0x80 && |
| 335 | p_report->contact[i].palm > 0) * 62; |
| 336 | if (x == 0xffff) { |
| 337 | x = 0; |
| 338 | y = 0; |
| 339 | z = 0; |
| 340 | } |
| 341 | input_mt_slot(hdata->input, i); |
| 342 | |
| 343 | input_mt_report_slot_state(hdata->input, |
| 344 | MT_TOOL_FINGER, z != 0); |
| 345 | |
| 346 | if (!z) |
| 347 | continue; |
| 348 | |
| 349 | input_report_abs(hdata->input, ABS_MT_POSITION_X, x); |
| 350 | input_report_abs(hdata->input, ABS_MT_POSITION_Y, y); |
| 351 | input_report_abs(hdata->input, ABS_MT_PRESSURE, z); |
| 352 | } |
| 353 | input_mt_sync_frame(hdata->input); |
| 354 | |
| 355 | input_report_key(hdata->input, BTN_LEFT, p_report->button); |
| 356 | |
| 357 | input_sync(hdata->input); |
| 358 | return 1; |
| 359 | } |
| 360 | |
| 361 | static int u1_raw_event(struct alps_dev *hdata, u8 *data, int size) |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 362 | { |
Masaki Ota | 819d64e | 2016-06-22 13:11:08 +0900 | [diff] [blame] | 363 | unsigned int x, y, z; |
| 364 | int i; |
| 365 | short sp_x, sp_y; |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 366 | |
Masaki Ota | 73196eb | 2017-10-06 11:53:17 +0900 | [diff] [blame] | 367 | if (!data) |
| 368 | return 0; |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 369 | switch (data[0]) { |
| 370 | case U1_MOUSE_REPORT_ID: |
| 371 | break; |
| 372 | case U1_FEATURE_REPORT_ID: |
| 373 | break; |
| 374 | case U1_ABSOLUTE_REPORT_ID: |
Masaki Ota | 73196eb | 2017-10-06 11:53:17 +0900 | [diff] [blame] | 375 | for (i = 0; i < hdata->max_fingers; i++) { |
Masaki Ota | 819d64e | 2016-06-22 13:11:08 +0900 | [diff] [blame] | 376 | u8 *contact = &data[i * 5]; |
| 377 | |
| 378 | x = get_unaligned_le16(contact + 3); |
| 379 | y = get_unaligned_le16(contact + 5); |
| 380 | z = contact[7] & 0x7F; |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 381 | |
| 382 | input_mt_slot(hdata->input, i); |
| 383 | |
Masaki Ota | 819d64e | 2016-06-22 13:11:08 +0900 | [diff] [blame] | 384 | if (z != 0) { |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 385 | input_mt_report_slot_state(hdata->input, |
| 386 | MT_TOOL_FINGER, 1); |
Masaki Ota | 9a54cf4 | 2016-09-27 14:04:37 +0900 | [diff] [blame] | 387 | input_report_abs(hdata->input, |
| 388 | ABS_MT_POSITION_X, x); |
| 389 | input_report_abs(hdata->input, |
| 390 | ABS_MT_POSITION_Y, y); |
| 391 | input_report_abs(hdata->input, |
| 392 | ABS_MT_PRESSURE, z); |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 393 | } else { |
| 394 | input_mt_report_slot_state(hdata->input, |
| 395 | MT_TOOL_FINGER, 0); |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 396 | } |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | input_mt_sync_frame(hdata->input); |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 400 | |
Masaki Ota | 819d64e | 2016-06-22 13:11:08 +0900 | [diff] [blame] | 401 | input_report_key(hdata->input, BTN_LEFT, |
| 402 | data[1] & 0x1); |
| 403 | input_report_key(hdata->input, BTN_RIGHT, |
| 404 | (data[1] & 0x2)); |
| 405 | input_report_key(hdata->input, BTN_MIDDLE, |
| 406 | (data[1] & 0x4)); |
| 407 | |
| 408 | input_sync(hdata->input); |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 409 | |
| 410 | return 1; |
| 411 | |
| 412 | case U1_SP_ABSOLUTE_REPORT_ID: |
Masaki Ota | 819d64e | 2016-06-22 13:11:08 +0900 | [diff] [blame] | 413 | sp_x = get_unaligned_le16(data+2); |
| 414 | sp_y = get_unaligned_le16(data+4); |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 415 | |
| 416 | sp_x = sp_x / 8; |
| 417 | sp_y = sp_y / 8; |
| 418 | |
Masaki Ota | 819d64e | 2016-06-22 13:11:08 +0900 | [diff] [blame] | 419 | input_report_rel(hdata->input2, REL_X, sp_x); |
| 420 | input_report_rel(hdata->input2, REL_Y, sp_y); |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 421 | |
Masaki Ota | 819d64e | 2016-06-22 13:11:08 +0900 | [diff] [blame] | 422 | input_report_key(hdata->input2, BTN_LEFT, |
| 423 | data[1] & 0x1); |
| 424 | input_report_key(hdata->input2, BTN_RIGHT, |
| 425 | (data[1] & 0x2)); |
| 426 | input_report_key(hdata->input2, BTN_MIDDLE, |
| 427 | (data[1] & 0x4)); |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 428 | |
Masaki Ota | 819d64e | 2016-06-22 13:11:08 +0900 | [diff] [blame] | 429 | input_sync(hdata->input2); |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 430 | |
| 431 | return 1; |
| 432 | } |
| 433 | |
| 434 | return 0; |
| 435 | } |
| 436 | |
Masaki Ota | 73196eb | 2017-10-06 11:53:17 +0900 | [diff] [blame] | 437 | static int alps_raw_event(struct hid_device *hdev, |
| 438 | struct hid_report *report, u8 *data, int size) |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 439 | { |
Masaki Ota | 73196eb | 2017-10-06 11:53:17 +0900 | [diff] [blame] | 440 | int ret = 0; |
| 441 | struct alps_dev *hdata = hid_get_drvdata(hdev); |
| 442 | |
| 443 | switch (hdev->product) { |
| 444 | case HID_PRODUCT_ID_T4_BTNLESS: |
| 445 | ret = t4_raw_event(hdata, data, size); |
| 446 | break; |
| 447 | default: |
| 448 | ret = u1_raw_event(hdata, data, size); |
| 449 | break; |
| 450 | } |
| 451 | return ret; |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 452 | } |
| 453 | |
Masaki Ota | 73196eb | 2017-10-06 11:53:17 +0900 | [diff] [blame] | 454 | static int __maybe_unused alps_post_reset(struct hid_device *hdev) |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 455 | { |
Masaki Ota | 73196eb | 2017-10-06 11:53:17 +0900 | [diff] [blame] | 456 | int ret = -1; |
| 457 | struct alps_dev *data = hid_get_drvdata(hdev); |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 458 | |
Masaki Ota | 73196eb | 2017-10-06 11:53:17 +0900 | [diff] [blame] | 459 | switch (data->dev_type) { |
| 460 | case T4: |
| 461 | ret = t4_read_write_register(hdev, T4_PRM_FEED_CONFIG_1, |
| 462 | NULL, T4_I2C_ABS, false); |
Christophe JAILLET | 6993401 | 2018-03-19 21:53:28 +0100 | [diff] [blame] | 463 | if (ret < 0) { |
| 464 | dev_err(&hdev->dev, "failed T4_PRM_FEED_CONFIG_1 (%d)\n", |
| 465 | ret); |
| 466 | goto exit; |
| 467 | } |
| 468 | |
Masaki Ota | 73196eb | 2017-10-06 11:53:17 +0900 | [diff] [blame] | 469 | ret = t4_read_write_register(hdev, T4_PRM_FEED_CONFIG_4, |
| 470 | NULL, T4_FEEDCFG4_ADVANCED_ABS_ENABLE, false); |
Christophe JAILLET | 6993401 | 2018-03-19 21:53:28 +0100 | [diff] [blame] | 471 | if (ret < 0) { |
| 472 | dev_err(&hdev->dev, "failed T4_PRM_FEED_CONFIG_4 (%d)\n", |
| 473 | ret); |
| 474 | goto exit; |
| 475 | } |
Masaki Ota | 73196eb | 2017-10-06 11:53:17 +0900 | [diff] [blame] | 476 | break; |
| 477 | case U1: |
| 478 | ret = u1_read_write_register(hdev, |
| 479 | ADDRESS_U1_DEV_CTRL_1, NULL, |
| 480 | U1_TP_ABS_MODE | U1_SP_ABS_MODE, false); |
Christophe JAILLET | 6993401 | 2018-03-19 21:53:28 +0100 | [diff] [blame] | 481 | if (ret < 0) { |
| 482 | dev_err(&hdev->dev, "failed to change TP mode (%d)\n", |
| 483 | ret); |
| 484 | goto exit; |
| 485 | } |
Masaki Ota | 73196eb | 2017-10-06 11:53:17 +0900 | [diff] [blame] | 486 | break; |
| 487 | default: |
| 488 | break; |
| 489 | } |
Christophe JAILLET | 6993401 | 2018-03-19 21:53:28 +0100 | [diff] [blame] | 490 | |
| 491 | exit: |
Masaki Ota | 73196eb | 2017-10-06 11:53:17 +0900 | [diff] [blame] | 492 | return ret; |
| 493 | } |
| 494 | |
| 495 | static int __maybe_unused alps_post_resume(struct hid_device *hdev) |
| 496 | { |
| 497 | return alps_post_reset(hdev); |
| 498 | } |
| 499 | |
| 500 | static int u1_init(struct hid_device *hdev, struct alps_dev *pri_data) |
Masaki Ota | 5d8c720 | 2017-10-06 11:53:14 +0900 | [diff] [blame] | 501 | { |
| 502 | int ret; |
Masaki Ota | 5992262 | 2017-10-06 11:53:16 +0900 | [diff] [blame] | 503 | u8 tmp, dev_ctrl, sen_line_num_x, sen_line_num_y; |
| 504 | u8 pitch_x, pitch_y, resolution; |
Masaki Ota | 5d8c720 | 2017-10-06 11:53:14 +0900 | [diff] [blame] | 505 | |
| 506 | /* Device initialization */ |
| 507 | ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1, |
Masaki Ota | 5992262 | 2017-10-06 11:53:16 +0900 | [diff] [blame] | 508 | &dev_ctrl, 0, true); |
Masaki Ota | 5d8c720 | 2017-10-06 11:53:14 +0900 | [diff] [blame] | 509 | if (ret < 0) { |
| 510 | dev_err(&hdev->dev, "failed U1_DEV_CTRL_1 (%d)\n", ret); |
| 511 | goto exit; |
| 512 | } |
| 513 | |
Masaki Ota | 5992262 | 2017-10-06 11:53:16 +0900 | [diff] [blame] | 514 | dev_ctrl &= ~U1_DISABLE_DEV; |
| 515 | dev_ctrl |= U1_TP_ABS_MODE; |
Masaki Ota | 5d8c720 | 2017-10-06 11:53:14 +0900 | [diff] [blame] | 516 | ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1, |
Masaki Ota | 5992262 | 2017-10-06 11:53:16 +0900 | [diff] [blame] | 517 | NULL, dev_ctrl, false); |
Masaki Ota | 5d8c720 | 2017-10-06 11:53:14 +0900 | [diff] [blame] | 518 | if (ret < 0) { |
| 519 | dev_err(&hdev->dev, "failed to change TP mode (%d)\n", ret); |
| 520 | goto exit; |
| 521 | } |
| 522 | |
| 523 | ret = u1_read_write_register(hdev, ADDRESS_U1_NUM_SENS_X, |
Masaki Ota | 5992262 | 2017-10-06 11:53:16 +0900 | [diff] [blame] | 524 | &sen_line_num_x, 0, true); |
Masaki Ota | 5d8c720 | 2017-10-06 11:53:14 +0900 | [diff] [blame] | 525 | if (ret < 0) { |
| 526 | dev_err(&hdev->dev, "failed U1_NUM_SENS_X (%d)\n", ret); |
| 527 | goto exit; |
| 528 | } |
| 529 | |
| 530 | ret = u1_read_write_register(hdev, ADDRESS_U1_NUM_SENS_Y, |
Masaki Ota | 5992262 | 2017-10-06 11:53:16 +0900 | [diff] [blame] | 531 | &sen_line_num_y, 0, true); |
Masaki Ota | 5d8c720 | 2017-10-06 11:53:14 +0900 | [diff] [blame] | 532 | if (ret < 0) { |
| 533 | dev_err(&hdev->dev, "failed U1_NUM_SENS_Y (%d)\n", ret); |
| 534 | goto exit; |
| 535 | } |
| 536 | |
| 537 | ret = u1_read_write_register(hdev, ADDRESS_U1_PITCH_SENS_X, |
Masaki Ota | 5992262 | 2017-10-06 11:53:16 +0900 | [diff] [blame] | 538 | &pitch_x, 0, true); |
Masaki Ota | 5d8c720 | 2017-10-06 11:53:14 +0900 | [diff] [blame] | 539 | if (ret < 0) { |
| 540 | dev_err(&hdev->dev, "failed U1_PITCH_SENS_X (%d)\n", ret); |
| 541 | goto exit; |
| 542 | } |
| 543 | |
| 544 | ret = u1_read_write_register(hdev, ADDRESS_U1_PITCH_SENS_Y, |
Masaki Ota | 5992262 | 2017-10-06 11:53:16 +0900 | [diff] [blame] | 545 | &pitch_y, 0, true); |
Masaki Ota | 5d8c720 | 2017-10-06 11:53:14 +0900 | [diff] [blame] | 546 | if (ret < 0) { |
| 547 | dev_err(&hdev->dev, "failed U1_PITCH_SENS_Y (%d)\n", ret); |
| 548 | goto exit; |
| 549 | } |
| 550 | |
| 551 | ret = u1_read_write_register(hdev, ADDRESS_U1_RESO_DWN_ABS, |
Masaki Ota | 5992262 | 2017-10-06 11:53:16 +0900 | [diff] [blame] | 552 | &resolution, 0, true); |
Masaki Ota | 5d8c720 | 2017-10-06 11:53:14 +0900 | [diff] [blame] | 553 | if (ret < 0) { |
| 554 | dev_err(&hdev->dev, "failed U1_RESO_DWN_ABS (%d)\n", ret); |
| 555 | goto exit; |
| 556 | } |
| 557 | pri_data->x_active_len_mm = |
Masaki Ota | 5992262 | 2017-10-06 11:53:16 +0900 | [diff] [blame] | 558 | (pitch_x * (sen_line_num_x - 1)) / 10; |
Masaki Ota | 5d8c720 | 2017-10-06 11:53:14 +0900 | [diff] [blame] | 559 | pri_data->y_active_len_mm = |
Masaki Ota | 5992262 | 2017-10-06 11:53:16 +0900 | [diff] [blame] | 560 | (pitch_y * (sen_line_num_y - 1)) / 10; |
Masaki Ota | 5d8c720 | 2017-10-06 11:53:14 +0900 | [diff] [blame] | 561 | |
| 562 | pri_data->x_max = |
Masaki Ota | 5992262 | 2017-10-06 11:53:16 +0900 | [diff] [blame] | 563 | (resolution << 2) * (sen_line_num_x - 1); |
Masaki Ota | c7083d3 | 2017-10-06 11:53:15 +0900 | [diff] [blame] | 564 | pri_data->x_min = 1; |
Masaki Ota | 5d8c720 | 2017-10-06 11:53:14 +0900 | [diff] [blame] | 565 | pri_data->y_max = |
Masaki Ota | 5992262 | 2017-10-06 11:53:16 +0900 | [diff] [blame] | 566 | (resolution << 2) * (sen_line_num_y - 1); |
Masaki Ota | c7083d3 | 2017-10-06 11:53:15 +0900 | [diff] [blame] | 567 | pri_data->y_min = 1; |
Masaki Ota | 5d8c720 | 2017-10-06 11:53:14 +0900 | [diff] [blame] | 568 | |
| 569 | ret = u1_read_write_register(hdev, ADDRESS_U1_PAD_BTN, |
Masaki Ota | 5992262 | 2017-10-06 11:53:16 +0900 | [diff] [blame] | 570 | &tmp, 0, true); |
Masaki Ota | 5d8c720 | 2017-10-06 11:53:14 +0900 | [diff] [blame] | 571 | if (ret < 0) { |
| 572 | dev_err(&hdev->dev, "failed U1_PAD_BTN (%d)\n", ret); |
| 573 | goto exit; |
| 574 | } |
Masaki Ota | 5992262 | 2017-10-06 11:53:16 +0900 | [diff] [blame] | 575 | if ((tmp & 0x0F) == (tmp & 0xF0) >> 4) { |
| 576 | pri_data->btn_cnt = (tmp & 0x0F); |
Masaki Ota | c7083d3 | 2017-10-06 11:53:15 +0900 | [diff] [blame] | 577 | } else { |
| 578 | /* Button pad */ |
| 579 | pri_data->btn_cnt = 1; |
| 580 | } |
Masaki Ota | 5d8c720 | 2017-10-06 11:53:14 +0900 | [diff] [blame] | 581 | |
| 582 | pri_data->has_sp = 0; |
| 583 | /* Check StickPointer device */ |
| 584 | ret = u1_read_write_register(hdev, ADDRESS_U1_DEVICE_TYP, |
Masaki Ota | 5992262 | 2017-10-06 11:53:16 +0900 | [diff] [blame] | 585 | &tmp, 0, true); |
Masaki Ota | 5d8c720 | 2017-10-06 11:53:14 +0900 | [diff] [blame] | 586 | if (ret < 0) { |
| 587 | dev_err(&hdev->dev, "failed U1_DEVICE_TYP (%d)\n", ret); |
| 588 | goto exit; |
| 589 | } |
Masaki Ota | 5992262 | 2017-10-06 11:53:16 +0900 | [diff] [blame] | 590 | if (tmp & U1_DEVTYPE_SP_SUPPORT) { |
| 591 | dev_ctrl |= U1_SP_ABS_MODE; |
Masaki Ota | 5d8c720 | 2017-10-06 11:53:14 +0900 | [diff] [blame] | 592 | ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1, |
Masaki Ota | 5992262 | 2017-10-06 11:53:16 +0900 | [diff] [blame] | 593 | NULL, dev_ctrl, false); |
Masaki Ota | 5d8c720 | 2017-10-06 11:53:14 +0900 | [diff] [blame] | 594 | if (ret < 0) { |
| 595 | dev_err(&hdev->dev, "failed SP mode (%d)\n", ret); |
| 596 | goto exit; |
| 597 | } |
| 598 | |
| 599 | ret = u1_read_write_register(hdev, ADDRESS_U1_SP_BTN, |
| 600 | &pri_data->sp_btn_info, 0, true); |
| 601 | if (ret < 0) { |
| 602 | dev_err(&hdev->dev, "failed U1_SP_BTN (%d)\n", ret); |
| 603 | goto exit; |
| 604 | } |
| 605 | pri_data->has_sp = 1; |
| 606 | } |
Masaki Ota | c7083d3 | 2017-10-06 11:53:15 +0900 | [diff] [blame] | 607 | pri_data->max_fingers = 5; |
Masaki Ota | 5d8c720 | 2017-10-06 11:53:14 +0900 | [diff] [blame] | 608 | exit: |
| 609 | return ret; |
| 610 | } |
| 611 | |
Masaki Ota | 73196eb | 2017-10-06 11:53:17 +0900 | [diff] [blame] | 612 | static int T4_init(struct hid_device *hdev, struct alps_dev *pri_data) |
| 613 | { |
| 614 | int ret; |
| 615 | u8 tmp, sen_line_num_x, sen_line_num_y; |
| 616 | |
| 617 | ret = t4_read_write_register(hdev, T4_PRM_ID_CONFIG_3, &tmp, 0, true); |
| 618 | if (ret < 0) { |
| 619 | dev_err(&hdev->dev, "failed T4_PRM_ID_CONFIG_3 (%d)\n", ret); |
| 620 | goto exit; |
| 621 | } |
| 622 | sen_line_num_x = 16 + ((tmp & 0x0F) | (tmp & 0x08 ? 0xF0 : 0)); |
| 623 | sen_line_num_y = 12 + (((tmp & 0xF0) >> 4) | (tmp & 0x80 ? 0xF0 : 0)); |
| 624 | |
| 625 | pri_data->x_max = sen_line_num_x * T4_COUNT_PER_ELECTRODE; |
| 626 | pri_data->x_min = T4_COUNT_PER_ELECTRODE; |
| 627 | pri_data->y_max = sen_line_num_y * T4_COUNT_PER_ELECTRODE; |
| 628 | pri_data->y_min = T4_COUNT_PER_ELECTRODE; |
| 629 | pri_data->x_active_len_mm = pri_data->y_active_len_mm = 0; |
| 630 | pri_data->btn_cnt = 1; |
| 631 | |
| 632 | ret = t4_read_write_register(hdev, PRM_SYS_CONFIG_1, &tmp, 0, true); |
| 633 | if (ret < 0) { |
| 634 | dev_err(&hdev->dev, "failed PRM_SYS_CONFIG_1 (%d)\n", ret); |
| 635 | goto exit; |
| 636 | } |
| 637 | tmp |= 0x02; |
| 638 | ret = t4_read_write_register(hdev, PRM_SYS_CONFIG_1, NULL, tmp, false); |
| 639 | if (ret < 0) { |
| 640 | dev_err(&hdev->dev, "failed PRM_SYS_CONFIG_1 (%d)\n", ret); |
| 641 | goto exit; |
| 642 | } |
| 643 | |
| 644 | ret = t4_read_write_register(hdev, T4_PRM_FEED_CONFIG_1, |
| 645 | NULL, T4_I2C_ABS, false); |
| 646 | if (ret < 0) { |
| 647 | dev_err(&hdev->dev, "failed T4_PRM_FEED_CONFIG_1 (%d)\n", ret); |
| 648 | goto exit; |
| 649 | } |
| 650 | |
| 651 | ret = t4_read_write_register(hdev, T4_PRM_FEED_CONFIG_4, NULL, |
| 652 | T4_FEEDCFG4_ADVANCED_ABS_ENABLE, false); |
| 653 | if (ret < 0) { |
| 654 | dev_err(&hdev->dev, "failed T4_PRM_FEED_CONFIG_4 (%d)\n", ret); |
| 655 | goto exit; |
| 656 | } |
| 657 | pri_data->max_fingers = 5; |
| 658 | pri_data->has_sp = 0; |
| 659 | exit: |
| 660 | return ret; |
| 661 | } |
| 662 | |
Benjamin Tissoires | 7dd8db6 | 2018-10-12 16:05:25 +0200 | [diff] [blame^] | 663 | static int alps_sp_open(struct input_dev *dev) |
| 664 | { |
| 665 | struct hid_device *hid = input_get_drvdata(dev); |
| 666 | |
| 667 | return hid_hw_open(hid); |
| 668 | } |
| 669 | |
| 670 | static void alps_sp_close(struct input_dev *dev) |
| 671 | { |
| 672 | struct hid_device *hid = input_get_drvdata(dev); |
| 673 | |
| 674 | hid_hw_close(hid); |
| 675 | } |
| 676 | |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 677 | static int alps_input_configured(struct hid_device *hdev, struct hid_input *hi) |
| 678 | { |
Masaki Ota | 73196eb | 2017-10-06 11:53:17 +0900 | [diff] [blame] | 679 | struct alps_dev *data = hid_get_drvdata(hdev); |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 680 | struct input_dev *input = hi->input, *input2; |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 681 | int ret; |
| 682 | int res_x, res_y, i; |
| 683 | |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 684 | data->input = input; |
| 685 | |
| 686 | hid_dbg(hdev, "Opening low level driver\n"); |
| 687 | ret = hid_hw_open(hdev); |
| 688 | if (ret) |
| 689 | return ret; |
| 690 | |
| 691 | /* Allow incoming hid reports */ |
| 692 | hid_device_io_start(hdev); |
Masaki Ota | 73196eb | 2017-10-06 11:53:17 +0900 | [diff] [blame] | 693 | switch (data->dev_type) { |
| 694 | case T4: |
| 695 | ret = T4_init(hdev, data); |
| 696 | break; |
| 697 | case U1: |
| 698 | ret = u1_init(hdev, data); |
| 699 | break; |
| 700 | default: |
| 701 | break; |
| 702 | } |
Masaki Ota | 5d8c720 | 2017-10-06 11:53:14 +0900 | [diff] [blame] | 703 | |
| 704 | if (ret) |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 705 | goto exit; |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 706 | |
| 707 | __set_bit(EV_ABS, input->evbit); |
Masaki Ota | c7083d3 | 2017-10-06 11:53:15 +0900 | [diff] [blame] | 708 | input_set_abs_params(input, ABS_MT_POSITION_X, |
| 709 | data->x_min, data->x_max, 0, 0); |
| 710 | input_set_abs_params(input, ABS_MT_POSITION_Y, |
| 711 | data->y_min, data->y_max, 0, 0); |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 712 | |
Masaki Ota | ce6abcf | 2017-10-06 11:53:13 +0900 | [diff] [blame] | 713 | if (data->x_active_len_mm && data->y_active_len_mm) { |
| 714 | res_x = (data->x_max - 1) / data->x_active_len_mm; |
| 715 | res_y = (data->y_max - 1) / data->y_active_len_mm; |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 716 | |
| 717 | input_abs_set_res(input, ABS_MT_POSITION_X, res_x); |
| 718 | input_abs_set_res(input, ABS_MT_POSITION_Y, res_y); |
| 719 | } |
| 720 | |
| 721 | input_set_abs_params(input, ABS_MT_PRESSURE, 0, 64, 0, 0); |
| 722 | |
Masaki Ota | c7083d3 | 2017-10-06 11:53:15 +0900 | [diff] [blame] | 723 | input_mt_init_slots(input, data->max_fingers, INPUT_MT_POINTER); |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 724 | |
| 725 | __set_bit(EV_KEY, input->evbit); |
Masaki Ota | c7083d3 | 2017-10-06 11:53:15 +0900 | [diff] [blame] | 726 | |
| 727 | if (data->btn_cnt == 1) |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 728 | __set_bit(INPUT_PROP_BUTTONPAD, input->propbit); |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 729 | |
Masaki Ota | ce6abcf | 2017-10-06 11:53:13 +0900 | [diff] [blame] | 730 | for (i = 0; i < data->btn_cnt; i++) |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 731 | __set_bit(BTN_LEFT + i, input->keybit); |
| 732 | |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 733 | /* Stick device initialization */ |
Masaki Ota | 5d8c720 | 2017-10-06 11:53:14 +0900 | [diff] [blame] | 734 | if (data->has_sp) { |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 735 | input2 = input_allocate_device(); |
| 736 | if (!input2) { |
Masaki Ota | c7083d3 | 2017-10-06 11:53:15 +0900 | [diff] [blame] | 737 | input_free_device(input2); |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 738 | goto exit; |
| 739 | } |
| 740 | |
Masaki Ota | 819d64e | 2016-06-22 13:11:08 +0900 | [diff] [blame] | 741 | data->input2 = input2; |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 742 | input2->phys = input->phys; |
| 743 | input2->name = "DualPoint Stick"; |
| 744 | input2->id.bustype = BUS_I2C; |
| 745 | input2->id.vendor = input->id.vendor; |
| 746 | input2->id.product = input->id.product; |
| 747 | input2->id.version = input->id.version; |
| 748 | input2->dev.parent = input->dev.parent; |
| 749 | |
Benjamin Tissoires | 7dd8db6 | 2018-10-12 16:05:25 +0200 | [diff] [blame^] | 750 | input_set_drvdata(input2, hdev); |
| 751 | input2->open = alps_sp_open; |
| 752 | input2->close = alps_sp_close; |
| 753 | |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 754 | __set_bit(EV_KEY, input2->evbit); |
Masaki Ota | ce6abcf | 2017-10-06 11:53:13 +0900 | [diff] [blame] | 755 | data->sp_btn_cnt = (data->sp_btn_info & 0x0F); |
| 756 | for (i = 0; i < data->sp_btn_cnt; i++) |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 757 | __set_bit(BTN_LEFT + i, input2->keybit); |
| 758 | |
| 759 | __set_bit(EV_REL, input2->evbit); |
| 760 | __set_bit(REL_X, input2->relbit); |
| 761 | __set_bit(REL_Y, input2->relbit); |
| 762 | __set_bit(INPUT_PROP_POINTER, input2->propbit); |
| 763 | __set_bit(INPUT_PROP_POINTING_STICK, input2->propbit); |
| 764 | |
Masaki Ota | c7083d3 | 2017-10-06 11:53:15 +0900 | [diff] [blame] | 765 | if (input_register_device(data->input2)) { |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 766 | input_free_device(input2); |
| 767 | goto exit; |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | exit: |
| 772 | hid_device_io_stop(hdev); |
| 773 | hid_hw_close(hdev); |
| 774 | return ret; |
| 775 | } |
| 776 | |
| 777 | static int alps_input_mapping(struct hid_device *hdev, |
| 778 | struct hid_input *hi, struct hid_field *field, |
| 779 | struct hid_usage *usage, unsigned long **bit, int *max) |
| 780 | { |
| 781 | return -1; |
| 782 | } |
| 783 | |
| 784 | static int alps_probe(struct hid_device *hdev, const struct hid_device_id *id) |
| 785 | { |
Masaki Ota | 73196eb | 2017-10-06 11:53:17 +0900 | [diff] [blame] | 786 | struct alps_dev *data = NULL; |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 787 | int ret; |
Masaki Ota | 73196eb | 2017-10-06 11:53:17 +0900 | [diff] [blame] | 788 | data = devm_kzalloc(&hdev->dev, sizeof(struct alps_dev), GFP_KERNEL); |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 789 | if (!data) |
| 790 | return -ENOMEM; |
| 791 | |
| 792 | data->hdev = hdev; |
| 793 | hid_set_drvdata(hdev, data); |
| 794 | |
| 795 | hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS; |
| 796 | |
| 797 | ret = hid_parse(hdev); |
| 798 | if (ret) { |
| 799 | hid_err(hdev, "parse failed\n"); |
| 800 | return ret; |
| 801 | } |
| 802 | |
Masaki Ota | 73196eb | 2017-10-06 11:53:17 +0900 | [diff] [blame] | 803 | switch (hdev->product) { |
| 804 | case HID_DEVICE_ID_ALPS_T4_BTNLESS: |
| 805 | data->dev_type = T4; |
| 806 | break; |
| 807 | case HID_DEVICE_ID_ALPS_U1_DUAL: |
Masaki Ota | 287b8e1 | 2017-10-06 11:53:18 +0900 | [diff] [blame] | 808 | case HID_DEVICE_ID_ALPS_U1: |
Masaki Ota | 73196eb | 2017-10-06 11:53:17 +0900 | [diff] [blame] | 809 | data->dev_type = U1; |
| 810 | break; |
| 811 | default: |
| 812 | data->dev_type = UNKNOWN; |
| 813 | } |
| 814 | |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 815 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); |
| 816 | if (ret) { |
| 817 | hid_err(hdev, "hw start failed\n"); |
| 818 | return ret; |
| 819 | } |
| 820 | |
| 821 | return 0; |
| 822 | } |
| 823 | |
| 824 | static void alps_remove(struct hid_device *hdev) |
| 825 | { |
| 826 | hid_hw_stop(hdev); |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | static const struct hid_device_id alps_id[] = { |
| 830 | { HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY, |
Masaki Ota | 819d64e | 2016-06-22 13:11:08 +0900 | [diff] [blame] | 831 | USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1_DUAL) }, |
Masaki Ota | 73196eb | 2017-10-06 11:53:17 +0900 | [diff] [blame] | 832 | { HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY, |
Masaki Ota | 287b8e1 | 2017-10-06 11:53:18 +0900 | [diff] [blame] | 833 | USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1) }, |
| 834 | { HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY, |
Masaki Ota | 73196eb | 2017-10-06 11:53:17 +0900 | [diff] [blame] | 835 | USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_T4_BTNLESS) }, |
Masaki Ota | 2562756 | 2016-06-16 18:45:57 +0900 | [diff] [blame] | 836 | { } |
| 837 | }; |
| 838 | MODULE_DEVICE_TABLE(hid, alps_id); |
| 839 | |
| 840 | static struct hid_driver alps_driver = { |
| 841 | .name = "hid-alps", |
| 842 | .id_table = alps_id, |
| 843 | .probe = alps_probe, |
| 844 | .remove = alps_remove, |
| 845 | .raw_event = alps_raw_event, |
| 846 | .input_mapping = alps_input_mapping, |
| 847 | .input_configured = alps_input_configured, |
| 848 | #ifdef CONFIG_PM |
| 849 | .resume = alps_post_resume, |
| 850 | .reset_resume = alps_post_reset, |
| 851 | #endif |
| 852 | }; |
| 853 | |
| 854 | module_hid_driver(alps_driver); |
| 855 | |
| 856 | MODULE_AUTHOR("Masaki Ota <masaki.ota@jp.alps.com>"); |
| 857 | MODULE_DESCRIPTION("ALPS HID driver"); |
| 858 | MODULE_LICENSE("GPL"); |