/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Tim Rightnour
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* We're going to use a display console. Probe for the keyboard
* we'll use.
*/
ofwoea_cnprobe_keyboard();
}
/*
* XXX This routine is a complete disaster, filled with platform-specific
* XXX stuff. Fix, plz.
*/
static void
ofwoea_cnprobe_keyboard(void)
{
extern int ofw_stdin;
int node, kstdin = ofw_stdin;
char name[16];
#if (NAKBD > 0) || (NADBKBD > 0)
int akbd;
#endif
#if NUKBD > 0
struct usb_kbd_ihandles *ukbds;
int ukbd;
#endif
/*
* We must determine which keyboard type we have.
*/
node = OF_instance_to_package(kstdin);
memset(name, 0, sizeof(name));
OF_getprop(node, "name", name, sizeof(name));
if (strcmp(name, "keyboard") != 0) {
ofprint("WARNING: stdin is not a keyboard: %s\n", name);
return;
}
/*
* It is not obviously an ADB/PC 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' (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.
*
* (3) If the keyboard is behind isa, we don't have enough
* kernel setup to use it yet, so punt to the ofroutines.
*
* So, what we do is this:
*
* (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.
*
* (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 as ADB.
* But only if ADB support is actually present.
*
* XXX This must be called before pmap_bootstrap().
*/
if (strcmp(name, "pseudo-hid") == 0) {
int adb_node;
adb_node = OF_finddevice("/pci/mac-io/via-pmu/adb");
if (adb_node > 0) {
ofprint("ADB support found\n");
#if NAKBD > 0
selected_keyboard = akbd_cnattach;
#endif
#if NADBKBD > 0
selected_keyboard = adbkbd_cnattach;
#endif
} else {
/* must be USB */
ofprint("No ADB support present, assuming USB "
"keyboard\n");
#if NUKBD > 0
selected_keyboard = 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().
*/
#if NWSDISPLAY > 0
/*
* XXX This is a little gross, but we don't get to call
* XXX wskbd_cnattach() twice.
*/
wsdisplay_set_cons_kbd(ofkbd_cngetc, NULL, NULL);
#endif
}
}
void
ofwoea_consinit(void)
{
static int initted = 0;