inport.c 5.3 KB

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