^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Elan Microelectronics touch panels with I2C interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2014 Elan Microelectronics Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Scott Liu <scott.liu@emc.com.tw>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * This code is partly based on hid-multitouch.c:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Copyright (c) 2010-2012 Stephane Chatty <chatty@enac.fr>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Copyright (c) 2010-2012 Benjamin Tissoires <benjamin.tissoires@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Copyright (c) 2010-2012 Ecole Nationale de l'Aviation Civile, France
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * This code is partly based on i2c-hid.c:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * Copyright (c) 2012 Benjamin Tissoires <benjamin.tissoires@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * Copyright (c) 2012 Ecole Nationale de l'Aviation Civile, France
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * Copyright (c) 2012 Red Hat, Inc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/bits.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/async.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/buffer_head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/firmware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/input/mt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/input/touchscreen.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <linux/gpio/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <linux/regulator/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <linux/uuid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <asm/unaligned.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) /* Device, Driver information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define DEVICE_NAME "elants_i2c"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) /* Convert from rows or columns into resolution */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define ELAN_TS_RESOLUTION(n, m) (((n) - 1) * (m))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) /* FW header data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define HEADER_SIZE 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define FW_HDR_TYPE 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define FW_HDR_COUNT 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define FW_HDR_LENGTH 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) /* Buffer mode Queue Header information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define QUEUE_HEADER_SINGLE 0x62
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define QUEUE_HEADER_NORMAL 0X63
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define QUEUE_HEADER_WAIT 0x64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) /* Command header definition */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define CMD_HEADER_WRITE 0x54
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #define CMD_HEADER_READ 0x53
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #define CMD_HEADER_6B_READ 0x5B
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #define CMD_HEADER_ROM_READ 0x96
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #define CMD_HEADER_RESP 0x52
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #define CMD_HEADER_6B_RESP 0x9B
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #define CMD_HEADER_ROM_RESP 0x95
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #define CMD_HEADER_HELLO 0x55
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) #define CMD_HEADER_REK 0x66
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /* FW position data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #define PACKET_SIZE 55
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #define MAX_CONTACT_NUM 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #define FW_POS_HEADER 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) #define FW_POS_STATE 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) #define FW_POS_TOTAL 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) #define FW_POS_XY 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #define FW_POS_TOOL_TYPE 33
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #define FW_POS_CHECKSUM 34
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) #define FW_POS_WIDTH 35
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #define FW_POS_PRESSURE 45
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #define HEADER_REPORT_10_FINGER 0x62
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) /* Header (4 bytes) plus 3 fill 10-finger packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) #define MAX_PACKET_SIZE 169
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) #define BOOT_TIME_DELAY_MS 50
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) /* FW read command, 0x53 0x?? 0x0, 0x01 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #define E_ELAN_INFO_FW_VER 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) #define E_ELAN_INFO_BC_VER 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) #define E_ELAN_INFO_REK 0xD0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) #define E_ELAN_INFO_TEST_VER 0xE0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) #define E_ELAN_INFO_FW_ID 0xF0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) #define E_INFO_OSR 0xD6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) #define E_INFO_PHY_SCAN 0xD7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) #define E_INFO_PHY_DRIVER 0xD8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #define MAX_RETRIES 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #define MAX_FW_UPDATE_RETRIES 30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #define ELAN_FW_PAGESIZE 132
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /* calibration timeout definition */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #define ELAN_CALI_TIMEOUT_MSEC 12000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #define ELAN_POWERON_DELAY_USEC 500
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) #define ELAN_RESET_DELAY_MSEC 20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) /* FW boot code version */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #define BC_VER_H_BYTE_FOR_EKTH3900x1_I2C 0x72
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) #define BC_VER_H_BYTE_FOR_EKTH3900x2_I2C 0x82
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) #define BC_VER_H_BYTE_FOR_EKTH3900x3_I2C 0x92
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) #define BC_VER_H_BYTE_FOR_EKTH5312x1_I2C 0x6D
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #define BC_VER_H_BYTE_FOR_EKTH5312x2_I2C 0x6E
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) #define BC_VER_H_BYTE_FOR_EKTH5312cx1_I2C 0x77
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) #define BC_VER_H_BYTE_FOR_EKTH5312cx2_I2C 0x78
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) #define BC_VER_H_BYTE_FOR_EKTH5312x1_I2C_USB 0x67
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) #define BC_VER_H_BYTE_FOR_EKTH5312x2_I2C_USB 0x68
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) #define BC_VER_H_BYTE_FOR_EKTH5312cx1_I2C_USB 0x74
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) #define BC_VER_H_BYTE_FOR_EKTH5312cx2_I2C_USB 0x75
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) enum elants_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) ELAN_STATE_NORMAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) ELAN_WAIT_QUEUE_HEADER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) ELAN_WAIT_RECALIBRATION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) enum elants_iap_mode {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) ELAN_IAP_OPERATIONAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) ELAN_IAP_RECOVERY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) /* struct elants_data - represents state of Elan touchscreen device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct elants_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) struct regulator *vcc33;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct regulator *vccio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) struct gpio_desc *reset_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) u16 fw_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) u8 test_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) u8 solution_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) u8 bc_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) u8 iap_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) u16 hw_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) u8 major_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) unsigned int x_res; /* resolution in units/mm */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) unsigned int y_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) unsigned int x_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) unsigned int y_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) struct touchscreen_properties prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) enum elants_state state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) enum elants_iap_mode iap_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) /* Guards against concurrent access to the device via sysfs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) struct mutex sysfs_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) u8 cmd_resp[HEADER_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) struct completion cmd_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) bool wake_irq_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) bool keep_power_in_suspend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) /* Must be last to be used for DMA operations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) u8 buf[MAX_PACKET_SIZE] ____cacheline_aligned;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) static int elants_i2c_send(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) const void *data, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) ret = i2c_master_send(client, data, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) if (ret == size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) if (ret >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) dev_err(&client->dev, "%s failed (%*ph): %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) __func__, (int)size, data, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static int elants_i2c_read(struct i2c_client *client, void *data, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) ret = i2c_master_recv(client, data, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (ret == size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) if (ret >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) dev_err(&client->dev, "%s failed: %d\n", __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static int elants_i2c_execute_command(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) const u8 *cmd, size_t cmd_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) u8 *resp, size_t resp_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) int retries, const char *cmd_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) struct i2c_msg msgs[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) u8 expected_response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) switch (cmd[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) case CMD_HEADER_READ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) expected_response = CMD_HEADER_RESP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) case CMD_HEADER_6B_READ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) expected_response = CMD_HEADER_6B_RESP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) case CMD_HEADER_ROM_READ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) expected_response = CMD_HEADER_ROM_RESP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) dev_err(&client->dev, "(%s): invalid command: %*ph\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) cmd_name, (int)cmd_size, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) msgs[0].addr = client->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) msgs[0].flags = client->flags & I2C_M_TEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) msgs[0].len = cmd_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) msgs[0].buf = (u8 *)cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) msgs[1].addr = client->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) msgs[1].flags = (client->flags & I2C_M_TEN) | I2C_M_RD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) msgs[1].flags |= I2C_M_RD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) msgs[1].len = resp_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) msgs[1].buf = resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) if (--retries > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) dev_dbg(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) "(%s) I2C transfer failed: %pe (retrying)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) cmd_name, ERR_PTR(ret));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) "(%s) I2C transfer failed: %pe\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) cmd_name, ERR_PTR(ret));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) if (ret != ARRAY_SIZE(msgs) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) resp[FW_HDR_TYPE] != expected_response) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) if (--retries > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) dev_dbg(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) "(%s) unexpected response: %*ph (retrying)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) cmd_name, ret, resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) "(%s) unexpected response: %*ph\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) cmd_name, ret, resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) static int elants_i2c_calibrate(struct elants_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) struct i2c_client *client = ts->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) int ret, error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) static const u8 w_flashkey[] = { 0x54, 0xC0, 0xE1, 0x5A };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) static const u8 rek[] = { 0x54, 0x29, 0x00, 0x01 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) static const u8 rek_resp[] = { CMD_HEADER_REK, 0x66, 0x66, 0x66 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) disable_irq(client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) ts->state = ELAN_WAIT_RECALIBRATION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) reinit_completion(&ts->cmd_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) elants_i2c_send(client, w_flashkey, sizeof(w_flashkey));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) elants_i2c_send(client, rek, sizeof(rek));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) enable_irq(client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) ret = wait_for_completion_interruptible_timeout(&ts->cmd_done,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) msecs_to_jiffies(ELAN_CALI_TIMEOUT_MSEC));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) ts->state = ELAN_STATE_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) if (ret <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) error = ret < 0 ? ret : -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) "error while waiting for calibration to complete: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) if (memcmp(rek_resp, ts->cmd_resp, sizeof(rek_resp))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) "unexpected calibration response: %*ph\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) (int)sizeof(ts->cmd_resp), ts->cmd_resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) static int elants_i2c_sw_reset(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) const u8 soft_rst_cmd[] = { 0x77, 0x77, 0x77, 0x77 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) error = elants_i2c_send(client, soft_rst_cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) sizeof(soft_rst_cmd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) dev_err(&client->dev, "software reset failed: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) * We should wait at least 10 msec (but no more than 40) before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) * sending fastboot or IAP command to the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) msleep(30);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) static u16 elants_i2c_parse_version(u8 *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) return get_unaligned_be32(buf) >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) static int elants_i2c_query_hw_version(struct elants_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) struct i2c_client *client = ts->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) int retry_cnt = MAX_RETRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) const u8 cmd[] = { CMD_HEADER_READ, E_ELAN_INFO_FW_ID, 0x00, 0x01 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) u8 resp[HEADER_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) while (retry_cnt--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) error = elants_i2c_execute_command(client, cmd, sizeof(cmd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) resp, sizeof(resp), 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) "read fw id");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) ts->hw_version = elants_i2c_parse_version(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) if (ts->hw_version != 0xffff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) dev_err(&client->dev, "Invalid fw id: %#04x\n", ts->hw_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) static int elants_i2c_query_fw_version(struct elants_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) struct i2c_client *client = ts->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) int retry_cnt = MAX_RETRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) const u8 cmd[] = { CMD_HEADER_READ, E_ELAN_INFO_FW_VER, 0x00, 0x01 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) u8 resp[HEADER_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) while (retry_cnt--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) error = elants_i2c_execute_command(client, cmd, sizeof(cmd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) resp, sizeof(resp), 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) "read fw version");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) ts->fw_version = elants_i2c_parse_version(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) if (ts->fw_version != 0x0000 && ts->fw_version != 0xffff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) dev_dbg(&client->dev, "(read fw version) resp %*phC\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) (int)sizeof(resp), resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) dev_err(&client->dev, "Invalid fw ver: %#04x\n", ts->fw_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) static int elants_i2c_query_test_version(struct elants_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) struct i2c_client *client = ts->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) u16 version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) const u8 cmd[] = { CMD_HEADER_READ, E_ELAN_INFO_TEST_VER, 0x00, 0x01 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) u8 resp[HEADER_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) error = elants_i2c_execute_command(client, cmd, sizeof(cmd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) resp, sizeof(resp), MAX_RETRIES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) "read test version");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) dev_err(&client->dev, "Failed to read test version\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) version = elants_i2c_parse_version(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) ts->test_version = version >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) ts->solution_version = version & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) static int elants_i2c_query_bc_version(struct elants_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) struct i2c_client *client = ts->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) const u8 cmd[] = { CMD_HEADER_READ, E_ELAN_INFO_BC_VER, 0x00, 0x01 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) u8 resp[HEADER_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) u16 version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) error = elants_i2c_execute_command(client, cmd, sizeof(cmd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) resp, sizeof(resp), 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) "read BC version");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) version = elants_i2c_parse_version(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) ts->bc_version = version >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) ts->iap_version = version & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) static int elants_i2c_query_ts_info(struct elants_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) struct i2c_client *client = ts->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) u8 resp[17];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) u16 phy_x, phy_y, rows, cols, osr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) const u8 get_resolution_cmd[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) CMD_HEADER_6B_READ, 0x00, 0x00, 0x00, 0x00, 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) const u8 get_osr_cmd[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) CMD_HEADER_READ, E_INFO_OSR, 0x00, 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) const u8 get_physical_scan_cmd[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) CMD_HEADER_READ, E_INFO_PHY_SCAN, 0x00, 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) const u8 get_physical_drive_cmd[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) CMD_HEADER_READ, E_INFO_PHY_DRIVER, 0x00, 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) /* Get trace number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) error = elants_i2c_execute_command(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) get_resolution_cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) sizeof(get_resolution_cmd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) resp, sizeof(resp), 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) "get resolution");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) rows = resp[2] + resp[6] + resp[10];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) cols = resp[3] + resp[7] + resp[11];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) /* Get report resolution value of ABS_MT_TOUCH_MAJOR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) ts->major_res = resp[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) /* Process mm_to_pixel information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) error = elants_i2c_execute_command(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) get_osr_cmd, sizeof(get_osr_cmd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) resp, sizeof(resp), 1, "get osr");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) osr = resp[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) error = elants_i2c_execute_command(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) get_physical_scan_cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) sizeof(get_physical_scan_cmd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) resp, sizeof(resp), 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) "get physical scan");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) phy_x = get_unaligned_be16(&resp[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) error = elants_i2c_execute_command(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) get_physical_drive_cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) sizeof(get_physical_drive_cmd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) resp, sizeof(resp), 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) "get physical drive");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) phy_y = get_unaligned_be16(&resp[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) dev_dbg(&client->dev, "phy_x=%d, phy_y=%d\n", phy_x, phy_y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) if (rows == 0 || cols == 0 || osr == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) dev_warn(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) "invalid trace number data: %d, %d, %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) rows, cols, osr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) /* translate trace number to TS resolution */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) ts->x_max = ELAN_TS_RESOLUTION(rows, osr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) ts->x_res = DIV_ROUND_CLOSEST(ts->x_max, phy_x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) ts->y_max = ELAN_TS_RESOLUTION(cols, osr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) ts->y_res = DIV_ROUND_CLOSEST(ts->y_max, phy_y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) static int elants_i2c_fastboot(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) const u8 boot_cmd[] = { 0x4D, 0x61, 0x69, 0x6E };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) error = elants_i2c_send(client, boot_cmd, sizeof(boot_cmd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) dev_err(&client->dev, "boot failed: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) dev_dbg(&client->dev, "boot success -- 0x%x\n", client->addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) return 0;
^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) static int elants_i2c_initialize(struct elants_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) struct i2c_client *client = ts->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) int error, error2, retry_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) const u8 hello_packet[] = { 0x55, 0x55, 0x55, 0x55 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) const u8 recov_packet[] = { 0x55, 0x55, 0x80, 0x80 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) u8 buf[HEADER_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) for (retry_cnt = 0; retry_cnt < MAX_RETRIES; retry_cnt++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) error = elants_i2c_sw_reset(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) /* Continue initializing if it's the last try */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) if (retry_cnt < MAX_RETRIES - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) error = elants_i2c_fastboot(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) /* Continue initializing if it's the last try */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) if (retry_cnt < MAX_RETRIES - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) /* Wait for Hello packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) msleep(BOOT_TIME_DELAY_MS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) error = elants_i2c_read(client, buf, sizeof(buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) "failed to read 'hello' packet: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) } else if (!memcmp(buf, hello_packet, sizeof(hello_packet))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) ts->iap_mode = ELAN_IAP_OPERATIONAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) } else if (!memcmp(buf, recov_packet, sizeof(recov_packet))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) * Setting error code will mark device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) * in recovery mode below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) error = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) error = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) "invalid 'hello' packet: %*ph\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) (int)sizeof(buf), buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) /* hw version is available even if device in recovery state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) error2 = elants_i2c_query_hw_version(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) if (!error2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) error2 = elants_i2c_query_bc_version(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) if (!error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) error = error2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) if (!error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) error = elants_i2c_query_fw_version(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) if (!error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) error = elants_i2c_query_test_version(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) if (!error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) error = elants_i2c_query_ts_info(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) ts->iap_mode = ELAN_IAP_RECOVERY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) return 0;
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) * Firmware update interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) static int elants_i2c_fw_write_page(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) const void *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) const u8 ack_ok[] = { 0xaa, 0xaa };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) u8 buf[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) int retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) for (retry = 0; retry < MAX_FW_UPDATE_RETRIES; retry++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) error = elants_i2c_send(client, page, ELAN_FW_PAGESIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) "IAP Write Page failed: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) error = elants_i2c_read(client, buf, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) "IAP Ack read failed: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) if (!memcmp(buf, ack_ok, sizeof(ack_ok)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) error = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) "IAP Get Ack Error [%02x:%02x]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) buf[0], buf[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) return error;
^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) static int elants_i2c_validate_remark_id(struct elants_data *ts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) const struct firmware *fw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) struct i2c_client *client = ts->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) const u8 cmd[] = { CMD_HEADER_ROM_READ, 0x80, 0x1F, 0x00, 0x00, 0x21 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) u8 resp[6] = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) u16 ts_remark_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) u16 fw_remark_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) /* Compare TS Remark ID and FW Remark ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) error = elants_i2c_execute_command(client, cmd, sizeof(cmd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) resp, sizeof(resp),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 1, "read Remark ID");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) ts_remark_id = get_unaligned_be16(&resp[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) fw_remark_id = get_unaligned_le16(&fw->data[fw->size - 4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) if (fw_remark_id != ts_remark_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) "Remark ID Mismatched: ts_remark_id=0x%04x, fw_remark_id=0x%04x.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) ts_remark_id, fw_remark_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) static bool elants_i2c_should_check_remark_id(struct elants_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) struct i2c_client *client = ts->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) const u8 bootcode_version = ts->iap_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) bool check;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) /* I2C eKTH3900 and eKTH5312 are NOT support Remark ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) if ((bootcode_version == BC_VER_H_BYTE_FOR_EKTH3900x1_I2C) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) (bootcode_version == BC_VER_H_BYTE_FOR_EKTH3900x2_I2C) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) (bootcode_version == BC_VER_H_BYTE_FOR_EKTH3900x3_I2C) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) (bootcode_version == BC_VER_H_BYTE_FOR_EKTH5312x1_I2C) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) (bootcode_version == BC_VER_H_BYTE_FOR_EKTH5312x2_I2C) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) (bootcode_version == BC_VER_H_BYTE_FOR_EKTH5312cx1_I2C) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) (bootcode_version == BC_VER_H_BYTE_FOR_EKTH5312cx2_I2C) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) (bootcode_version == BC_VER_H_BYTE_FOR_EKTH5312x1_I2C_USB) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) (bootcode_version == BC_VER_H_BYTE_FOR_EKTH5312x2_I2C_USB) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) (bootcode_version == BC_VER_H_BYTE_FOR_EKTH5312cx1_I2C_USB) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) (bootcode_version == BC_VER_H_BYTE_FOR_EKTH5312cx2_I2C_USB)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) dev_dbg(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) "eKTH3900/eKTH5312(0x%02x) are not support remark id\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) bootcode_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) check = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) } else if (bootcode_version >= 0x60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) check = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) check = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) return check;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) static int elants_i2c_do_update_firmware(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) const struct firmware *fw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) bool force)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) struct elants_data *ts = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) const u8 enter_iap[] = { 0x45, 0x49, 0x41, 0x50 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) const u8 enter_iap2[] = { 0x54, 0x00, 0x12, 0x34 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) const u8 iap_ack[] = { 0x55, 0xaa, 0x33, 0xcc };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) const u8 close_idle[] = { 0x54, 0x2c, 0x01, 0x01 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) u8 buf[HEADER_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) u16 send_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) int page, n_fw_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) bool check_remark_id = elants_i2c_should_check_remark_id(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) /* Recovery mode detection! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) if (force) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) dev_dbg(&client->dev, "Recovery mode procedure\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) if (check_remark_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) error = elants_i2c_validate_remark_id(ts, fw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) error = elants_i2c_send(client, enter_iap2, sizeof(enter_iap2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) dev_err(&client->dev, "failed to enter IAP mode: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) /* Start IAP Procedure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) dev_dbg(&client->dev, "Normal IAP procedure\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) /* Close idle mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) error = elants_i2c_send(client, close_idle, sizeof(close_idle));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) dev_err(&client->dev, "Failed close idle: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) msleep(60);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) elants_i2c_sw_reset(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) msleep(20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) if (check_remark_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) error = elants_i2c_validate_remark_id(ts, fw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) error = elants_i2c_send(client, enter_iap, sizeof(enter_iap));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) dev_err(&client->dev, "failed to enter IAP mode: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) }
^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) msleep(20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) /* check IAP state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) error = elants_i2c_read(client, buf, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) "failed to read IAP acknowledgement: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) if (memcmp(buf, iap_ack, sizeof(iap_ack))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) "failed to enter IAP: %*ph (expected %*ph)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) (int)sizeof(buf), buf, (int)sizeof(iap_ack), iap_ack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) dev_info(&client->dev, "successfully entered IAP mode");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) send_id = client->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) error = elants_i2c_send(client, &send_id, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) dev_err(&client->dev, "sending dummy byte failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) /* Clear the last page of Master */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) error = elants_i2c_send(client, fw->data, ELAN_FW_PAGESIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) dev_err(&client->dev, "clearing of the last page failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) error = elants_i2c_read(client, buf, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) "failed to read ACK for clearing the last page: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) n_fw_pages = fw->size / ELAN_FW_PAGESIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) dev_dbg(&client->dev, "IAP Pages = %d\n", n_fw_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) for (page = 0; page < n_fw_pages; page++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) error = elants_i2c_fw_write_page(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) fw->data + page * ELAN_FW_PAGESIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) "failed to write FW page %d: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) page, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) /* Old iap needs to wait 200ms for WDT and rest is for hello packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) msleep(300);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) dev_info(&client->dev, "firmware update completed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) static int elants_i2c_fw_update(struct elants_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) struct i2c_client *client = ts->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) const struct firmware *fw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) char *fw_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) fw_name = kasprintf(GFP_KERNEL, "elants_i2c_%04x.bin", ts->hw_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) if (!fw_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) dev_info(&client->dev, "requesting fw name = %s\n", fw_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) error = request_firmware(&fw, fw_name, &client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) kfree(fw_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) dev_err(&client->dev, "failed to request firmware: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) return error;
^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) if (fw->size % ELAN_FW_PAGESIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) dev_err(&client->dev, "invalid firmware length: %zu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) fw->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) error = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) disable_irq(client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) error = elants_i2c_do_update_firmware(client, fw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) ts->iap_mode == ELAN_IAP_RECOVERY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) dev_err(&client->dev, "firmware update failed: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) ts->iap_mode = ELAN_IAP_RECOVERY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) goto out_enable_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) error = elants_i2c_initialize(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) "failed to initialize device after firmware update: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) ts->iap_mode = ELAN_IAP_RECOVERY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) goto out_enable_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) ts->iap_mode = ELAN_IAP_OPERATIONAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) out_enable_irq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) ts->state = ELAN_STATE_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) enable_irq(client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) msleep(100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) if (!error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) elants_i2c_calibrate(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) release_firmware(fw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) * Event reporting.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) static void elants_i2c_mt_event(struct elants_data *ts, u8 *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) struct input_dev *input = ts->input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) unsigned int n_fingers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) unsigned int tool_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) u16 finger_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) n_fingers = buf[FW_POS_STATE + 1] & 0x0f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) finger_state = ((buf[FW_POS_STATE + 1] & 0x30) << 4) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) buf[FW_POS_STATE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) dev_dbg(&ts->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) "n_fingers: %u, state: %04x\n", n_fingers, finger_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) /* Note: all fingers have the same tool type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) tool_type = buf[FW_POS_TOOL_TYPE] & BIT(0) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) MT_TOOL_FINGER : MT_TOOL_PALM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) for (i = 0; i < MAX_CONTACT_NUM && n_fingers; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) if (finger_state & 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) unsigned int x, y, p, w;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) u8 *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) pos = &buf[FW_POS_XY + i * 3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) x = (((u16)pos[0] & 0xf0) << 4) | pos[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) y = (((u16)pos[0] & 0x0f) << 8) | pos[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) p = buf[FW_POS_PRESSURE + i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) w = buf[FW_POS_WIDTH + i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) dev_dbg(&ts->client->dev, "i=%d x=%d y=%d p=%d w=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) i, x, y, p, w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) input_mt_slot(input, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) input_mt_report_slot_state(input, tool_type, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) touchscreen_report_pos(input, &ts->prop, x, y, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) input_event(input, EV_ABS, ABS_MT_PRESSURE, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) n_fingers--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) finger_state >>= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) input_mt_sync_frame(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) input_sync(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) static u8 elants_i2c_calculate_checksum(u8 *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) u8 checksum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) u8 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) for (i = 0; i < FW_POS_CHECKSUM; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) checksum += buf[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) return checksum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) static void elants_i2c_event(struct elants_data *ts, u8 *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) u8 checksum = elants_i2c_calculate_checksum(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) if (unlikely(buf[FW_POS_CHECKSUM] != checksum))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) dev_warn(&ts->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) "%s: invalid checksum for packet %02x: %02x vs. %02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) __func__, buf[FW_POS_HEADER],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) checksum, buf[FW_POS_CHECKSUM]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) else if (unlikely(buf[FW_POS_HEADER] != HEADER_REPORT_10_FINGER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) dev_warn(&ts->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) "%s: unknown packet type: %02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) __func__, buf[FW_POS_HEADER]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) elants_i2c_mt_event(ts, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) static irqreturn_t elants_i2c_irq(int irq, void *_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) const u8 wait_packet[] = { 0x64, 0x64, 0x64, 0x64 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) struct elants_data *ts = _dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) struct i2c_client *client = ts->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) int report_count, report_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) len = i2c_master_recv_dmasafe(client, ts->buf, sizeof(ts->buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) if (len < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) dev_err(&client->dev, "%s: failed to read data: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) __func__, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) dev_dbg(&client->dev, "%s: packet %*ph\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) __func__, HEADER_SIZE, ts->buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) switch (ts->state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) case ELAN_WAIT_RECALIBRATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) if (ts->buf[FW_HDR_TYPE] == CMD_HEADER_REK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) memcpy(ts->cmd_resp, ts->buf, sizeof(ts->cmd_resp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) complete(&ts->cmd_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) ts->state = ELAN_STATE_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) case ELAN_WAIT_QUEUE_HEADER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) if (ts->buf[FW_HDR_TYPE] != QUEUE_HEADER_NORMAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) ts->state = ELAN_STATE_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) case ELAN_STATE_NORMAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) switch (ts->buf[FW_HDR_TYPE]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) case CMD_HEADER_HELLO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) case CMD_HEADER_RESP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) case CMD_HEADER_REK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) case QUEUE_HEADER_WAIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) if (memcmp(ts->buf, wait_packet, sizeof(wait_packet))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) "invalid wait packet %*ph\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) HEADER_SIZE, ts->buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) ts->state = ELAN_WAIT_QUEUE_HEADER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) udelay(30);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) case QUEUE_HEADER_SINGLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) elants_i2c_event(ts, &ts->buf[HEADER_SIZE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) case QUEUE_HEADER_NORMAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) report_count = ts->buf[FW_HDR_COUNT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) if (report_count == 0 || report_count > 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) "bad report count: %*ph\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) HEADER_SIZE, ts->buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) report_len = ts->buf[FW_HDR_LENGTH] / report_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) if (report_len != PACKET_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) "mismatching report length: %*ph\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) HEADER_SIZE, ts->buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) for (i = 0; i < report_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) u8 *buf = ts->buf + HEADER_SIZE +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) i * PACKET_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) elants_i2c_event(ts, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) dev_err(&client->dev, "unknown packet %*ph\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) HEADER_SIZE, ts->buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) * sysfs interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) static ssize_t calibrate_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) struct elants_data *ts = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) error = mutex_lock_interruptible(&ts->sysfs_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) error = elants_i2c_calibrate(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) mutex_unlock(&ts->sysfs_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) return error ?: count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) static ssize_t write_update_fw(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) struct elants_data *ts = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) error = mutex_lock_interruptible(&ts->sysfs_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) error = elants_i2c_fw_update(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) dev_dbg(dev, "firmware update result: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) mutex_unlock(&ts->sysfs_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) return error ?: count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) static ssize_t show_iap_mode(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) struct elants_data *ts = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) return sprintf(buf, "%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) ts->iap_mode == ELAN_IAP_OPERATIONAL ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) "Normal" : "Recovery");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) static ssize_t show_calibration_count(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) const u8 cmd[] = { CMD_HEADER_READ, E_ELAN_INFO_REK, 0x00, 0x01 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) u8 resp[HEADER_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) u16 rek_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) error = elants_i2c_execute_command(client, cmd, sizeof(cmd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) resp, sizeof(resp), 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) "read ReK status");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) return sprintf(buf, "%d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) rek_count = get_unaligned_be16(&resp[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) return sprintf(buf, "0x%04x\n", rek_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) static DEVICE_ATTR_WO(calibrate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) static DEVICE_ATTR(iap_mode, S_IRUGO, show_iap_mode, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) static DEVICE_ATTR(calibration_count, S_IRUGO, show_calibration_count, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) static DEVICE_ATTR(update_fw, S_IWUSR, NULL, write_update_fw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) struct elants_version_attribute {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) struct device_attribute dattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) size_t field_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) size_t field_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) #define __ELANTS_FIELD_SIZE(_field) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) sizeof(((struct elants_data *)NULL)->_field)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) #define __ELANTS_VERIFY_SIZE(_field) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) (BUILD_BUG_ON_ZERO(__ELANTS_FIELD_SIZE(_field) > 2) + \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) __ELANTS_FIELD_SIZE(_field))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) #define ELANTS_VERSION_ATTR(_field) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) struct elants_version_attribute elants_ver_attr_##_field = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) .dattr = __ATTR(_field, S_IRUGO, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) elants_version_attribute_show, NULL), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) .field_offset = offsetof(struct elants_data, _field), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) .field_size = __ELANTS_VERIFY_SIZE(_field), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) static ssize_t elants_version_attribute_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) struct device_attribute *dattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) struct elants_data *ts = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) struct elants_version_attribute *attr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) container_of(dattr, struct elants_version_attribute, dattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) u8 *field = (u8 *)((char *)ts + attr->field_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) unsigned int fmt_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) if (attr->field_size == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) val = *field;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) fmt_size = 2; /* 2 HEX digits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) val = *(u16 *)field;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) fmt_size = 4; /* 4 HEX digits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) return sprintf(buf, "%0*x\n", fmt_size, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) static ELANTS_VERSION_ATTR(fw_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) static ELANTS_VERSION_ATTR(hw_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) static ELANTS_VERSION_ATTR(test_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) static ELANTS_VERSION_ATTR(solution_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) static ELANTS_VERSION_ATTR(bc_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) static ELANTS_VERSION_ATTR(iap_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) static struct attribute *elants_attributes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) &dev_attr_calibrate.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) &dev_attr_update_fw.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) &dev_attr_iap_mode.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) &dev_attr_calibration_count.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) &elants_ver_attr_fw_version.dattr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) &elants_ver_attr_hw_version.dattr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) &elants_ver_attr_test_version.dattr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) &elants_ver_attr_solution_version.dattr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) &elants_ver_attr_bc_version.dattr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) &elants_ver_attr_iap_version.dattr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) static const struct attribute_group elants_attribute_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) .attrs = elants_attributes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) static int elants_i2c_power_on(struct elants_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) * If we do not have reset gpio assume platform firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) * controls regulators and does power them on for us.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) if (IS_ERR_OR_NULL(ts->reset_gpio))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) gpiod_set_value_cansleep(ts->reset_gpio, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) error = regulator_enable(ts->vcc33);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) dev_err(&ts->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) "failed to enable vcc33 regulator: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) goto release_reset_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) error = regulator_enable(ts->vccio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) dev_err(&ts->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) "failed to enable vccio regulator: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) regulator_disable(ts->vcc33);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) goto release_reset_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) * We need to wait a bit after powering on controller before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) * we are allowed to release reset GPIO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) udelay(ELAN_POWERON_DELAY_USEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) release_reset_gpio:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) gpiod_set_value_cansleep(ts->reset_gpio, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) msleep(ELAN_RESET_DELAY_MSEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) static void elants_i2c_power_off(void *_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) struct elants_data *ts = _data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) if (!IS_ERR_OR_NULL(ts->reset_gpio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) * Activate reset gpio to prevent leakage through the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) * pin once we shut off power to the controller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) gpiod_set_value_cansleep(ts->reset_gpio, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) regulator_disable(ts->vccio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) regulator_disable(ts->vcc33);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) #ifdef CONFIG_ACPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) static const struct acpi_device_id i2c_hid_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) {"ACPI0C50", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) {"PNP0C50", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) { },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) static const guid_t i2c_hid_guid =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) GUID_INIT(0x3CDFF6F7, 0x4267, 0x4555,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 0xAD, 0x05, 0xB3, 0x0A, 0x3D, 0x89, 0x38, 0xDE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) static bool elants_acpi_is_hid_device(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) acpi_handle handle = ACPI_HANDLE(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) union acpi_object *obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) if (acpi_match_device_ids(ACPI_COMPANION(dev), i2c_hid_ids))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) obj = acpi_evaluate_dsm_typed(handle, &i2c_hid_guid, 1, 1, NULL, ACPI_TYPE_INTEGER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) if (obj) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) ACPI_FREE(obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) static bool elants_acpi_is_hid_device(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) static int elants_i2c_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) union i2c_smbus_data dummy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) struct elants_data *ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) unsigned long irqflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) /* Don't bind to i2c-hid compatible devices, these are handled by the i2c-hid drv. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) if (elants_acpi_is_hid_device(&client->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) dev_warn(&client->dev, "This device appears to be an I2C-HID device, not binding\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) dev_err(&client->dev, "I2C check functionality error\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) ts = devm_kzalloc(&client->dev, sizeof(struct elants_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) if (!ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) mutex_init(&ts->sysfs_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) init_completion(&ts->cmd_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) ts->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) i2c_set_clientdata(client, ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) ts->vcc33 = devm_regulator_get(&client->dev, "vcc33");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) if (IS_ERR(ts->vcc33)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) error = PTR_ERR(ts->vcc33);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) if (error != -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) "Failed to get 'vcc33' regulator: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) ts->vccio = devm_regulator_get(&client->dev, "vccio");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) if (IS_ERR(ts->vccio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) error = PTR_ERR(ts->vccio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) if (error != -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) "Failed to get 'vccio' regulator: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) ts->reset_gpio = devm_gpiod_get(&client->dev, "reset", GPIOD_OUT_LOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) if (IS_ERR(ts->reset_gpio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) error = PTR_ERR(ts->reset_gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) if (error == -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) if (error != -ENOENT && error != -ENOSYS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) "failed to get reset gpio: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) ts->keep_power_in_suspend = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) error = elants_i2c_power_on(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) error = devm_add_action(&client->dev, elants_i2c_power_off, ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) "failed to install power off action: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) elants_i2c_power_off(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) /* Make sure there is something at this address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) if (i2c_smbus_xfer(client->adapter, client->addr, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) I2C_SMBUS_READ, 0, I2C_SMBUS_BYTE, &dummy) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) dev_err(&client->dev, "nothing at this address\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) error = elants_i2c_initialize(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) dev_err(&client->dev, "failed to initialize: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) ts->input = devm_input_allocate_device(&client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) if (!ts->input) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) dev_err(&client->dev, "Failed to allocate input device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) ts->input->name = "Elan Touchscreen";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) ts->input->id.bustype = BUS_I2C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) /* Multitouch input params setup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) input_set_abs_params(ts->input, ABS_MT_POSITION_X, 0, ts->x_max, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) input_set_abs_params(ts->input, ABS_MT_POSITION_Y, 0, ts->y_max, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) input_set_abs_params(ts->input, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) input_set_abs_params(ts->input, ABS_MT_PRESSURE, 0, 255, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) input_set_abs_params(ts->input, ABS_MT_TOOL_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 0, MT_TOOL_PALM, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) input_abs_set_res(ts->input, ABS_MT_POSITION_X, ts->x_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) input_abs_set_res(ts->input, ABS_MT_POSITION_Y, ts->y_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) if (ts->major_res > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) input_abs_set_res(ts->input, ABS_MT_TOUCH_MAJOR, ts->major_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) touchscreen_parse_properties(ts->input, true, &ts->prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) error = input_mt_init_slots(ts->input, MAX_CONTACT_NUM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) "failed to initialize MT slots: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) error = input_register_device(ts->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) "unable to register input device: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) * Platform code (ACPI, DTS) should normally set up interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) * for us, but in case it did not let's fall back to using falling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) * edge to be compatible with older Chromebooks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) irqflags = irq_get_trigger_type(client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) if (!irqflags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) irqflags = IRQF_TRIGGER_FALLING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) error = devm_request_threaded_irq(&client->dev, client->irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) NULL, elants_i2c_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) irqflags | IRQF_ONESHOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) client->name, ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) dev_err(&client->dev, "Failed to register interrupt\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) * Systems using device tree should set up wakeup via DTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) * the rest will configure device as wakeup source by default.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) if (!client->dev.of_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) device_init_wakeup(&client->dev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) error = devm_device_add_group(&client->dev, &elants_attribute_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) dev_err(&client->dev, "failed to create sysfs attributes: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) static int __maybe_unused elants_i2c_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) struct elants_data *ts = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) const u8 set_sleep_cmd[] = { 0x54, 0x50, 0x00, 0x01 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) int retry_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) /* Command not support in IAP recovery mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) if (ts->iap_mode != ELAN_IAP_OPERATIONAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) disable_irq(client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) if (device_may_wakeup(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) * The device will automatically enter idle mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) * that has reduced power consumption.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) ts->wake_irq_enabled = (enable_irq_wake(client->irq) == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) } else if (ts->keep_power_in_suspend) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) for (retry_cnt = 0; retry_cnt < MAX_RETRIES; retry_cnt++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) error = elants_i2c_send(client, set_sleep_cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) sizeof(set_sleep_cmd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) if (!error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) "suspend command failed: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) elants_i2c_power_off(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) static int __maybe_unused elants_i2c_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) struct elants_data *ts = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) const u8 set_active_cmd[] = { 0x54, 0x58, 0x00, 0x01 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) int retry_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) if (device_may_wakeup(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) if (ts->wake_irq_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) disable_irq_wake(client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) elants_i2c_sw_reset(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) } else if (ts->keep_power_in_suspend) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) for (retry_cnt = 0; retry_cnt < MAX_RETRIES; retry_cnt++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) error = elants_i2c_send(client, set_active_cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) sizeof(set_active_cmd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) if (!error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) "resume command failed: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) elants_i2c_power_on(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) elants_i2c_initialize(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) ts->state = ELAN_STATE_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) enable_irq(client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) static SIMPLE_DEV_PM_OPS(elants_i2c_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) elants_i2c_suspend, elants_i2c_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) static const struct i2c_device_id elants_i2c_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) { DEVICE_NAME, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) MODULE_DEVICE_TABLE(i2c, elants_i2c_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) #ifdef CONFIG_ACPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) static const struct acpi_device_id elants_acpi_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) { "ELAN0001", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) MODULE_DEVICE_TABLE(acpi, elants_acpi_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) static const struct of_device_id elants_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) { .compatible = "elan,ekth3500" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) { /* sentinel */ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) MODULE_DEVICE_TABLE(of, elants_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) static struct i2c_driver elants_i2c_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) .probe = elants_i2c_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) .id_table = elants_i2c_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) .name = DEVICE_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) .pm = &elants_i2c_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) .acpi_match_table = ACPI_PTR(elants_acpi_id),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) .of_match_table = of_match_ptr(elants_of_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) .probe_type = PROBE_PREFER_ASYNCHRONOUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) module_i2c_driver(elants_i2c_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) MODULE_AUTHOR("Scott Liu <scott.liu@emc.com.tw>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) MODULE_DESCRIPTION("Elan I2c Touchscreen driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) MODULE_LICENSE("GPL");