[PATCH 2/2] radeon: add libbacklight support.

Dave Airlie airlied at gmail.com
Wed Jun 5 18:08:55 PDT 2013


From: Dave Airlie <airlied at redhat.com>

This adds randr BACKLIGHT and Backlight properties using libbacklight
as the backend.

Signed-off-by: Dave Airlie <airlied at redhat.com>
---
 configure.ac          |  3 +++
 src/Makefile.am       |  7 ++++++-
 src/drmmode_display.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 src/drmmode_display.h |  9 +++++++++
 4 files changed, 65 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index b4f1d4c..b47f0b7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -81,6 +81,9 @@ PKG_CHECK_MODULES(XEXT, [xextproto >= 7.0.99.1],
                   HAVE_XEXTPROTO_71="no")
 AM_CONDITIONAL(HAVE_XEXTPROTO_71, [ test "$HAVE_XEXTPROTO_71" = "yes" ])
 
+PKG_CHECK_MODULES(LIBBACKLIGHT, [libbacklight], LIBBACKLIGHT="yes"; AC_DEFINE(HAVE_LIBBACKLIGHT, 1, [libbacklight available]), [LIBBACKLIGHT=no])
+AM_CONDITIONAL(LIBBACKLIGHT, [ test "$LIBBACKLIGHT" = "yes" ])
+
 AC_ARG_ENABLE([udev],
 		AS_HELP_STRING([--disable-udev], [Disable libudev support [default=auto]]),
 		[enable_udev="$enableval"],
diff --git a/src/Makefile.am b/src/Makefile.am
index 6b7171e..e777267 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -38,12 +38,17 @@ RADEON_EXA_SOURCES = radeon_exa.c r600_exa.c r6xx_accel.c r600_textured_videofun
 AM_CFLAGS = \
             @LIBDRM_RADEON_CFLAGS@ \
             @XORG_CFLAGS@ \
-            @LIBUDEV_CFLAGS@
+            @LIBUDEV_CFLAGS@ \
+	    @LIBBACKLIGHT_CFLAGS@
 
 if LIBUDEV
 radeon_drv_la_LIBADD += $(LIBUDEV_LIBS)
 endif
 
+if LIBBACKLIGHT
+radeon_drv_la_LIBADD += $(LIBBACKLIGHT_LIBS)
+endif
+
 ati_drv_la_LTLIBRARIES = ati_drv.la
 ati_drv_la_LDFLAGS = -module -avoid-version
 ati_drv_ladir = @moduledir@/drivers
diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index 6874ede..629b6c3 100644
--- a/src/drmmode_display.c
+++ b/src/drmmode_display.c
@@ -50,6 +50,12 @@
 #endif
 
 #define DEFAULT_NOMINAL_FRAME_RATE 60
+#ifdef HAVE_LIBBACKLIGHT
+#define BACKLIGHT_NAME             "Backlight"
+#define BACKLIGHT_DEPRECATED_NAME  "BACKLIGHT"
+
+static Atom backlight_atom, backlight_deprecated_atom;
+#endif
 
 static Bool
 RADEONZaphodStringMatches(ScrnInfoPtr pScrn, const char *s, char *output_name)
@@ -876,6 +882,10 @@ drmmode_output_destroy(xf86OutputPtr output)
 		drmModeFreeEncoder(drmmode_output->mode_encoders[i]);
 		free(drmmode_output->mode_encoders);
 	}
+#ifdef HAVE_LIBBACKLIGHT
+	backlight_destroy(drmmode_output->backlight);
+#endif
+
 	free(drmmode_output->props);
 	drmModeFreeConnector(drmmode_output->mode_output);
 	free(drmmode_output);
@@ -1010,6 +1020,27 @@ drmmode_output_create_resources(xf86OutputPtr output)
 	    }
 	}
     }
+
+#ifdef HAVE_LIBBACKLIGHT
+    {
+	RADEONInfoPtr  info   = RADEONPTR(output->scrn);
+	struct pci_device *dev = info->PciInfo;
+
+	drmmode_output->backlight = backlight_init(dev, 0, mode_output->connector_type,
+					mode_output->connector_type_id);
+
+	if (drmmode_output->backlight) {
+	    drmmode_output->backlight_max = backlight_get_max_brightness(drmmode_output->backlight);
+	    drmmode_output->backlight_active_level = backlight_get_brightness(drmmode_output->backlight);
+	    radeon_create_ranged_atom(output, &backlight_atom,
+				      BACKLIGHT_NAME, 0, drmmode_output->backlight_max,
+				      drmmode_output->backlight_active_level, FALSE);
+	    radeon_create_ranged_atom(output, &backlight_deprecated_atom,
+				      BACKLIGHT_DEPRECATED_NAME, 0, drmmode_output->backlight_max,
+				      drmmode_output->backlight_active_level, FALSE);
+	}
+    }
+#endif
 }
 
 static Bool
@@ -1020,6 +1051,22 @@ drmmode_output_set_property(xf86OutputPtr output, Atom property,
     drmmode_ptr drmmode = drmmode_output->drmmode;
     int i;
 
+#ifdef HAVE_LIBBACKLIGHT
+    if (property == backlight_atom || property == backlight_deprecated_atom) {
+	INT32 val;
+
+	if (value->type != XA_INTEGER || value->format != 32 ||
+	    value->size != 1)
+	    return FALSE;
+
+	val = *(INT32 *)value->data;
+	if (val < 0 || val > drmmode_output->backlight_max)
+	    return FALSE;
+
+	backlight_set_brightness(drmmode_output->backlight, val);
+    }
+
+#endif
     for (i = 0; i < drmmode_output->num_props; i++) {
 	drmmode_prop_ptr p = &drmmode_output->props[i];
 
diff --git a/src/drmmode_display.h b/src/drmmode_display.h
index 2fccfda..3d24cf1 100644
--- a/src/drmmode_display.h
+++ b/src/drmmode_display.h
@@ -32,6 +32,10 @@
 #include "libudev.h"
 #endif
 
+#ifdef HAVE_LIBBACKLIGHT
+#include "libbacklight.h"
+#endif
+
 #include "radeon_probe.h"
 
 #ifndef DRM_CAP_TIMESTAMP_MONOTONIC
@@ -102,6 +106,11 @@ typedef struct {
     drmmode_prop_ptr props;
     int enc_mask;
     int enc_clone_mask;
+#ifdef HAVE_LIBBACKLIGHT
+    struct backlight *backlight;
+    int backlight_active_level;
+    int backlight_max;
+#endif
 } drmmode_output_private_rec, *drmmode_output_private_ptr;
 
 
-- 
1.8.2.1



More information about the xorg-driver-ati mailing list