[BACK]Return to acpibtn.c CVS log [TXT][DIR] Up to [local] / sys / dev / acpi

Annotation of sys/dev/acpi/acpibtn.c, Revision 1.1

1.1     ! nbrk        1: /* $OpenBSD: acpibtn.c,v 1.15 2006/12/26 23:58:08 marco 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/proc.h>
        !            20: #include <sys/signalvar.h>
        !            21: #include <sys/systm.h>
        !            22: #include <sys/device.h>
        !            23: #include <sys/malloc.h>
        !            24:
        !            25: #include <machine/bus.h>
        !            26:
        !            27: #include <dev/acpi/acpireg.h>
        !            28: #include <dev/acpi/acpivar.h>
        !            29: #include <dev/acpi/acpidev.h>
        !            30: #include <dev/acpi/amltypes.h>
        !            31: #include <dev/acpi/dsdt.h>
        !            32:
        !            33: #include <sys/sensors.h>
        !            34:
        !            35: int    acpibtn_match(struct device *, void *, void *);
        !            36: void   acpibtn_attach(struct device *, struct device *, void *);
        !            37: int    acpibtn_notify(struct aml_node *, int, void *);
        !            38:
        !            39: struct acpibtn_softc {
        !            40:        struct device           sc_dev;
        !            41:
        !            42:        bus_space_tag_t         sc_iot;
        !            43:        bus_space_handle_t      sc_ioh;
        !            44:
        !            45:        struct acpi_softc       *sc_acpi;
        !            46:        struct aml_node         *sc_devnode;
        !            47:
        !            48:        int                     sc_btn_type;
        !            49: #define        ACPIBTN_UNKNOWN -1
        !            50: #define ACPIBTN_LID    0
        !            51: #define ACPIBTN_POWER  1
        !            52: #define ACPIBTN_SLEEP  2
        !            53: };
        !            54:
        !            55: int    acpibtn_getsta(struct acpibtn_softc *);
        !            56:
        !            57: struct cfattach acpibtn_ca = {
        !            58:        sizeof(struct acpibtn_softc), acpibtn_match, acpibtn_attach
        !            59: };
        !            60:
        !            61: struct cfdriver acpibtn_cd = {
        !            62:        NULL, "acpibtn", DV_DULL
        !            63: };
        !            64:
        !            65: int
        !            66: acpibtn_match(struct device *parent, void *match, void *aux)
        !            67: {
        !            68:        struct acpi_attach_args *aa = aux;
        !            69:        struct cfdata           *cf = match;
        !            70:
        !            71:        /* sanity */
        !            72:        if (aa->aaa_name == NULL ||
        !            73:            strcmp(aa->aaa_name, cf->cf_driver->cd_name) != 0 ||
        !            74:            aa->aaa_table != NULL)
        !            75:                return (0);
        !            76:
        !            77:        return (1);
        !            78: }
        !            79:
        !            80: void
        !            81: acpibtn_attach(struct device *parent, struct device *self, void *aux)
        !            82: {
        !            83:        struct acpibtn_softc    *sc = (struct acpibtn_softc *)self;
        !            84:        struct acpi_attach_args *aa = aux;
        !            85:
        !            86:        sc->sc_acpi = (struct acpi_softc *)parent;
        !            87:        sc->sc_devnode = aa->aaa_node->child;
        !            88:
        !            89:        if (!strcmp(aa->aaa_dev, ACPI_DEV_LD))
        !            90:                sc->sc_btn_type = ACPIBTN_LID;
        !            91:        else if (!strcmp(aa->aaa_dev, ACPI_DEV_PBD))
        !            92:                sc->sc_btn_type = ACPIBTN_POWER;
        !            93:        else if (!strcmp(aa->aaa_dev, ACPI_DEV_SBD))
        !            94:                sc->sc_btn_type = ACPIBTN_SLEEP;
        !            95:        else
        !            96:                sc->sc_btn_type = ACPIBTN_UNKNOWN;
        !            97:
        !            98:        acpibtn_getsta(sc);
        !            99:
        !           100:        printf(": %s\n", sc->sc_devnode->parent->name);
        !           101:
        !           102:        aml_register_notify(sc->sc_devnode->parent, aa->aaa_dev, acpibtn_notify,
        !           103:            sc, ACPIDEV_NOPOLL);
        !           104: }
        !           105:
        !           106: int
        !           107: acpibtn_getsta(struct acpibtn_softc *sc)
        !           108: {
        !           109:        if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "_STA", 0, NULL, NULL) != 0) {
        !           110:                dnprintf(20, "%s: no _STA\n", DEVNAME(sc));
        !           111:                /* XXX not all buttons have _STA so FALLTROUGH */
        !           112:        }
        !           113:
        !           114:        return (0);
        !           115: }
        !           116:
        !           117: int
        !           118: acpibtn_notify(struct aml_node *node, int notify_type, void *arg)
        !           119: {
        !           120:        struct acpibtn_softc    *sc = arg;
        !           121:        extern int              acpi_s5;
        !           122:
        !           123:        dnprintf(10, "acpibtn_notify: %.2x %s\n", notify_type,
        !           124:            sc->sc_devnode->parent->name);
        !           125:
        !           126:        switch (sc->sc_btn_type) {
        !           127:        case ACPIBTN_LID:
        !           128:        case ACPIBTN_SLEEP:
        !           129:                break;
        !           130:        case ACPIBTN_POWER:
        !           131:                if (notify_type == 0x80) {
        !           132:                        acpi_s5 = 1;
        !           133:                        psignal(initproc, SIGUSR1);
        !           134:                }
        !           135:                break;
        !           136:        default:
        !           137:                printf("%s: spurious acpi button interrupt %i\n", DEVNAME(sc),
        !           138:                    sc->sc_btn_type);
        !           139:                break;
        !           140:        }
        !           141:
        !           142:        return (0);
        !           143: }

CVSweb