1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) 1999-2001 Vojtech Pavlik
5 * Based on the work of:
6 * Teemu Rantanen Derrick Cole
7 * Peter Cervasio Christoph Niemann
8 * Philip Blundell Russell King
13 * Inport (ATI XL and Microsoft) busmouse driver for Linux
19 #include <linux/module.h>
20 #include <linux/ioport.h>
21 #include <linux/init.h>
22 #include <linux/interrupt.h>
23 #include <linux/input.h>
28 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
29 MODULE_DESCRIPTION("Inport (ATI XL and Microsoft) busmouse driver");
30 MODULE_LICENSE("GPL");
32 #define INPORT_BASE 0x23c
33 #define INPORT_EXTENT 4
35 #define INPORT_CONTROL_PORT INPORT_BASE + 0
36 #define INPORT_DATA_PORT INPORT_BASE + 1
37 #define INPORT_SIGNATURE_PORT INPORT_BASE + 2
39 #define INPORT_REG_BTNS 0x00
40 #define INPORT_REG_X 0x01
41 #define INPORT_REG_Y 0x02
42 #define INPORT_REG_MODE 0x07
43 #define INPORT_RESET 0x80
45 #ifdef CONFIG_MOUSE_ATIXL
46 #define INPORT_NAME "ATI XL Mouse"
47 #define INPORT_VENDOR 0x0002
48 #define INPORT_SPEED_30HZ 0x01
49 #define INPORT_SPEED_50HZ 0x02
50 #define INPORT_SPEED_100HZ 0x03
51 #define INPORT_SPEED_200HZ 0x04
52 #define INPORT_MODE_BASE INPORT_SPEED_100HZ
53 #define INPORT_MODE_IRQ 0x08
55 #define INPORT_NAME "Microsoft InPort Mouse"
56 #define INPORT_VENDOR 0x0001
57 #define INPORT_MODE_BASE 0x10
58 #define INPORT_MODE_IRQ 0x01
60 #define INPORT_MODE_HOLD 0x20
64 static int inport_irq
= INPORT_IRQ
;
65 module_param_hw_named(irq
, inport_irq
, uint
, irq
, 0);
66 MODULE_PARM_DESC(irq
, "IRQ number (5=default)");
68 static struct input_dev
*inport_dev
;
70 static irqreturn_t
inport_interrupt(int irq
, void *dev_id
)
72 unsigned char buttons
;
74 outb(INPORT_REG_MODE
, INPORT_CONTROL_PORT
);
75 outb(INPORT_MODE_HOLD
| INPORT_MODE_IRQ
| INPORT_MODE_BASE
, INPORT_DATA_PORT
);
77 outb(INPORT_REG_X
, INPORT_CONTROL_PORT
);
78 input_report_rel(inport_dev
, REL_X
, inb(INPORT_DATA_PORT
));
80 outb(INPORT_REG_Y
, INPORT_CONTROL_PORT
);
81 input_report_rel(inport_dev
, REL_Y
, inb(INPORT_DATA_PORT
));
83 outb(INPORT_REG_BTNS
, INPORT_CONTROL_PORT
);
84 buttons
= inb(INPORT_DATA_PORT
);
86 input_report_key(inport_dev
, BTN_MIDDLE
, buttons
& 1);
87 input_report_key(inport_dev
, BTN_LEFT
, buttons
& 2);
88 input_report_key(inport_dev
, BTN_RIGHT
, buttons
& 4);
90 outb(INPORT_REG_MODE
, INPORT_CONTROL_PORT
);
91 outb(INPORT_MODE_IRQ
| INPORT_MODE_BASE
, INPORT_DATA_PORT
);
93 input_sync(inport_dev
);
97 static int inport_open(struct input_dev
*dev
)
99 if (request_irq(inport_irq
, inport_interrupt
, 0, "inport", NULL
))
101 outb(INPORT_REG_MODE
, INPORT_CONTROL_PORT
);
102 outb(INPORT_MODE_IRQ
| INPORT_MODE_BASE
, INPORT_DATA_PORT
);
107 static void inport_close(struct input_dev
*dev
)
109 outb(INPORT_REG_MODE
, INPORT_CONTROL_PORT
);
110 outb(INPORT_MODE_BASE
, INPORT_DATA_PORT
);
111 free_irq(inport_irq
, NULL
);
114 static int __init
inport_init(void)
116 unsigned char a
, b
, c
;
119 if (!request_region(INPORT_BASE
, INPORT_EXTENT
, "inport")) {
120 printk(KERN_ERR
"inport.c: Can't allocate ports at %#x\n", INPORT_BASE
);
124 a
= inb(INPORT_SIGNATURE_PORT
);
125 b
= inb(INPORT_SIGNATURE_PORT
);
126 c
= inb(INPORT_SIGNATURE_PORT
);
127 if (a
== b
|| a
!= c
) {
128 printk(KERN_INFO
"inport.c: Didn't find InPort mouse at %#x\n", INPORT_BASE
);
130 goto err_release_region
;
133 inport_dev
= input_allocate_device();
135 printk(KERN_ERR
"inport.c: Not enough memory for input device\n");
137 goto err_release_region
;
140 inport_dev
->name
= INPORT_NAME
;
141 inport_dev
->phys
= "isa023c/input0";
142 inport_dev
->id
.bustype
= BUS_ISA
;
143 inport_dev
->id
.vendor
= INPORT_VENDOR
;
144 inport_dev
->id
.product
= 0x0001;
145 inport_dev
->id
.version
= 0x0100;
147 inport_dev
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_REL
);
148 inport_dev
->keybit
[BIT_WORD(BTN_LEFT
)] = BIT_MASK(BTN_LEFT
) |
149 BIT_MASK(BTN_MIDDLE
) | BIT_MASK(BTN_RIGHT
);
150 inport_dev
->relbit
[0] = BIT_MASK(REL_X
) | BIT_MASK(REL_Y
);
152 inport_dev
->open
= inport_open
;
153 inport_dev
->close
= inport_close
;
155 outb(INPORT_RESET
, INPORT_CONTROL_PORT
);
156 outb(INPORT_REG_MODE
, INPORT_CONTROL_PORT
);
157 outb(INPORT_MODE_BASE
, INPORT_DATA_PORT
);
159 err
= input_register_device(inport_dev
);
166 input_free_device(inport_dev
);
168 release_region(INPORT_BASE
, INPORT_EXTENT
);
173 static void __exit
inport_exit(void)
175 input_unregister_device(inport_dev
);
176 release_region(INPORT_BASE
, INPORT_EXTENT
);
179 module_init(inport_init
);
180 module_exit(inport_exit
);