2 * $Id: logibm.c,v 1.11 2001/09/25 10:12:07 vojtech Exp $
4 * Copyright (c) 1999-2001 Vojtech Pavlik
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
15 * Logitech Bus Mouse Driver for Linux
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 * Should you need to contact me, the author, you can do so either by
34 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
35 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
38 #include <linux/module.h>
39 #include <linux/moduleparam.h>
40 #include <linux/delay.h>
41 #include <linux/ioport.h>
42 #include <linux/init.h>
43 #include <linux/input.h>
44 #include <linux/interrupt.h>
49 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
50 MODULE_DESCRIPTION("Logitech busmouse driver");
51 MODULE_LICENSE("GPL");
53 #define LOGIBM_BASE 0x23c
54 #define LOGIBM_EXTENT 4
56 #define LOGIBM_DATA_PORT LOGIBM_BASE + 0
57 #define LOGIBM_SIGNATURE_PORT LOGIBM_BASE + 1
58 #define LOGIBM_CONTROL_PORT LOGIBM_BASE + 2
59 #define LOGIBM_CONFIG_PORT LOGIBM_BASE + 3
61 #define LOGIBM_ENABLE_IRQ 0x00
62 #define LOGIBM_DISABLE_IRQ 0x10
63 #define LOGIBM_READ_X_LOW 0x80
64 #define LOGIBM_READ_X_HIGH 0xa0
65 #define LOGIBM_READ_Y_LOW 0xc0
66 #define LOGIBM_READ_Y_HIGH 0xe0
68 #define LOGIBM_DEFAULT_MODE 0x90
69 #define LOGIBM_CONFIG_BYTE 0x91
70 #define LOGIBM_SIGNATURE_BYTE 0xa5
74 static int logibm_irq = LOGIBM_IRQ;
75 module_param_named(irq, logibm_irq, uint, 0);
76 MODULE_PARM_DESC(irq, "IRQ number (5=default)");
78 __obsolete_setup("logibm_irq=");
80 static struct input_dev *logibm_dev;
82 static irqreturn_t logibm_interrupt(int irq, void *dev_id, struct pt_regs *regs)
85 unsigned char buttons;
87 outb(LOGIBM_READ_X_LOW, LOGIBM_CONTROL_PORT);
88 dx = (inb(LOGIBM_DATA_PORT) & 0xf);
89 outb(LOGIBM_READ_X_HIGH, LOGIBM_CONTROL_PORT);
90 dx |= (inb(LOGIBM_DATA_PORT) & 0xf) << 4;
91 outb(LOGIBM_READ_Y_LOW, LOGIBM_CONTROL_PORT);
92 dy = (inb(LOGIBM_DATA_PORT) & 0xf);
93 outb(LOGIBM_READ_Y_HIGH, LOGIBM_CONTROL_PORT);
94 buttons = inb(LOGIBM_DATA_PORT);
95 dy |= (buttons & 0xf) << 4;
96 buttons = ~buttons >> 5;
98 input_regs(logibm_dev, regs);
99 input_report_rel(logibm_dev, REL_X, dx);
100 input_report_rel(logibm_dev, REL_Y, dy);
101 input_report_key(logibm_dev, BTN_RIGHT, buttons & 1);
102 input_report_key(logibm_dev, BTN_MIDDLE, buttons & 2);
103 input_report_key(logibm_dev, BTN_LEFT, buttons & 4);
104 input_sync(logibm_dev);
106 outb(LOGIBM_ENABLE_IRQ, LOGIBM_CONTROL_PORT);
110 static int logibm_open(struct input_dev *dev)
112 if (request_irq(logibm_irq, logibm_interrupt, 0, "logibm", NULL)) {
113 printk(KERN_ERR "logibm.c: Can't allocate irq %d\n", logibm_irq);
116 outb(LOGIBM_ENABLE_IRQ, LOGIBM_CONTROL_PORT);
120 static void logibm_close(struct input_dev *dev)
122 outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT);
123 free_irq(logibm_irq, NULL);
126 static int __init logibm_init(void)
128 if (!request_region(LOGIBM_BASE, LOGIBM_EXTENT, "logibm")) {
129 printk(KERN_ERR "logibm.c: Can't allocate ports at %#x\n", LOGIBM_BASE);
133 outb(LOGIBM_CONFIG_BYTE, LOGIBM_CONFIG_PORT);
134 outb(LOGIBM_SIGNATURE_BYTE, LOGIBM_SIGNATURE_PORT);
137 if (inb(LOGIBM_SIGNATURE_PORT) != LOGIBM_SIGNATURE_BYTE) {
138 release_region(LOGIBM_BASE, LOGIBM_EXTENT);
139 printk(KERN_ERR "logibm.c: Didn't find Logitech busmouse at %#x\n", LOGIBM_BASE);
143 outb(LOGIBM_DEFAULT_MODE, LOGIBM_CONFIG_PORT);
144 outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT);
146 if (!(logibm_dev = input_allocate_device())) {
147 printk(KERN_ERR "logibm.c: Not enough memory for input device\n");
148 release_region(LOGIBM_BASE, LOGIBM_EXTENT);
152 logibm_dev->name = "Logitech bus mouse";
153 logibm_dev->phys = "isa023c/input0";
154 logibm_dev->id.bustype = BUS_ISA;
155 logibm_dev->id.vendor = 0x0003;
156 logibm_dev->id.product = 0x0001;
157 logibm_dev->id.version = 0x0100;
159 logibm_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
160 logibm_dev->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
161 logibm_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
163 logibm_dev->open = logibm_open;
164 logibm_dev->close = logibm_close;
166 input_register_device(logibm_dev);
171 static void __exit logibm_exit(void)
173 input_unregister_device(logibm_dev);
174 release_region(LOGIBM_BASE, LOGIBM_EXTENT);
177 module_init(logibm_init);
178 module_exit(logibm_exit);