summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/libbacklight.c65
2 files changed, 30 insertions, 37 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index bebc103..96e1727 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -3,4 +3,4 @@ AM_CPPFLAGS = -I$(top_srcdir)/include
lib_LTLIBRARIES = libbacklight.la
libbacklight_la_SOURCES = libbacklight.c libbacklight.h
libbacklight_la_LDFLAGS = -version-number 0:0:1
-libatasmart_la_CFLAGS = $(PCIACCESS_CFLAGS)
+libbacklight_la_CFLAGS = $(UDEV_CFLAGS)
diff --git a/src/libbacklight.c b/src/libbacklight.c
index fa78be2..b2e19bf 100644
--- a/src/libbacklight.c
+++ b/src/libbacklight.c
@@ -1,6 +1,7 @@
/*
* libbacklight - userspace interface to Linux backlight control
*
+ * Copyright © 2012 Intel Corporation
* Copyright 2010 Red Hat <mjg@redhat.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -25,22 +26,19 @@
*
* Authors:
* Matthew Garrett <mjg@redhat.com>
+ * Tiago Vignatti <vignatti@freedesktop.org>
*/
#define _GNU_SOURCE
#include <libbacklight.h>
#include <stdio.h>
-#include <sys/types.h>
#include <linux/types.h>
#include <dirent.h>
-#include <sys/stat.h>
#include <drm/drm_mode.h>
#include <fcntl.h>
#include <malloc.h>
#include <string.h>
-#include <unistd.h>
-#include <stdlib.h>
#include <errno.h>
static const char *output_names[] = { "Unknown",
@@ -159,42 +157,49 @@ void backlight_destroy(struct backlight *backlight)
free(backlight);
}
-struct backlight *backlight_init(struct pci_device *dev, int card,
- int connector_type, int connector_type_id)
+struct backlight *backlight_init(struct udev_device *drm_device,
+ uint32_t connector_type)
{
+ const char *syspath = NULL;
char *pci_name = NULL;
- char *drm_name = NULL;
char *chosen_path = NULL;
+ char *path = NULL;
DIR *backlights;
struct dirent *entry;
enum backlight_type type = 0;
char buffer[100];
struct backlight *backlight;
- int err;
+ int err, ret;
- if (dev) {
- err = asprintf(&pci_name, "%04x:%02x:%02x.%d", dev->domain,
- dev->bus, dev->dev, dev->func);
- if (err < 0)
- return NULL;
- }
+ if (!drm_device)
+ return NULL;
- if (card) {
- err = asprintf(&drm_name, "card%d-%s-%d", card,
- output_names[connector_type], connector_type_id);
- if (err < 0)
- return NULL;
- }
+ syspath = udev_device_get_syspath(drm_device);
+ if (!syspath)
+ return NULL;
- backlights = opendir("/sys/class/backlight");
+ if (asprintf(&path, "%s/%s", syspath, "device") < 0)
+ return NULL;
+ ret = readlink(path, buffer, sizeof(buffer));
+ free(path);
+ if (ret < 0)
+ return NULL;
+
+ buffer[ret] = '\0';
+ pci_name = basename(buffer);
+
+ if (connector_type <= 0)
+ return NULL;
+
+ backlights = opendir("/sys/class/backlight");
if (!backlights)
return NULL;
/* Find the "best" backlight for the device. Firmware
interfaces are preferred over platform interfaces are
preferred over raw interfaces. For raw interfaces we'll
- match if either the pci ID or the output ID match, while
+ check if the device ID in the form of pci match, while
for firmware interfaces we require the pci ID to
match. It's assumed that platform interfaces always match,
since we can't actually associate them with IDs.
@@ -210,9 +215,8 @@ struct backlight *backlight_init(struct pci_device *dev, int card,
while ((entry = readdir(backlights))) {
char *backlight_path;
char *parent;
- char *path;
enum backlight_type entry_type;
- int fd, ret;
+ int fd;
if (entry->d_name[0] == '.')
continue;
@@ -272,8 +276,7 @@ struct backlight *backlight_init(struct pci_device *dev, int card,
platform backlights have to be assumed to match */
if (entry_type == BACKLIGHT_RAW ||
entry_type == BACKLIGHT_FIRMWARE) {
- if (!((drm_name && !strcmp(drm_name, parent)) ||
- (pci_name && !strcmp(pci_name, parent))))
+ if (!(pci_name && !strcmp(pci_name, parent)))
goto out;
}
@@ -310,18 +313,8 @@ struct backlight *backlight_init(struct pci_device *dev, int card,
if (backlight->brightness < 0)
goto err;
- if (pci_name)
- free(pci_name);
-
- if (drm_name)
- free(drm_name);
-
return backlight;
err:
- if (pci_name)
- free(pci_name);
- if (drm_name)
- free(drm_name);
if (chosen_path)
free(chosen_path);
free (backlight);