merge of '178eac00dc5aa8338d42e8e203633bec7817bbf6'
[vuplus_openembedded] / packages / linux / linux-rp-2.6.24 / tosa / 0068-Preliminary-tosa-denoiser.patch
1 From f7dad1cd9c1bd3fce5d228e0b644a51baea50cd9 Mon Sep 17 00:00:00 2001
2 From: Dmitry Baryshkov <dbaryshkov@gmail.com>
3 Date: Fri, 15 Feb 2008 15:35:07 +0300
4 Subject: [PATCH] Preliminary tosa denoiser
5
6 Signed-off-by: Dmitry Baryshkov <dbaryshkov@gmail.com>
7 ---
8  drivers/input/touchscreen/Kconfig       |   12 ++
9  drivers/input/touchscreen/Makefile      |    1 +
10  drivers/input/touchscreen/tosa-wm97xx.c |  182 +++++++++++++++++++++++++++++++
11  3 files changed, 195 insertions(+), 0 deletions(-)
12  create mode 100644 drivers/input/touchscreen/tosa-wm97xx.c
13
14 diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
15 index 0be05a2..938aed2 100644
16 --- a/drivers/input/touchscreen/Kconfig
17 +++ b/drivers/input/touchscreen/Kconfig
18 @@ -210,6 +210,18 @@ config TOUCHSCREEN_WM97XX_MAINSTONE
19           To compile this driver as a module, choose M here: the
20           module will be called mainstone-wm97xx
21  
22 +config TOUCHSCREEN_WM97XX_TOSA
23 +       tristate "WM97xx Tosa denoiser"
24 +       depends on TOUCHSCREEN_WM97XX && MACH_TOSA
25 +       help
26 +         Say Y here for support for touchscreen denoising on
27 +         Sharl Zaurus SL-6000 (tosa) system.
28 +
29 +         If unsure, say N
30 +
31 +         To compile this driver as a module, choose M here: the
32 +         module will be called tosa-wm97xx
33 +
34  config TOUCHSCREEN_TOUCHWIN
35         tristate "Touchwin serial touchscreen"
36         select SERIO
37 diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile
38 index d38156e..d86278b 100644
39 --- a/drivers/input/touchscreen/Makefile
40 +++ b/drivers/input/touchscreen/Makefile
41 @@ -23,6 +23,7 @@ obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN)    += touchwin.o
42  obj-$(CONFIG_TOUCHSCREEN_UCB1400)      += ucb1400_ts.o
43  obj-$(CONFIG_TOUCHSCREEN_WM97XX)       += wm97xx-ts.o
44  obj-$(CONFIG_TOUCHSCREEN_WM97XX_MAINSTONE)     += mainstone-wm97xx.o
45 +obj-$(CONFIG_TOUCHSCREEN_WM97XX_TOSA)  += tosa-wm97xx.o
46  wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9705)  += wm9705.o
47  wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9712)  += wm9712.o
48  wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9713)  += wm9713.o
49 diff --git a/drivers/input/touchscreen/tosa-wm97xx.c b/drivers/input/touchscreen/tosa-wm97xx.c
50 new file mode 100644
51 index 0000000..8fd542b
52 --- /dev/null
53 +++ b/drivers/input/touchscreen/tosa-wm97xx.c
54 @@ -0,0 +1,182 @@
55 +/*
56 + * tosa_ts.c  --  Touchscreen driver for Sharp SL-6000 (Tosa).
57 + *
58 + * Copyright 2008 Dmitry Baryshkov
59 + * Copyright 2006 Wolfson Microelectronics PLC.
60 + * Author: Mike Arthur
61 + *         linux@wolfsonmicro.com
62 + *
63 + *  This program is free software; you can redistribute  it and/or modify it
64 + *  under  the terms of  the GNU General  Public License as published by the
65 + *  Free Software Foundation;  either version 2 of the  License, or (at your
66 + *  option) any later version.
67 + *
68 + *  Revision history
69 + *     1st Sep 2006  Initial version.
70 + *
71 + */
72 +
73 +#include <linux/kernel.h>
74 +#include <linux/module.h>
75 +#include <linux/platform_device.h>
76 +#include <linux/wm97xx.h>
77 +#include <linux/fb.h>
78 +
79 +#include <asm/arch/tosa.h>
80 +#include <asm/gpio.h>
81 +
82 +static unsigned long hsync_time = 0;
83 +
84 +static void calc_hsync_time(const struct fb_videomode *mode)
85 +{
86 +       /* The 25 and 44 'magic numbers' are from Sharp's 2.4 patches */
87 +       if (mode->yres == 640) {
88 +               hsync_time = 25;
89 +       } else if (mode->yres == 320) {
90 +               hsync_time = 44;
91 +       } else {
92 +               printk(KERN_ERR "unknown video mode res specified: %dx%d!", mode->xres, mode->yres);
93 +               WARN_ON(1);
94 +       }
95 +
96 +       printk(KERN_ERR "tosa-wm97xx: using %lu hsync time\n", hsync_time);
97 +}
98 +
99 +static int fb_notifier_callback(struct notifier_block *self,
100 +                               unsigned long event, void *_data)
101 +{
102 +       if (event != FB_EVENT_MODE_CHANGE && event != FB_EVENT_MODE_CHANGE_ALL)
103 +               return 0;
104 +
105 +       calc_hsync_time(tosa_lcd_get_mode());
106 +
107 +       return 0;
108 +}
109 +
110 +static void tosa_lcd_wait_hsync(void)
111 +{
112 +       /* Waits for a rising edge on the VGA line */
113 +       while (gpio_get_value(TOSA_GPIO_VGA_LINE) == 0);
114 +       while (gpio_get_value(TOSA_GPIO_VGA_LINE) != 0);
115 +}
116 +
117 +/* Taken from the Sharp 2.4 kernel code */
118 +#define CCNT(a)     asm volatile ("mrc p14, 0, %0, C1, C1, 0" : "=r"(a))
119 +#define CCNT_ON()   asm("mcr p14, 0, %0, C0, C0, 0" : : "r"(1))
120 +#define CCNT_OFF()  asm("mcr p14, 0, %0, C0, C0, 0" : : "r"(0))
121 +
122 +/* On the Sharp SL-6000 (Tosa), due to a noisy LCD, we need to perform a wait
123 + * before sampling the Y axis of the touchscreen */
124 +static void tosa_lcd_sync_on(int adcsel)
125 +{
126 +       unsigned long timer1 = 0, timer2 = 0, wait_time = 0;
127 +       if (adcsel & WM97XX_ADCSEL_Y) {
128 +               CCNT_ON();
129 +               wait_time = hsync_time;
130 +
131 +               if (wait_time) {
132 +
133 +                       /* wait for LCD rising edge */
134 +                       tosa_lcd_wait_hsync();
135 +                       /* get clock */
136 +                       CCNT(timer1);
137 +                       CCNT(timer2);
138 +
139 +                       while ((timer2 - timer1) < wait_time) {
140 +                               CCNT(timer2);
141 +                       }
142 +               }
143 +       }
144 +}
145 +
146 +static void tosa_lcd_sync_off(int adcsel)
147 +{
148 +       if (adcsel & WM97XX_ADCSEL_Y)
149 +               CCNT_OFF();
150 +}
151 +
152 +static struct wm97xx_mach_ops tosa_mach_ops = {
153 +       .pre_sample =  tosa_lcd_sync_on,
154 +       .post_sample = tosa_lcd_sync_off,
155 +};
156 +
157 +static int __devinit tosa_ts_probe(struct platform_device *dev) {
158 +       struct wm97xx *wm = platform_get_drvdata(dev);
159 +       struct notifier_block *notif;
160 +       int err = -ENOMEM;
161 +
162 +       notif = kzalloc(sizeof(struct notifier_block), GFP_KERNEL);
163 +       if (!notif)
164 +               goto err_alloc;
165 +
166 +       notif->notifier_call = fb_notifier_callback;
167 +
168 +       err = gpio_request(TOSA_GPIO_VGA_LINE, "hsync");
169 +       if (err)
170 +               goto err_gpio;
171 +
172 +       err = gpio_direction_input(TOSA_GPIO_VGA_LINE);
173 +       if (err)
174 +               goto err_gpio;
175 +
176 +       platform_set_drvdata(dev, notif);
177 +
178 +       err = fb_register_client(notif);
179 +       if (err)
180 +               goto err_register;
181 +
182 +       err = wm97xx_register_mach_ops(wm, &tosa_mach_ops);
183 +       if (err)
184 +               goto err_wm97xx;
185 +
186 +       calc_hsync_time(tosa_lcd_get_mode());
187 +
188 +       return 0;
189 +
190 +err_wm97xx:
191 +       fb_unregister_client(notif);
192 +err_register:
193 +       gpio_free(TOSA_GPIO_VGA_LINE);
194 +err_gpio:
195 +       kfree(notif);
196 +err_alloc:
197 +       return err;
198 +}
199 +
200 +
201 +static int __devexit tosa_ts_remove(struct platform_device *dev) {
202 +       struct wm97xx *wm = platform_get_drvdata(dev);
203 +
204 +       wm97xx_unregister_mach_ops(wm);
205 +
206 +       fb_unregister_client(platform_get_drvdata(dev));
207 +       gpio_free(TOSA_GPIO_VGA_LINE);
208 +       kfree(platform_get_drvdata(dev));
209 +
210 +       return 0;
211 +}
212 +
213 +static struct platform_driver tosa_ts_driver = {
214 +       .driver.name = "wm97xx-touch",
215 +       .driver.owner = THIS_MODULE,
216 +       .probe = tosa_ts_probe,
217 +       .remove = __devexit_p(tosa_ts_remove),
218 +};
219 +
220 +static int __init tosa_ts_init(void)
221 +{
222 +       return platform_driver_register(&tosa_ts_driver);
223 +}
224 +
225 +static void __exit tosa_ts_exit(void)
226 +{
227 +       platform_driver_unregister(&tosa_ts_driver);
228 +}
229 +
230 +module_init(tosa_ts_init);
231 +module_exit(tosa_ts_exit);
232 +
233 +/* Module information */
234 +MODULE_AUTHOR("Dmitry Baryshkov, Mike Arthur, mike@mikearthur.co.uk, www.wolfsonmicro.com");
235 +MODULE_DESCRIPTION("Sharp SL6000 Tosa Touch Screen Denoiser");
236 +MODULE_LICENSE("GPL");
237 -- 
238 1.5.4.1
239