2 * Copyright (C) 2006-2008 Michael Hennerich, Analog Devices Inc.
4 * Description: AD7877 based touchscreen, sensor (ADCs), DAC and GPIO driver
7 * Bugs: Enter bugs at http://blackfin.uclinux.org/
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, see the file COPYING, or write
21 * to the Free Software Foundation, Inc.,
22 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 * Copyright (c) 2005 David Brownell
26 * Copyright (c) 2006 Nokia Corporation
27 * Various changes: Imre Deak <imre.deak@nokia.com>
31 * Copyright (C) 2004-2005 Richard Purdie
32 * - omap_ts.[hc], ads7846.h, ts_osk.c
33 * Copyright (C) 2002 MontaVista Software
34 * Copyright (C) 2004 Texas Instruments
35 * Copyright (C) 2005 Dirk Behme
39 #include <linux/device.h>
40 #include <linux/init.h>
41 #include <linux/delay.h>
42 #include <linux/input.h>
43 #include <linux/interrupt.h>
44 #include <linux/slab.h>
45 #include <linux/spi/spi.h>
46 #include <linux/spi/ad7877.h>
49 #define TS_PEN_UP_TIMEOUT msecs_to_jiffies(100)
51 #define MAX_SPI_FREQ_HZ 20000000
52 #define MAX_12BIT ((1<<12)-1)
54 #define AD7877_REG_ZEROS 0
55 #define AD7877_REG_CTRL1 1
56 #define AD7877_REG_CTRL2 2
57 #define AD7877_REG_ALERT 3
58 #define AD7877_REG_AUX1HIGH 4
59 #define AD7877_REG_AUX1LOW 5
60 #define AD7877_REG_BAT1HIGH 6
61 #define AD7877_REG_BAT1LOW 7
62 #define AD7877_REG_BAT2HIGH 8
63 #define AD7877_REG_BAT2LOW 9
64 #define AD7877_REG_TEMP1HIGH 10
65 #define AD7877_REG_TEMP1LOW 11
66 #define AD7877_REG_SEQ0 12
67 #define AD7877_REG_SEQ1 13
68 #define AD7877_REG_DAC 14
69 #define AD7877_REG_NONE1 15
70 #define AD7877_REG_EXTWRITE 15
71 #define AD7877_REG_XPLUS 16
72 #define AD7877_REG_YPLUS 17
73 #define AD7877_REG_Z2 18
74 #define AD7877_REG_aux1 19
75 #define AD7877_REG_aux2 20
76 #define AD7877_REG_aux3 21
77 #define AD7877_REG_bat1 22
78 #define AD7877_REG_bat2 23
79 #define AD7877_REG_temp1 24
80 #define AD7877_REG_temp2 25
81 #define AD7877_REG_Z1 26
82 #define AD7877_REG_GPIOCTRL1 27
83 #define AD7877_REG_GPIOCTRL2 28
84 #define AD7877_REG_GPIODATA 29
85 #define AD7877_REG_NONE2 30
86 #define AD7877_REG_NONE3 31
88 #define AD7877_SEQ_YPLUS_BIT (1<<11)
89 #define AD7877_SEQ_XPLUS_BIT (1<<10)
90 #define AD7877_SEQ_Z2_BIT (1<<9)
91 #define AD7877_SEQ_AUX1_BIT (1<<8)
92 #define AD7877_SEQ_AUX2_BIT (1<<7)
93 #define AD7877_SEQ_AUX3_BIT (1<<6)
94 #define AD7877_SEQ_BAT1_BIT (1<<5)
95 #define AD7877_SEQ_BAT2_BIT (1<<4)
96 #define AD7877_SEQ_TEMP1_BIT (1<<3)
97 #define AD7877_SEQ_TEMP2_BIT (1<<2)
98 #define AD7877_SEQ_Z1_BIT (1<<1)
109 AD7877_SEQ_TEMP1
= 8,
110 AD7877_SEQ_TEMP2
= 9,
112 AD7877_NR_SENSE
= 11,
115 /* DAC Register Default RANGE 0 to Vcc, Volatge Mode, DAC On */
116 #define AD7877_DAC_CONF 0x1
118 /* If gpio3 is set AUX3/GPIO3 acts as GPIO Output */
119 #define AD7877_EXTW_GPIO_3_CONF 0x1C4
120 #define AD7877_EXTW_GPIO_DATA 0x200
123 #define AD7877_TMR(x) ((x & 0x3) << 0)
124 #define AD7877_REF(x) ((x & 0x1) << 2)
125 #define AD7877_POL(x) ((x & 0x1) << 3)
126 #define AD7877_FCD(x) ((x & 0x3) << 4)
127 #define AD7877_PM(x) ((x & 0x3) << 6)
128 #define AD7877_ACQ(x) ((x & 0x3) << 8)
129 #define AD7877_AVG(x) ((x & 0x3) << 10)
132 #define AD7877_SER (1 << 11) /* non-differential */
133 #define AD7877_DFR (0 << 11) /* differential */
135 #define AD7877_MODE_NOC (0) /* Do not convert */
136 #define AD7877_MODE_SCC (1) /* Single channel conversion */
137 #define AD7877_MODE_SEQ0 (2) /* Sequence 0 in Slave Mode */
138 #define AD7877_MODE_SEQ1 (3) /* Sequence 1 in Master Mode */
140 #define AD7877_CHANADD(x) ((x&0xF)<<7)
141 #define AD7877_READADD(x) ((x)<<2)
142 #define AD7877_WRITEADD(x) ((x)<<12)
144 #define AD7877_READ_CHAN(x) (AD7877_WRITEADD(AD7877_REG_CTRL1) | AD7877_SER | \
145 AD7877_MODE_SCC | AD7877_CHANADD(AD7877_REG_ ## x) | \
146 AD7877_READADD(AD7877_REG_ ## x))
148 #define AD7877_MM_SEQUENCE (AD7877_SEQ_YPLUS_BIT | AD7877_SEQ_XPLUS_BIT | \
149 AD7877_SEQ_Z2_BIT | AD7877_SEQ_Z1_BIT)
152 * Non-touchscreen sensors only use single-ended conversions.
159 struct spi_message msg
;
160 struct spi_transfer xfer
[6];
163 * DMA (thus cache coherency maintenance) requires the
164 * transfer buffers to live in their own cache lines.
166 u16 sample ____cacheline_aligned
;
170 struct input_dev
*input
;
173 struct spi_device
*spi
;
175 u16 vref_delay_usecs
;
185 u8 first_conversion_delay
;
188 u8 pen_down_acc_interval
;
190 struct spi_transfer xfer
[AD7877_NR_SENSE
+ 2];
191 struct spi_message msg
;
194 bool disabled
; /* P: mutex */
195 bool gpio3
; /* P: mutex */
196 bool gpio4
; /* P: mutex */
199 struct timer_list timer
; /* P: lock */
202 * DMA (thus cache coherency maintenance) requires the
203 * transfer buffers to live in their own cache lines.
205 u16 conversion_data
[AD7877_NR_SENSE
] ____cacheline_aligned
;
209 module_param(gpio3
, bool, 0);
210 MODULE_PARM_DESC(gpio3
, "If gpio3 is set to 1 AUX3 acts as GPIO3");
213 * ad7877_read/write are only used for initial setup and for sysfs controls.
214 * The main traffic is done using spi_async() in the interrupt handler.
217 static int ad7877_read(struct spi_device
*spi
, u16 reg
)
222 req
= kzalloc(sizeof *req
, GFP_KERNEL
);
226 spi_message_init(&req
->msg
);
228 req
->command
= (u16
) (AD7877_WRITEADD(AD7877_REG_CTRL1
) |
229 AD7877_READADD(reg
));
230 req
->xfer
[0].tx_buf
= &req
->command
;
231 req
->xfer
[0].len
= 2;
232 req
->xfer
[0].cs_change
= 1;
234 req
->xfer
[1].rx_buf
= &req
->sample
;
235 req
->xfer
[1].len
= 2;
237 spi_message_add_tail(&req
->xfer
[0], &req
->msg
);
238 spi_message_add_tail(&req
->xfer
[1], &req
->msg
);
240 status
= spi_sync(spi
, &req
->msg
);
241 ret
= status
? : req
->sample
;
248 static int ad7877_write(struct spi_device
*spi
, u16 reg
, u16 val
)
253 req
= kzalloc(sizeof *req
, GFP_KERNEL
);
257 spi_message_init(&req
->msg
);
259 req
->command
= (u16
) (AD7877_WRITEADD(reg
) | (val
& MAX_12BIT
));
260 req
->xfer
[0].tx_buf
= &req
->command
;
261 req
->xfer
[0].len
= 2;
263 spi_message_add_tail(&req
->xfer
[0], &req
->msg
);
265 status
= spi_sync(spi
, &req
->msg
);
272 static int ad7877_read_adc(struct spi_device
*spi
, unsigned command
)
274 struct ad7877
*ts
= dev_get_drvdata(&spi
->dev
);
280 req
= kzalloc(sizeof *req
, GFP_KERNEL
);
284 spi_message_init(&req
->msg
);
286 /* activate reference, so it has time to settle; */
287 req
->ref_on
= AD7877_WRITEADD(AD7877_REG_CTRL2
) |
288 AD7877_POL(ts
->stopacq_polarity
) |
289 AD7877_AVG(0) | AD7877_PM(2) | AD7877_TMR(0) |
290 AD7877_ACQ(ts
->acquisition_time
) | AD7877_FCD(0);
292 req
->reset
= AD7877_WRITEADD(AD7877_REG_CTRL1
) | AD7877_MODE_NOC
;
294 req
->command
= (u16
) command
;
296 req
->xfer
[0].tx_buf
= &req
->reset
;
297 req
->xfer
[0].len
= 2;
298 req
->xfer
[0].cs_change
= 1;
300 req
->xfer
[1].tx_buf
= &req
->ref_on
;
301 req
->xfer
[1].len
= 2;
302 req
->xfer
[1].delay_usecs
= ts
->vref_delay_usecs
;
303 req
->xfer
[1].cs_change
= 1;
305 req
->xfer
[2].tx_buf
= &req
->command
;
306 req
->xfer
[2].len
= 2;
307 req
->xfer
[2].delay_usecs
= ts
->vref_delay_usecs
;
308 req
->xfer
[2].cs_change
= 1;
310 req
->xfer
[3].rx_buf
= &req
->sample
;
311 req
->xfer
[3].len
= 2;
312 req
->xfer
[3].cs_change
= 1;
314 req
->xfer
[4].tx_buf
= &ts
->cmd_crtl2
; /*REF OFF*/
315 req
->xfer
[4].len
= 2;
316 req
->xfer
[4].cs_change
= 1;
318 req
->xfer
[5].tx_buf
= &ts
->cmd_crtl1
; /*DEFAULT*/
319 req
->xfer
[5].len
= 2;
321 /* group all the transfers together, so we can't interfere with
322 * reading touchscreen state; disable penirq while sampling
324 for (i
= 0; i
< 6; i
++)
325 spi_message_add_tail(&req
->xfer
[i
], &req
->msg
);
327 status
= spi_sync(spi
, &req
->msg
);
328 sample
= req
->sample
;
332 return status
? : sample
;
335 static int ad7877_process_data(struct ad7877
*ts
)
337 struct input_dev
*input_dev
= ts
->input
;
341 x
= ts
->conversion_data
[AD7877_SEQ_XPOS
] & MAX_12BIT
;
342 y
= ts
->conversion_data
[AD7877_SEQ_YPOS
] & MAX_12BIT
;
343 z1
= ts
->conversion_data
[AD7877_SEQ_Z1
] & MAX_12BIT
;
344 z2
= ts
->conversion_data
[AD7877_SEQ_Z2
] & MAX_12BIT
;
347 * The samples processed here are already preprocessed by the AD7877.
348 * The preprocessing function consists of an averaging filter.
349 * The combination of 'first conversion delay' and averaging provides a robust solution,
350 * discarding the spurious noise in the signal and keeping only the data of interest.
351 * The size of the averaging filter is programmable. (dev.platform_data, see linux/spi/ad7877.h)
352 * Other user-programmable conversion controls include variable acquisition time,
353 * and first conversion delay. Up to 16 averages can be taken per conversion.
356 if (likely(x
&& z1
)) {
357 /* compute touch pressure resistance using equation #1 */
358 Rt
= (z2
- z1
) * x
* ts
->x_plate_ohms
;
360 Rt
= (Rt
+ 2047) >> 12;
363 * Sample found inconsistent, pressure is beyond
364 * the maximum. Don't report it to user space.
366 if (Rt
> ts
->pressure_max
)
369 if (!timer_pending(&ts
->timer
))
370 input_report_key(input_dev
, BTN_TOUCH
, 1);
372 input_report_abs(input_dev
, ABS_X
, x
);
373 input_report_abs(input_dev
, ABS_Y
, y
);
374 input_report_abs(input_dev
, ABS_PRESSURE
, Rt
);
375 input_sync(input_dev
);
383 static inline void ad7877_ts_event_release(struct ad7877
*ts
)
385 struct input_dev
*input_dev
= ts
->input
;
387 input_report_abs(input_dev
, ABS_PRESSURE
, 0);
388 input_report_key(input_dev
, BTN_TOUCH
, 0);
389 input_sync(input_dev
);
392 static void ad7877_timer(unsigned long handle
)
394 struct ad7877
*ts
= (void *)handle
;
397 spin_lock_irqsave(&ts
->lock
, flags
);
398 ad7877_ts_event_release(ts
);
399 spin_unlock_irqrestore(&ts
->lock
, flags
);
402 static irqreturn_t
ad7877_irq(int irq
, void *handle
)
404 struct ad7877
*ts
= handle
;
408 error
= spi_sync(ts
->spi
, &ts
->msg
);
410 dev_err(&ts
->spi
->dev
, "spi_sync --> %d\n", error
);
414 spin_lock_irqsave(&ts
->lock
, flags
);
415 error
= ad7877_process_data(ts
);
417 mod_timer(&ts
->timer
, jiffies
+ TS_PEN_UP_TIMEOUT
);
418 spin_unlock_irqrestore(&ts
->lock
, flags
);
424 static void ad7877_disable(struct ad7877
*ts
)
426 mutex_lock(&ts
->mutex
);
430 disable_irq(ts
->spi
->irq
);
432 if (del_timer_sync(&ts
->timer
))
433 ad7877_ts_event_release(ts
);
437 * We know the chip's in lowpower mode since we always
438 * leave it that way after every request
441 mutex_unlock(&ts
->mutex
);
444 static void ad7877_enable(struct ad7877
*ts
)
446 mutex_lock(&ts
->mutex
);
449 ts
->disabled
= false;
450 enable_irq(ts
->spi
->irq
);
453 mutex_unlock(&ts
->mutex
);
456 #define SHOW(name) static ssize_t \
457 name ## _show(struct device *dev, struct device_attribute *attr, char *buf) \
459 struct ad7877 *ts = dev_get_drvdata(dev); \
460 ssize_t v = ad7877_read_adc(ts->spi, \
461 AD7877_READ_CHAN(name)); \
464 return sprintf(buf, "%u\n", (unsigned) v); \
466 static DEVICE_ATTR(name, S_IRUGO, name ## _show, NULL);
476 static ssize_t
ad7877_disable_show(struct device
*dev
,
477 struct device_attribute
*attr
, char *buf
)
479 struct ad7877
*ts
= dev_get_drvdata(dev
);
481 return sprintf(buf
, "%u\n", ts
->disabled
);
484 static ssize_t
ad7877_disable_store(struct device
*dev
,
485 struct device_attribute
*attr
,
486 const char *buf
, size_t count
)
488 struct ad7877
*ts
= dev_get_drvdata(dev
);
492 error
= strict_strtoul(buf
, 10, &val
);
504 static DEVICE_ATTR(disable
, 0664, ad7877_disable_show
, ad7877_disable_store
);
506 static ssize_t
ad7877_dac_show(struct device
*dev
,
507 struct device_attribute
*attr
, char *buf
)
509 struct ad7877
*ts
= dev_get_drvdata(dev
);
511 return sprintf(buf
, "%u\n", ts
->dac
);
514 static ssize_t
ad7877_dac_store(struct device
*dev
,
515 struct device_attribute
*attr
,
516 const char *buf
, size_t count
)
518 struct ad7877
*ts
= dev_get_drvdata(dev
);
522 error
= strict_strtoul(buf
, 10, &val
);
526 mutex_lock(&ts
->mutex
);
527 ts
->dac
= val
& 0xFF;
528 ad7877_write(ts
->spi
, AD7877_REG_DAC
, (ts
->dac
<< 4) | AD7877_DAC_CONF
);
529 mutex_unlock(&ts
->mutex
);
534 static DEVICE_ATTR(dac
, 0664, ad7877_dac_show
, ad7877_dac_store
);
536 static ssize_t
ad7877_gpio3_show(struct device
*dev
,
537 struct device_attribute
*attr
, char *buf
)
539 struct ad7877
*ts
= dev_get_drvdata(dev
);
541 return sprintf(buf
, "%u\n", ts
->gpio3
);
544 static ssize_t
ad7877_gpio3_store(struct device
*dev
,
545 struct device_attribute
*attr
,
546 const char *buf
, size_t count
)
548 struct ad7877
*ts
= dev_get_drvdata(dev
);
552 error
= strict_strtoul(buf
, 10, &val
);
556 mutex_lock(&ts
->mutex
);
558 ad7877_write(ts
->spi
, AD7877_REG_EXTWRITE
, AD7877_EXTW_GPIO_DATA
|
559 (ts
->gpio4
<< 4) | (ts
->gpio3
<< 5));
560 mutex_unlock(&ts
->mutex
);
565 static DEVICE_ATTR(gpio3
, 0664, ad7877_gpio3_show
, ad7877_gpio3_store
);
567 static ssize_t
ad7877_gpio4_show(struct device
*dev
,
568 struct device_attribute
*attr
, char *buf
)
570 struct ad7877
*ts
= dev_get_drvdata(dev
);
572 return sprintf(buf
, "%u\n", ts
->gpio4
);
575 static ssize_t
ad7877_gpio4_store(struct device
*dev
,
576 struct device_attribute
*attr
,
577 const char *buf
, size_t count
)
579 struct ad7877
*ts
= dev_get_drvdata(dev
);
583 error
= strict_strtoul(buf
, 10, &val
);
587 mutex_lock(&ts
->mutex
);
589 ad7877_write(ts
->spi
, AD7877_REG_EXTWRITE
, AD7877_EXTW_GPIO_DATA
|
590 (ts
->gpio4
<< 4) | (ts
->gpio3
<< 5));
591 mutex_unlock(&ts
->mutex
);
596 static DEVICE_ATTR(gpio4
, 0664, ad7877_gpio4_show
, ad7877_gpio4_store
);
598 static struct attribute
*ad7877_attributes
[] = {
599 &dev_attr_temp1
.attr
,
600 &dev_attr_temp2
.attr
,
606 &dev_attr_disable
.attr
,
608 &dev_attr_gpio3
.attr
,
609 &dev_attr_gpio4
.attr
,
613 static mode_t
ad7877_attr_is_visible(struct kobject
*kobj
,
614 struct attribute
*attr
, int n
)
616 mode_t mode
= attr
->mode
;
618 if (attr
== &dev_attr_aux3
.attr
) {
621 } else if (attr
== &dev_attr_gpio3
.attr
) {
629 static const struct attribute_group ad7877_attr_group
= {
630 .is_visible
= ad7877_attr_is_visible
,
631 .attrs
= ad7877_attributes
,
634 static void ad7877_setup_ts_def_msg(struct spi_device
*spi
, struct ad7877
*ts
)
636 struct spi_message
*m
;
639 ts
->cmd_crtl2
= AD7877_WRITEADD(AD7877_REG_CTRL2
) |
640 AD7877_POL(ts
->stopacq_polarity
) |
641 AD7877_AVG(ts
->averaging
) | AD7877_PM(1) |
642 AD7877_TMR(ts
->pen_down_acc_interval
) |
643 AD7877_ACQ(ts
->acquisition_time
) |
644 AD7877_FCD(ts
->first_conversion_delay
);
646 ad7877_write(spi
, AD7877_REG_CTRL2
, ts
->cmd_crtl2
);
648 ts
->cmd_crtl1
= AD7877_WRITEADD(AD7877_REG_CTRL1
) |
649 AD7877_READADD(AD7877_REG_XPLUS
-1) |
650 AD7877_MODE_SEQ1
| AD7877_DFR
;
652 ad7877_write(spi
, AD7877_REG_CTRL1
, ts
->cmd_crtl1
);
662 ts
->xfer
[0].tx_buf
= &ts
->cmd_crtl1
;
664 ts
->xfer
[0].cs_change
= 1;
666 spi_message_add_tail(&ts
->xfer
[0], m
);
668 ts
->xfer
[1].tx_buf
= &ts
->cmd_dummy
; /* Send ZERO */
670 ts
->xfer
[1].cs_change
= 1;
672 spi_message_add_tail(&ts
->xfer
[1], m
);
674 for (i
= 0; i
< AD7877_NR_SENSE
; i
++) {
675 ts
->xfer
[i
+ 2].rx_buf
= &ts
->conversion_data
[AD7877_SEQ_YPOS
+ i
];
676 ts
->xfer
[i
+ 2].len
= 2;
677 if (i
< (AD7877_NR_SENSE
- 1))
678 ts
->xfer
[i
+ 2].cs_change
= 1;
679 spi_message_add_tail(&ts
->xfer
[i
+ 2], m
);
683 static int __devinit
ad7877_probe(struct spi_device
*spi
)
686 struct input_dev
*input_dev
;
687 struct ad7877_platform_data
*pdata
= spi
->dev
.platform_data
;
692 dev_dbg(&spi
->dev
, "no IRQ?\n");
697 dev_dbg(&spi
->dev
, "no platform data?\n");
701 /* don't exceed max specified SPI CLK frequency */
702 if (spi
->max_speed_hz
> MAX_SPI_FREQ_HZ
) {
703 dev_dbg(&spi
->dev
, "SPI CLK %d Hz?\n",spi
->max_speed_hz
);
707 spi
->bits_per_word
= 16;
708 err
= spi_setup(spi
);
710 dev_dbg(&spi
->dev
, "spi master doesn't support 16 bits/word\n");
714 ts
= kzalloc(sizeof(struct ad7877
), GFP_KERNEL
);
715 input_dev
= input_allocate_device();
716 if (!ts
|| !input_dev
) {
721 dev_set_drvdata(&spi
->dev
, ts
);
723 ts
->input
= input_dev
;
725 setup_timer(&ts
->timer
, ad7877_timer
, (unsigned long) ts
);
726 mutex_init(&ts
->mutex
);
727 spin_lock_init(&ts
->lock
);
729 ts
->model
= pdata
->model
? : 7877;
730 ts
->vref_delay_usecs
= pdata
->vref_delay_usecs
? : 100;
731 ts
->x_plate_ohms
= pdata
->x_plate_ohms
? : 400;
732 ts
->pressure_max
= pdata
->pressure_max
? : ~0;
734 ts
->stopacq_polarity
= pdata
->stopacq_polarity
;
735 ts
->first_conversion_delay
= pdata
->first_conversion_delay
;
736 ts
->acquisition_time
= pdata
->acquisition_time
;
737 ts
->averaging
= pdata
->averaging
;
738 ts
->pen_down_acc_interval
= pdata
->pen_down_acc_interval
;
740 snprintf(ts
->phys
, sizeof(ts
->phys
), "%s/input0", dev_name(&spi
->dev
));
742 input_dev
->name
= "AD7877 Touchscreen";
743 input_dev
->phys
= ts
->phys
;
744 input_dev
->dev
.parent
= &spi
->dev
;
746 __set_bit(EV_KEY
, input_dev
->evbit
);
747 __set_bit(BTN_TOUCH
, input_dev
->keybit
);
748 __set_bit(EV_ABS
, input_dev
->evbit
);
749 __set_bit(ABS_X
, input_dev
->absbit
);
750 __set_bit(ABS_Y
, input_dev
->absbit
);
751 __set_bit(ABS_PRESSURE
, input_dev
->absbit
);
753 input_set_abs_params(input_dev
, ABS_X
,
755 pdata
->x_max
? : MAX_12BIT
,
757 input_set_abs_params(input_dev
, ABS_Y
,
759 pdata
->y_max
? : MAX_12BIT
,
761 input_set_abs_params(input_dev
, ABS_PRESSURE
,
762 pdata
->pressure_min
, pdata
->pressure_max
, 0, 0);
764 ad7877_write(spi
, AD7877_REG_SEQ1
, AD7877_MM_SEQUENCE
);
766 verify
= ad7877_read(spi
, AD7877_REG_SEQ1
);
768 if (verify
!= AD7877_MM_SEQUENCE
){
769 dev_err(&spi
->dev
, "%s: Failed to probe %s\n",
770 dev_name(&spi
->dev
), input_dev
->name
);
776 ad7877_write(spi
, AD7877_REG_EXTWRITE
, AD7877_EXTW_GPIO_3_CONF
);
778 ad7877_setup_ts_def_msg(spi
, ts
);
780 /* Request AD7877 /DAV GPIO interrupt */
782 err
= request_threaded_irq(spi
->irq
, NULL
, ad7877_irq
,
783 IRQF_TRIGGER_FALLING
| IRQF_ONESHOT
,
784 spi
->dev
.driver
->name
, ts
);
786 dev_dbg(&spi
->dev
, "irq %d busy?\n", spi
->irq
);
790 err
= sysfs_create_group(&spi
->dev
.kobj
, &ad7877_attr_group
);
794 err
= input_register_device(input_dev
);
796 goto err_remove_attr_group
;
800 err_remove_attr_group
:
801 sysfs_remove_group(&spi
->dev
.kobj
, &ad7877_attr_group
);
803 free_irq(spi
->irq
, ts
);
805 input_free_device(input_dev
);
807 dev_set_drvdata(&spi
->dev
, NULL
);
811 static int __devexit
ad7877_remove(struct spi_device
*spi
)
813 struct ad7877
*ts
= dev_get_drvdata(&spi
->dev
);
815 sysfs_remove_group(&spi
->dev
.kobj
, &ad7877_attr_group
);
818 free_irq(ts
->spi
->irq
, ts
);
820 input_unregister_device(ts
->input
);
823 dev_dbg(&spi
->dev
, "unregistered touchscreen\n");
824 dev_set_drvdata(&spi
->dev
, NULL
);
830 static int ad7877_suspend(struct spi_device
*spi
, pm_message_t message
)
832 struct ad7877
*ts
= dev_get_drvdata(&spi
->dev
);
839 static int ad7877_resume(struct spi_device
*spi
)
841 struct ad7877
*ts
= dev_get_drvdata(&spi
->dev
);
848 #define ad7877_suspend NULL
849 #define ad7877_resume NULL
852 static struct spi_driver ad7877_driver
= {
855 .bus
= &spi_bus_type
,
856 .owner
= THIS_MODULE
,
858 .probe
= ad7877_probe
,
859 .remove
= __devexit_p(ad7877_remove
),
860 .suspend
= ad7877_suspend
,
861 .resume
= ad7877_resume
,
864 static int __init
ad7877_init(void)
866 return spi_register_driver(&ad7877_driver
);
868 module_init(ad7877_init
);
870 static void __exit
ad7877_exit(void)
872 spi_unregister_driver(&ad7877_driver
);
874 module_exit(ad7877_exit
);
876 MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
877 MODULE_DESCRIPTION("AD7877 touchscreen Driver");
878 MODULE_LICENSE("GPL");
879 MODULE_ALIAS("spi:ad7877");