Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / input / mouse / logibm.c
index 77eb83e..9c7ce38 100644 (file)
 /*
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or 
+ * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- * 
+ *
  * Should you need to contact me, the author, you can do so either by
  * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
  * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
@@ -77,46 +77,7 @@ MODULE_PARM_DESC(irq, "IRQ number (5=default)");
 
 __obsolete_setup("logibm_irq=");
 
-static int logibm_used = 0;
-
-static irqreturn_t logibm_interrupt(int irq, void *dev_id, struct pt_regs *regs);
-
-static int logibm_open(struct input_dev *dev)
-{
-       if (logibm_used++)
-               return 0;
-       if (request_irq(logibm_irq, logibm_interrupt, 0, "logibm", NULL)) {
-               logibm_used--;
-               printk(KERN_ERR "logibm.c: Can't allocate irq %d\n", logibm_irq);
-               return -EBUSY;
-       }
-       outb(LOGIBM_ENABLE_IRQ, LOGIBM_CONTROL_PORT);
-       return 0;
-}
-
-static void logibm_close(struct input_dev *dev)
-{
-       if (--logibm_used)
-               return;
-       outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT);
-       free_irq(logibm_irq, NULL);
-}
-
-static struct input_dev logibm_dev = {
-       .evbit  = { BIT(EV_KEY) | BIT(EV_REL) },
-       .keybit = { [LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT) },
-       .relbit = { BIT(REL_X) | BIT(REL_Y) },
-       .open   = logibm_open,
-       .close  = logibm_close,
-       .name   = "Logitech bus mouse",
-       .phys   = "isa023c/input0",
-       .id     = {
-               .bustype = BUS_ISA,
-               .vendor  = 0x0003,
-               .product = 0x0001,
-               .version = 0x0100,
-       },
-};
+static struct input_dev *logibm_dev;
 
 static irqreturn_t logibm_interrupt(int irq, void *dev_id, struct pt_regs *regs)
 {
@@ -134,18 +95,34 @@ static irqreturn_t logibm_interrupt(int irq, void *dev_id, struct pt_regs *regs)
        dy |= (buttons & 0xf) << 4;
        buttons = ~buttons >> 5;
 
-       input_regs(&logibm_dev, regs);
-       input_report_rel(&logibm_dev, REL_X, dx);
-       input_report_rel(&logibm_dev, REL_Y, dy);
-       input_report_key(&logibm_dev, BTN_RIGHT,  buttons & 1);
-       input_report_key(&logibm_dev, BTN_MIDDLE, buttons & 2);
-       input_report_key(&logibm_dev, BTN_LEFT,   buttons & 4);
-       input_sync(&logibm_dev);
+       input_regs(logibm_dev, regs);
+       input_report_rel(logibm_dev, REL_X, dx);
+       input_report_rel(logibm_dev, REL_Y, dy);
+       input_report_key(logibm_dev, BTN_RIGHT,  buttons & 1);
+       input_report_key(logibm_dev, BTN_MIDDLE, buttons & 2);
+       input_report_key(logibm_dev, BTN_LEFT,   buttons & 4);
+       input_sync(logibm_dev);
 
        outb(LOGIBM_ENABLE_IRQ, LOGIBM_CONTROL_PORT);
        return IRQ_HANDLED;
 }
 
+static int logibm_open(struct input_dev *dev)
+{
+       if (request_irq(logibm_irq, logibm_interrupt, 0, "logibm", NULL)) {
+               printk(KERN_ERR "logibm.c: Can't allocate irq %d\n", logibm_irq);
+               return -EBUSY;
+       }
+       outb(LOGIBM_ENABLE_IRQ, LOGIBM_CONTROL_PORT);
+       return 0;
+}
+
+static void logibm_close(struct input_dev *dev)
+{
+       outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT);
+       free_irq(logibm_irq, NULL);
+}
+
 static int __init logibm_init(void)
 {
        if (!request_region(LOGIBM_BASE, LOGIBM_EXTENT, "logibm")) {
@@ -166,16 +143,34 @@ static int __init logibm_init(void)
        outb(LOGIBM_DEFAULT_MODE, LOGIBM_CONFIG_PORT);
        outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT);
 
-       input_register_device(&logibm_dev);
-       
-       printk(KERN_INFO "input: Logitech bus mouse at %#x irq %d\n", LOGIBM_BASE, logibm_irq);
+       if (!(logibm_dev = input_allocate_device())) {
+               printk(KERN_ERR "logibm.c: Not enough memory for input device\n");
+               release_region(LOGIBM_BASE, LOGIBM_EXTENT);
+               return -ENOMEM;
+       }
+
+       logibm_dev->name = "Logitech bus mouse";
+       logibm_dev->phys = "isa023c/input0";
+       logibm_dev->id.bustype = BUS_ISA;
+       logibm_dev->id.vendor  = 0x0003;
+       logibm_dev->id.product = 0x0001;
+       logibm_dev->id.version = 0x0100;
+
+       logibm_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
+       logibm_dev->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
+       logibm_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
+
+       logibm_dev->open  = logibm_open;
+       logibm_dev->close = logibm_close;
+
+       input_register_device(logibm_dev);
 
        return 0;
 }
 
 static void __exit logibm_exit(void)
 {
-       input_unregister_device(&logibm_dev);
+       input_unregister_device(logibm_dev);
        release_region(LOGIBM_BASE, LOGIBM_EXTENT);
 }