2 * Copyright (c) 1999-2001 Vojtech Pavlik
4 * Based on the work of:
5 * Teemu Rantanen Derrick Cole
6 * Peter Cervasio Christoph Niemann
7 * Philip Blundell Russell King
12 * Inport (ATI XL and Microsoft) busmouse driver for Linux
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include <linux/module.h>
32 #include <linux/ioport.h>
33 #include <linux/init.h>
34 #include <linux/interrupt.h>
35 #include <linux/input.h>
40 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
41 MODULE_DESCRIPTION("Inport (ATI XL and Microsoft) busmouse driver");
42 MODULE_LICENSE("GPL");
44 #define INPORT_BASE 0x23c
45 #define INPORT_EXTENT 4
47 #define INPORT_CONTROL_PORT INPORT_BASE + 0
48 #define INPORT_DATA_PORT INPORT_BASE + 1
49 #define INPORT_SIGNATURE_PORT INPORT_BASE + 2
51 #define INPORT_REG_BTNS 0x00
52 #define INPORT_REG_X 0x01
53 #define INPORT_REG_Y 0x02
54 #define INPORT_REG_MODE 0x07
55 #define INPORT_RESET 0x80
57 #ifdef CONFIG_MOUSE_ATIXL
58 #define INPORT_NAME "ATI XL Mouse"
59 #define INPORT_VENDOR 0x0002
60 #define INPORT_SPEED_30HZ 0x01
61 #define INPORT_SPEED_50HZ 0x02
62 #define INPORT_SPEED_100HZ 0x03
63 #define INPORT_SPEED_200HZ 0x04
64 #define INPORT_MODE_BASE INPORT_SPEED_100HZ
65 #define INPORT_MODE_IRQ 0x08
67 #define INPORT_NAME "Microsoft InPort Mouse"
68 #define INPORT_VENDOR 0x0001
69 #define INPORT_MODE_BASE 0x10
70 #define INPORT_MODE_IRQ 0x01
72 #define INPORT_MODE_HOLD 0x20
76 static int inport_irq
= INPORT_IRQ
;
77 module_param_hw_named(irq
, inport_irq
, uint
, irq
, 0);
78 MODULE_PARM_DESC(irq
, "IRQ number (5=default)");
80 static struct input_dev
*inport_dev
;
82 static irqreturn_t
inport_interrupt(int irq
, void *dev_id
)
84 unsigned char buttons
;
86 outb(INPORT_REG_MODE
, INPORT_CONTROL_PORT
);
87 outb(INPORT_MODE_HOLD
| INPORT_MODE_IRQ
| INPORT_MODE_BASE
, INPORT_DATA_PORT
);
89 outb(INPORT_REG_X
, INPORT_CONTROL_PORT
);
90 input_report_rel(inport_dev
, REL_X
, inb(INPORT_DATA_PORT
));
92 outb(INPORT_REG_Y
, INPORT_CONTROL_PORT
);
93 input_report_rel(inport_dev
, REL_Y
, inb(INPORT_DATA_PORT
));
95 outb(INPORT_REG_BTNS
, INPORT_CONTROL_PORT
);
96 buttons
= inb(INPORT_DATA_PORT
);
98 input_report_key(inport_dev
, BTN_MIDDLE
, buttons
& 1);
99 input_report_key(inport_dev
, BTN_LEFT
, buttons
& 2);
100 input_report_key(inport_dev
, BTN_RIGHT
, buttons
& 4);
102 outb(INPORT_REG_MODE
, INPORT_CONTROL_PORT
);
103 outb(INPORT_MODE_IRQ
| INPORT_MODE_BASE
, INPORT_DATA_PORT
);
105 input_sync(inport_dev
);
109 static int inport_open(struct input_dev
*dev
)
111 if (request_irq(inport_irq
, inport_interrupt
, 0, "inport", NULL
))
113 outb(INPORT_REG_MODE
, INPORT_CONTROL_PORT
);
114 outb(INPORT_MODE_IRQ
| INPORT_MODE_BASE
, INPORT_DATA_PORT
);
119 static void inport_close(struct input_dev
*dev
)
121 outb(INPORT_REG_MODE
, INPORT_CONTROL_PORT
);
122 outb(INPORT_MODE_BASE
, INPORT_DATA_PORT
);
123 free_irq(inport_irq
, NULL
);
126 static int __init
inport_init(void)
128 unsigned char a
, b
, c
;
131 if (!request_region(INPORT_BASE
, INPORT_EXTENT
, "inport")) {
132 printk(KERN_ERR
"inport.c: Can't allocate ports at %#x\n", INPORT_BASE
);
136 a
= inb(INPORT_SIGNATURE_PORT
);
137 b
= inb(INPORT_SIGNATURE_PORT
);
138 c
= inb(INPORT_SIGNATURE_PORT
);
139 if (a
== b
|| a
!= c
) {
140 printk(KERN_INFO
"inport.c: Didn't find InPort mouse at %#x\n", INPORT_BASE
);
142 goto err_release_region
;
145 inport_dev
= input_allocate_device();
147 printk(KERN_ERR
"inport.c: Not enough memory for input device\n");
149 goto err_release_region
;
152 inport_dev
->name
= INPORT_NAME
;
153 inport_dev
->phys
= "isa023c/input0";
154 inport_dev
->id
.bustype
= BUS_ISA
;
155 inport_dev
->id
.vendor
= INPORT_VENDOR
;
156 inport_dev
->id
.product
= 0x0001;
157 inport_dev
->id
.version
= 0x0100;
159 inport_dev
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_REL
);
160 inport_dev
->keybit
[BIT_WORD(BTN_LEFT
)] = BIT_MASK(BTN_LEFT
) |
161 BIT_MASK(BTN_MIDDLE
) | BIT_MASK(BTN_RIGHT
);
162 inport_dev
->relbit
[0] = BIT_MASK(REL_X
) | BIT_MASK(REL_Y
);
164 inport_dev
->open
= inport_open
;
165 inport_dev
->close
= inport_close
;
167 outb(INPORT_RESET
, INPORT_CONTROL_PORT
);
168 outb(INPORT_REG_MODE
, INPORT_CONTROL_PORT
);
169 outb(INPORT_MODE_BASE
, INPORT_DATA_PORT
);
171 err
= input_register_device(inport_dev
);
178 input_free_device(inport_dev
);
180 release_region(INPORT_BASE
, INPORT_EXTENT
);
185 static void __exit
inport_exit(void)
187 input_unregister_device(inport_dev
);
188 release_region(INPORT_BASE
, INPORT_EXTENT
);
191 module_init(inport_init
);
192 module_exit(inport_exit
);