12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later 22562756dSMasaki Ota /* 32562756dSMasaki Ota * Copyright (c) 2016 Masaki Ota <masaki.ota@jp.alps.com> 42562756dSMasaki Ota */ 52562756dSMasaki Ota 62562756dSMasaki Ota #include <linux/kernel.h> 72562756dSMasaki Ota #include <linux/hid.h> 82562756dSMasaki Ota #include <linux/input.h> 92562756dSMasaki Ota #include <linux/input/mt.h> 102562756dSMasaki Ota #include <linux/module.h> 112562756dSMasaki Ota #include <asm/unaligned.h> 122562756dSMasaki Ota #include "hid-ids.h" 132562756dSMasaki Ota 142562756dSMasaki Ota /* ALPS Device Product ID */ 152562756dSMasaki Ota #define HID_PRODUCT_ID_T3_BTNLESS 0xD0C0 162562756dSMasaki Ota #define HID_PRODUCT_ID_COSMO 0x1202 172562756dSMasaki Ota #define HID_PRODUCT_ID_U1_PTP_1 0x1207 182562756dSMasaki Ota #define HID_PRODUCT_ID_U1 0x1209 192562756dSMasaki Ota #define HID_PRODUCT_ID_U1_PTP_2 0x120A 202562756dSMasaki Ota #define HID_PRODUCT_ID_U1_DUAL 0x120B 212562756dSMasaki Ota #define HID_PRODUCT_ID_T4_BTNLESS 0x120C 222562756dSMasaki Ota 232562756dSMasaki Ota #define DEV_SINGLEPOINT 0x01 242562756dSMasaki Ota #define DEV_DUALPOINT 0x02 252562756dSMasaki Ota 262562756dSMasaki Ota #define U1_MOUSE_REPORT_ID 0x01 /* Mouse data ReportID */ 272562756dSMasaki Ota #define U1_ABSOLUTE_REPORT_ID 0x03 /* Absolute data ReportID */ 282562756dSMasaki Ota #define U1_FEATURE_REPORT_ID 0x05 /* Feature ReportID */ 292562756dSMasaki Ota #define U1_SP_ABSOLUTE_REPORT_ID 0x06 /* Feature ReportID */ 302562756dSMasaki Ota 312562756dSMasaki Ota #define U1_FEATURE_REPORT_LEN 0x08 /* Feature Report Length */ 322562756dSMasaki Ota #define U1_FEATURE_REPORT_LEN_ALL 0x0A 332562756dSMasaki Ota #define U1_CMD_REGISTER_READ 0xD1 342562756dSMasaki Ota #define U1_CMD_REGISTER_WRITE 0xD2 352562756dSMasaki Ota 362562756dSMasaki Ota #define U1_DEVTYPE_SP_SUPPORT 0x10 /* SP Support */ 372562756dSMasaki Ota #define U1_DISABLE_DEV 0x01 382562756dSMasaki Ota #define U1_TP_ABS_MODE 0x02 392562756dSMasaki Ota #define U1_SP_ABS_MODE 0x80 402562756dSMasaki Ota 412562756dSMasaki Ota #define ADDRESS_U1_DEV_CTRL_1 0x00800040 422562756dSMasaki Ota #define ADDRESS_U1_DEVICE_TYP 0x00800043 432562756dSMasaki Ota #define ADDRESS_U1_NUM_SENS_X 0x00800047 442562756dSMasaki Ota #define ADDRESS_U1_NUM_SENS_Y 0x00800048 452562756dSMasaki Ota #define ADDRESS_U1_PITCH_SENS_X 0x00800049 462562756dSMasaki Ota #define ADDRESS_U1_PITCH_SENS_Y 0x0080004A 472562756dSMasaki Ota #define ADDRESS_U1_RESO_DWN_ABS 0x0080004E 482562756dSMasaki Ota #define ADDRESS_U1_PAD_BTN 0x00800052 492562756dSMasaki Ota #define ADDRESS_U1_SP_BTN 0x0080009F 502562756dSMasaki Ota 5173196ebeSMasaki Ota #define T4_INPUT_REPORT_LEN sizeof(struct t4_input_report) 5273196ebeSMasaki Ota #define T4_FEATURE_REPORT_LEN T4_INPUT_REPORT_LEN 5373196ebeSMasaki Ota #define T4_FEATURE_REPORT_ID 7 5473196ebeSMasaki Ota #define T4_CMD_REGISTER_READ 0x08 5573196ebeSMasaki Ota #define T4_CMD_REGISTER_WRITE 0x07 5673196ebeSMasaki Ota 5773196ebeSMasaki Ota #define T4_ADDRESS_BASE 0xC2C0 5873196ebeSMasaki Ota #define PRM_SYS_CONFIG_1 (T4_ADDRESS_BASE + 0x0002) 5973196ebeSMasaki Ota #define T4_PRM_FEED_CONFIG_1 (T4_ADDRESS_BASE + 0x0004) 6073196ebeSMasaki Ota #define T4_PRM_FEED_CONFIG_4 (T4_ADDRESS_BASE + 0x001A) 6173196ebeSMasaki Ota #define T4_PRM_ID_CONFIG_3 (T4_ADDRESS_BASE + 0x00B0) 6273196ebeSMasaki Ota 6373196ebeSMasaki Ota 6473196ebeSMasaki Ota #define T4_FEEDCFG4_ADVANCED_ABS_ENABLE 0x01 6573196ebeSMasaki Ota #define T4_I2C_ABS 0x78 6673196ebeSMasaki Ota 6773196ebeSMasaki Ota #define T4_COUNT_PER_ELECTRODE 256 682562756dSMasaki Ota #define MAX_TOUCHES 5 692562756dSMasaki Ota 7073196ebeSMasaki Ota enum dev_num { 7173196ebeSMasaki Ota U1, 7273196ebeSMasaki Ota T4, 7373196ebeSMasaki Ota UNKNOWN, 7473196ebeSMasaki Ota }; 752562756dSMasaki Ota /** 762562756dSMasaki Ota * struct u1_data 772562756dSMasaki Ota * 782562756dSMasaki Ota * @input: pointer to the kernel input device 792562756dSMasaki Ota * @input2: pointer to the kernel input2 device 802562756dSMasaki Ota * @hdev: pointer to the struct hid_device 812562756dSMasaki Ota * 822562756dSMasaki Ota * @dev_type: device type 835992262dSMasaki Ota * @max_fingers: total number of fingers 845992262dSMasaki Ota * @has_sp: boolean of sp existense 855992262dSMasaki Ota * @sp_btn_info: button information 862562756dSMasaki Ota * @x_active_len_mm: active area length of X (mm) 872562756dSMasaki Ota * @y_active_len_mm: active area length of Y (mm) 882562756dSMasaki Ota * @x_max: maximum x coordinate value 892562756dSMasaki Ota * @y_max: maximum y coordinate value 90c7083d3fSMasaki Ota * @x_min: minimum x coordinate value 91c7083d3fSMasaki Ota * @y_min: minimum y coordinate value 922562756dSMasaki Ota * @btn_cnt: number of buttons 932562756dSMasaki Ota * @sp_btn_cnt: number of stick buttons 942562756dSMasaki Ota */ 9573196ebeSMasaki Ota struct alps_dev { 962562756dSMasaki Ota struct input_dev *input; 972562756dSMasaki Ota struct input_dev *input2; 982562756dSMasaki Ota struct hid_device *hdev; 992562756dSMasaki Ota 10073196ebeSMasaki Ota enum dev_num dev_type; 1015992262dSMasaki Ota u8 max_fingers; 1025992262dSMasaki Ota u8 has_sp; 1032562756dSMasaki Ota u8 sp_btn_info; 1042562756dSMasaki Ota u32 x_active_len_mm; 1052562756dSMasaki Ota u32 y_active_len_mm; 1062562756dSMasaki Ota u32 x_max; 1072562756dSMasaki Ota u32 y_max; 108c7083d3fSMasaki Ota u32 x_min; 109c7083d3fSMasaki Ota u32 y_min; 1102562756dSMasaki Ota u32 btn_cnt; 1112562756dSMasaki Ota u32 sp_btn_cnt; 1122562756dSMasaki Ota }; 1132562756dSMasaki Ota 11473196ebeSMasaki Ota struct t4_contact_data { 11573196ebeSMasaki Ota u8 palm; 11673196ebeSMasaki Ota u8 x_lo; 11773196ebeSMasaki Ota u8 x_hi; 11873196ebeSMasaki Ota u8 y_lo; 11973196ebeSMasaki Ota u8 y_hi; 12073196ebeSMasaki Ota }; 12173196ebeSMasaki Ota 12273196ebeSMasaki Ota struct t4_input_report { 12373196ebeSMasaki Ota u8 reportID; 12473196ebeSMasaki Ota u8 numContacts; 12573196ebeSMasaki Ota struct t4_contact_data contact[5]; 12673196ebeSMasaki Ota u8 button; 12773196ebeSMasaki Ota u8 track[5]; 12873196ebeSMasaki Ota u8 zx[5], zy[5]; 12973196ebeSMasaki Ota u8 palmTime[5]; 13073196ebeSMasaki Ota u8 kilroy; 13173196ebeSMasaki Ota u16 timeStamp; 13273196ebeSMasaki Ota }; 13373196ebeSMasaki Ota 13473196ebeSMasaki Ota static u16 t4_calc_check_sum(u8 *buffer, 13573196ebeSMasaki Ota unsigned long offset, unsigned long length) 13673196ebeSMasaki Ota { 13773196ebeSMasaki Ota u16 sum1 = 0xFF, sum2 = 0xFF; 13873196ebeSMasaki Ota unsigned long i = 0; 13973196ebeSMasaki Ota 14073196ebeSMasaki Ota if (offset + length >= 50) 14173196ebeSMasaki Ota return 0; 14273196ebeSMasaki Ota 14373196ebeSMasaki Ota while (length > 0) { 14473196ebeSMasaki Ota u32 tlen = length > 20 ? 20 : length; 14573196ebeSMasaki Ota 14673196ebeSMasaki Ota length -= tlen; 14773196ebeSMasaki Ota 14873196ebeSMasaki Ota do { 14973196ebeSMasaki Ota sum1 += buffer[offset + i]; 15073196ebeSMasaki Ota sum2 += sum1; 15173196ebeSMasaki Ota i++; 15273196ebeSMasaki Ota } while (--tlen > 0); 15373196ebeSMasaki Ota 15473196ebeSMasaki Ota sum1 = (sum1 & 0xFF) + (sum1 >> 8); 15573196ebeSMasaki Ota sum2 = (sum2 & 0xFF) + (sum2 >> 8); 15673196ebeSMasaki Ota } 15773196ebeSMasaki Ota 15873196ebeSMasaki Ota sum1 = (sum1 & 0xFF) + (sum1 >> 8); 15973196ebeSMasaki Ota sum2 = (sum2 & 0xFF) + (sum2 >> 8); 16073196ebeSMasaki Ota 16173196ebeSMasaki Ota return(sum2 << 8 | sum1); 16273196ebeSMasaki Ota } 16373196ebeSMasaki Ota 16473196ebeSMasaki Ota static int t4_read_write_register(struct hid_device *hdev, u32 address, 16573196ebeSMasaki Ota u8 *read_val, u8 write_val, bool read_flag) 16673196ebeSMasaki Ota { 16773196ebeSMasaki Ota int ret; 16873196ebeSMasaki Ota u16 check_sum; 16973196ebeSMasaki Ota u8 *input; 170edb6cb3dSChristophe JAILLET u8 *readbuf = NULL; 17173196ebeSMasaki Ota 17273196ebeSMasaki Ota input = kzalloc(T4_FEATURE_REPORT_LEN, GFP_KERNEL); 17373196ebeSMasaki Ota if (!input) 17473196ebeSMasaki Ota return -ENOMEM; 17573196ebeSMasaki Ota 17673196ebeSMasaki Ota input[0] = T4_FEATURE_REPORT_ID; 17773196ebeSMasaki Ota if (read_flag) { 17873196ebeSMasaki Ota input[1] = T4_CMD_REGISTER_READ; 17973196ebeSMasaki Ota input[8] = 0x00; 18073196ebeSMasaki Ota } else { 18173196ebeSMasaki Ota input[1] = T4_CMD_REGISTER_WRITE; 18273196ebeSMasaki Ota input[8] = write_val; 18373196ebeSMasaki Ota } 18473196ebeSMasaki Ota put_unaligned_le32(address, input + 2); 18573196ebeSMasaki Ota input[6] = 1; 18673196ebeSMasaki Ota input[7] = 0; 18773196ebeSMasaki Ota 18873196ebeSMasaki Ota /* Calculate the checksum */ 18973196ebeSMasaki Ota check_sum = t4_calc_check_sum(input, 1, 8); 19073196ebeSMasaki Ota input[9] = (u8)check_sum; 19173196ebeSMasaki Ota input[10] = (u8)(check_sum >> 8); 19273196ebeSMasaki Ota input[11] = 0; 19373196ebeSMasaki Ota 19473196ebeSMasaki Ota ret = hid_hw_raw_request(hdev, T4_FEATURE_REPORT_ID, input, 19573196ebeSMasaki Ota T4_FEATURE_REPORT_LEN, 19673196ebeSMasaki Ota HID_FEATURE_REPORT, HID_REQ_SET_REPORT); 19773196ebeSMasaki Ota 19873196ebeSMasaki Ota if (ret < 0) { 19973196ebeSMasaki Ota dev_err(&hdev->dev, "failed to read command (%d)\n", ret); 20073196ebeSMasaki Ota goto exit; 20173196ebeSMasaki Ota } 20273196ebeSMasaki Ota 20373196ebeSMasaki Ota if (read_flag) { 204edb6cb3dSChristophe JAILLET readbuf = kzalloc(T4_FEATURE_REPORT_LEN, GFP_KERNEL); 20573196ebeSMasaki Ota if (!readbuf) { 20673196ebeSMasaki Ota ret = -ENOMEM; 20773196ebeSMasaki Ota goto exit; 20873196ebeSMasaki Ota } 20973196ebeSMasaki Ota 21073196ebeSMasaki Ota ret = hid_hw_raw_request(hdev, T4_FEATURE_REPORT_ID, readbuf, 21173196ebeSMasaki Ota T4_FEATURE_REPORT_LEN, 21273196ebeSMasaki Ota HID_FEATURE_REPORT, HID_REQ_GET_REPORT); 21373196ebeSMasaki Ota if (ret < 0) { 21473196ebeSMasaki Ota dev_err(&hdev->dev, "failed read register (%d)\n", ret); 21573196ebeSMasaki Ota goto exit_readbuf; 21673196ebeSMasaki Ota } 21773196ebeSMasaki Ota 218605f0772SChristophe JAILLET ret = -EINVAL; 219605f0772SChristophe JAILLET 22073196ebeSMasaki Ota if (*(u32 *)&readbuf[6] != address) { 22173196ebeSMasaki Ota dev_err(&hdev->dev, "read register address error (%x,%x)\n", 22273196ebeSMasaki Ota *(u32 *)&readbuf[6], address); 22373196ebeSMasaki Ota goto exit_readbuf; 22473196ebeSMasaki Ota } 22573196ebeSMasaki Ota 22673196ebeSMasaki Ota if (*(u16 *)&readbuf[10] != 1) { 22773196ebeSMasaki Ota dev_err(&hdev->dev, "read register size error (%x)\n", 22873196ebeSMasaki Ota *(u16 *)&readbuf[10]); 22973196ebeSMasaki Ota goto exit_readbuf; 23073196ebeSMasaki Ota } 23173196ebeSMasaki Ota 23273196ebeSMasaki Ota check_sum = t4_calc_check_sum(readbuf, 6, 7); 23373196ebeSMasaki Ota if (*(u16 *)&readbuf[13] != check_sum) { 23473196ebeSMasaki Ota dev_err(&hdev->dev, "read register checksum error (%x,%x)\n", 23573196ebeSMasaki Ota *(u16 *)&readbuf[13], check_sum); 23673196ebeSMasaki Ota goto exit_readbuf; 23773196ebeSMasaki Ota } 23873196ebeSMasaki Ota 23973196ebeSMasaki Ota *read_val = readbuf[12]; 24073196ebeSMasaki Ota } 24173196ebeSMasaki Ota 24273196ebeSMasaki Ota ret = 0; 24373196ebeSMasaki Ota 24473196ebeSMasaki Ota exit_readbuf: 24573196ebeSMasaki Ota kfree(readbuf); 24673196ebeSMasaki Ota exit: 24773196ebeSMasaki Ota kfree(input); 24873196ebeSMasaki Ota return ret; 24973196ebeSMasaki Ota } 25073196ebeSMasaki Ota 2512562756dSMasaki Ota static int u1_read_write_register(struct hid_device *hdev, u32 address, 2522562756dSMasaki Ota u8 *read_val, u8 write_val, bool read_flag) 2532562756dSMasaki Ota { 2542562756dSMasaki Ota int ret, i; 2552562756dSMasaki Ota u8 check_sum; 2562562756dSMasaki Ota u8 *input; 2572562756dSMasaki Ota u8 *readbuf; 2582562756dSMasaki Ota 259819d64e5SMasaki Ota input = kzalloc(U1_FEATURE_REPORT_LEN, GFP_KERNEL); 2602562756dSMasaki Ota if (!input) 2612562756dSMasaki Ota return -ENOMEM; 2622562756dSMasaki Ota 2632562756dSMasaki Ota input[0] = U1_FEATURE_REPORT_ID; 2642562756dSMasaki Ota if (read_flag) { 2652562756dSMasaki Ota input[1] = U1_CMD_REGISTER_READ; 2662562756dSMasaki Ota input[6] = 0x00; 2672562756dSMasaki Ota } else { 2682562756dSMasaki Ota input[1] = U1_CMD_REGISTER_WRITE; 2692562756dSMasaki Ota input[6] = write_val; 2702562756dSMasaki Ota } 2712562756dSMasaki Ota 2722562756dSMasaki Ota put_unaligned_le32(address, input + 2); 2732562756dSMasaki Ota 2742562756dSMasaki Ota /* Calculate the checksum */ 2752562756dSMasaki Ota check_sum = U1_FEATURE_REPORT_LEN_ALL; 2762562756dSMasaki Ota for (i = 0; i < U1_FEATURE_REPORT_LEN - 1; i++) 2772562756dSMasaki Ota check_sum += input[i]; 2782562756dSMasaki Ota 2792562756dSMasaki Ota input[7] = check_sum; 2802562756dSMasaki Ota ret = hid_hw_raw_request(hdev, U1_FEATURE_REPORT_ID, input, 281819d64e5SMasaki Ota U1_FEATURE_REPORT_LEN, 282819d64e5SMasaki Ota HID_FEATURE_REPORT, HID_REQ_SET_REPORT); 2832562756dSMasaki Ota 2842562756dSMasaki Ota if (ret < 0) { 2852562756dSMasaki Ota dev_err(&hdev->dev, "failed to read command (%d)\n", ret); 2862562756dSMasaki Ota goto exit; 2872562756dSMasaki Ota } 2882562756dSMasaki Ota 2892562756dSMasaki Ota if (read_flag) { 290819d64e5SMasaki Ota readbuf = kzalloc(U1_FEATURE_REPORT_LEN, GFP_KERNEL); 291819d64e5SMasaki Ota if (!readbuf) { 2927ee2eaa3SAxel Lin ret = -ENOMEM; 2937ee2eaa3SAxel Lin goto exit; 294819d64e5SMasaki Ota } 295819d64e5SMasaki Ota 2962562756dSMasaki Ota ret = hid_hw_raw_request(hdev, U1_FEATURE_REPORT_ID, readbuf, 297819d64e5SMasaki Ota U1_FEATURE_REPORT_LEN, 29863b3a7d0SJiri Kosina HID_FEATURE_REPORT, HID_REQ_GET_REPORT); 2992562756dSMasaki Ota 3002562756dSMasaki Ota if (ret < 0) { 3012562756dSMasaki Ota dev_err(&hdev->dev, "failed read register (%d)\n", ret); 3027ee2eaa3SAxel Lin kfree(readbuf); 3032562756dSMasaki Ota goto exit; 3042562756dSMasaki Ota } 3052562756dSMasaki Ota 3062562756dSMasaki Ota *read_val = readbuf[6]; 307819d64e5SMasaki Ota 308819d64e5SMasaki Ota kfree(readbuf); 3092562756dSMasaki Ota } 3102562756dSMasaki Ota 311819d64e5SMasaki Ota ret = 0; 3122562756dSMasaki Ota 3132562756dSMasaki Ota exit: 3142562756dSMasaki Ota kfree(input); 3152562756dSMasaki Ota return ret; 3162562756dSMasaki Ota } 3172562756dSMasaki Ota 31873196ebeSMasaki Ota static int t4_raw_event(struct alps_dev *hdata, u8 *data, int size) 31973196ebeSMasaki Ota { 32073196ebeSMasaki Ota unsigned int x, y, z; 32173196ebeSMasaki Ota int i; 32273196ebeSMasaki Ota struct t4_input_report *p_report = (struct t4_input_report *)data; 32373196ebeSMasaki Ota 32473196ebeSMasaki Ota if (!data) 32573196ebeSMasaki Ota return 0; 32673196ebeSMasaki Ota for (i = 0; i < hdata->max_fingers; i++) { 32773196ebeSMasaki Ota x = p_report->contact[i].x_hi << 8 | p_report->contact[i].x_lo; 32873196ebeSMasaki Ota y = p_report->contact[i].y_hi << 8 | p_report->contact[i].y_lo; 32973196ebeSMasaki Ota y = hdata->y_max - y + hdata->y_min; 33073196ebeSMasaki Ota z = (p_report->contact[i].palm < 0x80 && 33173196ebeSMasaki Ota p_report->contact[i].palm > 0) * 62; 33273196ebeSMasaki Ota if (x == 0xffff) { 33373196ebeSMasaki Ota x = 0; 33473196ebeSMasaki Ota y = 0; 33573196ebeSMasaki Ota z = 0; 33673196ebeSMasaki Ota } 33773196ebeSMasaki Ota input_mt_slot(hdata->input, i); 33873196ebeSMasaki Ota 33973196ebeSMasaki Ota input_mt_report_slot_state(hdata->input, 34073196ebeSMasaki Ota MT_TOOL_FINGER, z != 0); 34173196ebeSMasaki Ota 34273196ebeSMasaki Ota if (!z) 34373196ebeSMasaki Ota continue; 34473196ebeSMasaki Ota 34573196ebeSMasaki Ota input_report_abs(hdata->input, ABS_MT_POSITION_X, x); 34673196ebeSMasaki Ota input_report_abs(hdata->input, ABS_MT_POSITION_Y, y); 34773196ebeSMasaki Ota input_report_abs(hdata->input, ABS_MT_PRESSURE, z); 34873196ebeSMasaki Ota } 34973196ebeSMasaki Ota input_mt_sync_frame(hdata->input); 35073196ebeSMasaki Ota 35173196ebeSMasaki Ota input_report_key(hdata->input, BTN_LEFT, p_report->button); 35273196ebeSMasaki Ota 35373196ebeSMasaki Ota input_sync(hdata->input); 35473196ebeSMasaki Ota return 1; 35573196ebeSMasaki Ota } 35673196ebeSMasaki Ota 35773196ebeSMasaki Ota static int u1_raw_event(struct alps_dev *hdata, u8 *data, int size) 3582562756dSMasaki Ota { 359819d64e5SMasaki Ota unsigned int x, y, z; 360819d64e5SMasaki Ota int i; 361819d64e5SMasaki Ota short sp_x, sp_y; 3622562756dSMasaki Ota 36373196ebeSMasaki Ota if (!data) 36473196ebeSMasaki Ota return 0; 3652562756dSMasaki Ota switch (data[0]) { 3662562756dSMasaki Ota case U1_MOUSE_REPORT_ID: 3672562756dSMasaki Ota break; 3682562756dSMasaki Ota case U1_FEATURE_REPORT_ID: 3692562756dSMasaki Ota break; 3702562756dSMasaki Ota case U1_ABSOLUTE_REPORT_ID: 37173196ebeSMasaki Ota for (i = 0; i < hdata->max_fingers; i++) { 372819d64e5SMasaki Ota u8 *contact = &data[i * 5]; 373819d64e5SMasaki Ota 374819d64e5SMasaki Ota x = get_unaligned_le16(contact + 3); 375819d64e5SMasaki Ota y = get_unaligned_le16(contact + 5); 376819d64e5SMasaki Ota z = contact[7] & 0x7F; 3772562756dSMasaki Ota 3782562756dSMasaki Ota input_mt_slot(hdata->input, i); 3792562756dSMasaki Ota 380819d64e5SMasaki Ota if (z != 0) { 3812562756dSMasaki Ota input_mt_report_slot_state(hdata->input, 3822562756dSMasaki Ota MT_TOOL_FINGER, 1); 3839a54cf46SMasaki Ota input_report_abs(hdata->input, 3849a54cf46SMasaki Ota ABS_MT_POSITION_X, x); 3859a54cf46SMasaki Ota input_report_abs(hdata->input, 3869a54cf46SMasaki Ota ABS_MT_POSITION_Y, y); 3879a54cf46SMasaki Ota input_report_abs(hdata->input, 3889a54cf46SMasaki Ota ABS_MT_PRESSURE, z); 3892562756dSMasaki Ota } else { 3902562756dSMasaki Ota input_mt_report_slot_state(hdata->input, 3912562756dSMasaki Ota MT_TOOL_FINGER, 0); 3922562756dSMasaki Ota } 3932562756dSMasaki Ota } 3942562756dSMasaki Ota 3952562756dSMasaki Ota input_mt_sync_frame(hdata->input); 3962562756dSMasaki Ota 397819d64e5SMasaki Ota input_report_key(hdata->input, BTN_LEFT, 398819d64e5SMasaki Ota data[1] & 0x1); 399819d64e5SMasaki Ota input_report_key(hdata->input, BTN_RIGHT, 400819d64e5SMasaki Ota (data[1] & 0x2)); 401819d64e5SMasaki Ota input_report_key(hdata->input, BTN_MIDDLE, 402819d64e5SMasaki Ota (data[1] & 0x4)); 403819d64e5SMasaki Ota 404819d64e5SMasaki Ota input_sync(hdata->input); 4052562756dSMasaki Ota 4062562756dSMasaki Ota return 1; 4072562756dSMasaki Ota 4082562756dSMasaki Ota case U1_SP_ABSOLUTE_REPORT_ID: 409819d64e5SMasaki Ota sp_x = get_unaligned_le16(data+2); 410819d64e5SMasaki Ota sp_y = get_unaligned_le16(data+4); 4112562756dSMasaki Ota 4122562756dSMasaki Ota sp_x = sp_x / 8; 4132562756dSMasaki Ota sp_y = sp_y / 8; 4142562756dSMasaki Ota 415819d64e5SMasaki Ota input_report_rel(hdata->input2, REL_X, sp_x); 416819d64e5SMasaki Ota input_report_rel(hdata->input2, REL_Y, sp_y); 4172562756dSMasaki Ota 418819d64e5SMasaki Ota input_report_key(hdata->input2, BTN_LEFT, 419819d64e5SMasaki Ota data[1] & 0x1); 420819d64e5SMasaki Ota input_report_key(hdata->input2, BTN_RIGHT, 421819d64e5SMasaki Ota (data[1] & 0x2)); 422819d64e5SMasaki Ota input_report_key(hdata->input2, BTN_MIDDLE, 423819d64e5SMasaki Ota (data[1] & 0x4)); 4242562756dSMasaki Ota 425819d64e5SMasaki Ota input_sync(hdata->input2); 4262562756dSMasaki Ota 4272562756dSMasaki Ota return 1; 4282562756dSMasaki Ota } 4292562756dSMasaki Ota 4302562756dSMasaki Ota return 0; 4312562756dSMasaki Ota } 4322562756dSMasaki Ota 43373196ebeSMasaki Ota static int alps_raw_event(struct hid_device *hdev, 43473196ebeSMasaki Ota struct hid_report *report, u8 *data, int size) 4352562756dSMasaki Ota { 43673196ebeSMasaki Ota int ret = 0; 43773196ebeSMasaki Ota struct alps_dev *hdata = hid_get_drvdata(hdev); 43873196ebeSMasaki Ota 43973196ebeSMasaki Ota switch (hdev->product) { 44073196ebeSMasaki Ota case HID_PRODUCT_ID_T4_BTNLESS: 44173196ebeSMasaki Ota ret = t4_raw_event(hdata, data, size); 44273196ebeSMasaki Ota break; 44373196ebeSMasaki Ota default: 44473196ebeSMasaki Ota ret = u1_raw_event(hdata, data, size); 44573196ebeSMasaki Ota break; 44673196ebeSMasaki Ota } 44773196ebeSMasaki Ota return ret; 4482562756dSMasaki Ota } 4492562756dSMasaki Ota 45073196ebeSMasaki Ota static int __maybe_unused alps_post_reset(struct hid_device *hdev) 4512562756dSMasaki Ota { 45273196ebeSMasaki Ota int ret = -1; 45373196ebeSMasaki Ota struct alps_dev *data = hid_get_drvdata(hdev); 4542562756dSMasaki Ota 45573196ebeSMasaki Ota switch (data->dev_type) { 45673196ebeSMasaki Ota case T4: 45773196ebeSMasaki Ota ret = t4_read_write_register(hdev, T4_PRM_FEED_CONFIG_1, 45873196ebeSMasaki Ota NULL, T4_I2C_ABS, false); 45969934012SChristophe JAILLET if (ret < 0) { 46069934012SChristophe JAILLET dev_err(&hdev->dev, "failed T4_PRM_FEED_CONFIG_1 (%d)\n", 46169934012SChristophe JAILLET ret); 46269934012SChristophe JAILLET goto exit; 46369934012SChristophe JAILLET } 46469934012SChristophe JAILLET 46573196ebeSMasaki Ota ret = t4_read_write_register(hdev, T4_PRM_FEED_CONFIG_4, 46673196ebeSMasaki Ota NULL, T4_FEEDCFG4_ADVANCED_ABS_ENABLE, false); 46769934012SChristophe JAILLET if (ret < 0) { 46869934012SChristophe JAILLET dev_err(&hdev->dev, "failed T4_PRM_FEED_CONFIG_4 (%d)\n", 46969934012SChristophe JAILLET ret); 47069934012SChristophe JAILLET goto exit; 47169934012SChristophe JAILLET } 47273196ebeSMasaki Ota break; 47373196ebeSMasaki Ota case U1: 47473196ebeSMasaki Ota ret = u1_read_write_register(hdev, 47573196ebeSMasaki Ota ADDRESS_U1_DEV_CTRL_1, NULL, 47673196ebeSMasaki Ota U1_TP_ABS_MODE | U1_SP_ABS_MODE, false); 47769934012SChristophe JAILLET if (ret < 0) { 47869934012SChristophe JAILLET dev_err(&hdev->dev, "failed to change TP mode (%d)\n", 47969934012SChristophe JAILLET ret); 48069934012SChristophe JAILLET goto exit; 48169934012SChristophe JAILLET } 48273196ebeSMasaki Ota break; 48373196ebeSMasaki Ota default: 48473196ebeSMasaki Ota break; 48573196ebeSMasaki Ota } 48669934012SChristophe JAILLET 48769934012SChristophe JAILLET exit: 48873196ebeSMasaki Ota return ret; 48973196ebeSMasaki Ota } 49073196ebeSMasaki Ota 49173196ebeSMasaki Ota static int __maybe_unused alps_post_resume(struct hid_device *hdev) 49273196ebeSMasaki Ota { 49373196ebeSMasaki Ota return alps_post_reset(hdev); 49473196ebeSMasaki Ota } 49573196ebeSMasaki Ota 49673196ebeSMasaki Ota static int u1_init(struct hid_device *hdev, struct alps_dev *pri_data) 4975d8c720dSMasaki Ota { 4985d8c720dSMasaki Ota int ret; 4995992262dSMasaki Ota u8 tmp, dev_ctrl, sen_line_num_x, sen_line_num_y; 5005992262dSMasaki Ota u8 pitch_x, pitch_y, resolution; 5015d8c720dSMasaki Ota 5025d8c720dSMasaki Ota /* Device initialization */ 5035d8c720dSMasaki Ota ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1, 5045992262dSMasaki Ota &dev_ctrl, 0, true); 5055d8c720dSMasaki Ota if (ret < 0) { 5065d8c720dSMasaki Ota dev_err(&hdev->dev, "failed U1_DEV_CTRL_1 (%d)\n", ret); 5075d8c720dSMasaki Ota goto exit; 5085d8c720dSMasaki Ota } 5095d8c720dSMasaki Ota 5105992262dSMasaki Ota dev_ctrl &= ~U1_DISABLE_DEV; 5115992262dSMasaki Ota dev_ctrl |= U1_TP_ABS_MODE; 5125d8c720dSMasaki Ota ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1, 5135992262dSMasaki Ota NULL, dev_ctrl, false); 5145d8c720dSMasaki Ota if (ret < 0) { 5155d8c720dSMasaki Ota dev_err(&hdev->dev, "failed to change TP mode (%d)\n", ret); 5165d8c720dSMasaki Ota goto exit; 5175d8c720dSMasaki Ota } 5185d8c720dSMasaki Ota 5195d8c720dSMasaki Ota ret = u1_read_write_register(hdev, ADDRESS_U1_NUM_SENS_X, 5205992262dSMasaki Ota &sen_line_num_x, 0, true); 5215d8c720dSMasaki Ota if (ret < 0) { 5225d8c720dSMasaki Ota dev_err(&hdev->dev, "failed U1_NUM_SENS_X (%d)\n", ret); 5235d8c720dSMasaki Ota goto exit; 5245d8c720dSMasaki Ota } 5255d8c720dSMasaki Ota 5265d8c720dSMasaki Ota ret = u1_read_write_register(hdev, ADDRESS_U1_NUM_SENS_Y, 5275992262dSMasaki Ota &sen_line_num_y, 0, true); 5285d8c720dSMasaki Ota if (ret < 0) { 5295d8c720dSMasaki Ota dev_err(&hdev->dev, "failed U1_NUM_SENS_Y (%d)\n", ret); 5305d8c720dSMasaki Ota goto exit; 5315d8c720dSMasaki Ota } 5325d8c720dSMasaki Ota 5335d8c720dSMasaki Ota ret = u1_read_write_register(hdev, ADDRESS_U1_PITCH_SENS_X, 5345992262dSMasaki Ota &pitch_x, 0, true); 5355d8c720dSMasaki Ota if (ret < 0) { 5365d8c720dSMasaki Ota dev_err(&hdev->dev, "failed U1_PITCH_SENS_X (%d)\n", ret); 5375d8c720dSMasaki Ota goto exit; 5385d8c720dSMasaki Ota } 5395d8c720dSMasaki Ota 5405d8c720dSMasaki Ota ret = u1_read_write_register(hdev, ADDRESS_U1_PITCH_SENS_Y, 5415992262dSMasaki Ota &pitch_y, 0, true); 5425d8c720dSMasaki Ota if (ret < 0) { 5435d8c720dSMasaki Ota dev_err(&hdev->dev, "failed U1_PITCH_SENS_Y (%d)\n", ret); 5445d8c720dSMasaki Ota goto exit; 5455d8c720dSMasaki Ota } 5465d8c720dSMasaki Ota 5475d8c720dSMasaki Ota ret = u1_read_write_register(hdev, ADDRESS_U1_RESO_DWN_ABS, 5485992262dSMasaki Ota &resolution, 0, true); 5495d8c720dSMasaki Ota if (ret < 0) { 5505d8c720dSMasaki Ota dev_err(&hdev->dev, "failed U1_RESO_DWN_ABS (%d)\n", ret); 5515d8c720dSMasaki Ota goto exit; 5525d8c720dSMasaki Ota } 5535d8c720dSMasaki Ota pri_data->x_active_len_mm = 5545992262dSMasaki Ota (pitch_x * (sen_line_num_x - 1)) / 10; 5555d8c720dSMasaki Ota pri_data->y_active_len_mm = 5565992262dSMasaki Ota (pitch_y * (sen_line_num_y - 1)) / 10; 5575d8c720dSMasaki Ota 5585d8c720dSMasaki Ota pri_data->x_max = 5595992262dSMasaki Ota (resolution << 2) * (sen_line_num_x - 1); 560c7083d3fSMasaki Ota pri_data->x_min = 1; 5615d8c720dSMasaki Ota pri_data->y_max = 5625992262dSMasaki Ota (resolution << 2) * (sen_line_num_y - 1); 563c7083d3fSMasaki Ota pri_data->y_min = 1; 5645d8c720dSMasaki Ota 5655d8c720dSMasaki Ota ret = u1_read_write_register(hdev, ADDRESS_U1_PAD_BTN, 5665992262dSMasaki Ota &tmp, 0, true); 5675d8c720dSMasaki Ota if (ret < 0) { 5685d8c720dSMasaki Ota dev_err(&hdev->dev, "failed U1_PAD_BTN (%d)\n", ret); 5695d8c720dSMasaki Ota goto exit; 5705d8c720dSMasaki Ota } 5715992262dSMasaki Ota if ((tmp & 0x0F) == (tmp & 0xF0) >> 4) { 5725992262dSMasaki Ota pri_data->btn_cnt = (tmp & 0x0F); 573c7083d3fSMasaki Ota } else { 574c7083d3fSMasaki Ota /* Button pad */ 575c7083d3fSMasaki Ota pri_data->btn_cnt = 1; 576c7083d3fSMasaki Ota } 5775d8c720dSMasaki Ota 5785d8c720dSMasaki Ota pri_data->has_sp = 0; 5795d8c720dSMasaki Ota /* Check StickPointer device */ 5805d8c720dSMasaki Ota ret = u1_read_write_register(hdev, ADDRESS_U1_DEVICE_TYP, 5815992262dSMasaki Ota &tmp, 0, true); 5825d8c720dSMasaki Ota if (ret < 0) { 5835d8c720dSMasaki Ota dev_err(&hdev->dev, "failed U1_DEVICE_TYP (%d)\n", ret); 5845d8c720dSMasaki Ota goto exit; 5855d8c720dSMasaki Ota } 5865992262dSMasaki Ota if (tmp & U1_DEVTYPE_SP_SUPPORT) { 5875992262dSMasaki Ota dev_ctrl |= U1_SP_ABS_MODE; 5885d8c720dSMasaki Ota ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1, 5895992262dSMasaki Ota NULL, dev_ctrl, false); 5905d8c720dSMasaki Ota if (ret < 0) { 5915d8c720dSMasaki Ota dev_err(&hdev->dev, "failed SP mode (%d)\n", ret); 5925d8c720dSMasaki Ota goto exit; 5935d8c720dSMasaki Ota } 5945d8c720dSMasaki Ota 5955d8c720dSMasaki Ota ret = u1_read_write_register(hdev, ADDRESS_U1_SP_BTN, 5965d8c720dSMasaki Ota &pri_data->sp_btn_info, 0, true); 5975d8c720dSMasaki Ota if (ret < 0) { 5985d8c720dSMasaki Ota dev_err(&hdev->dev, "failed U1_SP_BTN (%d)\n", ret); 5995d8c720dSMasaki Ota goto exit; 6005d8c720dSMasaki Ota } 6015d8c720dSMasaki Ota pri_data->has_sp = 1; 6025d8c720dSMasaki Ota } 603c7083d3fSMasaki Ota pri_data->max_fingers = 5; 6045d8c720dSMasaki Ota exit: 6055d8c720dSMasaki Ota return ret; 6065d8c720dSMasaki Ota } 6075d8c720dSMasaki Ota 60873196ebeSMasaki Ota static int T4_init(struct hid_device *hdev, struct alps_dev *pri_data) 60973196ebeSMasaki Ota { 61073196ebeSMasaki Ota int ret; 61173196ebeSMasaki Ota u8 tmp, sen_line_num_x, sen_line_num_y; 61273196ebeSMasaki Ota 61373196ebeSMasaki Ota ret = t4_read_write_register(hdev, T4_PRM_ID_CONFIG_3, &tmp, 0, true); 61473196ebeSMasaki Ota if (ret < 0) { 61573196ebeSMasaki Ota dev_err(&hdev->dev, "failed T4_PRM_ID_CONFIG_3 (%d)\n", ret); 61673196ebeSMasaki Ota goto exit; 61773196ebeSMasaki Ota } 61873196ebeSMasaki Ota sen_line_num_x = 16 + ((tmp & 0x0F) | (tmp & 0x08 ? 0xF0 : 0)); 61973196ebeSMasaki Ota sen_line_num_y = 12 + (((tmp & 0xF0) >> 4) | (tmp & 0x80 ? 0xF0 : 0)); 62073196ebeSMasaki Ota 62173196ebeSMasaki Ota pri_data->x_max = sen_line_num_x * T4_COUNT_PER_ELECTRODE; 62273196ebeSMasaki Ota pri_data->x_min = T4_COUNT_PER_ELECTRODE; 62373196ebeSMasaki Ota pri_data->y_max = sen_line_num_y * T4_COUNT_PER_ELECTRODE; 62473196ebeSMasaki Ota pri_data->y_min = T4_COUNT_PER_ELECTRODE; 62573196ebeSMasaki Ota pri_data->x_active_len_mm = pri_data->y_active_len_mm = 0; 62673196ebeSMasaki Ota pri_data->btn_cnt = 1; 62773196ebeSMasaki Ota 62873196ebeSMasaki Ota ret = t4_read_write_register(hdev, PRM_SYS_CONFIG_1, &tmp, 0, true); 62973196ebeSMasaki Ota if (ret < 0) { 63073196ebeSMasaki Ota dev_err(&hdev->dev, "failed PRM_SYS_CONFIG_1 (%d)\n", ret); 63173196ebeSMasaki Ota goto exit; 63273196ebeSMasaki Ota } 63373196ebeSMasaki Ota tmp |= 0x02; 63473196ebeSMasaki Ota ret = t4_read_write_register(hdev, PRM_SYS_CONFIG_1, NULL, tmp, false); 63573196ebeSMasaki Ota if (ret < 0) { 63673196ebeSMasaki Ota dev_err(&hdev->dev, "failed PRM_SYS_CONFIG_1 (%d)\n", ret); 63773196ebeSMasaki Ota goto exit; 63873196ebeSMasaki Ota } 63973196ebeSMasaki Ota 64073196ebeSMasaki Ota ret = t4_read_write_register(hdev, T4_PRM_FEED_CONFIG_1, 64173196ebeSMasaki Ota NULL, T4_I2C_ABS, false); 64273196ebeSMasaki Ota if (ret < 0) { 64373196ebeSMasaki Ota dev_err(&hdev->dev, "failed T4_PRM_FEED_CONFIG_1 (%d)\n", ret); 64473196ebeSMasaki Ota goto exit; 64573196ebeSMasaki Ota } 64673196ebeSMasaki Ota 64773196ebeSMasaki Ota ret = t4_read_write_register(hdev, T4_PRM_FEED_CONFIG_4, NULL, 64873196ebeSMasaki Ota T4_FEEDCFG4_ADVANCED_ABS_ENABLE, false); 64973196ebeSMasaki Ota if (ret < 0) { 65073196ebeSMasaki Ota dev_err(&hdev->dev, "failed T4_PRM_FEED_CONFIG_4 (%d)\n", ret); 65173196ebeSMasaki Ota goto exit; 65273196ebeSMasaki Ota } 65373196ebeSMasaki Ota pri_data->max_fingers = 5; 65473196ebeSMasaki Ota pri_data->has_sp = 0; 65573196ebeSMasaki Ota exit: 65673196ebeSMasaki Ota return ret; 65773196ebeSMasaki Ota } 65873196ebeSMasaki Ota 6597dd8db68SBenjamin Tissoires static int alps_sp_open(struct input_dev *dev) 6607dd8db68SBenjamin Tissoires { 6617dd8db68SBenjamin Tissoires struct hid_device *hid = input_get_drvdata(dev); 6627dd8db68SBenjamin Tissoires 6637dd8db68SBenjamin Tissoires return hid_hw_open(hid); 6647dd8db68SBenjamin Tissoires } 6657dd8db68SBenjamin Tissoires 6667dd8db68SBenjamin Tissoires static void alps_sp_close(struct input_dev *dev) 6677dd8db68SBenjamin Tissoires { 6687dd8db68SBenjamin Tissoires struct hid_device *hid = input_get_drvdata(dev); 6697dd8db68SBenjamin Tissoires 6707dd8db68SBenjamin Tissoires hid_hw_close(hid); 6717dd8db68SBenjamin Tissoires } 6727dd8db68SBenjamin Tissoires 6732562756dSMasaki Ota static int alps_input_configured(struct hid_device *hdev, struct hid_input *hi) 6742562756dSMasaki Ota { 67573196ebeSMasaki Ota struct alps_dev *data = hid_get_drvdata(hdev); 6762562756dSMasaki Ota struct input_dev *input = hi->input, *input2; 6772562756dSMasaki Ota int ret; 6782562756dSMasaki Ota int res_x, res_y, i; 6792562756dSMasaki Ota 6802562756dSMasaki Ota data->input = input; 6812562756dSMasaki Ota 6822562756dSMasaki Ota hid_dbg(hdev, "Opening low level driver\n"); 6832562756dSMasaki Ota ret = hid_hw_open(hdev); 6842562756dSMasaki Ota if (ret) 6852562756dSMasaki Ota return ret; 6862562756dSMasaki Ota 6872562756dSMasaki Ota /* Allow incoming hid reports */ 6882562756dSMasaki Ota hid_device_io_start(hdev); 68973196ebeSMasaki Ota switch (data->dev_type) { 69073196ebeSMasaki Ota case T4: 69173196ebeSMasaki Ota ret = T4_init(hdev, data); 69273196ebeSMasaki Ota break; 69373196ebeSMasaki Ota case U1: 6945d8c720dSMasaki Ota ret = u1_init(hdev, data); 69573196ebeSMasaki Ota break; 69673196ebeSMasaki Ota default: 69773196ebeSMasaki Ota break; 69873196ebeSMasaki Ota } 6995d8c720dSMasaki Ota 7005d8c720dSMasaki Ota if (ret) 7012562756dSMasaki Ota goto exit; 7022562756dSMasaki Ota 7032562756dSMasaki Ota __set_bit(EV_ABS, input->evbit); 704c7083d3fSMasaki Ota input_set_abs_params(input, ABS_MT_POSITION_X, 705c7083d3fSMasaki Ota data->x_min, data->x_max, 0, 0); 706c7083d3fSMasaki Ota input_set_abs_params(input, ABS_MT_POSITION_Y, 707c7083d3fSMasaki Ota data->y_min, data->y_max, 0, 0); 7082562756dSMasaki Ota 709ce6abcf8SMasaki Ota if (data->x_active_len_mm && data->y_active_len_mm) { 710ce6abcf8SMasaki Ota res_x = (data->x_max - 1) / data->x_active_len_mm; 711ce6abcf8SMasaki Ota res_y = (data->y_max - 1) / data->y_active_len_mm; 7122562756dSMasaki Ota 7132562756dSMasaki Ota input_abs_set_res(input, ABS_MT_POSITION_X, res_x); 7142562756dSMasaki Ota input_abs_set_res(input, ABS_MT_POSITION_Y, res_y); 7152562756dSMasaki Ota } 7162562756dSMasaki Ota 7172562756dSMasaki Ota input_set_abs_params(input, ABS_MT_PRESSURE, 0, 64, 0, 0); 7182562756dSMasaki Ota 719c7083d3fSMasaki Ota input_mt_init_slots(input, data->max_fingers, INPUT_MT_POINTER); 7202562756dSMasaki Ota 7212562756dSMasaki Ota __set_bit(EV_KEY, input->evbit); 722c7083d3fSMasaki Ota 723c7083d3fSMasaki Ota if (data->btn_cnt == 1) 7242562756dSMasaki Ota __set_bit(INPUT_PROP_BUTTONPAD, input->propbit); 7252562756dSMasaki Ota 726ce6abcf8SMasaki Ota for (i = 0; i < data->btn_cnt; i++) 7272562756dSMasaki Ota __set_bit(BTN_LEFT + i, input->keybit); 7282562756dSMasaki Ota 7292562756dSMasaki Ota /* Stick device initialization */ 7305d8c720dSMasaki Ota if (data->has_sp) { 7312562756dSMasaki Ota input2 = input_allocate_device(); 7322562756dSMasaki Ota if (!input2) { 7338d2e77b3SChristophe JAILLET ret = -ENOMEM; 7342562756dSMasaki Ota goto exit; 7352562756dSMasaki Ota } 7362562756dSMasaki Ota 737819d64e5SMasaki Ota data->input2 = input2; 7382562756dSMasaki Ota input2->phys = input->phys; 7392562756dSMasaki Ota input2->name = "DualPoint Stick"; 7402562756dSMasaki Ota input2->id.bustype = BUS_I2C; 7412562756dSMasaki Ota input2->id.vendor = input->id.vendor; 7422562756dSMasaki Ota input2->id.product = input->id.product; 7432562756dSMasaki Ota input2->id.version = input->id.version; 7442562756dSMasaki Ota input2->dev.parent = input->dev.parent; 7452562756dSMasaki Ota 7467dd8db68SBenjamin Tissoires input_set_drvdata(input2, hdev); 7477dd8db68SBenjamin Tissoires input2->open = alps_sp_open; 7487dd8db68SBenjamin Tissoires input2->close = alps_sp_close; 7497dd8db68SBenjamin Tissoires 7502562756dSMasaki Ota __set_bit(EV_KEY, input2->evbit); 751ce6abcf8SMasaki Ota data->sp_btn_cnt = (data->sp_btn_info & 0x0F); 752ce6abcf8SMasaki Ota for (i = 0; i < data->sp_btn_cnt; i++) 7532562756dSMasaki Ota __set_bit(BTN_LEFT + i, input2->keybit); 7542562756dSMasaki Ota 7552562756dSMasaki Ota __set_bit(EV_REL, input2->evbit); 7562562756dSMasaki Ota __set_bit(REL_X, input2->relbit); 7572562756dSMasaki Ota __set_bit(REL_Y, input2->relbit); 7582562756dSMasaki Ota __set_bit(INPUT_PROP_POINTER, input2->propbit); 7592562756dSMasaki Ota __set_bit(INPUT_PROP_POINTING_STICK, input2->propbit); 7602562756dSMasaki Ota 761c7083d3fSMasaki Ota if (input_register_device(data->input2)) { 7622562756dSMasaki Ota input_free_device(input2); 7632562756dSMasaki Ota goto exit; 7642562756dSMasaki Ota } 7652562756dSMasaki Ota } 7662562756dSMasaki Ota 7672562756dSMasaki Ota exit: 7682562756dSMasaki Ota hid_device_io_stop(hdev); 7692562756dSMasaki Ota hid_hw_close(hdev); 7702562756dSMasaki Ota return ret; 7712562756dSMasaki Ota } 7722562756dSMasaki Ota 7732562756dSMasaki Ota static int alps_input_mapping(struct hid_device *hdev, 7742562756dSMasaki Ota struct hid_input *hi, struct hid_field *field, 7752562756dSMasaki Ota struct hid_usage *usage, unsigned long **bit, int *max) 7762562756dSMasaki Ota { 7772562756dSMasaki Ota return -1; 7782562756dSMasaki Ota } 7792562756dSMasaki Ota 7802562756dSMasaki Ota static int alps_probe(struct hid_device *hdev, const struct hid_device_id *id) 7812562756dSMasaki Ota { 78273196ebeSMasaki Ota struct alps_dev *data = NULL; 7832562756dSMasaki Ota int ret; 78473196ebeSMasaki Ota data = devm_kzalloc(&hdev->dev, sizeof(struct alps_dev), GFP_KERNEL); 7852562756dSMasaki Ota if (!data) 7862562756dSMasaki Ota return -ENOMEM; 7872562756dSMasaki Ota 7882562756dSMasaki Ota data->hdev = hdev; 7892562756dSMasaki Ota hid_set_drvdata(hdev, data); 7902562756dSMasaki Ota 7912562756dSMasaki Ota hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS; 7922562756dSMasaki Ota 7932562756dSMasaki Ota ret = hid_parse(hdev); 7942562756dSMasaki Ota if (ret) { 7952562756dSMasaki Ota hid_err(hdev, "parse failed\n"); 7962562756dSMasaki Ota return ret; 7972562756dSMasaki Ota } 7982562756dSMasaki Ota 79973196ebeSMasaki Ota switch (hdev->product) { 80073196ebeSMasaki Ota case HID_DEVICE_ID_ALPS_T4_BTNLESS: 80173196ebeSMasaki Ota data->dev_type = T4; 80273196ebeSMasaki Ota break; 80373196ebeSMasaki Ota case HID_DEVICE_ID_ALPS_U1_DUAL: 804287b8e11SMasaki Ota case HID_DEVICE_ID_ALPS_U1: 805*185af3e7SJiri Kosina case HID_DEVICE_ID_ALPS_U1_UNICORN_LEGACY: 80673196ebeSMasaki Ota data->dev_type = U1; 80773196ebeSMasaki Ota break; 80873196ebeSMasaki Ota default: 80973196ebeSMasaki Ota data->dev_type = UNKNOWN; 81073196ebeSMasaki Ota } 81173196ebeSMasaki Ota 8122562756dSMasaki Ota ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); 8132562756dSMasaki Ota if (ret) { 8142562756dSMasaki Ota hid_err(hdev, "hw start failed\n"); 8152562756dSMasaki Ota return ret; 8162562756dSMasaki Ota } 8172562756dSMasaki Ota 8182562756dSMasaki Ota return 0; 8192562756dSMasaki Ota } 8202562756dSMasaki Ota 8212562756dSMasaki Ota static void alps_remove(struct hid_device *hdev) 8222562756dSMasaki Ota { 8232562756dSMasaki Ota hid_hw_stop(hdev); 8242562756dSMasaki Ota } 8252562756dSMasaki Ota 8262562756dSMasaki Ota static const struct hid_device_id alps_id[] = { 8272562756dSMasaki Ota { HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY, 828819d64e5SMasaki Ota USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1_DUAL) }, 82973196ebeSMasaki Ota { HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY, 830287b8e11SMasaki Ota USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1) }, 831287b8e11SMasaki Ota { HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY, 83273196ebeSMasaki Ota USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_T4_BTNLESS) }, 8332562756dSMasaki Ota { } 8342562756dSMasaki Ota }; 8352562756dSMasaki Ota MODULE_DEVICE_TABLE(hid, alps_id); 8362562756dSMasaki Ota 8372562756dSMasaki Ota static struct hid_driver alps_driver = { 8382562756dSMasaki Ota .name = "hid-alps", 8392562756dSMasaki Ota .id_table = alps_id, 8402562756dSMasaki Ota .probe = alps_probe, 8412562756dSMasaki Ota .remove = alps_remove, 8422562756dSMasaki Ota .raw_event = alps_raw_event, 8432562756dSMasaki Ota .input_mapping = alps_input_mapping, 8442562756dSMasaki Ota .input_configured = alps_input_configured, 8452562756dSMasaki Ota #ifdef CONFIG_PM 8462562756dSMasaki Ota .resume = alps_post_resume, 8472562756dSMasaki Ota .reset_resume = alps_post_reset, 8482562756dSMasaki Ota #endif 8492562756dSMasaki Ota }; 8502562756dSMasaki Ota 8512562756dSMasaki Ota module_hid_driver(alps_driver); 8522562756dSMasaki Ota 8532562756dSMasaki Ota MODULE_AUTHOR("Masaki Ota <masaki.ota@jp.alps.com>"); 8542562756dSMasaki Ota MODULE_DESCRIPTION("ALPS HID driver"); 8552562756dSMasaki Ota MODULE_LICENSE("GPL"); 856