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