blob: b55d5af217a777e3a470ad651398c0e7218d11de [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>
Geert Uytterhoeven314c9262009-04-05 13:11:28 +020024#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26#include <asm/irq.h>
27#include <asm/setup.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Geert Uytterhoeven314c9262009-04-05 13:11:28 +020038static irqreturn_t amimouse_interrupt(int irq, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039{
Geert Uytterhoeven314c9262009-04-05 13:11:28 +020040 struct input_dev *dev = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 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
Geert Uytterhoeven314c9262009-04-05 13:11:28 +020062 input_report_rel(dev, REL_X, dx);
63 input_report_rel(dev, REL_Y, dy);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
Geert Uytterhoeven314c9262009-04-05 13:11:28 +020065 input_report_key(dev, BTN_LEFT, ciaa.pra & 0x40);
66 input_report_key(dev, BTN_MIDDLE, potgor & 0x0100);
67 input_report_key(dev, BTN_RIGHT, potgor & 0x0400);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Geert Uytterhoeven314c9262009-04-05 13:11:28 +020069 input_sync(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71 return IRQ_HANDLED;
72}
73
74static int amimouse_open(struct input_dev *dev)
75{
76 unsigned short joy0dat;
Geert Uytterhoeven314c9262009-04-05 13:11:28 +020077 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Al Virob4290a22006-01-12 01:06:12 -080079 joy0dat = amiga_custom.joy0dat;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
81 amimouse_lastx = joy0dat & 0xff;
82 amimouse_lasty = joy0dat >> 8;
83
Geert Uytterhoeven314c9262009-04-05 13:11:28 +020084 error = request_irq(IRQ_AMIGA_VERTB, amimouse_interrupt, 0, "amimouse",
85 dev);
86 if (error)
87 dev_err(&dev->dev, "Can't allocate irq %d\n", IRQ_AMIGA_VERTB);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Geert Uytterhoeven314c9262009-04-05 13:11:28 +020089 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090}
91
92static void amimouse_close(struct input_dev *dev)
93{
Geert Uytterhoeven314c9262009-04-05 13:11:28 +020094 free_irq(IRQ_AMIGA_VERTB, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095}
96
Geert Uytterhoeven314c9262009-04-05 13:11:28 +020097static int __init amimouse_probe(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098{
Dmitry Torokhov72155612006-11-05 22:40:19 -050099 int err;
Geert Uytterhoeven314c9262009-04-05 13:11:28 +0200100 struct input_dev *dev;
Dmitry Torokhov72155612006-11-05 22:40:19 -0500101
Geert Uytterhoeven314c9262009-04-05 13:11:28 +0200102 dev = input_allocate_device();
103 if (!dev)
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500104 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
Geert Uytterhoeven314c9262009-04-05 13:11:28 +0200106 dev->name = pdev->name;
107 dev->phys = "amimouse/input0";
108 dev->id.bustype = BUS_AMIGA;
109 dev->id.vendor = 0x0001;
110 dev->id.product = 0x0002;
111 dev->id.version = 0x0100;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Geert Uytterhoeven314c9262009-04-05 13:11:28 +0200113 dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
114 dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
115 dev->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) |
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700116 BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
Geert Uytterhoeven314c9262009-04-05 13:11:28 +0200117 dev->open = amimouse_open;
118 dev->close = amimouse_close;
119 dev->dev.parent = &pdev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
Geert Uytterhoeven314c9262009-04-05 13:11:28 +0200121 err = input_register_device(dev);
Dmitry Torokhov72155612006-11-05 22:40:19 -0500122 if (err) {
Geert Uytterhoeven314c9262009-04-05 13:11:28 +0200123 input_free_device(dev);
Dmitry Torokhov72155612006-11-05 22:40:19 -0500124 return err;
125 }
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500126
Geert Uytterhoeven314c9262009-04-05 13:11:28 +0200127 platform_set_drvdata(pdev, dev);
128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 return 0;
130}
131
Geert Uytterhoeven314c9262009-04-05 13:11:28 +0200132static int __exit amimouse_remove(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133{
Geert Uytterhoeven314c9262009-04-05 13:11:28 +0200134 struct input_dev *dev = platform_get_drvdata(pdev);
135
136 platform_set_drvdata(pdev, NULL);
137 input_unregister_device(dev);
138 return 0;
139}
140
141static struct platform_driver amimouse_driver = {
142 .remove = __exit_p(amimouse_remove),
143 .driver = {
144 .name = "amiga-mouse",
145 .owner = THIS_MODULE,
146 },
147};
Dmitry Torokhovd3d25802012-01-10 15:08:01 -0800148
Sachin Kamate492fe22013-03-17 21:28:00 -0700149module_platform_driver_probe(amimouse_driver, amimouse_probe);
Geert Uytterhoeven314c9262009-04-05 13:11:28 +0200150
151MODULE_ALIAS("platform:amiga-mouse");