2 drivers/input/touchscreen/Kconfig | 11
3 drivers/input/touchscreen/Makefile | 1
4 drivers/input/touchscreen/tsc2005.c | 958 ++++++++++++++++++++++++++++++++++++
5 include/linux/spi/tsc2005.h | 30 +
6 4 files changed, 1000 insertions(+)
8 Index: linux-2.6.37-rc1/drivers/input/touchscreen/Kconfig
9 ===================================================================
10 --- linux-2.6.37-rc1.orig/drivers/input/touchscreen/Kconfig 2010-11-01 12:54:12.000000000 +0100
11 +++ linux-2.6.37-rc1/drivers/input/touchscreen/Kconfig 2010-11-05 17:04:55.412000001 +0100
13 To compile this driver as a module, choose M here: the
14 module will be called touchit213.
16 +config TOUCHSCREEN_TSC2005
17 + tristate "TSC2005 based touchscreens"
18 + depends on SPI_MASTER
20 + Say Y here if you have a TSC2005 based touchscreen.
24 + To compile this driver as a module, choose M here: the
25 + module will be called tsc2005.
27 config TOUCHSCREEN_TSC2007
28 tristate "TSC2007 based touchscreens"
30 Index: linux-2.6.37-rc1/drivers/input/touchscreen/Makefile
31 ===================================================================
32 --- linux-2.6.37-rc1.orig/drivers/input/touchscreen/Makefile 2010-11-01 12:54:12.000000000 +0100
33 +++ linux-2.6.37-rc1/drivers/input/touchscreen/Makefile 2010-11-05 17:04:55.412000001 +0100
35 obj-$(CONFIG_TOUCHSCREEN_TOUCHIT213) += touchit213.o
36 obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o
37 obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o
38 +obj-$(CONFIG_TOUCHSCREEN_TSC2005) += tsc2005.o
39 obj-$(CONFIG_TOUCHSCREEN_TSC2007) += tsc2007.o
40 obj-$(CONFIG_TOUCHSCREEN_UCB1400) += ucb1400_ts.o
41 obj-$(CONFIG_TOUCHSCREEN_WACOM_W8001) += wacom_w8001.o
42 Index: linux-2.6.37-rc1/drivers/input/touchscreen/tsc2005.c
43 ===================================================================
44 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
45 +++ linux-2.6.37-rc1/drivers/input/touchscreen/tsc2005.c 2010-11-05 17:04:55.413000001 +0100
48 + * TSC2005 touchscreen driver
50 + * Copyright (C) 2006-2008 Nokia Corporation
52 + * Author: Lauri Leukkunen <lauri.leukkunen@nokia.com>
53 + * based on TSC2301 driver by Klaus K. Pedersen <klaus.k.pedersen@nokia.com>
55 + * This program is free software; you can redistribute it and/or modify
56 + * it under the terms of the GNU General Public License as published by
57 + * the Free Software Foundation; either version 2 of the License, or
58 + * (at your option) any later version.
60 + * This program is distributed in the hope that it will be useful,
61 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
62 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
63 + * GNU General Public License for more details.
65 + * You should have received a copy of the GNU General Public License
66 + * along with this program; if not, write to the Free Software
67 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
71 +#include <linux/kernel.h>
72 +#include <linux/module.h>
73 +#include <linux/input.h>
74 +#include <linux/interrupt.h>
75 +#include <linux/delay.h>
76 +#include <linux/spi/spi.h>
78 +#include <linux/spi/tsc2005.h>
81 + * The touchscreen interface operates as follows:
84 + * Request access to GPIO103 (DAV)
85 + * tsc2005_ts_irq_handler will trigger when DAV line goes down
87 + * 1) Pen is pressed against touchscreeen
88 + * 2) TSC2005 performs AD conversion
89 + * 3) After the conversion is done TSC2005 drives DAV line down
90 + * 4) GPIO IRQ is received and tsc2005_ts_irq_handler is called
91 + * 5) tsc2005_ts_irq_handler queues up an spi transfer to fetch
92 + * the x, y, z1, z2 values
93 + * 6) tsc2005_ts_rx() reports coordinates to input layer and
94 + * sets up tsc2005_ts_timer() to be called after TSC2005_TS_SCAN_TIME
95 + * 7) When the penup_timer expires, there have not been DAV interrupts
96 + * during the last 20ms which means the pen has been lifted.
99 +#define TSC2005_VDD_LOWER_27
101 +#ifdef TSC2005_VDD_LOWER_27
102 +#define TSC2005_HZ (10000000)
104 +#define TSC2005_HZ (25000000)
107 +#define TSC2005_CMD (0x80)
108 +#define TSC2005_REG (0x00)
110 +#define TSC2005_CMD_STOP (1)
111 +#define TSC2005_CMD_10BIT (0 << 2)
112 +#define TSC2005_CMD_12BIT (1 << 2)
114 +#define TSC2005_CMD_SCAN_XYZZ (0 << 3)
115 +#define TSC2005_CMD_SCAN_XY (1 << 3)
116 +#define TSC2005_CMD_SCAN_X (2 << 3)
117 +#define TSC2005_CMD_SCAN_Y (3 << 3)
118 +#define TSC2005_CMD_SCAN_ZZ (4 << 3)
119 +#define TSC2005_CMD_AUX_SINGLE (5 << 3)
120 +#define TSC2005_CMD_TEMP1 (6 << 3)
121 +#define TSC2005_CMD_TEMP2 (7 << 3)
122 +#define TSC2005_CMD_AUX_CONT (8 << 3)
123 +#define TSC2005_CMD_TEST_X_CONN (9 << 3)
124 +#define TSC2005_CMD_TEST_Y_CONN (10 << 3)
125 +#define TSC2005_CMD_TEST_SHORT (11 << 3)
126 +/* command 12 reserved, according to 2008-03 erratum */
127 +#define TSC2005_CMD_DRIVE_XX (13 << 3)
128 +#define TSC2005_CMD_DRIVE_YY (14 << 3)
129 +#define TSC2005_CMD_DRIVE_YX (15 << 3)
131 +#define TSC2005_REG_X (0 << 3)
132 +#define TSC2005_REG_Y (1 << 3)
133 +#define TSC2005_REG_Z1 (2 << 3)
134 +#define TSC2005_REG_Z2 (3 << 3)
135 +#define TSC2005_REG_AUX (4 << 3)
136 +#define TSC2005_REG_TEMP1 (5 << 3)
137 +#define TSC2005_REG_TEMP2 (6 << 3)
138 +#define TSC2005_REG_STATUS (7 << 3)
139 +#define TSC2005_REG_AUX_HIGH (8 << 3)
140 +#define TSC2005_REG_AUX_LOW (9 << 3)
141 +#define TSC2005_REG_TEMP_HIGH (10 << 3)
142 +#define TSC2005_REG_TEMP_LOW (11 << 3)
143 +#define TSC2005_REG_CFR0 (12 << 3)
144 +#define TSC2005_REG_CFR1 (13 << 3)
145 +#define TSC2005_REG_CFR2 (14 << 3)
146 +#define TSC2005_REG_FUNCTION (15 << 3)
148 +#define TSC2005_REG_PND0 (1 << 1)
149 +#define TSC2005_REG_READ (0x01)
150 +#define TSC2005_REG_WRITE (0x00)
153 +#define TSC2005_CFR0_LONGSAMPLING (1)
154 +#define TSC2005_CFR0_DETECTINWAIT (1 << 1)
155 +#define TSC2005_CFR0_SENSETIME_32US (0)
156 +#define TSC2005_CFR0_SENSETIME_96US (1 << 2)
157 +#define TSC2005_CFR0_SENSETIME_544US (1 << 3)
158 +#define TSC2005_CFR0_SENSETIME_2080US (1 << 4)
159 +#define TSC2005_CFR0_SENSETIME_2656US (0x001C)
160 +#define TSC2005_CFR0_PRECHARGE_20US (0x0000)
161 +#define TSC2005_CFR0_PRECHARGE_84US (0x0020)
162 +#define TSC2005_CFR0_PRECHARGE_276US (0x0040)
163 +#define TSC2005_CFR0_PRECHARGE_1044US (0x0080)
164 +#define TSC2005_CFR0_PRECHARGE_1364US (0x00E0)
165 +#define TSC2005_CFR0_STABTIME_0US (0x0000)
166 +#define TSC2005_CFR0_STABTIME_100US (0x0100)
167 +#define TSC2005_CFR0_STABTIME_500US (0x0200)
168 +#define TSC2005_CFR0_STABTIME_1MS (0x0300)
169 +#define TSC2005_CFR0_STABTIME_5MS (0x0400)
170 +#define TSC2005_CFR0_STABTIME_100MS (0x0700)
171 +#define TSC2005_CFR0_CLOCK_4MHZ (0x0000)
172 +#define TSC2005_CFR0_CLOCK_2MHZ (0x0800)
173 +#define TSC2005_CFR0_CLOCK_1MHZ (0x1000)
174 +#define TSC2005_CFR0_RESOLUTION12 (0x2000)
175 +#define TSC2005_CFR0_STATUS (0x4000)
176 +#define TSC2005_CFR0_PENMODE (0x8000)
178 +#define TSC2005_CFR0_INITVALUE (TSC2005_CFR0_STABTIME_1MS | \
179 + TSC2005_CFR0_CLOCK_1MHZ | \
180 + TSC2005_CFR0_RESOLUTION12 | \
181 + TSC2005_CFR0_PRECHARGE_276US | \
182 + TSC2005_CFR0_PENMODE)
184 +/* Bits common to both read and write of config register 0 */
185 +#define TSC2005_CFR0_RW_MASK 0x3fff
187 +#define TSC2005_CFR1_BATCHDELAY_0MS (0x0000)
188 +#define TSC2005_CFR1_BATCHDELAY_1MS (0x0001)
189 +#define TSC2005_CFR1_BATCHDELAY_2MS (0x0002)
190 +#define TSC2005_CFR1_BATCHDELAY_4MS (0x0003)
191 +#define TSC2005_CFR1_BATCHDELAY_10MS (0x0004)
192 +#define TSC2005_CFR1_BATCHDELAY_20MS (0x0005)
193 +#define TSC2005_CFR1_BATCHDELAY_40MS (0x0006)
194 +#define TSC2005_CFR1_BATCHDELAY_100MS (0x0007)
196 +#define TSC2005_CFR1_INITVALUE (TSC2005_CFR1_BATCHDELAY_4MS)
198 +#define TSC2005_CFR2_MAVE_TEMP (0x0001)
199 +#define TSC2005_CFR2_MAVE_AUX (0x0002)
200 +#define TSC2005_CFR2_MAVE_Z (0x0004)
201 +#define TSC2005_CFR2_MAVE_Y (0x0008)
202 +#define TSC2005_CFR2_MAVE_X (0x0010)
203 +#define TSC2005_CFR2_AVG_1 (0x0000)
204 +#define TSC2005_CFR2_AVG_3 (0x0400)
205 +#define TSC2005_CFR2_AVG_7 (0x0800)
206 +#define TSC2005_CFR2_MEDIUM_1 (0x0000)
207 +#define TSC2005_CFR2_MEDIUM_3 (0x1000)
208 +#define TSC2005_CFR2_MEDIUM_7 (0x2000)
209 +#define TSC2005_CFR2_MEDIUM_15 (0x3000)
211 +#define TSC2005_CFR2_IRQ_MASK (0xC000)
212 +#define TSC2005_CFR2_IRQ_DAV (0x4000)
213 +#define TSC2005_CFR2_IRQ_PEN (0x8000)
214 +#define TSC2005_CFR2_IRQ_PENDAV (0x0000)
216 +#define TSC2005_CFR2_INITVALUE (TSC2005_CFR2_IRQ_PENDAV | \
217 + TSC2005_CFR2_MAVE_X | \
218 + TSC2005_CFR2_MAVE_Y | \
219 + TSC2005_CFR2_MAVE_Z | \
220 + TSC2005_CFR2_MEDIUM_15 | \
221 + TSC2005_CFR2_AVG_7)
223 +#define MAX_12BIT ((1 << 12) - 1)
224 +#define TS_SAMPLES 4
225 +#define TSC2005_TS_PENUP_TIME 40
227 +static const u32 tsc2005_read_reg[] = {
228 + (TSC2005_REG | TSC2005_REG_X | TSC2005_REG_READ) << 16,
229 + (TSC2005_REG | TSC2005_REG_Y | TSC2005_REG_READ) << 16,
230 + (TSC2005_REG | TSC2005_REG_Z1 | TSC2005_REG_READ) << 16,
231 + (TSC2005_REG | TSC2005_REG_Z2 | TSC2005_REG_READ) << 16,
233 +#define NUM_READ_REGS (sizeof(tsc2005_read_reg)/sizeof(tsc2005_read_reg[0]))
236 + struct spi_device *spi;
238 + struct input_dev *idev;
240 + struct timer_list penup_timer;
242 + /* ESD recovery via a hardware reset if the tsc2005
243 + * doesn't respond after a configurable period (in ms) of
244 + * IRQ/SPI inactivity. If esd_timeout is 0, timer and work
248 + struct timer_list esd_timer;
249 + struct work_struct esd_work;
252 + struct mutex mutex;
254 + struct spi_message read_msg;
255 + struct spi_transfer read_xfer[NUM_READ_REGS];
256 + u32 data[NUM_READ_REGS];
258 + /* previously reported x,y,p (if pen_down) */
262 + /* fudge parameters - changes must exceed one of these. */
266 + /* raw copy of previous x,y,z */
271 + /* average accumulators for each component */
277 + /* configuration */
282 + int touch_pressure;
290 + void (*set_reset)(bool enable);
293 +static void tsc2005_cmd(struct tsc2005 *ts, u8 cmd)
295 + u8 data = TSC2005_CMD | TSC2005_CMD_12BIT | cmd;
296 + struct spi_message msg;
297 + struct spi_transfer xfer = { 0 };
299 + xfer.tx_buf = &data;
300 + xfer.rx_buf = NULL;
302 + xfer.bits_per_word = 8;
304 + spi_message_init(&msg);
305 + spi_message_add_tail(&xfer, &msg);
306 + spi_sync(ts->spi, &msg);
309 +static void tsc2005_write(struct tsc2005 *ts, u8 reg, u16 value)
312 + struct spi_message msg;
313 + struct spi_transfer xfer = { 0 };
315 + tx = (TSC2005_REG | reg | TSC2005_REG_PND0 |
316 + TSC2005_REG_WRITE) << 16;
320 + xfer.rx_buf = NULL;
322 + xfer.bits_per_word = 24;
324 + spi_message_init(&msg);
325 + spi_message_add_tail(&xfer, &msg);
326 + spi_sync(ts->spi, &msg);
329 +static void tsc2005_read(struct tsc2005 *ts, u8 reg, u16 *value)
333 + struct spi_message msg;
334 + struct spi_transfer xfer = { 0 };
336 + tx = (TSC2005_REG | reg | TSC2005_REG_READ) << 16;
341 + xfer.bits_per_word = 24;
343 + spi_message_init(&msg);
344 + spi_message_add_tail(&xfer, &msg);
345 + spi_sync(ts->spi, &msg);
349 +static void tsc2005_ts_update_pen_state(struct tsc2005 *ts,
350 + int x, int y, int pressure)
353 + input_report_abs(ts->idev, ABS_X, x);
354 + input_report_abs(ts->idev, ABS_Y, y);
355 + input_report_abs(ts->idev, ABS_PRESSURE, pressure);
356 + if (!ts->pen_down) {
357 + input_report_key(ts->idev, BTN_TOUCH, 1);
361 + input_report_abs(ts->idev, ABS_PRESSURE, 0);
362 + if (ts->pen_down) {
363 + input_report_key(ts->idev, BTN_TOUCH, 0);
368 + input_sync(ts->idev);
372 + * This function is called by the SPI framework after the coordinates
373 + * have been read from TSC2005
375 +static void tsc2005_ts_rx(void *arg)
377 + struct tsc2005 *ts = arg;
378 + unsigned long flags;
379 + int inside_rect, pressure_limit;
380 + int x, y, z1, z2, pressure;
382 + spin_lock_irqsave(&ts->lock, flags);
384 + if (ts->disable_depth) {
385 + ts->spi_pending = 0;
394 + /* validate pressure and position */
395 + if (x > MAX_12BIT || y > MAX_12BIT)
398 + /* skip coords if the pressure-components are out of range */
399 + if (z1 < 100 || z2 > MAX_12BIT || z1 >= z2)
402 + /* skip point if this is a pen down with the exact same values as
403 + * the value before pen-up - that implies SPI fed us stale data
405 + if (!ts->pen_down &&
412 + /* At this point we are happy we have a valid and useful reading.
413 + * Remember it for later comparisons. We may now begin downsampling
420 + /* don't run average on the "pen down" event */
421 + if (ts->sample_sent) {
427 + if (++ts->sample_cnt < TS_SAMPLES)
430 + x = ts->avg_x / TS_SAMPLES;
431 + y = ts->avg_y / TS_SAMPLES;
432 + z1 = ts->avg_z1 / TS_SAMPLES;
433 + z2 = ts->avg_z2 / TS_SAMPLES;
436 + ts->sample_cnt = 0;
442 + pressure = x * (z2 - z1) / z1;
443 + pressure = pressure * ts->x_plate_ohm / 4096;
445 + pressure_limit = ts->sample_sent ? ts->p_max : ts->touch_pressure;
446 + if (pressure > pressure_limit)
449 + /* Discard the event if it still is within the previous rect -
450 + * unless the pressure is clearly harder, but then use previous
451 + * x,y position. If any coordinate deviates enough, fudging
452 + * of all three will still take place in the input layer.
454 + inside_rect = (ts->sample_sent &&
455 + x > (int)ts->out_x - ts->fudge_x &&
456 + x < (int)ts->out_x + ts->fudge_x &&
457 + y > (int)ts->out_y - ts->fudge_y &&
458 + y < (int)ts->out_y + ts->fudge_y);
460 + x = ts->out_x, y = ts->out_y;
462 + if (!inside_rect || pressure < (ts->out_p - ts->fudge_p)) {
463 + tsc2005_ts_update_pen_state(ts, x, y, pressure);
464 + ts->sample_sent = 1;
467 + ts->out_p = pressure;
470 + if (ts->spi_pending > 1) {
471 + /* One or more interrupts (sometimes several dozens)
472 + * occured while waiting for the SPI read - get
473 + * another read going.
475 + ts->spi_pending = 1;
476 + if (spi_async(ts->spi, &ts->read_msg)) {
477 + dev_err(&ts->spi->dev, "ts: spi_async() failed");
478 + ts->spi_pending = 0;
481 + ts->spi_pending = 0;
483 + /* kick pen up timer - to make sure it expires again(!) */
484 + if (ts->sample_sent) {
485 + mod_timer(&ts->penup_timer,
486 + jiffies + msecs_to_jiffies(TSC2005_TS_PENUP_TIME));
487 + /* Also kick the watchdog, as we still think we're alive */
488 + if (ts->esd_timeout && ts->disable_depth == 0) {
489 + unsigned long wdj = msecs_to_jiffies(ts->esd_timeout);
490 + mod_timer(&ts->esd_timer, round_jiffies(jiffies+wdj));
493 + spin_unlock_irqrestore(&ts->lock, flags);
496 +/* This penup timer is very forgiving of delayed SPI reads. The
497 + * (ESD) watchdog will rescue us if spi_pending remains set, unless
498 + * we are enterring the disabled state. In that case we must just
499 + * handle the pen up, and let disabling complete.
501 +static void tsc2005_ts_penup_timer_handler(unsigned long data)
503 + struct tsc2005 *ts = (struct tsc2005 *)data;
504 + if ((!ts->spi_pending || ts->disable_depth) &&
506 + tsc2005_ts_update_pen_state(ts, 0, 0, 0);
507 + ts->sample_sent = 0;
512 + * This interrupt is called when pen is down and coordinates are
513 + * available. That is indicated by a either:
514 + * a) a rising edge on PINTDAV or (PENDAV mode)
515 + * b) a falling edge on DAV line (DAV mode)
516 + * depending on the setting of the IRQ bits in the CFR2 setting above.
518 +static irqreturn_t tsc2005_ts_irq_handler(int irq, void *dev_id)
520 + struct tsc2005 *ts = dev_id;
521 + if (ts->disable_depth)
524 + if (!ts->spi_pending) {
525 + if (spi_async(ts->spi, &ts->read_msg)) {
526 + dev_err(&ts->spi->dev, "ts: spi_async() failed");
530 + /* By shifting in 1s we can never wrap */
531 + ts->spi_pending = (ts->spi_pending<<1)+1;
533 + /* Kick pen up timer only if it's not been started yet. Strictly,
534 + * it isn't even necessary to start it at all here, but doing so
535 + * keeps an equivalence between pen state and timer state.
536 + * The SPI read loop will keep pushing it into the future.
537 + * If it times out with an SPI pending, it's ignored anyway.
539 + if (!timer_pending(&ts->penup_timer)) {
540 + unsigned long pu = msecs_to_jiffies(TSC2005_TS_PENUP_TIME);
541 + ts->penup_timer.expires = jiffies + pu;
542 + add_timer(&ts->penup_timer);
545 + return IRQ_HANDLED;
548 +static void tsc2005_ts_setup_spi_xfer(struct tsc2005 *ts)
550 + struct spi_message *m = &ts->read_msg;
551 + struct spi_transfer *x = &ts->read_xfer[0];
554 + spi_message_init(m);
556 + for (i = 0; i < NUM_READ_REGS; i++, x++) {
557 + x->tx_buf = &tsc2005_read_reg[i];
558 + x->rx_buf = &ts->data[i];
560 + x->bits_per_word = 24;
561 + x->cs_change = i < (NUM_READ_REGS - 1);
562 + spi_message_add_tail(x, m);
565 + m->complete = tsc2005_ts_rx;
569 +static ssize_t tsc2005_ts_pen_down_show(struct device *dev,
570 + struct device_attribute *attr,
573 + struct tsc2005 *ts = dev_get_drvdata(dev);
575 + return sprintf(buf, "%u\n", ts->pen_down);
578 +static DEVICE_ATTR(pen_down, S_IRUGO, tsc2005_ts_pen_down_show, NULL);
580 +static int tsc2005_configure(struct tsc2005 *ts, int flags)
582 + tsc2005_write(ts, TSC2005_REG_CFR0, TSC2005_CFR0_INITVALUE);
583 + tsc2005_write(ts, TSC2005_REG_CFR1, TSC2005_CFR1_INITVALUE);
584 + tsc2005_write(ts, TSC2005_REG_CFR2, TSC2005_CFR2_INITVALUE);
585 + tsc2005_cmd(ts, flags);
590 +static void tsc2005_start_scan(struct tsc2005 *ts)
592 + tsc2005_configure(ts, TSC2005_CMD_SCAN_XYZZ);
595 +static void tsc2005_stop_scan(struct tsc2005 *ts)
597 + tsc2005_cmd(ts, TSC2005_CMD_STOP);
600 +/* Must be called with mutex held */
601 +static void tsc2005_disable(struct tsc2005 *ts)
603 + if (ts->disable_depth++ != 0)
606 + disable_irq(ts->spi->irq);
607 + if (ts->esd_timeout)
608 + del_timer(&ts->esd_timer);
610 + /* wait until penup timer expire normally */
613 + } while (ts->sample_sent);
615 + tsc2005_stop_scan(ts);
618 +static void tsc2005_enable(struct tsc2005 *ts)
620 + if (ts->disable_depth != 1)
623 + if (ts->esd_timeout) {
624 + unsigned long wdj = msecs_to_jiffies(ts->esd_timeout);
625 + ts->esd_timer.expires = round_jiffies(jiffies+wdj);
626 + add_timer(&ts->esd_timer);
628 + tsc2005_start_scan(ts);
629 + enable_irq(ts->spi->irq);
631 + --ts->disable_depth;
634 +static ssize_t tsc2005_disable_show(struct device *dev,
635 + struct device_attribute *attr, char *buf)
637 + struct tsc2005 *ts = dev_get_drvdata(dev);
639 + return sprintf(buf, "%u\n", ts->disabled);
642 +static ssize_t tsc2005_disable_store(struct device *dev,
643 + struct device_attribute *attr,
644 + const char *buf, size_t count)
646 + struct tsc2005 *ts = dev_get_drvdata(dev);
650 + if (strict_strtoul(buf, 10, &res) < 0)
654 + mutex_lock(&ts->mutex);
655 + if (i == ts->disabled)
660 + tsc2005_disable(ts);
662 + tsc2005_enable(ts);
664 + mutex_unlock(&ts->mutex);
668 +static DEVICE_ATTR(disable_ts, 0664, tsc2005_disable_show,
669 + tsc2005_disable_store);
671 +static ssize_t tsc2005_ctrl_selftest_show(struct device *dev,
672 + struct device_attribute *attr,
675 + u16 temp_high_orig, temp_high_test, temp_high;
676 + unsigned int result = 1;
677 + struct tsc2005 *ts = dev_get_drvdata(dev);
679 + if (!ts->set_reset) {
680 + dev_warn(&ts->spi->dev,
681 + "unable to selftest: reset not configured\n");
686 + mutex_lock(&ts->mutex);
687 + tsc2005_disable(ts);
689 + /* Test ctrl communications via temp high / low registers */
690 + tsc2005_read(ts, TSC2005_REG_TEMP_HIGH, &temp_high_orig);
692 + temp_high_test = (temp_high_orig - 1) & 0x0FFF;
694 + tsc2005_write(ts, TSC2005_REG_TEMP_HIGH, temp_high_test);
696 + tsc2005_read(ts, TSC2005_REG_TEMP_HIGH, &temp_high);
698 + if (temp_high != temp_high_test) {
700 + dev_warn(dev, "selftest failed: %d != %d\n",
701 + temp_high, temp_high_test);
706 + msleep(1); /* only 10us required */
709 + tsc2005_enable(ts);
711 + /* Test that reset really happened */
712 + tsc2005_read(ts, TSC2005_REG_TEMP_HIGH, &temp_high);
714 + if (temp_high != temp_high_orig) {
716 + dev_warn(dev, "selftest failed after reset: "
718 + temp_high, temp_high_orig);
721 + mutex_unlock(&ts->mutex);
724 + return sprintf(buf, "%u\n", result);
727 +static DEVICE_ATTR(ts_ctrl_selftest, S_IRUGO, tsc2005_ctrl_selftest_show, NULL);
729 +static void tsc2005_esd_timer_handler(unsigned long data)
731 + struct tsc2005 *ts = (struct tsc2005 *)data;
732 + if (!ts->disable_depth)
733 + schedule_work(&ts->esd_work);
736 +static void tsc2005_rst_handler(struct work_struct *work)
739 + struct tsc2005 *ts = container_of(work, struct tsc2005, esd_work);
742 + mutex_lock(&ts->mutex);
744 + /* If we are disabled, or the a touch has been detected,
745 + * then ignore this timeout. The enable will restart the
746 + * watchdog, as it restarts scanning
748 + if (ts->disable_depth)
751 + /* If we cannot read our known value from configuration register 0
752 + * then reset the controller as if from power-up and start
753 + * scanning again. Always re-arm the watchdog.
755 + tsc2005_read(ts, TSC2005_REG_CFR0, ®_val);
756 + if ((reg_val ^ TSC2005_CFR0_INITVALUE) & TSC2005_CFR0_RW_MASK) {
757 + dev_info(&ts->spi->dev, "TSC not responding, resetting.\n");
758 + /* If this timer kicked in, the penup timer, if ever active
759 + * at all, must have expired ages ago, so no need to del it.
762 + if (ts->sample_sent) {
763 + tsc2005_ts_update_pen_state(ts, 0, 0, 0);
764 + ts->sample_sent = 0;
766 + ts->spi_pending = 0;
767 + msleep(1); /* only 10us required */
769 + tsc2005_start_scan(ts);
771 + wdj = msecs_to_jiffies(ts->esd_timeout);
772 + mod_timer(&ts->esd_timer, round_jiffies(jiffies+wdj));
775 + mutex_unlock(&ts->mutex);
778 +static int __devinit tsc2005_ts_init(struct tsc2005 *ts,
779 + struct tsc2005_platform_data *pdata)
781 + struct input_dev *idev;
785 + init_timer(&ts->penup_timer);
786 + setup_timer(&ts->penup_timer, tsc2005_ts_penup_timer_handler,
787 + (unsigned long)ts);
789 + spin_lock_init(&ts->lock);
790 + mutex_init(&ts->mutex);
792 + ts->x_plate_ohm = pdata->ts_x_plate_ohm ? : 280;
793 + ts->hw_avg_max = pdata->ts_hw_avg;
794 + ts->stab_time = pdata->ts_stab_time;
795 + x_max = pdata->ts_x_max ? : 4096;
796 + ts->fudge_x = pdata->ts_x_fudge ? : 4;
797 + y_max = pdata->ts_y_max ? : 4096;
798 + ts->fudge_y = pdata->ts_y_fudge ? : 8;
799 + ts->p_max = pdata->ts_pressure_max ? : MAX_12BIT;
800 + ts->touch_pressure = pdata->ts_touch_pressure ? : ts->p_max;
801 + ts->fudge_p = pdata->ts_pressure_fudge ? : 2;
803 + ts->set_reset = pdata->set_reset;
805 + idev = input_allocate_device();
806 + if (idev == NULL) {
811 + idev->name = "TSC2005 touchscreen";
812 + snprintf(ts->phys, sizeof(ts->phys), "%s/input-ts",
813 + dev_name(&ts->spi->dev));
814 + idev->phys = ts->phys;
816 + idev->evbit[0] = BIT(EV_ABS) | BIT(EV_KEY);
817 + idev->absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE);
818 + idev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
821 + tsc2005_ts_setup_spi_xfer(ts);
823 + input_set_abs_params(idev, ABS_X, 0, x_max, ts->fudge_x, 0);
824 + input_set_abs_params(idev, ABS_Y, 0, y_max, ts->fudge_y, 0);
825 + input_set_abs_params(idev, ABS_PRESSURE, 0, ts->p_max, ts->fudge_p, 0);
827 + tsc2005_start_scan(ts);
829 + r = request_irq(ts->spi->irq, tsc2005_ts_irq_handler,
830 + (((TSC2005_CFR2_INITVALUE & TSC2005_CFR2_IRQ_MASK) ==
831 + TSC2005_CFR2_IRQ_PENDAV)
832 + ? IRQF_TRIGGER_RISING
833 + : IRQF_TRIGGER_FALLING) |
834 + IRQF_DISABLED, "tsc2005", ts);
836 + dev_err(&ts->spi->dev, "unable to get DAV IRQ");
840 + set_irq_wake(ts->spi->irq, 1);
842 + r = input_register_device(idev);
844 + dev_err(&ts->spi->dev, "can't register touchscreen device\n");
848 + /* We can tolerate these failing */
849 + r = device_create_file(&ts->spi->dev, &dev_attr_ts_ctrl_selftest);
851 + dev_warn(&ts->spi->dev, "can't create sysfs file for %s: %d\n",
852 + dev_attr_ts_ctrl_selftest.attr.name, r);
854 + r = device_create_file(&ts->spi->dev, &dev_attr_pen_down);
856 + dev_warn(&ts->spi->dev, "can't create sysfs file for %s: %d\n",
857 + dev_attr_pen_down.attr.name, r);
859 + r = device_create_file(&ts->spi->dev, &dev_attr_disable_ts);
861 + dev_warn(&ts->spi->dev, "can't create sysfs file for %s: %d\n",
862 + dev_attr_disable_ts.attr.name, r);
864 + /* Finally, configure and start the optional EDD watchdog. */
865 + ts->esd_timeout = pdata->esd_timeout;
866 + if (ts->esd_timeout && ts->set_reset) {
868 + setup_timer(&ts->esd_timer, tsc2005_esd_timer_handler,
869 + (unsigned long)ts);
870 + INIT_WORK(&ts->esd_work, tsc2005_rst_handler);
871 + wdj = msecs_to_jiffies(ts->esd_timeout);
872 + ts->esd_timer.expires = round_jiffies(jiffies+wdj);
873 + add_timer(&ts->esd_timer);
878 + free_irq(ts->spi->irq, ts);
880 + tsc2005_stop_scan(ts);
881 + input_free_device(idev);
886 +static int __devinit tsc2005_probe(struct spi_device *spi)
888 + struct tsc2005 *ts;
889 + struct tsc2005_platform_data *pdata = spi->dev.platform_data;
892 + if (spi->irq < 0) {
893 + dev_dbg(&spi->dev, "no irq?\n");
897 + dev_dbg(&spi->dev, "no platform data?\n");
901 + ts = kzalloc(sizeof(*ts), GFP_KERNEL);
905 + dev_set_drvdata(&spi->dev, ts);
907 + spi->dev.power.power_state = PMSG_ON;
909 + spi->mode = SPI_MODE_0;
910 + spi->bits_per_word = 8;
911 + /* The max speed might've been defined by the board-specific
913 + if (!spi->max_speed_hz)
914 + spi->max_speed_hz = TSC2005_HZ;
918 + r = tsc2005_ts_init(ts, pdata);
929 +static int __devexit tsc2005_remove(struct spi_device *spi)
931 + struct tsc2005 *ts = dev_get_drvdata(&spi->dev);
933 + mutex_lock(&ts->mutex);
934 + tsc2005_disable(ts);
935 + mutex_unlock(&ts->mutex);
937 + device_remove_file(&ts->spi->dev, &dev_attr_disable_ts);
938 + device_remove_file(&ts->spi->dev, &dev_attr_pen_down);
939 + device_remove_file(&ts->spi->dev, &dev_attr_ts_ctrl_selftest);
941 + free_irq(ts->spi->irq, ts);
942 + input_unregister_device(ts->idev);
944 + if (ts->esd_timeout)
945 + del_timer(&ts->esd_timer);
952 +static int tsc2005_suspend(struct spi_device *spi, pm_message_t mesg)
954 + struct tsc2005 *ts = dev_get_drvdata(&spi->dev);
956 + mutex_lock(&ts->mutex);
957 + tsc2005_disable(ts);
958 + mutex_unlock(&ts->mutex);
963 +static int tsc2005_resume(struct spi_device *spi)
965 + struct tsc2005 *ts = dev_get_drvdata(&spi->dev);
967 + mutex_lock(&ts->mutex);
968 + tsc2005_enable(ts);
969 + mutex_unlock(&ts->mutex);
975 +static struct spi_driver tsc2005_driver = {
978 + .owner = THIS_MODULE,
981 + .suspend = tsc2005_suspend,
982 + .resume = tsc2005_resume,
984 + .probe = tsc2005_probe,
985 + .remove = __devexit_p(tsc2005_remove),
988 +static int __init tsc2005_init(void)
990 + printk(KERN_INFO "TSC2005 driver initializing\n");
992 + return spi_register_driver(&tsc2005_driver);
994 +module_init(tsc2005_init);
996 +static void __exit tsc2005_exit(void)
998 + spi_unregister_driver(&tsc2005_driver);
1000 +module_exit(tsc2005_exit);
1002 +MODULE_AUTHOR("Lauri Leukkunen <lauri.leukkunen@nokia.com>");
1003 +MODULE_LICENSE("GPL");
1004 +MODULE_ALIAS("platform:tsc2005");
1005 Index: linux-2.6.37-rc1/include/linux/spi/tsc2005.h
1006 ===================================================================
1007 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1008 +++ linux-2.6.37-rc1/include/linux/spi/tsc2005.h 2010-11-05 17:04:55.413000001 +0100
1010 +#ifndef _LINUX_SPI_TSC2005_H
1011 +#define _LINUX_SPI_TSC2005_H
1013 +#include <linux/types.h>
1015 +struct tsc2005_platform_data {
1016 + u16 ts_x_plate_ohm;
1017 + u32 ts_stab_time; /* voltage settling time */
1018 + u8 ts_hw_avg; /* HW assiseted averaging. Can be
1019 + 0, 4, 8, 16 samples per reading */
1020 + u32 ts_touch_pressure; /* Pressure limit until we report a
1021 + touch event. After that we switch
1022 + to ts_max_pressure. */
1023 + u32 ts_pressure_max;/* Samples with bigger pressure value will
1024 + be ignored, since the corresponding X, Y
1025 + values are unreliable */
1026 + u32 ts_pressure_fudge;
1032 + u32 esd_timeout; /* msec of inactivity before we check */
1034 + unsigned ts_ignore_last:1;
1036 + void (*set_reset)(bool enable);