inport.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. * Should you need to contact me, the author, you can do so either by
  29. * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
  30. * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
  31. */
  32. #include <linux/module.h>
  33. #include <linux/ioport.h>
  34. #include <linux/init.h>
  35. #include <linux/interrupt.h>
  36. #include <linux/input.h>
  37. #include <asm/io.h>
  38. #include <asm/irq.h>
  39. MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
  40. MODULE_DESCRIPTION("Inport (ATI XL and Microsoft) busmouse driver");
  41. MODULE_LICENSE("GPL");
  42. #define INPORT_BASE 0x23c
  43. #define INPORT_EXTENT 4
  44. #define INPORT_CONTROL_PORT INPORT_BASE + 0
  45. #define INPORT_DATA_PORT INPORT_BASE + 1
  46. #define INPORT_SIGNATURE_PORT INPORT_BASE + 2
  47. #define INPORT_REG_BTNS 0x00
  48. #define INPORT_REG_X 0x01
  49. #define INPORT_REG_Y 0x02
  50. #define INPORT_REG_MODE 0x07
  51. #define INPORT_RESET 0x80
  52. #ifdef CONFIG_MOUSE_ATIXL
  53. #define INPORT_NAME "ATI XL Mouse"
  54. #define INPORT_VENDOR 0x0002
  55. #define INPORT_SPEED_30HZ 0x01
  56. #define INPORT_SPEED_50HZ 0x02
  57. #define INPORT_SPEED_100HZ 0x03
  58. #define INPORT_SPEED_200HZ 0x04
  59. #define INPORT_MODE_BASE INPORT_SPEED_100HZ
  60. #define INPORT_MODE_IRQ 0x08
  61. #else
  62. #define INPORT_NAME "Microsoft InPort Mouse"
  63. #define INPORT_VENDOR 0x0001
  64. #define INPORT_MODE_BASE 0x10
  65. #define INPORT_MODE_IRQ 0x01
  66. #endif
  67. #define INPORT_MODE_HOLD 0x20
  68. #define INPORT_IRQ 5
  69. static int inport_irq = INPORT_IRQ;
  70. module_param_named(irq, inport_irq, uint, 0);
  71. MODULE_PARM_DESC(irq, "IRQ number (5=default)");
  72. static struct input_dev *inport_dev;
  73. static irqreturn_t inport_interrupt(int irq, void *dev_id)
  74. {
  75. unsigned char buttons;
  76. outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
  77. outb(INPORT_MODE_HOLD | INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT);
  78. outb(INPORT_REG_X, INPORT_CONTROL_PORT);
  79. input_report_rel(inport_dev, REL_X, inb(INPORT_DATA_PORT));
  80. outb(INPORT_REG_Y, INPORT_CONTROL_PORT);
  81. input_report_rel(inport_dev, REL_Y, inb(INPORT_DATA_PORT));
  82. outb(INPORT_REG_BTNS, INPORT_CONTROL_PORT);
  83. buttons = inb(INPORT_DATA_PORT);
  84. input_report_key(inport_dev, BTN_MIDDLE, buttons & 1);
  85. input_report_key(inport_dev, BTN_LEFT, buttons & 2);
  86. input_report_key(inport_dev, BTN_RIGHT, buttons & 4);
  87. outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
  88. outb(INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT);
  89. input_sync(inport_dev);
  90. return IRQ_HANDLED;
  91. }
  92. static int inport_open(struct input_dev *dev)
  93. {
  94. if (request_irq(inport_irq, inport_interrupt, 0, "inport", NULL))
  95. return -EBUSY;
  96. outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
  97. outb(INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT);
  98. return 0;
  99. }
  100. static void inport_close(struct input_dev *dev)
  101. {
  102. outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
  103. outb(INPORT_MODE_BASE, INPORT_DATA_PORT);
  104. free_irq(inport_irq, NULL);
  105. }
  106. static int __init inport_init(void)
  107. {
  108. unsigned char a, b, c;
  109. int err;
  110. if (!request_region(INPORT_BASE, INPORT_EXTENT, "inport")) {
  111. printk(KERN_ERR "inport.c: Can't allocate ports at %#x\n", INPORT_BASE);
  112. return -EBUSY;
  113. }
  114. a = inb(INPORT_SIGNATURE_PORT);
  115. b = inb(INPORT_SIGNATURE_PORT);
  116. c = inb(INPORT_SIGNATURE_PORT);
  117. if (a == b || a != c) {
  118. printk(KERN_INFO "inport.c: Didn't find InPort mouse at %#x\n", INPORT_BASE);
  119. err = -ENODEV;
  120. goto err_release_region;
  121. }
  122. inport_dev = input_allocate_device();
  123. if (!inport_dev) {
  124. printk(KERN_ERR "inport.c: Not enough memory for input device\n");
  125. err = -ENOMEM;
  126. goto err_release_region;
  127. }
  128. inport_dev->name = INPORT_NAME;
  129. inport_dev->phys = "isa023c/input0";
  130. inport_dev->id.bustype = BUS_ISA;
  131. inport_dev->id.vendor = INPORT_VENDOR;
  132. inport_dev->id.product = 0x0001;
  133. inport_dev->id.version = 0x0100;
  134. inport_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
  135. inport_dev->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) |
  136. BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
  137. inport_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
  138. inport_dev->open = inport_open;
  139. inport_dev->close = inport_close;
  140. outb(INPORT_RESET, INPORT_CONTROL_PORT);
  141. outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
  142. outb(INPORT_MODE_BASE, INPORT_DATA_PORT);
  143. err = input_register_device(inport_dev);
  144. if (err)
  145. goto err_free_dev;
  146. return 0;
  147. err_free_dev:
  148. input_free_device(inport_dev);
  149. err_release_region:
  150. release_region(INPORT_BASE, INPORT_EXTENT);
  151. return err;
  152. }
  153. static void __exit inport_exit(void)
  154. {
  155. input_unregister_device(inport_dev);
  156. release_region(INPORT_BASE, INPORT_EXTENT);
  157. }
  158. module_init(inport_init);
  159. module_exit(inport_exit);