David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 1 | /* |
| 2 | * ADS7846 based touchscreen and sensor driver |
| 3 | * |
| 4 | * Copyright (c) 2005 David Brownell |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 5 | * Copyright (c) 2006 Nokia Corporation |
| 6 | * Various changes: Imre Deak <imre.deak@nokia.com> |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 7 | * |
| 8 | * Using code from: |
| 9 | * - corgi_ts.c |
| 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 |
| 15 | * |
| 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. |
| 19 | */ |
David Brownell | 2c8dc07 | 2007-01-18 00:45:48 -0500 | [diff] [blame] | 20 | #include <linux/hwmon.h> |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 21 | #include <linux/init.h> |
David Brownell | 2c8dc07 | 2007-01-18 00:45:48 -0500 | [diff] [blame] | 22 | #include <linux/err.h> |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 23 | #include <linux/delay.h> |
| 24 | #include <linux/input.h> |
| 25 | #include <linux/interrupt.h> |
| 26 | #include <linux/slab.h> |
Eric Miao | 4d5975e | 2008-09-10 12:06:15 -0400 | [diff] [blame] | 27 | #include <linux/gpio.h> |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 28 | #include <linux/spi/spi.h> |
| 29 | #include <linux/spi/ads7846.h> |
Andrew Morton | 3ac8bf0 | 2006-03-26 01:37:33 -0800 | [diff] [blame] | 30 | #include <asm/irq.h> |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 31 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 32 | |
| 33 | /* |
David Brownell | 9084533 | 2006-05-25 18:44:20 -0700 | [diff] [blame] | 34 | * This code has been heavily tested on a Nokia 770, and lightly |
| 35 | * tested on other ads7846 devices (OSK/Mistral, Lubbock). |
David Brownell | bff0de5 | 2007-05-22 23:28:40 -0400 | [diff] [blame] | 36 | * TSC2046 is just newer ads7846 silicon. |
Nicolas Ferre | 969111e | 2007-02-28 23:51:03 -0500 | [diff] [blame] | 37 | * Support for ads7843 tested on Atmel at91sam926x-EK. |
| 38 | * Support for ads7845 has only been stubbed in. |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 39 | * |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 40 | * IRQ handling needs a workaround because of a shortcoming in handling |
| 41 | * edge triggered IRQs on some platforms like the OMAP1/2. These |
| 42 | * platforms don't handle the ARM lazy IRQ disabling properly, thus we |
| 43 | * have to maintain our own SW IRQ disabled status. This should be |
| 44 | * removed as soon as the affected platform's IRQ handling is fixed. |
| 45 | * |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 46 | * app note sbaa036 talks in more detail about accurate sampling... |
| 47 | * that ought to help in situations like LCDs inducing noise (which |
| 48 | * can also be helped by using synch signals) and more generally. |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 49 | * This driver tries to utilize the measures described in the app |
| 50 | * note. The strength of filtering can be set in the board-* specific |
| 51 | * files. |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 52 | */ |
| 53 | |
Imre Deak | 1936d59 | 2007-01-18 00:45:31 -0500 | [diff] [blame] | 54 | #define TS_POLL_DELAY (1 * 1000000) /* ns delay before the first sample */ |
| 55 | #define TS_POLL_PERIOD (5 * 1000000) /* ns delay between samples */ |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 56 | |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 57 | /* this driver doesn't aim at the peak continuous sample rate */ |
| 58 | #define SAMPLE_BITS (8 /*cmd*/ + 16 /*sample*/ + 2 /* before, after */) |
| 59 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 60 | struct ts_event { |
| 61 | /* For portability, we can't read 12 bit values using SPI (which |
| 62 | * would make the controller deliver them as native byteorder u16 |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 63 | * with msbs zeroed). Instead, we read them as two 8-bit values, |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 64 | * *** WHICH NEED BYTESWAPPING *** and range adjustment. |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 65 | */ |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 66 | u16 x; |
| 67 | u16 y; |
| 68 | u16 z1, z2; |
David Brownell | 2c8dc07 | 2007-01-18 00:45:48 -0500 | [diff] [blame] | 69 | int ignore; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 70 | }; |
| 71 | |
Dmitry Torokhov | e8f462d | 2008-10-09 00:52:23 -0400 | [diff] [blame] | 72 | /* |
| 73 | * We allocate this separately to avoid cache line sharing issues when |
| 74 | * driver is used with DMA-based SPI controllers (like atmel_spi) on |
| 75 | * systems where main memory is not DMA-coherent (most non-x86 boards). |
| 76 | */ |
| 77 | struct ads7846_packet { |
| 78 | u8 read_x, read_y, read_z1, read_z2, pwrdown; |
| 79 | u16 dummy; /* for the pwrdown read */ |
| 80 | struct ts_event tc; |
| 81 | }; |
| 82 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 83 | struct ads7846 { |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 84 | struct input_dev *input; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 85 | char phys[32]; |
| 86 | |
| 87 | struct spi_device *spi; |
David Brownell | 2c8dc07 | 2007-01-18 00:45:48 -0500 | [diff] [blame] | 88 | |
| 89 | #if defined(CONFIG_HWMON) || defined(CONFIG_HWMON_MODULE) |
Dmitry Torokhov | 8dd5165 | 2006-11-02 23:34:09 -0500 | [diff] [blame] | 90 | struct attribute_group *attr_group; |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 91 | struct device *hwmon; |
David Brownell | 2c8dc07 | 2007-01-18 00:45:48 -0500 | [diff] [blame] | 92 | #endif |
| 93 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 94 | u16 model; |
David Brownell | 7c6d0ee | 2008-04-02 00:43:01 -0400 | [diff] [blame] | 95 | u16 vref_mv; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 96 | u16 vref_delay_usecs; |
| 97 | u16 x_plate_ohms; |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 98 | u16 pressure_max; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 99 | |
Dmitry Torokhov | e8f462d | 2008-10-09 00:52:23 -0400 | [diff] [blame] | 100 | struct ads7846_packet *packet; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 101 | |
Semih Hazar | e4f4886 | 2007-07-18 00:35:56 -0400 | [diff] [blame] | 102 | struct spi_transfer xfer[18]; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 103 | struct spi_message msg[5]; |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 104 | struct spi_message *last_msg; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 105 | int msg_idx; |
| 106 | int read_cnt; |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 107 | int read_rep; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 108 | int last_read; |
| 109 | |
| 110 | u16 debounce_max; |
| 111 | u16 debounce_tol; |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 112 | u16 debounce_rep; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 113 | |
Semih Hazar | 1d25891 | 2007-07-18 00:36:04 -0400 | [diff] [blame] | 114 | u16 penirq_recheck_delay_usecs; |
| 115 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 116 | spinlock_t lock; |
Imre Deak | 1936d59 | 2007-01-18 00:45:31 -0500 | [diff] [blame] | 117 | struct hrtimer timer; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 118 | unsigned pendown:1; /* P: lock */ |
| 119 | unsigned pending:1; /* P: lock */ |
| 120 | // FIXME remove "irq_disabled" |
| 121 | unsigned irq_disabled:1; /* P: lock */ |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 122 | unsigned disabled:1; |
David Brownell | fbb38e3 | 2007-12-14 01:26:33 -0500 | [diff] [blame] | 123 | unsigned is_suspended:1; |
Imre Deak | c9e617a | 2006-04-11 23:44:05 -0400 | [diff] [blame] | 124 | |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 125 | int (*filter)(void *data, int data_idx, int *val); |
| 126 | void *filter_data; |
| 127 | void (*filter_cleanup)(void *data); |
Imre Deak | c9e617a | 2006-04-11 23:44:05 -0400 | [diff] [blame] | 128 | int (*get_pendown_state)(void); |
Eric Miao | 4d5975e | 2008-09-10 12:06:15 -0400 | [diff] [blame] | 129 | int gpio_pendown; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | /* leave chip selected when we're done, for quicker re-select? */ |
| 133 | #if 0 |
| 134 | #define CS_CHANGE(xfer) ((xfer).cs_change = 1) |
| 135 | #else |
| 136 | #define CS_CHANGE(xfer) ((xfer).cs_change = 0) |
| 137 | #endif |
| 138 | |
| 139 | /*--------------------------------------------------------------------------*/ |
| 140 | |
| 141 | /* The ADS7846 has touchscreen and other sensors. |
| 142 | * Earlier ads784x chips are somewhat compatible. |
| 143 | */ |
| 144 | #define ADS_START (1 << 7) |
| 145 | #define ADS_A2A1A0_d_y (1 << 4) /* differential */ |
| 146 | #define ADS_A2A1A0_d_z1 (3 << 4) /* differential */ |
| 147 | #define ADS_A2A1A0_d_z2 (4 << 4) /* differential */ |
| 148 | #define ADS_A2A1A0_d_x (5 << 4) /* differential */ |
| 149 | #define ADS_A2A1A0_temp0 (0 << 4) /* non-differential */ |
| 150 | #define ADS_A2A1A0_vbatt (2 << 4) /* non-differential */ |
| 151 | #define ADS_A2A1A0_vaux (6 << 4) /* non-differential */ |
| 152 | #define ADS_A2A1A0_temp1 (7 << 4) /* non-differential */ |
| 153 | #define ADS_8_BIT (1 << 3) |
| 154 | #define ADS_12_BIT (0 << 3) |
| 155 | #define ADS_SER (1 << 2) /* non-differential */ |
| 156 | #define ADS_DFR (0 << 2) /* differential */ |
| 157 | #define ADS_PD10_PDOWN (0 << 0) /* lowpower mode + penirq */ |
| 158 | #define ADS_PD10_ADC_ON (1 << 0) /* ADC on */ |
| 159 | #define ADS_PD10_REF_ON (2 << 0) /* vREF on + penirq */ |
| 160 | #define ADS_PD10_ALL_ON (3 << 0) /* ADC + vREF on */ |
| 161 | |
| 162 | #define MAX_12BIT ((1<<12)-1) |
| 163 | |
| 164 | /* leave ADC powered up (disables penirq) between differential samples */ |
Imre Deak | de2defd | 2007-01-18 00:45:21 -0500 | [diff] [blame] | 165 | #define READ_12BIT_DFR(x, adc, vref) (ADS_START | ADS_A2A1A0_d_ ## x \ |
| 166 | | ADS_12_BIT | ADS_DFR | \ |
| 167 | (adc ? ADS_PD10_ADC_ON : 0) | (vref ? ADS_PD10_REF_ON : 0)) |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 168 | |
Imre Deak | de2defd | 2007-01-18 00:45:21 -0500 | [diff] [blame] | 169 | #define READ_Y(vref) (READ_12BIT_DFR(y, 1, vref)) |
| 170 | #define READ_Z1(vref) (READ_12BIT_DFR(z1, 1, vref)) |
| 171 | #define READ_Z2(vref) (READ_12BIT_DFR(z2, 1, vref)) |
Imre Deak | 53a0ef89 | 2006-04-11 23:41:49 -0400 | [diff] [blame] | 172 | |
Imre Deak | de2defd | 2007-01-18 00:45:21 -0500 | [diff] [blame] | 173 | #define READ_X(vref) (READ_12BIT_DFR(x, 1, vref)) |
| 174 | #define PWRDOWN (READ_12BIT_DFR(y, 0, 0)) /* LAST */ |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 175 | |
| 176 | /* single-ended samples need to first power up reference voltage; |
| 177 | * we leave both ADC and VREF powered |
| 178 | */ |
| 179 | #define READ_12BIT_SER(x) (ADS_START | ADS_A2A1A0_ ## x \ |
| 180 | | ADS_12_BIT | ADS_SER) |
| 181 | |
Imre Deak | de2defd | 2007-01-18 00:45:21 -0500 | [diff] [blame] | 182 | #define REF_ON (READ_12BIT_DFR(x, 1, 1)) |
| 183 | #define REF_OFF (READ_12BIT_DFR(y, 0, 0)) |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 184 | |
| 185 | /*--------------------------------------------------------------------------*/ |
| 186 | |
| 187 | /* |
| 188 | * Non-touchscreen sensors only use single-ended conversions. |
David Brownell | 2c8dc07 | 2007-01-18 00:45:48 -0500 | [diff] [blame] | 189 | * The range is GND..vREF. The ads7843 and ads7835 must use external vREF; |
| 190 | * ads7846 lets that pin be unconnected, to use internal vREF. |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 191 | */ |
| 192 | |
| 193 | struct ser_req { |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 194 | u8 ref_on; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 195 | u8 command; |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 196 | u8 ref_off; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 197 | u16 scratch; |
| 198 | __be16 sample; |
| 199 | struct spi_message msg; |
| 200 | struct spi_transfer xfer[6]; |
| 201 | }; |
| 202 | |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 203 | static void ads7846_enable(struct ads7846 *ts); |
| 204 | static void ads7846_disable(struct ads7846 *ts); |
| 205 | |
Imre Deak | c9e617a | 2006-04-11 23:44:05 -0400 | [diff] [blame] | 206 | static int device_suspended(struct device *dev) |
| 207 | { |
| 208 | struct ads7846 *ts = dev_get_drvdata(dev); |
David Brownell | fbb38e3 | 2007-12-14 01:26:33 -0500 | [diff] [blame] | 209 | return ts->is_suspended || ts->disabled; |
Imre Deak | c9e617a | 2006-04-11 23:44:05 -0400 | [diff] [blame] | 210 | } |
| 211 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 212 | static int ads7846_read12_ser(struct device *dev, unsigned command) |
| 213 | { |
| 214 | struct spi_device *spi = to_spi_device(dev); |
| 215 | struct ads7846 *ts = dev_get_drvdata(dev); |
Christoph Lameter | e94b176 | 2006-12-06 20:33:17 -0800 | [diff] [blame] | 216 | struct ser_req *req = kzalloc(sizeof *req, GFP_KERNEL); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 217 | int status; |
David Brownell | 2c8dc07 | 2007-01-18 00:45:48 -0500 | [diff] [blame] | 218 | int use_internal; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 219 | |
| 220 | if (!req) |
| 221 | return -ENOMEM; |
| 222 | |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 223 | spi_message_init(&req->msg); |
Vitaly Wool | 8275c64 | 2006-01-08 13:34:28 -0800 | [diff] [blame] | 224 | |
David Brownell | 2c8dc07 | 2007-01-18 00:45:48 -0500 | [diff] [blame] | 225 | /* FIXME boards with ads7846 might use external vref instead ... */ |
| 226 | use_internal = (ts->model == 7846); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 227 | |
David Brownell | 2c8dc07 | 2007-01-18 00:45:48 -0500 | [diff] [blame] | 228 | /* maybe turn on internal vREF, and let it settle */ |
| 229 | if (use_internal) { |
| 230 | req->ref_on = REF_ON; |
| 231 | req->xfer[0].tx_buf = &req->ref_on; |
| 232 | req->xfer[0].len = 1; |
| 233 | spi_message_add_tail(&req->xfer[0], &req->msg); |
| 234 | |
| 235 | req->xfer[1].rx_buf = &req->scratch; |
| 236 | req->xfer[1].len = 2; |
| 237 | |
| 238 | /* for 1uF, settle for 800 usec; no cap, 100 usec. */ |
| 239 | req->xfer[1].delay_usecs = ts->vref_delay_usecs; |
| 240 | spi_message_add_tail(&req->xfer[1], &req->msg); |
| 241 | } |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 242 | |
| 243 | /* take sample */ |
| 244 | req->command = (u8) command; |
| 245 | req->xfer[2].tx_buf = &req->command; |
| 246 | req->xfer[2].len = 1; |
David Brownell | 2c8dc07 | 2007-01-18 00:45:48 -0500 | [diff] [blame] | 247 | spi_message_add_tail(&req->xfer[2], &req->msg); |
| 248 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 249 | req->xfer[3].rx_buf = &req->sample; |
| 250 | req->xfer[3].len = 2; |
David Brownell | 2c8dc07 | 2007-01-18 00:45:48 -0500 | [diff] [blame] | 251 | spi_message_add_tail(&req->xfer[3], &req->msg); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 252 | |
| 253 | /* REVISIT: take a few more samples, and compare ... */ |
| 254 | |
Nicolas Ferre | 969111e | 2007-02-28 23:51:03 -0500 | [diff] [blame] | 255 | /* converter in low power mode & enable PENIRQ */ |
| 256 | req->ref_off = PWRDOWN; |
| 257 | req->xfer[4].tx_buf = &req->ref_off; |
| 258 | req->xfer[4].len = 1; |
| 259 | spi_message_add_tail(&req->xfer[4], &req->msg); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 260 | |
Nicolas Ferre | 969111e | 2007-02-28 23:51:03 -0500 | [diff] [blame] | 261 | req->xfer[5].rx_buf = &req->scratch; |
| 262 | req->xfer[5].len = 2; |
| 263 | CS_CHANGE(req->xfer[5]); |
| 264 | spi_message_add_tail(&req->xfer[5], &req->msg); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 265 | |
Imre Deak | c9e617a | 2006-04-11 23:44:05 -0400 | [diff] [blame] | 266 | ts->irq_disabled = 1; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 267 | disable_irq(spi->irq); |
| 268 | status = spi_sync(spi, &req->msg); |
Imre Deak | c9e617a | 2006-04-11 23:44:05 -0400 | [diff] [blame] | 269 | ts->irq_disabled = 0; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 270 | enable_irq(spi->irq); |
| 271 | |
Marc Pignat | c24b260 | 2007-12-04 23:45:11 -0800 | [diff] [blame] | 272 | if (status == 0) { |
| 273 | /* on-wire is a must-ignore bit, a BE12 value, then padding */ |
David Brownell | 7c6d0ee | 2008-04-02 00:43:01 -0400 | [diff] [blame] | 274 | status = be16_to_cpu(req->sample); |
| 275 | status = status >> 3; |
| 276 | status &= 0x0fff; |
Marc Pignat | c24b260 | 2007-12-04 23:45:11 -0800 | [diff] [blame] | 277 | } |
David Brownell | 9084533 | 2006-05-25 18:44:20 -0700 | [diff] [blame] | 278 | |
| 279 | kfree(req); |
David Brownell | 7c6d0ee | 2008-04-02 00:43:01 -0400 | [diff] [blame] | 280 | return status; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 281 | } |
| 282 | |
David Brownell | 2c8dc07 | 2007-01-18 00:45:48 -0500 | [diff] [blame] | 283 | #if defined(CONFIG_HWMON) || defined(CONFIG_HWMON_MODULE) |
| 284 | |
| 285 | #define SHOW(name, var, adjust) static ssize_t \ |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 286 | name ## _show(struct device *dev, struct device_attribute *attr, char *buf) \ |
| 287 | { \ |
David Brownell | 2c8dc07 | 2007-01-18 00:45:48 -0500 | [diff] [blame] | 288 | struct ads7846 *ts = dev_get_drvdata(dev); \ |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 289 | ssize_t v = ads7846_read12_ser(dev, \ |
David Brownell | 2c8dc07 | 2007-01-18 00:45:48 -0500 | [diff] [blame] | 290 | READ_12BIT_SER(var) | ADS_PD10_ALL_ON); \ |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 291 | if (v < 0) \ |
| 292 | return v; \ |
David Brownell | 2c8dc07 | 2007-01-18 00:45:48 -0500 | [diff] [blame] | 293 | return sprintf(buf, "%u\n", adjust(ts, v)); \ |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 294 | } \ |
| 295 | static DEVICE_ATTR(name, S_IRUGO, name ## _show, NULL); |
| 296 | |
David Brownell | 2c8dc07 | 2007-01-18 00:45:48 -0500 | [diff] [blame] | 297 | |
| 298 | /* Sysfs conventions report temperatures in millidegrees Celcius. |
| 299 | * ADS7846 could use the low-accuracy two-sample scheme, but can't do the high |
| 300 | * accuracy scheme without calibration data. For now we won't try either; |
| 301 | * userspace sees raw sensor values, and must scale/calibrate appropriately. |
| 302 | */ |
| 303 | static inline unsigned null_adjust(struct ads7846 *ts, ssize_t v) |
| 304 | { |
| 305 | return v; |
| 306 | } |
| 307 | |
| 308 | SHOW(temp0, temp0, null_adjust) /* temp1_input */ |
| 309 | SHOW(temp1, temp1, null_adjust) /* temp2_input */ |
| 310 | |
| 311 | |
| 312 | /* sysfs conventions report voltages in millivolts. We can convert voltages |
| 313 | * if we know vREF. userspace may need to scale vAUX to match the board's |
| 314 | * external resistors; we assume that vBATT only uses the internal ones. |
| 315 | */ |
| 316 | static inline unsigned vaux_adjust(struct ads7846 *ts, ssize_t v) |
| 317 | { |
| 318 | unsigned retval = v; |
| 319 | |
| 320 | /* external resistors may scale vAUX into 0..vREF */ |
David Brownell | 7c6d0ee | 2008-04-02 00:43:01 -0400 | [diff] [blame] | 321 | retval *= ts->vref_mv; |
David Brownell | 2c8dc07 | 2007-01-18 00:45:48 -0500 | [diff] [blame] | 322 | retval = retval >> 12; |
| 323 | return retval; |
| 324 | } |
| 325 | |
| 326 | static inline unsigned vbatt_adjust(struct ads7846 *ts, ssize_t v) |
| 327 | { |
| 328 | unsigned retval = vaux_adjust(ts, v); |
| 329 | |
| 330 | /* ads7846 has a resistor ladder to scale this signal down */ |
| 331 | if (ts->model == 7846) |
| 332 | retval *= 4; |
| 333 | return retval; |
| 334 | } |
| 335 | |
| 336 | SHOW(in0_input, vaux, vaux_adjust) |
| 337 | SHOW(in1_input, vbatt, vbatt_adjust) |
| 338 | |
| 339 | |
| 340 | static struct attribute *ads7846_attributes[] = { |
| 341 | &dev_attr_temp0.attr, |
| 342 | &dev_attr_temp1.attr, |
| 343 | &dev_attr_in0_input.attr, |
| 344 | &dev_attr_in1_input.attr, |
| 345 | NULL, |
| 346 | }; |
| 347 | |
| 348 | static struct attribute_group ads7846_attr_group = { |
| 349 | .attrs = ads7846_attributes, |
| 350 | }; |
| 351 | |
| 352 | static struct attribute *ads7843_attributes[] = { |
| 353 | &dev_attr_in0_input.attr, |
| 354 | &dev_attr_in1_input.attr, |
| 355 | NULL, |
| 356 | }; |
| 357 | |
| 358 | static struct attribute_group ads7843_attr_group = { |
| 359 | .attrs = ads7843_attributes, |
| 360 | }; |
| 361 | |
| 362 | static struct attribute *ads7845_attributes[] = { |
| 363 | &dev_attr_in0_input.attr, |
| 364 | NULL, |
| 365 | }; |
| 366 | |
| 367 | static struct attribute_group ads7845_attr_group = { |
| 368 | .attrs = ads7845_attributes, |
| 369 | }; |
| 370 | |
| 371 | static int ads784x_hwmon_register(struct spi_device *spi, struct ads7846 *ts) |
| 372 | { |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 373 | struct device *hwmon; |
David Brownell | 2c8dc07 | 2007-01-18 00:45:48 -0500 | [diff] [blame] | 374 | int err; |
| 375 | |
| 376 | /* hwmon sensors need a reference voltage */ |
| 377 | switch (ts->model) { |
| 378 | case 7846: |
David Brownell | 7c6d0ee | 2008-04-02 00:43:01 -0400 | [diff] [blame] | 379 | if (!ts->vref_mv) { |
David Brownell | 2c8dc07 | 2007-01-18 00:45:48 -0500 | [diff] [blame] | 380 | dev_dbg(&spi->dev, "assuming 2.5V internal vREF\n"); |
David Brownell | 7c6d0ee | 2008-04-02 00:43:01 -0400 | [diff] [blame] | 381 | ts->vref_mv = 2500; |
David Brownell | 2c8dc07 | 2007-01-18 00:45:48 -0500 | [diff] [blame] | 382 | } |
| 383 | break; |
| 384 | case 7845: |
| 385 | case 7843: |
David Brownell | 7c6d0ee | 2008-04-02 00:43:01 -0400 | [diff] [blame] | 386 | if (!ts->vref_mv) { |
David Brownell | 2c8dc07 | 2007-01-18 00:45:48 -0500 | [diff] [blame] | 387 | dev_warn(&spi->dev, |
| 388 | "external vREF for ADS%d not specified\n", |
| 389 | ts->model); |
| 390 | return 0; |
| 391 | } |
| 392 | break; |
| 393 | } |
| 394 | |
| 395 | /* different chips have different sensor groups */ |
| 396 | switch (ts->model) { |
| 397 | case 7846: |
| 398 | ts->attr_group = &ads7846_attr_group; |
| 399 | break; |
| 400 | case 7845: |
| 401 | ts->attr_group = &ads7845_attr_group; |
| 402 | break; |
| 403 | case 7843: |
| 404 | ts->attr_group = &ads7843_attr_group; |
| 405 | break; |
| 406 | default: |
| 407 | dev_dbg(&spi->dev, "ADS%d not recognized\n", ts->model); |
| 408 | return 0; |
| 409 | } |
| 410 | |
| 411 | err = sysfs_create_group(&spi->dev.kobj, ts->attr_group); |
| 412 | if (err) |
| 413 | return err; |
| 414 | |
| 415 | hwmon = hwmon_device_register(&spi->dev); |
| 416 | if (IS_ERR(hwmon)) { |
| 417 | sysfs_remove_group(&spi->dev.kobj, ts->attr_group); |
| 418 | return PTR_ERR(hwmon); |
| 419 | } |
| 420 | |
| 421 | ts->hwmon = hwmon; |
| 422 | return 0; |
| 423 | } |
| 424 | |
| 425 | static void ads784x_hwmon_unregister(struct spi_device *spi, |
| 426 | struct ads7846 *ts) |
| 427 | { |
| 428 | if (ts->hwmon) { |
| 429 | sysfs_remove_group(&spi->dev.kobj, ts->attr_group); |
| 430 | hwmon_device_unregister(ts->hwmon); |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | #else |
| 435 | static inline int ads784x_hwmon_register(struct spi_device *spi, |
| 436 | struct ads7846 *ts) |
| 437 | { |
| 438 | return 0; |
| 439 | } |
| 440 | |
| 441 | static inline void ads784x_hwmon_unregister(struct spi_device *spi, |
| 442 | struct ads7846 *ts) |
| 443 | { |
| 444 | } |
| 445 | #endif |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 446 | |
Imre Deak | 438f2a7 | 2006-04-11 23:41:32 -0400 | [diff] [blame] | 447 | static int is_pen_down(struct device *dev) |
| 448 | { |
David Brownell | 2c8dc07 | 2007-01-18 00:45:48 -0500 | [diff] [blame] | 449 | struct ads7846 *ts = dev_get_drvdata(dev); |
Imre Deak | 438f2a7 | 2006-04-11 23:41:32 -0400 | [diff] [blame] | 450 | |
| 451 | return ts->pendown; |
| 452 | } |
| 453 | |
| 454 | static ssize_t ads7846_pen_down_show(struct device *dev, |
| 455 | struct device_attribute *attr, char *buf) |
| 456 | { |
| 457 | return sprintf(buf, "%u\n", is_pen_down(dev)); |
| 458 | } |
| 459 | |
| 460 | static DEVICE_ATTR(pen_down, S_IRUGO, ads7846_pen_down_show, NULL); |
| 461 | |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 462 | static ssize_t ads7846_disable_show(struct device *dev, |
| 463 | struct device_attribute *attr, char *buf) |
| 464 | { |
| 465 | struct ads7846 *ts = dev_get_drvdata(dev); |
| 466 | |
| 467 | return sprintf(buf, "%u\n", ts->disabled); |
| 468 | } |
| 469 | |
| 470 | static ssize_t ads7846_disable_store(struct device *dev, |
| 471 | struct device_attribute *attr, |
| 472 | const char *buf, size_t count) |
| 473 | { |
| 474 | struct ads7846 *ts = dev_get_drvdata(dev); |
Harvey Harrison | 3a0c58d | 2008-12-23 04:09:28 -0500 | [diff] [blame] | 475 | unsigned long i; |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 476 | |
Joe Rouvier | 160f1fe | 2008-08-10 00:29:25 -0400 | [diff] [blame] | 477 | if (strict_strtoul(buf, 10, &i)) |
| 478 | return -EINVAL; |
| 479 | |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 480 | spin_lock_irq(&ts->lock); |
| 481 | |
| 482 | if (i) |
| 483 | ads7846_disable(ts); |
| 484 | else |
| 485 | ads7846_enable(ts); |
| 486 | |
| 487 | spin_unlock_irq(&ts->lock); |
| 488 | |
| 489 | return count; |
| 490 | } |
| 491 | |
| 492 | static DEVICE_ATTR(disable, 0664, ads7846_disable_show, ads7846_disable_store); |
| 493 | |
David Brownell | 2c8dc07 | 2007-01-18 00:45:48 -0500 | [diff] [blame] | 494 | static struct attribute *ads784x_attributes[] = { |
Dmitry Torokhov | 8dd5165 | 2006-11-02 23:34:09 -0500 | [diff] [blame] | 495 | &dev_attr_pen_down.attr, |
| 496 | &dev_attr_disable.attr, |
| 497 | NULL, |
| 498 | }; |
| 499 | |
David Brownell | 2c8dc07 | 2007-01-18 00:45:48 -0500 | [diff] [blame] | 500 | static struct attribute_group ads784x_attr_group = { |
| 501 | .attrs = ads784x_attributes, |
Dmitry Torokhov | 8dd5165 | 2006-11-02 23:34:09 -0500 | [diff] [blame] | 502 | }; |
| 503 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 504 | /*--------------------------------------------------------------------------*/ |
| 505 | |
Eric Miao | 4d5975e | 2008-09-10 12:06:15 -0400 | [diff] [blame] | 506 | static int get_pendown_state(struct ads7846 *ts) |
| 507 | { |
| 508 | if (ts->get_pendown_state) |
| 509 | return ts->get_pendown_state(); |
| 510 | |
| 511 | return !gpio_get_value(ts->gpio_pendown); |
| 512 | } |
| 513 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 514 | /* |
| 515 | * PENIRQ only kicks the timer. The timer only reissues the SPI transfer, |
| 516 | * to retrieve touchscreen status. |
| 517 | * |
| 518 | * The SPI transfer completion callback does the real work. It reports |
| 519 | * touchscreen events and reactivates the timer (or IRQ) as appropriate. |
| 520 | */ |
| 521 | |
| 522 | static void ads7846_rx(void *ads) |
| 523 | { |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 524 | struct ads7846 *ts = ads; |
Dmitry Torokhov | e8f462d | 2008-10-09 00:52:23 -0400 | [diff] [blame] | 525 | struct ads7846_packet *packet = ts->packet; |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 526 | unsigned Rt; |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 527 | u16 x, y, z1, z2; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 528 | |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 529 | /* ads7846_rx_val() did in-place conversion (including byteswap) from |
| 530 | * on-the-wire format as part of debouncing to get stable readings. |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 531 | */ |
Dmitry Torokhov | e8f462d | 2008-10-09 00:52:23 -0400 | [diff] [blame] | 532 | x = packet->tc.x; |
| 533 | y = packet->tc.y; |
| 534 | z1 = packet->tc.z1; |
| 535 | z2 = packet->tc.z2; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 536 | |
| 537 | /* range filtering */ |
| 538 | if (x == MAX_12BIT) |
| 539 | x = 0; |
| 540 | |
Hans-Christian Egtvedt | 9460b65 | 2008-07-23 14:38:27 -0400 | [diff] [blame] | 541 | if (ts->model == 7843) { |
| 542 | Rt = ts->pressure_max / 2; |
| 543 | } else if (likely(x && z1)) { |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 544 | /* compute touch pressure resistance using equation #2 */ |
| 545 | Rt = z2; |
| 546 | Rt -= z1; |
| 547 | Rt *= x; |
| 548 | Rt *= ts->x_plate_ohms; |
| 549 | Rt /= z1; |
| 550 | Rt = (Rt + 2047) >> 12; |
Hans-Christian Egtvedt | 9460b65 | 2008-07-23 14:38:27 -0400 | [diff] [blame] | 551 | } else { |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 552 | Rt = 0; |
Hans-Christian Egtvedt | 9460b65 | 2008-07-23 14:38:27 -0400 | [diff] [blame] | 553 | } |
Nicolas Ferre | 969111e | 2007-02-28 23:51:03 -0500 | [diff] [blame] | 554 | |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 555 | /* Sample found inconsistent by debouncing or pressure is beyond |
Imre Deak | 1936d59 | 2007-01-18 00:45:31 -0500 | [diff] [blame] | 556 | * the maximum. Don't report it to user space, repeat at least |
| 557 | * once more the measurement |
| 558 | */ |
Dmitry Torokhov | e8f462d | 2008-10-09 00:52:23 -0400 | [diff] [blame] | 559 | if (packet->tc.ignore || Rt > ts->pressure_max) { |
Imre Deak | 15e3589 | 2007-01-18 00:45:43 -0500 | [diff] [blame] | 560 | #ifdef VERBOSE |
| 561 | pr_debug("%s: ignored %d pressure %d\n", |
Kay Sievers | a6c2490 | 2008-10-30 00:07:50 -0400 | [diff] [blame] | 562 | dev_name(&ts->spi->dev), packet->tc.ignore, Rt); |
Imre Deak | 15e3589 | 2007-01-18 00:45:43 -0500 | [diff] [blame] | 563 | #endif |
Imre Deak | 1936d59 | 2007-01-18 00:45:31 -0500 | [diff] [blame] | 564 | hrtimer_start(&ts->timer, ktime_set(0, TS_POLL_PERIOD), |
Thomas Gleixner | c9cb2e3 | 2007-02-16 01:27:49 -0800 | [diff] [blame] | 565 | HRTIMER_MODE_REL); |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 566 | return; |
| 567 | } |
| 568 | |
Semih Hazar | 1d25891 | 2007-07-18 00:36:04 -0400 | [diff] [blame] | 569 | /* Maybe check the pendown state before reporting. This discards |
| 570 | * false readings when the pen is lifted. |
| 571 | */ |
| 572 | if (ts->penirq_recheck_delay_usecs) { |
| 573 | udelay(ts->penirq_recheck_delay_usecs); |
Eric Miao | 4d5975e | 2008-09-10 12:06:15 -0400 | [diff] [blame] | 574 | if (!get_pendown_state(ts)) |
Semih Hazar | 1d25891 | 2007-07-18 00:36:04 -0400 | [diff] [blame] | 575 | Rt = 0; |
| 576 | } |
| 577 | |
Imre Deak | 15e3589 | 2007-01-18 00:45:43 -0500 | [diff] [blame] | 578 | /* NOTE: We can't rely on the pressure to determine the pen down |
| 579 | * state, even this controller has a pressure sensor. The pressure |
| 580 | * value can fluctuate for quite a while after lifting the pen and |
| 581 | * in some cases may not even settle at the expected value. |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 582 | * |
Imre Deak | 15e3589 | 2007-01-18 00:45:43 -0500 | [diff] [blame] | 583 | * The only safe way to check for the pen up condition is in the |
| 584 | * timer by reading the pen signal state (it's a GPIO _and_ IRQ). |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 585 | */ |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 586 | if (Rt) { |
Imre Deak | 15e3589 | 2007-01-18 00:45:43 -0500 | [diff] [blame] | 587 | struct input_dev *input = ts->input; |
Imre Deak | ae82d5a | 2006-04-26 00:12:14 -0400 | [diff] [blame] | 588 | |
Imre Deak | 15e3589 | 2007-01-18 00:45:43 -0500 | [diff] [blame] | 589 | if (!ts->pendown) { |
| 590 | input_report_key(input, BTN_TOUCH, 1); |
| 591 | ts->pendown = 1; |
| 592 | #ifdef VERBOSE |
| 593 | dev_dbg(&ts->spi->dev, "DOWN\n"); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 594 | #endif |
Imre Deak | 15e3589 | 2007-01-18 00:45:43 -0500 | [diff] [blame] | 595 | } |
| 596 | input_report_abs(input, ABS_X, x); |
| 597 | input_report_abs(input, ABS_Y, y); |
| 598 | input_report_abs(input, ABS_PRESSURE, Rt); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 599 | |
Imre Deak | 15e3589 | 2007-01-18 00:45:43 -0500 | [diff] [blame] | 600 | input_sync(input); |
| 601 | #ifdef VERBOSE |
| 602 | dev_dbg(&ts->spi->dev, "%4d/%4d/%4d\n", x, y, Rt); |
| 603 | #endif |
| 604 | } |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 605 | |
Thomas Gleixner | c9cb2e3 | 2007-02-16 01:27:49 -0800 | [diff] [blame] | 606 | hrtimer_start(&ts->timer, ktime_set(0, TS_POLL_PERIOD), |
| 607 | HRTIMER_MODE_REL); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 608 | } |
| 609 | |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 610 | static int ads7846_debounce(void *ads, int data_idx, int *val) |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 611 | { |
| 612 | struct ads7846 *ts = ads; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 613 | |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 614 | if (!ts->read_cnt || (abs(ts->last_read - *val) > ts->debounce_tol)) { |
| 615 | /* Start over collecting consistent readings. */ |
| 616 | ts->read_rep = 0; |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 617 | /* Repeat it, if this was the first read or the read |
| 618 | * wasn't consistent enough. */ |
| 619 | if (ts->read_cnt < ts->debounce_max) { |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 620 | ts->last_read = *val; |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 621 | ts->read_cnt++; |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 622 | return ADS7846_FILTER_REPEAT; |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 623 | } else { |
| 624 | /* Maximum number of debouncing reached and still |
| 625 | * not enough number of consistent readings. Abort |
| 626 | * the whole sample, repeat it in the next sampling |
| 627 | * period. |
| 628 | */ |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 629 | ts->read_cnt = 0; |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 630 | return ADS7846_FILTER_IGNORE; |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 631 | } |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 632 | } else { |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 633 | if (++ts->read_rep > ts->debounce_rep) { |
| 634 | /* Got a good reading for this coordinate, |
| 635 | * go for the next one. */ |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 636 | ts->read_cnt = 0; |
| 637 | ts->read_rep = 0; |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 638 | return ADS7846_FILTER_OK; |
| 639 | } else { |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 640 | /* Read more values that are consistent. */ |
| 641 | ts->read_cnt++; |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 642 | return ADS7846_FILTER_REPEAT; |
| 643 | } |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | static int ads7846_no_filter(void *ads, int data_idx, int *val) |
| 648 | { |
| 649 | return ADS7846_FILTER_OK; |
| 650 | } |
| 651 | |
| 652 | static void ads7846_rx_val(void *ads) |
| 653 | { |
| 654 | struct ads7846 *ts = ads; |
Dmitry Torokhov | e8f462d | 2008-10-09 00:52:23 -0400 | [diff] [blame] | 655 | struct ads7846_packet *packet = ts->packet; |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 656 | struct spi_message *m; |
| 657 | struct spi_transfer *t; |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 658 | int val; |
| 659 | int action; |
| 660 | int status; |
| 661 | |
| 662 | m = &ts->msg[ts->msg_idx]; |
| 663 | t = list_entry(m->transfers.prev, struct spi_transfer, transfer_list); |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 664 | |
| 665 | /* adjust: on-wire is a must-ignore bit, a BE12 value, then padding; |
| 666 | * built from two 8 bit values written msb-first. |
| 667 | */ |
Harvey Harrison | 494f685 | 2008-07-23 14:16:19 -0400 | [diff] [blame] | 668 | val = be16_to_cpup((__be16 *)t->rx_buf) >> 3; |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 669 | |
| 670 | action = ts->filter(ts->filter_data, ts->msg_idx, &val); |
| 671 | switch (action) { |
| 672 | case ADS7846_FILTER_REPEAT: |
| 673 | break; |
| 674 | case ADS7846_FILTER_IGNORE: |
Dmitry Torokhov | e8f462d | 2008-10-09 00:52:23 -0400 | [diff] [blame] | 675 | packet->tc.ignore = 1; |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 676 | /* Last message will contain ads7846_rx() as the |
| 677 | * completion function. |
| 678 | */ |
| 679 | m = ts->last_msg; |
| 680 | break; |
| 681 | case ADS7846_FILTER_OK: |
Harvey Harrison | 494f685 | 2008-07-23 14:16:19 -0400 | [diff] [blame] | 682 | *(u16 *)t->rx_buf = val; |
Dmitry Torokhov | e8f462d | 2008-10-09 00:52:23 -0400 | [diff] [blame] | 683 | packet->tc.ignore = 0; |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 684 | m = &ts->msg[++ts->msg_idx]; |
| 685 | break; |
| 686 | default: |
| 687 | BUG(); |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 688 | } |
| 689 | status = spi_async(ts->spi, m); |
| 690 | if (status) |
| 691 | dev_err(&ts->spi->dev, "spi_async --> %d\n", |
| 692 | status); |
| 693 | } |
| 694 | |
Thomas Gleixner | c9cb2e3 | 2007-02-16 01:27:49 -0800 | [diff] [blame] | 695 | static enum hrtimer_restart ads7846_timer(struct hrtimer *handle) |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 696 | { |
Imre Deak | 1936d59 | 2007-01-18 00:45:31 -0500 | [diff] [blame] | 697 | struct ads7846 *ts = container_of(handle, struct ads7846, timer); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 698 | int status = 0; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 699 | |
Peter Zijlstra | ca10949 | 2008-11-25 12:43:51 +0100 | [diff] [blame] | 700 | spin_lock(&ts->lock); |
Imre Deak | c9e617a | 2006-04-11 23:44:05 -0400 | [diff] [blame] | 701 | |
Eric Miao | 4d5975e | 2008-09-10 12:06:15 -0400 | [diff] [blame] | 702 | if (unlikely(!get_pendown_state(ts) || |
Imre Deak | 15e3589 | 2007-01-18 00:45:43 -0500 | [diff] [blame] | 703 | device_suspended(&ts->spi->dev))) { |
| 704 | if (ts->pendown) { |
| 705 | struct input_dev *input = ts->input; |
| 706 | |
| 707 | input_report_key(input, BTN_TOUCH, 0); |
| 708 | input_report_abs(input, ABS_PRESSURE, 0); |
| 709 | input_sync(input); |
| 710 | |
| 711 | ts->pendown = 0; |
| 712 | #ifdef VERBOSE |
| 713 | dev_dbg(&ts->spi->dev, "UP\n"); |
| 714 | #endif |
| 715 | } |
| 716 | |
David Brownell | 9084533 | 2006-05-25 18:44:20 -0700 | [diff] [blame] | 717 | /* measurement cycle ended */ |
Imre Deak | c9e617a | 2006-04-11 23:44:05 -0400 | [diff] [blame] | 718 | if (!device_suspended(&ts->spi->dev)) { |
| 719 | ts->irq_disabled = 0; |
| 720 | enable_irq(ts->spi->irq); |
| 721 | } |
| 722 | ts->pending = 0; |
Imre Deak | c9e617a | 2006-04-11 23:44:05 -0400 | [diff] [blame] | 723 | } else { |
| 724 | /* pen is still down, continue with the measurement */ |
| 725 | ts->msg_idx = 0; |
| 726 | status = spi_async(ts->spi, &ts->msg[0]); |
| 727 | if (status) |
| 728 | dev_err(&ts->spi->dev, "spi_async --> %d\n", status); |
| 729 | } |
| 730 | |
Peter Zijlstra | ca10949 | 2008-11-25 12:43:51 +0100 | [diff] [blame] | 731 | spin_unlock(&ts->lock); |
Imre Deak | 1936d59 | 2007-01-18 00:45:31 -0500 | [diff] [blame] | 732 | return HRTIMER_NORESTART; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 733 | } |
| 734 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 735 | static irqreturn_t ads7846_irq(int irq, void *handle) |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 736 | { |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 737 | struct ads7846 *ts = handle; |
| 738 | unsigned long flags; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 739 | |
| 740 | spin_lock_irqsave(&ts->lock, flags); |
Eric Miao | 4d5975e | 2008-09-10 12:06:15 -0400 | [diff] [blame] | 741 | if (likely(get_pendown_state(ts))) { |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 742 | if (!ts->irq_disabled) { |
David Brownell | 9084533 | 2006-05-25 18:44:20 -0700 | [diff] [blame] | 743 | /* The ARM do_simple_IRQ() dispatcher doesn't act |
| 744 | * like the other dispatchers: it will report IRQs |
| 745 | * even after they've been disabled. We work around |
| 746 | * that here. (The "generic irq" framework may help...) |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 747 | */ |
| 748 | ts->irq_disabled = 1; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 749 | disable_irq(ts->spi->irq); |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 750 | ts->pending = 1; |
Imre Deak | 1936d59 | 2007-01-18 00:45:31 -0500 | [diff] [blame] | 751 | hrtimer_start(&ts->timer, ktime_set(0, TS_POLL_DELAY), |
Thomas Gleixner | c9cb2e3 | 2007-02-16 01:27:49 -0800 | [diff] [blame] | 752 | HRTIMER_MODE_REL); |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 753 | } |
| 754 | } |
| 755 | spin_unlock_irqrestore(&ts->lock, flags); |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 756 | |
| 757 | return IRQ_HANDLED; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | /*--------------------------------------------------------------------------*/ |
| 761 | |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 762 | /* Must be called with ts->lock held */ |
| 763 | static void ads7846_disable(struct ads7846 *ts) |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 764 | { |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 765 | if (ts->disabled) |
| 766 | return; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 767 | |
Imre Deak | c9e617a | 2006-04-11 23:44:05 -0400 | [diff] [blame] | 768 | ts->disabled = 1; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 769 | |
Imre Deak | c9e617a | 2006-04-11 23:44:05 -0400 | [diff] [blame] | 770 | /* are we waiting for IRQ, or polling? */ |
| 771 | if (!ts->pending) { |
| 772 | ts->irq_disabled = 1; |
| 773 | disable_irq(ts->spi->irq); |
| 774 | } else { |
| 775 | /* the timer will run at least once more, and |
| 776 | * leave everything in a clean state, IRQ disabled |
| 777 | */ |
| 778 | while (ts->pending) { |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 779 | spin_unlock_irq(&ts->lock); |
Juha Yrjola | c4febb9 | 2006-04-11 23:42:25 -0400 | [diff] [blame] | 780 | msleep(1); |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 781 | spin_lock_irq(&ts->lock); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 782 | } |
| 783 | } |
| 784 | |
| 785 | /* we know the chip's in lowpower mode since we always |
| 786 | * leave it that way after every request |
| 787 | */ |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | /* Must be called with ts->lock held */ |
| 791 | static void ads7846_enable(struct ads7846 *ts) |
| 792 | { |
| 793 | if (!ts->disabled) |
| 794 | return; |
| 795 | |
| 796 | ts->disabled = 0; |
| 797 | ts->irq_disabled = 0; |
| 798 | enable_irq(ts->spi->irq); |
| 799 | } |
| 800 | |
| 801 | static int ads7846_suspend(struct spi_device *spi, pm_message_t message) |
| 802 | { |
| 803 | struct ads7846 *ts = dev_get_drvdata(&spi->dev); |
| 804 | |
| 805 | spin_lock_irq(&ts->lock); |
| 806 | |
David Brownell | fbb38e3 | 2007-12-14 01:26:33 -0500 | [diff] [blame] | 807 | ts->is_suspended = 1; |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 808 | ads7846_disable(ts); |
| 809 | |
| 810 | spin_unlock_irq(&ts->lock); |
| 811 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 812 | return 0; |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 813 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 814 | } |
| 815 | |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 816 | static int ads7846_resume(struct spi_device *spi) |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 817 | { |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 818 | struct ads7846 *ts = dev_get_drvdata(&spi->dev); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 819 | |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 820 | spin_lock_irq(&ts->lock); |
| 821 | |
David Brownell | fbb38e3 | 2007-12-14 01:26:33 -0500 | [diff] [blame] | 822 | ts->is_suspended = 0; |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 823 | ads7846_enable(ts); |
| 824 | |
| 825 | spin_unlock_irq(&ts->lock); |
| 826 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 827 | return 0; |
| 828 | } |
| 829 | |
Eric Miao | 4d5975e | 2008-09-10 12:06:15 -0400 | [diff] [blame] | 830 | static int __devinit setup_pendown(struct spi_device *spi, struct ads7846 *ts) |
| 831 | { |
| 832 | struct ads7846_platform_data *pdata = spi->dev.platform_data; |
| 833 | int err; |
| 834 | |
| 835 | /* REVISIT when the irq can be triggered active-low, or if for some |
| 836 | * reason the touchscreen isn't hooked up, we don't need to access |
| 837 | * the pendown state. |
| 838 | */ |
| 839 | if (!pdata->get_pendown_state && !gpio_is_valid(pdata->gpio_pendown)) { |
| 840 | dev_err(&spi->dev, "no get_pendown_state nor gpio_pendown?\n"); |
| 841 | return -EINVAL; |
| 842 | } |
| 843 | |
| 844 | if (pdata->get_pendown_state) { |
| 845 | ts->get_pendown_state = pdata->get_pendown_state; |
| 846 | return 0; |
| 847 | } |
| 848 | |
| 849 | err = gpio_request(pdata->gpio_pendown, "ads7846_pendown"); |
| 850 | if (err) { |
| 851 | dev_err(&spi->dev, "failed to request pendown GPIO%d\n", |
| 852 | pdata->gpio_pendown); |
| 853 | return err; |
| 854 | } |
| 855 | |
| 856 | ts->gpio_pendown = pdata->gpio_pendown; |
| 857 | return 0; |
| 858 | } |
| 859 | |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 860 | static int __devinit ads7846_probe(struct spi_device *spi) |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 861 | { |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 862 | struct ads7846 *ts; |
Dmitry Torokhov | e8f462d | 2008-10-09 00:52:23 -0400 | [diff] [blame] | 863 | struct ads7846_packet *packet; |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 864 | struct input_dev *input_dev; |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 865 | struct ads7846_platform_data *pdata = spi->dev.platform_data; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 866 | struct spi_message *m; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 867 | struct spi_transfer *x; |
Imre Deak | de2defd | 2007-01-18 00:45:21 -0500 | [diff] [blame] | 868 | int vref; |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 869 | int err; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 870 | |
| 871 | if (!spi->irq) { |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 872 | dev_dbg(&spi->dev, "no IRQ?\n"); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 873 | return -ENODEV; |
| 874 | } |
| 875 | |
| 876 | if (!pdata) { |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 877 | dev_dbg(&spi->dev, "no platform data?\n"); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 878 | return -ENODEV; |
| 879 | } |
| 880 | |
| 881 | /* don't exceed max specified sample rate */ |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 882 | if (spi->max_speed_hz > (125000 * SAMPLE_BITS)) { |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 883 | dev_dbg(&spi->dev, "f(sample) %d KHz?\n", |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 884 | (spi->max_speed_hz/SAMPLE_BITS)/1000); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 885 | return -EINVAL; |
| 886 | } |
| 887 | |
David Brownell | 9084533 | 2006-05-25 18:44:20 -0700 | [diff] [blame] | 888 | /* We'd set TX wordsize 8 bits and RX wordsize to 13 bits ... except |
| 889 | * that even if the hardware can do that, the SPI controller driver |
| 890 | * may not. So we stick to very-portable 8 bit words, both RX and TX. |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 891 | */ |
David Brownell | 9084533 | 2006-05-25 18:44:20 -0700 | [diff] [blame] | 892 | spi->bits_per_word = 8; |
Semih Hazar | 230ffc8 | 2007-05-22 23:35:12 -0400 | [diff] [blame] | 893 | spi->mode = SPI_MODE_0; |
Imre Deak | 7937e86 | 2007-01-18 00:45:38 -0500 | [diff] [blame] | 894 | err = spi_setup(spi); |
| 895 | if (err < 0) |
| 896 | return err; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 897 | |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 898 | ts = kzalloc(sizeof(struct ads7846), GFP_KERNEL); |
Dmitry Torokhov | e8f462d | 2008-10-09 00:52:23 -0400 | [diff] [blame] | 899 | packet = kzalloc(sizeof(struct ads7846_packet), GFP_KERNEL); |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 900 | input_dev = input_allocate_device(); |
Dmitry Torokhov | e8f462d | 2008-10-09 00:52:23 -0400 | [diff] [blame] | 901 | if (!ts || !packet || !input_dev) { |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 902 | err = -ENOMEM; |
| 903 | goto err_free_mem; |
| 904 | } |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 905 | |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 906 | dev_set_drvdata(&spi->dev, ts); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 907 | |
Dmitry Torokhov | e8f462d | 2008-10-09 00:52:23 -0400 | [diff] [blame] | 908 | ts->packet = packet; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 909 | ts->spi = spi; |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 910 | ts->input = input_dev; |
David Brownell | 7c6d0ee | 2008-04-02 00:43:01 -0400 | [diff] [blame] | 911 | ts->vref_mv = pdata->vref_mv; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 912 | |
Thomas Gleixner | c9cb2e3 | 2007-02-16 01:27:49 -0800 | [diff] [blame] | 913 | hrtimer_init(&ts->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 914 | ts->timer.function = ads7846_timer; |
| 915 | |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 916 | spin_lock_init(&ts->lock); |
| 917 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 918 | ts->model = pdata->model ? : 7846; |
| 919 | ts->vref_delay_usecs = pdata->vref_delay_usecs ? : 100; |
| 920 | ts->x_plate_ohms = pdata->x_plate_ohms ? : 400; |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 921 | ts->pressure_max = pdata->pressure_max ? : ~0; |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 922 | |
| 923 | if (pdata->filter != NULL) { |
| 924 | if (pdata->filter_init != NULL) { |
| 925 | err = pdata->filter_init(pdata, &ts->filter_data); |
| 926 | if (err < 0) |
| 927 | goto err_free_mem; |
| 928 | } |
| 929 | ts->filter = pdata->filter; |
| 930 | ts->filter_cleanup = pdata->filter_cleanup; |
| 931 | } else if (pdata->debounce_max) { |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 932 | ts->debounce_max = pdata->debounce_max; |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 933 | if (ts->debounce_max < 2) |
| 934 | ts->debounce_max = 2; |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 935 | ts->debounce_tol = pdata->debounce_tol; |
| 936 | ts->debounce_rep = pdata->debounce_rep; |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 937 | ts->filter = ads7846_debounce; |
| 938 | ts->filter_data = ts; |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 939 | } else |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 940 | ts->filter = ads7846_no_filter; |
Eric Miao | 4d5975e | 2008-09-10 12:06:15 -0400 | [diff] [blame] | 941 | |
| 942 | err = setup_pendown(spi, ts); |
| 943 | if (err) |
| 944 | goto err_cleanup_filter; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 945 | |
Semih Hazar | 1d25891 | 2007-07-18 00:36:04 -0400 | [diff] [blame] | 946 | if (pdata->penirq_recheck_delay_usecs) |
| 947 | ts->penirq_recheck_delay_usecs = |
| 948 | pdata->penirq_recheck_delay_usecs; |
| 949 | |
Kay Sievers | a6c2490 | 2008-10-30 00:07:50 -0400 | [diff] [blame] | 950 | snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(&spi->dev)); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 951 | |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 952 | input_dev->name = "ADS784x Touchscreen"; |
| 953 | input_dev->phys = ts->phys; |
Dmitry Torokhov | a5394fb0 | 2007-04-12 01:35:14 -0400 | [diff] [blame] | 954 | input_dev->dev.parent = &spi->dev; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 955 | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 956 | input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); |
| 957 | input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 958 | input_set_abs_params(input_dev, ABS_X, |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 959 | pdata->x_min ? : 0, |
| 960 | pdata->x_max ? : MAX_12BIT, |
| 961 | 0, 0); |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 962 | input_set_abs_params(input_dev, ABS_Y, |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 963 | pdata->y_min ? : 0, |
| 964 | pdata->y_max ? : MAX_12BIT, |
| 965 | 0, 0); |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 966 | input_set_abs_params(input_dev, ABS_PRESSURE, |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 967 | pdata->pressure_min, pdata->pressure_max, 0, 0); |
| 968 | |
Imre Deak | de2defd | 2007-01-18 00:45:21 -0500 | [diff] [blame] | 969 | vref = pdata->keep_vref_on; |
| 970 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 971 | /* set up the transfers to read touchscreen state; this assumes we |
| 972 | * use formula #2 for pressure, not #3. |
| 973 | */ |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 974 | m = &ts->msg[0]; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 975 | x = ts->xfer; |
| 976 | |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 977 | spi_message_init(m); |
| 978 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 979 | /* y- still on; turn on only y+ (and ADC) */ |
Dmitry Torokhov | e8f462d | 2008-10-09 00:52:23 -0400 | [diff] [blame] | 980 | packet->read_y = READ_Y(vref); |
| 981 | x->tx_buf = &packet->read_y; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 982 | x->len = 1; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 983 | spi_message_add_tail(x, m); |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 984 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 985 | x++; |
Dmitry Torokhov | e8f462d | 2008-10-09 00:52:23 -0400 | [diff] [blame] | 986 | x->rx_buf = &packet->tc.y; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 987 | x->len = 2; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 988 | spi_message_add_tail(x, m); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 989 | |
Semih Hazar | e4f4886 | 2007-07-18 00:35:56 -0400 | [diff] [blame] | 990 | /* the first sample after switching drivers can be low quality; |
| 991 | * optionally discard it, using a second one after the signals |
| 992 | * have had enough time to stabilize. |
| 993 | */ |
| 994 | if (pdata->settle_delay_usecs) { |
| 995 | x->delay_usecs = pdata->settle_delay_usecs; |
| 996 | |
| 997 | x++; |
Dmitry Torokhov | e8f462d | 2008-10-09 00:52:23 -0400 | [diff] [blame] | 998 | x->tx_buf = &packet->read_y; |
Semih Hazar | e4f4886 | 2007-07-18 00:35:56 -0400 | [diff] [blame] | 999 | x->len = 1; |
| 1000 | spi_message_add_tail(x, m); |
| 1001 | |
| 1002 | x++; |
Dmitry Torokhov | e8f462d | 2008-10-09 00:52:23 -0400 | [diff] [blame] | 1003 | x->rx_buf = &packet->tc.y; |
Semih Hazar | e4f4886 | 2007-07-18 00:35:56 -0400 | [diff] [blame] | 1004 | x->len = 2; |
| 1005 | spi_message_add_tail(x, m); |
| 1006 | } |
| 1007 | |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 1008 | m->complete = ads7846_rx_val; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 1009 | m->context = ts; |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 1010 | |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 1011 | m++; |
| 1012 | spi_message_init(m); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 1013 | |
| 1014 | /* turn y- off, x+ on, then leave in lowpower */ |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 1015 | x++; |
Dmitry Torokhov | e8f462d | 2008-10-09 00:52:23 -0400 | [diff] [blame] | 1016 | packet->read_x = READ_X(vref); |
| 1017 | x->tx_buf = &packet->read_x; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 1018 | x->len = 1; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 1019 | spi_message_add_tail(x, m); |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 1020 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 1021 | x++; |
Dmitry Torokhov | e8f462d | 2008-10-09 00:52:23 -0400 | [diff] [blame] | 1022 | x->rx_buf = &packet->tc.x; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 1023 | x->len = 2; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 1024 | spi_message_add_tail(x, m); |
| 1025 | |
Semih Hazar | e4f4886 | 2007-07-18 00:35:56 -0400 | [diff] [blame] | 1026 | /* ... maybe discard first sample ... */ |
| 1027 | if (pdata->settle_delay_usecs) { |
| 1028 | x->delay_usecs = pdata->settle_delay_usecs; |
| 1029 | |
| 1030 | x++; |
Dmitry Torokhov | e8f462d | 2008-10-09 00:52:23 -0400 | [diff] [blame] | 1031 | x->tx_buf = &packet->read_x; |
Semih Hazar | e4f4886 | 2007-07-18 00:35:56 -0400 | [diff] [blame] | 1032 | x->len = 1; |
| 1033 | spi_message_add_tail(x, m); |
| 1034 | |
| 1035 | x++; |
Dmitry Torokhov | e8f462d | 2008-10-09 00:52:23 -0400 | [diff] [blame] | 1036 | x->rx_buf = &packet->tc.x; |
Semih Hazar | e4f4886 | 2007-07-18 00:35:56 -0400 | [diff] [blame] | 1037 | x->len = 2; |
| 1038 | spi_message_add_tail(x, m); |
| 1039 | } |
| 1040 | |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 1041 | m->complete = ads7846_rx_val; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 1042 | m->context = ts; |
| 1043 | |
| 1044 | /* turn y+ off, x- on; we'll use formula #2 */ |
| 1045 | if (ts->model == 7846) { |
| 1046 | m++; |
| 1047 | spi_message_init(m); |
| 1048 | |
| 1049 | x++; |
Dmitry Torokhov | e8f462d | 2008-10-09 00:52:23 -0400 | [diff] [blame] | 1050 | packet->read_z1 = READ_Z1(vref); |
| 1051 | x->tx_buf = &packet->read_z1; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 1052 | x->len = 1; |
| 1053 | spi_message_add_tail(x, m); |
| 1054 | |
| 1055 | x++; |
Dmitry Torokhov | e8f462d | 2008-10-09 00:52:23 -0400 | [diff] [blame] | 1056 | x->rx_buf = &packet->tc.z1; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 1057 | x->len = 2; |
| 1058 | spi_message_add_tail(x, m); |
| 1059 | |
Semih Hazar | e4f4886 | 2007-07-18 00:35:56 -0400 | [diff] [blame] | 1060 | /* ... maybe discard first sample ... */ |
| 1061 | if (pdata->settle_delay_usecs) { |
| 1062 | x->delay_usecs = pdata->settle_delay_usecs; |
| 1063 | |
| 1064 | x++; |
Dmitry Torokhov | e8f462d | 2008-10-09 00:52:23 -0400 | [diff] [blame] | 1065 | x->tx_buf = &packet->read_z1; |
Semih Hazar | e4f4886 | 2007-07-18 00:35:56 -0400 | [diff] [blame] | 1066 | x->len = 1; |
| 1067 | spi_message_add_tail(x, m); |
| 1068 | |
| 1069 | x++; |
Dmitry Torokhov | e8f462d | 2008-10-09 00:52:23 -0400 | [diff] [blame] | 1070 | x->rx_buf = &packet->tc.z1; |
Semih Hazar | e4f4886 | 2007-07-18 00:35:56 -0400 | [diff] [blame] | 1071 | x->len = 2; |
| 1072 | spi_message_add_tail(x, m); |
| 1073 | } |
| 1074 | |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 1075 | m->complete = ads7846_rx_val; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 1076 | m->context = ts; |
| 1077 | |
| 1078 | m++; |
| 1079 | spi_message_init(m); |
| 1080 | |
| 1081 | x++; |
Dmitry Torokhov | e8f462d | 2008-10-09 00:52:23 -0400 | [diff] [blame] | 1082 | packet->read_z2 = READ_Z2(vref); |
| 1083 | x->tx_buf = &packet->read_z2; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 1084 | x->len = 1; |
| 1085 | spi_message_add_tail(x, m); |
| 1086 | |
| 1087 | x++; |
Dmitry Torokhov | e8f462d | 2008-10-09 00:52:23 -0400 | [diff] [blame] | 1088 | x->rx_buf = &packet->tc.z2; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 1089 | x->len = 2; |
| 1090 | spi_message_add_tail(x, m); |
| 1091 | |
Semih Hazar | e4f4886 | 2007-07-18 00:35:56 -0400 | [diff] [blame] | 1092 | /* ... maybe discard first sample ... */ |
| 1093 | if (pdata->settle_delay_usecs) { |
| 1094 | x->delay_usecs = pdata->settle_delay_usecs; |
| 1095 | |
| 1096 | x++; |
Dmitry Torokhov | e8f462d | 2008-10-09 00:52:23 -0400 | [diff] [blame] | 1097 | x->tx_buf = &packet->read_z2; |
Semih Hazar | e4f4886 | 2007-07-18 00:35:56 -0400 | [diff] [blame] | 1098 | x->len = 1; |
| 1099 | spi_message_add_tail(x, m); |
| 1100 | |
| 1101 | x++; |
Dmitry Torokhov | e8f462d | 2008-10-09 00:52:23 -0400 | [diff] [blame] | 1102 | x->rx_buf = &packet->tc.z2; |
Semih Hazar | e4f4886 | 2007-07-18 00:35:56 -0400 | [diff] [blame] | 1103 | x->len = 2; |
| 1104 | spi_message_add_tail(x, m); |
| 1105 | } |
| 1106 | |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 1107 | m->complete = ads7846_rx_val; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 1108 | m->context = ts; |
| 1109 | } |
Imre Deak | 53a0ef89 | 2006-04-11 23:41:49 -0400 | [diff] [blame] | 1110 | |
| 1111 | /* power down */ |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 1112 | m++; |
| 1113 | spi_message_init(m); |
| 1114 | |
Imre Deak | 53a0ef89 | 2006-04-11 23:41:49 -0400 | [diff] [blame] | 1115 | x++; |
Dmitry Torokhov | e8f462d | 2008-10-09 00:52:23 -0400 | [diff] [blame] | 1116 | packet->pwrdown = PWRDOWN; |
| 1117 | x->tx_buf = &packet->pwrdown; |
Imre Deak | 53a0ef89 | 2006-04-11 23:41:49 -0400 | [diff] [blame] | 1118 | x->len = 1; |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 1119 | spi_message_add_tail(x, m); |
Imre Deak | 53a0ef89 | 2006-04-11 23:41:49 -0400 | [diff] [blame] | 1120 | |
| 1121 | x++; |
Dmitry Torokhov | e8f462d | 2008-10-09 00:52:23 -0400 | [diff] [blame] | 1122 | x->rx_buf = &packet->dummy; |
Imre Deak | 53a0ef89 | 2006-04-11 23:41:49 -0400 | [diff] [blame] | 1123 | x->len = 2; |
David Brownell | d93f70b | 2006-02-15 00:49:35 -0500 | [diff] [blame] | 1124 | CS_CHANGE(*x); |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 1125 | spi_message_add_tail(x, m); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 1126 | |
Imre Deak | 0b7018a | 2006-04-11 23:42:03 -0400 | [diff] [blame] | 1127 | m->complete = ads7846_rx; |
| 1128 | m->context = ts; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 1129 | |
Imre Deak | d5b415c | 2006-04-26 00:13:18 -0400 | [diff] [blame] | 1130 | ts->last_msg = m; |
| 1131 | |
Thomas Gleixner | dace145 | 2006-07-01 19:29:38 -0700 | [diff] [blame] | 1132 | if (request_irq(spi->irq, ads7846_irq, IRQF_TRIGGER_FALLING, |
David Brownell | 9084533 | 2006-05-25 18:44:20 -0700 | [diff] [blame] | 1133 | spi->dev.driver->name, ts)) { |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 1134 | dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq); |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 1135 | err = -EBUSY; |
Eric Miao | 4d5975e | 2008-09-10 12:06:15 -0400 | [diff] [blame] | 1136 | goto err_free_gpio; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 1137 | } |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 1138 | |
David Brownell | 2c8dc07 | 2007-01-18 00:45:48 -0500 | [diff] [blame] | 1139 | err = ads784x_hwmon_register(spi, ts); |
| 1140 | if (err) |
| 1141 | goto err_free_irq; |
| 1142 | |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 1143 | dev_info(&spi->dev, "touchscreen, irq %d\n", spi->irq); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 1144 | |
David Brownell | 2c8dc07 | 2007-01-18 00:45:48 -0500 | [diff] [blame] | 1145 | /* take a first sample, leaving nPENIRQ active and vREF off; avoid |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 1146 | * the touchscreen, in case it's not connected. |
| 1147 | */ |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 1148 | (void) ads7846_read12_ser(&spi->dev, |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 1149 | READ_12BIT_SER(vaux) | ADS_PD10_ALL_ON); |
| 1150 | |
David Brownell | 2c8dc07 | 2007-01-18 00:45:48 -0500 | [diff] [blame] | 1151 | err = sysfs_create_group(&spi->dev.kobj, &ads784x_attr_group); |
Dmitry Torokhov | 8dd5165 | 2006-11-02 23:34:09 -0500 | [diff] [blame] | 1152 | if (err) |
David Brownell | 2c8dc07 | 2007-01-18 00:45:48 -0500 | [diff] [blame] | 1153 | goto err_remove_hwmon; |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 1154 | |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 1155 | err = input_register_device(input_dev); |
| 1156 | if (err) |
Dmitry Torokhov | 8dd5165 | 2006-11-02 23:34:09 -0500 | [diff] [blame] | 1157 | goto err_remove_attr_group; |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 1158 | |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 1159 | return 0; |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 1160 | |
Dmitry Torokhov | 8dd5165 | 2006-11-02 23:34:09 -0500 | [diff] [blame] | 1161 | err_remove_attr_group: |
David Brownell | 2c8dc07 | 2007-01-18 00:45:48 -0500 | [diff] [blame] | 1162 | sysfs_remove_group(&spi->dev.kobj, &ads784x_attr_group); |
| 1163 | err_remove_hwmon: |
| 1164 | ads784x_hwmon_unregister(spi, ts); |
Dmitry Torokhov | 8dd5165 | 2006-11-02 23:34:09 -0500 | [diff] [blame] | 1165 | err_free_irq: |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 1166 | free_irq(spi->irq, ts); |
Eric Miao | 4d5975e | 2008-09-10 12:06:15 -0400 | [diff] [blame] | 1167 | err_free_gpio: |
| 1168 | if (ts->gpio_pendown != -1) |
| 1169 | gpio_free(ts->gpio_pendown); |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 1170 | err_cleanup_filter: |
| 1171 | if (ts->filter_cleanup) |
| 1172 | ts->filter_cleanup(ts->filter_data); |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 1173 | err_free_mem: |
| 1174 | input_free_device(input_dev); |
Dmitry Torokhov | e8f462d | 2008-10-09 00:52:23 -0400 | [diff] [blame] | 1175 | kfree(packet); |
Dmitry Torokhov | a90f7e9 | 2006-02-15 00:49:22 -0500 | [diff] [blame] | 1176 | kfree(ts); |
| 1177 | return err; |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 1178 | } |
| 1179 | |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 1180 | static int __devexit ads7846_remove(struct spi_device *spi) |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 1181 | { |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 1182 | struct ads7846 *ts = dev_get_drvdata(&spi->dev); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 1183 | |
David Brownell | 2c8dc07 | 2007-01-18 00:45:48 -0500 | [diff] [blame] | 1184 | ads784x_hwmon_unregister(spi, ts); |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 1185 | input_unregister_device(ts->input); |
| 1186 | |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 1187 | ads7846_suspend(spi, PMSG_SUSPEND); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 1188 | |
David Brownell | 2c8dc07 | 2007-01-18 00:45:48 -0500 | [diff] [blame] | 1189 | sysfs_remove_group(&spi->dev.kobj, &ads784x_attr_group); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 1190 | |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 1191 | free_irq(ts->spi->irq, ts); |
Imre Deak | c9e617a | 2006-04-11 23:44:05 -0400 | [diff] [blame] | 1192 | /* suspend left the IRQ disabled */ |
| 1193 | enable_irq(ts->spi->irq); |
Imre Deak | 7de90a8 | 2006-04-11 23:43:55 -0400 | [diff] [blame] | 1194 | |
Eric Miao | 4d5975e | 2008-09-10 12:06:15 -0400 | [diff] [blame] | 1195 | if (ts->gpio_pendown != -1) |
| 1196 | gpio_free(ts->gpio_pendown); |
| 1197 | |
Imre Deak | da970e6 | 2007-01-18 00:44:41 -0500 | [diff] [blame] | 1198 | if (ts->filter_cleanup) |
| 1199 | ts->filter_cleanup(ts->filter_data); |
| 1200 | |
Dmitry Torokhov | e8f462d | 2008-10-09 00:52:23 -0400 | [diff] [blame] | 1201 | kfree(ts->packet); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 1202 | kfree(ts); |
| 1203 | |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 1204 | dev_dbg(&spi->dev, "unregistered touchscreen\n"); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 1205 | return 0; |
| 1206 | } |
| 1207 | |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 1208 | static struct spi_driver ads7846_driver = { |
| 1209 | .driver = { |
| 1210 | .name = "ads7846", |
| 1211 | .bus = &spi_bus_type, |
| 1212 | .owner = THIS_MODULE, |
| 1213 | }, |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 1214 | .probe = ads7846_probe, |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 1215 | .remove = __devexit_p(ads7846_remove), |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 1216 | .suspend = ads7846_suspend, |
| 1217 | .resume = ads7846_resume, |
| 1218 | }; |
| 1219 | |
| 1220 | static int __init ads7846_init(void) |
| 1221 | { |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 1222 | return spi_register_driver(&ads7846_driver); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 1223 | } |
| 1224 | module_init(ads7846_init); |
| 1225 | |
| 1226 | static void __exit ads7846_exit(void) |
| 1227 | { |
David Brownell | 2e5a7bd | 2006-01-08 13:34:25 -0800 | [diff] [blame] | 1228 | spi_unregister_driver(&ads7846_driver); |
David Brownell | ffa458c | 2006-01-08 13:34:21 -0800 | [diff] [blame] | 1229 | } |
| 1230 | module_exit(ads7846_exit); |
| 1231 | |
| 1232 | MODULE_DESCRIPTION("ADS7846 TouchScreen Driver"); |
| 1233 | MODULE_LICENSE("GPL"); |