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, false, 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;
115 char ref_crc_white[12];
116 char ref_crc_black[12];
119 ret = kmstest_get_connector_config(data->drm_fd,
123 igt_require(ret == 0);
126 connector_set_mode(data, &connector, &connector.config.default_mode, WHITE);
128 /* get reference crc for white color */
129 get_crc(ref_crc_white);
132 connector_set_mode(data, &connector, &connector.config.default_mode, BLACK);
134 /* get reference crc for black color */
135 get_crc(ref_crc_black);
137 igt_assert(strcmp(ref_crc_black, ref_crc_white) != 0);
140 connector_set_mode(data, &connector, &connector.config.default_mode, WHITE);
143 igt_assert(strcmp(crc_check, ref_crc_white) == 0);
146 connector_set_mode(data, &connector, &connector.config.default_mode, BLACK);
149 igt_assert(strcmp(crc_check, ref_crc_black) == 0);
151 kmstest_free_connector_config(&connector.config);
154 static void run_test(data_t *data)
157 drmModeConnectorPtr c;
158 uint32_t connector_id = 0;
160 for (i = 0; i < data->resources->count_connectors; i++) {
161 connector_id = data->resources->connectors[i];
162 c = drmModeGetConnector(data->drm_fd, connector_id);
164 if (c->connector_type != DRM_MODE_CONNECTOR_eDP ||
165 c->connection != DRM_MODE_CONNECTED)
168 basic_sink_crc_check(data, connector_id);
172 igt_skip("no eDP with CRC support found\n");
179 igt_skip_on_simulation();
181 data.drm_fd = drm_open_any();
183 igt_set_vt_graphics_mode();
185 data.resources = drmModeGetResources(data.drm_fd);
186 igt_assert(data.resources);
190 drmModeFreeResources(data.resources);