1 From 40787f3e48d1cc1e63dc5dd6aeda720f688fc05e Mon Sep 17 00:00:00 2001
2 From: Thomas Kunze <thommycheck@gmx.de>
3 Date: Mon, 20 Oct 2008 17:44:23 +0200
4 Subject: [PATCH 13/23] add collie touchscreen driver
7 drivers/input/touchscreen/Kconfig | 6 +
8 drivers/input/touchscreen/Makefile | 1 +
9 drivers/input/touchscreen/collie-ts.c | 449 +++++++++++++++++++++++++++++++++
10 drivers/mfd/Makefile | 1 -
11 include/linux/mfd/ucb1x00.h | 3 +
12 5 files changed, 459 insertions(+), 1 deletions(-)
13 create mode 100644 drivers/input/touchscreen/collie-ts.c
15 diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
16 index 3ac8cd6..a9f89ed 100644
17 --- a/drivers/input/touchscreen/Kconfig
18 +++ b/drivers/input/touchscreen/Kconfig
19 @@ -228,6 +228,12 @@ config TOUCHSCREEN_UCB1200_TS
20 This enabled support for the Pilips UCB1200 touchscreen interface
23 +config TOUCHSCREEN_COLLIE_TS
24 + tristate "Touchscreen collie support"
25 + depends on MCP_UCB1200 && INPUT && !MCP_UCB1200_TS
27 + Driver for touchscreen on collie - sharp sl-5500.
29 config TOUCHSCREEN_UCB1400
30 tristate "Philips UCB1400 touchscreen"
32 diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile
33 index 77ba930..77715cd 100644
34 --- a/drivers/input/touchscreen/Makefile
35 +++ b/drivers/input/touchscreen/Makefile
36 @@ -26,6 +26,7 @@ obj-$(CONFIG_TOUCHSCREEN_TOUCHIT213) += touchit213.o
37 obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o
38 obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o
39 obj-$(CONFIG_TOUCHSCREEN_UCB1200_TS) += ucb1x00-ts.o
40 +obj-$(CONFIG_TOUCHSCREEN_COLLIE_TS) += collie-ts.o
41 obj-$(CONFIG_TOUCHSCREEN_UCB1400) += ucb1400_ts.o
42 obj-$(CONFIG_TOUCHSCREEN_WM97XX) += wm97xx-ts.o
43 wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9705) += wm9705.o
44 diff --git a/drivers/input/touchscreen/collie-ts.c b/drivers/input/touchscreen/collie-ts.c
46 index 0000000..c7c0272
48 +++ b/drivers/input/touchscreen/collie-ts.c
51 + * Touchscreen driver for UCB1x00-based touchscreens
53 + * Copyright (C) 2001 Russell King, All Rights Reserved.
54 + * Copyright (C) 2005 Pavel Machek
56 + * This program is free software; you can redistribute it and/or modify
57 + * it under the terms of the GNU General Public License version 2 as
58 + * published by the Free Software Foundation.
60 + * 21-Jan-2002 <jco@ict.es> :
62 + * Added support for synchronous A/D mode. This mode is useful to
63 + * avoid noise induced in the touchpanel by the LCD, provided that
64 + * the UCB1x00 has a valid LCD sync signal routed to its ADCSYNC pin.
65 + * It is important to note that the signal connected to the ADCSYNC
66 + * pin should provide pulses even when the LCD is blanked, otherwise
67 + * a pen touch needed to unblank the LCD will never be read.
69 +#include <linux/module.h>
70 +#include <linux/moduleparam.h>
71 +#include <linux/init.h>
72 +#include <linux/smp.h>
73 +#include <linux/smp_lock.h>
74 +#include <linux/sched.h>
75 +#include <linux/completion.h>
76 +#include <linux/delay.h>
77 +#include <linux/string.h>
78 +#include <linux/input.h>
79 +#include <linux/device.h>
80 +#include <linux/freezer.h>
81 +#include <linux/slab.h>
82 +#include <linux/kthread.h>
83 +#include <linux/semaphore.h>
85 +#include <mach/dma.h>
86 +#include <mach/collie.h>
87 +#include <asm/mach-types.h>
89 +#include <linux/mfd/ucb1x00.h>
92 + struct input_dev *idev;
93 + struct ucb1x00 *ucb;
95 + wait_queue_head_t irq_wait;
96 + struct task_struct *rtask;
100 + unsigned int adcsync:1;
105 +/**********************************
124 +**********************************/
127 +static inline void ucb1x00_ts_evt_add(struct ucb1x00_ts *ts, u16 pressure, u16 x, u16 y)
129 + struct input_dev *idev = ts->idev;
131 + input_report_abs(idev, ABS_X, x);
132 + input_report_abs(idev, ABS_Y, y);
133 + input_report_abs(idev, ABS_PRESSURE, pressure);
134 + input_report_key(idev, BTN_TOUCH, 1);
138 +static inline void ucb1x00_ts_event_release(struct ucb1x00_ts *ts)
140 + struct input_dev *idev = ts->idev;
142 + input_report_abs(idev, ABS_PRESSURE, 0);
143 + input_report_key(idev, BTN_TOUCH, 0);
148 + * Switch to interrupt mode. This set touchscreen to interrupt
149 + * mode, so that chip is able to send interrupt.
151 +static inline void ucb1x00_ts_mode_int(struct ucb1x00_ts *ts)
153 + ucb1x00_reg_write(ts->ucb, UCB_TS_CR,
154 + UCB_TS_CR_TSMX_POW | UCB_TS_CR_TSPX_POW |
155 + UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_GND |
156 + UCB_TS_CR_MODE_INT);
160 + * Switch to pressure mode, and read pressure. We don't need to wait
161 + * here, since both plates are being driven.
163 + * set_read_pressure() in sharp code
165 +static inline void ucb1x00_ts_read_pressure(struct ucb1x00_ts *ts)
167 + ucb1x00_io_write(ts->ucb, COLLIE_TC35143_GPIO_TBL_CHK, 0);
168 + ucb1x00_reg_write(ts->ucb, UCB_TS_CR,
169 + UCB_TS_CR_TSPX_POW | UCB_TS_CR_TSMX_POW |
170 + UCB_TS_CR_MODE_POS | UCB_TS_CR_BIAS_ENA);
172 + ucb1x00_reg_write(ts->ucb, UCB_ADC_CR, ts->ucb->adc_cr |
176 + ucb1x00_reg_write(ts->ucb, UCB_ADC_CR, ts->ucb->adc_cr |
178 + UCB_ADC_SYNC_ENA | UCB_ADC_START);
182 + * Switch to X position mode and measure Y plate. We switch the plate
183 + * configuration in pressure mode, then switch to position mode. This
184 + * gives a faster response time. Even so, we need to wait about 55us
185 + * for things to stabilise.
187 +static inline void ucb1x00_ts_read_xpos(struct ucb1x00_ts *ts)
189 + ucb1x00_io_write(ts->ucb, 0, COLLIE_TC35143_GPIO_TBL_CHK);
190 + ucb1x00_reg_write(ts->ucb, UCB_TS_CR,
191 + UCB_TS_CR_TSMX_GND | UCB_TS_CR_TSPX_POW |
192 + UCB_TS_CR_MODE_POS | UCB_TS_CR_BIAS_ENA);
195 + ucb1x00_reg_write(ts->ucb, UCB_ADC_CR, ts->ucb->adc_cr |
196 + UCB_ADC_INP_TSPY | UCB_ADC_SYNC_ENA);
198 + ucb1x00_reg_write(ts->ucb, UCB_ADC_CR, ts->ucb->adc_cr |
199 + UCB_ADC_INP_TSPY | UCB_ADC_SYNC_ENA |
204 + * Switch to Y position mode and measure X plate. We switch the plate
205 + * configuration in pressure mode, then switch to position mode. This
206 + * gives a faster response time. Even so, we need to wait about 55us
207 + * for things to stabilise.
209 +static inline void ucb1x00_ts_read_ypos(struct ucb1x00_ts *ts)
211 + ucb1x00_io_write(ts->ucb, 0, COLLIE_TC35143_GPIO_TBL_CHK);
213 + ucb1x00_reg_write(ts->ucb, UCB_TS_CR,
214 + UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_POW |
215 + UCB_TS_CR_MODE_POS | UCB_TS_CR_BIAS_ENA);
218 + ucb1x00_reg_write(ts->ucb, UCB_ADC_CR, ts->ucb->adc_cr |
219 + UCB_ADC_INP_TSPX | UCB_ADC_SYNC_ENA);
221 + ucb1x00_reg_write(ts->ucb, UCB_ADC_CR, ts->ucb->adc_cr |
222 + UCB_ADC_INP_TSPX | UCB_ADC_SYNC_ENA |
227 + * Switch to X plate resistance mode. Set MX to ground, PX to
228 + * supply. Measure current.
230 +static inline unsigned int ucb1x00_ts_read_xres(struct ucb1x00_ts *ts)
232 + ucb1x00_reg_write(ts->ucb, UCB_TS_CR,
233 + UCB_TS_CR_TSMX_GND | UCB_TS_CR_TSPX_POW |
234 + UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA);
235 + return ucb1x00_adc_read(ts->ucb, 0, ts->adcsync);
239 + * Switch to Y plate resistance mode. Set MY to ground, PY to
240 + * supply. Measure current.
242 +static inline unsigned int ucb1x00_ts_read_yres(struct ucb1x00_ts *ts)
244 + ucb1x00_reg_write(ts->ucb, UCB_TS_CR,
245 + UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_POW |
246 + UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA);
247 + return ucb1x00_adc_read(ts->ucb, 0, ts->adcsync);
251 + * This is a RT kernel thread that handles the ADC accesses
252 + * (mainly so we can use semaphores in the UCB1200 core code
253 + * to serialise accesses to the ADC).
255 +static int ucb1x00_thread(void *_ts)
257 + struct ucb1x00_ts *ts = _ts;
258 + struct task_struct *tsk = current;
259 + DECLARE_WAITQUEUE(wait, tsk);
263 + * We could run as a real-time thread. However, thus far
264 + * this doesn't seem to be necessary.
267 + add_wait_queue(&ts->irq_wait, &wait);
269 + while (!kthread_should_stop()) {
270 + unsigned int data[3];
272 + for (state=0; state<3; state++) {
274 + ucb1x00_adc_enable(ts->ucb);
275 + ucb1x00_enable_irq(ts->ucb, UCB_IRQ_ADC, UCB_FALLING);
277 + /* Order matters here; last measurement seems to be more noisy then the
278 + rest, and we care about pressure least */
279 + case 2: ucb1x00_ts_read_pressure(ts);
281 + case 0: ucb1x00_ts_read_ypos(ts);
283 + case 1: ucb1x00_ts_read_xpos(ts);
288 + schedule_timeout(1000 * HZ);
289 + ucb1x00_disable_irq(ts->ucb, UCB_IRQ_ADC, UCB_FALLING);
290 + data[state] = UCB_ADC_DAT(ucb1x00_reg_read(ts->ucb, UCB_ADC_DATA));
291 + ucb1x00_adc_disable(ts->ucb);
294 + /* If not pressed any more, try to sleep! */
295 + if (data[2] < 300) {
296 + set_task_state(tsk, TASK_INTERRUPTIBLE);
297 + ucb1x00_enable_irq(ts->ucb, UCB_IRQ_TSPX, UCB_RISING);
298 + ucb1x00_ts_mode_int(ts);
299 + ucb1x00_disable(ts->ucb);
300 + ucb1x00_ts_event_release(ts);
302 + schedule_timeout(1000 * HZ);
303 + ucb1x00_disable_irq(ts->ucb, UCB_IRQ_TSPX, UCB_RISING);
304 + ucb1x00_enable(ts->ucb);
306 + ucb1x00_ts_evt_add(ts, data[2], data[1], data[0]);
308 + ucb1x00_disable(ts->ucb);
310 + ucb1x00_enable(ts->ucb);
313 + remove_wait_queue(&ts->irq_wait, &wait);
320 + * We only detect touch screen _touches_ with this interrupt
321 + * handler, and even then we just schedule our task.
323 +static void ucb1x00_ts_irq(int idx, void *id)
325 + struct ucb1x00_ts *ts = id;
326 + wake_up(&ts->irq_wait);
329 +static void ucb1x00_adc_irq(int idx, void *id)
331 + struct ucb1x00_ts *ts = id;
332 + wake_up(&ts->irq_wait);
335 +static int ucb1x00_ts_open(struct input_dev *idev)
337 + struct ucb1x00_ts *ts = input_get_drvdata(idev);
342 + init_waitqueue_head(&ts->irq_wait);
344 + ret = ucb1x00_hook_irq(ts->ucb, UCB_IRQ_TSPX, ucb1x00_ts_irq, ts);
348 + ret = ucb1x00_hook_irq(ts->ucb, UCB_IRQ_ADC, ucb1x00_adc_irq, ts);
350 + ucb1x00_free_irq(ts->ucb, UCB_IRQ_TSPX, ts);
354 + ucb1x00_enable_irq(ts->ucb, UCB_IRQ_TSPX, UCB_RISING);
357 + * If we do this at all, we should allow the user to
358 + * measure and read the X and Y resistance at any time.
360 + ucb1x00_adc_enable(ts->ucb);
361 + ts->x_res = ucb1x00_ts_read_xres(ts);
362 + ts->y_res = ucb1x00_ts_read_yres(ts);
363 + ucb1x00_adc_disable(ts->ucb);
365 + if (machine_is_collie()) {
366 + ucb1x00_io_set_dir(ts->ucb, 0, COLLIE_TC35143_GPIO_TBL_CHK);
369 + ts->rtask = kthread_run(ucb1x00_thread, ts, "ktsd");
370 + if (!IS_ERR(ts->rtask)) {
373 + ucb1x00_free_irq(ts->ucb, UCB_IRQ_TSPX, ts);
382 + * Release touchscreen resources. Disable IRQs.
384 +static void ucb1x00_ts_close(struct input_dev *idev)
386 + struct ucb1x00_ts *ts = input_get_drvdata(idev);
389 + kthread_stop(ts->rtask);
391 + ucb1x00_enable(ts->ucb);
392 + ucb1x00_free_irq(ts->ucb, UCB_IRQ_TSPX, ts);
393 + ucb1x00_free_irq(ts->ucb, UCB_IRQ_ADC, ts);
394 + ucb1x00_reg_write(ts->ucb, UCB_TS_CR, 0);
395 + ucb1x00_disable(ts->ucb);
399 +static int ucb1x00_ts_resume(struct ucb1x00_dev *dev)
401 + struct ucb1x00_ts *ts = dev->priv;
403 + if (ts->rtask != NULL) {
405 + * Restart the TS thread to ensure the
406 + * TS interrupt mode is set up again
409 + wake_up(&ts->irq_wait);
414 +#define ucb1x00_ts_resume NULL
421 +static int ucb1x00_ts_add(struct ucb1x00_dev *dev)
423 + struct ucb1x00_ts *ts;
424 + struct input_dev *idev;
427 + ts = kzalloc(sizeof(struct ucb1x00_ts), GFP_KERNEL);
428 + idev = input_allocate_device();
429 + if (!ts || !idev) {
434 + ts->ucb = dev->ucb;
436 + ts->adcsync = adcsync ? UCB_SYNC : UCB_NOSYNC;
438 + input_set_drvdata(idev, ts);
439 + idev->name = "Touchscreen panel";
440 + idev->id.product = ts->ucb->id;
441 + idev->open = ucb1x00_ts_open;
442 + idev->close = ucb1x00_ts_close;
444 + __set_bit(EV_ABS, idev->evbit);
445 + __set_bit(ABS_X, idev->absbit);
446 + __set_bit(ABS_Y, idev->absbit);
447 + __set_bit(ABS_PRESSURE, idev->absbit);
449 + input_set_abs_params(ts->idev, ABS_X, 0, 450, 0, 0);
450 + input_set_abs_params(ts->idev, ABS_Y, 200, 800, 0, 0);
451 + input_set_abs_params(ts->idev, ABS_PRESSURE, 400, 800, 0, 0);
454 + err = input_register_device(idev);
463 + input_free_device(idev);
468 +static void ucb1x00_ts_remove(struct ucb1x00_dev *dev)
470 + struct ucb1x00_ts *ts = dev->priv;
472 + input_unregister_device(ts->idev);
476 +static struct ucb1x00_driver ucb1x00_ts_driver = {
477 + .add = ucb1x00_ts_add,
478 + .remove = ucb1x00_ts_remove,
479 + .resume = ucb1x00_ts_resume,
482 +static int __init ucb1x00_ts_init(void)
484 + return ucb1x00_register_driver(&ucb1x00_ts_driver);
487 +static void __exit ucb1x00_ts_exit(void)
489 + ucb1x00_unregister_driver(&ucb1x00_ts_driver);
492 +module_param(adcsync, int, 0444);
493 +module_init(ucb1x00_ts_init);
494 +module_exit(ucb1x00_ts_exit);
496 +MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
497 +MODULE_DESCRIPTION("UCB1x00 touchscreen driver");
498 +MODULE_LICENSE("GPL");
499 diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
500 index 4981aff..7bbba6e 100644
501 --- a/drivers/mfd/Makefile
502 +++ b/drivers/mfd/Makefile
503 @@ -24,7 +24,6 @@ obj-$(CONFIG_MFD_CORE) += mfd-core.o
504 obj-$(CONFIG_MCP) += mcp-core.o
505 obj-$(CONFIG_MCP_SA11X0) += mcp-sa11x0.o
506 obj-$(CONFIG_MCP_UCB1200) += ucb1x00-core.o
508 ifeq ($(CONFIG_SA1100_ASSABET),y)
509 obj-$(CONFIG_MCP_UCB1200) += ucb1x00-assabet.o
511 diff --git a/include/linux/mfd/ucb1x00.h b/include/linux/mfd/ucb1x00.h
512 index eac3463..70eb763 100644
513 --- a/include/linux/mfd/ucb1x00.h
514 +++ b/include/linux/mfd/ucb1x00.h
516 #define UCB_IE_TCLIP (1 << 14)
517 #define UCB_IE_ACLIP (1 << 15)
520 +#define UCB_IRQ_ADC 11
521 #define UCB_IRQ_TSPX 12
522 +#define UCB_IRQ_TSMX 13
524 #define UCB_TC_A 0x05
525 #define UCB_TC_A_LOOP (1 << 7) /* UCB1200 */