pc110pad.c 3.7 KB

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