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