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