1 /* 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 18 * the Free Software Foundation; either version 2 of the License, or 19 * (at your option) any later version. 20 * 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. 25 * 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 29 */ 30 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> 36 37 #include <asm/io.h> 38 #include <asm/irq.h> 39 40 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); 41 MODULE_DESCRIPTION("Inport (ATI XL and Microsoft) busmouse driver"); 42 MODULE_LICENSE("GPL"); 43 44 #define INPORT_BASE 0x23c 45 #define INPORT_EXTENT 4 46 47 #define INPORT_CONTROL_PORT INPORT_BASE + 0 48 #define INPORT_DATA_PORT INPORT_BASE + 1 49 #define INPORT_SIGNATURE_PORT INPORT_BASE + 2 50 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 56 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 66 #else 67 #define INPORT_NAME "Microsoft InPort Mouse" 68 #define INPORT_VENDOR 0x0001 69 #define INPORT_MODE_BASE 0x10 70 #define INPORT_MODE_IRQ 0x01 71 #endif 72 #define INPORT_MODE_HOLD 0x20 73 74 #define INPORT_IRQ 5 75 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)"); 79 80 static struct input_dev *inport_dev; 81 82 static irqreturn_t inport_interrupt(int irq, void *dev_id) 83 { 84 unsigned char buttons; 85 86 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT); 87 outb(INPORT_MODE_HOLD | INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT); 88 89 outb(INPORT_REG_X, INPORT_CONTROL_PORT); 90 input_report_rel(inport_dev, REL_X, inb(INPORT_DATA_PORT)); 91 92 outb(INPORT_REG_Y, INPORT_CONTROL_PORT); 93 input_report_rel(inport_dev, REL_Y, inb(INPORT_DATA_PORT)); 94 95 outb(INPORT_REG_BTNS, INPORT_CONTROL_PORT); 96 buttons = inb(INPORT_DATA_PORT); 97 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); 101 102 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT); 103 outb(INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT); 104 105 input_sync(inport_dev); 106 return IRQ_HANDLED; 107 } 108 109 static int inport_open(struct input_dev *dev) 110 { 111 if (request_irq(inport_irq, inport_interrupt, 0, "inport", NULL)) 112 return -EBUSY; 113 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT); 114 outb(INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT); 115 116 return 0; 117 } 118 119 static void inport_close(struct input_dev *dev) 120 { 121 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT); 122 outb(INPORT_MODE_BASE, INPORT_DATA_PORT); 123 free_irq(inport_irq, NULL); 124 } 125 126 static int __init inport_init(void) 127 { 128 unsigned char a, b, c; 129 int err; 130 131 if (!request_region(INPORT_BASE, INPORT_EXTENT, "inport")) { 132 printk(KERN_ERR "inport.c: Can't allocate ports at %#x\n", INPORT_BASE); 133 return -EBUSY; 134 } 135 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); 141 err = -ENODEV; 142 goto err_release_region; 143 } 144 145 inport_dev = input_allocate_device(); 146 if (!inport_dev) { 147 printk(KERN_ERR "inport.c: Not enough memory for input device\n"); 148 err = -ENOMEM; 149 goto err_release_region; 150 } 151 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; 158 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); 163 164 inport_dev->open = inport_open; 165 inport_dev->close = inport_close; 166 167 outb(INPORT_RESET, INPORT_CONTROL_PORT); 168 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT); 169 outb(INPORT_MODE_BASE, INPORT_DATA_PORT); 170 171 err = input_register_device(inport_dev); 172 if (err) 173 goto err_free_dev; 174 175 return 0; 176 177 err_free_dev: 178 input_free_device(inport_dev); 179 err_release_region: 180 release_region(INPORT_BASE, INPORT_EXTENT); 181 182 return err; 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