logibm.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * $Id: logibm.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. * James Banks Matthew Dillon
  8. * David Giller Nathan Laredo
  9. * Linus Torvalds Johan Myreen
  10. * Cliff Matthews Philip Blundell
  11. * Russell King
  12. */
  13. /*
  14. * Logitech Bus Mouse Driver for Linux
  15. */
  16. /*
  17. * This program is free software; you can redistribute it and/or modify
  18. * it under the terms of the GNU General Public License as published by
  19. * the Free Software Foundation; either version 2 of the License, or
  20. * (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program; if not, write to the Free Software
  29. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  30. *
  31. * Should you need to contact me, the author, you can do so either by
  32. * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
  33. * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
  34. */
  35. #include <linux/module.h>
  36. #include <linux/moduleparam.h>
  37. #include <linux/delay.h>
  38. #include <linux/ioport.h>
  39. #include <linux/init.h>
  40. #include <linux/input.h>
  41. #include <linux/interrupt.h>
  42. #include <asm/io.h>
  43. #include <asm/irq.h>
  44. MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
  45. MODULE_DESCRIPTION("Logitech busmouse driver");
  46. MODULE_LICENSE("GPL");
  47. #define LOGIBM_BASE 0x23c
  48. #define LOGIBM_EXTENT 4
  49. #define LOGIBM_DATA_PORT LOGIBM_BASE + 0
  50. #define LOGIBM_SIGNATURE_PORT LOGIBM_BASE + 1
  51. #define LOGIBM_CONTROL_PORT LOGIBM_BASE + 2
  52. #define LOGIBM_CONFIG_PORT LOGIBM_BASE + 3
  53. #define LOGIBM_ENABLE_IRQ 0x00
  54. #define LOGIBM_DISABLE_IRQ 0x10
  55. #define LOGIBM_READ_X_LOW 0x80
  56. #define LOGIBM_READ_X_HIGH 0xa0
  57. #define LOGIBM_READ_Y_LOW 0xc0
  58. #define LOGIBM_READ_Y_HIGH 0xe0
  59. #define LOGIBM_DEFAULT_MODE 0x90
  60. #define LOGIBM_CONFIG_BYTE 0x91
  61. #define LOGIBM_SIGNATURE_BYTE 0xa5
  62. #define LOGIBM_IRQ 5
  63. static int logibm_irq = LOGIBM_IRQ;
  64. module_param_named(irq, logibm_irq, uint, 0);
  65. MODULE_PARM_DESC(irq, "IRQ number (5=default)");
  66. __obsolete_setup("logibm_irq=");
  67. static irqreturn_t logibm_interrupt(int irq, void *dev_id, struct pt_regs *regs);
  68. static int logibm_open(struct input_dev *dev)
  69. {
  70. if (request_irq(logibm_irq, logibm_interrupt, 0, "logibm", NULL)) {
  71. printk(KERN_ERR "logibm.c: Can't allocate irq %d\n", logibm_irq);
  72. return -EBUSY;
  73. }
  74. outb(LOGIBM_ENABLE_IRQ, LOGIBM_CONTROL_PORT);
  75. return 0;
  76. }
  77. static void logibm_close(struct input_dev *dev)
  78. {
  79. outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT);
  80. free_irq(logibm_irq, NULL);
  81. }
  82. static struct input_dev logibm_dev = {
  83. .evbit = { BIT(EV_KEY) | BIT(EV_REL) },
  84. .keybit = { [LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT) },
  85. .relbit = { BIT(REL_X) | BIT(REL_Y) },
  86. .open = logibm_open,
  87. .close = logibm_close,
  88. .name = "Logitech bus mouse",
  89. .phys = "isa023c/input0",
  90. .id = {
  91. .bustype = BUS_ISA,
  92. .vendor = 0x0003,
  93. .product = 0x0001,
  94. .version = 0x0100,
  95. },
  96. };
  97. static irqreturn_t logibm_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  98. {
  99. char dx, dy;
  100. unsigned char buttons;
  101. outb(LOGIBM_READ_X_LOW, LOGIBM_CONTROL_PORT);
  102. dx = (inb(LOGIBM_DATA_PORT) & 0xf);
  103. outb(LOGIBM_READ_X_HIGH, LOGIBM_CONTROL_PORT);
  104. dx |= (inb(LOGIBM_DATA_PORT) & 0xf) << 4;
  105. outb(LOGIBM_READ_Y_LOW, LOGIBM_CONTROL_PORT);
  106. dy = (inb(LOGIBM_DATA_PORT) & 0xf);
  107. outb(LOGIBM_READ_Y_HIGH, LOGIBM_CONTROL_PORT);
  108. buttons = inb(LOGIBM_DATA_PORT);
  109. dy |= (buttons & 0xf) << 4;
  110. buttons = ~buttons >> 5;
  111. input_regs(&logibm_dev, regs);
  112. input_report_rel(&logibm_dev, REL_X, dx);
  113. input_report_rel(&logibm_dev, REL_Y, dy);
  114. input_report_key(&logibm_dev, BTN_RIGHT, buttons & 1);
  115. input_report_key(&logibm_dev, BTN_MIDDLE, buttons & 2);
  116. input_report_key(&logibm_dev, BTN_LEFT, buttons & 4);
  117. input_sync(&logibm_dev);
  118. outb(LOGIBM_ENABLE_IRQ, LOGIBM_CONTROL_PORT);
  119. return IRQ_HANDLED;
  120. }
  121. static int __init logibm_init(void)
  122. {
  123. if (!request_region(LOGIBM_BASE, LOGIBM_EXTENT, "logibm")) {
  124. printk(KERN_ERR "logibm.c: Can't allocate ports at %#x\n", LOGIBM_BASE);
  125. return -EBUSY;
  126. }
  127. outb(LOGIBM_CONFIG_BYTE, LOGIBM_CONFIG_PORT);
  128. outb(LOGIBM_SIGNATURE_BYTE, LOGIBM_SIGNATURE_PORT);
  129. udelay(100);
  130. if (inb(LOGIBM_SIGNATURE_PORT) != LOGIBM_SIGNATURE_BYTE) {
  131. release_region(LOGIBM_BASE, LOGIBM_EXTENT);
  132. printk(KERN_ERR "logibm.c: Didn't find Logitech busmouse at %#x\n", LOGIBM_BASE);
  133. return -ENODEV;
  134. }
  135. outb(LOGIBM_DEFAULT_MODE, LOGIBM_CONFIG_PORT);
  136. outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT);
  137. input_register_device(&logibm_dev);
  138. printk(KERN_INFO "input: Logitech bus mouse at %#x irq %d\n", LOGIBM_BASE, logibm_irq);
  139. return 0;
  140. }
  141. static void __exit logibm_exit(void)
  142. {
  143. input_unregister_device(&logibm_dev);
  144. release_region(LOGIBM_BASE, LOGIBM_EXTENT);
  145. }
  146. module_init(logibm_init);
  147. module_exit(logibm_exit);