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 --- linux-2.6.35.orig/drivers/input/touchscreen/Kconfig
9 +++ linux-2.6.35/drivers/input/touchscreen/Kconfig
10 @@ -561,6 +561,17 @@ config TOUCHSCREEN_TOUCHIT213
11 To compile this driver as a module, choose M here: the
12 module will be called touchit213.
14 +config TOUCHSCREEN_TSC2005
15 + tristate "TSC2005 based touchscreens"
16 + depends on SPI_MASTER
18 + Say Y here if you have a TSC2005 based touchscreen.
22 + To compile this driver as a module, choose M here: the
23 + module will be called tsc2005.
25 config TOUCHSCREEN_TSC2007
26 tristate "TSC2007 based touchscreens"
28 --- linux-2.6.35.orig/drivers/input/touchscreen/Makefile
29 +++ linux-2.6.35/drivers/input/touchscreen/Makefile
30 @@ -34,6 +34,7 @@ obj-$(CONFIG_TOUCHSCREEN_S3C2410) += s3c
31 obj-$(CONFIG_TOUCHSCREEN_TOUCHIT213) += touchit213.o
32 obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o
33 obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o
34 +obj-$(CONFIG_TOUCHSCREEN_TSC2005) += tsc2005.o
35 obj-$(CONFIG_TOUCHSCREEN_TSC2007) += tsc2007.o
36 obj-$(CONFIG_TOUCHSCREEN_UCB1400) += ucb1400_ts.o
37 obj-$(CONFIG_TOUCHSCREEN_WACOM_W8001) += wacom_w8001.o
39 +++ linux-2.6.35/drivers/input/touchscreen/tsc2005.c
42 + * TSC2005 touchscreen driver
44 + * Copyright (C) 2006-2008 Nokia Corporation
46 + * Author: Lauri Leukkunen <lauri.leukkunen@nokia.com>
47 + * based on TSC2301 driver by Klaus K. Pedersen <klaus.k.pedersen@nokia.com>
49 + * This program is free software; you can redistribute it and/or modify
50 + * it under the terms of the GNU General Public License as published by
51 + * the Free Software Foundation; either version 2 of the License, or
52 + * (at your option) any later version.
54 + * This program is distributed in the hope that it will be useful,
55 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
56 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
57 + * GNU General Public License for more details.
59 + * You should have received a copy of the GNU General Public License
60 + * along with this program; if not, write to the Free Software
61 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
65 +#include <linux/kernel.h>
66 +#include <linux/module.h>
67 +#include <linux/input.h>
68 +#include <linux/interrupt.h>
69 +#include <linux/delay.h>
70 +#include <linux/spi/spi.h>
72 +#include <linux/spi/tsc2005.h>
75 + * The touchscreen interface operates as follows:
78 + * Request access to GPIO103 (DAV)
79 + * tsc2005_ts_irq_handler will trigger when DAV line goes down
81 + * 1) Pen is pressed against touchscreeen
82 + * 2) TSC2005 performs AD conversion
83 + * 3) After the conversion is done TSC2005 drives DAV line down
84 + * 4) GPIO IRQ is received and tsc2005_ts_irq_handler is called
85 + * 5) tsc2005_ts_irq_handler queues up an spi transfer to fetch
86 + * the x, y, z1, z2 values
87 + * 6) tsc2005_ts_rx() reports coordinates to input layer and
88 + * sets up tsc2005_ts_timer() to be called after TSC2005_TS_SCAN_TIME
89 + * 7) When the penup_timer expires, there have not been DAV interrupts
90 + * during the last 20ms which means the pen has been lifted.
93 +#define TSC2005_VDD_LOWER_27
95 +#ifdef TSC2005_VDD_LOWER_27
96 +#define TSC2005_HZ (10000000)
98 +#define TSC2005_HZ (25000000)
101 +#define TSC2005_CMD (0x80)
102 +#define TSC2005_REG (0x00)
104 +#define TSC2005_CMD_STOP (1)
105 +#define TSC2005_CMD_10BIT (0 << 2)
106 +#define TSC2005_CMD_12BIT (1 << 2)
108 +#define TSC2005_CMD_SCAN_XYZZ (0 << 3)
109 +#define TSC2005_CMD_SCAN_XY (1 << 3)
110 +#define TSC2005_CMD_SCAN_X (2 << 3)
111 +#define TSC2005_CMD_SCAN_Y (3 << 3)
112 +#define TSC2005_CMD_SCAN_ZZ (4 << 3)
113 +#define TSC2005_CMD_AUX_SINGLE (5 << 3)
114 +#define TSC2005_CMD_TEMP1 (6 << 3)
115 +#define TSC2005_CMD_TEMP2 (7 << 3)
116 +#define TSC2005_CMD_AUX_CONT (8 << 3)
117 +#define TSC2005_CMD_TEST_X_CONN (9 << 3)
118 +#define TSC2005_CMD_TEST_Y_CONN (10 << 3)
119 +#define TSC2005_CMD_TEST_SHORT (11 << 3)
120 +/* command 12 reserved, according to 2008-03 erratum */
121 +#define TSC2005_CMD_DRIVE_XX (13 << 3)
122 +#define TSC2005_CMD_DRIVE_YY (14 << 3)
123 +#define TSC2005_CMD_DRIVE_YX (15 << 3)
125 +#define TSC2005_REG_X (0 << 3)
126 +#define TSC2005_REG_Y (1 << 3)
127 +#define TSC2005_REG_Z1 (2 << 3)
128 +#define TSC2005_REG_Z2 (3 << 3)
129 +#define TSC2005_REG_AUX (4 << 3)
130 +#define TSC2005_REG_TEMP1 (5 << 3)
131 +#define TSC2005_REG_TEMP2 (6 << 3)
132 +#define TSC2005_REG_STATUS (7 << 3)
133 +#define TSC2005_REG_AUX_HIGH (8 << 3)
134 +#define TSC2005_REG_AUX_LOW (9 << 3)
135 +#define TSC2005_REG_TEMP_HIGH (10 << 3)
136 +#define TSC2005_REG_TEMP_LOW (11 << 3)
137 +#define TSC2005_REG_CFR0 (12 << 3)
138 +#define TSC2005_REG_CFR1 (13 << 3)
139 +#define TSC2005_REG_CFR2 (14 << 3)
140 +#define TSC2005_REG_FUNCTION (15 << 3)
142 +#define TSC2005_REG_PND0 (1 << 1)
143 +#define TSC2005_REG_READ (0x01)
144 +#define TSC2005_REG_WRITE (0x00)
147 +#define TSC2005_CFR0_LONGSAMPLING (1)
148 +#define TSC2005_CFR0_DETECTINWAIT (1 << 1)
149 +#define TSC2005_CFR0_SENSETIME_32US (0)
150 +#define TSC2005_CFR0_SENSETIME_96US (1 << 2)
151 +#define TSC2005_CFR0_SENSETIME_544US (1 << 3)
152 +#define TSC2005_CFR0_SENSETIME_2080US (1 << 4)
153 +#define TSC2005_CFR0_SENSETIME_2656US (0x001C)
154 +#define TSC2005_CFR0_PRECHARGE_20US (0x0000)
155 +#define TSC2005_CFR0_PRECHARGE_84US (0x0020)
156 +#define TSC2005_CFR0_PRECHARGE_276US (0x0040)
157 +#define TSC2005_CFR0_PRECHARGE_1044US (0x0080)
158 +#define TSC2005_CFR0_PRECHARGE_1364US (0x00E0)
159 +#define TSC2005_CFR0_STABTIME_0US (0x0000)
160 +#define TSC2005_CFR0_STABTIME_100US (0x0100)
161 +#define TSC2005_CFR0_STABTIME_500US (0x0200)
162 +#define TSC2005_CFR0_STABTIME_1MS (0x0300)
163 +#define TSC2005_CFR0_STABTIME_5MS (0x0400)
164 +#define TSC2005_CFR0_STABTIME_100MS (0x0700)
165 +#define TSC2005_CFR0_CLOCK_4MHZ (0x0000)
166 +#define TSC2005_CFR0_CLOCK_2MHZ (0x0800)
167 +#define TSC2005_CFR0_CLOCK_1MHZ (0x1000)
168 +#define TSC2005_CFR0_RESOLUTION12 (0x2000)
169 +#define TSC2005_CFR0_STATUS (0x4000)
170 +#define TSC2005_CFR0_PENMODE (0x8000)
172 +#define TSC2005_CFR0_INITVALUE (TSC2005_CFR0_STABTIME_1MS | \
173 + TSC2005_CFR0_CLOCK_1MHZ | \
174 + TSC2005_CFR0_RESOLUTION12 | \
175 + TSC2005_CFR0_PRECHARGE_276US | \
176 + TSC2005_CFR0_PENMODE)
178 +/* Bits common to both read and write of config register 0 */
179 +#define TSC2005_CFR0_RW_MASK 0x3fff
181 +#define TSC2005_CFR1_BATCHDELAY_0MS (0x0000)
182 +#define TSC2005_CFR1_BATCHDELAY_1MS (0x0001)
183 +#define TSC2005_CFR1_BATCHDELAY_2MS (0x0002)
184 +#define TSC2005_CFR1_BATCHDELAY_4MS (0x0003)
185 +#define TSC2005_CFR1_BATCHDELAY_10MS (0x0004)
186 +#define TSC2005_CFR1_BATCHDELAY_20MS (0x0005)
187 +#define TSC2005_CFR1_BATCHDELAY_40MS (0x0006)
188 +#define TSC2005_CFR1_BATCHDELAY_100MS (0x0007)
190 +#define TSC2005_CFR1_INITVALUE (TSC2005_CFR1_BATCHDELAY_4MS)
192 +#define TSC2005_CFR2_MAVE_TEMP (0x0001)
193 +#define TSC2005_CFR2_MAVE_AUX (0x0002)
194 +#define TSC2005_CFR2_MAVE_Z (0x0004)
195 +#define TSC2005_CFR2_MAVE_Y (0x0008)
196 +#define TSC2005_CFR2_MAVE_X (0x0010)
197 +#define TSC2005_CFR2_AVG_1 (0x0000)
198 +#define TSC2005_CFR2_AVG_3 (0x0400)
199 +#define TSC2005_CFR2_AVG_7 (0x0800)
200 +#define TSC2005_CFR2_MEDIUM_1 (0x0000)
201 +#define TSC2005_CFR2_MEDIUM_3 (0x1000)
202 +#define TSC2005_CFR2_MEDIUM_7 (0x2000)
203 +#define TSC2005_CFR2_MEDIUM_15 (0x3000)
205 +#define TSC2005_CFR2_IRQ_MASK (0xC000)
206 +#define TSC2005_CFR2_IRQ_DAV (0x4000)
207 +#define TSC2005_CFR2_IRQ_PEN (0x8000)
208 +#define TSC2005_CFR2_IRQ_PENDAV (0x0000)
210 +#define TSC2005_CFR2_INITVALUE (TSC2005_CFR2_IRQ_PENDAV | \
211 + TSC2005_CFR2_MAVE_X | \
212 + TSC2005_CFR2_MAVE_Y | \
213 + TSC2005_CFR2_MAVE_Z | \
214 + TSC2005_CFR2_MEDIUM_15 | \
215 + TSC2005_CFR2_AVG_7)
217 +#define MAX_12BIT ((1 << 12) - 1)
218 +#define TS_SAMPLES 4
219 +#define TSC2005_TS_PENUP_TIME 40
221 +static const u32 tsc2005_read_reg[] = {
222 + (TSC2005_REG | TSC2005_REG_X | TSC2005_REG_READ) << 16,
223 + (TSC2005_REG | TSC2005_REG_Y | TSC2005_REG_READ) << 16,
224 + (TSC2005_REG | TSC2005_REG_Z1 | TSC2005_REG_READ) << 16,
225 + (TSC2005_REG | TSC2005_REG_Z2 | TSC2005_REG_READ) << 16,
227 +#define NUM_READ_REGS (sizeof(tsc2005_read_reg)/sizeof(tsc2005_read_reg[0]))
230 + struct spi_device *spi;
232 + struct input_dev *idev;
234 + struct timer_list penup_timer;
236 + /* ESD recovery via a hardware reset if the tsc2005
237 + * doesn't respond after a configurable period (in ms) of
238 + * IRQ/SPI inactivity. If esd_timeout is 0, timer and work
242 + struct timer_list esd_timer;
243 + struct work_struct esd_work;
246 + struct mutex mutex;
248 + struct spi_message read_msg;
249 + struct spi_transfer read_xfer[NUM_READ_REGS];
250 + u32 data[NUM_READ_REGS];
252 + /* previously reported x,y,p (if pen_down) */
256 + /* fudge parameters - changes must exceed one of these. */
260 + /* raw copy of previous x,y,z */
265 + /* average accumulators for each component */
271 + /* configuration */
276 + int touch_pressure;
284 + void (*set_reset)(bool enable);
287 +static void tsc2005_cmd(struct tsc2005 *ts, u8 cmd)
289 + u8 data = TSC2005_CMD | TSC2005_CMD_12BIT | cmd;
290 + struct spi_message msg;
291 + struct spi_transfer xfer = { 0 };
293 + xfer.tx_buf = &data;
294 + xfer.rx_buf = NULL;
296 + xfer.bits_per_word = 8;
298 + spi_message_init(&msg);
299 + spi_message_add_tail(&xfer, &msg);
300 + spi_sync(ts->spi, &msg);
303 +static void tsc2005_write(struct tsc2005 *ts, u8 reg, u16 value)
306 + struct spi_message msg;
307 + struct spi_transfer xfer = { 0 };
309 + tx = (TSC2005_REG | reg | TSC2005_REG_PND0 |
310 + TSC2005_REG_WRITE) << 16;
314 + xfer.rx_buf = NULL;
316 + xfer.bits_per_word = 24;
318 + spi_message_init(&msg);
319 + spi_message_add_tail(&xfer, &msg);
320 + spi_sync(ts->spi, &msg);
323 +static void tsc2005_read(struct tsc2005 *ts, u8 reg, u16 *value)
327 + struct spi_message msg;
328 + struct spi_transfer xfer = { 0 };
330 + tx = (TSC2005_REG | reg | TSC2005_REG_READ) << 16;
335 + xfer.bits_per_word = 24;
337 + spi_message_init(&msg);
338 + spi_message_add_tail(&xfer, &msg);
339 + spi_sync(ts->spi, &msg);
343 +static void tsc2005_ts_update_pen_state(struct tsc2005 *ts,
344 + int x, int y, int pressure)
347 + input_report_abs(ts->idev, ABS_X, x);
348 + input_report_abs(ts->idev, ABS_Y, y);
349 + input_report_abs(ts->idev, ABS_PRESSURE, pressure);
350 + if (!ts->pen_down) {
351 + input_report_key(ts->idev, BTN_TOUCH, 1);
355 + input_report_abs(ts->idev, ABS_PRESSURE, 0);
356 + if (ts->pen_down) {
357 + input_report_key(ts->idev, BTN_TOUCH, 0);
362 + input_sync(ts->idev);
366 + * This function is called by the SPI framework after the coordinates
367 + * have been read from TSC2005
369 +static void tsc2005_ts_rx(void *arg)
371 + struct tsc2005 *ts = arg;
372 + unsigned long flags;
373 + int inside_rect, pressure_limit;
374 + int x, y, z1, z2, pressure;
376 + spin_lock_irqsave(&ts->lock, flags);
378 + if (ts->disable_depth) {
379 + ts->spi_pending = 0;
388 + /* validate pressure and position */
389 + if (x > MAX_12BIT || y > MAX_12BIT)
392 + /* skip coords if the pressure-components are out of range */
393 + if (z1 < 100 || z2 > MAX_12BIT || z1 >= z2)
396 + /* skip point if this is a pen down with the exact same values as
397 + * the value before pen-up - that implies SPI fed us stale data
399 + if (!ts->pen_down &&
406 + /* At this point we are happy we have a valid and useful reading.
407 + * Remember it for later comparisons. We may now begin downsampling
414 + /* don't run average on the "pen down" event */
415 + if (ts->sample_sent) {
421 + if (++ts->sample_cnt < TS_SAMPLES)
424 + x = ts->avg_x / TS_SAMPLES;
425 + y = ts->avg_y / TS_SAMPLES;
426 + z1 = ts->avg_z1 / TS_SAMPLES;
427 + z2 = ts->avg_z2 / TS_SAMPLES;
430 + ts->sample_cnt = 0;
436 + pressure = x * (z2 - z1) / z1;
437 + pressure = pressure * ts->x_plate_ohm / 4096;
439 + pressure_limit = ts->sample_sent ? ts->p_max : ts->touch_pressure;
440 + if (pressure > pressure_limit)
443 + /* Discard the event if it still is within the previous rect -
444 + * unless the pressure is clearly harder, but then use previous
445 + * x,y position. If any coordinate deviates enough, fudging
446 + * of all three will still take place in the input layer.
448 + inside_rect = (ts->sample_sent &&
449 + x > (int)ts->out_x - ts->fudge_x &&
450 + x < (int)ts->out_x + ts->fudge_x &&
451 + y > (int)ts->out_y - ts->fudge_y &&
452 + y < (int)ts->out_y + ts->fudge_y);
454 + x = ts->out_x, y = ts->out_y;
456 + if (!inside_rect || pressure < (ts->out_p - ts->fudge_p)) {
457 + tsc2005_ts_update_pen_state(ts, x, y, pressure);
458 + ts->sample_sent = 1;
461 + ts->out_p = pressure;
464 + if (ts->spi_pending > 1) {
465 + /* One or more interrupts (sometimes several dozens)
466 + * occured while waiting for the SPI read - get
467 + * another read going.
469 + ts->spi_pending = 1;
470 + if (spi_async(ts->spi, &ts->read_msg)) {
471 + dev_err(&ts->spi->dev, "ts: spi_async() failed");
472 + ts->spi_pending = 0;
475 + ts->spi_pending = 0;
477 + /* kick pen up timer - to make sure it expires again(!) */
478 + if (ts->sample_sent) {
479 + mod_timer(&ts->penup_timer,
480 + jiffies + msecs_to_jiffies(TSC2005_TS_PENUP_TIME));
481 + /* Also kick the watchdog, as we still think we're alive */
482 + if (ts->esd_timeout && ts->disable_depth == 0) {
483 + unsigned long wdj = msecs_to_jiffies(ts->esd_timeout);
484 + mod_timer(&ts->esd_timer, round_jiffies(jiffies+wdj));
487 + spin_unlock_irqrestore(&ts->lock, flags);
490 +/* This penup timer is very forgiving of delayed SPI reads. The
491 + * (ESD) watchdog will rescue us if spi_pending remains set, unless
492 + * we are enterring the disabled state. In that case we must just
493 + * handle the pen up, and let disabling complete.
495 +static void tsc2005_ts_penup_timer_handler(unsigned long data)
497 + struct tsc2005 *ts = (struct tsc2005 *)data;
498 + if ((!ts->spi_pending || ts->disable_depth) &&
500 + tsc2005_ts_update_pen_state(ts, 0, 0, 0);
501 + ts->sample_sent = 0;
506 + * This interrupt is called when pen is down and coordinates are
507 + * available. That is indicated by a either:
508 + * a) a rising edge on PINTDAV or (PENDAV mode)
509 + * b) a falling edge on DAV line (DAV mode)
510 + * depending on the setting of the IRQ bits in the CFR2 setting above.
512 +static irqreturn_t tsc2005_ts_irq_handler(int irq, void *dev_id)
514 + struct tsc2005 *ts = dev_id;
515 + if (ts->disable_depth)
518 + if (!ts->spi_pending) {
519 + if (spi_async(ts->spi, &ts->read_msg)) {
520 + dev_err(&ts->spi->dev, "ts: spi_async() failed");
524 + /* By shifting in 1s we can never wrap */
525 + ts->spi_pending = (ts->spi_pending<<1)+1;
527 + /* Kick pen up timer only if it's not been started yet. Strictly,
528 + * it isn't even necessary to start it at all here, but doing so
529 + * keeps an equivalence between pen state and timer state.
530 + * The SPI read loop will keep pushing it into the future.
531 + * If it times out with an SPI pending, it's ignored anyway.
533 + if (!timer_pending(&ts->penup_timer)) {
534 + unsigned long pu = msecs_to_jiffies(TSC2005_TS_PENUP_TIME);
535 + ts->penup_timer.expires = jiffies + pu;
536 + add_timer(&ts->penup_timer);
539 + return IRQ_HANDLED;
542 +static void tsc2005_ts_setup_spi_xfer(struct tsc2005 *ts)
544 + struct spi_message *m = &ts->read_msg;
545 + struct spi_transfer *x = &ts->read_xfer[0];
548 + spi_message_init(m);
550 + for (i = 0; i < NUM_READ_REGS; i++, x++) {
551 + x->tx_buf = &tsc2005_read_reg[i];
552 + x->rx_buf = &ts->data[i];
554 + x->bits_per_word = 24;
555 + x->cs_change = i < (NUM_READ_REGS - 1);
556 + spi_message_add_tail(x, m);
559 + m->complete = tsc2005_ts_rx;
563 +static ssize_t tsc2005_ts_pen_down_show(struct device *dev,
564 + struct device_attribute *attr,
567 + struct tsc2005 *ts = dev_get_drvdata(dev);
569 + return sprintf(buf, "%u\n", ts->pen_down);
572 +static DEVICE_ATTR(pen_down, S_IRUGO, tsc2005_ts_pen_down_show, NULL);
574 +static int tsc2005_configure(struct tsc2005 *ts, int flags)
576 + tsc2005_write(ts, TSC2005_REG_CFR0, TSC2005_CFR0_INITVALUE);
577 + tsc2005_write(ts, TSC2005_REG_CFR1, TSC2005_CFR1_INITVALUE);
578 + tsc2005_write(ts, TSC2005_REG_CFR2, TSC2005_CFR2_INITVALUE);
579 + tsc2005_cmd(ts, flags);
584 +static void tsc2005_start_scan(struct tsc2005 *ts)
586 + tsc2005_configure(ts, TSC2005_CMD_SCAN_XYZZ);
589 +static void tsc2005_stop_scan(struct tsc2005 *ts)
591 + tsc2005_cmd(ts, TSC2005_CMD_STOP);
594 +/* Must be called with mutex held */
595 +static void tsc2005_disable(struct tsc2005 *ts)
597 + if (ts->disable_depth++ != 0)
600 + disable_irq(ts->spi->irq);
601 + if (ts->esd_timeout)
602 + del_timer(&ts->esd_timer);
604 + /* wait until penup timer expire normally */
607 + } while (ts->sample_sent);
609 + tsc2005_stop_scan(ts);
612 +static void tsc2005_enable(struct tsc2005 *ts)
614 + if (ts->disable_depth != 1)
617 + if (ts->esd_timeout) {
618 + unsigned long wdj = msecs_to_jiffies(ts->esd_timeout);
619 + ts->esd_timer.expires = round_jiffies(jiffies+wdj);
620 + add_timer(&ts->esd_timer);
622 + tsc2005_start_scan(ts);
623 + enable_irq(ts->spi->irq);
625 + --ts->disable_depth;
628 +static ssize_t tsc2005_disable_show(struct device *dev,
629 + struct device_attribute *attr, char *buf)
631 + struct tsc2005 *ts = dev_get_drvdata(dev);
633 + return sprintf(buf, "%u\n", ts->disabled);
636 +static ssize_t tsc2005_disable_store(struct device *dev,
637 + struct device_attribute *attr,
638 + const char *buf, size_t count)
640 + struct tsc2005 *ts = dev_get_drvdata(dev);
644 + if (strict_strtoul(buf, 10, &res) < 0)
648 + mutex_lock(&ts->mutex);
649 + if (i == ts->disabled)
654 + tsc2005_disable(ts);
656 + tsc2005_enable(ts);
658 + mutex_unlock(&ts->mutex);
662 +static DEVICE_ATTR(disable_ts, 0664, tsc2005_disable_show,
663 + tsc2005_disable_store);
665 +static ssize_t tsc2005_ctrl_selftest_show(struct device *dev,
666 + struct device_attribute *attr,
669 + u16 temp_high_orig, temp_high_test, temp_high;
670 + unsigned int result = 1;
671 + struct tsc2005 *ts = dev_get_drvdata(dev);
673 + if (!ts->set_reset) {
674 + dev_warn(&ts->spi->dev,
675 + "unable to selftest: reset not configured\n");
680 + mutex_lock(&ts->mutex);
681 + tsc2005_disable(ts);
683 + /* Test ctrl communications via temp high / low registers */
684 + tsc2005_read(ts, TSC2005_REG_TEMP_HIGH, &temp_high_orig);
686 + temp_high_test = (temp_high_orig - 1) & 0x0FFF;
688 + tsc2005_write(ts, TSC2005_REG_TEMP_HIGH, temp_high_test);
690 + tsc2005_read(ts, TSC2005_REG_TEMP_HIGH, &temp_high);
692 + if (temp_high != temp_high_test) {
694 + dev_warn(dev, "selftest failed: %d != %d\n",
695 + temp_high, temp_high_test);
700 + msleep(1); /* only 10us required */
703 + tsc2005_enable(ts);
705 + /* Test that reset really happened */
706 + tsc2005_read(ts, TSC2005_REG_TEMP_HIGH, &temp_high);
708 + if (temp_high != temp_high_orig) {
710 + dev_warn(dev, "selftest failed after reset: "
712 + temp_high, temp_high_orig);
715 + mutex_unlock(&ts->mutex);
718 + return sprintf(buf, "%u\n", result);
721 +static DEVICE_ATTR(ts_ctrl_selftest, S_IRUGO, tsc2005_ctrl_selftest_show, NULL);
723 +static void tsc2005_esd_timer_handler(unsigned long data)
725 + struct tsc2005 *ts = (struct tsc2005 *)data;
726 + if (!ts->disable_depth)
727 + schedule_work(&ts->esd_work);
730 +static void tsc2005_rst_handler(struct work_struct *work)
733 + struct tsc2005 *ts = container_of(work, struct tsc2005, esd_work);
736 + mutex_lock(&ts->mutex);
738 + /* If we are disabled, or the a touch has been detected,
739 + * then ignore this timeout. The enable will restart the
740 + * watchdog, as it restarts scanning
742 + if (ts->disable_depth)
745 + /* If we cannot read our known value from configuration register 0
746 + * then reset the controller as if from power-up and start
747 + * scanning again. Always re-arm the watchdog.
749 + tsc2005_read(ts, TSC2005_REG_CFR0, ®_val);
750 + if ((reg_val ^ TSC2005_CFR0_INITVALUE) & TSC2005_CFR0_RW_MASK) {
751 + dev_info(&ts->spi->dev, "TSC not responding, resetting.\n");
752 + /* If this timer kicked in, the penup timer, if ever active
753 + * at all, must have expired ages ago, so no need to del it.
756 + if (ts->sample_sent) {
757 + tsc2005_ts_update_pen_state(ts, 0, 0, 0);
758 + ts->sample_sent = 0;
760 + ts->spi_pending = 0;
761 + msleep(1); /* only 10us required */
763 + tsc2005_start_scan(ts);
765 + wdj = msecs_to_jiffies(ts->esd_timeout);
766 + mod_timer(&ts->esd_timer, round_jiffies(jiffies+wdj));
769 + mutex_unlock(&ts->mutex);
772 +static int __devinit tsc2005_ts_init(struct tsc2005 *ts,
773 + struct tsc2005_platform_data *pdata)
775 + struct input_dev *idev;
779 + init_timer(&ts->penup_timer);
780 + setup_timer(&ts->penup_timer, tsc2005_ts_penup_timer_handler,
781 + (unsigned long)ts);
783 + spin_lock_init(&ts->lock);
784 + mutex_init(&ts->mutex);
786 + ts->x_plate_ohm = pdata->ts_x_plate_ohm ? : 280;
787 + ts->hw_avg_max = pdata->ts_hw_avg;
788 + ts->stab_time = pdata->ts_stab_time;
789 + x_max = pdata->ts_x_max ? : 4096;
790 + ts->fudge_x = pdata->ts_x_fudge ? : 4;
791 + y_max = pdata->ts_y_max ? : 4096;
792 + ts->fudge_y = pdata->ts_y_fudge ? : 8;
793 + ts->p_max = pdata->ts_pressure_max ? : MAX_12BIT;
794 + ts->touch_pressure = pdata->ts_touch_pressure ? : ts->p_max;
795 + ts->fudge_p = pdata->ts_pressure_fudge ? : 2;
797 + ts->set_reset = pdata->set_reset;
799 + idev = input_allocate_device();
800 + if (idev == NULL) {
805 + idev->name = "TSC2005 touchscreen";
806 + snprintf(ts->phys, sizeof(ts->phys), "%s/input-ts",
807 + dev_name(&ts->spi->dev));
808 + idev->phys = ts->phys;
810 + idev->evbit[0] = BIT(EV_ABS) | BIT(EV_KEY);
811 + idev->absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE);
812 + idev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
815 + tsc2005_ts_setup_spi_xfer(ts);
817 + input_set_abs_params(idev, ABS_X, 0, x_max, ts->fudge_x, 0);
818 + input_set_abs_params(idev, ABS_Y, 0, y_max, ts->fudge_y, 0);
819 + input_set_abs_params(idev, ABS_PRESSURE, 0, ts->p_max, ts->fudge_p, 0);
821 + tsc2005_start_scan(ts);
823 + r = request_irq(ts->spi->irq, tsc2005_ts_irq_handler,
824 + (((TSC2005_CFR2_INITVALUE & TSC2005_CFR2_IRQ_MASK) ==
825 + TSC2005_CFR2_IRQ_PENDAV)
826 + ? IRQF_TRIGGER_RISING
827 + : IRQF_TRIGGER_FALLING) |
828 + IRQF_DISABLED, "tsc2005", ts);
830 + dev_err(&ts->spi->dev, "unable to get DAV IRQ");
834 + set_irq_wake(ts->spi->irq, 1);
836 + r = input_register_device(idev);
838 + dev_err(&ts->spi->dev, "can't register touchscreen device\n");
842 + /* We can tolerate these failing */
843 + r = device_create_file(&ts->spi->dev, &dev_attr_ts_ctrl_selftest);
845 + dev_warn(&ts->spi->dev, "can't create sysfs file for %s: %d\n",
846 + dev_attr_ts_ctrl_selftest.attr.name, r);
848 + r = device_create_file(&ts->spi->dev, &dev_attr_pen_down);
850 + dev_warn(&ts->spi->dev, "can't create sysfs file for %s: %d\n",
851 + dev_attr_pen_down.attr.name, r);
853 + r = device_create_file(&ts->spi->dev, &dev_attr_disable_ts);
855 + dev_warn(&ts->spi->dev, "can't create sysfs file for %s: %d\n",
856 + dev_attr_disable_ts.attr.name, r);
858 + /* Finally, configure and start the optional EDD watchdog. */
859 + ts->esd_timeout = pdata->esd_timeout;
860 + if (ts->esd_timeout && ts->set_reset) {
862 + setup_timer(&ts->esd_timer, tsc2005_esd_timer_handler,
863 + (unsigned long)ts);
864 + INIT_WORK(&ts->esd_work, tsc2005_rst_handler);
865 + wdj = msecs_to_jiffies(ts->esd_timeout);
866 + ts->esd_timer.expires = round_jiffies(jiffies+wdj);
867 + add_timer(&ts->esd_timer);
872 + free_irq(ts->spi->irq, ts);
874 + tsc2005_stop_scan(ts);
875 + input_free_device(idev);
880 +static int __devinit tsc2005_probe(struct spi_device *spi)
882 + struct tsc2005 *ts;
883 + struct tsc2005_platform_data *pdata = spi->dev.platform_data;
886 + if (spi->irq < 0) {
887 + dev_dbg(&spi->dev, "no irq?\n");
891 + dev_dbg(&spi->dev, "no platform data?\n");
895 + ts = kzalloc(sizeof(*ts), GFP_KERNEL);
899 + dev_set_drvdata(&spi->dev, ts);
901 + spi->dev.power.power_state = PMSG_ON;
903 + spi->mode = SPI_MODE_0;
904 + spi->bits_per_word = 8;
905 + /* The max speed might've been defined by the board-specific
907 + if (!spi->max_speed_hz)
908 + spi->max_speed_hz = TSC2005_HZ;
912 + r = tsc2005_ts_init(ts, pdata);
923 +static int __devexit tsc2005_remove(struct spi_device *spi)
925 + struct tsc2005 *ts = dev_get_drvdata(&spi->dev);
927 + mutex_lock(&ts->mutex);
928 + tsc2005_disable(ts);
929 + mutex_unlock(&ts->mutex);
931 + device_remove_file(&ts->spi->dev, &dev_attr_disable_ts);
932 + device_remove_file(&ts->spi->dev, &dev_attr_pen_down);
933 + device_remove_file(&ts->spi->dev, &dev_attr_ts_ctrl_selftest);
935 + free_irq(ts->spi->irq, ts);
936 + input_unregister_device(ts->idev);
938 + if (ts->esd_timeout)
939 + del_timer(&ts->esd_timer);
946 +static int tsc2005_suspend(struct spi_device *spi, pm_message_t mesg)
948 + struct tsc2005 *ts = dev_get_drvdata(&spi->dev);
950 + mutex_lock(&ts->mutex);
951 + tsc2005_disable(ts);
952 + mutex_unlock(&ts->mutex);
957 +static int tsc2005_resume(struct spi_device *spi)
959 + struct tsc2005 *ts = dev_get_drvdata(&spi->dev);
961 + mutex_lock(&ts->mutex);
962 + tsc2005_enable(ts);
963 + mutex_unlock(&ts->mutex);
969 +static struct spi_driver tsc2005_driver = {
972 + .owner = THIS_MODULE,
975 + .suspend = tsc2005_suspend,
976 + .resume = tsc2005_resume,
978 + .probe = tsc2005_probe,
979 + .remove = __devexit_p(tsc2005_remove),
982 +static int __init tsc2005_init(void)
984 + printk(KERN_INFO "TSC2005 driver initializing\n");
986 + return spi_register_driver(&tsc2005_driver);
988 +module_init(tsc2005_init);
990 +static void __exit tsc2005_exit(void)
992 + spi_unregister_driver(&tsc2005_driver);
994 +module_exit(tsc2005_exit);
996 +MODULE_AUTHOR("Lauri Leukkunen <lauri.leukkunen@nokia.com>");
997 +MODULE_LICENSE("GPL");
998 +MODULE_ALIAS("platform:tsc2005");
1000 +++ linux-2.6.35/include/linux/spi/tsc2005.h
1002 +#ifndef _LINUX_SPI_TSC2005_H
1003 +#define _LINUX_SPI_TSC2005_H
1005 +#include <linux/types.h>
1007 +struct tsc2005_platform_data {
1008 + u16 ts_x_plate_ohm;
1009 + u32 ts_stab_time; /* voltage settling time */
1010 + u8 ts_hw_avg; /* HW assiseted averaging. Can be
1011 + 0, 4, 8, 16 samples per reading */
1012 + u32 ts_touch_pressure; /* Pressure limit until we report a
1013 + touch event. After that we switch
1014 + to ts_max_pressure. */
1015 + u32 ts_pressure_max;/* Samples with bigger pressure value will
1016 + be ignored, since the corresponding X, Y
1017 + values are unreliable */
1018 + u32 ts_pressure_fudge;
1024 + u32 esd_timeout; /* msec of inactivity before we check */
1026 + unsigned ts_ignore_last:1;
1028 + void (*set_reset)(bool enable);