^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) * Acorn RiscPC mouse driver for Linux/ARM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2000-2002 Vojtech Pavlik
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 1996-2002 Russell King
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^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) * This handles the Acorn RiscPCs mouse. We basically have a couple of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * hardware registers that track the sensor count for the X-Y movement and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * another register holding the button state. On every VSYNC interrupt we read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * the complete state and then work out if something has changed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <mach/hardware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <asm/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <asm/hardware/iomd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) MODULE_AUTHOR("Vojtech Pavlik, Russell King");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) MODULE_DESCRIPTION("Acorn RiscPC mouse driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static short rpcmouse_lastx, rpcmouse_lasty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static struct input_dev *rpcmouse_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static irqreturn_t rpcmouse_irq(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct input_dev *dev = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) short x, y, dx, dy, b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) x = (short) iomd_readl(IOMD_MOUSEX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) y = (short) iomd_readl(IOMD_MOUSEY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) b = (short) (__raw_readl(IOMEM(0xe0310000)) ^ 0x70);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) dx = x - rpcmouse_lastx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) dy = y - rpcmouse_lasty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) rpcmouse_lastx = x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) rpcmouse_lasty = y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) input_report_rel(dev, REL_X, dx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) input_report_rel(dev, REL_Y, -dy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) input_report_key(dev, BTN_LEFT, b & 0x40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) input_report_key(dev, BTN_MIDDLE, b & 0x20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) input_report_key(dev, BTN_RIGHT, b & 0x10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) input_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) static int __init rpcmouse_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) rpcmouse_dev = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) if (!rpcmouse_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) rpcmouse_dev->name = "Acorn RiscPC Mouse";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) rpcmouse_dev->phys = "rpcmouse/input0";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) rpcmouse_dev->id.bustype = BUS_HOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) rpcmouse_dev->id.vendor = 0x0005;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) rpcmouse_dev->id.product = 0x0001;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) rpcmouse_dev->id.version = 0x0100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) rpcmouse_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) rpcmouse_dev->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) rpcmouse_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) rpcmouse_lastx = (short) iomd_readl(IOMD_MOUSEX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) rpcmouse_lasty = (short) iomd_readl(IOMD_MOUSEY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) if (request_irq(IRQ_VSYNCPULSE, rpcmouse_irq, IRQF_SHARED, "rpcmouse", rpcmouse_dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) printk(KERN_ERR "rpcmouse: unable to allocate VSYNC interrupt\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) err = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) goto err_free_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) err = input_register_device(rpcmouse_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) goto err_free_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) err_free_irq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) free_irq(IRQ_VSYNCPULSE, rpcmouse_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) err_free_dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) input_free_device(rpcmouse_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static void __exit rpcmouse_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) free_irq(IRQ_VSYNCPULSE, rpcmouse_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) input_unregister_device(rpcmouse_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) module_init(rpcmouse_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) module_exit(rpcmouse_exit);