void acpisony_notify_setup(struct acpisony_softc *sc) { struct aml_value arg; bzero(&arg, sizeof(arg)); arg.type = AML_OBJTYPE_INTEGER; arg.v_integer = 1; aml_evalname(sc->sc_acpi, sc->sc_devnode, "ECON", 1, &arg, NULL); /* Enable all events */ arg.v_integer = 0xffff; aml_evalname(sc->sc_acpi, sc->sc_devnode, "SN02", 1, &arg, NULL); /* Enable hotkeys */ arg.v_integer = 0x04; aml_evalname(sc->sc_acpi, sc->sc_devnode, "SN02", 1, &arg, NULL); arg.v_integer = 0x02; aml_evalname(sc->sc_acpi, sc->sc_devnode, "SN07", 1, &arg, NULL); arg.v_integer = 0x10; aml_evalname(sc->sc_acpi, sc->sc_devnode, "SN02", 1, &arg, NULL); arg.v_integer = 0x00; aml_evalname(sc->sc_acpi, sc->sc_devnode, "SN07", 1, &arg, NULL); arg.v_integer = 0x02; aml_evalname(sc->sc_acpi, sc->sc_devnode, "SN03", 1, &arg, NULL); arg.v_integer = 0x101; aml_evalname(sc->sc_acpi, sc->sc_devnode, "SN07", 1, &arg, NULL); }
int thinkpad_adaptive_change(struct acpithinkpad_softc *sc) { struct aml_value arg; int64_t mode; if (aml_evalinteger(sc->sc_acpi, sc->sc_devnode, "GTRW", 0, NULL, &mode)) { printf("%s: couldn't get adaptive keyboard mode\n", DEVNAME(sc)); return (1); } bzero(&arg, sizeof(arg)); arg.type = AML_OBJTYPE_INTEGER; if (mode == THINKPAD_ADAPTIVE_MODE_FUNCTION) arg.v_integer = THINKPAD_ADAPTIVE_MODE_HOME; else arg.v_integer = THINKPAD_ADAPTIVE_MODE_FUNCTION; if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "STRW", 1, &arg, NULL)) { printf("%s: couldn't set adaptive keyboard mode\n", DEVNAME(sc)); return (1); } return (0); }
int acpidock_eject(struct acpidock_softc *sc, struct aml_node *node) { struct aml_value cmd; struct aml_value res; int rv; if (node != sc->sc_devnode) aml_notify(node, 3); memset(&cmd, 0, sizeof cmd); cmd.v_integer = 1; cmd.type = AML_OBJTYPE_INTEGER; if (aml_evalname(sc->sc_acpi, node, "_EJ0", 1, &cmd, &res) != 0) { dnprintf(15, "%s: _EJ0 failed\n", DEVNAME(sc)); rv = 0; } else { dnprintf(15, "%s: _EJ0 successful\n", DEVNAME(sc)); rv = 1; } aml_freevalue(&res); return (rv); }
void acpiprt_attach(struct device *parent, struct device *self, void *aux) { struct acpiprt_softc *sc = (struct acpiprt_softc *)self; struct acpi_attach_args *aa = aux; struct aml_value res; int i; sc->sc_acpi = (struct acpi_softc *)parent; sc->sc_devnode = aa->aaa_node; sc->sc_bus = acpiprt_getpcibus(sc, sc->sc_devnode); printf(": bus %d (%s)", sc->sc_bus, sc->sc_devnode->parent->name); if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "_PRT", 0, NULL, &res)) { printf(": no PCI interrupt routing table\n"); return; } if (res.type != AML_OBJTYPE_PACKAGE) { printf(": _PRT is not a package\n"); aml_freevalue(&res); return; } printf("\n"); if (sc->sc_bus == -1) return; for (i = 0; i < res.length; i++) acpiprt_prt_add(sc, res.v_package[i]); aml_freevalue(&res); }
int toshiba_get_brightness(struct acpitoshiba_softc *sc, u_int32_t *brightness) { struct aml_value args[HCI_WORDS]; struct aml_value res; int i; bzero(args, sizeof(args)); bzero(&res, sizeof(res)); for (i = 0; i < HCI_WORDS; ++i) args[i].type = AML_OBJTYPE_INTEGER; args[HCI_REG_AX].v_integer = HCI_GET; args[HCI_REG_BX].v_integer = HCI_REG_LCD_BRIGHTNESS; if (aml_evalname(sc->sc_acpi, sc->sc_devnode, METHOD_HCI, i, args, &res)) { printf("%s: get brightness failed\n", DEVNAME(sc)); return (HCI_FAILURE); } /* * We receive a package type so we need to get the event * value from the HCI_REG_CX. */ *brightness = aml_val2int(res.v_package[HCI_REG_CX]); *brightness >>= HCI_LCD_BRIGHTNESS_SHIFT; aml_freevalue(&res); return (HCI_SUCCESS); }
int toshiba_read_events(struct acpitoshiba_softc *sc) { struct aml_value args[HCI_WORDS]; struct aml_value res; int i, val; bzero(args, sizeof(args)); bzero(&res, sizeof(res)); for (i = 0; i < HCI_WORDS; ++i) args[i].type = AML_OBJTYPE_INTEGER; args[HCI_REG_AX].v_integer = HCI_GET; args[HCI_REG_BX].v_integer = HCI_REG_SYSTEM_EVENT; if (aml_evalname(sc->sc_acpi, sc->sc_devnode, METHOD_HCI, i, args, &res)) { printf("%s: couldn't toggle METHOD_HCI\n", DEVNAME(sc)); return (HCI_FAILURE); } /* * We receive a package type so we need to get the event * value from the HCI_REG_CX. */ val = aml_val2int(res.v_package[HCI_REG_CX]); aml_freevalue(&res); return (val); }
int toshiba_set_brightness(struct acpitoshiba_softc *sc, u_int32_t *brightness) { struct aml_value args[HCI_WORDS]; int i; bzero(args, sizeof(args)); for (i = 0; i < HCI_WORDS; ++i) args[i].type = AML_OBJTYPE_INTEGER; if ((*brightness < HCI_LCD_BRIGHTNESS_MIN) || (*brightness > HCI_LCD_BRIGHTNESS_MAX)) return (HCI_FAILURE); *brightness <<= HCI_LCD_BRIGHTNESS_SHIFT; args[HCI_REG_AX].v_integer = HCI_SET; args[HCI_REG_BX].v_integer = HCI_REG_LCD_BRIGHTNESS; args[HCI_REG_CX].v_integer = *brightness; if (aml_evalname(sc->sc_acpi, sc->sc_devnode, METHOD_HCI, i, args, NULL)) { printf("%s: set brightness failed\n", DEVNAME(sc)); return (HCI_FAILURE); } return (HCI_SUCCESS); }
int acpiasus_activate(struct device *self, int act) { struct acpiasus_softc *sc = (struct acpiasus_softc *)self; struct aml_value cmd; struct aml_value ret; switch (act) { case DVACT_SUSPEND: break; case DVACT_RESUME: acpiasus_init(self); bzero(&cmd, sizeof(cmd)); cmd.type = AML_OBJTYPE_INTEGER; cmd.v_integer = ASUS_SDSP_LCD; if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "SDSP", 1, &cmd, &ret)) printf("%s: no SDSP\n", DEVNAME(sc)); else aml_freevalue(&ret); break; } return (0); }
int acpitz_setcpu(struct acpitz_softc *sc, int trend) { struct aml_value res0, *ref; int x; if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "_PSL", 0, NULL, &res0)) { printf("%s: _PSL failed\n", DEVNAME(sc)); goto out; } if (res0.type != AML_OBJTYPE_PACKAGE) { printf("%s: not a package\n", DEVNAME(sc)); goto out; } for (x = 0; x < res0.length; x++) { if (res0.v_package[x]->type != AML_OBJTYPE_OBJREF) { printf("%s: _PSL[%d] not a object ref\n", DEVNAME(sc), x); continue; } ref = res0.v_package[x]->v_objref.ref; if (ref->type != AML_OBJTYPE_PROCESSOR) printf("%s: _PSL[%d] not a CPU\n", DEVNAME(sc), x); } out: aml_freevalue(&res0); return (0); }
int toshiba_get_video_output(struct acpitoshiba_softc *sc, u_int32_t *video_output) { struct aml_value res, args[HCI_WORDS]; int i; bzero(args, sizeof(args)); bzero(&res, sizeof(res)); for (i = 0; i < HCI_WORDS; ++i) args[i].type = AML_OBJTYPE_INTEGER; args[HCI_REG_AX].v_integer = HCI_GET; args[HCI_REG_BX].v_integer = HCI_REG_VIDEO_OUTPUT; if (aml_evalname(sc->sc_acpi, sc->sc_devnode, METHOD_HCI, i, args, &res)) { printf("%s: get video output failed\n", DEVNAME(sc)); return (HCI_FAILURE); } /* * We receive a package type so we need to get the event * value from the HCI_REG_CX. */ *video_output = aml_val2int(res.v_package[HCI_REG_CX]); *video_output &= 0xff; aml_freevalue(&res); return (HCI_SUCCESS); }
int toshiba_set_video_output(struct acpitoshiba_softc *sc, u_int32_t *video_output) { struct aml_value args[HCI_WORDS]; int i; bzero(args, sizeof(args)); if ((*video_output < HCI_VIDEO_OUTPUT_CYCLE_MIN) || (*video_output > HCI_VIDEO_OUTPUT_CYCLE_MAX)) return (HCI_FAILURE); *video_output |= HCI_VIDEO_OUTPUT_FLAG; for (i = 0; i < HCI_WORDS; ++i) args[i].type = AML_OBJTYPE_INTEGER; args[HCI_REG_AX].v_integer = HCI_SET; args[HCI_REG_BX].v_integer = HCI_REG_VIDEO_OUTPUT; args[HCI_REG_CX].v_integer = *video_output; if (aml_evalname(sc->sc_acpi, sc->sc_devnode, METHOD_HCI, i, args, NULL)) { printf("%s: set video output failed\n", DEVNAME(sc)); return (HCI_FAILURE); } return (HCI_SUCCESS); }
void acpisony_set_brightness(struct acpisony_softc *sc, int level) { struct aml_value arg; bzero(&arg, sizeof(arg)); arg.type = AML_OBJTYPE_INTEGER; arg.v_integer = level; aml_evalname(sc->sc_acpi, sc->sc_devnode, "SBRT", 1, &arg, NULL); aml_freevalue(&arg); }
int toshiba_enable_events(struct acpitoshiba_softc *sc) { if (aml_evalname(sc->sc_acpi, sc->sc_devnode, METHOD_HCI_ENABLE, 0, NULL, NULL)) { printf("%s: couldn't toggle METHOD_HCI_ENABLE\n", DEVNAME(sc)); return (HCI_FAILURE); } return (HCI_SUCCESS); }
int thinkpad_cmos(struct acpithinkpad_softc *sc, uint8_t cmd) { struct aml_value arg; bzero(&arg, sizeof(arg)); arg.type = AML_OBJTYPE_INTEGER; arg.v_integer = cmd; aml_evalname(sc->sc_acpi, sc->sc_devnode, "\\UCMS", 1, &arg, NULL); return (0); }
int acpisony_get_brightness(struct acpisony_softc *sc) { struct aml_value res; int val; aml_evalname(sc->sc_acpi, sc->sc_devnode, "GBRT", 0, NULL, &res); val = aml_val2int(&res); aml_freevalue(&res); return val; }
int thinkpad_enable_events(struct acpithinkpad_softc *sc) { 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)) { printf("%s: no MHKA\n", DEVNAME(sc)); return (1); } /* 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)) { printf("%s: couldn't toggle MHKM\n", DEVNAME(sc)); return (1); } } /* 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)) { printf("%s: couldn't enable hotkeys\n", DEVNAME(sc)); return (1); } return (0); }
void acpivout_set_brightness(struct acpivout_softc *sc, int level) { struct aml_value args, res; memset(&args, 0, sizeof(args)); args.v_integer = level; args.type = AML_OBJTYPE_INTEGER; DPRINTF(("%s: BCM = %d\n", DEVNAME(sc), level)); aml_evalname(sc->sc_acpi, sc->sc_devnode, "_BCM", 1, &args, &res); aml_freevalue(&res); }
void acpivideo_set_policy(struct acpivideo_softc *sc, int policy) { struct aml_value args, res; memset(&args, 0, sizeof(args)); args.v_integer = policy; args.type = AML_OBJTYPE_INTEGER; aml_evalname(sc->sc_acpi, sc->sc_devnode, "_DOS", 1, &args, &res); DPRINTF(("%s: set policy to %X\n", DEVNAME(sc), aml_val2int(&res))); aml_freevalue(&res); }
int acpitz_getreading(struct acpitz_softc *sc, char *name) { struct aml_value res; int rv = -1; if (aml_evalname(sc->sc_acpi, sc->sc_devnode, name, 0, NULL, &res)) { dnprintf(10, "%s: no %s\n", DEVNAME(sc), name); goto out; } rv = aml_val2int(&res); out: aml_freevalue(&res); return (rv); }
void acpiasus_init(struct device *self) { struct acpiasus_softc *sc = (struct acpiasus_softc *)self; struct aml_value cmd; struct aml_value ret; bzero(&cmd, sizeof(cmd)); cmd.type = AML_OBJTYPE_INTEGER; cmd.v_integer = 0x40; /* Disable ASL display switching. */ if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "INIT", 1, &cmd, &ret)) printf("%s: no INIT\n", DEVNAME(sc)); else aml_freevalue(&ret); }
int acpivout_get_brightness(struct acpivout_softc *sc) { struct aml_value res; int level; aml_evalname(sc->sc_acpi, sc->sc_devnode, "_BQC", 0, NULL, &res); level = aml_val2int(&res); aml_freevalue(&res); DPRINTF(("%s: BQC = %d\n", DEVNAME(sc), level)); if (level < sc->sc_bcl[0] || level > sc->sc_bcl[sc->sc_bcl_len -1]) level = -1; return (level); }
void acpibat_attach(struct device *parent, struct device *self, void *aux) { struct acpibat_softc *sc = (struct acpibat_softc *)self; struct acpi_attach_args *aa = aux; struct aml_value res; sc->sc_acpi = (struct acpi_softc *)parent; sc->sc_devnode = aa->aaa_node; if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "_STA", 0, NULL, &res)) { dnprintf(10, "%s: no _STA\n", DEVNAME(sc)); return; } if ((res.v_integer & STA_BATTERY) != 0) { sc->sc_bat_present = 1; acpibat_getbif(sc); acpibat_getbst(sc); printf(": %s", sc->sc_devnode->name); if (sc->sc_bif.bif_model[0]) printf(" model \"%s\"", sc->sc_bif.bif_model); if (sc->sc_bif.bif_serial[0]) printf(" serial %s", sc->sc_bif.bif_serial); if (sc->sc_bif.bif_type[0]) printf(" type %s", sc->sc_bif.bif_type); if (sc->sc_bif.bif_oem[0]) printf(" oem \"%s\"", sc->sc_bif.bif_oem); printf("\n"); } else { sc->sc_bat_present = 0; printf(": %s not present\n", sc->sc_devnode->name); } aml_freevalue(&res); /* create sensors */ acpibat_monitor(sc); /* populate sensors */ acpibat_refresh(sc); aml_register_notify(sc->sc_devnode, aa->aaa_dev, acpibat_notify, sc, ACPIDEV_POLL); }
void sdhc_acpi_attach(struct device *parent, struct device *self, void *aux) { struct acpi_attach_args *aaa = aux; struct sdhc_acpi_softc *sc = (struct sdhc_acpi_softc *)self; struct aml_value res; sc->sc_acpi = (struct acpi_softc *)parent; sc->sc_node = aaa->aaa_node; printf(": %s", sc->sc_node->name); if (aml_evalname(sc->sc_acpi, sc->sc_node, "_CRS", 0, NULL, &res)) { printf(", can't find registers\n"); return; } aml_parse_resource(&res, sdhc_acpi_parse_resources, sc); printf(" addr 0x%lx/0x%lx", sc->sc_addr, sc->sc_size); if (sc->sc_addr == 0 || sc->sc_size == 0) { printf("\n"); return; } printf(" irq %d", sc->sc_irq); sc->sc_memt = aaa->aaa_memt; if (bus_space_map(sc->sc_memt, sc->sc_addr, sc->sc_size, 0, &sc->sc_memh)) { printf(", can't map registers\n"); return; } sc->sc_ih = acpi_intr_establish(sc->sc_irq, sc->sc_irq_flags, IPL_BIO, sdhc_intr, sc, sc->sc.sc_dev.dv_xname); if (sc->sc_ih == NULL) { printf(", can't establish interrupt\n"); return; } printf("\n"); sc->sc.sc_host = &sc->sc_host; sdhc_host_found(&sc->sc, sc->sc_memt, sc->sc_memh, sc->sc_size, 0, 0); }
int acpiec_reg(struct acpiec_softc *sc) { struct aml_value arg[2]; memset(&arg, 0, sizeof(arg)); arg[0].type = AML_OBJTYPE_INTEGER; arg[0].v_integer = REG_TYPE_EC; arg[1].type = AML_OBJTYPE_INTEGER; arg[1].v_integer = 1; if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "_REG", 2, arg, NULL) != 0) { dnprintf(10, "%s: eval method _REG failed\n", DEVNAME(sc)); return (1); } return (0); }
int acpisony_find_offset(struct acpisony_softc *sc, int key) { struct aml_value arg, res; int val; bzero(&arg, sizeof(arg)); arg.type = AML_OBJTYPE_INTEGER; for (arg.v_integer = 0x20; arg.v_integer < 0x30; arg.v_integer++) { aml_evalname(sc->sc_acpi, sc->sc_devnode, "SN00", 1, &arg, &res); val = aml_val2int(&res); aml_freevalue(&res); if (val == key) { DPRINTF(("Matched key %X\n", val)); return arg.v_integer - 0x20; } } return -1; }
int acpisony_set_hotkey(struct acpisony_softc *sc, int key, int val) { int off, rc = -1; struct aml_value res, arg; bzero(&arg, sizeof(arg)); arg.type = AML_OBJTYPE_INTEGER; off = acpisony_find_offset(sc, key); DPRINTF(("off = %X\n", off)); if (off < 0) return rc; arg.v_integer = off | val; aml_evalname(sc->sc_acpi, sc->sc_devnode, "SN07", 1, &arg, &res); rc = aml_val2int(&res); aml_freevalue(&res); return rc; }
void acpivout_get_bcl(struct acpivout_softc *sc) { int i, j, value; struct aml_value res; DPRINTF(("Getting _BCL!")); aml_evalname(sc->sc_acpi, sc->sc_devnode, "_BCL", 0, NULL, &res); if (res.type != AML_OBJTYPE_PACKAGE) { sc->sc_bcl_len = 0; goto err; } /* * Per the ACPI spec section B.6.2 the _BCL method returns a package. * The first integer in the package is the brightness level * when the computer has full power, and the second is the * brightness level when the computer is on batteries. * All other levels may be used by OSPM. * So we skip the first two integers in the package. */ if (res.length <= 2) { sc->sc_bcl_len = 0; goto err; } sc->sc_bcl_len = res.length - 2; sc->sc_bcl = mallocarray(sc->sc_bcl_len, sizeof(int), M_DEVBUF, M_WAITOK | M_ZERO); for (i = 0; i < sc->sc_bcl_len; i++) { /* Sort darkest to brightest */ value = aml_val2int(res.v_package[i + 2]); for (j = i; j > 0 && sc->sc_bcl[j - 1] > value; j--) sc->sc_bcl[j] = sc->sc_bcl[j - 1]; sc->sc_bcl[j] = value; } err: aml_freevalue(&res); }
void acpiec_attach(struct device *parent, struct device *self, void *aux) { struct acpiec_softc *sc = (struct acpiec_softc *)self; struct acpi_attach_args *aa = aux; struct aml_value res; sc->sc_acpi = (struct acpi_softc *)parent; sc->sc_devnode = aa->aaa_node; if (acpiec_getcrs(sc, aa)) { printf(": Failed to read resource settings\n"); return; } sc->sc_acpi->sc_ec = sc; if (acpiec_reg(sc)) { printf(": Failed to register address space\n"); return; } acpiec_get_events(sc); dnprintf(10, "%s: GPE: %d\n", DEVNAME(sc), sc->sc_gpe); #ifndef SMALL_KERNEL acpi_set_gpehandler(sc->sc_acpi, sc->sc_gpe, acpiec_gpehandler, sc, 1); #endif if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "_GLK", 0, NULL, &res)) sc->sc_glk = 0; else if (res.type != AML_OBJTYPE_INTEGER) sc->sc_glk = 0; else sc->sc_glk = res.v_integer ? 1 : 0; printf("\n"); }
int acpicpu_getpss(struct acpicpu_softc *sc) { struct aml_value res; int i; if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "_PSS", 0, NULL, &res)) { dnprintf(20, "%s: no _PSS\n", DEVNAME(sc)); return (1); } if (sc->sc_pss) free(sc->sc_pss, M_DEVBUF); sc->sc_pss = malloc(res.length * sizeof *sc->sc_pss, M_DEVBUF, M_WAITOK); memset(sc->sc_pss, 0, res.length * sizeof *sc->sc_pss); for (i = 0; i < res.length; i++) { sc->sc_pss[i].pss_core_freq = aml_val2int( res.v_package[i]->v_package[0]); sc->sc_pss[i].pss_power = aml_val2int( res.v_package[i]->v_package[1]); sc->sc_pss[i].pss_trans_latency = aml_val2int( res.v_package[i]->v_package[2]); sc->sc_pss[i].pss_bus_latency = aml_val2int( res.v_package[i]->v_package[3]); sc->sc_pss[i].pss_ctrl = aml_val2int( res.v_package[i]->v_package[4]); sc->sc_pss[i].pss_status = aml_val2int( res.v_package[i]->v_package[5]); } aml_freevalue(&res); sc->sc_pss_len = res.length; return (0); }
int acpibat_getbst(struct acpibat_softc *sc) { struct aml_value res; int rv = EINVAL; if (!sc->sc_bat_present) { memset(&sc->sc_bst, 0, sizeof(sc->sc_bst)); return (0); } if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "_BST", 0, NULL, &res)) { dnprintf(10, "%s: no _BST\n", DEVNAME(sc)); goto out; } if (res.length != 4) { dnprintf(10, "%s: invalid _BST, battery status not saved\n", DEVNAME(sc)); goto out; } sc->sc_bst.bst_state = aml_val2int(res.v_package[0]); sc->sc_bst.bst_rate = aml_val2int(res.v_package[1]); sc->sc_bst.bst_capacity = aml_val2int(res.v_package[2]); sc->sc_bst.bst_voltage = aml_val2int(res.v_package[3]); dnprintf(60, "state: %u rate: %u cap: %u volt: %u ", sc->sc_bst.bst_state, sc->sc_bst.bst_rate, sc->sc_bst.bst_capacity, sc->sc_bst.bst_voltage); rv = 0; out: aml_freevalue(&res); return (rv); }