Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  *  Atari mouse driver for Linux/m68k
0004  *
0005  *  Copyright (c) 2005 Michael Schmitz
0006  *
0007  *  Based on:
0008  *  Amiga mouse driver for Linux/m68k
0009  *
0010  *  Copyright (c) 2000-2002 Vojtech Pavlik
0011  */
0012 /*
0013  * The low level init and interrupt stuff is handled in arch/mm68k/atari/atakeyb.c
0014  * (the keyboard ACIA also handles the mouse and joystick data, and the keyboard
0015  * interrupt is shared with the MIDI ACIA so MIDI data also get handled there).
0016  * This driver only deals with handing key events off to the input layer.
0017  *
0018  * Largely based on the old:
0019  *
0020  * Atari Mouse Driver for Linux
0021  * by Robert de Vries (robert@and.nl) 19Jul93
0022  *
0023  * 16 Nov 1994 Andreas Schwab
0024  * Compatibility with busmouse
0025  * Support for three button mouse (shamelessly stolen from MiNT)
0026  * third button wired to one of the joystick directions on joystick 1
0027  *
0028  * 1996/02/11 Andreas Schwab
0029  * Module support
0030  * Allow multiple open's
0031  *
0032  * Converted to use new generic busmouse code.  5 Apr 1998
0033  *   Russell King <rmk@arm.uk.linux.org>
0034  */
0035 
0036 
0037 
0038 #include <linux/module.h>
0039 #include <linux/init.h>
0040 #include <linux/input.h>
0041 #include <linux/interrupt.h>
0042 
0043 #include <asm/irq.h>
0044 #include <asm/setup.h>
0045 #include <linux/uaccess.h>
0046 #include <asm/atarihw.h>
0047 #include <asm/atarikb.h>
0048 #include <asm/atariints.h>
0049 
0050 MODULE_AUTHOR("Michael Schmitz <schmitz@biophys.uni-duesseldorf.de>");
0051 MODULE_DESCRIPTION("Atari mouse driver");
0052 MODULE_LICENSE("GPL");
0053 
0054 static int mouse_threshold[2] = {2, 2};
0055 module_param_array(mouse_threshold, int, NULL, 0);
0056 
0057 #ifdef FIXED_ATARI_JOYSTICK
0058 extern int atari_mouse_buttons;
0059 #endif
0060 
0061 static struct input_dev *atamouse_dev;
0062 
0063 static void atamouse_interrupt(char *buf)
0064 {
0065     int buttons, dx, dy;
0066 
0067     buttons = (buf[0] & 1) | ((buf[0] & 2) << 1);
0068 #ifdef FIXED_ATARI_JOYSTICK
0069     buttons |= atari_mouse_buttons & 2;
0070     atari_mouse_buttons = buttons;
0071 #endif
0072 
0073     /* only relative events get here */
0074     dx = buf[1];
0075     dy = buf[2];
0076 
0077     input_report_rel(atamouse_dev, REL_X, dx);
0078     input_report_rel(atamouse_dev, REL_Y, dy);
0079 
0080     input_report_key(atamouse_dev, BTN_LEFT,   buttons & 0x4);
0081     input_report_key(atamouse_dev, BTN_MIDDLE, buttons & 0x2);
0082     input_report_key(atamouse_dev, BTN_RIGHT,  buttons & 0x1);
0083 
0084     input_sync(atamouse_dev);
0085 
0086     return;
0087 }
0088 
0089 static int atamouse_open(struct input_dev *dev)
0090 {
0091 #ifdef FIXED_ATARI_JOYSTICK
0092     atari_mouse_buttons = 0;
0093 #endif
0094     ikbd_mouse_y0_top();
0095     ikbd_mouse_thresh(mouse_threshold[0], mouse_threshold[1]);
0096     ikbd_mouse_rel_pos();
0097     atari_input_mouse_interrupt_hook = atamouse_interrupt;
0098 
0099     return 0;
0100 }
0101 
0102 static void atamouse_close(struct input_dev *dev)
0103 {
0104     ikbd_mouse_disable();
0105     atari_input_mouse_interrupt_hook = NULL;
0106 }
0107 
0108 static int __init atamouse_init(void)
0109 {
0110     int error;
0111 
0112     if (!MACH_IS_ATARI || !ATARIHW_PRESENT(ST_MFP))
0113         return -ENODEV;
0114 
0115     error = atari_keyb_init();
0116     if (error)
0117         return error;
0118 
0119     atamouse_dev = input_allocate_device();
0120     if (!atamouse_dev)
0121         return -ENOMEM;
0122 
0123     atamouse_dev->name = "Atari mouse";
0124     atamouse_dev->phys = "atamouse/input0";
0125     atamouse_dev->id.bustype = BUS_HOST;
0126     atamouse_dev->id.vendor = 0x0001;
0127     atamouse_dev->id.product = 0x0002;
0128     atamouse_dev->id.version = 0x0100;
0129 
0130     atamouse_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
0131     atamouse_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
0132     atamouse_dev->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) |
0133         BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
0134 
0135     atamouse_dev->open = atamouse_open;
0136     atamouse_dev->close = atamouse_close;
0137 
0138     error = input_register_device(atamouse_dev);
0139     if (error) {
0140         input_free_device(atamouse_dev);
0141         return error;
0142     }
0143 
0144     return 0;
0145 }
0146 
0147 static void __exit atamouse_exit(void)
0148 {
0149     input_unregister_device(atamouse_dev);
0150 }
0151 
0152 module_init(atamouse_init);
0153 module_exit(atamouse_exit);