mk712.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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 int mk712_used = 0;
  70. static struct input_dev mk712_dev;
  71. static DEFINE_SPINLOCK(mk712_lock);
  72. static irqreturn_t mk712_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  73. {
  74. unsigned char status;
  75. static int debounce = 1;
  76. static unsigned short last_x;
  77. static unsigned short last_y;
  78. spin_lock(&mk712_lock);
  79. input_regs(&mk712_dev, regs);
  80. status = inb(mk712_io + MK712_STATUS);
  81. if (~status & MK712_CONVERSION_COMPLETE) {
  82. debounce = 1;
  83. goto end;
  84. }
  85. if (~status & MK712_STATUS_TOUCH)
  86. {
  87. debounce = 1;
  88. input_report_key(&mk712_dev, BTN_TOUCH, 0);
  89. goto end;
  90. }
  91. if (debounce)
  92. {
  93. debounce = 0;
  94. goto end;
  95. }
  96. input_report_key(&mk712_dev, BTN_TOUCH, 1);
  97. input_report_abs(&mk712_dev, ABS_X, last_x);
  98. input_report_abs(&mk712_dev, ABS_Y, last_y);
  99. end:
  100. last_x = inw(mk712_io + MK712_X) & 0x0fff;
  101. last_y = inw(mk712_io + MK712_Y) & 0x0fff;
  102. input_sync(&mk712_dev);
  103. spin_unlock(&mk712_lock);
  104. return IRQ_HANDLED;
  105. }
  106. static int mk712_open(struct input_dev *dev)
  107. {
  108. unsigned long flags;
  109. spin_lock_irqsave(&mk712_lock, flags);
  110. if (!mk712_used++) {
  111. outb(0, mk712_io + MK712_CONTROL); /* Reset */
  112. outb(MK712_ENABLE_INT | MK712_INT_ON_CONVERSION_COMPLETE |
  113. MK712_INT_ON_CHANGE_IN_TOUCH_STATUS |
  114. MK712_ENABLE_PERIODIC_CONVERSIONS |
  115. MK712_POWERUP, mk712_io + MK712_CONTROL);
  116. outb(10, mk712_io + MK712_RATE); /* 187 points per second */
  117. }
  118. spin_unlock_irqrestore(&mk712_lock, flags);
  119. return 0;
  120. }
  121. static void mk712_close(struct input_dev *dev)
  122. {
  123. unsigned long flags;
  124. spin_lock_irqsave(&mk712_lock, flags);
  125. if (!--mk712_used)
  126. outb(0, mk712_io + MK712_CONTROL);
  127. spin_unlock_irqrestore(&mk712_lock, flags);
  128. }
  129. static struct input_dev mk712_dev = {
  130. .evbit = { BIT(EV_KEY) | BIT(EV_ABS) },
  131. .keybit = { [LONG(BTN_TOUCH)] = BIT(BTN_TOUCH) },
  132. .absbit = { BIT(ABS_X) | BIT(ABS_Y) },
  133. .open = mk712_open,
  134. .close = mk712_close,
  135. .name = "ICS MicroClock MK712 TouchScreen",
  136. .phys = "isa0260/input0",
  137. .absmin = { [ABS_X] = 0, [ABS_Y] = 0 },
  138. .absmax = { [ABS_X] = 0xfff, [ABS_Y] = 0xfff },
  139. .absfuzz = { [ABS_X] = 88, [ABS_Y] = 88 },
  140. .id = {
  141. .bustype = BUS_ISA,
  142. .vendor = 0x0005,
  143. .product = 0x0001,
  144. .version = 0x0100,
  145. },
  146. };
  147. int __init mk712_init(void)
  148. {
  149. if(!request_region(mk712_io, 8, "mk712"))
  150. {
  151. printk(KERN_WARNING "mk712: unable to get IO region\n");
  152. return -ENODEV;
  153. }
  154. outb(0, mk712_io + MK712_CONTROL);
  155. if ((inw(mk712_io + MK712_X) & 0xf000) || /* Sanity check */
  156. (inw(mk712_io + MK712_Y) & 0xf000) ||
  157. (inw(mk712_io + MK712_STATUS) & 0xf333)) {
  158. printk(KERN_WARNING "mk712: device not present\n");
  159. release_region(mk712_io, 8);
  160. return -ENODEV;
  161. }
  162. if(request_irq(mk712_irq, mk712_interrupt, 0, "mk712", &mk712_dev))
  163. {
  164. printk(KERN_WARNING "mk712: unable to get IRQ\n");
  165. release_region(mk712_io, 8);
  166. return -EBUSY;
  167. }
  168. input_register_device(&mk712_dev);
  169. printk(KERN_INFO "input: ICS MicroClock MK712 TouchScreen at %#x irq %d\n", mk712_io, mk712_irq);
  170. return 0;
  171. }
  172. static void __exit mk712_exit(void)
  173. {
  174. input_unregister_device(&mk712_dev);
  175. free_irq(mk712_irq, &mk712_dev);
  176. release_region(mk712_io, 8);
  177. }
  178. module_init(mk712_init);
  179. module_exit(mk712_exit);