Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Richard Purdie | 513b6e1 | 2005-09-13 01:25:33 -0700 | [diff] [blame] | 2 | * Touchscreen driver for Sharp SL-C7xx and SL-Cxx00 models |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * Copyright (c) 2004-2005 Richard Purdie |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | */ |
| 11 | |
| 12 | |
| 13 | #include <linux/delay.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 14 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/init.h> |
| 16 | #include <linux/input.h> |
| 17 | #include <linux/interrupt.h> |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/slab.h> |
Thomas Gleixner | e6e3c3b | 2006-07-01 22:32:15 +0100 | [diff] [blame] | 20 | #include <linux/irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 22 | #include <mach/sharpsl.h> |
| 23 | #include <mach/hardware.h> |
| 24 | #include <mach/pxa-regs.h> |
| 25 | #include <mach/pxa2xx-gpio.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
| 27 | |
| 28 | #define PWR_MODE_ACTIVE 0 |
| 29 | #define PWR_MODE_SUSPEND 1 |
| 30 | |
| 31 | #define X_AXIS_MAX 3830 |
| 32 | #define X_AXIS_MIN 150 |
| 33 | #define Y_AXIS_MAX 3830 |
| 34 | #define Y_AXIS_MIN 190 |
| 35 | #define PRESSURE_MIN 0 |
| 36 | #define PRESSURE_MAX 15000 |
| 37 | |
| 38 | struct ts_event { |
| 39 | short pressure; |
| 40 | short x; |
| 41 | short y; |
| 42 | }; |
| 43 | |
| 44 | struct corgi_ts { |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 45 | struct input_dev *input; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | struct timer_list timer; |
| 47 | struct ts_event tc; |
| 48 | int pendown; |
| 49 | int power_mode; |
Richard Purdie | 513b6e1 | 2005-09-13 01:25:33 -0700 | [diff] [blame] | 50 | int irq_gpio; |
| 51 | struct corgits_machinfo *machinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | }; |
| 53 | |
Richard Purdie | 513b6e1 | 2005-09-13 01:25:33 -0700 | [diff] [blame] | 54 | #ifdef CONFIG_PXA25x |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | #define CCNT(a) asm volatile ("mrc p14, 0, %0, C1, C0, 0" : "=r"(a)) |
Richard Purdie | 347e484 | 2005-09-06 15:19:01 -0700 | [diff] [blame] | 56 | #define PMNC_GET(x) asm volatile ("mrc p14, 0, %0, C0, C0, 0" : "=r"(x)) |
| 57 | #define PMNC_SET(x) asm volatile ("mcr p14, 0, %0, C0, C0, 0" : : "r"(x)) |
Richard Purdie | 513b6e1 | 2005-09-13 01:25:33 -0700 | [diff] [blame] | 58 | #endif |
| 59 | #ifdef CONFIG_PXA27x |
| 60 | #define CCNT(a) asm volatile ("mrc p14, 0, %0, C1, C1, 0" : "=r"(a)) |
| 61 | #define PMNC_GET(x) asm volatile ("mrc p14, 0, %0, C0, C1, 0" : "=r"(x)) |
| 62 | #define PMNC_SET(x) asm volatile ("mcr p14, 0, %0, C0, C1, 0" : : "r"(x)) |
| 63 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
| 65 | /* ADS7846 Touch Screen Controller bit definitions */ |
| 66 | #define ADSCTRL_PD0 (1u << 0) /* PD0 */ |
| 67 | #define ADSCTRL_PD1 (1u << 1) /* PD1 */ |
| 68 | #define ADSCTRL_DFR (1u << 2) /* SER/DFR */ |
| 69 | #define ADSCTRL_MOD (1u << 3) /* Mode */ |
| 70 | #define ADSCTRL_ADR_SH 4 /* Address setting */ |
| 71 | #define ADSCTRL_STS (1u << 7) /* Start Bit */ |
| 72 | |
| 73 | /* External Functions */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | extern unsigned int get_clk_frequency_khz(int info); |
| 75 | |
Richard Purdie | 513b6e1 | 2005-09-13 01:25:33 -0700 | [diff] [blame] | 76 | static unsigned long calc_waittime(struct corgi_ts *corgi_ts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | { |
Richard Purdie | ca4d6cf | 2008-01-02 01:09:54 +0100 | [diff] [blame] | 78 | unsigned long hsync_invperiod = corgi_ts->machinfo->get_hsync_invperiod(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
Richard Purdie | ca4d6cf | 2008-01-02 01:09:54 +0100 | [diff] [blame] | 80 | if (hsync_invperiod) |
| 81 | return get_clk_frequency_khz(0)*1000/hsync_invperiod; |
Richard Purdie | 41b1bce | 2005-09-06 15:19:05 -0700 | [diff] [blame] | 82 | else |
Richard Purdie | 74b7489 | 2005-09-06 15:19:02 -0700 | [diff] [blame] | 83 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Richard Purdie | 513b6e1 | 2005-09-13 01:25:33 -0700 | [diff] [blame] | 86 | static int sync_receive_data_send_cmd(struct corgi_ts *corgi_ts, int doRecive, int doSend, |
| 87 | unsigned int address, unsigned long wait_time) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | { |
Richard Purdie | 347e484 | 2005-09-06 15:19:01 -0700 | [diff] [blame] | 89 | unsigned long timer1 = 0, timer2, pmnc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | int pos = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Richard Purdie | 74b7489 | 2005-09-06 15:19:02 -0700 | [diff] [blame] | 92 | if (wait_time && doSend) { |
Richard Purdie | 347e484 | 2005-09-06 15:19:01 -0700 | [diff] [blame] | 93 | PMNC_GET(pmnc); |
| 94 | if (!(pmnc & 0x01)) |
Richard Purdie | 8cc3c7a | 2005-09-06 15:19:02 -0700 | [diff] [blame] | 95 | PMNC_SET(0x01); |
Richard Purdie | 347e484 | 2005-09-06 15:19:01 -0700 | [diff] [blame] | 96 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | /* polling HSync */ |
Richard Purdie | 513b6e1 | 2005-09-13 01:25:33 -0700 | [diff] [blame] | 98 | corgi_ts->machinfo->wait_hsync(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | /* get CCNT */ |
| 100 | CCNT(timer1); |
| 101 | } |
| 102 | |
| 103 | if (doRecive) |
| 104 | pos = corgi_ssp_ads7846_get(); |
| 105 | |
| 106 | if (doSend) { |
| 107 | int cmd = ADSCTRL_PD0 | ADSCTRL_PD1 | (address << ADSCTRL_ADR_SH) | ADSCTRL_STS; |
| 108 | /* dummy command */ |
| 109 | corgi_ssp_ads7846_put(cmd); |
| 110 | corgi_ssp_ads7846_get(); |
| 111 | |
Richard Purdie | 74b7489 | 2005-09-06 15:19:02 -0700 | [diff] [blame] | 112 | if (wait_time) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | /* Wait after HSync */ |
| 114 | CCNT(timer2); |
| 115 | if (timer2-timer1 > wait_time) { |
Richard Purdie | 74b7489 | 2005-09-06 15:19:02 -0700 | [diff] [blame] | 116 | /* too slow - timeout, try again */ |
Richard Purdie | 513b6e1 | 2005-09-13 01:25:33 -0700 | [diff] [blame] | 117 | corgi_ts->machinfo->wait_hsync(); |
Richard Purdie | ca4d6cf | 2008-01-02 01:09:54 +0100 | [diff] [blame] | 118 | /* get CCNT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | CCNT(timer1); |
| 120 | /* Wait after HSync */ |
| 121 | CCNT(timer2); |
| 122 | } |
| 123 | while (timer2 - timer1 < wait_time) |
| 124 | CCNT(timer2); |
| 125 | } |
| 126 | corgi_ssp_ads7846_put(cmd); |
Richard Purdie | 74b7489 | 2005-09-06 15:19:02 -0700 | [diff] [blame] | 127 | if (wait_time && !(pmnc & 0x01)) |
Richard Purdie | 347e484 | 2005-09-06 15:19:01 -0700 | [diff] [blame] | 128 | PMNC_SET(pmnc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | } |
| 130 | return pos; |
| 131 | } |
| 132 | |
| 133 | static int read_xydata(struct corgi_ts *corgi_ts) |
| 134 | { |
| 135 | unsigned int x, y, z1, z2; |
| 136 | unsigned long flags, wait_time; |
| 137 | |
| 138 | /* critical section */ |
| 139 | local_irq_save(flags); |
| 140 | corgi_ssp_ads7846_lock(); |
Richard Purdie | 513b6e1 | 2005-09-13 01:25:33 -0700 | [diff] [blame] | 141 | wait_time = calc_waittime(corgi_ts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
| 143 | /* Y-axis */ |
Richard Purdie | 513b6e1 | 2005-09-13 01:25:33 -0700 | [diff] [blame] | 144 | sync_receive_data_send_cmd(corgi_ts, 0, 1, 1u, wait_time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
| 146 | /* Y-axis */ |
Richard Purdie | 513b6e1 | 2005-09-13 01:25:33 -0700 | [diff] [blame] | 147 | sync_receive_data_send_cmd(corgi_ts, 1, 1, 1u, wait_time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
| 149 | /* X-axis */ |
Richard Purdie | 513b6e1 | 2005-09-13 01:25:33 -0700 | [diff] [blame] | 150 | y = sync_receive_data_send_cmd(corgi_ts, 1, 1, 5u, wait_time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
| 152 | /* Z1 */ |
Richard Purdie | 513b6e1 | 2005-09-13 01:25:33 -0700 | [diff] [blame] | 153 | x = sync_receive_data_send_cmd(corgi_ts, 1, 1, 3u, wait_time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | |
| 155 | /* Z2 */ |
Richard Purdie | 513b6e1 | 2005-09-13 01:25:33 -0700 | [diff] [blame] | 156 | z1 = sync_receive_data_send_cmd(corgi_ts, 1, 1, 4u, wait_time); |
| 157 | z2 = sync_receive_data_send_cmd(corgi_ts, 1, 0, 4u, wait_time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
| 159 | /* Power-Down Enable */ |
| 160 | corgi_ssp_ads7846_put((1u << ADSCTRL_ADR_SH) | ADSCTRL_STS); |
| 161 | corgi_ssp_ads7846_get(); |
| 162 | |
| 163 | corgi_ssp_ads7846_unlock(); |
| 164 | local_irq_restore(flags); |
| 165 | |
| 166 | if (x== 0 || y == 0 || z1 == 0 || (x * (z2 - z1) / z1) >= 15000) { |
| 167 | corgi_ts->tc.pressure = 0; |
| 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | corgi_ts->tc.x = x; |
| 172 | corgi_ts->tc.y = y; |
| 173 | corgi_ts->tc.pressure = (x * (z2 - z1)) / z1; |
| 174 | return 1; |
| 175 | } |
| 176 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 177 | static void new_data(struct corgi_ts *corgi_ts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | { |
Dmitry Torokhov | 52c1f57 | 2006-11-05 22:40:03 -0500 | [diff] [blame] | 179 | struct input_dev *dev = corgi_ts->input; |
| 180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | if (corgi_ts->power_mode != PWR_MODE_ACTIVE) |
| 182 | return; |
| 183 | |
| 184 | if (!corgi_ts->tc.pressure && corgi_ts->pendown == 0) |
| 185 | return; |
| 186 | |
Dmitry Torokhov | 52c1f57 | 2006-11-05 22:40:03 -0500 | [diff] [blame] | 187 | input_report_abs(dev, ABS_X, corgi_ts->tc.x); |
| 188 | input_report_abs(dev, ABS_Y, corgi_ts->tc.y); |
| 189 | input_report_abs(dev, ABS_PRESSURE, corgi_ts->tc.pressure); |
| 190 | input_report_key(dev, BTN_TOUCH, corgi_ts->pendown); |
| 191 | input_sync(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | } |
| 193 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 194 | static void ts_interrupt_main(struct corgi_ts *corgi_ts, int isTimer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | { |
Richard Purdie | 513b6e1 | 2005-09-13 01:25:33 -0700 | [diff] [blame] | 196 | if ((GPLR(IRQ_TO_GPIO(corgi_ts->irq_gpio)) & GPIO_bit(IRQ_TO_GPIO(corgi_ts->irq_gpio))) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | /* Disable Interrupt */ |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 198 | set_irq_type(corgi_ts->irq_gpio, IRQ_TYPE_NONE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | if (read_xydata(corgi_ts)) { |
| 200 | corgi_ts->pendown = 1; |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 201 | new_data(corgi_ts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | } |
| 203 | mod_timer(&corgi_ts->timer, jiffies + HZ / 100); |
| 204 | } else { |
| 205 | if (corgi_ts->pendown == 1 || corgi_ts->pendown == 2) { |
| 206 | mod_timer(&corgi_ts->timer, jiffies + HZ / 100); |
| 207 | corgi_ts->pendown++; |
| 208 | return; |
| 209 | } |
| 210 | |
| 211 | if (corgi_ts->pendown) { |
| 212 | corgi_ts->tc.pressure = 0; |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 213 | new_data(corgi_ts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | /* Enable Falling Edge */ |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 217 | set_irq_type(corgi_ts->irq_gpio, IRQ_TYPE_EDGE_FALLING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | corgi_ts->pendown = 0; |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | static void corgi_ts_timer(unsigned long data) |
| 223 | { |
| 224 | struct corgi_ts *corgits_data = (struct corgi_ts *) data; |
Dmitry Torokhov | 52c1f57 | 2006-11-05 22:40:03 -0500 | [diff] [blame] | 225 | |
Russell King | 36bd262 | 2006-10-15 13:50:02 +0100 | [diff] [blame] | 226 | ts_interrupt_main(corgits_data, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | } |
| 228 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 229 | static irqreturn_t ts_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | { |
| 231 | struct corgi_ts *corgits_data = dev_id; |
Dmitry Torokhov | 52c1f57 | 2006-11-05 22:40:03 -0500 | [diff] [blame] | 232 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 233 | ts_interrupt_main(corgits_data, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | return IRQ_HANDLED; |
| 235 | } |
| 236 | |
| 237 | #ifdef CONFIG_PM |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 238 | static int corgits_suspend(struct platform_device *dev, pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 240 | struct corgi_ts *corgi_ts = platform_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 242 | if (corgi_ts->pendown) { |
| 243 | del_timer_sync(&corgi_ts->timer); |
| 244 | corgi_ts->tc.pressure = 0; |
Russell King | 36bd262 | 2006-10-15 13:50:02 +0100 | [diff] [blame] | 245 | new_data(corgi_ts); |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 246 | corgi_ts->pendown = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | } |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 248 | corgi_ts->power_mode = PWR_MODE_SUSPEND; |
| 249 | |
| 250 | corgi_ssp_ads7846_putget((1u << ADSCTRL_ADR_SH) | ADSCTRL_STS); |
| 251 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | return 0; |
| 253 | } |
| 254 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 255 | static int corgits_resume(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 257 | struct corgi_ts *corgi_ts = platform_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 259 | corgi_ssp_ads7846_putget((4u << ADSCTRL_ADR_SH) | ADSCTRL_STS); |
| 260 | /* Enable Falling Edge */ |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 261 | set_irq_type(corgi_ts->irq_gpio, IRQ_TYPE_EDGE_FALLING); |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 262 | corgi_ts->power_mode = PWR_MODE_ACTIVE; |
| 263 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | return 0; |
| 265 | } |
| 266 | #else |
| 267 | #define corgits_suspend NULL |
| 268 | #define corgits_resume NULL |
| 269 | #endif |
| 270 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 271 | static int __init corgits_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | { |
| 273 | struct corgi_ts *corgi_ts; |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 274 | struct input_dev *input_dev; |
| 275 | int err = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 277 | corgi_ts = kzalloc(sizeof(struct corgi_ts), GFP_KERNEL); |
| 278 | input_dev = input_allocate_device(); |
| 279 | if (!corgi_ts || !input_dev) |
Dmitry Torokhov | 52c1f57 | 2006-11-05 22:40:03 -0500 | [diff] [blame] | 280 | goto fail1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 282 | platform_set_drvdata(pdev, corgi_ts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 284 | corgi_ts->machinfo = pdev->dev.platform_data; |
Richard Purdie | 513b6e1 | 2005-09-13 01:25:33 -0700 | [diff] [blame] | 285 | corgi_ts->irq_gpio = platform_get_irq(pdev, 0); |
| 286 | |
| 287 | if (corgi_ts->irq_gpio < 0) { |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 288 | err = -ENODEV; |
Dmitry Torokhov | 52c1f57 | 2006-11-05 22:40:03 -0500 | [diff] [blame] | 289 | goto fail1; |
Richard Purdie | 513b6e1 | 2005-09-13 01:25:33 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 292 | corgi_ts->input = input_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 294 | init_timer(&corgi_ts->timer); |
| 295 | corgi_ts->timer.data = (unsigned long) corgi_ts; |
| 296 | corgi_ts->timer.function = corgi_ts_timer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 298 | input_dev->name = "Corgi Touchscreen"; |
| 299 | input_dev->phys = "corgits/input0"; |
| 300 | input_dev->id.bustype = BUS_HOST; |
| 301 | input_dev->id.vendor = 0x0001; |
| 302 | input_dev->id.product = 0x0002; |
| 303 | input_dev->id.version = 0x0100; |
Dmitry Torokhov | a5394fb0 | 2007-04-12 01:35:14 -0400 | [diff] [blame] | 304 | input_dev->dev.parent = &pdev->dev; |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 305 | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 306 | input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); |
| 307 | input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 308 | input_set_abs_params(input_dev, ABS_X, X_AXIS_MIN, X_AXIS_MAX, 0, 0); |
| 309 | input_set_abs_params(input_dev, ABS_Y, Y_AXIS_MIN, Y_AXIS_MAX, 0, 0); |
| 310 | input_set_abs_params(input_dev, ABS_PRESSURE, PRESSURE_MIN, PRESSURE_MAX, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | |
Richard Purdie | 513b6e1 | 2005-09-13 01:25:33 -0700 | [diff] [blame] | 312 | pxa_gpio_mode(IRQ_TO_GPIO(corgi_ts->irq_gpio) | GPIO_IN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | |
| 314 | /* Initiaize ADS7846 Difference Reference mode */ |
| 315 | corgi_ssp_ads7846_putget((1u << ADSCTRL_ADR_SH) | ADSCTRL_STS); |
| 316 | mdelay(5); |
| 317 | corgi_ssp_ads7846_putget((3u << ADSCTRL_ADR_SH) | ADSCTRL_STS); |
| 318 | mdelay(5); |
| 319 | corgi_ssp_ads7846_putget((4u << ADSCTRL_ADR_SH) | ADSCTRL_STS); |
| 320 | mdelay(5); |
| 321 | corgi_ssp_ads7846_putget((5u << ADSCTRL_ADR_SH) | ADSCTRL_STS); |
| 322 | mdelay(5); |
| 323 | |
Thomas Gleixner | dace145 | 2006-07-01 19:29:38 -0700 | [diff] [blame] | 324 | if (request_irq(corgi_ts->irq_gpio, ts_interrupt, IRQF_DISABLED, "ts", corgi_ts)) { |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 325 | err = -EBUSY; |
Dmitry Torokhov | 52c1f57 | 2006-11-05 22:40:03 -0500 | [diff] [blame] | 326 | goto fail1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | } |
| 328 | |
Dmitry Torokhov | 52c1f57 | 2006-11-05 22:40:03 -0500 | [diff] [blame] | 329 | err = input_register_device(corgi_ts->input); |
| 330 | if (err) |
| 331 | goto fail2; |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 332 | |
| 333 | corgi_ts->power_mode = PWR_MODE_ACTIVE; |
| 334 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | /* Enable Falling Edge */ |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 336 | set_irq_type(corgi_ts->irq_gpio, IRQ_TYPE_EDGE_FALLING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | return 0; |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 339 | |
Dmitry Torokhov | 52c1f57 | 2006-11-05 22:40:03 -0500 | [diff] [blame] | 340 | fail2: free_irq(corgi_ts->irq_gpio, corgi_ts); |
| 341 | fail1: input_free_device(input_dev); |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 342 | kfree(corgi_ts); |
| 343 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 346 | static int corgits_remove(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 348 | struct corgi_ts *corgi_ts = platform_get_drvdata(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | |
Dmitry Torokhov | 52c1f57 | 2006-11-05 22:40:03 -0500 | [diff] [blame] | 350 | free_irq(corgi_ts->irq_gpio, corgi_ts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | del_timer_sync(&corgi_ts->timer); |
Richard Purdie | 513b6e1 | 2005-09-13 01:25:33 -0700 | [diff] [blame] | 352 | corgi_ts->machinfo->put_hsync(); |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 353 | input_unregister_device(corgi_ts->input); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | kfree(corgi_ts); |
| 355 | return 0; |
| 356 | } |
| 357 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 358 | static struct platform_driver corgits_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | .probe = corgits_probe, |
| 360 | .remove = corgits_remove, |
| 361 | .suspend = corgits_suspend, |
| 362 | .resume = corgits_resume, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 363 | .driver = { |
| 364 | .name = "corgi-ts", |
Kay Sievers | d7b5247 | 2008-04-18 00:24:42 -0400 | [diff] [blame] | 365 | .owner = THIS_MODULE, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 366 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | }; |
| 368 | |
| 369 | static int __devinit corgits_init(void) |
| 370 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 371 | return platform_driver_register(&corgits_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | static void __exit corgits_exit(void) |
| 375 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 376 | platform_driver_unregister(&corgits_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | module_init(corgits_init); |
| 380 | module_exit(corgits_exit); |
| 381 | |
| 382 | MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>"); |
| 383 | MODULE_DESCRIPTION("Corgi TouchScreen Driver"); |
| 384 | MODULE_LICENSE("GPL"); |
Kay Sievers | d7b5247 | 2008-04-18 00:24:42 -0400 | [diff] [blame] | 385 | MODULE_ALIAS("platform:corgi-ts"); |