xf86-video-intel: 2 commits - src/backlight.c src/backlight.h src/sna/sna_display.c

Chris Wilson ickle at kemper.freedesktop.org
Thu Sep 11 01:05:26 PDT 2014


 src/backlight.c       |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/backlight.h       |    3 +++
 src/sna/sna_display.c |   30 +++++++++++++++++++++++++++---
 3 files changed, 80 insertions(+), 3 deletions(-)

New commits:
commit fda1ffb07e17469771bba7a8d53fd44c43ee3333
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Sep 11 08:11:34 2014 +0100

    sna: Request the backlight to be disabled along with DPMS off
    
    When we turn off the screen, either at the user request or when
    disabling an output, request that the associated backlight (which may
    only be known to userspace) also be disabled.
    
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/src/sna/sna_display.c b/src/sna/sna_display.c
index 6e80d1b..f136c20 100644
--- a/src/sna/sna_display.c
+++ b/src/sna/sna_display.c
@@ -624,6 +624,31 @@ sna_output_backlight_set(struct sna_output *sna_output, int level)
 	return ret;
 }
 
+static void
+sna_output_backlight_off(struct sna_output *sna_output)
+{
+	DBG(("%s(%s)\n", __FUNCTION__, output->name));
+	backlight_off(&sna_output->backlight);
+	sna_output_backlight_set(sna_output, 0);
+}
+
+static void
+sna_output_backlight_on(struct sna_output *sna_output)
+{
+	DBG(("%s(%s)\n", __FUNCTION__, output->name));
+	sna_output_backlight_set(sna_output,
+				 sna_output->backlight_active_level);
+	if (backlight_on(&sna_output->backlight) < 0) {
+		xf86OutputPtr output = sna_output->base;
+
+		backlight_disable(&sna_output->backlight);
+		if (output->randr_output) {
+			RRDeleteOutputProperty(output->randr_output, backlight_atom);
+			RRDeleteOutputProperty(output->randr_output, backlight_deprecated_atom);
+		}
+	}
+}
+
 static int
 sna_output_backlight_get(xf86OutputPtr output)
 {
@@ -3001,7 +3026,7 @@ sna_output_dpms(xf86OutputPtr output, int dpms)
 			     __FUNCTION__, sna_output->backlight_active_level));
 		}
 		sna_output->dpms_mode = dpms;
-		sna_output_backlight_set(sna_output, 0);
+		sna_output_backlight_off(sna_output);
 	}
 
 	if (output->crtc &&
@@ -3014,8 +3039,7 @@ sna_output_dpms(xf86OutputPtr output, int dpms)
 	if (sna_output->backlight.iface && dpms == DPMSModeOn) {
 		DBG(("%s: restoring previous backlight %d\n",
 		     __FUNCTION__, sna_output->backlight_active_level));
-		sna_output_backlight_set(sna_output,
-					 sna_output->backlight_active_level);
+		sna_output_backlight_on(sna_output);
 	}
 
 	sna_output->dpms_mode = dpms;
commit 08921e4bda0114c66270e500090e4cfd29f74d39
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Sep 11 08:03:41 2014 +0100

    backlight: Expose interface to switch backlight on/off entirely
    
    A feature in recent kernels is to disambiguate between the meaning of
    brightness=0, between disabling the the backlight entirely or setting
    the lowest valid brightness. As such, we now have an extra knob in sysfs
    to explicitly request that the backlight be turned off.
    
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/src/backlight.c b/src/backlight.c
index 129afea..4d3c39f 100644
--- a/src/backlight.c
+++ b/src/backlight.c
@@ -81,6 +81,7 @@ void backlight_init(struct backlight *b)
 	b->fd = -1;
 	b->pid = -1;
 	b->max = -1;
+	b->has_power = 0;
 }
 
 #ifdef __OpenBSD__
@@ -153,6 +154,15 @@ enum backlight_type backlight_exists(const char *iface)
 	return BL_PLATFORM;
 }
 
+int backlight_on(struct backlight *b)
+{
+	return 0;
+}
+
+int backlight_off(struct backlight *b)
+{
+	return 0;
+}
 #else
 
 static int
@@ -202,6 +212,21 @@ __backlight_read(const char *iface, const char *file)
 	return val;
 }
 
+static int
+__backlight_write(const char *iface, const char *file, const char *value)
+{
+	int fd, ret;
+
+	fd = __backlight_open(iface, file, O_RDONLY);
+	if (fd < 0)
+		return -1;
+
+	ret = write(fd, value, strlen(value)+1);
+	close(fd);
+
+	return ret;
+}
+
 /* List of available kernel interfaces in priority order */
 static const char *known_interfaces[] = {
 	"dell_backlight",
@@ -284,6 +309,9 @@ static int __backlight_direct_init(struct backlight *b, char *iface)
 	if (fd < 0)
 		return 0;
 
+	if (__backlight_read(iface, "bl_power") != -1)
+		b->has_power = 1;
+
 	return __backlight_init(b, iface, fd);
 }
 
@@ -448,6 +476,28 @@ int backlight_get(struct backlight *b)
 		level = -1;
 	return level;
 }
+
+int backlight_off(struct backlight *b)
+{
+	if (b->iface == NULL)
+		return 0;
+
+	if (!b->has_power)
+		return 0;
+
+	return __backlight_write(b->iface, "bl_power", "0");
+}
+
+int backlight_on(struct backlight *b)
+{
+	if (b->iface == NULL)
+		return 0;
+
+	if (!b->has_power)
+		return 0;
+
+	return __backlight_write(b->iface, "bl_power", "1");
+}
 #endif
 
 void backlight_disable(struct backlight *b)
diff --git a/src/backlight.h b/src/backlight.h
index 217629d..bb0e28b 100644
--- a/src/backlight.h
+++ b/src/backlight.h
@@ -39,6 +39,7 @@ struct backlight {
 	char *iface;
 	enum backlight_type type;
 	int max;
+	int has_power;
 	int pid, fd;
 };
 
@@ -48,6 +49,8 @@ void backlight_init(struct backlight *backlight);
 int backlight_open(struct backlight *backlight, char *iface);
 int backlight_set(struct backlight *backlight, int level);
 int backlight_get(struct backlight *backlight);
+int backlight_on(struct backlight *b);
+int backlight_off(struct backlight *b);
 void backlight_disable(struct backlight *backlight);
 void backlight_close(struct backlight *backlight);
 


More information about the xorg-commit mailing list