2 * ts_inn1510.c - touchscreen support for OMAP1510 Innovator board
4 * Copyright 2002 MontaVista Software Inc.
5 * Author: MontaVista Software, Inc.
6 * stevel@mvista.com or source@mvista.com
8 * The touchscreen hardware on the Innovator consists of an FPGA
9 * register which is bit-banged to generate SPI-like transactions
10 * to an ADS7846 touch screen controller.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include <linux/input.h>
28 #include <linux/device.h>
30 #include <asm/mach-types.h>
31 #include <asm/arch/fpga.h>
36 // The Touch Screen Register on Innovator FPGA
37 #define FPGA_TS_BCLK (1<<0)
38 #define FPGA_TS_BDIN (1<<1)
39 #define FPGA_TS_BCS (1<<2)
40 #define FPGA_TS_BBUSY (1<<3)
41 #define FPGA_TS_BOUT (1<<4)
42 #define FPGA_TS_BPENUP (1<<5)
44 #define X_PLATE_OHMS 419
45 #define Y_PLATE_OHMS 486
47 static int inn1510_ts_penup(void);
48 static int inn1510_ts_probe(struct omap_ts_t *ts);
49 static void inn1510_ts_read(u16 * data);
50 static void inn1510_ts_enable(void);
51 static void inn1510_ts_disable(void);
53 static void inn1510_ts_remove(void);
56 struct ts_device innovator1510_ts = {
57 .probe = inn1510_ts_probe,
58 .read = inn1510_ts_read,
59 .enable = inn1510_ts_enable,
60 .disable = inn1510_ts_disable,
61 .remove = __exit_p(inn1510_ts_remove),
62 .penup = inn1510_ts_penup,
65 static inline u8 fpga_ts_read(void)
67 return fpga_read(OMAP1510_FPGA_TOUCHSCREEN);
70 static inline void fpga_ts_write(u8 val)
72 fpga_write(val, OMAP1510_FPGA_TOUCHSCREEN);
75 static inline void fpga_ts_set_bits(u8 mask)
77 fpga_ts_write(fpga_ts_read() | mask);
80 static inline void fpga_ts_clear_bits(u8 mask)
82 fpga_ts_write(fpga_ts_read() & ~mask);
85 static inline void CS_H(void)
87 // EPLD inverts active low signals.
88 fpga_ts_clear_bits(FPGA_TS_BCS);
91 static inline void CS_L(void)
93 fpga_ts_set_bits(FPGA_TS_BCS);
96 static inline void SCLK_L(void)
98 fpga_ts_clear_bits(FPGA_TS_BCLK);
101 static inline void SCLK_H(void)
103 fpga_ts_set_bits(FPGA_TS_BCLK);
106 static inline void SDI_L(void)
108 fpga_ts_clear_bits(FPGA_TS_BDIN);
111 static inline void SDI_H(void)
113 fpga_ts_set_bits(FPGA_TS_BDIN);
116 static inline int BUSY(void)
118 return (((fpga_ts_read() & FPGA_TS_BBUSY) == 0) ? 1 : 0) ;
121 static inline u8 DOUT(void)
123 return ((fpga_ts_read() & FPGA_TS_BOUT) ? 1 : 0) ;
126 static u16 ads7846_do(u8 cmd)
133 CS_L() ; // enable the chip select
135 // send the command to the ADS7846
136 for (i=0; i<8; i++ ) {
140 SDI_L(); // prepare the data on line sdi OR din
142 SCLK_H() ; // clk in the data
151 // now read returned data
152 for (i=0 ; i<16 ; i++ ) {
163 CS_H() ; // disable the chip select
168 static int inn1510_ts_penup(void)
170 return ((fpga_ts_read() & FPGA_TS_BPENUP) ? 0 : 1) ;
173 static int __init inn1510_ts_probe(struct omap_ts_t *ts)
175 if (!cpu_is_omap15xx() || !machine_is_omap_innovator())
178 ts->irq = OMAP1510_INT_FPGA_TS;
179 ts->irq_type = SA_SAMPLE_RANDOM;
184 static void inn1510_ts_read(u16 *data)
188 data[0] = ads7846_do(MEASURE_12BIT_X);
189 data[1] = ads7846_do(MEASURE_12BIT_Y);
190 data[2] = ads7846_do(MEASURE_12BIT_Z1);
191 data[3] = ads7846_do(MEASURE_12BIT_Z2);
193 // Calculate touch pressure resistance
195 Rt = (X_PLATE_OHMS * (u32)data[0] *
196 ((u32)data[3] - (u32)data[2])) / (u32)data[2];
198 Rt = (Rt + 2048) >> 12; // round up to nearest ohm
204 static void inn1510_ts_enable(void)
209 static void inn1510_ts_disable(void)
215 static void __exit inn1510_ts_remove(void)
217 /* Nothing to do here */