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)  * TSI driver for Dialog DA9052
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright(c) 2012 Dialog Semiconductor Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Author: David Dajun Chen <dchen@diasemi.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/mfd/da9052/reg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/mfd/da9052/da9052.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #define TSI_PEN_DOWN_STATUS 0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) struct da9052_tsi {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	struct da9052 *da9052;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	struct input_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	struct delayed_work ts_pen_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	bool stopped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	bool adc_on;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static void da9052_ts_adc_toggle(struct da9052_tsi *tsi, bool on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	da9052_reg_update(tsi->da9052, DA9052_TSI_CONT_A_REG, 1 << 0, on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	tsi->adc_on = on;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) static irqreturn_t da9052_ts_pendwn_irq(int irq, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	struct da9052_tsi *tsi = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	if (!tsi->stopped) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		/* Mask PEN_DOWN event and unmask TSI_READY event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		da9052_disable_irq_nosync(tsi->da9052, DA9052_IRQ_PENDOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		da9052_enable_irq(tsi->da9052, DA9052_IRQ_TSIREADY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		da9052_ts_adc_toggle(tsi, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		schedule_delayed_work(&tsi->ts_pen_work, HZ / 50);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) static void da9052_ts_read(struct da9052_tsi *tsi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	struct input_dev *input = tsi->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	u16 x, y, z;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	u8 v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	ret = da9052_reg_read(tsi->da9052, DA9052_TSI_X_MSB_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	x = (u16) ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	ret = da9052_reg_read(tsi->da9052, DA9052_TSI_Y_MSB_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	y = (u16) ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	ret = da9052_reg_read(tsi->da9052, DA9052_TSI_Z_MSB_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	z = (u16) ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	ret = da9052_reg_read(tsi->da9052, DA9052_TSI_LSB_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	v = (u8) ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	x = ((x << 2) & 0x3fc) | (v & 0x3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	y = ((y << 2) & 0x3fc) | ((v & 0xc) >> 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	z = ((z << 2) & 0x3fc) | ((v & 0x30) >> 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	input_report_key(input, BTN_TOUCH, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	input_report_abs(input, ABS_X, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	input_report_abs(input, ABS_Y, y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	input_report_abs(input, ABS_PRESSURE, z);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	input_sync(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) static irqreturn_t da9052_ts_datardy_irq(int irq, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	struct da9052_tsi *tsi = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	da9052_ts_read(tsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static void da9052_ts_pen_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	struct da9052_tsi *tsi = container_of(work, struct da9052_tsi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 					      ts_pen_work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	if (!tsi->stopped) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		int ret = da9052_reg_read(tsi->da9052, DA9052_TSI_LSB_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		if (ret < 0 || (ret & TSI_PEN_DOWN_STATUS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 			/* Pen is still DOWN (or read error) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 			schedule_delayed_work(&tsi->ts_pen_work, HZ / 50);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 			struct input_dev *input = tsi->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			/* Pen UP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 			da9052_ts_adc_toggle(tsi, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 			/* Report Pen UP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 			input_report_key(input, BTN_TOUCH, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 			input_report_abs(input, ABS_PRESSURE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 			input_sync(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			 * FIXME: Fixes the unhandled irq issue when quick
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 			 * pen down and pen up events occurs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 			ret = da9052_reg_update(tsi->da9052,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 						DA9052_EVENT_B_REG, 0xC0, 0xC0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 			if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 				return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			/* Mask TSI_READY event and unmask PEN_DOWN event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			da9052_disable_irq(tsi->da9052, DA9052_IRQ_TSIREADY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			da9052_enable_irq(tsi->da9052, DA9052_IRQ_PENDOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static int da9052_ts_configure_gpio(struct da9052 *da9052)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	error = da9052_reg_update(da9052, DA9052_GPIO_2_3_REG, 0x30, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	error = da9052_reg_update(da9052, DA9052_GPIO_4_5_REG, 0x33, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	error = da9052_reg_update(da9052, DA9052_GPIO_6_7_REG, 0x33, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static int da9052_configure_tsi(struct da9052_tsi *tsi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	error = da9052_ts_configure_gpio(tsi->da9052);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	/* Measure TSI sample every 1ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	error = da9052_reg_update(tsi->da9052, DA9052_ADC_CONT_REG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 				  1 << 6, 1 << 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	/* TSI_DELAY: 3 slots, TSI_SKIP: 0 slots, TSI_MODE: XYZP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	error = da9052_reg_update(tsi->da9052, DA9052_TSI_CONT_A_REG, 0xFC, 0xC0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	/* Supply TSIRef through LD09 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	error = da9052_reg_write(tsi->da9052, DA9052_LDO9_REG, 0x59);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) static int da9052_ts_input_open(struct input_dev *input_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	struct da9052_tsi *tsi = input_get_drvdata(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	tsi->stopped = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	mb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	/* Unmask PEN_DOWN event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	da9052_enable_irq(tsi->da9052, DA9052_IRQ_PENDOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	/* Enable Pen Detect Circuit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	return da9052_reg_update(tsi->da9052, DA9052_TSI_CONT_A_REG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 				 1 << 1, 1 << 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) static void da9052_ts_input_close(struct input_dev *input_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	struct da9052_tsi *tsi = input_get_drvdata(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	tsi->stopped = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	mb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	da9052_disable_irq(tsi->da9052, DA9052_IRQ_PENDOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	cancel_delayed_work_sync(&tsi->ts_pen_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	if (tsi->adc_on) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		da9052_disable_irq(tsi->da9052, DA9052_IRQ_TSIREADY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		da9052_ts_adc_toggle(tsi, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		 * If ADC was on that means that pendwn IRQ was disabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		 * twice and we need to enable it to keep enable/disable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		 * counter balanced. IRQ is still off though.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		da9052_enable_irq(tsi->da9052, DA9052_IRQ_PENDOWN);
^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) 	/* Disable Pen Detect Circuit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	da9052_reg_update(tsi->da9052, DA9052_TSI_CONT_A_REG, 1 << 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) static int da9052_ts_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	struct da9052 *da9052;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	struct da9052_tsi *tsi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	da9052 = dev_get_drvdata(pdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	if (!da9052)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	tsi = kzalloc(sizeof(struct da9052_tsi), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	input_dev = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	if (!tsi || !input_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		goto err_free_mem;
^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) 	tsi->da9052 = da9052;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	tsi->dev = input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	tsi->stopped = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	INIT_DELAYED_WORK(&tsi->ts_pen_work, da9052_ts_pen_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	input_dev->id.version = 0x0101;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	input_dev->id.vendor = 0x15B6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	input_dev->id.product = 0x9052;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	input_dev->name = "Dialog DA9052 TouchScreen Driver";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	input_dev->dev.parent = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	input_dev->open = da9052_ts_input_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	input_dev->close = da9052_ts_input_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	__set_bit(EV_ABS, input_dev->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	__set_bit(EV_KEY, input_dev->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	__set_bit(BTN_TOUCH, input_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	input_set_abs_params(input_dev, ABS_X, 0, 1023, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	input_set_abs_params(input_dev, ABS_Y, 0, 1023, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	input_set_abs_params(input_dev, ABS_PRESSURE, 0, 1023, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	input_set_drvdata(input_dev, tsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	/* Disable Pen Detect Circuit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	da9052_reg_update(tsi->da9052, DA9052_TSI_CONT_A_REG, 1 << 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	/* Disable ADC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	da9052_ts_adc_toggle(tsi, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	error = da9052_request_irq(tsi->da9052, DA9052_IRQ_PENDOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 				"pendown-irq", da9052_ts_pendwn_irq, tsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		dev_err(tsi->da9052->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 			"Failed to register PENDWN IRQ: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		goto err_free_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	error = da9052_request_irq(tsi->da9052, DA9052_IRQ_TSIREADY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 				"tsiready-irq", da9052_ts_datardy_irq, tsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		dev_err(tsi->da9052->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			"Failed to register TSIRDY IRQ :%d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		goto err_free_pendwn_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	/* Mask PEN_DOWN and TSI_READY events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	da9052_disable_irq(tsi->da9052, DA9052_IRQ_PENDOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	da9052_disable_irq(tsi->da9052, DA9052_IRQ_TSIREADY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	error = da9052_configure_tsi(tsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		goto err_free_datardy_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	error = input_register_device(tsi->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		goto err_free_datardy_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	platform_set_drvdata(pdev, tsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) err_free_datardy_irq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	da9052_free_irq(tsi->da9052, DA9052_IRQ_TSIREADY, tsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) err_free_pendwn_irq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	da9052_free_irq(tsi->da9052, DA9052_IRQ_PENDOWN, tsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) err_free_mem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	kfree(tsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	input_free_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) static int  da9052_ts_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	struct da9052_tsi *tsi = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	da9052_reg_write(tsi->da9052, DA9052_LDO9_REG, 0x19);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	da9052_free_irq(tsi->da9052, DA9052_IRQ_TSIREADY, tsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	da9052_free_irq(tsi->da9052, DA9052_IRQ_PENDOWN, tsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	input_unregister_device(tsi->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	kfree(tsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) static struct platform_driver da9052_tsi_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	.probe	= da9052_ts_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	.remove	= da9052_ts_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	.driver	= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		.name	= "da9052-tsi",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) module_platform_driver(da9052_tsi_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) MODULE_DESCRIPTION("Touchscreen driver for Dialog Semiconductor DA9052");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) MODULE_AUTHOR("Anthony Olech <Anthony.Olech@diasemi.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) MODULE_ALIAS("platform:da9052-tsi");