summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2014-09-11 08:03:41 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2014-09-11 08:09:39 +0100
commit08921e4bda0114c66270e500090e4cfd29f74d39 (patch)
tree05d2f150742d18f55c974dd6ab13fe1ce34a5a05
parentf2b62ab38f0f5970b2f868e10dc3499ff3118dbb (diff)
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@chris-wilson.co.uk>
-rw-r--r--src/backlight.c50
-rw-r--r--src/backlight.h3
2 files changed, 53 insertions, 0 deletions
diff --git a/src/backlight.c b/src/backlight.c
index 129afea6..4d3c39fd 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 217629dd..bb0e28bc 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);