mk712.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*
  2. * ICS MK712 touchscreen controller driver
  3. *
  4. * Copyright (c) 1999-2002 Transmeta Corporation
  5. * Copyright (c) 2005 Rick Koch <n1gp@hotmail.com>
  6. * Copyright (c) 2005 Vojtech Pavlik <vojtech@suse.cz>
  7. */
  8. /*
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License version 2 as published by
  11. * the Free Software Foundation.
  12. */
  13. /*
  14. * This driver supports the ICS MicroClock MK712 TouchScreen controller,
  15. * found in Gateway AOL Connected Touchpad computers.
  16. *
  17. * Documentation for ICS MK712 can be found at:
  18. * http://www.icst.com/pdf/mk712.pdf
  19. */
  20. /*
  21. * 1999-12-18: original version, Daniel Quinlan
  22. * 1999-12-19: added anti-jitter code, report pen-up events, fixed mk712_poll
  23. * to use queue_empty, Nathan Laredo
  24. * 1999-12-20: improved random point rejection, Nathan Laredo
  25. * 2000-01-05: checked in new anti-jitter code, changed mouse protocol, fixed
  26. * queue code, added module options, other fixes, Daniel Quinlan
  27. * 2002-03-15: Clean up for kernel merge <alan@redhat.com>
  28. * Fixed multi open race, fixed memory checks, fixed resource
  29. * allocation, fixed close/powerdown bug, switched to new init
  30. * 2005-01-18: Ported to 2.6 from 2.4.28, Rick Koch
  31. * 2005-02-05: Rewritten for the input layer, Vojtech Pavlik
  32. *
  33. */
  34. #include <linux/module.h>
  35. #include <linux/moduleparam.h>
  36. #include <linux/kernel.h>
  37. #include <linux/init.h>
  38. #include <linux/errno.h>
  39. #include <linux/delay.h>
  40. #include <linux/ioport.h>
  41. #include <linux/interrupt.h>
  42. #include <linux/input.h>
  43. #include <asm/io.h>
  44. MODULE_AUTHOR("Daniel Quinlan <quinlan@pathname.com>, Vojtech Pavlik <vojtech@suse.cz>");
  45. MODULE_DESCRIPTION("ICS MicroClock MK712 TouchScreen driver");
  46. MODULE_LICENSE("GPL");
  47. static unsigned int mk712_io = 0x260; /* Also 0x200, 0x208, 0x300 */
  48. module_param_named(io, mk712_io, uint, 0);
  49. MODULE_PARM_DESC(io, "I/O base address of MK712 touchscreen controller");
  50. static unsigned int mk712_irq = 10; /* Also 12, 14, 15 */
  51. module_param_named(irq, mk712_irq, uint, 0);
  52. MODULE_PARM_DESC(irq, "IRQ of MK712 touchscreen controller");
  53. /* eight 8-bit registers */
  54. #define MK712_STATUS 0
  55. #define MK712_X 2
  56. #define MK712_Y 4
  57. #define MK712_CONTROL 6
  58. #define MK712_RATE 7
  59. /* status */
  60. #define MK712_STATUS_TOUCH 0x10
  61. #define MK712_CONVERSION_COMPLETE 0x80
  62. /* control */
  63. #define MK712_ENABLE_INT 0x01
  64. #define MK712_INT_ON_CONVERSION_COMPLETE 0x02
  65. #define MK712_INT_ON_CHANGE_IN_TOUCH_STATUS 0x04
  66. #define MK712_ENABLE_PERIODIC_CONVERSIONS 0x10
  67. #define MK712_READ_ONE_POINT 0x20
  68. #define MK712_POWERUP 0x40
  69. static struct input_dev *mk712_dev;
  70. static DEFINE_SPINLOCK(mk712_lock);
  71. static irqreturn_t mk712_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  72. {
  73. unsigned char status;
  74. static int debounce = 1;
  75. static unsigned short last_x;
  76. static unsigned short last_y;
  77. spin_lock(&mk712_lock);
  78. input_regs(mk712_dev, regs);
  79. status = inb(mk712_io + MK712_STATUS);
  80. if (~status & MK712_CONVERSION_COMPLETE) {
  81. debounce = 1;
  82. goto end;
  83. }
  84. if (~status & MK712_STATUS_TOUCH)
  85. {
  86. debounce = 1;
  87. input_report_key(mk712_dev, BTN_TOUCH, 0);
  88. goto end;
  89. }
  90. if (debounce)
  91. {
  92. debounce = 0;
  93. goto end;
  94. }
  95. input_report_key(mk712_dev, BTN_TOUCH, 1);
  96. input_report_abs(mk712_dev, ABS_X, last_x);
  97. input_report_abs(mk712_dev, ABS_Y, last_y);
  98. end:
  99. last_x = inw(mk712_io + MK712_X) & 0x0fff;
  100. last_y = inw(mk712_io + MK712_Y) & 0x0fff;
  101. input_sync(mk712_dev);
  102. spin_unlock(&mk712_lock);
  103. return IRQ_HANDLED;
  104. }
  105. static int mk712_open(struct input_dev *dev)
  106. {
  107. unsigned long flags;
  108. spin_lock_irqsave(&mk712_lock, flags);
  109. outb(0, mk712_io + MK712_CONTROL); /* Reset */
  110. outb(MK712_ENABLE_INT | MK712_INT_ON_CONVERSION_COMPLETE |
  111. MK712_INT_ON_CHANGE_IN_TOUCH_STATUS |
  112. MK712_ENABLE_PERIODIC_CONVERSIONS |
  113. MK712_POWERUP, mk712_io + MK712_CONTROL);
  114. outb(10, mk712_io + MK712_RATE); /* 187 points per second */
  115. spin_unlock_irqrestore(&mk712_lock, flags);
  116. return 0;
  117. }
  118. static void mk712_close(struct input_dev *dev)
  119. {
  120. unsigned long flags;
  121. spin_lock_irqsave(&mk712_lock, flags);
  122. outb(0, mk712_io + MK712_CONTROL);
  123. spin_unlock_irqrestore(&mk712_lock, flags);
  124. }
  125. static int __init mk712_init(void)
  126. {
  127. int err;
  128. if (!request_region(mk712_io, 8, "mk712")) {
  129. printk(KERN_WARNING "mk712: unable to get IO region\n");
  130. return -ENODEV;
  131. }
  132. outb(0, mk712_io + MK712_CONTROL);
  133. if ((inw(mk712_io + MK712_X) & 0xf000) || /* Sanity check */
  134. (inw(mk712_io + MK712_Y) & 0xf000) ||
  135. (inw(mk712_io + MK712_STATUS) & 0xf333)) {
  136. printk(KERN_WARNING "mk712: device not present\n");
  137. err = -ENODEV;
  138. goto fail;
  139. }
  140. if (!(mk712_dev = input_allocate_device())) {
  141. printk(KERN_ERR "mk712: not enough memory\n");
  142. err = -ENOMEM;
  143. goto fail;
  144. }
  145. mk712_dev->name = "ICS MicroClock MK712 TouchScreen";
  146. mk712_dev->phys = "isa0260/input0";
  147. mk712_dev->id.bustype = BUS_ISA;
  148. mk712_dev->id.vendor = 0x0005;
  149. mk712_dev->id.product = 0x0001;
  150. mk712_dev->id.version = 0x0100;
  151. mk712_dev->open = mk712_open;
  152. mk712_dev->close = mk712_close;
  153. mk712_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
  154. mk712_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
  155. input_set_abs_params(mk712_dev, ABS_X, 0, 0xfff, 88, 0);
  156. input_set_abs_params(mk712_dev, ABS_Y, 0, 0xfff, 88, 0);
  157. if (request_irq(mk712_irq, mk712_interrupt, 0, "mk712", mk712_dev)) {
  158. printk(KERN_WARNING "mk712: unable to get IRQ\n");
  159. err = -EBUSY;
  160. goto fail;
  161. }
  162. input_register_device(mk712_dev);
  163. return 0;
  164. fail: input_free_device(mk712_dev);
  165. release_region(mk712_io, 8);
  166. return err;
  167. }
  168. static void __exit mk712_exit(void)
  169. {
  170. input_unregister_device(mk712_dev);
  171. free_irq(mk712_irq, mk712_dev);
  172. release_region(mk712_io, 8);
  173. }
  174. module_init(mk712_init);
  175. module_exit(mk712_exit);