Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/macppc/macppc add support for backlight control wit...



details:   https://anonhg.NetBSD.org/src/rev/68493ad147a0
branches:  trunk
changeset: 757943:68493ad147a0
user:      macallan <macallan%NetBSD.org@localhost>
date:      Wed Oct 06 02:27:25 2010 +0000

description:
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.

diffstat:

 sys/arch/macppc/macppc/machdep.c |  63 ++++++++++++++++++++++++++++++++++++++-
 1 files changed, 60 insertions(+), 3 deletions(-)

diffs (105 lines):

diff -r fd3e280b2789 -r 68493ad147a0 sys/arch/macppc/macppc/machdep.c
--- a/sys/arch/macppc/macppc/machdep.c  Wed Oct 06 02:24:35 2010 +0000
+++ b/sys/arch/macppc/macppc/machdep.c  Wed Oct 06 02:27:25 2010 +0000
@@ -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;
+}



Home | Main Index | Thread Index | Old Index