summaryrefslogtreecommitdiff
path: root/src/backlight.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2015-06-17 17:55:04 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2015-06-17 17:58:28 +0100
commitb24e7581bd1e5a0215cb73ec87093ebf03c20278 (patch)
tree9e2245cd219cfa3b98f121dbccb87f135eeaba86 /src/backlight.c
parentf1f2e7202854c725293c63293de1552337c717b2 (diff)
backlight: Factor known names into preferred interfaces
Since the /sys/device/backlight never turned up we face an issue with disambiguating the backlight on multi-GPU devices. Both intel_backlight and nv_backlight are presented are raw interfaces, and on modern systems the ACPI interface is defunct, so we need a way to distinguish them. So, we fallback to our priority table of known interfaces and rank them accordingly, first by class (platform, native, raw) and then by priority. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'src/backlight.c')
-rw-r--r--src/backlight.c60
1 files changed, 34 insertions, 26 deletions
diff --git a/src/backlight.c b/src/backlight.c
index c65e466b..d020a7c4 100644
--- a/src/backlight.c
+++ b/src/backlight.c
@@ -152,12 +152,9 @@ int backlight_open(struct backlight *b, char *iface)
return param.curval;
}
-enum backlight_type backlight_exists(const char *iface)
+int backlight_exists(const char *iface)
{
- if (iface != NULL)
- return BL_NONE;
-
- return BL_PLATFORM;
+ return iface == NULL;
}
int backlight_on(struct backlight *b)
@@ -250,10 +247,10 @@ static const char *known_interfaces[] = {
"intel_backlight",
};
-static enum backlight_type __backlight_type(const char *iface)
+static int __backlight_type(const char *iface)
{
char buf[1024];
- int fd, v;
+ int fd, v, i;
v = -1;
fd = __backlight_open(iface, "type", O_RDONLY);
@@ -267,39 +264,41 @@ static enum backlight_type __backlight_type(const char *iface)
buf[v] = '\0';
if (strcmp(buf, "raw") == 0)
- v = BL_RAW;
+ v = BL_RAW << 8;
else if (strcmp(buf, "platform") == 0)
- v = BL_PLATFORM;
+ v = BL_PLATFORM << 8;
else if (strcmp(buf, "firmware") == 0)
- v = BL_FIRMWARE;
+ v = BL_FIRMWARE << 8;
else
- v = BL_NAMED;
+ v = BL_NAMED << 8;
} else
- v = BL_NAMED;
+ v = BL_NAMED << 8;
- if (v == BL_NAMED) {
- int i;
- for (i = 0; i < ARRAY_SIZE(known_interfaces); i++) {
- if (strcmp(iface, known_interfaces[i]) == 0)
- break;
- }
- v += i;
+ for (i = 0; i < ARRAY_SIZE(known_interfaces); i++) {
+ if (strcmp(iface, known_interfaces[i]) == 0)
+ break;
}
+ v += i;
return v;
}
-enum backlight_type backlight_exists(const char *iface)
+static int __backlight_exists(const char *iface)
{
if (__backlight_read(iface, "brightness") < 0)
- return BL_NONE;
+ return -1;
if (__backlight_read(iface, "max_brightness") <= 0)
- return BL_NONE;
+ return -1;
return __backlight_type(iface);
}
+int backlight_exists(const char *iface)
+{
+ return __backlight_exists(iface) != -1;
+}
+
static int __backlight_init(struct backlight *b, char *iface, int fd)
{
b->fd = fd_move_cloexec(fd_set_nonblock(fd));
@@ -405,7 +404,10 @@ __backlight_find(void)
continue;
/* Fallback to priority list of known iface for old kernels */
- v = backlight_exists(de->d_name);
+ v = __backlight_exists(de->d_name);
+ if (v < 0)
+ continue;
+
if (v < best_type) {
char *copy = strdup(de->d_name);
if (copy) {
@@ -422,14 +424,17 @@ __backlight_find(void)
int backlight_open(struct backlight *b, char *iface)
{
- int level;
+ int level, type;
if (iface == NULL)
iface = __backlight_find();
if (iface == NULL)
goto err;
- b->type = __backlight_type(iface);
+ type = __backlight_type(iface);
+ if (type < 0)
+ goto err;
+ b->type = type >> 8;
b->max = __backlight_read(iface, "max_brightness");
if (b->max <= 0)
@@ -549,7 +554,10 @@ char *backlight_find_for_device(struct pci_device *pci)
if (*de->d_name == '.')
continue;
- v = backlight_exists(de->d_name);
+ v = __backlight_exists(de->d_name);
+ if (v < 0)
+ continue;
+
if (v < best_type) {
char *copy = strdup(de->d_name);
if (copy) {