Module Name: src Committed By: macallan Date: Wed Oct 6 02:27:25 UTC 2010
Modified Files: src/sys/arch/macppc/macppc: machdep.c Log Message: add support for backlight control with genfb via OF Tested on a PowerBook Pismo only so far, it should work on all OF3 *Books though. Support for older PowerBooks is trickier since they control their backlight using PMU commands which have no OF equivalent. To generate a diff of this commit: cvs rdiff -u -r1.153 -r1.154 src/sys/arch/macppc/macppc/machdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/macppc/macppc/machdep.c diff -u src/sys/arch/macppc/macppc/machdep.c:1.153 src/sys/arch/macppc/macppc/machdep.c:1.154 --- src/sys/arch/macppc/macppc/machdep.c:1.153 Fri Nov 27 03:23:11 2009 +++ src/sys/arch/macppc/macppc/machdep.c Wed Oct 6 02:27:25 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.153 2009/11/27 03:23:11 rmind Exp $ */ +/* $NetBSD: machdep.c,v 1.154 2010/10/06 02:27:25 macallan Exp $ */ /* * Copyright (C) 1995, 1996 Wolfgang Solfrank. @@ -32,7 +32,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.153 2009/11/27 03:23:11 rmind Exp $"); +__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.154 2010/10/06 02:27:25 macallan Exp $"); #include "opt_compat_netbsd.h" #include "opt_ddb.h" @@ -107,9 +107,18 @@ #endif struct genfb_colormap_callback gfb_cb; +struct genfb_parameter_callback gpc; + +/* + * this is bogus - we need to read the actual default from the PMU and then + * put it here + */ +int backlight_level = 200; static void of_set_palette(void *, int, int, int, int); static void add_model_specifics(prop_dictionary_t); +static void of_set_backlight(void *, int); +static int of_get_backlight(void *); void initppc(u_int startkernel, u_int endkernel, char *args) @@ -258,7 +267,8 @@ copy_disp_props(struct device *dev, int node, prop_dictionary_t dict) { uint32_t temp; - uint64_t cmap_cb; + uint64_t cmap_cb, backlight_cb; + int have_backlight = 0; if (node != console_node) { /* @@ -319,6 +329,30 @@ gfb_cb.gcc_set_mapreg = of_set_palette; cmap_cb = (uint64_t)&gfb_cb; prop_dictionary_set_uint64(dict, "cmap_callback", cmap_cb); + + /* not let's look for backlight control */ + have_backlight = 0; + if (OF_getprop(node, "backlight-control", &temp, sizeof(temp)) == 4) { + have_backlight = 1; + } else if (OF_getprop(OF_parent(node), "backlight-control", &temp, + sizeof(temp)) == 4) { + have_backlight = 1; + } + if (have_backlight) { + gpc.gpc_cookie = (void *)console_instance; + gpc.gpc_set_parameter = of_set_backlight; + gpc.gpc_get_parameter = of_get_backlight; + backlight_cb = (uint64_t)&gpc; + prop_dictionary_set_uint64(dict, "backlight_callback", + backlight_cb); + /* + * since we don't know how to read the backlight level without + * access to the PMU we just set it to the default defined + * above so the hotkeys work as expected + */ + OF_call_method_1("set-contrast", console_instance, 1, + backlight_level); + } } static void @@ -342,3 +376,26 @@ OF_call_method_1("color!", ih, 4, r, g, b, index); } + +static void +of_set_backlight(void *cookie, int level) +{ + int ih = (int)cookie; + + if (level < 0) level = 0; + if (level > 255) level = 255; + backlight_level = level; + OF_call_method_1("set-contrast", ih, 1, level); +} + +static int +of_get_backlight(void *cookie) +{ + + /* + * we don't know how to read the backlight level from OF alone - we + * should read the default from the PMU and then just cache whatever + * we set last + */ + return backlight_level; +}