Skip to content

Commit

Permalink
acpi_ibm: pass brightness events to evdev(4)
Browse files Browse the repository at this point in the history
unless the dev.acpi_ibm.0.handlerevents sysctl is set to process
them internally.  The default for the latter is to ignore them,
so passing to evdev(4) is enabled by default.

Reviewed by:		wulf, imp
Tested on:		Lenovo Thinpad X11 Carbon 7Th Gen
Differential Revision:	https://reviews.freebsd.org/D48174
  • Loading branch information
glebius committed Dec 24, 2024
1 parent 98e34e8 commit c21f575
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
43 changes: 43 additions & 0 deletions sys/dev/acpi_support/acpi_ibm.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
*/

#include "opt_acpi.h"
#include "opt_evdev.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
Expand All @@ -55,6 +56,11 @@
#include <sys/sysctl.h>
#include <isa/rtc.h>

#ifdef EVDEV_SUPPORT
#include <dev/evdev/input.h>
#include <dev/evdev/evdev.h>
#endif

#define _COMPONENT ACPI_OEM
ACPI_MODULE_NAME("IBM")

Expand Down Expand Up @@ -198,6 +204,9 @@ struct acpi_ibm_softc {

struct sysctl_ctx_list *sysctl_ctx;
struct sysctl_oid *sysctl_tree;
#ifdef EVDEV_SUPPORT
struct evdev_dev *evdev;
#endif
};

static struct {
Expand Down Expand Up @@ -363,6 +372,9 @@ static driver_t acpi_ibm_driver = {

DRIVER_MODULE(acpi_ibm, acpi, acpi_ibm_driver, 0, 0);
MODULE_DEPEND(acpi_ibm, acpi, 1, 1, 1);
#ifdef EVDEV_SUPPORT
MODULE_DEPEND(acpi_ibm, evdev, 1, 1, 1);
#endif
static char *ibm_ids[] = {"IBM0068", "LEN0068", "LEN0268", NULL};

static int
Expand Down Expand Up @@ -482,6 +494,20 @@ acpi_ibm_attach(device_t dev)
}
sc->ec_handle = acpi_get_handle(sc->ec_dev);

#ifdef EVDEV_SUPPORT
sc->evdev = evdev_alloc();
evdev_set_name(sc->evdev, device_get_desc(dev));
evdev_set_phys(sc->evdev, device_get_nameunit(dev));
evdev_set_id(sc->evdev, BUS_HOST, 0, 0, 1);
evdev_support_event(sc->evdev, EV_SYN);
evdev_support_event(sc->evdev, EV_KEY);
evdev_support_key(sc->evdev, KEY_BRIGHTNESSUP);
evdev_support_key(sc->evdev, KEY_BRIGHTNESSDOWN);

if (evdev_register(sc->evdev) != 0)
return (ENXIO);
#endif

/* Get the sysctl tree */
sc->sysctl_ctx = device_get_sysctl_ctx(dev);
sc->sysctl_tree = device_get_sysctl_tree(dev);
Expand Down Expand Up @@ -627,6 +653,10 @@ acpi_ibm_detach(device_t dev)
if (sc->led_dev != NULL)
led_destroy(sc->led_dev);

#ifdef EVDEV_SUPPORT
evdev_free(sc->evdev);
#endif

return (0);
}

Expand Down Expand Up @@ -1499,6 +1529,19 @@ acpi_ibm_notify(ACPI_HANDLE h, UINT32 notify, void *context)
/* Execute event handler */
if (sc->handler_events & (1 << (arg - 1)))
acpi_ibm_eventhandler(sc, (arg & 0xff));
#ifdef EVDEV_SUPPORT
else if ((arg & 0xff) == IBM_EVENT_BRIGHTNESS_UP ||
(arg & 0xff) == IBM_EVENT_BRIGHTNESS_DOWN) {
uint16_t key;

key = arg == IBM_EVENT_BRIGHTNESS_UP ?
KEY_BRIGHTNESSUP : KEY_BRIGHTNESSDOWN;
evdev_push_key(sc->evdev, key, 1);
evdev_sync(sc->evdev);
evdev_push_key(sc->evdev, key, 0);
evdev_sync(sc->evdev);
}
#endif

/* Notify devd(8) */
acpi_UserNotify("IBM", h, (arg & 0xff));
Expand Down
2 changes: 1 addition & 1 deletion sys/modules/acpi/acpi_ibm/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PATH: ${SRCTOP}/sys/dev/acpi_support
KMOD= acpi_ibm
SRCS= acpi_ibm.c opt_acpi.h device_if.h bus_if.h acpi_if.h
SRCS+= opt_ddb.h
SRCS+= opt_ddb.h opt_evdev.h

.include <bsd.kmod.mk>

0 comments on commit c21f575

Please sign in to comment.