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