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