--- src/rhd_acpi.c.orig 2009-10-06 07:36:07.000000000 -0400 +++ src/rhd_acpi.c 2009-10-27 02:44:10.000000000 -0400 @@ -47,6 +47,54 @@ #include "rhd_acpi.h" +#if defined(__FreeBSD__) + +#include +#include + +/* + * Get/Set LCD backlight brightness via acpi_video(4). + */ +static Bool +rhdDoBacklight(struct rhdOutput *Output, Bool do_write, int *val) +{ + int *levels; + size_t len; + int level, num_levels; + RHDFUNC(Output); + + if (sysctlbyname("hw.acpi.video.lcd0.levels", NULL, &len, NULL, 0) != 0 || len == 0) + return FALSE; + + if (do_write) { + levels = (int *)malloc(len); + if (levels == NULL) + return FALSE; + if (sysctlbyname("hw.acpi.video.lcd0.levels", levels, &len, NULL, 0) != 0) { + free(levels); + return FALSE; + } + num_levels = len / sizeof(*levels); + for (level = 0; level < num_levels; level++) + if (levels[level] == *val) + break; + free(levels); + if (level >= num_levels) + return FALSE; + if (sysctlbyname("hw.acpi.video.lcd0.brightness", NULL, 0, val, sizeof(*val)) != 0) + return FALSE; + RHDDebug(Output->scrnIndex,"%s: Set brightness value %i\n", __func__, *val); + } else { + if (sysctlbyname("hw.acpi.video.lcd0.brightness", val, &len, NULL, 0) != 0) + return FALSE; + RHDDebug(Output->scrnIndex,"%s: Get brightness value %i\n", __func__, *val); + } + + return TRUE; +} + +#elif defined(__linux__) + #define ACPI_PATH "/sys/class/backlight" /* @@ -120,6 +168,7 @@ return FALSE; } +#endif /* * RhdACPIGetBacklightControl(): return backlight value in range 0..255; @@ -128,7 +177,7 @@ int RhdACPIGetBacklightControl(struct rhdOutput *Output) { -#ifdef __linux__ +#if defined(__FreeBSD__) || defined(__linux__) int ret; RHDFUNC(Output); if (rhdDoBacklight(Output, FALSE, &ret)) @@ -144,7 +193,7 @@ RhdACPISetBacklightControl(struct rhdOutput *Output, int val) { RHDFUNC(Output); -#ifdef __linux__ +#if defined(__FreeBSD__) || defined(__linux__) rhdDoBacklight(Output, TRUE, &val); #endif }