treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156
[linux-block.git] / drivers / input / mouse / pc110pad.c
CommitLineData
1a59d1b8 1// SPDX-License-Identifier: GPL-2.0-or-later
1da177e4 2/*
1da177e4
LT
3 * Copyright (c) 2000-2001 Vojtech Pavlik
4 *
5 * Based on the work of:
968ac842 6 * Alan Cox Robin O'Leary
1da177e4
LT
7 */
8
9/*
10 * IBM PC110 touchpad driver for Linux
11 */
12
13/*
1da177e4
LT
14 */
15
16#include <linux/module.h>
17#include <linux/kernel.h>
18#include <linux/errno.h>
19#include <linux/ioport.h>
20#include <linux/input.h>
21#include <linux/init.h>
22#include <linux/interrupt.h>
23#include <linux/pci.h>
41e191e8 24#include <linux/delay.h>
1da177e4
LT
25
26#include <asm/io.h>
27#include <asm/irq.h>
28
29MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
30MODULE_DESCRIPTION("IBM PC110 touchpad driver");
31MODULE_LICENSE("GPL");
32
33#define PC110PAD_OFF 0x30
34#define PC110PAD_ON 0x38
35
36static int pc110pad_irq = 10;
37static int pc110pad_io = 0x15e0;
38
2e5b636b 39static struct input_dev *pc110pad_dev;
1da177e4
LT
40static int pc110pad_data[3];
41static int pc110pad_count;
1da177e4 42
7d12e780 43static irqreturn_t pc110pad_interrupt(int irq, void *ptr)
1da177e4
LT
44{
45 int value = inb_p(pc110pad_io);
46 int handshake = inb_p(pc110pad_io + 2);
47
41e191e8
IM
48 outb(handshake | 1, pc110pad_io + 2);
49 udelay(2);
50 outb(handshake & ~1, pc110pad_io + 2);
51 udelay(2);
1da177e4
LT
52 inb_p(0x64);
53
54 pc110pad_data[pc110pad_count++] = value;
55
56 if (pc110pad_count < 3)
57 return IRQ_HANDLED;
968ac842 58
2e5b636b 59 input_report_key(pc110pad_dev, BTN_TOUCH,
1da177e4 60 pc110pad_data[0] & 0x01);
2e5b636b 61 input_report_abs(pc110pad_dev, ABS_X,
1da177e4 62 pc110pad_data[1] | ((pc110pad_data[0] << 3) & 0x80) | ((pc110pad_data[0] << 1) & 0x100));
2e5b636b 63 input_report_abs(pc110pad_dev, ABS_Y,
1da177e4 64 pc110pad_data[2] | ((pc110pad_data[0] << 4) & 0x80));
2e5b636b 65 input_sync(pc110pad_dev);
1da177e4
LT
66
67 pc110pad_count = 0;
68 return IRQ_HANDLED;
69}
70
71static void pc110pad_close(struct input_dev *dev)
72{
3108d42d 73 outb(PC110PAD_OFF, pc110pad_io + 2);
1da177e4
LT
74}
75
76static int pc110pad_open(struct input_dev *dev)
77{
7d12e780
DH
78 pc110pad_interrupt(0, NULL);
79 pc110pad_interrupt(0, NULL);
80 pc110pad_interrupt(0, NULL);
1da177e4
LT
81 outb(PC110PAD_ON, pc110pad_io + 2);
82 pc110pad_count = 0;
83
84 return 0;
85}
86
87/*
88 * We try to avoid enabling the hardware if it's not
89 * there, but we don't know how to test. But we do know
90 * that the PC110 is not a PCI system. So if we find any
91 * PCI devices in the machine, we don't have a PC110.
92 */
93static int __init pc110pad_init(void)
94{
72155615 95 int err;
1da177e4 96
b0ee0d3e 97 if (!no_pci_devices())
65a2d225 98 return -ENODEV;
1da177e4
LT
99
100 if (!request_region(pc110pad_io, 4, "pc110pad")) {
101 printk(KERN_ERR "pc110pad: I/O area %#x-%#x in use.\n",
102 pc110pad_io, pc110pad_io + 4);
103 return -EBUSY;
104 }
105
106 outb(PC110PAD_OFF, pc110pad_io + 2);
107
2e5b636b 108 if (request_irq(pc110pad_irq, pc110pad_interrupt, 0, "pc110pad", NULL)) {
1da177e4 109 printk(KERN_ERR "pc110pad: Unable to get irq %d.\n", pc110pad_irq);
72155615
DT
110 err = -EBUSY;
111 goto err_release_region;
1da177e4
LT
112 }
113
72155615
DT
114 pc110pad_dev = input_allocate_device();
115 if (!pc110pad_dev) {
2e5b636b 116 printk(KERN_ERR "pc110pad: Not enough memory.\n");
72155615
DT
117 err = -ENOMEM;
118 goto err_free_irq;
2e5b636b 119 }
1da177e4 120
2e5b636b
DT
121 pc110pad_dev->name = "IBM PC110 TouchPad";
122 pc110pad_dev->phys = "isa15e0/input0";
123 pc110pad_dev->id.bustype = BUS_ISA;
124 pc110pad_dev->id.vendor = 0x0003;
125 pc110pad_dev->id.product = 0x0001;
126 pc110pad_dev->id.version = 0x0100;
968ac842 127
7b19ada2
JS
128 pc110pad_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
129 pc110pad_dev->absbit[0] = BIT_MASK(ABS_X) | BIT_MASK(ABS_Y);
130 pc110pad_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
1da177e4 131
987a6c02
DM
132 input_abs_set_max(pc110pad_dev, ABS_X, 0x1ff);
133 input_abs_set_max(pc110pad_dev, ABS_Y, 0x0ff);
1da177e4 134
2e5b636b
DT
135 pc110pad_dev->open = pc110pad_open;
136 pc110pad_dev->close = pc110pad_close;
1da177e4 137
72155615
DT
138 err = input_register_device(pc110pad_dev);
139 if (err)
140 goto err_free_dev;
968ac842 141
1da177e4 142 return 0;
72155615
DT
143
144 err_free_dev:
145 input_free_device(pc110pad_dev);
146 err_free_irq:
147 free_irq(pc110pad_irq, NULL);
148 err_release_region:
149 release_region(pc110pad_io, 4);
150
151 return err;
1da177e4 152}
968ac842 153
1da177e4
LT
154static void __exit pc110pad_exit(void)
155{
1da177e4 156 outb(PC110PAD_OFF, pc110pad_io + 2);
1da177e4 157 free_irq(pc110pad_irq, NULL);
2e5b636b 158 input_unregister_device(pc110pad_dev);
1da177e4
LT
159 release_region(pc110pad_io, 4);
160}
161
162module_init(pc110pad_init);
163module_exit(pc110pad_exit);