acpi/ is being populated so I' reworked an old patch I made and
I post again it ported from NetBSD
all these key events are catched (alas no events for volume keys):
BrightnessDownPressed
BrightnessDownReleased
BrightnessUpPressed
BrightnessUpReleased
DisplaySwitchPressed
DisplaySwitchReleased
ZoomPressed
ZoomReleased
SuspendPressed
SuspendReleased
on my laptop (vaio vgn c1s/h model) brightness keys are mapped to:
Fn+F5 increase brighteness
Fn+F6 decrease brighteness
and it works.
I'm trying to understand the role of the SPIC (SNY6001 hid) so I'm wondering
if there is any nasty side effect in bypassing it and always
applying the Fn key initialization sequence as I've made
suggestions?
diff -ruN sys.orig/dev/acpi/acpi.c sys/dev/acpi/acpi.c
--- sys.orig/dev/acpi/acpi.c Mon Apr 28 13:56:27 2008
+++ sys/dev/acpi/acpi.c Mon Apr 28 17:24:25 2008
@@ -1857,6 +1857,8 @@
aaa.aaa_name = "acpiasus";
else if (!strcmp(dev, ACPI_DEV_THINKPAD))
aaa.aaa_name = "acpithinkpad";
+ else if (!strcmp(dev, ACPI_DEV_SONY))
+ aaa.aaa_name = "acpisony";
if (aaa.aaa_name)
config_found(self, &aaa, acpi_print);
diff -ruN sys.orig/dev/acpi/acpireg.h sys/dev/acpi/acpireg.h
--- sys.orig/dev/acpi/acpireg.h Mon Apr 28 13:56:27 2008
+++ sys/dev/acpi/acpireg.h Mon Apr 28 17:25:02 2008
@@ -486,5 +486,6 @@
#define ACPI_DEV_FFB "FIXEDBUTTON" /* Fixed Feature Button */
#define ACPI_DEV_ASUS "ASUS010" /* ASUS Hotkeys */
#define ACPI_DEV_THINKPAD "IBM0068" /* Thinkpad support */
+#define ACPI_DEV_SONY "SNY5001" /* Vaio support */
#endif /* !_DEV_ACPI_ACPIREG_H_ */
diff -ruN sys.orig/dev/acpi/acpisony.c sys/dev/acpi/acpisony.c
--- sys.orig/dev/acpi/acpisony.c Thu Jan 1 01:00:00 1970
+++ sys/dev/acpi/acpisony.c Mon Apr 28 22:02:56 2008
@@ -0,0 +1,239 @@
+/* $NetBSD: sony_acpi.c,v 1.5 2008/03/26 18:35:17 xtraeme Exp $ */
+
+/*-
+ * Copyright (c) 2005 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/param.h>
+#include <sys/device.h>
+#include <sys/systm.h>
+
+#include <dev/acpi/acpireg.h>
+#include <dev/acpi/acpivar.h>
+#include <dev/acpi/acpidev.h>
+#include <dev/acpi/amltypes.h>
+#include <dev/acpi/dsdt.h>
+
+#define SONY_NOTIFY_FnKeyEvent 0x92
+#define SONY_NOTIFY_BrightnessDownPressed 0x85
+#define SONY_NOTIFY_BrightnessDownReleased 0x05
+#define SONY_NOTIFY_BrightnessUpPressed 0x86
+#define SONY_NOTIFY_BrightnessUpReleased 0x06
+#define SONY_NOTIFY_DisplaySwitchPressed 0x87
+#define SONY_NOTIFY_DisplaySwitchReleased 0x07
+#define SONY_NOTIFY_ZoomPressed 0x8a
+#define SONY_NOTIFY_ZoomReleased 0x0a
+#define SONY_NOTIFY_SuspendPressed 0x8c
+#define SONY_NOTIFY_SuspendReleased 0x0c
+
+struct acpisony_softc {
+ struct device sc_dev;
+ struct acpi_softc *sc_acpi;
+ struct aml_node *sc_devnode;
+};
+
+int acpisony_match(struct device *, void *, void *);
+void acpisony_attach(struct device *, struct device *, void *);
+int acpisony_notify(struct aml_node *, int, void *);
+void acpisony_brightness_down(struct acpisony_softc *);
+void acpisony_brightness_up(struct acpisony_softc *);
+void acpisony_quirk_setup(struct acpisony_softc *);
+void acpisony_eval_set(struct acpisony_softc *, const char *, int);
+struct cfattach acpisony_ca = {
+ sizeof(struct acpisony_softc), acpisony_match, acpisony_attach
+};
+
+struct cfdriver acpisony_cd = {
+ NULL, "acpisony", DV_DULL
+};
+
+int
+acpisony_match(struct device *parent, void *match, void *aux)
+{
+ struct acpi_attach_args *aa = aux;
+ struct cfdata *cf = match;
+
+ if (aa->aaa_name == NULL ||
+ strcmp(aa->aaa_name, cf->cf_driver->cd_name) != 0 ||
+ aa->aaa_table != NULL)
+ return 0;
+
+ return 1;
+}
+
+void
+acpisony_attach(struct device *parent, struct device *self, void *aux)
+{
+ struct acpisony_softc *sc = (struct acpisony_softc *)self;
+ struct acpi_attach_args *aa = aux;
+
+ sc->sc_acpi = (struct acpi_softc *)parent;
+ sc->sc_devnode = aa->aaa_node->child;
+
+ printf("\n");
+
+ acpisony_quirk_setup(sc);
+
+ aml_register_notify(sc->sc_devnode->parent, aa->aaa_dev,
+ acpisony_notify, sc, ACPIDEV_NOPOLL);
+}
+
+int
+acpisony_notify(struct aml_node *node, int notify, void *arg)
+{
+ struct acpisony_softc *sc = arg;
+ struct aml_value res, res2;
+ int val;
+
+ if (notify == SONY_NOTIFY_FnKeyEvent) {
+ memset(&res, 0, sizeof(res));
+ res.type = AML_OBJTYPE_INTEGER;
+ res.v_integer = 0x202;
+
+ if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "SN07", 1, &res,
&res2))
+ dnprintf(20, "%s: error evaluating SN07", DEVNAME(sc));
+
+ val = aml_val2int(&res2);
+ aml_freevalue(&res);
+ aml_freevalue(&res2);
+
+ notify = val & 0xff;
+ }
+
+ switch (notify) {
+ case SONY_NOTIFY_BrightnessDownPressed:
+ acpisony_brightness_down(sc);
+ break;
+ case SONY_NOTIFY_BrightnessUpPressed:
+ acpisony_brightness_up(sc);
+ break;
+ case SONY_NOTIFY_BrightnessDownReleased:
+ case SONY_NOTIFY_BrightnessUpReleased:
+ break;
+ case SONY_NOTIFY_DisplaySwitchPressed:
+ case SONY_NOTIFY_DisplaySwitchReleased:
+ break;
+ case SONY_NOTIFY_ZoomPressed:
+ case SONY_NOTIFY_ZoomReleased:
+ break;
+ case SONY_NOTIFY_SuspendPressed:
+ case SONY_NOTIFY_SuspendReleased:
+ break;
+ default:
+ printf("%s: unknown event 0x%02x\n", DEVNAME(sc), notify);
+ break;
+ }
+
+ return 0;
+}
+
+void
+acpisony_brightness_up(struct acpisony_softc *sc)
+{
+ struct aml_value res;
+ int arg;
+
+ if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "GBRT", 0, NULL, &res)) {
+ dnprintf(10, "%s: error reading brightness", DEVNAME(sc));
+ goto err;
+ }
+
+ arg = aml_val2int(&res);
+
+ if (++arg >= 8)
+ arg = 8;
+
+ memset(&res, 0, sizeof(res));
+ res.type = AML_OBJTYPE_INTEGER;
+ res.v_integer = arg;
+
+ if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "SBRT", 1, &res, NULL))
+ printf("error setting brightness to %d\n", arg);
+
+err:
+ aml_freevalue(&res);
+}
+
+
+void
+acpisony_brightness_down(struct acpisony_softc *sc)
+{
+ struct aml_value res;
+ int arg;
+
+ if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "GBRT", 0, NULL, &res)) {
+ dnprintf(10, "%s: error reading brightness", DEVNAME(sc));
+ goto err;
+ }
+
+ arg = aml_val2int(&res);
+
+ if (--arg <= 0)
+ arg = 0;
+
+ memset(&res, 0, sizeof(res));
+ res.type = AML_OBJTYPE_INTEGER;
+ res.v_integer = arg;
+
+ if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "SBRT", 1, &res, NULL))
+ printf("error setting brightness to %d\n", arg);
+
+err:
+ aml_freevalue(&res);
+}
+
+void
+acpisony_quirk_setup(struct acpisony_softc *sc)
+{
+ /* Initialize extra Fn keys */
+ acpisony_eval_set(sc, "SN02", 0x04);
+ acpisony_eval_set(sc, "SN07", 0x02);
+ acpisony_eval_set(sc, "SN02", 0x10);
+ acpisony_eval_set(sc, "SN07", 0x00);
+ acpisony_eval_set(sc, "SN03", 0x02);
+ acpisony_eval_set(sc, "SN07", 0x101);
+}
+
+void
+acpisony_eval_set(struct acpisony_softc *sc, const char *method, int val)
+{
+ struct aml_value res;
+ int arg;
+
+ memset(&res, 0, sizeof(res));
+ res.type = AML_OBJTYPE_INTEGER;
+ res.v_integer = val;
+
+ if (aml_evalname(sc->sc_acpi, sc->sc_devnode, method, 1, &res, NULL))
+ printf("error setting brightness to %d\n", arg);
+
+ aml_freevalue(&res);
+}
diff -ruN sys.orig/dev/acpi/files.acpi sys/dev/acpi/files.acpi
--- sys.orig/dev/acpi/files.acpi Mon Apr 28 13:56:27 2008
+++ sys/dev/acpi/files.acpi Mon Apr 28 17:23:10 2008
@@ -75,3 +75,8 @@
device acpithinkpad
attach acpithinkpad at acpi
file dev/acpi/acpithinkpad.c acpithinkpad
+
+# Sony Vaio support
+device acpisony
+attach acpisony at acpi
+file dev/acpi/acpisony.c acpisony
--
see ya,
giovanni