mk712.c 5.7 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.idt.com/products/getDoc.cfm?docID=18713923
  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/kernel.h>
  36. #include <linux/init.h>
  37. #include <linux/errno.h>
  38. #include <linux/delay.h>
  39. #include <linux/ioport.h>
  40. #include <linux/interrupt.h>
  41. #include <linux/input.h>
  42. #include <asm/io.h>
  43. MODULE_AUTHOR("Daniel Quinlan <quinlan@pathname.com>, Vojtech Pavlik <vojtech@suse.cz>");
  44. MODULE_DESCRIPTION("ICS MicroClock MK712 TouchScreen driver");
  45. MODULE_LICENSE("GPL");
  46. static unsigned int mk712_io = 0x260; /* Also 0x200, 0x208, 0x300 */
  47. module_param_named(io, mk712_io, uint, 0);
  48. MODULE_PARM_DESC(io, "I/O base address of MK712 touchscreen controller");
  49. static unsigned int mk712_irq = 10; /* Also 12, 14, 15 */
  50. module_param_named(irq, mk712_irq, uint, 0);
  51. MODULE_PARM_DESC(irq, "IRQ of MK712 touchscreen controller");
  52. /* eight 8-bit registers */
  53. #define MK712_STATUS 0
  54. #define MK712_X 2
  55. #define MK712_Y 4
  56. #define MK712_CONTROL 6
  57. #define MK712_RATE 7
  58. /* status */
  59. #define MK712_STATUS_TOUCH 0x10
  60. #define MK712_CONVERSION_COMPLETE 0x80
  61. /* control */
  62. #define MK712_ENABLE_INT 0x01
  63. #define MK712_INT_ON_CONVERSION_COMPLETE 0x02
  64. #define MK712_INT_ON_CHANGE_IN_TOUCH_STATUS 0x04
  65. #define MK712_ENABLE_PERIODIC_CONVERSIONS 0x10
  66. #define MK712_READ_ONE_POINT 0x20
  67. #define MK712_POWERUP 0x40
  68. static struct input_dev *mk712_dev;
  69. static DEFINE_SPINLOCK(mk712_lock);
  70. static irqreturn_t mk712_interrupt(int irq, void *dev_id)
  71. {
  72. unsigned char status;
  73. static int debounce = 1;
  74. static unsigned short last_x;
  75. static unsigned short last_y;
  76. spin_lock(&mk712_lock);
  77. status = inb(mk712_io + MK712_STATUS);
  78. if (~status & MK712_CONVERSION_COMPLETE) {
  79. debounce = 1;
  80. goto end;
  81. }
  82. if (~status & MK712_STATUS_TOUCH) {
  83. debounce = 1;
  84. input_report_key(mk712_dev, BTN_TOUCH, 0);
  85. goto end;
  86. }
  87. if (debounce) {
  88. debounce = 0;
  89. goto end;
  90. }
  91. input_report_key(mk712_dev, BTN_TOUCH, 1);
  92. input_report_abs(mk712_dev, ABS_X, last_x);
  93. input_report_abs(mk712_dev, ABS_Y, last_y);
  94. end:
  95. last_x = inw(mk712_io + MK712_X) & 0x0fff;
  96. last_y = inw(mk712_io + MK712_Y) & 0x0fff;
  97. input_sync(mk712_dev);
  98. spin_unlock(&mk712_lock);
  99. return IRQ_HANDLED;
  100. }
  101. static int mk712_open(struct input_dev *dev)
  102. {
  103. unsigned long flags;
  104. spin_lock_irqsave(&mk712_lock, flags);
  105. outb(0, mk712_io + MK712_CONTROL); /* Reset */
  106. outb(MK712_ENABLE_INT | MK712_INT_ON_CONVERSION_COMPLETE |
  107. MK712_INT_ON_CHANGE_IN_TOUCH_STATUS |
  108. MK712_ENABLE_PERIODIC_CONVERSIONS |
  109. MK712_POWERUP, mk712_io + MK712_CONTROL);
  110. outb(10, mk712_io + MK712_RATE); /* 187 points per second */
  111. spin_unlock_irqrestore(&mk712_lock, flags);
  112. return 0;
  113. }
  114. static void mk712_close(struct input_dev *dev)
  115. {
  116. unsigned long flags;
  117. spin_lock_irqsave(&mk712_lock, flags);
  118. outb(0, mk712_io + MK712_CONTROL);
  119. spin_unlock_irqrestore(&mk712_lock, flags);
  120. }
  121. static int __init mk712_init(void)
  122. {
  123. int err;
  124. if (!request_region(mk712_io, 8, "mk712")) {
  125. printk(KERN_WARNING "mk712: unable to get IO region\n");
  126. return -ENODEV;
  127. }
  128. outb(0, mk712_io + MK712_CONTROL);
  129. if ((inw(mk712_io + MK712_X) & 0xf000) || /* Sanity check */
  130. (inw(mk712_io + MK712_Y) & 0xf000) ||
  131. (inw(mk712_io + MK712_STATUS) & 0xf333)) {
  132. printk(KERN_WARNING "mk712: device not present\n");
  133. err = -ENODEV;
  134. goto fail1;
  135. }
  136. mk712_dev = input_allocate_device();
  137. if (!mk712_dev) {
  138. printk(KERN_ERR "mk712: not enough memory\n");
  139. err = -ENOMEM;
  140. goto fail1;
  141. }
  142. mk712_dev->name = "ICS MicroClock MK712 TouchScreen";
  143. mk712_dev->phys = "isa0260/input0";
  144. mk712_dev->id.bustype = BUS_ISA;
  145. mk712_dev->id.vendor = 0x0005;
  146. mk712_dev->id.product = 0x0001;
  147. mk712_dev->id.version = 0x0100;
  148. mk712_dev->open = mk712_open;
  149. mk712_dev->close = mk712_close;
  150. mk712_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
  151. mk712_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
  152. input_set_abs_params(mk712_dev, ABS_X, 0, 0xfff, 88, 0);
  153. input_set_abs_params(mk712_dev, ABS_Y, 0, 0xfff, 88, 0);
  154. if (request_irq(mk712_irq, mk712_interrupt, 0, "mk712", mk712_dev)) {
  155. printk(KERN_WARNING "mk712: unable to get IRQ\n");
  156. err = -EBUSY;
  157. goto fail1;
  158. }
  159. err = input_register_device(mk712_dev);
  160. if (err)
  161. goto fail2;
  162. return 0;
  163. fail2: free_irq(mk712_irq, mk712_dev);
  164. fail1: 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);