mk712.c 5.6 KB

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