]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - drivers/input/mouse/logibm.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6 into for-linus
[mirror_ubuntu-jammy-kernel.git] / drivers / input / mouse / logibm.c
CommitLineData
1da177e4
LT
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/*
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
968ac842 21 * the Free Software Foundation; either version 2 of the License, or
1da177e4 22 * (at your option) any later version.
968ac842 23 *
1da177e4
LT
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.
968ac842 28 *
1da177e4
LT
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
968ac842 32 *
1da177e4
LT
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
36 */
37
38#include <linux/module.h>
1da177e4
LT
39#include <linux/delay.h>
40#include <linux/ioport.h>
41#include <linux/init.h>
42#include <linux/input.h>
43#include <linux/interrupt.h>
44
45#include <asm/io.h>
46#include <asm/irq.h>
47
48MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
49MODULE_DESCRIPTION("Logitech busmouse driver");
50MODULE_LICENSE("GPL");
51
52#define LOGIBM_BASE 0x23c
53#define LOGIBM_EXTENT 4
54
55#define LOGIBM_DATA_PORT LOGIBM_BASE + 0
56#define LOGIBM_SIGNATURE_PORT LOGIBM_BASE + 1
57#define LOGIBM_CONTROL_PORT LOGIBM_BASE + 2
58#define LOGIBM_CONFIG_PORT LOGIBM_BASE + 3
59
60#define LOGIBM_ENABLE_IRQ 0x00
61#define LOGIBM_DISABLE_IRQ 0x10
62#define LOGIBM_READ_X_LOW 0x80
63#define LOGIBM_READ_X_HIGH 0xa0
64#define LOGIBM_READ_Y_LOW 0xc0
65#define LOGIBM_READ_Y_HIGH 0xe0
66
67#define LOGIBM_DEFAULT_MODE 0x90
68#define LOGIBM_CONFIG_BYTE 0x91
69#define LOGIBM_SIGNATURE_BYTE 0xa5
70
71#define LOGIBM_IRQ 5
72
73static int logibm_irq = LOGIBM_IRQ;
74module_param_named(irq, logibm_irq, uint, 0);
75MODULE_PARM_DESC(irq, "IRQ number (5=default)");
76
2e5b636b 77static struct input_dev *logibm_dev;
1da177e4 78
7d12e780 79static irqreturn_t logibm_interrupt(int irq, void *dev_id)
1da177e4
LT
80{
81 char dx, dy;
82 unsigned char buttons;
83
84 outb(LOGIBM_READ_X_LOW, LOGIBM_CONTROL_PORT);
85 dx = (inb(LOGIBM_DATA_PORT) & 0xf);
86 outb(LOGIBM_READ_X_HIGH, LOGIBM_CONTROL_PORT);
87 dx |= (inb(LOGIBM_DATA_PORT) & 0xf) << 4;
88 outb(LOGIBM_READ_Y_LOW, LOGIBM_CONTROL_PORT);
89 dy = (inb(LOGIBM_DATA_PORT) & 0xf);
90 outb(LOGIBM_READ_Y_HIGH, LOGIBM_CONTROL_PORT);
91 buttons = inb(LOGIBM_DATA_PORT);
92 dy |= (buttons & 0xf) << 4;
93 buttons = ~buttons >> 5;
94
2e5b636b
DT
95 input_report_rel(logibm_dev, REL_X, dx);
96 input_report_rel(logibm_dev, REL_Y, dy);
97 input_report_key(logibm_dev, BTN_RIGHT, buttons & 1);
98 input_report_key(logibm_dev, BTN_MIDDLE, buttons & 2);
99 input_report_key(logibm_dev, BTN_LEFT, buttons & 4);
100 input_sync(logibm_dev);
1da177e4
LT
101
102 outb(LOGIBM_ENABLE_IRQ, LOGIBM_CONTROL_PORT);
103 return IRQ_HANDLED;
104}
105
2e5b636b
DT
106static int logibm_open(struct input_dev *dev)
107{
108 if (request_irq(logibm_irq, logibm_interrupt, 0, "logibm", NULL)) {
109 printk(KERN_ERR "logibm.c: Can't allocate irq %d\n", logibm_irq);
110 return -EBUSY;
111 }
112 outb(LOGIBM_ENABLE_IRQ, LOGIBM_CONTROL_PORT);
113 return 0;
114}
115
116static void logibm_close(struct input_dev *dev)
117{
118 outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT);
119 free_irq(logibm_irq, NULL);
120}
121
1da177e4
LT
122static int __init logibm_init(void)
123{
72155615
DT
124 int err;
125
1da177e4
LT
126 if (!request_region(LOGIBM_BASE, LOGIBM_EXTENT, "logibm")) {
127 printk(KERN_ERR "logibm.c: Can't allocate ports at %#x\n", LOGIBM_BASE);
128 return -EBUSY;
129 }
130
131 outb(LOGIBM_CONFIG_BYTE, LOGIBM_CONFIG_PORT);
132 outb(LOGIBM_SIGNATURE_BYTE, LOGIBM_SIGNATURE_PORT);
133 udelay(100);
134
135 if (inb(LOGIBM_SIGNATURE_PORT) != LOGIBM_SIGNATURE_BYTE) {
2a0f9c4c 136 printk(KERN_INFO "logibm.c: Didn't find Logitech busmouse at %#x\n", LOGIBM_BASE);
72155615
DT
137 err = -ENODEV;
138 goto err_release_region;
1da177e4
LT
139 }
140
141 outb(LOGIBM_DEFAULT_MODE, LOGIBM_CONFIG_PORT);
142 outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT);
143
72155615
DT
144 logibm_dev = input_allocate_device();
145 if (!logibm_dev) {
2e5b636b 146 printk(KERN_ERR "logibm.c: Not enough memory for input device\n");
72155615
DT
147 err = -ENOMEM;
148 goto err_release_region;
2e5b636b
DT
149 }
150
151 logibm_dev->name = "Logitech bus mouse";
152 logibm_dev->phys = "isa023c/input0";
153 logibm_dev->id.bustype = BUS_ISA;
154 logibm_dev->id.vendor = 0x0003;
155 logibm_dev->id.product = 0x0001;
156 logibm_dev->id.version = 0x0100;
157
7b19ada2
JS
158 logibm_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
159 logibm_dev->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) |
160 BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
161 logibm_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
2e5b636b
DT
162
163 logibm_dev->open = logibm_open;
164 logibm_dev->close = logibm_close;
968ac842 165
72155615
DT
166 err = input_register_device(logibm_dev);
167 if (err)
168 goto err_free_dev;
1da177e4
LT
169
170 return 0;
72155615
DT
171
172 err_free_dev:
173 input_free_device(logibm_dev);
174 err_release_region:
175 release_region(LOGIBM_BASE, LOGIBM_EXTENT);
176
177 return err;
1da177e4
LT
178}
179
180static void __exit logibm_exit(void)
181{
2e5b636b 182 input_unregister_device(logibm_dev);
1da177e4
LT
183 release_region(LOGIBM_BASE, LOGIBM_EXTENT);
184}
185
186module_init(logibm_init);
187module_exit(logibm_exit);