Annotation of sys/dev/acpi/acpiac.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: acpiac.c,v 1.18 2007/06/23 11:41:03 canacar Exp $ */
! 2: /*
! 3: * Copyright (c) 2005 Marco Peereboom <marco@openbsd.org>
! 4: *
! 5: * Permission to use, copy, modify, and distribute this software for any
! 6: * purpose with or without fee is hereby granted, provided that the above
! 7: * copyright notice and this permission notice appear in all copies.
! 8: *
! 9: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
! 10: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
! 11: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
! 12: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
! 13: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
! 14: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
! 15: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
! 16: */
! 17:
! 18: #include <sys/param.h>
! 19: #include <sys/systm.h>
! 20: #include <sys/device.h>
! 21: #include <sys/malloc.h>
! 22:
! 23: #include <machine/bus.h>
! 24:
! 25: #include <dev/acpi/acpireg.h>
! 26: #include <dev/acpi/acpivar.h>
! 27: #include <dev/acpi/acpidev.h>
! 28: #include <dev/acpi/amltypes.h>
! 29: #include <dev/acpi/dsdt.h>
! 30:
! 31: #include <sys/sensors.h>
! 32:
! 33: int acpiac_match(struct device *, void *, void *);
! 34: void acpiac_attach(struct device *, struct device *, void *);
! 35: int acpiac_notify(struct aml_node *, int, void *);
! 36:
! 37: void acpiac_refresh(void *);
! 38: int acpiac_getsta(struct acpiac_softc *);
! 39:
! 40: struct cfattach acpiac_ca = {
! 41: sizeof(struct acpiac_softc), acpiac_match, acpiac_attach
! 42: };
! 43:
! 44: struct cfdriver acpiac_cd = {
! 45: NULL, "acpiac", DV_DULL
! 46: };
! 47:
! 48: int
! 49: acpiac_match(struct device *parent, void *match, void *aux)
! 50: {
! 51: struct acpi_attach_args *aa = aux;
! 52: struct cfdata *cf = match;
! 53:
! 54: /* sanity */
! 55: if (aa->aaa_name == NULL ||
! 56: strcmp(aa->aaa_name, cf->cf_driver->cd_name) != 0 ||
! 57: aa->aaa_table != NULL)
! 58: return (0);
! 59: return (1);
! 60: }
! 61:
! 62: void
! 63: acpiac_attach(struct device *parent, struct device *self, void *aux)
! 64: {
! 65: struct acpiac_softc *sc = (struct acpiac_softc *)self;
! 66: struct acpi_attach_args *aa = aux;
! 67:
! 68: sc->sc_acpi = (struct acpi_softc *)parent;
! 69: sc->sc_devnode = aa->aaa_node->child;
! 70:
! 71: aml_register_notify(sc->sc_devnode->parent, aa->aaa_dev,
! 72: acpiac_notify, sc, ACPIDEV_NOPOLL);
! 73:
! 74: acpiac_getsta(sc);
! 75: printf(": AC unit ");
! 76: if (sc->sc_ac_stat == PSR_ONLINE)
! 77: printf("online\n");
! 78: else if (sc->sc_ac_stat == PSR_OFFLINE)
! 79: printf("offline\n");
! 80: else
! 81: printf("in unknown state\n");
! 82:
! 83: strlcpy(sc->sc_sensdev.xname, DEVNAME(sc),
! 84: sizeof(sc->sc_sensdev.xname));
! 85: strlcpy(sc->sc_sens[0].desc, "power supply",
! 86: sizeof(sc->sc_sens[0].desc));
! 87: sc->sc_sens[0].type = SENSOR_INDICATOR;
! 88: sensor_attach(&sc->sc_sensdev, &sc->sc_sens[0]);
! 89: sensordev_install(&sc->sc_sensdev);
! 90: sc->sc_sens[0].value = sc->sc_ac_stat;
! 91: }
! 92:
! 93: void
! 94: acpiac_refresh(void *arg)
! 95: {
! 96: struct acpiac_softc *sc = arg;
! 97:
! 98: acpiac_getsta(sc);
! 99: sc->sc_sens[0].value = sc->sc_ac_stat;
! 100: }
! 101:
! 102: int
! 103: acpiac_getsta(struct acpiac_softc *sc)
! 104: {
! 105: struct aml_value res;
! 106:
! 107: if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "_STA", 0, NULL, NULL)) {
! 108: dnprintf(10, "%s: no _STA\n",
! 109: DEVNAME(sc));
! 110: }
! 111:
! 112: if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "_PSR", 0, NULL, &res)) {
! 113: dnprintf(10, "%s: no _PSR\n",
! 114: DEVNAME(sc));
! 115: return (1);
! 116: }
! 117: sc->sc_ac_stat = aml_val2int(&res);
! 118: aml_freevalue(&res);
! 119: return (0);
! 120: }
! 121:
! 122: int
! 123: acpiac_notify(struct aml_node *node, int notify_type, void *arg)
! 124: {
! 125: struct acpiac_softc *sc = arg;
! 126:
! 127: dnprintf(10, "acpiac_notify: %.2x %s\n", notify_type,
! 128: sc->sc_devnode->parent->name);
! 129:
! 130: switch (notify_type) {
! 131: case 0x00:
! 132: case 0x81:
! 133: /*
! 134: * XXX some sony vaio's use the wrong notify type
! 135: * work around it by honoring it as a 0x80
! 136: */
! 137: /* FALLTHROUGH */
! 138: case 0x80:
! 139: acpiac_refresh(sc);
! 140: dnprintf(10, "A/C status: %d\n", sc->sc_ac_stat);
! 141: break;
! 142: }
! 143: return (0);
! 144: }
CVSweb