OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [char/] [adbmouse.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*
2
 * Macintosh ADB Mouse driver for Linux
3
 *
4
 * 27 Oct 1997 Michael Schmitz
5
 * logitech fixes by anthony tong
6
 * further hacking by Paul Mackerras
7
 *
8
 * Apple mouse protocol according to:
9
 *
10
 * Device code shamelessly stolen from:
11
 */
12
/*
13
 * Atari Mouse Driver for Linux
14
 * by Robert de Vries (robert@and.nl) 19Jul93
15
 *
16
 * 16 Nov 1994 Andreas Schwab
17
 * Compatibility with busmouse
18
 * Support for three button mouse (shamelessly stolen from MiNT)
19
 * third button wired to one of the joystick directions on joystick 1
20
 *
21
 * 1996/02/11 Andreas Schwab
22
 * Module support
23
 * Allow multiple open's
24
 *
25
 * Converted to use new generic busmouse code.  11 July 1998
26
 *   Russell King <rmk@arm.uk.linux.org>
27
 */
28
 
29
#include <linux/module.h>
30
 
31
#include <linux/sched.h>
32
#include <linux/errno.h>
33
#include <linux/miscdevice.h>
34
#include <linux/mm.h>
35
#include <linux/random.h>
36
#include <linux/poll.h>
37
#include <linux/init.h>
38
#include <linux/adb_mouse.h>
39
 
40
#ifdef __powerpc__
41
#include <asm/processor.h>
42
#endif
43
#if defined(__mc68000__) || defined(MODULE)
44
#include <asm/setup.h>
45
#endif
46
 
47
#include "busmouse.h"
48
 
49
static int msedev;
50
static unsigned char adb_mouse_buttons[16];
51
 
52
extern void (*adb_mouse_interrupt_hook)(unsigned char *, int);
53
extern int adb_emulate_buttons;
54
extern int adb_button2_keycode;
55
extern int adb_button3_keycode;
56
 
57
/*
58
 *    XXX: need to figure out what ADB mouse packets mean ...
59
 *      This is the stuff stolen from the Atari driver ...
60
 */
61
static void adb_mouse_interrupt(unsigned char *buf, int nb)
62
{
63
        int buttons, id;
64
        char dx, dy;
65
 
66
        /*
67
           Handler 1 -- 100cpi original Apple mouse protocol.
68
           Handler 2 -- 200cpi original Apple mouse protocol.
69
 
70
           For Apple's standard one-button mouse protocol the data array will
71
           contain the following values:
72
 
73
                       BITS    COMMENTS
74
           data[0] = dddd 1100 ADB command: Talk, register 0, for device dddd.
75
           data[1] = bxxx xxxx First button and x-axis motion.
76
           data[2] = byyy yyyy Second button and y-axis motion.
77
 
78
           Handler 4 -- Apple Extended mouse protocol.
79
 
80
           For Apple's 3-button mouse protocol the data array will contain the
81
           following values:
82
 
83
                       BITS    COMMENTS
84
           data[0] = dddd 1100 ADB command: Talk, register 0, for device dddd.
85
           data[1] = bxxx xxxx Left button and x-axis motion.
86
           data[2] = byyy yyyy Second button and y-axis motion.
87
           data[3] = byyy bxxx Third button and fourth button.
88
                   Y is additiona. high bits of y-axis motion.
89
                   X is additional high bits of x-axis motion.
90
 
91
           'buttons' here means 'button down' states!
92
           Button 1 (left)  : bit 2, busmouse button 3
93
           Button 2 (right) : bit 0, busmouse button 1
94
           Button 3 (middle): bit 1, busmouse button 2
95
         */
96
 
97
        /* x/y and buttons swapped */
98
 
99
        id = (buf[0] >> 4) & 0xf;
100
 
101
        buttons = adb_mouse_buttons[id];
102
 
103
        /* button 1 (left, bit 2) */
104
        buttons = (buttons & 3) | (buf[1] & 0x80 ? 4 : 0); /* 1+2 unchanged */
105
 
106
        /* button 2 (middle) */
107
        buttons = (buttons & 5) | (buf[2] & 0x80 ? 2 : 0); /* 2+3 unchanged */
108
 
109
        /* button 3 (right) present?
110
         *  on a logitech mouseman, the right and mid buttons sometimes behave
111
         *  strangely until they both have been pressed after booting. */
112
        /* data valid only if extended mouse format ! */
113
        if (nb >= 4)
114
                buttons = (buttons & 6) | (buf[3] & 0x80 ? 1 : 0); /* 1+3 unchanged */
115
 
116
        adb_mouse_buttons[id] = buttons;
117
 
118
        /* a button is down if it is down on any mouse */
119
        for (id = 0; id < 16; ++id)
120
                buttons &= adb_mouse_buttons[id];
121
 
122
        dx = ((buf[2] & 0x7f) < 64 ? (buf[2] & 0x7f) : (buf[2] & 0x7f) - 128);
123
        dy = ((buf[1] & 0x7f) < 64 ? (buf[1] & 0x7f) : (buf[1] & 0x7f) - 128);
124
        busmouse_add_movementbuttons(msedev, dx, -dy, buttons);
125
 
126
        if (console_loglevel >= 8)
127
                printk(" %X %X %X dx %d dy %d \n",
128
                       buf[1], buf[2], buf[3], dx, dy);
129
}
130
 
131
static int release_mouse(struct inode *inode, struct file *file)
132
{
133
        adb_mouse_interrupt_hook = NULL;
134
        /*
135
         *      FIXME?: adb_mouse_interrupt_hook may still be executing
136
         *      on another CPU.
137
         */
138
        return 0;
139
}
140
 
141
static int open_mouse(struct inode *inode, struct file *file)
142
{
143
        adb_mouse_interrupt_hook = adb_mouse_interrupt;
144
        return 0;
145
}
146
 
147
static struct busmouse adb_mouse =
148
{
149
        ADB_MOUSE_MINOR, "adbmouse", THIS_MODULE, open_mouse, release_mouse, 7
150
};
151
 
152
static int __init adb_mouse_init(void)
153
{
154
#ifdef __powerpc__
155
        if ((_machine != _MACH_chrp) && (_machine != _MACH_Pmac))
156
                return -ENODEV;
157
#endif
158
#ifdef __mc68000__
159
        if (!MACH_IS_MAC)
160
                return -ENODEV;
161
#endif
162
        /* all buttons up */
163
        memset(adb_mouse_buttons, 7, sizeof(adb_mouse_buttons));
164
 
165
        msedev = register_busmouse(&adb_mouse);
166
        if (msedev < 0)
167
                printk(KERN_WARNING "Unable to register ADB mouse driver.\n");
168
        else
169
                printk(KERN_INFO "Macintosh ADB mouse driver installed.\n");
170
 
171
        return msedev < 0 ? msedev : 0;
172
}
173
 
174
#ifndef MODULE
175
 
176
/*
177
 * XXX this function is misnamed.
178
 * It is called if the kernel is booted with the adb_buttons=xxx
179
 * option, which is about using ADB keyboard buttons to emulate
180
 * mouse buttons. -- paulus
181
 */
182
static int __init adb_mouse_setup(char *str)
183
{
184
        int ints[4];
185
 
186
        str = get_options(str, ARRAY_SIZE(ints), ints);
187
        if (ints[0] >= 1) {
188
                adb_emulate_buttons = ints[1];
189
                if (ints[0] >= 2)
190
                        adb_button2_keycode = ints[2];
191
                if (ints[0] >= 3)
192
                        adb_button3_keycode = ints[3];
193
        }
194
        return 1;
195
}
196
 
197
__setup("adb_buttons=", adb_mouse_setup);
198
 
199
#endif /* !MODULE */
200
 
201
static void __exit adb_mouse_cleanup(void)
202
{
203
        unregister_busmouse(msedev);
204
}
205
 
206
module_init(adb_mouse_init);
207
module_exit(adb_mouse_cleanup);
208
 
209
MODULE_LICENSE("GPL");

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.