1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 3 #ifndef TESTS_LIB_EDID_H 4 #define TESTS_LIB_EDID_H 5 6 #include <stdlib.h> 7 #include <commonlib/bsd/helpers.h> 8 9 10 struct edid_raw { 11 uint8_t header[8]; 12 13 /* Display product identification */ 14 uint16_t manufacturer_id; 15 uint16_t product_code; 16 uint32_t serial_number; 17 uint8_t manufacture_week; 18 uint8_t manufacture_year; 19 20 /* EDID version information */ 21 uint8_t edid_version; 22 uint8_t edid_revision; 23 24 /* Basic display parameters */ 25 uint8_t video_input_type; 26 uint8_t horizontal_size; /* [cm] */ 27 uint8_t vertical_size; /* [cm] */ 28 uint8_t display_gamma; 29 uint8_t supported_features; 30 31 /* Color space definition */ 32 uint8_t color_characteristics[10]; 33 34 /* Timing information */ 35 uint8_t established_supported_timings[2]; 36 uint8_t manufacturers_reserved_timing; 37 uint8_t standard_timings_supported[16]; 38 uint8_t descriptor_block_1[18]; 39 uint8_t descriptor_block_2[18]; 40 uint8_t descriptor_block_3[18]; 41 uint8_t descriptor_block_4[18]; 42 43 /* Number of optional 128-byte extension blocks */ 44 uint8_t extension_flag; 45 46 uint8_t checksum; 47 } __packed; 48 49 _Static_assert(sizeof(struct edid_raw) == 128, "assert failed: edid_raw size mismatch"); 50 51 #define EDID_HEADER_RAW \ 52 { \ 53 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00 \ 54 } 55 #define EDID_HEADER_INVALID_RAW \ 56 { \ 57 0, 0, 0, 0, 0, 0, 0, 0 \ 58 } 59 60 #define EDID_MANUFACTURER_ID 0xcb55 61 #define EDID_MANUFACTURER_NAME "UNK" 62 #define EDID_PRODUCT_CODE 0x1234 63 #define EDID_SERIAL_NUMBER 0x56789ABC 64 #define EDID_MANUFACTURE_WEEK 23u 65 #define EDID_MANUFACTURE_NO_WEEK 0u 66 #define EDID_MANUFACTURE_YEAR (2015u - 1990u) 67 68 /* Video Input Definition for Analog Video Signal Interface */ 69 #define EDID_ANALOG_VSI (0u << 7) 70 #define EDID_SIGNAL_LEVEL_0 0u 71 #define EDID_SIGNAL_LEVEL_1 (1u << 5) 72 #define EDID_SIGNAL_LEVEL_2 (2u << 5) 73 #define EDID_SIGNAL_LEVEL_3 (3u << 5) 74 #define EDID_VIDEO_SETUP_BLANK_EQ_BLACK 0u 75 #define EDID_VIDEO_SETUP_BLANK_TO_BLACK (1u << 4) 76 #define EDID_SEPARATE_SYNC_H_AND_V(v) ((v != 0 ? 0x1 : 0x0) << 3) 77 #define EDID_COMPOSITE_SYNC_H(v) ((v != 0 ? 0x1 : 0x0) << 2) 78 #define EDID_COMPOSITE_SYNC_ON_GREEN(v) ((v != 0 ? 0x1 : 0x0) << 1) 79 #define EDID_SERRATION_VSYNC(v) (v != 0 ? 0x1 : 0x0) 80 81 /* Video Input Definition for Digital Video Signal Interface */ 82 #define EDID_DIGITAL_VSI (1u << 7) 83 #define EDID_COLOR_BIT_DEPTH_UNDEFINED 0u 84 #define EDID_COLOR_BIT_DEPTH_6B (1u << 4) 85 #define EDID_COLOR_BIT_DEPTH_8B (2u << 4) 86 #define EDID_COLOR_BIT_DEPTH_10B (3u << 4) 87 #define EDID_COLOR_BIT_DEPTH_12B (4u << 4) 88 #define EDID_COLOR_BIT_DEPTH_14B (5u << 4) 89 #define EDID_COLOR_BIT_DEPTH_16B (6u << 4) 90 #define EDID_INTERFACE_UNDEFINED 0u 91 #define EDID_INTERFACE_DVI 1u 92 #define EDID_INTERFACE_HDMI_A 2u 93 #define EDID_INTERFACE_HDMI_B 3u 94 #define EDID_INTERFACE_MDDI 4u 95 #define EDID_INTERFACE_DP 5u 96 97 /* BEGIN Supported features */ 98 #define EDID_STANDBY_MODE(v) ((v != 0 ? 0x1 : 0x0) << 7) 99 #define EDID_SUSPEND_MODE(v) ((v != 0 ? 0x1 : 0x0) << 6) 100 #define EDID_ACTIVE_OFF(v) ((v != 0 ? 0x1 : 0x0) << 5) 101 /* For analog interface */ 102 #define EDID_COLOR_TYPE_MONO 0u 103 #define EDID_COLOR_TYPE_RGB (1u << 3) 104 #define EDID_COLOR_TYPE_NON_RGB (2u << 3) 105 #define EDID_COLOR_TYPE_UNDEFINED (3u << 3) 106 /* For digital interface */ 107 #define EDID_COLOR_FORMAT_RGB444 0u 108 #define EDID_COLOR_FORMAT_RGB444_YCRCB444 (1u << 3) 109 #define EDID_COLOR_FORMAT_RGB444_YCRCB422 (2u << 3) 110 #define EDID_COLOR_FORMAT_RGB444_YCRCB422_YCRCB422 (3u << 3) 111 112 #define EDID_SRGB_SUPPORTED(v) (((v) == 0 ? 0u : 1u) << 2) 113 #define EDID_PREFERRED_TIMING_EXTENDED_INFO (1u << 1) 114 #define EDID_PREFERRED_TIMING_NO_EXTENDED_INFO 0u 115 #define EDID_DISPLAY_FREQUENCY_CONTINUOUS 1u 116 #define EDID_DISPLAY_FREQUENCY_NON_CONTINUOUS 0u 117 /* END Supported features */ 118 119 /* Red X 0.640 */ 120 #define EDID_COLOR_R_X 0x25 121 /* Red Y 0.330 */ 122 #define EDID_COLOR_R_Y 0x152 123 /* Green X 0.300 */ 124 #define EDID_COLOR_G_X 0x13a 125 /* Green Y 0.600 */ 126 #define EDID_COLOR_G_Y 0x267 127 /* Blue X 0.150 */ 128 #define EDID_COLOR_B_X 0x9a 129 /* Blue Y 0.060 */ 130 #define EDID_COLOR_B_Y 0x3e 131 /* White X 0.3125 */ 132 #define EDID_COLOR_W_X 0xa 133 /* White Y 0.3291 */ 134 #define EDID_COLOR_W_Y 0x22a 135 136 /* 1 and 0 bits of each color */ 137 #define EDID_COLOR_R_X10_Y10 (((EDID_COLOR_R_X & 0x3) << 2) | (EDID_COLOR_R_Y & 0x3)) 138 #define EDID_COLOR_G_X10_Y10 (((EDID_COLOR_G_X & 0x3) << 2) | (EDID_COLOR_G_Y & 0x3)) 139 #define EDID_COLOR_B_X10_Y10 (((EDID_COLOR_B_X & 0x3) << 2) | (EDID_COLOR_B_Y & 0x3)) 140 #define EDID_COLOR_W_X10_Y10 (((EDID_COLOR_W_X & 0x3) << 2) | (EDID_COLOR_W_Y & 0x3)) 141 142 /* Concatenated 0 and 1 bits of each color. To be put 143 * as first and second byte of color characteristic. */ 144 #define EDID_COLOR_RG_XY ((EDID_COLOR_R_X10_Y10 << 4) | EDID_COLOR_G_X10_Y10) 145 #define EDID_COLOR_BW_XY ((EDID_COLOR_B_X10_Y10 << 4) | EDID_COLOR_W_X10_Y10) 146 147 /* Bits 9 through 2 of each color */ 148 #define EDID_COLOR_R_X92 (EDID_COLOR_R_X >> 2) 149 #define EDID_COLOR_R_Y92 (EDID_COLOR_R_Y >> 2) 150 #define EDID_COLOR_G_X92 (EDID_COLOR_G_X >> 2) 151 #define EDID_COLOR_G_Y92 (EDID_COLOR_G_Y >> 2) 152 #define EDID_COLOR_B_X92 (EDID_COLOR_B_X >> 2) 153 #define EDID_COLOR_B_Y92 (EDID_COLOR_B_Y >> 2) 154 #define EDID_COLOR_W_X92 (EDID_COLOR_W_X >> 2) 155 #define EDID_COLOR_W_Y92 (EDID_COLOR_W_Y >> 2) 156 157 #define EDID_ESTABLISHED_TIMINGS_1_800x600_60Hz 1u 158 #define EDID_ESTABLISHED_TIMINGS_1_800x600_56Hz (1u << 1) 159 #define EDID_ESTABLISHED_TIMINGS_1_640x480_75Hz (1u << 2) 160 #define EDID_ESTABLISHED_TIMINGS_1_640x480_72Hz (1u << 3) 161 #define EDID_ESTABLISHED_TIMINGS_1_640x480_67Hz (1u << 4) 162 #define EDID_ESTABLISHED_TIMINGS_1_640x480_60Hz (1u << 5) 163 #define EDID_ESTABLISHED_TIMINGS_1_720x400_88Hz (1u << 6) 164 #define EDID_ESTABLISHED_TIMINGS_1_720x400_70Hz (1u << 7) 165 166 #define EDID_ESTABLISHED_TIMINGS_2_1280x1024_75Hz 1u 167 #define EDID_ESTABLISHED_TIMINGS_2_1024x768_75Hz (1u << 1) 168 #define EDID_ESTABLISHED_TIMINGS_2_1024x768_70Hz (1u << 2) 169 #define EDID_ESTABLISHED_TIMINGS_2_1024x768_60Hz (1u << 3) 170 #define EDID_ESTABLISHED_TIMINGS_2_1024x768_80HzI (1u << 4) 171 #define EDID_ESTABLISHED_TIMINGS_2_832x624_75Hz (1u << 5) 172 #define EDID_ESTABLISHED_TIMINGS_2_800x600_75Hz (1u << 6) 173 #define EDID_ESTABLISHED_TIMINGS_2_800x600_72Hz (1u << 7) 174 175 #define EDID_MANUFACTURERS_TIMINGS_1152x870_75Hz (1u << 7) 176 177 #define EDID_HORIZONTAL_ACCESSIBLE_PIXELS(px) (((px) / 8 - 31) & 0xFF) 178 #define EDID_ASPECT_RATIO_16_10 0u 179 #define EDID_ASPECT_RATIO_4_3 (1u << 6) 180 #define EDID_ASPECT_RATIO_5_4 (2u << 6) 181 #define EDID_ASPECT_RATIO_16_9 (3u << 6) 182 #define EDID_FIELD_REFRESH_RATE(hz) (((hz)-60) & 0x1f) 183 184 #define EDID_PIXEL_CLOCK(v) (((v) / 10000) & 0xFFFF) 185 186 #define EDID_RAW_DEFAULT_PARAMS \ 187 .header = EDID_HEADER_RAW, .edid_version = 1, .edid_revision = 4, \ 188 .manufacturer_id = EDID_MANUFACTURER_ID, .product_code = EDID_PRODUCT_CODE, \ 189 .serial_number = EDID_SERIAL_NUMBER, .manufacture_week = EDID_MANUFACTURE_NO_WEEK, \ 190 .manufacture_year = EDID_MANUFACTURE_YEAR, \ 191 .color_characteristics = { \ 192 EDID_COLOR_RG_XY, EDID_COLOR_BW_XY, EDID_COLOR_R_X92, EDID_COLOR_R_Y92, \ 193 EDID_COLOR_G_X92, EDID_COLOR_G_Y92, EDID_COLOR_B_X92, EDID_COLOR_B_Y92, \ 194 EDID_COLOR_W_X92, EDID_COLOR_W_Y92, \ 195 } 196 197 #endif /* TESTS_LIB_EDID_H */ 198