2 * ADS7846 based touchscreen and sensor driver
4 * Copyright (c) 2005 David Brownell
5 * Copyright (c) 2006 Nokia Corporation
6 * Various changes: Imre Deak <imre.deak@nokia.com>
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
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.
20 #include <linux/hwmon.h>
21 #include <linux/init.h>
22 #include <linux/err.h>
23 #include <linux/delay.h>
24 #include <linux/input.h>
25 #include <linux/interrupt.h>
26 #include <linux/slab.h>
27 #include <linux/spi/spi.h>
28 #include <linux/spi/ads7846.h>
32 #include <asm/mach-types.h>
33 #ifdef CONFIG_ARCH_OMAP
34 #include <asm/arch/gpio.h>
40 * This code has been heavily tested on a Nokia 770, and lightly
41 * tested on other ads7846 devices (OSK/Mistral, Lubbock).
42 * Support for ads7843 and ads7845 has only been stubbed in.
44 * IRQ handling needs a workaround because of a shortcoming in handling
45 * edge triggered IRQs on some platforms like the OMAP1/2. These
46 * platforms don't handle the ARM lazy IRQ disabling properly, thus we
47 * have to maintain our own SW IRQ disabled status. This should be
48 * removed as soon as the affected platform's IRQ handling is fixed.
50 * app note sbaa036 talks in more detail about accurate sampling...
51 * that ought to help in situations like LCDs inducing noise (which
52 * can also be helped by using synch signals) and more generally.
53 * This driver tries to utilize the measures described in the app
54 * note. The strength of filtering can be set in the board-* specific
58 #define TS_POLL_PERIOD msecs_to_jiffies(10)
60 /* this driver doesn't aim at the peak continuous sample rate */
61 #define SAMPLE_BITS (8 /*cmd*/ + 16 /*sample*/ + 2 /* before, after */)
64 /* For portability, we can't read 12 bit values using SPI (which
65 * would make the controller deliver them as native byteorder u16
66 * with msbs zeroed). Instead, we read them as two 8-bit values,
67 * which need byteswapping then range adjustment.
76 struct input_dev *input;
79 struct spi_device *spi;
80 struct class_device *hwmon;
86 u8 read_x, read_y, read_z1, read_z2, pwrdown;
87 u16 dummy; /* for the pwrdown read */
90 struct spi_transfer xfer[10];
91 struct spi_message msg[5];
92 struct spi_message *last_msg;
103 struct timer_list timer; /* P: lock */
104 unsigned pendown:1; /* P: lock */
105 unsigned pending:1; /* P: lock */
106 // FIXME remove "irq_disabled"
107 unsigned irq_disabled:1; /* P: lock */
110 int (*get_pendown_state)(void);
113 /* leave chip selected when we're done, for quicker re-select? */
115 #define CS_CHANGE(xfer) ((xfer).cs_change = 1)
117 #define CS_CHANGE(xfer) ((xfer).cs_change = 0)
120 /*--------------------------------------------------------------------------*/
122 /* The ADS7846 has touchscreen and other sensors.
123 * Earlier ads784x chips are somewhat compatible.
125 #define ADS_START (1 << 7)
126 #define ADS_A2A1A0_d_y (1 << 4) /* differential */
127 #define ADS_A2A1A0_d_z1 (3 << 4) /* differential */
128 #define ADS_A2A1A0_d_z2 (4 << 4) /* differential */
129 #define ADS_A2A1A0_d_x (5 << 4) /* differential */
130 #define ADS_A2A1A0_temp0 (0 << 4) /* non-differential */
131 #define ADS_A2A1A0_vbatt (2 << 4) /* non-differential */
132 #define ADS_A2A1A0_vaux (6 << 4) /* non-differential */
133 #define ADS_A2A1A0_temp1 (7 << 4) /* non-differential */
134 #define ADS_8_BIT (1 << 3)
135 #define ADS_12_BIT (0 << 3)
136 #define ADS_SER (1 << 2) /* non-differential */
137 #define ADS_DFR (0 << 2) /* differential */
138 #define ADS_PD10_PDOWN (0 << 0) /* lowpower mode + penirq */
139 #define ADS_PD10_ADC_ON (1 << 0) /* ADC on */
140 #define ADS_PD10_REF_ON (2 << 0) /* vREF on + penirq */
141 #define ADS_PD10_ALL_ON (3 << 0) /* ADC + vREF on */
143 #define MAX_12BIT ((1<<12)-1)
145 /* leave ADC powered up (disables penirq) between differential samples */
146 #define READ_12BIT_DFR(x) (ADS_START | ADS_A2A1A0_d_ ## x \
147 | ADS_12_BIT | ADS_DFR)
149 #define READ_Y (READ_12BIT_DFR(y) | ADS_PD10_ADC_ON)
150 #define READ_Z1 (READ_12BIT_DFR(z1) | ADS_PD10_ADC_ON)
151 #define READ_Z2 (READ_12BIT_DFR(z2) | ADS_PD10_ADC_ON)
153 #define READ_X (READ_12BIT_DFR(x) | ADS_PD10_ADC_ON)
154 #define PWRDOWN (READ_12BIT_DFR(y) | ADS_PD10_PDOWN) /* LAST */
156 /* single-ended samples need to first power up reference voltage;
157 * we leave both ADC and VREF powered
159 #define READ_12BIT_SER(x) (ADS_START | ADS_A2A1A0_ ## x \
160 | ADS_12_BIT | ADS_SER)
162 #define REF_ON (READ_12BIT_DFR(x) | ADS_PD10_ALL_ON)
163 #define REF_OFF (READ_12BIT_DFR(y) | ADS_PD10_PDOWN)
165 /*--------------------------------------------------------------------------*/
168 * Non-touchscreen sensors only use single-ended conversions.
169 * The range is GND..vREF. The ads7843 and ads7835 must use external vREF;
170 * ads7846 lets that pin be unconnected, to use internal vREF.
172 * FIXME make external vREF_mV be a module option, and use that as needed...
174 static const unsigned vREF_mV = 2500;
182 struct spi_message msg;
183 struct spi_transfer xfer[6];
186 static void ads7846_enable(struct ads7846 *ts);
187 static void ads7846_disable(struct ads7846 *ts);
189 static int device_suspended(struct device *dev)
191 struct ads7846 *ts = dev_get_drvdata(dev);
192 return dev->power.power_state.event != PM_EVENT_ON || ts->disabled;
195 static int ads7846_read12_ser(struct device *dev, unsigned command)
197 struct spi_device *spi = to_spi_device(dev);
198 struct ads7846 *ts = dev_get_drvdata(dev);
199 struct ser_req *req = kzalloc(sizeof *req, SLAB_KERNEL);
207 spi_message_init(&req->msg);
209 /* FIXME boards with ads7846 might use external vref instead ... */
210 use_internal = (ts->model == 7846);
212 /* maybe turn on internal vREF, and let it settle */
214 req->ref_on = REF_ON;
215 req->xfer[0].tx_buf = &req->ref_on;
216 req->xfer[0].len = 1;
217 spi_message_add_tail(&req->xfer[0], &req->msg);
219 req->xfer[1].rx_buf = &req->scratch;
220 req->xfer[1].len = 2;
222 /* for 1uF, settle for 800 usec; no cap, 100 usec. */
223 req->xfer[1].delay_usecs = ts->vref_delay_usecs;
224 spi_message_add_tail(&req->xfer[1], &req->msg);
228 req->command = (u8) command;
229 req->xfer[2].tx_buf = &req->command;
230 req->xfer[2].len = 1;
231 spi_message_add_tail(&req->xfer[2], &req->msg);
233 req->xfer[3].rx_buf = &req->sample;
234 req->xfer[3].len = 2;
235 spi_message_add_tail(&req->xfer[3], &req->msg);
237 /* REVISIT: take a few more samples, and compare ... */
239 /* maybe off internal vREF */
241 req->ref_off = REF_OFF;
242 req->xfer[4].tx_buf = &req->ref_off;
243 req->xfer[4].len = 1;
244 spi_message_add_tail(&req->xfer[4], &req->msg);
246 req->xfer[5].rx_buf = &req->scratch;
247 req->xfer[5].len = 2;
248 CS_CHANGE(req->xfer[5]);
249 spi_message_add_tail(&req->xfer[5], &req->msg);
252 ts->irq_disabled = 1;
253 disable_irq(spi->irq);
254 status = spi_sync(spi, &req->msg);
255 ts->irq_disabled = 0;
256 enable_irq(spi->irq);
259 status = req->msg.status;
261 /* on-wire is a must-ignore bit, a BE12 value, then padding */
262 sample = be16_to_cpu(req->sample);
263 sample = sample >> 3;
267 return status ? status : sample;
270 #define SHOW(name,var,adjust) static ssize_t \
271 name ## _show(struct device *dev, struct device_attribute *attr, char *buf) \
273 struct ads7846 *ts = dev_get_drvdata(dev); \
274 ssize_t v = ads7846_read12_ser(dev, \
275 READ_12BIT_SER(var) | ADS_PD10_ALL_ON); \
278 return sprintf(buf, "%u\n", adjust(ts, v)); \
280 static DEVICE_ATTR(name, S_IRUGO, name ## _show, NULL);
283 /* Sysfs conventions report temperatures in millidegrees Celcius.
284 * We could use the low-accuracy two-sample scheme, but can't do the high
285 * accuracy scheme without calibration data. For now we won't try either;
286 * userspace sees raw sensor values, and must scale appropriately.
288 static inline unsigned null_adjust(struct ads7846 *ts, ssize_t v)
293 SHOW(temp0, temp0, null_adjust) // temp1_input
294 SHOW(temp1, temp1, null_adjust) // temp2_input
297 /* sysfs conventions report voltages in millivolts. We can convert voltages
298 * if we know vREF. userspace may need to scale vAUX to match the board's
299 * external resistors; we assume that vBATT only uses the internal ones.
301 static inline unsigned vaux_adjust(struct ads7846 *ts, ssize_t v)
305 /* external resistors may scale vAUX into 0..vREF */
307 retval = retval >> 12;
311 static inline unsigned vbatt_adjust(struct ads7846 *ts, ssize_t v)
313 unsigned retval = vaux_adjust(ts, v);
315 /* ads7846 has a resistor ladder to scale this signal down */
316 if (ts->model == 7846)
321 SHOW(in0_input, vaux, vaux_adjust)
322 SHOW(in1_input, vbatt, vbatt_adjust)
325 static int is_pen_down(struct device *dev)
327 struct ads7846 *ts = dev_get_drvdata(dev);
332 static ssize_t ads7846_pen_down_show(struct device *dev,
333 struct device_attribute *attr, char *buf)
335 return sprintf(buf, "%u\n", is_pen_down(dev));
338 static DEVICE_ATTR(pen_down, S_IRUGO, ads7846_pen_down_show, NULL);
340 static ssize_t ads7846_disable_show(struct device *dev,
341 struct device_attribute *attr, char *buf)
343 struct ads7846 *ts = dev_get_drvdata(dev);
345 return sprintf(buf, "%u\n", ts->disabled);
348 static ssize_t ads7846_disable_store(struct device *dev,
349 struct device_attribute *attr,
350 const char *buf, size_t count)
352 struct ads7846 *ts = dev_get_drvdata(dev);
356 i = simple_strtoul(buf, &endp, 10);
357 spin_lock_irq(&ts->lock);
364 spin_unlock_irq(&ts->lock);
369 static DEVICE_ATTR(disable, 0664, ads7846_disable_show, ads7846_disable_store);
371 /*--------------------------------------------------------------------------*/
374 * PENIRQ only kicks the timer. The timer only reissues the SPI transfer,
375 * to retrieve touchscreen status.
377 * The SPI transfer completion callback does the real work. It reports
378 * touchscreen events and reactivates the timer (or IRQ) as appropriate.
381 static void ads7846_rx(void *ads)
383 struct ads7846 *ts = ads;
384 struct input_dev *input_dev = ts->input;
390 /* adjust: on-wire is a must-ignore bit, a BE12 value, then padding;
391 * built from two 8 bit values written msb-first.
393 x = (be16_to_cpu(ts->tc.x) >> 3) & 0x0fff;
394 y = (be16_to_cpu(ts->tc.y) >> 3) & 0x0fff;
395 z1 = (be16_to_cpu(ts->tc.z1) >> 3) & 0x0fff;
396 z2 = (be16_to_cpu(ts->tc.z2) >> 3) & 0x0fff;
398 /* range filtering */
402 if (likely(x && z1 && !device_suspended(&ts->spi->dev))) {
403 /* compute touch pressure resistance using equation #2 */
407 Rt *= ts->x_plate_ohms;
409 Rt = (Rt + 2047) >> 12;
413 /* Sample found inconsistent by debouncing or pressure is beyond
414 * the maximum. Don't report it to user space, repeat at least
415 * once more the measurement */
416 if (ts->tc.ignore || Rt > ts->pressure_max) {
417 mod_timer(&ts->timer, jiffies + TS_POLL_PERIOD);
421 /* NOTE: "pendown" is inferred from pressure; we don't rely on
422 * being able to check nPENIRQ status, or "friendly" trigger modes
423 * (both-edges is much better than just-falling or low-level).
425 * REVISIT: some boards may require reading nPENIRQ; it's
426 * needed on 7843. and 7845 reads pressure differently...
428 * REVISIT: the touchscreen might not be connected; this code
429 * won't notice that, even if nPENIRQ never fires ...
431 if (!ts->pendown && Rt != 0) {
432 input_report_key(input_dev, BTN_TOUCH, 1);
434 } else if (ts->pendown && Rt == 0) {
435 input_report_key(input_dev, BTN_TOUCH, 0);
440 input_report_abs(input_dev, ABS_X, x);
441 input_report_abs(input_dev, ABS_Y, y);
446 input_report_abs(input_dev, ABS_PRESSURE, Rt);
447 input_sync(input_dev);
451 if (Rt || ts->pendown)
452 pr_debug("%s: %d/%d/%d%s\n", ts->spi->dev.bus_id,
453 x, y, Rt, Rt ? "" : " UP");
456 spin_lock_irqsave(&ts->lock, flags);
458 ts->pendown = (Rt != 0);
459 mod_timer(&ts->timer, jiffies + TS_POLL_PERIOD);
461 spin_unlock_irqrestore(&ts->lock, flags);
464 static void ads7846_debounce(void *ads)
466 struct ads7846 *ts = ads;
467 struct spi_message *m;
468 struct spi_transfer *t;
472 m = &ts->msg[ts->msg_idx];
473 t = list_entry(m->transfers.prev, struct spi_transfer, transfer_list);
474 val = (be16_to_cpu(*(__be16 *)t->rx_buf) >> 3) & 0x0fff;
475 if (ts->debounce_max && (
476 !ts->read_cnt || (abs(ts->last_read - val) > ts->debounce_tol))) {
477 /* Repeat it, if this was the first read or the read
478 * wasn't consistent enough. */
479 if (ts->read_cnt < ts->debounce_max) {
483 /* Maximum number of debouncing reached and still
484 * not enough number of consistent readings. Abort
485 * the whole sample, repeat it in the next sampling
490 /* Last message will contain ads7846_rx() as the
491 * completion function.
495 /* Start over collecting consistent readings. */
498 if (++ts->read_rep > ts->debounce_rep) {
499 /* Got a good reading for this coordinate,
500 * go for the next one. */
507 /* Read more values that are consistent. */
510 status = spi_async(ts->spi, m);
512 dev_err(&ts->spi->dev, "spi_async --> %d\n",
516 static void ads7846_timer(unsigned long handle)
518 struct ads7846 *ts = (void *)handle;
521 spin_lock_irq(&ts->lock);
523 if (unlikely(ts->msg_idx && !ts->pendown)) {
524 /* measurment cycle ended */
525 if (!device_suspended(&ts->spi->dev)) {
526 ts->irq_disabled = 0;
527 enable_irq(ts->spi->irq);
532 /* pen is still down, continue with the measurement */
534 status = spi_async(ts->spi, &ts->msg[0]);
536 dev_err(&ts->spi->dev, "spi_async --> %d\n", status);
539 spin_unlock_irq(&ts->lock);
542 static irqreturn_t ads7846_irq(int irq, void *handle, struct pt_regs *regs)
544 struct ads7846 *ts = handle;
547 spin_lock_irqsave(&ts->lock, flags);
548 if (likely(ts->get_pendown_state())) {
549 if (!ts->irq_disabled) {
550 /* REVISIT irq logic for many ARM chips has cloned a
551 * bug wherein disabling an irq in its handler won't
552 * work;(it's disabled lazily, and too late to work.
553 * until all their irq logic is fixed, we must shadow
556 ts->irq_disabled = 1;
557 disable_irq(ts->spi->irq);
559 mod_timer(&ts->timer, jiffies);
562 spin_unlock_irqrestore(&ts->lock, flags);
567 /*--------------------------------------------------------------------------*/
569 /* Must be called with ts->lock held */
570 static void ads7846_disable(struct ads7846 *ts)
577 /* are we waiting for IRQ, or polling? */
579 ts->irq_disabled = 1;
580 disable_irq(ts->spi->irq);
582 /* the timer will run at least once more, and
583 * leave everything in a clean state, IRQ disabled
585 while (ts->pending) {
586 spin_unlock_irq(&ts->lock);
588 spin_lock_irq(&ts->lock);
592 /* we know the chip's in lowpower mode since we always
593 * leave it that way after every request
598 /* Must be called with ts->lock held */
599 static void ads7846_enable(struct ads7846 *ts)
605 ts->irq_disabled = 0;
606 enable_irq(ts->spi->irq);
609 static int ads7846_suspend(struct spi_device *spi, pm_message_t message)
611 struct ads7846 *ts = dev_get_drvdata(&spi->dev);
613 spin_lock_irq(&ts->lock);
615 spi->dev.power.power_state = message;
618 spin_unlock_irq(&ts->lock);
624 static int ads7846_resume(struct spi_device *spi)
626 struct ads7846 *ts = dev_get_drvdata(&spi->dev);
628 spin_lock_irq(&ts->lock);
630 spi->dev.power.power_state = PMSG_ON;
633 spin_unlock_irq(&ts->lock);
638 static int __devinit ads7846_probe(struct spi_device *spi)
641 struct input_dev *input_dev;
642 struct class_device *hwmon = ERR_PTR(-ENOMEM);
643 struct ads7846_platform_data *pdata = spi->dev.platform_data;
644 struct spi_message *m;
645 struct spi_transfer *x;
649 dev_dbg(&spi->dev, "no IRQ?\n");
654 dev_dbg(&spi->dev, "no platform data?\n");
658 /* don't exceed max specified sample rate */
659 if (spi->max_speed_hz > (125000 * SAMPLE_BITS)) {
660 dev_dbg(&spi->dev, "f(sample) %d KHz?\n",
661 (spi->max_speed_hz/SAMPLE_BITS)/1000);
665 if (pdata->get_pendown_state == NULL) {
666 dev_dbg(&spi->dev, "no get_pendown_state function?\n");
670 /* We'd set the wordsize to 12 bits ... except that some controllers
671 * will then treat the 8 bit command words as 12 bits (and drop the
672 * four MSBs of the 12 bit result). Result: inputs must be shifted
673 * to discard the four garbage LSBs. (Also, not all controllers can
674 * support 12 bit words.)
677 ts = kzalloc(sizeof(struct ads7846), GFP_KERNEL);
678 input_dev = input_allocate_device();
679 hwmon = hwmon_device_register(&spi->dev);
680 if (!ts || !input_dev || IS_ERR(hwmon)) {
685 dev_set_drvdata(&spi->dev, ts);
686 spi->dev.power.power_state = PMSG_ON;
687 spi->mode = SPI_MODE_1;
688 err = spi_setup(spi);
693 ts->input = input_dev;
696 init_timer(&ts->timer);
697 ts->timer.data = (unsigned long) ts;
698 ts->timer.function = ads7846_timer;
700 spin_lock_init(&ts->lock);
702 ts->model = pdata->model ? : 7846;
703 ts->vref_delay_usecs = pdata->vref_delay_usecs ? : 100;
704 ts->x_plate_ohms = pdata->x_plate_ohms ? : 400;
705 ts->pressure_max = pdata->pressure_max ? : ~0;
706 ts->debounce_max = pdata->debounce_max;
707 ts->debounce_tol = pdata->debounce_tol;
708 ts->debounce_rep = pdata->debounce_rep;
709 ts->get_pendown_state = pdata->get_pendown_state;
711 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", spi->dev.bus_id);
713 input_dev->name = "ADS784x Touchscreen";
714 input_dev->phys = ts->phys;
715 input_dev->cdev.dev = &spi->dev;
717 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
718 input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
719 input_set_abs_params(input_dev, ABS_X,
721 pdata->x_max ? : MAX_12BIT,
723 input_set_abs_params(input_dev, ABS_Y,
725 pdata->y_max ? : MAX_12BIT,
727 input_set_abs_params(input_dev, ABS_PRESSURE,
728 pdata->pressure_min, pdata->pressure_max, 0, 0);
730 /* set up the transfers to read touchscreen state; this assumes we
731 * use formula #2 for pressure, not #3.
738 /* y- still on; turn on only y+ (and ADC) */
740 x->tx_buf = &ts->read_y;
742 spi_message_add_tail(x, m);
745 x->rx_buf = &ts->tc.y;
747 spi_message_add_tail(x, m);
749 m->complete = ads7846_debounce;
755 /* turn y- off, x+ on, then leave in lowpower */
758 x->tx_buf = &ts->read_x;
760 spi_message_add_tail(x, m);
763 x->rx_buf = &ts->tc.x;
765 spi_message_add_tail(x, m);
767 m->complete = ads7846_debounce;
770 /* turn y+ off, x- on; we'll use formula #2 */
771 if (ts->model == 7846) {
776 ts->read_z1 = READ_Z1;
777 x->tx_buf = &ts->read_z1;
779 spi_message_add_tail(x, m);
782 x->rx_buf = &ts->tc.z1;
784 spi_message_add_tail(x, m);
786 m->complete = ads7846_debounce;
793 ts->read_z2 = READ_Z2;
794 x->tx_buf = &ts->read_z2;
796 spi_message_add_tail(x, m);
799 x->rx_buf = &ts->tc.z2;
801 spi_message_add_tail(x, m);
803 m->complete = ads7846_debounce;
812 ts->pwrdown = PWRDOWN;
813 x->tx_buf = &ts->pwrdown;
815 spi_message_add_tail(x, m);
818 x->rx_buf = &ts->dummy;
821 spi_message_add_tail(x, m);
823 m->complete = ads7846_rx;
828 if (request_irq(spi->irq, ads7846_irq,
829 SA_SAMPLE_RANDOM | SA_TRIGGER_FALLING,
830 spi->dev.bus_id, ts)) {
831 dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq);
836 dev_info(&spi->dev, "touchscreen + hwmon, irq %d\n", spi->irq);
838 /* take a first sample, leaving nPENIRQ active and vREF off; avoid
839 * the touchscreen, in case it's not connected.
841 (void) ads7846_read12_ser(&spi->dev,
842 READ_12BIT_SER(vaux) | ADS_PD10_ALL_ON);
844 /* ads7843/7845 don't have temperature sensors, and
845 * use the other ADC lines a bit differently too
847 if (ts->model == 7846) {
848 device_create_file(&spi->dev, &dev_attr_temp0);
849 device_create_file(&spi->dev, &dev_attr_temp1);
851 /* in1 == vBAT (7846), or a non-scaled ADC input */
852 if (ts->model != 7845)
853 device_create_file(&spi->dev, &dev_attr_in1_input);
854 /* in0 == a non-scaled ADC input */
855 device_create_file(&spi->dev, &dev_attr_in0_input);
857 /* non-hwmon device attributes */
858 device_create_file(&spi->dev, &dev_attr_pen_down);
859 device_create_file(&spi->dev, &dev_attr_disable);
861 err = input_register_device(input_dev);
863 goto err_remove_attr;
868 device_remove_file(&spi->dev, &dev_attr_disable);
869 device_remove_file(&spi->dev, &dev_attr_pen_down);
870 if (ts->model == 7846) {
871 device_remove_file(&spi->dev, &dev_attr_temp1);
872 device_remove_file(&spi->dev, &dev_attr_temp0);
874 if (ts->model != 7845)
875 device_remove_file(&spi->dev, &dev_attr_in1_input);
876 device_remove_file(&spi->dev, &dev_attr_in0_input);
878 free_irq(spi->irq, ts);
881 hwmon_device_unregister(hwmon);
882 input_free_device(input_dev);
887 static int __devexit ads7846_remove(struct spi_device *spi)
889 struct ads7846 *ts = dev_get_drvdata(&spi->dev);
891 hwmon_device_unregister(ts->hwmon);
892 input_unregister_device(ts->input);
894 ads7846_suspend(spi, PMSG_SUSPEND);
896 device_remove_file(&spi->dev, &dev_attr_disable);
897 device_remove_file(&spi->dev, &dev_attr_pen_down);
898 if (ts->model == 7846) {
899 device_remove_file(&spi->dev, &dev_attr_temp1);
900 device_remove_file(&spi->dev, &dev_attr_temp0);
902 if (ts->model != 7845)
903 device_remove_file(&spi->dev, &dev_attr_in1_input);
904 device_remove_file(&spi->dev, &dev_attr_in0_input);
906 free_irq(ts->spi->irq, ts);
907 /* suspend left the IRQ disabled */
908 enable_irq(ts->spi->irq);
912 dev_dbg(&spi->dev, "unregistered touchscreen\n");
916 static struct spi_driver ads7846_driver = {
919 .bus = &spi_bus_type,
920 .owner = THIS_MODULE,
922 .probe = ads7846_probe,
923 .remove = __devexit_p(ads7846_remove),
924 .suspend = ads7846_suspend,
925 .resume = ads7846_resume,
928 static int __init ads7846_init(void)
930 /* grr, board-specific init should stay out of drivers!! */
932 #ifdef CONFIG_ARCH_OMAP
933 if (machine_is_omap_osk()) {
934 /* GPIO4 = PENIRQ; GPIO6 = BUSY */
935 omap_request_gpio(4);
936 omap_set_gpio_direction(4, 1);
937 omap_request_gpio(6);
938 omap_set_gpio_direction(6, 1);
940 // also TI 1510 Innovator, bitbanging through FPGA
942 // also Palm Tungsten T2
946 // also Dell Axim X50
947 // also HP iPaq H191x/H192x/H415x/H435x
948 // also Intel Lubbock (additional to UCB1400; as temperature sensor)
949 // also Sharp Zaurus C7xx, C8xx (corgi/sheperd/husky)
951 // Atmel at91sam9261-EK uses ads7843
953 // also various AMD Au1x00 devel boards
955 return spi_register_driver(&ads7846_driver);
957 device_initcall(ads7846_init);
959 static void __exit ads7846_exit(void)
961 spi_unregister_driver(&ads7846_driver);
963 #ifdef CONFIG_ARCH_OMAP
964 if (machine_is_omap_osk()) {
971 module_exit(ads7846_exit);
973 MODULE_DESCRIPTION("ADS7846 TouchScreen Driver");
974 MODULE_LICENSE("GPL");