]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/input/touchscreen/tsc2301_ts.c
fa42f21a6b95912c416974da1941370ab95d0880
[linux-2.6-omap-h63xx.git] / drivers / input / touchscreen / tsc2301_ts.c
1 /*
2  * TSC2301 touchscreen driver
3  *
4  * Copyright (C) 2005-2006 Nokia Corporation
5  *
6  * Written by Jarkko Oikarinen, Imre Deak and Juha Yrjola
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  *
22  */
23
24 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/input.h>
27 #include <linux/interrupt.h>
28 #include <linux/delay.h>
29 #include <linux/spi/spi.h>
30
31 #ifdef CONFIG_ARCH_OMAP
32 #include <asm/arch/gpio.h>
33 #endif
34
35 #include <linux/spi/tsc2301.h>
36
37 /**
38  * The touchscreen interface operates as follows:
39  *
40  * Initialize:
41  *    Request access to GPIO103 (DAV)
42  *    tsc2301_dav_irq_handler will trigger when DAV line goes down
43  *
44  *  1) Pen is pressed against touchscreeen
45  *  2) TSC2301 performs AD conversion
46  *  3) After the conversion is done TSC2301 drives DAV line down
47  *  4) GPIO IRQ is received and tsc2301_dav_irq_handler is called
48  *  5) tsc2301_dav_irq_handler sets up tsc2301_ts_timer in TSC2301_TS_SCAN_TIME
49  *  6) tsc2301_ts_timer disables the irq and requests spi driver
50  *     to read X, Y, Z1 and Z2
51  *  7) SPI framework calls tsc2301_ts_rx after the coordinates are read
52  *  8) tsc2301_ts_rx reports coordinates to input layer and
53  *     sets up tsc2301_ts_timer to be called after TSC2301_TS_SCAN_TIME
54  *  9) if tsc2301_tx_timer notices that the pen has been lifted, the lift event
55  *     is sent, and irq is again enabled.
56  */
57
58
59 #define TSC2301_TOUCHSCREEN_PRODUCT_ID                  0x0052
60 #define TSC2301_TOUCHSCREEN_PRODUCT_VERSION             0x0001
61
62 #define TSC2301_TS_SCAN_TIME                            1
63
64 #define TSC2301_ADCREG_CONVERSION_CTRL_BY_TSC2301       0x8000
65 #define TSC2301_ADCREG_CONVERSION_CTRL_BY_HOST          0x0000
66
67 #define TSC2301_ADCREG_FUNCTION_NONE                    0x0000
68 #define TSC2301_ADCREG_FUNCTION_XY                      0x0400
69 #define TSC2301_ADCREG_FUNCTION_XYZ                     0x0800
70 #define TSC2301_ADCREG_FUNCTION_X                       0x0C00
71 #define TSC2301_ADCREG_FUNCTION_Y                       0x1000
72 #define TSC2301_ADCREG_FUNCTION_Z                       0x1400
73 #define TSC2301_ADCREG_FUNCTION_DAT1                    0x1800
74 #define TSC2301_ADCREG_FUNCTION_DAT2                    0x1C00
75 #define TSC2301_ADCREG_FUNCTION_AUX1                    0x2000
76 #define TSC2301_ADCREG_FUNCTION_AUX2                    0x2400
77 #define TSC2301_ADCREG_FUNCTION_TEMP                    0x2800
78
79 #define TSC2301_ADCREG_RESOLUTION_8BIT                  0x0100
80 #define TSC2301_ADCREG_RESOLUTION_10BIT                 0x0200
81 #define TSC2301_ADCREG_RESOLUTION_12BIT                 0x0300
82
83 #define TSC2301_ADCREG_AVERAGING_NONE                   0x0000
84 #define TSC2301_ADCREG_AVERAGING_4AVG                   0x0040
85 #define TSC2301_ADCREG_AVERAGING_8AVG                   0x0080
86 #define TSC2301_ADCREG_AVERAGING_16AVG                  0x00C0
87
88 #define TSC2301_ADCREG_CLOCK_8MHZ                       0x0000
89 #define TSC2301_ADCREG_CLOCK_4MHZ                       0x0010
90 #define TSC2301_ADCREG_CLOCK_2MHZ                       0x0020
91 #define TSC2301_ADCREG_CLOCK_1MHZ                       0x0030
92
93 #define TSC2301_ADCREG_VOLTAGE_STAB_0US                 0x0000
94 #define TSC2301_ADCREG_VOLTAGE_STAB_100US               0x0002
95 #define TSC2301_ADCREG_VOLTAGE_STAB_500US               0x0004
96 #define TSC2301_ADCREG_VOLTAGE_STAB_1MS                 0x0006
97 #define TSC2301_ADCREG_VOLTAGE_STAB_5MS                 0x0008
98 #define TSC2301_ADCREG_VOLTAGE_STAB_10MS                0x000A
99 #define TSC2301_ADCREG_VOLTAGE_STAB_50MS                0x000C
100 #define TSC2301_ADCREG_VOLTAGE_STAB_100MS               0x000E
101
102 #define TSC2301_ADCREG_STOP_CONVERSION                  0x4000
103
104 #define MAX_12BIT                                       ((1 << 12) - 1)
105
106 struct tsc2301_ts {
107         struct input_dev        *idev;
108         char                    phys[32];
109         struct timer_list       timer;
110         spinlock_t              lock;
111
112         struct spi_transfer     read_xfer[2];
113         struct spi_message      read_msg;
114         u16                     data[4];
115
116         int                     hw_avg_max;
117         u16                     x;
118         u16                     y;
119         u16                     p;
120         int                     sample_cnt;
121
122         int                     ignore_last : 1;
123         u16                     x_plate_ohm;
124         int                     stab_time;
125         int                     max_pressure;
126         int                     touch_pressure;
127         int                     pressure_limit;
128
129         u16                     irq_enabled:1;
130         u16                     pen_down:1;
131         u16                     disabled:1;
132         u16                     pending:1;
133
134         int                     hw_flags;
135
136         s16                     dav_gpio;
137         int                     irq;
138 };
139
140
141 static const u16 tsc2301_ts_read_data = 0x8000 | TSC2301_REG_X;
142
143 static int tsc2301_ts_check_config(struct tsc2301_ts *ts, int *hw_flags)
144 {
145         int flags;
146
147         flags = 0;
148         switch (ts->hw_avg_max) {
149         case 0:
150                 flags |= TSC2301_ADCREG_AVERAGING_NONE;
151                 break;
152         case 4:
153                 flags |= TSC2301_ADCREG_AVERAGING_4AVG;
154                 break;
155         case 8:
156                 flags |= TSC2301_ADCREG_AVERAGING_8AVG;
157                 break;
158         case 16:
159                 flags |= TSC2301_ADCREG_AVERAGING_16AVG;
160                 break;
161         default:
162                 return -EINVAL;
163         }
164
165         switch (ts->stab_time) {
166         case 0:
167                 flags |= TSC2301_ADCREG_VOLTAGE_STAB_0US;
168                 break;
169         case 100:
170                 flags |= TSC2301_ADCREG_VOLTAGE_STAB_100US;
171                 break;
172         case 500:
173                 flags |= TSC2301_ADCREG_VOLTAGE_STAB_500US;
174                 break;
175         case 1000:
176                 flags |= TSC2301_ADCREG_VOLTAGE_STAB_1MS;
177                 break;
178         case 5000:
179                 flags |= TSC2301_ADCREG_VOLTAGE_STAB_5MS;
180                 break;
181         case 10000:
182                 flags |= TSC2301_ADCREG_VOLTAGE_STAB_10MS;
183                 break;
184         case 50000:
185                 flags |= TSC2301_ADCREG_VOLTAGE_STAB_50MS;
186                 break;
187         case 100000:
188                 flags |= TSC2301_ADCREG_VOLTAGE_STAB_100MS;
189                 break;
190         default:
191                 return -EINVAL;
192         }
193
194         *hw_flags = flags;
195         return 0;
196 }
197
198 /*
199  * This odd three-time initialization is to work around a bug in TSC2301.
200  * See TSC2301 errata for details.
201  */
202 static int tsc2301_ts_configure(struct tsc2301 *tsc, int flags)
203 {
204         struct spi_transfer xfer[3];
205         struct spi_transfer *x;
206         struct spi_message m;
207         int reg = TSC2301_REG_ADC;
208         u16 val1, val2, val3;
209         u16 data[6];
210
211         val1 = TSC2301_ADCREG_CONVERSION_CTRL_BY_HOST |
212                 TSC2301_ADCREG_STOP_CONVERSION |
213                 TSC2301_ADCREG_FUNCTION_NONE |
214                 TSC2301_ADCREG_RESOLUTION_12BIT |
215                 TSC2301_ADCREG_AVERAGING_NONE |
216                 TSC2301_ADCREG_CLOCK_2MHZ |
217                 TSC2301_ADCREG_VOLTAGE_STAB_100MS;
218
219         val2 = TSC2301_ADCREG_CONVERSION_CTRL_BY_HOST |
220                 TSC2301_ADCREG_FUNCTION_XYZ |
221                 TSC2301_ADCREG_RESOLUTION_12BIT |
222                 TSC2301_ADCREG_AVERAGING_16AVG |
223                 TSC2301_ADCREG_CLOCK_1MHZ |
224                 TSC2301_ADCREG_VOLTAGE_STAB_100MS;
225
226         /* Averaging and voltage stabilization settings in flags */
227         val3 = TSC2301_ADCREG_CONVERSION_CTRL_BY_TSC2301 |
228                 TSC2301_ADCREG_FUNCTION_XYZ |
229                 TSC2301_ADCREG_RESOLUTION_12BIT |
230                 TSC2301_ADCREG_CLOCK_1MHZ |
231                 flags;
232
233         /* Now we prepare the command for transferring */
234         data[0] = reg;
235         data[1] = val1;
236         data[2] = reg;
237         data[3] = val2;
238         data[4] = reg;
239         data[5] = val3;
240
241         spi_message_init(&m);
242         m.spi = tsc->spi;
243
244         memset(xfer, 0, sizeof(xfer));
245         x = &xfer[0];
246
247         x->tx_buf = &data[0];
248         x->len = 4;
249         x->cs_change = 1;
250         spi_message_add_tail(x, &m);
251
252         x++;
253         x->tx_buf = &data[2];
254         x->len = 4;
255         x->cs_change = 1;
256         spi_message_add_tail(x, &m);
257
258         x++;
259         x->tx_buf = &data[4];
260         x->len = 4;
261         spi_message_add_tail(x, &m);
262
263         spi_sync(m.spi, &m);
264
265         return 0;
266 }
267
268 static void tsc2301_ts_start_scan(struct tsc2301 *tsc)
269 {
270         tsc2301_ts_configure(tsc, tsc->ts->hw_flags);
271 }
272
273 static void tsc2301_ts_stop_scan(struct tsc2301 *tsc)
274 {
275         tsc2301_ts_configure(tsc, TSC2301_ADCREG_STOP_CONVERSION);
276 }
277
278 static int device_suspended(struct device *dev)
279 {
280         struct tsc2301 *tsc = dev_get_drvdata(dev);
281         return dev->power.power_state.event != PM_EVENT_ON || tsc->ts->disabled;
282 }
283
284 static void update_pen_state(struct tsc2301_ts *ts, int x, int y, int pressure)
285 {
286         int sync = 0;
287
288         if (pressure) {
289                 input_report_abs(ts->idev, ABS_X, x);
290                 input_report_abs(ts->idev, ABS_Y, y);
291                 input_report_abs(ts->idev, ABS_PRESSURE, pressure);
292                 if (!ts->pen_down)
293                         input_report_key(ts->idev, BTN_TOUCH, 1);
294                 sync = 1;
295         } else if (ts->pen_down) {
296                 input_report_abs(ts->idev, ABS_PRESSURE, 0);
297                 input_report_key(ts->idev, BTN_TOUCH, 0);
298                 sync = 1;
299         }
300
301         if (sync)
302                 input_sync(ts->idev);
303
304         ts->pen_down = pressure ? 1 : 0;
305 #ifdef VERBOSE
306         dev_dbg(&tsc->spi->dev, "x %4d y %4d p %4d\n", x, y, pressure);
307 #endif
308 }
309
310 /*
311  * This procedure is called by the SPI framework after the coordinates
312  * have been read from TSC2301
313  */
314 static void tsc2301_ts_rx(void *arg)
315 {
316         struct tsc2301 *tsc = arg;
317         struct tsc2301_ts *ts = tsc->ts;
318         unsigned int x, y, z1, z2, pressure;
319
320         x  = ts->data[0];
321         y  = ts->data[1];
322         z1 = ts->data[2];
323         z2 = ts->data[3];
324
325         if (z1) {
326                 pressure = ts->x_plate_ohm * x;
327                 pressure /= 4096;
328                 pressure *= z2 - z1;
329                 pressure /= z1;
330         } else
331                 pressure = 0;
332
333         /* If pressure value is above a preset limit (pen is barely
334          * touching the screen) we can't trust the coordinate values.
335          */
336         if (pressure < ts->pressure_limit && x < MAX_12BIT && y < MAX_12BIT) {
337                 ts->pressure_limit = ts->max_pressure;
338                 if (ts->ignore_last) {
339                         if (ts->sample_cnt)
340                                 update_pen_state(ts, ts->x, ts->y, ts->p);
341                         ts->x = x;
342                         ts->y = y;
343                         ts->p = pressure;
344                 } else
345                         update_pen_state(ts, x, y, pressure);
346                 ts->sample_cnt++;
347         }
348
349         mod_timer(&ts->timer,
350                   jiffies + msecs_to_jiffies(TSC2301_TS_SCAN_TIME));
351 }
352
353 static int is_pen_down(struct tsc2301_ts *ts)
354 {
355         return ts->pen_down;
356 }
357
358 /*
359  * Timer is called every TSC2301_TS_SCAN_TIME when the pen is down
360  */
361 static void tsc2301_ts_timer(unsigned long arg)
362 {
363         struct tsc2301 *tsc = (void *) arg;
364         struct tsc2301_ts *ts = tsc->ts;
365         unsigned long flags;
366         int ndav;
367         int r;
368
369         spin_lock_irqsave(&ts->lock, flags);
370         ndav = omap_get_gpio_datain(ts->dav_gpio);
371         if (ndav || device_suspended(&tsc->spi->dev)) {
372                 /* Pen has been lifted */
373                 if (!device_suspended(&tsc->spi->dev)) {
374                         ts->irq_enabled = 1;
375                         enable_irq(ts->irq);
376                 }
377                 update_pen_state(ts, 0, 0, 0);
378                 ts->pending = 0;
379                 spin_unlock_irqrestore(&ts->lock, flags);
380
381         } else {
382                 ts->pen_down = 1;
383                 spin_unlock_irqrestore(&ts->lock, flags);
384
385                 r = spi_async(tsc->spi, &ts->read_msg);
386                 if (r)
387                         dev_err(&tsc->spi->dev, "ts: spi_async() failed");
388         }
389 }
390
391 /*
392  * This interrupt is called when pen is down and first coordinates are
393  * available. That is indicated by a falling edge on DEV line.  IRQ is
394  * disabled here because while the pen is down the coordinates are
395  * read by a timer.
396  */
397 static irqreturn_t tsc2301_ts_irq_handler(int irq, void *dev_id)
398 {
399         struct tsc2301 *tsc = dev_id;
400         struct tsc2301_ts *ts = tsc->ts;
401         unsigned long flags;
402
403         spin_lock_irqsave(&ts->lock, flags);
404         if (ts->irq_enabled) {
405                 ts->irq_enabled = 0;
406                 disable_irq(ts->irq);
407                 ts->pending = 1;
408                 ts->pressure_limit = ts->touch_pressure;
409                 ts->sample_cnt = 0;
410                 mod_timer(&ts->timer,
411                           jiffies + msecs_to_jiffies(TSC2301_TS_SCAN_TIME));
412         }
413         spin_unlock_irqrestore(&ts->lock, flags);
414
415         return IRQ_HANDLED;
416 }
417
418 /* Must be called with ts->lock held */
419 static void tsc2301_ts_disable(struct tsc2301 *tsc)
420 {
421         struct tsc2301_ts *ts = tsc->ts;
422
423         if (ts->disabled)
424                 return;
425
426         ts->disabled = 1;
427         if (!ts->pending) {
428                 ts->irq_enabled = 0;
429                 disable_irq(ts->irq);
430         } else {
431                 while (ts->pending) {
432                         spin_unlock_irq(&ts->lock);
433                         msleep(1);
434                         spin_lock_irq(&ts->lock);
435                 }
436         }
437
438         spin_unlock_irq(&ts->lock);
439         tsc2301_ts_stop_scan(tsc);
440         /* Workaround a bug where turning on / off touchscreen scanner
441          * can get the keypad scanner stuck.
442          */
443         tsc2301_kp_restart(tsc);
444         spin_lock_irq(&ts->lock);
445 }
446
447 static void tsc2301_ts_enable(struct tsc2301 *tsc)
448 {
449         struct tsc2301_ts *ts = tsc->ts;
450
451         if (!ts->disabled)
452                 return;
453
454         ts->disabled = 0;
455         ts->irq_enabled = 1;
456         enable_irq(ts->irq);
457
458         spin_unlock_irq(&ts->lock);
459         tsc2301_ts_start_scan(tsc);
460         /* Same workaround as above. */
461         tsc2301_kp_restart(tsc);
462         spin_lock_irq(&ts->lock);
463 }
464
465 #ifdef CONFIG_PM
466 int tsc2301_ts_suspend(struct tsc2301 *tsc)
467 {
468         struct tsc2301_ts *ts = tsc->ts;
469
470         spin_lock_irq(&ts->lock);
471         tsc2301_ts_disable(tsc);
472         spin_unlock_irq(&ts->lock);
473
474         return 0;
475 }
476
477 void tsc2301_ts_resume(struct tsc2301 *tsc)
478 {
479         struct tsc2301_ts *ts = tsc->ts;
480
481         spin_lock_irq(&ts->lock);
482         tsc2301_ts_enable(tsc);
483         spin_unlock_irq(&ts->lock);
484 }
485 #endif
486
487 static void tsc2301_ts_setup_spi_xfer(struct tsc2301 *tsc)
488 {
489         struct tsc2301_ts *ts = tsc->ts;
490         struct spi_message *m = &ts->read_msg;
491         struct spi_transfer *x = &ts->read_xfer[0];
492
493         spi_message_init(m);
494
495         x->tx_buf = &tsc2301_ts_read_data;
496         x->len = 2;
497         spi_message_add_tail(x, m);
498
499         x++;
500         x->rx_buf = &ts->data;
501         x->len = 8;
502         spi_message_add_tail(x, m);
503
504         m->complete = tsc2301_ts_rx;
505         m->context = tsc;
506 }
507
508 static ssize_t tsc2301_ts_pen_down_show(struct device *dev,
509                                         struct device_attribute *attr,
510                                         char *buf)
511 {
512         struct tsc2301 *tsc = dev_get_drvdata(dev);
513
514         return sprintf(buf, "%u\n", is_pen_down(tsc->ts));
515 }
516
517 static DEVICE_ATTR(pen_down, S_IRUGO, tsc2301_ts_pen_down_show, NULL);
518
519 static ssize_t tsc2301_ts_disable_show(struct device *dev,
520                                        struct device_attribute *attr, char *buf)
521 {
522         struct tsc2301          *tsc = dev_get_drvdata(dev);
523         struct tsc2301_ts       *ts = tsc->ts;
524
525         return sprintf(buf, "%u\n", ts->disabled);
526 }
527
528 static ssize_t tsc2301_ts_disable_store(struct device *dev,
529                                         struct device_attribute *attr,
530                                         const char *buf, size_t count)
531 {
532         struct tsc2301          *tsc = dev_get_drvdata(dev);
533         struct tsc2301_ts       *ts = tsc->ts;
534         char *endp;
535         int i;
536
537         i = simple_strtoul(buf, &endp, 10);
538         spin_lock_irq(&ts->lock);
539
540         if (i)
541                 tsc2301_ts_disable(tsc);
542         else
543                 tsc2301_ts_enable(tsc);
544
545         spin_unlock_irq(&ts->lock);
546
547         return count;
548 }
549
550 static DEVICE_ATTR(disable_ts, 0664, tsc2301_ts_disable_show,
551                    tsc2301_ts_disable_store);
552
553 int __devinit tsc2301_ts_init(struct tsc2301 *tsc,
554                               struct tsc2301_platform_data *pdata)
555 {
556         struct tsc2301_ts *ts;
557         struct input_dev *idev;
558         int dav_gpio, r;
559
560         if (pdata->dav_gpio < 0) {
561                 dev_err(&tsc->spi->dev, "need DAV GPIO");
562                 return -EINVAL;
563         }
564         dav_gpio = pdata->dav_gpio;
565
566         ts = kzalloc(sizeof(*ts), GFP_KERNEL);
567         if (ts == NULL)
568                 return -ENOMEM;
569         tsc->ts = ts;
570
571         ts->dav_gpio = dav_gpio;
572 #ifdef CONFIG_ARCH_OMAP
573         r = omap_request_gpio(dav_gpio);
574         if (r < 0) {
575                 dev_err(&tsc->spi->dev, "unable to get DAV GPIO");
576                 goto err1;
577         }
578         omap_set_gpio_direction(dav_gpio, 1);
579         ts->irq = OMAP_GPIO_IRQ(dav_gpio);
580 #endif
581         init_timer(&ts->timer);
582         ts->timer.data = (unsigned long) tsc;
583         ts->timer.function = tsc2301_ts_timer;
584
585         spin_lock_init(&ts->lock);
586
587         ts->x_plate_ohm = pdata->ts_x_plate_ohm ? : 280;
588         ts->hw_avg_max  = pdata->ts_hw_avg;
589         ts->max_pressure= pdata->ts_max_pressure ? : MAX_12BIT;
590         ts->touch_pressure = pdata->ts_touch_pressure ? : ts->max_pressure;
591         ts->ignore_last = pdata->ts_ignore_last;
592         ts->stab_time   = pdata->ts_stab_time;
593
594         if ((r = tsc2301_ts_check_config(ts, &ts->hw_flags))) {
595                 dev_err(&tsc->spi->dev, "invalid configuration\n");
596                 goto err2;
597         }
598
599         idev = input_allocate_device();
600         if (idev == NULL) {
601                 r = -ENOMEM;
602                 goto err2;
603         }
604         idev->name = "TSC2301 touchscreen";
605         snprintf(ts->phys, sizeof(ts->phys),
606                  "%s/input-ts", tsc->spi->dev.bus_id);
607         idev->phys = ts->phys;
608
609         idev->evbit[0] = BIT(EV_ABS) | BIT(EV_KEY);
610         idev->absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE);
611         ts->idev = idev;
612
613         tsc2301_ts_setup_spi_xfer(tsc);
614
615         /* These parameters should perhaps be configurable? */
616         input_set_abs_params(idev, ABS_X, 0, 4096, 0, 0);
617         input_set_abs_params(idev, ABS_Y, 0, 4096, 0, 0);
618         input_set_abs_params(idev, ABS_PRESSURE, 0, 1024, 0, 0);
619
620         tsc2301_ts_start_scan(tsc);
621
622         ts->irq_enabled = 1;
623         r = request_irq(ts->irq, tsc2301_ts_irq_handler,
624                         IRQF_SAMPLE_RANDOM | IRQF_TRIGGER_FALLING,
625                         "tsc2301-ts", tsc);
626         if (r < 0) {
627                 dev_err(&tsc->spi->dev, "unable to get DAV IRQ");
628                 goto err3;
629         }
630         set_irq_wake(ts->irq, 1);
631
632         if (device_create_file(&tsc->spi->dev, &dev_attr_pen_down) < 0)
633                 goto err4;
634         if (device_create_file(&tsc->spi->dev, &dev_attr_disable_ts) < 0)
635                 goto err5;
636
637         r = input_register_device(idev);
638         if (r < 0) {
639                 dev_err(&tsc->spi->dev, "can't register touchscreen device\n");
640                 goto err6;
641         }
642
643         return 0;
644 err6:
645         device_remove_file(&tsc->spi->dev, &dev_attr_disable_ts);
646 err5:
647         device_remove_file(&tsc->spi->dev, &dev_attr_pen_down);
648 err4:
649         free_irq(ts->irq, tsc);
650 err3:
651         tsc2301_ts_stop_scan(tsc);
652         input_free_device(idev);
653 err2:
654 #ifdef CONFIG_ARCH_OMAP
655         omap_free_gpio(dav_gpio);
656 #endif
657 err1:
658         kfree(ts);
659         return r;
660 }
661
662 void __devexit tsc2301_ts_exit(struct tsc2301 *tsc)
663 {
664         struct tsc2301_ts *ts = tsc->ts;
665         unsigned long flags;
666
667         spin_lock_irqsave(&ts->lock, flags);
668         tsc2301_ts_disable(tsc);
669         spin_unlock_irqrestore(&ts->lock, flags);
670
671         device_remove_file(&tsc->spi->dev, &dev_attr_disable_ts);
672         device_remove_file(&tsc->spi->dev, &dev_attr_pen_down);
673
674         free_irq(ts->irq, tsc);
675         input_unregister_device(ts->idev);
676
677 #ifdef CONFIG_ARCH_OMAP
678         omap_free_gpio(ts->dav_gpio);
679 #endif
680         kfree(ts);
681 }
682 MODULE_AUTHOR("Jarkko Oikarinen <jarkko.oikarinen@nokia.com>");
683 MODULE_LICENSE("GPL");