David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 1 | /* |
| 2 | * ADS7846 based touchscreen and sensor driver |
| 3 | * |
| 4 | * Copyright (c) 2005 David Brownell |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 5 | * Copyright (c) 2006 Nokia Corporation |
| 6 | * Various changes: Imre Deak <imre.deak@nokia.com> |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 7 | * |
| 8 | * Using code from: |
| 9 | * - corgi_ts.c |
| 10 | * Copyright (C) 2004-2005 Richard Purdie |
| 11 | * - omap_ts.[hc], ads7846.h, ts_osk.c |
| 12 | * Copyright (C) 2002 MontaVista Software |
| 13 | * Copyright (C) 2004 Texas Instruments |
| 14 | * Copyright (C) 2005 Dirk Behme |
| 15 | * |
| 16 | * This program is free software; you can redistribute it and/or modify |
| 17 | * it under the terms of the GNU General Public License version 2 as |
| 18 | * published by the Free Software Foundation. |
| 19 | */ |
| 20 | #include <linux/device.h> |
| 21 | #include <linux/init.h> |
| 22 | #include <linux/delay.h> |
| 23 | #include <linux/input.h> |
| 24 | #include <linux/interrupt.h> |
| 25 | #include <linux/slab.h> |
| 26 | #include <linux/spi/spi.h> |
| 27 | #include <linux/spi/ads7846.h> |
Andrew Morton | 3ac8bf0 | 2006-03-26 01:37:33 -0800 | [diff] [blame] | 28 | #include <asm/irq.h> |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 29 | |
| 30 | #ifdef CONFIG_ARM |
| 31 | #include <asm/mach-types.h> |
| 32 | #ifdef CONFIG_ARCH_OMAP |
| 33 | #include <asm/arch/gpio.h> |
| 34 | #endif |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 35 | #endif |
| 36 | |
| 37 | |
| 38 | /* |
David Brownell | 9084533 | 2006-05-25 18:44:20 -0700 | [diff] [blame] | 39 | * This code has been heavily tested on a Nokia 770, and lightly |
| 40 | * tested on other ads7846 devices (OSK/Mistral, Lubbock). |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 41 | * Support for ads7843 and ads7845 has only been stubbed in. |
| 42 | * |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 43 | * IRQ handling needs a workaround because of a shortcoming in handling |
| 44 | * edge triggered IRQs on some platforms like the OMAP1/2. These |
| 45 | * platforms don't handle the ARM lazy IRQ disabling properly, thus we |
| 46 | * have to maintain our own SW IRQ disabled status. This should be |
| 47 | * removed as soon as the affected platform's IRQ handling is fixed. |
| 48 | * |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 49 | * app note sbaa036 talks in more detail about accurate sampling... |
| 50 | * that ought to help in situations like LCDs inducing noise (which |
| 51 | * can also be helped by using synch signals) and more generally. |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 52 | * This driver tries to utilize the measures described in the app |
| 53 | * note. The strength of filtering can be set in the board-* specific |
| 54 | * files. |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 55 | */ |
| 56 | |
| 57 | #define TS_POLL_PERIOD msecs_to_jiffies(10) |
| 58 | |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 59 | /* this driver doesn't aim at the peak continuous sample rate */ |
| 60 | #define SAMPLE_BITS (8 /*cmd*/ + 16 /*sample*/ + 2 /* before, after */) |
| 61 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 62 | struct ts_event { |
| 63 | /* For portability, we can't read 12 bit values using SPI (which |
| 64 | * would make the controller deliver them as native byteorder u16 |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 65 | * with msbs zeroed). Instead, we read them as two 8-bit values, |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 66 | * *** WHICH NEED BYTESWAPPING *** and range adjustment. |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 67 | */ |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 68 | u16 x; |
| 69 | u16 y; |
| 70 | u16 z1, z2; |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 71 | int ignore; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | struct ads7846 { |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 75 | struct input_dev *input; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 76 | char phys[32]; |
| 77 | |
| 78 | struct spi_device *spi; |
Dmitry Torokhov | 8dd5165 | 2006-11-02 23:34:09 -0500 | [diff] [blame] | 79 | struct attribute_group *attr_group; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 80 | u16 model; |
| 81 | u16 vref_delay_usecs; |
| 82 | u16 x_plate_ohms; |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 83 | u16 pressure_max; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 84 | |
Imre Deak | 53a0ef89 | 2006-04-11 23:41:49 -0400 | [diff] [blame] | 85 | u8 read_x, read_y, read_z1, read_z2, pwrdown; |
| 86 | u16 dummy; /* for the pwrdown read */ |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 87 | struct ts_event tc; |
| 88 | |
Imre Deak | 53a0ef89 | 2006-04-11 23:41:49 -0400 | [diff] [blame] | 89 | struct spi_transfer xfer[10]; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 90 | struct spi_message msg[5]; |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 91 | struct spi_message *last_msg; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 92 | int msg_idx; |
| 93 | int read_cnt; |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 94 | int read_rep; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 95 | int last_read; |
| 96 | |
| 97 | u16 debounce_max; |
| 98 | u16 debounce_tol; |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 99 | u16 debounce_rep; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 100 | |
| 101 | spinlock_t lock; |
| 102 | struct timer_list timer; /* P: lock */ |
| 103 | unsigned pendown:1; /* P: lock */ |
| 104 | unsigned pending:1; /* P: lock */ |
| 105 | // FIXME remove "irq_disabled" |
| 106 | unsigned irq_disabled:1; /* P: lock */ |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 107 | unsigned disabled:1; |
Imre Deak | c9e617a | 2006-04-11 23:44:05 -0400 | [diff] [blame] | 108 | |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 109 | int (*filter)(void *data, int data_idx, int *val); |
| 110 | void *filter_data; |
| 111 | void (*filter_cleanup)(void *data); |
Imre Deak | c9e617a | 2006-04-11 23:44:05 -0400 | [diff] [blame] | 112 | int (*get_pendown_state)(void); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | /* leave chip selected when we're done, for quicker re-select? */ |
| 116 | #if 0 |
| 117 | #define CS_CHANGE(xfer) ((xfer).cs_change = 1) |
| 118 | #else |
| 119 | #define CS_CHANGE(xfer) ((xfer).cs_change = 0) |
| 120 | #endif |
| 121 | |
| 122 | /*--------------------------------------------------------------------------*/ |
| 123 | |
| 124 | /* The ADS7846 has touchscreen and other sensors. |
| 125 | * Earlier ads784x chips are somewhat compatible. |
| 126 | */ |
| 127 | #define ADS_START (1 << 7) |
| 128 | #define ADS_A2A1A0_d_y (1 << 4) /* differential */ |
| 129 | #define ADS_A2A1A0_d_z1 (3 << 4) /* differential */ |
| 130 | #define ADS_A2A1A0_d_z2 (4 << 4) /* differential */ |
| 131 | #define ADS_A2A1A0_d_x (5 << 4) /* differential */ |
| 132 | #define ADS_A2A1A0_temp0 (0 << 4) /* non-differential */ |
| 133 | #define ADS_A2A1A0_vbatt (2 << 4) /* non-differential */ |
| 134 | #define ADS_A2A1A0_vaux (6 << 4) /* non-differential */ |
| 135 | #define ADS_A2A1A0_temp1 (7 << 4) /* non-differential */ |
| 136 | #define ADS_8_BIT (1 << 3) |
| 137 | #define ADS_12_BIT (0 << 3) |
| 138 | #define ADS_SER (1 << 2) /* non-differential */ |
| 139 | #define ADS_DFR (0 << 2) /* differential */ |
| 140 | #define ADS_PD10_PDOWN (0 << 0) /* lowpower mode + penirq */ |
| 141 | #define ADS_PD10_ADC_ON (1 << 0) /* ADC on */ |
| 142 | #define ADS_PD10_REF_ON (2 << 0) /* vREF on + penirq */ |
| 143 | #define ADS_PD10_ALL_ON (3 << 0) /* ADC + vREF on */ |
| 144 | |
| 145 | #define MAX_12BIT ((1<<12)-1) |
| 146 | |
| 147 | /* leave ADC powered up (disables penirq) between differential samples */ |
Imre Deak | de2defd | 2007-01-18 00:45:21 -0500 | [diff] [blame^] | 148 | #define READ_12BIT_DFR(x, adc, vref) (ADS_START | ADS_A2A1A0_d_ ## x \ |
| 149 | | ADS_12_BIT | ADS_DFR | \ |
| 150 | (adc ? ADS_PD10_ADC_ON : 0) | (vref ? ADS_PD10_REF_ON : 0)) |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 151 | |
Imre Deak | de2defd | 2007-01-18 00:45:21 -0500 | [diff] [blame^] | 152 | #define READ_Y(vref) (READ_12BIT_DFR(y, 1, vref)) |
| 153 | #define READ_Z1(vref) (READ_12BIT_DFR(z1, 1, vref)) |
| 154 | #define READ_Z2(vref) (READ_12BIT_DFR(z2, 1, vref)) |
Imre Deak | 53a0ef89 | 2006-04-11 23:41:49 -0400 | [diff] [blame] | 155 | |
Imre Deak | de2defd | 2007-01-18 00:45:21 -0500 | [diff] [blame^] | 156 | #define READ_X(vref) (READ_12BIT_DFR(x, 1, vref)) |
| 157 | #define PWRDOWN (READ_12BIT_DFR(y, 0, 0)) /* LAST */ |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 158 | |
| 159 | /* single-ended samples need to first power up reference voltage; |
| 160 | * we leave both ADC and VREF powered |
| 161 | */ |
| 162 | #define READ_12BIT_SER(x) (ADS_START | ADS_A2A1A0_ ## x \ |
| 163 | | ADS_12_BIT | ADS_SER) |
| 164 | |
Imre Deak | de2defd | 2007-01-18 00:45:21 -0500 | [diff] [blame^] | 165 | #define REF_ON (READ_12BIT_DFR(x, 1, 1)) |
| 166 | #define REF_OFF (READ_12BIT_DFR(y, 0, 0)) |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 167 | |
| 168 | /*--------------------------------------------------------------------------*/ |
| 169 | |
| 170 | /* |
| 171 | * Non-touchscreen sensors only use single-ended conversions. |
| 172 | */ |
| 173 | |
| 174 | struct ser_req { |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 175 | u8 ref_on; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 176 | u8 command; |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 177 | u8 ref_off; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 178 | u16 scratch; |
| 179 | __be16 sample; |
| 180 | struct spi_message msg; |
| 181 | struct spi_transfer xfer[6]; |
| 182 | }; |
| 183 | |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 184 | static void ads7846_enable(struct ads7846 *ts); |
| 185 | static void ads7846_disable(struct ads7846 *ts); |
| 186 | |
Imre Deak | c9e617a | 2006-04-11 23:44:05 -0400 | [diff] [blame] | 187 | static int device_suspended(struct device *dev) |
| 188 | { |
| 189 | struct ads7846 *ts = dev_get_drvdata(dev); |
| 190 | return dev->power.power_state.event != PM_EVENT_ON || ts->disabled; |
| 191 | } |
| 192 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 193 | static int ads7846_read12_ser(struct device *dev, unsigned command) |
| 194 | { |
| 195 | struct spi_device *spi = to_spi_device(dev); |
| 196 | struct ads7846 *ts = dev_get_drvdata(dev); |
Christoph Lameter | e94b176 | 2006-12-06 20:33:17 -0800 | [diff] [blame] | 197 | struct ser_req *req = kzalloc(sizeof *req, GFP_KERNEL); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 198 | int status; |
| 199 | int sample; |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 200 | int i; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 201 | |
| 202 | if (!req) |
| 203 | return -ENOMEM; |
| 204 | |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 205 | spi_message_init(&req->msg); |
Vitaly Wool | 8275c64 | 2006-01-08 13:34:28 -0800 | [diff] [blame] | 206 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 207 | /* activate reference, so it has time to settle; */ |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 208 | req->ref_on = REF_ON; |
| 209 | req->xfer[0].tx_buf = &req->ref_on; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 210 | req->xfer[0].len = 1; |
| 211 | req->xfer[1].rx_buf = &req->scratch; |
| 212 | req->xfer[1].len = 2; |
| 213 | |
| 214 | /* |
| 215 | * for external VREF, 0 usec (and assume it's always on); |
| 216 | * for 1uF, use 800 usec; |
| 217 | * no cap, 100 usec. |
| 218 | */ |
| 219 | req->xfer[1].delay_usecs = ts->vref_delay_usecs; |
| 220 | |
| 221 | /* take sample */ |
| 222 | req->command = (u8) command; |
| 223 | req->xfer[2].tx_buf = &req->command; |
| 224 | req->xfer[2].len = 1; |
| 225 | req->xfer[3].rx_buf = &req->sample; |
| 226 | req->xfer[3].len = 2; |
| 227 | |
| 228 | /* REVISIT: take a few more samples, and compare ... */ |
| 229 | |
| 230 | /* turn off reference */ |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 231 | req->ref_off = REF_OFF; |
| 232 | req->xfer[4].tx_buf = &req->ref_off; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 233 | req->xfer[4].len = 1; |
| 234 | req->xfer[5].rx_buf = &req->scratch; |
| 235 | req->xfer[5].len = 2; |
| 236 | |
| 237 | CS_CHANGE(req->xfer[5]); |
| 238 | |
| 239 | /* group all the transfers together, so we can't interfere with |
| 240 | * reading touchscreen state; disable penirq while sampling |
| 241 | */ |
Vitaly Wool | 8275c64 | 2006-01-08 13:34:28 -0800 | [diff] [blame] | 242 | for (i = 0; i < 6; i++) |
| 243 | spi_message_add_tail(&req->xfer[i], &req->msg); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 244 | |
Imre Deak | c9e617a | 2006-04-11 23:44:05 -0400 | [diff] [blame] | 245 | ts->irq_disabled = 1; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 246 | disable_irq(spi->irq); |
| 247 | status = spi_sync(spi, &req->msg); |
Imre Deak | c9e617a | 2006-04-11 23:44:05 -0400 | [diff] [blame] | 248 | ts->irq_disabled = 0; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 249 | enable_irq(spi->irq); |
| 250 | |
| 251 | if (req->msg.status) |
| 252 | status = req->msg.status; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 253 | |
David Brownell | 9084533 | 2006-05-25 18:44:20 -0700 | [diff] [blame] | 254 | /* on-wire is a must-ignore bit, a BE12 value, then padding */ |
| 255 | sample = be16_to_cpu(req->sample); |
| 256 | sample = sample >> 3; |
| 257 | sample &= 0x0fff; |
| 258 | |
| 259 | kfree(req); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 260 | return status ? status : sample; |
| 261 | } |
| 262 | |
| 263 | #define SHOW(name) static ssize_t \ |
| 264 | name ## _show(struct device *dev, struct device_attribute *attr, char *buf) \ |
| 265 | { \ |
| 266 | ssize_t v = ads7846_read12_ser(dev, \ |
| 267 | READ_12BIT_SER(name) | ADS_PD10_ALL_ON); \ |
| 268 | if (v < 0) \ |
| 269 | return v; \ |
| 270 | return sprintf(buf, "%u\n", (unsigned) v); \ |
| 271 | } \ |
| 272 | static DEVICE_ATTR(name, S_IRUGO, name ## _show, NULL); |
| 273 | |
| 274 | SHOW(temp0) |
| 275 | SHOW(temp1) |
| 276 | SHOW(vaux) |
| 277 | SHOW(vbatt) |
| 278 | |
Imre Deak | 438f2a7 | 2006-04-11 23:41:32 -0400 | [diff] [blame] | 279 | static int is_pen_down(struct device *dev) |
| 280 | { |
| 281 | struct ads7846 *ts = dev_get_drvdata(dev); |
| 282 | |
| 283 | return ts->pendown; |
| 284 | } |
| 285 | |
| 286 | static ssize_t ads7846_pen_down_show(struct device *dev, |
| 287 | struct device_attribute *attr, char *buf) |
| 288 | { |
| 289 | return sprintf(buf, "%u\n", is_pen_down(dev)); |
| 290 | } |
| 291 | |
| 292 | static DEVICE_ATTR(pen_down, S_IRUGO, ads7846_pen_down_show, NULL); |
| 293 | |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 294 | static ssize_t ads7846_disable_show(struct device *dev, |
| 295 | struct device_attribute *attr, char *buf) |
| 296 | { |
| 297 | struct ads7846 *ts = dev_get_drvdata(dev); |
| 298 | |
| 299 | return sprintf(buf, "%u\n", ts->disabled); |
| 300 | } |
| 301 | |
| 302 | static ssize_t ads7846_disable_store(struct device *dev, |
| 303 | struct device_attribute *attr, |
| 304 | const char *buf, size_t count) |
| 305 | { |
| 306 | struct ads7846 *ts = dev_get_drvdata(dev); |
| 307 | char *endp; |
| 308 | int i; |
| 309 | |
| 310 | i = simple_strtoul(buf, &endp, 10); |
| 311 | spin_lock_irq(&ts->lock); |
| 312 | |
| 313 | if (i) |
| 314 | ads7846_disable(ts); |
| 315 | else |
| 316 | ads7846_enable(ts); |
| 317 | |
| 318 | spin_unlock_irq(&ts->lock); |
| 319 | |
| 320 | return count; |
| 321 | } |
| 322 | |
| 323 | static DEVICE_ATTR(disable, 0664, ads7846_disable_show, ads7846_disable_store); |
| 324 | |
Dmitry Torokhov | 8dd5165 | 2006-11-02 23:34:09 -0500 | [diff] [blame] | 325 | static struct attribute *ads7846_attributes[] = { |
| 326 | &dev_attr_temp0.attr, |
| 327 | &dev_attr_temp1.attr, |
| 328 | &dev_attr_vbatt.attr, |
| 329 | &dev_attr_vaux.attr, |
| 330 | &dev_attr_pen_down.attr, |
| 331 | &dev_attr_disable.attr, |
| 332 | NULL, |
| 333 | }; |
| 334 | |
| 335 | static struct attribute_group ads7846_attr_group = { |
| 336 | .attrs = ads7846_attributes, |
| 337 | }; |
| 338 | |
| 339 | /* |
| 340 | * ads7843/7845 don't have temperature sensors, and |
| 341 | * use the other sensors a bit differently too |
| 342 | */ |
| 343 | |
| 344 | static struct attribute *ads7843_attributes[] = { |
| 345 | &dev_attr_vbatt.attr, |
| 346 | &dev_attr_vaux.attr, |
| 347 | &dev_attr_pen_down.attr, |
| 348 | &dev_attr_disable.attr, |
| 349 | NULL, |
| 350 | }; |
| 351 | |
| 352 | static struct attribute_group ads7843_attr_group = { |
| 353 | .attrs = ads7843_attributes, |
| 354 | }; |
| 355 | |
| 356 | static struct attribute *ads7845_attributes[] = { |
| 357 | &dev_attr_vaux.attr, |
| 358 | &dev_attr_pen_down.attr, |
| 359 | &dev_attr_disable.attr, |
| 360 | NULL, |
| 361 | }; |
| 362 | |
| 363 | static struct attribute_group ads7845_attr_group = { |
| 364 | .attrs = ads7845_attributes, |
| 365 | }; |
| 366 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 367 | /*--------------------------------------------------------------------------*/ |
| 368 | |
| 369 | /* |
| 370 | * PENIRQ only kicks the timer. The timer only reissues the SPI transfer, |
| 371 | * to retrieve touchscreen status. |
| 372 | * |
| 373 | * The SPI transfer completion callback does the real work. It reports |
| 374 | * touchscreen events and reactivates the timer (or IRQ) as appropriate. |
| 375 | */ |
| 376 | |
| 377 | static void ads7846_rx(void *ads) |
| 378 | { |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 379 | struct ads7846 *ts = ads; |
| 380 | struct input_dev *input_dev = ts->input; |
| 381 | unsigned Rt; |
| 382 | unsigned sync = 0; |
| 383 | u16 x, y, z1, z2; |
| 384 | unsigned long flags; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 385 | |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 386 | /* ads7846_rx_val() did in-place conversion (including byteswap) from |
| 387 | * on-the-wire format as part of debouncing to get stable readings. |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 388 | */ |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 389 | x = ts->tc.x; |
| 390 | y = ts->tc.y; |
| 391 | z1 = ts->tc.z1; |
| 392 | z2 = ts->tc.z2; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 393 | |
| 394 | /* range filtering */ |
| 395 | if (x == MAX_12BIT) |
| 396 | x = 0; |
| 397 | |
Imre Deak | c9e617a | 2006-04-11 23:44:05 -0400 | [diff] [blame] | 398 | if (likely(x && z1 && !device_suspended(&ts->spi->dev))) { |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 399 | /* compute touch pressure resistance using equation #2 */ |
| 400 | Rt = z2; |
| 401 | Rt -= z1; |
| 402 | Rt *= x; |
| 403 | Rt *= ts->x_plate_ohms; |
| 404 | Rt /= z1; |
| 405 | Rt = (Rt + 2047) >> 12; |
| 406 | } else |
| 407 | Rt = 0; |
| 408 | |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 409 | /* Sample found inconsistent by debouncing or pressure is beyond |
| 410 | * the maximum. Don't report it to user space, repeat at least |
| 411 | * once more the measurement */ |
| 412 | if (ts->tc.ignore || Rt > ts->pressure_max) { |
| 413 | mod_timer(&ts->timer, jiffies + TS_POLL_PERIOD); |
| 414 | return; |
| 415 | } |
| 416 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 417 | /* NOTE: "pendown" is inferred from pressure; we don't rely on |
| 418 | * being able to check nPENIRQ status, or "friendly" trigger modes |
| 419 | * (both-edges is much better than just-falling or low-level). |
| 420 | * |
| 421 | * REVISIT: some boards may require reading nPENIRQ; it's |
| 422 | * needed on 7843. and 7845 reads pressure differently... |
| 423 | * |
| 424 | * REVISIT: the touchscreen might not be connected; this code |
| 425 | * won't notice that, even if nPENIRQ never fires ... |
| 426 | */ |
| 427 | if (!ts->pendown && Rt != 0) { |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 428 | input_report_key(input_dev, BTN_TOUCH, 1); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 429 | sync = 1; |
| 430 | } else if (ts->pendown && Rt == 0) { |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 431 | input_report_key(input_dev, BTN_TOUCH, 0); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 432 | sync = 1; |
| 433 | } |
| 434 | |
| 435 | if (Rt) { |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 436 | input_report_abs(input_dev, ABS_X, x); |
| 437 | input_report_abs(input_dev, ABS_Y, y); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 438 | sync = 1; |
| 439 | } |
Imre Deak | ae82d5a | 2006-04-26 00:12:14 -0400 | [diff] [blame] | 440 | |
| 441 | if (sync) { |
| 442 | input_report_abs(input_dev, ABS_PRESSURE, Rt); |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 443 | input_sync(input_dev); |
Imre Deak | ae82d5a | 2006-04-26 00:12:14 -0400 | [diff] [blame] | 444 | } |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 445 | |
| 446 | #ifdef VERBOSE |
| 447 | if (Rt || ts->pendown) |
| 448 | pr_debug("%s: %d/%d/%d%s\n", ts->spi->dev.bus_id, |
| 449 | x, y, Rt, Rt ? "" : " UP"); |
| 450 | #endif |
| 451 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 452 | spin_lock_irqsave(&ts->lock, flags); |
| 453 | |
| 454 | ts->pendown = (Rt != 0); |
Imre Deak | c9e617a | 2006-04-11 23:44:05 -0400 | [diff] [blame] | 455 | mod_timer(&ts->timer, jiffies + TS_POLL_PERIOD); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 456 | |
| 457 | spin_unlock_irqrestore(&ts->lock, flags); |
| 458 | } |
| 459 | |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 460 | static int ads7846_debounce(void *ads, int data_idx, int *val) |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 461 | { |
| 462 | struct ads7846 *ts = ads; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 463 | |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 464 | if (!ts->read_cnt || (abs(ts->last_read - *val) > ts->debounce_tol)) { |
| 465 | /* Start over collecting consistent readings. */ |
| 466 | ts->read_rep = 0; |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 467 | /* Repeat it, if this was the first read or the read |
| 468 | * wasn't consistent enough. */ |
| 469 | if (ts->read_cnt < ts->debounce_max) { |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 470 | ts->last_read = *val; |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 471 | ts->read_cnt++; |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 472 | return ADS7846_FILTER_REPEAT; |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 473 | } else { |
| 474 | /* Maximum number of debouncing reached and still |
| 475 | * not enough number of consistent readings. Abort |
| 476 | * the whole sample, repeat it in the next sampling |
| 477 | * period. |
| 478 | */ |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 479 | ts->read_cnt = 0; |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 480 | return ADS7846_FILTER_IGNORE; |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 481 | } |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 482 | } else { |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 483 | if (++ts->read_rep > ts->debounce_rep) { |
| 484 | /* Got a good reading for this coordinate, |
| 485 | * go for the next one. */ |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 486 | ts->read_cnt = 0; |
| 487 | ts->read_rep = 0; |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 488 | return ADS7846_FILTER_OK; |
| 489 | } else { |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 490 | /* Read more values that are consistent. */ |
| 491 | ts->read_cnt++; |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 492 | return ADS7846_FILTER_REPEAT; |
| 493 | } |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | static int ads7846_no_filter(void *ads, int data_idx, int *val) |
| 498 | { |
| 499 | return ADS7846_FILTER_OK; |
| 500 | } |
| 501 | |
| 502 | static void ads7846_rx_val(void *ads) |
| 503 | { |
| 504 | struct ads7846 *ts = ads; |
| 505 | struct spi_message *m; |
| 506 | struct spi_transfer *t; |
| 507 | u16 *rx_val; |
| 508 | int val; |
| 509 | int action; |
| 510 | int status; |
| 511 | |
| 512 | m = &ts->msg[ts->msg_idx]; |
| 513 | t = list_entry(m->transfers.prev, struct spi_transfer, transfer_list); |
| 514 | rx_val = t->rx_buf; |
| 515 | |
| 516 | /* adjust: on-wire is a must-ignore bit, a BE12 value, then padding; |
| 517 | * built from two 8 bit values written msb-first. |
| 518 | */ |
| 519 | val = be16_to_cpu(*rx_val) >> 3; |
| 520 | |
| 521 | action = ts->filter(ts->filter_data, ts->msg_idx, &val); |
| 522 | switch (action) { |
| 523 | case ADS7846_FILTER_REPEAT: |
| 524 | break; |
| 525 | case ADS7846_FILTER_IGNORE: |
| 526 | ts->tc.ignore = 1; |
| 527 | /* Last message will contain ads7846_rx() as the |
| 528 | * completion function. |
| 529 | */ |
| 530 | m = ts->last_msg; |
| 531 | break; |
| 532 | case ADS7846_FILTER_OK: |
| 533 | *rx_val = val; |
| 534 | ts->tc.ignore = 0; |
| 535 | m = &ts->msg[++ts->msg_idx]; |
| 536 | break; |
| 537 | default: |
| 538 | BUG(); |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 539 | } |
| 540 | status = spi_async(ts->spi, m); |
| 541 | if (status) |
| 542 | dev_err(&ts->spi->dev, "spi_async --> %d\n", |
| 543 | status); |
| 544 | } |
| 545 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 546 | static void ads7846_timer(unsigned long handle) |
| 547 | { |
| 548 | struct ads7846 *ts = (void *)handle; |
| 549 | int status = 0; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 550 | |
Imre Deak | c9e617a | 2006-04-11 23:44:05 -0400 | [diff] [blame] | 551 | spin_lock_irq(&ts->lock); |
| 552 | |
| 553 | if (unlikely(ts->msg_idx && !ts->pendown)) { |
David Brownell | 9084533 | 2006-05-25 18:44:20 -0700 | [diff] [blame] | 554 | /* measurement cycle ended */ |
Imre Deak | c9e617a | 2006-04-11 23:44:05 -0400 | [diff] [blame] | 555 | if (!device_suspended(&ts->spi->dev)) { |
| 556 | ts->irq_disabled = 0; |
| 557 | enable_irq(ts->spi->irq); |
| 558 | } |
| 559 | ts->pending = 0; |
| 560 | ts->msg_idx = 0; |
| 561 | } else { |
| 562 | /* pen is still down, continue with the measurement */ |
| 563 | ts->msg_idx = 0; |
| 564 | status = spi_async(ts->spi, &ts->msg[0]); |
| 565 | if (status) |
| 566 | dev_err(&ts->spi->dev, "spi_async --> %d\n", status); |
| 567 | } |
| 568 | |
| 569 | spin_unlock_irq(&ts->lock); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 570 | } |
| 571 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 572 | static irqreturn_t ads7846_irq(int irq, void *handle) |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 573 | { |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 574 | struct ads7846 *ts = handle; |
| 575 | unsigned long flags; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 576 | |
| 577 | spin_lock_irqsave(&ts->lock, flags); |
Imre Deak | c9e617a | 2006-04-11 23:44:05 -0400 | [diff] [blame] | 578 | if (likely(ts->get_pendown_state())) { |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 579 | if (!ts->irq_disabled) { |
David Brownell | 9084533 | 2006-05-25 18:44:20 -0700 | [diff] [blame] | 580 | /* The ARM do_simple_IRQ() dispatcher doesn't act |
| 581 | * like the other dispatchers: it will report IRQs |
| 582 | * even after they've been disabled. We work around |
| 583 | * that here. (The "generic irq" framework may help...) |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 584 | */ |
| 585 | ts->irq_disabled = 1; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 586 | disable_irq(ts->spi->irq); |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 587 | ts->pending = 1; |
| 588 | mod_timer(&ts->timer, jiffies); |
| 589 | } |
| 590 | } |
| 591 | spin_unlock_irqrestore(&ts->lock, flags); |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 592 | |
| 593 | return IRQ_HANDLED; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | /*--------------------------------------------------------------------------*/ |
| 597 | |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 598 | /* Must be called with ts->lock held */ |
| 599 | static void ads7846_disable(struct ads7846 *ts) |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 600 | { |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 601 | if (ts->disabled) |
| 602 | return; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 603 | |
Imre Deak | c9e617a | 2006-04-11 23:44:05 -0400 | [diff] [blame] | 604 | ts->disabled = 1; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 605 | |
Imre Deak | c9e617a | 2006-04-11 23:44:05 -0400 | [diff] [blame] | 606 | /* are we waiting for IRQ, or polling? */ |
| 607 | if (!ts->pending) { |
| 608 | ts->irq_disabled = 1; |
| 609 | disable_irq(ts->spi->irq); |
| 610 | } else { |
| 611 | /* the timer will run at least once more, and |
| 612 | * leave everything in a clean state, IRQ disabled |
| 613 | */ |
| 614 | while (ts->pending) { |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 615 | spin_unlock_irq(&ts->lock); |
Juha Yrjola | c4febb9 | 2006-04-11 23:42:25 -0400 | [diff] [blame] | 616 | msleep(1); |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 617 | spin_lock_irq(&ts->lock); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 618 | } |
| 619 | } |
| 620 | |
| 621 | /* we know the chip's in lowpower mode since we always |
| 622 | * leave it that way after every request |
| 623 | */ |
| 624 | |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | /* Must be called with ts->lock held */ |
| 628 | static void ads7846_enable(struct ads7846 *ts) |
| 629 | { |
| 630 | if (!ts->disabled) |
| 631 | return; |
| 632 | |
| 633 | ts->disabled = 0; |
| 634 | ts->irq_disabled = 0; |
| 635 | enable_irq(ts->spi->irq); |
| 636 | } |
| 637 | |
| 638 | static int ads7846_suspend(struct spi_device *spi, pm_message_t message) |
| 639 | { |
| 640 | struct ads7846 *ts = dev_get_drvdata(&spi->dev); |
| 641 | |
| 642 | spin_lock_irq(&ts->lock); |
| 643 | |
| 644 | spi->dev.power.power_state = message; |
| 645 | ads7846_disable(ts); |
| 646 | |
| 647 | spin_unlock_irq(&ts->lock); |
| 648 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 649 | return 0; |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 650 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 651 | } |
| 652 | |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 653 | static int ads7846_resume(struct spi_device *spi) |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 654 | { |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 655 | struct ads7846 *ts = dev_get_drvdata(&spi->dev); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 656 | |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 657 | spin_lock_irq(&ts->lock); |
| 658 | |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 659 | spi->dev.power.power_state = PMSG_ON; |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 660 | ads7846_enable(ts); |
| 661 | |
| 662 | spin_unlock_irq(&ts->lock); |
| 663 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 664 | return 0; |
| 665 | } |
| 666 | |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 667 | static int __devinit ads7846_probe(struct spi_device *spi) |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 668 | { |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 669 | struct ads7846 *ts; |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 670 | struct input_dev *input_dev; |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 671 | struct ads7846_platform_data *pdata = spi->dev.platform_data; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 672 | struct spi_message *m; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 673 | struct spi_transfer *x; |
Imre Deak | de2defd | 2007-01-18 00:45:21 -0500 | [diff] [blame^] | 674 | int vref; |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 675 | int err; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 676 | |
| 677 | if (!spi->irq) { |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 678 | dev_dbg(&spi->dev, "no IRQ?\n"); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 679 | return -ENODEV; |
| 680 | } |
| 681 | |
| 682 | if (!pdata) { |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 683 | dev_dbg(&spi->dev, "no platform data?\n"); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 684 | return -ENODEV; |
| 685 | } |
| 686 | |
| 687 | /* don't exceed max specified sample rate */ |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 688 | if (spi->max_speed_hz > (125000 * SAMPLE_BITS)) { |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 689 | dev_dbg(&spi->dev, "f(sample) %d KHz?\n", |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 690 | (spi->max_speed_hz/SAMPLE_BITS)/1000); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 691 | return -EINVAL; |
| 692 | } |
| 693 | |
David Brownell | 9084533 | 2006-05-25 18:44:20 -0700 | [diff] [blame] | 694 | /* REVISIT when the irq can be triggered active-low, or if for some |
| 695 | * reason the touchscreen isn't hooked up, we don't need to access |
| 696 | * the pendown state. |
| 697 | */ |
Imre Deak | c9e617a | 2006-04-11 23:44:05 -0400 | [diff] [blame] | 698 | if (pdata->get_pendown_state == NULL) { |
| 699 | dev_dbg(&spi->dev, "no get_pendown_state function?\n"); |
| 700 | return -EINVAL; |
| 701 | } |
| 702 | |
David Brownell | 9084533 | 2006-05-25 18:44:20 -0700 | [diff] [blame] | 703 | /* We'd set TX wordsize 8 bits and RX wordsize to 13 bits ... except |
| 704 | * that even if the hardware can do that, the SPI controller driver |
| 705 | * may not. So we stick to very-portable 8 bit words, both RX and TX. |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 706 | */ |
David Brownell | 9084533 | 2006-05-25 18:44:20 -0700 | [diff] [blame] | 707 | spi->bits_per_word = 8; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 708 | |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 709 | ts = kzalloc(sizeof(struct ads7846), GFP_KERNEL); |
| 710 | input_dev = input_allocate_device(); |
| 711 | if (!ts || !input_dev) { |
| 712 | err = -ENOMEM; |
| 713 | goto err_free_mem; |
| 714 | } |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 715 | |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 716 | dev_set_drvdata(&spi->dev, ts); |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 717 | spi->dev.power.power_state = PMSG_ON; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 718 | |
| 719 | ts->spi = spi; |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 720 | ts->input = input_dev; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 721 | |
| 722 | init_timer(&ts->timer); |
| 723 | ts->timer.data = (unsigned long) ts; |
| 724 | ts->timer.function = ads7846_timer; |
| 725 | |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 726 | spin_lock_init(&ts->lock); |
| 727 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 728 | ts->model = pdata->model ? : 7846; |
| 729 | ts->vref_delay_usecs = pdata->vref_delay_usecs ? : 100; |
| 730 | ts->x_plate_ohms = pdata->x_plate_ohms ? : 400; |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 731 | ts->pressure_max = pdata->pressure_max ? : ~0; |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 732 | |
| 733 | if (pdata->filter != NULL) { |
| 734 | if (pdata->filter_init != NULL) { |
| 735 | err = pdata->filter_init(pdata, &ts->filter_data); |
| 736 | if (err < 0) |
| 737 | goto err_free_mem; |
| 738 | } |
| 739 | ts->filter = pdata->filter; |
| 740 | ts->filter_cleanup = pdata->filter_cleanup; |
| 741 | } else if (pdata->debounce_max) { |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 742 | ts->debounce_max = pdata->debounce_max; |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 743 | if (ts->debounce_max < 2) |
| 744 | ts->debounce_max = 2; |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 745 | ts->debounce_tol = pdata->debounce_tol; |
| 746 | ts->debounce_rep = pdata->debounce_rep; |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 747 | ts->filter = ads7846_debounce; |
| 748 | ts->filter_data = ts; |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 749 | } else |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 750 | ts->filter = ads7846_no_filter; |
Imre Deak | c9e617a | 2006-04-11 23:44:05 -0400 | [diff] [blame] | 751 | ts->get_pendown_state = pdata->get_pendown_state; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 752 | |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 753 | snprintf(ts->phys, sizeof(ts->phys), "%s/input0", spi->dev.bus_id); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 754 | |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 755 | input_dev->name = "ADS784x Touchscreen"; |
| 756 | input_dev->phys = ts->phys; |
| 757 | input_dev->cdev.dev = &spi->dev; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 758 | |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 759 | input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); |
| 760 | input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); |
| 761 | input_set_abs_params(input_dev, ABS_X, |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 762 | pdata->x_min ? : 0, |
| 763 | pdata->x_max ? : MAX_12BIT, |
| 764 | 0, 0); |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 765 | input_set_abs_params(input_dev, ABS_Y, |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 766 | pdata->y_min ? : 0, |
| 767 | pdata->y_max ? : MAX_12BIT, |
| 768 | 0, 0); |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 769 | input_set_abs_params(input_dev, ABS_PRESSURE, |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 770 | pdata->pressure_min, pdata->pressure_max, 0, 0); |
| 771 | |
Imre Deak | de2defd | 2007-01-18 00:45:21 -0500 | [diff] [blame^] | 772 | vref = pdata->keep_vref_on; |
| 773 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 774 | /* set up the transfers to read touchscreen state; this assumes we |
| 775 | * use formula #2 for pressure, not #3. |
| 776 | */ |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 777 | m = &ts->msg[0]; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 778 | x = ts->xfer; |
| 779 | |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 780 | spi_message_init(m); |
| 781 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 782 | /* y- still on; turn on only y+ (and ADC) */ |
Imre Deak | de2defd | 2007-01-18 00:45:21 -0500 | [diff] [blame^] | 783 | ts->read_y = READ_Y(vref); |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 784 | x->tx_buf = &ts->read_y; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 785 | x->len = 1; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 786 | spi_message_add_tail(x, m); |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 787 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 788 | x++; |
| 789 | x->rx_buf = &ts->tc.y; |
| 790 | x->len = 2; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 791 | spi_message_add_tail(x, m); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 792 | |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 793 | m->complete = ads7846_rx_val; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 794 | m->context = ts; |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 795 | |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 796 | m++; |
| 797 | spi_message_init(m); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 798 | |
| 799 | /* turn y- off, x+ on, then leave in lowpower */ |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 800 | x++; |
Imre Deak | de2defd | 2007-01-18 00:45:21 -0500 | [diff] [blame^] | 801 | ts->read_x = READ_X(vref); |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 802 | x->tx_buf = &ts->read_x; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 803 | x->len = 1; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 804 | spi_message_add_tail(x, m); |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 805 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 806 | x++; |
| 807 | x->rx_buf = &ts->tc.x; |
| 808 | x->len = 2; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 809 | spi_message_add_tail(x, m); |
| 810 | |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 811 | m->complete = ads7846_rx_val; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 812 | m->context = ts; |
| 813 | |
| 814 | /* turn y+ off, x- on; we'll use formula #2 */ |
| 815 | if (ts->model == 7846) { |
| 816 | m++; |
| 817 | spi_message_init(m); |
| 818 | |
| 819 | x++; |
Imre Deak | de2defd | 2007-01-18 00:45:21 -0500 | [diff] [blame^] | 820 | ts->read_z1 = READ_Z1(vref); |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 821 | x->tx_buf = &ts->read_z1; |
| 822 | x->len = 1; |
| 823 | spi_message_add_tail(x, m); |
| 824 | |
| 825 | x++; |
| 826 | x->rx_buf = &ts->tc.z1; |
| 827 | x->len = 2; |
| 828 | spi_message_add_tail(x, m); |
| 829 | |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 830 | m->complete = ads7846_rx_val; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 831 | m->context = ts; |
| 832 | |
| 833 | m++; |
| 834 | spi_message_init(m); |
| 835 | |
| 836 | x++; |
Imre Deak | de2defd | 2007-01-18 00:45:21 -0500 | [diff] [blame^] | 837 | ts->read_z2 = READ_Z2(vref); |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 838 | x->tx_buf = &ts->read_z2; |
| 839 | x->len = 1; |
| 840 | spi_message_add_tail(x, m); |
| 841 | |
| 842 | x++; |
| 843 | x->rx_buf = &ts->tc.z2; |
| 844 | x->len = 2; |
| 845 | spi_message_add_tail(x, m); |
| 846 | |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 847 | m->complete = ads7846_rx_val; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 848 | m->context = ts; |
| 849 | } |
Imre Deak | 53a0ef89 | 2006-04-11 23:41:49 -0400 | [diff] [blame] | 850 | |
| 851 | /* power down */ |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 852 | m++; |
| 853 | spi_message_init(m); |
| 854 | |
Imre Deak | 53a0ef89 | 2006-04-11 23:41:49 -0400 | [diff] [blame] | 855 | x++; |
| 856 | ts->pwrdown = PWRDOWN; |
| 857 | x->tx_buf = &ts->pwrdown; |
| 858 | x->len = 1; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 859 | spi_message_add_tail(x, m); |
Imre Deak | 53a0ef89 | 2006-04-11 23:41:49 -0400 | [diff] [blame] | 860 | |
| 861 | x++; |
| 862 | x->rx_buf = &ts->dummy; |
| 863 | x->len = 2; |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 864 | CS_CHANGE(*x); |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 865 | spi_message_add_tail(x, m); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 866 | |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 867 | m->complete = ads7846_rx; |
| 868 | m->context = ts; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 869 | |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 870 | ts->last_msg = m; |
| 871 | |
Thomas Gleixner | dace145 | 2006-07-01 19:29:38 -0700 | [diff] [blame] | 872 | if (request_irq(spi->irq, ads7846_irq, IRQF_TRIGGER_FALLING, |
David Brownell | 9084533 | 2006-05-25 18:44:20 -0700 | [diff] [blame] | 873 | spi->dev.driver->name, ts)) { |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 874 | dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq); |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 875 | err = -EBUSY; |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 876 | goto err_cleanup_filter; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 877 | } |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 878 | |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 879 | dev_info(&spi->dev, "touchscreen, irq %d\n", spi->irq); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 880 | |
| 881 | /* take a first sample, leaving nPENIRQ active; avoid |
| 882 | * the touchscreen, in case it's not connected. |
| 883 | */ |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 884 | (void) ads7846_read12_ser(&spi->dev, |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 885 | READ_12BIT_SER(vaux) | ADS_PD10_ALL_ON); |
| 886 | |
Dmitry Torokhov | 8dd5165 | 2006-11-02 23:34:09 -0500 | [diff] [blame] | 887 | switch (ts->model) { |
| 888 | case 7846: |
| 889 | ts->attr_group = &ads7846_attr_group; |
| 890 | break; |
| 891 | case 7845: |
| 892 | ts->attr_group = &ads7845_attr_group; |
| 893 | break; |
| 894 | default: |
| 895 | ts->attr_group = &ads7843_attr_group; |
| 896 | break; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 897 | } |
Dmitry Torokhov | 8dd5165 | 2006-11-02 23:34:09 -0500 | [diff] [blame] | 898 | err = sysfs_create_group(&spi->dev.kobj, ts->attr_group); |
| 899 | if (err) |
| 900 | goto err_free_irq; |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 901 | |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 902 | err = input_register_device(input_dev); |
| 903 | if (err) |
Dmitry Torokhov | 8dd5165 | 2006-11-02 23:34:09 -0500 | [diff] [blame] | 904 | goto err_remove_attr_group; |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 905 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 906 | return 0; |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 907 | |
Dmitry Torokhov | 8dd5165 | 2006-11-02 23:34:09 -0500 | [diff] [blame] | 908 | err_remove_attr_group: |
| 909 | sysfs_remove_group(&spi->dev.kobj, ts->attr_group); |
| 910 | err_free_irq: |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 911 | free_irq(spi->irq, ts); |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 912 | err_cleanup_filter: |
| 913 | if (ts->filter_cleanup) |
| 914 | ts->filter_cleanup(ts->filter_data); |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 915 | err_free_mem: |
| 916 | input_free_device(input_dev); |
| 917 | kfree(ts); |
| 918 | return err; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 919 | } |
| 920 | |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 921 | static int __devexit ads7846_remove(struct spi_device *spi) |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 922 | { |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 923 | struct ads7846 *ts = dev_get_drvdata(&spi->dev); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 924 | |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 925 | input_unregister_device(ts->input); |
| 926 | |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 927 | ads7846_suspend(spi, PMSG_SUSPEND); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 928 | |
Dmitry Torokhov | 8dd5165 | 2006-11-02 23:34:09 -0500 | [diff] [blame] | 929 | sysfs_remove_group(&spi->dev.kobj, ts->attr_group); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 930 | |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 931 | free_irq(ts->spi->irq, ts); |
Imre Deak | c9e617a | 2006-04-11 23:44:05 -0400 | [diff] [blame] | 932 | /* suspend left the IRQ disabled */ |
| 933 | enable_irq(ts->spi->irq); |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 934 | |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 935 | if (ts->filter_cleanup) |
| 936 | ts->filter_cleanup(ts->filter_data); |
| 937 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 938 | kfree(ts); |
| 939 | |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 940 | dev_dbg(&spi->dev, "unregistered touchscreen\n"); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 941 | return 0; |
| 942 | } |
| 943 | |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 944 | static struct spi_driver ads7846_driver = { |
| 945 | .driver = { |
| 946 | .name = "ads7846", |
| 947 | .bus = &spi_bus_type, |
| 948 | .owner = THIS_MODULE, |
| 949 | }, |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 950 | .probe = ads7846_probe, |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 951 | .remove = __devexit_p(ads7846_remove), |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 952 | .suspend = ads7846_suspend, |
| 953 | .resume = ads7846_resume, |
| 954 | }; |
| 955 | |
| 956 | static int __init ads7846_init(void) |
| 957 | { |
| 958 | /* grr, board-specific init should stay out of drivers!! */ |
| 959 | |
| 960 | #ifdef CONFIG_ARCH_OMAP |
| 961 | if (machine_is_omap_osk()) { |
| 962 | /* GPIO4 = PENIRQ; GPIO6 = BUSY */ |
| 963 | omap_request_gpio(4); |
| 964 | omap_set_gpio_direction(4, 1); |
| 965 | omap_request_gpio(6); |
| 966 | omap_set_gpio_direction(6, 1); |
| 967 | } |
| 968 | // also TI 1510 Innovator, bitbanging through FPGA |
| 969 | // also Nokia 770 |
| 970 | // also Palm Tungsten T2 |
| 971 | #endif |
| 972 | |
| 973 | // PXA: |
| 974 | // also Dell Axim X50 |
| 975 | // also HP iPaq H191x/H192x/H415x/H435x |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 976 | // also Intel Lubbock (additional to UCB1400; as temperature sensor) |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 977 | // also Sharp Zaurus C7xx, C8xx (corgi/sheperd/husky) |
| 978 | |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 979 | // Atmel at91sam9261-EK uses ads7843 |
| 980 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 981 | // also various AMD Au1x00 devel boards |
| 982 | |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 983 | return spi_register_driver(&ads7846_driver); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 984 | } |
| 985 | module_init(ads7846_init); |
| 986 | |
| 987 | static void __exit ads7846_exit(void) |
| 988 | { |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 989 | spi_unregister_driver(&ads7846_driver); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 990 | |
| 991 | #ifdef CONFIG_ARCH_OMAP |
| 992 | if (machine_is_omap_osk()) { |
| 993 | omap_free_gpio(4); |
| 994 | omap_free_gpio(6); |
| 995 | } |
| 996 | #endif |
| 997 | |
| 998 | } |
| 999 | module_exit(ads7846_exit); |
| 1000 | |
| 1001 | MODULE_DESCRIPTION("ADS7846 TouchScreen Driver"); |
| 1002 | MODULE_LICENSE("GPL"); |