blob: 13dd96785e397bf81d632993512e9457ae3e0053 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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/*
14 * Inport (ATI XL and Microsoft) busmouse driver for Linux
15 */
16
17/*
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
Dmitry Torokhov968ac842005-05-29 02:28:29 -050020 * the Free Software Foundation; either version 2 of the License, or
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 * (at your option) any later version.
Dmitry Torokhov968ac842005-05-29 02:28:29 -050022 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
Dmitry Torokhov968ac842005-05-29 02:28:29 -050027 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Dmitry Torokhov968ac842005-05-29 02:28:29 -050031 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 * Should you need to contact me, the author, you can do so either by
33 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
34 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
35 */
36
37#include <linux/module.h>
38#include <linux/moduleparam.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <linux/ioport.h>
40#include <linux/init.h>
41#include <linux/interrupt.h>
42#include <linux/input.h>
43
44#include <asm/io.h>
45#include <asm/irq.h>
46
47MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
48MODULE_DESCRIPTION("Inport (ATI XL and Microsoft) busmouse driver");
49MODULE_LICENSE("GPL");
50
51#define INPORT_BASE 0x23c
52#define INPORT_EXTENT 4
53
54#define INPORT_CONTROL_PORT INPORT_BASE + 0
55#define INPORT_DATA_PORT INPORT_BASE + 1
56#define INPORT_SIGNATURE_PORT INPORT_BASE + 2
57
58#define INPORT_REG_BTNS 0x00
59#define INPORT_REG_X 0x01
60#define INPORT_REG_Y 0x02
61#define INPORT_REG_MODE 0x07
62#define INPORT_RESET 0x80
63
64#ifdef CONFIG_INPUT_ATIXL
65#define INPORT_NAME "ATI XL Mouse"
66#define INPORT_VENDOR 0x0002
67#define INPORT_SPEED_30HZ 0x01
68#define INPORT_SPEED_50HZ 0x02
69#define INPORT_SPEED_100HZ 0x03
70#define INPORT_SPEED_200HZ 0x04
71#define INPORT_MODE_BASE INPORT_SPEED_100HZ
72#define INPORT_MODE_IRQ 0x08
73#else
74#define INPORT_NAME "Microsoft InPort Mouse"
75#define INPORT_VENDOR 0x0001
76#define INPORT_MODE_BASE 0x10
77#define INPORT_MODE_IRQ 0x01
78#endif
79#define INPORT_MODE_HOLD 0x20
80
81#define INPORT_IRQ 5
82
83static int inport_irq = INPORT_IRQ;
84module_param_named(irq, inport_irq, uint, 0);
85MODULE_PARM_DESC(irq, "IRQ number (5=default)");
86
87__obsolete_setup("inport_irq=");
88
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -050089static struct input_dev *inport_dev;
90
David Howells7d12e782006-10-05 14:55:46 +010091static irqreturn_t inport_interrupt(int irq, void *dev_id)
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -050092{
93 unsigned char buttons;
94
95 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
96 outb(INPORT_MODE_HOLD | INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT);
97
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -050098 outb(INPORT_REG_X, INPORT_CONTROL_PORT);
99 input_report_rel(inport_dev, REL_X, inb(INPORT_DATA_PORT));
100
101 outb(INPORT_REG_Y, INPORT_CONTROL_PORT);
102 input_report_rel(inport_dev, REL_Y, inb(INPORT_DATA_PORT));
103
104 outb(INPORT_REG_BTNS, INPORT_CONTROL_PORT);
105 buttons = inb(INPORT_DATA_PORT);
106
107 input_report_key(inport_dev, BTN_MIDDLE, buttons & 1);
108 input_report_key(inport_dev, BTN_LEFT, buttons & 2);
109 input_report_key(inport_dev, BTN_RIGHT, buttons & 4);
110
111 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
112 outb(INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT);
113
114 input_sync(inport_dev);
115 return IRQ_HANDLED;
116}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
118static int inport_open(struct input_dev *dev)
119{
Dmitry Torokhov3108d422005-05-29 02:29:30 -0500120 if (request_irq(inport_irq, inport_interrupt, 0, "inport", NULL))
121 return -EBUSY;
122 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
123 outb(INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
125 return 0;
126}
127
128static void inport_close(struct input_dev *dev)
129{
Dmitry Torokhov3108d422005-05-29 02:29:30 -0500130 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
131 outb(INPORT_MODE_BASE, INPORT_DATA_PORT);
132 free_irq(inport_irq, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133}
134
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135static int __init inport_init(void)
136{
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500137 unsigned char a, b, c;
Dmitry Torokhov72155612006-11-05 22:40:19 -0500138 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
140 if (!request_region(INPORT_BASE, INPORT_EXTENT, "inport")) {
141 printk(KERN_ERR "inport.c: Can't allocate ports at %#x\n", INPORT_BASE);
142 return -EBUSY;
143 }
144
145 a = inb(INPORT_SIGNATURE_PORT);
146 b = inb(INPORT_SIGNATURE_PORT);
147 c = inb(INPORT_SIGNATURE_PORT);
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500148 if (a == b || a != c) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 printk(KERN_ERR "inport.c: Didn't find InPort mouse at %#x\n", INPORT_BASE);
Dmitry Torokhov72155612006-11-05 22:40:19 -0500150 err = -ENODEV;
151 goto err_release_region;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 }
153
Dmitry Torokhov72155612006-11-05 22:40:19 -0500154 inport_dev = input_allocate_device();
155 if (!inport_dev) {
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500156 printk(KERN_ERR "inport.c: Not enough memory for input device\n");
Dmitry Torokhov72155612006-11-05 22:40:19 -0500157 err = -ENOMEM;
158 goto err_release_region;
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500159 }
160
161 inport_dev->name = INPORT_NAME;
162 inport_dev->phys = "isa023c/input0";
163 inport_dev->id.bustype = BUS_ISA;
164 inport_dev->id.vendor = INPORT_VENDOR;
165 inport_dev->id.product = 0x0001;
166 inport_dev->id.version = 0x0100;
167
168 inport_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
169 inport_dev->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
170 inport_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
171
172 inport_dev->open = inport_open;
173 inport_dev->close = inport_close;
174
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 outb(INPORT_RESET, INPORT_CONTROL_PORT);
176 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
177 outb(INPORT_MODE_BASE, INPORT_DATA_PORT);
178
Dmitry Torokhov72155612006-11-05 22:40:19 -0500179 err = input_register_device(inport_dev);
180 if (err)
181 goto err_free_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
183 return 0;
Dmitry Torokhov72155612006-11-05 22:40:19 -0500184
185 err_free_dev:
186 input_free_device(inport_dev);
187 err_release_region:
188 release_region(INPORT_BASE, INPORT_EXTENT);
189
190 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191}
192
193static void __exit inport_exit(void)
194{
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500195 input_unregister_device(inport_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 release_region(INPORT_BASE, INPORT_EXTENT);
197}
198
199module_init(inport_init);
200module_exit(inport_exit);