diff options
Diffstat (limited to 'sys')
-rw-r--r-- | sys/dev/acpi/acpithinkpad.c | 349 |
1 files changed, 157 insertions, 192 deletions
diff --git a/sys/dev/acpi/acpithinkpad.c b/sys/dev/acpi/acpithinkpad.c index 343b948d2a2..9ffdf0299d4 100644 --- a/sys/dev/acpi/acpithinkpad.c +++ b/sys/dev/acpi/acpithinkpad.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpithinkpad.c,v 1.20 2009/04/26 02:59:05 cnst Exp $ */ +/* $OpenBSD: acpithinkpad.c,v 1.21 2009/09/14 23:19:59 fgsch Exp $ */ /* * Copyright (c) 2008 joshua stein <jcs@openbsd.org> * @@ -39,41 +39,34 @@ #define THINKPAD_WAN_PRESENT 0x01 #define THINKPAD_WAN_ENABLED 0x02 -/* type 1 events */ -#define THINKPAD_BUTTON_FN_F1 0x001 -#define THINKPAD_BUTTON_LOCK_SCREEN 0x002 -#define THINKPAD_BUTTON_BATTERY_INFO 0x003 -#define THINKPAD_BUTTON_SUSPEND 0x004 -#define THINKPAD_BUTTON_WIRELESS 0x005 -#define THINKPAD_BUTTON_FN_F6 0x006 -#define THINKPAD_BUTTON_EXTERNAL_SCREEN 0x007 -#define THINKPAD_BUTTON_POINTER_SWITCH 0x008 -#define THINKPAD_BUTTON_EJECT 0x009 -#define THINKPAD_BUTTON_BRIGHTNESS_UP 0x010 -#define THINKPAD_BUTTON_BRIGHTNESS_DOWN 0x011 -#define THINKPAD_BUTTON_THINKLIGHT 0x012 -#define THINKPAD_BUTTON_FN_SPACE 0x014 -#define THINKPAD_BUTTON_VOLUME_UP 0x015 -#define THINKPAD_BUTTON_VOLUME_DOWN 0x016 -#define THINKPAD_BUTTON_VOLUME_MUTE 0x017 -#define THINKPAD_BUTTON_THINKVANTAGE 0x018 -#define THINKPAD_BUTTON_FN_F11 0x00b -#define THINKPAD_BUTTON_HIBERNATE 0x00c - -/* type 5 events */ -#define THINKPAD_LID_OPEN 0x001 -#define THINKPAD_LID_CLOSED 0x002 -#define THINKPAD_TABLET_SCREEN_NORMAL 0x00a -#define THINKPAD_TABLET_SCREEN_ROTATED 0x009 -#define THINKPAD_BRIGHTNESS_CHANGED 0x010 -#define THINKPAD_TABLET_PEN_INSERTED 0x00b -#define THINKPAD_TABLET_PEN_REMOVED 0x00c - -/* type 6 events */ -#define THINKPAD_POWER_CHANGED 0x030 - -/* type 7 events */ -#define THINKPAD_SWITCH_WIRELESS 0x000 +#define THINKPAD_BUTTON_FN_F1 0x1001 +#define THINKPAD_BUTTON_LOCK_SCREEN 0x1002 +#define THINKPAD_BUTTON_BATTERY_INFO 0x1003 +#define THINKPAD_BUTTON_SUSPEND 0x1004 +#define THINKPAD_BUTTON_WIRELESS 0x1005 +#define THINKPAD_BUTTON_FN_F6 0x1006 +#define THINKPAD_BUTTON_EXTERNAL_SCREEN 0x1007 +#define THINKPAD_BUTTON_POINTER_SWITCH 0x1008 +#define THINKPAD_BUTTON_EJECT 0x1009 +#define THINKPAD_BUTTON_BRIGHTNESS_UP 0x1010 +#define THINKPAD_BUTTON_BRIGHTNESS_DOWN 0x1011 +#define THINKPAD_BUTTON_THINKLIGHT 0x1012 +#define THINKPAD_BUTTON_FN_SPACE 0x1014 +#define THINKPAD_BUTTON_VOLUME_UP 0x1015 +#define THINKPAD_BUTTON_VOLUME_DOWN 0x1016 +#define THINKPAD_BUTTON_VOLUME_MUTE 0x1017 +#define THINKPAD_BUTTON_THINKVANTAGE 0x1018 +#define THINKPAD_BUTTON_FN_F11 0x100b +#define THINKPAD_BUTTON_HIBERNATE 0x100c +#define THINKPAD_LID_OPEN 0x5001 +#define THINKPAD_LID_CLOSED 0x5002 +#define THINKPAD_TABLET_SCREEN_NORMAL 0x500a +#define THINKPAD_TABLET_SCREEN_ROTATED 0x5009 +#define THINKPAD_BRIGHTNESS_CHANGED 0x5010 +#define THINKPAD_TABLET_PEN_INSERTED 0x500b +#define THINKPAD_TABLET_PEN_REMOVED 0x500c +#define THINKPAD_POWER_CHANGED 0x6030 +#define THINKPAD_SWITCH_WIRELESS 0x7000 #define THINKPAD_NSENSORS 9 #define THINKPAD_NTEMPSENSORS 8 @@ -82,14 +75,14 @@ #define THINKPAD_ECOFFSET_FANHI 0x85 struct acpithinkpad_softc { - struct device sc_dev; + struct device sc_dev; struct acpiec_softc *sc_ec; struct acpi_softc *sc_acpi; struct aml_node *sc_devnode; - struct ksensor sc_sens[THINKPAD_NSENSORS]; - struct ksensordev sc_sensdev; + struct ksensor sc_sens[THINKPAD_NSENSORS]; + struct ksensordev sc_sensdev; }; extern void acpiec_read(struct acpiec_softc *, u_int8_t, int, u_int8_t *); @@ -124,9 +117,8 @@ int thinkpad_match(struct device *parent, void *match, void *aux) { struct acpi_attach_args *aa = aux; - struct cfdata *cf = match; - int64_t res; - int rv = 0; + struct cfdata *cf = match; + int64_t res; if (!acpi_matchhids(aa, acpithinkpad_hids, cf->cf_driver->cd_name)) return (0); @@ -135,10 +127,10 @@ thinkpad_match(struct device *parent, void *match, void *aux) "MHKV", 0, NULL, &res)) return (0); - if (res == THINKPAD_HKEY_VERSION) - rv = 1; + if (res != THINKPAD_HKEY_VERSION) + return (0); - return (rv); + return (1); } void @@ -176,7 +168,7 @@ thinkpad_sensor_refresh(void *arg) /* Refresh sensor readings */ for (i=0; i<THINKPAD_NTEMPSENSORS; i++) { snprintf(sname, sizeof(sname), "TMP%d", i); - aml_evalinteger(sc->sc_acpi, sc->sc_ec->sc_devnode, + aml_evalinteger(sc->sc_acpi, sc->sc_ec->sc_devnode, sname, 0, 0, &tmp); sc->sc_sens[i].value = (tmp * 1000000) + 273150000; if (tmp > 127 || tmp < -127) @@ -200,11 +192,11 @@ thinkpad_attach(struct device *parent, struct device *self, void *aux) printf("\n"); - /* set event mask to receive everything */ + /* Set event mask to receive everything */ thinkpad_enable_events(sc); thinkpad_sensor_attach(sc); - /* run thinkpad_hotkey on button presses */ + /* Run thinkpad_hotkey on button presses */ aml_register_notify(sc->sc_devnode, aa->aaa_dev, thinkpad_hotkey, sc, ACPIDEV_POLL); } @@ -212,226 +204,199 @@ thinkpad_attach(struct device *parent, struct device *self, void *aux) int thinkpad_enable_events(struct acpithinkpad_softc *sc) { - struct aml_value arg, args[2]; - int64_t mask; - int i, rv = 1; + struct aml_value arg, args[2]; + int64_t mask; + int i; - /* get the supported event mask */ - if (aml_evalinteger(sc->sc_acpi, sc->sc_devnode, "MHKA", 0, NULL, &mask)) { + /* Get the supported event mask */ + if (aml_evalinteger(sc->sc_acpi, sc->sc_devnode, "MHKA", + 0, NULL, &mask)) { printf("%s: no MHKA\n", DEVNAME(sc)); - goto fail; + return (1); } - /* update hotkey mask */ + /* Update hotkey mask */ bzero(args, sizeof(args)); args[0].type = args[1].type = AML_OBJTYPE_INTEGER; for (i = 0; i < 32; i++) { args[0].v_integer = i + 1; args[1].v_integer = (((1 << i) & mask) != 0); - if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "MHKM", 2, args, - NULL)) { + if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "MHKM", + 2, args, NULL)) { printf("%s: couldn't toggle MHKM\n", DEVNAME(sc)); - goto fail; + return (1); } } - /* enable hotkeys */ + /* Enable hotkeys */ bzero(&arg, sizeof(arg)); arg.type = AML_OBJTYPE_INTEGER; arg.v_integer = 1; - if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "MHKC", 1, &arg, NULL)) { + if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "MHKC", + 1, &arg, NULL)) { printf("%s: couldn't enable hotkeys\n", DEVNAME(sc)); - goto fail; + return (1); } - rv = 0; -fail: - return (rv); + return (0); } int thinkpad_hotkey(struct aml_node *node, int notify_type, void *arg) { struct acpithinkpad_softc *sc = arg; - int type, event, handled, rv = 1, tot = 0; - int64_t val; + int handled = 0; + int64_t event; if (notify_type == 0x00) { - /* poll sensors */ + /* Poll sensors */ thinkpad_sensor_refresh(sc); - return 0; + return (0); } + if (notify_type != 0x80) - goto fail; + return (1); for (;;) { - if (aml_evalinteger(sc->sc_acpi, sc->sc_devnode, "MHKP", 0, NULL, - &val)) - goto done; - if (val == 0) - goto done; - - type = (val & 0xf000) >> 12; - event = val & 0x0fff; - handled = 0; - - switch (type) { - case 1: - switch (event) { - case THINKPAD_BUTTON_BRIGHTNESS_UP: - thinkpad_brightness_up(sc); - handled = 1; - break; - case THINKPAD_BUTTON_BRIGHTNESS_DOWN: - thinkpad_brightness_down(sc); - handled = 1; - break; - case THINKPAD_BUTTON_WIRELESS: - thinkpad_toggle_bluetooth(sc); - handled = 1; - break; - case THINKPAD_BUTTON_SUSPEND: - handled = 1; - /* - acpi_enter_sleep_state(sc->sc_acpi, - ACPI_STATE_S3); - */ - break; - case THINKPAD_BUTTON_HIBERNATE: - case THINKPAD_BUTTON_FN_F1: - case THINKPAD_BUTTON_LOCK_SCREEN: - case THINKPAD_BUTTON_BATTERY_INFO: - case THINKPAD_BUTTON_FN_F6: - case THINKPAD_BUTTON_EXTERNAL_SCREEN: - case THINKPAD_BUTTON_POINTER_SWITCH: - case THINKPAD_BUTTON_EJECT: - case THINKPAD_BUTTON_THINKLIGHT: - case THINKPAD_BUTTON_FN_SPACE: - handled = 1; - break; - case THINKPAD_BUTTON_VOLUME_DOWN: - thinkpad_volume_down(sc); - handled = 1; - break; - case THINKPAD_BUTTON_VOLUME_UP: - thinkpad_volume_up(sc); - handled = 1; - break; - case THINKPAD_BUTTON_VOLUME_MUTE: - thinkpad_volume_mute(sc); - handled = 1; - break; - case THINKPAD_BUTTON_THINKVANTAGE: - case THINKPAD_BUTTON_FN_F11: - handled = 1; - break; - } + if (aml_evalinteger(sc->sc_acpi, sc->sc_devnode, "MHKP", + 0, NULL, &event)) + break; + if (event == 0) + break; + + switch (event) { + case THINKPAD_BUTTON_BRIGHTNESS_UP: + thinkpad_brightness_up(sc); + handled = 1; + break; + case THINKPAD_BUTTON_BRIGHTNESS_DOWN: + thinkpad_brightness_down(sc); + handled = 1; + break; + case THINKPAD_BUTTON_WIRELESS: + thinkpad_toggle_bluetooth(sc); + handled = 1; + break; + case THINKPAD_BUTTON_SUSPEND: + handled = 1; + /* + acpi_enter_sleep_state(sc->sc_acpi, + ACPI_STATE_S3); + */ + break; + case THINKPAD_BUTTON_HIBERNATE: + case THINKPAD_BUTTON_FN_F1: + case THINKPAD_BUTTON_LOCK_SCREEN: + case THINKPAD_BUTTON_BATTERY_INFO: + case THINKPAD_BUTTON_FN_F6: + case THINKPAD_BUTTON_EXTERNAL_SCREEN: + case THINKPAD_BUTTON_POINTER_SWITCH: + case THINKPAD_BUTTON_EJECT: + case THINKPAD_BUTTON_THINKLIGHT: + case THINKPAD_BUTTON_FN_SPACE: + handled = 1; break; - case 5: - switch (event) { - case THINKPAD_LID_OPEN: - case THINKPAD_LID_CLOSED: - case THINKPAD_TABLET_SCREEN_NORMAL: - case THINKPAD_TABLET_SCREEN_ROTATED: - case THINKPAD_BRIGHTNESS_CHANGED: - case THINKPAD_TABLET_PEN_INSERTED: - case THINKPAD_TABLET_PEN_REMOVED: - handled = 1; - break; - } + case THINKPAD_BUTTON_VOLUME_MUTE: + thinkpad_volume_mute(sc); + handled = 1; break; - case 6: - switch (event) { - case THINKPAD_POWER_CHANGED: - handled = 1; - break; - } + case THINKPAD_BUTTON_VOLUME_DOWN: + thinkpad_volume_down(sc); + handled = 1; break; - case 7: - switch (event) { - case THINKPAD_SWITCH_WIRELESS: - handled = 1; - break; - } + case THINKPAD_BUTTON_VOLUME_UP: + thinkpad_volume_up(sc); + handled = 1; break; + case THINKPAD_BUTTON_THINKVANTAGE: + case THINKPAD_BUTTON_FN_F11: + handled = 1; + break; + case THINKPAD_LID_OPEN: + case THINKPAD_LID_CLOSED: + case THINKPAD_TABLET_SCREEN_NORMAL: + case THINKPAD_TABLET_SCREEN_ROTATED: + case THINKPAD_BRIGHTNESS_CHANGED: + case THINKPAD_TABLET_PEN_INSERTED: + case THINKPAD_TABLET_PEN_REMOVED: + handled = 1; + break; + case THINKPAD_POWER_CHANGED: + handled = 1; + break; + case THINKPAD_SWITCH_WIRELESS: + handled = 1; + break; + default: + printf("%s: unknown event 0x%03x\n", + DEVNAME(sc), event); } - - if (handled) - tot++; - else - printf("%s: unknown type %d event 0x%03x\n", - DEVNAME(sc), type, event); } -done: - if (tot) - rv = 0; -fail: - return (rv); + + return (handled); } int thinkpad_toggle_bluetooth(struct acpithinkpad_softc *sc) { - struct aml_value arg; - int rv = 1; - int64_t bluetooth; + struct aml_value arg; + int64_t bluetooth; - if (aml_evalinteger(sc->sc_acpi, sc->sc_devnode, "GBDC", 0, NULL, &bluetooth)) - goto fail; + if (aml_evalinteger(sc->sc_acpi, sc->sc_devnode, "GBDC", + 0, NULL, &bluetooth)) + return (1); if (!(bluetooth & THINKPAD_BLUETOOTH_PRESENT)) - goto fail; + return (1); bzero(&arg, sizeof(arg)); arg.type = AML_OBJTYPE_INTEGER; - arg.v_integer = bluetooth ^= THINKPAD_BLUETOOTH_ENABLED; - if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "SBDC", 1, &arg, NULL)) { + arg.v_integer = bluetooth ^ THINKPAD_BLUETOOTH_ENABLED; + if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "SBDC", + 1, &arg, NULL)) { printf("%s: couldn't toggle bluetooth\n", DEVNAME(sc)); - goto fail; + return (1); } - rv = 0; -fail: - return (rv); + return (0); } int thinkpad_toggle_wan(struct acpithinkpad_softc *sc) { - struct aml_value arg; - int rv = 1; - int64_t wan; + struct aml_value arg; + int64_t wan; - if (aml_evalinteger(sc->sc_acpi, sc->sc_devnode, "GWAN", 0, NULL, &wan)) - goto fail; + if (aml_evalinteger(sc->sc_acpi, sc->sc_devnode, "GWAN", + 0, NULL, &wan)) + return (1); if (!(wan & THINKPAD_WAN_PRESENT)) - goto fail; + return (1); bzero(&arg, sizeof(arg)); arg.type = AML_OBJTYPE_INTEGER; - arg.v_integer = (wan ^= THINKPAD_WAN_ENABLED); - if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "SWAN", 1, &arg, NULL)) { + arg.v_integer = wan ^ THINKPAD_WAN_ENABLED; + if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "SWAN", + 1, &arg, NULL)) { printf("%s: couldn't toggle wan\n", DEVNAME(sc)); - goto fail; + return (1); } - rv = 0; -fail: - return (rv); + return (0); } int thinkpad_cmos(struct acpithinkpad_softc *sc, uint8_t cmd) { - struct aml_value arg; + struct aml_value arg; bzero(&arg, sizeof(arg)); arg.type = AML_OBJTYPE_INTEGER; arg.v_integer = cmd; - if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "\\UCMS", 1, &arg, - NULL)) { + if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "\\UCMS", + 1, &arg, NULL)) { printf("%s: cmos command 0x%x failed\n", DEVNAME(sc), cmd); return (1); } |