From c74b647fa73486de5f7576ffb1f632ebcbf3091c Mon Sep 17 00:00:00 2001 From: Marco Peereboom Date: Tue, 21 Feb 2006 04:30:46 +0000 Subject: Rig the power button so that the machine shuts down correctly. --- sys/dev/acpi/acpi.c | 39 ++++++++++++++------------------------- sys/dev/acpi/acpibtn.c | 38 ++++++++++++++++++++++++++++++++------ sys/dev/acpi/acpivar.h | 3 ++- 3 files changed, 48 insertions(+), 32 deletions(-) diff --git a/sys/dev/acpi/acpi.c b/sys/dev/acpi/acpi.c index 2ab7e9a01f8..79189e15a7f 100644 --- a/sys/dev/acpi/acpi.c +++ b/sys/dev/acpi/acpi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpi.c,v 1.37 2006/02/20 00:48:10 marco Exp $ */ +/* $OpenBSD: acpi.c,v 1.38 2006/02/21 04:30:44 marco Exp $ */ /* * Copyright (c) 2005 Thorsten Lockert * Copyright (c) 2005 Jordan Hargrave @@ -492,6 +492,7 @@ acpi_foundhid(struct aml_node *node, void *arg) struct device *self = (struct device *)arg; const char *dev; struct aml_value res; + struct acpi_attach_args aaa; dnprintf(20, "found hid device: %s ", node->parent->name); aml_eval_object(sc, node, &res, 0, NULL); @@ -509,35 +510,23 @@ acpi_foundhid(struct aml_node *node, void *arg) } dnprintf(20, " device: %s\n", dev); - if (!strcmp(dev, ACPI_DEV_AC)) { - struct acpi_attach_args aaa; + memset(&aaa, 0, sizeof(aaa)); + aaa.aaa_iot = sc->sc_iot; + aaa.aaa_memt = sc->sc_memt; + aaa.aaa_node = node->parent; + aaa.aaa_dev = dev; - memset(&aaa, 0, sizeof(aaa)); + if (!strcmp(dev, ACPI_DEV_AC)) aaa.aaa_name = "acpiac"; - aaa.aaa_iot = sc->sc_iot; - aaa.aaa_memt = sc->sc_memt; - aaa.aaa_node = node->parent; - config_found(self, &aaa, acpi_print); - } else if (!strcmp(dev, ACPI_DEV_CMB)) { - struct acpi_attach_args aaa; - - memset(&aaa, 0, sizeof(aaa)); + else if (!strcmp(dev, ACPI_DEV_CMB)) aaa.aaa_name = "acpibat"; - aaa.aaa_iot = sc->sc_iot; - aaa.aaa_memt = sc->sc_memt; - aaa.aaa_node = node->parent; - config_found(self, &aaa, acpi_print); - } else if (!strcmp(dev, ACPI_DEV_LD) || !strcmp(dev, ACPI_DEV_PBD) || - !strcmp(dev, ACPI_DEV_SBD)) { - struct acpi_attach_args aaa; - - memset(&aaa, 0, sizeof(aaa)); + else if (!strcmp(dev, ACPI_DEV_LD) || + !strcmp(dev, ACPI_DEV_PBD) || + !strcmp(dev, ACPI_DEV_SBD)) aaa.aaa_name = "acpibtn"; - aaa.aaa_iot = sc->sc_iot; - aaa.aaa_memt = sc->sc_memt; - aaa.aaa_node = node->parent; + + if (aaa.aaa_name) config_found(self, &aaa, acpi_print); - } } int diff --git a/sys/dev/acpi/acpibtn.c b/sys/dev/acpi/acpibtn.c index 711f931e94b..ca2ff5501d8 100644 --- a/sys/dev/acpi/acpibtn.c +++ b/sys/dev/acpi/acpibtn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpibtn.c,v 1.3 2006/02/21 01:10:10 marco Exp $ */ +/* $OpenBSD: acpibtn.c,v 1.4 2006/02/21 04:30:45 marco Exp $ */ /* * Copyright (c) 2005 Marco Peereboom * @@ -16,6 +16,8 @@ */ #include +#include +#include #include #include #include @@ -43,9 +45,10 @@ struct acpibtn_softc { struct acpi_softc *sc_acpi; struct aml_node *sc_devnode; - int sc_pwr_btn; - int sc_lid_btn; - int sc_sleep_btn; + int sc_btn_type; +#define ACPIBTN_LID 0 +#define ACPIBTN_POWER 1 +#define ACPIBTN_SLEEP 2 #if 0 struct sensor sens[3]; /* XXX debug only */ #endif @@ -89,6 +92,13 @@ acpibtn_attach(struct device *parent, struct device *self, void *aux) sc->sc_acpi = (struct acpi_softc *)parent; sc->sc_devnode = aa->aaa_node->child; + if (!strcmp(aa->aaa_dev, ACPI_DEV_LD)) + sc->sc_btn_type = ACPIBTN_LID; + if (!strcmp(aa->aaa_dev, ACPI_DEV_PBD)) + sc->sc_btn_type = ACPIBTN_POWER; + if (!strcmp(aa->aaa_dev, ACPI_DEV_SBD)) + sc->sc_btn_type = ACPIBTN_SLEEP; + acpibtn_getsta(sc); /* XXX print which buttons are available and state */ @@ -144,10 +154,26 @@ acpibtn_getsta(struct acpibtn_softc *sc) int acpibtn_notify(struct aml_node *node, int notify_type, void *arg) { - struct acpibtn_softc *sc = arg; + struct acpibtn_softc *sc = arg; + extern int acpi_s5; - printf("acpibtn_notify: %.2x %s\n", notify_type, + dnprintf(10, "acpibtn_notify: %.2x %s\n", notify_type, sc->sc_devnode->parent->name); + switch (sc->sc_btn_type) { + case ACPIBTN_LID: + break; + case ACPIBTN_POWER: + acpi_s5 = 1; + psignal(initproc, SIGUSR1); + /* NOTREACHED */ + break; + case ACPIBTN_SLEEP: + break; + default: + printf("%s: spurious acpi interrupt\n", DEVNAME(sc)); + break; + } + return (0); } diff --git a/sys/dev/acpi/acpivar.h b/sys/dev/acpi/acpivar.h index ccad337e833..172960232f7 100644 --- a/sys/dev/acpi/acpivar.h +++ b/sys/dev/acpi/acpivar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: acpivar.h,v 1.18 2006/02/20 21:39:06 jordan Exp $ */ +/* $OpenBSD: acpivar.h,v 1.19 2006/02/21 04:30:45 marco Exp $ */ /* * Copyright (c) 2005 Thorsten Lockert * @@ -39,6 +39,7 @@ struct acpi_attach_args { void *aaa_table; paddr_t aaa_pbase; /* Physical base address of ACPI tables */ struct aml_node *aaa_node; + const char *aaa_dev; }; struct acpi_mem_map { -- cgit v1.2.3