Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  *  Copyright (c) 1999-2001 Vojtech Pavlik
0004  *
0005  *  Based on the work of:
0006  *  Teemu Rantanen      Derrick Cole
0007  *  Peter Cervasio      Christoph Niemann
0008  *  Philip Blundell     Russell King
0009  *  Bob Harris
0010  */
0011 
0012 /*
0013  * Inport (ATI XL and Microsoft) busmouse driver for Linux
0014  */
0015 
0016 /*
0017  */
0018 
0019 #include <linux/module.h>
0020 #include <linux/ioport.h>
0021 #include <linux/init.h>
0022 #include <linux/interrupt.h>
0023 #include <linux/input.h>
0024 
0025 #include <asm/io.h>
0026 #include <asm/irq.h>
0027 
0028 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
0029 MODULE_DESCRIPTION("Inport (ATI XL and Microsoft) busmouse driver");
0030 MODULE_LICENSE("GPL");
0031 
0032 #define INPORT_BASE     0x23c
0033 #define INPORT_EXTENT       4
0034 
0035 #define INPORT_CONTROL_PORT INPORT_BASE + 0
0036 #define INPORT_DATA_PORT    INPORT_BASE + 1
0037 #define INPORT_SIGNATURE_PORT   INPORT_BASE + 2
0038 
0039 #define INPORT_REG_BTNS 0x00
0040 #define INPORT_REG_X        0x01
0041 #define INPORT_REG_Y        0x02
0042 #define INPORT_REG_MODE     0x07
0043 #define INPORT_RESET        0x80
0044 
0045 #ifdef CONFIG_MOUSE_ATIXL
0046 #define INPORT_NAME     "ATI XL Mouse"
0047 #define INPORT_VENDOR       0x0002
0048 #define INPORT_SPEED_30HZ   0x01
0049 #define INPORT_SPEED_50HZ   0x02
0050 #define INPORT_SPEED_100HZ  0x03
0051 #define INPORT_SPEED_200HZ  0x04
0052 #define INPORT_MODE_BASE    INPORT_SPEED_100HZ
0053 #define INPORT_MODE_IRQ     0x08
0054 #else
0055 #define INPORT_NAME     "Microsoft InPort Mouse"
0056 #define INPORT_VENDOR       0x0001
0057 #define INPORT_MODE_BASE    0x10
0058 #define INPORT_MODE_IRQ     0x01
0059 #endif
0060 #define INPORT_MODE_HOLD    0x20
0061 
0062 #define INPORT_IRQ      5
0063 
0064 static int inport_irq = INPORT_IRQ;
0065 module_param_hw_named(irq, inport_irq, uint, irq, 0);
0066 MODULE_PARM_DESC(irq, "IRQ number (5=default)");
0067 
0068 static struct input_dev *inport_dev;
0069 
0070 static irqreturn_t inport_interrupt(int irq, void *dev_id)
0071 {
0072     unsigned char buttons;
0073 
0074     outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
0075     outb(INPORT_MODE_HOLD | INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT);
0076 
0077     outb(INPORT_REG_X, INPORT_CONTROL_PORT);
0078     input_report_rel(inport_dev, REL_X, inb(INPORT_DATA_PORT));
0079 
0080     outb(INPORT_REG_Y, INPORT_CONTROL_PORT);
0081     input_report_rel(inport_dev, REL_Y, inb(INPORT_DATA_PORT));
0082 
0083     outb(INPORT_REG_BTNS, INPORT_CONTROL_PORT);
0084     buttons = inb(INPORT_DATA_PORT);
0085 
0086     input_report_key(inport_dev, BTN_MIDDLE, buttons & 1);
0087     input_report_key(inport_dev, BTN_LEFT,   buttons & 2);
0088     input_report_key(inport_dev, BTN_RIGHT,  buttons & 4);
0089 
0090     outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
0091     outb(INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT);
0092 
0093     input_sync(inport_dev);
0094     return IRQ_HANDLED;
0095 }
0096 
0097 static int inport_open(struct input_dev *dev)
0098 {
0099     if (request_irq(inport_irq, inport_interrupt, 0, "inport", NULL))
0100         return -EBUSY;
0101     outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
0102     outb(INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT);
0103 
0104     return 0;
0105 }
0106 
0107 static void inport_close(struct input_dev *dev)
0108 {
0109     outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
0110     outb(INPORT_MODE_BASE, INPORT_DATA_PORT);
0111     free_irq(inport_irq, NULL);
0112 }
0113 
0114 static int __init inport_init(void)
0115 {
0116     unsigned char a, b, c;
0117     int err;
0118 
0119     if (!request_region(INPORT_BASE, INPORT_EXTENT, "inport")) {
0120         printk(KERN_ERR "inport.c: Can't allocate ports at %#x\n", INPORT_BASE);
0121         return -EBUSY;
0122     }
0123 
0124     a = inb(INPORT_SIGNATURE_PORT);
0125     b = inb(INPORT_SIGNATURE_PORT);
0126     c = inb(INPORT_SIGNATURE_PORT);
0127     if (a == b || a != c) {
0128         printk(KERN_INFO "inport.c: Didn't find InPort mouse at %#x\n", INPORT_BASE);
0129         err = -ENODEV;
0130         goto err_release_region;
0131     }
0132 
0133     inport_dev = input_allocate_device();
0134     if (!inport_dev) {
0135         printk(KERN_ERR "inport.c: Not enough memory for input device\n");
0136         err = -ENOMEM;
0137         goto err_release_region;
0138     }
0139 
0140     inport_dev->name = INPORT_NAME;
0141     inport_dev->phys = "isa023c/input0";
0142     inport_dev->id.bustype = BUS_ISA;
0143     inport_dev->id.vendor  = INPORT_VENDOR;
0144     inport_dev->id.product = 0x0001;
0145     inport_dev->id.version = 0x0100;
0146 
0147     inport_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
0148     inport_dev->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) |
0149         BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
0150     inport_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
0151 
0152     inport_dev->open  = inport_open;
0153     inport_dev->close = inport_close;
0154 
0155     outb(INPORT_RESET, INPORT_CONTROL_PORT);
0156     outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
0157     outb(INPORT_MODE_BASE, INPORT_DATA_PORT);
0158 
0159     err = input_register_device(inport_dev);
0160     if (err)
0161         goto err_free_dev;
0162 
0163     return 0;
0164 
0165  err_free_dev:
0166     input_free_device(inport_dev);
0167  err_release_region:
0168     release_region(INPORT_BASE, INPORT_EXTENT);
0169 
0170     return err;
0171 }
0172 
0173 static void __exit inport_exit(void)
0174 {
0175     input_unregister_device(inport_dev);
0176     release_region(INPORT_BASE, INPORT_EXTENT);
0177 }
0178 
0179 module_init(inport_init);
0180 module_exit(inport_exit);