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 |
| 5 | * |
| 6 | * Using code from: |
| 7 | * - corgi_ts.c |
| 8 | * Copyright (C) 2004-2005 Richard Purdie |
| 9 | * - omap_ts.[hc], ads7846.h, ts_osk.c |
| 10 | * Copyright (C) 2002 MontaVista Software |
| 11 | * Copyright (C) 2004 Texas Instruments |
| 12 | * Copyright (C) 2005 Dirk Behme |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or modify |
| 15 | * it under the terms of the GNU General Public License version 2 as |
| 16 | * published by the Free Software Foundation. |
| 17 | */ |
| 18 | #include <linux/device.h> |
| 19 | #include <linux/init.h> |
| 20 | #include <linux/delay.h> |
| 21 | #include <linux/input.h> |
| 22 | #include <linux/interrupt.h> |
| 23 | #include <linux/slab.h> |
| 24 | #include <linux/spi/spi.h> |
| 25 | #include <linux/spi/ads7846.h> |
Andrew Morton | 3ac8bf0 | 2006-03-26 01:37:33 -0800 | [diff] [blame] | 26 | #include <asm/irq.h> |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 27 | |
| 28 | #ifdef CONFIG_ARM |
| 29 | #include <asm/mach-types.h> |
| 30 | #ifdef CONFIG_ARCH_OMAP |
| 31 | #include <asm/arch/gpio.h> |
| 32 | #endif |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 33 | #endif |
| 34 | |
| 35 | |
| 36 | /* |
| 37 | * This code has been lightly tested on an ads7846. |
| 38 | * Support for ads7843 and ads7845 has only been stubbed in. |
| 39 | * |
| 40 | * Not yet done: investigate the values reported. Are x/y/pressure |
| 41 | * event values sane enough for X11? How accurate are the temperature |
| 42 | * and voltage readings? (System-specific calibration should support |
| 43 | * accuracy of 0.3 degrees C; otherwise it's 2.0 degrees.) |
| 44 | * |
| 45 | * app note sbaa036 talks in more detail about accurate sampling... |
| 46 | * that ought to help in situations like LCDs inducing noise (which |
| 47 | * can also be helped by using synch signals) and more generally. |
| 48 | */ |
| 49 | |
| 50 | #define TS_POLL_PERIOD msecs_to_jiffies(10) |
| 51 | |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 52 | /* this driver doesn't aim at the peak continuous sample rate */ |
| 53 | #define SAMPLE_BITS (8 /*cmd*/ + 16 /*sample*/ + 2 /* before, after */) |
| 54 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 55 | struct ts_event { |
| 56 | /* For portability, we can't read 12 bit values using SPI (which |
| 57 | * would make the controller deliver them as native byteorder u16 |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 58 | * with msbs zeroed). Instead, we read them as two 8-bit values, |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 59 | * which need byteswapping then range adjustment. |
| 60 | */ |
| 61 | __be16 x; |
| 62 | __be16 y; |
| 63 | __be16 z1, z2; |
| 64 | }; |
| 65 | |
| 66 | struct ads7846 { |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 67 | struct input_dev *input; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 68 | char phys[32]; |
| 69 | |
| 70 | struct spi_device *spi; |
| 71 | u16 model; |
| 72 | u16 vref_delay_usecs; |
| 73 | u16 x_plate_ohms; |
| 74 | |
Imre Deak | 53a0ef89 | 2006-04-11 23:41:49 -0400 | [diff] [blame] | 75 | u8 read_x, read_y, read_z1, read_z2, pwrdown; |
| 76 | u16 dummy; /* for the pwrdown read */ |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 77 | struct ts_event tc; |
| 78 | |
Imre Deak | 53a0ef89 | 2006-04-11 23:41:49 -0400 | [diff] [blame] | 79 | struct spi_transfer xfer[10]; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 80 | struct spi_message msg[5]; |
| 81 | int msg_idx; |
| 82 | int read_cnt; |
| 83 | int last_read; |
| 84 | |
| 85 | u16 debounce_max; |
| 86 | u16 debounce_tol; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 87 | |
| 88 | spinlock_t lock; |
| 89 | struct timer_list timer; /* P: lock */ |
| 90 | unsigned pendown:1; /* P: lock */ |
| 91 | unsigned pending:1; /* P: lock */ |
| 92 | // FIXME remove "irq_disabled" |
| 93 | unsigned irq_disabled:1; /* P: lock */ |
| 94 | }; |
| 95 | |
| 96 | /* leave chip selected when we're done, for quicker re-select? */ |
| 97 | #if 0 |
| 98 | #define CS_CHANGE(xfer) ((xfer).cs_change = 1) |
| 99 | #else |
| 100 | #define CS_CHANGE(xfer) ((xfer).cs_change = 0) |
| 101 | #endif |
| 102 | |
| 103 | /*--------------------------------------------------------------------------*/ |
| 104 | |
| 105 | /* The ADS7846 has touchscreen and other sensors. |
| 106 | * Earlier ads784x chips are somewhat compatible. |
| 107 | */ |
| 108 | #define ADS_START (1 << 7) |
| 109 | #define ADS_A2A1A0_d_y (1 << 4) /* differential */ |
| 110 | #define ADS_A2A1A0_d_z1 (3 << 4) /* differential */ |
| 111 | #define ADS_A2A1A0_d_z2 (4 << 4) /* differential */ |
| 112 | #define ADS_A2A1A0_d_x (5 << 4) /* differential */ |
| 113 | #define ADS_A2A1A0_temp0 (0 << 4) /* non-differential */ |
| 114 | #define ADS_A2A1A0_vbatt (2 << 4) /* non-differential */ |
| 115 | #define ADS_A2A1A0_vaux (6 << 4) /* non-differential */ |
| 116 | #define ADS_A2A1A0_temp1 (7 << 4) /* non-differential */ |
| 117 | #define ADS_8_BIT (1 << 3) |
| 118 | #define ADS_12_BIT (0 << 3) |
| 119 | #define ADS_SER (1 << 2) /* non-differential */ |
| 120 | #define ADS_DFR (0 << 2) /* differential */ |
| 121 | #define ADS_PD10_PDOWN (0 << 0) /* lowpower mode + penirq */ |
| 122 | #define ADS_PD10_ADC_ON (1 << 0) /* ADC on */ |
| 123 | #define ADS_PD10_REF_ON (2 << 0) /* vREF on + penirq */ |
| 124 | #define ADS_PD10_ALL_ON (3 << 0) /* ADC + vREF on */ |
| 125 | |
| 126 | #define MAX_12BIT ((1<<12)-1) |
| 127 | |
| 128 | /* leave ADC powered up (disables penirq) between differential samples */ |
| 129 | #define READ_12BIT_DFR(x) (ADS_START | ADS_A2A1A0_d_ ## x \ |
| 130 | | ADS_12_BIT | ADS_DFR) |
| 131 | |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 132 | #define READ_Y (READ_12BIT_DFR(y) | ADS_PD10_ADC_ON) |
| 133 | #define READ_Z1 (READ_12BIT_DFR(z1) | ADS_PD10_ADC_ON) |
| 134 | #define READ_Z2 (READ_12BIT_DFR(z2) | ADS_PD10_ADC_ON) |
Imre Deak | 53a0ef89 | 2006-04-11 23:41:49 -0400 | [diff] [blame] | 135 | |
| 136 | #define READ_X (READ_12BIT_DFR(x) | ADS_PD10_ADC_ON) |
| 137 | #define PWRDOWN (READ_12BIT_DFR(y) | ADS_PD10_PDOWN) /* LAST */ |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 138 | |
| 139 | /* single-ended samples need to first power up reference voltage; |
| 140 | * we leave both ADC and VREF powered |
| 141 | */ |
| 142 | #define READ_12BIT_SER(x) (ADS_START | ADS_A2A1A0_ ## x \ |
| 143 | | ADS_12_BIT | ADS_SER) |
| 144 | |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 145 | #define REF_ON (READ_12BIT_DFR(x) | ADS_PD10_ALL_ON) |
| 146 | #define REF_OFF (READ_12BIT_DFR(y) | ADS_PD10_PDOWN) |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 147 | |
| 148 | /*--------------------------------------------------------------------------*/ |
| 149 | |
| 150 | /* |
| 151 | * Non-touchscreen sensors only use single-ended conversions. |
| 152 | */ |
| 153 | |
| 154 | struct ser_req { |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 155 | u8 ref_on; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 156 | u8 command; |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 157 | u8 ref_off; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 158 | u16 scratch; |
| 159 | __be16 sample; |
| 160 | struct spi_message msg; |
| 161 | struct spi_transfer xfer[6]; |
| 162 | }; |
| 163 | |
| 164 | static int ads7846_read12_ser(struct device *dev, unsigned command) |
| 165 | { |
| 166 | struct spi_device *spi = to_spi_device(dev); |
| 167 | struct ads7846 *ts = dev_get_drvdata(dev); |
| 168 | struct ser_req *req = kzalloc(sizeof *req, SLAB_KERNEL); |
| 169 | int status; |
| 170 | int sample; |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 171 | int i; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 172 | |
| 173 | if (!req) |
| 174 | return -ENOMEM; |
| 175 | |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 176 | spi_message_init(&req->msg); |
Vitaly Wool | 8275c64 | 2006-01-08 13:34:28 -0800 | [diff] [blame] | 177 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 178 | /* activate reference, so it has time to settle; */ |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 179 | req->ref_on = REF_ON; |
| 180 | req->xfer[0].tx_buf = &req->ref_on; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 181 | req->xfer[0].len = 1; |
| 182 | req->xfer[1].rx_buf = &req->scratch; |
| 183 | req->xfer[1].len = 2; |
| 184 | |
| 185 | /* |
| 186 | * for external VREF, 0 usec (and assume it's always on); |
| 187 | * for 1uF, use 800 usec; |
| 188 | * no cap, 100 usec. |
| 189 | */ |
| 190 | req->xfer[1].delay_usecs = ts->vref_delay_usecs; |
| 191 | |
| 192 | /* take sample */ |
| 193 | req->command = (u8) command; |
| 194 | req->xfer[2].tx_buf = &req->command; |
| 195 | req->xfer[2].len = 1; |
| 196 | req->xfer[3].rx_buf = &req->sample; |
| 197 | req->xfer[3].len = 2; |
| 198 | |
| 199 | /* REVISIT: take a few more samples, and compare ... */ |
| 200 | |
| 201 | /* turn off reference */ |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 202 | req->ref_off = REF_OFF; |
| 203 | req->xfer[4].tx_buf = &req->ref_off; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 204 | req->xfer[4].len = 1; |
| 205 | req->xfer[5].rx_buf = &req->scratch; |
| 206 | req->xfer[5].len = 2; |
| 207 | |
| 208 | CS_CHANGE(req->xfer[5]); |
| 209 | |
| 210 | /* group all the transfers together, so we can't interfere with |
| 211 | * reading touchscreen state; disable penirq while sampling |
| 212 | */ |
Vitaly Wool | 8275c64 | 2006-01-08 13:34:28 -0800 | [diff] [blame] | 213 | for (i = 0; i < 6; i++) |
| 214 | spi_message_add_tail(&req->xfer[i], &req->msg); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 215 | |
| 216 | disable_irq(spi->irq); |
| 217 | status = spi_sync(spi, &req->msg); |
| 218 | enable_irq(spi->irq); |
| 219 | |
| 220 | if (req->msg.status) |
| 221 | status = req->msg.status; |
| 222 | sample = be16_to_cpu(req->sample); |
| 223 | sample = sample >> 4; |
| 224 | kfree(req); |
| 225 | |
| 226 | return status ? status : sample; |
| 227 | } |
| 228 | |
| 229 | #define SHOW(name) static ssize_t \ |
| 230 | name ## _show(struct device *dev, struct device_attribute *attr, char *buf) \ |
| 231 | { \ |
| 232 | ssize_t v = ads7846_read12_ser(dev, \ |
| 233 | READ_12BIT_SER(name) | ADS_PD10_ALL_ON); \ |
| 234 | if (v < 0) \ |
| 235 | return v; \ |
| 236 | return sprintf(buf, "%u\n", (unsigned) v); \ |
| 237 | } \ |
| 238 | static DEVICE_ATTR(name, S_IRUGO, name ## _show, NULL); |
| 239 | |
| 240 | SHOW(temp0) |
| 241 | SHOW(temp1) |
| 242 | SHOW(vaux) |
| 243 | SHOW(vbatt) |
| 244 | |
Imre Deak | 438f2a7 | 2006-04-11 23:41:32 -0400 | [diff] [blame] | 245 | static int is_pen_down(struct device *dev) |
| 246 | { |
| 247 | struct ads7846 *ts = dev_get_drvdata(dev); |
| 248 | |
| 249 | return ts->pendown; |
| 250 | } |
| 251 | |
| 252 | static ssize_t ads7846_pen_down_show(struct device *dev, |
| 253 | struct device_attribute *attr, char *buf) |
| 254 | { |
| 255 | return sprintf(buf, "%u\n", is_pen_down(dev)); |
| 256 | } |
| 257 | |
| 258 | static DEVICE_ATTR(pen_down, S_IRUGO, ads7846_pen_down_show, NULL); |
| 259 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 260 | /*--------------------------------------------------------------------------*/ |
| 261 | |
| 262 | /* |
| 263 | * PENIRQ only kicks the timer. The timer only reissues the SPI transfer, |
| 264 | * to retrieve touchscreen status. |
| 265 | * |
| 266 | * The SPI transfer completion callback does the real work. It reports |
| 267 | * touchscreen events and reactivates the timer (or IRQ) as appropriate. |
| 268 | */ |
| 269 | |
| 270 | static void ads7846_rx(void *ads) |
| 271 | { |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 272 | struct ads7846 *ts = ads; |
| 273 | struct input_dev *input_dev = ts->input; |
| 274 | unsigned Rt; |
| 275 | unsigned sync = 0; |
| 276 | u16 x, y, z1, z2; |
| 277 | unsigned long flags; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 278 | |
| 279 | /* adjust: 12 bit samples (left aligned), built from |
| 280 | * two 8 bit values writen msb-first. |
| 281 | */ |
| 282 | x = be16_to_cpu(ts->tc.x) >> 4; |
| 283 | y = be16_to_cpu(ts->tc.y) >> 4; |
| 284 | z1 = be16_to_cpu(ts->tc.z1) >> 4; |
| 285 | z2 = be16_to_cpu(ts->tc.z2) >> 4; |
| 286 | |
| 287 | /* range filtering */ |
| 288 | if (x == MAX_12BIT) |
| 289 | x = 0; |
| 290 | |
| 291 | if (x && z1 && ts->spi->dev.power.power_state.event == PM_EVENT_ON) { |
| 292 | /* compute touch pressure resistance using equation #2 */ |
| 293 | Rt = z2; |
| 294 | Rt -= z1; |
| 295 | Rt *= x; |
| 296 | Rt *= ts->x_plate_ohms; |
| 297 | Rt /= z1; |
| 298 | Rt = (Rt + 2047) >> 12; |
| 299 | } else |
| 300 | Rt = 0; |
| 301 | |
| 302 | /* NOTE: "pendown" is inferred from pressure; we don't rely on |
| 303 | * being able to check nPENIRQ status, or "friendly" trigger modes |
| 304 | * (both-edges is much better than just-falling or low-level). |
| 305 | * |
| 306 | * REVISIT: some boards may require reading nPENIRQ; it's |
| 307 | * needed on 7843. and 7845 reads pressure differently... |
| 308 | * |
| 309 | * REVISIT: the touchscreen might not be connected; this code |
| 310 | * won't notice that, even if nPENIRQ never fires ... |
| 311 | */ |
| 312 | if (!ts->pendown && Rt != 0) { |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 313 | input_report_key(input_dev, BTN_TOUCH, 1); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 314 | sync = 1; |
| 315 | } else if (ts->pendown && Rt == 0) { |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 316 | input_report_key(input_dev, BTN_TOUCH, 0); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 317 | sync = 1; |
| 318 | } |
| 319 | |
| 320 | if (Rt) { |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 321 | input_report_abs(input_dev, ABS_X, x); |
| 322 | input_report_abs(input_dev, ABS_Y, y); |
| 323 | input_report_abs(input_dev, ABS_PRESSURE, Rt); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 324 | sync = 1; |
| 325 | } |
| 326 | if (sync) |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 327 | input_sync(input_dev); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 328 | |
| 329 | #ifdef VERBOSE |
| 330 | if (Rt || ts->pendown) |
| 331 | pr_debug("%s: %d/%d/%d%s\n", ts->spi->dev.bus_id, |
| 332 | x, y, Rt, Rt ? "" : " UP"); |
| 333 | #endif |
| 334 | |
| 335 | /* don't retrigger while we're suspended */ |
| 336 | spin_lock_irqsave(&ts->lock, flags); |
| 337 | |
| 338 | ts->pendown = (Rt != 0); |
| 339 | ts->pending = 0; |
| 340 | |
| 341 | if (ts->spi->dev.power.power_state.event == PM_EVENT_ON) { |
| 342 | if (ts->pendown) |
| 343 | mod_timer(&ts->timer, jiffies + TS_POLL_PERIOD); |
| 344 | else if (ts->irq_disabled) { |
| 345 | ts->irq_disabled = 0; |
| 346 | enable_irq(ts->spi->irq); |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | spin_unlock_irqrestore(&ts->lock, flags); |
| 351 | } |
| 352 | |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 353 | static void ads7846_debounce(void *ads) |
| 354 | { |
| 355 | struct ads7846 *ts = ads; |
| 356 | struct spi_message *m; |
| 357 | struct spi_transfer *t; |
| 358 | u16 val; |
| 359 | int status; |
| 360 | |
| 361 | m = &ts->msg[ts->msg_idx]; |
| 362 | t = list_entry(m->transfers.prev, struct spi_transfer, transfer_list); |
| 363 | val = (*(u16 *)t->rx_buf) >> 3; |
| 364 | |
| 365 | if (!ts->read_cnt || (abs(ts->last_read - val) > ts->debounce_tol |
| 366 | && ts->read_cnt < ts->debounce_max)) { |
| 367 | /* Repeat it, if this was the first read or the read wasn't |
| 368 | * consistent enough |
| 369 | */ |
| 370 | ts->read_cnt++; |
| 371 | ts->last_read = val; |
| 372 | } else { |
| 373 | /* Go for the next read */ |
| 374 | ts->msg_idx++; |
| 375 | ts->read_cnt = 0; |
| 376 | m++; |
| 377 | } |
| 378 | status = spi_async(ts->spi, m); |
| 379 | if (status) |
| 380 | dev_err(&ts->spi->dev, "spi_async --> %d\n", |
| 381 | status); |
| 382 | } |
| 383 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 384 | static void ads7846_timer(unsigned long handle) |
| 385 | { |
| 386 | struct ads7846 *ts = (void *)handle; |
| 387 | int status = 0; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 388 | |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 389 | ts->msg_idx = 0; |
| 390 | status = spi_async(ts->spi, &ts->msg[0]); |
| 391 | if (status) |
| 392 | dev_err(&ts->spi->dev, "spi_async --> %d\n", status); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | static irqreturn_t ads7846_irq(int irq, void *handle, struct pt_regs *regs) |
| 396 | { |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 397 | struct ads7846 *ts = handle; |
| 398 | unsigned long flags; |
| 399 | int r = IRQ_HANDLED; |
| 400 | |
| 401 | spin_lock_irqsave(&ts->lock, flags); |
| 402 | if (ts->irq_disabled) |
| 403 | r = IRQ_HANDLED; |
| 404 | else { |
| 405 | if (!ts->irq_disabled) { |
| 406 | /* REVISIT irq logic for many ARM chips has cloned a |
| 407 | * bug wherein disabling an irq in its handler won't |
| 408 | * work;(it's disabled lazily, and too late to work. |
| 409 | * until all their irq logic is fixed, we must shadow |
| 410 | * that state here. |
| 411 | */ |
| 412 | ts->irq_disabled = 1; |
| 413 | |
| 414 | disable_irq(ts->spi->irq); |
| 415 | } |
| 416 | if (!ts->pending) { |
| 417 | ts->pending = 1; |
| 418 | mod_timer(&ts->timer, jiffies); |
| 419 | } |
| 420 | } |
| 421 | spin_unlock_irqrestore(&ts->lock, flags); |
| 422 | return r; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | /*--------------------------------------------------------------------------*/ |
| 426 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 427 | static int |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 428 | ads7846_suspend(struct spi_device *spi, pm_message_t message) |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 429 | { |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 430 | struct ads7846 *ts = dev_get_drvdata(&spi->dev); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 431 | unsigned long flags; |
| 432 | |
| 433 | spin_lock_irqsave(&ts->lock, flags); |
| 434 | |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 435 | spi->dev.power.power_state = message; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 436 | |
| 437 | /* are we waiting for IRQ, or polling? */ |
| 438 | if (!ts->pendown) { |
| 439 | if (!ts->irq_disabled) { |
| 440 | ts->irq_disabled = 1; |
| 441 | disable_irq(ts->spi->irq); |
| 442 | } |
| 443 | } else { |
| 444 | /* polling; force a final SPI completion; |
| 445 | * that will clean things up neatly |
| 446 | */ |
| 447 | if (!ts->pending) |
| 448 | mod_timer(&ts->timer, jiffies); |
| 449 | |
| 450 | while (ts->pendown || ts->pending) { |
| 451 | spin_unlock_irqrestore(&ts->lock, flags); |
Juha Yrjola | c4febb9 | 2006-04-11 23:42:25 -0400 | [diff] [blame^] | 452 | msleep(1); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 453 | spin_lock_irqsave(&ts->lock, flags); |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | /* we know the chip's in lowpower mode since we always |
| 458 | * leave it that way after every request |
| 459 | */ |
| 460 | |
| 461 | spin_unlock_irqrestore(&ts->lock, flags); |
| 462 | return 0; |
| 463 | } |
| 464 | |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 465 | static int ads7846_resume(struct spi_device *spi) |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 466 | { |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 467 | struct ads7846 *ts = dev_get_drvdata(&spi->dev); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 468 | |
| 469 | ts->irq_disabled = 0; |
| 470 | enable_irq(ts->spi->irq); |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 471 | spi->dev.power.power_state = PMSG_ON; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 472 | return 0; |
| 473 | } |
| 474 | |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 475 | static int __devinit ads7846_probe(struct spi_device *spi) |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 476 | { |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 477 | struct ads7846 *ts; |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 478 | struct input_dev *input_dev; |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 479 | struct ads7846_platform_data *pdata = spi->dev.platform_data; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 480 | struct spi_message *m; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 481 | struct spi_transfer *x; |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 482 | int err; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 483 | |
| 484 | if (!spi->irq) { |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 485 | dev_dbg(&spi->dev, "no IRQ?\n"); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 486 | return -ENODEV; |
| 487 | } |
| 488 | |
| 489 | if (!pdata) { |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 490 | dev_dbg(&spi->dev, "no platform data?\n"); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 491 | return -ENODEV; |
| 492 | } |
| 493 | |
| 494 | /* don't exceed max specified sample rate */ |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 495 | if (spi->max_speed_hz > (125000 * SAMPLE_BITS)) { |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 496 | dev_dbg(&spi->dev, "f(sample) %d KHz?\n", |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 497 | (spi->max_speed_hz/SAMPLE_BITS)/1000); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 498 | return -EINVAL; |
| 499 | } |
| 500 | |
| 501 | /* We'd set the wordsize to 12 bits ... except that some controllers |
| 502 | * will then treat the 8 bit command words as 12 bits (and drop the |
| 503 | * four MSBs of the 12 bit result). Result: inputs must be shifted |
| 504 | * to discard the four garbage LSBs. |
| 505 | */ |
| 506 | |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 507 | ts = kzalloc(sizeof(struct ads7846), GFP_KERNEL); |
| 508 | input_dev = input_allocate_device(); |
| 509 | if (!ts || !input_dev) { |
| 510 | err = -ENOMEM; |
| 511 | goto err_free_mem; |
| 512 | } |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 513 | |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 514 | dev_set_drvdata(&spi->dev, ts); |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 515 | spi->dev.power.power_state = PMSG_ON; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 516 | |
| 517 | ts->spi = spi; |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 518 | ts->input = input_dev; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 519 | |
| 520 | init_timer(&ts->timer); |
| 521 | ts->timer.data = (unsigned long) ts; |
| 522 | ts->timer.function = ads7846_timer; |
| 523 | |
| 524 | ts->model = pdata->model ? : 7846; |
| 525 | ts->vref_delay_usecs = pdata->vref_delay_usecs ? : 100; |
| 526 | ts->x_plate_ohms = pdata->x_plate_ohms ? : 400; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 527 | ts->debounce_max = pdata->debounce_max ? : 1; |
| 528 | ts->debounce_tol = pdata->debounce_tol ? : 10; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 529 | |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 530 | snprintf(ts->phys, sizeof(ts->phys), "%s/input0", spi->dev.bus_id); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 531 | |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 532 | input_dev->name = "ADS784x Touchscreen"; |
| 533 | input_dev->phys = ts->phys; |
| 534 | input_dev->cdev.dev = &spi->dev; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 535 | |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 536 | input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); |
| 537 | input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); |
| 538 | input_set_abs_params(input_dev, ABS_X, |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 539 | pdata->x_min ? : 0, |
| 540 | pdata->x_max ? : MAX_12BIT, |
| 541 | 0, 0); |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 542 | input_set_abs_params(input_dev, ABS_Y, |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 543 | pdata->y_min ? : 0, |
| 544 | pdata->y_max ? : MAX_12BIT, |
| 545 | 0, 0); |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 546 | input_set_abs_params(input_dev, ABS_PRESSURE, |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 547 | pdata->pressure_min, pdata->pressure_max, 0, 0); |
| 548 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 549 | /* set up the transfers to read touchscreen state; this assumes we |
| 550 | * use formula #2 for pressure, not #3. |
| 551 | */ |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 552 | m = &ts->msg[0]; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 553 | x = ts->xfer; |
| 554 | |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 555 | spi_message_init(m); |
| 556 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 557 | /* y- still on; turn on only y+ (and ADC) */ |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 558 | ts->read_y = READ_Y; |
| 559 | x->tx_buf = &ts->read_y; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 560 | x->len = 1; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 561 | spi_message_add_tail(x, m); |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 562 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 563 | x++; |
| 564 | x->rx_buf = &ts->tc.y; |
| 565 | x->len = 2; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 566 | spi_message_add_tail(x, m); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 567 | |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 568 | m->complete = ads7846_debounce; |
| 569 | m->context = ts; |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 570 | |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 571 | m++; |
| 572 | spi_message_init(m); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 573 | |
| 574 | /* turn y- off, x+ on, then leave in lowpower */ |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 575 | x++; |
| 576 | ts->read_x = READ_X; |
| 577 | x->tx_buf = &ts->read_x; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 578 | x->len = 1; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 579 | spi_message_add_tail(x, m); |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 580 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 581 | x++; |
| 582 | x->rx_buf = &ts->tc.x; |
| 583 | x->len = 2; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 584 | spi_message_add_tail(x, m); |
| 585 | |
| 586 | m->complete = ads7846_debounce; |
| 587 | m->context = ts; |
| 588 | |
| 589 | /* turn y+ off, x- on; we'll use formula #2 */ |
| 590 | if (ts->model == 7846) { |
| 591 | m++; |
| 592 | spi_message_init(m); |
| 593 | |
| 594 | x++; |
| 595 | ts->read_z1 = READ_Z1; |
| 596 | x->tx_buf = &ts->read_z1; |
| 597 | x->len = 1; |
| 598 | spi_message_add_tail(x, m); |
| 599 | |
| 600 | x++; |
| 601 | x->rx_buf = &ts->tc.z1; |
| 602 | x->len = 2; |
| 603 | spi_message_add_tail(x, m); |
| 604 | |
| 605 | m->complete = ads7846_debounce; |
| 606 | m->context = ts; |
| 607 | |
| 608 | m++; |
| 609 | spi_message_init(m); |
| 610 | |
| 611 | x++; |
| 612 | ts->read_z2 = READ_Z2; |
| 613 | x->tx_buf = &ts->read_z2; |
| 614 | x->len = 1; |
| 615 | spi_message_add_tail(x, m); |
| 616 | |
| 617 | x++; |
| 618 | x->rx_buf = &ts->tc.z2; |
| 619 | x->len = 2; |
| 620 | spi_message_add_tail(x, m); |
| 621 | |
| 622 | m->complete = ads7846_debounce; |
| 623 | m->context = ts; |
| 624 | } |
Imre Deak | 53a0ef89 | 2006-04-11 23:41:49 -0400 | [diff] [blame] | 625 | |
| 626 | /* power down */ |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 627 | m++; |
| 628 | spi_message_init(m); |
| 629 | |
Imre Deak | 53a0ef89 | 2006-04-11 23:41:49 -0400 | [diff] [blame] | 630 | x++; |
| 631 | ts->pwrdown = PWRDOWN; |
| 632 | x->tx_buf = &ts->pwrdown; |
| 633 | x->len = 1; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 634 | spi_message_add_tail(x, m); |
Imre Deak | 53a0ef89 | 2006-04-11 23:41:49 -0400 | [diff] [blame] | 635 | |
| 636 | x++; |
| 637 | x->rx_buf = &ts->dummy; |
| 638 | x->len = 2; |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 639 | CS_CHANGE(*x); |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 640 | spi_message_add_tail(x, m); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 641 | |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 642 | m->complete = ads7846_rx; |
| 643 | m->context = ts; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 644 | |
Russell King | f43aaba | 2006-01-19 12:26:57 +0000 | [diff] [blame] | 645 | if (request_irq(spi->irq, ads7846_irq, |
| 646 | SA_SAMPLE_RANDOM | SA_TRIGGER_FALLING, |
| 647 | spi->dev.bus_id, ts)) { |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 648 | dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq); |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 649 | err = -EBUSY; |
| 650 | goto err_free_mem; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 651 | } |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 652 | |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 653 | dev_info(&spi->dev, "touchscreen, irq %d\n", spi->irq); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 654 | |
| 655 | /* take a first sample, leaving nPENIRQ active; avoid |
| 656 | * the touchscreen, in case it's not connected. |
| 657 | */ |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 658 | (void) ads7846_read12_ser(&spi->dev, |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 659 | READ_12BIT_SER(vaux) | ADS_PD10_ALL_ON); |
| 660 | |
| 661 | /* ads7843/7845 don't have temperature sensors, and |
| 662 | * use the other sensors a bit differently too |
| 663 | */ |
| 664 | if (ts->model == 7846) { |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 665 | device_create_file(&spi->dev, &dev_attr_temp0); |
| 666 | device_create_file(&spi->dev, &dev_attr_temp1); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 667 | } |
| 668 | if (ts->model != 7845) |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 669 | device_create_file(&spi->dev, &dev_attr_vbatt); |
| 670 | device_create_file(&spi->dev, &dev_attr_vaux); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 671 | |
Imre Deak | 438f2a7 | 2006-04-11 23:41:32 -0400 | [diff] [blame] | 672 | device_create_file(&spi->dev, &dev_attr_pen_down); |
| 673 | |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 674 | err = input_register_device(input_dev); |
| 675 | if (err) |
| 676 | goto err_free_irq; |
| 677 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 678 | return 0; |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 679 | |
| 680 | err_free_irq: |
| 681 | free_irq(spi->irq, ts); |
| 682 | err_free_mem: |
| 683 | input_free_device(input_dev); |
| 684 | kfree(ts); |
| 685 | return err; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 686 | } |
| 687 | |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 688 | static int __devexit ads7846_remove(struct spi_device *spi) |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 689 | { |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 690 | struct ads7846 *ts = dev_get_drvdata(&spi->dev); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 691 | |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 692 | ads7846_suspend(spi, PMSG_SUSPEND); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 693 | free_irq(ts->spi->irq, ts); |
| 694 | if (ts->irq_disabled) |
| 695 | enable_irq(ts->spi->irq); |
| 696 | |
Imre Deak | 438f2a7 | 2006-04-11 23:41:32 -0400 | [diff] [blame] | 697 | device_remove_file(&spi->dev, &dev_attr_pen_down); |
| 698 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 699 | if (ts->model == 7846) { |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 700 | device_remove_file(&spi->dev, &dev_attr_temp0); |
| 701 | device_remove_file(&spi->dev, &dev_attr_temp1); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 702 | } |
| 703 | if (ts->model != 7845) |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 704 | device_remove_file(&spi->dev, &dev_attr_vbatt); |
| 705 | device_remove_file(&spi->dev, &dev_attr_vaux); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 706 | |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 707 | input_unregister_device(ts->input); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 708 | kfree(ts); |
| 709 | |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 710 | dev_dbg(&spi->dev, "unregistered touchscreen\n"); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 711 | return 0; |
| 712 | } |
| 713 | |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 714 | static struct spi_driver ads7846_driver = { |
| 715 | .driver = { |
| 716 | .name = "ads7846", |
| 717 | .bus = &spi_bus_type, |
| 718 | .owner = THIS_MODULE, |
| 719 | }, |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 720 | .probe = ads7846_probe, |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 721 | .remove = __devexit_p(ads7846_remove), |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 722 | .suspend = ads7846_suspend, |
| 723 | .resume = ads7846_resume, |
| 724 | }; |
| 725 | |
| 726 | static int __init ads7846_init(void) |
| 727 | { |
| 728 | /* grr, board-specific init should stay out of drivers!! */ |
| 729 | |
| 730 | #ifdef CONFIG_ARCH_OMAP |
| 731 | if (machine_is_omap_osk()) { |
| 732 | /* GPIO4 = PENIRQ; GPIO6 = BUSY */ |
| 733 | omap_request_gpio(4); |
| 734 | omap_set_gpio_direction(4, 1); |
| 735 | omap_request_gpio(6); |
| 736 | omap_set_gpio_direction(6, 1); |
| 737 | } |
| 738 | // also TI 1510 Innovator, bitbanging through FPGA |
| 739 | // also Nokia 770 |
| 740 | // also Palm Tungsten T2 |
| 741 | #endif |
| 742 | |
| 743 | // PXA: |
| 744 | // also Dell Axim X50 |
| 745 | // also HP iPaq H191x/H192x/H415x/H435x |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 746 | // also Intel Lubbock (additional to UCB1400; as temperature sensor) |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 747 | // also Sharp Zaurus C7xx, C8xx (corgi/sheperd/husky) |
| 748 | |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 749 | // Atmel at91sam9261-EK uses ads7843 |
| 750 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 751 | // also various AMD Au1x00 devel boards |
| 752 | |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 753 | return spi_register_driver(&ads7846_driver); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 754 | } |
| 755 | module_init(ads7846_init); |
| 756 | |
| 757 | static void __exit ads7846_exit(void) |
| 758 | { |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 759 | spi_unregister_driver(&ads7846_driver); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 760 | |
| 761 | #ifdef CONFIG_ARCH_OMAP |
| 762 | if (machine_is_omap_osk()) { |
| 763 | omap_free_gpio(4); |
| 764 | omap_free_gpio(6); |
| 765 | } |
| 766 | #endif |
| 767 | |
| 768 | } |
| 769 | module_exit(ads7846_exit); |
| 770 | |
| 771 | MODULE_DESCRIPTION("ADS7846 TouchScreen Driver"); |
| 772 | MODULE_LICENSE("GPL"); |