/*
* Copyright (C) 1998 Colin Wood
* Copyright (C) 2006, 2007 Michael Lorenz
* All rights reserved.
*
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Colin Wood.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
sc->sc_leds = 0; /* initially off */
sc->sc_have_led_control = 0;
/*
* If this is != 0 then pushing the power button will not immadiately
* send a shutdown event to sysmon but instead require another key
* press within 5 seconds with a gap of at least two seconds. The
* reason to do this is the fact that some PowerBook keyboards,
* like the 2400, 3400 and original G3 have their power buttons
* right next to the backspace key and it's extremely easy to hit
* it by accident.
* On most other keyboards the power button is sufficiently far out
* of the way so we don't need this.
*/
sc->sc_power_button_delay = 0;
sc->sc_msg_len = 0;
sc->sc_poll = 0;
sc->sc_capslock = 0;
sc->sc_trans[1] = 103; /* F11 */
sc->sc_trans[2] = 111; /* F12 */
/*
* Most ADB keyboards send 0x7f 0x7f when the power button is pressed.
* Some older PowerBooks, like the 3400c, will send a single scancode
* 0x7e instead. Unfortunately Fn-Command on some more recent *Books
* sends the same scancode, so by default sc_power is set to a value
* that can't occur as a scancode and only set to 0x7e on hardware that
* needs it
*/
sc->sc_power = 0xffff;
sc->sc_timestamp = 0;
sc->sc_emul_usb = ADB_EMUL_USB_NONE;
#ifdef ADBKBD_POWER_DDB
sc->sc_power_dbg = TRUE;
#else
sc->sc_power_dbg = FALSE;
#endif
switch (sc->sc_adbdev->handler_id) {
case ADB_STDKBD:
aprint_normal("standard keyboard\n");
break;
case ADB_ISOKBD:
aprint_normal("standard keyboard (ISO layout)\n");
break;
case ADB_EXTKBD:
cmd = ADBTALK(sc->sc_adbdev->current_addr, 1);
sc->sc_msg_len = 0;
sc->sc_ops->send(sc->sc_ops->cookie, sc->sc_poll, cmd, 0, NULL);
adbkbd_wait(sc, 10);
/* Ignore Logitech MouseMan/Trackman pseudo keyboard */
/* XXX needs testing */
if (sc->sc_buffer[2] == 0x9a && sc->sc_buffer[3] == 0x20) {
aprint_normal("Mouseman (non-EMP) pseudo keyboard\n");
return;
} else if (sc->sc_buffer[2] == 0x9a &&
sc->sc_buffer[3] == 0x21) {
aprint_normal("Trackman (non-EMP) pseudo keyboard\n");
return;
} else {
aprint_normal("extended keyboard\n");
adbkbd_initleds(sc);
}
break;
case ADB_EXTISOKBD:
aprint_normal("extended keyboard (ISO layout)\n");
adbkbd_initleds(sc);
break;
case ADB_KBDII:
aprint_normal("keyboard II\n");
break;
case ADB_ISOKBDII:
aprint_normal("keyboard II (ISO layout)\n");
break;
case ADB_PBKBD:
aprint_normal("PowerBook keyboard\n");
sc->sc_power = 0x7e;
sc->sc_power_button_delay = 1;
break;
case ADB_PBISOKBD:
aprint_normal("PowerBook keyboard (ISO layout)\n");
sc->sc_power = 0x7e;
sc->sc_power_button_delay = 1;
break;
case ADB_ADJKPD:
aprint_normal("adjustable keypad\n");
break;
case ADB_ADJKBD:
aprint_normal("adjustable keyboard\n");
break;
case ADB_ADJISOKBD:
aprint_normal("adjustable keyboard (ISO layout)\n");
break;
case ADB_ADJJAPKBD:
aprint_normal("adjustable keyboard (Japanese layout)\n");
break;
case ADB_PBEXTISOKBD:
aprint_normal("PowerBook extended keyboard (ISO layout)\n");
sc->sc_power_button_delay = 1;
sc->sc_power = 0x7e;
break;
case ADB_PBEXTJAPKBD:
aprint_normal("PowerBook extended keyboard (Japanese layout)\n");
sc->sc_power_button_delay = 1;
sc->sc_power = 0x7e;
break;
case ADB_JPKBDII:
aprint_normal("keyboard II (Japanese layout)\n");
break;
case ADB_PBEXTKBD:
aprint_normal("PowerBook extended keyboard\n");
sc->sc_power_button_delay = 1;
sc->sc_power = 0x7e;
break;
case ADB_DESIGNKBD:
aprint_normal("extended keyboard\n");
adbkbd_initleds(sc);
break;
case ADB_PBJPKBD:
aprint_normal("PowerBook keyboard (Japanese layout)\n");
sc->sc_power_button_delay = 1;
sc->sc_power = 0x7e;
break;
case ADB_PBG3KBD:
aprint_normal("PowerBook G3 keyboard\n");
break;
case ADB_PBG3JPKBD:
aprint_normal("PowerBook G3 keyboard (Japanese layout)\n");
break;
case ADB_IBOOKKBD:
aprint_normal("iBook keyboard\n");
break;
default:
aprint_normal("mapped device (%d)\n", sc->sc_adbdev->handler_id);
break;
}
/*
* try to switch to extended protocol
* as in, tell the keyboard to distinguish between left and right
* Shift, Control and Alt keys
*/
cmd = ADBLISTEN(sc->sc_adbdev->current_addr, 3);
buffer[0] = sc->sc_adbdev->current_addr;
buffer[1] = 3;
sc->sc_msg_len = 0;
sc->sc_ops->send(sc->sc_ops->cookie, sc->sc_poll, cmd, 2, buffer);
adbkbd_wait(sc, 10);
/*
* Set the keyboard LED's.
*
* Automatically translates from ioctl/softc format to the
* actual keyboard register format
*/
static void
adbkbd_set_leds(void *cookie, int leds)
{
struct adbkbd_softc *sc = cookie;
int aleds;
short cmd;
uint8_t buffer[2];