pc110pad.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * $Id: pc110pad.c,v 1.12 2001/09/25 10:12:07 vojtech Exp $
  3. *
  4. * Copyright (c) 2000-2001 Vojtech Pavlik
  5. *
  6. * Based on the work of:
  7. * Alan Cox Robin O'Leary
  8. */
  9. /*
  10. * IBM PC110 touchpad driver for Linux
  11. */
  12. /*
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  26. *
  27. * Should you need to contact me, the author, you can do so either by
  28. * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
  29. * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
  30. */
  31. #include <linux/module.h>
  32. #include <linux/kernel.h>
  33. #include <linux/errno.h>
  34. #include <linux/ioport.h>
  35. #include <linux/input.h>
  36. #include <linux/init.h>
  37. #include <linux/interrupt.h>
  38. #include <linux/pci.h>
  39. #include <asm/io.h>
  40. #include <asm/irq.h>
  41. MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
  42. MODULE_DESCRIPTION("IBM PC110 touchpad driver");
  43. MODULE_LICENSE("GPL");
  44. #define PC110PAD_OFF 0x30
  45. #define PC110PAD_ON 0x38
  46. static int pc110pad_irq = 10;
  47. static int pc110pad_io = 0x15e0;
  48. static struct input_dev pc110pad_dev;
  49. static int pc110pad_data[3];
  50. static int pc110pad_count;
  51. static int pc110pad_used;
  52. static char *pc110pad_name = "IBM PC110 TouchPad";
  53. static char *pc110pad_phys = "isa15e0/input0";
  54. static irqreturn_t pc110pad_interrupt(int irq, void *ptr, struct pt_regs *regs)
  55. {
  56. int value = inb_p(pc110pad_io);
  57. int handshake = inb_p(pc110pad_io + 2);
  58. outb_p(handshake | 1, pc110pad_io + 2);
  59. outb_p(handshake & ~1, pc110pad_io + 2);
  60. inb_p(0x64);
  61. pc110pad_data[pc110pad_count++] = value;
  62. if (pc110pad_count < 3)
  63. return IRQ_HANDLED;
  64. input_regs(&pc110pad_dev, regs);
  65. input_report_key(&pc110pad_dev, BTN_TOUCH,
  66. pc110pad_data[0] & 0x01);
  67. input_report_abs(&pc110pad_dev, ABS_X,
  68. pc110pad_data[1] | ((pc110pad_data[0] << 3) & 0x80) | ((pc110pad_data[0] << 1) & 0x100));
  69. input_report_abs(&pc110pad_dev, ABS_Y,
  70. pc110pad_data[2] | ((pc110pad_data[0] << 4) & 0x80));
  71. input_sync(&pc110pad_dev);
  72. pc110pad_count = 0;
  73. return IRQ_HANDLED;
  74. }
  75. static void pc110pad_close(struct input_dev *dev)
  76. {
  77. if (!--pc110pad_used)
  78. outb(PC110PAD_OFF, pc110pad_io + 2);
  79. }
  80. static int pc110pad_open(struct input_dev *dev)
  81. {
  82. if (pc110pad_used++)
  83. return 0;
  84. pc110pad_interrupt(0,NULL,NULL);
  85. pc110pad_interrupt(0,NULL,NULL);
  86. pc110pad_interrupt(0,NULL,NULL);
  87. outb(PC110PAD_ON, pc110pad_io + 2);
  88. pc110pad_count = 0;
  89. return 0;
  90. }
  91. /*
  92. * We try to avoid enabling the hardware if it's not
  93. * there, but we don't know how to test. But we do know
  94. * that the PC110 is not a PCI system. So if we find any
  95. * PCI devices in the machine, we don't have a PC110.
  96. */
  97. static int __init pc110pad_init(void)
  98. {
  99. struct pci_dev *dev;
  100. dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL);
  101. if (dev) {
  102. pci_dev_put(dev);
  103. return -ENOENT;
  104. }
  105. if (!request_region(pc110pad_io, 4, "pc110pad")) {
  106. printk(KERN_ERR "pc110pad: I/O area %#x-%#x in use.\n",
  107. pc110pad_io, pc110pad_io + 4);
  108. return -EBUSY;
  109. }
  110. outb(PC110PAD_OFF, pc110pad_io + 2);
  111. if (request_irq(pc110pad_irq, pc110pad_interrupt, 0, "pc110pad", NULL))
  112. {
  113. release_region(pc110pad_io, 4);
  114. printk(KERN_ERR "pc110pad: Unable to get irq %d.\n", pc110pad_irq);
  115. return -EBUSY;
  116. }
  117. pc110pad_dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
  118. pc110pad_dev.absbit[0] = BIT(ABS_X) | BIT(ABS_Y);
  119. pc110pad_dev.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
  120. pc110pad_dev.absmax[ABS_X] = 0x1ff;
  121. pc110pad_dev.absmax[ABS_Y] = 0x0ff;
  122. pc110pad_dev.open = pc110pad_open;
  123. pc110pad_dev.close = pc110pad_close;
  124. pc110pad_dev.name = pc110pad_name;
  125. pc110pad_dev.phys = pc110pad_phys;
  126. pc110pad_dev.id.bustype = BUS_ISA;
  127. pc110pad_dev.id.vendor = 0x0003;
  128. pc110pad_dev.id.product = 0x0001;
  129. pc110pad_dev.id.version = 0x0100;
  130. input_register_device(&pc110pad_dev);
  131. printk(KERN_INFO "input: %s at %#x irq %d\n",
  132. pc110pad_name, pc110pad_io, pc110pad_irq);
  133. return 0;
  134. }
  135. static void __exit pc110pad_exit(void)
  136. {
  137. input_unregister_device(&pc110pad_dev);
  138. outb(PC110PAD_OFF, pc110pad_io + 2);
  139. free_irq(pc110pad_irq, NULL);
  140. release_region(pc110pad_io, 4);
  141. }
  142. module_init(pc110pad_init);
  143. module_exit(pc110pad_exit);