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 heavily tested on a Nokia 770, and lightly
40 * tested on other ads7846 devices (OSK/Mistral, Lubbock).
41 * Support for ads7843 and ads7845 has only been stubbed in.
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.
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.
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
57 #define TS_POLL_DELAY (1 * 1000000) /* ns delay before the first sample */
58 #define TS_POLL_PERIOD (5 * 1000000) /* ns delay between samples */
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 *** and range adjustment.
76 struct input_dev
*input
;
79 struct spi_device
*spi
;
80 struct attribute_group
*attr_group
;
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 hrtimer timer
;
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 (*filter
)(void *data
, int data_idx
, int *val
);
112 void (*filter_cleanup
)(void *data
);
113 int (*get_pendown_state
)(void);
116 /* leave chip selected when we're done, for quicker re-select? */
118 #define CS_CHANGE(xfer) ((xfer).cs_change = 1)
120 #define CS_CHANGE(xfer) ((xfer).cs_change = 0)
123 /*--------------------------------------------------------------------------*/
125 /* The ADS7846 has touchscreen and other sensors.
126 * Earlier ads784x chips are somewhat compatible.
128 #define ADS_START (1 << 7)
129 #define ADS_A2A1A0_d_y (1 << 4) /* differential */
130 #define ADS_A2A1A0_d_z1 (3 << 4) /* differential */
131 #define ADS_A2A1A0_d_z2 (4 << 4) /* differential */
132 #define ADS_A2A1A0_d_x (5 << 4) /* differential */
133 #define ADS_A2A1A0_temp0 (0 << 4) /* non-differential */
134 #define ADS_A2A1A0_vbatt (2 << 4) /* non-differential */
135 #define ADS_A2A1A0_vaux (6 << 4) /* non-differential */
136 #define ADS_A2A1A0_temp1 (7 << 4) /* non-differential */
137 #define ADS_8_BIT (1 << 3)
138 #define ADS_12_BIT (0 << 3)
139 #define ADS_SER (1 << 2) /* non-differential */
140 #define ADS_DFR (0 << 2) /* differential */
141 #define ADS_PD10_PDOWN (0 << 0) /* lowpower mode + penirq */
142 #define ADS_PD10_ADC_ON (1 << 0) /* ADC on */
143 #define ADS_PD10_REF_ON (2 << 0) /* vREF on + penirq */
144 #define ADS_PD10_ALL_ON (3 << 0) /* ADC + vREF on */
146 #define MAX_12BIT ((1<<12)-1)
148 /* leave ADC powered up (disables penirq) between differential samples */
149 #define READ_12BIT_DFR(x, adc, vref) (ADS_START | ADS_A2A1A0_d_ ## x \
150 | ADS_12_BIT | ADS_DFR | \
151 (adc ? ADS_PD10_ADC_ON : 0) | (vref ? ADS_PD10_REF_ON : 0))
153 #define READ_Y(vref) (READ_12BIT_DFR(y, 1, vref))
154 #define READ_Z1(vref) (READ_12BIT_DFR(z1, 1, vref))
155 #define READ_Z2(vref) (READ_12BIT_DFR(z2, 1, vref))
157 #define READ_X(vref) (READ_12BIT_DFR(x, 1, vref))
158 #define PWRDOWN (READ_12BIT_DFR(y, 0, 0)) /* LAST */
160 /* single-ended samples need to first power up reference voltage;
161 * we leave both ADC and VREF powered
163 #define READ_12BIT_SER(x) (ADS_START | ADS_A2A1A0_ ## x \
164 | ADS_12_BIT | ADS_SER)
166 #define REF_ON (READ_12BIT_DFR(x, 1, 1))
167 #define REF_OFF (READ_12BIT_DFR(y, 0, 0))
169 /*--------------------------------------------------------------------------*/
172 * Non-touchscreen sensors only use single-ended conversions.
181 struct spi_message msg
;
182 struct spi_transfer xfer
[6];
185 static void ads7846_enable(struct ads7846
*ts
);
186 static void ads7846_disable(struct ads7846
*ts
);
188 static int device_suspended(struct device
*dev
)
190 struct ads7846
*ts
= dev_get_drvdata(dev
);
191 return dev
->power
.power_state
.event
!= PM_EVENT_ON
|| ts
->disabled
;
194 static int ads7846_read12_ser(struct device
*dev
, unsigned command
)
196 struct spi_device
*spi
= to_spi_device(dev
);
197 struct ads7846
*ts
= dev_get_drvdata(dev
);
198 struct ser_req
*req
= kzalloc(sizeof *req
, GFP_KERNEL
);
206 spi_message_init(&req
->msg
);
208 /* activate reference, so it has time to settle; */
209 req
->ref_on
= REF_ON
;
210 req
->xfer
[0].tx_buf
= &req
->ref_on
;
211 req
->xfer
[0].len
= 1;
212 req
->xfer
[1].rx_buf
= &req
->scratch
;
213 req
->xfer
[1].len
= 2;
216 * for external VREF, 0 usec (and assume it's always on);
217 * for 1uF, use 800 usec;
220 req
->xfer
[1].delay_usecs
= ts
->vref_delay_usecs
;
223 req
->command
= (u8
) command
;
224 req
->xfer
[2].tx_buf
= &req
->command
;
225 req
->xfer
[2].len
= 1;
226 req
->xfer
[3].rx_buf
= &req
->sample
;
227 req
->xfer
[3].len
= 2;
229 /* REVISIT: take a few more samples, and compare ... */
231 /* turn off reference */
232 req
->ref_off
= REF_OFF
;
233 req
->xfer
[4].tx_buf
= &req
->ref_off
;
234 req
->xfer
[4].len
= 1;
235 req
->xfer
[5].rx_buf
= &req
->scratch
;
236 req
->xfer
[5].len
= 2;
238 CS_CHANGE(req
->xfer
[5]);
240 /* group all the transfers together, so we can't interfere with
241 * reading touchscreen state; disable penirq while sampling
243 for (i
= 0; i
< 6; i
++)
244 spi_message_add_tail(&req
->xfer
[i
], &req
->msg
);
246 ts
->irq_disabled
= 1;
247 disable_irq(spi
->irq
);
248 status
= spi_sync(spi
, &req
->msg
);
249 ts
->irq_disabled
= 0;
250 enable_irq(spi
->irq
);
253 status
= req
->msg
.status
;
255 /* on-wire is a must-ignore bit, a BE12 value, then padding */
256 sample
= be16_to_cpu(req
->sample
);
257 sample
= sample
>> 3;
261 return status
? status
: sample
;
264 #define SHOW(name) static ssize_t \
265 name ## _show(struct device *dev, struct device_attribute *attr, char *buf) \
267 ssize_t v = ads7846_read12_ser(dev, \
268 READ_12BIT_SER(name) | ADS_PD10_ALL_ON); \
271 return sprintf(buf, "%u\n", (unsigned) v); \
273 static DEVICE_ATTR(name, S_IRUGO, name ## _show, NULL);
280 static int is_pen_down(struct device
*dev
)
282 struct ads7846
*ts
= dev_get_drvdata(dev
);
287 static ssize_t
ads7846_pen_down_show(struct device
*dev
,
288 struct device_attribute
*attr
, char *buf
)
290 return sprintf(buf
, "%u\n", is_pen_down(dev
));
293 static DEVICE_ATTR(pen_down
, S_IRUGO
, ads7846_pen_down_show
, NULL
);
295 static ssize_t
ads7846_disable_show(struct device
*dev
,
296 struct device_attribute
*attr
, char *buf
)
298 struct ads7846
*ts
= dev_get_drvdata(dev
);
300 return sprintf(buf
, "%u\n", ts
->disabled
);
303 static ssize_t
ads7846_disable_store(struct device
*dev
,
304 struct device_attribute
*attr
,
305 const char *buf
, size_t count
)
307 struct ads7846
*ts
= dev_get_drvdata(dev
);
311 i
= simple_strtoul(buf
, &endp
, 10);
312 spin_lock_irq(&ts
->lock
);
319 spin_unlock_irq(&ts
->lock
);
324 static DEVICE_ATTR(disable
, 0664, ads7846_disable_show
, ads7846_disable_store
);
326 static struct attribute
*ads7846_attributes
[] = {
327 &dev_attr_temp0
.attr
,
328 &dev_attr_temp1
.attr
,
329 &dev_attr_vbatt
.attr
,
331 &dev_attr_pen_down
.attr
,
332 &dev_attr_disable
.attr
,
336 static struct attribute_group ads7846_attr_group
= {
337 .attrs
= ads7846_attributes
,
341 * ads7843/7845 don't have temperature sensors, and
342 * use the other sensors a bit differently too
345 static struct attribute
*ads7843_attributes
[] = {
346 &dev_attr_vbatt
.attr
,
348 &dev_attr_pen_down
.attr
,
349 &dev_attr_disable
.attr
,
353 static struct attribute_group ads7843_attr_group
= {
354 .attrs
= ads7843_attributes
,
357 static struct attribute
*ads7845_attributes
[] = {
359 &dev_attr_pen_down
.attr
,
360 &dev_attr_disable
.attr
,
364 static struct attribute_group ads7845_attr_group
= {
365 .attrs
= ads7845_attributes
,
368 /*--------------------------------------------------------------------------*/
371 * PENIRQ only kicks the timer. The timer only reissues the SPI transfer,
372 * to retrieve touchscreen status.
374 * The SPI transfer completion callback does the real work. It reports
375 * touchscreen events and reactivates the timer (or IRQ) as appropriate.
378 static void ads7846_rx(void *ads
)
380 struct ads7846
*ts
= ads
;
384 /* ads7846_rx_val() did in-place conversion (including byteswap) from
385 * on-the-wire format as part of debouncing to get stable readings.
392 /* range filtering */
396 if (likely(x
&& z1
)) {
397 /* compute touch pressure resistance using equation #2 */
401 Rt
*= ts
->x_plate_ohms
;
403 Rt
= (Rt
+ 2047) >> 12;
407 /* Sample found inconsistent by debouncing or pressure is beyond
408 * the maximum. Don't report it to user space, repeat at least
409 * once more the measurement
411 if (ts
->tc
.ignore
|| Rt
> ts
->pressure_max
) {
413 pr_debug("%s: ignored %d pressure %d\n",
414 ts
->spi
->dev
.bus_id
, ts
->tc
.ignore
, Rt
);
416 hrtimer_start(&ts
->timer
, ktime_set(0, TS_POLL_PERIOD
),
421 /* NOTE: We can't rely on the pressure to determine the pen down
422 * state, even this controller has a pressure sensor. The pressure
423 * value can fluctuate for quite a while after lifting the pen and
424 * in some cases may not even settle at the expected value.
426 * The only safe way to check for the pen up condition is in the
427 * timer by reading the pen signal state (it's a GPIO _and_ IRQ).
430 struct input_dev
*input
= ts
->input
;
433 input_report_key(input
, BTN_TOUCH
, 1);
436 dev_dbg(&ts
->spi
->dev
, "DOWN\n");
439 input_report_abs(input
, ABS_X
, x
);
440 input_report_abs(input
, ABS_Y
, y
);
441 input_report_abs(input
, ABS_PRESSURE
, Rt
);
445 dev_dbg(&ts
->spi
->dev
, "%4d/%4d/%4d\n", x
, y
, Rt
);
449 hrtimer_start(&ts
->timer
, ktime_set(0, TS_POLL_PERIOD
), HRTIMER_REL
);
452 static int ads7846_debounce(void *ads
, int data_idx
, int *val
)
454 struct ads7846
*ts
= ads
;
456 if (!ts
->read_cnt
|| (abs(ts
->last_read
- *val
) > ts
->debounce_tol
)) {
457 /* Start over collecting consistent readings. */
459 /* Repeat it, if this was the first read or the read
460 * wasn't consistent enough. */
461 if (ts
->read_cnt
< ts
->debounce_max
) {
462 ts
->last_read
= *val
;
464 return ADS7846_FILTER_REPEAT
;
466 /* Maximum number of debouncing reached and still
467 * not enough number of consistent readings. Abort
468 * the whole sample, repeat it in the next sampling
472 return ADS7846_FILTER_IGNORE
;
475 if (++ts
->read_rep
> ts
->debounce_rep
) {
476 /* Got a good reading for this coordinate,
477 * go for the next one. */
480 return ADS7846_FILTER_OK
;
482 /* Read more values that are consistent. */
484 return ADS7846_FILTER_REPEAT
;
489 static int ads7846_no_filter(void *ads
, int data_idx
, int *val
)
491 return ADS7846_FILTER_OK
;
494 static void ads7846_rx_val(void *ads
)
496 struct ads7846
*ts
= ads
;
497 struct spi_message
*m
;
498 struct spi_transfer
*t
;
504 m
= &ts
->msg
[ts
->msg_idx
];
505 t
= list_entry(m
->transfers
.prev
, struct spi_transfer
, transfer_list
);
508 /* adjust: on-wire is a must-ignore bit, a BE12 value, then padding;
509 * built from two 8 bit values written msb-first.
511 val
= be16_to_cpu(*rx_val
) >> 3;
513 action
= ts
->filter(ts
->filter_data
, ts
->msg_idx
, &val
);
515 case ADS7846_FILTER_REPEAT
:
517 case ADS7846_FILTER_IGNORE
:
519 /* Last message will contain ads7846_rx() as the
520 * completion function.
524 case ADS7846_FILTER_OK
:
527 m
= &ts
->msg
[++ts
->msg_idx
];
532 status
= spi_async(ts
->spi
, m
);
534 dev_err(&ts
->spi
->dev
, "spi_async --> %d\n",
538 static int ads7846_timer(struct hrtimer
*handle
)
540 struct ads7846
*ts
= container_of(handle
, struct ads7846
, timer
);
543 spin_lock_irq(&ts
->lock
);
545 if (unlikely(!ts
->get_pendown_state() ||
546 device_suspended(&ts
->spi
->dev
))) {
548 struct input_dev
*input
= ts
->input
;
550 input_report_key(input
, BTN_TOUCH
, 0);
551 input_report_abs(input
, ABS_PRESSURE
, 0);
556 dev_dbg(&ts
->spi
->dev
, "UP\n");
560 /* measurement cycle ended */
561 if (!device_suspended(&ts
->spi
->dev
)) {
562 ts
->irq_disabled
= 0;
563 enable_irq(ts
->spi
->irq
);
567 /* pen is still down, continue with the measurement */
569 status
= spi_async(ts
->spi
, &ts
->msg
[0]);
571 dev_err(&ts
->spi
->dev
, "spi_async --> %d\n", status
);
574 spin_unlock_irq(&ts
->lock
);
575 return HRTIMER_NORESTART
;
578 static irqreturn_t
ads7846_irq(int irq
, void *handle
)
580 struct ads7846
*ts
= handle
;
583 spin_lock_irqsave(&ts
->lock
, flags
);
584 if (likely(ts
->get_pendown_state())) {
585 if (!ts
->irq_disabled
) {
586 /* The ARM do_simple_IRQ() dispatcher doesn't act
587 * like the other dispatchers: it will report IRQs
588 * even after they've been disabled. We work around
589 * that here. (The "generic irq" framework may help...)
591 ts
->irq_disabled
= 1;
592 disable_irq(ts
->spi
->irq
);
594 hrtimer_start(&ts
->timer
, ktime_set(0, TS_POLL_DELAY
),
598 spin_unlock_irqrestore(&ts
->lock
, flags
);
603 /*--------------------------------------------------------------------------*/
605 /* Must be called with ts->lock held */
606 static void ads7846_disable(struct ads7846
*ts
)
613 /* are we waiting for IRQ, or polling? */
615 ts
->irq_disabled
= 1;
616 disable_irq(ts
->spi
->irq
);
618 /* the timer will run at least once more, and
619 * leave everything in a clean state, IRQ disabled
621 while (ts
->pending
) {
622 spin_unlock_irq(&ts
->lock
);
624 spin_lock_irq(&ts
->lock
);
628 /* we know the chip's in lowpower mode since we always
629 * leave it that way after every request
634 /* Must be called with ts->lock held */
635 static void ads7846_enable(struct ads7846
*ts
)
641 ts
->irq_disabled
= 0;
642 enable_irq(ts
->spi
->irq
);
645 static int ads7846_suspend(struct spi_device
*spi
, pm_message_t message
)
647 struct ads7846
*ts
= dev_get_drvdata(&spi
->dev
);
649 spin_lock_irq(&ts
->lock
);
651 spi
->dev
.power
.power_state
= message
;
654 spin_unlock_irq(&ts
->lock
);
660 static int ads7846_resume(struct spi_device
*spi
)
662 struct ads7846
*ts
= dev_get_drvdata(&spi
->dev
);
664 spin_lock_irq(&ts
->lock
);
666 spi
->dev
.power
.power_state
= PMSG_ON
;
669 spin_unlock_irq(&ts
->lock
);
674 static int __devinit
ads7846_probe(struct spi_device
*spi
)
677 struct input_dev
*input_dev
;
678 struct ads7846_platform_data
*pdata
= spi
->dev
.platform_data
;
679 struct spi_message
*m
;
680 struct spi_transfer
*x
;
685 dev_dbg(&spi
->dev
, "no IRQ?\n");
690 dev_dbg(&spi
->dev
, "no platform data?\n");
694 /* don't exceed max specified sample rate */
695 if (spi
->max_speed_hz
> (125000 * SAMPLE_BITS
)) {
696 dev_dbg(&spi
->dev
, "f(sample) %d KHz?\n",
697 (spi
->max_speed_hz
/SAMPLE_BITS
)/1000);
701 /* REVISIT when the irq can be triggered active-low, or if for some
702 * reason the touchscreen isn't hooked up, we don't need to access
705 if (pdata
->get_pendown_state
== NULL
) {
706 dev_dbg(&spi
->dev
, "no get_pendown_state function?\n");
710 /* We'd set TX wordsize 8 bits and RX wordsize to 13 bits ... except
711 * that even if the hardware can do that, the SPI controller driver
712 * may not. So we stick to very-portable 8 bit words, both RX and TX.
714 spi
->bits_per_word
= 8;
715 spi
->mode
= SPI_MODE_1
;
716 err
= spi_setup(spi
);
720 ts
= kzalloc(sizeof(struct ads7846
), GFP_KERNEL
);
721 input_dev
= input_allocate_device();
722 if (!ts
|| !input_dev
) {
727 dev_set_drvdata(&spi
->dev
, ts
);
728 spi
->dev
.power
.power_state
= PMSG_ON
;
731 ts
->input
= input_dev
;
733 hrtimer_init(&ts
->timer
, CLOCK_MONOTONIC
, HRTIMER_REL
);
734 ts
->timer
.function
= ads7846_timer
;
736 spin_lock_init(&ts
->lock
);
738 ts
->model
= pdata
->model
? : 7846;
739 ts
->vref_delay_usecs
= pdata
->vref_delay_usecs
? : 100;
740 ts
->x_plate_ohms
= pdata
->x_plate_ohms
? : 400;
741 ts
->pressure_max
= pdata
->pressure_max
? : ~0;
743 if (pdata
->filter
!= NULL
) {
744 if (pdata
->filter_init
!= NULL
) {
745 err
= pdata
->filter_init(pdata
, &ts
->filter_data
);
749 ts
->filter
= pdata
->filter
;
750 ts
->filter_cleanup
= pdata
->filter_cleanup
;
751 } else if (pdata
->debounce_max
) {
752 ts
->debounce_max
= pdata
->debounce_max
;
753 if (ts
->debounce_max
< 2)
754 ts
->debounce_max
= 2;
755 ts
->debounce_tol
= pdata
->debounce_tol
;
756 ts
->debounce_rep
= pdata
->debounce_rep
;
757 ts
->filter
= ads7846_debounce
;
758 ts
->filter_data
= ts
;
760 ts
->filter
= ads7846_no_filter
;
761 ts
->get_pendown_state
= pdata
->get_pendown_state
;
763 snprintf(ts
->phys
, sizeof(ts
->phys
), "%s/input0", spi
->dev
.bus_id
);
765 input_dev
->name
= "ADS784x Touchscreen";
766 input_dev
->phys
= ts
->phys
;
767 input_dev
->cdev
.dev
= &spi
->dev
;
769 input_dev
->evbit
[0] = BIT(EV_KEY
) | BIT(EV_ABS
);
770 input_dev
->keybit
[LONG(BTN_TOUCH
)] = BIT(BTN_TOUCH
);
771 input_set_abs_params(input_dev
, ABS_X
,
773 pdata
->x_max
? : MAX_12BIT
,
775 input_set_abs_params(input_dev
, ABS_Y
,
777 pdata
->y_max
? : MAX_12BIT
,
779 input_set_abs_params(input_dev
, ABS_PRESSURE
,
780 pdata
->pressure_min
, pdata
->pressure_max
, 0, 0);
782 vref
= pdata
->keep_vref_on
;
784 /* set up the transfers to read touchscreen state; this assumes we
785 * use formula #2 for pressure, not #3.
792 /* y- still on; turn on only y+ (and ADC) */
793 ts
->read_y
= READ_Y(vref
);
794 x
->tx_buf
= &ts
->read_y
;
796 spi_message_add_tail(x
, m
);
799 x
->rx_buf
= &ts
->tc
.y
;
801 spi_message_add_tail(x
, m
);
803 m
->complete
= ads7846_rx_val
;
809 /* turn y- off, x+ on, then leave in lowpower */
811 ts
->read_x
= READ_X(vref
);
812 x
->tx_buf
= &ts
->read_x
;
814 spi_message_add_tail(x
, m
);
817 x
->rx_buf
= &ts
->tc
.x
;
819 spi_message_add_tail(x
, m
);
821 m
->complete
= ads7846_rx_val
;
824 /* turn y+ off, x- on; we'll use formula #2 */
825 if (ts
->model
== 7846) {
830 ts
->read_z1
= READ_Z1(vref
);
831 x
->tx_buf
= &ts
->read_z1
;
833 spi_message_add_tail(x
, m
);
836 x
->rx_buf
= &ts
->tc
.z1
;
838 spi_message_add_tail(x
, m
);
840 m
->complete
= ads7846_rx_val
;
847 ts
->read_z2
= READ_Z2(vref
);
848 x
->tx_buf
= &ts
->read_z2
;
850 spi_message_add_tail(x
, m
);
853 x
->rx_buf
= &ts
->tc
.z2
;
855 spi_message_add_tail(x
, m
);
857 m
->complete
= ads7846_rx_val
;
866 ts
->pwrdown
= PWRDOWN
;
867 x
->tx_buf
= &ts
->pwrdown
;
869 spi_message_add_tail(x
, m
);
872 x
->rx_buf
= &ts
->dummy
;
875 spi_message_add_tail(x
, m
);
877 m
->complete
= ads7846_rx
;
882 if (request_irq(spi
->irq
, ads7846_irq
, IRQF_TRIGGER_FALLING
,
883 spi
->dev
.driver
->name
, ts
)) {
884 dev_dbg(&spi
->dev
, "irq %d busy?\n", spi
->irq
);
886 goto err_cleanup_filter
;
889 dev_info(&spi
->dev
, "touchscreen, irq %d\n", spi
->irq
);
891 /* take a first sample, leaving nPENIRQ active; avoid
892 * the touchscreen, in case it's not connected.
894 (void) ads7846_read12_ser(&spi
->dev
,
895 READ_12BIT_SER(vaux
) | ADS_PD10_ALL_ON
);
899 ts
->attr_group
= &ads7846_attr_group
;
902 ts
->attr_group
= &ads7845_attr_group
;
905 ts
->attr_group
= &ads7843_attr_group
;
908 err
= sysfs_create_group(&spi
->dev
.kobj
, ts
->attr_group
);
912 err
= input_register_device(input_dev
);
914 goto err_remove_attr_group
;
918 err_remove_attr_group
:
919 sysfs_remove_group(&spi
->dev
.kobj
, ts
->attr_group
);
921 free_irq(spi
->irq
, ts
);
923 if (ts
->filter_cleanup
)
924 ts
->filter_cleanup(ts
->filter_data
);
926 input_free_device(input_dev
);
931 static int __devexit
ads7846_remove(struct spi_device
*spi
)
933 struct ads7846
*ts
= dev_get_drvdata(&spi
->dev
);
935 input_unregister_device(ts
->input
);
937 ads7846_suspend(spi
, PMSG_SUSPEND
);
939 sysfs_remove_group(&spi
->dev
.kobj
, ts
->attr_group
);
941 free_irq(ts
->spi
->irq
, ts
);
942 /* suspend left the IRQ disabled */
943 enable_irq(ts
->spi
->irq
);
945 if (ts
->filter_cleanup
)
946 ts
->filter_cleanup(ts
->filter_data
);
950 dev_dbg(&spi
->dev
, "unregistered touchscreen\n");
954 static struct spi_driver ads7846_driver
= {
957 .bus
= &spi_bus_type
,
958 .owner
= THIS_MODULE
,
960 .probe
= ads7846_probe
,
961 .remove
= __devexit_p(ads7846_remove
),
962 .suspend
= ads7846_suspend
,
963 .resume
= ads7846_resume
,
966 static int __init
ads7846_init(void)
968 /* grr, board-specific init should stay out of drivers!! */
970 #ifdef CONFIG_ARCH_OMAP
971 if (machine_is_omap_osk()) {
972 /* GPIO4 = PENIRQ; GPIO6 = BUSY */
973 omap_request_gpio(4);
974 omap_set_gpio_direction(4, 1);
975 omap_request_gpio(6);
976 omap_set_gpio_direction(6, 1);
978 // also TI 1510 Innovator, bitbanging through FPGA
980 // also Palm Tungsten T2
984 // also Dell Axim X50
985 // also HP iPaq H191x/H192x/H415x/H435x
986 // also Intel Lubbock (additional to UCB1400; as temperature sensor)
987 // also Sharp Zaurus C7xx, C8xx (corgi/sheperd/husky)
989 // Atmel at91sam9261-EK uses ads7843
991 // also various AMD Au1x00 devel boards
993 return spi_register_driver(&ads7846_driver
);
995 module_init(ads7846_init
);
997 static void __exit
ads7846_exit(void)
999 spi_unregister_driver(&ads7846_driver
);
1001 #ifdef CONFIG_ARCH_OMAP
1002 if (machine_is_omap_osk()) {
1009 module_exit(ads7846_exit
);
1011 MODULE_DESCRIPTION("ADS7846 TouchScreen Driver");
1012 MODULE_LICENSE("GPL");