Home | History | Annotate | Line # | Download | only in acpi
      1  1.27   thorpej /* $NetBSD: asus_acpi.c,v 1.27 2021/01/29 15:49:55 thorpej 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.27   thorpej __KERNEL_RCSID(0, "$NetBSD: asus_acpi.c,v 1.27 2021/01/29 15:49:55 thorpej Exp $");
     31   1.1  jmcneill 
     32   1.1  jmcneill #include <sys/param.h>
     33   1.1  jmcneill #include <sys/device.h>
     34  1.21    jruoho #include <sys/module.h>
     35   1.7  jmcneill #include <sys/sysctl.h>
     36  1.18    jruoho #include <sys/systm.h>
     37   1.1  jmcneill 
     38  1.18    jruoho #include <dev/acpi/acpireg.h>
     39   1.1  jmcneill #include <dev/acpi/acpivar.h>
     40  1.11   mlelstv 
     41  1.11   mlelstv #define _COMPONENT          ACPI_RESOURCE_COMPONENT
     42  1.11   mlelstv ACPI_MODULE_NAME            ("asus_acpi")
     43   1.1  jmcneill 
     44   1.7  jmcneill struct asus_softc {
     45   1.1  jmcneill 	device_t		sc_dev;
     46   1.1  jmcneill 	struct acpi_devnode	*sc_node;
     47   1.1  jmcneill 
     48   1.1  jmcneill #define ASUS_PSW_DISPLAY_CYCLE	0
     49   1.1  jmcneill #define ASUS_PSW_LAST		1
     50   1.1  jmcneill 	struct sysmon_pswitch	sc_smpsw[ASUS_PSW_LAST];
     51   1.1  jmcneill 	bool			sc_smpsw_valid;
     52   1.6  jmcneill 
     53   1.7  jmcneill 	struct sysmon_envsys	*sc_sme;
     54   1.7  jmcneill #define	ASUS_SENSOR_FAN		0
     55   1.7  jmcneill #define	ASUS_SENSOR_LAST	1
     56   1.7  jmcneill 	envsys_data_t		sc_sensor[ASUS_SENSOR_LAST];
     57   1.7  jmcneill 
     58  1.15    jruoho 	int32_t			sc_brightness;
     59   1.7  jmcneill 	ACPI_INTEGER		sc_cfvnum;
     60   1.7  jmcneill 
     61   1.7  jmcneill 	struct sysctllog	*sc_log;
     62   1.7  jmcneill 	int			sc_cfv_mib;
     63   1.7  jmcneill 	int			sc_cfvnum_mib;
     64   1.7  jmcneill };
     65   1.1  jmcneill 
     66   1.1  jmcneill #define ASUS_NOTIFY_WirelessSwitch	0x10
     67   1.1  jmcneill #define ASUS_NOTIFY_BrightnessLow	0x20
     68   1.1  jmcneill #define	ASUS_NOTIFY_BrightnessHigh	0x2f
     69   1.1  jmcneill #define ASUS_NOTIFY_DisplayCycle	0x30
     70   1.1  jmcneill #define ASUS_NOTIFY_WindowSwitch	0x12	/* XXXJDM ?? */
     71   1.1  jmcneill #define ASUS_NOTIFY_VolumeMute		0x13
     72   1.1  jmcneill #define ASUS_NOTIFY_VolumeDown		0x14
     73   1.1  jmcneill #define ASUS_NOTIFY_VolumeUp		0x15
     74   1.1  jmcneill 
     75   1.1  jmcneill #define	ASUS_METHOD_SDSP	"SDSP"
     76   1.1  jmcneill #define		ASUS_SDSP_LCD	0x01
     77   1.1  jmcneill #define		ASUS_SDSP_CRT	0x02
     78   1.1  jmcneill #define		ASUS_SDSP_TV	0x04
     79   1.1  jmcneill #define		ASUS_SDSP_DVI	0x08
     80   1.1  jmcneill #define		ASUS_SDSP_ALL	\
     81   1.1  jmcneill 		(ASUS_SDSP_LCD | ASUS_SDSP_CRT | ASUS_SDSP_TV | ASUS_SDSP_DVI)
     82   1.6  jmcneill #define ASUS_METHOD_PBLG	"PBLG"
     83   1.6  jmcneill #define ASUS_METHOD_PBLS	"PBLS"
     84   1.7  jmcneill #define	ASUS_METHOD_CFVS	"CFVS"
     85   1.7  jmcneill #define	ASUS_METHOD_CFVG	"CFVG"
     86   1.7  jmcneill 
     87   1.7  jmcneill #define	ASUS_EC_METHOD_FAN_RPMH	"\\_SB.PCI0.SBRG.EC0.SC05"
     88   1.7  jmcneill #define	ASUS_EC_METHOD_FAN_RPML	"\\_SB.PCI0.SBRG.EC0.SC06"
     89   1.1  jmcneill 
     90   1.3  jmcneill static int	asus_match(device_t, cfdata_t, void *);
     91   1.1  jmcneill static void	asus_attach(device_t, device_t, void *);
     92   1.7  jmcneill static int	asus_detach(device_t, int);
     93   1.1  jmcneill 
     94  1.19    jruoho static void	asus_notify_handler(ACPI_HANDLE, uint32_t, void *);
     95   1.1  jmcneill 
     96   1.1  jmcneill static void	asus_init(device_t);
     97  1.17    dyoung static bool	asus_suspend(device_t, const pmf_qual_t *);
     98  1.17    dyoung static bool	asus_resume(device_t, const pmf_qual_t *);
     99   1.1  jmcneill 
    100   1.7  jmcneill static void	asus_sysctl_setup(struct asus_softc *);
    101   1.7  jmcneill 
    102   1.7  jmcneill static void	asus_sensors_refresh(struct sysmon_envsys *, envsys_data_t *);
    103   1.7  jmcneill static bool	asus_get_fan_speed(struct asus_softc *, uint32_t *);
    104   1.7  jmcneill 
    105   1.7  jmcneill CFATTACH_DECL_NEW(asus, sizeof(struct asus_softc),
    106   1.7  jmcneill     asus_match, asus_attach, asus_detach, NULL);
    107   1.1  jmcneill 
    108  1.27   thorpej static const struct device_compatible_entry compat_data[] = {
    109  1.27   thorpej 	{ .compat = "ASUS010" },
    110  1.27   thorpej 	DEVICE_COMPAT_EOL
    111   1.1  jmcneill };
    112   1.1  jmcneill 
    113   1.1  jmcneill static int
    114   1.1  jmcneill asus_match(device_t parent, cfdata_t match, void *opaque)
    115   1.1  jmcneill {
    116   1.1  jmcneill 	struct acpi_attach_args *aa = opaque;
    117   1.1  jmcneill 
    118  1.27   thorpej 	return acpi_compatible_match(aa, compat_data);
    119   1.1  jmcneill }
    120   1.1  jmcneill 
    121   1.1  jmcneill static void
    122   1.1  jmcneill asus_attach(device_t parent, device_t self, void *opaque)
    123   1.1  jmcneill {
    124   1.7  jmcneill 	struct asus_softc *sc = device_private(self);
    125   1.1  jmcneill 	struct acpi_attach_args *aa = opaque;
    126   1.1  jmcneill 
    127  1.20    jruoho 	sc->sc_dev = self;
    128   1.1  jmcneill 	sc->sc_node = aa->aa_node;
    129   1.1  jmcneill 
    130   1.1  jmcneill 	aprint_naive("\n");
    131   1.1  jmcneill 	aprint_normal("\n");
    132   1.1  jmcneill 
    133   1.1  jmcneill 	asus_init(self);
    134   1.9  jmcneill 	asus_sysctl_setup(sc);
    135   1.1  jmcneill 
    136   1.1  jmcneill 	sc->sc_smpsw_valid = true;
    137   1.1  jmcneill 	sc->sc_smpsw[ASUS_PSW_DISPLAY_CYCLE].smpsw_name =
    138   1.1  jmcneill 	    PSWITCH_HK_DISPLAY_CYCLE;
    139   1.1  jmcneill 	sc->sc_smpsw[ASUS_PSW_DISPLAY_CYCLE].smpsw_type =
    140   1.1  jmcneill 	    PSWITCH_TYPE_HOTKEY;
    141   1.1  jmcneill 	if (sysmon_pswitch_register(&sc->sc_smpsw[ASUS_PSW_DISPLAY_CYCLE])) {
    142   1.1  jmcneill 		aprint_error_dev(self, "couldn't register with sysmon\n");
    143   1.1  jmcneill 		sc->sc_smpsw_valid = false;
    144   1.1  jmcneill 	}
    145   1.1  jmcneill 
    146   1.7  jmcneill 	if (asus_get_fan_speed(sc, NULL) == false)
    147  1.20    jruoho 		goto out;
    148   1.7  jmcneill 
    149   1.7  jmcneill 	sc->sc_sme = sysmon_envsys_create();
    150   1.7  jmcneill 
    151   1.7  jmcneill 	strcpy(sc->sc_sensor[ASUS_SENSOR_FAN].desc, "fan");
    152   1.7  jmcneill 	sc->sc_sensor[ASUS_SENSOR_FAN].units = ENVSYS_SFANRPM;
    153  1.23  jmcneill 	sc->sc_sensor[ASUS_SENSOR_FAN].state = ENVSYS_SINVALID;
    154   1.7  jmcneill 	sysmon_envsys_sensor_attach(sc->sc_sme,
    155   1.7  jmcneill 	    &sc->sc_sensor[ASUS_SENSOR_FAN]);
    156   1.7  jmcneill 
    157   1.7  jmcneill 	sc->sc_sme->sme_name = device_xname(self);
    158   1.7  jmcneill 	sc->sc_sme->sme_cookie = sc;
    159   1.7  jmcneill 	sc->sc_sme->sme_refresh = asus_sensors_refresh;
    160  1.10  jmcneill 	sc->sc_sme->sme_flags = SME_POLL_ONLY;
    161   1.7  jmcneill 
    162   1.7  jmcneill 	if (sysmon_envsys_register(sc->sc_sme)) {
    163   1.7  jmcneill 		aprint_error_dev(self, "couldn't register with envsys\n");
    164   1.7  jmcneill 		sysmon_envsys_destroy(sc->sc_sme);
    165   1.7  jmcneill 		sc->sc_sme = NULL;
    166   1.7  jmcneill 	}
    167   1.7  jmcneill 
    168  1.20    jruoho out:
    169  1.20    jruoho 	(void)pmf_device_register(self, asus_suspend, asus_resume);
    170  1.20    jruoho 	(void)acpi_register_notify(sc->sc_node, asus_notify_handler);
    171   1.1  jmcneill }
    172   1.1  jmcneill 
    173   1.7  jmcneill static int
    174   1.7  jmcneill asus_detach(device_t self, int flags)
    175   1.7  jmcneill {
    176   1.7  jmcneill 	struct asus_softc *sc = device_private(self);
    177   1.7  jmcneill 	int i;
    178   1.7  jmcneill 
    179  1.20    jruoho 	acpi_deregister_notify(sc->sc_node);
    180  1.16    jruoho 
    181  1.20    jruoho 	if (sc->sc_smpsw_valid != false) {
    182  1.16    jruoho 
    183   1.7  jmcneill 		for (i = 0; i < ASUS_PSW_LAST; i++)
    184   1.7  jmcneill 			sysmon_pswitch_unregister(&sc->sc_smpsw[i]);
    185  1.20    jruoho 	}
    186   1.7  jmcneill 
    187  1.20    jruoho 	if (sc->sc_sme != NULL)
    188   1.7  jmcneill 		sysmon_envsys_unregister(sc->sc_sme);
    189  1.20    jruoho 
    190  1.20    jruoho 	if (sc->sc_log != NULL)
    191   1.7  jmcneill 		sysctl_teardown(&sc->sc_log);
    192  1.20    jruoho 
    193   1.7  jmcneill 	pmf_device_deregister(self);
    194   1.7  jmcneill 
    195   1.7  jmcneill 	return 0;
    196   1.7  jmcneill }
    197   1.7  jmcneill 
    198   1.1  jmcneill static void
    199  1.19    jruoho asus_notify_handler(ACPI_HANDLE hdl, uint32_t notify, void *opaque)
    200   1.1  jmcneill {
    201  1.20    jruoho 	struct asus_softc *sc;
    202  1.20    jruoho 	device_t self = opaque;
    203  1.20    jruoho 
    204  1.20    jruoho 	sc = device_private(self);
    205   1.1  jmcneill 
    206   1.1  jmcneill 	if (notify >= ASUS_NOTIFY_BrightnessLow &&
    207   1.1  jmcneill 	    notify <= ASUS_NOTIFY_BrightnessHigh) {
    208   1.1  jmcneill 		aprint_debug_dev(sc->sc_dev, "brightness %d percent\n",
    209   1.1  jmcneill 		    (notify & 0xf) * 100 / 0xf);
    210   1.1  jmcneill 		return;
    211   1.1  jmcneill 	}
    212   1.1  jmcneill 
    213   1.1  jmcneill 	switch (notify) {
    214   1.1  jmcneill 	case ASUS_NOTIFY_WirelessSwitch:	/* handled by AML */
    215   1.1  jmcneill 	case ASUS_NOTIFY_WindowSwitch:		/* XXXJDM what is this? */
    216   1.1  jmcneill 		break;
    217   1.1  jmcneill 	case ASUS_NOTIFY_DisplayCycle:
    218   1.1  jmcneill 		if (sc->sc_smpsw_valid == false)
    219   1.1  jmcneill 			break;
    220   1.1  jmcneill 		sysmon_pswitch_event(&sc->sc_smpsw[ASUS_PSW_DISPLAY_CYCLE],
    221   1.1  jmcneill 		    PSWITCH_EVENT_PRESSED);
    222   1.1  jmcneill 		break;
    223   1.1  jmcneill 	case ASUS_NOTIFY_VolumeMute:
    224   1.1  jmcneill 		pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_TOGGLE);
    225   1.1  jmcneill 		break;
    226   1.1  jmcneill 	case ASUS_NOTIFY_VolumeDown:
    227   1.1  jmcneill 		pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_DOWN);
    228   1.1  jmcneill 		break;
    229   1.1  jmcneill 	case ASUS_NOTIFY_VolumeUp:
    230   1.1  jmcneill 		pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_UP);
    231   1.1  jmcneill 		break;
    232   1.1  jmcneill 	default:
    233   1.1  jmcneill 		aprint_debug_dev(sc->sc_dev, "unknown event 0x%02x\n", notify);
    234   1.1  jmcneill 		break;
    235   1.1  jmcneill 	}
    236   1.1  jmcneill }
    237   1.1  jmcneill 
    238   1.1  jmcneill static void
    239   1.1  jmcneill asus_init(device_t self)
    240   1.1  jmcneill {
    241   1.7  jmcneill 	struct asus_softc *sc = device_private(self);
    242  1.14    jruoho 	ACPI_INTEGER cfv;
    243   1.1  jmcneill 	ACPI_STATUS rv;
    244   1.1  jmcneill 
    245  1.14    jruoho 	/* Disable ASL display switching. */
    246  1.14    jruoho 	rv = acpi_eval_set_integer(sc->sc_node->ad_handle, "INIT", 0x40);
    247   1.1  jmcneill 
    248   1.1  jmcneill 	if (ACPI_FAILURE(rv))
    249   1.1  jmcneill 		aprint_error_dev(self, "couldn't evaluate INIT: %s\n",
    250   1.1  jmcneill 		    AcpiFormatException(rv));
    251   1.5  jmcneill 
    252  1.14    jruoho 	rv = acpi_eval_integer(sc->sc_node->ad_handle, ASUS_METHOD_CFVG, &cfv);
    253   1.7  jmcneill 
    254   1.7  jmcneill 	if (ACPI_FAILURE(rv))
    255   1.7  jmcneill 		return;
    256   1.7  jmcneill 
    257   1.7  jmcneill 	sc->sc_cfvnum = (cfv >> 8) & 0xff;
    258   1.1  jmcneill }
    259   1.1  jmcneill 
    260   1.1  jmcneill static bool
    261  1.17    dyoung asus_suspend(device_t self, const pmf_qual_t *qual)
    262   1.6  jmcneill {
    263   1.7  jmcneill 	struct asus_softc *sc = device_private(self);
    264  1.15    jruoho 	ACPI_INTEGER val = 0;
    265   1.6  jmcneill 	ACPI_STATUS rv;
    266   1.6  jmcneill 
    267  1.15    jruoho 	/* Capture display brightness. */
    268  1.15    jruoho 	rv = acpi_eval_integer(sc->sc_node->ad_handle, ASUS_METHOD_PBLG, &val);
    269  1.15    jruoho 
    270  1.15    jruoho 	if (ACPI_FAILURE(rv) || val > INT32_MAX)
    271  1.15    jruoho 		sc->sc_brightness = -1;
    272  1.15    jruoho 	else
    273  1.15    jruoho 		sc->sc_brightness = val;
    274   1.6  jmcneill 
    275   1.6  jmcneill 	return true;
    276   1.6  jmcneill }
    277   1.6  jmcneill 
    278   1.6  jmcneill static bool
    279  1.17    dyoung asus_resume(device_t self, const pmf_qual_t *qual)
    280   1.1  jmcneill {
    281   1.7  jmcneill 	struct asus_softc *sc = device_private(self);
    282   1.1  jmcneill 	ACPI_STATUS rv;
    283   1.1  jmcneill 
    284   1.1  jmcneill 	asus_init(self);
    285   1.1  jmcneill 
    286  1.15    jruoho 	if (sc->sc_brightness < 0)
    287  1.15    jruoho 		return true;
    288  1.15    jruoho 
    289  1.14    jruoho 	/* Restore previous display brightness. */
    290  1.14    jruoho 	rv = acpi_eval_set_integer(sc->sc_node->ad_handle, ASUS_METHOD_PBLS,
    291  1.14    jruoho 	    sc->sc_brightness);
    292   1.1  jmcneill 
    293   1.1  jmcneill 	if (ACPI_FAILURE(rv))
    294   1.6  jmcneill 		aprint_error_dev(self, "couldn't evaluate PBLS: %s\n",
    295   1.1  jmcneill 		    AcpiFormatException(rv));
    296   1.1  jmcneill 
    297   1.1  jmcneill 	return true;
    298   1.1  jmcneill }
    299   1.7  jmcneill 
    300   1.7  jmcneill static int
    301   1.7  jmcneill asus_sysctl_verify(SYSCTLFN_ARGS)
    302   1.7  jmcneill {
    303   1.7  jmcneill 	struct sysctlnode node;
    304   1.7  jmcneill 	struct asus_softc *sc;
    305  1.14    jruoho 	ACPI_INTEGER cfv;
    306   1.7  jmcneill 	ACPI_STATUS rv;
    307   1.7  jmcneill 	int err, tmp;
    308   1.7  jmcneill 
    309   1.7  jmcneill 	node = *rnode;
    310   1.7  jmcneill 	sc = rnode->sysctl_data;
    311   1.7  jmcneill 	if (node.sysctl_num == sc->sc_cfv_mib) {
    312   1.7  jmcneill 		rv = acpi_eval_integer(sc->sc_node->ad_handle,
    313   1.7  jmcneill 		    ASUS_METHOD_CFVG, &cfv);
    314   1.7  jmcneill 		if (ACPI_FAILURE(rv))
    315   1.7  jmcneill 			return ENXIO;
    316   1.7  jmcneill 		tmp = cfv & 0xff;
    317   1.7  jmcneill 		node.sysctl_data = &tmp;
    318   1.7  jmcneill 		err = sysctl_lookup(SYSCTLFN_CALL(&node));
    319   1.7  jmcneill 		if (err || newp == NULL)
    320   1.7  jmcneill 			return err;
    321   1.7  jmcneill 
    322  1.21    jruoho 		if (tmp < 0 || (uint64_t)tmp >= sc->sc_cfvnum)
    323   1.7  jmcneill 			return EINVAL;
    324   1.7  jmcneill 
    325  1.14    jruoho 		rv = acpi_eval_set_integer(sc->sc_node->ad_handle,
    326  1.14    jruoho 		    ASUS_METHOD_CFVS, tmp);
    327   1.7  jmcneill 
    328   1.7  jmcneill 		if (ACPI_FAILURE(rv))
    329   1.7  jmcneill 			return ENXIO;
    330   1.7  jmcneill 	}
    331   1.7  jmcneill 
    332   1.7  jmcneill 	return 0;
    333   1.7  jmcneill }
    334   1.7  jmcneill 
    335   1.7  jmcneill static void
    336   1.7  jmcneill asus_sysctl_setup(struct asus_softc *sc)
    337   1.7  jmcneill {
    338   1.7  jmcneill 	const struct sysctlnode *node, *node_cfv, *node_ncfv;
    339   1.7  jmcneill 	int err, node_mib;
    340   1.7  jmcneill 
    341   1.7  jmcneill 	if (sc->sc_cfvnum == 0)
    342   1.7  jmcneill 		return;
    343   1.7  jmcneill 
    344   1.7  jmcneill 	err = sysctl_createv(&sc->sc_log, 0, NULL, &node, 0,
    345   1.7  jmcneill 	    CTLTYPE_NODE, device_xname(sc->sc_dev), NULL, NULL, 0,
    346   1.7  jmcneill 	    NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL);
    347   1.7  jmcneill 	if (err)
    348   1.7  jmcneill 		goto sysctl_err;
    349   1.7  jmcneill 	node_mib = node->sysctl_num;
    350   1.7  jmcneill 	err = sysctl_createv(&sc->sc_log, 0, NULL, &node_ncfv,
    351  1.24       dsl 	    CTLFLAG_READONLY, CTLTYPE_QUAD, "ncfv",
    352   1.7  jmcneill 	    SYSCTL_DESCR("Number of CPU frequency/voltage modes"),
    353   1.7  jmcneill 	    NULL, 0, &sc->sc_cfvnum, 0,
    354   1.7  jmcneill 	    CTL_HW, node_mib, CTL_CREATE, CTL_EOL);
    355   1.7  jmcneill 	if (err)
    356   1.7  jmcneill 		goto sysctl_err;
    357   1.7  jmcneill 	sc->sc_cfvnum_mib = node_ncfv->sysctl_num;
    358   1.7  jmcneill 	err = sysctl_createv(&sc->sc_log, 0, NULL, &node_cfv,
    359   1.7  jmcneill 	    CTLFLAG_READWRITE, CTLTYPE_INT, "cfv",
    360   1.7  jmcneill 	    SYSCTL_DESCR("Current CPU frequency/voltage mode"),
    361  1.24       dsl 	    asus_sysctl_verify, 0, (void *)sc, 0,
    362   1.7  jmcneill 	    CTL_HW, node_mib, CTL_CREATE, CTL_EOL);
    363   1.7  jmcneill 	if (err)
    364   1.7  jmcneill 		goto sysctl_err;
    365   1.7  jmcneill 	sc->sc_cfv_mib = node_cfv->sysctl_num;
    366   1.7  jmcneill 
    367   1.8  jmcneill 	return;
    368   1.7  jmcneill sysctl_err:
    369   1.7  jmcneill 	aprint_error_dev(sc->sc_dev, "failed to add sysctl nodes. (%d)\n", err);
    370   1.7  jmcneill }
    371   1.7  jmcneill 
    372   1.7  jmcneill static void
    373   1.7  jmcneill asus_sensors_refresh(struct sysmon_envsys *sme, envsys_data_t *edata)
    374   1.7  jmcneill {
    375   1.7  jmcneill 	struct asus_softc *sc = sme->sme_cookie;
    376   1.7  jmcneill 	uint32_t rpm;
    377   1.7  jmcneill 
    378   1.7  jmcneill 	switch (edata->sensor) {
    379   1.7  jmcneill 	case ASUS_SENSOR_FAN:
    380   1.7  jmcneill 		if (asus_get_fan_speed(sc, &rpm)) {
    381   1.7  jmcneill 			edata->value_cur = rpm;
    382   1.7  jmcneill 			edata->state = ENVSYS_SVALID;
    383   1.7  jmcneill 		} else
    384   1.7  jmcneill 			edata->state = ENVSYS_SINVALID;
    385   1.7  jmcneill 		break;
    386   1.7  jmcneill 	}
    387   1.7  jmcneill }
    388   1.7  jmcneill 
    389   1.7  jmcneill static bool
    390   1.7  jmcneill asus_get_fan_speed(struct asus_softc *sc, uint32_t *speed)
    391   1.7  jmcneill {
    392   1.7  jmcneill 	ACPI_INTEGER rpmh, rpml;
    393   1.7  jmcneill 	ACPI_STATUS rv;
    394   1.7  jmcneill 
    395   1.7  jmcneill 	rv = acpi_eval_integer(sc->sc_node->ad_handle,
    396   1.7  jmcneill 	    ASUS_EC_METHOD_FAN_RPMH, &rpmh);
    397   1.7  jmcneill 	if (ACPI_FAILURE(rv))
    398   1.7  jmcneill 		return false;
    399   1.7  jmcneill 	rv = acpi_eval_integer(sc->sc_node->ad_handle,
    400   1.7  jmcneill 	    ASUS_EC_METHOD_FAN_RPML, &rpml);
    401   1.7  jmcneill 	if (ACPI_FAILURE(rv))
    402   1.7  jmcneill 		return false;
    403   1.7  jmcneill 
    404   1.7  jmcneill 	if (speed)
    405   1.7  jmcneill 		*speed = (rpmh << 8) | rpml;
    406   1.7  jmcneill 	return true;
    407   1.7  jmcneill }
    408  1.21    jruoho 
    409  1.26  pgoyette MODULE(MODULE_CLASS_DRIVER, asus, "sysmon_envsys,sysmon_power");
    410  1.21    jruoho 
    411  1.22    jruoho #ifdef _MODULE
    412  1.21    jruoho #include "ioconf.c"
    413  1.22    jruoho #endif
    414  1.21    jruoho 
    415  1.21    jruoho static int
    416  1.22    jruoho asus_modcmd(modcmd_t cmd, void *aux)
    417  1.21    jruoho {
    418  1.22    jruoho 	int rv = 0;
    419  1.21    jruoho 
    420  1.21    jruoho 	switch (cmd) {
    421  1.21    jruoho 
    422  1.21    jruoho 	case MODULE_CMD_INIT:
    423  1.22    jruoho 
    424  1.22    jruoho #ifdef _MODULE
    425  1.22    jruoho 		rv = config_init_component(cfdriver_ioconf_asus,
    426  1.21    jruoho 		    cfattach_ioconf_asus, cfdata_ioconf_asus);
    427  1.22    jruoho #endif
    428  1.22    jruoho 		break;
    429  1.21    jruoho 
    430  1.21    jruoho 	case MODULE_CMD_FINI:
    431  1.22    jruoho 
    432  1.22    jruoho #ifdef _MODULE
    433  1.22    jruoho 		rv = config_fini_component(cfdriver_ioconf_asus,
    434  1.21    jruoho 		    cfattach_ioconf_asus, cfdata_ioconf_asus);
    435  1.22    jruoho #endif
    436  1.22    jruoho 		break;
    437  1.21    jruoho 
    438  1.21    jruoho 	default:
    439  1.22    jruoho 		rv = ENOTTY;
    440  1.21    jruoho 	}
    441  1.22    jruoho 
    442  1.22    jruoho 	return rv;
    443  1.21    jruoho }
    444