2 * Copyright 2008 Tungsten Graphics
3 * Jakob Bornecrantz <jakob@tungstengraphics.com>
4 * Copyright 2008 Intel Corporation
5 * Jesse Barnes <jesse.barnes@intel.com>
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27 * This fairly simple test program dumps output in a similar format to the
28 * "xrandr" tool everyone knows & loves. It's necessarily slightly different
29 * since the kernel separates outputs into encoder and connector structures,
30 * each with their own unique ID. The program also allows test testing of the
31 * memory management and mode setting APIs by allowing the user to specify a
32 * connector and mode to use for mode setting. If all works as expected, a
33 * blue background should be painted on the monitor attached to the specified
34 * connector after the selected mode is set.
36 * TODO: use cairo to write the mode info on the selected output once
37 * the mode has been programmed, along with possible test patterns.
47 #include "xf86drmMode.h"
56 static const char *util_lookup_type_name(unsigned int type,
57 const struct type_name *table,
62 for (i = 0; i < count; i++)
63 if (table[i].type == type)
69 static const struct type_name encoder_type_names[] = {
70 { DRM_MODE_ENCODER_NONE, "none" },
71 { DRM_MODE_ENCODER_DAC, "DAC" },
72 { DRM_MODE_ENCODER_TMDS, "TMDS" },
73 { DRM_MODE_ENCODER_LVDS, "LVDS" },
74 { DRM_MODE_ENCODER_TVDAC, "TVDAC" },
75 { DRM_MODE_ENCODER_VIRTUAL, "Virtual" },
76 { DRM_MODE_ENCODER_DSI, "DSI" },
77 { DRM_MODE_ENCODER_DPMST, "DPMST" },
78 { DRM_MODE_ENCODER_DPI, "DPI" },
81 const char *util_lookup_encoder_type_name(unsigned int type)
83 return util_lookup_type_name(type, encoder_type_names,
84 ARRAY_SIZE(encoder_type_names));
87 static const struct type_name connector_status_names[] = {
88 { DRM_MODE_CONNECTED, "connected" },
89 { DRM_MODE_DISCONNECTED, "disconnected" },
90 { DRM_MODE_UNKNOWNCONNECTION, "unknown" },
93 const char *util_lookup_connector_status_name(unsigned int status)
95 return util_lookup_type_name(status, connector_status_names,
96 ARRAY_SIZE(connector_status_names));
99 static const struct type_name connector_type_names[] = {
100 { DRM_MODE_CONNECTOR_Unknown, "unknown" },
101 { DRM_MODE_CONNECTOR_VGA, "VGA" },
102 { DRM_MODE_CONNECTOR_DVII, "DVI-I" },
103 { DRM_MODE_CONNECTOR_DVID, "DVI-D" },
104 { DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
105 { DRM_MODE_CONNECTOR_Composite, "composite" },
106 { DRM_MODE_CONNECTOR_SVIDEO, "s-video" },
107 { DRM_MODE_CONNECTOR_LVDS, "LVDS" },
108 { DRM_MODE_CONNECTOR_Component, "component" },
109 { DRM_MODE_CONNECTOR_9PinDIN, "9-pin DIN" },
110 { DRM_MODE_CONNECTOR_DisplayPort, "DP" },
111 { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
112 { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
113 { DRM_MODE_CONNECTOR_TV, "TV" },
114 { DRM_MODE_CONNECTOR_eDP, "eDP" },
115 { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" },
116 { DRM_MODE_CONNECTOR_DSI, "DSI" },
117 { DRM_MODE_CONNECTOR_DPI, "DPI" },
120 const char *util_lookup_connector_type_name(unsigned int type)
122 return util_lookup_type_name(type, connector_type_names,
123 ARRAY_SIZE(connector_type_names));
126 static const char * const modules[] = {
155 int util_open(const char *device, const char *module)
160 fd = drmOpen(module, device);
162 fprintf(stderr, "failed to open device '%s': %s\n",
163 module, strerror(errno));
169 for (i = 0; i < ARRAY_SIZE(modules); i++) {
170 printf("trying to open device '%s'...", modules[i]);
172 fd = drmOpen(modules[i], device);
182 fprintf(stderr, "no device found\n");