Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Driver for ChipOne icn8505 i2c touchscreen controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (c) 2015-2018 Red Hat Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Red Hat authors:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Hans de Goede <hdegoede@redhat.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <asm/unaligned.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/crc32.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/firmware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/input/mt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/input/touchscreen.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) /* Normal operation mode defines */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define ICN8505_REG_ADDR_WIDTH		16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define ICN8505_REG_POWER		0x0004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define ICN8505_REG_TOUCHDATA		0x1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define ICN8505_REG_CONFIGDATA		0x8000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) /* ICN8505_REG_POWER commands */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define ICN8505_POWER_ACTIVE		0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define ICN8505_POWER_MONITOR		0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define ICN8505_POWER_HIBERNATE		0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * The Android driver uses these to turn on/off the charger filter, but the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * filter is way too aggressive making e.g. onscreen keyboards unusable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define ICN8505_POWER_ENA_CHARGER_MODE	0x55
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define ICN8505_POWER_DIS_CHARGER_MODE	0x66
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #define ICN8505_MAX_TOUCHES		10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) /* Programming mode defines */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define ICN8505_PROG_I2C_ADDR		0x30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #define ICN8505_PROG_REG_ADDR_WIDTH	24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #define MAX_FW_UPLOAD_TRIES		3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) struct icn8505_touch {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	u8 slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	u8 x[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	u8 y[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	u8 pressure;	/* Seems more like finger width then pressure really */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	u8 event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) /* The difference between 2 and 3 is unclear */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) #define ICN8505_EVENT_NO_DATA	1 /* No finger seen yet since wakeup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) #define ICN8505_EVENT_UPDATE1	2 /* New or updated coordinates */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #define ICN8505_EVENT_UPDATE2	3 /* New or updated coordinates */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) #define ICN8505_EVENT_END	4 /* Finger lifted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) struct icn8505_touch_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	u8 softbutton;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	u8 touch_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	struct icn8505_touch touches[ICN8505_MAX_TOUCHES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) struct icn8505_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	struct gpio_desc *wake_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	struct touchscreen_properties prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	char firmware_name[32];
^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) static int icn8505_read_xfer(struct i2c_client *client, u16 i2c_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			     int reg_addr, int reg_addr_width,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			     void *data, int len, bool silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	u8 buf[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	int i, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	struct i2c_msg msg[2] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			.addr = i2c_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			.buf = buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			.len = reg_addr_width / 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			.addr = i2c_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			.flags = I2C_M_RD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			.buf = data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			.len = len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	for (i = 0; i < (reg_addr_width / 8); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		buf[i] = (reg_addr >> (reg_addr_width - (i + 1) * 8)) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	ret = i2c_transfer(client->adapter, msg, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	if (ret != ARRAY_SIZE(msg)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		if (ret >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		if (!silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 				"Error reading addr %#x reg %#x: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 				i2c_addr, reg_addr, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	return 0;
^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 icn8505_write_xfer(struct i2c_client *client, u16 i2c_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			      int reg_addr, int reg_addr_width,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 			      const void *data, int len, bool silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	u8 buf[3 + 32]; /* 3 bytes for 24 bit reg-addr + 32 bytes max len */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	int i, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	struct i2c_msg msg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		.addr = i2c_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		.buf = buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		.len = reg_addr_width / 8 + len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	if (WARN_ON(len > 32))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	for (i = 0; i < (reg_addr_width / 8); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		buf[i] = (reg_addr >> (reg_addr_width - (i + 1) * 8)) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	memcpy(buf + reg_addr_width / 8, data, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	ret = i2c_transfer(client->adapter, &msg, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	if (ret != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		if (ret >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		if (!silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 				"Error writing addr %#x reg %#x: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 				i2c_addr, reg_addr, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) static int icn8505_read_data(struct icn8505_data *icn8505, int reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			     void *buf, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	return icn8505_read_xfer(icn8505->client, icn8505->client->addr, reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 				 ICN8505_REG_ADDR_WIDTH, buf, len, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) static int icn8505_read_reg_silent(struct icn8505_data *icn8505, int reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	u8 buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	error = icn8505_read_xfer(icn8505->client, icn8505->client->addr, reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 				  ICN8505_REG_ADDR_WIDTH, &buf, 1, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	return buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) static int icn8505_write_reg(struct icn8505_data *icn8505, int reg, u8 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	return icn8505_write_xfer(icn8505->client, icn8505->client->addr, reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 				  ICN8505_REG_ADDR_WIDTH, &val, 1, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) static int icn8505_read_prog_data(struct icn8505_data *icn8505, int reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 				  void *buf, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	return icn8505_read_xfer(icn8505->client, ICN8505_PROG_I2C_ADDR, reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 				 ICN8505_PROG_REG_ADDR_WIDTH, buf, len, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) static int icn8505_write_prog_data(struct icn8505_data *icn8505, int reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 				   const void *buf, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	return icn8505_write_xfer(icn8505->client, ICN8505_PROG_I2C_ADDR, reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 				  ICN8505_PROG_REG_ADDR_WIDTH, buf, len, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) static int icn8505_write_prog_reg(struct icn8505_data *icn8505, int reg, u8 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	return icn8505_write_xfer(icn8505->client, ICN8505_PROG_I2C_ADDR, reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 				  ICN8505_PROG_REG_ADDR_WIDTH, &val, 1, false);
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)  * Note this function uses a number of magic register addresses and values,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)  * there are deliberately no defines for these because the algorithm is taken
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)  * from the icn85xx Android driver and I do not want to make up possibly wrong
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)  * names for the addresses and/or values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) static int icn8505_try_fw_upload(struct icn8505_data *icn8505,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 				 const struct firmware *fw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	struct device *dev = &icn8505->client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	size_t offset, count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	u8 buf[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	u32 crc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	/* Put the controller in programming mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	error = icn8505_write_prog_reg(icn8505, 0xcc3355, 0x5a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	usleep_range(2000, 5000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	error = icn8505_write_prog_reg(icn8505, 0x040400, 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	usleep_range(2000, 5000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	error = icn8505_read_prog_data(icn8505, 0x040002, buf, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	if (buf[0] != 0x85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		dev_err(dev, "Failed to enter programming mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	usleep_range(1000, 5000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	/* Enable CRC mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	error = icn8505_write_prog_reg(icn8505, 0x40028, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	/* Send the firmware to SRAM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	for (offset = 0; offset < fw->size; offset += count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		count = min_t(size_t, fw->size - offset, 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		error = icn8505_write_prog_data(icn8505, offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 					      fw->data + offset, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	/* Disable CRC mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	error = icn8505_write_prog_reg(icn8505, 0x40028, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	/* Get and check length and CRC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	error = icn8505_read_prog_data(icn8505, 0x40034, buf, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	if (get_unaligned_le16(buf) != fw->size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		dev_warn(dev, "Length mismatch after uploading fw\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	error = icn8505_read_prog_data(icn8505, 0x4002c, buf, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	crc = crc32_be(0, fw->data, fw->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	if (get_unaligned_le32(buf) != crc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		dev_warn(dev, "CRC mismatch after uploading fw\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		return -EIO;
^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) 	/* Boot controller from SRAM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	error = icn8505_write_prog_reg(icn8505, 0x40400, 0x03);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	usleep_range(2000, 5000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) static int icn8505_upload_fw(struct icn8505_data *icn8505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	struct device *dev = &icn8505->client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	const struct firmware *fw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	int i, error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	 * Always load the firmware, even if we don't need it at boot, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	 * we may need it at resume. Having loaded it once will make the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	 * firmware class code cache it at suspend/resume.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	error = firmware_request_platform(&fw, icn8505->firmware_name, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		dev_err(dev, "Firmware request error %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	/* Check if the controller is not already up and running */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	if (icn8505_read_reg_silent(icn8505, 0x000a) == 0x85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		goto success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	for (i = 1; i <= MAX_FW_UPLOAD_TRIES; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		error = icn8505_try_fw_upload(icn8505, fw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		if (!error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 			goto success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		dev_err(dev, "Failed to upload firmware: %d (attempt %d/%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 			error, i, MAX_FW_UPLOAD_TRIES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		usleep_range(2000, 5000);
^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) success:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	release_firmware(fw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) static bool icn8505_touch_active(u8 event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	return event == ICN8505_EVENT_UPDATE1 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	       event == ICN8505_EVENT_UPDATE2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) static irqreturn_t icn8505_irq(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	struct icn8505_data *icn8505 = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	struct device *dev = &icn8505->client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	struct icn8505_touch_data touch_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	int i, error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	error = icn8505_read_data(icn8505, ICN8505_REG_TOUCHDATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 				  &touch_data, sizeof(touch_data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		dev_err(dev, "Error reading touch data: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		return IRQ_HANDLED;
^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) 	if (touch_data.touch_count > ICN8505_MAX_TOUCHES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		dev_warn(dev, "Too many touches %d > %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 			 touch_data.touch_count, ICN8505_MAX_TOUCHES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		touch_data.touch_count = ICN8505_MAX_TOUCHES;
^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) 	for (i = 0; i < touch_data.touch_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		struct icn8505_touch *touch = &touch_data.touches[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		bool act = icn8505_touch_active(touch->event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		input_mt_slot(icn8505->input, touch->slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		input_mt_report_slot_state(icn8505->input, MT_TOOL_FINGER, act);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		if (!act)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		touchscreen_report_pos(icn8505->input, &icn8505->prop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 				       get_unaligned_le16(touch->x),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 				       get_unaligned_le16(touch->y),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 				       true);
^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) 	input_mt_sync_frame(icn8505->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	input_report_key(icn8505->input, KEY_LEFTMETA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 			 touch_data.softbutton == 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	input_sync(icn8505->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) static int icn8505_probe_acpi(struct icn8505_data *icn8505, struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	const char *subsys = "unknown";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	struct acpi_device *adev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	union acpi_object *obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	adev = ACPI_COMPANION(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	if (!adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	status = acpi_evaluate_object(adev->handle, "_SUB", NULL, &buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	if (ACPI_SUCCESS(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		obj = buffer.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		if (obj->type == ACPI_TYPE_STRING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 			subsys = obj->string.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 			dev_warn(dev, "Warning ACPI _SUB did not return a string\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		dev_warn(dev, "Warning ACPI _SUB failed: %#x\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 		buffer.pointer = NULL;
^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) 	snprintf(icn8505->firmware_name, sizeof(icn8505->firmware_name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 		 "chipone/icn8505-%s.fw", subsys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	kfree(buffer.pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) static int icn8505_probe(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	struct device *dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	struct icn8505_data *icn8505;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	__le16 resolution[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	if (!client->irq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		dev_err(dev, "No irq specified\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	icn8505 = devm_kzalloc(dev, sizeof(*icn8505), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	if (!icn8505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	input = devm_input_allocate_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	if (!input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	input->name = client->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	input->id.bustype = BUS_I2C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	input_set_capability(input, EV_ABS, ABS_MT_POSITION_X);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	input_set_capability(input, EV_ABS, ABS_MT_POSITION_Y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	input_set_capability(input, EV_KEY, KEY_LEFTMETA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	icn8505->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	icn8505->input = input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	input_set_drvdata(input, icn8505);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	error = icn8505_probe_acpi(icn8505, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	error = icn8505_upload_fw(icn8505);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	error = icn8505_read_data(icn8505, ICN8505_REG_CONFIGDATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 				resolution, sizeof(resolution));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 		dev_err(dev, "Error reading resolution: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	input_set_abs_params(input, ABS_MT_POSITION_X, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 			     le16_to_cpu(resolution[0]) - 1, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	input_set_abs_params(input, ABS_MT_POSITION_Y, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 			     le16_to_cpu(resolution[1]) - 1, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	touchscreen_parse_properties(input, true, &icn8505->prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	if (!input_abs_get_max(input, ABS_MT_POSITION_X) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	    !input_abs_get_max(input, ABS_MT_POSITION_Y)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 		dev_err(dev, "Error touchscreen-size-x and/or -y missing\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	error = input_mt_init_slots(input, ICN8505_MAX_TOUCHES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 				  INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	if (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) 	error = devm_request_threaded_irq(dev, client->irq, NULL, icn8505_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 					IRQF_ONESHOT, client->name, icn8505);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 		dev_err(dev, "Error requesting irq: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	error = input_register_device(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	i2c_set_clientdata(client, icn8505);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) static int __maybe_unused icn8505_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	struct icn8505_data *icn8505 = i2c_get_clientdata(to_i2c_client(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	disable_irq(icn8505->client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	icn8505_write_reg(icn8505, ICN8505_REG_POWER, ICN8505_POWER_HIBERNATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	return 0;
^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) static int __maybe_unused icn8505_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	struct icn8505_data *icn8505 = i2c_get_clientdata(to_i2c_client(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	error = icn8505_upload_fw(icn8505);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	enable_irq(icn8505->client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) static SIMPLE_DEV_PM_OPS(icn8505_pm_ops, icn8505_suspend, icn8505_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) static const struct acpi_device_id icn8505_acpi_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	{ "CHPN0001" },
^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(acpi, icn8505_acpi_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) static struct i2c_driver icn8505_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 		.name	= "chipone_icn8505",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 		.pm	= &icn8505_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 		.acpi_match_table = icn8505_acpi_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	.probe_new = icn8505_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(icn8505_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) MODULE_DESCRIPTION("ChipOne icn8505 I2C Touchscreen Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) MODULE_LICENSE("GPL");