Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Elo serial touchscreen driver |
| 3 | * |
| 4 | * Copyright (c) 2004 Vojtech Pavlik |
| 5 | */ |
| 6 | |
| 7 | /* |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License version 2 as published by |
| 10 | * the Free Software Foundation. |
| 11 | */ |
| 12 | |
| 13 | /* |
| 14 | * This driver can handle serial Elo touchscreens using either the Elo standard |
| 15 | * 'E271-2210' 10-byte protocol, Elo legacy 'E281A-4002' 6-byte protocol, Elo |
| 16 | * legacy 'E271-140' 4-byte protocol and Elo legacy 'E261-280' 3-byte protocol. |
| 17 | */ |
| 18 | |
| 19 | #include <linux/errno.h> |
| 20 | #include <linux/kernel.h> |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/slab.h> |
| 23 | #include <linux/input.h> |
| 24 | #include <linux/serio.h> |
| 25 | #include <linux/init.h> |
Shaun Jackman | fae3006 | 2006-08-05 00:29:49 -0400 | [diff] [blame] | 26 | #include <linux/ctype.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
| 28 | #define DRIVER_DESC "Elo serial touchscreen driver" |
| 29 | |
| 30 | MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); |
| 31 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 32 | MODULE_LICENSE("GPL"); |
| 33 | |
| 34 | /* |
| 35 | * Definitions & global arrays. |
| 36 | */ |
| 37 | |
Shaun Jackman | 1ce316e | 2006-08-05 00:27:59 -0400 | [diff] [blame] | 38 | #define ELO_MAX_LENGTH 10 |
| 39 | |
Shaun Jackman | fae3006 | 2006-08-05 00:29:49 -0400 | [diff] [blame] | 40 | #define ELO10_PACKET_LEN 8 |
| 41 | #define ELO10_TOUCH 0x03 |
| 42 | #define ELO10_PRESSURE 0x80 |
| 43 | |
Shaun Jackman | 1ce316e | 2006-08-05 00:27:59 -0400 | [diff] [blame] | 44 | #define ELO10_LEAD_BYTE 'U' |
| 45 | |
Shaun Jackman | fae3006 | 2006-08-05 00:29:49 -0400 | [diff] [blame] | 46 | #define ELO10_ID_CMD 'i' |
| 47 | |
Shaun Jackman | 1ce316e | 2006-08-05 00:27:59 -0400 | [diff] [blame] | 48 | #define ELO10_TOUCH_PACKET 'T' |
Shaun Jackman | fae3006 | 2006-08-05 00:29:49 -0400 | [diff] [blame] | 49 | #define ELO10_ACK_PACKET 'A' |
| 50 | #define ELI10_ID_PACKET 'I' |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | /* |
| 53 | * Per-touchscreen data. |
| 54 | */ |
| 55 | |
| 56 | struct elo { |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 57 | struct input_dev *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | struct serio *serio; |
Shaun Jackman | fae3006 | 2006-08-05 00:29:49 -0400 | [diff] [blame] | 59 | struct mutex cmd_mutex; |
| 60 | struct completion cmd_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | int id; |
| 62 | int idx; |
Shaun Jackman | fae3006 | 2006-08-05 00:29:49 -0400 | [diff] [blame] | 63 | unsigned char expected_packet; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | unsigned char csum; |
| 65 | unsigned char data[ELO_MAX_LENGTH]; |
Shaun Jackman | fae3006 | 2006-08-05 00:29:49 -0400 | [diff] [blame] | 66 | unsigned char response[ELO10_PACKET_LEN]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | char phys[32]; |
| 68 | }; |
| 69 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 70 | static void elo_process_data_10(struct elo *elo, unsigned char data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | { |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 72 | struct input_dev *dev = elo->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
Shaun Jackman | 1ce316e | 2006-08-05 00:27:59 -0400 | [diff] [blame] | 74 | elo->data[elo->idx] = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | switch (elo->idx++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | case 0: |
Shaun Jackman | 1ce316e | 2006-08-05 00:27:59 -0400 | [diff] [blame] | 77 | elo->csum = 0xaa; |
| 78 | if (data != ELO10_LEAD_BYTE) { |
| 79 | pr_debug("elo: unsynchronized data: 0x%02x\n", data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | elo->idx = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | } |
| 82 | break; |
| 83 | |
| 84 | case 9: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | elo->idx = 0; |
Shaun Jackman | 1ce316e | 2006-08-05 00:27:59 -0400 | [diff] [blame] | 86 | if (data != elo->csum) { |
| 87 | pr_debug("elo: bad checksum: 0x%02x, expected 0x%02x\n", |
| 88 | data, elo->csum); |
| 89 | break; |
| 90 | } |
Shaun Jackman | fae3006 | 2006-08-05 00:29:49 -0400 | [diff] [blame] | 91 | if (elo->data[1] != elo->expected_packet) { |
| 92 | if (elo->data[1] != ELO10_TOUCH_PACKET) |
| 93 | pr_debug("elo: unexpected packet: 0x%02x\n", |
| 94 | elo->data[1]); |
Shaun Jackman | 1ce316e | 2006-08-05 00:27:59 -0400 | [diff] [blame] | 95 | break; |
| 96 | } |
Shaun Jackman | fae3006 | 2006-08-05 00:29:49 -0400 | [diff] [blame] | 97 | if (likely(elo->data[1] == ELO10_TOUCH_PACKET)) { |
Shaun Jackman | fae3006 | 2006-08-05 00:29:49 -0400 | [diff] [blame] | 98 | input_report_abs(dev, ABS_X, (elo->data[4] << 8) | elo->data[3]); |
| 99 | input_report_abs(dev, ABS_Y, (elo->data[6] << 8) | elo->data[5]); |
| 100 | if (elo->data[2] & ELO10_PRESSURE) |
| 101 | input_report_abs(dev, ABS_PRESSURE, |
| 102 | (elo->data[8] << 8) | elo->data[7]); |
| 103 | input_report_key(dev, BTN_TOUCH, elo->data[2] & ELO10_TOUCH); |
| 104 | input_sync(dev); |
| 105 | } else if (elo->data[1] == ELO10_ACK_PACKET) { |
| 106 | if (elo->data[2] == '0') |
| 107 | elo->expected_packet = ELO10_TOUCH_PACKET; |
| 108 | complete(&elo->cmd_done); |
| 109 | } else { |
| 110 | memcpy(elo->response, &elo->data[1], ELO10_PACKET_LEN); |
| 111 | elo->expected_packet = ELO10_ACK_PACKET; |
| 112 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | break; |
| 114 | } |
Shaun Jackman | 1ce316e | 2006-08-05 00:27:59 -0400 | [diff] [blame] | 115 | elo->csum += data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | } |
| 117 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 118 | static void elo_process_data_6(struct elo *elo, unsigned char data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | { |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 120 | struct input_dev *dev = elo->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
| 122 | elo->data[elo->idx] = data; |
| 123 | |
| 124 | switch (elo->idx++) { |
| 125 | |
| 126 | case 0: if ((data & 0xc0) != 0xc0) elo->idx = 0; break; |
| 127 | case 1: if ((data & 0xc0) != 0x80) elo->idx = 0; break; |
| 128 | case 2: if ((data & 0xc0) != 0x40) elo->idx = 0; break; |
| 129 | |
| 130 | case 3: |
| 131 | if (data & 0xc0) { |
| 132 | elo->idx = 0; |
| 133 | break; |
| 134 | } |
| 135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | input_report_abs(dev, ABS_X, ((elo->data[0] & 0x3f) << 6) | (elo->data[1] & 0x3f)); |
| 137 | input_report_abs(dev, ABS_Y, ((elo->data[2] & 0x3f) << 6) | (elo->data[3] & 0x3f)); |
| 138 | |
| 139 | if (elo->id == 2) { |
| 140 | input_report_key(dev, BTN_TOUCH, 1); |
| 141 | input_sync(dev); |
| 142 | elo->idx = 0; |
| 143 | } |
| 144 | |
| 145 | break; |
| 146 | |
| 147 | case 4: |
| 148 | if (data) { |
| 149 | input_sync(dev); |
| 150 | elo->idx = 0; |
| 151 | } |
| 152 | break; |
| 153 | |
| 154 | case 5: |
| 155 | if ((data & 0xf0) == 0) { |
| 156 | input_report_abs(dev, ABS_PRESSURE, elo->data[5]); |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 157 | input_report_key(dev, BTN_TOUCH, !!elo->data[5]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | } |
| 159 | input_sync(dev); |
| 160 | elo->idx = 0; |
| 161 | break; |
| 162 | } |
| 163 | } |
| 164 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 165 | static void elo_process_data_3(struct elo *elo, unsigned char data) |
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 = elo->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | |
| 169 | elo->data[elo->idx] = data; |
| 170 | |
| 171 | switch (elo->idx++) { |
| 172 | |
| 173 | case 0: |
| 174 | if ((data & 0x7f) != 0x01) |
| 175 | elo->idx = 0; |
| 176 | break; |
| 177 | case 2: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | input_report_key(dev, BTN_TOUCH, !(elo->data[1] & 0x80)); |
| 179 | input_report_abs(dev, ABS_X, elo->data[1]); |
| 180 | input_report_abs(dev, ABS_Y, elo->data[2]); |
| 181 | input_sync(dev); |
| 182 | elo->idx = 0; |
| 183 | break; |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | static irqreturn_t elo_interrupt(struct serio *serio, |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 188 | unsigned char data, unsigned int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | { |
Shaun Jackman | 1ce316e | 2006-08-05 00:27:59 -0400 | [diff] [blame] | 190 | struct elo *elo = serio_get_drvdata(serio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | |
| 192 | switch(elo->id) { |
| 193 | case 0: |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 194 | elo_process_data_10(elo, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | break; |
| 196 | |
| 197 | case 1: |
| 198 | case 2: |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 199 | elo_process_data_6(elo, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | break; |
| 201 | |
| 202 | case 3: |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 203 | elo_process_data_3(elo, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | break; |
| 205 | } |
| 206 | |
| 207 | return IRQ_HANDLED; |
| 208 | } |
| 209 | |
Shaun Jackman | fae3006 | 2006-08-05 00:29:49 -0400 | [diff] [blame] | 210 | static int elo_command_10(struct elo *elo, unsigned char *packet) |
| 211 | { |
| 212 | int rc = -1; |
| 213 | int i; |
| 214 | unsigned char csum = 0xaa + ELO10_LEAD_BYTE; |
| 215 | |
| 216 | mutex_lock(&elo->cmd_mutex); |
| 217 | |
| 218 | serio_pause_rx(elo->serio); |
| 219 | elo->expected_packet = toupper(packet[0]); |
| 220 | init_completion(&elo->cmd_done); |
| 221 | serio_continue_rx(elo->serio); |
| 222 | |
| 223 | if (serio_write(elo->serio, ELO10_LEAD_BYTE)) |
| 224 | goto out; |
| 225 | |
| 226 | for (i = 0; i < ELO10_PACKET_LEN; i++) { |
| 227 | csum += packet[i]; |
| 228 | if (serio_write(elo->serio, packet[i])) |
| 229 | goto out; |
| 230 | } |
| 231 | |
| 232 | if (serio_write(elo->serio, csum)) |
| 233 | goto out; |
| 234 | |
| 235 | wait_for_completion_timeout(&elo->cmd_done, HZ); |
| 236 | |
| 237 | if (elo->expected_packet == ELO10_TOUCH_PACKET) { |
| 238 | /* We are back in reporting mode, the command was ACKed */ |
| 239 | memcpy(packet, elo->response, ELO10_PACKET_LEN); |
| 240 | rc = 0; |
| 241 | } |
| 242 | |
| 243 | out: |
| 244 | mutex_unlock(&elo->cmd_mutex); |
| 245 | return rc; |
| 246 | } |
| 247 | |
| 248 | static int elo_setup_10(struct elo *elo) |
| 249 | { |
| 250 | static const char *elo_types[] = { "Accu", "Dura", "Intelli", "Carroll" }; |
| 251 | struct input_dev *dev = elo->dev; |
| 252 | unsigned char packet[ELO10_PACKET_LEN] = { ELO10_ID_CMD }; |
| 253 | |
| 254 | if (elo_command_10(elo, packet)) |
| 255 | return -1; |
| 256 | |
| 257 | dev->id.version = (packet[5] << 8) | packet[4]; |
| 258 | |
| 259 | input_set_abs_params(dev, ABS_X, 96, 4000, 0, 0); |
| 260 | input_set_abs_params(dev, ABS_Y, 96, 4000, 0, 0); |
| 261 | if (packet[3] & ELO10_PRESSURE) |
| 262 | input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0); |
| 263 | |
| 264 | printk(KERN_INFO "elo: %sTouch touchscreen, fw: %02x.%02x, " |
Vojtech Pavlik | 9a5415f | 2008-10-30 09:11:40 -0400 | [diff] [blame] | 265 | "features: 0x%02x, controller: 0x%02x\n", |
Shaun Jackman | fae3006 | 2006-08-05 00:29:49 -0400 | [diff] [blame] | 266 | elo_types[(packet[1] -'0') & 0x03], |
| 267 | packet[5], packet[4], packet[3], packet[7]); |
| 268 | |
| 269 | return 0; |
| 270 | } |
| 271 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | /* |
| 273 | * elo_disconnect() is the opposite of elo_connect() |
| 274 | */ |
| 275 | |
| 276 | static void elo_disconnect(struct serio *serio) |
| 277 | { |
Dmitry Torokhov | 6b50d8b | 2006-08-05 00:27:00 -0400 | [diff] [blame] | 278 | struct elo *elo = serio_get_drvdata(serio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | |
Dmitry Torokhov | 6b50d8b | 2006-08-05 00:27:00 -0400 | [diff] [blame] | 280 | input_get_device(elo->dev); |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 281 | input_unregister_device(elo->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | serio_close(serio); |
| 283 | serio_set_drvdata(serio, NULL); |
Dmitry Torokhov | 6b50d8b | 2006-08-05 00:27:00 -0400 | [diff] [blame] | 284 | input_put_device(elo->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | kfree(elo); |
| 286 | } |
| 287 | |
| 288 | /* |
| 289 | * elo_connect() is the routine that is called when someone adds a |
| 290 | * new serio device that supports Gunze protocol and registers it as |
| 291 | * an input device. |
| 292 | */ |
| 293 | |
| 294 | static int elo_connect(struct serio *serio, struct serio_driver *drv) |
| 295 | { |
| 296 | struct elo *elo; |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 297 | struct input_dev *input_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | int err; |
| 299 | |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 300 | elo = kzalloc(sizeof(struct elo), GFP_KERNEL); |
| 301 | input_dev = input_allocate_device(); |
| 302 | if (!elo || !input_dev) { |
| 303 | err = -ENOMEM; |
Dmitry Torokhov | 6b50d8b | 2006-08-05 00:27:00 -0400 | [diff] [blame] | 304 | goto fail1; |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 305 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 307 | elo->serio = serio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | elo->id = serio->id.id; |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 309 | elo->dev = input_dev; |
Shaun Jackman | fae3006 | 2006-08-05 00:29:49 -0400 | [diff] [blame] | 310 | elo->expected_packet = ELO10_TOUCH_PACKET; |
| 311 | mutex_init(&elo->cmd_mutex); |
| 312 | init_completion(&elo->cmd_done); |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 313 | snprintf(elo->phys, sizeof(elo->phys), "%s/input0", serio->phys); |
| 314 | |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 315 | input_dev->name = "Elo Serial TouchScreen"; |
| 316 | input_dev->phys = elo->phys; |
| 317 | input_dev->id.bustype = BUS_RS232; |
| 318 | input_dev->id.vendor = SERIO_ELO; |
| 319 | input_dev->id.product = elo->id; |
| 320 | input_dev->id.version = 0x0100; |
Dmitry Torokhov | a5394fb0 | 2007-04-12 01:35:14 -0400 | [diff] [blame] | 321 | input_dev->dev.parent = &serio->dev; |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 322 | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 323 | input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); |
| 324 | input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
Shaun Jackman | fae3006 | 2006-08-05 00:29:49 -0400 | [diff] [blame] | 326 | serio_set_drvdata(serio, elo); |
| 327 | err = serio_open(serio, drv); |
| 328 | if (err) |
| 329 | goto fail2; |
| 330 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | switch (elo->id) { |
| 332 | |
| 333 | case 0: /* 10-byte protocol */ |
Shaun Jackman | fae3006 | 2006-08-05 00:29:49 -0400 | [diff] [blame] | 334 | if (elo_setup_10(elo)) |
| 335 | goto fail3; |
| 336 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | break; |
Dmitry Torokhov | de1b963 | 2005-05-29 02:28:50 -0500 | [diff] [blame] | 338 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | case 1: /* 6-byte protocol */ |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 340 | input_set_abs_params(input_dev, ABS_PRESSURE, 0, 15, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
| 342 | case 2: /* 4-byte protocol */ |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 343 | input_set_abs_params(input_dev, ABS_X, 96, 4000, 0, 0); |
| 344 | input_set_abs_params(input_dev, ABS_Y, 96, 4000, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | break; |
| 346 | |
| 347 | case 3: /* 3-byte protocol */ |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 348 | input_set_abs_params(input_dev, ABS_X, 0, 255, 0, 0); |
| 349 | input_set_abs_params(input_dev, ABS_Y, 0, 255, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | break; |
| 351 | } |
| 352 | |
Dmitry Torokhov | 6b50d8b | 2006-08-05 00:27:00 -0400 | [diff] [blame] | 353 | err = input_register_device(elo->dev); |
| 354 | if (err) |
| 355 | goto fail3; |
| 356 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | return 0; |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 358 | |
Dmitry Torokhov | 6b50d8b | 2006-08-05 00:27:00 -0400 | [diff] [blame] | 359 | fail3: serio_close(serio); |
| 360 | fail2: serio_set_drvdata(serio, NULL); |
| 361 | fail1: input_free_device(input_dev); |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 362 | kfree(elo); |
| 363 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | /* |
| 367 | * The serio driver structure. |
| 368 | */ |
| 369 | |
| 370 | static struct serio_device_id elo_serio_ids[] = { |
| 371 | { |
| 372 | .type = SERIO_RS232, |
| 373 | .proto = SERIO_ELO, |
| 374 | .id = SERIO_ANY, |
| 375 | .extra = SERIO_ANY, |
| 376 | }, |
| 377 | { 0 } |
| 378 | }; |
| 379 | |
| 380 | MODULE_DEVICE_TABLE(serio, elo_serio_ids); |
| 381 | |
| 382 | static struct serio_driver elo_drv = { |
| 383 | .driver = { |
| 384 | .name = "elo", |
| 385 | }, |
| 386 | .description = DRIVER_DESC, |
| 387 | .id_table = elo_serio_ids, |
| 388 | .interrupt = elo_interrupt, |
| 389 | .connect = elo_connect, |
| 390 | .disconnect = elo_disconnect, |
| 391 | }; |
| 392 | |
| 393 | /* |
| 394 | * The functions for inserting/removing us as a module. |
| 395 | */ |
| 396 | |
| 397 | static int __init elo_init(void) |
| 398 | { |
Akinobu Mita | 153a9df0 | 2006-11-23 23:35:10 -0500 | [diff] [blame] | 399 | return serio_register_driver(&elo_drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | static void __exit elo_exit(void) |
| 403 | { |
| 404 | serio_unregister_driver(&elo_drv); |
| 405 | } |
| 406 | |
| 407 | module_init(elo_init); |
| 408 | module_exit(elo_exit); |