Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Copyright (c) 2001 "Crazy" James Simmons jsimmons@transvirtual.com |
| 3 | * |
| 4 | * Sponsored by Transvirtual Technology. |
| 5 | * |
| 6 | * Derived from the code in h3600_ts.[ch] by Charles Flynn |
| 7 | */ |
| 8 | |
| 9 | /* |
| 10 | * Driver for the h3600 Touch Screen and other Atmel controlled devices. |
| 11 | */ |
| 12 | |
| 13 | /* |
| 14 | * This program is free software; you can redistribute it and/or modify |
| 15 | * it under the terms of the GNU General Public License as published by |
| 16 | * the Free Software Foundation; either version 2 of the License, or |
| 17 | * (at your option) any later version. |
| 18 | * |
| 19 | * This program is distributed in the hope that it will be useful, |
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | * GNU General Public License for more details. |
| 23 | * |
| 24 | * You should have received a copy of the GNU General Public License |
| 25 | * along with this program; if not, write to the Free Software |
| 26 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 27 | * |
| 28 | * Should you need to contact me, the author, you can do so by |
| 29 | * e-mail - mail your message to <jsimmons@transvirtual.com>. |
| 30 | */ |
| 31 | |
| 32 | #include <linux/errno.h> |
| 33 | #include <linux/kernel.h> |
| 34 | #include <linux/module.h> |
| 35 | #include <linux/slab.h> |
| 36 | #include <linux/input.h> |
| 37 | #include <linux/serio.h> |
| 38 | #include <linux/init.h> |
| 39 | #include <linux/delay.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
| 41 | /* SA1100 serial defines */ |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 42 | #include <mach/hardware.h> |
| 43 | #include <mach/irqs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
| 45 | #define DRIVER_DESC "H3600 touchscreen driver" |
| 46 | |
| 47 | MODULE_AUTHOR("James Simmons <jsimmons@transvirtual.com>"); |
| 48 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 49 | MODULE_LICENSE("GPL"); |
| 50 | |
| 51 | /* |
| 52 | * Definitions & global arrays. |
| 53 | */ |
| 54 | |
| 55 | /* The start and end of frame characters SOF and EOF */ |
| 56 | #define CHAR_SOF 0x02 |
| 57 | #define CHAR_EOF 0x03 |
| 58 | #define FRAME_OVERHEAD 3 /* CHAR_SOF,CHAR_EOF,LENGTH = 3 */ |
| 59 | |
| 60 | /* |
| 61 | Atmel events and response IDs contained in frame. |
| 62 | Programmer has no control over these numbers. |
| 63 | TODO there are holes - specifically 1,7,0x0a |
| 64 | */ |
Sylvestre Ledru | d51ca07 | 2011-03-26 22:52:25 -0700 | [diff] [blame] | 65 | #define VERSION_ID 0 /* Get Version (request/response) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | #define KEYBD_ID 2 /* Keyboard (event) */ |
| 67 | #define TOUCHS_ID 3 /* Touch Screen (event)*/ |
| 68 | #define EEPROM_READ_ID 4 /* (request/response) */ |
| 69 | #define EEPROM_WRITE_ID 5 /* (request/response) */ |
| 70 | #define THERMAL_ID 6 /* (request/response) */ |
| 71 | #define NOTIFY_LED_ID 8 /* (request/response) */ |
| 72 | #define BATTERY_ID 9 /* (request/response) */ |
| 73 | #define SPI_READ_ID 0x0b /* ( request/response) */ |
| 74 | #define SPI_WRITE_ID 0x0c /* ( request/response) */ |
| 75 | #define FLITE_ID 0x0d /* backlight ( request/response) */ |
| 76 | #define STX_ID 0xa1 /* extension pack status (req/resp) */ |
| 77 | |
| 78 | #define MAX_ID 14 |
| 79 | |
| 80 | #define H3600_MAX_LENGTH 16 |
| 81 | #define H3600_KEY 0xf |
| 82 | |
| 83 | #define H3600_SCANCODE_RECORD 1 /* 1 -> record button */ |
| 84 | #define H3600_SCANCODE_CALENDAR 2 /* 2 -> calendar */ |
| 85 | #define H3600_SCANCODE_CONTACTS 3 /* 3 -> contact */ |
| 86 | #define H3600_SCANCODE_Q 4 /* 4 -> Q button */ |
| 87 | #define H3600_SCANCODE_START 5 /* 5 -> start menu */ |
| 88 | #define H3600_SCANCODE_UP 6 /* 6 -> up */ |
Dmitry Torokhov | de1b963 | 2005-05-29 02:28:50 -0500 | [diff] [blame] | 89 | #define H3600_SCANCODE_RIGHT 7 /* 7 -> right */ |
| 90 | #define H3600_SCANCODE_LEFT 8 /* 8 -> left */ |
| 91 | #define H3600_SCANCODE_DOWN 9 /* 9 -> down */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | /* |
| 94 | * Per-touchscreen data. |
| 95 | */ |
| 96 | struct h3600_dev { |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 97 | struct input_dev *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | struct serio *serio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | unsigned char event; /* event ID from packet */ |
| 100 | unsigned char chksum; |
| 101 | unsigned char len; |
| 102 | unsigned char idx; |
| 103 | unsigned char buf[H3600_MAX_LENGTH]; |
| 104 | char phys[32]; |
| 105 | }; |
| 106 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 107 | static irqreturn_t action_button_handler(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | { |
Dmitry Torokhov | de1b963 | 2005-05-29 02:28:50 -0500 | [diff] [blame] | 109 | int down = (GPLR & GPIO_BITSY_ACTION_BUTTON) ? 0 : 1; |
Jeff Garzik | 15aafa2 | 2008-02-06 01:36:20 -0800 | [diff] [blame] | 110 | struct input_dev *dev = dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | input_report_key(dev, KEY_ENTER, down); |
| 113 | input_sync(dev); |
| 114 | |
| 115 | return IRQ_HANDLED; |
| 116 | } |
| 117 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 118 | static irqreturn_t npower_button_handler(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | { |
Dmitry Torokhov | de1b963 | 2005-05-29 02:28:50 -0500 | [diff] [blame] | 120 | int down = (GPLR & GPIO_BITSY_NPOWER_BUTTON) ? 0 : 1; |
Jeff Garzik | 15aafa2 | 2008-02-06 01:36:20 -0800 | [diff] [blame] | 121 | struct input_dev *dev = dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
| 123 | /* |
| 124 | * This interrupt is only called when we release the key. So we have |
| 125 | * to fake a key press. |
| 126 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | input_report_key(dev, KEY_SUSPEND, 1); |
| 128 | input_report_key(dev, KEY_SUSPEND, down); |
| 129 | input_sync(dev); |
| 130 | |
| 131 | return IRQ_HANDLED; |
| 132 | } |
| 133 | |
| 134 | #ifdef CONFIG_PM |
| 135 | |
| 136 | static int flite_brightness = 25; |
| 137 | |
| 138 | enum flite_pwr { |
Dmitry Torokhov | de1b963 | 2005-05-29 02:28:50 -0500 | [diff] [blame] | 139 | FLITE_PWR_OFF = 0, |
| 140 | FLITE_PWR_ON = 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | }; |
| 142 | |
| 143 | /* |
| 144 | * h3600_flite_power: enables or disables power to frontlight, using last bright */ |
| 145 | unsigned int h3600_flite_power(struct input_dev *dev, enum flite_pwr pwr) |
| 146 | { |
| 147 | unsigned char brightness = (pwr == FLITE_PWR_OFF) ? 0 : flite_brightness; |
Dmitry Torokhov | 40b9b0b | 2007-04-12 01:34:08 -0400 | [diff] [blame] | 148 | struct h3600_dev *ts = input_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
| 150 | /* Must be in this order */ |
Dmitry Torokhov | dd0d544 | 2009-08-05 00:30:26 -0700 | [diff] [blame] | 151 | serio_write(ts->serio, 1); |
| 152 | serio_write(ts->serio, pwr); |
| 153 | serio_write(ts->serio, brightness); |
| 154 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | return 0; |
| 156 | } |
| 157 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | #endif |
| 159 | |
| 160 | /* |
| 161 | * This function translates the native event packets to linux input event |
| 162 | * packets. Some packets coming from serial are not touchscreen related. In |
| 163 | * this case we send them off to be processed elsewhere. |
| 164 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 165 | static void h3600ts_process_packet(struct h3600_dev *ts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | { |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 167 | struct input_dev *dev = ts->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | static int touched = 0; |
| 169 | int key, down = 0; |
| 170 | |
Dmitry Torokhov | de1b963 | 2005-05-29 02:28:50 -0500 | [diff] [blame] | 171 | switch (ts->event) { |
| 172 | /* |
| 173 | Buttons - returned as a single byte |
| 174 | 7 6 5 4 3 2 1 0 |
| 175 | S x x x N N N N |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
Dmitry Torokhov | de1b963 | 2005-05-29 02:28:50 -0500 | [diff] [blame] | 177 | S switch state ( 0=pressed 1=released) |
| 178 | x Unused. |
| 179 | NNNN switch number 0-15 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | |
Dmitry Torokhov | de1b963 | 2005-05-29 02:28:50 -0500 | [diff] [blame] | 181 | Note: This is true for non interrupt generated key events. |
| 182 | */ |
| 183 | case KEYBD_ID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | down = (ts->buf[0] & 0x80) ? 0 : 1; |
| 185 | |
| 186 | switch (ts->buf[0] & 0x7f) { |
| 187 | case H3600_SCANCODE_RECORD: |
| 188 | key = KEY_RECORD; |
| 189 | break; |
| 190 | case H3600_SCANCODE_CALENDAR: |
| 191 | key = KEY_PROG1; |
| 192 | break; |
| 193 | case H3600_SCANCODE_CONTACTS: |
| 194 | key = KEY_PROG2; |
Dmitry Torokhov | de1b963 | 2005-05-29 02:28:50 -0500 | [diff] [blame] | 195 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | case H3600_SCANCODE_Q: |
| 197 | key = KEY_Q; |
Dmitry Torokhov | de1b963 | 2005-05-29 02:28:50 -0500 | [diff] [blame] | 198 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | case H3600_SCANCODE_START: |
| 200 | key = KEY_PROG3; |
Dmitry Torokhov | de1b963 | 2005-05-29 02:28:50 -0500 | [diff] [blame] | 201 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | case H3600_SCANCODE_UP: |
| 203 | key = KEY_UP; |
Dmitry Torokhov | de1b963 | 2005-05-29 02:28:50 -0500 | [diff] [blame] | 204 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | case H3600_SCANCODE_RIGHT: |
| 206 | key = KEY_RIGHT; |
Dmitry Torokhov | de1b963 | 2005-05-29 02:28:50 -0500 | [diff] [blame] | 207 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | case H3600_SCANCODE_LEFT: |
| 209 | key = KEY_LEFT; |
Dmitry Torokhov | de1b963 | 2005-05-29 02:28:50 -0500 | [diff] [blame] | 210 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | case H3600_SCANCODE_DOWN: |
| 212 | key = KEY_DOWN; |
Dmitry Torokhov | de1b963 | 2005-05-29 02:28:50 -0500 | [diff] [blame] | 213 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | default: |
| 215 | key = 0; |
| 216 | } |
Dmitry Torokhov | de1b963 | 2005-05-29 02:28:50 -0500 | [diff] [blame] | 217 | if (key) |
| 218 | input_report_key(dev, key, down); |
| 219 | break; |
| 220 | /* |
| 221 | * Native touchscreen event data is formatted as shown below:- |
| 222 | * |
| 223 | * +-------+-------+-------+-------+ |
| 224 | * | Xmsb | Xlsb | Ymsb | Ylsb | |
| 225 | * +-------+-------+-------+-------+ |
| 226 | * byte 0 1 2 3 |
| 227 | */ |
| 228 | case TOUCHS_ID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | if (!touched) { |
| 230 | input_report_key(dev, BTN_TOUCH, 1); |
| 231 | touched = 1; |
| 232 | } |
| 233 | |
| 234 | if (ts->len) { |
| 235 | unsigned short x, y; |
| 236 | |
| 237 | x = ts->buf[0]; x <<= 8; x += ts->buf[1]; |
Dmitry Torokhov | de1b963 | 2005-05-29 02:28:50 -0500 | [diff] [blame] | 238 | y = ts->buf[2]; y <<= 8; y += ts->buf[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | |
Dmitry Torokhov | de1b963 | 2005-05-29 02:28:50 -0500 | [diff] [blame] | 240 | input_report_abs(dev, ABS_X, x); |
| 241 | input_report_abs(dev, ABS_Y, y); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | } else { |
Dmitry Torokhov | de1b963 | 2005-05-29 02:28:50 -0500 | [diff] [blame] | 243 | input_report_key(dev, BTN_TOUCH, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | touched = 0; |
| 245 | } |
Dmitry Torokhov | de1b963 | 2005-05-29 02:28:50 -0500 | [diff] [blame] | 246 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | default: |
| 248 | /* Send a non input event elsewhere */ |
| 249 | break; |
Dmitry Torokhov | de1b963 | 2005-05-29 02:28:50 -0500 | [diff] [blame] | 250 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
| 252 | input_sync(dev); |
| 253 | } |
| 254 | |
| 255 | /* |
| 256 | * h3600ts_event() handles events from the input module. |
| 257 | */ |
| 258 | static int h3600ts_event(struct input_dev *dev, unsigned int type, |
Dmitry Torokhov | de1b963 | 2005-05-29 02:28:50 -0500 | [diff] [blame] | 259 | unsigned int code, int value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | { |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 261 | #if 0 |
Dmitry Torokhov | 40b9b0b | 2007-04-12 01:34:08 -0400 | [diff] [blame] | 262 | struct h3600_dev *ts = input_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | |
| 264 | switch (type) { |
| 265 | case EV_LED: { |
Dmitry Torokhov | dd0d544 | 2009-08-05 00:30:26 -0700 | [diff] [blame] | 266 | // serio_write(ts->serio, SOME_CMD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | return 0; |
| 268 | } |
| 269 | } |
| 270 | return -1; |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 271 | #endif |
| 272 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | /* |
| 276 | Frame format |
| 277 | byte 1 2 3 len + 4 |
| 278 | +-------+---------------+---------------+--=------------+ |
| 279 | |SOF |id |len | len bytes | Chksum | |
| 280 | +-------+---------------+---------------+--=------------+ |
| 281 | bit 0 7 8 11 12 15 16 |
| 282 | |
| 283 | +-------+---------------+-------+ |
| 284 | |SOF |id |0 |Chksum | - Note Chksum does not include SOF |
| 285 | +-------+---------------+-------+ |
| 286 | bit 0 7 8 11 12 15 16 |
| 287 | |
| 288 | */ |
| 289 | |
| 290 | static int state; |
| 291 | |
| 292 | /* decode States */ |
| 293 | #define STATE_SOF 0 /* start of FRAME */ |
| 294 | #define STATE_ID 1 /* state where we decode the ID & len */ |
| 295 | #define STATE_DATA 2 /* state where we decode data */ |
| 296 | #define STATE_EOF 3 /* state where we decode checksum or EOF */ |
| 297 | |
| 298 | static irqreturn_t h3600ts_interrupt(struct serio *serio, unsigned char data, |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 299 | unsigned int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | { |
Dmitry Torokhov | de1b963 | 2005-05-29 02:28:50 -0500 | [diff] [blame] | 301 | struct h3600_dev *ts = serio_get_drvdata(serio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | |
| 303 | /* |
Dmitry Torokhov | de1b963 | 2005-05-29 02:28:50 -0500 | [diff] [blame] | 304 | * We have a new frame coming in. |
| 305 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | switch (state) { |
| 307 | case STATE_SOF: |
Dmitry Torokhov | de1b963 | 2005-05-29 02:28:50 -0500 | [diff] [blame] | 308 | if (data == CHAR_SOF) |
| 309 | state = STATE_ID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | break; |
Dmitry Torokhov | de1b963 | 2005-05-29 02:28:50 -0500 | [diff] [blame] | 311 | case STATE_ID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | ts->event = (data & 0xf0) >> 4; |
| 313 | ts->len = (data & 0xf); |
| 314 | ts->idx = 0; |
| 315 | if (ts->event >= MAX_ID) { |
| 316 | state = STATE_SOF; |
Dmitry Torokhov | de1b963 | 2005-05-29 02:28:50 -0500 | [diff] [blame] | 317 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | } |
| 319 | ts->chksum = data; |
Dmitry Torokhov | de1b963 | 2005-05-29 02:28:50 -0500 | [diff] [blame] | 320 | state = (ts->len > 0) ? STATE_DATA : STATE_EOF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | break; |
| 322 | case STATE_DATA: |
| 323 | ts->chksum += data; |
| 324 | ts->buf[ts->idx]= data; |
Dmitry Torokhov | de1b963 | 2005-05-29 02:28:50 -0500 | [diff] [blame] | 325 | if (++ts->idx == ts->len) |
| 326 | state = STATE_EOF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | break; |
| 328 | case STATE_EOF: |
Dmitry Torokhov | de1b963 | 2005-05-29 02:28:50 -0500 | [diff] [blame] | 329 | state = STATE_SOF; |
| 330 | if (data == CHAR_EOF || data == ts->chksum) |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 331 | h3600ts_process_packet(ts); |
Dmitry Torokhov | de1b963 | 2005-05-29 02:28:50 -0500 | [diff] [blame] | 332 | break; |
| 333 | default: |
| 334 | printk("Error3\n"); |
| 335 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | return IRQ_HANDLED; |
| 339 | } |
| 340 | |
| 341 | /* |
| 342 | * h3600ts_connect() is the routine that is called when someone adds a |
| 343 | * new serio device that supports H3600 protocol and registers it as |
| 344 | * an input device. |
| 345 | */ |
| 346 | static int h3600ts_connect(struct serio *serio, struct serio_driver *drv) |
| 347 | { |
| 348 | struct h3600_dev *ts; |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 349 | struct input_dev *input_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | int err; |
| 351 | |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 352 | ts = kzalloc(sizeof(struct h3600_dev), GFP_KERNEL); |
| 353 | input_dev = input_allocate_device(); |
| 354 | if (!ts || !input_dev) { |
| 355 | err = -ENOMEM; |
| 356 | goto fail1; |
| 357 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 359 | ts->serio = serio; |
| 360 | ts->dev = input_dev; |
Dmitry Torokhov | a21466c | 2006-06-26 01:46:04 -0400 | [diff] [blame] | 361 | snprintf(ts->phys, sizeof(ts->phys), "%s/input0", serio->phys); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 363 | input_dev->name = "H3600 TouchScreen"; |
| 364 | input_dev->phys = ts->phys; |
| 365 | input_dev->id.bustype = BUS_RS232; |
| 366 | input_dev->id.vendor = SERIO_H3600; |
| 367 | input_dev->id.product = 0x0666; /* FIXME !!! We can ask the hardware */ |
| 368 | input_dev->id.version = 0x0100; |
Dmitry Torokhov | a5394fb0 | 2007-04-12 01:35:14 -0400 | [diff] [blame] | 369 | input_dev->dev.parent = &serio->dev; |
Dmitry Torokhov | 40b9b0b | 2007-04-12 01:34:08 -0400 | [diff] [blame] | 370 | |
| 371 | input_set_drvdata(input_dev, ts); |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 372 | |
| 373 | input_dev->event = h3600ts_event; |
| 374 | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 375 | input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS) | |
| 376 | BIT_MASK(EV_LED) | BIT_MASK(EV_PWR); |
| 377 | input_dev->ledbit[0] = BIT_MASK(LED_SLEEP); |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 378 | input_set_abs_params(input_dev, ABS_X, 60, 985, 0, 0); |
| 379 | input_set_abs_params(input_dev, ABS_Y, 35, 1024, 0, 0); |
| 380 | |
| 381 | set_bit(KEY_RECORD, input_dev->keybit); |
| 382 | set_bit(KEY_Q, input_dev->keybit); |
| 383 | set_bit(KEY_PROG1, input_dev->keybit); |
| 384 | set_bit(KEY_PROG2, input_dev->keybit); |
| 385 | set_bit(KEY_PROG3, input_dev->keybit); |
| 386 | set_bit(KEY_UP, input_dev->keybit); |
| 387 | set_bit(KEY_RIGHT, input_dev->keybit); |
| 388 | set_bit(KEY_LEFT, input_dev->keybit); |
| 389 | set_bit(KEY_DOWN, input_dev->keybit); |
| 390 | set_bit(KEY_ENTER, input_dev->keybit); |
| 391 | set_bit(KEY_SUSPEND, input_dev->keybit); |
| 392 | set_bit(BTN_TOUCH, input_dev->keybit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | |
| 394 | /* Device specific stuff */ |
Dmitry Torokhov | de1b963 | 2005-05-29 02:28:50 -0500 | [diff] [blame] | 395 | set_GPIO_IRQ_edge(GPIO_BITSY_ACTION_BUTTON, GPIO_BOTH_EDGES); |
| 396 | set_GPIO_IRQ_edge(GPIO_BITSY_NPOWER_BUTTON, GPIO_RISING_EDGE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | |
Dmitry Torokhov | de1b963 | 2005-05-29 02:28:50 -0500 | [diff] [blame] | 398 | if (request_irq(IRQ_GPIO_BITSY_ACTION_BUTTON, action_button_handler, |
Yong Zhang | ec4665c | 2011-09-07 14:04:16 -0700 | [diff] [blame] | 399 | IRQF_SHARED, "h3600_action", ts->dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | printk(KERN_ERR "h3600ts.c: Could not allocate Action Button IRQ!\n"); |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 401 | err = -EBUSY; |
Christoph Fritz | 9084338 | 2011-04-06 15:33:16 -0700 | [diff] [blame] | 402 | goto fail1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | } |
| 404 | |
Dmitry Torokhov | de1b963 | 2005-05-29 02:28:50 -0500 | [diff] [blame] | 405 | if (request_irq(IRQ_GPIO_BITSY_NPOWER_BUTTON, npower_button_handler, |
Yong Zhang | ec4665c | 2011-09-07 14:04:16 -0700 | [diff] [blame] | 406 | IRQF_SHARED, "h3600_suspend", ts->dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | printk(KERN_ERR "h3600ts.c: Could not allocate Power Button IRQ!\n"); |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 408 | err = -EBUSY; |
Christoph Fritz | 9084338 | 2011-04-06 15:33:16 -0700 | [diff] [blame] | 409 | goto fail2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | } |
| 411 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | serio_set_drvdata(serio, ts); |
| 413 | |
| 414 | err = serio_open(serio, drv); |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 415 | if (err) |
Christoph Fritz | 9084338 | 2011-04-06 15:33:16 -0700 | [diff] [blame] | 416 | goto fail3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | |
| 418 | //h3600_flite_control(1, 25); /* default brightness */ |
Christoph Fritz | 9084338 | 2011-04-06 15:33:16 -0700 | [diff] [blame] | 419 | err = input_register_device(ts->dev); |
| 420 | if (err) |
| 421 | goto fail4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | |
| 423 | return 0; |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 424 | |
Christoph Fritz | 9084338 | 2011-04-06 15:33:16 -0700 | [diff] [blame] | 425 | fail4: serio_close(serio); |
| 426 | fail3: serio_set_drvdata(serio, NULL); |
| 427 | free_irq(IRQ_GPIO_BITSY_NPOWER_BUTTON, ts->dev); |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 428 | fail2: free_irq(IRQ_GPIO_BITSY_ACTION_BUTTON, ts->dev); |
Christoph Fritz | 9084338 | 2011-04-06 15:33:16 -0700 | [diff] [blame] | 429 | fail1: input_free_device(input_dev); |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 430 | kfree(ts); |
| 431 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | /* |
| 435 | * h3600ts_disconnect() is the opposite of h3600ts_connect() |
| 436 | */ |
| 437 | |
| 438 | static void h3600ts_disconnect(struct serio *serio) |
| 439 | { |
| 440 | struct h3600_dev *ts = serio_get_drvdata(serio); |
| 441 | |
Axel Lin | 4296f1a | 2011-05-03 08:56:56 -0700 | [diff] [blame] | 442 | free_irq(IRQ_GPIO_BITSY_ACTION_BUTTON, ts->dev); |
| 443 | free_irq(IRQ_GPIO_BITSY_NPOWER_BUTTON, ts->dev); |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 444 | input_get_device(ts->dev); |
| 445 | input_unregister_device(ts->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | serio_close(serio); |
| 447 | serio_set_drvdata(serio, NULL); |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 448 | input_put_device(ts->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | kfree(ts); |
| 450 | } |
| 451 | |
| 452 | /* |
| 453 | * The serio driver structure. |
| 454 | */ |
| 455 | |
| 456 | static struct serio_device_id h3600ts_serio_ids[] = { |
| 457 | { |
| 458 | .type = SERIO_RS232, |
| 459 | .proto = SERIO_H3600, |
| 460 | .id = SERIO_ANY, |
| 461 | .extra = SERIO_ANY, |
| 462 | }, |
| 463 | { 0 } |
| 464 | }; |
| 465 | |
| 466 | MODULE_DEVICE_TABLE(serio, h3600ts_serio_ids); |
| 467 | |
| 468 | static struct serio_driver h3600ts_drv = { |
| 469 | .driver = { |
| 470 | .name = "h3600ts", |
| 471 | }, |
| 472 | .description = DRIVER_DESC, |
| 473 | .id_table = h3600ts_serio_ids, |
| 474 | .interrupt = h3600ts_interrupt, |
| 475 | .connect = h3600ts_connect, |
| 476 | .disconnect = h3600ts_disconnect, |
| 477 | }; |
| 478 | |
| 479 | /* |
| 480 | * The functions for inserting/removing us as a module. |
| 481 | */ |
| 482 | |
| 483 | static int __init h3600ts_init(void) |
| 484 | { |
Akinobu Mita | 153a9df0 | 2006-11-23 23:35:10 -0500 | [diff] [blame] | 485 | return serio_register_driver(&h3600ts_drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | static void __exit h3600ts_exit(void) |
| 489 | { |
| 490 | serio_unregister_driver(&h3600ts_drv); |
| 491 | } |
| 492 | |
| 493 | module_init(h3600ts_init); |
| 494 | module_exit(h3600ts_exit); |