diff options
Diffstat (limited to 'drivers/input')
-rw-r--r-- | drivers/input/misc/uinput.c | 1 | ||||
-rw-r--r-- | drivers/input/serio/serio.c | 55 | ||||
-rw-r--r-- | drivers/input/touchscreen/Kconfig | 12 | ||||
-rw-r--r-- | drivers/input/touchscreen/Makefile | 1 | ||||
-rw-r--r-- | drivers/input/touchscreen/ads7846.c | 16 | ||||
-rw-r--r-- | drivers/input/touchscreen/atmel_tsadcc.c | 332 |
6 files changed, 389 insertions, 28 deletions
diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c index 2bcfa0b35061..223d56d5555b 100644 --- a/drivers/input/misc/uinput.c +++ b/drivers/input/misc/uinput.c | |||
@@ -37,7 +37,6 @@ | |||
37 | #include <linux/fs.h> | 37 | #include <linux/fs.h> |
38 | #include <linux/miscdevice.h> | 38 | #include <linux/miscdevice.h> |
39 | #include <linux/uinput.h> | 39 | #include <linux/uinput.h> |
40 | #include <linux/smp_lock.h> | ||
41 | 40 | ||
42 | static int uinput_dev_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) | 41 | static int uinput_dev_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) |
43 | { | 42 | { |
diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c index 78f2abb5c11b..2f12d60eee3b 100644 --- a/drivers/input/serio/serio.c +++ b/drivers/input/serio/serio.c | |||
@@ -63,8 +63,9 @@ static LIST_HEAD(serio_list); | |||
63 | static struct bus_type serio_bus; | 63 | static struct bus_type serio_bus; |
64 | 64 | ||
65 | static void serio_add_port(struct serio *serio); | 65 | static void serio_add_port(struct serio *serio); |
66 | static void serio_reconnect_port(struct serio *serio); | 66 | static int serio_reconnect_port(struct serio *serio); |
67 | static void serio_disconnect_port(struct serio *serio); | 67 | static void serio_disconnect_port(struct serio *serio); |
68 | static void serio_reconnect_chain(struct serio *serio); | ||
68 | static void serio_attach_driver(struct serio_driver *drv); | 69 | static void serio_attach_driver(struct serio_driver *drv); |
69 | 70 | ||
70 | static int serio_connect_driver(struct serio *serio, struct serio_driver *drv) | 71 | static int serio_connect_driver(struct serio *serio, struct serio_driver *drv) |
@@ -161,6 +162,7 @@ static void serio_find_driver(struct serio *serio) | |||
161 | enum serio_event_type { | 162 | enum serio_event_type { |
162 | SERIO_RESCAN_PORT, | 163 | SERIO_RESCAN_PORT, |
163 | SERIO_RECONNECT_PORT, | 164 | SERIO_RECONNECT_PORT, |
165 | SERIO_RECONNECT_CHAIN, | ||
164 | SERIO_REGISTER_PORT, | 166 | SERIO_REGISTER_PORT, |
165 | SERIO_ATTACH_DRIVER, | 167 | SERIO_ATTACH_DRIVER, |
166 | }; | 168 | }; |
@@ -315,6 +317,10 @@ static void serio_handle_event(void) | |||
315 | serio_find_driver(event->object); | 317 | serio_find_driver(event->object); |
316 | break; | 318 | break; |
317 | 319 | ||
320 | case SERIO_RECONNECT_CHAIN: | ||
321 | serio_reconnect_chain(event->object); | ||
322 | break; | ||
323 | |||
318 | case SERIO_ATTACH_DRIVER: | 324 | case SERIO_ATTACH_DRIVER: |
319 | serio_attach_driver(event->object); | 325 | serio_attach_driver(event->object); |
320 | break; | 326 | break; |
@@ -470,7 +476,7 @@ static ssize_t serio_rebind_driver(struct device *dev, struct device_attribute * | |||
470 | if (!strncmp(buf, "none", count)) { | 476 | if (!strncmp(buf, "none", count)) { |
471 | serio_disconnect_port(serio); | 477 | serio_disconnect_port(serio); |
472 | } else if (!strncmp(buf, "reconnect", count)) { | 478 | } else if (!strncmp(buf, "reconnect", count)) { |
473 | serio_reconnect_port(serio); | 479 | serio_reconnect_chain(serio); |
474 | } else if (!strncmp(buf, "rescan", count)) { | 480 | } else if (!strncmp(buf, "rescan", count)) { |
475 | serio_disconnect_port(serio); | 481 | serio_disconnect_port(serio); |
476 | serio_find_driver(serio); | 482 | serio_find_driver(serio); |
@@ -620,14 +626,30 @@ static void serio_destroy_port(struct serio *serio) | |||
620 | } | 626 | } |
621 | 627 | ||
622 | /* | 628 | /* |
629 | * Reconnect serio port (re-initialize attached device). | ||
630 | * If reconnect fails (old device is no longer attached or | ||
631 | * there was no device to begin with) we do full rescan in | ||
632 | * hope of finding a driver for the port. | ||
633 | */ | ||
634 | static int serio_reconnect_port(struct serio *serio) | ||
635 | { | ||
636 | int error = serio_reconnect_driver(serio); | ||
637 | |||
638 | if (error) { | ||
639 | serio_disconnect_port(serio); | ||
640 | serio_find_driver(serio); | ||
641 | } | ||
642 | |||
643 | return error; | ||
644 | } | ||
645 | |||
646 | /* | ||
623 | * Reconnect serio port and all its children (re-initialize attached devices) | 647 | * Reconnect serio port and all its children (re-initialize attached devices) |
624 | */ | 648 | */ |
625 | static void serio_reconnect_port(struct serio *serio) | 649 | static void serio_reconnect_chain(struct serio *serio) |
626 | { | 650 | { |
627 | do { | 651 | do { |
628 | if (serio_reconnect_driver(serio)) { | 652 | if (serio_reconnect_port(serio)) { |
629 | serio_disconnect_port(serio); | ||
630 | serio_find_driver(serio); | ||
631 | /* Ok, old children are now gone, we are done */ | 653 | /* Ok, old children are now gone, we are done */ |
632 | break; | 654 | break; |
633 | } | 655 | } |
@@ -673,7 +695,7 @@ void serio_rescan(struct serio *serio) | |||
673 | 695 | ||
674 | void serio_reconnect(struct serio *serio) | 696 | void serio_reconnect(struct serio *serio) |
675 | { | 697 | { |
676 | serio_queue_event(serio, NULL, SERIO_RECONNECT_PORT); | 698 | serio_queue_event(serio, NULL, SERIO_RECONNECT_CHAIN); |
677 | } | 699 | } |
678 | 700 | ||
679 | /* | 701 | /* |
@@ -927,19 +949,16 @@ static int serio_suspend(struct device *dev, pm_message_t state) | |||
927 | 949 | ||
928 | static int serio_resume(struct device *dev) | 950 | static int serio_resume(struct device *dev) |
929 | { | 951 | { |
930 | struct serio *serio = to_serio_port(dev); | 952 | /* |
931 | 953 | * Driver reconnect can take a while, so better let kseriod | |
932 | if (dev->power.power_state.event != PM_EVENT_ON && | 954 | * deal with it. |
933 | serio_reconnect_driver(serio)) { | 955 | */ |
934 | /* | 956 | if (dev->power.power_state.event != PM_EVENT_ON) { |
935 | * Driver re-probing can take a while, so better let kseriod | 957 | dev->power.power_state = PMSG_ON; |
936 | * deal with it. | 958 | serio_queue_event(to_serio_port(dev), NULL, |
937 | */ | 959 | SERIO_RECONNECT_PORT); |
938 | serio_rescan(serio); | ||
939 | } | 960 | } |
940 | 961 | ||
941 | dev->power.power_state = PMSG_ON; | ||
942 | |||
943 | return 0; | 962 | return 0; |
944 | } | 963 | } |
945 | #endif /* CONFIG_PM */ | 964 | #endif /* CONFIG_PM */ |
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig index e57366521572..6e60a97a234c 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig | |||
@@ -205,6 +205,18 @@ config TOUCHSCREEN_TOUCHWIN | |||
205 | To compile this driver as a module, choose M here: the | 205 | To compile this driver as a module, choose M here: the |
206 | module will be called touchwin. | 206 | module will be called touchwin. |
207 | 207 | ||
208 | config TOUCHSCREEN_ATMEL_TSADCC | ||
209 | tristate "Atmel Touchscreen Interface" | ||
210 | depends on ARCH_AT91SAM9RL | ||
211 | help | ||
212 | Say Y here if you have a 4-wire touchscreen connected to the | ||
213 | ADC Controller on your Atmel SoC (such as the AT91SAM9RL). | ||
214 | |||
215 | If unsure, say N. | ||
216 | |||
217 | To compile this driver as a module, choose M here: the | ||
218 | module will be called atmel_tsadcc. | ||
219 | |||
208 | config TOUCHSCREEN_UCB1400 | 220 | config TOUCHSCREEN_UCB1400 |
209 | tristate "Philips UCB1400 touchscreen" | 221 | tristate "Philips UCB1400 touchscreen" |
210 | select AC97_BUS | 222 | select AC97_BUS |
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile index 39a804cd80f1..15cf29079489 100644 --- a/drivers/input/touchscreen/Makefile +++ b/drivers/input/touchscreen/Makefile | |||
@@ -7,6 +7,7 @@ | |||
7 | wm97xx-ts-y := wm97xx-core.o | 7 | wm97xx-ts-y := wm97xx-core.o |
8 | 8 | ||
9 | obj-$(CONFIG_TOUCHSCREEN_ADS7846) += ads7846.o | 9 | obj-$(CONFIG_TOUCHSCREEN_ADS7846) += ads7846.o |
10 | obj-$(CONFIG_TOUCHSCREEN_ATMEL_TSADCC) += atmel_tsadcc.o | ||
10 | obj-$(CONFIG_TOUCHSCREEN_BITSY) += h3600_ts_input.o | 11 | obj-$(CONFIG_TOUCHSCREEN_BITSY) += h3600_ts_input.o |
11 | obj-$(CONFIG_TOUCHSCREEN_CORGI) += corgi_ts.o | 12 | obj-$(CONFIG_TOUCHSCREEN_CORGI) += corgi_ts.o |
12 | obj-$(CONFIG_TOUCHSCREEN_GUNZE) += gunze.o | 13 | obj-$(CONFIG_TOUCHSCREEN_GUNZE) += gunze.o |
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c index 907a45fe9d40..ce6f48c695f5 100644 --- a/drivers/input/touchscreen/ads7846.c +++ b/drivers/input/touchscreen/ads7846.c | |||
@@ -517,7 +517,9 @@ static void ads7846_rx(void *ads) | |||
517 | if (x == MAX_12BIT) | 517 | if (x == MAX_12BIT) |
518 | x = 0; | 518 | x = 0; |
519 | 519 | ||
520 | if (likely(x && z1)) { | 520 | if (ts->model == 7843) { |
521 | Rt = ts->pressure_max / 2; | ||
522 | } else if (likely(x && z1)) { | ||
521 | /* compute touch pressure resistance using equation #2 */ | 523 | /* compute touch pressure resistance using equation #2 */ |
522 | Rt = z2; | 524 | Rt = z2; |
523 | Rt -= z1; | 525 | Rt -= z1; |
@@ -525,11 +527,9 @@ static void ads7846_rx(void *ads) | |||
525 | Rt *= ts->x_plate_ohms; | 527 | Rt *= ts->x_plate_ohms; |
526 | Rt /= z1; | 528 | Rt /= z1; |
527 | Rt = (Rt + 2047) >> 12; | 529 | Rt = (Rt + 2047) >> 12; |
528 | } else | 530 | } else { |
529 | Rt = 0; | 531 | Rt = 0; |
530 | 532 | } | |
531 | if (ts->model == 7843) | ||
532 | Rt = ts->pressure_max / 2; | ||
533 | 533 | ||
534 | /* Sample found inconsistent by debouncing or pressure is beyond | 534 | /* Sample found inconsistent by debouncing or pressure is beyond |
535 | * the maximum. Don't report it to user space, repeat at least | 535 | * the maximum. Don't report it to user space, repeat at least |
@@ -633,19 +633,17 @@ static void ads7846_rx_val(void *ads) | |||
633 | struct ads7846 *ts = ads; | 633 | struct ads7846 *ts = ads; |
634 | struct spi_message *m; | 634 | struct spi_message *m; |
635 | struct spi_transfer *t; | 635 | struct spi_transfer *t; |
636 | u16 *rx_val; | ||
637 | int val; | 636 | int val; |
638 | int action; | 637 | int action; |
639 | int status; | 638 | int status; |
640 | 639 | ||
641 | m = &ts->msg[ts->msg_idx]; | 640 | m = &ts->msg[ts->msg_idx]; |
642 | t = list_entry(m->transfers.prev, struct spi_transfer, transfer_list); | 641 | t = list_entry(m->transfers.prev, struct spi_transfer, transfer_list); |
643 | rx_val = t->rx_buf; | ||
644 | 642 | ||
645 | /* adjust: on-wire is a must-ignore bit, a BE12 value, then padding; | 643 | /* adjust: on-wire is a must-ignore bit, a BE12 value, then padding; |
646 | * built from two 8 bit values written msb-first. | 644 | * built from two 8 bit values written msb-first. |
647 | */ | 645 | */ |
648 | val = be16_to_cpu(*rx_val) >> 3; | 646 | val = be16_to_cpup((__be16 *)t->rx_buf) >> 3; |
649 | 647 | ||
650 | action = ts->filter(ts->filter_data, ts->msg_idx, &val); | 648 | action = ts->filter(ts->filter_data, ts->msg_idx, &val); |
651 | switch (action) { | 649 | switch (action) { |
@@ -659,7 +657,7 @@ static void ads7846_rx_val(void *ads) | |||
659 | m = ts->last_msg; | 657 | m = ts->last_msg; |
660 | break; | 658 | break; |
661 | case ADS7846_FILTER_OK: | 659 | case ADS7846_FILTER_OK: |
662 | *rx_val = val; | 660 | *(u16 *)t->rx_buf = val; |
663 | ts->tc.ignore = 0; | 661 | ts->tc.ignore = 0; |
664 | m = &ts->msg[++ts->msg_idx]; | 662 | m = &ts->msg[++ts->msg_idx]; |
665 | break; | 663 | break; |
diff --git a/drivers/input/touchscreen/atmel_tsadcc.c b/drivers/input/touchscreen/atmel_tsadcc.c new file mode 100644 index 000000000000..eee126b19e8b --- /dev/null +++ b/drivers/input/touchscreen/atmel_tsadcc.c | |||
@@ -0,0 +1,332 @@ | |||
1 | /* | ||
2 | * Atmel Touch Screen Driver | ||
3 | * | ||
4 | * Copyright (c) 2008 ATMEL | ||
5 | * Copyright (c) 2008 Dan Liang | ||
6 | * Copyright (c) 2008 TimeSys Corporation | ||
7 | * Copyright (c) 2008 Justin Waters | ||
8 | * | ||
9 | * Based on touchscreen code from Atmel Corporation. | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU General Public License version 2 as | ||
13 | * published by the Free Software Foundation. | ||
14 | */ | ||
15 | #include <linux/init.h> | ||
16 | #include <linux/err.h> | ||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/module.h> | ||
19 | #include <linux/input.h> | ||
20 | #include <linux/slab.h> | ||
21 | #include <linux/interrupt.h> | ||
22 | #include <linux/clk.h> | ||
23 | #include <linux/platform_device.h> | ||
24 | #include <linux/io.h> | ||
25 | |||
26 | /* Register definitions based on AT91SAM9RL64 preliminary draft datasheet */ | ||
27 | |||
28 | #define ATMEL_TSADCC_CR 0x00 /* Control register */ | ||
29 | #define ATMEL_TSADCC_SWRST (1 << 0) /* Software Reset*/ | ||
30 | #define ATMEL_TSADCC_START (1 << 1) /* Start conversion */ | ||
31 | |||
32 | #define ATMEL_TSADCC_MR 0x04 /* Mode register */ | ||
33 | #define ATMEL_TSADCC_TSAMOD (3 << 0) /* ADC mode */ | ||
34 | #define ATMEL_TSADCC_TSAMOD_ADC_ONLY_MODE (0x0) /* ADC Mode */ | ||
35 | #define ATMEL_TSADCC_TSAMOD_TS_ONLY_MODE (0x1) /* Touch Screen Only Mode */ | ||
36 | #define ATMEL_TSADCC_LOWRES (1 << 4) /* Resolution selection */ | ||
37 | #define ATMEL_TSADCC_SLEEP (1 << 5) /* Sleep mode */ | ||
38 | #define ATMEL_TSADCC_PENDET (1 << 6) /* Pen Detect selection */ | ||
39 | #define ATMEL_TSADCC_PRESCAL (0x3f << 8) /* Prescalar Rate Selection */ | ||
40 | #define ATMEL_TSADCC_STARTUP (0x7f << 16) /* Start Up time */ | ||
41 | #define ATMEL_TSADCC_SHTIM (0xf << 24) /* Sample & Hold time */ | ||
42 | #define ATMEL_TSADCC_PENDBC (0xf << 28) /* Pen Detect debouncing time */ | ||
43 | |||
44 | #define ATMEL_TSADCC_TRGR 0x08 /* Trigger register */ | ||
45 | #define ATMEL_TSADCC_TRGMOD (7 << 0) /* Trigger mode */ | ||
46 | #define ATMEL_TSADCC_TRGMOD_NONE (0 << 0) | ||
47 | #define ATMEL_TSADCC_TRGMOD_EXT_RISING (1 << 0) | ||
48 | #define ATMEL_TSADCC_TRGMOD_EXT_FALLING (2 << 0) | ||
49 | #define ATMEL_TSADCC_TRGMOD_EXT_ANY (3 << 0) | ||
50 | #define ATMEL_TSADCC_TRGMOD_PENDET (4 << 0) | ||
51 | #define ATMEL_TSADCC_TRGMOD_PERIOD (5 << 0) | ||
52 | #define ATMEL_TSADCC_TRGMOD_CONTINUOUS (6 << 0) | ||
53 | #define ATMEL_TSADCC_TRGPER (0xffff << 16) /* Trigger period */ | ||
54 | |||
55 | #define ATMEL_TSADCC_TSR 0x0C /* Touch Screen register */ | ||
56 | #define ATMEL_TSADCC_TSFREQ (0xf << 0) /* TS Frequency in Interleaved mode */ | ||
57 | #define ATMEL_TSADCC_TSSHTIM (0xf << 24) /* Sample & Hold time */ | ||
58 | |||
59 | #define ATMEL_TSADCC_CHER 0x10 /* Channel Enable register */ | ||
60 | #define ATMEL_TSADCC_CHDR 0x14 /* Channel Disable register */ | ||
61 | #define ATMEL_TSADCC_CHSR 0x18 /* Channel Status register */ | ||
62 | #define ATMEL_TSADCC_CH(n) (1 << (n)) /* Channel number */ | ||
63 | |||
64 | #define ATMEL_TSADCC_SR 0x1C /* Status register */ | ||
65 | #define ATMEL_TSADCC_EOC(n) (1 << ((n)+0)) /* End of conversion for channel N */ | ||
66 | #define ATMEL_TSADCC_OVRE(n) (1 << ((n)+8)) /* Overrun error for channel N */ | ||
67 | #define ATMEL_TSADCC_DRDY (1 << 16) /* Data Ready */ | ||
68 | #define ATMEL_TSADCC_GOVRE (1 << 17) /* General Overrun Error */ | ||
69 | #define ATMEL_TSADCC_ENDRX (1 << 18) /* End of RX Buffer */ | ||
70 | #define ATMEL_TSADCC_RXBUFF (1 << 19) /* TX Buffer full */ | ||
71 | #define ATMEL_TSADCC_PENCNT (1 << 20) /* Pen contact */ | ||
72 | #define ATMEL_TSADCC_NOCNT (1 << 21) /* No contact */ | ||
73 | |||
74 | #define ATMEL_TSADCC_LCDR 0x20 /* Last Converted Data register */ | ||
75 | #define ATMEL_TSADCC_DATA (0x3ff << 0) /* Channel data */ | ||
76 | |||
77 | #define ATMEL_TSADCC_IER 0x24 /* Interrupt Enable register */ | ||
78 | #define ATMEL_TSADCC_IDR 0x28 /* Interrupt Disable register */ | ||
79 | #define ATMEL_TSADCC_IMR 0x2C /* Interrupt Mask register */ | ||
80 | #define ATMEL_TSADCC_CDR0 0x30 /* Channel Data 0 */ | ||
81 | #define ATMEL_TSADCC_CDR1 0x34 /* Channel Data 1 */ | ||
82 | #define ATMEL_TSADCC_CDR2 0x38 /* Channel Data 2 */ | ||
83 | #define ATMEL_TSADCC_CDR3 0x3C /* Channel Data 3 */ | ||
84 | #define ATMEL_TSADCC_CDR4 0x40 /* Channel Data 4 */ | ||
85 | #define ATMEL_TSADCC_CDR5 0x44 /* Channel Data 5 */ | ||
86 | |||
87 | #define ADC_CLOCK 1000000 | ||
88 | |||
89 | struct atmel_tsadcc { | ||
90 | struct input_dev *input; | ||
91 | char phys[32]; | ||
92 | struct clk *clk; | ||
93 | int irq; | ||
94 | }; | ||
95 | |||
96 | static void __iomem *tsc_base; | ||
97 | |||
98 | #define atmel_tsadcc_read(reg) __raw_readl(tsc_base + (reg)) | ||
99 | #define atmel_tsadcc_write(reg, val) __raw_writel((val), tsc_base + (reg)) | ||
100 | |||
101 | static irqreturn_t atmel_tsadcc_interrupt(int irq, void *dev) | ||
102 | { | ||
103 | struct input_dev *input_dev = ((struct atmel_tsadcc *)dev)->input; | ||
104 | |||
105 | unsigned int absx; | ||
106 | unsigned int absy; | ||
107 | unsigned int status; | ||
108 | unsigned int reg; | ||
109 | |||
110 | status = atmel_tsadcc_read(ATMEL_TSADCC_SR); | ||
111 | status &= atmel_tsadcc_read(ATMEL_TSADCC_IMR); | ||
112 | |||
113 | if (status & ATMEL_TSADCC_NOCNT) { | ||
114 | /* Contact lost */ | ||
115 | reg = atmel_tsadcc_read(ATMEL_TSADCC_MR) | ATMEL_TSADCC_PENDBC; | ||
116 | |||
117 | atmel_tsadcc_write(ATMEL_TSADCC_MR, reg); | ||
118 | atmel_tsadcc_write(ATMEL_TSADCC_TRGR, ATMEL_TSADCC_TRGMOD_NONE); | ||
119 | atmel_tsadcc_write(ATMEL_TSADCC_IDR, | ||
120 | ATMEL_TSADCC_EOC(3) | ATMEL_TSADCC_NOCNT); | ||
121 | atmel_tsadcc_write(ATMEL_TSADCC_IER, ATMEL_TSADCC_PENCNT); | ||
122 | |||
123 | input_report_key(input_dev, BTN_TOUCH, 0); | ||
124 | input_sync(input_dev); | ||
125 | |||
126 | } else if (status & ATMEL_TSADCC_PENCNT) { | ||
127 | /* Pen detected */ | ||
128 | reg = atmel_tsadcc_read(ATMEL_TSADCC_MR); | ||
129 | reg &= ~ATMEL_TSADCC_PENDBC; | ||
130 | |||
131 | atmel_tsadcc_write(ATMEL_TSADCC_IDR, ATMEL_TSADCC_PENCNT); | ||
132 | atmel_tsadcc_write(ATMEL_TSADCC_MR, reg); | ||
133 | atmel_tsadcc_write(ATMEL_TSADCC_IER, | ||
134 | ATMEL_TSADCC_EOC(3) | ATMEL_TSADCC_NOCNT); | ||
135 | atmel_tsadcc_write(ATMEL_TSADCC_TRGR, | ||
136 | ATMEL_TSADCC_TRGMOD_PERIOD | (0x0FFF << 16)); | ||
137 | |||
138 | } else if (status & ATMEL_TSADCC_EOC(3)) { | ||
139 | /* Conversion finished */ | ||
140 | |||
141 | absx = atmel_tsadcc_read(ATMEL_TSADCC_CDR3) << 10; | ||
142 | absx /= atmel_tsadcc_read(ATMEL_TSADCC_CDR2); | ||
143 | |||
144 | absy = atmel_tsadcc_read(ATMEL_TSADCC_CDR1) << 10; | ||
145 | absy /= atmel_tsadcc_read(ATMEL_TSADCC_CDR0); | ||
146 | |||
147 | input_report_abs(input_dev, ABS_X, absx); | ||
148 | input_report_abs(input_dev, ABS_Y, absy); | ||
149 | input_report_key(input_dev, BTN_TOUCH, 1); | ||
150 | input_sync(input_dev); | ||
151 | } | ||
152 | |||
153 | return IRQ_HANDLED; | ||
154 | } | ||
155 | |||
156 | /* | ||
157 | * The functions for inserting/removing us as a module. | ||
158 | */ | ||
159 | |||
160 | static int __devinit atmel_tsadcc_probe(struct platform_device *pdev) | ||
161 | { | ||
162 | struct atmel_tsadcc *ts_dev; | ||
163 | struct input_dev *input_dev; | ||
164 | struct resource *res; | ||
165 | int err = 0; | ||
166 | unsigned int prsc; | ||
167 | unsigned int reg; | ||
168 | |||
169 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
170 | if (!res) { | ||
171 | dev_err(&pdev->dev, "no mmio resource defined.\n"); | ||
172 | return -ENXIO; | ||
173 | } | ||
174 | |||
175 | /* Allocate memory for device */ | ||
176 | ts_dev = kzalloc(sizeof(struct atmel_tsadcc), GFP_KERNEL); | ||
177 | if (!ts_dev) { | ||
178 | dev_err(&pdev->dev, "failed to allocate memory.\n"); | ||
179 | return -ENOMEM; | ||
180 | } | ||
181 | platform_set_drvdata(pdev, ts_dev); | ||
182 | |||
183 | input_dev = input_allocate_device(); | ||
184 | if (!input_dev) { | ||
185 | dev_err(&pdev->dev, "failed to allocate input device.\n"); | ||
186 | err = -EBUSY; | ||
187 | goto err_free_mem; | ||
188 | } | ||
189 | |||
190 | ts_dev->irq = platform_get_irq(pdev, 0); | ||
191 | if (ts_dev->irq < 0) { | ||
192 | dev_err(&pdev->dev, "no irq ID is designated.\n"); | ||
193 | err = -ENODEV; | ||
194 | goto err_free_dev; | ||
195 | } | ||
196 | |||
197 | if (!request_mem_region(res->start, res->end - res->start + 1, | ||
198 | "atmel tsadcc regs")) { | ||
199 | dev_err(&pdev->dev, "resources is unavailable.\n"); | ||
200 | err = -EBUSY; | ||
201 | goto err_free_dev; | ||
202 | } | ||
203 | |||
204 | tsc_base = ioremap(res->start, res->end - res->start + 1); | ||
205 | if (!tsc_base) { | ||
206 | dev_err(&pdev->dev, "failed to map registers.\n"); | ||
207 | err = -ENOMEM; | ||
208 | goto err_release_mem; | ||
209 | } | ||
210 | |||
211 | err = request_irq(ts_dev->irq, atmel_tsadcc_interrupt, IRQF_DISABLED, | ||
212 | pdev->dev.driver->name, ts_dev); | ||
213 | if (err) { | ||
214 | dev_err(&pdev->dev, "failed to allocate irq.\n"); | ||
215 | goto err_unmap_regs; | ||
216 | } | ||
217 | |||
218 | ts_dev->clk = clk_get(&pdev->dev, "tsc_clk"); | ||
219 | if (IS_ERR(ts_dev->clk)) { | ||
220 | dev_err(&pdev->dev, "failed to get ts_clk\n"); | ||
221 | err = PTR_ERR(ts_dev->clk); | ||
222 | goto err_free_irq; | ||
223 | } | ||
224 | |||
225 | ts_dev->input = input_dev; | ||
226 | |||
227 | snprintf(ts_dev->phys, sizeof(ts_dev->phys), | ||
228 | "%s/input0", pdev->dev.bus_id); | ||
229 | |||
230 | input_dev->name = "atmel touch screen controller"; | ||
231 | input_dev->phys = ts_dev->phys; | ||
232 | input_dev->dev.parent = &pdev->dev; | ||
233 | |||
234 | input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); | ||
235 | input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); | ||
236 | |||
237 | input_set_abs_params(input_dev, ABS_X, 0, 0x3FF, 0, 0); | ||
238 | input_set_abs_params(input_dev, ABS_Y, 0, 0x3FF, 0, 0); | ||
239 | |||
240 | /* clk_enable() always returns 0, no need to check it */ | ||
241 | clk_enable(ts_dev->clk); | ||
242 | |||
243 | prsc = clk_get_rate(ts_dev->clk); | ||
244 | dev_info(&pdev->dev, "Master clock is set at: %d Hz\n", prsc); | ||
245 | |||
246 | prsc = prsc / ADC_CLOCK / 2 - 1; | ||
247 | |||
248 | reg = ATMEL_TSADCC_TSAMOD_TS_ONLY_MODE | | ||
249 | ((0x00 << 5) & ATMEL_TSADCC_SLEEP) | /* Normal Mode */ | ||
250 | ((0x01 << 6) & ATMEL_TSADCC_PENDET) | /* Enable Pen Detect */ | ||
251 | ((prsc << 8) & ATMEL_TSADCC_PRESCAL) | /* PRESCAL */ | ||
252 | ((0x13 << 16) & ATMEL_TSADCC_STARTUP) | /* STARTUP */ | ||
253 | ((0x0F << 28) & ATMEL_TSADCC_PENDBC); /* PENDBC */ | ||
254 | |||
255 | atmel_tsadcc_write(ATMEL_TSADCC_CR, ATMEL_TSADCC_SWRST); | ||
256 | atmel_tsadcc_write(ATMEL_TSADCC_MR, reg); | ||
257 | atmel_tsadcc_write(ATMEL_TSADCC_TRGR, ATMEL_TSADCC_TRGMOD_NONE); | ||
258 | atmel_tsadcc_write(ATMEL_TSADCC_TSR, (0x3 << 24) & ATMEL_TSADCC_TSSHTIM); | ||
259 | |||
260 | atmel_tsadcc_read(ATMEL_TSADCC_SR); | ||
261 | atmel_tsadcc_write(ATMEL_TSADCC_IER, ATMEL_TSADCC_PENCNT); | ||
262 | |||
263 | /* All went ok, so register to the input system */ | ||
264 | err = input_register_device(input_dev); | ||
265 | if (err) | ||
266 | goto err_fail; | ||
267 | |||
268 | return 0; | ||
269 | |||
270 | err_fail: | ||
271 | clk_disable(ts_dev->clk); | ||
272 | clk_put(ts_dev->clk); | ||
273 | err_free_irq: | ||
274 | free_irq(ts_dev->irq, ts_dev); | ||
275 | err_unmap_regs: | ||
276 | iounmap(tsc_base); | ||
277 | err_release_mem: | ||
278 | release_mem_region(res->start, res->end - res->start + 1); | ||
279 | err_free_dev: | ||
280 | input_free_device(ts_dev->input); | ||
281 | err_free_mem: | ||
282 | kfree(ts_dev); | ||
283 | return err; | ||
284 | } | ||
285 | |||
286 | static int __devexit atmel_tsadcc_remove(struct platform_device *pdev) | ||
287 | { | ||
288 | struct atmel_tsadcc *ts_dev = dev_get_drvdata(&pdev->dev); | ||
289 | struct resource *res; | ||
290 | |||
291 | free_irq(ts_dev->irq, ts_dev); | ||
292 | |||
293 | input_unregister_device(ts_dev->input); | ||
294 | |||
295 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
296 | iounmap(tsc_base); | ||
297 | release_mem_region(res->start, res->end - res->start + 1); | ||
298 | |||
299 | clk_disable(ts_dev->clk); | ||
300 | clk_put(ts_dev->clk); | ||
301 | |||
302 | kfree(ts_dev); | ||
303 | |||
304 | return 0; | ||
305 | } | ||
306 | |||
307 | static struct platform_driver atmel_tsadcc_driver = { | ||
308 | .probe = atmel_tsadcc_probe, | ||
309 | .remove = __devexit_p(atmel_tsadcc_remove), | ||
310 | .driver = { | ||
311 | .name = "atmel_tsadcc", | ||
312 | }, | ||
313 | }; | ||
314 | |||
315 | static int __init atmel_tsadcc_init(void) | ||
316 | { | ||
317 | return platform_driver_register(&atmel_tsadcc_driver); | ||
318 | } | ||
319 | |||
320 | static void __exit atmel_tsadcc_exit(void) | ||
321 | { | ||
322 | platform_driver_unregister(&atmel_tsadcc_driver); | ||
323 | } | ||
324 | |||
325 | module_init(atmel_tsadcc_init); | ||
326 | module_exit(atmel_tsadcc_exit); | ||
327 | |||
328 | |||
329 | MODULE_LICENSE("GPL"); | ||
330 | MODULE_DESCRIPTION("Atmel TouchScreen Driver"); | ||
331 | MODULE_AUTHOR("Dan Liang <dan.liang@atmel.com>"); | ||
332 | |||