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)  * ST1232 Touchscreen Controller Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2010 Renesas Solutions Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *	Tony SIM <chinyeow.sim.xt@renesas.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Using code from:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *  - android.git.kernel.org: projects/kernel/common.git: synaptics_i2c_rmi.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *	Copyright (C) 2007 Google, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/gpio/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/input/mt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/input/touchscreen.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/pm_qos.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define ST1232_TS_NAME	"st1232-ts"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define ST1633_TS_NAME	"st1633-ts"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define ST_TS_MAX_FINGERS	10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) struct st_chip_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	bool	have_z;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	u16	max_x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	u16	max_y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	u16	max_area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	u16	max_fingers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	u8	start_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) struct st1232_ts_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	struct touchscreen_properties prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	struct dev_pm_qos_request low_latency_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	struct gpio_desc *reset_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	const struct st_chip_info *chip_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	int read_buf_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	u8 *read_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) static int st1232_ts_read_data(struct st1232_ts_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	struct i2c_client *client = ts->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	u8 start_reg = ts->chip_info->start_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	struct i2c_msg msg[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 			.addr	= client->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 			.len	= sizeof(start_reg),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 			.buf	= &start_reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 			.addr	= client->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 			.flags	= I2C_M_RD | I2C_M_DMA_SAFE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 			.len	= ts->read_buf_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 			.buf	= ts->read_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	if (ret != ARRAY_SIZE(msg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		return ret < 0 ? ret : -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) static int st1232_ts_parse_and_report(struct st1232_ts_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	struct input_dev *input = ts->input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	struct input_mt_pos pos[ST_TS_MAX_FINGERS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	u8 z[ST_TS_MAX_FINGERS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	int slots[ST_TS_MAX_FINGERS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	int n_contacts = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	for (i = 0; i < ts->chip_info->max_fingers; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		u8 *buf = &ts->read_buf[i * 4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		if (buf[0] & BIT(7)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			unsigned int x = ((buf[0] & 0x70) << 4) | buf[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			unsigned int y = ((buf[0] & 0x07) << 8) | buf[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			touchscreen_set_mt_pos(&pos[n_contacts],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 					       &ts->prop, x, y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			/* st1232 includes a z-axis / touch strength */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			if (ts->chip_info->have_z)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 				z[n_contacts] = ts->read_buf[i + 6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 			n_contacts++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		}
^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) 	input_mt_assign_slots(input, slots, pos, n_contacts, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	for (i = 0; i < n_contacts; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		input_mt_slot(input, slots[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		input_mt_report_slot_state(input, MT_TOOL_FINGER, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		input_report_abs(input, ABS_MT_POSITION_X, pos[i].x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		input_report_abs(input, ABS_MT_POSITION_Y, pos[i].y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		if (ts->chip_info->have_z)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 			input_report_abs(input, ABS_MT_TOUCH_MAJOR, z[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	input_mt_sync_frame(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	input_sync(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	return n_contacts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) static irqreturn_t st1232_ts_irq_handler(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	struct st1232_ts_data *ts = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	error = st1232_ts_read_data(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	count = st1232_ts_parse_and_report(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	if (!count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		if (ts->low_latency_req.dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			dev_pm_qos_remove_request(&ts->low_latency_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			ts->low_latency_req.dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	} else if (!ts->low_latency_req.dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		/* First contact, request 100 us latency. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		dev_pm_qos_add_ancestor_request(&ts->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 						&ts->low_latency_req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 						DEV_PM_QOS_RESUME_LATENCY, 100);
^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) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	return IRQ_HANDLED;
^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 void st1232_ts_power(struct st1232_ts_data *ts, bool poweron)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	if (ts->reset_gpio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		gpiod_set_value_cansleep(ts->reset_gpio, !poweron);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static void st1232_ts_power_off(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	st1232_ts_power(data, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static const struct st_chip_info st1232_chip_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	.have_z		= true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	.max_x		= 0x31f, /* 800 - 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	.max_y		= 0x1df, /* 480 -1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	.max_area	= 0xff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	.max_fingers	= 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	.start_reg	= 0x12,
^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 const struct st_chip_info st1633_chip_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	.have_z		= false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	.max_x		= 0x13f, /* 320 - 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	.max_y		= 0x1df, /* 480 -1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	.max_area	= 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	.max_fingers	= 5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	.start_reg	= 0x12,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) static int st1232_ts_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 			   const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	const struct st_chip_info *match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	struct st1232_ts_data *ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	match = device_get_match_data(&client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	if (!match && id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		match = (const void *)id->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	if (!match) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		dev_err(&client->dev, "unknown device model\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		dev_err(&client->dev, "need I2C_FUNC_I2C\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	if (!client->irq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		dev_err(&client->dev, "no IRQ?\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	if (!ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	ts->chip_info = match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	/* allocate a buffer according to the number of registers to read */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	ts->read_buf_len = ts->chip_info->max_fingers * 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	ts->read_buf = devm_kzalloc(&client->dev, ts->read_buf_len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	if (!ts->read_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	input_dev = devm_input_allocate_device(&client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	if (!input_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	ts->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	ts->input_dev = input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	ts->reset_gpio = devm_gpiod_get_optional(&client->dev, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 						 GPIOD_OUT_HIGH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	if (IS_ERR(ts->reset_gpio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		error = PTR_ERR(ts->reset_gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		dev_err(&client->dev, "Unable to request GPIO pin: %d.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 			error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		return error;
^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) 	st1232_ts_power(ts, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	error = devm_add_action_or_reset(&client->dev, st1232_ts_power_off, ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 			"Failed to install power off action: %d\n", 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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	input_dev->name = "st1232-touchscreen";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	input_dev->id.bustype = BUS_I2C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	if (ts->chip_info->have_z)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 				     ts->chip_info->max_area, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	input_set_abs_params(input_dev, ABS_MT_POSITION_X,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 			     0, ts->chip_info->max_x, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 			     0, ts->chip_info->max_y, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	touchscreen_parse_properties(input_dev, true, &ts->prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	error = input_mt_init_slots(input_dev, ts->chip_info->max_fingers,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 				    INPUT_MT_DIRECT | INPUT_MT_TRACK |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 					INPUT_MT_DROP_UNUSED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		dev_err(&client->dev, "failed to initialize MT slots\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		return error;
^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 = devm_request_threaded_irq(&client->dev, client->irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 					  NULL, st1232_ts_irq_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 					  IRQF_ONESHOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 					  client->name, ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		dev_err(&client->dev, "Failed to register interrupt\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	error = input_register_device(ts->input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		dev_err(&client->dev, "Unable to register %s input device\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			input_dev->name);
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	i2c_set_clientdata(client, ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) static int __maybe_unused st1232_ts_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	struct st1232_ts_data *ts = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	disable_irq(client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	if (!device_may_wakeup(&client->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		st1232_ts_power(ts, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) static int __maybe_unused st1232_ts_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	struct st1232_ts_data *ts = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	if (!device_may_wakeup(&client->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		st1232_ts_power(ts, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	enable_irq(client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) static SIMPLE_DEV_PM_OPS(st1232_ts_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 			 st1232_ts_suspend, st1232_ts_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) static const struct i2c_device_id st1232_ts_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	{ ST1232_TS_NAME, (unsigned long)&st1232_chip_info },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	{ ST1633_TS_NAME, (unsigned long)&st1633_chip_info },
^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) MODULE_DEVICE_TABLE(i2c, st1232_ts_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) static const struct of_device_id st1232_ts_dt_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	{ .compatible = "sitronix,st1232", .data = &st1232_chip_info },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	{ .compatible = "sitronix,st1633", .data = &st1633_chip_info },
^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) MODULE_DEVICE_TABLE(of, st1232_ts_dt_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) static struct i2c_driver st1232_ts_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	.probe		= st1232_ts_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	.id_table	= st1232_ts_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		.name	= ST1232_TS_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		.of_match_table = st1232_ts_dt_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		.pm	= &st1232_ts_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) module_i2c_driver(st1232_ts_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) MODULE_AUTHOR("Tony SIM <chinyeow.sim.xt@renesas.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) MODULE_AUTHOR("Martin Kepplinger <martin.kepplinger@ginzinger.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) MODULE_DESCRIPTION("SITRONIX ST1232 Touchscreen Controller Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) MODULE_LICENSE("GPL v2");