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/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>
 
  31 #include <asm/mach-types.h>
 
  32 #ifdef  CONFIG_ARCH_OMAP
 
  33 #include <asm/arch/gpio.h>
 
  39  * This code has been tested on an ads7846 / N770 device.
 
  40  * Support for ads7843 and ads7845 has only been stubbed in.
 
  42  * Not yet done:  How accurate are the temperature and voltage
 
  43  * readings? (System-specific calibration should support
 
  44  * accuracy of 0.3 degrees C; otherwise it's 2.0 degrees.)
 
  46  * IRQ handling needs a workaround because of a shortcoming in handling
 
  47  * edge triggered IRQs on some platforms like the OMAP1/2. These
 
  48  * platforms don't handle the ARM lazy IRQ disabling properly, thus we
 
  49  * have to maintain our own SW IRQ disabled status. This should be
 
  50  * removed as soon as the affected platform's IRQ handling is fixed.
 
  52  * app note sbaa036 talks in more detail about accurate sampling...
 
  53  * that ought to help in situations like LCDs inducing noise (which
 
  54  * can also be helped by using synch signals) and more generally.
 
  55  * This driver tries to utilize the measures described in the app
 
  56  * note. The strength of filtering can be set in the board-* specific
 
  60 #define TS_POLL_PERIOD  msecs_to_jiffies(10)
 
  62 /* this driver doesn't aim at the peak continuous sample rate */
 
  63 #define SAMPLE_BITS     (8 /*cmd*/ + 16 /*sample*/ + 2 /* before, after */)
 
  66         /* For portability, we can't read 12 bit values using SPI (which
 
  67          * would make the controller deliver them as native byteorder u16
 
  68          * with msbs zeroed).  Instead, we read them as two 8-bit values,
 
  69          * which need byteswapping then range adjustment.
 
  78         struct input_dev        *input;
 
  81         struct spi_device       *spi;
 
  87         u8                      read_x, read_y, read_z1, read_z2, pwrdown;
 
  88         u16                     dummy;          /* for the pwrdown read */
 
  91         struct spi_transfer     xfer[10];
 
  92         struct spi_message      msg[5];
 
  93         struct spi_message      *last_msg;
 
 104         struct timer_list       timer;          /* P: lock */
 
 105         unsigned                pendown:1;      /* P: lock */
 
 106         unsigned                pending:1;      /* P: lock */
 
 107 // FIXME remove "irq_disabled"
 
 108         unsigned                irq_disabled:1; /* P: lock */
 
 111         int                     (*get_pendown_state)(void);
 
 114 /* leave chip selected when we're done, for quicker re-select? */
 
 116 #define CS_CHANGE(xfer) ((xfer).cs_change = 1)
 
 118 #define CS_CHANGE(xfer) ((xfer).cs_change = 0)
 
 121 /*--------------------------------------------------------------------------*/
 
 123 /* The ADS7846 has touchscreen and other sensors.
 
 124  * Earlier ads784x chips are somewhat compatible.
 
 126 #define ADS_START               (1 << 7)
 
 127 #define ADS_A2A1A0_d_y          (1 << 4)        /* differential */
 
 128 #define ADS_A2A1A0_d_z1         (3 << 4)        /* differential */
 
 129 #define ADS_A2A1A0_d_z2         (4 << 4)        /* differential */
 
 130 #define ADS_A2A1A0_d_x          (5 << 4)        /* differential */
 
 131 #define ADS_A2A1A0_temp0        (0 << 4)        /* non-differential */
 
 132 #define ADS_A2A1A0_vbatt        (2 << 4)        /* non-differential */
 
 133 #define ADS_A2A1A0_vaux         (6 << 4)        /* non-differential */
 
 134 #define ADS_A2A1A0_temp1        (7 << 4)        /* non-differential */
 
 135 #define ADS_8_BIT               (1 << 3)
 
 136 #define ADS_12_BIT              (0 << 3)
 
 137 #define ADS_SER                 (1 << 2)        /* non-differential */
 
 138 #define ADS_DFR                 (0 << 2)        /* differential */
 
 139 #define ADS_PD10_PDOWN          (0 << 0)        /* lowpower mode + penirq */
 
 140 #define ADS_PD10_ADC_ON         (1 << 0)        /* ADC on */
 
 141 #define ADS_PD10_REF_ON         (2 << 0)        /* vREF on + penirq */
 
 142 #define ADS_PD10_ALL_ON         (3 << 0)        /* ADC + vREF on */
 
 144 #define MAX_12BIT       ((1<<12)-1)
 
 146 /* leave ADC powered up (disables penirq) between differential samples */
 
 147 #define READ_12BIT_DFR(x) (ADS_START | ADS_A2A1A0_d_ ## x \
 
 148         | ADS_12_BIT | ADS_DFR)
 
 150 #define READ_Y  (READ_12BIT_DFR(y)  | ADS_PD10_ADC_ON)
 
 151 #define READ_Z1 (READ_12BIT_DFR(z1) | ADS_PD10_ADC_ON)
 
 152 #define READ_Z2 (READ_12BIT_DFR(z2) | ADS_PD10_ADC_ON)
 
 154 #define READ_X  (READ_12BIT_DFR(x)  | ADS_PD10_ADC_ON)
 
 155 #define PWRDOWN (READ_12BIT_DFR(y)  | ADS_PD10_PDOWN)   /* LAST */
 
 157 /* single-ended samples need to first power up reference voltage;
 
 158  * we leave both ADC and VREF powered
 
 160 #define READ_12BIT_SER(x) (ADS_START | ADS_A2A1A0_ ## x \
 
 161         | ADS_12_BIT | ADS_SER)
 
 163 #define REF_ON  (READ_12BIT_DFR(x) | ADS_PD10_ALL_ON)
 
 164 #define REF_OFF (READ_12BIT_DFR(y) | ADS_PD10_PDOWN)
 
 166 /*--------------------------------------------------------------------------*/
 
 169  * Non-touchscreen sensors only use single-ended conversions.
 
 178         struct spi_message      msg;
 
 179         struct spi_transfer     xfer[6];
 
 182 static void ads7846_enable(struct ads7846 *ts);
 
 183 static void ads7846_disable(struct ads7846 *ts);
 
 185 static int device_suspended(struct device *dev)
 
 187         struct ads7846 *ts = dev_get_drvdata(dev);
 
 188         return dev->power.power_state.event != PM_EVENT_ON || ts->disabled;
 
 191 static int ads7846_read12_ser(struct device *dev, unsigned command)
 
 193         struct spi_device       *spi = to_spi_device(dev);
 
 194         struct ads7846          *ts = dev_get_drvdata(dev);
 
 195         struct ser_req          *req = kzalloc(sizeof *req, SLAB_KERNEL);
 
 203         spi_message_init(&req->msg);
 
 205         /* activate reference, so it has time to settle; */
 
 206         req->ref_on = REF_ON;
 
 207         req->xfer[0].tx_buf = &req->ref_on;
 
 208         req->xfer[0].len = 1;
 
 209         req->xfer[1].rx_buf = &req->scratch;
 
 210         req->xfer[1].len = 2;
 
 213          * for external VREF, 0 usec (and assume it's always on);
 
 214          * for 1uF, use 800 usec;
 
 217         req->xfer[1].delay_usecs = ts->vref_delay_usecs;
 
 220         req->command = (u8) command;
 
 221         req->xfer[2].tx_buf = &req->command;
 
 222         req->xfer[2].len = 1;
 
 223         req->xfer[3].rx_buf = &req->sample;
 
 224         req->xfer[3].len = 2;
 
 226         /* REVISIT:  take a few more samples, and compare ... */
 
 228         /* turn off reference */
 
 229         req->ref_off = REF_OFF;
 
 230         req->xfer[4].tx_buf = &req->ref_off;
 
 231         req->xfer[4].len = 1;
 
 232         req->xfer[5].rx_buf = &req->scratch;
 
 233         req->xfer[5].len = 2;
 
 235         CS_CHANGE(req->xfer[5]);
 
 237         /* group all the transfers together, so we can't interfere with
 
 238          * reading touchscreen state; disable penirq while sampling
 
 240         for (i = 0; i < 6; i++)
 
 241                 spi_message_add_tail(&req->xfer[i], &req->msg);
 
 243         ts->irq_disabled = 1;
 
 244         disable_irq(spi->irq);
 
 245         status = spi_sync(spi, &req->msg);
 
 246         ts->irq_disabled = 0;
 
 247         enable_irq(spi->irq);
 
 250                 status = req->msg.status;
 
 251         sample = be16_to_cpu(req->sample);
 
 252         sample = sample >> 4;
 
 255         return status ? status : sample;
 
 258 #define SHOW(name) static ssize_t \
 
 259 name ## _show(struct device *dev, struct device_attribute *attr, char *buf) \
 
 261         ssize_t v = ads7846_read12_ser(dev, \
 
 262                         READ_12BIT_SER(name) | ADS_PD10_ALL_ON); \
 
 265         return sprintf(buf, "%u\n", (unsigned) v); \
 
 267 static DEVICE_ATTR(name, S_IRUGO, name ## _show, NULL);
 
 274 static int is_pen_down(struct device *dev)
 
 276         struct ads7846          *ts = dev_get_drvdata(dev);
 
 281 static ssize_t ads7846_pen_down_show(struct device *dev,
 
 282                                      struct device_attribute *attr, char *buf)
 
 284         return sprintf(buf, "%u\n", is_pen_down(dev));
 
 287 static DEVICE_ATTR(pen_down, S_IRUGO, ads7846_pen_down_show, NULL);
 
 289 static ssize_t ads7846_disable_show(struct device *dev,
 
 290                                      struct device_attribute *attr, char *buf)
 
 292         struct ads7846  *ts = dev_get_drvdata(dev);
 
 294         return sprintf(buf, "%u\n", ts->disabled);
 
 297 static ssize_t ads7846_disable_store(struct device *dev,
 
 298                                      struct device_attribute *attr,
 
 299                                      const char *buf, size_t count)
 
 301         struct ads7846 *ts = dev_get_drvdata(dev);
 
 305         i = simple_strtoul(buf, &endp, 10);
 
 306         spin_lock_irq(&ts->lock);
 
 313         spin_unlock_irq(&ts->lock);
 
 318 static DEVICE_ATTR(disable, 0664, ads7846_disable_show, ads7846_disable_store);
 
 320 /*--------------------------------------------------------------------------*/
 
 323  * PENIRQ only kicks the timer.  The timer only reissues the SPI transfer,
 
 324  * to retrieve touchscreen status.
 
 326  * The SPI transfer completion callback does the real work.  It reports
 
 327  * touchscreen events and reactivates the timer (or IRQ) as appropriate.
 
 330 static void ads7846_rx(void *ads)
 
 332         struct ads7846          *ts = ads;
 
 333         struct input_dev        *input_dev = ts->input;
 
 339         /* adjust:  12 bit samples (left aligned), built from
 
 340          * two 8 bit values writen msb-first.
 
 342         x = be16_to_cpu(ts->tc.x) >> 4;
 
 343         y = be16_to_cpu(ts->tc.y) >> 4;
 
 344         z1 = be16_to_cpu(ts->tc.z1) >> 4;
 
 345         z2 = be16_to_cpu(ts->tc.z2) >> 4;
 
 347         /* range filtering */
 
 351         if (likely(x && z1 && !device_suspended(&ts->spi->dev))) {
 
 352                 /* compute touch pressure resistance using equation #2 */
 
 356                 Rt *= ts->x_plate_ohms;
 
 358                 Rt = (Rt + 2047) >> 12;
 
 362         /* Sample found inconsistent by debouncing or pressure is beyond
 
 363         * the maximum. Don't report it to user space, repeat at least
 
 364         * once more the measurement */
 
 365         if (ts->tc.ignore || Rt > ts->pressure_max) {
 
 366                 mod_timer(&ts->timer, jiffies + TS_POLL_PERIOD);
 
 370         /* NOTE:  "pendown" is inferred from pressure; we don't rely on
 
 371          * being able to check nPENIRQ status, or "friendly" trigger modes
 
 372          * (both-edges is much better than just-falling or low-level).
 
 374          * REVISIT:  some boards may require reading nPENIRQ; it's
 
 375          * needed on 7843.  and 7845 reads pressure differently...
 
 377          * REVISIT:  the touchscreen might not be connected; this code
 
 378          * won't notice that, even if nPENIRQ never fires ...
 
 380         if (!ts->pendown && Rt != 0) {
 
 381                 input_report_key(input_dev, BTN_TOUCH, 1);
 
 383         } else if (ts->pendown && Rt == 0) {
 
 384                 input_report_key(input_dev, BTN_TOUCH, 0);
 
 389                 input_report_abs(input_dev, ABS_X, x);
 
 390                 input_report_abs(input_dev, ABS_Y, y);
 
 395                 input_report_abs(input_dev, ABS_PRESSURE, Rt);
 
 396                 input_sync(input_dev);
 
 400         if (Rt || ts->pendown)
 
 401                 pr_debug("%s: %d/%d/%d%s\n", ts->spi->dev.bus_id,
 
 402                         x, y, Rt, Rt ? "" : " UP");
 
 405         spin_lock_irqsave(&ts->lock, flags);
 
 407         ts->pendown = (Rt != 0);
 
 408         mod_timer(&ts->timer, jiffies + TS_POLL_PERIOD);
 
 410         spin_unlock_irqrestore(&ts->lock, flags);
 
 413 static void ads7846_debounce(void *ads)
 
 415         struct ads7846          *ts = ads;
 
 416         struct spi_message      *m;
 
 417         struct spi_transfer     *t;
 
 421         m = &ts->msg[ts->msg_idx];
 
 422         t = list_entry(m->transfers.prev, struct spi_transfer, transfer_list);
 
 423         val = (*(u16 *)t->rx_buf) >> 3;
 
 424         if (!ts->read_cnt || (abs(ts->last_read - val) > ts->debounce_tol)) {
 
 425                 /* Repeat it, if this was the first read or the read
 
 426                  * wasn't consistent enough. */
 
 427                 if (ts->read_cnt < ts->debounce_max) {
 
 431                         /* Maximum number of debouncing reached and still
 
 432                          * not enough number of consistent readings. Abort
 
 433                          * the whole sample, repeat it in the next sampling
 
 438                         /* Last message will contain ads7846_rx() as the
 
 439                          * completion function.
 
 443                 /* Start over collecting consistent readings. */
 
 446                 if (++ts->read_rep > ts->debounce_rep) {
 
 447                         /* Got a good reading for this coordinate,
 
 448                          * go for the next one. */
 
 455                         /* Read more values that are consistent. */
 
 458         status = spi_async(ts->spi, m);
 
 460                 dev_err(&ts->spi->dev, "spi_async --> %d\n",
 
 464 static void ads7846_timer(unsigned long handle)
 
 466         struct ads7846  *ts = (void *)handle;
 
 469         spin_lock_irq(&ts->lock);
 
 471         if (unlikely(ts->msg_idx && !ts->pendown)) {
 
 472                 /* measurment cycle ended */
 
 473                 if (!device_suspended(&ts->spi->dev)) {
 
 474                         ts->irq_disabled = 0;
 
 475                         enable_irq(ts->spi->irq);
 
 480                 /* pen is still down, continue with the measurement */
 
 482                 status = spi_async(ts->spi, &ts->msg[0]);
 
 484                         dev_err(&ts->spi->dev, "spi_async --> %d\n", status);
 
 487         spin_unlock_irq(&ts->lock);
 
 490 static irqreturn_t ads7846_irq(int irq, void *handle, struct pt_regs *regs)
 
 492         struct ads7846 *ts = handle;
 
 495         spin_lock_irqsave(&ts->lock, flags);
 
 496         if (likely(ts->get_pendown_state())) {
 
 497                 if (!ts->irq_disabled) {
 
 498                         /* REVISIT irq logic for many ARM chips has cloned a
 
 499                          * bug wherein disabling an irq in its handler won't
 
 500                          * work;(it's disabled lazily, and too late to work.
 
 501                          * until all their irq logic is fixed, we must shadow
 
 504                         ts->irq_disabled = 1;
 
 505                         disable_irq(ts->spi->irq);
 
 507                         mod_timer(&ts->timer, jiffies);
 
 510         spin_unlock_irqrestore(&ts->lock, flags);
 
 515 /*--------------------------------------------------------------------------*/
 
 517 /* Must be called with ts->lock held */
 
 518 static void ads7846_disable(struct ads7846 *ts)
 
 525         /* are we waiting for IRQ, or polling? */
 
 527                 ts->irq_disabled = 1;
 
 528                 disable_irq(ts->spi->irq);
 
 530                 /* the timer will run at least once more, and
 
 531                  * leave everything in a clean state, IRQ disabled
 
 533                 while (ts->pending) {
 
 534                         spin_unlock_irq(&ts->lock);
 
 536                         spin_lock_irq(&ts->lock);
 
 540         /* we know the chip's in lowpower mode since we always
 
 541          * leave it that way after every request
 
 546 /* Must be called with ts->lock held */
 
 547 static void ads7846_enable(struct ads7846 *ts)
 
 553         ts->irq_disabled = 0;
 
 554         enable_irq(ts->spi->irq);
 
 557 static int ads7846_suspend(struct spi_device *spi, pm_message_t message)
 
 559         struct ads7846 *ts = dev_get_drvdata(&spi->dev);
 
 561         spin_lock_irq(&ts->lock);
 
 563         spi->dev.power.power_state = message;
 
 566         spin_unlock_irq(&ts->lock);
 
 572 static int ads7846_resume(struct spi_device *spi)
 
 574         struct ads7846 *ts = dev_get_drvdata(&spi->dev);
 
 576         spin_lock_irq(&ts->lock);
 
 578         spi->dev.power.power_state = PMSG_ON;
 
 581         spin_unlock_irq(&ts->lock);
 
 586 static int __devinit ads7846_probe(struct spi_device *spi)
 
 589         struct input_dev                *input_dev;
 
 590         struct ads7846_platform_data    *pdata = spi->dev.platform_data;
 
 591         struct spi_message              *m;
 
 592         struct spi_transfer             *x;
 
 596                 dev_dbg(&spi->dev, "no IRQ?\n");
 
 601                 dev_dbg(&spi->dev, "no platform data?\n");
 
 605         /* don't exceed max specified sample rate */
 
 606         if (spi->max_speed_hz > (125000 * SAMPLE_BITS)) {
 
 607                 dev_dbg(&spi->dev, "f(sample) %d KHz?\n",
 
 608                                 (spi->max_speed_hz/SAMPLE_BITS)/1000);
 
 612         if (pdata->get_pendown_state == NULL) {
 
 613                 dev_dbg(&spi->dev, "no get_pendown_state function?\n");
 
 617         /* We'd set the wordsize to 12 bits ... except that some controllers
 
 618          * will then treat the 8 bit command words as 12 bits (and drop the
 
 619          * four MSBs of the 12 bit result).  Result: inputs must be shifted
 
 620          * to discard the four garbage LSBs.
 
 623         ts = kzalloc(sizeof(struct ads7846), GFP_KERNEL);
 
 624         input_dev = input_allocate_device();
 
 625         if (!ts || !input_dev) {
 
 630         dev_set_drvdata(&spi->dev, ts);
 
 631         spi->dev.power.power_state = PMSG_ON;
 
 634         ts->input = input_dev;
 
 636         init_timer(&ts->timer);
 
 637         ts->timer.data = (unsigned long) ts;
 
 638         ts->timer.function = ads7846_timer;
 
 640         spin_lock_init(&ts->lock);
 
 642         ts->model = pdata->model ? : 7846;
 
 643         ts->vref_delay_usecs = pdata->vref_delay_usecs ? : 100;
 
 644         ts->x_plate_ohms = pdata->x_plate_ohms ? : 400;
 
 645         ts->pressure_max = pdata->pressure_max ? : ~0;
 
 646         if (pdata->debounce_max) {
 
 647                 ts->debounce_max = pdata->debounce_max;
 
 648                 ts->debounce_tol = pdata->debounce_tol;
 
 649                 ts->debounce_rep = pdata->debounce_rep;
 
 650                 if (ts->debounce_rep > ts->debounce_max + 1)
 
 651                         ts->debounce_rep = ts->debounce_max - 1;
 
 653                 ts->debounce_tol = ~0;
 
 654         ts->get_pendown_state = pdata->get_pendown_state;
 
 656         snprintf(ts->phys, sizeof(ts->phys), "%s/input0", spi->dev.bus_id);
 
 658         input_dev->name = "ADS784x Touchscreen";
 
 659         input_dev->phys = ts->phys;
 
 660         input_dev->cdev.dev = &spi->dev;
 
 662         input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
 
 663         input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
 
 664         input_set_abs_params(input_dev, ABS_X,
 
 666                         pdata->x_max ? : MAX_12BIT,
 
 668         input_set_abs_params(input_dev, ABS_Y,
 
 670                         pdata->y_max ? : MAX_12BIT,
 
 672         input_set_abs_params(input_dev, ABS_PRESSURE,
 
 673                         pdata->pressure_min, pdata->pressure_max, 0, 0);
 
 675         /* set up the transfers to read touchscreen state; this assumes we
 
 676          * use formula #2 for pressure, not #3.
 
 683         /* y- still on; turn on only y+ (and ADC) */
 
 685         x->tx_buf = &ts->read_y;
 
 687         spi_message_add_tail(x, m);
 
 690         x->rx_buf = &ts->tc.y;
 
 692         spi_message_add_tail(x, m);
 
 694         m->complete = ads7846_debounce;
 
 700         /* turn y- off, x+ on, then leave in lowpower */
 
 703         x->tx_buf = &ts->read_x;
 
 705         spi_message_add_tail(x, m);
 
 708         x->rx_buf = &ts->tc.x;
 
 710         spi_message_add_tail(x, m);
 
 712         m->complete = ads7846_debounce;
 
 715         /* turn y+ off, x- on; we'll use formula #2 */
 
 716         if (ts->model == 7846) {
 
 721                 ts->read_z1 = READ_Z1;
 
 722                 x->tx_buf = &ts->read_z1;
 
 724                 spi_message_add_tail(x, m);
 
 727                 x->rx_buf = &ts->tc.z1;
 
 729                 spi_message_add_tail(x, m);
 
 731                 m->complete = ads7846_debounce;
 
 738                 ts->read_z2 = READ_Z2;
 
 739                 x->tx_buf = &ts->read_z2;
 
 741                 spi_message_add_tail(x, m);
 
 744                 x->rx_buf = &ts->tc.z2;
 
 746                 spi_message_add_tail(x, m);
 
 748                 m->complete = ads7846_debounce;
 
 757         ts->pwrdown = PWRDOWN;
 
 758         x->tx_buf = &ts->pwrdown;
 
 760         spi_message_add_tail(x, m);
 
 763         x->rx_buf = &ts->dummy;
 
 766         spi_message_add_tail(x, m);
 
 768         m->complete = ads7846_rx;
 
 773         if (request_irq(spi->irq, ads7846_irq,
 
 774                         SA_SAMPLE_RANDOM | SA_TRIGGER_FALLING,
 
 775                         spi->dev.bus_id, ts)) {
 
 776                 dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq);
 
 781         dev_info(&spi->dev, "touchscreen, irq %d\n", spi->irq);
 
 783         /* take a first sample, leaving nPENIRQ active; avoid
 
 784          * the touchscreen, in case it's not connected.
 
 786         (void) ads7846_read12_ser(&spi->dev,
 
 787                           READ_12BIT_SER(vaux) | ADS_PD10_ALL_ON);
 
 789         /* ads7843/7845 don't have temperature sensors, and
 
 790          * use the other sensors a bit differently too
 
 792         if (ts->model == 7846) {
 
 793                 device_create_file(&spi->dev, &dev_attr_temp0);
 
 794                 device_create_file(&spi->dev, &dev_attr_temp1);
 
 796         if (ts->model != 7845)
 
 797                 device_create_file(&spi->dev, &dev_attr_vbatt);
 
 798         device_create_file(&spi->dev, &dev_attr_vaux);
 
 800         device_create_file(&spi->dev, &dev_attr_pen_down);
 
 802         device_create_file(&spi->dev, &dev_attr_disable);
 
 804         err = input_register_device(input_dev);
 
 806                 goto err_remove_attr;
 
 811         device_remove_file(&spi->dev, &dev_attr_disable);
 
 812         device_remove_file(&spi->dev, &dev_attr_pen_down);
 
 813         if (ts->model == 7846) {
 
 814                 device_remove_file(&spi->dev, &dev_attr_temp1);
 
 815                 device_remove_file(&spi->dev, &dev_attr_temp0);
 
 817         if (ts->model != 7845)
 
 818                 device_remove_file(&spi->dev, &dev_attr_vbatt);
 
 819         device_remove_file(&spi->dev, &dev_attr_vaux);
 
 821         free_irq(spi->irq, ts);
 
 823         input_free_device(input_dev);
 
 828 static int __devexit ads7846_remove(struct spi_device *spi)
 
 830         struct ads7846          *ts = dev_get_drvdata(&spi->dev);
 
 832         input_unregister_device(ts->input);
 
 834         ads7846_suspend(spi, PMSG_SUSPEND);
 
 836         device_remove_file(&spi->dev, &dev_attr_disable);
 
 837         device_remove_file(&spi->dev, &dev_attr_pen_down);
 
 838         if (ts->model == 7846) {
 
 839                 device_remove_file(&spi->dev, &dev_attr_temp1);
 
 840                 device_remove_file(&spi->dev, &dev_attr_temp0);
 
 842         if (ts->model != 7845)
 
 843                 device_remove_file(&spi->dev, &dev_attr_vbatt);
 
 844         device_remove_file(&spi->dev, &dev_attr_vaux);
 
 846         free_irq(ts->spi->irq, ts);
 
 847         /* suspend left the IRQ disabled */
 
 848         enable_irq(ts->spi->irq);
 
 852         dev_dbg(&spi->dev, "unregistered touchscreen\n");
 
 856 static struct spi_driver ads7846_driver = {
 
 859                 .bus    = &spi_bus_type,
 
 860                 .owner  = THIS_MODULE,
 
 862         .probe          = ads7846_probe,
 
 863         .remove         = __devexit_p(ads7846_remove),
 
 864         .suspend        = ads7846_suspend,
 
 865         .resume         = ads7846_resume,
 
 868 static int __init ads7846_init(void)
 
 870         /* grr, board-specific init should stay out of drivers!! */
 
 872 #ifdef  CONFIG_ARCH_OMAP
 
 873         if (machine_is_omap_osk()) {
 
 874                 /* GPIO4 = PENIRQ; GPIO6 = BUSY */
 
 875                 omap_request_gpio(4);
 
 876                 omap_set_gpio_direction(4, 1);
 
 877                 omap_request_gpio(6);
 
 878                 omap_set_gpio_direction(6, 1);
 
 880         // also TI 1510 Innovator, bitbanging through FPGA
 
 882         // also Palm Tungsten T2
 
 886         // also Dell Axim X50
 
 887         // also HP iPaq H191x/H192x/H415x/H435x
 
 888         // also Intel Lubbock (additional to UCB1400; as temperature sensor)
 
 889         // also Sharp Zaurus C7xx, C8xx (corgi/sheperd/husky)
 
 891         // Atmel at91sam9261-EK uses ads7843
 
 893         // also various AMD Au1x00 devel boards
 
 895         return spi_register_driver(&ads7846_driver);
 
 897 module_init(ads7846_init);
 
 899 static void __exit ads7846_exit(void)
 
 901         spi_unregister_driver(&ads7846_driver);
 
 903 #ifdef  CONFIG_ARCH_OMAP
 
 904         if (machine_is_omap_osk()) {
 
 911 module_exit(ads7846_exit);
 
 913 MODULE_DESCRIPTION("ADS7846 TouchScreen Driver");
 
 914 MODULE_LICENSE("GPL");