^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * ICS MK712 touchscreen controller driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 1999-2002 Transmeta Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (c) 2005 Rick Koch <n1gp@hotmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (c) 2005 Vojtech Pavlik <vojtech@suse.cz>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * This driver supports the ICS MicroClock MK712 TouchScreen controller,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * found in Gateway AOL Connected Touchpad computers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * Documentation for ICS MK712 can be found at:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * https://www.idt.com/general-parts/mk712-touch-screen-controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * 1999-12-18: original version, Daniel Quinlan
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * 1999-12-19: added anti-jitter code, report pen-up events, fixed mk712_poll
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * to use queue_empty, Nathan Laredo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * 1999-12-20: improved random point rejection, Nathan Laredo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * 2000-01-05: checked in new anti-jitter code, changed mouse protocol, fixed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * queue code, added module options, other fixes, Daniel Quinlan
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * 2002-03-15: Clean up for kernel merge <alan@redhat.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * Fixed multi open race, fixed memory checks, fixed resource
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * allocation, fixed close/powerdown bug, switched to new init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * 2005-01-18: Ported to 2.6 from 2.4.28, Rick Koch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * 2005-02-05: Rewritten for the input layer, Vojtech Pavlik
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) MODULE_AUTHOR("Daniel Quinlan <quinlan@pathname.com>, Vojtech Pavlik <vojtech@suse.cz>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) MODULE_DESCRIPTION("ICS MicroClock MK712 TouchScreen driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static unsigned int mk712_io = 0x260; /* Also 0x200, 0x208, 0x300 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) module_param_hw_named(io, mk712_io, uint, ioport, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) MODULE_PARM_DESC(io, "I/O base address of MK712 touchscreen controller");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) static unsigned int mk712_irq = 10; /* Also 12, 14, 15 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) module_param_hw_named(irq, mk712_irq, uint, irq, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) MODULE_PARM_DESC(irq, "IRQ of MK712 touchscreen controller");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) /* eight 8-bit registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define MK712_STATUS 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define MK712_X 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define MK712_Y 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define MK712_CONTROL 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #define MK712_RATE 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /* status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #define MK712_STATUS_TOUCH 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #define MK712_CONVERSION_COMPLETE 0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) /* control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #define MK712_ENABLE_INT 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #define MK712_INT_ON_CONVERSION_COMPLETE 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) #define MK712_INT_ON_CHANGE_IN_TOUCH_STATUS 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #define MK712_ENABLE_PERIODIC_CONVERSIONS 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) #define MK712_READ_ONE_POINT 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #define MK712_POWERUP 0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) static struct input_dev *mk712_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static DEFINE_SPINLOCK(mk712_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) static irqreturn_t mk712_interrupt(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) unsigned char status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) static int debounce = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) static unsigned short last_x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) static unsigned short last_y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) spin_lock(&mk712_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) status = inb(mk712_io + MK712_STATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (~status & MK712_CONVERSION_COMPLETE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) debounce = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) if (~status & MK712_STATUS_TOUCH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) debounce = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) input_report_key(mk712_dev, BTN_TOUCH, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if (debounce) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) debounce = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) input_report_key(mk712_dev, BTN_TOUCH, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) input_report_abs(mk712_dev, ABS_X, last_x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) input_report_abs(mk712_dev, ABS_Y, last_y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) last_x = inw(mk712_io + MK712_X) & 0x0fff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) last_y = inw(mk712_io + MK712_Y) & 0x0fff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) input_sync(mk712_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) spin_unlock(&mk712_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static int mk712_open(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) spin_lock_irqsave(&mk712_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) outb(0, mk712_io + MK712_CONTROL); /* Reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) outb(MK712_ENABLE_INT | MK712_INT_ON_CONVERSION_COMPLETE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) MK712_INT_ON_CHANGE_IN_TOUCH_STATUS |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) MK712_ENABLE_PERIODIC_CONVERSIONS |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) MK712_POWERUP, mk712_io + MK712_CONTROL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) outb(10, mk712_io + MK712_RATE); /* 187 points per second */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) spin_unlock_irqrestore(&mk712_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) static void mk712_close(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) spin_lock_irqsave(&mk712_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) outb(0, mk712_io + MK712_CONTROL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) spin_unlock_irqrestore(&mk712_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static int __init mk712_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) if (!request_region(mk712_io, 8, "mk712")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) printk(KERN_WARNING "mk712: unable to get IO region\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) outb(0, mk712_io + MK712_CONTROL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) if ((inw(mk712_io + MK712_X) & 0xf000) || /* Sanity check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) (inw(mk712_io + MK712_Y) & 0xf000) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) (inw(mk712_io + MK712_STATUS) & 0xf333)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) printk(KERN_WARNING "mk712: device not present\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) goto fail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) mk712_dev = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) if (!mk712_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) printk(KERN_ERR "mk712: not enough memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) goto fail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) mk712_dev->name = "ICS MicroClock MK712 TouchScreen";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) mk712_dev->phys = "isa0260/input0";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) mk712_dev->id.bustype = BUS_ISA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) mk712_dev->id.vendor = 0x0005;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) mk712_dev->id.product = 0x0001;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) mk712_dev->id.version = 0x0100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) mk712_dev->open = mk712_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) mk712_dev->close = mk712_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) mk712_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) mk712_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) input_set_abs_params(mk712_dev, ABS_X, 0, 0xfff, 88, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) input_set_abs_params(mk712_dev, ABS_Y, 0, 0xfff, 88, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if (request_irq(mk712_irq, mk712_interrupt, 0, "mk712", mk712_dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) printk(KERN_WARNING "mk712: unable to get IRQ\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) err = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) goto fail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) err = input_register_device(mk712_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) goto fail2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) fail2: free_irq(mk712_irq, mk712_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) fail1: input_free_device(mk712_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) release_region(mk712_io, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static void __exit mk712_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) input_unregister_device(mk712_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) free_irq(mk712_irq, mk712_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) release_region(mk712_io, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) module_init(mk712_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) module_exit(mk712_exit);