This repository has been archived by the owner on Jun 15, 2023. It is now read-only.
forked from freebsd/freebsd-src
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
acpi_cros_kblt: New driver for Chromebook keyboard backlight control h…
- Loading branch information
1 parent
b390cbb
commit 083131f
Showing
2 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
/*- | ||
* Copyright (c) 2019 Greg V <greg@unrelenting.technology> | ||
* | ||
* 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. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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/cdefs.h> | ||
__FBSDID("$FreeBSD$"); | ||
|
||
#include "opt_acpi.h" | ||
#include <sys/param.h> | ||
#include <sys/systm.h> | ||
#include <sys/kernel.h> | ||
#include <sys/bus.h> | ||
#include <sys/sysctl.h> | ||
#include <machine/cpufunc.h> | ||
|
||
#include <contrib/dev/acpica/include/acpi.h> | ||
#include <contrib/dev/acpica/include/accommon.h> | ||
|
||
#include "acpi_if.h" | ||
#include <sys/module.h> | ||
#include <dev/acpica/acpivar.h> | ||
|
||
ACPI_MODULE_NAME("CROS_KBLT") | ||
|
||
struct acpi_cros_kblt_softc { | ||
device_t dev; | ||
ACPI_HANDLE handle; | ||
int val; | ||
|
||
struct sysctl_ctx_list *sysctl_ctx; | ||
struct sysctl_oid *sysctl_tree; | ||
}; | ||
|
||
static int | ||
acpi_cros_kblt_sysctl(SYSCTL_HANDLER_ARGS) | ||
{ | ||
struct acpi_cros_kblt_softc *sc = | ||
(struct acpi_cros_kblt_softc*)oidp->oid_arg1; | ||
int err = 0; | ||
|
||
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); | ||
|
||
if (ACPI_FAILURE(acpi_GetInteger(sc->handle, "KBQC", &sc->val))) { | ||
device_printf(sc->dev, "ACPI failure\n"); | ||
return (ENXIO); | ||
} | ||
|
||
err = sysctl_handle_int(oidp, &sc->val, 0, req); | ||
if (err != 0 || req->newptr == NULL) | ||
return (err); | ||
|
||
if (sc->val > 100) | ||
return (EINVAL); | ||
|
||
if (ACPI_FAILURE(acpi_SetInteger(sc->handle, "KBCM", sc->val))) { | ||
device_printf(sc->dev, "ACPI failure\n"); | ||
return (ENXIO); | ||
} | ||
|
||
return (err); | ||
} | ||
|
||
static int | ||
acpi_cros_kblt_resume(device_t dev) | ||
{ | ||
struct acpi_cros_kblt_softc *sc = device_get_softc(dev); | ||
|
||
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); | ||
|
||
if (ACPI_FAILURE(acpi_SetInteger(sc->handle, "KBCM", sc->val))) { | ||
device_printf(sc->dev, "ACPI failure\n"); | ||
return (ENXIO); | ||
} | ||
|
||
return (0); | ||
} | ||
|
||
static char *cros_kblt_ids[] = {"GOOG0002", NULL}; | ||
|
||
static int | ||
acpi_cros_kblt_probe(device_t dev) | ||
{ | ||
int err; | ||
|
||
if (acpi_disabled("cros_kblt") || | ||
device_get_unit(dev) != 0) | ||
return (ENXIO); | ||
|
||
err = ACPI_ID_PROBE(device_get_parent(dev), dev, cros_kblt_ids, NULL); | ||
|
||
if (err <= 0) | ||
device_set_desc(dev, "Google Keyboard Backlight Control"); | ||
|
||
return (err); | ||
} | ||
|
||
static int | ||
acpi_cros_kblt_attach(device_t dev) | ||
{ | ||
struct acpi_cros_kblt_softc *sc; | ||
|
||
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); | ||
|
||
sc = device_get_softc(dev); | ||
sc->dev = dev; | ||
sc->handle = acpi_get_handle(dev); | ||
sc->sysctl_ctx = device_get_sysctl_ctx(dev); | ||
sc->sysctl_tree = device_get_sysctl_tree(dev); | ||
|
||
SYSCTL_ADD_PROC(sc->sysctl_ctx, | ||
SYSCTL_CHILDREN(sc->sysctl_tree), OID_AUTO, | ||
"level", CTLTYPE_INT | CTLFLAG_RW, | ||
sc, 0, acpi_cros_kblt_sysctl, "I", | ||
"Keyboard backlight level (0-100)"); | ||
|
||
return (0); | ||
} | ||
|
||
static device_method_t acpi_cros_kblt_methods[] = { | ||
/* Device interface */ | ||
DEVMETHOD(device_probe, acpi_cros_kblt_probe), | ||
DEVMETHOD(device_attach, acpi_cros_kblt_attach), | ||
DEVMETHOD(device_resume, acpi_cros_kblt_resume), | ||
|
||
DEVMETHOD_END | ||
}; | ||
|
||
static driver_t acpi_cros_kblt_driver = { | ||
"acpi_cros_kblt", | ||
acpi_cros_kblt_methods, | ||
sizeof(struct acpi_cros_kblt_softc), | ||
}; | ||
|
||
static devclass_t acpi_cros_kblt_devclass; | ||
|
||
DRIVER_MODULE(acpi_cros_kblt, acpi, acpi_cros_kblt_driver, | ||
acpi_cros_kblt_devclass, 0, 0); | ||
MODULE_DEPEND(acpi_cros_kblt, acpi, 1, 1, 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# $FreeBSD$ | ||
|
||
.PATH: ${SRCTOP}/sys/dev/acpi_support | ||
KMOD= acpi_cros_kblt | ||
SRCS= acpi_cros_kblt.c opt_acpi.h device_if.h bus_if.h acpi_if.h | ||
|
||
.include <bsd.kmod.mk> |