summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/backlight.c60
-rw-r--r--src/backlight.h2
-rw-r--r--src/sna/sna_display.c2
-rw-r--r--src/uxa/intel_display.c2
4 files changed, 37 insertions, 29 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) {
diff --git a/src/backlight.h b/src/backlight.h
index bb0e28bc..ba17755b 100644
--- a/src/backlight.h
+++ b/src/backlight.h
@@ -43,7 +43,7 @@ struct backlight {
int pid, fd;
};
-enum backlight_type backlight_exists(const char *iface);
+int backlight_exists(const char *iface);
void backlight_init(struct backlight *backlight);
int backlight_open(struct backlight *backlight, char *iface);
diff --git a/src/sna/sna_display.c b/src/sna/sna_display.c
index efc5fc9f..53eb9ca5 100644
--- a/src/sna/sna_display.c
+++ b/src/sna/sna_display.c
@@ -767,7 +767,7 @@ has_user_backlight_override(xf86OutputPtr output)
if (*str == '\0')
return (char *)str;
- if (backlight_exists(str) == BL_NONE) {
+ if (!backlight_exists(str)) {
xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
"Unrecognised backlight control interface '%s'\n",
str);
diff --git a/src/uxa/intel_display.c b/src/uxa/intel_display.c
index 0cdc8d26..8bf0184d 100644
--- a/src/uxa/intel_display.c
+++ b/src/uxa/intel_display.c
@@ -192,7 +192,7 @@ intel_output_backlight_init(xf86OutputPtr output)
str = xf86GetOptValString(intel->Options, OPTION_BACKLIGHT);
if (str != NULL) {
- if (backlight_exists(str) != BL_NONE) {
+ if (backlight_exists(str)) {
intel_output->backlight_active_level =
backlight_open(&intel_output->backlight,
strdup(str));