| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | *  Copyright (c) 1999-2001 Vojtech Pavlik | 
|  | 3 | * | 
|  | 4 | *  Based on the work of: | 
|  | 5 | *	Teemu Rantanen		Derrick Cole | 
|  | 6 | *	Peter Cervasio		Christoph Niemann | 
|  | 7 | *	Philip Blundell		Russell King | 
|  | 8 | *	Bob Harris | 
|  | 9 | */ | 
|  | 10 |  | 
|  | 11 | /* | 
|  | 12 | * Inport (ATI XL and Microsoft) busmouse driver for Linux | 
|  | 13 | */ | 
|  | 14 |  | 
|  | 15 | /* | 
|  | 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 | 
| Dmitry Torokhov | 968ac84 | 2005-05-29 02:28:29 -0500 | [diff] [blame] | 18 | * the Free Software Foundation; either version 2 of the License, or | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | * (at your option) any later version. | 
| Dmitry Torokhov | 968ac84 | 2005-05-29 02:28:29 -0500 | [diff] [blame] | 20 | * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. | 
| Dmitry Torokhov | 968ac84 | 2005-05-29 02:28:29 -0500 | [diff] [blame] | 25 | * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | 
| Dmitry Torokhov | 968ac84 | 2005-05-29 02:28:29 -0500 | [diff] [blame] | 29 | * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | * Should you need to contact me, the author, you can do so either by | 
|  | 31 | * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail: | 
|  | 32 | * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic | 
|  | 33 | */ | 
|  | 34 |  | 
|  | 35 | #include <linux/module.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <linux/ioport.h> | 
|  | 37 | #include <linux/init.h> | 
|  | 38 | #include <linux/interrupt.h> | 
|  | 39 | #include <linux/input.h> | 
|  | 40 |  | 
|  | 41 | #include <asm/io.h> | 
|  | 42 | #include <asm/irq.h> | 
|  | 43 |  | 
|  | 44 | MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); | 
|  | 45 | MODULE_DESCRIPTION("Inport (ATI XL and Microsoft) busmouse driver"); | 
|  | 46 | MODULE_LICENSE("GPL"); | 
|  | 47 |  | 
|  | 48 | #define INPORT_BASE		0x23c | 
|  | 49 | #define INPORT_EXTENT		4 | 
|  | 50 |  | 
|  | 51 | #define INPORT_CONTROL_PORT	INPORT_BASE + 0 | 
|  | 52 | #define INPORT_DATA_PORT	INPORT_BASE + 1 | 
|  | 53 | #define INPORT_SIGNATURE_PORT	INPORT_BASE + 2 | 
|  | 54 |  | 
|  | 55 | #define INPORT_REG_BTNS	0x00 | 
|  | 56 | #define INPORT_REG_X		0x01 | 
|  | 57 | #define INPORT_REG_Y		0x02 | 
|  | 58 | #define INPORT_REG_MODE		0x07 | 
|  | 59 | #define INPORT_RESET		0x80 | 
|  | 60 |  | 
| Robert P. J. Day | 8370a64 | 2007-02-10 01:29:31 -0500 | [diff] [blame] | 61 | #ifdef CONFIG_MOUSE_ATIXL | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | #define INPORT_NAME		"ATI XL Mouse" | 
|  | 63 | #define INPORT_VENDOR		0x0002 | 
|  | 64 | #define INPORT_SPEED_30HZ	0x01 | 
|  | 65 | #define INPORT_SPEED_50HZ	0x02 | 
|  | 66 | #define INPORT_SPEED_100HZ	0x03 | 
|  | 67 | #define INPORT_SPEED_200HZ	0x04 | 
|  | 68 | #define INPORT_MODE_BASE	INPORT_SPEED_100HZ | 
|  | 69 | #define INPORT_MODE_IRQ		0x08 | 
|  | 70 | #else | 
|  | 71 | #define INPORT_NAME		"Microsoft InPort Mouse" | 
|  | 72 | #define INPORT_VENDOR		0x0001 | 
|  | 73 | #define INPORT_MODE_BASE	0x10 | 
|  | 74 | #define INPORT_MODE_IRQ		0x01 | 
|  | 75 | #endif | 
|  | 76 | #define INPORT_MODE_HOLD	0x20 | 
|  | 77 |  | 
|  | 78 | #define INPORT_IRQ		5 | 
|  | 79 |  | 
|  | 80 | static int inport_irq = INPORT_IRQ; | 
|  | 81 | module_param_named(irq, inport_irq, uint, 0); | 
|  | 82 | MODULE_PARM_DESC(irq, "IRQ number (5=default)"); | 
|  | 83 |  | 
| Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 84 | static struct input_dev *inport_dev; | 
|  | 85 |  | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 86 | static irqreturn_t inport_interrupt(int irq, void *dev_id) | 
| Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 87 | { | 
|  | 88 | unsigned char buttons; | 
|  | 89 |  | 
|  | 90 | outb(INPORT_REG_MODE, INPORT_CONTROL_PORT); | 
|  | 91 | outb(INPORT_MODE_HOLD | INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT); | 
|  | 92 |  | 
| Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 93 | outb(INPORT_REG_X, INPORT_CONTROL_PORT); | 
|  | 94 | input_report_rel(inport_dev, REL_X, inb(INPORT_DATA_PORT)); | 
|  | 95 |  | 
|  | 96 | outb(INPORT_REG_Y, INPORT_CONTROL_PORT); | 
|  | 97 | input_report_rel(inport_dev, REL_Y, inb(INPORT_DATA_PORT)); | 
|  | 98 |  | 
|  | 99 | outb(INPORT_REG_BTNS, INPORT_CONTROL_PORT); | 
|  | 100 | buttons = inb(INPORT_DATA_PORT); | 
|  | 101 |  | 
|  | 102 | input_report_key(inport_dev, BTN_MIDDLE, buttons & 1); | 
|  | 103 | input_report_key(inport_dev, BTN_LEFT,   buttons & 2); | 
|  | 104 | input_report_key(inport_dev, BTN_RIGHT,  buttons & 4); | 
|  | 105 |  | 
|  | 106 | outb(INPORT_REG_MODE, INPORT_CONTROL_PORT); | 
|  | 107 | outb(INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT); | 
|  | 108 |  | 
|  | 109 | input_sync(inport_dev); | 
|  | 110 | return IRQ_HANDLED; | 
|  | 111 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 |  | 
|  | 113 | static int inport_open(struct input_dev *dev) | 
|  | 114 | { | 
| Dmitry Torokhov | 3108d42 | 2005-05-29 02:29:30 -0500 | [diff] [blame] | 115 | if (request_irq(inport_irq, inport_interrupt, 0, "inport", NULL)) | 
|  | 116 | return -EBUSY; | 
|  | 117 | outb(INPORT_REG_MODE, INPORT_CONTROL_PORT); | 
|  | 118 | outb(INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 |  | 
|  | 120 | return 0; | 
|  | 121 | } | 
|  | 122 |  | 
|  | 123 | static void inport_close(struct input_dev *dev) | 
|  | 124 | { | 
| Dmitry Torokhov | 3108d42 | 2005-05-29 02:29:30 -0500 | [diff] [blame] | 125 | outb(INPORT_REG_MODE, INPORT_CONTROL_PORT); | 
|  | 126 | outb(INPORT_MODE_BASE, INPORT_DATA_PORT); | 
|  | 127 | free_irq(inport_irq, NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | } | 
|  | 129 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | static int __init inport_init(void) | 
|  | 131 | { | 
| Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 132 | unsigned char a, b, c; | 
| Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 133 | int err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 |  | 
|  | 135 | if (!request_region(INPORT_BASE, INPORT_EXTENT, "inport")) { | 
|  | 136 | printk(KERN_ERR "inport.c: Can't allocate ports at %#x\n", INPORT_BASE); | 
|  | 137 | return -EBUSY; | 
|  | 138 | } | 
|  | 139 |  | 
|  | 140 | a = inb(INPORT_SIGNATURE_PORT); | 
|  | 141 | b = inb(INPORT_SIGNATURE_PORT); | 
|  | 142 | c = inb(INPORT_SIGNATURE_PORT); | 
| Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 143 | if (a == b || a != c) { | 
| Helge Deller | 2a0f9c4 | 2007-11-01 22:19:15 -0400 | [diff] [blame] | 144 | printk(KERN_INFO "inport.c: Didn't find InPort mouse at %#x\n", INPORT_BASE); | 
| Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 145 | err = -ENODEV; | 
|  | 146 | goto err_release_region; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | } | 
|  | 148 |  | 
| Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 149 | inport_dev = input_allocate_device(); | 
|  | 150 | if (!inport_dev) { | 
| Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 151 | printk(KERN_ERR "inport.c: Not enough memory for input device\n"); | 
| Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 152 | err = -ENOMEM; | 
|  | 153 | goto err_release_region; | 
| Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 154 | } | 
|  | 155 |  | 
|  | 156 | inport_dev->name = INPORT_NAME; | 
|  | 157 | inport_dev->phys = "isa023c/input0"; | 
|  | 158 | inport_dev->id.bustype = BUS_ISA; | 
|  | 159 | inport_dev->id.vendor  = INPORT_VENDOR; | 
|  | 160 | inport_dev->id.product = 0x0001; | 
|  | 161 | inport_dev->id.version = 0x0100; | 
|  | 162 |  | 
| Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 163 | inport_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); | 
|  | 164 | inport_dev->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) | | 
|  | 165 | BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT); | 
|  | 166 | inport_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y); | 
| Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 167 |  | 
|  | 168 | inport_dev->open  = inport_open; | 
|  | 169 | inport_dev->close = inport_close; | 
|  | 170 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | outb(INPORT_RESET, INPORT_CONTROL_PORT); | 
|  | 172 | outb(INPORT_REG_MODE, INPORT_CONTROL_PORT); | 
|  | 173 | outb(INPORT_MODE_BASE, INPORT_DATA_PORT); | 
|  | 174 |  | 
| Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 175 | err = input_register_device(inport_dev); | 
|  | 176 | if (err) | 
|  | 177 | goto err_free_dev; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 |  | 
|  | 179 | return 0; | 
| Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 180 |  | 
|  | 181 | err_free_dev: | 
|  | 182 | input_free_device(inport_dev); | 
|  | 183 | err_release_region: | 
|  | 184 | release_region(INPORT_BASE, INPORT_EXTENT); | 
|  | 185 |  | 
|  | 186 | return err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | } | 
|  | 188 |  | 
|  | 189 | static void __exit inport_exit(void) | 
|  | 190 | { | 
| Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 191 | input_unregister_device(inport_dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | release_region(INPORT_BASE, INPORT_EXTENT); | 
|  | 193 | } | 
|  | 194 |  | 
|  | 195 | module_init(inport_init); | 
|  | 196 | module_exit(inport_exit); |