2 * Copyright (c) 2000 Takanori Watanabe <takawata@jp.freebsd.org>
3 * Copyright (c) 2000 Mitsuru IWASAKI <iwasaki@jp.freebsd.org>
4 * Copyright (c) 2000 Michael Smith <msmith@freebd.org>
5 * Copyright (c) 2000 BSDi
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * $FreeBSD: src/sys/dev/acpica/acpi_lid.c,v 1.15 2003/10/25 05:03:24 njl Exp $
30 * $DragonFly: src/sys/dev/acpica5/acpi_lid.c,v 1.1 2004/02/21 06:48:08 dillon Exp $
34 #include <sys/param.h>
35 #include <sys/kernel.h>
40 #include <dev/acpica5/acpivar.h>
42 /* Hooks for the ACPI CA debugging infrastructure */
43 #define _COMPONENT ACPI_BUTTON
44 ACPI_MODULE_NAME("LID")
46 struct acpi_lid_softc {
48 ACPI_HANDLE lid_handle;
49 int lid_status; /* open or closed */
52 static int acpi_lid_probe(device_t dev);
53 static int acpi_lid_attach(device_t dev);
54 static int acpi_lid_suspend(device_t dev);
55 static int acpi_lid_resume(device_t dev);
56 static void acpi_lid_notify_status_changed(void *arg);
57 static void acpi_lid_notify_handler(ACPI_HANDLE h, UINT32 notify,
60 static device_method_t acpi_lid_methods[] = {
61 /* Device interface */
62 DEVMETHOD(device_probe, acpi_lid_probe),
63 DEVMETHOD(device_attach, acpi_lid_attach),
64 DEVMETHOD(device_suspend, acpi_lid_suspend),
65 DEVMETHOD(device_resume, acpi_lid_resume),
70 static driver_t acpi_lid_driver = {
73 sizeof(struct acpi_lid_softc),
76 static devclass_t acpi_lid_devclass;
77 DRIVER_MODULE(acpi_lid, acpi, acpi_lid_driver, acpi_lid_devclass, 0, 0);
80 acpi_lid_probe(device_t dev)
82 if (acpi_get_type(dev) == ACPI_TYPE_DEVICE && !acpi_disabled("lid") &&
83 acpi_MatchHid(dev, "PNP0C0D")) {
85 device_set_desc(dev, "Control Method Lid Switch");
92 acpi_lid_attach(device_t dev)
94 struct acpi_lid_softc *sc;
96 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
98 sc = device_get_softc(dev);
100 sc->lid_handle = acpi_get_handle(dev);
102 /* Install notification handler */
103 AcpiInstallNotifyHandler(sc->lid_handle, ACPI_DEVICE_NOTIFY,
104 acpi_lid_notify_handler, sc);
105 acpi_device_enable_wake_capability(sc->lid_handle, 1);
111 acpi_lid_suspend(device_t dev)
113 struct acpi_lid_softc *sc;
115 sc = device_get_softc(dev);
116 acpi_device_enable_wake_event(sc->lid_handle);
121 acpi_lid_resume(device_t dev)
127 acpi_lid_notify_status_changed(void *arg)
129 struct acpi_lid_softc *sc;
130 struct acpi_softc *acpi_sc;
133 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
135 sc = (struct acpi_lid_softc *)arg;
138 * Evaluate _LID and check the return value, update lid status.
139 * Zero: The lid is closed
140 * Non-zero: The lid is open
142 status = acpi_EvaluateInteger(sc->lid_handle, "_LID", &sc->lid_status);
143 if (ACPI_FAILURE(status))
146 acpi_sc = acpi_device_get_parent_softc(sc->lid_dev);
150 ACPI_VPRINT(sc->lid_dev, acpi_sc, "Lid %s\n",
151 sc->lid_status ? "opened" : "closed");
153 acpi_UserNotify("Lid", sc->lid_handle, sc->lid_status);
155 if (sc->lid_status == 0)
156 EVENTHANDLER_INVOKE(acpi_sleep_event, acpi_sc->acpi_lid_switch_sx);
158 EVENTHANDLER_INVOKE(acpi_wakeup_event, acpi_sc->acpi_lid_switch_sx);
163 /* XXX maybe not here */
164 #define ACPI_NOTIFY_STATUS_CHANGED 0x80
167 acpi_lid_notify_handler(ACPI_HANDLE h, UINT32 notify, void *context)
169 struct acpi_lid_softc *sc = (struct acpi_lid_softc *)context;
171 ACPI_FUNCTION_TRACE_U32((char *)(uintptr_t)__func__, notify);
174 case ACPI_NOTIFY_STATUS_CHANGED:
175 AcpiOsQueueForExecution(OSD_PRIORITY_LO,
176 acpi_lid_notify_status_changed, sc);