^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) * STMicroelectronics STMPE811 Touchscreen Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * (C) 2010 Luotao Fu <l.fu@pengutronix.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/mfd/stmpe.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) /* Register layouts and functionalities are identical on all stmpexxx variants
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * with touchscreen controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define STMPE_REG_INT_STA 0x0B
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define STMPE_REG_TSC_CTRL 0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define STMPE_REG_TSC_CFG 0x41
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define STMPE_REG_FIFO_TH 0x4A
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define STMPE_REG_FIFO_STA 0x4B
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define STMPE_REG_FIFO_SIZE 0x4C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define STMPE_REG_TSC_DATA_XYZ 0x52
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define STMPE_REG_TSC_FRACTION_Z 0x56
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define STMPE_REG_TSC_I_DRIVE 0x58
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define OP_MOD_XYZ 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define STMPE_TSC_CTRL_TSC_EN (1<<0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define STMPE_FIFO_STA_RESET (1<<0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define STMPE_IRQ_TOUCH_DET 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define STMPE_TS_NAME "stmpe-ts"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define XY_MASK 0xfff
^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 stmpe_touch - stmpe811 touch screen controller state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * @stmpe: pointer back to STMPE MFD container
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * @idev: registered input device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * @work: a work item used to scan the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * @dev: a pointer back to the MFD cell struct device*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * @ave_ctrl: Sample average control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * (0 -> 1 sample, 1 -> 2 samples, 2 -> 4 samples, 3 -> 8 samples)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * @touch_det_delay: Touch detect interrupt delay
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * (0 -> 10 us, 1 -> 50 us, 2 -> 100 us, 3 -> 500 us,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * 4-> 1 ms, 5 -> 5 ms, 6 -> 10 ms, 7 -> 50 ms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * recommended is 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * @settling: Panel driver settling time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * (0 -> 10 us, 1 -> 100 us, 2 -> 500 us, 3 -> 1 ms,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * 4 -> 5 ms, 5 -> 10 ms, 6 for 50 ms, 7 -> 100 ms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * recommended is 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * @fraction_z: Length of the fractional part in z
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * (fraction_z ([0..7]) = Count of the fractional part)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * recommended is 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * @i_drive: current limit value of the touchscreen drivers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * (0 -> 20 mA typical 35 mA max, 1 -> 50 mA typical 80 mA max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct stmpe_touch {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct stmpe *stmpe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct input_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct delayed_work work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) u8 ave_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) u8 touch_det_delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) u8 settling;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) u8 fraction_z;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) u8 i_drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) static int __stmpe_reset_fifo(struct stmpe *stmpe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) {
^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 = stmpe_set_bits(stmpe, STMPE_REG_FIFO_STA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) STMPE_FIFO_STA_RESET, STMPE_FIFO_STA_RESET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) return stmpe_set_bits(stmpe, STMPE_REG_FIFO_STA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) STMPE_FIFO_STA_RESET, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) static void stmpe_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) int int_sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) u32 timeout = 40;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) struct stmpe_touch *ts =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) container_of(work, struct stmpe_touch, work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) int_sta = stmpe_reg_read(ts->stmpe, STMPE_REG_INT_STA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * touch_det sometimes get desasserted or just get stuck. This appears
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * to be a silicon bug, We still have to clearify this with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * manufacture. As a workaround We release the key anyway if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * touch_det keeps coming in after 4ms, while the FIFO contains no value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * during the whole time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) while ((int_sta & (1 << STMPE_IRQ_TOUCH_DET)) && (timeout > 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) timeout--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) int_sta = stmpe_reg_read(ts->stmpe, STMPE_REG_INT_STA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) udelay(100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /* reset the FIFO before we report release event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) __stmpe_reset_fifo(ts->stmpe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) input_report_abs(ts->idev, ABS_PRESSURE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) input_report_key(ts->idev, BTN_TOUCH, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) input_sync(ts->idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) static irqreturn_t stmpe_ts_handler(int irq, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) u8 data_set[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) int x, y, z;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) struct stmpe_touch *ts = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * Cancel scheduled polling for release if we have new value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * available. Wait if the polling is already running.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) cancel_delayed_work_sync(&ts->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * The FIFO sometimes just crashes and stops generating interrupts. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * appears to be a silicon bug. We still have to clearify this with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) * the manufacture. As a workaround we disable the TSC while we are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) * collecting data and flush the FIFO after reading
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) stmpe_set_bits(ts->stmpe, STMPE_REG_TSC_CTRL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) STMPE_TSC_CTRL_TSC_EN, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) stmpe_block_read(ts->stmpe, STMPE_REG_TSC_DATA_XYZ, 4, data_set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) x = (data_set[0] << 4) | (data_set[1] >> 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) y = ((data_set[1] & 0xf) << 8) | data_set[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) z = data_set[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) input_report_abs(ts->idev, ABS_X, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) input_report_abs(ts->idev, ABS_Y, y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) input_report_abs(ts->idev, ABS_PRESSURE, z);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) input_report_key(ts->idev, BTN_TOUCH, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) input_sync(ts->idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) /* flush the FIFO after we have read out our values. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) __stmpe_reset_fifo(ts->stmpe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) /* reenable the tsc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) stmpe_set_bits(ts->stmpe, STMPE_REG_TSC_CTRL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) STMPE_TSC_CTRL_TSC_EN, STMPE_TSC_CTRL_TSC_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) /* start polling for touch_det to detect release */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) schedule_delayed_work(&ts->work, msecs_to_jiffies(50));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) static int stmpe_init_hw(struct stmpe_touch *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) u8 tsc_cfg, tsc_cfg_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) struct stmpe *stmpe = ts->stmpe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) struct device *dev = ts->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) ret = stmpe_enable(stmpe, STMPE_BLOCK_TOUCHSCREEN | STMPE_BLOCK_ADC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) dev_err(dev, "Could not enable clock for ADC and TS\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) ret = stmpe811_adc_common_init(stmpe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) stmpe_disable(stmpe, STMPE_BLOCK_TOUCHSCREEN | STMPE_BLOCK_ADC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) tsc_cfg = STMPE_AVE_CTRL(ts->ave_ctrl) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) STMPE_DET_DELAY(ts->touch_det_delay) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) STMPE_SETTLING(ts->settling);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) tsc_cfg_mask = STMPE_AVE_CTRL(0xff) | STMPE_DET_DELAY(0xff) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) STMPE_SETTLING(0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) ret = stmpe_set_bits(stmpe, STMPE_REG_TSC_CFG, tsc_cfg_mask, tsc_cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) dev_err(dev, "Could not config touch\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) ret = stmpe_set_bits(stmpe, STMPE_REG_TSC_FRACTION_Z,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) STMPE_FRACTION_Z(0xff), STMPE_FRACTION_Z(ts->fraction_z));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) dev_err(dev, "Could not config touch\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) ret = stmpe_set_bits(stmpe, STMPE_REG_TSC_I_DRIVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) STMPE_I_DRIVE(0xff), STMPE_I_DRIVE(ts->i_drive));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) dev_err(dev, "Could not config touch\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) /* set FIFO to 1 for single point reading */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) ret = stmpe_reg_write(stmpe, STMPE_REG_FIFO_TH, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) dev_err(dev, "Could not set FIFO\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) return ret;
^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) ret = stmpe_set_bits(stmpe, STMPE_REG_TSC_CTRL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) STMPE_OP_MODE(0xff), STMPE_OP_MODE(OP_MOD_XYZ));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) dev_err(dev, "Could not set mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) return ret;
^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) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) static int stmpe_ts_open(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) struct stmpe_touch *ts = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) ret = __stmpe_reset_fifo(ts->stmpe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) return stmpe_set_bits(ts->stmpe, STMPE_REG_TSC_CTRL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) STMPE_TSC_CTRL_TSC_EN, STMPE_TSC_CTRL_TSC_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) static void stmpe_ts_close(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) struct stmpe_touch *ts = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) cancel_delayed_work_sync(&ts->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) stmpe_set_bits(ts->stmpe, STMPE_REG_TSC_CTRL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) STMPE_TSC_CTRL_TSC_EN, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) static void stmpe_ts_get_platform_info(struct platform_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) struct stmpe_touch *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) struct device_node *np = pdev->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) u32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) if (np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) if (!of_property_read_u32(np, "st,sample-time", &val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) ts->stmpe->sample_time = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) if (!of_property_read_u32(np, "st,mod-12b", &val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) ts->stmpe->mod_12b = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) if (!of_property_read_u32(np, "st,ref-sel", &val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) ts->stmpe->ref_sel = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) if (!of_property_read_u32(np, "st,adc-freq", &val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) ts->stmpe->adc_freq = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if (!of_property_read_u32(np, "st,ave-ctrl", &val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) ts->ave_ctrl = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) if (!of_property_read_u32(np, "st,touch-det-delay", &val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) ts->touch_det_delay = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) if (!of_property_read_u32(np, "st,settling", &val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) ts->settling = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) if (!of_property_read_u32(np, "st,fraction-z", &val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) ts->fraction_z = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) if (!of_property_read_u32(np, "st,i-drive", &val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) ts->i_drive = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) static int stmpe_input_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) struct stmpe_touch *ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) struct input_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) int ts_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) ts_irq = platform_get_irq_byname(pdev, "FIFO_TH");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) if (ts_irq < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) return ts_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) ts = devm_kzalloc(&pdev->dev, sizeof(*ts), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) if (!ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) idev = devm_input_allocate_device(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) if (!idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) platform_set_drvdata(pdev, ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) ts->stmpe = stmpe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) ts->idev = idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) ts->dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) stmpe_ts_get_platform_info(pdev, ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) INIT_DELAYED_WORK(&ts->work, stmpe_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) error = devm_request_threaded_irq(&pdev->dev, ts_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) NULL, stmpe_ts_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) IRQF_ONESHOT, STMPE_TS_NAME, ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) dev_err(&pdev->dev, "Failed to request IRQ %d\n", ts_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) error = stmpe_init_hw(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) idev->name = STMPE_TS_NAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) idev->phys = STMPE_TS_NAME"/input0";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) idev->id.bustype = BUS_I2C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) idev->open = stmpe_ts_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) idev->close = stmpe_ts_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) input_set_drvdata(idev, ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) input_set_capability(idev, EV_KEY, BTN_TOUCH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) input_set_abs_params(idev, ABS_X, 0, XY_MASK, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) input_set_abs_params(idev, ABS_Y, 0, XY_MASK, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) input_set_abs_params(idev, ABS_PRESSURE, 0x0, 0xff, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) error = input_register_device(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) dev_err(&pdev->dev, "Could not register input device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) static int stmpe_ts_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) struct stmpe_touch *ts = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) stmpe_disable(ts->stmpe, STMPE_BLOCK_TOUCHSCREEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) static struct platform_driver stmpe_ts_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) .name = STMPE_TS_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) .probe = stmpe_input_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) .remove = stmpe_ts_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) module_platform_driver(stmpe_ts_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) static const struct of_device_id stmpe_ts_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) { .compatible = "st,stmpe-ts", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) { },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) MODULE_DEVICE_TABLE(of, stmpe_ts_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) MODULE_AUTHOR("Luotao Fu <l.fu@pengutronix.de>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) MODULE_DESCRIPTION("STMPEXXX touchscreen driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) MODULE_LICENSE("GPL");