diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2010-08-12 13:01:06 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-08-12 13:01:06 -0400 |
commit | e83ddb335468cdd9ea6e9767eb30b64d8ff176ce (patch) | |
tree | af7ca0b5be74b713970149efaebe682596523252 /drivers/input | |
parent | 14a4fa20a10d76eb98b7feb25be60735217929ba (diff) | |
parent | d0a11693967295772d2a7c22b6b37eb20684e709 (diff) |
Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/sameo/mfd-2.6
* 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/sameo/mfd-2.6: (40 commits)
mfd: Fix incorrect kfree(i2c) in wm8994-core i2c_driver probe
mfd: Fix incorrect kfree(i2c) in wm831x-core i2c_driver probe
mfd: Fix incorrect kfree(i2c) in tps6507x i2c_driver probe
mfd: Add TPS6586x driver
mfd: Use macros instead of some constant magic numbers for menelaus
mfd: Fix menelaus mmc slot 2 misconfiguration
mfd: Missing slab.h includes
mfd: Fix wrong wm8350-core kfree in error path
mfd: Fix wm8994_device_init() return value
mfd: Avoid calling platform_device_put() twice in ucb1400 probe error path
mfd: Annotate tc6387xb probe/remove routines with __devinit/__devexit
mfd: Fix tc6387xb resource reclaim
mfd: Fix wrong goto labels for tc6393xb error handling
mfd: Get rid of now unused mc13783 private header
hwmon: Don't access struct mc13783 directly from mc13783-adc
mfd: New mc13783 function exposing flags
mfd: Check jz4740-adc kmalloc() result
mfd: Fix jz4740-adc resource reclaim in probe error path
mfd: Add WM8321 support
mfd: Add stmpe auto sleep feature
...
Diffstat (limited to 'drivers/input')
-rw-r--r-- | drivers/input/keyboard/Kconfig | 10 | ||||
-rw-r--r-- | drivers/input/keyboard/Makefile | 1 | ||||
-rw-r--r-- | drivers/input/keyboard/stmpe-keypad.c | 386 | ||||
-rw-r--r-- | drivers/input/touchscreen/Kconfig | 10 | ||||
-rw-r--r-- | drivers/input/touchscreen/Makefile | 1 | ||||
-rw-r--r-- | drivers/input/touchscreen/stmpe-ts.c | 397 |
6 files changed, 805 insertions, 0 deletions
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig index b171f63fe4d..9cc488d2149 100644 --- a/drivers/input/keyboard/Kconfig +++ b/drivers/input/keyboard/Kconfig | |||
@@ -395,6 +395,16 @@ config KEYBOARD_SH_KEYSC | |||
395 | To compile this driver as a module, choose M here: the | 395 | To compile this driver as a module, choose M here: the |
396 | module will be called sh_keysc. | 396 | module will be called sh_keysc. |
397 | 397 | ||
398 | config KEYBOARD_STMPE | ||
399 | tristate "STMPE keypad support" | ||
400 | depends on MFD_STMPE | ||
401 | help | ||
402 | Say Y here if you want to use the keypad controller on STMPE I/O | ||
403 | expanders. | ||
404 | |||
405 | To compile this driver as a module, choose M here: the module will be | ||
406 | called stmpe-keypad. | ||
407 | |||
398 | config KEYBOARD_DAVINCI | 408 | config KEYBOARD_DAVINCI |
399 | tristate "TI DaVinci Key Scan" | 409 | tristate "TI DaVinci Key Scan" |
400 | depends on ARCH_DAVINCI_DM365 | 410 | depends on ARCH_DAVINCI_DM365 |
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile index 1a66d5f1ca8..504b591be0c 100644 --- a/drivers/input/keyboard/Makefile +++ b/drivers/input/keyboard/Makefile | |||
@@ -35,6 +35,7 @@ obj-$(CONFIG_KEYBOARD_PXA930_ROTARY) += pxa930_rotary.o | |||
35 | obj-$(CONFIG_KEYBOARD_QT2160) += qt2160.o | 35 | obj-$(CONFIG_KEYBOARD_QT2160) += qt2160.o |
36 | obj-$(CONFIG_KEYBOARD_SAMSUNG) += samsung-keypad.o | 36 | obj-$(CONFIG_KEYBOARD_SAMSUNG) += samsung-keypad.o |
37 | obj-$(CONFIG_KEYBOARD_SH_KEYSC) += sh_keysc.o | 37 | obj-$(CONFIG_KEYBOARD_SH_KEYSC) += sh_keysc.o |
38 | obj-$(CONFIG_KEYBOARD_STMPE) += stmpe-keypad.o | ||
38 | obj-$(CONFIG_KEYBOARD_STOWAWAY) += stowaway.o | 39 | obj-$(CONFIG_KEYBOARD_STOWAWAY) += stowaway.o |
39 | obj-$(CONFIG_KEYBOARD_SUNKBD) += sunkbd.o | 40 | obj-$(CONFIG_KEYBOARD_SUNKBD) += sunkbd.o |
40 | obj-$(CONFIG_KEYBOARD_TWL4030) += twl4030_keypad.o | 41 | obj-$(CONFIG_KEYBOARD_TWL4030) += twl4030_keypad.o |
diff --git a/drivers/input/keyboard/stmpe-keypad.c b/drivers/input/keyboard/stmpe-keypad.c new file mode 100644 index 00000000000..ab7610ca10e --- /dev/null +++ b/drivers/input/keyboard/stmpe-keypad.c | |||
@@ -0,0 +1,386 @@ | |||
1 | /* | ||
2 | * Copyright (C) ST-Ericsson SA 2010 | ||
3 | * | ||
4 | * License Terms: GNU General Public License, version 2 | ||
5 | * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson | ||
6 | */ | ||
7 | |||
8 | #include <linux/module.h> | ||
9 | #include <linux/init.h> | ||
10 | #include <linux/slab.h> | ||
11 | #include <linux/input.h> | ||
12 | #include <linux/interrupt.h> | ||
13 | #include <linux/platform_device.h> | ||
14 | #include <linux/input/matrix_keypad.h> | ||
15 | #include <linux/mfd/stmpe.h> | ||
16 | |||
17 | /* These are at the same addresses in all STMPE variants */ | ||
18 | #define STMPE_KPC_COL 0x60 | ||
19 | #define STMPE_KPC_ROW_MSB 0x61 | ||
20 | #define STMPE_KPC_ROW_LSB 0x62 | ||
21 | #define STMPE_KPC_CTRL_MSB 0x63 | ||
22 | #define STMPE_KPC_CTRL_LSB 0x64 | ||
23 | #define STMPE_KPC_COMBI_KEY_0 0x65 | ||
24 | #define STMPE_KPC_COMBI_KEY_1 0x66 | ||
25 | #define STMPE_KPC_COMBI_KEY_2 0x67 | ||
26 | #define STMPE_KPC_DATA_BYTE0 0x68 | ||
27 | #define STMPE_KPC_DATA_BYTE1 0x69 | ||
28 | #define STMPE_KPC_DATA_BYTE2 0x6a | ||
29 | #define STMPE_KPC_DATA_BYTE3 0x6b | ||
30 | #define STMPE_KPC_DATA_BYTE4 0x6c | ||
31 | |||
32 | #define STMPE_KPC_CTRL_LSB_SCAN (0x1 << 0) | ||
33 | #define STMPE_KPC_CTRL_LSB_DEBOUNCE (0x7f << 1) | ||
34 | #define STMPE_KPC_CTRL_MSB_SCAN_COUNT (0xf << 4) | ||
35 | |||
36 | #define STMPE_KPC_ROW_MSB_ROWS 0xff | ||
37 | |||
38 | #define STMPE_KPC_DATA_UP (0x1 << 7) | ||
39 | #define STMPE_KPC_DATA_ROW (0xf << 3) | ||
40 | #define STMPE_KPC_DATA_COL (0x7 << 0) | ||
41 | #define STMPE_KPC_DATA_NOKEY_MASK 0x78 | ||
42 | |||
43 | #define STMPE_KEYPAD_MAX_DEBOUNCE 127 | ||
44 | #define STMPE_KEYPAD_MAX_SCAN_COUNT 15 | ||
45 | |||
46 | #define STMPE_KEYPAD_MAX_ROWS 8 | ||
47 | #define STMPE_KEYPAD_MAX_COLS 8 | ||
48 | #define STMPE_KEYPAD_ROW_SHIFT 3 | ||
49 | #define STMPE_KEYPAD_KEYMAP_SIZE \ | ||
50 | (STMPE_KEYPAD_MAX_ROWS * STMPE_KEYPAD_MAX_COLS) | ||
51 | |||
52 | /** | ||
53 | * struct stmpe_keypad_variant - model-specific attributes | ||
54 | * @auto_increment: whether the KPC_DATA_BYTE register address | ||
55 | * auto-increments on multiple read | ||
56 | * @num_data: number of data bytes | ||
57 | * @num_normal_data: number of normal keys' data bytes | ||
58 | * @max_cols: maximum number of columns supported | ||
59 | * @max_rows: maximum number of rows supported | ||
60 | * @col_gpios: bitmask of gpios which can be used for columns | ||
61 | * @row_gpios: bitmask of gpios which can be used for rows | ||
62 | */ | ||
63 | struct stmpe_keypad_variant { | ||
64 | bool auto_increment; | ||
65 | int num_data; | ||
66 | int num_normal_data; | ||
67 | int max_cols; | ||
68 | int max_rows; | ||
69 | unsigned int col_gpios; | ||
70 | unsigned int row_gpios; | ||
71 | }; | ||
72 | |||
73 | static const struct stmpe_keypad_variant stmpe_keypad_variants[] = { | ||
74 | [STMPE1601] = { | ||
75 | .auto_increment = true, | ||
76 | .num_data = 5, | ||
77 | .num_normal_data = 3, | ||
78 | .max_cols = 8, | ||
79 | .max_rows = 8, | ||
80 | .col_gpios = 0x000ff, /* GPIO 0 - 7 */ | ||
81 | .row_gpios = 0x0ff00, /* GPIO 8 - 15 */ | ||
82 | }, | ||
83 | [STMPE2401] = { | ||
84 | .auto_increment = false, | ||
85 | .num_data = 3, | ||
86 | .num_normal_data = 2, | ||
87 | .max_cols = 8, | ||
88 | .max_rows = 12, | ||
89 | .col_gpios = 0x0000ff, /* GPIO 0 - 7*/ | ||
90 | .row_gpios = 0x1fef00, /* GPIO 8-14, 16-20 */ | ||
91 | }, | ||
92 | [STMPE2403] = { | ||
93 | .auto_increment = true, | ||
94 | .num_data = 5, | ||
95 | .num_normal_data = 3, | ||
96 | .max_cols = 8, | ||
97 | .max_rows = 12, | ||
98 | .col_gpios = 0x0000ff, /* GPIO 0 - 7*/ | ||
99 | .row_gpios = 0x1fef00, /* GPIO 8-14, 16-20 */ | ||
100 | }, | ||
101 | }; | ||
102 | |||
103 | struct stmpe_keypad { | ||
104 | struct stmpe *stmpe; | ||
105 | struct input_dev *input; | ||
106 | const struct stmpe_keypad_variant *variant; | ||
107 | const struct stmpe_keypad_platform_data *plat; | ||
108 | |||
109 | unsigned int rows; | ||
110 | unsigned int cols; | ||
111 | |||
112 | unsigned short keymap[STMPE_KEYPAD_KEYMAP_SIZE]; | ||
113 | }; | ||
114 | |||
115 | static int stmpe_keypad_read_data(struct stmpe_keypad *keypad, u8 *data) | ||
116 | { | ||
117 | const struct stmpe_keypad_variant *variant = keypad->variant; | ||
118 | struct stmpe *stmpe = keypad->stmpe; | ||
119 | int ret; | ||
120 | int i; | ||
121 | |||
122 | if (variant->auto_increment) | ||
123 | return stmpe_block_read(stmpe, STMPE_KPC_DATA_BYTE0, | ||
124 | variant->num_data, data); | ||
125 | |||
126 | for (i = 0; i < variant->num_data; i++) { | ||
127 | ret = stmpe_reg_read(stmpe, STMPE_KPC_DATA_BYTE0 + i); | ||
128 | if (ret < 0) | ||
129 | return ret; | ||
130 | |||
131 | data[i] = ret; | ||
132 | } | ||
133 | |||
134 | return 0; | ||
135 | } | ||
136 | |||
137 | static irqreturn_t stmpe_keypad_irq(int irq, void *dev) | ||
138 | { | ||
139 | struct stmpe_keypad *keypad = dev; | ||
140 | struct input_dev *input = keypad->input; | ||
141 | const struct stmpe_keypad_variant *variant = keypad->variant; | ||
142 | u8 fifo[variant->num_data]; | ||
143 | int ret; | ||
144 | int i; | ||
145 | |||
146 | ret = stmpe_keypad_read_data(keypad, fifo); | ||
147 | if (ret < 0) | ||
148 | return IRQ_NONE; | ||
149 | |||
150 | for (i = 0; i < variant->num_normal_data; i++) { | ||
151 | u8 data = fifo[i]; | ||
152 | int row = (data & STMPE_KPC_DATA_ROW) >> 3; | ||
153 | int col = data & STMPE_KPC_DATA_COL; | ||
154 | int code = MATRIX_SCAN_CODE(row, col, STMPE_KEYPAD_ROW_SHIFT); | ||
155 | bool up = data & STMPE_KPC_DATA_UP; | ||
156 | |||
157 | if ((data & STMPE_KPC_DATA_NOKEY_MASK) | ||
158 | == STMPE_KPC_DATA_NOKEY_MASK) | ||
159 | continue; | ||
160 | |||
161 | input_event(input, EV_MSC, MSC_SCAN, code); | ||
162 | input_report_key(input, keypad->keymap[code], !up); | ||
163 | input_sync(input); | ||
164 | } | ||
165 | |||
166 | return IRQ_HANDLED; | ||
167 | } | ||
168 | |||
169 | static int __devinit stmpe_keypad_altfunc_init(struct stmpe_keypad *keypad) | ||
170 | { | ||
171 | const struct stmpe_keypad_variant *variant = keypad->variant; | ||
172 | unsigned int col_gpios = variant->col_gpios; | ||
173 | unsigned int row_gpios = variant->row_gpios; | ||
174 | struct stmpe *stmpe = keypad->stmpe; | ||
175 | unsigned int pins = 0; | ||
176 | int i; | ||
177 | |||
178 | /* | ||
179 | * Figure out which pins need to be set to the keypad alternate | ||
180 | * function. | ||
181 | * | ||
182 | * {cols,rows}_gpios are bitmasks of which pins on the chip can be used | ||
183 | * for the keypad. | ||
184 | * | ||
185 | * keypad->{cols,rows} are a bitmask of which pins (of the ones useable | ||
186 | * for the keypad) are used on the board. | ||
187 | */ | ||
188 | |||
189 | for (i = 0; i < variant->max_cols; i++) { | ||
190 | int num = __ffs(col_gpios); | ||
191 | |||
192 | if (keypad->cols & (1 << i)) | ||
193 | pins |= 1 << num; | ||
194 | |||
195 | col_gpios &= ~(1 << num); | ||
196 | } | ||
197 | |||
198 | for (i = 0; i < variant->max_rows; i++) { | ||
199 | int num = __ffs(row_gpios); | ||
200 | |||
201 | if (keypad->rows & (1 << i)) | ||
202 | pins |= 1 << num; | ||
203 | |||
204 | row_gpios &= ~(1 << num); | ||
205 | } | ||
206 | |||
207 | return stmpe_set_altfunc(stmpe, pins, STMPE_BLOCK_KEYPAD); | ||
208 | } | ||
209 | |||
210 | static int __devinit stmpe_keypad_chip_init(struct stmpe_keypad *keypad) | ||
211 | { | ||
212 | const struct stmpe_keypad_platform_data *plat = keypad->plat; | ||
213 | const struct stmpe_keypad_variant *variant = keypad->variant; | ||
214 | struct stmpe *stmpe = keypad->stmpe; | ||
215 | int ret; | ||
216 | |||
217 | if (plat->debounce_ms > STMPE_KEYPAD_MAX_DEBOUNCE) | ||
218 | return -EINVAL; | ||
219 | |||
220 | if (plat->scan_count > STMPE_KEYPAD_MAX_SCAN_COUNT) | ||
221 | return -EINVAL; | ||
222 | |||
223 | ret = stmpe_enable(stmpe, STMPE_BLOCK_KEYPAD); | ||
224 | if (ret < 0) | ||
225 | return ret; | ||
226 | |||
227 | ret = stmpe_keypad_altfunc_init(keypad); | ||
228 | if (ret < 0) | ||
229 | return ret; | ||
230 | |||
231 | ret = stmpe_reg_write(stmpe, STMPE_KPC_COL, keypad->cols); | ||
232 | if (ret < 0) | ||
233 | return ret; | ||
234 | |||
235 | ret = stmpe_reg_write(stmpe, STMPE_KPC_ROW_LSB, keypad->rows); | ||
236 | if (ret < 0) | ||
237 | return ret; | ||
238 | |||
239 | if (variant->max_rows > 8) { | ||
240 | ret = stmpe_set_bits(stmpe, STMPE_KPC_ROW_MSB, | ||
241 | STMPE_KPC_ROW_MSB_ROWS, | ||
242 | keypad->rows >> 8); | ||
243 | if (ret < 0) | ||
244 | return ret; | ||
245 | } | ||
246 | |||
247 | ret = stmpe_set_bits(stmpe, STMPE_KPC_CTRL_MSB, | ||
248 | STMPE_KPC_CTRL_MSB_SCAN_COUNT, | ||
249 | plat->scan_count << 4); | ||
250 | if (ret < 0) | ||
251 | return ret; | ||
252 | |||
253 | return stmpe_set_bits(stmpe, STMPE_KPC_CTRL_LSB, | ||
254 | STMPE_KPC_CTRL_LSB_SCAN | | ||
255 | STMPE_KPC_CTRL_LSB_DEBOUNCE, | ||
256 | STMPE_KPC_CTRL_LSB_SCAN | | ||
257 | (plat->debounce_ms << 1)); | ||
258 | } | ||
259 | |||
260 | static int __devinit stmpe_keypad_probe(struct platform_device *pdev) | ||
261 | { | ||
262 | struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent); | ||
263 | struct stmpe_keypad_platform_data *plat; | ||
264 | struct stmpe_keypad *keypad; | ||
265 | struct input_dev *input; | ||
266 | int ret; | ||
267 | int irq; | ||
268 | int i; | ||
269 | |||
270 | plat = stmpe->pdata->keypad; | ||
271 | if (!plat) | ||
272 | return -ENODEV; | ||
273 | |||
274 | irq = platform_get_irq(pdev, 0); | ||
275 | if (irq < 0) | ||
276 | return irq; | ||
277 | |||
278 | keypad = kzalloc(sizeof(struct stmpe_keypad), GFP_KERNEL); | ||
279 | if (!keypad) | ||
280 | return -ENOMEM; | ||
281 | |||
282 | input = input_allocate_device(); | ||
283 | if (!input) { | ||
284 | ret = -ENOMEM; | ||
285 | goto out_freekeypad; | ||
286 | } | ||
287 | |||
288 | input->name = "STMPE keypad"; | ||
289 | input->id.bustype = BUS_I2C; | ||
290 | input->dev.parent = &pdev->dev; | ||
291 | |||
292 | input_set_capability(input, EV_MSC, MSC_SCAN); | ||
293 | |||
294 | __set_bit(EV_KEY, input->evbit); | ||
295 | if (!plat->no_autorepeat) | ||
296 | __set_bit(EV_REP, input->evbit); | ||
297 | |||
298 | input->keycode = keypad->keymap; | ||
299 | input->keycodesize = sizeof(keypad->keymap[0]); | ||
300 | input->keycodemax = ARRAY_SIZE(keypad->keymap); | ||
301 | |||
302 | matrix_keypad_build_keymap(plat->keymap_data, STMPE_KEYPAD_ROW_SHIFT, | ||
303 | input->keycode, input->keybit); | ||
304 | |||
305 | for (i = 0; i < plat->keymap_data->keymap_size; i++) { | ||
306 | unsigned int key = plat->keymap_data->keymap[i]; | ||
307 | |||
308 | keypad->cols |= 1 << KEY_COL(key); | ||
309 | keypad->rows |= 1 << KEY_ROW(key); | ||
310 | } | ||
311 | |||
312 | keypad->stmpe = stmpe; | ||
313 | keypad->plat = plat; | ||
314 | keypad->input = input; | ||
315 | keypad->variant = &stmpe_keypad_variants[stmpe->partnum]; | ||
316 | |||
317 | ret = stmpe_keypad_chip_init(keypad); | ||
318 | if (ret < 0) | ||
319 | goto out_freeinput; | ||
320 | |||
321 | ret = input_register_device(input); | ||
322 | if (ret) { | ||
323 | dev_err(&pdev->dev, | ||
324 | "unable to register input device: %d\n", ret); | ||
325 | goto out_freeinput; | ||
326 | } | ||
327 | |||
328 | ret = request_threaded_irq(irq, NULL, stmpe_keypad_irq, IRQF_ONESHOT, | ||
329 | "stmpe-keypad", keypad); | ||
330 | if (ret) { | ||
331 | dev_err(&pdev->dev, "unable to get irq: %d\n", ret); | ||
332 | goto out_unregisterinput; | ||
333 | } | ||
334 | |||
335 | platform_set_drvdata(pdev, keypad); | ||
336 | |||
337 | return 0; | ||
338 | |||
339 | out_unregisterinput: | ||
340 | input_unregister_device(input); | ||
341 | input = NULL; | ||
342 | out_freeinput: | ||
343 | input_free_device(input); | ||
344 | out_freekeypad: | ||
345 | kfree(keypad); | ||
346 | return ret; | ||
347 | } | ||
348 | |||
349 | static int __devexit stmpe_keypad_remove(struct platform_device *pdev) | ||
350 | { | ||
351 | struct stmpe_keypad *keypad = platform_get_drvdata(pdev); | ||
352 | struct stmpe *stmpe = keypad->stmpe; | ||
353 | int irq = platform_get_irq(pdev, 0); | ||
354 | |||
355 | stmpe_disable(stmpe, STMPE_BLOCK_KEYPAD); | ||
356 | |||
357 | free_irq(irq, keypad); | ||
358 | input_unregister_device(keypad->input); | ||
359 | platform_set_drvdata(pdev, NULL); | ||
360 | kfree(keypad); | ||
361 | |||
362 | return 0; | ||
363 | } | ||
364 | |||
365 | static struct platform_driver stmpe_keypad_driver = { | ||
366 | .driver.name = "stmpe-keypad", | ||
367 | .driver.owner = THIS_MODULE, | ||
368 | .probe = stmpe_keypad_probe, | ||
369 | .remove = __devexit_p(stmpe_keypad_remove), | ||
370 | }; | ||
371 | |||
372 | static int __init stmpe_keypad_init(void) | ||
373 | { | ||
374 | return platform_driver_register(&stmpe_keypad_driver); | ||
375 | } | ||
376 | module_init(stmpe_keypad_init); | ||
377 | |||
378 | static void __exit stmpe_keypad_exit(void) | ||
379 | { | ||
380 | platform_driver_unregister(&stmpe_keypad_driver); | ||
381 | } | ||
382 | module_exit(stmpe_keypad_exit); | ||
383 | |||
384 | MODULE_LICENSE("GPL v2"); | ||
385 | MODULE_DESCRIPTION("STMPExxxx keypad driver"); | ||
386 | MODULE_AUTHOR("Rabin Vincent <rabin.vincent@stericsson.com>"); | ||
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig index 61f35184f76..0069d9703fd 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig | |||
@@ -628,4 +628,14 @@ config TOUCHSCREEN_TPS6507X | |||
628 | To compile this driver as a module, choose M here: the | 628 | To compile this driver as a module, choose M here: the |
629 | module will be called tps6507x_ts. | 629 | module will be called tps6507x_ts. |
630 | 630 | ||
631 | config TOUCHSCREEN_STMPE | ||
632 | tristate "STMicroelectronics STMPE touchscreens" | ||
633 | depends on MFD_STMPE | ||
634 | help | ||
635 | Say Y here if you want support for STMicroelectronics | ||
636 | STMPE touchscreen controllers. | ||
637 | |||
638 | To compile this driver as a module, choose M here: the | ||
639 | module will be called stmpe-ts. | ||
640 | |||
631 | endif | 641 | endif |
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile index bd6f30b4ff7..28217e1dcaf 100644 --- a/drivers/input/touchscreen/Makefile +++ b/drivers/input/touchscreen/Makefile | |||
@@ -36,6 +36,7 @@ obj-$(CONFIG_TOUCHSCREEN_PCAP) += pcap_ts.o | |||
36 | obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o | 36 | obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o |
37 | obj-$(CONFIG_TOUCHSCREEN_QT602240) += qt602240_ts.o | 37 | obj-$(CONFIG_TOUCHSCREEN_QT602240) += qt602240_ts.o |
38 | obj-$(CONFIG_TOUCHSCREEN_S3C2410) += s3c2410_ts.o | 38 | obj-$(CONFIG_TOUCHSCREEN_S3C2410) += s3c2410_ts.o |
39 | obj-$(CONFIG_TOUCHSCREEN_STMPE) += stmpe-ts.o | ||
39 | obj-$(CONFIG_TOUCHSCREEN_TOUCHIT213) += touchit213.o | 40 | obj-$(CONFIG_TOUCHSCREEN_TOUCHIT213) += touchit213.o |
40 | obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o | 41 | obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o |
41 | obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o | 42 | obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o |
diff --git a/drivers/input/touchscreen/stmpe-ts.c b/drivers/input/touchscreen/stmpe-ts.c new file mode 100644 index 00000000000..656148ec002 --- /dev/null +++ b/drivers/input/touchscreen/stmpe-ts.c | |||
@@ -0,0 +1,397 @@ | |||
1 | /* STMicroelectronics STMPE811 Touchscreen Driver | ||
2 | * | ||
3 | * (C) 2010 Luotao Fu <l.fu@pengutronix.de> | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms of the GNU General Public License as published by the | ||
8 | * Free Software Foundation; either version 2 of the License, or (at your | ||
9 | * option) any later version. | ||
10 | * | ||
11 | */ | ||
12 | |||
13 | #include <linux/kernel.h> | ||
14 | #include <linux/module.h> | ||
15 | #include <linux/sched.h> | ||
16 | #include <linux/interrupt.h> | ||
17 | #include <linux/init.h> | ||
18 | #include <linux/device.h> | ||
19 | #include <linux/platform_device.h> | ||
20 | #include <linux/input.h> | ||
21 | #include <linux/slab.h> | ||
22 | #include <linux/delay.h> | ||
23 | #include <linux/i2c.h> | ||
24 | #include <linux/workqueue.h> | ||
25 | |||
26 | #include <linux/mfd/stmpe.h> | ||
27 | |||
28 | /* Register layouts and functionalities are identical on all stmpexxx variants | ||
29 | * with touchscreen controller | ||
30 | */ | ||
31 | #define STMPE_REG_INT_STA 0x0B | ||
32 | #define STMPE_REG_ADC_CTRL1 0x20 | ||
33 | #define STMPE_REG_ADC_CTRL2 0x21 | ||
34 | #define STMPE_REG_TSC_CTRL 0x40 | ||
35 | #define STMPE_REG_TSC_CFG 0x41 | ||
36 | #define STMPE_REG_FIFO_TH 0x4A | ||
37 | #define STMPE_REG_FIFO_STA 0x4B | ||
38 | #define STMPE_REG_FIFO_SIZE 0x4C | ||
39 | #define STMPE_REG_TSC_DATA_XYZ 0x52 | ||
40 | #define STMPE_REG_TSC_FRACTION_Z 0x56 | ||
41 | #define STMPE_REG_TSC_I_DRIVE 0x58 | ||
42 | |||
43 | #define OP_MOD_XYZ 0 | ||
44 | |||
45 | #define STMPE_TSC_CTRL_TSC_EN (1<<0) | ||
46 | |||
47 | #define STMPE_FIFO_STA_RESET (1<<0) | ||
48 | |||
49 | #define STMPE_IRQ_TOUCH_DET 0 | ||
50 | |||
51 | #define SAMPLE_TIME(x) ((x & 0xf) << 4) | ||
52 | #define MOD_12B(x) ((x & 0x1) << 3) | ||
53 | #define REF_SEL(x) ((x & 0x1) << 1) | ||
54 | #define ADC_FREQ(x) (x & 0x3) | ||
55 | #define AVE_CTRL(x) ((x & 0x3) << 6) | ||
56 | #define DET_DELAY(x) ((x & 0x7) << 3) | ||
57 | #define SETTLING(x) (x & 0x7) | ||
58 | #define FRACTION_Z(x) (x & 0x7) | ||
59 | #define I_DRIVE(x) (x & 0x1) | ||
60 | #define OP_MODE(x) ((x & 0x7) << 1) | ||
61 | |||
62 | #define STMPE_TS_NAME "stmpe-ts" | ||
63 | #define XY_MASK 0xfff | ||
64 | |||
65 | struct stmpe_touch { | ||
66 | struct stmpe *stmpe; | ||
67 | struct input_dev *idev; | ||
68 | struct delayed_work work; | ||
69 | struct device *dev; | ||
70 | u8 sample_time; | ||
71 | u8 mod_12b; | ||
72 | u8 ref_sel; | ||
73 | u8 adc_freq; | ||
74 | u8 ave_ctrl; | ||
75 | u8 touch_det_delay; | ||
76 | u8 settling; | ||
77 | u8 fraction_z; | ||
78 | u8 i_drive; | ||
79 | }; | ||
80 | |||
81 | static int __stmpe_reset_fifo(struct stmpe *stmpe) | ||
82 | { | ||
83 | int ret; | ||
84 | |||
85 | ret = stmpe_set_bits(stmpe, STMPE_REG_FIFO_STA, | ||
86 | STMPE_FIFO_STA_RESET, STMPE_FIFO_STA_RESET); | ||
87 | if (ret) | ||
88 | return ret; | ||
89 | |||
90 | return stmpe_set_bits(stmpe, STMPE_REG_FIFO_STA, | ||
91 | STMPE_FIFO_STA_RESET, 0); | ||
92 | } | ||
93 | |||
94 | static void stmpe_work(struct work_struct *work) | ||
95 | { | ||
96 | int int_sta; | ||
97 | u32 timeout = 40; | ||
98 | |||
99 | struct stmpe_touch *ts = | ||
100 | container_of(work, struct stmpe_touch, work.work); | ||
101 | |||
102 | int_sta = stmpe_reg_read(ts->stmpe, STMPE_REG_INT_STA); | ||
103 | |||
104 | /* | ||
105 | * touch_det sometimes get desasserted or just get stuck. This appears | ||
106 | * to be a silicon bug, We still have to clearify this with the | ||
107 | * manufacture. As a workaround We release the key anyway if the | ||
108 | * touch_det keeps coming in after 4ms, while the FIFO contains no value | ||
109 | * during the whole time. | ||
110 | */ | ||
111 | while ((int_sta & (1 << STMPE_IRQ_TOUCH_DET)) && (timeout > 0)) { | ||
112 | timeout--; | ||
113 | int_sta = stmpe_reg_read(ts->stmpe, STMPE_REG_INT_STA); | ||
114 | udelay(100); | ||
115 | } | ||
116 | |||
117 | /* reset the FIFO before we report release event */ | ||
118 | __stmpe_reset_fifo(ts->stmpe); | ||
119 | |||
120 | input_report_abs(ts->idev, ABS_PRESSURE, 0); | ||
121 | input_sync(ts->idev); | ||
122 | } | ||
123 | |||
124 | static irqreturn_t stmpe_ts_handler(int irq, void *data) | ||
125 | { | ||
126 | u8 data_set[4]; | ||
127 | int x, y, z; | ||
128 | struct stmpe_touch *ts = data; | ||
129 | |||
130 | /* | ||
131 | * Cancel scheduled polling for release if we have new value | ||
132 | * available. Wait if the polling is already running. | ||
133 | */ | ||
134 | cancel_delayed_work_sync(&ts->work); | ||
135 | |||
136 | /* | ||
137 | * The FIFO sometimes just crashes and stops generating interrupts. This | ||
138 | * appears to be a silicon bug. We still have to clearify this with | ||
139 | * the manufacture. As a workaround we disable the TSC while we are | ||
140 | * collecting data and flush the FIFO after reading | ||
141 | */ | ||
142 | stmpe_set_bits(ts->stmpe, STMPE_REG_TSC_CTRL, | ||
143 | STMPE_TSC_CTRL_TSC_EN, 0); | ||
144 | |||
145 | stmpe_block_read(ts->stmpe, STMPE_REG_TSC_DATA_XYZ, 4, data_set); | ||
146 | |||
147 | x = (data_set[0] << 4) | (data_set[1] >> 4); | ||
148 | y = ((data_set[1] & 0xf) << 8) | data_set[2]; | ||
149 | z = data_set[3]; | ||
150 | |||
151 | input_report_abs(ts->idev, ABS_X, x); | ||
152 | input_report_abs(ts->idev, ABS_Y, y); | ||
153 | input_report_abs(ts->idev, ABS_PRESSURE, z); | ||
154 | input_sync(ts->idev); | ||
155 | |||
156 | /* flush the FIFO after we have read out our values. */ | ||
157 | __stmpe_reset_fifo(ts->stmpe); | ||
158 | |||
159 | /* reenable the tsc */ | ||
160 | stmpe_set_bits(ts->stmpe, STMPE_REG_TSC_CTRL, | ||
161 | STMPE_TSC_CTRL_TSC_EN, STMPE_TSC_CTRL_TSC_EN); | ||
162 | |||
163 | /* start polling for touch_det to detect release */ | ||
164 | schedule_delayed_work(&ts->work, HZ / 50); | ||
165 | |||
166 | return IRQ_HANDLED; | ||
167 | } | ||
168 | |||
169 | static int __devinit stmpe_init_hw(struct stmpe_touch *ts) | ||
170 | { | ||
171 | int ret; | ||
172 | u8 adc_ctrl1, adc_ctrl1_mask, tsc_cfg, tsc_cfg_mask; | ||
173 | struct stmpe *stmpe = ts->stmpe; | ||
174 | struct device *dev = ts->dev; | ||
175 | |||
176 | ret = stmpe_enable(stmpe, STMPE_BLOCK_TOUCHSCREEN | STMPE_BLOCK_ADC); | ||
177 | if (ret) { | ||
178 | dev_err(dev, "Could not enable clock for ADC and TS\n"); | ||
179 | return ret; | ||
180 | } | ||
181 | |||
182 | adc_ctrl1 = SAMPLE_TIME(ts->sample_time) | MOD_12B(ts->mod_12b) | | ||
183 | REF_SEL(ts->ref_sel); | ||
184 | adc_ctrl1_mask = SAMPLE_TIME(0xff) | MOD_12B(0xff) | REF_SEL(0xff); | ||
185 | |||
186 | ret = stmpe_set_bits(stmpe, STMPE_REG_ADC_CTRL1, | ||
187 | adc_ctrl1_mask, adc_ctrl1); | ||
188 | if (ret) { | ||
189 | dev_err(dev, "Could not setup ADC\n"); | ||
190 | return ret; | ||
191 | } | ||
192 | |||
193 | ret = stmpe_set_bits(stmpe, STMPE_REG_ADC_CTRL2, | ||
194 | ADC_FREQ(0xff), ADC_FREQ(ts->adc_freq)); | ||
195 | if (ret) { | ||
196 | dev_err(dev, "Could not setup ADC\n"); | ||
197 | return ret; | ||
198 | } | ||
199 | |||
200 | tsc_cfg = AVE_CTRL(ts->ave_ctrl) | DET_DELAY(ts->touch_det_delay) | | ||
201 | SETTLING(ts->settling); | ||
202 | tsc_cfg_mask = AVE_CTRL(0xff) | DET_DELAY(0xff) | SETTLING(0xff); | ||
203 | |||
204 | ret = stmpe_set_bits(stmpe, STMPE_REG_TSC_CFG, tsc_cfg_mask, tsc_cfg); | ||
205 | if (ret) { | ||
206 | dev_err(dev, "Could not config touch\n"); | ||
207 | return ret; | ||
208 | } | ||
209 | |||
210 | ret = stmpe_set_bits(stmpe, STMPE_REG_TSC_FRACTION_Z, | ||
211 | FRACTION_Z(0xff), FRACTION_Z(ts->fraction_z)); | ||
212 | if (ret) { | ||
213 | dev_err(dev, "Could not config touch\n"); | ||
214 | return ret; | ||
215 | } | ||
216 | |||
217 | ret = stmpe_set_bits(stmpe, STMPE_REG_TSC_I_DRIVE, | ||
218 | I_DRIVE(0xff), I_DRIVE(ts->i_drive)); | ||
219 | if (ret) { | ||
220 | dev_err(dev, "Could not config touch\n"); | ||
221 | return ret; | ||
222 | } | ||
223 | |||
224 | /* set FIFO to 1 for single point reading */ | ||
225 | ret = stmpe_reg_write(stmpe, STMPE_REG_FIFO_TH, 1); | ||
226 | if (ret) { | ||
227 | dev_err(dev, "Could not set FIFO\n"); | ||
228 | return ret; | ||
229 | } | ||
230 | |||
231 | ret = stmpe_set_bits(stmpe, STMPE_REG_TSC_CTRL, | ||
232 | OP_MODE(0xff), OP_MODE(OP_MOD_XYZ)); | ||
233 | if (ret) { | ||
234 | dev_err(dev, "Could not set mode\n"); | ||
235 | return ret; | ||
236 | } | ||
237 | |||
238 | return 0; | ||
239 | } | ||
240 | |||
241 | static int stmpe_ts_open(struct input_dev *dev) | ||
242 | { | ||
243 | struct stmpe_touch *ts = input_get_drvdata(dev); | ||
244 | int ret = 0; | ||
245 | |||
246 | ret = __stmpe_reset_fifo(ts->stmpe); | ||
247 | if (ret) | ||
248 | return ret; | ||
249 | |||
250 | return stmpe_set_bits(ts->stmpe, STMPE_REG_TSC_CTRL, | ||
251 | STMPE_TSC_CTRL_TSC_EN, STMPE_TSC_CTRL_TSC_EN); | ||
252 | } | ||
253 | |||
254 | static void stmpe_ts_close(struct input_dev *dev) | ||
255 | { | ||
256 | struct stmpe_touch *ts = input_get_drvdata(dev); | ||
257 | |||
258 | cancel_delayed_work_sync(&ts->work); | ||
259 | |||
260 | stmpe_set_bits(ts->stmpe, STMPE_REG_TSC_CTRL, | ||
261 | STMPE_TSC_CTRL_TSC_EN, 0); | ||
262 | } | ||
263 | |||
264 | static int __devinit stmpe_input_probe(struct platform_device *pdev) | ||
265 | { | ||
266 | struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent); | ||
267 | struct stmpe_platform_data *pdata = stmpe->pdata; | ||
268 | struct stmpe_touch *ts; | ||
269 | struct input_dev *idev; | ||
270 | struct stmpe_ts_platform_data *ts_pdata = NULL; | ||
271 | int ret = 0; | ||
272 | int ts_irq; | ||
273 | |||
274 | ts_irq = platform_get_irq_byname(pdev, "FIFO_TH"); | ||
275 | if (ts_irq < 0) | ||
276 | return ts_irq; | ||
277 | |||
278 | ts = kzalloc(sizeof(*ts), GFP_KERNEL); | ||
279 | if (!ts) | ||
280 | goto err_out; | ||
281 | |||
282 | idev = input_allocate_device(); | ||
283 | if (!idev) | ||
284 | goto err_free_ts; | ||
285 | |||
286 | platform_set_drvdata(pdev, ts); | ||
287 | ts->stmpe = stmpe; | ||
288 | ts->idev = idev; | ||
289 | ts->dev = &pdev->dev; | ||
290 | |||
291 | if (pdata) | ||
292 | ts_pdata = pdata->ts; | ||
293 | |||
294 | if (ts_pdata) { | ||
295 | ts->sample_time = ts_pdata->sample_time; | ||
296 | ts->mod_12b = ts_pdata->mod_12b; | ||
297 | ts->ref_sel = ts_pdata->ref_sel; | ||
298 | ts->adc_freq = ts_pdata->adc_freq; | ||
299 | ts->ave_ctrl = ts_pdata->ave_ctrl; | ||
300 | ts->touch_det_delay = ts_pdata->touch_det_delay; | ||
301 | ts->settling = ts_pdata->settling; | ||
302 | ts->fraction_z = ts_pdata->fraction_z; | ||
303 | ts->i_drive = ts_pdata->i_drive; | ||
304 | } | ||
305 | |||
306 | INIT_DELAYED_WORK(&ts->work, stmpe_work); | ||
307 | |||
308 | ret = request_threaded_irq(ts_irq, NULL, stmpe_ts_handler, | ||
309 | IRQF_ONESHOT, STMPE_TS_NAME, ts); | ||
310 | if (ret) { | ||
311 | dev_err(&pdev->dev, "Failed to request IRQ %d\n", ts_irq); | ||
312 | goto err_free_input; | ||
313 | } | ||
314 | |||
315 | ret = stmpe_init_hw(ts); | ||
316 | if (ret) | ||
317 | goto err_free_irq; | ||
318 | |||
319 | idev->name = STMPE_TS_NAME; | ||
320 | idev->id.bustype = BUS_I2C; | ||
321 | idev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); | ||
322 | idev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); | ||
323 | |||
324 | idev->open = stmpe_ts_open; | ||
325 | idev->close = stmpe_ts_close; | ||
326 | |||
327 | input_set_drvdata(idev, ts); | ||
328 | |||
329 | input_set_abs_params(idev, ABS_X, 0, XY_MASK, 0, 0); | ||
330 | input_set_abs_params(idev, ABS_Y, 0, XY_MASK, 0, 0); | ||
331 | input_set_abs_params(idev, ABS_PRESSURE, 0x0, 0xff, 0, 0); | ||
332 | |||
333 | ret = input_register_device(idev); | ||
334 | if (ret) { | ||
335 | dev_err(&pdev->dev, "Could not register input device\n"); | ||
336 | goto err_free_irq; | ||
337 | } | ||
338 | |||
339 | return ret; | ||
340 | |||
341 | err_free_irq: | ||
342 | free_irq(ts_irq, ts); | ||
343 | err_free_input: | ||
344 | input_free_device(idev); | ||
345 | platform_set_drvdata(pdev, NULL); | ||
346 | err_free_ts: | ||
347 | kfree(ts); | ||
348 | err_out: | ||
349 | return ret; | ||
350 | } | ||
351 | |||
352 | static int __devexit stmpe_ts_remove(struct platform_device *pdev) | ||
353 | { | ||
354 | struct stmpe_touch *ts = platform_get_drvdata(pdev); | ||
355 | unsigned int ts_irq = platform_get_irq_byname(pdev, "FIFO_TH"); | ||
356 | |||
357 | stmpe_disable(ts->stmpe, STMPE_BLOCK_TOUCHSCREEN); | ||
358 | |||
359 | free_irq(ts_irq, ts); | ||
360 | |||
361 | platform_set_drvdata(pdev, NULL); | ||
362 | |||
363 | input_unregister_device(ts->idev); | ||
364 | input_free_device(ts->idev); | ||
365 | |||
366 | kfree(ts); | ||
367 | |||
368 | return 0; | ||
369 | } | ||
370 | |||
371 | static struct platform_driver stmpe_ts_driver = { | ||
372 | .driver = { | ||
373 | .name = STMPE_TS_NAME, | ||
374 | .owner = THIS_MODULE, | ||
375 | }, | ||
376 | .probe = stmpe_input_probe, | ||
377 | .remove = __devexit_p(stmpe_ts_remove), | ||
378 | }; | ||
379 | |||
380 | static int __init stmpe_ts_init(void) | ||
381 | { | ||
382 | return platform_driver_register(&stmpe_ts_driver); | ||
383 | } | ||
384 | |||
385 | module_init(stmpe_ts_init); | ||
386 | |||
387 | static void __exit stmpe_ts_exit(void) | ||
388 | { | ||
389 | platform_driver_unregister(&stmpe_ts_driver); | ||
390 | } | ||
391 | |||
392 | module_exit(stmpe_ts_exit); | ||
393 | |||
394 | MODULE_AUTHOR("Luotao Fu <l.fu@pengutronix.de>"); | ||
395 | MODULE_DESCRIPTION("STMPEXXX touchscreen driver"); | ||
396 | MODULE_LICENSE("GPL"); | ||
397 | MODULE_ALIAS("platform:" STMPE_TS_NAME); | ||