diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2014-02-20 19:18:46 +0000 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2014-02-20 19:22:03 +0000 |
commit | 0b92b1285ce553c4f475c7fb8ac57ba418009682 (patch) | |
tree | 314dd8365ae578808376249cdbf81c56c004ab62 | |
parent | caaf52834015c084704cf638f453b1fc3316eaa9 (diff) |
backlight: Make search routine for device specific backlight common
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
-rw-r--r-- | src/backlight.c | 38 | ||||
-rw-r--r-- | src/backlight.h | 3 | ||||
-rw-r--r-- | src/sna/sna_display.c | 57 |
3 files changed, 45 insertions, 53 deletions
diff --git a/src/backlight.c b/src/backlight.c index 6b74a21a..d5b10a07 100644 --- a/src/backlight.c +++ b/src/backlight.c @@ -43,6 +43,7 @@ #include <unistd.h> #include <dirent.h> #include <xf86.h> +#include <pciaccess.h> #include "backlight.h" #include "fd.h" @@ -452,3 +453,40 @@ void backlight_close(struct backlight *b) if (b->pid) waitpid(b->pid, NULL, 0); } + +char *backlight_find_for_device(struct pci_device *pci) +{ + char path[200]; + unsigned best_type = INT_MAX; + char *best_iface = NULL; + DIR *dir; + struct dirent *de; + + snprintf(path, sizeof(path), + "/sys/bus/pci/devices/%04x:%02x:%02x.%d/backlight", + pci->domain, pci->bus, pci->dev, pci->func); + + dir = opendir(path); + if (dir == NULL) + return NULL; + + while ((de = readdir(dir))) { + int v; + + if (*de->d_name == '.') + continue; + + v = backlight_exists(de->d_name); + if (v < best_type) { + char *copy = strdup(de->d_name); + if (copy) { + free(best_iface); + best_iface = copy; + best_type = v; + } + } + } + closedir(dir); + + return best_iface; +} diff --git a/src/backlight.h b/src/backlight.h index 6eeaff6f..c251bd92 100644 --- a/src/backlight.h +++ b/src/backlight.h @@ -50,4 +50,7 @@ int backlight_get(struct backlight *backlight); void backlight_disable(struct backlight *backlight); void backlight_close(struct backlight *backlight); +struct pci_device; +char *backlight_find_for_device(struct pci_device *pci); + #endif /* BACKLIGHT_H */ diff --git a/src/sna/sna_display.c b/src/sna/sna_display.c index 0902f804..496a3000 100644 --- a/src/sna/sna_display.c +++ b/src/sna/sna_display.c @@ -35,7 +35,6 @@ #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> -#include <dirent.h> #include <errno.h> #include <poll.h> #include <ctype.h> @@ -349,57 +348,11 @@ has_user_backlight_override(xf86OutputPtr output) return strdup(str); } -static char * -has_device_backlight(xf86OutputPtr output) -{ - struct sna *sna = to_sna(output->scrn); - struct pci_device *pci; - char path[1024]; - unsigned best_type = INT_MAX; - char *best_iface = NULL; - DIR *dir; - struct dirent *de; - - pci = xf86GetPciInfoForEntity(sna->pEnt->index); - if (pci == NULL) - return NULL; - - snprintf(path, sizeof(path), - "/sys/bus/pci/devices/%04x:%02x:%02x.%d/backlight", - pci->domain, pci->bus, pci->dev, pci->func); - - DBG(("%s: scanning %s\n", __FUNCTION__, path)); - dir = opendir(path); - if (dir == NULL) - return NULL; - - while ((de = readdir(dir))) { - int v; - - if (*de->d_name == '.') - continue; - - v = backlight_exists(de->d_name); - DBG(("%s: %s: exists=%d\n", __FUNCTION__, de->d_name, v)); - - if (v < best_type) { - char *copy = strdup(de->d_name); - if (copy) { - free(best_iface); - best_iface = copy; - best_type = v; - } - } - } - closedir(dir); - - return best_iface; -} - static void sna_output_backlight_init(xf86OutputPtr output) { struct sna_output *sna_output = output->driver_private; + struct pci_device *pci; MessageType from; char *best_iface; @@ -410,11 +363,9 @@ sna_output_backlight_init(xf86OutputPtr output) /* XXX detect right backlight for multi-GPU/panels */ from = X_PROBED; - best_iface = has_device_backlight(output); - if (best_iface) - goto done; - - best_iface = NULL; + pci = xf86GetPciInfoForEntity(to_sna(output->scrn)->pEnt->index); + if (pci != NULL) + best_iface = backlight_find_for_device(pci); done: DBG(("%s(%s) opening backlight %s\n", __FUNCTION__, |