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