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) // STMicroelectronics FTS Touchscreen device driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) // Copyright (c) 2017 Samsung Electronics Co., Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) // Copyright (c) 2017 Andi Shyti <andi@etezian.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/input/mt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/input/touchscreen.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/leds.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/pm_runtime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/regulator/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) /* I2C commands */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define STMFTS_READ_INFO			0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define STMFTS_READ_STATUS			0x84
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define STMFTS_READ_ONE_EVENT			0x85
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define STMFTS_READ_ALL_EVENT			0x86
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define STMFTS_LATEST_EVENT			0x87
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define STMFTS_SLEEP_IN				0x90
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define STMFTS_SLEEP_OUT			0x91
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define STMFTS_MS_MT_SENSE_OFF			0x92
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define STMFTS_MS_MT_SENSE_ON			0x93
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define STMFTS_SS_HOVER_SENSE_OFF		0x94
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define STMFTS_SS_HOVER_SENSE_ON		0x95
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define STMFTS_MS_KEY_SENSE_OFF			0x9a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define STMFTS_MS_KEY_SENSE_ON			0x9b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define STMFTS_SYSTEM_RESET			0xa0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define STMFTS_CLEAR_EVENT_STACK		0xa1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define STMFTS_FULL_FORCE_CALIBRATION		0xa2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define STMFTS_MS_CX_TUNING			0xa3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define STMFTS_SS_CX_TUNING			0xa4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) /* events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define STMFTS_EV_NO_EVENT			0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define STMFTS_EV_MULTI_TOUCH_DETECTED		0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #define STMFTS_EV_MULTI_TOUCH_ENTER		0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #define STMFTS_EV_MULTI_TOUCH_LEAVE		0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define STMFTS_EV_MULTI_TOUCH_MOTION		0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define STMFTS_EV_HOVER_ENTER			0x07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #define STMFTS_EV_HOVER_LEAVE			0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #define STMFTS_EV_HOVER_MOTION			0x09
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #define STMFTS_EV_KEY_STATUS			0x0e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #define STMFTS_EV_ERROR				0x0f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #define STMFTS_EV_CONTROLLER_READY		0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #define STMFTS_EV_SLEEP_OUT_CONTROLLER_READY	0x11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #define STMFTS_EV_STATUS			0x16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #define STMFTS_EV_DEBUG				0xdb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) /* multi touch related event masks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) #define STMFTS_MASK_EVENT_ID			0x0f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) #define STMFTS_MASK_TOUCH_ID			0xf0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) #define STMFTS_MASK_LEFT_EVENT			0x0f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #define STMFTS_MASK_X_MSB			0x0f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) #define STMFTS_MASK_Y_LSB			0xf0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) /* key related event masks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) #define STMFTS_MASK_KEY_NO_TOUCH		0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) #define STMFTS_MASK_KEY_MENU			0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) #define STMFTS_MASK_KEY_BACK			0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) #define STMFTS_EVENT_SIZE	8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) #define STMFTS_STACK_DEPTH	32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) #define STMFTS_DATA_MAX_SIZE	(STMFTS_EVENT_SIZE * STMFTS_STACK_DEPTH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) #define STMFTS_MAX_FINGERS	10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) #define STMFTS_DEV_NAME		"stmfts"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) enum stmfts_regulators {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	STMFTS_REGULATOR_VDD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	STMFTS_REGULATOR_AVDD,
^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) struct stmfts_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	struct led_classdev led_cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	struct mutex mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	struct touchscreen_properties prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	struct regulator_bulk_data regulators[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	 * Presence of ledvdd will be used also to check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	 * whether the LED is supported.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	struct regulator *ledvdd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	u16 chip_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	u8 chip_ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	u16 fw_ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	u8 config_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	u8 config_ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	u8 data[STMFTS_DATA_MAX_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	struct completion cmd_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	bool use_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	bool led_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	bool hover_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	bool running;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static int stmfts_brightness_set(struct led_classdev *led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 					enum led_brightness value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	struct stmfts_data *sdata = container_of(led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 					struct stmfts_data, led_cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	if (value != sdata->led_status && sdata->ledvdd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		if (!value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 			regulator_disable(sdata->ledvdd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 			err = regulator_enable(sdata->ledvdd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 			if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 				dev_warn(&sdata->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 					 "failed to disable ledvdd regulator: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 					 err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 				return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		sdata->led_status = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	return 0;
^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 enum led_brightness stmfts_brightness_get(struct led_classdev *led_cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	struct stmfts_data *sdata = container_of(led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 						struct stmfts_data, led_cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	return !!regulator_is_enabled(sdata->ledvdd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^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)  * We can't simply use i2c_smbus_read_i2c_block_data because we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)  * need to read more than 255 bytes (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) static int stmfts_read_events(struct stmfts_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	u8 cmd = STMFTS_READ_ALL_EVENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	struct i2c_msg msgs[2] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			.addr	= sdata->client->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 			.len	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 			.buf	= &cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			.addr	= sdata->client->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			.flags	= I2C_M_RD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			.len	= STMFTS_DATA_MAX_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			.buf	= sdata->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	ret = i2c_transfer(sdata->client->adapter, msgs, ARRAY_SIZE(msgs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	return ret == ARRAY_SIZE(msgs) ? 0 : -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) static void stmfts_report_contact_event(struct stmfts_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 					const u8 event[])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	u8 slot_id = (event[0] & STMFTS_MASK_TOUCH_ID) >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	u16 x = event[1] | ((event[2] & STMFTS_MASK_X_MSB) << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	u16 y = (event[2] >> 4) | (event[3] << 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	u8 maj = event[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	u8 min = event[5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	u8 orientation = event[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	u8 area = event[7];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	input_mt_slot(sdata->input, slot_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	input_mt_report_slot_state(sdata->input, MT_TOOL_FINGER, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	input_report_abs(sdata->input, ABS_MT_POSITION_X, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	input_report_abs(sdata->input, ABS_MT_POSITION_Y, y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	input_report_abs(sdata->input, ABS_MT_TOUCH_MAJOR, maj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	input_report_abs(sdata->input, ABS_MT_TOUCH_MINOR, min);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	input_report_abs(sdata->input, ABS_MT_PRESSURE, area);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	input_report_abs(sdata->input, ABS_MT_ORIENTATION, orientation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	input_sync(sdata->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) static void stmfts_report_contact_release(struct stmfts_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 					  const u8 event[])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	u8 slot_id = (event[0] & STMFTS_MASK_TOUCH_ID) >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	input_mt_slot(sdata->input, slot_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	input_mt_report_slot_inactive(sdata->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	input_sync(sdata->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) static void stmfts_report_hover_event(struct stmfts_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 				      const u8 event[])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	u16 x = (event[2] << 4) | (event[4] >> 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	u16 y = (event[3] << 4) | (event[4] & STMFTS_MASK_Y_LSB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	u8 z = event[5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	input_report_abs(sdata->input, ABS_X, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	input_report_abs(sdata->input, ABS_Y, y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	input_report_abs(sdata->input, ABS_DISTANCE, z);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	input_sync(sdata->input);
^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) static void stmfts_report_key_event(struct stmfts_data *sdata, const u8 event[])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	switch (event[2]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		input_report_key(sdata->input, KEY_BACK, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		input_report_key(sdata->input, KEY_MENU, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	case STMFTS_MASK_KEY_BACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		input_report_key(sdata->input, KEY_BACK, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	case STMFTS_MASK_KEY_MENU:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		input_report_key(sdata->input, KEY_MENU, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		dev_warn(&sdata->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 			 "unknown key event: %#02x\n", event[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	input_sync(sdata->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) static void stmfts_parse_events(struct stmfts_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	for (i = 0; i < STMFTS_STACK_DEPTH; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		u8 *event = &sdata->data[i * STMFTS_EVENT_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		switch (event[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		case STMFTS_EV_CONTROLLER_READY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		case STMFTS_EV_SLEEP_OUT_CONTROLLER_READY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		case STMFTS_EV_STATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 			complete(&sdata->cmd_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 			fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		case STMFTS_EV_NO_EVENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		case STMFTS_EV_DEBUG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		switch (event[0] & STMFTS_MASK_EVENT_ID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		case STMFTS_EV_MULTI_TOUCH_ENTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		case STMFTS_EV_MULTI_TOUCH_MOTION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 			stmfts_report_contact_event(sdata, event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		case STMFTS_EV_MULTI_TOUCH_LEAVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			stmfts_report_contact_release(sdata, event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		case STMFTS_EV_HOVER_ENTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		case STMFTS_EV_HOVER_LEAVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		case STMFTS_EV_HOVER_MOTION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 			stmfts_report_hover_event(sdata, event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		case STMFTS_EV_KEY_STATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			stmfts_report_key_event(sdata, event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		case STMFTS_EV_ERROR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 			dev_warn(&sdata->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 					"error code: 0x%x%x%x%x%x%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 					event[6], event[5], event[4],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 					event[3], event[2], event[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 			dev_err(&sdata->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 				"unknown event %#02x\n", event[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		}
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) static irqreturn_t stmfts_irq_handler(int irq, void *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	struct stmfts_data *sdata = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	mutex_lock(&sdata->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	err = stmfts_read_events(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	if (unlikely(err))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		dev_err(&sdata->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 			"failed to read events: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		stmfts_parse_events(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	mutex_unlock(&sdata->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) static int stmfts_command(struct stmfts_data *sdata, const u8 cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	reinit_completion(&sdata->cmd_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	err = i2c_smbus_write_byte(sdata->client, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	if (!wait_for_completion_timeout(&sdata->cmd_done,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 					 msecs_to_jiffies(1000)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		return -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	return 0;
^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) static int stmfts_input_open(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	struct stmfts_data *sdata = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	err = pm_runtime_get_sync(&sdata->client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	err = i2c_smbus_write_byte(sdata->client, STMFTS_MS_MT_SENSE_ON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	mutex_lock(&sdata->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	sdata->running = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	if (sdata->hover_enabled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		err = i2c_smbus_write_byte(sdata->client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 					   STMFTS_SS_HOVER_SENSE_ON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 			dev_warn(&sdata->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 				 "failed to enable hover\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	mutex_unlock(&sdata->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	if (sdata->use_key) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		err = i2c_smbus_write_byte(sdata->client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 					   STMFTS_MS_KEY_SENSE_ON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 			/* I can still use only the touch screen */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 			dev_warn(&sdata->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 				 "failed to enable touchkey\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	return 0;
^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 stmfts_input_close(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	struct stmfts_data *sdata = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	err = i2c_smbus_write_byte(sdata->client, STMFTS_MS_MT_SENSE_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		dev_warn(&sdata->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 			 "failed to disable touchscreen: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	mutex_lock(&sdata->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	sdata->running = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	if (sdata->hover_enabled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		err = i2c_smbus_write_byte(sdata->client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 					   STMFTS_SS_HOVER_SENSE_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 			dev_warn(&sdata->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 				 "failed to disable hover: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	mutex_unlock(&sdata->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	if (sdata->use_key) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		err = i2c_smbus_write_byte(sdata->client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 					   STMFTS_MS_KEY_SENSE_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 			dev_warn(&sdata->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 				 "failed to disable touchkey: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	pm_runtime_put_sync(&sdata->client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) static ssize_t stmfts_sysfs_chip_id(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 				struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	struct stmfts_data *sdata = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	return sprintf(buf, "%#x\n", sdata->chip_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) static ssize_t stmfts_sysfs_chip_version(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 				struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	struct stmfts_data *sdata = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	return sprintf(buf, "%u\n", sdata->chip_ver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) static ssize_t stmfts_sysfs_fw_ver(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 				struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	struct stmfts_data *sdata = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	return sprintf(buf, "%u\n", sdata->fw_ver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) static ssize_t stmfts_sysfs_config_id(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 				struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	struct stmfts_data *sdata = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	return sprintf(buf, "%#x\n", sdata->config_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) static ssize_t stmfts_sysfs_config_version(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 				struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	struct stmfts_data *sdata = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	return sprintf(buf, "%u\n", sdata->config_ver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) static ssize_t stmfts_sysfs_read_status(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 				struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	struct stmfts_data *sdata = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	u8 status[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	err = i2c_smbus_read_i2c_block_data(sdata->client, STMFTS_READ_STATUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 					    sizeof(status), status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	return sprintf(buf, "%#02x\n", status[0]);
^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) static ssize_t stmfts_sysfs_hover_enable_read(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 				struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	struct stmfts_data *sdata = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	return sprintf(buf, "%u\n", sdata->hover_enabled);
^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) static ssize_t stmfts_sysfs_hover_enable_write(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 				struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 				const char *buf, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	struct stmfts_data *sdata = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	unsigned long value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	if (kstrtoul(buf, 0, &value))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	mutex_lock(&sdata->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	if (value && sdata->hover_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	if (sdata->running)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 		err = i2c_smbus_write_byte(sdata->client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 					   value ? STMFTS_SS_HOVER_SENSE_ON :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 						   STMFTS_SS_HOVER_SENSE_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 		sdata->hover_enabled = !!value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	mutex_unlock(&sdata->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	return len;
^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 DEVICE_ATTR(chip_id, 0444, stmfts_sysfs_chip_id, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) static DEVICE_ATTR(chip_version, 0444, stmfts_sysfs_chip_version, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) static DEVICE_ATTR(fw_ver, 0444, stmfts_sysfs_fw_ver, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) static DEVICE_ATTR(config_id, 0444, stmfts_sysfs_config_id, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) static DEVICE_ATTR(config_version, 0444, stmfts_sysfs_config_version, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) static DEVICE_ATTR(status, 0444, stmfts_sysfs_read_status, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) static DEVICE_ATTR(hover_enable, 0644, stmfts_sysfs_hover_enable_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 					stmfts_sysfs_hover_enable_write);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) static struct attribute *stmfts_sysfs_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	&dev_attr_chip_id.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	&dev_attr_chip_version.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	&dev_attr_fw_ver.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	&dev_attr_config_id.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	&dev_attr_config_version.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	&dev_attr_status.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	&dev_attr_hover_enable.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) static struct attribute_group stmfts_attribute_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	.attrs = stmfts_sysfs_attrs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) static int stmfts_power_on(struct stmfts_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	u8 reg[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	err = regulator_bulk_enable(ARRAY_SIZE(sdata->regulators),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 				    sdata->regulators);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	 * The datasheet does not specify the power on time, but considering
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	 * that the reset time is < 10ms, I sleep 20ms to be sure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	msleep(20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	err = i2c_smbus_read_i2c_block_data(sdata->client, STMFTS_READ_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 					    sizeof(reg), reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	if (err != sizeof(reg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	sdata->chip_id = be16_to_cpup((__be16 *)&reg[6]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	sdata->chip_ver = reg[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	sdata->fw_ver = be16_to_cpup((__be16 *)&reg[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	sdata->config_id = reg[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	sdata->config_ver = reg[5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	enable_irq(sdata->client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	msleep(50);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	err = stmfts_command(sdata, STMFTS_SYSTEM_RESET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	err = stmfts_command(sdata, STMFTS_SLEEP_OUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	/* optional tuning */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	err = stmfts_command(sdata, STMFTS_MS_CX_TUNING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 		dev_warn(&sdata->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 			 "failed to perform mutual auto tune: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	/* optional tuning */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	err = stmfts_command(sdata, STMFTS_SS_CX_TUNING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 		dev_warn(&sdata->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 			 "failed to perform self auto tune: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	err = stmfts_command(sdata, STMFTS_FULL_FORCE_CALIBRATION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	 * At this point no one is using the touchscreen
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	 * and I don't really care about the return value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	(void) i2c_smbus_write_byte(sdata->client, STMFTS_SLEEP_IN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) static void stmfts_power_off(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	struct stmfts_data *sdata = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	disable_irq(sdata->client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	regulator_bulk_disable(ARRAY_SIZE(sdata->regulators),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 						sdata->regulators);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) /* This function is void because I don't want to prevent using the touch key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)  * only because the LEDs don't get registered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) static int stmfts_enable_led(struct stmfts_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	/* get the regulator for powering the leds on */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	sdata->ledvdd = devm_regulator_get(&sdata->client->dev, "ledvdd");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	if (IS_ERR(sdata->ledvdd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 		return PTR_ERR(sdata->ledvdd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	sdata->led_cdev.name = STMFTS_DEV_NAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 	sdata->led_cdev.max_brightness = LED_ON;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 	sdata->led_cdev.brightness = LED_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 	sdata->led_cdev.brightness_set_blocking = stmfts_brightness_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	sdata->led_cdev.brightness_get = stmfts_brightness_get;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	err = devm_led_classdev_register(&sdata->client->dev, &sdata->led_cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 		devm_regulator_put(sdata->ledvdd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) static int stmfts_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 			const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	struct stmfts_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 						I2C_FUNC_SMBUS_BYTE_DATA |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 						I2C_FUNC_SMBUS_I2C_BLOCK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	sdata = devm_kzalloc(&client->dev, sizeof(*sdata), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	if (!sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 	i2c_set_clientdata(client, sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 	sdata->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	mutex_init(&sdata->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	init_completion(&sdata->cmd_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	sdata->regulators[STMFTS_REGULATOR_VDD].supply = "vdd";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	sdata->regulators[STMFTS_REGULATOR_AVDD].supply = "avdd";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	err = devm_regulator_bulk_get(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 				      ARRAY_SIZE(sdata->regulators),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 				      sdata->regulators);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	sdata->input = devm_input_allocate_device(&client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	if (!sdata->input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	sdata->input->name = STMFTS_DEV_NAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 	sdata->input->id.bustype = BUS_I2C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	sdata->input->open = stmfts_input_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 	sdata->input->close = stmfts_input_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 	input_set_capability(sdata->input, EV_ABS, ABS_MT_POSITION_X);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 	input_set_capability(sdata->input, EV_ABS, ABS_MT_POSITION_Y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 	touchscreen_parse_properties(sdata->input, true, &sdata->prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 	input_set_abs_params(sdata->input, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 	input_set_abs_params(sdata->input, ABS_MT_TOUCH_MINOR, 0, 255, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 	input_set_abs_params(sdata->input, ABS_MT_ORIENTATION, 0, 255, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 	input_set_abs_params(sdata->input, ABS_MT_PRESSURE, 0, 255, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 	input_set_abs_params(sdata->input, ABS_DISTANCE, 0, 255, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 	sdata->use_key = device_property_read_bool(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 						   "touch-key-connected");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 	if (sdata->use_key) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 		input_set_capability(sdata->input, EV_KEY, KEY_MENU);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 		input_set_capability(sdata->input, EV_KEY, KEY_BACK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 	err = input_mt_init_slots(sdata->input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 				  STMFTS_MAX_FINGERS, INPUT_MT_DIRECT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 	input_set_drvdata(sdata->input, sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 	 * stmfts_power_on expects interrupt to be disabled, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	 * at this point the device is still off and I do not trust
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 	 * the status of the irq line that can generate some spurious
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 	 * interrupts. To be on the safe side it's better to not enable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 	 * the interrupts during their request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 	irq_set_status_flags(client->irq, IRQ_NOAUTOEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 	err = devm_request_threaded_irq(&client->dev, client->irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 					NULL, stmfts_irq_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 					IRQF_ONESHOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 					"stmfts_irq", sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 	dev_dbg(&client->dev, "initializing ST-Microelectronics FTS...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 	err = stmfts_power_on(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 	err = devm_add_action_or_reset(&client->dev, stmfts_power_off, sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 	err = input_register_device(sdata->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 	if (sdata->use_key) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 		err = stmfts_enable_led(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 			 * Even if the LEDs have failed to be initialized and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 			 * used in the driver, I can still use the device even
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 			 * without LEDs. The ledvdd regulator pointer will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 			 * used as a flag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 			dev_warn(&client->dev, "unable to use touchkey leds\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 			sdata->ledvdd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 	err = devm_device_add_group(&client->dev, &stmfts_attribute_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 	pm_runtime_enable(&client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 	device_enable_async_suspend(&client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) static int stmfts_remove(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 	pm_runtime_disable(&client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) static int __maybe_unused stmfts_runtime_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 	struct stmfts_data *sdata = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 	ret = i2c_smbus_write_byte(sdata->client, STMFTS_SLEEP_IN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 		dev_warn(dev, "failed to suspend device: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) static int __maybe_unused stmfts_runtime_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) 	struct stmfts_data *sdata = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) 	ret = i2c_smbus_write_byte(sdata->client, STMFTS_SLEEP_OUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 		dev_err(dev, "failed to resume device: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) static int __maybe_unused stmfts_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) 	struct stmfts_data *sdata = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) 	stmfts_power_off(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) static int __maybe_unused stmfts_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) 	struct stmfts_data *sdata = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) 	return stmfts_power_on(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) static const struct dev_pm_ops stmfts_pm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) 	SET_SYSTEM_SLEEP_PM_OPS(stmfts_suspend, stmfts_resume)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) 	SET_RUNTIME_PM_OPS(stmfts_runtime_suspend, stmfts_runtime_resume, NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) static const struct of_device_id stmfts_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) 	{ .compatible = "st,stmfts", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 	{ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) MODULE_DEVICE_TABLE(of, stmfts_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) static const struct i2c_device_id stmfts_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) 	{ "stmfts", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) 	{ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) MODULE_DEVICE_TABLE(i2c, stmfts_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) static struct i2c_driver stmfts_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) 		.name = STMFTS_DEV_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) 		.of_match_table = of_match_ptr(stmfts_of_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) 		.pm = &stmfts_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) 		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) 	.probe = stmfts_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) 	.remove = stmfts_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) 	.id_table = stmfts_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) module_i2c_driver(stmfts_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) MODULE_AUTHOR("Andi Shyti <andi.shyti@samsung.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) MODULE_DESCRIPTION("STMicroelectronics FTS Touch Screen");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) MODULE_LICENSE("GPL v2");