hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/input/touchscreen/stmpe-ts.c
....@@ -1,14 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * STMicroelectronics STMPE811 Touchscreen Driver
34 *
45 * (C) 2010 Luotao Fu <l.fu@pengutronix.de>
56 * All rights reserved.
6
- *
7
- * This program is free software; you can redistribute it and/or modify it
8
- * under the terms of the GNU General Public License as published by the
9
- * Free Software Foundation; either version 2 of the License, or (at your
10
- * option) any later version.
11
- *
127 */
138
149 #include <linux/kernel.h>
....@@ -30,8 +25,6 @@
3025 * with touchscreen controller
3126 */
3227 #define STMPE_REG_INT_STA 0x0B
33
-#define STMPE_REG_ADC_CTRL1 0x20
34
-#define STMPE_REG_ADC_CTRL2 0x21
3528 #define STMPE_REG_TSC_CTRL 0x40
3629 #define STMPE_REG_TSC_CFG 0x41
3730 #define STMPE_REG_FIFO_TH 0x4A
....@@ -49,17 +42,6 @@
4942
5043 #define STMPE_IRQ_TOUCH_DET 0
5144
52
-#define SAMPLE_TIME(x) ((x & 0xf) << 4)
53
-#define MOD_12B(x) ((x & 0x1) << 3)
54
-#define REF_SEL(x) ((x & 0x1) << 1)
55
-#define ADC_FREQ(x) (x & 0x3)
56
-#define AVE_CTRL(x) ((x & 0x3) << 6)
57
-#define DET_DELAY(x) ((x & 0x7) << 3)
58
-#define SETTLING(x) (x & 0x7)
59
-#define FRACTION_Z(x) (x & 0x7)
60
-#define I_DRIVE(x) (x & 0x1)
61
-#define OP_MODE(x) ((x & 0x7) << 1)
62
-
6345 #define STMPE_TS_NAME "stmpe-ts"
6446 #define XY_MASK 0xfff
6547
....@@ -69,15 +51,6 @@
6951 * @idev: registered input device
7052 * @work: a work item used to scan the device
7153 * @dev: a pointer back to the MFD cell struct device*
72
- * @sample_time: ADC converstion time in number of clock.
73
- * (0 -> 36 clocks, 1 -> 44 clocks, 2 -> 56 clocks, 3 -> 64 clocks,
74
- * 4 -> 80 clocks, 5 -> 96 clocks, 6 -> 144 clocks),
75
- * recommended is 4.
76
- * @mod_12b: ADC Bit mode (0 -> 10bit ADC, 1 -> 12bit ADC)
77
- * @ref_sel: ADC reference source
78
- * (0 -> internal reference, 1 -> external reference)
79
- * @adc_freq: ADC Clock speed
80
- * (0 -> 1.625 MHz, 1 -> 3.25 MHz, 2 || 3 -> 6.5 MHz)
8154 * @ave_ctrl: Sample average control
8255 * (0 -> 1 sample, 1 -> 2 samples, 2 -> 4 samples, 3 -> 8 samples)
8356 * @touch_det_delay: Touch detect interrupt delay
....@@ -99,10 +72,6 @@
9972 struct input_dev *idev;
10073 struct delayed_work work;
10174 struct device *dev;
102
- u8 sample_time;
103
- u8 mod_12b;
104
- u8 ref_sel;
105
- u8 adc_freq;
10675 u8 ave_ctrl;
10776 u8 touch_det_delay;
10877 u8 settling;
....@@ -203,7 +172,7 @@
203172 static int stmpe_init_hw(struct stmpe_touch *ts)
204173 {
205174 int ret;
206
- u8 adc_ctrl1, adc_ctrl1_mask, tsc_cfg, tsc_cfg_mask;
175
+ u8 tsc_cfg, tsc_cfg_mask;
207176 struct stmpe *stmpe = ts->stmpe;
208177 struct device *dev = ts->dev;
209178
....@@ -213,27 +182,17 @@
213182 return ret;
214183 }
215184
216
- adc_ctrl1 = SAMPLE_TIME(ts->sample_time) | MOD_12B(ts->mod_12b) |
217
- REF_SEL(ts->ref_sel);
218
- adc_ctrl1_mask = SAMPLE_TIME(0xff) | MOD_12B(0xff) | REF_SEL(0xff);
219
-
220
- ret = stmpe_set_bits(stmpe, STMPE_REG_ADC_CTRL1,
221
- adc_ctrl1_mask, adc_ctrl1);
185
+ ret = stmpe811_adc_common_init(stmpe);
222186 if (ret) {
223
- dev_err(dev, "Could not setup ADC\n");
187
+ stmpe_disable(stmpe, STMPE_BLOCK_TOUCHSCREEN | STMPE_BLOCK_ADC);
224188 return ret;
225189 }
226190
227
- ret = stmpe_set_bits(stmpe, STMPE_REG_ADC_CTRL2,
228
- ADC_FREQ(0xff), ADC_FREQ(ts->adc_freq));
229
- if (ret) {
230
- dev_err(dev, "Could not setup ADC\n");
231
- return ret;
232
- }
233
-
234
- tsc_cfg = AVE_CTRL(ts->ave_ctrl) | DET_DELAY(ts->touch_det_delay) |
235
- SETTLING(ts->settling);
236
- tsc_cfg_mask = AVE_CTRL(0xff) | DET_DELAY(0xff) | SETTLING(0xff);
191
+ tsc_cfg = STMPE_AVE_CTRL(ts->ave_ctrl) |
192
+ STMPE_DET_DELAY(ts->touch_det_delay) |
193
+ STMPE_SETTLING(ts->settling);
194
+ tsc_cfg_mask = STMPE_AVE_CTRL(0xff) | STMPE_DET_DELAY(0xff) |
195
+ STMPE_SETTLING(0xff);
237196
238197 ret = stmpe_set_bits(stmpe, STMPE_REG_TSC_CFG, tsc_cfg_mask, tsc_cfg);
239198 if (ret) {
....@@ -242,14 +201,14 @@
242201 }
243202
244203 ret = stmpe_set_bits(stmpe, STMPE_REG_TSC_FRACTION_Z,
245
- FRACTION_Z(0xff), FRACTION_Z(ts->fraction_z));
204
+ STMPE_FRACTION_Z(0xff), STMPE_FRACTION_Z(ts->fraction_z));
246205 if (ret) {
247206 dev_err(dev, "Could not config touch\n");
248207 return ret;
249208 }
250209
251210 ret = stmpe_set_bits(stmpe, STMPE_REG_TSC_I_DRIVE,
252
- I_DRIVE(0xff), I_DRIVE(ts->i_drive));
211
+ STMPE_I_DRIVE(0xff), STMPE_I_DRIVE(ts->i_drive));
253212 if (ret) {
254213 dev_err(dev, "Could not config touch\n");
255214 return ret;
....@@ -263,7 +222,7 @@
263222 }
264223
265224 ret = stmpe_set_bits(stmpe, STMPE_REG_TSC_CTRL,
266
- OP_MODE(0xff), OP_MODE(OP_MOD_XYZ));
225
+ STMPE_OP_MODE(0xff), STMPE_OP_MODE(OP_MOD_XYZ));
267226 if (ret) {
268227 dev_err(dev, "Could not set mode\n");
269228 return ret;
....@@ -303,13 +262,13 @@
303262
304263 if (np) {
305264 if (!of_property_read_u32(np, "st,sample-time", &val))
306
- ts->sample_time = val;
265
+ ts->stmpe->sample_time = val;
307266 if (!of_property_read_u32(np, "st,mod-12b", &val))
308
- ts->mod_12b = val;
267
+ ts->stmpe->mod_12b = val;
309268 if (!of_property_read_u32(np, "st,ref-sel", &val))
310
- ts->ref_sel = val;
269
+ ts->stmpe->ref_sel = val;
311270 if (!of_property_read_u32(np, "st,adc-freq", &val))
312
- ts->adc_freq = val;
271
+ ts->stmpe->adc_freq = val;
313272 if (!of_property_read_u32(np, "st,ave-ctrl", &val))
314273 ts->ave_ctrl = val;
315274 if (!of_property_read_u32(np, "st,touch-det-delay", &val))