Home | History | Annotate | Line # | Download | only in acpi
sony_acpi.c revision 1.23.32.1
      1  1.23.32.1   thorpej /*	$NetBSD: sony_acpi.c,v 1.23.32.1 2021/04/03 22:28:43 thorpej 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  *
     19        1.1  jmcneill  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20        1.1  jmcneill  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21        1.1  jmcneill  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22        1.1  jmcneill  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23        1.1  jmcneill  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24        1.1  jmcneill  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25        1.1  jmcneill  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26        1.1  jmcneill  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27        1.1  jmcneill  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28        1.1  jmcneill  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29        1.1  jmcneill  * POSSIBILITY OF SUCH DAMAGE.
     30        1.1  jmcneill  */
     31        1.1  jmcneill #include <sys/cdefs.h>
     32  1.23.32.1   thorpej __KERNEL_RCSID(0, "$NetBSD: sony_acpi.c,v 1.23.32.1 2021/04/03 22:28:43 thorpej Exp $");
     33        1.1  jmcneill 
     34        1.1  jmcneill #include <sys/param.h>
     35       1.15    jruoho #include <sys/sysctl.h>
     36        1.1  jmcneill #include <sys/systm.h>
     37        1.1  jmcneill 
     38       1.15    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            ("sony_acpi")
     43        1.1  jmcneill 
     44        1.7    simonb #define	SONY_NOTIFY_FnKeyEvent			0x92
     45        1.7    simonb #define	SONY_NOTIFY_BrightnessDownPressed	0x85
     46        1.7    simonb #define	SONY_NOTIFY_BrightnessDownReleased	0x05
     47        1.7    simonb #define	SONY_NOTIFY_BrightnessUpPressed		0x86
     48        1.7    simonb #define	SONY_NOTIFY_BrightnessUpReleased	0x06
     49        1.7    simonb #define	SONY_NOTIFY_DisplaySwitchPressed	0x87
     50        1.7    simonb #define	SONY_NOTIFY_DisplaySwitchReleased	0x07
     51        1.7    simonb #define	SONY_NOTIFY_ZoomPressed			0x8a
     52        1.7    simonb #define	SONY_NOTIFY_ZoomReleased		0x0a
     53        1.7    simonb #define	SONY_NOTIFY_SuspendPressed		0x8c
     54        1.7    simonb #define	SONY_NOTIFY_SuspendReleased		0x0c
     55        1.1  jmcneill 
     56        1.1  jmcneill struct sony_acpi_softc {
     57        1.5   xtraeme 	device_t sc_dev;
     58        1.1  jmcneill 	struct sysctllog *sc_log;
     59        1.1  jmcneill 	struct acpi_devnode *sc_node;
     60        1.1  jmcneill 
     61        1.1  jmcneill #define	SONY_PSW_SLEEP		0
     62        1.1  jmcneill #define	SONY_PSW_DISPLAY_CYCLE	1
     63        1.1  jmcneill #define	SONY_PSW_ZOOM		2
     64        1.1  jmcneill #define	SONY_PSW_LAST		3
     65        1.1  jmcneill 	struct sysmon_pswitch sc_smpsw[SONY_PSW_LAST];
     66        1.1  jmcneill 	int sc_smpsw_valid;
     67        1.1  jmcneill 
     68        1.7    simonb #define	SONY_ACPI_QUIRK_FNINIT	0x01
     69        1.2  jmcneill 	int sc_quirks;
     70        1.2  jmcneill 	bool sc_has_pic;
     71        1.2  jmcneill 
     72        1.1  jmcneill 	struct sony_acpi_pmstate {
     73        1.1  jmcneill 		ACPI_INTEGER	brt;
     74        1.1  jmcneill 	} sc_pmstate;
     75        1.1  jmcneill };
     76        1.1  jmcneill 
     77  1.23.32.1   thorpej static const struct device_compatible_entry compat_data[] = {
     78  1.23.32.1   thorpej 	{ .compat = "SNY5001" },
     79  1.23.32.1   thorpej 	DEVICE_COMPAT_EOL
     80        1.1  jmcneill };
     81        1.1  jmcneill 
     82        1.5   xtraeme static int	sony_acpi_match(device_t, cfdata_t, void *);
     83        1.5   xtraeme static void	sony_acpi_attach(device_t, device_t, void *);
     84        1.1  jmcneill static ACPI_STATUS sony_acpi_eval_set_integer(ACPI_HANDLE, const char *,
     85        1.1  jmcneill     ACPI_INTEGER, ACPI_INTEGER *);
     86        1.1  jmcneill static void	sony_acpi_quirk_setup(struct sony_acpi_softc *);
     87       1.17    jruoho static void	sony_acpi_notify_handler(ACPI_HANDLE, uint32_t, void *);
     88       1.13    dyoung static bool	sony_acpi_suspend(device_t, const pmf_qual_t *);
     89       1.13    dyoung static bool	sony_acpi_resume(device_t, const pmf_qual_t *);
     90        1.1  jmcneill static void	sony_acpi_brightness_down(device_t);
     91        1.1  jmcneill static void	sony_acpi_brightness_up(device_t);
     92       1.17    jruoho static ACPI_STATUS sony_acpi_find_pic(ACPI_HANDLE, uint32_t, void *, void **);
     93        1.1  jmcneill 
     94        1.5   xtraeme CFATTACH_DECL_NEW(sony_acpi, sizeof(struct sony_acpi_softc),
     95        1.1  jmcneill     sony_acpi_match, sony_acpi_attach, NULL, NULL);
     96        1.1  jmcneill 
     97        1.1  jmcneill static int
     98        1.5   xtraeme sony_acpi_match(device_t parent, cfdata_t match, void *aux)
     99        1.1  jmcneill {
    100        1.1  jmcneill 	struct acpi_attach_args *aa = aux;
    101        1.1  jmcneill 
    102  1.23.32.1   thorpej 	return acpi_compatible_match(aa, compat_data);
    103        1.1  jmcneill }
    104        1.1  jmcneill 
    105        1.1  jmcneill static int
    106        1.1  jmcneill sony_sysctl_helper(SYSCTLFN_ARGS)
    107        1.1  jmcneill {
    108        1.1  jmcneill 	struct sysctlnode node;
    109        1.1  jmcneill 	ACPI_INTEGER acpi_val;
    110        1.1  jmcneill 	ACPI_STATUS rv;
    111        1.1  jmcneill 	int val, old_val, error;
    112        1.1  jmcneill 	char buf[SYSCTL_NAMELEN + 1], *ptr;
    113        1.1  jmcneill 	struct sony_acpi_softc *sc = rnode->sysctl_data;
    114        1.1  jmcneill 
    115        1.1  jmcneill 	(void)snprintf(buf, sizeof(buf), "G%s", rnode->sysctl_name);
    116        1.1  jmcneill 	for (ptr = buf; *ptr; ptr++)
    117        1.8  christos 		*ptr = toupper((unsigned char)*ptr);
    118        1.1  jmcneill 
    119        1.1  jmcneill 	rv = acpi_eval_integer(sc->sc_node->ad_handle, buf, &acpi_val);
    120        1.1  jmcneill 	if (ACPI_FAILURE(rv)) {
    121        1.1  jmcneill #ifdef DIAGNOSTIC
    122       1.23   msaitoh 		printf("%s: couldn't get `%s'\n", device_xname(sc->sc_dev),
    123       1.23   msaitoh 		    buf);
    124        1.1  jmcneill #endif
    125        1.1  jmcneill 		return EIO;
    126        1.1  jmcneill 	}
    127        1.1  jmcneill 	val = old_val = acpi_val;
    128        1.1  jmcneill 
    129        1.1  jmcneill 	node = *rnode;
    130        1.1  jmcneill 	node.sysctl_data = &val;
    131        1.1  jmcneill 
    132        1.1  jmcneill 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    133        1.1  jmcneill 	if (error || newp == NULL)
    134        1.1  jmcneill 		return error;
    135        1.1  jmcneill 
    136        1.8  christos 	buf[0] = 'S';
    137        1.1  jmcneill 	acpi_val = val;
    138        1.1  jmcneill 	rv = sony_acpi_eval_set_integer(sc->sc_node->ad_handle, buf,
    139        1.1  jmcneill 	    acpi_val, NULL);
    140        1.1  jmcneill 	if (ACPI_FAILURE(rv)) {
    141        1.1  jmcneill #ifdef DIAGNOSTIC
    142        1.1  jmcneill 		printf("%s: couldn't set `%s' to %d\n",
    143        1.5   xtraeme 		    device_xname(sc->sc_dev), buf, val);
    144        1.1  jmcneill #endif
    145        1.1  jmcneill 		return EIO;
    146        1.1  jmcneill 	}
    147        1.1  jmcneill 	return 0;
    148        1.1  jmcneill }
    149        1.1  jmcneill 
    150        1.1  jmcneill static ACPI_STATUS
    151       1.17    jruoho sony_walk_cb(ACPI_HANDLE hnd, uint32_t v, void *context, void **status)
    152        1.1  jmcneill {
    153        1.5   xtraeme 	struct sony_acpi_softc *sc = (void *)context;
    154        1.1  jmcneill 	const struct sysctlnode *node, *snode;
    155        1.1  jmcneill 	const char *name = acpi_name(hnd);
    156        1.1  jmcneill 	ACPI_INTEGER acpi_val;
    157        1.1  jmcneill 	char buf[SYSCTL_NAMELEN + 1], *ptr;
    158        1.1  jmcneill 	int rv;
    159        1.1  jmcneill 
    160        1.1  jmcneill 	if ((name = strrchr(name, '.')) == NULL)
    161        1.1  jmcneill 		return AE_OK;
    162        1.1  jmcneill 
    163        1.1  jmcneill 	name++;
    164        1.1  jmcneill 	if ((*name != 'G') && (*name != 'S'))
    165        1.1  jmcneill 		return AE_OK;
    166        1.1  jmcneill 
    167        1.1  jmcneill 	(void)strlcpy(buf, name, sizeof(buf));
    168        1.1  jmcneill 	*buf = 'G';
    169        1.1  jmcneill 
    170        1.1  jmcneill 	/*
    171        1.1  jmcneill 	 * We assume that if the 'get' of the name as an integer is
    172        1.1  jmcneill 	 * successful it is ok.
    173        1.1  jmcneill 	 */
    174        1.1  jmcneill 	if (acpi_eval_integer(sc->sc_node->ad_handle, buf, &acpi_val))
    175        1.1  jmcneill 		return AE_OK;
    176        1.1  jmcneill 
    177        1.1  jmcneill 	for (ptr = buf; *ptr; ptr++)
    178        1.1  jmcneill 		*ptr = tolower(*ptr);
    179        1.1  jmcneill 
    180       1.22     pooka 	if ((rv = sysctl_createv(&sc->sc_log, 0, NULL, &snode, 0,
    181        1.5   xtraeme 	    CTLTYPE_NODE, device_xname(sc->sc_dev),
    182        1.1  jmcneill 	    SYSCTL_DESCR("sony controls"),
    183       1.22     pooka 	    NULL, 0, NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL)) != 0)
    184        1.1  jmcneill 		goto out;
    185        1.1  jmcneill 
    186        1.1  jmcneill 	if ((rv = sysctl_createv(&sc->sc_log, 0, &snode, &node,
    187        1.1  jmcneill 	    CTLFLAG_READWRITE, CTLTYPE_INT, buf + 1, NULL,
    188       1.21       dsl 	    sony_sysctl_helper, 0, (void *)sc, 0, CTL_CREATE, CTL_EOL)) != 0)
    189        1.1  jmcneill 		goto out;
    190        1.1  jmcneill 
    191        1.1  jmcneill out:
    192        1.1  jmcneill #ifdef DIAGNOSTIC
    193        1.1  jmcneill 	if (rv)
    194        1.1  jmcneill 		printf("%s: sysctl_createv failed (rv = %d)\n",
    195        1.5   xtraeme 		    device_xname(sc->sc_dev), rv);
    196        1.1  jmcneill #endif
    197        1.1  jmcneill 	return AE_OK;
    198        1.1  jmcneill }
    199        1.1  jmcneill 
    200        1.1  jmcneill ACPI_STATUS
    201        1.1  jmcneill sony_acpi_eval_set_integer(ACPI_HANDLE handle, const char *path,
    202        1.1  jmcneill     ACPI_INTEGER val, ACPI_INTEGER *valp)
    203        1.1  jmcneill {
    204        1.1  jmcneill 	ACPI_STATUS rv;
    205        1.1  jmcneill 	ACPI_BUFFER buf;
    206        1.1  jmcneill 	ACPI_OBJECT param, ret_val;
    207        1.1  jmcneill 	ACPI_OBJECT_LIST params;
    208        1.1  jmcneill 
    209        1.1  jmcneill 	if (handle == NULL)
    210        1.1  jmcneill 		handle = ACPI_ROOT_OBJECT;
    211        1.1  jmcneill 
    212        1.1  jmcneill 	params.Count = 1;
    213        1.1  jmcneill 	params.Pointer = &param;
    214        1.1  jmcneill 
    215        1.1  jmcneill 	param.Type = ACPI_TYPE_INTEGER;
    216        1.1  jmcneill 	param.Integer.Value = val;
    217        1.1  jmcneill 
    218        1.1  jmcneill 	buf.Pointer = &ret_val;
    219        1.1  jmcneill 	buf.Length = sizeof(ret_val);
    220        1.1  jmcneill 
    221        1.1  jmcneill 	rv = AcpiEvaluateObjectTyped(handle, path, &params, &buf,
    222        1.1  jmcneill 	    ACPI_TYPE_INTEGER);
    223        1.1  jmcneill 
    224        1.1  jmcneill 	if (ACPI_SUCCESS(rv) && valp)
    225        1.1  jmcneill 		*valp = ret_val.Integer.Value;
    226        1.1  jmcneill 
    227        1.1  jmcneill 	return rv;
    228        1.1  jmcneill }
    229        1.1  jmcneill 
    230        1.1  jmcneill static void
    231        1.5   xtraeme sony_acpi_attach(device_t parent, device_t self, void *aux)
    232        1.1  jmcneill {
    233        1.5   xtraeme 	struct sony_acpi_softc *sc = device_private(self);
    234        1.1  jmcneill 	struct acpi_attach_args *aa = aux;
    235        1.1  jmcneill 	ACPI_STATUS rv;
    236        1.1  jmcneill 	int i;
    237        1.1  jmcneill 
    238        1.1  jmcneill 	aprint_naive(": Sony Miscellaneous Controller\n");
    239        1.1  jmcneill 	aprint_normal(": Sony Miscellaneous Controller\n");
    240        1.1  jmcneill 
    241        1.1  jmcneill 	sc->sc_node = aa->aa_node;
    242        1.5   xtraeme 	sc->sc_dev = self;
    243        1.1  jmcneill 
    244        1.2  jmcneill 	rv = AcpiWalkNamespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, 100,
    245       1.16    jruoho 	    sony_acpi_find_pic, NULL, sc, NULL);
    246        1.2  jmcneill 	if (ACPI_FAILURE(rv))
    247        1.2  jmcneill 		aprint_error_dev(self, "couldn't walk namespace: %s\n",
    248        1.2  jmcneill 		    AcpiFormatException(rv));
    249        1.2  jmcneill 
    250        1.2  jmcneill 	/*
    251        1.2  jmcneill 	 * If we don't find an SNY6001 device, assume that we need the
    252        1.2  jmcneill 	 * Fn key initialization sequence.
    253        1.2  jmcneill 	 */
    254        1.2  jmcneill 	if (sc->sc_has_pic == false)
    255        1.2  jmcneill 		sc->sc_quirks |= SONY_ACPI_QUIRK_FNINIT;
    256        1.2  jmcneill 
    257        1.1  jmcneill 	sony_acpi_quirk_setup(sc);
    258        1.1  jmcneill 
    259        1.1  jmcneill 	/* Configure suspend button and hotkeys */
    260        1.5   xtraeme 	sc->sc_smpsw[SONY_PSW_SLEEP].smpsw_name = device_xname(self);
    261        1.1  jmcneill 	sc->sc_smpsw[SONY_PSW_SLEEP].smpsw_type = PSWITCH_TYPE_SLEEP;
    262        1.1  jmcneill 	sc->sc_smpsw[SONY_PSW_DISPLAY_CYCLE].smpsw_name =
    263        1.1  jmcneill 	    PSWITCH_HK_DISPLAY_CYCLE;
    264        1.1  jmcneill 	sc->sc_smpsw[SONY_PSW_DISPLAY_CYCLE].smpsw_type = PSWITCH_TYPE_HOTKEY;
    265        1.1  jmcneill 	sc->sc_smpsw[SONY_PSW_ZOOM].smpsw_name = PSWITCH_HK_ZOOM_BUTTON;
    266        1.1  jmcneill 	sc->sc_smpsw[SONY_PSW_ZOOM].smpsw_type = PSWITCH_TYPE_HOTKEY;
    267        1.1  jmcneill 	sc->sc_smpsw_valid = 1;
    268        1.1  jmcneill 
    269        1.1  jmcneill 	for (i = 0; i < SONY_PSW_LAST; i++)
    270        1.1  jmcneill 		if (sysmon_pswitch_register(&sc->sc_smpsw[i]) != 0) {
    271        1.5   xtraeme 			aprint_error_dev(self,
    272        1.5   xtraeme 			    "couldn't register %s with sysmon\n",
    273        1.5   xtraeme 			    sc->sc_smpsw[i].smpsw_name);
    274        1.1  jmcneill 			sc->sc_smpsw_valid = 0;
    275        1.1  jmcneill 		}
    276        1.1  jmcneill 
    277       1.18    jruoho 	(void)acpi_register_notify(sc->sc_node, sony_acpi_notify_handler);
    278        1.1  jmcneill 
    279        1.1  jmcneill 	/* Install sysctl handler */
    280        1.1  jmcneill 	rv = AcpiWalkNamespace(ACPI_TYPE_METHOD,
    281       1.16    jruoho 	    sc->sc_node->ad_handle, 1, sony_walk_cb, NULL, sc, NULL);
    282       1.18    jruoho 
    283        1.1  jmcneill #ifdef DIAGNOSTIC
    284        1.1  jmcneill 	if (ACPI_FAILURE(rv))
    285       1.14    jruoho 		aprint_error_dev(self, "Cannot walk ACPI namespace (%u)\n",
    286        1.5   xtraeme 		    rv);
    287        1.1  jmcneill #endif
    288        1.1  jmcneill 
    289        1.1  jmcneill 	if (!pmf_device_register(self, sony_acpi_suspend, sony_acpi_resume))
    290        1.1  jmcneill 		aprint_error_dev(self, "couldn't establish power handler\n");
    291        1.1  jmcneill 
    292        1.1  jmcneill 	if (!pmf_event_register(self, PMFE_DISPLAY_BRIGHTNESS_UP,
    293        1.1  jmcneill 				 sony_acpi_brightness_up, true))
    294       1.23   msaitoh 		aprint_error_dev(self,
    295       1.23   msaitoh 		    "couldn't register BRIGHTNESS UP handler\n");
    296        1.1  jmcneill 
    297        1.1  jmcneill 	if (!pmf_event_register(self, PMFE_DISPLAY_BRIGHTNESS_DOWN,
    298        1.1  jmcneill 				 sony_acpi_brightness_down, true))
    299       1.23   msaitoh 		aprint_error_dev(self,
    300       1.23   msaitoh 		    "couldn't register BRIGHTNESS DOWN handler\n");
    301        1.1  jmcneill }
    302        1.1  jmcneill 
    303        1.1  jmcneill static void
    304        1.1  jmcneill sony_acpi_quirk_setup(struct sony_acpi_softc *sc)
    305        1.1  jmcneill {
    306        1.2  jmcneill 	ACPI_HANDLE hdl = sc->sc_node->ad_handle;
    307        1.1  jmcneill 
    308        1.2  jmcneill 	if (sc->sc_quirks & SONY_ACPI_QUIRK_FNINIT) {
    309        1.1  jmcneill 		/* Initialize extra Fn keys */
    310        1.1  jmcneill 		sony_acpi_eval_set_integer(hdl, "SN02", 0x04, NULL);
    311        1.1  jmcneill 		sony_acpi_eval_set_integer(hdl, "SN07", 0x02, NULL);
    312        1.1  jmcneill 		sony_acpi_eval_set_integer(hdl, "SN02", 0x10, NULL);
    313        1.1  jmcneill 		sony_acpi_eval_set_integer(hdl, "SN07", 0x00, NULL);
    314        1.1  jmcneill 		sony_acpi_eval_set_integer(hdl, "SN03", 0x02, NULL);
    315        1.1  jmcneill 		sony_acpi_eval_set_integer(hdl, "SN07", 0x101, NULL);
    316        1.1  jmcneill 	}
    317        1.1  jmcneill }
    318        1.1  jmcneill 
    319        1.1  jmcneill static void
    320       1.17    jruoho sony_acpi_notify_handler(ACPI_HANDLE hdl, uint32_t notify, void *opaque)
    321        1.1  jmcneill {
    322        1.1  jmcneill 	device_t dv = opaque;
    323        1.1  jmcneill 	struct sony_acpi_softc *sc = device_private(dv);
    324        1.1  jmcneill 	ACPI_STATUS rv;
    325        1.1  jmcneill 	ACPI_INTEGER arg;
    326        1.1  jmcneill 
    327        1.1  jmcneill 	if (notify == SONY_NOTIFY_FnKeyEvent) {
    328        1.1  jmcneill 		rv = sony_acpi_eval_set_integer(hdl, "SN07", 0x202, &arg);
    329        1.1  jmcneill 		if (ACPI_FAILURE(rv))
    330        1.1  jmcneill 			return;
    331        1.1  jmcneill 
    332        1.1  jmcneill 		notify = arg & 0xff;
    333        1.1  jmcneill 	}
    334        1.1  jmcneill 
    335        1.1  jmcneill 	switch (notify) {
    336        1.1  jmcneill 	case SONY_NOTIFY_BrightnessDownPressed:
    337        1.1  jmcneill 		sony_acpi_brightness_down(dv);
    338        1.1  jmcneill 		break;
    339        1.1  jmcneill 	case SONY_NOTIFY_BrightnessUpPressed:
    340        1.1  jmcneill 		sony_acpi_brightness_up(dv);
    341        1.1  jmcneill 		break;
    342        1.1  jmcneill 	case SONY_NOTIFY_BrightnessDownReleased:
    343        1.1  jmcneill 	case SONY_NOTIFY_BrightnessUpReleased:
    344        1.1  jmcneill 		break;
    345        1.1  jmcneill 	case SONY_NOTIFY_SuspendPressed:
    346        1.1  jmcneill 		if (!sc->sc_smpsw_valid)
    347        1.1  jmcneill 			break;
    348        1.1  jmcneill 		sysmon_pswitch_event(&sc->sc_smpsw[SONY_PSW_SLEEP],
    349        1.1  jmcneill 		    PSWITCH_EVENT_PRESSED);
    350        1.1  jmcneill 		break;
    351        1.1  jmcneill 	case SONY_NOTIFY_SuspendReleased:
    352        1.1  jmcneill 		break;
    353        1.1  jmcneill 	case SONY_NOTIFY_DisplaySwitchPressed:
    354        1.1  jmcneill 		if (!sc->sc_smpsw_valid)
    355        1.1  jmcneill 			break;
    356        1.1  jmcneill 		sysmon_pswitch_event(&sc->sc_smpsw[SONY_PSW_DISPLAY_CYCLE],
    357        1.1  jmcneill 		    PSWITCH_EVENT_PRESSED);
    358        1.1  jmcneill 		break;
    359        1.1  jmcneill 	case SONY_NOTIFY_DisplaySwitchReleased:
    360        1.1  jmcneill 		break;
    361        1.1  jmcneill 	case SONY_NOTIFY_ZoomPressed:
    362        1.1  jmcneill 		if (!sc->sc_smpsw_valid)
    363        1.1  jmcneill 			break;
    364        1.1  jmcneill 		sysmon_pswitch_event(&sc->sc_smpsw[SONY_PSW_ZOOM],
    365        1.1  jmcneill 		    PSWITCH_EVENT_PRESSED);
    366        1.1  jmcneill 		break;
    367        1.1  jmcneill 	case SONY_NOTIFY_ZoomReleased:
    368        1.1  jmcneill 		break;
    369        1.1  jmcneill 	default:
    370       1.19    jruoho 		aprint_debug_dev(dv, "unknown notify event 0x%x\n", notify);
    371        1.1  jmcneill 		break;
    372        1.1  jmcneill 	}
    373        1.1  jmcneill }
    374        1.1  jmcneill 
    375        1.1  jmcneill static bool
    376       1.13    dyoung sony_acpi_suspend(device_t dv, const pmf_qual_t *qual)
    377        1.1  jmcneill {
    378        1.1  jmcneill 	struct sony_acpi_softc *sc = device_private(dv);
    379        1.1  jmcneill 
    380        1.1  jmcneill 	acpi_eval_integer(sc->sc_node->ad_handle, "GBRT", &sc->sc_pmstate.brt);
    381        1.1  jmcneill 
    382        1.1  jmcneill 	return true;
    383        1.1  jmcneill }
    384        1.1  jmcneill 
    385        1.1  jmcneill static bool
    386       1.13    dyoung sony_acpi_resume(device_t dv, const pmf_qual_t *qual)
    387        1.1  jmcneill {
    388        1.1  jmcneill 	struct sony_acpi_softc *sc = device_private(dv);
    389        1.1  jmcneill 
    390        1.1  jmcneill 	sony_acpi_eval_set_integer(sc->sc_node->ad_handle, "SBRT",
    391        1.1  jmcneill 	    sc->sc_pmstate.brt, NULL);
    392        1.1  jmcneill 	sony_acpi_quirk_setup(sc);
    393        1.1  jmcneill 
    394        1.1  jmcneill 	return true;
    395        1.1  jmcneill }
    396        1.1  jmcneill 
    397        1.1  jmcneill static void
    398        1.1  jmcneill sony_acpi_brightness_up(device_t dv)
    399        1.1  jmcneill {
    400        1.1  jmcneill 	struct sony_acpi_softc *sc = device_private(dv);
    401        1.1  jmcneill 	ACPI_INTEGER arg;
    402        1.1  jmcneill 	ACPI_STATUS rv;
    403        1.1  jmcneill 
    404        1.1  jmcneill 	rv = acpi_eval_integer(sc->sc_node->ad_handle, "GBRT", &arg);
    405        1.3  christos 	if (ACPI_FAILURE(rv))
    406        1.1  jmcneill 		return;
    407        1.3  christos 	if (arg >= 8)
    408        1.3  christos 		arg = 8;
    409        1.3  christos 	else
    410        1.3  christos 		arg++;
    411        1.1  jmcneill 	sony_acpi_eval_set_integer(sc->sc_node->ad_handle, "SBRT", arg, NULL);
    412        1.1  jmcneill }
    413        1.1  jmcneill 
    414        1.1  jmcneill static void
    415        1.1  jmcneill sony_acpi_brightness_down(device_t dv)
    416        1.1  jmcneill {
    417        1.1  jmcneill 	struct sony_acpi_softc *sc = device_private(dv);
    418        1.1  jmcneill 	ACPI_INTEGER arg;
    419        1.1  jmcneill 	ACPI_STATUS rv;
    420        1.1  jmcneill 
    421        1.1  jmcneill 	rv = acpi_eval_integer(sc->sc_node->ad_handle, "GBRT", &arg);
    422        1.3  christos 	if (ACPI_FAILURE(rv))
    423        1.1  jmcneill 		return;
    424        1.3  christos 	if (arg <= 0)
    425        1.3  christos 		arg = 0;
    426        1.3  christos 	else
    427        1.3  christos 		arg--;
    428        1.1  jmcneill 	sony_acpi_eval_set_integer(sc->sc_node->ad_handle, "SBRT", arg, NULL);
    429        1.2  jmcneill }
    430        1.1  jmcneill 
    431        1.2  jmcneill static ACPI_STATUS
    432       1.17    jruoho sony_acpi_find_pic(ACPI_HANDLE hdl, uint32_t level,
    433       1.17    jruoho     void *opaque, void **status)
    434        1.2  jmcneill {
    435        1.2  jmcneill 	struct sony_acpi_softc *sc = opaque;
    436        1.2  jmcneill 	ACPI_STATUS rv;
    437        1.2  jmcneill 	ACPI_DEVICE_INFO *devinfo;
    438        1.2  jmcneill 
    439        1.9  jmcneill 	rv = AcpiGetObjectInfo(hdl, &devinfo);
    440        1.9  jmcneill 	if (ACPI_FAILURE(rv) || devinfo == NULL)
    441        1.2  jmcneill 		return AE_OK;	/* we don't want to stop searching */
    442        1.2  jmcneill 
    443       1.20    gsutre 	if ((devinfo->Valid & ACPI_VALID_HID) != 0 &&
    444       1.20    gsutre 	    devinfo->HardwareId.String &&
    445       1.10  christos 	    strncmp(devinfo->HardwareId.String, "SNY6001", 7) == 0)
    446        1.2  jmcneill 		sc->sc_has_pic = true;
    447        1.2  jmcneill 
    448       1.11   mlelstv 	ACPI_FREE(devinfo);
    449        1.2  jmcneill 
    450        1.2  jmcneill 	return AE_OK;
    451        1.1  jmcneill }
    452