gunze.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. static char *gunze_name = "Gunze AHL-51S TouchScreen";
  44. /*
  45. * Per-touchscreen data.
  46. */
  47. struct gunze {
  48. struct input_dev dev;
  49. struct serio *serio;
  50. int idx;
  51. unsigned char data[GUNZE_MAX_LENGTH];
  52. char phys[32];
  53. };
  54. static void gunze_process_packet(struct gunze* gunze, struct pt_regs *regs)
  55. {
  56. struct input_dev *dev = &gunze->dev;
  57. if (gunze->idx != GUNZE_MAX_LENGTH || gunze->data[5] != ',' ||
  58. (gunze->data[0] != 'T' && gunze->data[0] != 'R')) {
  59. printk(KERN_WARNING "gunze.c: bad packet: >%.*s<\n", GUNZE_MAX_LENGTH, gunze->data);
  60. return;
  61. }
  62. input_regs(dev, regs);
  63. input_report_abs(dev, ABS_X, simple_strtoul(gunze->data + 1, NULL, 10));
  64. input_report_abs(dev, ABS_Y, 1024 - simple_strtoul(gunze->data + 6, NULL, 10));
  65. input_report_key(dev, BTN_TOUCH, gunze->data[0] == 'T');
  66. input_sync(dev);
  67. }
  68. static irqreturn_t gunze_interrupt(struct serio *serio,
  69. unsigned char data, unsigned int flags, struct pt_regs *regs)
  70. {
  71. struct gunze* gunze = serio_get_drvdata(serio);
  72. if (data == '\r') {
  73. gunze_process_packet(gunze, regs);
  74. gunze->idx = 0;
  75. } else {
  76. if (gunze->idx < GUNZE_MAX_LENGTH)
  77. gunze->data[gunze->idx++] = data;
  78. }
  79. return IRQ_HANDLED;
  80. }
  81. /*
  82. * gunze_disconnect() is the opposite of gunze_connect()
  83. */
  84. static void gunze_disconnect(struct serio *serio)
  85. {
  86. struct gunze* gunze = serio_get_drvdata(serio);
  87. input_unregister_device(&gunze->dev);
  88. serio_close(serio);
  89. serio_set_drvdata(serio, NULL);
  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. int err;
  101. if (!(gunze = kmalloc(sizeof(struct gunze), GFP_KERNEL)))
  102. return -ENOMEM;
  103. memset(gunze, 0, sizeof(struct gunze));
  104. init_input_dev(&gunze->dev);
  105. gunze->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
  106. gunze->dev.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
  107. input_set_abs_params(&gunze->dev, ABS_X, 24, 1000, 0, 0);
  108. input_set_abs_params(&gunze->dev, ABS_Y, 24, 1000, 0, 0);
  109. gunze->serio = serio;
  110. sprintf(gunze->phys, "%s/input0", serio->phys);
  111. gunze->dev.private = gunze;
  112. gunze->dev.name = gunze_name;
  113. gunze->dev.phys = gunze->phys;
  114. gunze->dev.id.bustype = BUS_RS232;
  115. gunze->dev.id.vendor = SERIO_GUNZE;
  116. gunze->dev.id.product = 0x0051;
  117. gunze->dev.id.version = 0x0100;
  118. serio_set_drvdata(serio, gunze);
  119. err = serio_open(serio, drv);
  120. if (err) {
  121. serio_set_drvdata(serio, NULL);
  122. kfree(gunze);
  123. return err;
  124. }
  125. input_register_device(&gunze->dev);
  126. printk(KERN_INFO "input: %s on %s\n", gunze_name, serio->phys);
  127. return 0;
  128. }
  129. /*
  130. * The serio driver structure.
  131. */
  132. static struct serio_device_id gunze_serio_ids[] = {
  133. {
  134. .type = SERIO_RS232,
  135. .proto = SERIO_GUNZE,
  136. .id = SERIO_ANY,
  137. .extra = SERIO_ANY,
  138. },
  139. { 0 }
  140. };
  141. MODULE_DEVICE_TABLE(serio, gunze_serio_ids);
  142. static struct serio_driver gunze_drv = {
  143. .driver = {
  144. .name = "gunze",
  145. },
  146. .description = DRIVER_DESC,
  147. .id_table = gunze_serio_ids,
  148. .interrupt = gunze_interrupt,
  149. .connect = gunze_connect,
  150. .disconnect = gunze_disconnect,
  151. };
  152. /*
  153. * The functions for inserting/removing us as a module.
  154. */
  155. static int __init gunze_init(void)
  156. {
  157. serio_register_driver(&gunze_drv);
  158. return 0;
  159. }
  160. static void __exit gunze_exit(void)
  161. {
  162. serio_unregister_driver(&gunze_drv);
  163. }
  164. module_init(gunze_init);
  165. module_exit(gunze_exit);