2 * drivers/input/touchscreen/xpt2046_ts.c - driver for rk2818 spi xpt2046 device and console
4 * Copyright (C) 2010 ROCKCHIP, Inc.
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <linux/hwmon.h>
17 #include <linux/init.h>
18 #include <linux/err.h>
19 #include <linux/delay.h>
20 #include <linux/input.h>
21 #include <linux/interrupt.h>
22 #include <linux/slab.h>
23 #include <linux/gpio.h>
24 #include <linux/spi/spi.h>
27 #include "xpt2046_ts.h"
30 * This code has been heavily tested on a Nokia 770, and lightly
31 * tested on other xpt2046 devices (OSK/Mistral, Lubbock).
32 * TSC2046 is just newer xpt2046 silicon.
33 * Support for ads7843 tested on Atmel at91sam926x-EK.
34 * Support for ads7845 has only been stubbed in.
36 * IRQ handling needs a workaround because of a shortcoming in handling
37 * edge triggered IRQs on some platforms like the OMAP1/2. These
38 * platforms don't handle the ARM lazy IRQ disabling properly, thus we
39 * have to maintain our own SW IRQ disabled status. This should be
40 * removed as soon as the affected platform's IRQ handling is fixed.
42 * app note sbaa036 talks in more detail about accurate sampling...
43 * that ought to help in situations like LCDs inducing noise (which
44 * can also be helped by using synch signals) and more generally.
45 * This driver tries to utilize the measures described in the app
46 * note. The strength of filtering can be set in the board-* specific
49 #define XPT2046_DEBUG 0
51 #define xpt2046printk(msg...) printk(msg);
53 #define xpt2046printk(msg...)
55 #define LCD_MAX_LENGTH 800
56 #define LCD_MAX_WIDTH 480
57 #define PT2046_TOUCH_AD_LEFT 3855
58 #define PT2046_TOUCH_AD_RIGHT 260
59 #define PT2046_TOUCH_AD_TOP 300
60 #define PT2046_TOUCH_AD_BOTTOM 3755
61 #define AD_TO_X(adx) (LCD_MAX_WIDTH * (adx - PT2046_TOUCH_AD_TOP) / ( PT2046_TOUCH_AD_BOTTOM - PT2046_TOUCH_AD_TOP ))
62 #define AD_TO_Y(ady) (LCD_MAX_LENGTH * (PT2046_TOUCH_AD_LEFT - ady) / (PT2046_TOUCH_AD_LEFT - PT2046_TOUCH_AD_RIGHT))
64 #define TS_POLL_DELAY (15 * 1000000) /* ns delay before the first sample */
65 #define TS_POLL_PERIOD (15 * 1000000) /* ns delay between samples */
67 #define DEBOUNCE_REPTIME 3
68 /* this driver doesn't aim at the peak continuous sample rate */
69 #define SAMPLE_BITS (8 /*cmd*/ + 16 /*sample*/ + 2 /* before, after */)
72 /* For portability, we can't read 12 bit values using SPI (which
73 * would make the controller deliver them as native byteorder u16
74 * with msbs zeroed). Instead, we read them as two 8-bit values,
75 * *** WHICH NEED BYTESWAPPING *** and range adjustment.
83 * We allocate this separately to avoid cache line sharing issues when
84 * driver is used with DMA-based SPI controllers (like atmel_spi) on
85 * systems where main memory is not DMA-coherent (most non-x86 boards).
87 struct xpt2046_packet {
88 u8 read_x, read_y, pwrdown;
89 u16 dummy; /* for the pwrdown read */
94 struct input_dev *input;
98 struct spi_device *spi;
103 struct xpt2046_packet *packet;
105 struct spi_transfer xfer[18];
106 struct spi_message msg[5];
107 struct spi_message *last_msg;
117 u16 penirq_recheck_delay_usecs;
120 struct hrtimer timer;
121 unsigned pendown:1; /* P: lock */
122 unsigned pending:1; /* P: lock */
123 // FIXME remove "irq_disabled"
124 unsigned irq_disabled:1; /* P: lock */
126 unsigned is_suspended:1;
128 int (*filter)(void *data, int data_idx, int *val);
130 void (*filter_cleanup)(void *data);
131 int (*get_pendown_state)(void);
134 void (*wait_for_sync)(void);
137 /* leave chip selected when we're done, for quicker re-select? */
139 #define CS_CHANGE(xfer) ((xfer).cs_change = 1)
141 #define CS_CHANGE(xfer) ((xfer).cs_change = 0)
144 /*--------------------------------------------------------------------------*/
146 /* The xpt2046 has touchscreen and other sensors.
147 * Earlier xpt2046 chips are somewhat compatible.
149 #define XPT2046_START (1 << 7)
150 #define XPT2046_A2A1A0_d_y (1 << 4) /* differential */
151 #define XPT2046_A2A1A0_d_z1 (3 << 4) /* differential */
152 #define XPT2046_A2A1A0_d_z2 (4 << 4) /* differential */
153 #define XPT2046_A2A1A0_d_x (5 << 4) /* differential */
154 #define XPT2046_A2A1A0_temp0 (0 << 4) /* non-differential */
155 #define XPT2046_A2A1A0_vbatt (2 << 4) /* non-differential */
156 #define XPT2046_A2A1A0_vaux (6 << 4) /* non-differential */
157 #define XPT2046_A2A1A0_temp1 (7 << 4) /* non-differential */
158 #define XPT2046_8_BIT (1 << 3)
159 #define XPT2046_12_BIT (0 << 3)
160 #define XPT2046_SER (1 << 2) /* non-differential */
161 #define XPT2046_DFR (0 << 2) /* differential */
162 #define XPT2046_PD10_PDOWN (0 << 0) /* lowpower mode + penirq */
163 #define XPT2046_PD10_ADC_ON (1 << 0) /* ADC on */
164 #define XPT2046_PD10_REF_ON (2 << 0) /* vREF on + penirq */
165 #define XPT2046_PD10_ALL_ON (3 << 0) /* ADC + vREF on */
167 #define MAX_12BIT ((1<<12)-1)
169 /* leave ADC powered up (disables penirq) between differential samples */
170 #define READ_12BIT_DFR(x, adc, vref) (XPT2046_START | XPT2046_A2A1A0_d_ ## x \
171 | XPT2046_12_BIT | XPT2046_DFR | \
172 (adc ? XPT2046_PD10_ADC_ON : 0) | (vref ? XPT2046_PD10_REF_ON : 0))
174 #define READ_Y(vref) (READ_12BIT_DFR(y, 1, vref))
175 #define READ_Z1(vref) (READ_12BIT_DFR(z1, 1, vref))
176 #define READ_Z2(vref) (READ_12BIT_DFR(z2, 1, vref))
178 #define READ_X(vref) (READ_12BIT_DFR(x, 1, vref))
179 #define PWRDOWN (READ_12BIT_DFR(y, 0, 0)) /* LAST */
181 /* single-ended samples need to first power up reference voltage;
182 * we leave both ADC and VREF powered
184 #define READ_12BIT_SER(x) (XPT2046_START | XPT2046_A2A1A0_ ## x \
185 | XPT2046_12_BIT | XPT2046_SER)
187 #define REF_ON (READ_12BIT_DFR(x, 1, 1))
188 #define REF_OFF (READ_12BIT_DFR(y, 0, 0))
190 /*--------------------------------------------------------------------------*/
192 * touchscreen sensors use differential conversions.
198 u16 dummy; /* for the pwrdown read */
200 struct spi_message msg;
201 struct spi_transfer xfer[4];
204 static struct xpt2046_platform_data xpt2046_info = {
213 .debounce_rep = DEBOUNCE_REPTIME,
215 .gpio_pendown = RK2818_PIN_PE3,
218 static void xpt2046_enable(struct xpt2046 *ts);
219 static void xpt2046_disable(struct xpt2046 *ts);
221 static int device_suspended(struct device *dev)
223 struct xpt2046 *ts = dev_get_drvdata(dev);
224 return ts->is_suspended || ts->disabled;
227 static int xpt2046_read12_dfr(struct device *dev, unsigned command)
229 struct spi_device *spi = to_spi_device(dev);
230 struct xpt2046 *ts = dev_get_drvdata(dev);
231 struct dfr_req *req = kzalloc(sizeof *req, GFP_KERNEL);
237 spi_message_init(&req->msg);
240 req->command = (u8) command;
241 req->xfer[0].tx_buf = &req->command;
242 req->xfer[0].len = 1;
243 spi_message_add_tail(&req->xfer[0], &req->msg);
245 req->xfer[1].rx_buf = &req->sample;
246 req->xfer[1].len = 2;
247 spi_message_add_tail(&req->xfer[1], &req->msg);
249 /* converter in low power mode & enable PENIRQ */
250 req->pwrdown= PWRDOWN;
251 req->xfer[2].tx_buf = &req->pwrdown;
252 req->xfer[2].len = 1;
253 spi_message_add_tail(&req->xfer[2], &req->msg);
255 req->xfer[3].rx_buf = &req->dummy;
256 req->xfer[3].len = 2;
257 CS_CHANGE(req->xfer[3]);
258 spi_message_add_tail(&req->xfer[3], &req->msg);
260 ts->irq_disabled = 1;
261 disable_irq(spi->irq);
262 status = spi_sync(spi, &req->msg);
263 ts->irq_disabled = 0;
264 enable_irq(spi->irq);
267 /* on-wire is a must-ignore bit, a BE12 value, then padding */
268 status = be16_to_cpu(req->sample);
269 status = status >> 3;
271 xpt2046printk("***>%s:status=%d\n",__FUNCTION__,status);
280 /*--------------------------------------------------------------------------*/
282 static int get_pendown_state(struct xpt2046 *ts)
284 if (ts->get_pendown_state)
285 return ts->get_pendown_state();
287 return !gpio_get_value(ts->gpio_pendown);
290 static void null_wait_for_sync(void)
296 * PENIRQ only kicks the timer. The timer only reissues the SPI transfer,
297 * to retrieve touchscreen status.
299 * The SPI transfer completion callback does the real work. It reports
300 * touchscreen events and reactivates the timer (or IRQ) as appropriate.
303 static void xpt2046_rx(void *xpt)
305 struct xpt2046 *ts = xpt;
306 struct xpt2046_packet *packet = ts->packet;
310 /* xpt2046_rx_val() did in-place conversion (including byteswap) from
311 * on-the-wire format as part of debouncing to get stable readings.
316 xpt2046printk("***>%s:x=%d,y=%d\n",__FUNCTION__,x,y);
318 /* range filtering */
322 /* Sample found inconsistent by debouncing or pressure is beyond
323 * the maximum. Don't report it to user space, repeat at least
324 * once more the measurement
326 if (packet->tc.ignore) {
328 xpt2046printk("***>%s:ignored=%d\n",__FUNCTION__,packet->tc.ignore);
330 hrtimer_start(&ts->timer, ktime_set(0, TS_POLL_PERIOD),
335 /* Maybe check the pendown state before reporting. This discards
336 * false readings when the pen is lifted.
338 if (ts->penirq_recheck_delay_usecs) {
339 udelay(ts->penirq_recheck_delay_usecs);
340 if (!get_pendown_state(ts))
342 xpt2046printk("***>%s:get_pendown_state(ts)==0,discard false reading\n",__FUNCTION__);
347 /* NOTE: We can't rely on the pressure to determine the pen down
348 * state, even this controller has a pressure sensor. The pressure
349 * value can fluctuate for quite a while after lifting the pen and
350 * in some cases may not even settle at the expected value.
352 * The only safe way to check for the pen up condition is in the
353 * timer by reading the pen signal state (it's a GPIO _and_ IRQ).
356 struct input_dev *input = ts->input;
358 input_report_key(input, BTN_TOUCH, 1);
360 xpt2046printk("***>%s:input_report_key(pen down)\n",__FUNCTION__);
369 input_report_abs(input, ABS_X, x);
370 input_report_abs(input, ABS_Y, y);
373 xpt2046printk("***>%s:input_report_abs(%4d/%4d)\n",__FUNCTION__,x, y);
376 hrtimer_start(&ts->timer, ktime_set(0, TS_POLL_PERIOD),
380 static int xpt2046_debounce(void *xpt, int data_idx, int *val)
382 struct xpt2046 *ts = xpt;
383 static int average_val[2];
386 xpt2046printk("***>%s:%d,%d,%d,%d,%d,%d,%d,%d\n",__FUNCTION__,
387 data_idx,ts->last_read,
388 ts->read_cnt,ts->debounce_max,
389 abs(ts->last_read - *val),ts->debounce_tol,
390 ts->read_rep,ts->debounce_rep);
392 /* discard the first sample. */
397 return XPT2046_FILTER_REPEAT;
400 if (ts->read_cnt==1 || (abs(ts->last_read - *val) > ts->debounce_tol)) {
401 /* Start over collecting consistent readings. */
403 average_val[data_idx] = *val;
404 /* Repeat it, if this was the first read or the read
405 * wasn't consistent enough. */
406 if (ts->read_cnt < ts->debounce_max) {
407 ts->last_read = *val;
409 return XPT2046_FILTER_REPEAT;
411 /* Maximum number of debouncing reached and still
412 * not enough number of consistent readings. Abort
413 * the whole sample, repeat it in the next sampling
418 memset(average_val,0,sizeof(average_val));
419 xpt2046printk("***>%s:XPT2046_FILTER_IGNORE\n",__FUNCTION__);
420 return XPT2046_FILTER_IGNORE;
424 average_val[data_idx] += *val;
426 if (++ts->read_rep >= ts->debounce_rep) {
427 /* Got a good reading for this coordinate,
428 * go for the next one. */
432 *val = average_val[data_idx]/(ts->debounce_rep);
433 return XPT2046_FILTER_OK;
435 /* Read more values that are consistent. */
438 return XPT2046_FILTER_REPEAT;
443 static int xpt2046_no_filter(void *xpt, int data_idx, int *val)
445 return XPT2046_FILTER_OK;
448 static void xpt2046_rx_val(void *xpt)
450 struct xpt2046 *ts = xpt;
451 struct xpt2046_packet *packet = ts->packet;
452 struct spi_message *m;
453 struct spi_transfer *t;
458 m = &ts->msg[ts->msg_idx];
459 t = list_entry(m->transfers.prev, struct spi_transfer, transfer_list);
461 /* adjust: on-wire is a must-ignore bit, a BE12 value, then padding;
462 * built from two 8 bit values written msb-first.
464 val = (be16_to_cpup((__be16 *)t->rx_buf) >> 3) & 0x0fff;
466 xpt2046printk("***>%s:value=%d\n",__FUNCTION__,val);
468 action = ts->filter(ts->filter_data, ts->msg_idx, &val);
470 case XPT2046_FILTER_REPEAT:
472 case XPT2046_FILTER_IGNORE:
473 packet->tc.ignore = 1;
474 /* Last message will contain xpt2046_rx() as the
475 * completion function.
479 case XPT2046_FILTER_OK:
480 *(u16 *)t->rx_buf = val;
481 packet->tc.ignore = 0;
482 m = &ts->msg[++ts->msg_idx];
488 status = spi_async(ts->spi, m);
490 dev_err(&ts->spi->dev, "spi_async --> %d\n",
494 static enum hrtimer_restart xpt2046_timer(struct hrtimer *handle)
496 struct xpt2046 *ts = container_of(handle, struct xpt2046, timer);
499 spin_lock(&ts->lock);
501 if (unlikely(!get_pendown_state(ts) ||
502 device_suspended(&ts->spi->dev))) {
504 struct input_dev *input = ts->input;
505 input_report_key(input, BTN_TOUCH, 0);
510 xpt2046printk("***>%s:input_report_key(The touchscreen up)\n",__FUNCTION__);
513 /* measurement cycle ended */
514 if (!device_suspended(&ts->spi->dev)) {
515 xpt2046printk("***>%s:device_suspended==0\n",__FUNCTION__);
516 ts->irq_disabled = 0;
517 enable_irq(ts->spi->irq);
521 /* pen is still down, continue with the measurement */
522 xpt2046printk("***>%s:pen is still down, continue with the measurement\n",__FUNCTION__);
525 status = spi_async(ts->spi, &ts->msg[0]);
527 dev_err(&ts->spi->dev, "spi_async --> %d\n", status);
530 spin_unlock(&ts->lock);
531 return HRTIMER_NORESTART;
534 static irqreturn_t xpt2046_irq(int irq, void *handle)
536 struct xpt2046 *ts = handle;
539 xpt2046printk("***>%s.....%s.....%d\n",__FILE__,__FUNCTION__,__LINE__);
541 spin_lock_irqsave(&ts->lock, flags);
543 if (likely(get_pendown_state(ts))) {
544 if (!ts->irq_disabled) {
545 /* The ARM do_simple_IRQ() dispatcher doesn't act
546 * like the other dispatchers: it will report IRQs
547 * even after they've been disabled. We work around
548 * that here. (The "generic irq" framework may help...)
550 ts->irq_disabled = 1;
551 disable_irq_nosync(ts->spi->irq);
553 hrtimer_start(&ts->timer, ktime_set(0, TS_POLL_DELAY),
557 spin_unlock_irqrestore(&ts->lock, flags);
562 /*--------------------------------------------------------------------------*/
564 /* Must be called with ts->lock held */
565 static void xpt2046_disable(struct xpt2046 *ts)
572 /* are we waiting for IRQ, or polling? */
574 ts->irq_disabled = 1;
575 disable_irq(ts->spi->irq);
577 /* the timer will run at least once more, and
578 * leave everything in a clean state, IRQ disabled
580 while (ts->pending) {
581 spin_unlock_irq(&ts->lock);
583 spin_lock_irq(&ts->lock);
587 /* we know the chip's in lowpower mode since we always
588 * leave it that way after every request
592 /* Must be called with ts->lock held */
593 static void xpt2046_enable(struct xpt2046 *ts)
599 ts->irq_disabled = 0;
600 enable_irq(ts->spi->irq);
603 static int xpt2046_suspend(struct spi_device *spi, pm_message_t message)
605 struct xpt2046 *ts = dev_get_drvdata(&spi->dev);
607 spin_lock_irq(&ts->lock);
609 ts->is_suspended = 1;
612 spin_unlock_irq(&ts->lock);
618 static int xpt2046_resume(struct spi_device *spi)
620 struct xpt2046 *ts = dev_get_drvdata(&spi->dev);
622 spin_lock_irq(&ts->lock);
624 ts->is_suspended = 0;
627 spin_unlock_irq(&ts->lock);
632 static int __devinit setup_pendown(struct spi_device *spi, struct xpt2046 *ts)
634 struct xpt2046_platform_data *pdata = spi->dev.platform_data;
637 /* REVISIT when the irq can be triggered active-low, or if for some
638 * reason the touchscreen isn't hooked up, we don't need to access
641 if (!pdata->get_pendown_state && !gpio_is_valid(pdata->gpio_pendown)) {
642 dev_err(&spi->dev, "no get_pendown_state nor gpio_pendown?\n");
646 if (pdata->get_pendown_state) {
647 ts->get_pendown_state = pdata->get_pendown_state;
651 err = gpio_request(pdata->gpio_pendown, "xpt2046_pendown");
653 dev_err(&spi->dev, "failed to request pendown GPIO%d\n",
654 pdata->gpio_pendown);
658 ts->gpio_pendown = pdata->gpio_pendown;
662 static int __devinit xpt2046_probe(struct spi_device *spi)
665 struct xpt2046_packet *packet;
666 struct input_dev *input_dev;
667 struct xpt2046_platform_data *pdata = spi->dev.platform_data;
668 struct spi_message *m;
669 struct spi_transfer *x;
676 dev_dbg(&spi->dev, "no IRQ?\n");
680 spi->irq = gpio_to_irq(spi->irq);
681 dev_dbg(&spi->dev, "no IRQ?\n");
685 spi->dev.platform_data = &xpt2046_info;
686 pdata = spi->dev.platform_data;
689 /* don't exceed max specified sample rate */
690 if (spi->max_speed_hz > (125000 * SAMPLE_BITS)) {
691 dev_dbg(&spi->dev, "f(sample) %d KHz?\n",
692 (spi->max_speed_hz/SAMPLE_BITS)/1000);
696 /* We'd set TX wordsize 8 bits and RX wordsize to 13 bits ... except
697 * that even if the hardware can do that, the SPI controller driver
698 * may not. So we stick to very-portable 8 bit words, both RX and TX.
700 spi->bits_per_word = 8;
701 spi->mode = SPI_MODE_0;
702 err = spi_setup(spi);
706 ts = kzalloc(sizeof(struct xpt2046), GFP_KERNEL);
707 packet = kzalloc(sizeof(struct xpt2046_packet), GFP_KERNEL);
708 input_dev = input_allocate_device();
709 if (!ts || !packet || !input_dev) {
714 dev_set_drvdata(&spi->dev, ts);
718 ts->input = input_dev;
719 ts->swap_xy = pdata->swap_xy;
721 hrtimer_init(&ts->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
722 ts->timer.function = xpt2046_timer;
724 spin_lock_init(&ts->lock);
726 ts->model = pdata->model ? : 2046;
728 if (pdata->filter != NULL) {
729 if (pdata->filter_init != NULL) {
730 err = pdata->filter_init(pdata, &ts->filter_data);
734 ts->filter = pdata->filter;
735 ts->filter_cleanup = pdata->filter_cleanup;
736 } else if (pdata->debounce_max) {
737 ts->debounce_max = pdata->debounce_max;
738 if (ts->debounce_max < DEBOUNCE_REPTIME)
739 ts->debounce_max = DEBOUNCE_REPTIME;
740 ts->debounce_tol = pdata->debounce_tol;
741 ts->debounce_rep = pdata->debounce_rep;
742 ts->filter = xpt2046_debounce;
743 ts->filter_data = ts;
745 ts->filter = xpt2046_no_filter;
747 err = setup_pendown(spi, ts);
749 goto err_cleanup_filter;
751 if (pdata->penirq_recheck_delay_usecs)
752 ts->penirq_recheck_delay_usecs =
753 pdata->penirq_recheck_delay_usecs;
755 ts->wait_for_sync = pdata->wait_for_sync ? : null_wait_for_sync;
757 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(&spi->dev));
758 snprintf(ts->name, sizeof(ts->name), "XPT%d Touchscreen", ts->model);
760 input_dev->name = ts->name;
761 input_dev->phys = ts->phys;
762 input_dev->dev.parent = &spi->dev;
764 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
765 input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
766 input_set_abs_params(input_dev, ABS_X,
768 pdata->x_max ? : MAX_12BIT,
770 input_set_abs_params(input_dev, ABS_Y,
772 pdata->y_max ? : MAX_12BIT,
775 vref = pdata->keep_vref_on;
777 /* set up the transfers to read touchscreen state; this assumes we
778 * use formula #2 for pressure, not #3.
785 /* y- still on; turn on only y+ (and ADC) */
786 packet->read_y = READ_Y(vref);
787 x->tx_buf = &packet->read_y;
789 spi_message_add_tail(x, m);
792 x->rx_buf = &packet->tc.y;
794 spi_message_add_tail(x, m);
796 m->complete = xpt2046_rx_val;
802 /* turn y- off, x+ on, then leave in lowpower */
804 packet->read_x = READ_X(vref);
805 x->tx_buf = &packet->read_x;
807 spi_message_add_tail(x, m);
810 x->rx_buf = &packet->tc.x;
812 spi_message_add_tail(x, m);
814 m->complete = xpt2046_rx_val;
822 packet->pwrdown = PWRDOWN;
823 x->tx_buf = &packet->pwrdown;
825 spi_message_add_tail(x, m);
828 x->rx_buf = &packet->dummy;
831 spi_message_add_tail(x, m);
833 m->complete = xpt2046_rx;
838 if (request_irq(spi->irq, xpt2046_irq, IRQF_TRIGGER_FALLING,
839 spi->dev.driver->name, ts)) {
840 printk("%s:trying pin change workaround on irq %d\n",__FUNCTION__,spi->irq);
841 err = request_irq(spi->irq, xpt2046_irq,
842 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
843 spi->dev.driver->name, ts);
845 dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq);
849 xpt2046printk("***>%s:touchscreen irq %d\n",__FUNCTION__,spi->irq);
851 /* take a first sample, leaving nPENIRQ active and vREF off; avoid
852 * the touchscreen, in case it's not connected.
854 xpt2046_read12_dfr(&spi->dev,READ_X(1));
856 err = input_register_device(input_dev);
858 goto err_remove_attr_group;
859 printk("xpt2046_ts: driver initialized\n");
862 err_remove_attr_group:
863 free_irq(spi->irq, ts);
865 if (ts->gpio_pendown != -1)
866 gpio_free(ts->gpio_pendown);
868 if (ts->filter_cleanup)
869 ts->filter_cleanup(ts->filter_data);
871 input_free_device(input_dev);
877 static int __devexit xpt2046_remove(struct spi_device *spi)
879 struct xpt2046 *ts = dev_get_drvdata(&spi->dev);
881 input_unregister_device(ts->input);
883 xpt2046_suspend(spi, PMSG_SUSPEND);
885 free_irq(ts->spi->irq, ts);
886 /* suspend left the IRQ disabled */
887 enable_irq(ts->spi->irq);
889 if (ts->gpio_pendown != -1)
890 gpio_free(ts->gpio_pendown);
892 if (ts->filter_cleanup)
893 ts->filter_cleanup(ts->filter_data);
898 dev_dbg(&spi->dev, "unregistered touchscreen\n");
902 static struct spi_driver xpt2046_driver = {
904 .name = "xpt2046_ts",
905 .bus = &spi_bus_type,
906 .owner = THIS_MODULE,
908 .probe = xpt2046_probe,
909 .remove = __devexit_p(xpt2046_remove),
910 .suspend = xpt2046_suspend,
911 .resume = xpt2046_resume,
914 static int __init xpt2046_init(void)
916 return spi_register_driver(&xpt2046_driver);
918 module_init(xpt2046_init);
920 static void __exit xpt2046_exit(void)
922 spi_unregister_driver(&xpt2046_driver);
924 module_exit(xpt2046_exit);
926 MODULE_DESCRIPTION("rk2818 spi xpt2046 TouchScreen Driver");
927 MODULE_LICENSE("GPL");
928 MODULE_ALIAS("spi:xpt2046");