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-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Touchscreen driver for Dialog Semiconductor DA9034
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2006-2008 Marvell International Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *	Fengwei Yin <fengwei.yin@marvell.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *	Bin Yang  <bin.yang@marvell.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *	Eric Miao <eric.miao@marvell.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/kernel.h>
^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/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/mfd/da903x.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define DA9034_MANUAL_CTRL	0x50
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define DA9034_LDO_ADC_EN	(1 << 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define DA9034_AUTO_CTRL1	0x51
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define DA9034_AUTO_CTRL2	0x52
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define DA9034_AUTO_TSI_EN	(1 << 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define DA9034_PEN_DETECT	(1 << 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define DA9034_TSI_CTRL1	0x53
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define DA9034_TSI_CTRL2	0x54
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define DA9034_TSI_X_MSB	0x6c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define DA9034_TSI_Y_MSB	0x6d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define DA9034_TSI_XY_LSB	0x6e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	STATE_IDLE,	/* wait for pendown */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	STATE_BUSY,	/* TSI busy sampling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	STATE_STOP,	/* sample available */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	STATE_WAIT,	/* Wait to start next sample */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	EVENT_PEN_DOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	EVENT_PEN_UP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	EVENT_TSI_READY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	EVENT_TIMEDOUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) struct da9034_touch {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	struct device		*da9034_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	struct input_dev	*input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	struct delayed_work	tsi_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	struct notifier_block	notifier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	int	state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	int	interval_ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	int	x_inverted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	int	y_inverted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	int	last_x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	int	last_y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) static inline int is_pen_down(struct da9034_touch *touch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	return da903x_query_status(touch->da9034_dev, DA9034_STATUS_PEN_DOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) static inline int detect_pen_down(struct da9034_touch *touch, int on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	if (on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		return da903x_set_bits(touch->da9034_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 				DA9034_AUTO_CTRL2, DA9034_PEN_DETECT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		return da903x_clr_bits(touch->da9034_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 				DA9034_AUTO_CTRL2, DA9034_PEN_DETECT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) static int read_tsi(struct da9034_touch *touch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	uint8_t _x, _y, _v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	ret = da903x_read(touch->da9034_dev, DA9034_TSI_X_MSB, &_x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	ret = da903x_read(touch->da9034_dev, DA9034_TSI_Y_MSB, &_y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	ret = da903x_read(touch->da9034_dev, DA9034_TSI_XY_LSB, &_v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	touch->last_x = ((_x << 2) & 0x3fc) | (_v & 0x3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	touch->last_y = ((_y << 2) & 0x3fc) | ((_v & 0xc) >> 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static inline int start_tsi(struct da9034_touch *touch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	return da903x_set_bits(touch->da9034_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			DA9034_AUTO_CTRL2, DA9034_AUTO_TSI_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static inline int stop_tsi(struct da9034_touch *touch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	return da903x_clr_bits(touch->da9034_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 			DA9034_AUTO_CTRL2, DA9034_AUTO_TSI_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static inline void report_pen_down(struct da9034_touch *touch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	int x = touch->last_x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	int y = touch->last_y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	x &= 0xfff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	if (touch->x_inverted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		x = 1024 - x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	y &= 0xfff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	if (touch->y_inverted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		y = 1024 - y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	input_report_abs(touch->input_dev, ABS_X, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	input_report_abs(touch->input_dev, ABS_Y, y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	input_report_key(touch->input_dev, BTN_TOUCH, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	input_sync(touch->input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static inline void report_pen_up(struct da9034_touch *touch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	input_report_key(touch->input_dev, BTN_TOUCH, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	input_sync(touch->input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static void da9034_event_handler(struct da9034_touch *touch, int event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	switch (touch->state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	case STATE_IDLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		if (event != EVENT_PEN_DOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		/* Enable auto measurement of the TSI, this will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		 * automatically disable pen down detection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		err = start_tsi(touch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 			goto err_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		touch->state = STATE_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	case STATE_BUSY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		if (event != EVENT_TSI_READY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		err = read_tsi(touch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 			goto err_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		/* Disable auto measurement of the TSI, so that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		 * pen down status will be available
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		err = stop_tsi(touch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 			goto err_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		touch->state = STATE_STOP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		/* FIXME: PEN_{UP/DOWN} events are expected to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		 * available by stopping TSI, but this is found not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		 * always true, delay and simulate such an event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		 * here is more reliable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		mdelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		da9034_event_handler(touch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 				     is_pen_down(touch) ? EVENT_PEN_DOWN :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 							  EVENT_PEN_UP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	case STATE_STOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		if (event == EVENT_PEN_DOWN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 			report_pen_down(touch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 			schedule_delayed_work(&touch->tsi_work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 				msecs_to_jiffies(touch->interval_ms));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			touch->state = STATE_WAIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		if (event == EVENT_PEN_UP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 			report_pen_up(touch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 			touch->state = STATE_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	case STATE_WAIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		if (event != EVENT_TIMEDOUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		if (is_pen_down(touch)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 			start_tsi(touch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			touch->state = STATE_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			report_pen_up(touch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 			touch->state = STATE_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) err_reset:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	touch->state = STATE_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	stop_tsi(touch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	detect_pen_down(touch, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) static void da9034_tsi_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	struct da9034_touch *touch =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		container_of(work, struct da9034_touch, tsi_work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	da9034_event_handler(touch, EVENT_TIMEDOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) static int da9034_touch_notifier(struct notifier_block *nb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 				 unsigned long event, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	struct da9034_touch *touch =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		container_of(nb, struct da9034_touch, notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	if (event & DA9034_EVENT_TSI_READY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		da9034_event_handler(touch, EVENT_TSI_READY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	if ((event & DA9034_EVENT_PEN_DOWN) && touch->state == STATE_IDLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		da9034_event_handler(touch, EVENT_PEN_DOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) static int da9034_touch_open(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	struct da9034_touch *touch = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	ret = da903x_register_notifier(touch->da9034_dev, &touch->notifier,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 			DA9034_EVENT_PEN_DOWN | DA9034_EVENT_TSI_READY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	/* Enable ADC LDO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	ret = da903x_set_bits(touch->da9034_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 			DA9034_MANUAL_CTRL, DA9034_LDO_ADC_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	/* TSI_DELAY: 3 slots, TSI_SKIP: 3 slots */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	ret = da903x_write(touch->da9034_dev, DA9034_TSI_CTRL1, 0x1b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	ret = da903x_write(touch->da9034_dev, DA9034_TSI_CTRL2, 0x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	touch->state = STATE_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	detect_pen_down(touch, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	return 0;
^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) static void da9034_touch_close(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	struct da9034_touch *touch = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	da903x_unregister_notifier(touch->da9034_dev, &touch->notifier,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 			DA9034_EVENT_PEN_DOWN | DA9034_EVENT_TSI_READY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	cancel_delayed_work_sync(&touch->tsi_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	touch->state = STATE_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	stop_tsi(touch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	detect_pen_down(touch, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	/* Disable ADC LDO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	da903x_clr_bits(touch->da9034_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 			DA9034_MANUAL_CTRL, DA9034_LDO_ADC_EN);
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) static int da9034_touch_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	struct da9034_touch_pdata *pdata = dev_get_platdata(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	struct da9034_touch *touch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	touch = devm_kzalloc(&pdev->dev, sizeof(struct da9034_touch),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 			     GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	if (!touch) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		dev_err(&pdev->dev, "failed to allocate driver data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		return -ENOMEM;
^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) 	touch->da9034_dev = pdev->dev.parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	if (pdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		touch->interval_ms	= pdata->interval_ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		touch->x_inverted	= pdata->x_inverted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		touch->y_inverted	= pdata->y_inverted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		/* fallback into default */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		touch->interval_ms	= 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	INIT_DELAYED_WORK(&touch->tsi_work, da9034_tsi_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	touch->notifier.notifier_call = da9034_touch_notifier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	input_dev = devm_input_allocate_device(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	if (!input_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		dev_err(&pdev->dev, "failed to allocate input device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	input_dev->name		= pdev->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	input_dev->open		= da9034_touch_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	input_dev->close	= da9034_touch_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	input_dev->dev.parent	= &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	__set_bit(EV_ABS, input_dev->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	__set_bit(ABS_X, input_dev->absbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	__set_bit(ABS_Y, input_dev->absbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	input_set_abs_params(input_dev, ABS_X, 0, 1023, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	input_set_abs_params(input_dev, ABS_Y, 0, 1023, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	__set_bit(EV_KEY, input_dev->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	__set_bit(BTN_TOUCH, input_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	touch->input_dev = input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	input_set_drvdata(input_dev, touch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	error = input_register_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) static struct platform_driver da9034_touch_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	.driver	= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		.name	= "da9034-touch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	.probe		= da9034_touch_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) module_platform_driver(da9034_touch_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) MODULE_DESCRIPTION("Touchscreen driver for Dialog Semiconductor DA9034");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) MODULE_AUTHOR("Eric Miao <eric.miao@marvell.com>, Bin Yang <bin.yang@marvell.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) MODULE_ALIAS("platform:da9034-touch");