> Date: Fri, 1 Jul 2016 09:18:41 -0500
> From: joshua stein <[email protected]>
> 
> Small ACPI driver for controlling the keyboard backlight on some
> Chromebooks with wsconsctl.

ok kettenis@

> Index: sys/arch/amd64/conf/GENERIC
> ===================================================================
> RCS file: /cvs/src/sys/arch/amd64/conf/GENERIC,v
> retrieving revision 1.422
> diff -u -p -u -p -r1.422 GENERIC
> --- sys/arch/amd64/conf/GENERIC       28 Jun 2016 04:41:37 -0000      1.422
> +++ sys/arch/amd64/conf/GENERIC       1 Jul 2016 14:17:06 -0000
> @@ -64,6 +64,7 @@ aibs*               at acpi?
>  bytgpio*     at acpi?
>  chvgpio*     at acpi?
>  sdhc*                at acpi?
> +acpicbkbd*   at acpi?
>  
>  mpbios0              at bios0
>  
> Index: sys/dev/acpi/acpicbkbd.c
> ===================================================================
> RCS file: sys/dev/acpi/acpicbkbd.c
> diff -N sys/dev/acpi/acpicbkbd.c
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ sys/dev/acpi/acpicbkbd.c  1 Jul 2016 14:17:06 -0000
> @@ -0,0 +1,140 @@
> +/* $OpenBSD$ */
> +/*
> + * Copyright (c) 2016 joshua stein <[email protected]>
> + *
> + * Permission to use, copy, modify, and/or distribute this software for any
> + * purpose with or without fee is hereby granted, provided that the above
> + * copyright notice and this permission notice appear in all copies.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
> + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
> + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
> + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
> + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
> + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
> + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
> + */
> +
> +#include <sys/param.h>
> +#include <sys/systm.h>
> +
> +#include <dev/acpi/acpivar.h>
> +#include <dev/acpi/amltypes.h>
> +#include <dev/acpi/dsdt.h>
> +
> +#include <dev/wscons/wsconsio.h>
> +
> +#ifdef ACPICBKBD_DEBUG
> +#define DPRINTF(x)   printf x
> +#else
> +#define DPRINTF(x)
> +#endif
> +
> +#define ACPICBKBD_MAX_BACKLIGHT      100
> +
> +struct acpicbkbd_softc {
> +     struct device           sc_dev;
> +     struct acpi_softc       *sc_acpi;
> +     struct aml_node         *sc_devnode;
> +
> +     uint64_t                sc_backlight;
> +};
> +
> +int  acpicbkbd_match(struct device *, void *, void *);
> +void acpicbkbd_attach(struct device *, struct device *, void *);
> +
> +int  acpicbkbd_get_backlight(struct wskbd_backlight *);
> +int  acpicbkbd_set_backlight(struct wskbd_backlight *);
> +void acpicbkbd_write_backlight(void *, int);
> +extern int (*wskbd_get_backlight)(struct wskbd_backlight *);
> +extern int (*wskbd_set_backlight)(struct wskbd_backlight *);
> +
> +struct cfattach acpicbkbd_ca = {
> +     sizeof(struct acpicbkbd_softc), acpicbkbd_match, acpicbkbd_attach
> +};
> +
> +struct cfdriver acpicbkbd_cd = {
> +     NULL, "acpicbkbd", DV_DULL
> +};
> +
> +const char *acpicbkbd_hids[] = {
> +     "GOOG0002",
> +     NULL
> +};
> +
> +int
> +acpicbkbd_match(struct device *parent, void *match, void *aux)
> +{
> +     struct acpi_attach_args *aaa = aux;
> +     struct cfdata *cf = match;
> +
> +     return acpi_matchhids(aaa, acpicbkbd_hids, cf->cf_driver->cd_name);
> +}
> +
> +void
> +acpicbkbd_attach(struct device *parent, struct device *self, void *aux)
> +{
> +     struct acpicbkbd_softc  *sc = (struct acpicbkbd_softc *)self;
> +     struct acpi_attach_args *aa = aux;
> +
> +     sc->sc_acpi = (struct acpi_softc *)parent;
> +     sc->sc_devnode = aa->aaa_node;
> +
> +     printf(": %s", sc->sc_devnode->name);
> +
> +     if (aml_evalinteger(sc->sc_acpi, sc->sc_devnode, "KBQC",
> +         0, NULL, &sc->sc_backlight) == 0) {
> +             wskbd_get_backlight = acpicbkbd_get_backlight;
> +             wskbd_set_backlight = acpicbkbd_set_backlight;
> +     } else
> +             printf(", no backlight control");
> +
> +     printf("\n");
> +}
> +
> +int
> +acpicbkbd_get_backlight(struct wskbd_backlight *kbl)
> +{
> +     struct acpicbkbd_softc *sc = acpicbkbd_cd.cd_devs[0];
> +
> +     KASSERT(sc != NULL);
> +
> +     kbl->min = 0;
> +     kbl->max = ACPICBKBD_MAX_BACKLIGHT;
> +     kbl->curval = sc->sc_backlight;
> +
> +     return 0;
> +}
> +
> +int
> +acpicbkbd_set_backlight(struct wskbd_backlight *kbl)
> +{
> +     struct acpicbkbd_softc *sc = acpicbkbd_cd.cd_devs[0];
> +
> +     KASSERT(sc != NULL);
> +
> +     if (kbl->curval > ACPICBKBD_MAX_BACKLIGHT)
> +             return EINVAL;
> +
> +     sc->sc_backlight = kbl->curval;
> +
> +     acpi_addtask(sc->sc_acpi, acpicbkbd_write_backlight, sc, 0);
> +     acpi_wakeup(sc->sc_acpi);
> +
> +     return 0;
> +}
> +
> +void
> +acpicbkbd_write_backlight(void *arg0, int arg1)
> +{
> +     struct acpicbkbd_softc *sc = arg0;
> +     struct aml_value arg;
> +
> +     DPRINTF(("%s: writing backlight of %lld\n", DEVNAME(sc),
> +         sc->sc_backlight));
> +
> +     memset(&arg, 0, sizeof(arg));
> +     arg.type = AML_OBJTYPE_INTEGER;
> +     arg.v_integer = sc->sc_backlight;
> +     aml_evalname(sc->sc_acpi, sc->sc_devnode, "KBCM", 1, &arg, NULL);
> +}
> Index: sys/dev/acpi/files.acpi
> ===================================================================
> RCS file: /cvs/src/sys/dev/acpi/files.acpi,v
> retrieving revision 1.32
> diff -u -p -u -p -r1.32 files.acpi
> --- sys/dev/acpi/files.acpi   7 May 2016 23:10:50 -0000       1.32
> +++ sys/dev/acpi/files.acpi   1 Jul 2016 14:17:06 -0000
> @@ -130,3 +130,8 @@ file      dev/acpi/sdhc_acpi.c            sdhc_acpi
>  device       dwiic: i2cbus
>  attach       dwiic at acpi
>  file dev/acpi/dwiic.c                dwiic
> +
> +# Chromebook keyboard backlight
> +device       acpicbkbd
> +attach       acpicbkbd at acpi
> +file dev/acpi/acpicbkbd.c            acpicbkbd
> 
> 

Reply via email to