diff options
author | Tiago Vignatti <tiago.vignatti@intel.com> | 2012-02-14 15:42:21 +0200 |
---|---|---|
committer | Tiago Vignatti <tiago.vignatti@intel.com> | 2012-02-14 18:28:19 +0200 |
commit | 64702064524aab7537b1b5dbc34dc6279da0d513 (patch) | |
tree | ab440d99831539d47c85de60b4b0f3da799582ea | |
parent | 6c02975a650883250ce505f310685f74f7d4ccd6 (diff) |
setbacklight: add new test for backlight control
Signed-off-by: Tiago Vignatti <tiago.vignatti@intel.com>
-rw-r--r-- | Makefile.am | 12 | ||||
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | test/Makefile.am | 6 | ||||
-rw-r--r-- | test/setbacklight.c | 105 |
4 files changed, 111 insertions, 13 deletions
diff --git a/Makefile.am b/Makefile.am index 7390993..d85c470 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,15 +2,3 @@ SUBDIRS = include src test pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = libbacklight.pc - -MAINTAINERCLEANFILES = ChangeLog INSTALL - -.PHONY: ChangeLog INSTALL - -INSTALL: - $(INSTALL_CMD) - -ChangeLog: - $(CHANGELOG_CMD) - -dist-hook: ChangeLog INSTALL diff --git a/configure.ac b/configure.ac index a137bfd..f1d0838 100644 --- a/configure.ac +++ b/configure.ac @@ -10,6 +10,7 @@ AM_SILENT_RULES([yes]) AC_PROG_CC AC_PROG_LIBTOOL +PKG_CHECK_MODULES([DRM], [libdrm]) PKG_CHECK_MODULES([PCIACCESS], [pciaccess >= 0.10.0]) AC_CONFIG_FILES([Makefile include/Makefile diff --git a/test/Makefile.am b/test/Makefile.am index 200aec6..7fbb4a1 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -23,7 +23,11 @@ noinst_PROGRAMS = setbacklight -AM_CPPFLAGS = -I$(top_srcdir)/include +AM_CPPFLAGS = -I$(top_srcdir)/include $(DRM_CFLAGS) LDADD = $(top_builddir)/src/libbacklight.la setbacklight_SOURCES = setbacklight.c +setbacklight_LDFLAGS = $(DRM_CFLAGS) $(PCIACCESS_CFLAGS) +setbacklight_LDADD = $(DRM_LIBS) \ + $(PCIACCESS_LIBS) \ + $(top_builddir)/src/libbacklight.la diff --git a/test/setbacklight.c b/test/setbacklight.c index 021d7bf..657908c 100644 --- a/test/setbacklight.c +++ b/test/setbacklight.c @@ -1,9 +1,114 @@ +/* + * Copyright © 2012 Intel Corporation + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the copyright holders not be used in + * advertising or publicity pertaining to distribution of the software + * without specific, written prior permission. The copyright holders make + * no representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: Tiago Vignatti + */ + #include <stdio.h> +#include <xf86drm.h> +#include <xf86drmMode.h> #include "libbacklight.h" +static void +set_backlight(int fd, drmModeResPtr res, struct pci_device * dev, int blight) +{ + drmModeConnectorPtr connector; + int i; + long max_brightness, brightness, actual_brightness; + + struct backlight *backlight; + + for (i = 0; i < res->count_connectors; i++) { + connector = drmModeGetConnector(fd, res->connectors[i]); + + if (!connector) + continue; + + if (connector->connection == DRM_MODE_DISCONNECTED) + continue; + backlight = backlight_init(dev, + 0, + connector->connector_type, + connector->connector_type_id); + drmModeFreeConnector(connector); + } + + if (!backlight) { + printf("backlight adjust failed\n"); + return; + } + + max_brightness = backlight_get_max_brightness(backlight); + printf("Max backlight: %ld\n", max_brightness); + + brightness = backlight_get_brightness(backlight); + printf("Cached backlight: %ld\n", brightness); + + actual_brightness = backlight_get_actual_brightness(backlight); + printf("Hardware backlight: %ld\n", actual_brightness); + + backlight_set_brightness(backlight, blight); + printf("Setting brightness to: %d\n", blight); + + backlight_destroy(backlight); +} + int main(int argc, char **argv) { + int fd, blight; + drmModeResPtr res; + const char *module_name = "i915"; + struct pci_id_match dev_match = { + PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, + (0x03 << 16), 0xff000, 0 }; + struct pci_device_iterator * iter; + struct pci_device * dev; + + if (argc < 2) { + printf("Please add a brightness value\n"); + return 1; + } + + blight = atoi(argv[1]); + + fd = drmOpen(module_name, NULL); + if (fd < 0) { + printf("Failed to open the card fd (%d)\n",fd); + return 1; + } + + res = drmModeGetResources(fd); + if (res == 0) { + printf("Failed to get resources from card\n"); + drmClose(fd); + return 1; + } + + pci_system_init(); + iter = pci_id_match_iterator_create(&dev_match); + + while ((dev = pci_device_next(iter)) != NULL) + set_backlight(fd, res, dev, blight); + return 0; } |