2 * Amiga mouse driver for Linux/m68k
4 * Copyright (c) 2000-2002 Vojtech Pavlik
6 * Based on the work of:
7 * Michael Rausch James Banks
8 * Matther Dillon David Giller
9 * Nathan Laredo Linus Torvalds
10 * Johan Myreen Jes Sorensen
15 * This program is free software; you can redistribute it and/or modify it
16 * under the terms of the GNU General Public License version 2 as published by
17 * the Free Software Foundation
20 #include <linux/module.h>
21 #include <linux/init.h>
22 #include <linux/input.h>
23 #include <linux/interrupt.h>
26 #include <asm/setup.h>
27 #include <asm/system.h>
28 #include <asm/uaccess.h>
29 #include <asm/amigahw.h>
30 #include <asm/amigaints.h>
32 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
33 MODULE_DESCRIPTION("Amiga mouse driver");
34 MODULE_LICENSE("GPL");
36 static int amimouse_lastx, amimouse_lasty;
37 static struct input_dev *amimouse_dev;
39 static irqreturn_t amimouse_interrupt(int irq, void *dummy)
41 unsigned short joy0dat, potgor;
44 joy0dat = amiga_custom.joy0dat;
49 dx = nx - amimouse_lastx;
50 dy = ny - amimouse_lasty;
52 if (dx < -127) dx = (256 + nx) - amimouse_lastx;
53 if (dx > 127) dx = (nx - 256) - amimouse_lastx;
54 if (dy < -127) dy = (256 + ny) - amimouse_lasty;
55 if (dy > 127) dy = (ny - 256) - amimouse_lasty;
60 potgor = amiga_custom.potgor;
62 input_report_rel(amimouse_dev, REL_X, dx);
63 input_report_rel(amimouse_dev, REL_Y, dy);
65 input_report_key(amimouse_dev, BTN_LEFT, ciaa.pra & 0x40);
66 input_report_key(amimouse_dev, BTN_MIDDLE, potgor & 0x0100);
67 input_report_key(amimouse_dev, BTN_RIGHT, potgor & 0x0400);
69 input_sync(amimouse_dev);
74 static int amimouse_open(struct input_dev *dev)
76 unsigned short joy0dat;
78 joy0dat = amiga_custom.joy0dat;
80 amimouse_lastx = joy0dat & 0xff;
81 amimouse_lasty = joy0dat >> 8;
83 if (request_irq(IRQ_AMIGA_VERTB, amimouse_interrupt, 0, "amimouse", amimouse_interrupt)) {
84 printk(KERN_ERR "amimouse.c: Can't allocate irq %d\n", IRQ_AMIGA_VERTB);
91 static void amimouse_close(struct input_dev *dev)
93 free_irq(IRQ_AMIGA_VERTB, amimouse_interrupt);
96 static int __init amimouse_init(void)
100 if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(AMI_MOUSE))
103 amimouse_dev = input_allocate_device();
107 amimouse_dev->name = "Amiga mouse";
108 amimouse_dev->phys = "amimouse/input0";
109 amimouse_dev->id.bustype = BUS_AMIGA;
110 amimouse_dev->id.vendor = 0x0001;
111 amimouse_dev->id.product = 0x0002;
112 amimouse_dev->id.version = 0x0100;
114 amimouse_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
115 amimouse_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
116 amimouse_dev->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) |
117 BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
118 amimouse_dev->open = amimouse_open;
119 amimouse_dev->close = amimouse_close;
121 err = input_register_device(amimouse_dev);
123 input_free_device(amimouse_dev);
130 static void __exit amimouse_exit(void)
132 input_unregister_device(amimouse_dev);
135 module_init(amimouse_init);
136 module_exit(amimouse_exit);