2 * Copyright © 2013 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
31 #include "drm_fourcc.h"
34 #include "igt_debugfs.h"
44 struct kmstest_connector_config config;
50 drmModeRes *resources;
53 static void get_crc(char *crc) {
55 FILE *file = fopen("/sys/kernel/debug/dri/0/i915_sink_crc_eDP1", "r");
58 ret = fscanf(file, "%s\n", crc);
64 static uint32_t create_fb(data_t *data,
66 double r, double g, double b,
72 fb_id = igt_create_fb(data->drm_fd, w, h,
73 DRM_FORMAT_XRGB8888, I915_TILING_NONE, fb);
76 cr = igt_get_cairo_ctx(data->drm_fd, fb);
77 igt_paint_color(cr, 0, 0, w, h, r, g, b);
78 igt_assert(cairo_status(cr) == 0);
84 connector_set_mode(data_t *data, connector_t *connector, drmModeModeInfo *mode,
85 enum color crtc_color)
87 struct kmstest_connector_config *config = &connector->config;
91 if (crtc_color == WHITE)
92 fb_id = create_fb(data, mode->hdisplay, mode->vdisplay,
93 1.0, 1.0, 1.0, &connector->fb);
95 fb_id = create_fb(data, mode->hdisplay, mode->vdisplay,
96 0.0, 0.0, 0.0, &connector->fb);
99 ret = drmModeSetCrtc(data->drm_fd,
100 config->crtc->crtc_id,
103 &config->connector->connector_id,
106 igt_assert(ret == 0);
111 static void basic_sink_crc_check(data_t *data, uint32_t connector_id)
113 connector_t connector;
114 char ref_crc_white[12];
115 char ref_crc_black[12];
118 igt_require(kmstest_get_connector_config(data->drm_fd,
124 connector_set_mode(data, &connector, &connector.config.default_mode, WHITE);
126 /* get reference crc for white color */
127 get_crc(ref_crc_white);
130 connector_set_mode(data, &connector, &connector.config.default_mode, BLACK);
132 /* get reference crc for black color */
133 get_crc(ref_crc_black);
135 igt_assert(strcmp(ref_crc_black, ref_crc_white) != 0);
138 connector_set_mode(data, &connector, &connector.config.default_mode, WHITE);
141 igt_assert(strcmp(crc_check, ref_crc_white) == 0);
144 connector_set_mode(data, &connector, &connector.config.default_mode, BLACK);
147 igt_assert(strcmp(crc_check, ref_crc_black) == 0);
149 kmstest_free_connector_config(&connector.config);
152 static void run_test(data_t *data)
155 drmModeConnectorPtr c;
156 uint32_t connector_id = 0;
158 for (i = 0; i < data->resources->count_connectors; i++) {
159 connector_id = data->resources->connectors[i];
160 c = drmModeGetConnector(data->drm_fd, connector_id);
162 if (c->connector_type != DRM_MODE_CONNECTOR_eDP ||
163 c->connection != DRM_MODE_CONNECTED)
166 basic_sink_crc_check(data, connector_id);
170 igt_skip("no eDP with CRC support found\n");
177 igt_skip_on_simulation();
179 data.drm_fd = drm_open_any();
181 kmstest_set_vt_graphics_mode();
183 data.resources = drmModeGetResources(data.drm_fd);
184 igt_assert(data.resources);
188 drmModeFreeResources(data.resources);