penmount.c 3.8 KB

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