All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Airlie <airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Subject: [PATCH 2/2] nouveau: add libbacklight and randr property support.
Date: Thu,  6 Jun 2013 11:35:01 +1000	[thread overview]
Message-ID: <1370482501-14023-2-git-send-email-airlied@gmail.com> (raw)
In-Reply-To: <1370482501-14023-1-git-send-email-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

From: Dave Airlie <airlied-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>

This adds support to detect libbacklight and use it to provide the standard
randr backlight properties, for desktops environments to use.

untested as of yet.

Signed-off-by: Dave Airlie <airlied-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
 configure.ac          |  3 +++
 src/Makefile.am       |  4 ++--
 src/drmmode_display.c | 40 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 137de9c..d3e8692 100644
--- a/configure.ac
+++ b/configure.ac
@@ -81,6 +81,9 @@ sdkdir=$(pkg-config --variable=sdkdir xorg-server)
 # Checks for libraries.
 PKG_CHECK_MODULES([PCIACCESS], [pciaccess >= 0.10])
 
+PKG_CHECK_MODULES(LIBBACKLIGHT, [libbacklight], LIBBACKLIGHT="yes"; AC_DEFINE(HAVE_LIBBACKLIGHT, 1, [libbacklight available]), [LIBBACKLIGHT=no])
+AM_CONDITIONAL(LIBBACKLIGHT, [ test "$LIBBACKLIGHT" = "yes" ])
+
 PKG_CHECK_MODULES(LIBUDEV, [libudev], [LIBUDEV=yes], [LIBUDEV=no])
 if test "x$LIBUDEV" = xyes; then
 	AC_DEFINE(HAVE_LIBUDEV, 1, [libudev support])
diff --git a/src/Makefile.am b/src/Makefile.am
index 17c6389..826a3f6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -23,10 +23,10 @@
 # -avoid-version prevents gratuitous .0.0.0 version numbers on the end
 # _ladir passes a dummy rpath to libtool so the thing will actually link
 # TODO: -nostdlib/-Bstatic/-lgcc platform magic, not installing the .a, etc.
-AM_CFLAGS = @XORG_CFLAGS@ @LIBUDEV_CFLAGS@ @LIBDRM_NOUVEAU_CFLAGS@
+AM_CFLAGS = @XORG_CFLAGS@ @LIBUDEV_CFLAGS@ @LIBDRM_NOUVEAU_CFLAGS@ @LIBBACKLIGHT_CFLAGS@
 nouveau_drv_la_LTLIBRARIES = nouveau_drv.la
 nouveau_drv_la_LDFLAGS = -module -avoid-version @LIBDRM_NOUVEAU_LIBS@ \
-			 @LIBUDEV_LIBS@
+			 @LIBUDEV_LIBS@ @LIBBACKLIGHT_LIBS@
 nouveau_drv_ladir = @moduledir@/drivers
 
 nouveau_drv_la_SOURCES = \
diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index ad7bc1f..927dbcf 100644
--- a/src/drmmode_display.c
+++ b/src/drmmode_display.c
@@ -42,6 +42,10 @@
 #include "libudev.h"
 #endif
 
+#ifdef HAVE_LIBBACKLIGHT
+#include "libbacklight.h"
+#endif
+
 static Bool drmmode_xf86crtc_resize(ScrnInfoPtr scrn, int width, int height);
 typedef struct {
     int fd;
@@ -82,6 +86,11 @@ typedef struct {
     drmModePropertyBlobPtr edid_blob;
     int num_props;
     drmmode_prop_ptr props;
+#ifdef HAVE_LIBBACKLIGHT
+    struct backlight *backlight;
+    int backlight_active_level;
+    int backlight_max;
+#endif
 } drmmode_output_private_rec, *drmmode_output_private_ptr;
 
 typedef struct {
@@ -99,6 +108,13 @@ typedef struct {
     Bool dispatch_me;
 } drmmode_flipevtcarrier_rec, *drmmode_flipevtcarrier_ptr;
 
+#ifdef HAVE_LIBBACKLIGHT
+#define BACKLIGHT_NAME             "Backlight"
+#define BACKLIGHT_DEPRECATED_NAME  "BACKLIGHT"
+
+static Atom backlight_atom, backlight_deprecated_atom;
+#endif
+
 static void drmmode_output_dpms(xf86OutputPtr output, int mode);
 
 static drmmode_ptr
@@ -717,6 +733,9 @@ drmmode_output_destroy(xf86OutputPtr output)
 		drmModeFreeProperty(drmmode_output->props[i].mode_prop);
 		free(drmmode_output->props[i].atoms);
 	}
+#ifdef HAVE_LIBBACKLIGHT
+	backlight_destroy(drmmode_output->backlight);
+#endif
 	drmModeFreeConnector(drmmode_output->mode_output);
 	free(drmmode_output);
 	output->driver_private = NULL;
@@ -868,6 +887,27 @@ drmmode_output_create_resources(xf86OutputPtr output)
 			}
 		}
 	}
+
+#ifdef HAVE_LIBBACKLIGHT
+    {
+	NVPtr pNv = NVPTR(output->scrn);
+	struct pci_device *dev = pNv->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);
+	    nouveau_create_ranged_atom(output, &backlight_atom,
+				      BACKLIGHT_NAME, 0, drmmode_output->backlight_max,
+				      drmmode_output->backlight_active_level, FALSE);
+	    nouveau_create_ranged_atom(output, &backlight_deprecated_atom,
+				      BACKLIGHT_DEPRECATED_NAME, 0, drmmode_output->backlight_max,
+				      drmmode_output->backlight_active_level, FALSE);
+	}
+    }
+#endif
 }
 
 static Bool
-- 
1.8.2.1

      parent reply	other threads:[~2013-06-06  1:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-06  1:35 [PATCH 1/2] nouveau/mode: split out create_ranged_atom Dave Airlie
     [not found] ` <1370482501-14023-1-git-send-email-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2013-06-06  1:35   ` Dave Airlie [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1370482501-14023-2-git-send-email-airlied@gmail.com \
    --to=airlied-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.