Home | History | Annotate | Line # | Download | only in acpi
asus_acpi.c revision 1.9
      1  1.9  jmcneill /* $NetBSD: asus_acpi.c,v 1.9 2009/08/03 16:33:55 jmcneill Exp $ */
      2  1.1  jmcneill 
      3  1.1  jmcneill /*-
      4  1.7  jmcneill  * Copyright (c) 2007, 2008, 2009 Jared D. McNeill <jmcneill (at) invisible.ca>
      5  1.1  jmcneill  * All rights reserved.
      6  1.1  jmcneill  *
      7  1.1  jmcneill  * Redistribution and use in source and binary forms, with or without
      8  1.1  jmcneill  * modification, are permitted provided that the following conditions
      9  1.1  jmcneill  * are met:
     10  1.1  jmcneill  * 1. Redistributions of source code must retain the above copyright
     11  1.1  jmcneill  *    notice, this list of conditions and the following disclaimer.
     12  1.1  jmcneill  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  jmcneill  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  jmcneill  *    documentation and/or other materials provided with the distribution.
     15  1.1  jmcneill  *
     16  1.1  jmcneill  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17  1.1  jmcneill  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  1.1  jmcneill  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  1.1  jmcneill  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20  1.1  jmcneill  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  1.1  jmcneill  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  1.1  jmcneill  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  1.1  jmcneill  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  1.1  jmcneill  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  1.1  jmcneill  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  1.1  jmcneill  * POSSIBILITY OF SUCH DAMAGE.
     27  1.1  jmcneill  */
     28  1.1  jmcneill 
     29  1.1  jmcneill #include <sys/cdefs.h>
     30  1.9  jmcneill __KERNEL_RCSID(0, "$NetBSD: asus_acpi.c,v 1.9 2009/08/03 16:33:55 jmcneill Exp $");
     31  1.1  jmcneill 
     32  1.1  jmcneill #include <sys/types.h>
     33  1.1  jmcneill #include <sys/param.h>
     34  1.1  jmcneill #include <sys/malloc.h>
     35  1.1  jmcneill #include <sys/buf.h>
     36  1.1  jmcneill #include <sys/callout.h>
     37  1.1  jmcneill #include <sys/kernel.h>
     38  1.1  jmcneill #include <sys/device.h>
     39  1.7  jmcneill #include <sys/sysctl.h>
     40  1.1  jmcneill 
     41  1.1  jmcneill #include <dev/acpi/acpivar.h>
     42  1.1  jmcneill 
     43  1.7  jmcneill struct asus_softc {
     44  1.1  jmcneill 	device_t		sc_dev;
     45  1.1  jmcneill 	struct acpi_devnode	*sc_node;
     46  1.1  jmcneill 
     47  1.1  jmcneill #define ASUS_PSW_DISPLAY_CYCLE	0
     48  1.1  jmcneill #define ASUS_PSW_LAST		1
     49  1.1  jmcneill 	struct sysmon_pswitch	sc_smpsw[ASUS_PSW_LAST];
     50  1.1  jmcneill 	bool			sc_smpsw_valid;
     51  1.6  jmcneill 
     52  1.7  jmcneill 	struct sysmon_envsys	*sc_sme;
     53  1.7  jmcneill #define	ASUS_SENSOR_FAN		0
     54  1.7  jmcneill #define	ASUS_SENSOR_LAST	1
     55  1.7  jmcneill 	envsys_data_t		sc_sensor[ASUS_SENSOR_LAST];
     56  1.7  jmcneill 
     57  1.6  jmcneill 	ACPI_INTEGER		sc_brightness;
     58  1.7  jmcneill 	ACPI_INTEGER		sc_cfvnum;
     59  1.7  jmcneill 
     60  1.7  jmcneill 	struct sysctllog	*sc_log;
     61  1.7  jmcneill 	int			sc_cfv_mib;
     62  1.7  jmcneill 	int			sc_cfvnum_mib;
     63  1.7  jmcneill };
     64  1.1  jmcneill 
     65  1.1  jmcneill #define ASUS_NOTIFY_WirelessSwitch	0x10
     66  1.1  jmcneill #define ASUS_NOTIFY_BrightnessLow	0x20
     67  1.1  jmcneill #define	ASUS_NOTIFY_BrightnessHigh	0x2f
     68  1.1  jmcneill #define ASUS_NOTIFY_DisplayCycle	0x30
     69  1.1  jmcneill #define ASUS_NOTIFY_WindowSwitch	0x12	/* XXXJDM ?? */
     70  1.1  jmcneill #define ASUS_NOTIFY_VolumeMute		0x13
     71  1.1  jmcneill #define ASUS_NOTIFY_VolumeDown		0x14
     72  1.1  jmcneill #define ASUS_NOTIFY_VolumeUp		0x15
     73  1.1  jmcneill 
     74  1.1  jmcneill #define	ASUS_METHOD_SDSP	"SDSP"
     75  1.1  jmcneill #define		ASUS_SDSP_LCD	0x01
     76  1.1  jmcneill #define		ASUS_SDSP_CRT	0x02
     77  1.1  jmcneill #define		ASUS_SDSP_TV	0x04
     78  1.1  jmcneill #define		ASUS_SDSP_DVI	0x08
     79  1.1  jmcneill #define		ASUS_SDSP_ALL	\
     80  1.1  jmcneill 		(ASUS_SDSP_LCD | ASUS_SDSP_CRT | ASUS_SDSP_TV | ASUS_SDSP_DVI)
     81  1.6  jmcneill #define ASUS_METHOD_PBLG	"PBLG"
     82  1.6  jmcneill #define ASUS_METHOD_PBLS	"PBLS"
     83  1.7  jmcneill #define	ASUS_METHOD_CFVS	"CFVS"
     84  1.7  jmcneill #define	ASUS_METHOD_CFVG	"CFVG"
     85  1.7  jmcneill 
     86  1.7  jmcneill #define	ASUS_EC_METHOD_FAN_RPMH	"\\_SB.PCI0.SBRG.EC0.SC05"
     87  1.7  jmcneill #define	ASUS_EC_METHOD_FAN_RPML	"\\_SB.PCI0.SBRG.EC0.SC06"
     88  1.1  jmcneill 
     89  1.3  jmcneill static int	asus_match(device_t, cfdata_t, void *);
     90  1.1  jmcneill static void	asus_attach(device_t, device_t, void *);
     91  1.7  jmcneill static int	asus_detach(device_t, int);
     92  1.1  jmcneill 
     93  1.1  jmcneill static void	asus_notify_handler(ACPI_HANDLE, UINT32, void *);
     94  1.1  jmcneill 
     95  1.1  jmcneill static void	asus_init(device_t);
     96  1.6  jmcneill static bool	asus_suspend(device_t PMF_FN_PROTO);
     97  1.1  jmcneill static bool	asus_resume(device_t PMF_FN_PROTO);
     98  1.1  jmcneill 
     99  1.7  jmcneill static void	asus_sysctl_setup(struct asus_softc *);
    100  1.7  jmcneill 
    101  1.7  jmcneill static void	asus_sensors_refresh(struct sysmon_envsys *, envsys_data_t *);
    102  1.7  jmcneill static bool	asus_get_fan_speed(struct asus_softc *, uint32_t *);
    103  1.7  jmcneill 
    104  1.7  jmcneill CFATTACH_DECL_NEW(asus, sizeof(struct asus_softc),
    105  1.7  jmcneill     asus_match, asus_attach, asus_detach, NULL);
    106  1.1  jmcneill 
    107  1.1  jmcneill static const char * const asus_ids[] = {
    108  1.1  jmcneill 	"ASUS010",
    109  1.1  jmcneill 	NULL
    110  1.1  jmcneill };
    111  1.1  jmcneill 
    112  1.1  jmcneill static int
    113  1.1  jmcneill asus_match(device_t parent, cfdata_t match, void *opaque)
    114  1.1  jmcneill {
    115  1.1  jmcneill 	struct acpi_attach_args *aa = opaque;
    116  1.1  jmcneill 
    117  1.1  jmcneill 	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
    118  1.1  jmcneill 		return 0;
    119  1.1  jmcneill 
    120  1.1  jmcneill 	return acpi_match_hid(aa->aa_node->ad_devinfo, asus_ids);
    121  1.1  jmcneill }
    122  1.1  jmcneill 
    123  1.1  jmcneill static void
    124  1.1  jmcneill asus_attach(device_t parent, device_t self, void *opaque)
    125  1.1  jmcneill {
    126  1.7  jmcneill 	struct asus_softc *sc = device_private(self);
    127  1.1  jmcneill 	struct acpi_attach_args *aa = opaque;
    128  1.1  jmcneill 	ACPI_STATUS rv;
    129  1.1  jmcneill 
    130  1.1  jmcneill 	sc->sc_node = aa->aa_node;
    131  1.1  jmcneill 	sc->sc_dev = self;
    132  1.1  jmcneill 
    133  1.1  jmcneill 	aprint_naive("\n");
    134  1.1  jmcneill 	aprint_normal("\n");
    135  1.1  jmcneill 
    136  1.1  jmcneill 	asus_init(self);
    137  1.9  jmcneill 	asus_sysctl_setup(sc);
    138  1.1  jmcneill 
    139  1.1  jmcneill 	sc->sc_smpsw_valid = true;
    140  1.1  jmcneill 	sc->sc_smpsw[ASUS_PSW_DISPLAY_CYCLE].smpsw_name =
    141  1.1  jmcneill 	    PSWITCH_HK_DISPLAY_CYCLE;
    142  1.1  jmcneill 	sc->sc_smpsw[ASUS_PSW_DISPLAY_CYCLE].smpsw_type =
    143  1.1  jmcneill 	    PSWITCH_TYPE_HOTKEY;
    144  1.1  jmcneill 	if (sysmon_pswitch_register(&sc->sc_smpsw[ASUS_PSW_DISPLAY_CYCLE])) {
    145  1.1  jmcneill 		aprint_error_dev(self, "couldn't register with sysmon\n");
    146  1.1  jmcneill 		sc->sc_smpsw_valid = false;
    147  1.1  jmcneill 	}
    148  1.1  jmcneill 
    149  1.7  jmcneill 	if (asus_get_fan_speed(sc, NULL) == false)
    150  1.7  jmcneill 		goto nosensors;
    151  1.7  jmcneill 
    152  1.7  jmcneill 	sc->sc_sme = sysmon_envsys_create();
    153  1.7  jmcneill 
    154  1.7  jmcneill 	strcpy(sc->sc_sensor[ASUS_SENSOR_FAN].desc, "fan");
    155  1.7  jmcneill 	sc->sc_sensor[ASUS_SENSOR_FAN].units = ENVSYS_SFANRPM;
    156  1.7  jmcneill 	sysmon_envsys_sensor_attach(sc->sc_sme,
    157  1.7  jmcneill 	    &sc->sc_sensor[ASUS_SENSOR_FAN]);
    158  1.7  jmcneill 
    159  1.7  jmcneill 	sc->sc_sme->sme_name = device_xname(self);
    160  1.7  jmcneill 	sc->sc_sme->sme_cookie = sc;
    161  1.7  jmcneill 	sc->sc_sme->sme_refresh = asus_sensors_refresh;
    162  1.7  jmcneill 
    163  1.7  jmcneill 	if (sysmon_envsys_register(sc->sc_sme)) {
    164  1.7  jmcneill 		aprint_error_dev(self, "couldn't register with envsys\n");
    165  1.7  jmcneill 		sysmon_envsys_destroy(sc->sc_sme);
    166  1.7  jmcneill 		sc->sc_sme = NULL;
    167  1.7  jmcneill 	}
    168  1.7  jmcneill nosensors:
    169  1.7  jmcneill 
    170  1.1  jmcneill 	rv = AcpiInstallNotifyHandler(sc->sc_node->ad_handle, ACPI_ALL_NOTIFY,
    171  1.1  jmcneill 	    asus_notify_handler, sc);
    172  1.1  jmcneill 	if (ACPI_FAILURE(rv))
    173  1.1  jmcneill 		aprint_error_dev(self, "couldn't install notify handler: %s\n",
    174  1.1  jmcneill 		    AcpiFormatException(rv));
    175  1.1  jmcneill 
    176  1.6  jmcneill 	if (!pmf_device_register(self, asus_suspend, asus_resume))
    177  1.1  jmcneill 		aprint_error_dev(self, "couldn't establish power handler\n");
    178  1.1  jmcneill }
    179  1.1  jmcneill 
    180  1.7  jmcneill static int
    181  1.7  jmcneill asus_detach(device_t self, int flags)
    182  1.7  jmcneill {
    183  1.7  jmcneill 	struct asus_softc *sc = device_private(self);
    184  1.7  jmcneill 	int i;
    185  1.7  jmcneill 
    186  1.7  jmcneill 	if (sc->sc_smpsw_valid)
    187  1.7  jmcneill 		for (i = 0; i < ASUS_PSW_LAST; i++)
    188  1.7  jmcneill 			sysmon_pswitch_unregister(&sc->sc_smpsw[i]);
    189  1.7  jmcneill 
    190  1.7  jmcneill 	if (sc->sc_sme)
    191  1.7  jmcneill 		sysmon_envsys_unregister(sc->sc_sme);
    192  1.7  jmcneill 	if (sc->sc_log)
    193  1.7  jmcneill 		sysctl_teardown(&sc->sc_log);
    194  1.7  jmcneill 	pmf_device_deregister(self);
    195  1.7  jmcneill 
    196  1.7  jmcneill 	return 0;
    197  1.7  jmcneill }
    198  1.7  jmcneill 
    199  1.1  jmcneill static void
    200  1.1  jmcneill asus_notify_handler(ACPI_HANDLE hdl, UINT32 notify, void *opaque)
    201  1.1  jmcneill {
    202  1.7  jmcneill 	struct asus_softc *sc = opaque;
    203  1.1  jmcneill 
    204  1.1  jmcneill 	if (notify >= ASUS_NOTIFY_BrightnessLow &&
    205  1.1  jmcneill 	    notify <= ASUS_NOTIFY_BrightnessHigh) {
    206  1.1  jmcneill 		aprint_debug_dev(sc->sc_dev, "brightness %d percent\n",
    207  1.1  jmcneill 		    (notify & 0xf) * 100 / 0xf);
    208  1.1  jmcneill 		return;
    209  1.1  jmcneill 	}
    210  1.1  jmcneill 
    211  1.1  jmcneill 	switch (notify) {
    212  1.1  jmcneill 	case ASUS_NOTIFY_WirelessSwitch:	/* handled by AML */
    213  1.1  jmcneill 	case ASUS_NOTIFY_WindowSwitch:		/* XXXJDM what is this? */
    214  1.1  jmcneill 		break;
    215  1.1  jmcneill 	case ASUS_NOTIFY_DisplayCycle:
    216  1.1  jmcneill 		if (sc->sc_smpsw_valid == false)
    217  1.1  jmcneill 			break;
    218  1.1  jmcneill 		sysmon_pswitch_event(&sc->sc_smpsw[ASUS_PSW_DISPLAY_CYCLE],
    219  1.1  jmcneill 		    PSWITCH_EVENT_PRESSED);
    220  1.1  jmcneill 		break;
    221  1.1  jmcneill 	case ASUS_NOTIFY_VolumeMute:
    222  1.1  jmcneill 		pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_TOGGLE);
    223  1.1  jmcneill 		break;
    224  1.1  jmcneill 	case ASUS_NOTIFY_VolumeDown:
    225  1.1  jmcneill 		pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_DOWN);
    226  1.1  jmcneill 		break;
    227  1.1  jmcneill 	case ASUS_NOTIFY_VolumeUp:
    228  1.1  jmcneill 		pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_UP);
    229  1.1  jmcneill 		break;
    230  1.1  jmcneill 	default:
    231  1.1  jmcneill 		aprint_debug_dev(sc->sc_dev, "unknown event 0x%02x\n", notify);
    232  1.1  jmcneill 		break;
    233  1.1  jmcneill 	}
    234  1.1  jmcneill }
    235  1.1  jmcneill 
    236  1.1  jmcneill static void
    237  1.1  jmcneill asus_init(device_t self)
    238  1.1  jmcneill {
    239  1.7  jmcneill 	struct asus_softc *sc = device_private(self);
    240  1.1  jmcneill 	ACPI_STATUS rv;
    241  1.1  jmcneill 	ACPI_OBJECT param;
    242  1.1  jmcneill 	ACPI_OBJECT_LIST params;
    243  1.1  jmcneill 	ACPI_BUFFER ret;
    244  1.7  jmcneill 	ACPI_INTEGER cfv;
    245  1.1  jmcneill 
    246  1.1  jmcneill 	ret.Pointer = NULL;
    247  1.1  jmcneill 	ret.Length = ACPI_ALLOCATE_BUFFER;
    248  1.1  jmcneill 	param.Type = ACPI_TYPE_INTEGER;
    249  1.1  jmcneill 	param.Integer.Value = 0x40;	/* disable ASL display switching */
    250  1.1  jmcneill 	params.Pointer = &param;
    251  1.1  jmcneill 	params.Count = 1;
    252  1.1  jmcneill 
    253  1.1  jmcneill 	rv = AcpiEvaluateObject(sc->sc_node->ad_handle, "INIT",
    254  1.1  jmcneill 	    &params, &ret);
    255  1.1  jmcneill 	if (ACPI_FAILURE(rv))
    256  1.1  jmcneill 		aprint_error_dev(self, "couldn't evaluate INIT: %s\n",
    257  1.1  jmcneill 		    AcpiFormatException(rv));
    258  1.5  jmcneill 
    259  1.5  jmcneill 	if (ret.Pointer)
    260  1.5  jmcneill 		AcpiOsFree(ret.Pointer);
    261  1.7  jmcneill 
    262  1.7  jmcneill 	rv = acpi_eval_integer(sc->sc_node->ad_handle, ASUS_METHOD_CFVG, &cfv);
    263  1.7  jmcneill 	if (ACPI_FAILURE(rv))
    264  1.7  jmcneill 		return;
    265  1.7  jmcneill 
    266  1.7  jmcneill 	sc->sc_cfvnum = (cfv >> 8) & 0xff;
    267  1.1  jmcneill }
    268  1.1  jmcneill 
    269  1.1  jmcneill static bool
    270  1.6  jmcneill asus_suspend(device_t self PMF_FN_ARGS)
    271  1.6  jmcneill {
    272  1.7  jmcneill 	struct asus_softc *sc = device_private(self);
    273  1.6  jmcneill 	ACPI_STATUS rv;
    274  1.6  jmcneill 
    275  1.6  jmcneill 	/* capture display brightness when we're sleeping */
    276  1.6  jmcneill 	rv = acpi_eval_integer(sc->sc_node->ad_handle, ASUS_METHOD_PBLG,
    277  1.6  jmcneill 	    &sc->sc_brightness);
    278  1.6  jmcneill 	if (ACPI_FAILURE(rv))
    279  1.6  jmcneill 		aprint_error_dev(sc->sc_dev, "couldn't evaluate PBLG: %s\n",
    280  1.6  jmcneill 		    AcpiFormatException(rv));
    281  1.6  jmcneill 
    282  1.6  jmcneill 	return true;
    283  1.6  jmcneill }
    284  1.6  jmcneill 
    285  1.6  jmcneill static bool
    286  1.1  jmcneill asus_resume(device_t self PMF_FN_ARGS)
    287  1.1  jmcneill {
    288  1.7  jmcneill 	struct asus_softc *sc = device_private(self);
    289  1.1  jmcneill 	ACPI_STATUS rv;
    290  1.1  jmcneill 	ACPI_OBJECT param;
    291  1.1  jmcneill 	ACPI_OBJECT_LIST params;
    292  1.1  jmcneill 	ACPI_BUFFER ret;
    293  1.1  jmcneill 
    294  1.1  jmcneill 	asus_init(self);
    295  1.1  jmcneill 
    296  1.6  jmcneill 	/* restore previous display brightness */
    297  1.1  jmcneill 	ret.Pointer = NULL;
    298  1.1  jmcneill 	ret.Length = ACPI_ALLOCATE_BUFFER;
    299  1.1  jmcneill 	param.Type = ACPI_TYPE_INTEGER;
    300  1.6  jmcneill 	param.Integer.Value = sc->sc_brightness;
    301  1.1  jmcneill 	params.Pointer = &param;
    302  1.1  jmcneill 	params.Count = 1;
    303  1.1  jmcneill 
    304  1.6  jmcneill 	rv = AcpiEvaluateObject(sc->sc_node->ad_handle, ASUS_METHOD_PBLS,
    305  1.1  jmcneill 	    &params, &ret);
    306  1.1  jmcneill 	if (ACPI_FAILURE(rv))
    307  1.6  jmcneill 		aprint_error_dev(self, "couldn't evaluate PBLS: %s\n",
    308  1.1  jmcneill 		    AcpiFormatException(rv));
    309  1.1  jmcneill 
    310  1.1  jmcneill 	return true;
    311  1.1  jmcneill }
    312  1.7  jmcneill 
    313  1.7  jmcneill static int
    314  1.7  jmcneill asus_sysctl_verify(SYSCTLFN_ARGS)
    315  1.7  jmcneill {
    316  1.7  jmcneill 	struct sysctlnode node;
    317  1.7  jmcneill 	struct asus_softc *sc;
    318  1.7  jmcneill 	ACPI_STATUS rv;
    319  1.7  jmcneill 	ACPI_INTEGER cfv;
    320  1.7  jmcneill 	ACPI_OBJECT param, retval;
    321  1.7  jmcneill 	ACPI_OBJECT_LIST params;
    322  1.7  jmcneill 	ACPI_BUFFER ret;
    323  1.7  jmcneill 	int err, tmp;
    324  1.7  jmcneill 
    325  1.7  jmcneill 	node = *rnode;
    326  1.7  jmcneill 	sc = rnode->sysctl_data;
    327  1.7  jmcneill 	if (node.sysctl_num == sc->sc_cfv_mib) {
    328  1.7  jmcneill 		rv = acpi_eval_integer(sc->sc_node->ad_handle,
    329  1.7  jmcneill 		    ASUS_METHOD_CFVG, &cfv);
    330  1.7  jmcneill 		if (ACPI_FAILURE(rv))
    331  1.7  jmcneill 			return ENXIO;
    332  1.7  jmcneill 		tmp = cfv & 0xff;
    333  1.7  jmcneill 		node.sysctl_data = &tmp;
    334  1.7  jmcneill 		err = sysctl_lookup(SYSCTLFN_CALL(&node));
    335  1.7  jmcneill 		if (err || newp == NULL)
    336  1.7  jmcneill 			return err;
    337  1.7  jmcneill 
    338  1.7  jmcneill 		if (tmp < 0 || tmp >= sc->sc_cfvnum)
    339  1.7  jmcneill 			return EINVAL;
    340  1.7  jmcneill 
    341  1.7  jmcneill 		ret.Pointer = &retval;
    342  1.7  jmcneill 		ret.Length = sizeof(retval);
    343  1.7  jmcneill 		param.Type = ACPI_TYPE_INTEGER;
    344  1.7  jmcneill 		param.Integer.Value = tmp;
    345  1.7  jmcneill 		params.Pointer = &param;
    346  1.7  jmcneill 		params.Count = 1;
    347  1.7  jmcneill 
    348  1.7  jmcneill 		rv = AcpiEvaluateObject(sc->sc_node->ad_handle,
    349  1.7  jmcneill 		    ASUS_METHOD_CFVS, &params, &ret);
    350  1.7  jmcneill 		if (ACPI_FAILURE(rv))
    351  1.7  jmcneill 			return ENXIO;
    352  1.7  jmcneill 	}
    353  1.7  jmcneill 
    354  1.7  jmcneill 	return 0;
    355  1.7  jmcneill }
    356  1.7  jmcneill 
    357  1.7  jmcneill static void
    358  1.7  jmcneill asus_sysctl_setup(struct asus_softc *sc)
    359  1.7  jmcneill {
    360  1.7  jmcneill 	const struct sysctlnode *node, *node_cfv, *node_ncfv;
    361  1.7  jmcneill 	int err, node_mib;
    362  1.7  jmcneill 
    363  1.7  jmcneill 	if (sc->sc_cfvnum == 0)
    364  1.7  jmcneill 		return;
    365  1.7  jmcneill 
    366  1.7  jmcneill 	err = sysctl_createv(&sc->sc_log, 0, NULL, NULL, 0,
    367  1.7  jmcneill 	    CTLTYPE_NODE, "hw", NULL, NULL, 0, NULL, 0, CTL_HW, CTL_EOL);
    368  1.7  jmcneill 	if (err)
    369  1.7  jmcneill 		goto sysctl_err;
    370  1.7  jmcneill 	err = sysctl_createv(&sc->sc_log, 0, NULL, &node, 0,
    371  1.7  jmcneill 	    CTLTYPE_NODE, device_xname(sc->sc_dev), NULL, NULL, 0,
    372  1.7  jmcneill 	    NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL);
    373  1.7  jmcneill 	if (err)
    374  1.7  jmcneill 		goto sysctl_err;
    375  1.7  jmcneill 	node_mib = node->sysctl_num;
    376  1.7  jmcneill 	err = sysctl_createv(&sc->sc_log, 0, NULL, &node_ncfv,
    377  1.7  jmcneill 	    CTLFLAG_READONLY, CTLTYPE_INT, "ncfv",
    378  1.7  jmcneill 	    SYSCTL_DESCR("Number of CPU frequency/voltage modes"),
    379  1.7  jmcneill 	    NULL, 0, &sc->sc_cfvnum, 0,
    380  1.7  jmcneill 	    CTL_HW, node_mib, CTL_CREATE, CTL_EOL);
    381  1.7  jmcneill 	if (err)
    382  1.7  jmcneill 		goto sysctl_err;
    383  1.7  jmcneill 	sc->sc_cfvnum_mib = node_ncfv->sysctl_num;
    384  1.7  jmcneill 	err = sysctl_createv(&sc->sc_log, 0, NULL, &node_cfv,
    385  1.7  jmcneill 	    CTLFLAG_READWRITE, CTLTYPE_INT, "cfv",
    386  1.7  jmcneill 	    SYSCTL_DESCR("Current CPU frequency/voltage mode"),
    387  1.7  jmcneill 	    asus_sysctl_verify, 0, sc, 0,
    388  1.7  jmcneill 	    CTL_HW, node_mib, CTL_CREATE, CTL_EOL);
    389  1.7  jmcneill 	if (err)
    390  1.7  jmcneill 		goto sysctl_err;
    391  1.7  jmcneill 	sc->sc_cfv_mib = node_cfv->sysctl_num;
    392  1.7  jmcneill 
    393  1.8  jmcneill 	return;
    394  1.7  jmcneill sysctl_err:
    395  1.7  jmcneill 	aprint_error_dev(sc->sc_dev, "failed to add sysctl nodes. (%d)\n", err);
    396  1.7  jmcneill }
    397  1.7  jmcneill 
    398  1.7  jmcneill static void
    399  1.7  jmcneill asus_sensors_refresh(struct sysmon_envsys *sme, envsys_data_t *edata)
    400  1.7  jmcneill {
    401  1.7  jmcneill 	struct asus_softc *sc = sme->sme_cookie;
    402  1.7  jmcneill 	uint32_t rpm;
    403  1.7  jmcneill 
    404  1.7  jmcneill 	switch (edata->sensor) {
    405  1.7  jmcneill 	case ASUS_SENSOR_FAN:
    406  1.7  jmcneill 		if (asus_get_fan_speed(sc, &rpm)) {
    407  1.7  jmcneill 			edata->value_cur = rpm;
    408  1.7  jmcneill 			edata->state = ENVSYS_SVALID;
    409  1.7  jmcneill 		} else
    410  1.7  jmcneill 			edata->state = ENVSYS_SINVALID;
    411  1.7  jmcneill 		break;
    412  1.7  jmcneill 	}
    413  1.7  jmcneill }
    414  1.7  jmcneill 
    415  1.7  jmcneill static bool
    416  1.7  jmcneill asus_get_fan_speed(struct asus_softc *sc, uint32_t *speed)
    417  1.7  jmcneill {
    418  1.7  jmcneill 	ACPI_INTEGER rpmh, rpml;
    419  1.7  jmcneill 	ACPI_STATUS rv;
    420  1.7  jmcneill 
    421  1.7  jmcneill 	rv = acpi_eval_integer(sc->sc_node->ad_handle,
    422  1.7  jmcneill 	    ASUS_EC_METHOD_FAN_RPMH, &rpmh);
    423  1.7  jmcneill 	if (ACPI_FAILURE(rv))
    424  1.7  jmcneill 		return false;
    425  1.7  jmcneill 	rv = acpi_eval_integer(sc->sc_node->ad_handle,
    426  1.7  jmcneill 	    ASUS_EC_METHOD_FAN_RPML, &rpml);
    427  1.7  jmcneill 	if (ACPI_FAILURE(rv))
    428  1.7  jmcneill 		return false;
    429  1.7  jmcneill 
    430  1.7  jmcneill 	if (speed)
    431  1.7  jmcneill 		*speed = (rpmh << 8) | rpml;
    432  1.7  jmcneill 	return true;
    433  1.7  jmcneill }
    434