xref: /openbmc/linux/drivers/input/mouse/inport.c (revision 2e5b636b)
1 /*
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
20  * the Free Software Foundation; either version 2 of the License, or
21  * (at your option) any later version.
22  *
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.
27  *
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
31  *
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
35  */
36 
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>
44 
45 #include <asm/io.h>
46 #include <asm/irq.h>
47 
48 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
49 MODULE_DESCRIPTION("Inport (ATI XL and Microsoft) busmouse driver");
50 MODULE_LICENSE("GPL");
51 
52 #define INPORT_BASE		0x23c
53 #define INPORT_EXTENT		4
54 
55 #define INPORT_CONTROL_PORT	INPORT_BASE + 0
56 #define INPORT_DATA_PORT	INPORT_BASE + 1
57 #define INPORT_SIGNATURE_PORT	INPORT_BASE + 2
58 
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
64 
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
81 
82 #define INPORT_IRQ		5
83 
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)");
87 
88 __obsolete_setup("inport_irq=");
89 
90 static struct input_dev *inport_dev;
91 
92 static irqreturn_t inport_interrupt(int irq, void *dev_id, struct pt_regs *regs)
93 {
94 	unsigned char buttons;
95 
96 	outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
97 	outb(INPORT_MODE_HOLD | INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT);
98 
99 	input_regs(inport_dev, regs);
100 
101 	outb(INPORT_REG_X, INPORT_CONTROL_PORT);
102 	input_report_rel(inport_dev, REL_X, inb(INPORT_DATA_PORT));
103 
104 	outb(INPORT_REG_Y, INPORT_CONTROL_PORT);
105 	input_report_rel(inport_dev, REL_Y, inb(INPORT_DATA_PORT));
106 
107 	outb(INPORT_REG_BTNS, INPORT_CONTROL_PORT);
108 	buttons = inb(INPORT_DATA_PORT);
109 
110 	input_report_key(inport_dev, BTN_MIDDLE, buttons & 1);
111 	input_report_key(inport_dev, BTN_LEFT,   buttons & 2);
112 	input_report_key(inport_dev, BTN_RIGHT,  buttons & 4);
113 
114 	outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
115 	outb(INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT);
116 
117 	input_sync(inport_dev);
118 	return IRQ_HANDLED;
119 }
120 
121 static int inport_open(struct input_dev *dev)
122 {
123 	if (request_irq(inport_irq, inport_interrupt, 0, "inport", NULL))
124 		return -EBUSY;
125 	outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
126 	outb(INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT);
127 
128 	return 0;
129 }
130 
131 static void inport_close(struct input_dev *dev)
132 {
133 	outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
134 	outb(INPORT_MODE_BASE, INPORT_DATA_PORT);
135 	free_irq(inport_irq, NULL);
136 }
137 
138 static int __init inport_init(void)
139 {
140 	unsigned char a, b, c;
141 
142 	if (!request_region(INPORT_BASE, INPORT_EXTENT, "inport")) {
143 		printk(KERN_ERR "inport.c: Can't allocate ports at %#x\n", INPORT_BASE);
144 		return -EBUSY;
145 	}
146 
147 	a = inb(INPORT_SIGNATURE_PORT);
148 	b = inb(INPORT_SIGNATURE_PORT);
149 	c = inb(INPORT_SIGNATURE_PORT);
150 	if (a == b || a != c) {
151 		release_region(INPORT_BASE, INPORT_EXTENT);
152 		printk(KERN_ERR "inport.c: Didn't find InPort mouse at %#x\n", INPORT_BASE);
153 		return -ENODEV;
154 	}
155 
156 	if (!(inport_dev = input_allocate_device())) {
157 		printk(KERN_ERR "inport.c: Not enough memory for input device\n");
158 		release_region(INPORT_BASE, INPORT_EXTENT);
159 		return -ENOMEM;
160 	}
161 
162 	inport_dev->name = INPORT_NAME;
163 	inport_dev->phys = "isa023c/input0";
164 	inport_dev->id.bustype = BUS_ISA;
165 	inport_dev->id.vendor  = INPORT_VENDOR;
166 	inport_dev->id.product = 0x0001;
167 	inport_dev->id.version = 0x0100;
168 
169 	inport_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
170 	inport_dev->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
171 	inport_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
172 
173 	inport_dev->open  = inport_open;
174 	inport_dev->close = inport_close;
175 
176 	outb(INPORT_RESET, INPORT_CONTROL_PORT);
177 	outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
178 	outb(INPORT_MODE_BASE, INPORT_DATA_PORT);
179 
180 	input_register_device(inport_dev);
181 
182 	return 0;
183 }
184 
185 static void __exit inport_exit(void)
186 {
187 	input_unregister_device(inport_dev);
188 	release_region(INPORT_BASE, INPORT_EXTENT);
189 }
190 
191 module_init(inport_init);
192 module_exit(inport_exit);
193