diff options
author | Tiago Vignatti <tiago.vignatti@intel.com> | 2012-02-14 16:23:22 +0200 |
---|---|---|
committer | Tiago Vignatti <tiago.vignatti@intel.com> | 2012-02-14 18:28:23 +0200 |
commit | a0baaafd556d97ad7e80bd9558352826876e73ae (patch) | |
tree | f566b48467d3ef977147bf984dd5e92028a391ca | |
parent | 64702064524aab7537b1b5dbc34dc6279da0d513 (diff) |
setdpms: add new test for dpms control
alright, it doesn't really depends on libbacklight but it's quite related for
playing around and testing.
Signed-off-by: Tiago Vignatti <tiago.vignatti@intel.com>
-rw-r--r-- | test/Makefile.am | 6 | ||||
-rw-r--r-- | test/setdpms.c | 98 |
2 files changed, 103 insertions, 1 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index 7fbb4a1..f168def 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -21,7 +21,7 @@ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. -noinst_PROGRAMS = setbacklight +noinst_PROGRAMS = setbacklight setdpms AM_CPPFLAGS = -I$(top_srcdir)/include $(DRM_CFLAGS) LDADD = $(top_builddir)/src/libbacklight.la @@ -31,3 +31,7 @@ setbacklight_LDFLAGS = $(DRM_CFLAGS) $(PCIACCESS_CFLAGS) setbacklight_LDADD = $(DRM_LIBS) \ $(PCIACCESS_LIBS) \ $(top_builddir)/src/libbacklight.la + +setdpms_SOURCES = setdpms.c +setdpms_LDFLAGS = $(DRM_CFLAGS) +setdpms_LDADD = $(DRM_LIBS) $(top_builddir)/src/libbacklight.la diff --git a/test/setdpms.c b/test/setdpms.c new file mode 100644 index 0000000..19f658d --- /dev/null +++ b/test/setdpms.c @@ -0,0 +1,98 @@ +/* + * 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 <string.h> + +#include <xf86drm.h> +#include <xf86drmMode.h> + +static void +set_dpms(int fd, drmModeResPtr res, const int dpms) +{ + drmModeConnectorPtr connector; + int i, j; + + for (i = 0; i < res->count_connectors; i++) { + connector = drmModeGetConnector(fd, res->connectors[i]); + + if (!connector) + continue; + + if (connector->connection == DRM_MODE_DISCONNECTED) + continue; + + for (j = 0; j < connector->count_props; j++) { + drmModePropertyPtr props; + props = drmModeGetProperty(fd, connector->props[j]); + if (!props) + continue; + + if (!strcmp(props->name, "DPMS")) { + drmModeConnectorSetProperty(fd, + connector->connector_id, + props->prop_id, + dpms); + } + drmModeFreeProperty(props); + } + drmModeFreeConnector(connector); + } +} + +int +main(int argc, char **argv) +{ + int fd, dpms; + drmModeResPtr res; + const char *module_name = "i915"; + + if (argc < 2) { + printf("Please add argument 0 or 1 for DPMS on/off\n"); + return 1; + } + + dpms = atoi(argv[1]); + if (dpms != 0 && dpms != 1) { + printf("Please add argument 0 or 1 for DPMS on/off\n"); + return 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; + } + + set_dpms(fd, res, dpms); + + return 0; +} |