| Michael Schmitz | c04cb85 | 2007-05-01 22:32:38 +0200 | [diff] [blame] | 1 | /* | 
|  | 2 | *  Atari mouse driver for Linux/m68k | 
|  | 3 | * | 
|  | 4 | *  Copyright (c) 2005 Michael Schmitz | 
|  | 5 | * | 
|  | 6 | *  Based on: | 
|  | 7 | *  Amiga mouse driver for Linux/m68k | 
|  | 8 | * | 
|  | 9 | *  Copyright (c) 2000-2002 Vojtech Pavlik | 
|  | 10 | * | 
|  | 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 | * This program is free software; you can redistribute it and/or modify it | 
|  | 39 | * under the terms of the GNU General Public License version 2 as published by | 
|  | 40 | * the Free Software Foundation | 
|  | 41 | */ | 
|  | 42 |  | 
|  | 43 | #include <linux/module.h> | 
|  | 44 | #include <linux/init.h> | 
|  | 45 | #include <linux/input.h> | 
|  | 46 | #include <linux/interrupt.h> | 
|  | 47 |  | 
|  | 48 | #include <asm/irq.h> | 
|  | 49 | #include <asm/setup.h> | 
| Michael Schmitz | c04cb85 | 2007-05-01 22:32:38 +0200 | [diff] [blame] | 50 | #include <asm/uaccess.h> | 
|  | 51 | #include <asm/atarihw.h> | 
|  | 52 | #include <asm/atarikb.h> | 
|  | 53 | #include <asm/atariints.h> | 
|  | 54 |  | 
|  | 55 | MODULE_AUTHOR("Michael Schmitz <schmitz@biophys.uni-duesseldorf.de>"); | 
|  | 56 | MODULE_DESCRIPTION("Atari mouse driver"); | 
|  | 57 | MODULE_LICENSE("GPL"); | 
|  | 58 |  | 
| Dmitry Torokhov | 82547e9 | 2008-06-02 01:03:24 -0400 | [diff] [blame] | 59 | static int mouse_threshold[2] = {2, 2}; | 
|  | 60 | module_param_array(mouse_threshold, int, NULL, 0); | 
| Michael Schmitz | c04cb85 | 2007-05-01 22:32:38 +0200 | [diff] [blame] | 61 |  | 
| Michael Schmitz | c04cb85 | 2007-05-01 22:32:38 +0200 | [diff] [blame] | 62 | #ifdef FIXED_ATARI_JOYSTICK | 
|  | 63 | extern int atari_mouse_buttons; | 
|  | 64 | #endif | 
| Michael Schmitz | c04cb85 | 2007-05-01 22:32:38 +0200 | [diff] [blame] | 65 |  | 
|  | 66 | static struct input_dev *atamouse_dev; | 
|  | 67 |  | 
|  | 68 | static void atamouse_interrupt(char *buf) | 
|  | 69 | { | 
|  | 70 | int buttons, dx, dy; | 
|  | 71 |  | 
| Michael Schmitz | c04cb85 | 2007-05-01 22:32:38 +0200 | [diff] [blame] | 72 | buttons = (buf[0] & 1) | ((buf[0] & 2) << 1); | 
|  | 73 | #ifdef FIXED_ATARI_JOYSTICK | 
|  | 74 | buttons |= atari_mouse_buttons & 2; | 
|  | 75 | atari_mouse_buttons = buttons; | 
|  | 76 | #endif | 
| Michael Schmitz | c04cb85 | 2007-05-01 22:32:38 +0200 | [diff] [blame] | 77 |  | 
|  | 78 | /* only relative events get here */ | 
| Geert Uytterhoeven | 659e6ed | 2011-01-31 20:15:04 +0100 | [diff] [blame] | 79 | dx = buf[1]; | 
|  | 80 | dy = buf[2]; | 
| Michael Schmitz | c04cb85 | 2007-05-01 22:32:38 +0200 | [diff] [blame] | 81 |  | 
|  | 82 | input_report_rel(atamouse_dev, REL_X, dx); | 
|  | 83 | input_report_rel(atamouse_dev, REL_Y, dy); | 
|  | 84 |  | 
| Geert Uytterhoeven | 659e6ed | 2011-01-31 20:15:04 +0100 | [diff] [blame] | 85 | input_report_key(atamouse_dev, BTN_LEFT,   buttons & 0x4); | 
| Michael Schmitz | c04cb85 | 2007-05-01 22:32:38 +0200 | [diff] [blame] | 86 | input_report_key(atamouse_dev, BTN_MIDDLE, buttons & 0x2); | 
| Geert Uytterhoeven | 659e6ed | 2011-01-31 20:15:04 +0100 | [diff] [blame] | 87 | input_report_key(atamouse_dev, BTN_RIGHT,  buttons & 0x1); | 
| Michael Schmitz | c04cb85 | 2007-05-01 22:32:38 +0200 | [diff] [blame] | 88 |  | 
|  | 89 | input_sync(atamouse_dev); | 
|  | 90 |  | 
|  | 91 | return; | 
|  | 92 | } | 
|  | 93 |  | 
|  | 94 | static int atamouse_open(struct input_dev *dev) | 
|  | 95 | { | 
| Michael Schmitz | c04cb85 | 2007-05-01 22:32:38 +0200 | [diff] [blame] | 96 | #ifdef FIXED_ATARI_JOYSTICK | 
|  | 97 | atari_mouse_buttons = 0; | 
|  | 98 | #endif | 
|  | 99 | ikbd_mouse_y0_top(); | 
|  | 100 | ikbd_mouse_thresh(mouse_threshold[0], mouse_threshold[1]); | 
|  | 101 | ikbd_mouse_rel_pos(); | 
|  | 102 | atari_input_mouse_interrupt_hook = atamouse_interrupt; | 
| Dmitry Torokhov | 82547e9 | 2008-06-02 01:03:24 -0400 | [diff] [blame] | 103 |  | 
| Michael Schmitz | c04cb85 | 2007-05-01 22:32:38 +0200 | [diff] [blame] | 104 | return 0; | 
|  | 105 | } | 
|  | 106 |  | 
|  | 107 | static void atamouse_close(struct input_dev *dev) | 
|  | 108 | { | 
| Dmitry Torokhov | 82547e9 | 2008-06-02 01:03:24 -0400 | [diff] [blame] | 109 | ikbd_mouse_disable(); | 
| Michael Schmitz | 7786908 | 2008-12-16 21:26:03 +0100 | [diff] [blame] | 110 | atari_input_mouse_interrupt_hook = NULL; | 
| Michael Schmitz | c04cb85 | 2007-05-01 22:32:38 +0200 | [diff] [blame] | 111 | } | 
|  | 112 |  | 
|  | 113 | static int __init atamouse_init(void) | 
|  | 114 | { | 
| Dmitry Torokhov | 82547e9 | 2008-06-02 01:03:24 -0400 | [diff] [blame] | 115 | int error; | 
|  | 116 |  | 
| Michael Schmitz | c04cb85 | 2007-05-01 22:32:38 +0200 | [diff] [blame] | 117 | if (!MACH_IS_ATARI || !ATARIHW_PRESENT(ST_MFP)) | 
|  | 118 | return -ENODEV; | 
|  | 119 |  | 
| Michael Schmitz | 186f200 | 2008-12-28 23:00:45 +0100 | [diff] [blame] | 120 | error = atari_keyb_init(); | 
|  | 121 | if (error) | 
|  | 122 | return error; | 
| Michael Schmitz | c04cb85 | 2007-05-01 22:32:38 +0200 | [diff] [blame] | 123 |  | 
| Geert Uytterhoeven | 6615c5b | 2007-10-13 14:31:24 +0200 | [diff] [blame] | 124 | atamouse_dev = input_allocate_device(); | 
|  | 125 | if (!atamouse_dev) | 
|  | 126 | return -ENOMEM; | 
|  | 127 |  | 
| Michael Schmitz | c04cb85 | 2007-05-01 22:32:38 +0200 | [diff] [blame] | 128 | atamouse_dev->name = "Atari mouse"; | 
|  | 129 | atamouse_dev->phys = "atamouse/input0"; | 
| Geert Uytterhoeven | 6615c5b | 2007-10-13 14:31:24 +0200 | [diff] [blame] | 130 | atamouse_dev->id.bustype = BUS_HOST; | 
| Michael Schmitz | c04cb85 | 2007-05-01 22:32:38 +0200 | [diff] [blame] | 131 | atamouse_dev->id.vendor = 0x0001; | 
|  | 132 | atamouse_dev->id.product = 0x0002; | 
|  | 133 | atamouse_dev->id.version = 0x0100; | 
|  | 134 |  | 
| Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 135 | atamouse_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); | 
|  | 136 | atamouse_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y); | 
|  | 137 | atamouse_dev->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) | | 
|  | 138 | BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT); | 
| Dmitry Torokhov | 82547e9 | 2008-06-02 01:03:24 -0400 | [diff] [blame] | 139 |  | 
| Michael Schmitz | c04cb85 | 2007-05-01 22:32:38 +0200 | [diff] [blame] | 140 | atamouse_dev->open = atamouse_open; | 
|  | 141 | atamouse_dev->close = atamouse_close; | 
|  | 142 |  | 
| Dmitry Torokhov | 82547e9 | 2008-06-02 01:03:24 -0400 | [diff] [blame] | 143 | error = input_register_device(atamouse_dev); | 
|  | 144 | if (error) { | 
| Geert Uytterhoeven | 6615c5b | 2007-10-13 14:31:24 +0200 | [diff] [blame] | 145 | input_free_device(atamouse_dev); | 
| Dmitry Torokhov | 82547e9 | 2008-06-02 01:03:24 -0400 | [diff] [blame] | 146 | return error; | 
| Geert Uytterhoeven | 6615c5b | 2007-10-13 14:31:24 +0200 | [diff] [blame] | 147 | } | 
| Michael Schmitz | c04cb85 | 2007-05-01 22:32:38 +0200 | [diff] [blame] | 148 |  | 
| Michael Schmitz | c04cb85 | 2007-05-01 22:32:38 +0200 | [diff] [blame] | 149 | return 0; | 
|  | 150 | } | 
|  | 151 |  | 
|  | 152 | static void __exit atamouse_exit(void) | 
|  | 153 | { | 
|  | 154 | input_unregister_device(atamouse_dev); | 
|  | 155 | } | 
|  | 156 |  | 
|  | 157 | module_init(atamouse_init); | 
|  | 158 | module_exit(atamouse_exit); |