Rick Koch | ee47999 | 2006-08-05 00:32:18 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Penmount serial touchscreen driver |
| 3 | * |
| 4 | * Copyright (c) 2006 Rick Koch <n1gp@hotmail.com> |
John Sung | 21ae508 | 2011-09-09 13:33:12 -0700 | [diff] [blame^] | 5 | * Copyright (c) 2011 John Sung <penmount.touch@gmail.com> |
Rick Koch | ee47999 | 2006-08-05 00:32:18 -0400 | [diff] [blame] | 6 | * |
| 7 | * Based on ELO driver (drivers/input/touchscreen/elo.c) |
| 8 | * Copyright (c) 2004 Vojtech Pavlik |
| 9 | */ |
| 10 | |
| 11 | /* |
| 12 | * This program is free software; you can redistribute it and/or modify it |
| 13 | * under the terms of the GNU General Public License version 2 as published |
| 14 | * by the Free Software Foundation. |
| 15 | */ |
| 16 | |
| 17 | #include <linux/errno.h> |
| 18 | #include <linux/kernel.h> |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/slab.h> |
| 21 | #include <linux/input.h> |
| 22 | #include <linux/serio.h> |
| 23 | #include <linux/init.h> |
| 24 | |
John Sung | 21ae508 | 2011-09-09 13:33:12 -0700 | [diff] [blame^] | 25 | #define DRIVER_DESC "PenMount serial touchscreen driver" |
Rick Koch | ee47999 | 2006-08-05 00:32:18 -0400 | [diff] [blame] | 26 | |
| 27 | MODULE_AUTHOR("Rick Koch <n1gp@hotmail.com>"); |
John Sung | 21ae508 | 2011-09-09 13:33:12 -0700 | [diff] [blame^] | 28 | MODULE_AUTHOR("John Sung <penmount.touch@gmail.com>"); |
Rick Koch | ee47999 | 2006-08-05 00:32:18 -0400 | [diff] [blame] | 29 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 30 | MODULE_LICENSE("GPL"); |
| 31 | |
| 32 | /* |
| 33 | * Definitions & global arrays. |
| 34 | */ |
| 35 | |
| 36 | #define PM_MAX_LENGTH 5 |
| 37 | |
| 38 | /* |
| 39 | * Per-touchscreen data. |
| 40 | */ |
| 41 | |
| 42 | struct pm { |
| 43 | struct input_dev *dev; |
| 44 | struct serio *serio; |
| 45 | int idx; |
| 46 | unsigned char data[PM_MAX_LENGTH]; |
| 47 | char phys[32]; |
| 48 | }; |
| 49 | |
| 50 | static irqreturn_t pm_interrupt(struct serio *serio, |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 51 | unsigned char data, unsigned int flags) |
Rick Koch | ee47999 | 2006-08-05 00:32:18 -0400 | [diff] [blame] | 52 | { |
| 53 | struct pm *pm = serio_get_drvdata(serio); |
| 54 | struct input_dev *dev = pm->dev; |
| 55 | |
| 56 | pm->data[pm->idx] = data; |
| 57 | |
| 58 | if (pm->data[0] & 0x80) { |
| 59 | if (PM_MAX_LENGTH == ++pm->idx) { |
John Sung | 21ae508 | 2011-09-09 13:33:12 -0700 | [diff] [blame^] | 60 | input_report_abs(dev, ABS_X, pm->data[1] * 128 + pm->data[2]); |
| 61 | input_report_abs(dev, ABS_Y, pm->data[3] * 128 + pm->data[4]); |
Rick Koch | ee47999 | 2006-08-05 00:32:18 -0400 | [diff] [blame] | 62 | input_report_key(dev, BTN_TOUCH, !!(pm->data[0] & 0x40)); |
| 63 | input_sync(dev); |
| 64 | pm->idx = 0; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | return IRQ_HANDLED; |
| 69 | } |
| 70 | |
| 71 | /* |
| 72 | * pm_disconnect() is the opposite of pm_connect() |
| 73 | */ |
| 74 | |
| 75 | static void pm_disconnect(struct serio *serio) |
| 76 | { |
| 77 | struct pm *pm = serio_get_drvdata(serio); |
| 78 | |
| 79 | input_get_device(pm->dev); |
| 80 | input_unregister_device(pm->dev); |
| 81 | serio_close(serio); |
| 82 | serio_set_drvdata(serio, NULL); |
| 83 | input_put_device(pm->dev); |
| 84 | kfree(pm); |
| 85 | } |
| 86 | |
| 87 | /* |
| 88 | * pm_connect() is the routine that is called when someone adds a |
John Sung | 21ae508 | 2011-09-09 13:33:12 -0700 | [diff] [blame^] | 89 | * new serio device that supports PenMount protocol and registers it as |
Rick Koch | ee47999 | 2006-08-05 00:32:18 -0400 | [diff] [blame] | 90 | * an input device. |
| 91 | */ |
| 92 | |
| 93 | static int pm_connect(struct serio *serio, struct serio_driver *drv) |
| 94 | { |
| 95 | struct pm *pm; |
| 96 | struct input_dev *input_dev; |
| 97 | int err; |
| 98 | |
| 99 | pm = kzalloc(sizeof(struct pm), GFP_KERNEL); |
| 100 | input_dev = input_allocate_device(); |
| 101 | if (!pm || !input_dev) { |
| 102 | err = -ENOMEM; |
| 103 | goto fail1; |
| 104 | } |
| 105 | |
| 106 | pm->serio = serio; |
| 107 | pm->dev = input_dev; |
| 108 | snprintf(pm->phys, sizeof(pm->phys), "%s/input0", serio->phys); |
| 109 | |
John Sung | 21ae508 | 2011-09-09 13:33:12 -0700 | [diff] [blame^] | 110 | input_dev->name = "PenMount Serial TouchScreen"; |
Rick Koch | ee47999 | 2006-08-05 00:32:18 -0400 | [diff] [blame] | 111 | input_dev->phys = pm->phys; |
| 112 | input_dev->id.bustype = BUS_RS232; |
| 113 | input_dev->id.vendor = SERIO_PENMOUNT; |
| 114 | input_dev->id.product = 0; |
| 115 | input_dev->id.version = 0x0100; |
Dmitry Torokhov | a5394fb0 | 2007-04-12 01:35:14 -0400 | [diff] [blame] | 116 | input_dev->dev.parent = &serio->dev; |
Rick Koch | ee47999 | 2006-08-05 00:32:18 -0400 | [diff] [blame] | 117 | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 118 | input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); |
| 119 | input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); |
Rick Koch | ee47999 | 2006-08-05 00:32:18 -0400 | [diff] [blame] | 120 | input_set_abs_params(pm->dev, ABS_X, 0, 0x3ff, 0, 0); |
| 121 | input_set_abs_params(pm->dev, ABS_Y, 0, 0x3ff, 0, 0); |
| 122 | |
| 123 | serio_set_drvdata(serio, pm); |
| 124 | |
| 125 | err = serio_open(serio, drv); |
| 126 | if (err) |
| 127 | goto fail2; |
| 128 | |
| 129 | err = input_register_device(pm->dev); |
| 130 | if (err) |
| 131 | goto fail3; |
| 132 | |
| 133 | return 0; |
| 134 | |
| 135 | fail3: serio_close(serio); |
| 136 | fail2: serio_set_drvdata(serio, NULL); |
| 137 | fail1: input_free_device(input_dev); |
| 138 | kfree(pm); |
| 139 | return err; |
| 140 | } |
| 141 | |
| 142 | /* |
| 143 | * The serio driver structure. |
| 144 | */ |
| 145 | |
| 146 | static struct serio_device_id pm_serio_ids[] = { |
| 147 | { |
| 148 | .type = SERIO_RS232, |
| 149 | .proto = SERIO_PENMOUNT, |
| 150 | .id = SERIO_ANY, |
| 151 | .extra = SERIO_ANY, |
| 152 | }, |
| 153 | { 0 } |
| 154 | }; |
| 155 | |
| 156 | MODULE_DEVICE_TABLE(serio, pm_serio_ids); |
| 157 | |
| 158 | static struct serio_driver pm_drv = { |
| 159 | .driver = { |
John Sung | 21ae508 | 2011-09-09 13:33:12 -0700 | [diff] [blame^] | 160 | .name = "serio-penmount", |
Rick Koch | ee47999 | 2006-08-05 00:32:18 -0400 | [diff] [blame] | 161 | }, |
| 162 | .description = DRIVER_DESC, |
| 163 | .id_table = pm_serio_ids, |
| 164 | .interrupt = pm_interrupt, |
| 165 | .connect = pm_connect, |
| 166 | .disconnect = pm_disconnect, |
| 167 | }; |
| 168 | |
| 169 | /* |
| 170 | * The functions for inserting/removing us as a module. |
| 171 | */ |
| 172 | |
| 173 | static int __init pm_init(void) |
| 174 | { |
Akinobu Mita | 153a9df0 | 2006-11-23 23:35:10 -0500 | [diff] [blame] | 175 | return serio_register_driver(&pm_drv); |
Rick Koch | ee47999 | 2006-08-05 00:32:18 -0400 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | static void __exit pm_exit(void) |
| 179 | { |
| 180 | serio_unregister_driver(&pm_drv); |
| 181 | } |
| 182 | |
| 183 | module_init(pm_init); |
| 184 | module_exit(pm_exit); |