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