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