2 * input/touchscreen/omap/ts_hx.c
3 * touchscreen support for OMAP H3 and H2 boards
5 * Copyright (c) 2002 MontaVista Software Inc.
6 * Copyright (c) 2004 Texas Instruments, Inc.
8 * Assembled using driver code copyright the companies above.
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.
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.
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
25 * 9/12/2004 Srinath Modified and integrated H2 and H3 code
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>
37 #include "../drivers/ssi/omap-tsc2101.h"
41 #define H3_GPIO_NUM 48
42 #define H6300_GPIO_NUM 2
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)
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);
58 static void hx_ts_remove(void);
61 struct ts_device hx_ts = {
64 .enable = hx_ts_enable,
65 .disable = hx_ts_disable,
66 .remove = __exit_p(hx_ts_remove),
70 static int hx_ts_penup(void)
73 /* Read the status register */
74 ret = omap_tsc2101_read(TOUCHSCREEN_CONTROL_REGISTERS_PAGE,
76 /* Check for availability of data in status register */
77 ret = TSC2101_GETSTATUS(ret);
82 static int __init hx_ts_probe(struct omap_ts_t *ts)
86 if (machine_is_omap_h2()) {
88 omap_cfg_reg(P20_1610_GPIO4);
89 } else if (machine_is_omap_h3()) {
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);
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");
104 omap_set_gpio_direction(gpio, 1);
105 ts->irq_type = SA_TRIGGER_FALLING;
109 static void hx_ts_read(u16 * values)
114 /* Read X, Y, Z1 and Z2 */
115 omap_tsc2101_reads(TOUCHSCREEN_DATA_REGISTERS_PAGE, TSC2101_TS_X,
116 values, OMAP_TSC2101_READ_MAX);
118 for (i = 0; i < OMAP_TSC2101_READ_MAX; i++)
119 values[i] &= TSC2101_MASKVAL;
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]));
130 values[TSC2101_TS_Z1] = p;
133 static void hx_ts_enable(void)
135 int ret = omap_tsc2101_enable();
137 printk(KERN_ERR "FAILED TO INITIALIZE TSC CODEC\n");
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);
158 * TSC2101-controlled conversions
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
165 omap_tsc2101_write(TOUCHSCREEN_CONTROL_REGISTERS_PAGE,
166 TSC2101_TS_ADC_CTRL, TSC2101_ADC_CONTROL);
172 static void hx_ts_disable(void)
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();
181 static void __exit hx_ts_remove(void)
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);