.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * STMicroelectronics STMPE811 Touchscreen Driver |
---|
3 | 4 | * |
---|
4 | 5 | * (C) 2010 Luotao Fu <l.fu@pengutronix.de> |
---|
5 | 6 | * 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 | | - * |
---|
12 | 7 | */ |
---|
13 | 8 | |
---|
14 | 9 | #include <linux/kernel.h> |
---|
.. | .. |
---|
30 | 25 | * with touchscreen controller |
---|
31 | 26 | */ |
---|
32 | 27 | #define STMPE_REG_INT_STA 0x0B |
---|
33 | | -#define STMPE_REG_ADC_CTRL1 0x20 |
---|
34 | | -#define STMPE_REG_ADC_CTRL2 0x21 |
---|
35 | 28 | #define STMPE_REG_TSC_CTRL 0x40 |
---|
36 | 29 | #define STMPE_REG_TSC_CFG 0x41 |
---|
37 | 30 | #define STMPE_REG_FIFO_TH 0x4A |
---|
.. | .. |
---|
49 | 42 | |
---|
50 | 43 | #define STMPE_IRQ_TOUCH_DET 0 |
---|
51 | 44 | |
---|
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 | | - |
---|
63 | 45 | #define STMPE_TS_NAME "stmpe-ts" |
---|
64 | 46 | #define XY_MASK 0xfff |
---|
65 | 47 | |
---|
.. | .. |
---|
69 | 51 | * @idev: registered input device |
---|
70 | 52 | * @work: a work item used to scan the device |
---|
71 | 53 | * @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) |
---|
81 | 54 | * @ave_ctrl: Sample average control |
---|
82 | 55 | * (0 -> 1 sample, 1 -> 2 samples, 2 -> 4 samples, 3 -> 8 samples) |
---|
83 | 56 | * @touch_det_delay: Touch detect interrupt delay |
---|
.. | .. |
---|
99 | 72 | struct input_dev *idev; |
---|
100 | 73 | struct delayed_work work; |
---|
101 | 74 | struct device *dev; |
---|
102 | | - u8 sample_time; |
---|
103 | | - u8 mod_12b; |
---|
104 | | - u8 ref_sel; |
---|
105 | | - u8 adc_freq; |
---|
106 | 75 | u8 ave_ctrl; |
---|
107 | 76 | u8 touch_det_delay; |
---|
108 | 77 | u8 settling; |
---|
.. | .. |
---|
203 | 172 | static int stmpe_init_hw(struct stmpe_touch *ts) |
---|
204 | 173 | { |
---|
205 | 174 | int ret; |
---|
206 | | - u8 adc_ctrl1, adc_ctrl1_mask, tsc_cfg, tsc_cfg_mask; |
---|
| 175 | + u8 tsc_cfg, tsc_cfg_mask; |
---|
207 | 176 | struct stmpe *stmpe = ts->stmpe; |
---|
208 | 177 | struct device *dev = ts->dev; |
---|
209 | 178 | |
---|
.. | .. |
---|
213 | 182 | return ret; |
---|
214 | 183 | } |
---|
215 | 184 | |
---|
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); |
---|
222 | 186 | if (ret) { |
---|
223 | | - dev_err(dev, "Could not setup ADC\n"); |
---|
| 187 | + stmpe_disable(stmpe, STMPE_BLOCK_TOUCHSCREEN | STMPE_BLOCK_ADC); |
---|
224 | 188 | return ret; |
---|
225 | 189 | } |
---|
226 | 190 | |
---|
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); |
---|
237 | 196 | |
---|
238 | 197 | ret = stmpe_set_bits(stmpe, STMPE_REG_TSC_CFG, tsc_cfg_mask, tsc_cfg); |
---|
239 | 198 | if (ret) { |
---|
.. | .. |
---|
242 | 201 | } |
---|
243 | 202 | |
---|
244 | 203 | 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)); |
---|
246 | 205 | if (ret) { |
---|
247 | 206 | dev_err(dev, "Could not config touch\n"); |
---|
248 | 207 | return ret; |
---|
249 | 208 | } |
---|
250 | 209 | |
---|
251 | 210 | 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)); |
---|
253 | 212 | if (ret) { |
---|
254 | 213 | dev_err(dev, "Could not config touch\n"); |
---|
255 | 214 | return ret; |
---|
.. | .. |
---|
263 | 222 | } |
---|
264 | 223 | |
---|
265 | 224 | 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)); |
---|
267 | 226 | if (ret) { |
---|
268 | 227 | dev_err(dev, "Could not set mode\n"); |
---|
269 | 228 | return ret; |
---|
.. | .. |
---|
303 | 262 | |
---|
304 | 263 | if (np) { |
---|
305 | 264 | if (!of_property_read_u32(np, "st,sample-time", &val)) |
---|
306 | | - ts->sample_time = val; |
---|
| 265 | + ts->stmpe->sample_time = val; |
---|
307 | 266 | if (!of_property_read_u32(np, "st,mod-12b", &val)) |
---|
308 | | - ts->mod_12b = val; |
---|
| 267 | + ts->stmpe->mod_12b = val; |
---|
309 | 268 | if (!of_property_read_u32(np, "st,ref-sel", &val)) |
---|
310 | | - ts->ref_sel = val; |
---|
| 269 | + ts->stmpe->ref_sel = val; |
---|
311 | 270 | if (!of_property_read_u32(np, "st,adc-freq", &val)) |
---|
312 | | - ts->adc_freq = val; |
---|
| 271 | + ts->stmpe->adc_freq = val; |
---|
313 | 272 | if (!of_property_read_u32(np, "st,ave-ctrl", &val)) |
---|
314 | 273 | ts->ave_ctrl = val; |
---|
315 | 274 | if (!of_property_read_u32(np, "st,touch-det-delay", &val)) |
---|