1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Atari mouse driver for Linux/m68k
4 *
5 * Copyright (c) 2005 Michael Schmitz
6 *
7 * Based on:
8 * Amiga mouse driver for Linux/m68k
9 *
10 * Copyright (c) 2000-2002 Vojtech Pavlik
11 */
12/*
13 * The low level init and interrupt stuff is handled in arch/mm68k/atari/atakeyb.c
14 * (the keyboard ACIA also handles the mouse and joystick data, and the keyboard
15 * interrupt is shared with the MIDI ACIA so MIDI data also get handled there).
16 * This driver only deals with handing key events off to the input layer.
17 *
18 * Largely based on the old:
19 *
20 * Atari Mouse Driver for Linux
21 * by Robert de Vries (robert@and.nl) 19Jul93
22 *
23 * 16 Nov 1994 Andreas Schwab
24 * Compatibility with busmouse
25 * Support for three button mouse (shamelessly stolen from MiNT)
26 * third button wired to one of the joystick directions on joystick 1
27 *
28 * 1996/02/11 Andreas Schwab
29 * Module support
30 * Allow multiple open's
31 *
32 * Converted to use new generic busmouse code. 5 Apr 1998
33 * Russell King <rmk@arm.uk.linux.org>
34 */
35
36
37
38#include <linux/module.h>
39#include <linux/init.h>
40#include <linux/input.h>
41#include <linux/interrupt.h>
42
43#include <asm/irq.h>
44#include <asm/setup.h>
45#include <linux/uaccess.h>
46#include <asm/atarihw.h>
47#include <asm/atarikb.h>
48#include <asm/atariints.h>
49
50MODULE_AUTHOR("Michael Schmitz <schmitz@biophys.uni-duesseldorf.de>");
51MODULE_DESCRIPTION("Atari mouse driver");
52MODULE_LICENSE("GPL");
53
54static int mouse_threshold[2] = {2, 2};
55module_param_array(mouse_threshold, int, NULL, 0);
56
57#ifdef FIXED_ATARI_JOYSTICK
58extern int atari_mouse_buttons;
59#endif
60
61static struct input_dev *atamouse_dev;
62
63static void atamouse_interrupt(char *buf)
64{
65 int buttons, dx, dy;
66
67 buttons = (buf[0] & 1) | ((buf[0] & 2) << 1);
68#ifdef FIXED_ATARI_JOYSTICK
69 buttons |= atari_mouse_buttons & 2;
70 atari_mouse_buttons = buttons;
71#endif
72
73 /* only relative events get here */
74 dx = buf[1];
75 dy = buf[2];
76
77 input_report_rel(dev: atamouse_dev, REL_X, value: dx);
78 input_report_rel(dev: atamouse_dev, REL_Y, value: dy);
79
80 input_report_key(dev: atamouse_dev, BTN_LEFT, value: buttons & 0x4);
81 input_report_key(dev: atamouse_dev, BTN_MIDDLE, value: buttons & 0x2);
82 input_report_key(dev: atamouse_dev, BTN_RIGHT, value: buttons & 0x1);
83
84 input_sync(dev: atamouse_dev);
85
86 return;
87}
88
89static int atamouse_open(struct input_dev *dev)
90{
91#ifdef FIXED_ATARI_JOYSTICK
92 atari_mouse_buttons = 0;
93#endif
94 ikbd_mouse_y0_top();
95 ikbd_mouse_thresh(mouse_threshold[0], mouse_threshold[1]);
96 ikbd_mouse_rel_pos();
97 atari_input_mouse_interrupt_hook = atamouse_interrupt;
98
99 return 0;
100}
101
102static void atamouse_close(struct input_dev *dev)
103{
104 ikbd_mouse_disable();
105 atari_input_mouse_interrupt_hook = NULL;
106}
107
108static int __init atamouse_init(void)
109{
110 int error;
111
112 if (!MACH_IS_ATARI || !ATARIHW_PRESENT(ST_MFP))
113 return -ENODEV;
114
115 error = atari_keyb_init();
116 if (error)
117 return error;
118
119 atamouse_dev = input_allocate_device();
120 if (!atamouse_dev)
121 return -ENOMEM;
122
123 atamouse_dev->name = "Atari mouse";
124 atamouse_dev->phys = "atamouse/input0";
125 atamouse_dev->id.bustype = BUS_HOST;
126 atamouse_dev->id.vendor = 0x0001;
127 atamouse_dev->id.product = 0x0002;
128 atamouse_dev->id.version = 0x0100;
129
130 atamouse_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
131 atamouse_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
132 atamouse_dev->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) |
133 BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
134
135 atamouse_dev->open = atamouse_open;
136 atamouse_dev->close = atamouse_close;
137
138 error = input_register_device(atamouse_dev);
139 if (error) {
140 input_free_device(dev: atamouse_dev);
141 return error;
142 }
143
144 return 0;
145}
146
147static void __exit atamouse_exit(void)
148{
149 input_unregister_device(atamouse_dev);
150}
151
152module_init(atamouse_init);
153module_exit(atamouse_exit);
154

source code of linux/drivers/input/mouse/atarimouse.c