diff -ru linux-2.1.103/arch/ppc/config.in linux-2.1.103-macx-mouse/arch/ppc/config.in --- linux-2.1.103/arch/ppc/config.in Sun May 31 20:04:16 1998 +++ linux-2.1.103-macx-mouse/arch/ppc/config.in Tue Sep 8 22:19:07 1998 @@ -107,6 +107,10 @@ bool 'Support for PowerMac serial ports' CONFIG_MAC_SERIAL if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then bool 'Support for PowerMac mouse (EXPERIMENTAL)' CONFIG_MACMOUSE + bool 'Support for MacX 3 Button mouse (EXPERIMENTAL)' CONFIG_MACX_MOUSE + if [ "$CONFIG_MACX_MOUSE" = "y" ]; then + bool 'MacX mouse driver printk debugging' CONFIG_MACX_MOUSE_DEBUG + fi fi bool 'Support for Open Firmware device tree in /proc' CONFIG_PROC_DEVICETREE bool 'Include kgdb kernel debugger' CONFIG_KGDB diff -ru linux-2.1.103/arch/ppc/pmac_defconfig linux-2.1.103-macx-mouse/arch/ppc/pmac_defconfig --- linux-2.1.103/arch/ppc/pmac_defconfig Sun May 31 19:59:55 1998 +++ linux-2.1.103-macx-mouse/arch/ppc/pmac_defconfig Thu Sep 3 16:56:04 1998 @@ -41,6 +41,7 @@ CONFIG_MAC_FLOPPY=y CONFIG_MAC_SERIAL=y CONFIG_MACMOUSE=y +# CONFIG_MACX_MOUSE is not set CONFIG_PROC_DEVICETREE=y # CONFIG_KGDB is not set # CONFIG_XMON is not set diff -ru linux-2.1.103/drivers/macintosh/adb.c linux-2.1.103-macx-mouse/drivers/macintosh/adb.c --- linux-2.1.103/drivers/macintosh/adb.c Mon May 4 22:55:55 1998 +++ linux-2.1.103-macx-mouse/drivers/macintosh/adb.c Tue Sep 8 17:13:02 1998 @@ -185,22 +185,73 @@ { int i; + int dump = 0; + +/* DKH:9/98 -- RETHINK THE LOGIC FOR THIS FUNCTION.... DOESN'T FEEL RIGHT */ + ids->nids = 0; for (i = 1; i < 16; i++) { if ((adb_handler[i].original_address == default_id) || (adb_handler[i].handler_id == handler_id)) { if (adb_handler[i].handler != 0) { - printk(KERN_ERR - "Two handlers for ADB device %d\n", - default_id); - return 0; + printk(KERN_ERR "Replacing old ADB handler for device %d\n", i); + dump = 1; } adb_handler[i].handler = handler; ids->id[ids->nids++] = i; } } +#ifdef CONFIG_MACX_MOUSE_DEBUG + /* DKH:9/98 -- Dump out all of the adb information */ + + /* THIS SHOULD REALLY BE A PROC FILE AS WELL */ + + if ( dump ) + { + int j; + printk("address orig address handler_id handler \n"); + for ( j = 1 ; j < 16 ; j++ ){ + printk("%d ",j); + printk("%d ",adb_handler[j].original_address); + printk("%d ",adb_handler[j].handler_id); + printk("0x%x\n",adb_handler[j].handler); + } + } +#endif + + return 1; +} + + +/* DKH:9/98 -- Allow specific individual handlers to be swapped + We want to be able to have multiple "keyboards" that use different + handler functions to allow the MacX mice to function. + + CHECK: Is adb_ids being used properly in this case? */ +int +adb_register_by_id(int id, struct adb_ids *ids, + void (*handler)(unsigned char *, int, struct pt_regs *, int)) +{ + if ( id < 1 || id > 15 ) + return 0; + ids->nids = 0; + adb_handler[id].handler = handler; + ids->id[ids->nids++] = id; +#ifdef CONFIG_MACX_MOUSE_DEBUG + { + int j; + printk("address orig address handler_id handler \n"); + for ( j = 1 ; j < 16 ; j++ ){ + printk("%d ",j); + printk("%d ",adb_handler[j].original_address); + printk("%d ",adb_handler[j].handler_id); + printk("0x%x\n",adb_handler[j].handler); + } + } +#endif /*CONFIG_MACX_MOUSE_DEBUG*/ return 1; } + void adb_input(unsigned char *buf, int nb, struct pt_regs *regs, int autopoll) diff -ru linux-2.1.103/drivers/macintosh/mac_keyb.c linux-2.1.103-macx-mouse/drivers/macintosh/mac_keyb.c --- linux-2.1.103/drivers/macintosh/mac_keyb.c Mon May 18 21:09:27 1998 +++ linux-2.1.103-macx-mouse/drivers/macintosh/mac_keyb.c Sat Sep 19 20:57:59 1998 @@ -176,6 +176,12 @@ static int adb_emulate_buttons = 0; extern int console_loglevel; +#ifdef CONFIG_MACX_MOUSE +/* DKH:9/98 -- State variables for the MacX mouse */ +static unsigned char macx_middle_button = 0x7f; +static unsigned char macx_right_button = 0x7f; +#endif /*CONFIG_MACX_MOUSE*/ + extern struct kbd_struct kbd_table[]; extern void handle_scancode(unsigned char); @@ -247,6 +253,65 @@ input_keycode(data[2], 0); } +#ifdef CONFIG_MACX_MOUSE +/* DKH:9/98 -- Take care of the fake keyboard that the middle and right buttons + of the MacX mouse act like*/ +static void +fake_keyboard_input(unsigned char *data, int nb, struct pt_regs *regs, int apoll) +{ +/* This does not work with the adb mouse driver right now */ +/* + if (adb_mouse_interrupt_hook) + adb_mouse_interrupt_hook(data, nb); +*/ + + if (nb != 3 || (data[0] & 3) != KEYB_KEYREG) + return; + kbd_pt_regs = regs; + + /* If it's not the mouse, re-register as regular keyboard + and call keyboard_input so we don't loose this keystroke (HACK)*/ + switch(data[1]){ + case 0x3b: + macx_middle_button = 0xff; + put_queue( 0x3f ); + break; + case 0xbb: + macx_middle_button = 0x7f; + put_queue( 0xbf ); + break; + case 0x3c: + macx_right_button = 0xff; + put_queue( 0x40 ); + break; + case 0xbc: + macx_right_button = 0x7f; + put_queue( 0xc0 ); + break; + default: +#ifdef CONFIG_MACX_MOUSE_DEBUG + printk("Whoops, looks like this isn't the MacX mouse.\n"); +#endif + adb_register_by_id( data[0]>>4 , &keyboard_ids, keyboard_input); + keyboard_input(data, nb, regs, apoll); + return; + } + +#ifdef CONFIG_MACX_MOUSE_DEBUG + { + int i, id; + printk("Fake keyboard input of keycode 0x%x\n",data[1]); + + id = data[0] >> 4; + printk("adb packet: "); + for (i = 0; i < nb; ++i) + printk(" %x", data[i]); + printk(", id = %d\n", id); + } +#endif /*CONFIG_MACX_MOUSE_DEBUG*/ +} +#endif /*CONFIG_MACX_MOUSE*/ + static void input_keycode(int keycode, int repeat) { @@ -496,6 +561,73 @@ } } +#ifdef CONFIG_MACX_MOUSE +static void +macx_mouse_input(unsigned char *data, int nb, struct pt_regs *regs, int autopoll) +{ + struct kbd_struct *kbd; + + /* Store the button states in data */ + data[2] = data[2] & macx_middle_button; + data[3] = data[3] & macx_right_button; + + if (adb_mouse_interrupt_hook) + adb_mouse_interrupt_hook(data, nb); +/* + else + if (console_loglevel == 10) + printk("mouse_input: data %x %x %x buttons %x dx %d dy %d \n", + data[1], data[2], data[3], + ~((data[1] & 0x80 ? 0 : 4) + | (data[2] & 0x80 ? 0 : 1) + | (data[3] & 0x80 ? 0 : 2))&7, + ((data[2]&0x7f) < 64 ? (data[2]&0x7f) : (data[2]&0x7f)-128 ), + ((data[1]&0x7f) < 64 ? -(data[1]&0x7f) : 128-(data[1]&0x7f) ) ); +*/ + kbd = kbd_table + fg_console; + + /* Only send mouse codes when keyboard is in raw mode. */ + if (kbd->kbdmode == VC_RAW) { +/* + static unsigned char uch_ButtonStateSecond = 0x80; + unsigned char uchButtonSecond; +*/ + + /* Send first button, second button and movement. */ + put_queue( 0x7e ); + put_queue( data[1] ); + put_queue( data[2] ); + + /* Store the button state. * + uchButtonSecond = (data[2] & 0x80); + + /* This all seems redundant and inefficient + + /* Send second button. * + if (uchButtonSecond != uch_ButtonStateSecond) { + put_queue( 0x3f | uchButtonSecond ); + uch_ButtonStateSecond = uchButtonSecond; + } + + /* Macintosh 3-button mouse (handler 4). * + if ((nb == 4) && autopoll /*?*) { + static unsigned char uch_ButtonStateThird = 0x80; + unsigned char uchButtonThird; + + /* Store the button state for speed. * + uchButtonThird = (data[3] & 0x80); + + /* Send third button. * + if (uchButtonThird != uch_ButtonStateThird) { + put_queue( 0x40 | uchButtonThird ); + uch_ButtonStateThird = uchButtonThird; + } + } + */ + } +} +#endif /*CONFIG_MACX_MOUSE*/ + /* Map led flags as defined in kbd_kern.h to bits for Apple keyboard. */ static unsigned char mac_ledmap[8] = { 0, /* none */ @@ -574,8 +706,14 @@ /* initialize mouse interrupt hook */ adb_mouse_interrupt_hook = NULL; +#ifndef CONFIG_MACX_MOUSE /*Not sure if this is the best way */ + adb_register(ADB_KEYBOARD, 5, &keyboard_ids, keyboard_input); adb_register(ADB_MOUSE, 1, &mouse_ids, mouse_input); +#else + adb_register(ADB_MOUSE, 3, &mouse_ids, macx_mouse_input); + adb_register(ADB_KEYBOARD, 5, &keyboard_ids, fake_keyboard_input); +#endif for(i = 0; i < keyboard_ids.nids; i++) { /* turn off all leds */ @@ -633,6 +771,11 @@ ADB_WRITEREG(mouse_ids.id[i],1), 03,0x38); } } + +#ifdef CONFIG_MACX_MOUSE_DEBUG_FALSE + panic("Forced panic for CONFIG_MACX_MOUSE_DEBUG"); +#endif + } void adb_setup_mouse( char *s, int *ints )