Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  *  Copyright (c) 2000-2001 Vojtech Pavlik
0004  *
0005  *  Based on the work of:
0006  *  Alan Cox    Robin O'Leary
0007  */
0008 
0009 /*
0010  * IBM PC110 touchpad driver for Linux
0011  */
0012 
0013 /*
0014  */
0015 
0016 #include <linux/module.h>
0017 #include <linux/kernel.h>
0018 #include <linux/errno.h>
0019 #include <linux/ioport.h>
0020 #include <linux/input.h>
0021 #include <linux/init.h>
0022 #include <linux/interrupt.h>
0023 #include <linux/pci.h>
0024 #include <linux/delay.h>
0025 
0026 #include <asm/io.h>
0027 #include <asm/irq.h>
0028 
0029 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
0030 MODULE_DESCRIPTION("IBM PC110 touchpad driver");
0031 MODULE_LICENSE("GPL");
0032 
0033 #define PC110PAD_OFF    0x30
0034 #define PC110PAD_ON 0x38
0035 
0036 static int pc110pad_irq = 10;
0037 static int pc110pad_io = 0x15e0;
0038 
0039 static struct input_dev *pc110pad_dev;
0040 static int pc110pad_data[3];
0041 static int pc110pad_count;
0042 
0043 static irqreturn_t pc110pad_interrupt(int irq, void *ptr)
0044 {
0045     int value     = inb_p(pc110pad_io);
0046     int handshake = inb_p(pc110pad_io + 2);
0047 
0048     outb(handshake |  1, pc110pad_io + 2);
0049     udelay(2);
0050     outb(handshake & ~1, pc110pad_io + 2);
0051     udelay(2);
0052     inb_p(0x64);
0053 
0054     pc110pad_data[pc110pad_count++] = value;
0055 
0056     if (pc110pad_count < 3)
0057         return IRQ_HANDLED;
0058 
0059     input_report_key(pc110pad_dev, BTN_TOUCH,
0060         pc110pad_data[0] & 0x01);
0061     input_report_abs(pc110pad_dev, ABS_X,
0062         pc110pad_data[1] | ((pc110pad_data[0] << 3) & 0x80) | ((pc110pad_data[0] << 1) & 0x100));
0063     input_report_abs(pc110pad_dev, ABS_Y,
0064         pc110pad_data[2] | ((pc110pad_data[0] << 4) & 0x80));
0065     input_sync(pc110pad_dev);
0066 
0067     pc110pad_count = 0;
0068     return IRQ_HANDLED;
0069 }
0070 
0071 static void pc110pad_close(struct input_dev *dev)
0072 {
0073     outb(PC110PAD_OFF, pc110pad_io + 2);
0074 }
0075 
0076 static int pc110pad_open(struct input_dev *dev)
0077 {
0078     pc110pad_interrupt(0, NULL);
0079     pc110pad_interrupt(0, NULL);
0080     pc110pad_interrupt(0, NULL);
0081     outb(PC110PAD_ON, pc110pad_io + 2);
0082     pc110pad_count = 0;
0083 
0084     return 0;
0085 }
0086 
0087 /*
0088  * We try to avoid enabling the hardware if it's not
0089  * there, but we don't know how to test. But we do know
0090  * that the PC110 is not a PCI system. So if we find any
0091  * PCI devices in the machine, we don't have a PC110.
0092  */
0093 static int __init pc110pad_init(void)
0094 {
0095     int err;
0096 
0097     if (!no_pci_devices())
0098         return -ENODEV;
0099 
0100     if (!request_region(pc110pad_io, 4, "pc110pad")) {
0101         printk(KERN_ERR "pc110pad: I/O area %#x-%#x in use.\n",
0102                 pc110pad_io, pc110pad_io + 4);
0103         return -EBUSY;
0104     }
0105 
0106     outb(PC110PAD_OFF, pc110pad_io + 2);
0107 
0108     if (request_irq(pc110pad_irq, pc110pad_interrupt, 0, "pc110pad", NULL)) {
0109         printk(KERN_ERR "pc110pad: Unable to get irq %d.\n", pc110pad_irq);
0110         err = -EBUSY;
0111         goto err_release_region;
0112     }
0113 
0114     pc110pad_dev = input_allocate_device();
0115     if (!pc110pad_dev) {
0116         printk(KERN_ERR "pc110pad: Not enough memory.\n");
0117         err = -ENOMEM;
0118         goto err_free_irq;
0119     }
0120 
0121     pc110pad_dev->name = "IBM PC110 TouchPad";
0122     pc110pad_dev->phys = "isa15e0/input0";
0123     pc110pad_dev->id.bustype = BUS_ISA;
0124     pc110pad_dev->id.vendor = 0x0003;
0125     pc110pad_dev->id.product = 0x0001;
0126     pc110pad_dev->id.version = 0x0100;
0127 
0128     pc110pad_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
0129     pc110pad_dev->absbit[0] = BIT_MASK(ABS_X) | BIT_MASK(ABS_Y);
0130     pc110pad_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
0131 
0132     input_abs_set_max(pc110pad_dev, ABS_X, 0x1ff);
0133     input_abs_set_max(pc110pad_dev, ABS_Y, 0x0ff);
0134 
0135     pc110pad_dev->open = pc110pad_open;
0136     pc110pad_dev->close = pc110pad_close;
0137 
0138     err = input_register_device(pc110pad_dev);
0139     if (err)
0140         goto err_free_dev;
0141 
0142     return 0;
0143 
0144  err_free_dev:
0145     input_free_device(pc110pad_dev);
0146  err_free_irq:
0147     free_irq(pc110pad_irq, NULL);
0148  err_release_region:
0149     release_region(pc110pad_io, 4);
0150 
0151     return err;
0152 }
0153 
0154 static void __exit pc110pad_exit(void)
0155 {
0156     outb(PC110PAD_OFF, pc110pad_io + 2);
0157     free_irq(pc110pad_irq, NULL);
0158     input_unregister_device(pc110pad_dev);
0159     release_region(pc110pad_io, 4);
0160 }
0161 
0162 module_init(pc110pad_init);
0163 module_exit(pc110pad_exit);