Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * $Id: gunze.c,v 1.12 2001/09/25 10:12:07 vojtech Exp $ |
| 3 | * |
| 4 | * Copyright (c) 2000-2001 Vojtech Pavlik |
| 5 | */ |
| 6 | |
| 7 | /* |
| 8 | * Gunze AHL-51S touchscreen driver for Linux |
| 9 | */ |
| 10 | |
| 11 | /* |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2 of the License, or |
| 15 | * (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 | * |
| 26 | * Should you need to contact me, the author, you can do so either by |
| 27 | * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail: |
| 28 | * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic |
| 29 | */ |
| 30 | |
| 31 | #include <linux/errno.h> |
| 32 | #include <linux/kernel.h> |
| 33 | #include <linux/module.h> |
| 34 | #include <linux/slab.h> |
| 35 | #include <linux/input.h> |
| 36 | #include <linux/serio.h> |
| 37 | #include <linux/init.h> |
| 38 | |
| 39 | #define DRIVER_DESC "Gunze AHL-51S touchscreen driver" |
| 40 | |
| 41 | MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); |
| 42 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 43 | MODULE_LICENSE("GPL"); |
| 44 | |
| 45 | /* |
| 46 | * Definitions & global arrays. |
| 47 | */ |
| 48 | |
| 49 | #define GUNZE_MAX_LENGTH 10 |
| 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | /* |
| 52 | * Per-touchscreen data. |
| 53 | */ |
| 54 | |
| 55 | struct gunze { |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 56 | struct input_dev *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | struct serio *serio; |
| 58 | int idx; |
| 59 | unsigned char data[GUNZE_MAX_LENGTH]; |
| 60 | char phys[32]; |
| 61 | }; |
| 62 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 63 | static void gunze_process_packet(struct gunze* gunze) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | { |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 65 | struct input_dev *dev = gunze->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
| 67 | if (gunze->idx != GUNZE_MAX_LENGTH || gunze->data[5] != ',' || |
| 68 | (gunze->data[0] != 'T' && gunze->data[0] != 'R')) { |
Dmitry Torokhov | a07461e | 2005-05-28 02:12:00 -0500 | [diff] [blame] | 69 | printk(KERN_WARNING "gunze.c: bad packet: >%.*s<\n", GUNZE_MAX_LENGTH, gunze->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | return; |
| 71 | } |
| 72 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | input_report_abs(dev, ABS_X, simple_strtoul(gunze->data + 1, NULL, 10)); |
| 74 | input_report_abs(dev, ABS_Y, 1024 - simple_strtoul(gunze->data + 6, NULL, 10)); |
| 75 | input_report_key(dev, BTN_TOUCH, gunze->data[0] == 'T'); |
| 76 | input_sync(dev); |
| 77 | } |
| 78 | |
| 79 | static irqreturn_t gunze_interrupt(struct serio *serio, |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 80 | unsigned char data, unsigned int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | { |
| 82 | struct gunze* gunze = serio_get_drvdata(serio); |
| 83 | |
| 84 | if (data == '\r') { |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 85 | gunze_process_packet(gunze); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | gunze->idx = 0; |
| 87 | } else { |
| 88 | if (gunze->idx < GUNZE_MAX_LENGTH) |
| 89 | gunze->data[gunze->idx++] = data; |
| 90 | } |
| 91 | return IRQ_HANDLED; |
| 92 | } |
| 93 | |
| 94 | /* |
| 95 | * gunze_disconnect() is the opposite of gunze_connect() |
| 96 | */ |
| 97 | |
| 98 | static void gunze_disconnect(struct serio *serio) |
| 99 | { |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 100 | struct gunze *gunze = serio_get_drvdata(serio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 102 | input_get_device(gunze->dev); |
| 103 | input_unregister_device(gunze->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | serio_close(serio); |
| 105 | serio_set_drvdata(serio, NULL); |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 106 | input_put_device(gunze->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | kfree(gunze); |
| 108 | } |
| 109 | |
| 110 | /* |
| 111 | * gunze_connect() is the routine that is called when someone adds a |
| 112 | * new serio device that supports Gunze protocol and registers it as |
| 113 | * an input device. |
| 114 | */ |
| 115 | |
| 116 | static int gunze_connect(struct serio *serio, struct serio_driver *drv) |
| 117 | { |
| 118 | struct gunze *gunze; |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 119 | struct input_dev *input_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | int err; |
| 121 | |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 122 | gunze = kzalloc(sizeof(struct gunze), GFP_KERNEL); |
| 123 | input_dev = input_allocate_device(); |
| 124 | if (!gunze || !input_dev) { |
| 125 | err = -ENOMEM; |
Dmitry Torokhov | 52c1f57 | 2006-11-05 22:40:03 -0500 | [diff] [blame] | 126 | goto fail1; |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 127 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
| 129 | gunze->serio = serio; |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 130 | gunze->dev = input_dev; |
Dmitry Torokhov | a21466c | 2006-06-26 01:46:04 -0400 | [diff] [blame] | 131 | snprintf(gunze->phys, sizeof(serio->phys), "%s/input0", serio->phys); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 133 | input_dev->name = "Gunze AHL-51S TouchScreen"; |
| 134 | input_dev->phys = gunze->phys; |
| 135 | input_dev->id.bustype = BUS_RS232; |
| 136 | input_dev->id.vendor = SERIO_GUNZE; |
| 137 | input_dev->id.product = 0x0051; |
| 138 | input_dev->id.version = 0x0100; |
Dmitry Torokhov | a5394fb0 | 2007-04-12 01:35:14 -0400 | [diff] [blame] | 139 | input_dev->dev.parent = &serio->dev; |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 140 | input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); |
| 141 | input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 142 | input_set_abs_params(input_dev, ABS_X, 24, 1000, 0, 0); |
| 143 | input_set_abs_params(input_dev, ABS_Y, 24, 1000, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
| 145 | serio_set_drvdata(serio, gunze); |
| 146 | |
| 147 | err = serio_open(serio, drv); |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 148 | if (err) |
Dmitry Torokhov | 52c1f57 | 2006-11-05 22:40:03 -0500 | [diff] [blame] | 149 | goto fail2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
Dmitry Torokhov | 52c1f57 | 2006-11-05 22:40:03 -0500 | [diff] [blame] | 151 | err = input_register_device(gunze->dev); |
| 152 | if (err) |
| 153 | goto fail3; |
| 154 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | return 0; |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 156 | |
Dmitry Torokhov | 52c1f57 | 2006-11-05 22:40:03 -0500 | [diff] [blame] | 157 | fail3: serio_close(serio); |
| 158 | fail2: serio_set_drvdata(serio, NULL); |
| 159 | fail1: input_free_device(input_dev); |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 160 | kfree(gunze); |
| 161 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | /* |
| 165 | * The serio driver structure. |
| 166 | */ |
| 167 | |
| 168 | static struct serio_device_id gunze_serio_ids[] = { |
| 169 | { |
| 170 | .type = SERIO_RS232, |
| 171 | .proto = SERIO_GUNZE, |
| 172 | .id = SERIO_ANY, |
| 173 | .extra = SERIO_ANY, |
| 174 | }, |
| 175 | { 0 } |
| 176 | }; |
| 177 | |
| 178 | MODULE_DEVICE_TABLE(serio, gunze_serio_ids); |
| 179 | |
| 180 | static struct serio_driver gunze_drv = { |
| 181 | .driver = { |
| 182 | .name = "gunze", |
| 183 | }, |
| 184 | .description = DRIVER_DESC, |
| 185 | .id_table = gunze_serio_ids, |
| 186 | .interrupt = gunze_interrupt, |
| 187 | .connect = gunze_connect, |
| 188 | .disconnect = gunze_disconnect, |
| 189 | }; |
| 190 | |
| 191 | /* |
| 192 | * The functions for inserting/removing us as a module. |
| 193 | */ |
| 194 | |
| 195 | static int __init gunze_init(void) |
| 196 | { |
Akinobu Mita | 153a9df0 | 2006-11-23 23:35:10 -0500 | [diff] [blame] | 197 | return serio_register_driver(&gunze_drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | static void __exit gunze_exit(void) |
| 201 | { |
| 202 | serio_unregister_driver(&gunze_drv); |
| 203 | } |
| 204 | |
| 205 | module_init(gunze_init); |
| 206 | module_exit(gunze_exit); |