inport.c 5.3 KB

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