acpi_button.c revision 1.7
11.7Sthorpej#define ACPI_BUT_DEBUG 21.7Sthorpej/* $NetBSD: acpi_button.c,v 1.7 2003/04/17 01:22:21 thorpej Exp $ */ 31.1Sthorpej 41.1Sthorpej/* 51.7Sthorpej * Copyright 2001, 2003 Wasabi Systems, Inc. 61.1Sthorpej * All rights reserved. 71.1Sthorpej * 81.1Sthorpej * Written by Jason R. Thorpe for Wasabi Systems, Inc. 91.1Sthorpej * 101.1Sthorpej * Redistribution and use in source and binary forms, with or without 111.1Sthorpej * modification, are permitted provided that the following conditions 121.1Sthorpej * are met: 131.1Sthorpej * 1. Redistributions of source code must retain the above copyright 141.1Sthorpej * notice, this list of conditions and the following disclaimer. 151.1Sthorpej * 2. Redistributions in binary form must reproduce the above copyright 161.1Sthorpej * notice, this list of conditions and the following disclaimer in the 171.1Sthorpej * documentation and/or other materials provided with the distribution. 181.1Sthorpej * 3. All advertising materials mentioning features or use of this software 191.1Sthorpej * must display the following acknowledgement: 201.1Sthorpej * This product includes software developed for the NetBSD Project by 211.1Sthorpej * Wasabi Systems, Inc. 221.1Sthorpej * 4. The name of Wasabi Systems, Inc. may not be used to endorse 231.1Sthorpej * or promote products derived from this software without specific prior 241.1Sthorpej * written permission. 251.1Sthorpej * 261.1Sthorpej * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 271.1Sthorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 281.1Sthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 291.1Sthorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 301.1Sthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 311.1Sthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 321.1Sthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 331.1Sthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 341.1Sthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 351.1Sthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 361.1Sthorpej * POSSIBILITY OF SUCH DAMAGE. 371.1Sthorpej */ 381.1Sthorpej 391.1Sthorpej/* 401.1Sthorpej * ACPI Button driver. 411.1Sthorpej */ 421.2Slukem 431.2Slukem#include <sys/cdefs.h> 441.7Sthorpej__KERNEL_RCSID(0, "$NetBSD: acpi_button.c,v 1.7 2003/04/17 01:22:21 thorpej Exp $"); 451.1Sthorpej 461.1Sthorpej#include <sys/param.h> 471.1Sthorpej#include <sys/systm.h> 481.1Sthorpej#include <sys/device.h> 491.1Sthorpej 501.1Sthorpej#include <dev/acpi/acpica.h> 511.1Sthorpej#include <dev/acpi/acpireg.h> 521.1Sthorpej#include <dev/acpi/acpivar.h> 531.1Sthorpej 541.7Sthorpej#include <dev/sysmon/sysmonvar.h> 551.7Sthorpej 561.1Sthorpejstruct acpibut_softc { 571.1Sthorpej struct device sc_dev; /* base device glue */ 581.1Sthorpej struct acpi_devnode *sc_node; /* our ACPI devnode */ 591.7Sthorpej struct sysmon_pswitch sc_smpsw; /* our sysmon glue */ 601.1Sthorpej int sc_flags; /* see below */ 611.1Sthorpej}; 621.1Sthorpej 631.1Sthorpej#define ACPIBUT_F_VERBOSE 0x01 /* verbose events */ 641.1Sthorpej 651.1Sthorpejint acpibut_match(struct device *, struct cfdata *, void *); 661.1Sthorpejvoid acpibut_attach(struct device *, struct device *, void *); 671.1Sthorpej 681.5SthorpejCFATTACH_DECL(acpibut, sizeof(struct acpibut_softc), 691.6Sthorpej acpibut_match, acpibut_attach, NULL, NULL); 701.1Sthorpej 711.7Sthorpejvoid acpibut_pressed_event(void *); 721.1Sthorpejvoid acpibut_notify_handler(ACPI_HANDLE, UINT32, void *context); 731.1Sthorpej 741.1Sthorpej/* 751.1Sthorpej * acpibut_match: 761.1Sthorpej * 771.1Sthorpej * Autoconfiguration `match' routine. 781.1Sthorpej */ 791.1Sthorpejint 801.1Sthorpejacpibut_match(struct device *parent, struct cfdata *match, void *aux) 811.1Sthorpej{ 821.1Sthorpej struct acpi_attach_args *aa = aux; 831.1Sthorpej 841.1Sthorpej if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE) 851.1Sthorpej return (0); 861.1Sthorpej 871.1Sthorpej if (strcmp(aa->aa_node->ad_devinfo.HardwareId, "PNP0C0C") == 0 || 881.1Sthorpej strcmp(aa->aa_node->ad_devinfo.HardwareId, "PNP0C0E") == 0) 891.1Sthorpej return (1); 901.1Sthorpej 911.1Sthorpej return (0); 921.1Sthorpej} 931.1Sthorpej 941.1Sthorpej/* 951.1Sthorpej * acpibut_attach: 961.1Sthorpej * 971.1Sthorpej * Autoconfiguration `attach' routine. 981.1Sthorpej */ 991.1Sthorpejvoid 1001.1Sthorpejacpibut_attach(struct device *parent, struct device *self, void *aux) 1011.1Sthorpej{ 1021.1Sthorpej struct acpibut_softc *sc = (void *) self; 1031.1Sthorpej struct acpi_attach_args *aa = aux; 1041.1Sthorpej const char *desc; 1051.1Sthorpej ACPI_STATUS rv; 1061.1Sthorpej 1071.7Sthorpej sc->sc_smpsw.smpsw_name = sc->sc_dev.dv_xname; 1081.7Sthorpej 1091.1Sthorpej if (strcmp(aa->aa_node->ad_devinfo.HardwareId, "PNP0C0C") == 0) { 1101.7Sthorpej sc->sc_smpsw.smpsw_type = SMPSW_TYPE_POWER; 1111.1Sthorpej desc = "Power"; 1121.1Sthorpej } else if (strcmp(aa->aa_node->ad_devinfo.HardwareId, "PNP0C0E") == 0) { 1131.7Sthorpej sc->sc_smpsw.smpsw_type = SMPSW_TYPE_SLEEP; 1141.1Sthorpej desc = "Sleep"; 1151.1Sthorpej } else { 1161.1Sthorpej printf("\n"); 1171.1Sthorpej panic("acpibut_attach: impossible"); 1181.1Sthorpej } 1191.1Sthorpej 1201.1Sthorpej printf(": ACPI %s Button\n", desc); 1211.1Sthorpej 1221.1Sthorpej sc->sc_node = aa->aa_node; 1231.1Sthorpej 1241.7Sthorpej if (sysmon_pswitch_register(&sc->sc_smpsw) != 0) { 1251.7Sthorpej printf("%s: unable to register with sysmon\n", 1261.7Sthorpej sc->sc_dev.dv_xname); 1271.7Sthorpej return; 1281.7Sthorpej } 1291.7Sthorpej 1301.1Sthorpej rv = AcpiInstallNotifyHandler(sc->sc_node->ad_handle, 1311.1Sthorpej ACPI_DEVICE_NOTIFY, acpibut_notify_handler, sc); 1321.1Sthorpej if (rv != AE_OK) { 1331.1Sthorpej printf("%s: unable to register device notify handler: %d\n", 1341.1Sthorpej sc->sc_dev.dv_xname, rv); 1351.1Sthorpej return; 1361.1Sthorpej } 1371.1Sthorpej 1381.1Sthorpej#ifdef ACPI_BUT_DEBUG 1391.1Sthorpej /* Display the current state when it changes. */ 1401.1Sthorpej sc->sc_flags = ACPIBUT_F_VERBOSE; 1411.1Sthorpej#endif 1421.1Sthorpej} 1431.1Sthorpej 1441.1Sthorpej/* 1451.7Sthorpej * acpibut_pressed_event: 1461.1Sthorpej * 1471.7Sthorpej * Deal with a button being pressed. 1481.1Sthorpej */ 1491.1Sthorpejvoid 1501.7Sthorpejacpibut_pressed_event(void *arg) 1511.1Sthorpej{ 1521.1Sthorpej struct acpibut_softc *sc = arg; 1531.1Sthorpej 1541.1Sthorpej if (sc->sc_flags & ACPIBUT_F_VERBOSE) 1551.7Sthorpej printf("%s: button pressed\n", sc->sc_dev.dv_xname); 1561.1Sthorpej 1571.7Sthorpej sysmon_pswitch_event(&sc->sc_smpsw, SMPSW_EVENT_PRESSED); 1581.1Sthorpej} 1591.1Sthorpej 1601.1Sthorpej/* 1611.1Sthorpej * acpibut_notify_handler: 1621.1Sthorpej * 1631.1Sthorpej * Callback from ACPI interrupt handler to notify us of an event. 1641.1Sthorpej */ 1651.1Sthorpejvoid 1661.1Sthorpejacpibut_notify_handler(ACPI_HANDLE handle, UINT32 notify, void *context) 1671.1Sthorpej{ 1681.1Sthorpej struct acpibut_softc *sc = context; 1691.1Sthorpej int rv; 1701.1Sthorpej 1711.1Sthorpej switch (notify) { 1721.1Sthorpej case ACPI_NOTIFY_S0PowerButtonPressed: 1731.1Sthorpej#if 0 1741.1Sthorpej case ACPI_NOTIFY_S0SleepButtonPressed: /* same as above */ 1751.1Sthorpej#endif 1761.1Sthorpej#ifdef ACPI_BUT_DEBUG 1771.1Sthorpej printf("%s: received ButtonPressed message\n", 1781.1Sthorpej sc->sc_dev.dv_xname); 1791.1Sthorpej#endif 1801.1Sthorpej rv = AcpiOsQueueForExecution(OSD_PRIORITY_LO, 1811.7Sthorpej acpibut_pressed_event, sc); 1821.1Sthorpej if (rv != AE_OK) 1831.1Sthorpej printf("%s: WARNING: unable to queue button pressed " 1841.7Sthorpej "callback: %d\n", sc->sc_dev.dv_xname, rv); 1851.1Sthorpej break; 1861.1Sthorpej 1871.1Sthorpej /* XXX ACPI_NOTIFY_DeviceWake?? */ 1881.1Sthorpej 1891.1Sthorpej default: 1901.1Sthorpej printf("%s: received unknown notify message: 0x%x\n", 1911.1Sthorpej sc->sc_dev.dv_xname, notify); 1921.1Sthorpej } 1931.1Sthorpej} 194