2011-02-16 11:35:51 +03:00
|
|
|
/* $NetBSD: acpi_lid.c,v 1.43 2011/02/16 08:35:51 jruoho Exp $ */
|
2001-09-28 06:30:13 +04:00
|
|
|
|
|
|
|
/*
|
2003-04-17 05:34:14 +04:00
|
|
|
* Copyright 2001, 2003 Wasabi Systems, Inc.
|
2001-09-28 06:30:13 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Written by Jason R. Thorpe for Wasabi Systems, Inc.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed for the NetBSD Project by
|
|
|
|
* Wasabi Systems, Inc.
|
|
|
|
* 4. The name of Wasabi Systems, Inc. may not be used to endorse
|
|
|
|
* or promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ACPI Lid Switch driver.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 16:01:57 +03:00
|
|
|
#include <sys/cdefs.h>
|
2011-02-16 11:35:51 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: acpi_lid.c,v 1.43 2011/02/16 08:35:51 jruoho Exp $");
|
2001-11-13 16:01:57 +03:00
|
|
|
|
2001-09-28 06:30:13 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/device.h>
|
2010-02-28 20:22:41 +03:00
|
|
|
#include <sys/module.h>
|
2010-03-05 17:00:16 +03:00
|
|
|
#include <sys/systm.h>
|
2001-09-28 06:30:13 +04:00
|
|
|
|
|
|
|
#include <dev/acpi/acpireg.h>
|
|
|
|
#include <dev/acpi/acpivar.h>
|
|
|
|
|
2010-02-28 12:23:30 +03:00
|
|
|
#define _COMPONENT ACPI_LID_COMPONENT
|
|
|
|
ACPI_MODULE_NAME ("acpi_lid")
|
2010-01-30 21:35:48 +03:00
|
|
|
|
2010-04-27 09:57:43 +04:00
|
|
|
#define ACPI_NOTIFY_LID 0x80
|
|
|
|
|
2001-09-28 06:30:13 +04:00
|
|
|
struct acpilid_softc {
|
2010-02-28 12:23:30 +03:00
|
|
|
struct acpi_devnode *sc_node;
|
|
|
|
struct sysmon_pswitch sc_smpsw;
|
|
|
|
uint64_t sc_status;
|
2001-09-28 06:30:13 +04:00
|
|
|
};
|
|
|
|
|
2003-11-03 09:03:47 +03:00
|
|
|
static const char * const lid_hid[] = {
|
|
|
|
"PNP0C0D",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2008-03-26 18:31:59 +03:00
|
|
|
static int acpilid_match(device_t, cfdata_t, void *);
|
|
|
|
static void acpilid_attach(device_t, device_t, void *);
|
2008-07-15 20:19:37 +04:00
|
|
|
static int acpilid_detach(device_t, int);
|
2004-05-01 16:03:27 +04:00
|
|
|
static void acpilid_status_changed(void *);
|
2010-04-14 23:27:28 +04:00
|
|
|
static void acpilid_notify_handler(ACPI_HANDLE, uint32_t, void *);
|
2007-12-09 23:27:42 +03:00
|
|
|
|
2010-02-28 12:23:30 +03:00
|
|
|
CFATTACH_DECL_NEW(acpilid, sizeof(struct acpilid_softc),
|
|
|
|
acpilid_match, acpilid_attach, acpilid_detach, NULL);
|
|
|
|
|
2001-09-28 06:30:13 +04:00
|
|
|
/*
|
|
|
|
* acpilid_match:
|
|
|
|
*
|
|
|
|
* Autoconfiguration `match' routine.
|
|
|
|
*/
|
2004-05-01 16:03:27 +04:00
|
|
|
static int
|
2008-03-26 18:31:59 +03:00
|
|
|
acpilid_match(device_t parent, cfdata_t match, void *aux)
|
2001-09-28 06:30:13 +04:00
|
|
|
{
|
|
|
|
struct acpi_attach_args *aa = aux;
|
|
|
|
|
|
|
|
if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
|
2004-04-11 10:48:25 +04:00
|
|
|
return 0;
|
2001-09-28 06:30:13 +04:00
|
|
|
|
2004-04-11 10:48:25 +04:00
|
|
|
return acpi_match_hid(aa->aa_node->ad_devinfo, lid_hid);
|
2001-09-28 06:30:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* acpilid_attach:
|
|
|
|
*
|
|
|
|
* Autoconfiguration `attach' routine.
|
|
|
|
*/
|
2004-05-01 16:03:27 +04:00
|
|
|
static void
|
2008-03-26 18:31:59 +03:00
|
|
|
acpilid_attach(device_t parent, device_t self, void *aux)
|
2001-09-28 06:30:13 +04:00
|
|
|
{
|
2008-03-26 18:31:59 +03:00
|
|
|
struct acpilid_softc *sc = device_private(self);
|
2001-09-28 06:30:13 +04:00
|
|
|
struct acpi_attach_args *aa = aux;
|
|
|
|
|
2006-02-20 15:17:49 +03:00
|
|
|
aprint_naive(": ACPI Lid Switch\n");
|
|
|
|
aprint_normal(": ACPI Lid Switch\n");
|
2001-09-28 06:30:13 +04:00
|
|
|
|
|
|
|
sc->sc_node = aa->aa_node;
|
|
|
|
|
2008-03-26 18:31:59 +03:00
|
|
|
sc->sc_smpsw.smpsw_name = device_xname(self);
|
2003-04-18 05:31:34 +04:00
|
|
|
sc->sc_smpsw.smpsw_type = PSWITCH_TYPE_LID;
|
2010-02-28 12:23:30 +03:00
|
|
|
|
2010-03-06 00:01:44 +03:00
|
|
|
(void)pmf_device_register(self, NULL, NULL);
|
2010-02-28 12:23:30 +03:00
|
|
|
(void)sysmon_pswitch_register(&sc->sc_smpsw);
|
2010-04-15 11:02:24 +04:00
|
|
|
(void)acpi_register_notify(sc->sc_node, acpilid_notify_handler);
|
2007-12-09 23:27:42 +03:00
|
|
|
}
|
|
|
|
|
2008-07-15 20:19:37 +04:00
|
|
|
static int
|
|
|
|
acpilid_detach(device_t self, int flags)
|
|
|
|
{
|
|
|
|
struct acpilid_softc *sc = device_private(self);
|
|
|
|
|
|
|
|
pmf_device_deregister(self);
|
2010-04-15 11:02:24 +04:00
|
|
|
acpi_deregister_notify(sc->sc_node);
|
2008-07-15 20:19:37 +04:00
|
|
|
sysmon_pswitch_unregister(&sc->sc_smpsw);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-09-28 06:30:13 +04:00
|
|
|
/*
|
|
|
|
* acpilid_status_changed:
|
|
|
|
*
|
|
|
|
* Get, and possibly display, the lid status, and take action.
|
|
|
|
*/
|
2004-05-01 16:03:27 +04:00
|
|
|
static void
|
2001-09-28 06:30:13 +04:00
|
|
|
acpilid_status_changed(void *arg)
|
|
|
|
{
|
2010-02-28 12:23:30 +03:00
|
|
|
device_t dv = arg;
|
|
|
|
struct acpilid_softc *sc = device_private(dv);
|
2003-11-03 21:07:10 +03:00
|
|
|
ACPI_STATUS rv;
|
2001-09-28 06:30:13 +04:00
|
|
|
|
2010-02-28 12:23:30 +03:00
|
|
|
rv = acpi_eval_integer(sc->sc_node->ad_handle, "_LID", &sc->sc_status);
|
|
|
|
|
2003-11-03 21:07:10 +03:00
|
|
|
if (ACPI_FAILURE(rv))
|
2001-09-28 06:30:13 +04:00
|
|
|
return;
|
|
|
|
|
2010-02-28 12:23:30 +03:00
|
|
|
sysmon_pswitch_event(&sc->sc_smpsw, (sc->sc_status == 0) ?
|
2003-04-18 05:31:34 +04:00
|
|
|
PSWITCH_EVENT_PRESSED : PSWITCH_EVENT_RELEASED);
|
2001-09-28 06:30:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* acpilid_notify_handler:
|
|
|
|
*
|
|
|
|
* Callback from ACPI interrupt handler to notify us of an event.
|
|
|
|
*/
|
2004-05-01 16:03:27 +04:00
|
|
|
static void
|
2010-02-28 12:23:30 +03:00
|
|
|
acpilid_notify_handler(ACPI_HANDLE handle, uint32_t notify, void *context)
|
2001-09-28 06:30:13 +04:00
|
|
|
{
|
2010-02-28 12:23:30 +03:00
|
|
|
static const int handler = OSL_NOTIFY_HANDLER;
|
2008-03-26 18:31:59 +03:00
|
|
|
device_t dv = context;
|
2001-09-28 06:30:13 +04:00
|
|
|
|
|
|
|
switch (notify) {
|
2010-02-28 12:23:30 +03:00
|
|
|
|
2010-04-27 09:57:43 +04:00
|
|
|
case ACPI_NOTIFY_LID:
|
2010-02-28 12:23:30 +03:00
|
|
|
(void)AcpiOsExecute(handler, acpilid_status_changed, dv);
|
2001-09-28 06:30:13 +04:00
|
|
|
break;
|
|
|
|
|
2010-08-24 19:03:34 +04:00
|
|
|
case ACPI_NOTIFY_DEVICE_WAKE:
|
|
|
|
break;
|
|
|
|
|
2001-09-28 06:30:13 +04:00
|
|
|
default:
|
2010-08-24 19:03:34 +04:00
|
|
|
aprint_debug_dev(dv, "unknown notify 0x%02X\n", notify);
|
2001-09-28 06:30:13 +04:00
|
|
|
}
|
|
|
|
}
|
2007-12-09 23:27:42 +03:00
|
|
|
|
2010-02-28 20:22:41 +03:00
|
|
|
MODULE(MODULE_CLASS_DRIVER, acpilid, NULL);
|
|
|
|
|
2011-02-16 11:35:51 +03:00
|
|
|
#ifdef _MODULE
|
|
|
|
#include "ioconf.c"
|
|
|
|
#endif
|
2010-02-28 20:22:41 +03:00
|
|
|
|
|
|
|
static int
|
2011-02-16 11:35:51 +03:00
|
|
|
acpilid_modcmd(modcmd_t cmd, void *aux)
|
2010-02-28 20:22:41 +03:00
|
|
|
{
|
2011-02-16 11:35:51 +03:00
|
|
|
int rv = 0;
|
2010-02-28 20:22:41 +03:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
|
|
|
|
case MODULE_CMD_INIT:
|
|
|
|
|
2011-02-16 11:35:51 +03:00
|
|
|
#ifdef _MODULE
|
|
|
|
rv = config_init_component(cfdriver_ioconf_acpilid,
|
|
|
|
cfattach_ioconf_acpilid, cfdata_ioconf_acpilid);
|
|
|
|
#endif
|
|
|
|
break;
|
2010-02-28 20:22:41 +03:00
|
|
|
|
|
|
|
case MODULE_CMD_FINI:
|
|
|
|
|
2011-02-16 11:35:51 +03:00
|
|
|
#ifdef _MODULE
|
|
|
|
rv = config_fini_component(cfdriver_ioconf_acpilid,
|
|
|
|
cfattach_ioconf_acpilid, cfdata_ioconf_acpilid);
|
|
|
|
#endif
|
|
|
|
break;
|
2010-02-28 20:22:41 +03:00
|
|
|
|
|
|
|
default:
|
2011-02-16 11:35:51 +03:00
|
|
|
rv = ENOTTY;
|
2010-02-28 20:22:41 +03:00
|
|
|
}
|
|
|
|
|
2011-02-16 11:35:51 +03:00
|
|
|
return rv;
|
|
|
|
}
|