[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / drivers / input / mouse / inport.c
blobca4e9688662729bd1fbb377d8b2c9b5c18196d2f
1 /*
2 * $Id: inport.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 * Teemu Rantanen Derrick Cole
8 * Peter Cervasio Christoph Niemann
9 * Philip Blundell Russell King
10 * Bob Harris
14 * Inport (ATI XL and Microsoft) busmouse driver for Linux
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
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
23 * 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.
28 * 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
32 * 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
37 #include <linux/module.h>
38 #include <linux/moduleparam.h>
39 #include <linux/config.h>
40 #include <linux/ioport.h>
41 #include <linux/init.h>
42 #include <linux/interrupt.h>
43 #include <linux/input.h>
45 #include <asm/io.h>
46 #include <asm/irq.h>
48 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
49 MODULE_DESCRIPTION("Inport (ATI XL and Microsoft) busmouse driver");
50 MODULE_LICENSE("GPL");
52 #define INPORT_BASE 0x23c
53 #define INPORT_EXTENT 4
55 #define INPORT_CONTROL_PORT INPORT_BASE + 0
56 #define INPORT_DATA_PORT INPORT_BASE + 1
57 #define INPORT_SIGNATURE_PORT INPORT_BASE + 2
59 #define INPORT_REG_BTNS 0x00
60 #define INPORT_REG_X 0x01
61 #define INPORT_REG_Y 0x02
62 #define INPORT_REG_MODE 0x07
63 #define INPORT_RESET 0x80
65 #ifdef CONFIG_INPUT_ATIXL
66 #define INPORT_NAME "ATI XL Mouse"
67 #define INPORT_VENDOR 0x0002
68 #define INPORT_SPEED_30HZ 0x01
69 #define INPORT_SPEED_50HZ 0x02
70 #define INPORT_SPEED_100HZ 0x03
71 #define INPORT_SPEED_200HZ 0x04
72 #define INPORT_MODE_BASE INPORT_SPEED_100HZ
73 #define INPORT_MODE_IRQ 0x08
74 #else
75 #define INPORT_NAME "Microsoft InPort Mouse"
76 #define INPORT_VENDOR 0x0001
77 #define INPORT_MODE_BASE 0x10
78 #define INPORT_MODE_IRQ 0x01
79 #endif
80 #define INPORT_MODE_HOLD 0x20
82 #define INPORT_IRQ 5
84 static int inport_irq = INPORT_IRQ;
85 module_param_named(irq, inport_irq, uint, 0);
86 MODULE_PARM_DESC(irq, "IRQ number (5=default)");
88 __obsolete_setup("inport_irq=");
90 static int inport_used;
92 static irqreturn_t inport_interrupt(int irq, void *dev_id, struct pt_regs *regs);
94 static int inport_open(struct input_dev *dev)
96 if (!inport_used++) {
97 if (request_irq(inport_irq, inport_interrupt, 0, "inport", NULL))
98 return -EBUSY;
99 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
100 outb(INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT);
103 return 0;
106 static void inport_close(struct input_dev *dev)
108 if (!--inport_used) {
109 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
110 outb(INPORT_MODE_BASE, INPORT_DATA_PORT);
111 free_irq(inport_irq, NULL);
115 static struct input_dev inport_dev = {
116 .evbit = { BIT(EV_KEY) | BIT(EV_REL) },
117 .keybit = { [LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT) },
118 .relbit = { BIT(REL_X) | BIT(REL_Y) },
119 .open = inport_open,
120 .close = inport_close,
121 .name = INPORT_NAME,
122 .phys = "isa023c/input0",
123 .id = {
124 .bustype = BUS_ISA,
125 .vendor = INPORT_VENDOR,
126 .product = 0x0001,
127 .version = 0x0100,
131 static irqreturn_t inport_interrupt(int irq, void *dev_id, struct pt_regs *regs)
133 unsigned char buttons;
135 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
136 outb(INPORT_MODE_HOLD | INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT);
138 input_regs(&inport_dev, regs);
140 outb(INPORT_REG_X, INPORT_CONTROL_PORT);
141 input_report_rel(&inport_dev, REL_X, inb(INPORT_DATA_PORT));
143 outb(INPORT_REG_Y, INPORT_CONTROL_PORT);
144 input_report_rel(&inport_dev, REL_Y, inb(INPORT_DATA_PORT));
146 outb(INPORT_REG_BTNS, INPORT_CONTROL_PORT);
147 buttons = inb(INPORT_DATA_PORT);
149 input_report_key(&inport_dev, BTN_MIDDLE, buttons & 1);
150 input_report_key(&inport_dev, BTN_LEFT, buttons & 2);
151 input_report_key(&inport_dev, BTN_RIGHT, buttons & 4);
153 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
154 outb(INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT);
156 input_sync(&inport_dev);
157 return IRQ_HANDLED;
160 static int __init inport_init(void)
162 unsigned char a,b,c;
164 if (!request_region(INPORT_BASE, INPORT_EXTENT, "inport")) {
165 printk(KERN_ERR "inport.c: Can't allocate ports at %#x\n", INPORT_BASE);
166 return -EBUSY;
169 a = inb(INPORT_SIGNATURE_PORT);
170 b = inb(INPORT_SIGNATURE_PORT);
171 c = inb(INPORT_SIGNATURE_PORT);
172 if (( a == b ) || ( a != c )) {
173 release_region(INPORT_BASE, INPORT_EXTENT);
174 printk(KERN_ERR "inport.c: Didn't find InPort mouse at %#x\n", INPORT_BASE);
175 return -ENODEV;
178 outb(INPORT_RESET, INPORT_CONTROL_PORT);
179 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
180 outb(INPORT_MODE_BASE, INPORT_DATA_PORT);
182 input_register_device(&inport_dev);
184 printk(KERN_INFO "input: " INPORT_NAME " at %#x irq %d\n", INPORT_BASE, inport_irq);
186 return 0;
189 static void __exit inport_exit(void)
191 input_unregister_device(&inport_dev);
192 release_region(INPORT_BASE, INPORT_EXTENT);
195 module_init(inport_init);
196 module_exit(inport_exit);