]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/input/touchscreen/omap/ts_hx.c
h63xx: touchscreen support
[linux-2.6-omap-h63xx.git] / drivers / input / touchscreen / omap / ts_hx.c
1 /*
2  * input/touchscreen/omap/ts_hx.c
3  * touchscreen support for OMAP H3 and H2  boards
4  *
5  * Copyright (c) 2002 MontaVista Software Inc.
6  * Copyright (c) 2004 Texas Instruments, Inc.
7  *
8  * Assembled using driver code copyright the companies above.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  *
24  * History:
25  * 9/12/2004    Srinath Modified and integrated  H2 and H3 code
26  *
27  */
28
29 #include <linux/input.h>
30 #include <linux/device.h>
31 #include <asm/mach-types.h>
32 #include <asm/arch/gpio.h>
33 #include <asm/arch/mux.h>
34 #include <asm/arch/hardware.h>
35 #include <asm/hardware/tsc2101.h>
36
37 #include "../drivers/ssi/omap-tsc2101.h"
38 #include "omap_ts.h"
39
40 #define H2_GPIO_NUM             4
41 #define H3_GPIO_NUM             48
42 #define H6300_GPIO_NUM  2
43
44 #define OMAP_TSC2101_XRES                      500
45 #define TOUCHSCREEN_DATA_REGISTERS_PAGE  0x0
46 #define TOUCHSCREEN_CONTROL_REGISTERS_PAGE      0x1
47 #define OMAP_TSC2101_READ_MAX              0x4
48 #define TSC2101_GETSTATUS(ret)            (((ret) >> 11) & 0x1)
49 #define TSC2101_MASKVAL                  0xFFF
50 #define TSC2101_PRESSUREVAL(x)            ((x) << 12)
51
52 static int hx_ts_penup(void);
53 static int hx_ts_probe(struct omap_ts_t *ts);
54 static void hx_ts_read(u16 * data);
55 static void hx_ts_enable(void);
56 static void hx_ts_disable(void);
57 #ifdef  MODULE
58 static void hx_ts_remove(void);
59 #endif
60
61 struct ts_device hx_ts = {
62         .probe          = hx_ts_probe,
63         .read           = hx_ts_read,
64         .enable         = hx_ts_enable,
65         .disable        = hx_ts_disable,
66         .remove         = __exit_p(hx_ts_remove),
67         .penup          = hx_ts_penup,
68 };
69
70 static int hx_ts_penup(void)
71 {
72         int ret = 0;
73         /* Read the status register */
74         ret = omap_tsc2101_read(TOUCHSCREEN_CONTROL_REGISTERS_PAGE,
75                                 TSC2101_TS_STATUS);
76         /* Check for availability of data in status register */
77         ret = TSC2101_GETSTATUS(ret);
78         return !ret;
79
80 }
81
82 static int __init hx_ts_probe(struct omap_ts_t *ts)
83 {
84         unsigned        gpio;
85
86         if (machine_is_omap_h2()) {
87                 gpio = H2_GPIO_NUM;
88                 omap_cfg_reg(P20_1610_GPIO4);
89         } else if (machine_is_omap_h3()) {
90                 gpio = H3_GPIO_NUM;
91                 omap_cfg_reg(W19_1610_GPIO48);
92         } else if (machine_is_omap_h6300 ()) {
93                 gpio = H6300_GPIO_NUM;
94                 omap_cfg_reg(M14_1510_GPIO2);   
95         } else
96                 return -ENODEV;
97
98         ts->irq = OMAP_GPIO_IRQ(gpio);
99         if (omap_request_gpio(gpio) != 0) {
100                 printk(KERN_ERR "hX_ts_init.c: Could not reserve GPIO!\n");
101                 return -EINVAL;
102         };
103
104         omap_set_gpio_direction(gpio, 1);
105         ts->irq_type = SA_TRIGGER_FALLING;
106         return 0;
107 }
108
109 static void hx_ts_read(u16 * values)
110 {
111         s32 t, p = 0;
112         int i;
113
114         /* Read X, Y, Z1 and Z2 */
115         omap_tsc2101_reads(TOUCHSCREEN_DATA_REGISTERS_PAGE, TSC2101_TS_X,
116                            values, OMAP_TSC2101_READ_MAX);
117
118         for (i = 0; i < OMAP_TSC2101_READ_MAX; i++)
119                 values[i] &= TSC2101_MASKVAL;
120
121         /* Calculate Pressure */
122         if (values[TSC2101_TS_Z1] != 0) {
123                 t = ((OMAP_TSC2101_XRES * values[TSC2101_TS_X]) *
124                      (values[TSC2101_TS_Z2] - values[TSC2101_TS_Z1]));
125                 p = t / (u32) (TSC2101_PRESSUREVAL(values[TSC2101_TS_Z1]));
126                 if (p < 0)
127                         p = 0;
128         }
129
130         values[TSC2101_TS_Z1] = p;
131 }
132
133 static void hx_ts_enable(void)
134 {
135         int ret = omap_tsc2101_enable();
136         if (ret) {
137                 printk(KERN_ERR "FAILED TO INITIALIZE TSC CODEC\n");
138                 return;
139         }
140
141         /* PINTDAV is data available only */
142         omap_tsc2101_write(TOUCHSCREEN_CONTROL_REGISTERS_PAGE,
143                            TSC2101_TS_STATUS, TSC2101_DATA_AVAILABLE);
144         /* disable buffer mode */
145         omap_tsc2101_write(TOUCHSCREEN_CONTROL_REGISTERS_PAGE,
146                            TSC2101_TS_BUFFER_CTRL, TSC2101_BUFFERMODE_DISABLE);
147         /* use internal reference, 100 usec power-up delay,
148          *        * power down between conversions, 1.25V internal reference */
149         omap_tsc2101_write(TOUCHSCREEN_CONTROL_REGISTERS_PAGE,
150                            TSC2101_TS_REF_CTRL, TSC2101_REF_POWERUP);
151         /* enable touch detection, 84usec precharge time, 32 usec sense time */
152         omap_tsc2101_write(TOUCHSCREEN_CONTROL_REGISTERS_PAGE,
153                            TSC2101_TS_CONFIG_CTRL, TSC2101_ENABLE_TOUCHDETECT);
154         /* 3 msec conversion delays  */
155         omap_tsc2101_write(TOUCHSCREEN_CONTROL_REGISTERS_PAGE,
156                            TSC2101_TS_PROG_DELAY, TSC2101_PRG_DELAY);
157         /*
158          * TSC2101-controlled conversions
159          * 12-bit samples
160          * continuous X,Y,Z1,Z2 scan mode
161          * average (mean) 4 samples per coordinate
162          * 1 MHz internal conversion clock
163          * 500 usec panel voltage stabilization delay
164          */
165         omap_tsc2101_write(TOUCHSCREEN_CONTROL_REGISTERS_PAGE,
166                            TSC2101_TS_ADC_CTRL, TSC2101_ADC_CONTROL);
167
168         return;
169
170 }
171
172 static void hx_ts_disable(void)
173 {
174         /* stop conversions and power down */
175         omap_tsc2101_write(TOUCHSCREEN_CONTROL_REGISTERS_PAGE,
176                            TSC2101_TS_ADC_CTRL, TSC2101_ADC_POWERDOWN);
177         omap_tsc2101_disable();
178 }
179
180 #ifdef  MODULE
181 static void __exit hx_ts_remove(void)
182 {
183         if (machine_is_omap_h2())
184                 omap_free_gpio(H2_GPIO_NUM);
185         else if (machine_is_omap_h3())
186                 omap_free_gpio(H3_GPIO_NUM);
187         else if (machine_is_omap_h6300())
188                 omap_free_gpio(H6300_GPIO_NUM);
189 }
190 #endif