blob: b23a4f3ea5cdcf48d5e09cf789ba610940a3f68f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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/*
15 * Logitech Bus Mouse Driver for Linux
16 */
17
18/*
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
Dmitry Torokhov968ac842005-05-29 02:28:29 -050021 * the Free Software Foundation; either version 2 of the License, or
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 * (at your option) any later version.
Dmitry Torokhov968ac842005-05-29 02:28:29 -050023 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 * 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.
Dmitry Torokhov968ac842005-05-29 02:28:29 -050028 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 * 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
Dmitry Torokhov968ac842005-05-29 02:28:29 -050032 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 * 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
36 */
37
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>
45
46#include <asm/io.h>
47#include <asm/irq.h>
48
49MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
50MODULE_DESCRIPTION("Logitech busmouse driver");
51MODULE_LICENSE("GPL");
52
53#define LOGIBM_BASE 0x23c
54#define LOGIBM_EXTENT 4
55
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
60
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
67
68#define LOGIBM_DEFAULT_MODE 0x90
69#define LOGIBM_CONFIG_BYTE 0x91
70#define LOGIBM_SIGNATURE_BYTE 0xa5
71
72#define LOGIBM_IRQ 5
73
74static int logibm_irq = LOGIBM_IRQ;
75module_param_named(irq, logibm_irq, uint, 0);
76MODULE_PARM_DESC(irq, "IRQ number (5=default)");
77
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -050078static struct input_dev *logibm_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
David Howells7d12e782006-10-05 14:55:46 +010080static irqreturn_t logibm_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081{
82 char dx, dy;
83 unsigned char buttons;
84
85 outb(LOGIBM_READ_X_LOW, LOGIBM_CONTROL_PORT);
86 dx = (inb(LOGIBM_DATA_PORT) & 0xf);
87 outb(LOGIBM_READ_X_HIGH, LOGIBM_CONTROL_PORT);
88 dx |= (inb(LOGIBM_DATA_PORT) & 0xf) << 4;
89 outb(LOGIBM_READ_Y_LOW, LOGIBM_CONTROL_PORT);
90 dy = (inb(LOGIBM_DATA_PORT) & 0xf);
91 outb(LOGIBM_READ_Y_HIGH, LOGIBM_CONTROL_PORT);
92 buttons = inb(LOGIBM_DATA_PORT);
93 dy |= (buttons & 0xf) << 4;
94 buttons = ~buttons >> 5;
95
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -050096 input_report_rel(logibm_dev, REL_X, dx);
97 input_report_rel(logibm_dev, REL_Y, dy);
98 input_report_key(logibm_dev, BTN_RIGHT, buttons & 1);
99 input_report_key(logibm_dev, BTN_MIDDLE, buttons & 2);
100 input_report_key(logibm_dev, BTN_LEFT, buttons & 4);
101 input_sync(logibm_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
103 outb(LOGIBM_ENABLE_IRQ, LOGIBM_CONTROL_PORT);
104 return IRQ_HANDLED;
105}
106
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500107static int logibm_open(struct input_dev *dev)
108{
109 if (request_irq(logibm_irq, logibm_interrupt, 0, "logibm", NULL)) {
110 printk(KERN_ERR "logibm.c: Can't allocate irq %d\n", logibm_irq);
111 return -EBUSY;
112 }
113 outb(LOGIBM_ENABLE_IRQ, LOGIBM_CONTROL_PORT);
114 return 0;
115}
116
117static void logibm_close(struct input_dev *dev)
118{
119 outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT);
120 free_irq(logibm_irq, NULL);
121}
122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123static int __init logibm_init(void)
124{
Dmitry Torokhov72155612006-11-05 22:40:19 -0500125 int err;
126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 if (!request_region(LOGIBM_BASE, LOGIBM_EXTENT, "logibm")) {
128 printk(KERN_ERR "logibm.c: Can't allocate ports at %#x\n", LOGIBM_BASE);
129 return -EBUSY;
130 }
131
132 outb(LOGIBM_CONFIG_BYTE, LOGIBM_CONFIG_PORT);
133 outb(LOGIBM_SIGNATURE_BYTE, LOGIBM_SIGNATURE_PORT);
134 udelay(100);
135
136 if (inb(LOGIBM_SIGNATURE_PORT) != LOGIBM_SIGNATURE_BYTE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 printk(KERN_ERR "logibm.c: Didn't find Logitech busmouse at %#x\n", LOGIBM_BASE);
Dmitry Torokhov72155612006-11-05 22:40:19 -0500138 err = -ENODEV;
139 goto err_release_region;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 }
141
142 outb(LOGIBM_DEFAULT_MODE, LOGIBM_CONFIG_PORT);
143 outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT);
144
Dmitry Torokhov72155612006-11-05 22:40:19 -0500145 logibm_dev = input_allocate_device();
146 if (!logibm_dev) {
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500147 printk(KERN_ERR "logibm.c: Not enough memory for input device\n");
Dmitry Torokhov72155612006-11-05 22:40:19 -0500148 err = -ENOMEM;
149 goto err_release_region;
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500150 }
Dmitry Torokhov968ac842005-05-29 02:28:29 -0500151
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500152 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;
158
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700159 logibm_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
160 logibm_dev->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) |
161 BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
162 logibm_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500163
164 logibm_dev->open = logibm_open;
165 logibm_dev->close = logibm_close;
166
Dmitry Torokhov72155612006-11-05 22:40:19 -0500167 err = input_register_device(logibm_dev);
168 if (err)
169 goto err_free_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
171 return 0;
Dmitry Torokhov72155612006-11-05 22:40:19 -0500172
173 err_free_dev:
174 input_free_device(logibm_dev);
175 err_release_region:
176 release_region(LOGIBM_BASE, LOGIBM_EXTENT);
177
178 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179}
180
181static void __exit logibm_exit(void)
182{
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500183 input_unregister_device(logibm_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 release_region(LOGIBM_BASE, LOGIBM_EXTENT);
185}
186
187module_init(logibm_init);
188module_exit(logibm_exit);