diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2010-10-25 13:59:31 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-10-25 13:59:31 -0400 |
commit | 72e58063d63c5f0a7bf65312f1e3a5ed9bb5c2ff (patch) | |
tree | df5c21244d46aacef47e6b7fff3ad02c3612b15c /drivers/input | |
parent | 57c155d51e2f3d7411eeac5e7fd7634d2d1f6b4f (diff) | |
parent | 489e176c71f36654dcb8835926f7e5717b8b4c19 (diff) |
Merge branch 'davinci-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/khilman/linux-davinci
* 'davinci-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/khilman/linux-davinci: (50 commits)
davinci: fix remaining board support after io_pgoffst removal
davinci: mityomapl138: make file local data static
arm/davinci: remove duplicated include
davinci: Initial support for Omapl138-Hawkboard
davinci: MityDSP-L138/MityARM-1808 read MAC address from I2C Prom
davinci: add tnetv107x touchscreen platform device
input: add driver for tnetv107x touchscreen controller
davinci: add keypad config for tnetv107x evm board
davinci: add tnetv107x keypad platform device
input: add driver for tnetv107x on-chip keypad controller
net: davinci_emac: cleanup unused cpdma code
net: davinci_emac: switch to new cpdma layer
net: davinci_emac: separate out cpdma code
net: davinci_emac: cleanup unused mdio emac code
omap: cleanup unused davinci mdio arch code
davinci: cleanup mdio arch code and switch to phy_id
net: davinci_emac: switch to new mdio
omap: add mdio platform devices
davinci: add mdio platform devices
net: davinci_emac: separate out davinci mdio
...
Fix up trivial conflict in drivers/input/keyboard/Kconfig (two entries
added next to each other - one from the davinci merge, one from the
input merge)
Diffstat (limited to 'drivers/input')
-rw-r--r-- | drivers/input/keyboard/Kconfig | 9 | ||||
-rw-r--r-- | drivers/input/keyboard/Makefile | 1 | ||||
-rw-r--r-- | drivers/input/keyboard/tnetv107x-keypad.c | 340 | ||||
-rw-r--r-- | drivers/input/touchscreen/Kconfig | 9 | ||||
-rw-r--r-- | drivers/input/touchscreen/Makefile | 1 | ||||
-rw-r--r-- | drivers/input/touchscreen/tnetv107x-ts.c | 396 |
6 files changed, 756 insertions, 0 deletions
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig index 0426630f0e98..b8c51b9781db 100644 --- a/drivers/input/keyboard/Kconfig +++ b/drivers/input/keyboard/Kconfig | |||
@@ -443,6 +443,15 @@ config KEYBOARD_OMAP4 | |||
443 | To compile this driver as a module, choose M here: the | 443 | To compile this driver as a module, choose M here: the |
444 | module will be called omap4-keypad. | 444 | module will be called omap4-keypad. |
445 | 445 | ||
446 | config KEYBOARD_TNETV107X | ||
447 | tristate "TI TNETV107X keypad support" | ||
448 | depends on ARCH_DAVINCI_TNETV107X | ||
449 | help | ||
450 | Say Y here if you want to use the TNETV107X keypad. | ||
451 | |||
452 | To compile this driver as a module, choose M here: the | ||
453 | module will be called tnetv107x-keypad. | ||
454 | |||
446 | config KEYBOARD_TWL4030 | 455 | config KEYBOARD_TWL4030 |
447 | tristate "TI TWL4030/TWL5030/TPS659x0 keypad support" | 456 | tristate "TI TWL4030/TWL5030/TPS659x0 keypad support" |
448 | depends on TWL4030_CORE | 457 | depends on TWL4030_CORE |
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile index c13809c5c3a7..a34452e8ebe2 100644 --- a/drivers/input/keyboard/Makefile +++ b/drivers/input/keyboard/Makefile | |||
@@ -40,6 +40,7 @@ obj-$(CONFIG_KEYBOARD_SH_KEYSC) += sh_keysc.o | |||
40 | obj-$(CONFIG_KEYBOARD_STMPE) += stmpe-keypad.o | 40 | obj-$(CONFIG_KEYBOARD_STMPE) += stmpe-keypad.o |
41 | obj-$(CONFIG_KEYBOARD_STOWAWAY) += stowaway.o | 41 | obj-$(CONFIG_KEYBOARD_STOWAWAY) += stowaway.o |
42 | obj-$(CONFIG_KEYBOARD_SUNKBD) += sunkbd.o | 42 | obj-$(CONFIG_KEYBOARD_SUNKBD) += sunkbd.o |
43 | obj-$(CONFIG_KEYBOARD_TNETV107X) += tnetv107x-keypad.o | ||
43 | obj-$(CONFIG_KEYBOARD_TWL4030) += twl4030_keypad.o | 44 | obj-$(CONFIG_KEYBOARD_TWL4030) += twl4030_keypad.o |
44 | obj-$(CONFIG_KEYBOARD_XTKBD) += xtkbd.o | 45 | obj-$(CONFIG_KEYBOARD_XTKBD) += xtkbd.o |
45 | obj-$(CONFIG_KEYBOARD_W90P910) += w90p910_keypad.o | 46 | obj-$(CONFIG_KEYBOARD_W90P910) += w90p910_keypad.o |
diff --git a/drivers/input/keyboard/tnetv107x-keypad.c b/drivers/input/keyboard/tnetv107x-keypad.c new file mode 100644 index 000000000000..b4a81ebfab92 --- /dev/null +++ b/drivers/input/keyboard/tnetv107x-keypad.c | |||
@@ -0,0 +1,340 @@ | |||
1 | /* | ||
2 | * Texas Instruments TNETV107X Keypad Driver | ||
3 | * | ||
4 | * Copyright (C) 2010 Texas Instruments | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License as | ||
8 | * published by the Free Software Foundation version 2. | ||
9 | * | ||
10 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any | ||
11 | * kind, whether express or implied; without even the implied warranty | ||
12 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | */ | ||
15 | |||
16 | #include <linux/kernel.h> | ||
17 | #include <linux/errno.h> | ||
18 | #include <linux/input.h> | ||
19 | #include <linux/platform_device.h> | ||
20 | #include <linux/interrupt.h> | ||
21 | #include <linux/slab.h> | ||
22 | #include <linux/delay.h> | ||
23 | #include <linux/io.h> | ||
24 | #include <linux/clk.h> | ||
25 | #include <linux/input/matrix_keypad.h> | ||
26 | |||
27 | #define BITS(x) (BIT(x) - 1) | ||
28 | |||
29 | #define KEYPAD_ROWS 9 | ||
30 | #define KEYPAD_COLS 9 | ||
31 | |||
32 | #define DEBOUNCE_MIN 0x400ul | ||
33 | #define DEBOUNCE_MAX 0x3ffffffful | ||
34 | |||
35 | struct keypad_regs { | ||
36 | u32 rev; | ||
37 | u32 mode; | ||
38 | u32 mask; | ||
39 | u32 pol; | ||
40 | u32 dclock; | ||
41 | u32 rclock; | ||
42 | u32 stable_cnt; | ||
43 | u32 in_en; | ||
44 | u32 out; | ||
45 | u32 out_en; | ||
46 | u32 in; | ||
47 | u32 lock; | ||
48 | u32 pres[3]; | ||
49 | }; | ||
50 | |||
51 | #define keypad_read(kp, reg) __raw_readl(&(kp)->regs->reg) | ||
52 | #define keypad_write(kp, reg, val) __raw_writel(val, &(kp)->regs->reg) | ||
53 | |||
54 | struct keypad_data { | ||
55 | struct input_dev *input_dev; | ||
56 | struct resource *res; | ||
57 | struct keypad_regs __iomem *regs; | ||
58 | struct clk *clk; | ||
59 | struct device *dev; | ||
60 | spinlock_t lock; | ||
61 | u32 irq_press; | ||
62 | u32 irq_release; | ||
63 | int rows, cols, row_shift; | ||
64 | int debounce_ms, active_low; | ||
65 | u32 prev_keys[3]; | ||
66 | unsigned short keycodes[]; | ||
67 | }; | ||
68 | |||
69 | static irqreturn_t keypad_irq(int irq, void *data) | ||
70 | { | ||
71 | struct keypad_data *kp = data; | ||
72 | int i, bit, val, row, col, code; | ||
73 | unsigned long flags; | ||
74 | u32 curr_keys[3]; | ||
75 | u32 change; | ||
76 | |||
77 | spin_lock_irqsave(&kp->lock, flags); | ||
78 | |||
79 | memset(curr_keys, 0, sizeof(curr_keys)); | ||
80 | if (irq == kp->irq_press) | ||
81 | for (i = 0; i < 3; i++) | ||
82 | curr_keys[i] = keypad_read(kp, pres[i]); | ||
83 | |||
84 | for (i = 0; i < 3; i++) { | ||
85 | change = curr_keys[i] ^ kp->prev_keys[i]; | ||
86 | |||
87 | while (change) { | ||
88 | bit = fls(change) - 1; | ||
89 | change ^= BIT(bit); | ||
90 | val = curr_keys[i] & BIT(bit); | ||
91 | bit += i * 32; | ||
92 | row = bit / KEYPAD_COLS; | ||
93 | col = bit % KEYPAD_COLS; | ||
94 | |||
95 | code = MATRIX_SCAN_CODE(row, col, kp->row_shift); | ||
96 | input_event(kp->input_dev, EV_MSC, MSC_SCAN, code); | ||
97 | input_report_key(kp->input_dev, kp->keycodes[code], | ||
98 | val); | ||
99 | } | ||
100 | } | ||
101 | input_sync(kp->input_dev); | ||
102 | memcpy(kp->prev_keys, curr_keys, sizeof(curr_keys)); | ||
103 | |||
104 | if (irq == kp->irq_press) | ||
105 | keypad_write(kp, lock, 0); /* Allow hardware updates */ | ||
106 | |||
107 | spin_unlock_irqrestore(&kp->lock, flags); | ||
108 | |||
109 | return IRQ_HANDLED; | ||
110 | } | ||
111 | |||
112 | static int keypad_start(struct input_dev *dev) | ||
113 | { | ||
114 | struct keypad_data *kp = input_get_drvdata(dev); | ||
115 | unsigned long mask, debounce, clk_rate_khz; | ||
116 | unsigned long flags; | ||
117 | |||
118 | clk_enable(kp->clk); | ||
119 | clk_rate_khz = clk_get_rate(kp->clk) / 1000; | ||
120 | |||
121 | spin_lock_irqsave(&kp->lock, flags); | ||
122 | |||
123 | /* Initialize device registers */ | ||
124 | keypad_write(kp, mode, 0); | ||
125 | |||
126 | mask = BITS(kp->rows) << KEYPAD_COLS; | ||
127 | mask |= BITS(kp->cols); | ||
128 | keypad_write(kp, mask, ~mask); | ||
129 | |||
130 | keypad_write(kp, pol, kp->active_low ? 0 : 0x3ffff); | ||
131 | keypad_write(kp, stable_cnt, 3); | ||
132 | |||
133 | debounce = kp->debounce_ms * clk_rate_khz; | ||
134 | debounce = clamp(debounce, DEBOUNCE_MIN, DEBOUNCE_MAX); | ||
135 | keypad_write(kp, dclock, debounce); | ||
136 | keypad_write(kp, rclock, 4 * debounce); | ||
137 | |||
138 | keypad_write(kp, in_en, 1); | ||
139 | |||
140 | spin_unlock_irqrestore(&kp->lock, flags); | ||
141 | |||
142 | return 0; | ||
143 | } | ||
144 | |||
145 | static void keypad_stop(struct input_dev *dev) | ||
146 | { | ||
147 | struct keypad_data *kp = input_get_drvdata(dev); | ||
148 | |||
149 | synchronize_irq(kp->irq_press); | ||
150 | synchronize_irq(kp->irq_release); | ||
151 | clk_disable(kp->clk); | ||
152 | } | ||
153 | |||
154 | static int __devinit keypad_probe(struct platform_device *pdev) | ||
155 | { | ||
156 | const struct matrix_keypad_platform_data *pdata; | ||
157 | const struct matrix_keymap_data *keymap_data; | ||
158 | struct device *dev = &pdev->dev; | ||
159 | struct keypad_data *kp; | ||
160 | int error = 0, sz, row_shift; | ||
161 | u32 rev = 0; | ||
162 | |||
163 | pdata = pdev->dev.platform_data; | ||
164 | if (!pdata) { | ||
165 | dev_err(dev, "cannot find device data\n"); | ||
166 | return -EINVAL; | ||
167 | } | ||
168 | |||
169 | keymap_data = pdata->keymap_data; | ||
170 | if (!keymap_data) { | ||
171 | dev_err(dev, "cannot find keymap data\n"); | ||
172 | return -EINVAL; | ||
173 | } | ||
174 | |||
175 | row_shift = get_count_order(pdata->num_col_gpios); | ||
176 | sz = offsetof(struct keypad_data, keycodes); | ||
177 | sz += (pdata->num_row_gpios << row_shift) * sizeof(kp->keycodes[0]); | ||
178 | kp = kzalloc(sz, GFP_KERNEL); | ||
179 | if (!kp) { | ||
180 | dev_err(dev, "cannot allocate device info\n"); | ||
181 | return -ENOMEM; | ||
182 | } | ||
183 | |||
184 | kp->dev = dev; | ||
185 | kp->rows = pdata->num_row_gpios; | ||
186 | kp->cols = pdata->num_col_gpios; | ||
187 | kp->row_shift = row_shift; | ||
188 | platform_set_drvdata(pdev, kp); | ||
189 | spin_lock_init(&kp->lock); | ||
190 | |||
191 | kp->irq_press = platform_get_irq_byname(pdev, "press"); | ||
192 | kp->irq_release = platform_get_irq_byname(pdev, "release"); | ||
193 | if (kp->irq_press < 0 || kp->irq_release < 0) { | ||
194 | dev_err(dev, "cannot determine device interrupts\n"); | ||
195 | error = -ENODEV; | ||
196 | goto error_res; | ||
197 | } | ||
198 | |||
199 | kp->res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
200 | if (!kp->res) { | ||
201 | dev_err(dev, "cannot determine register area\n"); | ||
202 | error = -ENODEV; | ||
203 | goto error_res; | ||
204 | } | ||
205 | |||
206 | if (!request_mem_region(kp->res->start, resource_size(kp->res), | ||
207 | pdev->name)) { | ||
208 | dev_err(dev, "cannot claim register memory\n"); | ||
209 | kp->res = NULL; | ||
210 | error = -EINVAL; | ||
211 | goto error_res; | ||
212 | } | ||
213 | |||
214 | kp->regs = ioremap(kp->res->start, resource_size(kp->res)); | ||
215 | if (!kp->regs) { | ||
216 | dev_err(dev, "cannot map register memory\n"); | ||
217 | error = -ENOMEM; | ||
218 | goto error_map; | ||
219 | } | ||
220 | |||
221 | kp->clk = clk_get(dev, NULL); | ||
222 | if (!kp->clk) { | ||
223 | dev_err(dev, "cannot claim device clock\n"); | ||
224 | error = -EINVAL; | ||
225 | goto error_clk; | ||
226 | } | ||
227 | |||
228 | error = request_threaded_irq(kp->irq_press, NULL, keypad_irq, 0, | ||
229 | dev_name(dev), kp); | ||
230 | if (error < 0) { | ||
231 | dev_err(kp->dev, "Could not allocate keypad press key irq\n"); | ||
232 | goto error_irq_press; | ||
233 | } | ||
234 | |||
235 | error = request_threaded_irq(kp->irq_release, NULL, keypad_irq, 0, | ||
236 | dev_name(dev), kp); | ||
237 | if (error < 0) { | ||
238 | dev_err(kp->dev, "Could not allocate keypad release key irq\n"); | ||
239 | goto error_irq_release; | ||
240 | } | ||
241 | |||
242 | kp->input_dev = input_allocate_device(); | ||
243 | if (!kp->input_dev) { | ||
244 | dev_err(dev, "cannot allocate input device\n"); | ||
245 | error = -ENOMEM; | ||
246 | goto error_input; | ||
247 | } | ||
248 | input_set_drvdata(kp->input_dev, kp); | ||
249 | |||
250 | kp->input_dev->name = pdev->name; | ||
251 | kp->input_dev->dev.parent = &pdev->dev; | ||
252 | kp->input_dev->open = keypad_start; | ||
253 | kp->input_dev->close = keypad_stop; | ||
254 | kp->input_dev->evbit[0] = BIT_MASK(EV_KEY); | ||
255 | if (!pdata->no_autorepeat) | ||
256 | kp->input_dev->evbit[0] |= BIT_MASK(EV_REP); | ||
257 | |||
258 | clk_enable(kp->clk); | ||
259 | rev = keypad_read(kp, rev); | ||
260 | kp->input_dev->id.bustype = BUS_HOST; | ||
261 | kp->input_dev->id.product = ((rev >> 8) & 0x07); | ||
262 | kp->input_dev->id.version = ((rev >> 16) & 0xfff); | ||
263 | clk_disable(kp->clk); | ||
264 | |||
265 | kp->input_dev->keycode = kp->keycodes; | ||
266 | kp->input_dev->keycodesize = sizeof(kp->keycodes[0]); | ||
267 | kp->input_dev->keycodemax = kp->rows << kp->row_shift; | ||
268 | |||
269 | matrix_keypad_build_keymap(keymap_data, kp->row_shift, kp->keycodes, | ||
270 | kp->input_dev->keybit); | ||
271 | |||
272 | input_set_capability(kp->input_dev, EV_MSC, MSC_SCAN); | ||
273 | |||
274 | error = input_register_device(kp->input_dev); | ||
275 | if (error < 0) { | ||
276 | dev_err(dev, "Could not register input device\n"); | ||
277 | goto error_reg; | ||
278 | } | ||
279 | |||
280 | return 0; | ||
281 | |||
282 | |||
283 | error_reg: | ||
284 | input_free_device(kp->input_dev); | ||
285 | error_input: | ||
286 | free_irq(kp->irq_release, kp); | ||
287 | error_irq_release: | ||
288 | free_irq(kp->irq_press, kp); | ||
289 | error_irq_press: | ||
290 | clk_put(kp->clk); | ||
291 | error_clk: | ||
292 | iounmap(kp->regs); | ||
293 | error_map: | ||
294 | release_mem_region(kp->res->start, resource_size(kp->res)); | ||
295 | error_res: | ||
296 | platform_set_drvdata(pdev, NULL); | ||
297 | kfree(kp); | ||
298 | return error; | ||
299 | } | ||
300 | |||
301 | static int __devexit keypad_remove(struct platform_device *pdev) | ||
302 | { | ||
303 | struct keypad_data *kp = platform_get_drvdata(pdev); | ||
304 | |||
305 | free_irq(kp->irq_press, kp); | ||
306 | free_irq(kp->irq_release, kp); | ||
307 | input_unregister_device(kp->input_dev); | ||
308 | clk_put(kp->clk); | ||
309 | iounmap(kp->regs); | ||
310 | release_mem_region(kp->res->start, resource_size(kp->res)); | ||
311 | platform_set_drvdata(pdev, NULL); | ||
312 | kfree(kp); | ||
313 | |||
314 | return 0; | ||
315 | } | ||
316 | |||
317 | static struct platform_driver keypad_driver = { | ||
318 | .probe = keypad_probe, | ||
319 | .remove = __devexit_p(keypad_remove), | ||
320 | .driver.name = "tnetv107x-keypad", | ||
321 | .driver.owner = THIS_MODULE, | ||
322 | }; | ||
323 | |||
324 | static int __init keypad_init(void) | ||
325 | { | ||
326 | return platform_driver_register(&keypad_driver); | ||
327 | } | ||
328 | |||
329 | static void __exit keypad_exit(void) | ||
330 | { | ||
331 | platform_driver_unregister(&keypad_driver); | ||
332 | } | ||
333 | |||
334 | module_init(keypad_init); | ||
335 | module_exit(keypad_exit); | ||
336 | |||
337 | MODULE_AUTHOR("Cyril Chemparathy"); | ||
338 | MODULE_DESCRIPTION("TNETV107X Keypad Driver"); | ||
339 | MODULE_ALIAS("platform: tnetv107x-keypad"); | ||
340 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig index 0ea361f23fa7..06ea8da95c62 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig | |||
@@ -362,6 +362,15 @@ config TOUCHSCREEN_MIGOR | |||
362 | To compile this driver as a module, choose M here: the | 362 | To compile this driver as a module, choose M here: the |
363 | module will be called migor_ts. | 363 | module will be called migor_ts. |
364 | 364 | ||
365 | config TOUCHSCREEN_TNETV107X | ||
366 | tristate "TI TNETV107X touchscreen support" | ||
367 | depends on ARCH_DAVINCI_TNETV107X | ||
368 | help | ||
369 | Say Y here if you want to use the TNETV107X touchscreen. | ||
370 | |||
371 | To compile this driver as a module, choose M here: the | ||
372 | module will be called tnetv107x-ts. | ||
373 | |||
365 | config TOUCHSCREEN_TOUCHRIGHT | 374 | config TOUCHSCREEN_TOUCHRIGHT |
366 | tristate "Touchright serial touchscreen" | 375 | tristate "Touchright serial touchscreen" |
367 | select SERIO | 376 | select SERIO |
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile index 99b353c4e9ae..7cc1b4f4b677 100644 --- a/drivers/input/touchscreen/Makefile +++ b/drivers/input/touchscreen/Makefile | |||
@@ -40,6 +40,7 @@ obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o | |||
40 | obj-$(CONFIG_TOUCHSCREEN_QT602240) += qt602240_ts.o | 40 | obj-$(CONFIG_TOUCHSCREEN_QT602240) += qt602240_ts.o |
41 | obj-$(CONFIG_TOUCHSCREEN_S3C2410) += s3c2410_ts.o | 41 | obj-$(CONFIG_TOUCHSCREEN_S3C2410) += s3c2410_ts.o |
42 | obj-$(CONFIG_TOUCHSCREEN_STMPE) += stmpe-ts.o | 42 | obj-$(CONFIG_TOUCHSCREEN_STMPE) += stmpe-ts.o |
43 | obj-$(CONFIG_TOUCHSCREEN_TNETV107X) += tnetv107x-ts.o | ||
43 | obj-$(CONFIG_TOUCHSCREEN_TOUCHIT213) += touchit213.o | 44 | obj-$(CONFIG_TOUCHSCREEN_TOUCHIT213) += touchit213.o |
44 | obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o | 45 | obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o |
45 | obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o | 46 | obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o |
diff --git a/drivers/input/touchscreen/tnetv107x-ts.c b/drivers/input/touchscreen/tnetv107x-ts.c new file mode 100644 index 000000000000..cf1dba2e267c --- /dev/null +++ b/drivers/input/touchscreen/tnetv107x-ts.c | |||
@@ -0,0 +1,396 @@ | |||
1 | /* | ||
2 | * Texas Instruments TNETV107X Touchscreen Driver | ||
3 | * | ||
4 | * Copyright (C) 2010 Texas Instruments | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License as | ||
8 | * published by the Free Software Foundation version 2. | ||
9 | * | ||
10 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any | ||
11 | * kind, whether express or implied; without even the implied warranty | ||
12 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | */ | ||
15 | |||
16 | #include <linux/kernel.h> | ||
17 | #include <linux/errno.h> | ||
18 | #include <linux/input.h> | ||
19 | #include <linux/platform_device.h> | ||
20 | #include <linux/interrupt.h> | ||
21 | #include <linux/slab.h> | ||
22 | #include <linux/delay.h> | ||
23 | #include <linux/ctype.h> | ||
24 | #include <linux/io.h> | ||
25 | #include <linux/clk.h> | ||
26 | |||
27 | #include <mach/tnetv107x.h> | ||
28 | |||
29 | #define TSC_PENUP_POLL (HZ / 5) | ||
30 | #define IDLE_TIMEOUT 100 /* msec */ | ||
31 | |||
32 | /* | ||
33 | * The first and last samples of a touch interval are usually garbage and need | ||
34 | * to be filtered out with these devices. The following definitions control | ||
35 | * the number of samples skipped. | ||
36 | */ | ||
37 | #define TSC_HEAD_SKIP 1 | ||
38 | #define TSC_TAIL_SKIP 1 | ||
39 | #define TSC_SKIP (TSC_HEAD_SKIP + TSC_TAIL_SKIP + 1) | ||
40 | #define TSC_SAMPLES (TSC_SKIP + 1) | ||
41 | |||
42 | /* Register Offsets */ | ||
43 | struct tsc_regs { | ||
44 | u32 rev; | ||
45 | u32 tscm; | ||
46 | u32 bwcm; | ||
47 | u32 swc; | ||
48 | u32 adcchnl; | ||
49 | u32 adcdata; | ||
50 | u32 chval[4]; | ||
51 | }; | ||
52 | |||
53 | /* TSC Mode Configuration Register (tscm) bits */ | ||
54 | #define WMODE BIT(0) | ||
55 | #define TSKIND BIT(1) | ||
56 | #define ZMEASURE_EN BIT(2) | ||
57 | #define IDLE BIT(3) | ||
58 | #define TSC_EN BIT(4) | ||
59 | #define STOP BIT(5) | ||
60 | #define ONE_SHOT BIT(6) | ||
61 | #define SINGLE BIT(7) | ||
62 | #define AVG BIT(8) | ||
63 | #define AVGNUM(x) (((x) & 0x03) << 9) | ||
64 | #define PVSTC(x) (((x) & 0x07) << 11) | ||
65 | #define PON BIT(14) | ||
66 | #define PONBG BIT(15) | ||
67 | #define AFERST BIT(16) | ||
68 | |||
69 | /* ADC DATA Capture Register bits */ | ||
70 | #define DATA_VALID BIT(16) | ||
71 | |||
72 | /* Register Access Macros */ | ||
73 | #define tsc_read(ts, reg) __raw_readl(&(ts)->regs->reg) | ||
74 | #define tsc_write(ts, reg, val) __raw_writel(val, &(ts)->regs->reg); | ||
75 | #define tsc_set_bits(ts, reg, val) \ | ||
76 | tsc_write(ts, reg, tsc_read(ts, reg) | (val)) | ||
77 | #define tsc_clr_bits(ts, reg, val) \ | ||
78 | tsc_write(ts, reg, tsc_read(ts, reg) & ~(val)) | ||
79 | |||
80 | struct sample { | ||
81 | int x, y, p; | ||
82 | }; | ||
83 | |||
84 | struct tsc_data { | ||
85 | struct input_dev *input_dev; | ||
86 | struct resource *res; | ||
87 | struct tsc_regs __iomem *regs; | ||
88 | struct timer_list timer; | ||
89 | spinlock_t lock; | ||
90 | struct clk *clk; | ||
91 | struct device *dev; | ||
92 | int sample_count; | ||
93 | struct sample samples[TSC_SAMPLES]; | ||
94 | int tsc_irq; | ||
95 | }; | ||
96 | |||
97 | static int tsc_read_sample(struct tsc_data *ts, struct sample* sample) | ||
98 | { | ||
99 | int x, y, z1, z2, t, p = 0; | ||
100 | u32 val; | ||
101 | |||
102 | val = tsc_read(ts, chval[0]); | ||
103 | if (val & DATA_VALID) | ||
104 | x = val & 0xffff; | ||
105 | else | ||
106 | return -EINVAL; | ||
107 | |||
108 | y = tsc_read(ts, chval[1]) & 0xffff; | ||
109 | z1 = tsc_read(ts, chval[2]) & 0xffff; | ||
110 | z2 = tsc_read(ts, chval[3]) & 0xffff; | ||
111 | |||
112 | if (z1) { | ||
113 | t = ((600 * x) * (z2 - z1)); | ||
114 | p = t / (u32) (z1 << 12); | ||
115 | if (p < 0) | ||
116 | p = 0; | ||
117 | } | ||
118 | |||
119 | sample->x = x; | ||
120 | sample->y = y; | ||
121 | sample->p = p; | ||
122 | |||
123 | return 0; | ||
124 | } | ||
125 | |||
126 | static void tsc_poll(unsigned long data) | ||
127 | { | ||
128 | struct tsc_data *ts = (struct tsc_data *)data; | ||
129 | unsigned long flags; | ||
130 | int i, val, x, y, p; | ||
131 | |||
132 | spin_lock_irqsave(&ts->lock, flags); | ||
133 | |||
134 | if (ts->sample_count >= TSC_SKIP) { | ||
135 | input_report_abs(ts->input_dev, ABS_PRESSURE, 0); | ||
136 | input_report_key(ts->input_dev, BTN_TOUCH, 0); | ||
137 | input_sync(ts->input_dev); | ||
138 | } else if (ts->sample_count > 0) { | ||
139 | /* | ||
140 | * A touch event lasted less than our skip count. Salvage and | ||
141 | * report anyway. | ||
142 | */ | ||
143 | for (i = 0, val = 0; i < ts->sample_count; i++) | ||
144 | val += ts->samples[i].x; | ||
145 | x = val / ts->sample_count; | ||
146 | |||
147 | for (i = 0, val = 0; i < ts->sample_count; i++) | ||
148 | val += ts->samples[i].y; | ||
149 | y = val / ts->sample_count; | ||
150 | |||
151 | for (i = 0, val = 0; i < ts->sample_count; i++) | ||
152 | val += ts->samples[i].p; | ||
153 | p = val / ts->sample_count; | ||
154 | |||
155 | input_report_abs(ts->input_dev, ABS_X, x); | ||
156 | input_report_abs(ts->input_dev, ABS_Y, y); | ||
157 | input_report_abs(ts->input_dev, ABS_PRESSURE, p); | ||
158 | input_report_key(ts->input_dev, BTN_TOUCH, 1); | ||
159 | input_sync(ts->input_dev); | ||
160 | } | ||
161 | |||
162 | ts->sample_count = 0; | ||
163 | |||
164 | spin_unlock_irqrestore(&ts->lock, flags); | ||
165 | } | ||
166 | |||
167 | static irqreturn_t tsc_irq(int irq, void *dev_id) | ||
168 | { | ||
169 | struct tsc_data *ts = (struct tsc_data *)dev_id; | ||
170 | struct sample *sample; | ||
171 | int index; | ||
172 | |||
173 | spin_lock(&ts->lock); | ||
174 | |||
175 | index = ts->sample_count % TSC_SAMPLES; | ||
176 | sample = &ts->samples[index]; | ||
177 | if (tsc_read_sample(ts, sample) < 0) | ||
178 | goto out; | ||
179 | |||
180 | if (++ts->sample_count >= TSC_SKIP) { | ||
181 | index = (ts->sample_count - TSC_TAIL_SKIP - 1) % TSC_SAMPLES; | ||
182 | sample = &ts->samples[index]; | ||
183 | |||
184 | input_report_abs(ts->input_dev, ABS_X, sample->x); | ||
185 | input_report_abs(ts->input_dev, ABS_Y, sample->y); | ||
186 | input_report_abs(ts->input_dev, ABS_PRESSURE, sample->p); | ||
187 | if (ts->sample_count == TSC_SKIP) | ||
188 | input_report_key(ts->input_dev, BTN_TOUCH, 1); | ||
189 | input_sync(ts->input_dev); | ||
190 | } | ||
191 | mod_timer(&ts->timer, jiffies + TSC_PENUP_POLL); | ||
192 | out: | ||
193 | spin_unlock(&ts->lock); | ||
194 | return IRQ_HANDLED; | ||
195 | } | ||
196 | |||
197 | static int tsc_start(struct input_dev *dev) | ||
198 | { | ||
199 | struct tsc_data *ts = input_get_drvdata(dev); | ||
200 | unsigned long timeout = jiffies + msecs_to_jiffies(IDLE_TIMEOUT); | ||
201 | u32 val; | ||
202 | |||
203 | clk_enable(ts->clk); | ||
204 | |||
205 | /* Go to idle mode, before any initialization */ | ||
206 | while (time_after(timeout, jiffies)) { | ||
207 | if (tsc_read(ts, tscm) & IDLE) | ||
208 | break; | ||
209 | } | ||
210 | |||
211 | if (time_before(timeout, jiffies)) { | ||
212 | dev_warn(ts->dev, "timeout waiting for idle\n"); | ||
213 | clk_disable(ts->clk); | ||
214 | return -EIO; | ||
215 | } | ||
216 | |||
217 | /* Configure TSC Control register*/ | ||
218 | val = (PONBG | PON | PVSTC(4) | ONE_SHOT | ZMEASURE_EN); | ||
219 | tsc_write(ts, tscm, val); | ||
220 | |||
221 | /* Bring TSC out of reset: Clear AFE reset bit */ | ||
222 | val &= ~(AFERST); | ||
223 | tsc_write(ts, tscm, val); | ||
224 | |||
225 | /* Configure all pins for hardware control*/ | ||
226 | tsc_write(ts, bwcm, 0); | ||
227 | |||
228 | /* Finally enable the TSC */ | ||
229 | tsc_set_bits(ts, tscm, TSC_EN); | ||
230 | |||
231 | return 0; | ||
232 | } | ||
233 | |||
234 | static void tsc_stop(struct input_dev *dev) | ||
235 | { | ||
236 | struct tsc_data *ts = input_get_drvdata(dev); | ||
237 | |||
238 | tsc_clr_bits(ts, tscm, TSC_EN); | ||
239 | synchronize_irq(ts->tsc_irq); | ||
240 | del_timer_sync(&ts->timer); | ||
241 | clk_disable(ts->clk); | ||
242 | } | ||
243 | |||
244 | static int __devinit tsc_probe(struct platform_device *pdev) | ||
245 | { | ||
246 | struct device *dev = &pdev->dev; | ||
247 | struct tsc_data *ts; | ||
248 | int error = 0; | ||
249 | u32 rev = 0; | ||
250 | |||
251 | ts = kzalloc(sizeof(struct tsc_data), GFP_KERNEL); | ||
252 | if (!ts) { | ||
253 | dev_err(dev, "cannot allocate device info\n"); | ||
254 | return -ENOMEM; | ||
255 | } | ||
256 | |||
257 | ts->dev = dev; | ||
258 | spin_lock_init(&ts->lock); | ||
259 | setup_timer(&ts->timer, tsc_poll, (unsigned long)ts); | ||
260 | platform_set_drvdata(pdev, ts); | ||
261 | |||
262 | ts->tsc_irq = platform_get_irq(pdev, 0); | ||
263 | if (ts->tsc_irq < 0) { | ||
264 | dev_err(dev, "cannot determine device interrupt\n"); | ||
265 | error = -ENODEV; | ||
266 | goto error_res; | ||
267 | } | ||
268 | |||
269 | ts->res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
270 | if (!ts->res) { | ||
271 | dev_err(dev, "cannot determine register area\n"); | ||
272 | error = -ENODEV; | ||
273 | goto error_res; | ||
274 | } | ||
275 | |||
276 | if (!request_mem_region(ts->res->start, resource_size(ts->res), | ||
277 | pdev->name)) { | ||
278 | dev_err(dev, "cannot claim register memory\n"); | ||
279 | ts->res = NULL; | ||
280 | error = -EINVAL; | ||
281 | goto error_res; | ||
282 | } | ||
283 | |||
284 | ts->regs = ioremap(ts->res->start, resource_size(ts->res)); | ||
285 | if (!ts->regs) { | ||
286 | dev_err(dev, "cannot map register memory\n"); | ||
287 | error = -ENOMEM; | ||
288 | goto error_map; | ||
289 | } | ||
290 | |||
291 | ts->clk = clk_get(dev, NULL); | ||
292 | if (!ts->clk) { | ||
293 | dev_err(dev, "cannot claim device clock\n"); | ||
294 | error = -EINVAL; | ||
295 | goto error_clk; | ||
296 | } | ||
297 | |||
298 | error = request_threaded_irq(ts->tsc_irq, NULL, tsc_irq, 0, | ||
299 | dev_name(dev), ts); | ||
300 | if (error < 0) { | ||
301 | dev_err(ts->dev, "Could not allocate ts irq\n"); | ||
302 | goto error_irq; | ||
303 | } | ||
304 | |||
305 | ts->input_dev = input_allocate_device(); | ||
306 | if (!ts->input_dev) { | ||
307 | dev_err(dev, "cannot allocate input device\n"); | ||
308 | error = -ENOMEM; | ||
309 | goto error_input; | ||
310 | } | ||
311 | input_set_drvdata(ts->input_dev, ts); | ||
312 | |||
313 | ts->input_dev->name = pdev->name; | ||
314 | ts->input_dev->id.bustype = BUS_HOST; | ||
315 | ts->input_dev->dev.parent = &pdev->dev; | ||
316 | ts->input_dev->open = tsc_start; | ||
317 | ts->input_dev->close = tsc_stop; | ||
318 | |||
319 | clk_enable(ts->clk); | ||
320 | rev = tsc_read(ts, rev); | ||
321 | ts->input_dev->id.product = ((rev >> 8) & 0x07); | ||
322 | ts->input_dev->id.version = ((rev >> 16) & 0xfff); | ||
323 | clk_disable(ts->clk); | ||
324 | |||
325 | __set_bit(EV_KEY, ts->input_dev->evbit); | ||
326 | __set_bit(EV_ABS, ts->input_dev->evbit); | ||
327 | __set_bit(BTN_TOUCH, ts->input_dev->keybit); | ||
328 | |||
329 | input_set_abs_params(ts->input_dev, ABS_X, 0, 0xffff, 5, 0); | ||
330 | input_set_abs_params(ts->input_dev, ABS_Y, 0, 0xffff, 5, 0); | ||
331 | input_set_abs_params(ts->input_dev, ABS_PRESSURE, 0, 4095, 128, 0); | ||
332 | |||
333 | error = input_register_device(ts->input_dev); | ||
334 | if (error < 0) { | ||
335 | dev_err(dev, "failed input device registration\n"); | ||
336 | goto error_reg; | ||
337 | } | ||
338 | |||
339 | return 0; | ||
340 | |||
341 | error_reg: | ||
342 | input_free_device(ts->input_dev); | ||
343 | error_input: | ||
344 | free_irq(ts->tsc_irq, ts); | ||
345 | error_irq: | ||
346 | clk_put(ts->clk); | ||
347 | error_clk: | ||
348 | iounmap(ts->regs); | ||
349 | error_map: | ||
350 | release_mem_region(ts->res->start, resource_size(ts->res)); | ||
351 | error_res: | ||
352 | platform_set_drvdata(pdev, NULL); | ||
353 | kfree(ts); | ||
354 | |||
355 | return error; | ||
356 | } | ||
357 | |||
358 | static int __devexit tsc_remove(struct platform_device *pdev) | ||
359 | { | ||
360 | struct tsc_data *ts = platform_get_drvdata(pdev); | ||
361 | |||
362 | input_unregister_device(ts->input_dev); | ||
363 | free_irq(ts->tsc_irq, ts); | ||
364 | clk_put(ts->clk); | ||
365 | iounmap(ts->regs); | ||
366 | release_mem_region(ts->res->start, resource_size(ts->res)); | ||
367 | platform_set_drvdata(pdev, NULL); | ||
368 | kfree(ts); | ||
369 | |||
370 | return 0; | ||
371 | } | ||
372 | |||
373 | static struct platform_driver tsc_driver = { | ||
374 | .probe = tsc_probe, | ||
375 | .remove = __devexit_p(tsc_remove), | ||
376 | .driver.name = "tnetv107x-ts", | ||
377 | .driver.owner = THIS_MODULE, | ||
378 | }; | ||
379 | |||
380 | static int __init tsc_init(void) | ||
381 | { | ||
382 | return platform_driver_register(&tsc_driver); | ||
383 | } | ||
384 | |||
385 | static void __exit tsc_exit(void) | ||
386 | { | ||
387 | platform_driver_unregister(&tsc_driver); | ||
388 | } | ||
389 | |||
390 | module_init(tsc_init); | ||
391 | module_exit(tsc_exit); | ||
392 | |||
393 | MODULE_AUTHOR("Cyril Chemparathy"); | ||
394 | MODULE_DESCRIPTION("TNETV107X Touchscreen Driver"); | ||
395 | MODULE_ALIAS("platform: tnetv107x-ts"); | ||
396 | MODULE_LICENSE("GPL"); | ||