Home | History | Annotate | Line # | Download | only in acpi
sony_acpi.c revision 1.1
      1  1.1  jmcneill /*	$NetBSD: sony_acpi.c,v 1.1 2007/12/23 17:29:26 jmcneill Exp $	*/
      2  1.1  jmcneill 
      3  1.1  jmcneill /*-
      4  1.1  jmcneill  * Copyright (c) 2005 The NetBSD Foundation, Inc.
      5  1.1  jmcneill  * All rights reserved.
      6  1.1  jmcneill  *
      7  1.1  jmcneill  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  jmcneill  * by Christos Zoulas.
      9  1.1  jmcneill  *
     10  1.1  jmcneill  * Redistribution and use in source and binary forms, with or without
     11  1.1  jmcneill  * modification, are permitted provided that the following conditions
     12  1.1  jmcneill  * are met:
     13  1.1  jmcneill  * 1. Redistributions of source code must retain the above copyright
     14  1.1  jmcneill  *    notice, this list of conditions and the following disclaimer.
     15  1.1  jmcneill  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  jmcneill  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  jmcneill  *    documentation and/or other materials provided with the distribution.
     18  1.1  jmcneill  * 3. All advertising materials mentioning features or use of this software
     19  1.1  jmcneill  *    must display the following acknowledgement:
     20  1.1  jmcneill  *        This product includes software developed by the NetBSD
     21  1.1  jmcneill  *        Foundation, Inc. and its contributors.
     22  1.1  jmcneill  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1  jmcneill  *    contributors may be used to endorse or promote products derived
     24  1.1  jmcneill  *    from this software without specific prior written permission.
     25  1.1  jmcneill  *
     26  1.1  jmcneill  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1  jmcneill  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1  jmcneill  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1  jmcneill  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1  jmcneill  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1  jmcneill  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1  jmcneill  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1  jmcneill  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1  jmcneill  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1  jmcneill  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1  jmcneill  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  jmcneill  */
     38  1.1  jmcneill #include <sys/cdefs.h>
     39  1.1  jmcneill __KERNEL_RCSID(0, "$NetBSD: sony_acpi.c,v 1.1 2007/12/23 17:29:26 jmcneill Exp $");
     40  1.1  jmcneill 
     41  1.1  jmcneill #include <sys/param.h>
     42  1.1  jmcneill #include <sys/systm.h>
     43  1.1  jmcneill #include <sys/device.h>
     44  1.1  jmcneill #include <sys/proc.h>
     45  1.1  jmcneill #include <sys/kernel.h>
     46  1.1  jmcneill #include <sys/callout.h>
     47  1.1  jmcneill #include <sys/sysctl.h>
     48  1.1  jmcneill 
     49  1.1  jmcneill #include <machine/bus.h>
     50  1.1  jmcneill 
     51  1.1  jmcneill #include <dev/acpi/acpica.h>
     52  1.1  jmcneill #include <dev/acpi/acpivar.h>
     53  1.1  jmcneill 
     54  1.1  jmcneill #define SONY_NOTIFY_FnKeyEvent			0x92
     55  1.1  jmcneill #define SONY_NOTIFY_BrightnessDownPressed	0x85
     56  1.1  jmcneill #define SONY_NOTIFY_BrightnessDownReleased	0x05
     57  1.1  jmcneill #define SONY_NOTIFY_BrightnessUpPressed		0x86
     58  1.1  jmcneill #define SONY_NOTIFY_BrightnessUpReleased	0x06
     59  1.1  jmcneill #define SONY_NOTIFY_DisplaySwitchPressed	0x87
     60  1.1  jmcneill #define SONY_NOTIFY_DisplaySwitchReleased	0x07
     61  1.1  jmcneill #define SONY_NOTIFY_ZoomPressed			0x8a
     62  1.1  jmcneill #define SONY_NOTIFY_ZoomReleased		0x0a
     63  1.1  jmcneill #define SONY_NOTIFY_SuspendPressed		0x8c
     64  1.1  jmcneill #define SONY_NOTIFY_SuspendReleased		0x0c
     65  1.1  jmcneill 
     66  1.1  jmcneill struct sony_acpi_softc {
     67  1.1  jmcneill         struct device sc_dev;
     68  1.1  jmcneill 	struct sysctllog *sc_log;
     69  1.1  jmcneill 	struct acpi_devnode *sc_node;
     70  1.1  jmcneill 
     71  1.1  jmcneill #define	SONY_PSW_SLEEP		0
     72  1.1  jmcneill #define	SONY_PSW_DISPLAY_CYCLE	1
     73  1.1  jmcneill #define	SONY_PSW_ZOOM		2
     74  1.1  jmcneill #define	SONY_PSW_LAST		3
     75  1.1  jmcneill 	struct sysmon_pswitch sc_smpsw[SONY_PSW_LAST];
     76  1.1  jmcneill 	int sc_smpsw_valid;
     77  1.1  jmcneill 
     78  1.1  jmcneill 	struct sony_acpi_pmstate {
     79  1.1  jmcneill 		ACPI_INTEGER	brt;
     80  1.1  jmcneill 	} sc_pmstate;
     81  1.1  jmcneill };
     82  1.1  jmcneill 
     83  1.1  jmcneill static const char * const sony_acpi_ids[] = {
     84  1.1  jmcneill 	"SNY5001",
     85  1.1  jmcneill 	NULL
     86  1.1  jmcneill };
     87  1.1  jmcneill 
     88  1.1  jmcneill #define SONY_ACPI_QUIRK_FNINIT	0x01
     89  1.1  jmcneill 
     90  1.1  jmcneill static const struct sony_acpi_quirk_table {
     91  1.1  jmcneill 	const char *	product_name;
     92  1.1  jmcneill 	int		quirks;
     93  1.1  jmcneill } sony_acpi_quirks[] = {
     94  1.1  jmcneill 	{ "VGN-N250E",	SONY_ACPI_QUIRK_FNINIT },
     95  1.1  jmcneill 	{ NULL, -1 }
     96  1.1  jmcneill };
     97  1.1  jmcneill 
     98  1.1  jmcneill static int	sony_acpi_match(struct device *, struct cfdata *, void *);
     99  1.1  jmcneill static void	sony_acpi_attach(struct device *, struct device *, void *);
    100  1.1  jmcneill static ACPI_STATUS sony_acpi_eval_set_integer(ACPI_HANDLE, const char *,
    101  1.1  jmcneill     ACPI_INTEGER, ACPI_INTEGER *);
    102  1.1  jmcneill static void	sony_acpi_quirk_setup(struct sony_acpi_softc *);
    103  1.1  jmcneill static void	sony_acpi_notify_handler(ACPI_HANDLE, UINT32, void *);
    104  1.1  jmcneill static bool	sony_acpi_suspend(device_t);
    105  1.1  jmcneill static bool	sony_acpi_resume(device_t);
    106  1.1  jmcneill static void	sony_acpi_brightness_down(device_t);
    107  1.1  jmcneill static void	sony_acpi_brightness_up(device_t);
    108  1.1  jmcneill 
    109  1.1  jmcneill CFATTACH_DECL(sony_acpi, sizeof(struct sony_acpi_softc),
    110  1.1  jmcneill     sony_acpi_match, sony_acpi_attach, NULL, NULL);
    111  1.1  jmcneill 
    112  1.1  jmcneill static int
    113  1.1  jmcneill sony_acpi_match(struct device *parent, struct cfdata *match,
    114  1.1  jmcneill     void *aux)
    115  1.1  jmcneill {
    116  1.1  jmcneill 	struct acpi_attach_args *aa = aux;
    117  1.1  jmcneill 
    118  1.1  jmcneill 	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
    119  1.1  jmcneill 		return 0;
    120  1.1  jmcneill 
    121  1.1  jmcneill 	return acpi_match_hid(aa->aa_node->ad_devinfo, sony_acpi_ids);
    122  1.1  jmcneill }
    123  1.1  jmcneill 
    124  1.1  jmcneill static int
    125  1.1  jmcneill sony_sysctl_helper(SYSCTLFN_ARGS)
    126  1.1  jmcneill {
    127  1.1  jmcneill 	struct sysctlnode node;
    128  1.1  jmcneill 	ACPI_INTEGER acpi_val;
    129  1.1  jmcneill 	ACPI_STATUS rv;
    130  1.1  jmcneill 	int val, old_val, error;
    131  1.1  jmcneill 	char buf[SYSCTL_NAMELEN + 1], *ptr;
    132  1.1  jmcneill 	struct sony_acpi_softc *sc = rnode->sysctl_data;
    133  1.1  jmcneill 
    134  1.1  jmcneill 	(void)snprintf(buf, sizeof(buf), "G%s", rnode->sysctl_name);
    135  1.1  jmcneill 	for (ptr = buf; *ptr; ptr++)
    136  1.1  jmcneill 		*ptr = toupper(*ptr);
    137  1.1  jmcneill 
    138  1.1  jmcneill 	rv = acpi_eval_integer(sc->sc_node->ad_handle, buf, &acpi_val);
    139  1.1  jmcneill 	if (ACPI_FAILURE(rv)) {
    140  1.1  jmcneill #ifdef DIAGNOSTIC
    141  1.1  jmcneill 		printf("%s: couldn't get `%s'\n", device_xname(&sc->sc_dev), buf);
    142  1.1  jmcneill #endif
    143  1.1  jmcneill 		return EIO;
    144  1.1  jmcneill 	}
    145  1.1  jmcneill 	val = old_val = acpi_val;
    146  1.1  jmcneill 
    147  1.1  jmcneill 	node = *rnode;
    148  1.1  jmcneill 	node.sysctl_data = &val;
    149  1.1  jmcneill 
    150  1.1  jmcneill 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    151  1.1  jmcneill 	if (error || newp == NULL)
    152  1.1  jmcneill 		return error;
    153  1.1  jmcneill 
    154  1.1  jmcneill 	(void)snprintf(buf, sizeof(buf), "S%s", rnode->sysctl_name);
    155  1.1  jmcneill 	acpi_val = val;
    156  1.1  jmcneill 	rv = sony_acpi_eval_set_integer(sc->sc_node->ad_handle, buf,
    157  1.1  jmcneill 	    acpi_val, NULL);
    158  1.1  jmcneill 	if (ACPI_FAILURE(rv)) {
    159  1.1  jmcneill #ifdef DIAGNOSTIC
    160  1.1  jmcneill 		printf("%s: couldn't set `%s' to %d\n",
    161  1.1  jmcneill 		    device_xname(&sc->sc_dev), buf, val);
    162  1.1  jmcneill #endif
    163  1.1  jmcneill 		return EIO;
    164  1.1  jmcneill 	}
    165  1.1  jmcneill 	return 0;
    166  1.1  jmcneill }
    167  1.1  jmcneill 
    168  1.1  jmcneill static ACPI_STATUS
    169  1.1  jmcneill sony_walk_cb(ACPI_HANDLE hnd, UINT32 v, void *context,
    170  1.1  jmcneill     void **status)
    171  1.1  jmcneill {
    172  1.1  jmcneill 	struct sony_acpi_softc *sc = (void*)context;
    173  1.1  jmcneill 	const struct sysctlnode *node, *snode;
    174  1.1  jmcneill 	const char *name = acpi_name(hnd);
    175  1.1  jmcneill 	ACPI_INTEGER acpi_val;
    176  1.1  jmcneill 	char buf[SYSCTL_NAMELEN + 1], *ptr;
    177  1.1  jmcneill 	int rv;
    178  1.1  jmcneill 
    179  1.1  jmcneill 	if ((name = strrchr(name, '.')) == NULL)
    180  1.1  jmcneill 		return AE_OK;
    181  1.1  jmcneill 
    182  1.1  jmcneill 	name++;
    183  1.1  jmcneill 	if ((*name != 'G') && (*name != 'S'))
    184  1.1  jmcneill 		return AE_OK;
    185  1.1  jmcneill 
    186  1.1  jmcneill 	(void)strlcpy(buf, name, sizeof(buf));
    187  1.1  jmcneill 	*buf = 'G';
    188  1.1  jmcneill 
    189  1.1  jmcneill 	/*
    190  1.1  jmcneill 	 * We assume that if the 'get' of the name as an integer is
    191  1.1  jmcneill 	 * successful it is ok.
    192  1.1  jmcneill 	 */
    193  1.1  jmcneill 	if (acpi_eval_integer(sc->sc_node->ad_handle, buf, &acpi_val))
    194  1.1  jmcneill 		return AE_OK;
    195  1.1  jmcneill 
    196  1.1  jmcneill 	for (ptr = buf; *ptr; ptr++)
    197  1.1  jmcneill 		*ptr = tolower(*ptr);
    198  1.1  jmcneill 
    199  1.1  jmcneill 	if ((rv = sysctl_createv(&sc->sc_log, 0, NULL, &node, CTLFLAG_PERMANENT,
    200  1.1  jmcneill 	    CTLTYPE_NODE, "hw", NULL, NULL, 0, NULL, 0, CTL_HW, CTL_EOL)) != 0)
    201  1.1  jmcneill 		goto out;
    202  1.1  jmcneill 
    203  1.1  jmcneill 	if ((rv = sysctl_createv(&sc->sc_log, 0, &node, &snode, 0,
    204  1.1  jmcneill 	    CTLTYPE_NODE, device_xname(&sc->sc_dev),
    205  1.1  jmcneill 	    SYSCTL_DESCR("sony controls"),
    206  1.1  jmcneill 	    NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL)) != 0)
    207  1.1  jmcneill 		goto out;
    208  1.1  jmcneill 
    209  1.1  jmcneill 	if ((rv = sysctl_createv(&sc->sc_log, 0, &snode, &node,
    210  1.1  jmcneill 	    CTLFLAG_READWRITE, CTLTYPE_INT, buf + 1, NULL,
    211  1.1  jmcneill 	    sony_sysctl_helper, 0, sc, 0, CTL_CREATE, CTL_EOL)) != 0)
    212  1.1  jmcneill 		goto out;
    213  1.1  jmcneill 
    214  1.1  jmcneill out:
    215  1.1  jmcneill #ifdef DIAGNOSTIC
    216  1.1  jmcneill 	if (rv)
    217  1.1  jmcneill 		printf("%s: sysctl_createv failed (rv = %d)\n",
    218  1.1  jmcneill 		    device_xname(&sc->sc_dev), rv);
    219  1.1  jmcneill #endif
    220  1.1  jmcneill 	return AE_OK;
    221  1.1  jmcneill }
    222  1.1  jmcneill 
    223  1.1  jmcneill ACPI_STATUS
    224  1.1  jmcneill sony_acpi_eval_set_integer(ACPI_HANDLE handle, const char *path,
    225  1.1  jmcneill     ACPI_INTEGER val, ACPI_INTEGER *valp)
    226  1.1  jmcneill {
    227  1.1  jmcneill 	ACPI_STATUS rv;
    228  1.1  jmcneill 	ACPI_BUFFER buf;
    229  1.1  jmcneill 	ACPI_OBJECT param, ret_val;
    230  1.1  jmcneill 	ACPI_OBJECT_LIST params;
    231  1.1  jmcneill 
    232  1.1  jmcneill 	if (handle == NULL)
    233  1.1  jmcneill 		handle = ACPI_ROOT_OBJECT;
    234  1.1  jmcneill 
    235  1.1  jmcneill 	params.Count = 1;
    236  1.1  jmcneill 	params.Pointer = &param;
    237  1.1  jmcneill 
    238  1.1  jmcneill 	param.Type = ACPI_TYPE_INTEGER;
    239  1.1  jmcneill 	param.Integer.Value = val;
    240  1.1  jmcneill 
    241  1.1  jmcneill 	buf.Pointer = &ret_val;
    242  1.1  jmcneill 	buf.Length = sizeof(ret_val);
    243  1.1  jmcneill 
    244  1.1  jmcneill 	rv = AcpiEvaluateObjectTyped(handle, path, &params, &buf,
    245  1.1  jmcneill 	    ACPI_TYPE_INTEGER);
    246  1.1  jmcneill 
    247  1.1  jmcneill 	if (ACPI_SUCCESS(rv) && valp)
    248  1.1  jmcneill 		*valp = ret_val.Integer.Value;
    249  1.1  jmcneill 
    250  1.1  jmcneill 	return rv;
    251  1.1  jmcneill }
    252  1.1  jmcneill 
    253  1.1  jmcneill static void
    254  1.1  jmcneill sony_acpi_attach(struct device *parent, struct device *self, void *aux)
    255  1.1  jmcneill {
    256  1.1  jmcneill 	struct sony_acpi_softc *sc = (void *)self;
    257  1.1  jmcneill 	struct acpi_attach_args *aa = aux;
    258  1.1  jmcneill 	ACPI_STATUS rv;
    259  1.1  jmcneill 	int i;
    260  1.1  jmcneill 
    261  1.1  jmcneill 	aprint_naive(": Sony Miscellaneous Controller\n");
    262  1.1  jmcneill 	aprint_normal(": Sony Miscellaneous Controller\n");
    263  1.1  jmcneill 
    264  1.1  jmcneill 	sc->sc_node = aa->aa_node;
    265  1.1  jmcneill 
    266  1.1  jmcneill 	sony_acpi_quirk_setup(sc);
    267  1.1  jmcneill 
    268  1.1  jmcneill 	/* Configure suspend button and hotkeys */
    269  1.1  jmcneill 	sc->sc_smpsw[SONY_PSW_SLEEP].smpsw_name = sc->sc_dev.dv_xname;
    270  1.1  jmcneill 	sc->sc_smpsw[SONY_PSW_SLEEP].smpsw_type = PSWITCH_TYPE_SLEEP;
    271  1.1  jmcneill 	sc->sc_smpsw[SONY_PSW_DISPLAY_CYCLE].smpsw_name =
    272  1.1  jmcneill 	    PSWITCH_HK_DISPLAY_CYCLE;
    273  1.1  jmcneill 	sc->sc_smpsw[SONY_PSW_DISPLAY_CYCLE].smpsw_type = PSWITCH_TYPE_HOTKEY;
    274  1.1  jmcneill 	sc->sc_smpsw[SONY_PSW_ZOOM].smpsw_name = PSWITCH_HK_ZOOM_BUTTON;
    275  1.1  jmcneill 	sc->sc_smpsw[SONY_PSW_ZOOM].smpsw_type = PSWITCH_TYPE_HOTKEY;
    276  1.1  jmcneill 	sc->sc_smpsw_valid = 1;
    277  1.1  jmcneill 
    278  1.1  jmcneill 	for (i = 0; i < SONY_PSW_LAST; i++)
    279  1.1  jmcneill 		if (sysmon_pswitch_register(&sc->sc_smpsw[i]) != 0) {
    280  1.1  jmcneill 			aprint_error("%s: couldn't register %s with sysmon\n",
    281  1.1  jmcneill 			    device_xname(self), sc->sc_smpsw[i].smpsw_name);
    282  1.1  jmcneill 			sc->sc_smpsw_valid = 0;
    283  1.1  jmcneill 		}
    284  1.1  jmcneill 
    285  1.1  jmcneill 	/* Install notify handler */
    286  1.1  jmcneill 	rv = AcpiInstallNotifyHandler(sc->sc_node->ad_handle,
    287  1.1  jmcneill 	    ACPI_DEVICE_NOTIFY, sony_acpi_notify_handler, self);
    288  1.1  jmcneill 	if (ACPI_FAILURE(rv))
    289  1.1  jmcneill 		aprint_error("%s: couldn't install notify handler (%d)\n",
    290  1.1  jmcneill 		    device_xname(self), rv);
    291  1.1  jmcneill 
    292  1.1  jmcneill 	/* Install sysctl handler */
    293  1.1  jmcneill 	rv = AcpiWalkNamespace(ACPI_TYPE_METHOD,
    294  1.1  jmcneill 	    sc->sc_node->ad_handle, 1, sony_walk_cb, sc, NULL);
    295  1.1  jmcneill #ifdef DIAGNOSTIC
    296  1.1  jmcneill 	if (ACPI_FAILURE(rv))
    297  1.1  jmcneill 		aprint_error("%s: Cannot walk ACPI namespace (%d)\n",
    298  1.1  jmcneill 		    device_xname(self), rv);
    299  1.1  jmcneill #endif
    300  1.1  jmcneill 
    301  1.1  jmcneill 	if (!pmf_device_register(self, sony_acpi_suspend, sony_acpi_resume))
    302  1.1  jmcneill 		aprint_error_dev(self, "couldn't establish power handler\n");
    303  1.1  jmcneill 
    304  1.1  jmcneill 	if (!pmf_event_register(self, PMFE_DISPLAY_BRIGHTNESS_UP,
    305  1.1  jmcneill 				 sony_acpi_brightness_up, true))
    306  1.1  jmcneill 		aprint_error_dev(self, "couldn't register BRIGHTNESS UP handler\n");
    307  1.1  jmcneill 
    308  1.1  jmcneill 	if (!pmf_event_register(self, PMFE_DISPLAY_BRIGHTNESS_DOWN,
    309  1.1  jmcneill 				 sony_acpi_brightness_down, true))
    310  1.1  jmcneill 		aprint_error_dev(self, "couldn't register BRIGHTNESS DOWN handler\n");
    311  1.1  jmcneill }
    312  1.1  jmcneill 
    313  1.1  jmcneill static void
    314  1.1  jmcneill sony_acpi_quirk_setup(struct sony_acpi_softc *sc)
    315  1.1  jmcneill {
    316  1.1  jmcneill 	const char *product_name;
    317  1.1  jmcneill 	ACPI_HANDLE hdl;
    318  1.1  jmcneill 	int i;
    319  1.1  jmcneill 
    320  1.1  jmcneill 	hdl = sc->sc_node->ad_handle;
    321  1.1  jmcneill 
    322  1.1  jmcneill 	product_name = pmf_get_platform("system-product-name");
    323  1.1  jmcneill 	if (product_name == NULL)
    324  1.1  jmcneill 		return;
    325  1.1  jmcneill 
    326  1.1  jmcneill 	for (i = 0; sony_acpi_quirks[i].product_name != NULL; i++)
    327  1.1  jmcneill 		if (strcmp(sony_acpi_quirks[i].product_name, product_name) == 0)
    328  1.1  jmcneill 			break;
    329  1.1  jmcneill 
    330  1.1  jmcneill 	if (sony_acpi_quirks[i].product_name == NULL)
    331  1.1  jmcneill 		return;
    332  1.1  jmcneill 
    333  1.1  jmcneill 	if (sony_acpi_quirks[i].quirks & SONY_ACPI_QUIRK_FNINIT) {
    334  1.1  jmcneill 		/* Initialize extra Fn keys */
    335  1.1  jmcneill 		sony_acpi_eval_set_integer(hdl, "SN02", 0x04, NULL);
    336  1.1  jmcneill 		sony_acpi_eval_set_integer(hdl, "SN07", 0x02, NULL);
    337  1.1  jmcneill 		sony_acpi_eval_set_integer(hdl, "SN02", 0x10, NULL);
    338  1.1  jmcneill 		sony_acpi_eval_set_integer(hdl, "SN07", 0x00, NULL);
    339  1.1  jmcneill 		sony_acpi_eval_set_integer(hdl, "SN03", 0x02, NULL);
    340  1.1  jmcneill 		sony_acpi_eval_set_integer(hdl, "SN07", 0x101, NULL);
    341  1.1  jmcneill 	}
    342  1.1  jmcneill 
    343  1.1  jmcneill 	return;
    344  1.1  jmcneill }
    345  1.1  jmcneill 
    346  1.1  jmcneill static void
    347  1.1  jmcneill sony_acpi_notify_handler(ACPI_HANDLE hdl, UINT32 notify, void *opaque)
    348  1.1  jmcneill {
    349  1.1  jmcneill 	device_t dv = opaque;
    350  1.1  jmcneill 	struct sony_acpi_softc *sc = device_private(dv);
    351  1.1  jmcneill 	ACPI_STATUS rv;
    352  1.1  jmcneill 	ACPI_INTEGER arg;
    353  1.1  jmcneill 	int s;
    354  1.1  jmcneill 
    355  1.1  jmcneill 	if (notify == SONY_NOTIFY_FnKeyEvent) {
    356  1.1  jmcneill 		rv = sony_acpi_eval_set_integer(hdl, "SN07", 0x202, &arg);
    357  1.1  jmcneill 		if (ACPI_FAILURE(rv))
    358  1.1  jmcneill 			return;
    359  1.1  jmcneill 
    360  1.1  jmcneill 		notify = arg & 0xff;
    361  1.1  jmcneill 	}
    362  1.1  jmcneill 
    363  1.1  jmcneill 	s = spltty();
    364  1.1  jmcneill 	switch (notify) {
    365  1.1  jmcneill 	case SONY_NOTIFY_BrightnessDownPressed:
    366  1.1  jmcneill 		sony_acpi_brightness_down(dv);
    367  1.1  jmcneill 		break;
    368  1.1  jmcneill 	case SONY_NOTIFY_BrightnessUpPressed:
    369  1.1  jmcneill 		sony_acpi_brightness_up(dv);
    370  1.1  jmcneill 		break;
    371  1.1  jmcneill 	case SONY_NOTIFY_BrightnessDownReleased:
    372  1.1  jmcneill 	case SONY_NOTIFY_BrightnessUpReleased:
    373  1.1  jmcneill 		break;
    374  1.1  jmcneill 	case SONY_NOTIFY_SuspendPressed:
    375  1.1  jmcneill 		if (!sc->sc_smpsw_valid)
    376  1.1  jmcneill 			break;
    377  1.1  jmcneill 		sysmon_pswitch_event(&sc->sc_smpsw[SONY_PSW_SLEEP],
    378  1.1  jmcneill 		    PSWITCH_EVENT_PRESSED);
    379  1.1  jmcneill 		break;
    380  1.1  jmcneill 	case SONY_NOTIFY_SuspendReleased:
    381  1.1  jmcneill 		break;
    382  1.1  jmcneill 	case SONY_NOTIFY_DisplaySwitchPressed:
    383  1.1  jmcneill 		if (!sc->sc_smpsw_valid)
    384  1.1  jmcneill 			break;
    385  1.1  jmcneill 		sysmon_pswitch_event(&sc->sc_smpsw[SONY_PSW_DISPLAY_CYCLE],
    386  1.1  jmcneill 		    PSWITCH_EVENT_PRESSED);
    387  1.1  jmcneill 		break;
    388  1.1  jmcneill 	case SONY_NOTIFY_DisplaySwitchReleased:
    389  1.1  jmcneill 		break;
    390  1.1  jmcneill 	case SONY_NOTIFY_ZoomPressed:
    391  1.1  jmcneill 		if (!sc->sc_smpsw_valid)
    392  1.1  jmcneill 			break;
    393  1.1  jmcneill 		sysmon_pswitch_event(&sc->sc_smpsw[SONY_PSW_ZOOM],
    394  1.1  jmcneill 		    PSWITCH_EVENT_PRESSED);
    395  1.1  jmcneill 		break;
    396  1.1  jmcneill 	case SONY_NOTIFY_ZoomReleased:
    397  1.1  jmcneill 		break;
    398  1.1  jmcneill 	default:
    399  1.1  jmcneill 		printf("%s: unknown notify event 0x%x\n",
    400  1.1  jmcneill 		    device_xname(&sc->sc_dev), notify);
    401  1.1  jmcneill 		break;
    402  1.1  jmcneill 	}
    403  1.1  jmcneill 	splx(s);
    404  1.1  jmcneill 
    405  1.1  jmcneill 	return;
    406  1.1  jmcneill }
    407  1.1  jmcneill 
    408  1.1  jmcneill static bool
    409  1.1  jmcneill sony_acpi_suspend(device_t dv)
    410  1.1  jmcneill {
    411  1.1  jmcneill 	struct sony_acpi_softc *sc = device_private(dv);
    412  1.1  jmcneill 
    413  1.1  jmcneill 	acpi_eval_integer(sc->sc_node->ad_handle, "GBRT", &sc->sc_pmstate.brt);
    414  1.1  jmcneill 
    415  1.1  jmcneill 	return true;
    416  1.1  jmcneill }
    417  1.1  jmcneill 
    418  1.1  jmcneill static bool
    419  1.1  jmcneill sony_acpi_resume(device_t dv)
    420  1.1  jmcneill {
    421  1.1  jmcneill 	struct sony_acpi_softc *sc = device_private(dv);
    422  1.1  jmcneill 
    423  1.1  jmcneill 	sony_acpi_eval_set_integer(sc->sc_node->ad_handle, "SBRT",
    424  1.1  jmcneill 	    sc->sc_pmstate.brt, NULL);
    425  1.1  jmcneill 	sony_acpi_quirk_setup(sc);
    426  1.1  jmcneill 
    427  1.1  jmcneill 	return true;
    428  1.1  jmcneill }
    429  1.1  jmcneill 
    430  1.1  jmcneill static void
    431  1.1  jmcneill sony_acpi_brightness_up(device_t dv)
    432  1.1  jmcneill {
    433  1.1  jmcneill 	struct sony_acpi_softc *sc = device_private(dv);
    434  1.1  jmcneill 	ACPI_INTEGER arg;
    435  1.1  jmcneill 	ACPI_STATUS rv;
    436  1.1  jmcneill 
    437  1.1  jmcneill 	rv = acpi_eval_integer(sc->sc_node->ad_handle, "GBRT", &arg);
    438  1.1  jmcneill 	if (ACPI_FAILURE(rv) || arg > 8)
    439  1.1  jmcneill 		return;
    440  1.1  jmcneill 	arg++;
    441  1.1  jmcneill 	sony_acpi_eval_set_integer(sc->sc_node->ad_handle, "SBRT", arg, NULL);
    442  1.1  jmcneill 
    443  1.1  jmcneill 	return;
    444  1.1  jmcneill }
    445  1.1  jmcneill 
    446  1.1  jmcneill static void
    447  1.1  jmcneill sony_acpi_brightness_down(device_t dv)
    448  1.1  jmcneill {
    449  1.1  jmcneill 	struct sony_acpi_softc *sc = device_private(dv);
    450  1.1  jmcneill 	ACPI_INTEGER arg;
    451  1.1  jmcneill 	ACPI_STATUS rv;
    452  1.1  jmcneill 
    453  1.1  jmcneill 	rv = acpi_eval_integer(sc->sc_node->ad_handle, "GBRT", &arg);
    454  1.1  jmcneill 	if (ACPI_FAILURE(rv) || arg == 0)
    455  1.1  jmcneill 		return;
    456  1.1  jmcneill 	arg--;
    457  1.1  jmcneill 	sony_acpi_eval_set_integer(sc->sc_node->ad_handle, "SBRT", arg, NULL);
    458  1.1  jmcneill 
    459  1.1  jmcneill 	return;
    460  1.1  jmcneill }
    461