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 | * James Banks Matthew Dillon |
| 6 | * David Giller Nathan Laredo |
| 7 | * Linus Torvalds Johan Myreen |
| 8 | * Cliff Matthews Philip Blundell |
| 9 | * Russell King |
| 10 | */ |
| 11 | |
| 12 | /* |
| 13 | * Logitech Bus Mouse Driver for Linux |
| 14 | */ |
| 15 | |
| 16 | /* |
| 17 | * This program is free software; you can redistribute it and/or modify |
| 18 | * 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] | 19 | * the Free Software Foundation; either version 2 of the License, or |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | * (at your option) any later version. |
Dmitry Torokhov | 968ac84 | 2005-05-29 02:28:29 -0500 | [diff] [blame] | 21 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | * This program is distributed in the hope that it will be useful, |
| 23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 25 | * GNU General Public License for more details. |
Dmitry Torokhov | 968ac84 | 2005-05-29 02:28:29 -0500 | [diff] [blame] | 26 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | * You should have received a copy of the GNU General Public License |
| 28 | * along with this program; if not, write to the Free Software |
| 29 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Dmitry Torokhov | 968ac84 | 2005-05-29 02:28:29 -0500 | [diff] [blame] | 30 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | * Should you need to contact me, the author, you can do so either by |
| 32 | * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail: |
| 33 | * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic |
| 34 | */ |
| 35 | |
| 36 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <linux/delay.h> |
| 38 | #include <linux/ioport.h> |
| 39 | #include <linux/init.h> |
| 40 | #include <linux/input.h> |
| 41 | #include <linux/interrupt.h> |
| 42 | |
| 43 | #include <asm/io.h> |
| 44 | #include <asm/irq.h> |
| 45 | |
| 46 | MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); |
| 47 | MODULE_DESCRIPTION("Logitech busmouse driver"); |
| 48 | MODULE_LICENSE("GPL"); |
| 49 | |
| 50 | #define LOGIBM_BASE 0x23c |
| 51 | #define LOGIBM_EXTENT 4 |
| 52 | |
| 53 | #define LOGIBM_DATA_PORT LOGIBM_BASE + 0 |
| 54 | #define LOGIBM_SIGNATURE_PORT LOGIBM_BASE + 1 |
| 55 | #define LOGIBM_CONTROL_PORT LOGIBM_BASE + 2 |
| 56 | #define LOGIBM_CONFIG_PORT LOGIBM_BASE + 3 |
| 57 | |
| 58 | #define LOGIBM_ENABLE_IRQ 0x00 |
| 59 | #define LOGIBM_DISABLE_IRQ 0x10 |
| 60 | #define LOGIBM_READ_X_LOW 0x80 |
| 61 | #define LOGIBM_READ_X_HIGH 0xa0 |
| 62 | #define LOGIBM_READ_Y_LOW 0xc0 |
| 63 | #define LOGIBM_READ_Y_HIGH 0xe0 |
| 64 | |
| 65 | #define LOGIBM_DEFAULT_MODE 0x90 |
| 66 | #define LOGIBM_CONFIG_BYTE 0x91 |
| 67 | #define LOGIBM_SIGNATURE_BYTE 0xa5 |
| 68 | |
| 69 | #define LOGIBM_IRQ 5 |
| 70 | |
| 71 | static int logibm_irq = LOGIBM_IRQ; |
| 72 | module_param_named(irq, logibm_irq, uint, 0); |
| 73 | MODULE_PARM_DESC(irq, "IRQ number (5=default)"); |
| 74 | |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 75 | static struct input_dev *logibm_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 77 | static irqreturn_t logibm_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | { |
| 79 | char dx, dy; |
| 80 | unsigned char buttons; |
| 81 | |
| 82 | outb(LOGIBM_READ_X_LOW, LOGIBM_CONTROL_PORT); |
| 83 | dx = (inb(LOGIBM_DATA_PORT) & 0xf); |
| 84 | outb(LOGIBM_READ_X_HIGH, LOGIBM_CONTROL_PORT); |
| 85 | dx |= (inb(LOGIBM_DATA_PORT) & 0xf) << 4; |
| 86 | outb(LOGIBM_READ_Y_LOW, LOGIBM_CONTROL_PORT); |
| 87 | dy = (inb(LOGIBM_DATA_PORT) & 0xf); |
| 88 | outb(LOGIBM_READ_Y_HIGH, LOGIBM_CONTROL_PORT); |
| 89 | buttons = inb(LOGIBM_DATA_PORT); |
| 90 | dy |= (buttons & 0xf) << 4; |
| 91 | buttons = ~buttons >> 5; |
| 92 | |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 93 | input_report_rel(logibm_dev, REL_X, dx); |
| 94 | input_report_rel(logibm_dev, REL_Y, dy); |
| 95 | input_report_key(logibm_dev, BTN_RIGHT, buttons & 1); |
| 96 | input_report_key(logibm_dev, BTN_MIDDLE, buttons & 2); |
| 97 | input_report_key(logibm_dev, BTN_LEFT, buttons & 4); |
| 98 | input_sync(logibm_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
| 100 | outb(LOGIBM_ENABLE_IRQ, LOGIBM_CONTROL_PORT); |
| 101 | return IRQ_HANDLED; |
| 102 | } |
| 103 | |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 104 | static int logibm_open(struct input_dev *dev) |
| 105 | { |
| 106 | if (request_irq(logibm_irq, logibm_interrupt, 0, "logibm", NULL)) { |
| 107 | printk(KERN_ERR "logibm.c: Can't allocate irq %d\n", logibm_irq); |
| 108 | return -EBUSY; |
| 109 | } |
| 110 | outb(LOGIBM_ENABLE_IRQ, LOGIBM_CONTROL_PORT); |
| 111 | return 0; |
| 112 | } |
| 113 | |
| 114 | static void logibm_close(struct input_dev *dev) |
| 115 | { |
| 116 | outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT); |
| 117 | free_irq(logibm_irq, NULL); |
| 118 | } |
| 119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | static int __init logibm_init(void) |
| 121 | { |
Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 122 | int err; |
| 123 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | if (!request_region(LOGIBM_BASE, LOGIBM_EXTENT, "logibm")) { |
| 125 | printk(KERN_ERR "logibm.c: Can't allocate ports at %#x\n", LOGIBM_BASE); |
| 126 | return -EBUSY; |
| 127 | } |
| 128 | |
| 129 | outb(LOGIBM_CONFIG_BYTE, LOGIBM_CONFIG_PORT); |
| 130 | outb(LOGIBM_SIGNATURE_BYTE, LOGIBM_SIGNATURE_PORT); |
| 131 | udelay(100); |
| 132 | |
| 133 | if (inb(LOGIBM_SIGNATURE_PORT) != LOGIBM_SIGNATURE_BYTE) { |
Helge Deller | 2a0f9c4 | 2007-11-01 22:19:15 -0400 | [diff] [blame] | 134 | printk(KERN_INFO "logibm.c: Didn't find Logitech busmouse at %#x\n", LOGIBM_BASE); |
Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 135 | err = -ENODEV; |
| 136 | goto err_release_region; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | outb(LOGIBM_DEFAULT_MODE, LOGIBM_CONFIG_PORT); |
| 140 | outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT); |
| 141 | |
Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 142 | logibm_dev = input_allocate_device(); |
| 143 | if (!logibm_dev) { |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 144 | printk(KERN_ERR "logibm.c: Not enough memory for input device\n"); |
Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 145 | err = -ENOMEM; |
| 146 | goto err_release_region; |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 147 | } |
Dmitry Torokhov | 968ac84 | 2005-05-29 02:28:29 -0500 | [diff] [blame] | 148 | |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 149 | logibm_dev->name = "Logitech bus mouse"; |
| 150 | logibm_dev->phys = "isa023c/input0"; |
| 151 | logibm_dev->id.bustype = BUS_ISA; |
| 152 | logibm_dev->id.vendor = 0x0003; |
| 153 | logibm_dev->id.product = 0x0001; |
| 154 | logibm_dev->id.version = 0x0100; |
| 155 | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 156 | logibm_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); |
| 157 | logibm_dev->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) | |
| 158 | BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT); |
| 159 | logibm_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y); |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 160 | |
| 161 | logibm_dev->open = logibm_open; |
| 162 | logibm_dev->close = logibm_close; |
| 163 | |
Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 164 | err = input_register_device(logibm_dev); |
| 165 | if (err) |
| 166 | goto err_free_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
| 168 | return 0; |
Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 169 | |
| 170 | err_free_dev: |
| 171 | input_free_device(logibm_dev); |
| 172 | err_release_region: |
| 173 | release_region(LOGIBM_BASE, LOGIBM_EXTENT); |
| 174 | |
| 175 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | static void __exit logibm_exit(void) |
| 179 | { |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 180 | input_unregister_device(logibm_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | release_region(LOGIBM_BASE, LOGIBM_EXTENT); |
| 182 | } |
| 183 | |
| 184 | module_init(logibm_init); |
| 185 | module_exit(logibm_exit); |