]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/input/touchscreen/tsc2301_ts.c
tsc2301 - Remove OMAP gpio from ts & kb driver
[linux-2.6-omap-h63xx.git] / drivers / input / touchscreen / tsc2301_ts.c
1 /*
2  * TSC2301 touchscreen driver
3  *
4  * Copyright (C) 2005-2008 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 #include <linux/spi/tsc2301.h>
32
33 /**
34  * The touchscreen interface operates as follows:
35  *
36  * Initialize:
37  *    Request access to GPIO103 (DAV)
38  *    tsc2301_ts_irq_handler will trigger when DAV line goes down
39  *
40  *  1) Pen is pressed against touchscreeen
41  *  2) TSC2301 performs AD conversion
42  *  3) After the conversion is done TSC2301 drives DAV line down
43  *  4) GPIO IRQ is received and tsc2301_ts_irq_handler is called
44  *  5) tsc2301_ts_irq_handler queues up an spi transfer to fetch
45  *     the x, y, z1, z2 values
46  *  6) SPI framework calls tsc2301_ts_rx after the coordinates are read
47  *  7) When the penup_timer expires, there have not been DAV interrupts
48  *     during the last 20ms which means the pen has been lifted.
49  */
50
51
52 #define TSC2301_TOUCHSCREEN_PRODUCT_ID                  0x0052
53 #define TSC2301_TOUCHSCREEN_PRODUCT_VERSION             0x0001
54
55 #define TSC2301_TS_PENUP_TIME                           20
56
57 #define TSC2301_ADCREG_CONVERSION_CTRL_BY_TSC2301       0x8000
58 #define TSC2301_ADCREG_CONVERSION_CTRL_BY_HOST          0x0000
59
60 #define TSC2301_ADCREG_FUNCTION_NONE                    0x0000
61 #define TSC2301_ADCREG_FUNCTION_XY                      0x0400
62 #define TSC2301_ADCREG_FUNCTION_XYZ                     0x0800
63 #define TSC2301_ADCREG_FUNCTION_X                       0x0C00
64 #define TSC2301_ADCREG_FUNCTION_Y                       0x1000
65 #define TSC2301_ADCREG_FUNCTION_Z                       0x1400
66 #define TSC2301_ADCREG_FUNCTION_DAT1                    0x1800
67 #define TSC2301_ADCREG_FUNCTION_DAT2                    0x1C00
68 #define TSC2301_ADCREG_FUNCTION_AUX1                    0x2000
69 #define TSC2301_ADCREG_FUNCTION_AUX2                    0x2400
70 #define TSC2301_ADCREG_FUNCTION_TEMP                    0x2800
71
72 #define TSC2301_ADCREG_RESOLUTION_8BIT                  0x0100
73 #define TSC2301_ADCREG_RESOLUTION_10BIT                 0x0200
74 #define TSC2301_ADCREG_RESOLUTION_12BIT                 0x0300
75
76 #define TSC2301_ADCREG_AVERAGING_NONE                   0x0000
77 #define TSC2301_ADCREG_AVERAGING_4AVG                   0x0040
78 #define TSC2301_ADCREG_AVERAGING_8AVG                   0x0080
79 #define TSC2301_ADCREG_AVERAGING_16AVG                  0x00C0
80
81 #define TSC2301_ADCREG_CLOCK_8MHZ                       0x0000
82 #define TSC2301_ADCREG_CLOCK_4MHZ                       0x0010
83 #define TSC2301_ADCREG_CLOCK_2MHZ                       0x0020
84 #define TSC2301_ADCREG_CLOCK_1MHZ                       0x0030
85
86 #define TSC2301_ADCREG_VOLTAGE_STAB_0US                 0x0000
87 #define TSC2301_ADCREG_VOLTAGE_STAB_100US               0x0002
88 #define TSC2301_ADCREG_VOLTAGE_STAB_500US               0x0004
89 #define TSC2301_ADCREG_VOLTAGE_STAB_1MS                 0x0006
90 #define TSC2301_ADCREG_VOLTAGE_STAB_5MS                 0x0008
91 #define TSC2301_ADCREG_VOLTAGE_STAB_10MS                0x000A
92 #define TSC2301_ADCREG_VOLTAGE_STAB_50MS                0x000C
93 #define TSC2301_ADCREG_VOLTAGE_STAB_100MS               0x000E
94
95 #define TSC2301_ADCREG_STOP_CONVERSION                  0x4000
96
97 #define MAX_12BIT                                       ((1 << 12) - 1)
98
99 #define TS_RECT_SIZE                                    8
100 #define TSF_MIN_Z1                                      100
101 #define TSF_MAX_Z2                                      4000
102
103 #define TSF_SAMPLES                                     4
104
105 struct ts_filter {
106         int                     sample_cnt;
107
108         int                     avg_x;
109         int                     avg_y;
110         int                     avg_z1;
111         int                     avg_z2;
112 };
113
114 struct tsc2301_ts {
115         struct input_dev        *idev;
116         char                    phys[32];
117         struct timer_list       penup_timer;
118         struct mutex            mutex;
119
120         struct spi_transfer     read_xfer[2];
121         struct spi_message      read_msg;
122         u16                     data[4];
123
124         struct ts_filter        filter;
125
126         int                     hw_avg_max;
127         u16                     x;
128         u16                     y;
129         u16                     p;
130
131         u16                     x_plate_ohm;
132         int                     stab_time;
133         int                     max_pressure;
134         int                     touch_pressure;
135
136         u8                      event_sent;
137         u8                      pen_down;
138         u8                      disabled;
139         u8                      disable_depth;
140
141         int                     hw_flags;
142         int                     irq;
143 };
144
145
146 static const u16 tsc2301_ts_read_data = 0x8000 | TSC2301_REG_X;
147
148 static int tsc2301_ts_check_config(struct tsc2301_ts *ts, int *hw_flags)
149 {
150         int flags;
151
152         flags = 0;
153         switch (ts->hw_avg_max) {
154         case 0:
155                 flags |= TSC2301_ADCREG_AVERAGING_NONE;
156                 break;
157         case 4:
158                 flags |= TSC2301_ADCREG_AVERAGING_4AVG;
159                 break;
160         case 8:
161                 flags |= TSC2301_ADCREG_AVERAGING_8AVG;
162                 break;
163         case 16:
164                 flags |= TSC2301_ADCREG_AVERAGING_16AVG;
165                 break;
166         default:
167                 return -EINVAL;
168         }
169
170         switch (ts->stab_time) {
171         case 0:
172                 flags |= TSC2301_ADCREG_VOLTAGE_STAB_0US;
173                 break;
174         case 100:
175                 flags |= TSC2301_ADCREG_VOLTAGE_STAB_100US;
176                 break;
177         case 500:
178                 flags |= TSC2301_ADCREG_VOLTAGE_STAB_500US;
179                 break;
180         case 1000:
181                 flags |= TSC2301_ADCREG_VOLTAGE_STAB_1MS;
182                 break;
183         case 5000:
184                 flags |= TSC2301_ADCREG_VOLTAGE_STAB_5MS;
185                 break;
186         case 10000:
187                 flags |= TSC2301_ADCREG_VOLTAGE_STAB_10MS;
188                 break;
189         case 50000:
190                 flags |= TSC2301_ADCREG_VOLTAGE_STAB_50MS;
191                 break;
192         case 100000:
193                 flags |= TSC2301_ADCREG_VOLTAGE_STAB_100MS;
194                 break;
195         default:
196                 return -EINVAL;
197         }
198
199         *hw_flags = flags;
200         return 0;
201 }
202
203 /*
204  * This odd three-time initialization is to work around a bug in TSC2301.
205  * See TSC2301 errata for details.
206  */
207 static int tsc2301_ts_configure(struct tsc2301 *tsc, int flags)
208 {
209         struct spi_transfer xfer[5];
210         struct spi_transfer *x;
211         struct spi_message m;
212         int i;
213         u16 val1, val2, val3;
214         u16 data[10];
215
216         val1 = TSC2301_ADCREG_CONVERSION_CTRL_BY_HOST |
217                 TSC2301_ADCREG_STOP_CONVERSION |
218                 TSC2301_ADCREG_FUNCTION_NONE |
219                 TSC2301_ADCREG_RESOLUTION_12BIT |
220                 TSC2301_ADCREG_AVERAGING_NONE |
221                 TSC2301_ADCREG_CLOCK_2MHZ |
222                 TSC2301_ADCREG_VOLTAGE_STAB_100MS;
223
224         val2 = TSC2301_ADCREG_CONVERSION_CTRL_BY_HOST |
225                 TSC2301_ADCREG_FUNCTION_XYZ |
226                 TSC2301_ADCREG_RESOLUTION_12BIT |
227                 TSC2301_ADCREG_AVERAGING_16AVG |
228                 TSC2301_ADCREG_CLOCK_1MHZ |
229                 TSC2301_ADCREG_VOLTAGE_STAB_100MS;
230
231         /* Averaging and voltage stabilization settings in flags */
232         val3 = TSC2301_ADCREG_CONVERSION_CTRL_BY_TSC2301 |
233                 TSC2301_ADCREG_FUNCTION_XYZ |
234                 TSC2301_ADCREG_RESOLUTION_12BIT |
235                 TSC2301_ADCREG_CLOCK_2MHZ |
236                 flags;
237
238         /* Now we prepare the command for transferring */
239         data[0] = TSC2301_REG_ADC;
240         data[1] = val1;
241         data[2] = TSC2301_REG_ADC;
242         data[3] = val2;
243         data[4] = TSC2301_REG_ADC;
244         data[5] = val3;
245         data[6] = TSC2301_REG_REF;
246         data[7] = 1 << 4 | 1 << 2 | 1; /* intref, 100uS settl, 2.5V ref */
247         data[8] = TSC2301_REG_CONFIG;
248         data[9] = 3 << 3 | 2 << 0; /* 340uS pre-chrg, 544us delay */
249
250         spi_message_init(&m);
251         m.spi = tsc->spi;
252
253         memset(xfer, 0, sizeof(xfer));
254         x = &xfer[0];
255
256         for (i = 0; i < 10; i += 2) {
257                 x->tx_buf = &data[i];
258                 x->len = 4;
259                 if (i != 8)
260                         x->cs_change = 1;
261                 spi_message_add_tail(x, &m);
262                 x++;
263         }
264         spi_sync(m.spi, &m);
265
266         return 0;
267 }
268
269 static void tsc2301_ts_start_scan(struct tsc2301 *tsc)
270 {
271         tsc2301_ts_configure(tsc, tsc->ts->hw_flags);
272         tsc2301_kp_restart(tsc);
273 }
274
275 static void tsc2301_ts_stop_scan(struct tsc2301 *tsc)
276 {
277         tsc2301_write_reg(tsc, TSC2301_REG_ADC, TSC2301_ADCREG_STOP_CONVERSION);
278         tsc2301_kp_restart(tsc);
279 }
280
281 static void update_pen_state(struct tsc2301_ts *ts, int x, int y, int pressure)
282 {
283         if (pressure) {
284                 input_report_abs(ts->idev, ABS_X, x);
285                 input_report_abs(ts->idev, ABS_Y, y);
286                 input_report_abs(ts->idev, ABS_PRESSURE, pressure);
287                 if (!ts->pen_down)
288                         input_report_key(ts->idev, BTN_TOUCH, 1);
289                 ts->pen_down = 1;
290         } else {
291                 input_report_abs(ts->idev, ABS_PRESSURE, 0);
292                 if (ts->pen_down)
293                         input_report_key(ts->idev, BTN_TOUCH, 0);
294                 ts->pen_down = 0;
295         }
296
297         input_sync(ts->idev);
298
299 #ifdef VERBOSE
300         dev_dbg(&tsc->spi->dev, "x %4d y %4d p %4d\n", x, y, pressure);
301 #endif
302 }
303
304 static int filter(struct tsc2301_ts *ts, int x, int y, int z1, int z2)
305 {
306         int inside_rect, pressure_limit, Rt;
307         struct ts_filter *tsf = &ts->filter;
308
309         /* validate pressure and position */
310         if (x > MAX_12BIT || y > MAX_12BIT)
311                 return 0;
312
313         /* skip coords if the pressure-components are out of range */
314         if (z1 < TSF_MIN_Z1 || z2 > TSF_MAX_Z2)
315                 return 0;
316
317         /* Use the x,y,z1,z2 directly on the first "pen down" event */
318         if (ts->event_sent) {
319                 tsf->avg_x  += x;
320                 tsf->avg_y  += y;
321                 tsf->avg_z1 += z1;
322                 tsf->avg_z2 += z2;
323
324                 if (++tsf->sample_cnt < TSF_SAMPLES)
325                         return 0;
326                 x = tsf->avg_x / TSF_SAMPLES;
327                 y = tsf->avg_y / TSF_SAMPLES;
328                 z1 = tsf->avg_z1 / TSF_SAMPLES;
329                 z2 = tsf->avg_z2 / TSF_SAMPLES;
330         }
331         tsf->sample_cnt = 0;
332         tsf->avg_x  = 0;
333         tsf->avg_y  = 0;
334         tsf->avg_z1 = 0;
335         tsf->avg_z2 = 0;
336
337         pressure_limit = ts->event_sent? ts->max_pressure: ts->touch_pressure;
338
339         /* z1 is always at least 100: */
340         Rt = x * (z2 - z1) / z1;
341         Rt = Rt * ts->x_plate_ohm / 4096;
342         if (Rt > pressure_limit)
343                 return 0;
344
345         /* discard the event if it still is within the previous rect - unless
346          * if the pressure is harder, but then use previous x,y position */
347         inside_rect = (
348             x > (int)ts->x - TS_RECT_SIZE && x < (int)ts->x + TS_RECT_SIZE &&
349             y > (int)ts->y - TS_RECT_SIZE && y < (int)ts->y + TS_RECT_SIZE);
350
351         if (!ts->event_sent || !inside_rect) {
352                 ts->x = x;
353                 ts->y = y;
354                 ts->p = Rt;
355                 return 1;
356         } else if (Rt < ts->p) {
357                 ts->p = Rt;
358                 return 1;
359         }
360         return 0;
361 }
362
363 /*
364  * This procedure is called by the SPI framework after the coordinates
365  * have been read from TSC2301
366  */
367 static void tsc2301_ts_rx(void *arg)
368 {
369         struct tsc2301 *tsc = arg;
370         struct tsc2301_ts *ts = tsc->ts;
371         int send_event;
372         int x, y, z1, z2;
373
374         x  = ts->data[0];
375         y  = ts->data[1];
376         z1 = ts->data[2];
377         z2 = ts->data[3];
378
379         send_event = filter(ts, x, y, z1, z2);
380         if (send_event) {
381                 update_pen_state(ts, ts->x, ts->y, ts->p);
382                 ts->event_sent = 1;
383         }
384
385         mod_timer(&ts->penup_timer,
386                   jiffies + msecs_to_jiffies(TSC2301_TS_PENUP_TIME));
387 }
388
389 /*
390  * Timer is called TSC2301_TS_PENUP_TIME after pen is up
391  */
392 static void tsc2301_ts_timer_handler(unsigned long data)
393 {
394         struct tsc2301 *tsc = (struct tsc2301 *)data;
395         struct tsc2301_ts *ts = tsc->ts;
396
397         if (ts->event_sent) {
398                 ts->event_sent = 0;
399                 update_pen_state(ts, 0, 0, 0);
400         }
401 }
402
403 /*
404  * This interrupt is called when pen is down and coordinates are
405  * available. That is indicated by a falling edge on DEV line.
406  */
407 static irqreturn_t tsc2301_ts_irq_handler(int irq, void *dev_id)
408 {
409         struct tsc2301 *tsc = dev_id;
410         struct tsc2301_ts *ts = tsc->ts;
411         int r;
412
413         r = spi_async(tsc->spi, &ts->read_msg);
414         if (r)
415                 dev_err(&tsc->spi->dev, "ts: spi_async() failed");
416
417         mod_timer(&ts->penup_timer,
418                   jiffies + msecs_to_jiffies(TSC2301_TS_PENUP_TIME));
419
420         return IRQ_HANDLED;
421 }
422
423 static void tsc2301_ts_disable(struct tsc2301 *tsc)
424 {
425         struct tsc2301_ts *ts = tsc->ts;
426
427         if (ts->disable_depth++ != 0)
428                 return;
429
430         disable_irq(ts->irq);
431
432         /* wait until penup timer expire normally */
433         do {
434                 msleep(1);
435         } while (ts->event_sent);
436
437         tsc2301_ts_stop_scan(tsc);
438 }
439
440 static void tsc2301_ts_enable(struct tsc2301 *tsc)
441 {
442         struct tsc2301_ts *ts = tsc->ts;
443
444         if (--ts->disable_depth != 0)
445                 return;
446
447         enable_irq(ts->irq);
448
449         tsc2301_ts_start_scan(tsc);
450 }
451
452 #ifdef CONFIG_PM
453 int tsc2301_ts_suspend(struct tsc2301 *tsc)
454 {
455         struct tsc2301_ts *ts = tsc->ts;
456
457         mutex_lock(&ts->mutex);
458         tsc2301_ts_disable(tsc);
459         mutex_unlock(&ts->mutex);
460
461         return 0;
462 }
463
464 void tsc2301_ts_resume(struct tsc2301 *tsc)
465 {
466         struct tsc2301_ts *ts = tsc->ts;
467
468         mutex_lock(&ts->mutex);
469         tsc2301_ts_enable(tsc);
470         mutex_unlock(&ts->mutex);
471 }
472 #endif
473
474 static void tsc2301_ts_setup_spi_xfer(struct tsc2301 *tsc)
475 {
476         struct tsc2301_ts *ts = tsc->ts;
477         struct spi_message *m = &ts->read_msg;
478         struct spi_transfer *x = &ts->read_xfer[0];
479
480         spi_message_init(m);
481
482         x->tx_buf = &tsc2301_ts_read_data;
483         x->len = 2;
484         spi_message_add_tail(x, m);
485
486         x++;
487         x->rx_buf = &ts->data;
488         x->len = 8;
489         spi_message_add_tail(x, m);
490
491         m->complete = tsc2301_ts_rx;
492         m->context = tsc;
493 }
494
495 static ssize_t tsc2301_ts_pen_down_show(struct device *dev,
496                                         struct device_attribute *attr,
497                                         char *buf)
498 {
499         struct tsc2301 *tsc = dev_get_drvdata(dev);
500
501         return sprintf(buf, "%u\n", tsc->ts->pen_down);
502 }
503
504 static DEVICE_ATTR(pen_down, S_IRUGO, tsc2301_ts_pen_down_show, NULL);
505
506 static ssize_t tsc2301_ts_disable_show(struct device *dev,
507                                        struct device_attribute *attr, char *buf)
508 {
509         struct tsc2301          *tsc = dev_get_drvdata(dev);
510         struct tsc2301_ts       *ts = tsc->ts;
511
512         return sprintf(buf, "%u\n", ts->disabled);
513 }
514
515 static ssize_t tsc2301_ts_disable_store(struct device *dev,
516                                         struct device_attribute *attr,
517                                         const char *buf, size_t count)
518 {
519         struct tsc2301          *tsc = dev_get_drvdata(dev);
520         struct tsc2301_ts       *ts = tsc->ts;
521         char *endp;
522         int i;
523
524         i = simple_strtoul(buf, &endp, 10);
525         i = i ? 1 : 0;
526         mutex_lock(&ts->mutex);
527         if (i == ts->disabled) goto out;
528         ts->disabled = i;
529
530         if (i)
531                 tsc2301_ts_disable(tsc);
532         else
533                 tsc2301_ts_enable(tsc);
534 out:
535         mutex_unlock(&ts->mutex);
536         return count;
537 }
538
539 static DEVICE_ATTR(disable_ts, 0664, tsc2301_ts_disable_show,
540                    tsc2301_ts_disable_store);
541
542 int __devinit tsc2301_ts_init(struct tsc2301 *tsc,
543                               struct tsc2301_platform_data *pdata)
544 {
545         struct tsc2301_ts *ts;
546         struct input_dev *idev;
547         int r;
548         int x_max, y_max;
549         int x_fudge, y_fudge, p_fudge;
550
551         if (pdata->dav_int <= 0) {
552                 dev_err(&tsc->spi->dev, "need DAV IRQ");
553                 return -EINVAL;
554         }
555
556         ts = kzalloc(sizeof(*ts), GFP_KERNEL);
557         if (ts == NULL)
558                 return -ENOMEM;
559         tsc->ts = ts;
560
561         ts->irq = pdata->dav_int;
562
563         init_timer(&ts->penup_timer);
564         setup_timer(&ts->penup_timer, tsc2301_ts_timer_handler,
565                         (unsigned long)tsc);
566
567         mutex_init(&ts->mutex);
568
569         ts->x_plate_ohm = pdata->ts_x_plate_ohm ? : 280;
570         ts->hw_avg_max  = pdata->ts_hw_avg;
571         ts->max_pressure = pdata->ts_max_pressure ? : MAX_12BIT;
572         ts->touch_pressure = pdata->ts_touch_pressure ? : ts->max_pressure;
573         ts->stab_time   = pdata->ts_stab_time;
574
575         x_max           = pdata->ts_x_max ? : 4096;
576         y_max           = pdata->ts_y_max ? : 4096;
577         x_fudge         = pdata->ts_x_fudge ? : 4;
578         y_fudge         = pdata->ts_y_fudge ? : 8;
579         p_fudge         = pdata->ts_pressure_fudge ? : 2;
580
581         if ((r = tsc2301_ts_check_config(ts, &ts->hw_flags))) {
582                 dev_err(&tsc->spi->dev, "invalid configuration\n");
583                 goto err2;
584         }
585
586         idev = input_allocate_device();
587         if (idev == NULL) {
588                 r = -ENOMEM;
589                 goto err2;
590         }
591         idev->name = "TSC2301 touchscreen";
592         snprintf(ts->phys, sizeof(ts->phys),
593                  "%s/input-ts", tsc->spi->dev.bus_id);
594         idev->phys = ts->phys;
595         idev->dev.parent = &tsc->spi->dev;
596
597         idev->evbit[0] = BIT(EV_ABS) | BIT(EV_KEY);
598         idev->absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE);
599         ts->idev = idev;
600
601         tsc2301_ts_setup_spi_xfer(tsc);
602
603         /* These parameters should perhaps be configurable? */
604         input_set_abs_params(idev, ABS_X, 0, x_max, x_fudge, 0);
605         input_set_abs_params(idev, ABS_Y, 0, y_max, y_fudge, 0);
606         input_set_abs_params(idev, ABS_PRESSURE, 0, ts->max_pressure,
607                              p_fudge, 0);
608
609         tsc2301_ts_start_scan(tsc);
610
611         r = request_irq(ts->irq, tsc2301_ts_irq_handler,
612                         IRQF_SAMPLE_RANDOM | IRQF_TRIGGER_FALLING,
613                         "tsc2301-ts", tsc);
614         if (r < 0) {
615                 dev_err(&tsc->spi->dev, "unable to get DAV IRQ");
616                 goto err3;
617         }
618         set_irq_wake(ts->irq, 1);
619
620         if (device_create_file(&tsc->spi->dev, &dev_attr_pen_down) < 0)
621                 goto err4;
622         if (device_create_file(&tsc->spi->dev, &dev_attr_disable_ts) < 0)
623                 goto err5;
624
625         r = input_register_device(idev);
626         if (r < 0) {
627                 dev_err(&tsc->spi->dev, "can't register touchscreen device\n");
628                 goto err6;
629         }
630
631         return 0;
632 err6:
633         device_remove_file(&tsc->spi->dev, &dev_attr_disable_ts);
634 err5:
635         device_remove_file(&tsc->spi->dev, &dev_attr_pen_down);
636 err4:
637         free_irq(ts->irq, tsc);
638 err3:
639         tsc2301_ts_stop_scan(tsc);
640         input_free_device(idev);
641 err2:
642         kfree(ts);
643         return r;
644 }
645
646 void __devexit tsc2301_ts_exit(struct tsc2301 *tsc)
647 {
648         struct tsc2301_ts *ts = tsc->ts;
649
650         tsc2301_ts_disable(tsc);
651
652         device_remove_file(&tsc->spi->dev, &dev_attr_disable_ts);
653         device_remove_file(&tsc->spi->dev, &dev_attr_pen_down);
654
655         free_irq(ts->irq, tsc);
656         input_unregister_device(ts->idev);
657
658         kfree(ts);
659 }
660 MODULE_AUTHOR("Jarkko Oikarinen <jarkko.oikarinen@nokia.com>");
661 MODULE_LICENSE("GPL");