^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) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #include <linux/gpio/consumer.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/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/of_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/sizes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <asm/unaligned.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define ILI2XXX_POLL_PERIOD 20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define ILI210X_DATA_SIZE 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define ILI211X_DATA_SIZE 43
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define ILI251X_DATA_SIZE1 31
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define ILI251X_DATA_SIZE2 20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) /* Touchscreen commands */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define REG_TOUCHDATA 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define REG_PANEL_INFO 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define REG_CALIBRATE 0xcc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct ili2xxx_chip {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) int (*read_reg)(struct i2c_client *client, u8 reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) void *buf, size_t len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) int (*get_touch_data)(struct i2c_client *client, u8 *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) bool (*parse_touch_data)(const u8 *data, unsigned int finger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) unsigned int *x, unsigned int *y,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) unsigned int *z);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) bool (*continue_polling)(const u8 *data, bool touch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) unsigned int max_touches;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) unsigned int resolution;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) bool has_calibrate_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) bool has_pressure_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) struct ili210x {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct gpio_desc *reset_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct touchscreen_properties prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) const struct ili2xxx_chip *chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) bool stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static int ili210x_read_reg(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) u8 reg, void *buf, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct i2c_msg msg[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) .addr = client->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) .flags = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) .len = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) .buf = ®,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) .addr = client->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) .flags = I2C_M_RD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) .len = len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) .buf = buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) int error, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) if (ret != ARRAY_SIZE(msg)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) error = ret < 0 ? ret : -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) dev_err(&client->dev, "%s failed: %d\n", __func__, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) static int ili210x_read_touch_data(struct i2c_client *client, u8 *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) return ili210x_read_reg(client, REG_TOUCHDATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) data, ILI210X_DATA_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) static bool ili210x_touchdata_to_coords(const u8 *touchdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) unsigned int finger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) unsigned int *x, unsigned int *y,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) unsigned int *z)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (!(touchdata[0] & BIT(finger)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) *x = get_unaligned_be16(touchdata + 1 + (finger * 4) + 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) *y = get_unaligned_be16(touchdata + 1 + (finger * 4) + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) static bool ili210x_check_continue_polling(const u8 *data, bool touch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) return data[0] & 0xf3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static const struct ili2xxx_chip ili210x_chip = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) .read_reg = ili210x_read_reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) .get_touch_data = ili210x_read_touch_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) .parse_touch_data = ili210x_touchdata_to_coords,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) .continue_polling = ili210x_check_continue_polling,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) .max_touches = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) .has_calibrate_reg = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static int ili211x_read_touch_data(struct i2c_client *client, u8 *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) s16 sum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) ret = i2c_master_recv(client, data, ILI211X_DATA_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) if (ret != ILI211X_DATA_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) error = ret < 0 ? ret : -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) dev_err(&client->dev, "%s failed: %d\n", __func__, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /* This chip uses custom checksum at the end of data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) for (i = 0; i < ILI211X_DATA_SIZE - 1; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) sum = (sum + data[i]) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) if ((-sum & 0xff) != data[ILI211X_DATA_SIZE - 1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) "CRC error (crc=0x%02x expected=0x%02x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) sum, data[ILI211X_DATA_SIZE - 1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static bool ili211x_touchdata_to_coords(const u8 *touchdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) unsigned int finger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) unsigned int *x, unsigned int *y,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) unsigned int *z)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) u32 data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) data = get_unaligned_be32(touchdata + 1 + (finger * 4) + 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) if (data == 0xffffffff) /* Finger up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) *x = ((touchdata[1 + (finger * 4) + 0] & 0xf0) << 4) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) touchdata[1 + (finger * 4) + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) *y = ((touchdata[1 + (finger * 4) + 0] & 0x0f) << 8) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) touchdata[1 + (finger * 4) + 2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) static bool ili211x_decline_polling(const u8 *data, bool touch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static const struct ili2xxx_chip ili211x_chip = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) .read_reg = ili210x_read_reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) .get_touch_data = ili211x_read_touch_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) .parse_touch_data = ili211x_touchdata_to_coords,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) .continue_polling = ili211x_decline_polling,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) .max_touches = 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) .resolution = 2048,
^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 bool ili212x_touchdata_to_coords(const u8 *touchdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) unsigned int finger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) unsigned int *x, unsigned int *y,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) unsigned int *z)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) u16 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) val = get_unaligned_be16(touchdata + 3 + (finger * 5) + 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if (!(val & BIT(15))) /* Touch indication */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) *x = val & 0x3fff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) *y = get_unaligned_be16(touchdata + 3 + (finger * 5) + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) static bool ili212x_check_continue_polling(const u8 *data, bool touch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) return touch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) static const struct ili2xxx_chip ili212x_chip = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) .read_reg = ili210x_read_reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) .get_touch_data = ili210x_read_touch_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) .parse_touch_data = ili212x_touchdata_to_coords,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) .continue_polling = ili212x_check_continue_polling,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) .max_touches = 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) .has_calibrate_reg = true,
^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) static int ili251x_read_reg(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) u8 reg, void *buf, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) ret = i2c_master_send(client, ®, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) if (ret == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) usleep_range(5000, 5500);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) ret = i2c_master_recv(client, buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) if (ret == len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) error = ret < 0 ? ret : -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) dev_err(&client->dev, "%s failed: %d\n", __func__, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) static int ili251x_read_touch_data(struct i2c_client *client, u8 *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) error = ili251x_read_reg(client, REG_TOUCHDATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) data, ILI251X_DATA_SIZE1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if (!error && data[0] == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) error = i2c_master_recv(client, data + ILI251X_DATA_SIZE1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) ILI251X_DATA_SIZE2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) if (error >= 0 && error != ILI251X_DATA_SIZE2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) error = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) static bool ili251x_touchdata_to_coords(const u8 *touchdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) unsigned int finger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) unsigned int *x, unsigned int *y,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) unsigned int *z)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) u16 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) val = get_unaligned_be16(touchdata + 1 + (finger * 5) + 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) if (!(val & BIT(15))) /* Touch indication */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) *x = val & 0x3fff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) *y = get_unaligned_be16(touchdata + 1 + (finger * 5) + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) *z = touchdata[1 + (finger * 5) + 4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static bool ili251x_check_continue_polling(const u8 *data, bool touch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) return touch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) static const struct ili2xxx_chip ili251x_chip = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) .read_reg = ili251x_read_reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) .get_touch_data = ili251x_read_touch_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) .parse_touch_data = ili251x_touchdata_to_coords,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) .continue_polling = ili251x_check_continue_polling,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) .max_touches = 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) .has_calibrate_reg = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) .has_pressure_reg = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) static bool ili210x_report_events(struct ili210x *priv, u8 *touchdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) struct input_dev *input = priv->input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) bool contact = false, touch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) unsigned int x = 0, y = 0, z = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) for (i = 0; i < priv->chip->max_touches; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) touch = priv->chip->parse_touch_data(touchdata, i, &x, &y, &z);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) input_mt_slot(input, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) if (input_mt_report_slot_state(input, MT_TOOL_FINGER, touch)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) touchscreen_report_pos(input, &priv->prop, x, y, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) if (priv->chip->has_pressure_reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) input_report_abs(input, ABS_MT_PRESSURE, z);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) contact = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) input_mt_report_pointer_emulation(input, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) input_sync(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) return contact;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) static irqreturn_t ili210x_irq(int irq, void *irq_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) struct ili210x *priv = irq_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) struct i2c_client *client = priv->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) const struct ili2xxx_chip *chip = priv->chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) u8 touchdata[ILI210X_DATA_SIZE] = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) bool keep_polling;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) bool touch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) error = chip->get_touch_data(client, touchdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) "Unable to get touch data: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) touch = ili210x_report_events(priv, touchdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) keep_polling = chip->continue_polling(touchdata, touch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) if (keep_polling)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) msleep(ILI2XXX_POLL_PERIOD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) } while (!priv->stop && keep_polling);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) static ssize_t ili210x_calibrate(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) struct ili210x *priv = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) unsigned long calibrate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) u8 cmd = REG_CALIBRATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) if (kstrtoul(buf, 10, &calibrate))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) if (calibrate > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) if (calibrate) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) rc = i2c_master_send(priv->client, &cmd, sizeof(cmd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) if (rc != sizeof(cmd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) static DEVICE_ATTR(calibrate, S_IWUSR, NULL, ili210x_calibrate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) static struct attribute *ili210x_attributes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) &dev_attr_calibrate.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) static umode_t ili210x_calibrate_visible(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) struct attribute *attr, int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) struct device *dev = kobj_to_dev(kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) struct ili210x *priv = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) return priv->chip->has_calibrate_reg ? attr->mode : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) static const struct attribute_group ili210x_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) .attrs = ili210x_attributes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) .is_visible = ili210x_calibrate_visible,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) static void ili210x_power_down(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) struct gpio_desc *reset_gpio = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) gpiod_set_value_cansleep(reset_gpio, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) static void ili210x_stop(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) struct ili210x *priv = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) /* Tell ISR to quit even if there is a contact. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) priv->stop = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) static int ili210x_i2c_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) struct device *dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) const struct ili2xxx_chip *chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) struct ili210x *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) struct gpio_desc *reset_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) unsigned int max_xy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) dev_dbg(dev, "Probing for ILI210X I2C Touschreen driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) chip = device_get_match_data(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) if (!chip && id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) chip = (const struct ili2xxx_chip *)id->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) if (!chip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) dev_err(&client->dev, "unknown device model\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) if (client->irq <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) dev_err(dev, "No IRQ!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) if (IS_ERR(reset_gpio))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) return PTR_ERR(reset_gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) if (reset_gpio) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) error = devm_add_action_or_reset(dev, ili210x_power_down,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) reset_gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) if (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) usleep_range(50, 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) gpiod_set_value_cansleep(reset_gpio, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) msleep(100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) if (!priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) input = devm_input_allocate_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) if (!input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) priv->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) priv->input = input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) priv->reset_gpio = reset_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) priv->chip = chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) i2c_set_clientdata(client, priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) /* Setup input device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) input->name = "ILI210x Touchscreen";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) input->id.bustype = BUS_I2C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) /* Multi touch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) max_xy = (chip->resolution ?: SZ_64K) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) input_set_abs_params(input, ABS_MT_POSITION_X, 0, max_xy, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) input_set_abs_params(input, ABS_MT_POSITION_Y, 0, max_xy, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) if (priv->chip->has_pressure_reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) input_set_abs_params(input, ABS_MT_PRESSURE, 0, 0xa, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) touchscreen_parse_properties(input, true, &priv->prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) error = input_mt_init_slots(input, priv->chip->max_touches,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) INPUT_MT_DIRECT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) dev_err(dev, "Unable to set up slots, err: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) error = devm_request_threaded_irq(dev, client->irq, NULL, ili210x_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) IRQF_ONESHOT, client->name, priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) dev_err(dev, "Unable to request touchscreen IRQ, err: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) error = devm_add_action_or_reset(dev, ili210x_stop, priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) error = devm_device_add_group(dev, &ili210x_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) dev_err(dev, "Unable to create sysfs attributes, err: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) error = input_register_device(priv->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) dev_err(dev, "Cannot register input device, err: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) return 0;
^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) static const struct i2c_device_id ili210x_i2c_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) { "ili210x", (long)&ili210x_chip },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) { "ili2117", (long)&ili211x_chip },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) { "ili2120", (long)&ili212x_chip },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) { "ili251x", (long)&ili251x_chip },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) MODULE_DEVICE_TABLE(i2c, ili210x_i2c_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) static const struct of_device_id ili210x_dt_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) { .compatible = "ilitek,ili210x", .data = &ili210x_chip },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) { .compatible = "ilitek,ili2117", .data = &ili211x_chip },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) { .compatible = "ilitek,ili2120", .data = &ili212x_chip },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) { .compatible = "ilitek,ili251x", .data = &ili251x_chip },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) MODULE_DEVICE_TABLE(of, ili210x_dt_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) static struct i2c_driver ili210x_ts_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) .name = "ili210x_i2c",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) .of_match_table = ili210x_dt_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) .id_table = ili210x_i2c_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) .probe = ili210x_i2c_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) module_i2c_driver(ili210x_ts_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) MODULE_AUTHOR("Olivier Sobrie <olivier@sobrie.be>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) MODULE_DESCRIPTION("ILI210X I2C Touchscreen Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) MODULE_LICENSE("GPL");