inport.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. * Copyright (c) 1999-2001 Vojtech Pavlik
  3. *
  4. * Based on the work of:
  5. * Teemu Rantanen Derrick Cole
  6. * Peter Cervasio Christoph Niemann
  7. * Philip Blundell Russell King
  8. * Bob Harris
  9. */
  10. /*
  11. * Inport (ATI XL and Microsoft) busmouse driver for Linux
  12. */
  13. /*
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  27. */
  28. #include <linux/module.h>
  29. #include <linux/ioport.h>
  30. #include <linux/init.h>
  31. #include <linux/interrupt.h>
  32. #include <linux/input.h>
  33. #include <asm/io.h>
  34. #include <asm/irq.h>
  35. MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
  36. MODULE_DESCRIPTION("Inport (ATI XL and Microsoft) busmouse driver");
  37. MODULE_LICENSE("GPL");
  38. #define INPORT_BASE 0x23c
  39. #define INPORT_EXTENT 4
  40. #define INPORT_CONTROL_PORT INPORT_BASE + 0
  41. #define INPORT_DATA_PORT INPORT_BASE + 1
  42. #define INPORT_SIGNATURE_PORT INPORT_BASE + 2
  43. #define INPORT_REG_BTNS 0x00
  44. #define INPORT_REG_X 0x01
  45. #define INPORT_REG_Y 0x02
  46. #define INPORT_REG_MODE 0x07
  47. #define INPORT_RESET 0x80
  48. #ifdef CONFIG_MOUSE_ATIXL
  49. #define INPORT_NAME "ATI XL Mouse"
  50. #define INPORT_VENDOR 0x0002
  51. #define INPORT_SPEED_30HZ 0x01
  52. #define INPORT_SPEED_50HZ 0x02
  53. #define INPORT_SPEED_100HZ 0x03
  54. #define INPORT_SPEED_200HZ 0x04
  55. #define INPORT_MODE_BASE INPORT_SPEED_100HZ
  56. #define INPORT_MODE_IRQ 0x08
  57. #else
  58. #define INPORT_NAME "Microsoft InPort Mouse"
  59. #define INPORT_VENDOR 0x0001
  60. #define INPORT_MODE_BASE 0x10
  61. #define INPORT_MODE_IRQ 0x01
  62. #endif
  63. #define INPORT_MODE_HOLD 0x20
  64. #define INPORT_IRQ 5
  65. static int inport_irq = INPORT_IRQ;
  66. module_param_hw_named(irq, inport_irq, uint, irq, 0);
  67. MODULE_PARM_DESC(irq, "IRQ number (5=default)");
  68. static struct input_dev *inport_dev;
  69. static irqreturn_t inport_interrupt(int irq, void *dev_id)
  70. {
  71. unsigned char buttons;
  72. outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
  73. outb(INPORT_MODE_HOLD | INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT);
  74. outb(INPORT_REG_X, INPORT_CONTROL_PORT);
  75. input_report_rel(inport_dev, REL_X, inb(INPORT_DATA_PORT));
  76. outb(INPORT_REG_Y, INPORT_CONTROL_PORT);
  77. input_report_rel(inport_dev, REL_Y, inb(INPORT_DATA_PORT));
  78. outb(INPORT_REG_BTNS, INPORT_CONTROL_PORT);
  79. buttons = inb(INPORT_DATA_PORT);
  80. input_report_key(inport_dev, BTN_MIDDLE, buttons & 1);
  81. input_report_key(inport_dev, BTN_LEFT, buttons & 2);
  82. input_report_key(inport_dev, BTN_RIGHT, buttons & 4);
  83. outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
  84. outb(INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT);
  85. input_sync(inport_dev);
  86. return IRQ_HANDLED;
  87. }
  88. static int inport_open(struct input_dev *dev)
  89. {
  90. if (request_irq(inport_irq, inport_interrupt, 0, "inport", NULL))
  91. return -EBUSY;
  92. outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
  93. outb(INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT);
  94. return 0;
  95. }
  96. static void inport_close(struct input_dev *dev)
  97. {
  98. outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
  99. outb(INPORT_MODE_BASE, INPORT_DATA_PORT);
  100. free_irq(inport_irq, NULL);
  101. }
  102. static int __init inport_init(void)
  103. {
  104. unsigned char a, b, c;
  105. int err;
  106. if (!request_region(INPORT_BASE, INPORT_EXTENT, "inport")) {
  107. printk(KERN_ERR "inport.c: Can't allocate ports at %#x\n", INPORT_BASE);
  108. return -EBUSY;
  109. }
  110. a = inb(INPORT_SIGNATURE_PORT);
  111. b = inb(INPORT_SIGNATURE_PORT);
  112. c = inb(INPORT_SIGNATURE_PORT);
  113. if (a == b || a != c) {
  114. printk(KERN_INFO "inport.c: Didn't find InPort mouse at %#x\n", INPORT_BASE);
  115. err = -ENODEV;
  116. goto err_release_region;
  117. }
  118. inport_dev = input_allocate_device();
  119. if (!inport_dev) {
  120. printk(KERN_ERR "inport.c: Not enough memory for input device\n");
  121. err = -ENOMEM;
  122. goto err_release_region;
  123. }
  124. inport_dev->name = INPORT_NAME;
  125. inport_dev->phys = "isa023c/input0";
  126. inport_dev->id.bustype = BUS_ISA;
  127. inport_dev->id.vendor = INPORT_VENDOR;
  128. inport_dev->id.product = 0x0001;
  129. inport_dev->id.version = 0x0100;
  130. inport_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
  131. inport_dev->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) |
  132. BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
  133. inport_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
  134. inport_dev->open = inport_open;
  135. inport_dev->close = inport_close;
  136. outb(INPORT_RESET, INPORT_CONTROL_PORT);
  137. outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
  138. outb(INPORT_MODE_BASE, INPORT_DATA_PORT);
  139. err = input_register_device(inport_dev);
  140. if (err)
  141. goto err_free_dev;
  142. return 0;
  143. err_free_dev:
  144. input_free_device(inport_dev);
  145. err_release_region:
  146. release_region(INPORT_BASE, INPORT_EXTENT);
  147. return err;
  148. }
  149. static void __exit inport_exit(void)
  150. {
  151. input_unregister_device(inport_dev);
  152. release_region(INPORT_BASE, INPORT_EXTENT);
  153. }
  154. module_init(inport_init);
  155. module_exit(inport_exit);