Replace <asm/uaccess.h> with <linux/uaccess.h> globally
[linux-2.6-block.git] / drivers / input / mouse / amimouse.c
CommitLineData
1da177e4
LT
1/*
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>
314c926f 24#include <linux/platform_device.h>
1da177e4
LT
25
26#include <asm/irq.h>
27#include <asm/setup.h>
7c0f6ba6 28#include <linux/uaccess.h>
1da177e4
LT
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
1da177e4 36static int amimouse_lastx, amimouse_lasty;
1da177e4 37
314c926f 38static irqreturn_t amimouse_interrupt(int irq, void *data)
1da177e4 39{
314c926f 40 struct input_dev *dev = data;
1da177e4
LT
41 unsigned short joy0dat, potgor;
42 int nx, ny, dx, dy;
43
b4290a23 44 joy0dat = amiga_custom.joy0dat;
1da177e4
LT
45
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
b4290a23 60 potgor = amiga_custom.potgor;
1da177e4 61
314c926f
GU
62 input_report_rel(dev, REL_X, dx);
63 input_report_rel(dev, REL_Y, dy);
1da177e4 64
314c926f
GU
65 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);
1da177e4 68
314c926f 69 input_sync(dev);
1da177e4
LT
70
71 return IRQ_HANDLED;
72}
73
74static int amimouse_open(struct input_dev *dev)
75{
76 unsigned short joy0dat;
314c926f 77 int error;
1da177e4 78
b4290a23 79 joy0dat = amiga_custom.joy0dat;
1da177e4
LT
80
81 amimouse_lastx = joy0dat & 0xff;
82 amimouse_lasty = joy0dat >> 8;
83
314c926f
GU
84 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);
1da177e4 88
314c926f 89 return error;
1da177e4
LT
90}
91
92static void amimouse_close(struct input_dev *dev)
93{
314c926f 94 free_irq(IRQ_AMIGA_VERTB, dev);
1da177e4
LT
95}
96
314c926f 97static int __init amimouse_probe(struct platform_device *pdev)
1da177e4 98{
72155615 99 int err;
314c926f 100 struct input_dev *dev;
72155615 101
314c926f
GU
102 dev = input_allocate_device();
103 if (!dev)
2e5b636b
DT
104 return -ENOMEM;
105
314c926f
GU
106 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;
1da177e4 112
314c926f
GU
113 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) |
7b19ada2 116 BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
314c926f
GU
117 dev->open = amimouse_open;
118 dev->close = amimouse_close;
119 dev->dev.parent = &pdev->dev;
1da177e4 120
314c926f 121 err = input_register_device(dev);
72155615 122 if (err) {
314c926f 123 input_free_device(dev);
72155615
DT
124 return err;
125 }
1da177e4 126
314c926f
GU
127 platform_set_drvdata(pdev, dev);
128
1da177e4
LT
129 return 0;
130}
131
314c926f 132static int __exit amimouse_remove(struct platform_device *pdev)
1da177e4 133{
314c926f
GU
134 struct input_dev *dev = platform_get_drvdata(pdev);
135
314c926f
GU
136 input_unregister_device(dev);
137 return 0;
138}
139
140static struct platform_driver amimouse_driver = {
141 .remove = __exit_p(amimouse_remove),
142 .driver = {
143 .name = "amiga-mouse",
314c926f
GU
144 },
145};
d3d25808 146
e492fe27 147module_platform_driver_probe(amimouse_driver, amimouse_probe);
314c926f
GU
148
149MODULE_ALIAS("platform:amiga-mouse");