mk712.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 struct input_dev mk712_dev = {
  126. .evbit = { BIT(EV_KEY) | BIT(EV_ABS) },
  127. .keybit = { [LONG(BTN_TOUCH)] = BIT(BTN_TOUCH) },
  128. .absbit = { BIT(ABS_X) | BIT(ABS_Y) },
  129. .open = mk712_open,
  130. .close = mk712_close,
  131. .name = "ICS MicroClock MK712 TouchScreen",
  132. .phys = "isa0260/input0",
  133. .absmin = { [ABS_X] = 0, [ABS_Y] = 0 },
  134. .absmax = { [ABS_X] = 0xfff, [ABS_Y] = 0xfff },
  135. .absfuzz = { [ABS_X] = 88, [ABS_Y] = 88 },
  136. .id = {
  137. .bustype = BUS_ISA,
  138. .vendor = 0x0005,
  139. .product = 0x0001,
  140. .version = 0x0100,
  141. },
  142. };
  143. int __init mk712_init(void)
  144. {
  145. if(!request_region(mk712_io, 8, "mk712"))
  146. {
  147. printk(KERN_WARNING "mk712: unable to get IO region\n");
  148. return -ENODEV;
  149. }
  150. outb(0, mk712_io + MK712_CONTROL);
  151. if ((inw(mk712_io + MK712_X) & 0xf000) || /* Sanity check */
  152. (inw(mk712_io + MK712_Y) & 0xf000) ||
  153. (inw(mk712_io + MK712_STATUS) & 0xf333)) {
  154. printk(KERN_WARNING "mk712: device not present\n");
  155. release_region(mk712_io, 8);
  156. return -ENODEV;
  157. }
  158. if(request_irq(mk712_irq, mk712_interrupt, 0, "mk712", &mk712_dev))
  159. {
  160. printk(KERN_WARNING "mk712: unable to get IRQ\n");
  161. release_region(mk712_io, 8);
  162. return -EBUSY;
  163. }
  164. input_register_device(&mk712_dev);
  165. printk(KERN_INFO "input: ICS MicroClock MK712 TouchScreen at %#x irq %d\n", mk712_io, mk712_irq);
  166. return 0;
  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);