2 * Macintosh ADB Mouse driver for Linux 4 * 27 Oct 1997 Michael Schmitz 5 * logitech fixes by anthony tong 6 * further hacking by Paul Mackerras 8 * Apple mouse protocol according to: 10 * Device code shamelessly stolen from: 13 * Atari Mouse Driver for Linux 14 * by Robert de Vries (robert@and.nl) 19Jul93 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 21 * 1996/02/11 Andreas Schwab 23 * Allow multiple open's 25 * Converted to use new generic busmouse code. 11 July 1998 26 * Russell King <rmk@arm.uk.linux.org> 29 #include <linux/module.h> 31 #include <linux/sched.h> 32 #include <linux/errno.h> 33 #include <linux/miscdevice.h> 35 #include <linux/random.h> 36 #include <linux/poll.h> 37 #include <linux/init.h> 39 #include <asm/adb_mouse.h> 41 #include <asm/processor.h> 43 #if defined(__mc68000__) || defined(MODULE) 44 #include <asm/setup.h> 50 static unsigned char adb_mouse_buttons
[16]; 52 externvoid(*adb_mouse_interrupt_hook
)(unsigned char*,int); 53 externint adb_emulate_buttons
; 54 externint adb_button2_keycode
; 55 externint adb_button3_keycode
; 56 externint console_loglevel
; 59 * XXX: need to figure out what ADB mouse packets mean ... 60 * This is the stuff stolen from the Atari driver ... 62 static voidadb_mouse_interrupt(unsigned char*buf
,int nb
) 68 Handler 1 -- 100cpi original Apple mouse protocol. 69 Handler 2 -- 200cpi original Apple mouse protocol. 71 For Apple's standard one-button mouse protocol the data array will 72 contain the following values: 75 data[0] = dddd 1100 ADB command: Talk, register 0, for device dddd. 76 data[1] = bxxx xxxx First button and x-axis motion. 77 data[2] = byyy yyyy Second button and y-axis motion. 79 Handler 4 -- Apple Extended mouse protocol. 81 For Apple's 3-button mouse protocol the data array will contain the 85 data[0] = dddd 1100 ADB command: Talk, register 0, for device dddd. 86 data[1] = bxxx xxxx Left button and x-axis motion. 87 data[2] = byyy yyyy Second button and y-axis motion. 88 data[3] = byyy bxxx Third button and fourth button. 89 Y is additiona. high bits of y-axis motion. 90 X is additional high bits of x-axis motion. 92 'buttons' here means 'button down' states! 93 Button 1 (left) : bit 2, busmouse button 3 94 Button 2 (right) : bit 0, busmouse button 1 95 Button 3 (middle): bit 1, busmouse button 2 98 /* x/y and buttons swapped */ 100 id
= (buf
[0] >>4) &0xf; 102 buttons
= adb_mouse_buttons
[id
]; 104 /* button 1 (left, bit 2) */ 105 buttons
= (buttons
&3) | (buf
[1] &0x80?4:0);/* 1+2 unchanged */ 107 /* button 2 (middle) */ 108 buttons
= (buttons
&5) | (buf
[2] &0x80?2:0);/* 2+3 unchanged */ 110 /* button 3 (right) present? 111 * on a logitech mouseman, the right and mid buttons sometimes behave 112 * strangely until they both have been pressed after booting. */ 113 /* data valid only if extended mouse format ! */ 115 buttons
= (buttons
&6) | (buf
[3] &0x80?1:0);/* 1+3 unchanged */ 117 adb_mouse_buttons
[id
] = buttons
; 119 /* a button is down if it is down on any mouse */ 120 for(id
=0; id
<16; ++id
) 121 buttons
&= adb_mouse_buttons
[id
]; 123 dx
= ((buf
[2] &0x7f) <64? (buf
[2] &0x7f) : (buf
[2] &0x7f) -128); 124 dy
= ((buf
[1] &0x7f) <64? (buf
[1] &0x7f) : (buf
[1] &0x7f) -128); 125 busmouse_add_movementbuttons(msedev
, dx
, -dy
, buttons
); 127 if(console_loglevel
>=8) 128 printk(" %X %X %X dx %d dy %d\n", 129 buf
[1], buf
[2], buf
[3], dx
, dy
); 132 static intrelease_mouse(struct inode
*inode
,struct file
*file
) 134 adb_mouse_interrupt_hook
= NULL
; 139 static intopen_mouse(struct inode
*inode
,struct file
*file
) 142 adb_mouse_interrupt_hook
= adb_mouse_interrupt
; 146 static struct busmouse adb_mouse
= 148 ADB_MOUSE_MINOR
,"adbmouse", open_mouse
, release_mouse
,7 151 int __init
adb_mouse_init(void) 154 if((_machine
!= _MACH_chrp
) && (_machine
!= _MACH_Pmac
)) 162 msedev
=register_busmouse(&adb_mouse
); 164 printk(KERN_WARNING
"Unable to register ADB mouse driver.\n"); 166 printk(KERN_INFO
"Macintosh ADB mouse driver installed.\n"); 168 return msedev
<0? msedev
:0; 172 * XXX this function is misnamed. 173 * It is called if the kernel is booted with the adb_buttons=xxx 174 * option, which is about using ADB keyboard buttons to emulate 175 * mouse buttons. -- paulus 177 static int __init
adb_mouse_setup(char*str
) 181 str
=get_options(str
,ARRAY_SIZE(ints
), ints
); 183 adb_emulate_buttons
= ints
[1]; 185 adb_button2_keycode
= ints
[2]; 187 adb_button3_keycode
= ints
[3]; 192 __setup("adb_buttons=", adb_mouse_setup
); 197 returnadb_mouse_init(); 200 voidcleanup_module(void) 202 unregister_busmouse(msedev
);