^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) * Amiga mouse driver for Linux/m68k
^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) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Based on the work of:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Michael Rausch James Banks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Matther Dillon David Giller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Nathan Laredo Linus Torvalds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Johan Myreen Jes Sorensen
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Russell King
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/input.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/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <asm/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <asm/amigahw.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <asm/amigaints.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 <vojtech@ucw.cz>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) MODULE_DESCRIPTION("Amiga 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 int amimouse_lastx, amimouse_lasty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static irqreturn_t amimouse_interrupt(int irq, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct input_dev *dev = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) unsigned short joy0dat, potgor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) int nx, ny, dx, dy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) joy0dat = amiga_custom.joy0dat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) nx = joy0dat & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) ny = joy0dat >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) dx = nx - amimouse_lastx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) dy = ny - amimouse_lasty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) if (dx < -127) dx = (256 + nx) - amimouse_lastx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) if (dx > 127) dx = (nx - 256) - amimouse_lastx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) if (dy < -127) dy = (256 + ny) - amimouse_lasty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) if (dy > 127) dy = (ny - 256) - amimouse_lasty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) amimouse_lastx = nx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) amimouse_lasty = ny;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) potgor = amiga_custom.potgor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) input_report_rel(dev, REL_X, dx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) input_report_rel(dev, REL_Y, dy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) input_report_key(dev, BTN_LEFT, ciaa.pra & 0x40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) input_report_key(dev, BTN_MIDDLE, potgor & 0x0100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) input_report_key(dev, BTN_RIGHT, potgor & 0x0400);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) input_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) static int amimouse_open(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) unsigned short joy0dat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) joy0dat = amiga_custom.joy0dat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) amimouse_lastx = joy0dat & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) amimouse_lasty = joy0dat >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) error = request_irq(IRQ_AMIGA_VERTB, amimouse_interrupt, 0, "amimouse",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) dev_err(&dev->dev, "Can't allocate irq %d\n", IRQ_AMIGA_VERTB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) static void amimouse_close(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) free_irq(IRQ_AMIGA_VERTB, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) static int __init amimouse_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) struct input_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) dev = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) dev->name = pdev->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) dev->phys = "amimouse/input0";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) dev->id.bustype = BUS_AMIGA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) dev->id.vendor = 0x0001;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) dev->id.product = 0x0002;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) dev->id.version = 0x0100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) dev->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) dev->open = amimouse_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) dev->close = amimouse_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) dev->dev.parent = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) err = input_register_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) input_free_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) platform_set_drvdata(pdev, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static int __exit amimouse_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) struct input_dev *dev = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) input_unregister_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static struct platform_driver amimouse_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) .remove = __exit_p(amimouse_remove),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) .name = "amiga-mouse",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) module_platform_driver_probe(amimouse_driver, amimouse_probe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) MODULE_ALIAS("platform:amiga-mouse");