Subject: Missing keyboard on iBook G4: patch review
To: None <port-macppc@netbsd.org>
From: Emmanuel Dreyfus <manu@netbsd.org>
List: port-macppc
Date: 05/31/2004 21:06:14
Hello

I've investigated a bit deeper the missing keyboard on iBook G4. 
I found that the keyboard was detected as USB, where it's an ADB keyboard.

Everything happens in machdep.c, where we assume that if the keyboard name in OF
is adb then it's ADB, else it's USB. That's wrong.

On the iBook G4's OF? the keyboard is peudo-hid (not puedo-hid), and there is no
word nor any property available: no way to tell if it's ADB or USB.

The following patch causes wscons to consider the keyboard as part of the
console. That still does not work (except in ddb), but I assume that caling
akbd_attach is mandatory if we want to get beyond.

Someone has some coments about this patch? Should it be committed?

Index: machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/macppc/macppc/machdep.c,v
retrieving revision 1.131
diff -U4 -r1.131 machdep.c
--- machdep.c   1 Apr 2004 16:57:45 -0000       1.131
+++ machdep.c   31 May 2004 18:45:23 -0000
@@ -525,44 +525,71 @@
 
 #if NAKBD > 0
        memset(name, 0, sizeof(name));
        OF_getprop(OF_parent(node), "name", name, sizeof(name));
        if (strcmp(name, "adb") == 0) {
                printf("console keyboard type: ADB\n");
                akbd_cnattach();
                goto kbd_found;
        }
 #endif
 
        /*
-        * We're not an ADB keyboard; must be USB.  Unfortunately,
-        * we have a few problems:
+        * It is not obviously an ADB keyboard. Could be USB,
+        * or ADB on some firmware versions (e.g.: iBook G4)
+        * This is not enough, we have a few more problems:
         *
         *      (1) The stupid Macintosh firmware uses a
-        *          `psuedo-hid' (yes, they even spell it
-        *          incorrectly!) which apparently merges
-        *          all USB keyboard input into a single
-        *          input stream.  Because of this, we can't
-        *          actually determine which USB controller
-        *          or keyboard is really the console keyboard!
-        *
-        *      (2) Even if we could, USB requires a lot of
-        *          the kernel to be running in order for it
-        *          to work.
+        *          `psuedo-hid' (no typo) or `pseudo-hid',  
+        *          which apparently merges all keyboards 
+        *          input into a single input stream.  
+        *          Because of this, we can't actually 
+        *          determine which controller or keyboard 
+        *          is really the console keyboard!
+        *
+        *      (2) Even if we could, the keyboard can be USB,
+        *          and this requires a lot of the kernel to 
+        *          be running in order for it to work.
         *
         * So, what we do is this:
         *
-        *      (1) Tell the ukbd driver that it is the console.
+        *      (1) First check for OpenFirmware implementation
+        *          that will not let us distinguish between 
+        *          USB and ADB. In that situation, try attaching 
+        *          anything as we can, and hope things get better 
+        *          at autoconfiguration time.
+        *
+        *      (2) Assume the keyboard is USB.
+        *          Tell the ukbd driver that it is the console.
         *          At autoconfiguration time, it will attach the
         *          first USB keyboard instance as the console
         *          keyboard.
         *
-        *      (2) Until then, so that we have _something_, we
+        *      (3) Until then, so that we have _something_, we
         *          use the OpenFirmware I/O facilities to read
         *          the keyboard.
         */
 
        /*
+        * stdin is /pseudo-hid/keyboard.  There is no 
+        * `adb-kbd-ihandle or `usb-kbd-ihandles methods
+        * available. Try attaching anything.
+        *
+        * XXX This must be called before pmap_bootstrap().
+        */
+       if (strcmp(name, "pseudo-hid") == 0) {
+               printf("console keyboard type: unknown\n");
+#if NAKBD > 0
+               akbd_cnattach();
+#endif
+#if NUKBD > 0
+               ukbd_cnattach();
+#endif
+               goto kbd_found;
+       }
+
+       /*
         * stdin is /psuedo-hid/keyboard.  Test `adb-kbd-ihandle and
         * `usb-kbd-ihandles to figure out the real keyboard(s).
         *
         * XXX This must be called before pmap_bootstrap().
@@ -602,8 +632,9 @@
        /*
         * XXX Old firmware does not have `usb-kbd-ihandles method.  Assume
         * XXX USB keyboard anyway.
         */
+       printf("defaulting to USB...");
        printf("console keyboard type: USB\n");
        ukbd_cnattach();
        goto kbd_found;
 #endif

-- 
Emmanuel Dreyfus
Il y a 10 sortes de personnes dans le monde: ceux qui comprennent 
le binaire et ceux qui ne le comprennent pas.
manu@netbsd.org