1 #include "rockchip-hdmi.h"
3 static const struct hdmi_video_timing hdmi_mode[] = {
6 .name = "720x480i@60Hz",
18 .vmode = FB_VMODE_INTERLACED,
21 .vic = HDMI_720X480I_60HZ_4_3,
22 .vic_2nd = HDMI_720X480I_60HZ_16_9,
24 .interface = OUT_P888,
28 .name = "720x576i@50Hz",
40 .vmode = FB_VMODE_INTERLACED,
43 .vic = HDMI_720X576I_50HZ_4_3,
44 .vic_2nd = HDMI_720X576I_50HZ_16_9,
46 .interface = OUT_P888,
50 .name = "720x480p@60Hz",
65 .vic = HDMI_720X480P_60HZ_4_3,
66 .vic_2nd = HDMI_720X480P_60HZ_16_9,
68 .interface = OUT_P888,
72 .name = "720x576p@50Hz",
87 .vic = HDMI_720X576P_50HZ_4_3,
88 .vic_2nd = HDMI_720X576P_50HZ_16_9,
90 .interface = OUT_P888,
94 .name = "1280x720p@24Hz",
100 .right_margin = 1760,
105 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
109 .vic = HDMI_1280X720P_24HZ,
110 .vic_2nd = HDMI_1280X720P_24HZ_21_9,
112 .interface = OUT_P888,
116 .name = "1280x720p@25Hz",
120 .pixclock = 74250000,
122 .right_margin = 2420,
127 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
131 .vic = HDMI_1280X720P_25HZ,
132 .vic_2nd = HDMI_1280X720P_25HZ_21_9,
134 .interface = OUT_P888,
138 .name = "1280x720p@30Hz",
142 .pixclock = 74250000,
144 .right_margin = 1760,
149 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
153 .vic = HDMI_1280X720P_30HZ,
154 .vic_2nd = HDMI_1280X720P_30HZ_21_9,
156 .interface = OUT_P888,
160 .name = "1280x720p@50Hz",
164 .pixclock = 74250000,
171 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
175 .vic = HDMI_1280X720P_50HZ,
176 .vic_2nd = HDMI_1280X720P_50HZ_21_9,
178 .interface = OUT_P888,
182 .name = "1280x720p@60Hz",
186 .pixclock = 74250000,
193 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
197 .vic = HDMI_1280X720P_60HZ,
198 .vic_2nd = HDMI_1280X720P_60HZ_21_9,
200 .interface = OUT_P888,
204 .name = "1920x1080i@50Hz",
208 .pixclock = 74250000,
215 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
216 .vmode = FB_VMODE_INTERLACED,
219 .vic = HDMI_1920X1080I_50HZ,
222 .interface = OUT_P888,
226 .name = "1920x1080i@60Hz",
230 .pixclock = 74250000,
237 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
238 .vmode = FB_VMODE_INTERLACED,
241 .vic = HDMI_1920X1080I_60HZ,
244 .interface = OUT_P888,
248 .name = "1920x1080p@24Hz",
252 .pixclock = 74250000,
259 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
263 .vic = HDMI_1920X1080P_24HZ,
264 .vic_2nd = HDMI_1920X1080P_24HZ_21_9,
266 .interface = OUT_P888,
270 .name = "1920x1080p@25Hz",
274 .pixclock = 74250000,
281 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
285 .vic = HDMI_1920X1080P_25HZ,
286 .vic_2nd = HDMI_1920X1080P_25HZ_21_9,
288 .interface = OUT_P888,
292 .name = "1920x1080p@30Hz",
296 .pixclock = 74250000,
303 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
307 .vic = HDMI_1920X1080P_30HZ,
308 .vic_2nd = HDMI_1920X1080P_30HZ_21_9,
310 .interface = OUT_P888,
314 .name = "1920x1080p@50Hz",
318 .pixclock = 148500000,
325 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
329 .vic = HDMI_1920X1080P_50HZ,
330 .vic_2nd = HDMI_1920X1080P_50HZ_21_9,
332 .interface = OUT_P888,
336 .name = "1920x1080p@60Hz",
340 .pixclock = 148500000,
347 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
351 .vic = HDMI_1920X1080P_60HZ,
352 .vic_2nd = HDMI_1920X1080P_60HZ_21_9,
354 .interface = OUT_P888,
358 .name = "3840x2160p@24Hz",
362 .pixclock = 297000000,
364 .right_margin = 1276,
369 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
373 .vic = HDMI_3840X2160P_24HZ,
374 .vic_2nd = HDMI_3840X2160P_24HZ_21_9,
376 .interface = OUT_P888,
380 .name = "3840x2160p@25Hz",
384 .pixclock = 297000000,
386 .right_margin = 1056,
391 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
395 .vic = HDMI_3840X2160P_25HZ,
396 .vic_2nd = HDMI_3840X2160P_25HZ_21_9,
398 .interface = OUT_P888,
402 .name = "3840x2160p@30Hz",
406 .pixclock = 297000000,
413 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
417 .vic = HDMI_3840X2160P_30HZ,
418 .vic_2nd = HDMI_3840X2160P_30HZ_21_9,
420 .interface = OUT_P888,
424 .name = "4096x2160p@24Hz",
428 .pixclock = 297000000,
430 .right_margin = 1020,
435 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
439 .vic = HDMI_4096X2160P_24HZ,
442 .interface = OUT_P888,
446 .name = "4096x2160p@25Hz",
450 .pixclock = 297000000,
457 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
461 .vic = HDMI_4096X2160P_25HZ,
464 .interface = OUT_P888,
468 .name = "4096x2160p@30Hz",
472 .pixclock = 297000000,
479 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
483 .vic = HDMI_4096X2160P_30HZ,
486 .interface = OUT_P888,
490 .name = "3840x2160p@50Hz",
494 .pixclock = 594000000,
496 .right_margin = 1056,
501 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
505 .vic = HDMI_3840X2160P_50HZ,
506 .vic_2nd = HDMI_3840X2160P_50HZ_21_9,
508 .interface = OUT_P888,
512 .name = "3840x2160p@60Hz",
516 .pixclock = 594000000,
523 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
527 .vic = HDMI_3840X2160P_60HZ,
528 .vic_2nd = HDMI_3840X2160P_60HZ_21_9,
530 .interface = OUT_P888,
534 .name = "4096x2160p@50Hz",
538 .pixclock = 594000000,
545 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
549 .vic = HDMI_4096X2160P_50HZ,
552 .interface = OUT_P888,
556 .name = "4096x2160p@60Hz",
560 .pixclock = 594000000,
567 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
571 .vic = HDMI_4096X2160P_60HZ,
574 .interface = OUT_P888,
578 .name = "800x600p@60Hz",
582 .pixclock = 40000000,
589 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
593 .vic = HDMI_VIDEO_DMT | 1,
596 .interface = OUT_P888,
600 .name = "1024x768p@60Hz",
604 .pixclock = 65000000,
615 .vic = HDMI_VIDEO_DMT | 2,
618 .interface = OUT_P888,
622 .name = "1280x960p@60Hz",
626 .pixclock = 108000000,
633 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
637 .vic = HDMI_VIDEO_DMT | 3,
640 .interface = OUT_P888,
644 .name = "1280x1024p@60Hz",
648 .pixclock = 108000000,
655 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
659 .vic = HDMI_VIDEO_DMT | 4,
662 .interface = OUT_P888,
666 .name = "1360x768p@60Hz",
670 .pixclock = 85500000,
677 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
681 .vic = HDMI_VIDEO_DMT | 5,
684 .interface = OUT_P888,
688 .name = "1366x768p@60Hz",
692 .pixclock = 85500000,
699 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
703 .vic = HDMI_VIDEO_DMT | 6,
706 .interface = OUT_P888,
710 .name = "1440x900p@60Hz",
714 .pixclock = 106500000,
721 .sync = FB_SYNC_VERT_HIGH_ACT,
725 .vic = HDMI_VIDEO_DMT | 7,
728 .interface = OUT_P888,
732 .name = "1600x900p@60Hz",
736 .pixclock = 108000000,
743 .sync = FB_SYNC_VERT_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
747 .vic = HDMI_VIDEO_DMT | 8,
750 .interface = OUT_P888,
754 .name = "1680x1050@60Hz",
758 .pixclock = 146250000,
765 .sync = FB_SYNC_VERT_HIGH_ACT,
769 .vic = HDMI_VIDEO_DMT | 9,
772 .interface = OUT_P888,
776 .name = "1440x1280@60Hz",
780 .pixclock = 148500000,
791 .vic = HDMI_VIDEO_DISCRETE_VR | 1,
794 .interface = OUT_P888,
799 .name = "2160x1200@75Hz",
803 .pixclock = 245000000,
814 .vic = HDMI_VIDEO_DISCRETE_VR | 3,
817 .interface = OUT_P888,
822 .name = "2880x1440@75Hz",
826 .pixclock = 340000000,
837 .vic = HDMI_VIDEO_DISCRETE_VR | 4,
840 .interface = OUT_P888,
845 .name = "1440x2560@60Hz",
849 .pixclock = 268500000,
860 .vic = HDMI_VIDEO_DISCRETE_VR | 5,
863 .interface = OUT_P888,
868 .name = "1440x2560@70Hz",
872 .pixclock = 285000000,
883 .vic = HDMI_VIDEO_DISCRETE_VR | 6,
886 .interface = OUT_P888,
890 static int hdmi_set_info(struct rk_screen *screen, struct hdmi *hdmi)
893 struct fb_videomode *mode;
895 if (!screen || !hdmi)
896 return HDMI_ERROR_FALSE;
899 hdmi->vic = hdmi->property->defaultmode;
901 if (hdmi->edid_auto_support) {
902 if ((hdmi->vic & HDMI_VIDEO_DMT) ||
903 (hdmi->vic & HDMI_VIDEO_DISCRETE_VR)) {
904 if (hdmi->prop.value.vic)
905 vic = hdmi->prop.value.vic;
909 vic = hdmi->vic & HDMI_VIC_MASK;
912 if ((hdmi->vic & HDMI_VIDEO_DMT) ||
913 (hdmi->vic & HDMI_VIDEO_DISCRETE_VR))
916 vic = hdmi->vic & HDMI_VIC_MASK;
919 for (i = 0; i < ARRAY_SIZE(hdmi_mode); i++) {
920 if (hdmi_mode[i].vic == vic ||
921 hdmi_mode[i].vic_2nd == vic)
924 if (i == ARRAY_SIZE(hdmi_mode))
925 return HDMI_ERROR_FALSE;
927 memset(screen, 0, sizeof(struct rk_screen));
929 /* screen type & face */
930 screen->type = SCREEN_HDMI;
931 if (hdmi->video.color_input == HDMI_COLOR_RGB_0_255)
932 screen->color_mode = COLOR_RGB;
934 screen->color_mode = COLOR_YCBCR;
935 if (hdmi->vic & HDMI_VIDEO_YUV420) {
936 if (hdmi->video.color_output_depth == 10)
937 screen->face = OUT_YUV_420_10BIT;
939 screen->face = OUT_YUV_420;
941 if (hdmi->video.color_output_depth == 10)
942 screen->face = OUT_P101010;
944 screen->face = hdmi_mode[i].interface;
946 screen->pixelrepeat = hdmi_mode[i].pixelrepeat - 1;
947 mode = (struct fb_videomode *)&hdmi_mode[i].mode;
949 screen->mode = *mode;
950 if (hdmi->video.format_3d == HDMI_3D_FRAME_PACKING) {
951 screen->mode.pixclock = 2 * mode->pixclock;
952 if (mode->vmode == 0) {
953 screen->mode.yres = 2 * mode->yres +
958 screen->mode.yres = 2 * mode->yres +
959 3 * (mode->upper_margin +
961 mode->vsync_len) + 2;
962 screen->mode.vmode = 0;
966 if (FB_SYNC_HOR_HIGH_ACT & mode->sync)
967 screen->pin_hsync = 1;
969 screen->pin_hsync = 0;
970 if (FB_SYNC_VERT_HIGH_ACT & mode->sync)
971 screen->pin_vsync = 1;
973 screen->pin_vsync = 0;
976 screen->pin_dclk = 1;
979 if (hdmi->soctype > HDMI_SOC_RK312X &&
980 screen->color_mode > COLOR_RGB &&
981 (screen->face == OUT_P888 ||
982 screen->face == OUT_P101010))
988 screen->swap_delta = 0;
989 screen->swap_dumy = 0;
991 /* Operation function*/
993 screen->standby = NULL;
995 screen->overscan.left = hdmi->xscale;
996 screen->overscan.top = hdmi->yscale;
997 screen->overscan.right = hdmi->xscale;
998 screen->overscan.bottom = hdmi->yscale;
1000 screen->width = hdmi->prop.value.width;
1001 screen->height = hdmi->prop.value.height;
1002 pr_info("%s:line=%d %d %d %d %d %d %d %d %d\n",
1003 __func__, __LINE__, screen->mode.xres, screen->mode.yres,
1004 screen->mode.left_margin, screen->mode.right_margin,
1005 screen->mode.upper_margin, screen->mode.lower_margin,
1006 screen->mode.hsync_len, screen->mode.vsync_len);
1012 * hdmi_find_best_mode: find the video mode nearest to input vic
1017 * If vic is zero, return the high resolution video mode vic.
1019 int hdmi_find_best_mode(struct hdmi *hdmi, int vic)
1021 struct list_head *pos, *head = &hdmi->edid.modelist;
1022 struct display_modelist *modelist = NULL;
1026 list_for_each(pos, head) {
1029 struct display_modelist, list);
1030 if (modelist->vic == vic) {
1036 if ((!vic || !found) && head->next != head) {
1037 /* If parse edid error, we select default mode; */
1038 if (hdmi->edid.specs &&
1039 hdmi->edid.specs->modedb_len)
1040 modelist = list_entry(head->next,
1041 struct display_modelist, list);
1043 return hdmi->property->defaultmode;
1047 return modelist->vic;
1053 * hdmi_set_lcdc: switch lcdc mode to required video mode
1059 int hdmi_set_lcdc(struct hdmi *hdmi)
1062 struct rk_screen screen;
1064 rc = hdmi_set_info(&screen, hdmi);
1066 rk_fb_switch_screen(&screen, 1, hdmi->lcdc->id);
1071 * hdmi_videomode_compare - compare 2 videomodes
1072 * @mode1: first videomode
1073 * @mode2: second videomode
1076 * 1 if mode1 > mode2, 0 if mode1 = mode2, -1 mode1 < mode2
1078 static int hdmi_videomode_compare(const struct fb_videomode *mode1,
1079 const struct fb_videomode *mode2)
1081 if (mode1->xres > mode2->xres)
1084 if (mode1->xres == mode2->xres) {
1085 if (mode1->yres > mode2->yres)
1087 if (mode1->yres == mode2->yres) {
1088 if (mode1->vmode < mode2->vmode)
1090 if (mode1->pixclock > mode2->pixclock)
1092 if (mode1->pixclock == mode2->pixclock) {
1093 if (mode1->refresh > mode2->refresh)
1095 if (mode1->refresh == mode2->refresh) {
1096 if (mode2->flag > mode1->flag)
1098 if (mode2->flag < mode1->flag)
1100 if (mode2->vmode > mode1->vmode)
1102 if (mode2->vmode == mode1->vmode)
1112 * hdmi_add_vic - add entry to modelist according vic
1113 * @vic: vic to be added
1114 * @head: struct list_head of modelist
1117 * Will only add unmatched mode entries
1119 int hdmi_add_vic(int vic, struct list_head *head)
1121 struct list_head *pos;
1122 struct display_modelist *modelist;
1125 /*pr_info("%s vic %d\n", __FUNCTION__, vic);*/
1129 list_for_each(pos, head) {
1130 modelist = list_entry(pos, struct display_modelist, list);
1138 modelist = kmalloc(sizeof(*modelist),
1143 memset(modelist, 0, sizeof(struct display_modelist));
1144 modelist->vic = vic;
1145 list_add_tail(&modelist->list, head);
1151 * hdmi_add_videomode: adds videomode entry to modelist
1152 * @mode: videomode to be added
1153 * @head: struct list_head of modelist
1156 * Will only add unmatched mode entries
1158 static int hdmi_add_videomode(const struct fb_videomode *mode,
1159 struct list_head *head)
1161 struct list_head *pos;
1162 struct display_modelist *modelist, *modelist_new;
1163 struct fb_videomode *m;
1166 for (i = 0; i < ARRAY_SIZE(hdmi_mode); i++) {
1167 m = (struct fb_videomode *)&hdmi_mode[i].mode;
1168 if (fb_mode_is_equal(m, mode)) {
1175 list_for_each(pos, head) {
1176 modelist = list_entry(pos,
1177 struct display_modelist, list);
1178 m = &modelist->mode;
1179 if (fb_mode_is_equal(m, mode))
1181 else if (hdmi_videomode_compare(m, mode) == -1)
1185 modelist_new = kmalloc(sizeof(*modelist_new), GFP_KERNEL);
1188 memset(modelist_new, 0, sizeof(struct display_modelist));
1189 modelist_new->mode = hdmi_mode[i].mode;
1190 modelist_new->vic = hdmi_mode[i].vic;
1191 list_add_tail(&modelist_new->list, pos);
1198 * hdmi_sort_modelist: sort modelist of edid
1199 * @edid: edid to be sort
1201 static void hdmi_sort_modelist(struct hdmi_edid *edid, int feature)
1203 struct list_head *pos, *pos_new;
1204 struct list_head head_new, *head = &edid->modelist;
1205 struct display_modelist *modelist, *modelist_new, *modelist_n;
1206 struct fb_videomode *m, *m_new;
1207 int i, compare, vic;
1209 INIT_LIST_HEAD(&head_new);
1210 list_for_each(pos, head) {
1211 modelist = list_entry(pos, struct display_modelist, list);
1212 /*pr_info("%s vic %d\n", __function__, modelist->vic);*/
1213 for (i = 0; i < ARRAY_SIZE(hdmi_mode); i++) {
1214 if ((modelist->vic & HDMI_VIDEO_DMT) || (modelist->vic & HDMI_VIDEO_DISCRETE_VR)) {
1215 if (feature & (SUPPORT_VESA_DMT | SUPPORT_RK_DISCRETE_VR))
1216 vic = modelist->vic;
1220 vic = modelist->vic & HDMI_VIC_MASK;
1222 if (vic == hdmi_mode[i].vic ||
1223 vic == hdmi_mode[i].vic_2nd) {
1224 if ((feature & SUPPORT_4K) == 0 &&
1225 hdmi_mode[i].mode.xres >= 3840)
1227 if ((feature & SUPPORT_4K_4096) == 0 &&
1228 hdmi_mode[i].mode.xres == 4096)
1230 if ((feature & SUPPORT_TMDS_600M) == 0 &&
1231 !(modelist->vic & HDMI_VIDEO_YUV420) &&
1232 hdmi_mode[i].mode.pixclock > 340000000)
1234 if ((modelist->vic & HDMI_VIDEO_YUV420) &&
1235 (feature & SUPPORT_YUV420) == 0)
1237 if ((feature & SUPPORT_1080I) == 0 &&
1238 hdmi_mode[i].mode.xres == 1920 &&
1239 (hdmi_mode[i].mode.vmode &
1240 FB_VMODE_INTERLACED))
1242 if ((feature & SUPPORT_480I_576I) == 0 &&
1243 hdmi_mode[i].mode.xres == 720 &&
1244 hdmi_mode[i].mode.vmode &
1245 FB_VMODE_INTERLACED)
1247 modelist->mode = hdmi_mode[i].mode;
1248 if (modelist->vic & HDMI_VIDEO_YUV420)
1249 modelist->mode.flag = 1;
1252 m = (struct fb_videomode *)&modelist->mode;
1253 list_for_each(pos_new, &head_new) {
1256 struct display_modelist,
1258 m_new = &modelist_new->mode;
1260 hdmi_videomode_compare(m, m_new);
1266 kmalloc(sizeof(*modelist_n),
1270 *modelist_n = *modelist;
1271 list_add_tail(&modelist_n->list,
1278 fb_destroy_modelist(head);
1279 if (head_new.next == &head_new) {
1280 pr_info("There is no available video mode in EDID.\n");
1281 INIT_LIST_HEAD(&edid->modelist);
1283 edid->modelist = head_new;
1284 edid->modelist.prev->next = &edid->modelist;
1285 edid->modelist.next->prev = &edid->modelist;
1289 static int edid_select_prop_value(struct hdmi *hdmi)
1291 struct edid_prop_value *prop_value = NULL;
1293 int i, vid, pid, sn, xres, yres, reboot = 0;
1295 prop_value = hdmi->pvalue;
1296 nstates = hdmi->nstates;
1299 pr_info("%s:pvalue is NULL\n", __func__);
1303 vid = hdmi->edid.value.vid;
1304 pid = hdmi->edid.value.pid;
1305 sn = hdmi->edid.value.sn;
1306 xres = hdmi->edid.value.xres;
1307 yres = hdmi->edid.value.yres;
1309 for (i = 0; i < nstates; i++) {
1310 if ((prop_value[i].vid == vid) &&
1311 (prop_value[i].pid == pid) &&
1312 (prop_value[i].sn == sn) &&
1313 (prop_value[i].xres == xres) &&
1314 (prop_value[i].yres == yres)) {
1315 hdmi->edid.value = prop_value[i];
1316 hdmi->prop.value = prop_value[i];
1317 if ((hdmi->prop.valid) &&
1318 ((hdmi->prop.last_vid != vid) ||
1319 (hdmi->prop.last_pid != pid) ||
1320 (hdmi->prop.last_sn != sn) ||
1321 (hdmi->prop.last_xres != xres) ||
1322 (hdmi->prop.last_yres != yres))) {
1328 hdmi->prop.last_vid = vid;
1329 hdmi->prop.last_pid = pid;
1330 hdmi->prop.last_sn = sn;
1331 hdmi->prop.last_xres = xres;
1332 hdmi->prop.last_yres = yres;
1333 hdmi->prop.valid = 1;
1334 pr_info("%s:i=%d reboot=%d,valid=%d\n",
1335 __func__, i, reboot, hdmi->prop.valid);
1342 dev_info(hdmi->dev, "%s:kernel_restart\n", __func__);
1343 kernel_restart(NULL);
1350 * hdmi_ouputmode_select - select hdmi transmitter output mode: hdmi or dvi?
1351 * @hdmi: handle of hdmi
1352 * @edid_ok: get EDID data success or not, HDMI_ERROR_SUCCESS means success.
1354 int hdmi_ouputmode_select(struct hdmi *hdmi, int edid_ok)
1356 struct list_head *head = &hdmi->edid.modelist;
1357 struct fb_monspecs *specs = hdmi->edid.specs;
1358 struct fb_videomode *modedb = NULL, *mode = NULL;
1359 int i, pixclock, feature = hdmi->property->feature;
1361 if (edid_ok != HDMI_ERROR_SUCCESS) {
1362 dev_err(hdmi->dev, "warning: EDID error, assume sink as HDMI !!!!");
1363 hdmi->edid.status = -1;
1364 hdmi->edid.sink_hdmi = 1;
1365 hdmi->edid.baseaudio_support = 1;
1366 hdmi->edid.ycbcr444 = 0;
1367 hdmi->edid.ycbcr422 = 0;
1370 if (hdmi->edid_auto_support)
1371 edid_select_prop_value(hdmi);
1373 if (head->next == head) {
1375 "warning: no CEA video mode parsed from EDID !!!!\n");
1376 /* If EDID get error, list all system supported mode.
1377 * If output mode is set to DVI and EDID is ok, check
1378 * the output timing.
1380 if (hdmi->edid.sink_hdmi == 0 && specs && specs->modedb_len) {
1381 /* Get max resolution timing */
1382 modedb = &specs->modedb[0];
1383 for (i = 0; i < specs->modedb_len; i++) {
1384 if (specs->modedb[i].xres > modedb->xres)
1385 modedb = &specs->modedb[i];
1386 else if (specs->modedb[i].xres ==
1388 specs->modedb[i].yres > modedb->yres)
1389 modedb = &specs->modedb[i];
1391 /* For some monitor, the max pixclock read from EDID
1392 * is smaller than the clock of max resolution mode
1393 * supported. We fix it.
1395 pixclock = PICOS2KHZ(modedb->pixclock);
1399 if (pixclock == 148250000)
1400 pixclock = 148500000;
1401 if (pixclock > specs->dclkmax)
1402 specs->dclkmax = pixclock;
1405 for (i = 0; i < ARRAY_SIZE(hdmi_mode); i++) {
1406 mode = (struct fb_videomode *)&hdmi_mode[i].mode;
1408 if ((mode->pixclock < specs->dclkmin) ||
1409 (mode->pixclock > specs->dclkmax) ||
1410 (mode->refresh < specs->vfmin) ||
1411 (mode->refresh > specs->vfmax) ||
1412 (mode->xres > modedb->xres) ||
1413 (mode->yres > modedb->yres))
1416 /* If there is no valid information in EDID,
1417 * just list common hdmi foramt.
1419 if (mode->xres > 3840 ||
1420 mode->refresh < 50 ||
1421 (mode->vmode & FB_VMODE_INTERLACED) ||
1422 hdmi_mode[i].vic & HDMI_VIDEO_DMT ||
1423 hdmi_mode[i].vic & HDMI_VIDEO_DISCRETE_VR)
1426 if ((feature & SUPPORT_TMDS_600M) == 0 &&
1427 mode->pixclock > 340000000)
1429 if ((feature & SUPPORT_4K) == 0 &&
1432 if ((feature & SUPPORT_4K_4096) == 0 &&
1435 if ((feature & SUPPORT_1080I) == 0 &&
1436 mode->xres == 1920 &&
1437 (mode->vmode & FB_VMODE_INTERLACED))
1439 if ((feature & SUPPORT_480I_576I) == 0 &&
1440 mode->xres == 720 &&
1441 (mode->vmode & FB_VMODE_INTERLACED))
1443 hdmi_add_videomode(mode, head);
1446 /* There are some video mode is not defined in EDID extend
1447 * block, so we need to check first block data.
1449 if (specs && specs->modedb_len) {
1450 for (i = 0; i < specs->modedb_len; i++) {
1451 modedb = &specs->modedb[i];
1452 pixclock = hdmi_videomode_to_vic(modedb);
1454 hdmi_add_vic(pixclock, head);
1457 hdmi_sort_modelist(&hdmi->edid, hdmi->property->feature);
1460 return HDMI_ERROR_SUCCESS;
1464 * hdmi_videomode_to_vic: transverse video mode to vic
1465 * @vmode: videomode to transverse
1468 int hdmi_videomode_to_vic(struct fb_videomode *vmode)
1470 struct fb_videomode *mode;
1471 unsigned int vic = 0;
1474 for (i = 0; i < ARRAY_SIZE(hdmi_mode); i++) {
1475 mode = (struct fb_videomode *)&hdmi_mode[i].mode;
1476 if (vmode->vmode == mode->vmode &&
1477 vmode->refresh == mode->refresh &&
1478 vmode->xres == mode->xres &&
1479 vmode->yres == mode->yres &&
1480 vmode->left_margin == mode->left_margin &&
1481 vmode->right_margin == mode->right_margin &&
1482 vmode->upper_margin == mode->upper_margin &&
1483 vmode->lower_margin == mode->lower_margin &&
1484 vmode->hsync_len == mode->hsync_len &&
1485 vmode->vsync_len == mode->vsync_len) {
1486 vic = hdmi_mode[i].vic;
1494 * hdmi_vic2timing: transverse vic mode to video timing
1495 * @vmode: vic to transverse
1498 const struct hdmi_video_timing *hdmi_vic2timing(int vic)
1505 for (i = 0; i < ARRAY_SIZE(hdmi_mode); i++) {
1506 if (hdmi_mode[i].vic == vic || hdmi_mode[i].vic_2nd == vic)
1507 return &hdmi_mode[i];
1513 * hdmi_vic_to_videomode: transverse vic mode to video mode
1514 * @vmode: vic to transverse
1517 const struct fb_videomode *hdmi_vic_to_videomode(int vic)
1523 else if ((vic & HDMI_VIDEO_DMT) || (vic & HDMI_VIDEO_DISCRETE_VR))
1526 vid = vic & HDMI_VIC_MASK;
1527 for (i = 0; i < ARRAY_SIZE(hdmi_mode); i++) {
1528 if (hdmi_mode[i].vic == vid ||
1529 hdmi_mode[i].vic_2nd == vid)
1530 return &hdmi_mode[i].mode;
1536 * hdmi_init_modelist: initial hdmi mode list
1542 void hdmi_init_modelist(struct hdmi *hdmi)
1545 struct list_head *head = &hdmi->edid.modelist;
1547 feature = hdmi->property->feature;
1548 INIT_LIST_HEAD(&hdmi->edid.modelist);
1549 for (i = 0; i < ARRAY_SIZE(hdmi_mode); i++) {
1550 if ((hdmi_mode[i].vic & HDMI_VIDEO_DMT) || (hdmi_mode[i].vic & HDMI_VIDEO_DISCRETE_VR))
1552 if ((feature & SUPPORT_TMDS_600M) == 0 &&
1553 hdmi_mode[i].mode.pixclock > 340000000)
1555 if ((feature & SUPPORT_4K) == 0 &&
1556 hdmi_mode[i].mode.xres >= 3840)
1558 if ((feature & SUPPORT_4K_4096) == 0 &&
1559 hdmi_mode[i].mode.xres == 4096)
1561 if ((feature & SUPPORT_1080I) == 0 &&
1562 hdmi_mode[i].mode.xres == 1920 &&
1563 (hdmi_mode[i].mode.vmode & FB_VMODE_INTERLACED))
1565 if ((feature & SUPPORT_480I_576I) == 0 &&
1566 hdmi_mode[i].mode.xres == 720 &&
1567 (hdmi_mode[i].mode.vmode & FB_VMODE_INTERLACED))
1569 hdmi_add_videomode(&hdmi_mode[i].mode, head);