blob: c8b2cc9f184c7355b1004d913cc5c0f7ace57c29 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Amiga mouse driver for Linux/m68k
3 *
4 * Copyright (c) 2000-2002 Vojtech Pavlik
5 *
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
11 * Russell King
12 */
13
14/*
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
18 */
19
20#include <linux/module.h>
21#include <linux/init.h>
22#include <linux/input.h>
23#include <linux/interrupt.h>
24
25#include <asm/irq.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>
31
32MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
33MODULE_DESCRIPTION("Amiga mouse driver");
34MODULE_LICENSE("GPL");
35
Linus Torvalds1da177e2005-04-16 15:20:36 -070036static int amimouse_lastx, amimouse_lasty;
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -050037static struct input_dev *amimouse_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39static irqreturn_t amimouse_interrupt(int irq, void *dummy, struct pt_regs *fp)
40{
41 unsigned short joy0dat, potgor;
42 int nx, ny, dx, dy;
43
Al Virob4290a22006-01-12 01:06:12 -080044 joy0dat = amiga_custom.joy0dat;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46 nx = joy0dat & 0xff;
47 ny = joy0dat >> 8;
48
49 dx = nx - amimouse_lastx;
50 dy = ny - amimouse_lasty;
51
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;
56
57 amimouse_lastx = nx;
58 amimouse_lasty = ny;
59
Al Virob4290a22006-01-12 01:06:12 -080060 potgor = amiga_custom.potgor;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -050062 input_regs(amimouse_dev, fp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -050064 input_report_rel(amimouse_dev, REL_X, dx);
65 input_report_rel(amimouse_dev, REL_Y, dy);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -050067 input_report_key(amimouse_dev, BTN_LEFT, ciaa.pra & 0x40);
68 input_report_key(amimouse_dev, BTN_MIDDLE, potgor & 0x0100);
69 input_report_key(amimouse_dev, BTN_RIGHT, potgor & 0x0400);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -050071 input_sync(amimouse_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73 return IRQ_HANDLED;
74}
75
76static int amimouse_open(struct input_dev *dev)
77{
78 unsigned short joy0dat;
79
Al Virob4290a22006-01-12 01:06:12 -080080 joy0dat = amiga_custom.joy0dat;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82 amimouse_lastx = joy0dat & 0xff;
83 amimouse_lasty = joy0dat >> 8;
84
85 if (request_irq(IRQ_AMIGA_VERTB, amimouse_interrupt, 0, "amimouse", amimouse_interrupt)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 printk(KERN_ERR "amimouse.c: Can't allocate irq %d\n", IRQ_AMIGA_VERTB);
87 return -EBUSY;
88 }
89
90 return 0;
91}
92
93static void amimouse_close(struct input_dev *dev)
94{
Dmitry Torokhov3108d422005-05-29 02:29:30 -050095 free_irq(IRQ_AMIGA_VERTB, amimouse_interrupt);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096}
97
98static int __init amimouse_init(void)
99{
100 if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(AMI_MOUSE))
101 return -ENODEV;
102
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500103 if (!(amimouse_dev = input_allocate_device()))
104 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500106 amimouse_dev->name = "Amiga mouse";
107 amimouse_dev->phys = "amimouse/input0";
108 amimouse_dev->id.bustype = BUS_AMIGA;
109 amimouse_dev->id.vendor = 0x0001;
110 amimouse_dev->id.product = 0x0002;
111 amimouse_dev->id.version = 0x0100;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500113 amimouse_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
114 amimouse_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
115 amimouse_dev->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
116 amimouse_dev->open = amimouse_open;
117 amimouse_dev->close = amimouse_close;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500119 input_register_device(amimouse_dev);
120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 return 0;
122}
123
124static void __exit amimouse_exit(void)
125{
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500126 input_unregister_device(amimouse_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127}
128
129module_init(amimouse_init);
130module_exit(amimouse_exit);