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-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Driver for ELAN eKTF2127 i2c touchscreen controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * For this driver the layout of the Chipone icn8318 i2c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * touchscreencontroller is used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Author:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Michel Verlaan <michel.verl@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * Siebren Vroegindeweij <siebren.vroegindeweij@hotmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * Original chipone_icn8318 driver:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * Hans de Goede <hdegoede@redhat.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/gpio/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/input/mt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/input/touchscreen.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) /* Packet header defines (first byte of data send / received) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define EKTF2127_NOISE			0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define EKTF2127_RESPONSE		0x52
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define EKTF2127_REQUEST		0x53
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define EKTF2127_HELLO			0x55
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define EKTF2127_REPORT			0x5d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define EKTF2127_CALIB_DONE		0x66
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) /* Register defines (second byte of data send / received) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define EKTF2127_ENV_NOISY		0x41
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define EKTF2127_HEIGHT			0x60
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define EKTF2127_WIDTH			0x63
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) /* 2 bytes header + 5 * 3 bytes coordinates + 3 bytes pressure info + footer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define EKTF2127_TOUCH_REPORT_SIZE	21
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #define EKTF2127_MAX_TOUCHES		5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) struct ektf2127_ts {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	struct gpio_desc *power_gpios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	struct touchscreen_properties prop;
^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 void ektf2127_parse_coordinates(const u8 *buf, unsigned int touch_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 				       struct input_mt_pos *touches)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	int index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	for (i = 0; i < touch_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		index = 2 + i * 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		touches[i].x = (buf[index] & 0x0f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		touches[i].x <<= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		touches[i].x |= buf[index + 2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		touches[i].y = (buf[index] & 0xf0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		touches[i].y <<= 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		touches[i].y |= buf[index + 1];
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) static void ektf2127_report_event(struct ektf2127_ts *ts, const u8 *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	struct input_mt_pos touches[EKTF2127_MAX_TOUCHES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	int slots[EKTF2127_MAX_TOUCHES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	unsigned int touch_count, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	touch_count = buf[1] & 0x07;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	if (touch_count > EKTF2127_MAX_TOUCHES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		dev_err(&ts->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			"Too many touches %d > %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 			touch_count, EKTF2127_MAX_TOUCHES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		touch_count = EKTF2127_MAX_TOUCHES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	ektf2127_parse_coordinates(buf, touch_count, touches);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	input_mt_assign_slots(ts->input, slots, touches,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			      touch_count, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	for (i = 0; i < touch_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		input_mt_slot(ts->input, slots[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		touchscreen_report_pos(ts->input, &ts->prop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 				       touches[i].x, touches[i].y, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	input_mt_sync_frame(ts->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	input_sync(ts->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) static irqreturn_t ektf2127_irq(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	struct ektf2127_ts *ts = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	struct device *dev = &ts->client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	char buf[EKTF2127_TOUCH_REPORT_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	ret = i2c_master_recv(ts->client, buf, EKTF2127_TOUCH_REPORT_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	if (ret != EKTF2127_TOUCH_REPORT_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		dev_err(dev, "Error reading touch data: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	switch (buf[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	case EKTF2127_REPORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		ektf2127_report_event(ts, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	case EKTF2127_NOISE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		if (buf[1] == EKTF2127_ENV_NOISY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 			dev_dbg(dev, "Environment is electrically noisy\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	case EKTF2127_HELLO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	case EKTF2127_CALIB_DONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		dev_err(dev, "Unexpected packet header byte %#02x\n", buf[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static int ektf2127_start(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	struct ektf2127_ts *ts = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	enable_irq(ts->client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	gpiod_set_value_cansleep(ts->power_gpios, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	return 0;
^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) static void ektf2127_stop(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	struct ektf2127_ts *ts = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	disable_irq(ts->client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	gpiod_set_value_cansleep(ts->power_gpios, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) static int __maybe_unused ektf2127_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	struct ektf2127_ts *ts = i2c_get_clientdata(to_i2c_client(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	mutex_lock(&ts->input->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	if (ts->input->users)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		ektf2127_stop(ts->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	mutex_unlock(&ts->input->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static int __maybe_unused ektf2127_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	struct ektf2127_ts *ts = i2c_get_clientdata(to_i2c_client(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	mutex_lock(&ts->input->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	if (ts->input->users)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		ektf2127_start(ts->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	mutex_unlock(&ts->input->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	return 0;
^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 SIMPLE_DEV_PM_OPS(ektf2127_pm_ops, ektf2127_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 			 ektf2127_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) static int ektf2127_query_dimension(struct i2c_client *client, bool width)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	struct device *dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	const char *what = width ? "width" : "height";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	u8 what_code = width ? EKTF2127_WIDTH : EKTF2127_HEIGHT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	u8 buf[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	/* Request dimension */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	buf[0] = EKTF2127_REQUEST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	buf[1] = width ? EKTF2127_WIDTH : EKTF2127_HEIGHT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	buf[2] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	buf[3] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	ret = i2c_master_send(client, buf, sizeof(buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	if (ret != sizeof(buf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		error = ret < 0 ? ret : -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		dev_err(dev, "Failed to request %s: %d\n", what, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	msleep(20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	/* Read response */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	ret = i2c_master_recv(client, buf, sizeof(buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	if (ret != sizeof(buf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		error = ret < 0 ? ret : -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		dev_err(dev, "Failed to receive %s data: %d\n", what, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	if (buf[0] != EKTF2127_RESPONSE || buf[1] != what_code) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		dev_err(dev, "Unexpected %s data: %#02x %#02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 			what, buf[0], buf[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	return (((buf[3] & 0xf0) << 4) | buf[2]) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) static int ektf2127_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 			  const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	struct device *dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	struct ektf2127_ts *ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	u8 buf[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	int max_x, max_y;
^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) 	if (!client->irq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		dev_err(dev, "Error no irq specified\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	if (!ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	/* This requests the gpio *and* turns on the touchscreen controller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	ts->power_gpios = devm_gpiod_get(dev, "power", GPIOD_OUT_HIGH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	if (IS_ERR(ts->power_gpios)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		error = PTR_ERR(ts->power_gpios);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		if (error != -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 			dev_err(dev, "Error getting power gpio: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	input = devm_input_allocate_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	if (!input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	input->name = client->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	input->id.bustype = BUS_I2C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	input->open = ektf2127_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	input->close = ektf2127_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	ts->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	/* Read hello (ignore result, depends on initial power state) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	msleep(20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	i2c_master_recv(ts->client, buf, sizeof(buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	/* Read resolution from chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	max_x = ektf2127_query_dimension(client, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	if (max_x < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		return max_x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	max_y = ektf2127_query_dimension(client, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	if (max_y < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		return max_y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	input_set_abs_params(input, ABS_MT_POSITION_X, 0, max_x, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	input_set_abs_params(input, ABS_MT_POSITION_Y, 0, max_y, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	touchscreen_parse_properties(input, true, &ts->prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	error = input_mt_init_slots(input, EKTF2127_MAX_TOUCHES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 				    INPUT_MT_DIRECT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 					INPUT_MT_DROP_UNUSED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 					INPUT_MT_TRACK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	ts->input = input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	input_set_drvdata(input, ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	error = devm_request_threaded_irq(dev, client->irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 					  NULL, ektf2127_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 					  IRQF_ONESHOT, client->name, ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		dev_err(dev, "Error requesting irq: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		return error;
^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) 	/* Stop device till opened */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	ektf2127_stop(ts->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	error = input_register_device(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	i2c_set_clientdata(client, ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) static const struct of_device_id ektf2127_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	{ .compatible = "elan,ektf2127" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) MODULE_DEVICE_TABLE(of, ektf2127_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) static const struct i2c_device_id ektf2127_i2c_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	{ "ektf2127", 0 },
^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) MODULE_DEVICE_TABLE(i2c, ektf2127_i2c_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) static struct i2c_driver ektf2127_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		.name	= "elan_ektf2127",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		.pm	= &ektf2127_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		.of_match_table = of_match_ptr(ektf2127_of_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	.probe = ektf2127_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	.id_table = ektf2127_i2c_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) module_i2c_driver(ektf2127_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) MODULE_DESCRIPTION("ELAN eKTF2127 I2C Touchscreen Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) MODULE_AUTHOR("Michel Verlaan, Siebren Vroegindeweij");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) MODULE_LICENSE("GPL");