gunze.c 4.8 KB

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