pc110pad.c 4.4 KB

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