^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) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/input/mt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/input/touchscreen.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/regulator/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) /* Register Map */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define BT541_SWRESET_CMD 0x0000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define BT541_WAKEUP_CMD 0x0001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define BT541_IDLE_CMD 0x0004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define BT541_SLEEP_CMD 0x0005
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define BT541_CLEAR_INT_STATUS_CMD 0x0003
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define BT541_CALIBRATE_CMD 0x0006
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define BT541_SAVE_STATUS_CMD 0x0007
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define BT541_SAVE_CALIBRATION_CMD 0x0008
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define BT541_RECALL_FACTORY_CMD 0x000f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define BT541_THRESHOLD 0x0020
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define BT541_LARGE_PALM_REJECT_AREA_TH 0x003F
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define BT541_DEBUG_REG 0x0115 /* 0~7 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define BT541_TOUCH_MODE 0x0010
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define BT541_CHIP_REVISION 0x0011
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define BT541_FIRMWARE_VERSION 0x0012
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define ZINITIX_USB_DETECT 0x116
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define BT541_MINOR_FW_VERSION 0x0121
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define BT541_VENDOR_ID 0x001C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define BT541_HW_ID 0x0014
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define BT541_DATA_VERSION_REG 0x0013
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define BT541_SUPPORTED_FINGER_NUM 0x0015
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define BT541_EEPROM_INFO 0x0018
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define BT541_INITIAL_TOUCH_MODE 0x0019
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define BT541_TOTAL_NUMBER_OF_X 0x0060
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define BT541_TOTAL_NUMBER_OF_Y 0x0061
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define BT541_DELAY_RAW_FOR_HOST 0x007f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define BT541_BUTTON_SUPPORTED_NUM 0x00B0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define BT541_BUTTON_SENSITIVITY 0x00B2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define BT541_DUMMY_BUTTON_SENSITIVITY 0X00C8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #define BT541_X_RESOLUTION 0x00C0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define BT541_Y_RESOLUTION 0x00C1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #define BT541_POINT_STATUS_REG 0x0080
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #define BT541_ICON_STATUS_REG 0x00AA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #define BT541_POINT_COORD_REG (BT541_POINT_STATUS_REG + 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #define BT541_AFE_FREQUENCY 0x0100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) #define BT541_DND_N_COUNT 0x0122
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #define BT541_DND_U_COUNT 0x0135
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #define BT541_RAWDATA_REG 0x0200
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #define BT541_EEPROM_INFO_REG 0x0018
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) #define BT541_INT_ENABLE_FLAG 0x00f0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) #define BT541_PERIODICAL_INTERRUPT_INTERVAL 0x00f1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #define BT541_BTN_WIDTH 0x016d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #define BT541_CHECKSUM_RESULT 0x012c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #define BT541_INIT_FLASH 0x01d0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) #define BT541_WRITE_FLASH 0x01d1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) #define BT541_READ_FLASH 0x01d2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) #define ZINITIX_INTERNAL_FLAG_02 0x011e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) #define ZINITIX_INTERNAL_FLAG_03 0x011f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) #define ZINITIX_I2C_CHECKSUM_WCNT 0x016a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #define ZINITIX_I2C_CHECKSUM_RESULT 0x016c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) /* Interrupt & status register flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) #define BIT_PT_CNT_CHANGE BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) #define BIT_DOWN BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) #define BIT_MOVE BIT(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) #define BIT_UP BIT(3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #define BIT_PALM BIT(4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #define BIT_PALM_REJECT BIT(5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #define BIT_RESERVED_0 BIT(6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #define BIT_RESERVED_1 BIT(7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #define BIT_WEIGHT_CHANGE BIT(8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) #define BIT_PT_NO_CHANGE BIT(9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #define BIT_REJECT BIT(10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #define BIT_PT_EXIST BIT(11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) #define BIT_RESERVED_2 BIT(12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #define BIT_ERROR BIT(13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) #define BIT_DEBUG BIT(14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #define BIT_ICON_EVENT BIT(15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #define SUB_BIT_EXIST BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) #define SUB_BIT_DOWN BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) #define SUB_BIT_MOVE BIT(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) #define SUB_BIT_UP BIT(3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #define SUB_BIT_UPDATE BIT(4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) #define SUB_BIT_WAIT BIT(5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) #define DEFAULT_TOUCH_POINT_MODE 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) #define MAX_SUPPORTED_FINGER_NUM 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) #define CHIP_ON_DELAY 15 // ms
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) #define FIRMWARE_ON_DELAY 40 // ms
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) struct point_coord {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) __le16 x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) __le16 y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) u8 width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) u8 sub_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) // currently unused, but needed as padding:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) u8 minor_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) u8 angle;
^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 touch_event {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) __le16 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) u8 finger_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) u8 time_stamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) struct point_coord point_coord[MAX_SUPPORTED_FINGER_NUM];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) struct bt541_ts_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) struct touchscreen_properties prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct regulator_bulk_data supplies[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) u32 zinitix_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static int zinitix_read_data(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) u16 reg, void *values, size_t length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) __le16 reg_le = cpu_to_le16(reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) /* A single i2c_transfer() transaction does not work here. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) ret = i2c_master_send(client, (u8 *)®_le, sizeof(reg_le));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) if (ret != sizeof(reg_le))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) return ret < 0 ? ret : -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) ret = i2c_master_recv(client, (u8 *)values, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (ret != length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) return ret < 0 ? ret : -EIO; ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static int zinitix_write_u16(struct i2c_client *client, u16 reg, u16 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) __le16 packet[2] = {cpu_to_le16(reg), cpu_to_le16(value)};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) ret = i2c_master_send(client, (u8 *)packet, sizeof(packet));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) if (ret != sizeof(packet))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) return ret < 0 ? ret : -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) static int zinitix_write_cmd(struct i2c_client *client, u16 reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) __le16 reg_le = cpu_to_le16(reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) ret = i2c_master_send(client, (u8 *)®_le, sizeof(reg_le));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) if (ret != sizeof(reg_le))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) return ret < 0 ? ret : -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) static int zinitix_init_touch(struct bt541_ts_data *bt541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) struct i2c_client *client = bt541->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) error = zinitix_write_cmd(client, BT541_SWRESET_CMD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) dev_err(&client->dev, "Failed to write reset command\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) error = zinitix_write_u16(client, BT541_INT_ENABLE_FLAG, 0x0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) "Failed to reset interrupt enable flag\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) /* initialize */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) error = zinitix_write_u16(client, BT541_X_RESOLUTION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) bt541->prop.max_x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) error = zinitix_write_u16(client, BT541_Y_RESOLUTION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) bt541->prop.max_y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) error = zinitix_write_u16(client, BT541_SUPPORTED_FINGER_NUM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) MAX_SUPPORTED_FINGER_NUM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) error = zinitix_write_u16(client, BT541_INITIAL_TOUCH_MODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) bt541->zinitix_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) error = zinitix_write_u16(client, BT541_TOUCH_MODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) bt541->zinitix_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) error = zinitix_write_u16(client, BT541_INT_ENABLE_FLAG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) BIT_PT_CNT_CHANGE | BIT_DOWN | BIT_MOVE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) BIT_UP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) /* clear queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) for (i = 0; i < 10; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) zinitix_write_cmd(client, BT541_CLEAR_INT_STATUS_CMD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) udelay(10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static int zinitix_init_regulators(struct bt541_ts_data *bt541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) struct i2c_client *client = bt541->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) bt541->supplies[0].supply = "vdd";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) bt541->supplies[1].supply = "vddo";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) error = devm_regulator_bulk_get(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) ARRAY_SIZE(bt541->supplies),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) bt541->supplies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) dev_err(&client->dev, "Failed to get regulators: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) static int zinitix_send_power_on_sequence(struct bt541_ts_data *bt541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) struct i2c_client *client = bt541->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) error = zinitix_write_u16(client, 0xc000, 0x0001);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) "Failed to send power sequence(vendor cmd enable)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) udelay(10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) error = zinitix_write_cmd(client, 0xc004);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) "Failed to send power sequence (intn clear)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) udelay(10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) error = zinitix_write_u16(client, 0xc002, 0x0001);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) "Failed to send power sequence (nvm init)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) mdelay(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) error = zinitix_write_u16(client, 0xc001, 0x0001);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) "Failed to send power sequence (program start)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) msleep(FIRMWARE_ON_DELAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) static void zinitix_report_finger(struct bt541_ts_data *bt541, int slot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) const struct point_coord *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) u16 x, y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) if (unlikely(!(p->sub_status &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) (SUB_BIT_UP | SUB_BIT_DOWN | SUB_BIT_MOVE)))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) dev_dbg(&bt541->client->dev, "unknown finger event %#02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) p->sub_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) return;
^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) x = le16_to_cpu(p->x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) y = le16_to_cpu(p->y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) input_mt_slot(bt541->input_dev, slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) if (input_mt_report_slot_state(bt541->input_dev, MT_TOOL_FINGER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) !(p->sub_status & SUB_BIT_UP))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) touchscreen_report_pos(bt541->input_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) &bt541->prop, x, y, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) input_report_abs(bt541->input_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) ABS_MT_TOUCH_MAJOR, p->width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) dev_dbg(&bt541->client->dev, "finger %d %s (%u, %u)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) slot, p->sub_status & SUB_BIT_DOWN ? "down" : "move",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) x, y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) dev_dbg(&bt541->client->dev, "finger %d up (%u, %u)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) slot, x, y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) static irqreturn_t zinitix_ts_irq_handler(int irq, void *bt541_handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) struct bt541_ts_data *bt541 = bt541_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) struct i2c_client *client = bt541->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) struct touch_event touch_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) unsigned long finger_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) memset(&touch_event, 0, sizeof(struct touch_event));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) error = zinitix_read_data(bt541->client, BT541_POINT_STATUS_REG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) &touch_event, sizeof(struct touch_event));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) dev_err(&client->dev, "Failed to read in touchpoint struct\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) finger_mask = touch_event.finger_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) for_each_set_bit(i, &finger_mask, MAX_SUPPORTED_FINGER_NUM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) const struct point_coord *p = &touch_event.point_coord[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) /* Only process contacts that are actually reported */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) if (p->sub_status & SUB_BIT_EXIST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) zinitix_report_finger(bt541, i, p);
^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) input_mt_sync_frame(bt541->input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) input_sync(bt541->input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) zinitix_write_cmd(bt541->client, BT541_CLEAR_INT_STATUS_CMD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) static int zinitix_start(struct bt541_ts_data *bt541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) error = regulator_bulk_enable(ARRAY_SIZE(bt541->supplies),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) bt541->supplies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) dev_err(&bt541->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) "Failed to enable regulators: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) msleep(CHIP_ON_DELAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) error = zinitix_send_power_on_sequence(bt541);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) dev_err(&bt541->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) "Error while sending power-on sequence: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) error = zinitix_init_touch(bt541);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) dev_err(&bt541->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) "Error while configuring touch IC\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) enable_irq(bt541->client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) static int zinitix_stop(struct bt541_ts_data *bt541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) disable_irq(bt541->client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) error = regulator_bulk_disable(ARRAY_SIZE(bt541->supplies),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) bt541->supplies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) dev_err(&bt541->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) "Failed to disable regulators: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) static int zinitix_input_open(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) struct bt541_ts_data *bt541 = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) return zinitix_start(bt541);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) static void zinitix_input_close(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) struct bt541_ts_data *bt541 = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) zinitix_stop(bt541);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) static int zinitix_init_input_dev(struct bt541_ts_data *bt541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) input_dev = devm_input_allocate_device(&bt541->client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) if (!input_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) dev_err(&bt541->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) "Failed to allocate input device.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) input_set_drvdata(input_dev, bt541);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) bt541->input_dev = input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) input_dev->name = "Zinitix Capacitive TouchScreen";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) input_dev->phys = "input/ts";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) input_dev->id.bustype = BUS_I2C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) input_dev->open = zinitix_input_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) input_dev->close = zinitix_input_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_X);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_Y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) input_set_abs_params(input_dev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) touchscreen_parse_properties(input_dev, true, &bt541->prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) if (!bt541->prop.max_x || !bt541->prop.max_y) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) dev_err(&bt541->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) "Touchscreen-size-x and/or touchscreen-size-y not set in dts\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) error = input_mt_init_slots(input_dev, MAX_SUPPORTED_FINGER_NUM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) dev_err(&bt541->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) "Failed to initialize MT slots: %d", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) error = input_register_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) dev_err(&bt541->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) "Failed to register input device: %d", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) static int zinitix_ts_probe(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) struct bt541_ts_data *bt541;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) "Failed to assert adapter's support for plain I2C.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) bt541 = devm_kzalloc(&client->dev, sizeof(*bt541), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) if (!bt541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) bt541->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) i2c_set_clientdata(client, bt541);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) error = zinitix_init_regulators(bt541);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) "Failed to initialize regulators: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) error = devm_request_threaded_irq(&client->dev, client->irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) NULL, zinitix_ts_irq_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) IRQF_ONESHOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) client->name, bt541);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) dev_err(&client->dev, "Failed to request IRQ: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) return error;
^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) error = zinitix_init_input_dev(bt541);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) "Failed to initialize input device: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) error = device_property_read_u32(&client->dev, "zinitix,mode",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) &bt541->zinitix_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) /* fall back to mode 2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) bt541->zinitix_mode = DEFAULT_TOUCH_POINT_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) if (bt541->zinitix_mode != 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) * If there are devices that don't support mode 2, support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) * for other modes (0, 1) will be needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) "Malformed zinitix,mode property, must be 2 (supplied: %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) bt541->zinitix_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) irq_set_status_flags(client->irq, IRQ_NOAUTOEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) static int __maybe_unused zinitix_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) struct bt541_ts_data *bt541 = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) mutex_lock(&bt541->input_dev->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) if (bt541->input_dev->users)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) zinitix_stop(bt541);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) mutex_unlock(&bt541->input_dev->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) static int __maybe_unused zinitix_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) struct bt541_ts_data *bt541 = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) mutex_lock(&bt541->input_dev->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) if (bt541->input_dev->users)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) ret = zinitix_start(bt541);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) mutex_unlock(&bt541->input_dev->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) static SIMPLE_DEV_PM_OPS(zinitix_pm_ops, zinitix_suspend, zinitix_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) static const struct of_device_id zinitix_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) { .compatible = "zinitix,bt541" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) MODULE_DEVICE_TABLE(of, zinitix_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) static struct i2c_driver zinitix_ts_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) .probe_new = zinitix_ts_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) .name = "Zinitix-TS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) .pm = &zinitix_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) .of_match_table = of_match_ptr(zinitix_of_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) module_i2c_driver(zinitix_ts_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) MODULE_AUTHOR("Michael Srba <Michael.Srba@seznam.cz>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) MODULE_DESCRIPTION("Zinitix touchscreen driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) MODULE_LICENSE("GPL v2");