2010-04-12 16:14:26 +04:00
|
|
|
/* $NetBSD: acpi_wakedev.c,v 1.9 2010/04/12 12:14:26 jruoho Exp $ */
|
2009-08-04 18:20:40 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2009 Jared D. McNeill <jmcneill@invisible.ca>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2010-04-12 16:14:26 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: acpi_wakedev.c,v 1.9 2010/04/12 12:14:26 jruoho Exp $");
|
2009-08-04 18:20:40 +04:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/sysctl.h>
|
2010-03-05 17:00:16 +03:00
|
|
|
#include <sys/systm.h>
|
2009-08-04 18:20:40 +04:00
|
|
|
|
|
|
|
#include <dev/acpi/acpireg.h>
|
2010-03-05 17:00:16 +03:00
|
|
|
#include <dev/acpi/acpivar.h>
|
2009-08-04 18:20:40 +04:00
|
|
|
#include <dev/acpi/acpi_wakedev.h>
|
|
|
|
|
2010-03-06 01:00:11 +03:00
|
|
|
#define _COMPONENT ACPI_BUS_COMPONENT
|
|
|
|
ACPI_MODULE_NAME ("acpi_wakedev")
|
|
|
|
|
2009-08-04 18:20:40 +04:00
|
|
|
static const char * const acpi_wakedev_default[] = {
|
|
|
|
"PNP0C0C", /* power button */
|
|
|
|
"PNP0C0E", /* sleep button */
|
|
|
|
"PNP0C0D", /* lid switch */
|
|
|
|
"PNP03??", /* PC KBD port */
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2010-04-12 16:14:26 +04:00
|
|
|
static const struct sysctlnode *rnode = NULL;
|
|
|
|
|
2010-03-06 01:00:11 +03:00
|
|
|
static void acpi_wakedev_prepare(struct acpi_devnode *, int, int);
|
|
|
|
|
2010-04-12 16:14:26 +04:00
|
|
|
SYSCTL_SETUP(sysctl_acpi_wakedev_setup, "sysctl hw.acpi.wake subtree setup")
|
2009-08-04 18:20:40 +04:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = sysctl_createv(NULL, 0, NULL, &rnode,
|
2010-04-12 16:14:26 +04:00
|
|
|
CTLFLAG_PERMANENT, CTLTYPE_NODE, "hw",
|
|
|
|
NULL, NULL, 0, NULL, 0,
|
|
|
|
CTL_HW, CTL_EOL);
|
|
|
|
|
|
|
|
if (err != 0)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
err = sysctl_createv(NULL, 0, &rnode, &rnode,
|
|
|
|
CTLFLAG_PERMANENT, CTLTYPE_NODE, "acpi",
|
|
|
|
NULL, NULL, 0, NULL, 0,
|
|
|
|
CTL_CREATE, CTL_EOL);
|
|
|
|
|
|
|
|
if (err != 0)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
err = sysctl_createv(NULL, 0, &rnode, &rnode,
|
|
|
|
CTLFLAG_PERMANENT, CTLTYPE_NODE,
|
|
|
|
"wake", SYSCTL_DESCR("ACPI device wake-up"),
|
2009-08-04 18:20:40 +04:00
|
|
|
NULL, 0, NULL, 0,
|
2010-04-12 16:14:26 +04:00
|
|
|
CTL_CREATE, CTL_EOL);
|
|
|
|
|
|
|
|
if (err != 0)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
rnode = NULL;
|
2009-08-04 18:20:40 +04:00
|
|
|
}
|
|
|
|
|
2010-03-16 08:48:42 +03:00
|
|
|
void
|
|
|
|
acpi_wakedev_add(struct acpi_devnode *ad)
|
2009-08-04 18:20:40 +04:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2010-03-16 08:48:42 +03:00
|
|
|
KASSERT(ad != NULL && ad->ad_parent != NULL);
|
|
|
|
KASSERT((ad->ad_flags & ACPI_DEVICE_WAKEUP) != 0);
|
2009-08-04 18:20:40 +04:00
|
|
|
|
2010-04-12 16:14:26 +04:00
|
|
|
ad->ad_wake = 0;
|
2009-08-04 18:20:40 +04:00
|
|
|
|
|
|
|
if (acpi_match_hid(ad->ad_devinfo, acpi_wakedev_default))
|
2010-04-12 16:14:26 +04:00
|
|
|
ad->ad_wake = 1;
|
2009-08-04 18:20:40 +04:00
|
|
|
|
2010-04-12 16:14:26 +04:00
|
|
|
if (rnode == NULL)
|
2010-03-16 08:48:42 +03:00
|
|
|
return;
|
2009-08-04 18:20:40 +04:00
|
|
|
|
2010-04-12 16:14:26 +04:00
|
|
|
err = sysctl_createv(NULL, 0, &rnode, NULL,
|
|
|
|
CTLFLAG_READWRITE, CTLTYPE_BOOL, ad->ad_name,
|
|
|
|
NULL, NULL, 0, &ad->ad_wake, 0,
|
|
|
|
CTL_CREATE, CTL_EOL);
|
2009-08-04 18:20:40 +04:00
|
|
|
|
2010-03-16 08:48:42 +03:00
|
|
|
if (err != 0)
|
2010-04-12 16:14:26 +04:00
|
|
|
aprint_error_dev(ad->ad_parent, "sysctl_createv"
|
|
|
|
"(hw.acpi.wake.%s) failed (err %d)\n", ad->ad_name, err);
|
2009-08-04 18:20:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-03-06 00:01:44 +03:00
|
|
|
acpi_wakedev_commit(struct acpi_softc *sc, int state)
|
2009-08-04 18:20:40 +04:00
|
|
|
{
|
2010-03-16 08:48:42 +03:00
|
|
|
struct acpi_devnode *ad;
|
2009-08-04 18:20:40 +04:00
|
|
|
|
2010-03-06 00:01:44 +03:00
|
|
|
/*
|
|
|
|
* As noted in ACPI 3.0 (p. 243), preparing
|
|
|
|
* a device for wakeup is a two-step process:
|
|
|
|
*
|
|
|
|
* 1. Enable all power resources in _PRW.
|
|
|
|
*
|
|
|
|
* 2. If present, execute _DSW/_PSW method.
|
|
|
|
*
|
|
|
|
* XXX: The first one is yet to be implemented.
|
|
|
|
*/
|
2010-03-16 08:48:42 +03:00
|
|
|
SIMPLEQ_FOREACH(ad, &sc->sc_devnodes, ad_list) {
|
|
|
|
|
|
|
|
if ((ad->ad_flags & ACPI_DEVICE_WAKEUP) == 0)
|
|
|
|
continue;
|
2010-03-06 00:01:44 +03:00
|
|
|
|
2010-04-12 16:14:26 +04:00
|
|
|
if (ad->ad_wake == 0)
|
2010-03-16 08:48:42 +03:00
|
|
|
acpi_clear_wake_gpe(ad->ad_handle);
|
|
|
|
else {
|
|
|
|
aprint_debug_dev(ad->ad_parent,
|
|
|
|
"set wake GPE for %s\n", ad->ad_name);
|
|
|
|
acpi_set_wake_gpe(ad->ad_handle);
|
|
|
|
}
|
2010-03-06 00:01:44 +03:00
|
|
|
|
2010-04-12 16:14:26 +04:00
|
|
|
acpi_wakedev_prepare(ad, ad->ad_wake, state);
|
2009-08-04 18:20:40 +04:00
|
|
|
}
|
|
|
|
}
|
2010-03-06 00:01:44 +03:00
|
|
|
|
|
|
|
static void
|
|
|
|
acpi_wakedev_prepare(struct acpi_devnode *ad, int enable, int state)
|
|
|
|
{
|
|
|
|
ACPI_OBJECT_LIST arg;
|
|
|
|
ACPI_OBJECT obj[3];
|
|
|
|
ACPI_STATUS rv;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First try to call the Device Sleep Wake control method, _DSW.
|
|
|
|
* Only if this is not available, resort to to the Power State
|
|
|
|
* Wake control method, _PSW, which was deprecated in ACPI 3.0.
|
|
|
|
*
|
|
|
|
* The arguments to these methods are as follows:
|
|
|
|
*
|
|
|
|
* arg0 arg1 arg2
|
|
|
|
* ---- ---- ----
|
|
|
|
* _PSW 0: disable
|
|
|
|
* 1: enable
|
|
|
|
*
|
|
|
|
* _DSW 0: disable 0: S0 0: D0
|
|
|
|
* 1: enable 1: S1 1: D0 or D1
|
|
|
|
* 2: D0, D1, or D2
|
|
|
|
* x: Sx 3: D0, D1, D2 or D3
|
|
|
|
*/
|
|
|
|
arg.Count = 3;
|
|
|
|
arg.Pointer = obj;
|
|
|
|
|
|
|
|
obj[0].Integer.Value = enable;
|
|
|
|
obj[1].Integer.Value = state;
|
|
|
|
obj[2].Integer.Value = 3;
|
|
|
|
|
|
|
|
obj[0].Type = obj[1].Type = obj[2].Type = ACPI_TYPE_INTEGER;
|
|
|
|
|
|
|
|
rv = AcpiEvaluateObject(ad->ad_handle, "_DSW", &arg, NULL);
|
|
|
|
|
|
|
|
if (ACPI_SUCCESS(rv))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (rv != AE_NOT_FOUND)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
rv = acpi_eval_set_integer(ad->ad_handle, "_PSW", enable);
|
|
|
|
|
|
|
|
if (ACPI_FAILURE(rv) && rv != AE_NOT_FOUND)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
fail:
|
2010-03-16 08:48:42 +03:00
|
|
|
aprint_error_dev(ad->ad_parent, "failed to evaluate wake "
|
2010-03-06 00:01:44 +03:00
|
|
|
"control method: %s\n", AcpiFormatException(rv));
|
|
|
|
}
|