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