Guest User

C4 hdmitx debug

a guest
Nov 7th, 2020
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 96.61 KB | None | 0 0
  1. /*
  2.  * drivers/amlogic/media/vout/hdmitx/hdmi_tx_20/hdmi_tx_edid.c
  3.  *
  4.  * Copyright (C) 2017 Amlogic, Inc. All rights reserved.
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * (at your option) any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful, but WITHOUT
  12.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13.  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  14.  * more details.
  15.  *
  16.  */
  17.  
  18. #include <linux/version.h>
  19. #include <linux/module.h>
  20. #include <linux/types.h>
  21. #include <linux/kernel.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/fs.h>
  24. #include <linux/init.h>
  25. #include <linux/device.h>
  26. #include <linux/mm.h>
  27. #include <linux/major.h>
  28. #include <linux/platform_device.h>
  29. #include <linux/mutex.h>
  30. #include <linux/cdev.h>
  31. #include <linux/uaccess.h>
  32. #include <crypto/hash.h>
  33. #include <linux/crypto.h>
  34. #include <linux/scatterlist.h>
  35. #include <linux/delay.h>
  36.  
  37. #include <linux/amlogic/media/vout/vinfo.h>
  38. #include <linux/amlogic/media/vout/vout_notify.h>
  39. #include <linux/amlogic/media/vout/hdmi_tx/hdmi_info_global.h>
  40. #include <linux/amlogic/media/vout/hdmi_tx/hdmi_tx_module.h>
  41. #include "hw/common.h"
  42.  
  43. #define CEA_DATA_BLOCK_COLLECTION_ADDR_1StP 0x04
  44. #define VIDEO_TAG 0x40
  45. #define AUDIO_TAG 0x20
  46. #define VENDOR_TAG 0x60
  47. #define SPEAKER_TAG 0x80
  48.  
  49. #define HDMI_EDID_BLOCK_TYPE_RESERVED           0
  50. #define HDMI_EDID_BLOCK_TYPE_AUDIO      1
  51. #define HDMI_EDID_BLOCK_TYPE_VIDEO      2
  52. #define HDMI_EDID_BLOCK_TYPE_VENDER         3
  53. #define HDMI_EDID_BLOCK_TYPE_SPEAKER            4
  54. #define HDMI_EDID_BLOCK_TYPE_VESA       5
  55. #define HDMI_EDID_BLOCK_TYPE_RESERVED2          6
  56. #define HDMI_EDID_BLOCK_TYPE_EXTENDED_TAG       7
  57.  
  58. #define EXTENSION_VENDOR_SPECIFIC 0x1
  59. #define EXTENSION_COLORMETRY_TAG 0x5
  60. /* DRM stands for "Dynamic Range and Mastering " */
  61. #define EXTENSION_DRM_STATIC_TAG    0x6
  62. #define EXTENSION_DRM_DYNAMIC_TAG   0x7
  63.    #define TYPE_1_HDR_METADATA_TYPE    0x0001
  64.    #define TS_103_433_SPEC_TYPE        0x0002
  65.    #define ITU_T_H265_SPEC_TYPE        0x0003
  66.    #define TYPE_4_HDR_METADATA_TYPE    0x0004
  67. /* Video Format Preference Data block */
  68. #define EXTENSION_VFPDB_TAG 0xd
  69. #define EXTENSION_Y420_VDB_TAG  0xe
  70. #define EXTENSION_Y420_CMDB_TAG 0xf
  71.  
  72. #define EDID_DETAILED_TIMING_DES_BLOCK0_POS 0x36
  73. #define EDID_DETAILED_TIMING_DES_BLOCK1_POS 0x48
  74. #define EDID_DETAILED_TIMING_DES_BLOCK2_POS 0x5A
  75. #define EDID_DETAILED_TIMING_DES_BLOCK3_POS 0x6C
  76.  
  77. /* EDID Descrptor Tag */
  78. #define TAG_PRODUCT_SERIAL_NUMBER 0xFF
  79. #define TAG_ALPHA_DATA_STRING 0xFE
  80. #define TAG_RANGE_LIMITS 0xFD
  81. #define TAG_DISPLAY_PRODUCT_NAME_STRING 0xFC /* MONITOR NAME */
  82. #define TAG_COLOR_POINT_DATA 0xFB
  83. #define TAG_STANDARD_TIMINGS 0xFA
  84. #define TAG_DISPLAY_COLOR_MANAGEMENT 0xF9
  85. #define TAG_CVT_TIMING_CODES 0xF8
  86. #define TAG_ESTABLISHED_TIMING_III 0xF7
  87. #define TAG_DUMMY_DES 0x10
  88.  
  89. static unsigned int tmds1;
  90. static unsigned int tmds2;
  91. static unsigned int dver;
  92. static unsigned int dvsup;
  93.  
  94. static int __init forcetmds1(char *num) {kstrtoint(num, 0, &tmds1); pr_info("hdmi_debug: bootargs forcing Max_TMDS_Clock1: %d\n", tmds1); return 0;}
  95. static int __init forcetmds2(char *num) {kstrtoint(num, 0, &tmds2); pr_info("hdmi_debug: bootargs forcing Max_TMDS_Clock2: %d\n", tmds2); return 0;}
  96. static int __init forcedver(char *num) {kstrtoint(num, 0, &dver); pr_info("hdmi_debug: bootargs forcing DV version: %d\n", dver); return 0;}
  97. static int __init forcedvsup(char *num) {kstrtoint(num, 0, &dvsup); pr_info("hdmi_debug: bootargs forcing DV support 2160p60hz: %d\n", dvsup); return 0;}
  98.  
  99. __setup("tmds1clk=", forcetmds1);
  100. __setup("tmds2clk=", forcetmds2);
  101. __setup("DV_version=", forcedver);
  102. __setup("DVsup2160=", forcedvsup);
  103.  
  104. static unsigned char __nosavedata edid_checkvalue[4] = {0};
  105. static unsigned int hdmitx_edid_check_valid_blocks(unsigned char *buf);
  106. static void Edid_DTD_parsing(struct rx_cap *prxcap, unsigned char *data);
  107. static void hdmitx_edid_set_default_aud(struct hdmitx_dev *hdev);
  108.  
  109. static int xtochar(int num, unsigned char *checksum)
  110. {
  111.     if (((edid_checkvalue[num]  >> 4) & 0xf) <= 9)
  112.         checksum[0] = ((edid_checkvalue[num]  >> 4) & 0xf) + '0';
  113.     else
  114.         checksum[0] = ((edid_checkvalue[num]  >> 4) & 0xf) - 10 + 'a';
  115.  
  116.     if ((edid_checkvalue[num] & 0xf) <= 9)
  117.         checksum[1] = (edid_checkvalue[num] & 0xf) + '0';
  118.     else
  119.         checksum[1] = (edid_checkvalue[num] & 0xf) - 10 + 'a';
  120.  
  121.     return 0;
  122. }
  123.  
  124. static void edid_save_checkvalue(unsigned char *buf, unsigned int block_cnt,
  125.     struct rx_cap *rxcap)
  126. {
  127.     unsigned int i, length, max;
  128.  
  129.     if (buf == NULL)
  130.         return;
  131.  
  132.     length = sizeof(edid_checkvalue);
  133.     memset(edid_checkvalue, 0x00, length);
  134.  
  135.     max = (block_cnt > length)?length:block_cnt;
  136.  
  137.     for (i = 0; i < max; i++)
  138.         edid_checkvalue[i] = *(buf+(i+1)*128-1);
  139.  
  140.     rxcap->chksum[0] = '0';
  141.     rxcap->chksum[1] = 'x';
  142.  
  143.     for (i = 0; i < 4; i++)
  144.         xtochar(i, &rxcap->chksum[2 * i + 2]);
  145. }
  146.  
  147. static int Edid_DecodeHeader(struct hdmitx_info *info, unsigned char *buff)
  148. {
  149.     int i, ret = 0;
  150.  
  151.     if (!(buff[0] | buff[7])) {
  152.         for (i = 1; i < 7; i++) {
  153.             if (buff[i] != 0xFF)
  154.                 ret = -1;
  155.         }
  156.     } else
  157.         ret = -1;
  158.     return ret;
  159. }
  160.  
  161. static void Edid_ParsingIDManufacturerName(struct rx_cap *prxcap,
  162.                        unsigned char *data)
  163. {
  164.     int i;
  165.     unsigned char uppercase[26] = { 0 };
  166.     unsigned char brand[3];
  167.  
  168.     /* Fill array uppercase with 'A' to 'Z' */
  169.     for (i = 0; i < 26; i++)
  170.         uppercase[i] = 'A' + i;
  171.  
  172.     brand[0] = data[0] >> 2;
  173.     brand[1] = ((data[0] & 0x3) << 3) + (data[1] >> 5);
  174.     brand[2] = data[1] & 0x1f;
  175.  
  176.     if (((brand[0] > 26) || (brand[0] == 0))
  177.         || ((brand[1] > 26) || (brand[1] == 0))
  178.         || ((brand[2] > 26) || (brand[2] == 0)))
  179.         return;
  180.     for (i = 0; i < 3; i++)
  181.         prxcap->IDManufacturerName[i] = uppercase[brand[i] - 1];
  182. }
  183.  
  184. static void Edid_ParsingIDProductCode(struct rx_cap *prxcap,
  185.                       unsigned char *data)
  186. {
  187.     if (data == NULL)
  188.         return;
  189.     prxcap->IDProductCode[0] = data[1];
  190.     prxcap->IDProductCode[1] = data[0];
  191. }
  192.  
  193. static void Edid_ParsingIDSerialNumber(struct rx_cap *prxcap,
  194.                        unsigned char *data)
  195. {
  196.     int i;
  197.  
  198.     if (data != NULL)
  199.         for (i = 0; i < 4; i++)
  200.             prxcap->IDSerialNumber[i] = data[3 - i];
  201. }
  202.  
  203. /* store the idx of vesa_timing[32], which is 0 */
  204. static void store_vesa_idx(struct rx_cap *prxcap, enum hdmi_vic vesa_timing)
  205. {
  206.     int i;
  207.  
  208.     for (i = 0; i < VESA_MAX_TIMING; i++) {
  209.         if (!prxcap->vesa_timing[i]) {
  210.             prxcap->vesa_timing[i] = vesa_timing;
  211.             break;
  212.         }
  213.  
  214.         if (prxcap->vesa_timing[i] == vesa_timing)
  215.             break;
  216.     }
  217.     pr_info("hdmitx: reach vesa idx MAX\n");
  218. }
  219.  
  220. static void Edid_EstablishedTimings(struct rx_cap *prxcap, unsigned char *data)
  221. {
  222.     if (data[0] & (1 << 5))
  223.         store_vesa_idx(prxcap, HDMIV_640x480p60hz);
  224.     if (data[0] & (1 << 0))
  225.         store_vesa_idx(prxcap, HDMIV_800x600p60hz);
  226.     if (data[1] & (1 << 3))
  227.         store_vesa_idx(prxcap, HDMIV_1024x768p60hz);
  228. }
  229.  
  230. static void Edid_StandardTimingIII(struct rx_cap *prxcap, unsigned char *data)
  231. {
  232.     if (data[0] & (1 << 0))
  233.         store_vesa_idx(prxcap, HDMIV_1152x864p75hz);
  234.     if (data[1] & (1 << 6))
  235.         store_vesa_idx(prxcap, HDMIV_1280x768p60hz);
  236.     if (data[1] & (1 << 2))
  237.         store_vesa_idx(prxcap, HDMIV_1280x960p60hz);
  238.     if (data[1] & (1 << 1))
  239.         store_vesa_idx(prxcap, HDMIV_1280x1024p60hz);
  240.     if (data[2] & (1 << 7))
  241.         store_vesa_idx(prxcap, HDMIV_1360x768p60hz);
  242.     if (data[2] & (1 << 1))
  243.         store_vesa_idx(prxcap, HDMIV_1400x1050p60hz);
  244.     if (data[3] & (1 << 5))
  245.         store_vesa_idx(prxcap, HDMIV_1680x1050p60hz);
  246.     if (data[3] & (1 << 2))
  247.         store_vesa_idx(prxcap, HDMIV_1600x1200p60hz);
  248.     if (data[4] & (1 << 0))
  249.         store_vesa_idx(prxcap, HDMIV_1920x1200p60hz);
  250. }
  251.  
  252. static void calc_timing(unsigned char *data, struct vesa_standard_timing *t)
  253. {
  254.     struct hdmi_format_para *para = NULL;
  255.  
  256.     if ((data[0] < 2) && (data[1] < 2))
  257.         return;
  258.     t->hactive = (data[0] + 31) * 8;
  259.     switch ((data[1] >> 6) & 0x3) {
  260.     case 0:
  261.         t->vactive = t->hactive * 5 / 8;
  262.         break;
  263.     case 1:
  264.         t->vactive = t->hactive * 3 / 4;
  265.         break;
  266.     case 2:
  267.         t->vactive = t->hactive * 4 / 5;
  268.         break;
  269.     case 3:
  270.     default:
  271.         t->vactive = t->hactive * 9 / 16;
  272.         break;
  273.     }
  274.     t->hsync = (data[1] & 0x3f) + 60;
  275.     para = hdmi_get_vesa_paras(t);
  276.     if (para)
  277.         t->vesa_timing = para->vic;
  278.  
  279. }
  280.  
  281. static void Edid_StandardTiming(struct rx_cap *prxcap, unsigned char *data,
  282.                 int max_num)
  283. {
  284.     int i;
  285.     struct vesa_standard_timing timing;
  286.  
  287.     for (i = 0; i < max_num; i++) {
  288.         memset(&timing, 0, sizeof(struct vesa_standard_timing));
  289.         calc_timing(&data[i * 2], &timing);
  290.         if (timing.vesa_timing)
  291.             store_vesa_idx(prxcap, timing.vesa_timing);
  292.     }
  293. }
  294.  
  295. static void Edid_ReceiverProductNameParse(struct rx_cap *prxcap,
  296.                       unsigned char *data)
  297. {
  298.     int i = 0;
  299.     /* some Display Product name end with 0x20, not 0x0a
  300.      */
  301.     while ((data[i] != 0x0a) && (data[i] != 0x20) && (i < 13)) {
  302.         prxcap->ReceiverProductName[i] = data[i];
  303.         i++;
  304.     }
  305.     prxcap->ReceiverProductName[i] = '\0';
  306. }
  307.  
  308. void Edid_DecodeStandardTiming(struct hdmitx_info *info,
  309.     unsigned char *Data, unsigned char length)
  310. {
  311.      unsigned char  i, TmpVal;
  312.      int hor_pixel, frame_rate;
  313.  
  314.     for (i = 0; i < length; i++) {
  315.         if ((Data[i*2] != 0x01) && (Data[i*2 + 1] != 0x01)) {
  316.             hor_pixel = (int)((Data[i*2]+31)*8);
  317.             TmpVal = Data[i*2 + 1] & 0xC0;
  318.  
  319.             frame_rate = (int)((Data[i*2 + 1]) & 0x3F) + 60;
  320.  
  321.             if ((hor_pixel == 720) && (frame_rate == 60))
  322.                 info->hdmi_sup_480p  = 1;
  323.             else if ((hor_pixel == 1280) && (frame_rate == 60))
  324.                 info->hdmi_sup_720p_60hz  = 1;
  325.             else if ((hor_pixel == 1920) && (frame_rate == 60))
  326.                 info->hdmi_sup_1080p_60hz  = 1;
  327.         }
  328.     }
  329. }
  330.  
  331. /* ----------------------------------------------------------- */
  332. void Edid_ParseCEADetailedTimingDescriptors(struct hdmitx_info *info,
  333.     unsigned char blk_mun, unsigned char BaseAddr,
  334.     unsigned char *buff)
  335. {
  336.     unsigned char index_edid;
  337.  
  338.     for (index_edid = 0; index_edid < blk_mun; index_edid++) {
  339.         BaseAddr += 18;
  340.         /* there is not the TimingDescriptors */
  341.         if ((BaseAddr + 18) > 0x7d)
  342.             break;
  343.     }
  344. }
  345.  
  346. static struct vsdb_phyaddr vsdb_local = {0};
  347. int get_vsdb_phy_addr(struct vsdb_phyaddr *vsdb)
  348. {
  349.     vsdb = &vsdb_local;
  350.     return vsdb->valid;
  351. }
  352.  
  353. static void set_vsdb_phy_addr(struct hdmitx_dev *hdev,
  354.                   struct vsdb_phyaddr *vsdb,
  355.                   unsigned char *edid_offset)
  356. {
  357.     int phy_addr;
  358.  
  359.     vsdb->a = (edid_offset[4] >> 4) & 0xf;
  360.     vsdb->b = (edid_offset[4] >> 0) & 0xf;
  361.     vsdb->c = (edid_offset[5] >> 4) & 0xf;
  362.     vsdb->d = (edid_offset[5] >> 0) & 0xf;
  363.     vsdb_local = *vsdb;
  364.     vsdb->valid = 1;
  365.  
  366.     phy_addr = ((vsdb->a & 0xf) << 12) |
  367.            ((vsdb->b & 0xf) <<  8) |
  368.            ((vsdb->c & 0xf) <<  4) |
  369.            ((vsdb->d & 0xf) <<  0);
  370.     hdev->physical_addr = phy_addr;
  371.     hdmitx_event_notify(HDMITX_PHY_ADDR_VALID, &phy_addr);
  372. }
  373.  
  374. static void set_vsdb_dc_cap(struct rx_cap *prxcap)
  375. {
  376.     prxcap->dc_y444 = !!(prxcap->ColorDeepSupport & (1 << 3));
  377.     prxcap->dc_30bit = !!(prxcap->ColorDeepSupport & (1 << 4));
  378.     prxcap->dc_36bit = !!(prxcap->ColorDeepSupport & (1 << 5));
  379.     prxcap->dc_48bit = !!(prxcap->ColorDeepSupport & (1 << 6));
  380. }
  381.  
  382. static void set_vsdb_dc_420_cap(struct rx_cap *prxcap,
  383.                 unsigned char *edid_offset)
  384. {
  385.     prxcap->dc_30bit_420 = !!(edid_offset[6] & (1 << 0));
  386.     prxcap->dc_36bit_420 = !!(edid_offset[6] & (1 << 1));
  387.     prxcap->dc_48bit_420 = !!(edid_offset[6] & (1 << 2));
  388. }
  389.  
  390. /* Special FBC check */
  391. static int check_fbc_special(unsigned char *edid_dat)
  392. {
  393.     if ((edid_dat[250] == 0xfb) && (edid_dat[251] == 0x0c))
  394.         return 1;
  395.     else
  396.         return 0;
  397. }
  398.  
  399. int Edid_Parse_check_HDMI_VSDB(struct hdmitx_dev *hdev,
  400.     unsigned char *buff)
  401. {
  402.     int ret = 0;
  403.     struct hdmitx_info *info = &(hdev->hdmi_info);
  404.     unsigned char  VSpecificBoundary, BlockAddr, len;
  405.     int temp_addr = 0;
  406.  
  407.     VSpecificBoundary = buff[2];
  408.  
  409.     if (VSpecificBoundary < 4)
  410.         ret = -1;
  411.     BlockAddr = CEA_DATA_BLOCK_COLLECTION_ADDR_1StP;
  412.     while (BlockAddr < VSpecificBoundary) {
  413.         len = buff[BlockAddr] & 0x1F;
  414.         if ((buff[BlockAddr] & 0xE0) == VENDOR_TAG)
  415.             break;
  416.         temp_addr = BlockAddr + len + 1;
  417.         if (temp_addr >= VSpecificBoundary)
  418.             break;
  419.         BlockAddr = BlockAddr + len + 1;
  420.     }
  421.  
  422.     set_vsdb_phy_addr(hdev, &info->vsdb_phy_addr, &buff[BlockAddr]);
  423.     if ((check_fbc_special(&hdev->EDID_buf[0])) ||
  424.         (check_fbc_special(&hdev->EDID_buf1[0])))
  425.         rx_edid_physical_addr(0, 0, 0, 0);
  426.     else
  427.         rx_edid_physical_addr(info->vsdb_phy_addr.a,
  428.             info->vsdb_phy_addr.b,
  429.             info->vsdb_phy_addr.c,
  430.             info->vsdb_phy_addr.d);
  431.  
  432.     if (temp_addr >= VSpecificBoundary)
  433.         ret = -1;
  434.     else {
  435.         if ((buff[BlockAddr + 1] != GET_OUI_BYTE0(HDMI_IEEEOUI)) ||
  436.             (buff[BlockAddr + 2] != GET_OUI_BYTE1(HDMI_IEEEOUI)) ||
  437.             (buff[BlockAddr + 3] != GET_OUI_BYTE2(HDMI_IEEEOUI)))
  438.             ret = -1;
  439.     }
  440.     return ret;
  441. }
  442.  
  443. /* ----------------------------------------------------------- */
  444. void Edid_MonitorCapable861(struct hdmitx_info *info,
  445.     unsigned char edid_flag)
  446. {
  447.     if (edid_flag & 0x80)
  448.         info->support_underscan_flag = 1;
  449.     if (edid_flag & 0x40) {
  450.         struct hdmitx_dev *hdev =
  451.             container_of(info, struct hdmitx_dev, hdmi_info);
  452.         info->support_basic_audio_flag = 1;
  453.         hdmitx_edid_set_default_aud(hdev);
  454.     }
  455.     if (edid_flag & 0x20)
  456.         info->support_ycbcr444_flag = 1;
  457.     if (edid_flag & 0x10)
  458.         info->support_ycbcr422_flag = 1;
  459. }
  460.  
  461.  
  462. /* ----------------------------------------------------------- */
  463. static void Edid_ParsingVideoDATABlock(struct hdmitx_info *info,
  464.     unsigned char *buff, unsigned char BaseAddr,
  465.     unsigned char NBytes)
  466. {
  467.     unsigned char i;
  468.     pr_info("entered Edid_ParsingVideoDATABlock()\n");
  469.     NBytes &= 0x1F;
  470.     for (i = 0; i < NBytes; i++) {
  471.         switch (buff[i + BaseAddr]&0x7F) {
  472.         case 6:
  473.         case 7:
  474.             info->hdmi_sup_480i  = 1;
  475.             pr_info("hdmi_debug: hdmi_sup_480i supported\n");
  476.             break;
  477.         case 21:
  478.         case 22:
  479.             info->hdmi_sup_576i  = 1;
  480.             pr_info("hdmi_debug: hdmi_sup_576i supported\n");
  481.             break;
  482.         case 2:
  483.         case 3:
  484.             info->hdmi_sup_480p  = 1;
  485.             pr_info("hdmi_debug: hdmi_sup_480p supported\n");
  486.             break;
  487.         case 17:
  488.         case 18:
  489.             info->hdmi_sup_576p  = 1;
  490.             pr_info("hdmi_debug: hdmi_sup_576p supported\n");
  491.             break;
  492.         case 4:
  493.             info->hdmi_sup_720p_60hz  = 1;
  494.             pr_info("hdmi_debug: hdmi_sup_720p_60hz supported\n");
  495.             break;
  496.         case 19:
  497.             info->hdmi_sup_720p_50hz  = 1;
  498.             pr_info("hdmi_debug: hdmi_sup_720p_50hz supported\n");
  499.             break;
  500.         case 5:
  501.             info->hdmi_sup_1080i_60hz  = 1;
  502.             pr_info("hdmi_debug: hdmi_sup_1080i_60hz supported\n");
  503.             break;
  504.         case 20:
  505.             info->hdmi_sup_1080i_50hz  = 1;
  506.             pr_info("hdmi_debug: hdmi_sup_1080i_50hz supported\n");
  507.             break;
  508.         case 16:
  509.             info->hdmi_sup_1080p_60hz  = 1;
  510.             pr_info("hdmi_debug: hdmi_sup_1080p_60hz supported\n");
  511.             break;
  512.         case 31:
  513.             info->hdmi_sup_1080p_50hz  = 1;
  514.             pr_info("hdmi_debug: hdmi_sup_1080p_50hz supported\n");
  515.             break;
  516.         case 32:
  517.             info->hdmi_sup_1080p_24hz  = 1;
  518.             pr_info("hdmi_debug: hdmi_sup_1080p_24hz supported\n");
  519.             break;
  520.         case 33:
  521.             info->hdmi_sup_1080p_25hz  = 1;
  522.             pr_info("hdmi_debug: hdmi_sup_1080p_25hz supported\n");
  523.             break;
  524.         case 34:
  525.             info->hdmi_sup_1080p_30hz  = 1;
  526.             pr_info("hdmi_debug: hdmi_sup_1080p_30hz supported\n");
  527.             break;
  528.         default:
  529.             pr_info("hdmi_debug: Edid_ParsingVideoDATABlock: default case switch\n");
  530.             break;
  531.         }
  532.     }
  533. }
  534.  
  535. /* ----------------------------------------------------------- */
  536. static void Edid_ParsingAudioDATABlock(struct hdmitx_info *info,
  537.     unsigned char *Data, unsigned char BaseAddr,
  538.     unsigned char NBytes)
  539. {
  540.      unsigned char AudioFormatCode;
  541.      int i = BaseAddr;
  542.     NBytes &= 0x1F;
  543.     do {
  544.         AudioFormatCode = (Data[i]&0xF8)>>3;
  545.         switch (AudioFormatCode) {
  546.         case 1:
  547.             info->tv_audio_info._60958_PCM.support_flag = 1;
  548.             info->tv_audio_info._60958_PCM.max_channel_num =
  549.                 (Data[i]&0x07);
  550.             if ((Data[i+1]&0x40))
  551.                 info->tv_audio_info._60958_PCM._192k =
  552.                     1;
  553.             if ((Data[i+1]&0x20))
  554.                 info->tv_audio_info._60958_PCM._176k =
  555.                     1;
  556.             if ((Data[i+1]&0x10))
  557.                 info->tv_audio_info._60958_PCM._96k = 1;
  558.             if ((Data[i+1]&0x08))
  559.                 info->tv_audio_info._60958_PCM._88k = 1;
  560.             if ((Data[i+1]&0x04))
  561.                 info->tv_audio_info._60958_PCM._48k = 1;
  562.             if ((Data[i+1]&0x02))
  563.                 info->tv_audio_info._60958_PCM._44k = 1;
  564.             if ((Data[i+1]&0x01))
  565.                 info->tv_audio_info._60958_PCM._32k = 1;
  566.             if ((Data[i+2]&0x04))
  567.                 info->tv_audio_info._60958_PCM._24bit = 1;
  568.             if ((Data[i+2]&0x02))
  569.                 info->tv_audio_info._60958_PCM._20bit = 1;
  570.             if ((Data[i+2]&0x01))
  571.                 info->tv_audio_info._60958_PCM._16bit = 1;
  572.             break;
  573.         case 2:
  574.             info->tv_audio_info._AC3.support_flag = 1;
  575.             info->tv_audio_info._AC3.max_channel_num =
  576.                 (Data[i]&0x07);
  577.             if ((Data[i+1]&0x40))
  578.                 info->tv_audio_info._AC3._192k = 1;
  579.             if ((Data[i+1]&0x20))
  580.                 info->tv_audio_info._AC3._176k = 1;
  581.             if ((Data[i+1]&0x10))
  582.                 info->tv_audio_info._AC3._96k = 1;
  583.             if ((Data[i+1]&0x08))
  584.                 info->tv_audio_info._AC3._88k = 1;
  585.             if ((Data[i+1]&0x04))
  586.                 info->tv_audio_info._AC3._48k = 1;
  587.             if ((Data[i+1]&0x02))
  588.                 info->tv_audio_info._AC3._44k = 1;
  589.             if ((Data[i+1]&0x01))
  590.                 info->tv_audio_info._AC3._32k = 1;
  591.             info->tv_audio_info._AC3._max_bit =
  592.                 Data[i+2];
  593.             break;
  594.         case 3:
  595.             info->tv_audio_info._MPEG1.support_flag = 1;
  596.             info->tv_audio_info._MPEG1.max_channel_num =
  597.                 (Data[i]&0x07);
  598.             if ((Data[i+1]&0x40))
  599.                 info->tv_audio_info._MPEG1._192k = 1;
  600.             if ((Data[i+1]&0x20))
  601.                 info->tv_audio_info._MPEG1._176k = 1;
  602.             if ((Data[i+1]&0x10))
  603.                 info->tv_audio_info._MPEG1._96k = 1;
  604.             if ((Data[i+1]&0x08))
  605.                 info->tv_audio_info._MPEG1._88k = 1;
  606.             if ((Data[i+1]&0x04))
  607.                 info->tv_audio_info._MPEG1._48k = 1;
  608.             if ((Data[i+1]&0x02))
  609.                 info->tv_audio_info._MPEG1._44k = 1;
  610.             if ((Data[i+1]&0x01))
  611.                 info->tv_audio_info._MPEG1._32k = 1;
  612.             info->tv_audio_info._MPEG1._max_bit =
  613.                 Data[i+2];
  614.             break;
  615.         case 4:
  616.             info->tv_audio_info._MP3.support_flag = 1;
  617.             info->tv_audio_info._MP3.max_channel_num =
  618.                 (Data[i]&0x07);
  619.             if ((Data[i+1]&0x40))
  620.                 info->tv_audio_info._MP3._192k = 1;
  621.             if ((Data[i+1]&0x20))
  622.                 info->tv_audio_info._MP3._176k = 1;
  623.             if ((Data[i+1]&0x10))
  624.                 info->tv_audio_info._MP3._96k = 1;
  625.             if ((Data[i+1]&0x08))
  626.                 info->tv_audio_info._MP3._88k = 1;
  627.             if ((Data[i+1]&0x04))
  628.                 info->tv_audio_info._MP3._48k = 1;
  629.             if ((Data[i+1]&0x02))
  630.                 info->tv_audio_info._MP3._44k = 1;
  631.             if ((Data[i+1]&0x01))
  632.                 info->tv_audio_info._MP3._32k = 1;
  633.             info->tv_audio_info._MP3._max_bit = Data[i+2];
  634.             break;
  635.         case 5:
  636.             info->tv_audio_info._MPEG2.support_flag = 1;
  637.             info->tv_audio_info._MPEG2.max_channel_num =
  638.                 (Data[i]&0x07);
  639.             if ((Data[i+1]&0x40))
  640.                 info->tv_audio_info._MPEG2._192k = 1;
  641.             if ((Data[i+1]&0x20))
  642.                 info->tv_audio_info._MPEG2._176k = 1;
  643.             if ((Data[i+1]&0x10))
  644.                 info->tv_audio_info._MPEG2._96k = 1;
  645.             if ((Data[i+1]&0x08))
  646.                 info->tv_audio_info._MPEG2._88k = 1;
  647.             if ((Data[i+1]&0x04))
  648.                 info->tv_audio_info._MPEG2._48k = 1;
  649.             if ((Data[i+1]&0x02))
  650.                 info->tv_audio_info._MPEG2._44k = 1;
  651.             if ((Data[i+1]&0x01))
  652.                 info->tv_audio_info._MPEG2._32k = 1;
  653.             info->tv_audio_info._MPEG2._max_bit = Data[i+2];
  654.             break;
  655.         case 6:
  656.             info->tv_audio_info._AAC.support_flag = 1;
  657.             info->tv_audio_info._AAC.max_channel_num =
  658.                 (Data[i]&0x07);
  659.             if ((Data[i+1]&0x40))
  660.                 info->tv_audio_info._AAC._192k = 1;
  661.             if ((Data[i+1]&0x20))
  662.                 info->tv_audio_info._AAC._176k = 1;
  663.             if ((Data[i+1]&0x10))
  664.                 info->tv_audio_info._AAC._96k = 1;
  665.             if ((Data[i+1]&0x08))
  666.                 info->tv_audio_info._AAC._88k = 1;
  667.             if ((Data[i+1]&0x04))
  668.                 info->tv_audio_info._AAC._48k = 1;
  669.             if ((Data[i+1]&0x02))
  670.                 info->tv_audio_info._AAC._44k = 1;
  671.             if ((Data[i+1]&0x01))
  672.                 info->tv_audio_info._AAC._32k = 1;
  673.             info->tv_audio_info._AAC._max_bit = Data[i+2];
  674.             break;
  675.         case 7:
  676.             info->tv_audio_info._DTS.support_flag = 1;
  677.             info->tv_audio_info._DTS.max_channel_num =
  678.                 (Data[i]&0x07);
  679.             if ((Data[i+1]&0x40))
  680.                 info->tv_audio_info._DTS._192k = 1;
  681.             if ((Data[i+1]&0x20))
  682.                 info->tv_audio_info._DTS._176k = 1;
  683.             if ((Data[i+1]&0x10))
  684.                 info->tv_audio_info._DTS._96k = 1;
  685.             if ((Data[i+1]&0x08))
  686.                 info->tv_audio_info._DTS._88k = 1;
  687.             if ((Data[i+1]&0x04))
  688.                 info->tv_audio_info._DTS._48k = 1;
  689.             if ((Data[i+1]&0x02))
  690.                 info->tv_audio_info._DTS._44k = 1;
  691.             if ((Data[i+1]&0x01))
  692.                 info->tv_audio_info._DTS._32k = 1;
  693.             info->tv_audio_info._DTS._max_bit = Data[i+2];
  694.             break;
  695.         case 8:
  696.             info->tv_audio_info._ATRAC.support_flag = 1;
  697.             info->tv_audio_info._ATRAC.max_channel_num =
  698.                 (Data[i]&0x07);
  699.             if ((Data[i+1]&0x40))
  700.                 info->tv_audio_info._ATRAC._192k = 1;
  701.             if ((Data[i+1]&0x20))
  702.                 info->tv_audio_info._ATRAC._176k = 1;
  703.             if ((Data[i+1]&0x10))
  704.                 info->tv_audio_info._ATRAC._96k = 1;
  705.             if ((Data[i+1]&0x08))
  706.                 info->tv_audio_info._ATRAC._88k = 1;
  707.             if ((Data[i+1]&0x04))
  708.                 info->tv_audio_info._ATRAC._48k = 1;
  709.             if ((Data[i+1]&0x02))
  710.                 info->tv_audio_info._ATRAC._44k = 1;
  711.             if ((Data[i+1]&0x01))
  712.                 info->tv_audio_info._ATRAC._32k = 1;
  713.             info->tv_audio_info._ATRAC._max_bit = Data[i+2];
  714.             break;
  715.         case 9:
  716.             info->tv_audio_info._One_Bit_Audio.support_flag = 1;
  717.             info->tv_audio_info._One_Bit_Audio.max_channel_num =
  718.                 (Data[i]&0x07);
  719.             if ((Data[i+1]&0x40))
  720.                 info->tv_audio_info._One_Bit_Audio._192k = 1;
  721.             if ((Data[i+1]&0x20))
  722.                 info->tv_audio_info._One_Bit_Audio._176k = 1;
  723.             if ((Data[i+1]&0x10))
  724.                 info->tv_audio_info._One_Bit_Audio._96k = 1;
  725.             if ((Data[i+1]&0x08))
  726.                 info->tv_audio_info._One_Bit_Audio._88k = 1;
  727.             if ((Data[i+1]&0x04))
  728.                 info->tv_audio_info._One_Bit_Audio._48k = 1;
  729.             if ((Data[i+1]&0x02))
  730.                 info->tv_audio_info._One_Bit_Audio._44k = 1;
  731.             if ((Data[i+1]&0x01))
  732.                 info->tv_audio_info._One_Bit_Audio._32k = 1;
  733.             info->tv_audio_info._One_Bit_Audio._max_bit =
  734.                 Data[i+2];
  735.             break;
  736.         case 10:
  737.             info->tv_audio_info._Dolby.support_flag = 1;
  738.             info->tv_audio_info._Dolby.max_channel_num =
  739.                 (Data[i]&0x07);
  740.             if ((Data[i+1]&0x40))
  741.                 info->tv_audio_info._Dolby._192k = 1;
  742.             if ((Data[i+1]&0x20))
  743.                 info->tv_audio_info._Dolby._176k = 1;
  744.             if ((Data[i+1]&0x10))
  745.                 info->tv_audio_info._Dolby._96k = 1;
  746.             if ((Data[i+1]&0x08))
  747.                 info->tv_audio_info._Dolby._88k = 1;
  748.             if ((Data[i+1]&0x04))
  749.                 info->tv_audio_info._Dolby._48k = 1;
  750.             if ((Data[i+1]&0x02))
  751.                 info->tv_audio_info._Dolby._44k = 1;
  752.             if ((Data[i+1]&0x01))
  753.                 info->tv_audio_info._Dolby._32k = 1;
  754.             info->tv_audio_info._Dolby._max_bit = Data[i+2];
  755.             break;
  756.  
  757.         case 11:
  758.             info->tv_audio_info._DTS_HD.support_flag = 1;
  759.             info->tv_audio_info._DTS_HD.max_channel_num =
  760.                 (Data[i]&0x07);
  761.             if ((Data[i+1]&0x40))
  762.                 info->tv_audio_info._DTS_HD._192k = 1;
  763.             if ((Data[i+1]&0x20))
  764.                 info->tv_audio_info._DTS_HD._176k = 1;
  765.             if ((Data[i+1]&0x10))
  766.                 info->tv_audio_info._DTS_HD._96k = 1;
  767.             if ((Data[i+1]&0x08))
  768.                 info->tv_audio_info._DTS_HD._88k = 1;
  769.             if ((Data[i+1]&0x04))
  770.                 info->tv_audio_info._DTS_HD._48k = 1;
  771.             if ((Data[i+1]&0x02))
  772.                 info->tv_audio_info._DTS_HD._44k = 1;
  773.             if ((Data[i+1]&0x01))
  774.                 info->tv_audio_info._DTS_HD._32k = 1;
  775.             info->tv_audio_info._DTS_HD._max_bit =
  776.                 Data[i+2];
  777.             break;
  778.         case 12:
  779.             info->tv_audio_info._MAT.support_flag = 1;
  780.             info->tv_audio_info._MAT.max_channel_num =
  781.                 (Data[i]&0x07);
  782.             if ((Data[i+1]&0x40))
  783.                 info->tv_audio_info._MAT._192k = 1;
  784.             if ((Data[i+1]&0x20))
  785.                 info->tv_audio_info._MAT._176k = 1;
  786.             if ((Data[i+1]&0x10))
  787.                 info->tv_audio_info._MAT._96k = 1;
  788.             if ((Data[i+1]&0x08))
  789.                 info->tv_audio_info._MAT._88k = 1;
  790.             if ((Data[i+1]&0x04))
  791.                 info->tv_audio_info._MAT._48k = 1;
  792.             if ((Data[i+1]&0x02))
  793.                 info->tv_audio_info._MAT._44k = 1;
  794.             if ((Data[i+1]&0x01))
  795.                 info->tv_audio_info._MAT._32k = 1;
  796.             info->tv_audio_info._MAT._max_bit = Data[i+2];
  797.             break;
  798.  
  799.         case 13:
  800.             info->tv_audio_info._ATRAC.support_flag = 1;
  801.             info->tv_audio_info._ATRAC.max_channel_num =
  802.                 (Data[i]&0x07);
  803.             if ((Data[i+1]&0x40))
  804.                 info->tv_audio_info._DST._192k = 1;
  805.             if ((Data[i+1]&0x20))
  806.                 info->tv_audio_info._DST._176k = 1;
  807.             if ((Data[i+1]&0x10))
  808.                 info->tv_audio_info._DST._96k = 1;
  809.             if ((Data[i+1]&0x08))
  810.                 info->tv_audio_info._DST._88k = 1;
  811.             if ((Data[i+1]&0x04))
  812.                 info->tv_audio_info._DST._48k = 1;
  813.             if ((Data[i+1]&0x02))
  814.                 info->tv_audio_info._DST._44k = 1;
  815.             if ((Data[i+1]&0x01))
  816.                 info->tv_audio_info._DST._32k = 1;
  817.             info->tv_audio_info._DST._max_bit = Data[i+2];
  818.             break;
  819.  
  820.         case 14:
  821.             info->tv_audio_info._WMA.support_flag = 1;
  822.             info->tv_audio_info._WMA.max_channel_num =
  823.                 (Data[i]&0x07);
  824.             if ((Data[i+1]&0x40))
  825.                 info->tv_audio_info._WMA._192k = 1;
  826.             if ((Data[i+1]&0x20))
  827.                 info->tv_audio_info._WMA._176k = 1;
  828.             if ((Data[i+1]&0x10))
  829.                 info->tv_audio_info._WMA._96k = 1;
  830.             if ((Data[i+1]&0x08))
  831.                 info->tv_audio_info._WMA._88k = 1;
  832.             if ((Data[i+1]&0x04))
  833.                 info->tv_audio_info._WMA._48k = 1;
  834.             if ((Data[i+1]&0x02))
  835.                 info->tv_audio_info._WMA._44k = 1;
  836.             if ((Data[i+1]&0x01))
  837.                 info->tv_audio_info._WMA._32k = 1;
  838.             info->tv_audio_info._WMA._max_bit = Data[i+2];
  839.             break;
  840.  
  841.         default:
  842.         break;
  843.         }
  844.     i += 3;
  845.     } while (i < (NBytes + BaseAddr));
  846. }
  847.  
  848. /* ----------------------------------------------------------- */
  849. static void Edid_ParsingSpeakerDATABlock(struct hdmitx_info *info,
  850.     unsigned char *buff, unsigned char BaseAddr)
  851. {
  852.     int ii;
  853.  
  854.     for (ii = 1; ii < 0x80; ) {
  855.         switch (buff[BaseAddr] & ii) {
  856.         case 0x40:
  857.             info->tv_audio_info.speaker_allocation.rlc_rrc = 1;
  858.             break;
  859.  
  860.         case 0x20:
  861.             info->tv_audio_info.speaker_allocation.flc_frc = 1;
  862.             break;
  863.  
  864.         case 0x10:
  865.             info->tv_audio_info.speaker_allocation.rc = 1;
  866.             break;
  867.  
  868.         case 0x08:
  869.             info->tv_audio_info.speaker_allocation.rl_rr = 1;
  870.             break;
  871.  
  872.         case 0x04:
  873.             info->tv_audio_info.speaker_allocation.fc = 1;
  874.             break;
  875.  
  876.         case 0x02:
  877.             info->tv_audio_info.speaker_allocation.lfe = 1;
  878.             break;
  879.  
  880.         case 0x01:
  881.             info->tv_audio_info.speaker_allocation.fl_fr = 1;
  882.             break;
  883.  
  884.         default:
  885.         break;
  886.         }
  887.         ii = ii << 1;
  888.     }
  889. }
  890.  
  891. static void Edid_ParsingVendSpec(struct rx_cap *prxcap,
  892.                  unsigned char *buf)
  893. {
  894.     struct dv_info *dv = &prxcap->dv_info;
  895.     struct hdr10_plus_info *hdr10_plus = &prxcap->hdr10plus_info;
  896.     unsigned char *dat = buf;
  897.     unsigned char pos = 0;
  898.     unsigned int ieeeoui = 0;
  899.  
  900.     memset(dv, 0, sizeof(struct dv_info));
  901.     memset(hdr10_plus, 0, sizeof(struct hdr10_plus_info));
  902.  
  903.     dv->block_flag = CORRECT;
  904.     dv->length = dat[pos] & 0x1f;
  905.     hdr10_plus->length = dat[pos] & 0x1f;
  906.     memcpy(dv->rawdata, dat, dv->length + 1);
  907.     pos++;
  908.  
  909.     if (dat[pos] != 1) {
  910.         pr_info("hdmitx: edid: parsing fail %s[%d]\n", __func__,
  911.             __LINE__);
  912.         return;
  913.     }
  914.  
  915.     pos++;
  916.     ieeeoui = dat[pos++];
  917.     ieeeoui += dat[pos++] << 8;
  918.     ieeeoui += dat[pos++] << 16;
  919.     pr_info("hdmi_debug: ieeeoui: %d\n", ieeeoui);
  920.  
  921. /*HDR10+ use vsvdb*/
  922.     if (ieeeoui == HDR10_PLUS_IEEE_OUI) {
  923.         pr_info("hdmi_debug: ieeeoui == HDR10_PLUS_IEEE_OUI\n");
  924.         hdr10_plus->ieeeoui = ieeeoui;
  925.         hdr10_plus->application_version = dat[pos] & 0x3;
  926.         pos++;
  927.         return;
  928.     }
  929.  
  930.     if (ieeeoui != DV_IEEE_OUI) {
  931.         pr_info("hdmi_debug: ieeeoui != DV_IEEE_OUI\n");
  932.         dv->block_flag = ERROR_OUI;
  933.         return;
  934.     }
  935.     dv->ieeeoui = ieeeoui;
  936.     dv->ver = (dat[pos] >> 5) & 0x7;
  937.     pr_info("hdmi_debug: detected dv->ver: %d\n", dv->ver);
  938.     if (dver) {
  939.         dv->ver = dver;
  940.         pr_info("hdmi_debug: forcing DV version per bootargs: version %d\n", dv->ver);
  941.     }
  942.     if ((dv->ver) > 2) {
  943.         dv->block_flag = ERROR_VER;
  944.         pr_info("hdmi_debug: dv->block_flag = ERROR_VER (dv->ver > 2)\n");
  945.         return;
  946.     }
  947.     /* Refer to DV 2.9 Page 27 */
  948.     if (dv->ver == 0) {
  949.         pr_info("hdmi_debug: entering dv->ver == 0 routine\n");/*marker*/
  950.         if (dv->length == 0x19) {
  951.             dv->sup_yuv422_12bit = dat[pos] & 0x1;
  952.             dv->sup_2160p60hz = (dat[pos] >> 1) & 0x1;
  953.             dv->sup_global_dimming = (dat[pos] >> 2) & 0x1;
  954.             pos++;
  955.             dv->Rx =
  956.                 (dat[pos+1] << 4) | (dat[pos] >> 4);
  957.             dv->Ry =
  958.                 (dat[pos+2] << 4) | (dat[pos] & 0xf);
  959.             pos += 3;
  960.             dv->Gx =
  961.                 (dat[pos+1] << 4) | (dat[pos] >> 4);
  962.             dv->Gy =
  963.                 (dat[pos+2] << 4) | (dat[pos] & 0xf);
  964.             pos += 3;
  965.             dv->Bx =
  966.                 (dat[pos+1] << 4) | (dat[pos] >> 4);
  967.             dv->By =
  968.                 (dat[pos+2] << 4) | (dat[pos] & 0xf);
  969.             pos += 3;
  970.             dv->Wx =
  971.                 (dat[pos+1] << 4) | (dat[pos] >> 4);
  972.             dv->Wy =
  973.                 (dat[pos+2] << 4) | (dat[pos] & 0xf);
  974.             pos += 3;
  975.             dv->tminPQ =
  976.                 (dat[pos+1] << 4) | (dat[pos] >> 4);
  977.             dv->tmaxPQ =
  978.                 (dat[pos+2] << 4) | (dat[pos] & 0xf);
  979.             pos += 3;
  980.             dv->dm_major_ver = dat[pos] >> 4;
  981.             dv->dm_minor_ver = dat[pos] & 0xf;
  982.             pos++;
  983.             pr_info("v0 VSVDB: len=%d, sup_2160p60hz=%d\n",
  984.                 dv->length, dv->sup_2160p60hz);
  985.         } else
  986.             dv->block_flag = ERROR_LENGTH;
  987.             pr_info("hdmi_debug: dv->block_flag = ERROR_LENGTH\n");
  988.     }
  989.  
  990.     if (dv->ver == 1) {
  991.         pr_info("hdmi_debug: entering dv->ver == 1 routine\n");
  992.         if (dv->length == 0x0B) {/* Refer to DV 2.9 Page 33 */
  993.             pr_info("hdmi_debug: entering dv->length == 0x0B routine\n");
  994.             dv->dm_version = (dat[pos] >> 2) & 0x7;
  995.             dv->sup_yuv422_12bit = dat[pos] & 0x1;
  996.             dv->sup_2160p60hz = (dat[pos] >> 1) & 0x1;
  997.             pos++;
  998.             dv->sup_global_dimming = dat[pos] & 0x1;
  999.             dv->tmaxLUM = dat[pos] >> 1;
  1000.             pos++;
  1001.             dv->colorimetry = dat[pos] & 0x1;
  1002.             dv->tminLUM = dat[pos] >> 1;
  1003.             pos++;
  1004.             dv->low_latency = dat[pos] & 0x3;
  1005.             dv->Bx = 0x20 | ((dat[pos] >> 5) & 0x7);
  1006.             dv->By = 0x08 | ((dat[pos] >> 2) & 0x7);
  1007.             pos++;
  1008.             dv->Gx = 0x00 | (dat[pos] >> 1);
  1009.             dv->Ry = 0x40 | ((dat[pos] & 0x1) |
  1010.                 ((dat[pos + 1] & 0x1) << 1) |
  1011.                 ((dat[pos + 2] & 0x3) << 2));
  1012.             pos++;
  1013.             dv->Gy = 0x80 | (dat[pos] >> 1);
  1014.             pos++;
  1015.             dv->Rx = 0xA0 | (dat[pos] >> 3);
  1016.             pos++;
  1017.             pr_info("v1 VSVDB: len=%d, sup_2160p60hz=%d, low_latency=%d\n",
  1018.                 dv->length, dv->sup_2160p60hz, dv->low_latency);
  1019.         } else if (dv->length == 0x0E) {
  1020.             pr_info("hdmi_debug: entering dv->length == 0x0E routine\n");
  1021.             dv->dm_version = (dat[pos] >> 2) & 0x7;
  1022.             dv->sup_yuv422_12bit = dat[pos] & 0x1;
  1023.             dv->sup_2160p60hz = (dat[pos] >> 1) & 0x1;
  1024.             pos++;
  1025.             dv->sup_global_dimming = dat[pos] & 0x1;
  1026.             dv->tmaxLUM = dat[pos] >> 1;
  1027.             pos++;
  1028.             dv->colorimetry = dat[pos] & 0x1;
  1029.             dv->tminLUM = dat[pos] >> 1;
  1030.             pos += 2; /* byte8 is reserved as 0 */
  1031.             dv->Rx = dat[pos++];
  1032.             dv->Ry = dat[pos++];
  1033.             dv->Gx = dat[pos++];
  1034.             dv->Gy = dat[pos++];
  1035.             dv->Bx = dat[pos++];
  1036.             dv->By = dat[pos++];
  1037.             pr_info("v1 VSVDB: len=%d, sup_2160p60hz=%d\n",
  1038.                 dv->length, dv->sup_2160p60hz);
  1039.         } else {
  1040.             dv->block_flag = ERROR_LENGTH;
  1041.             pr_info("hdmi_debug: dv->block_flag = ERROR_LENGTH @ dv->ver == 1 routine\n");
  1042.         }
  1043.     }
  1044.     if (dv->ver == 2) {
  1045.         /* v2 VSVDB length could be greater than 0xB
  1046.          * and should not be treated as unrecognized
  1047.          * block. Instead, we should parse it as a regular
  1048.          * v2 VSVDB using just the remaining 11 bytes here
  1049.          */
  1050.         pr_info("hdmi_debug: entering dv->ver == 2 routine\n");
  1051.         if (dv->length >= 0x0B) {
  1052.             dv->sup_2160p60hz = 0x1;/*default*/
  1053.             dv->dm_version = (dat[pos] >> 2) & 0x7;
  1054.             dv->sup_yuv422_12bit = dat[pos] & 0x1;
  1055.             dv->sup_backlight_control = (dat[pos] >> 1) & 0x1;
  1056.             pos++;
  1057.             dv->sup_global_dimming = (dat[pos] >> 2) & 0x1;
  1058.             dv->backlt_min_luma = dat[pos] & 0x3;
  1059.             dv->tminPQ = dat[pos] >> 3;
  1060.             pos++;
  1061.             dv->Interface = dat[pos] & 0x3;
  1062.             dv->tmaxPQ = dat[pos] >> 3;
  1063.             pos++;
  1064.             dv->sup_10b_12b_444 = ((dat[pos] & 0x1) << 1) |
  1065.                 (dat[pos + 1] & 0x1);
  1066.             dv->Gx = 0x00 | (dat[pos] >> 1);
  1067.             pos++;
  1068.             dv->Gy = 0x80 | (dat[pos] >> 1);
  1069.             pos++;
  1070.             dv->Rx = 0xA0 | (dat[pos] >> 3);
  1071.             dv->Bx = 0x20 | (dat[pos] & 0x7);
  1072.             pos++;
  1073.             dv->Ry = 0x40  | (dat[pos] >> 3);
  1074.             dv->By = 0x08  | (dat[pos] & 0x7);
  1075.             pos++;
  1076.             pr_info("v2 VSVDB: len=%d, sup_2160p60hz=%d, Interface=%d\n",
  1077.                 dv->length, dv->sup_2160p60hz, dv->Interface);
  1078.         } else
  1079.             dv->block_flag = ERROR_LENGTH;
  1080.     }
  1081.  
  1082.     if (pos > (dv->length + 1))
  1083.         pr_info("hdmitx: edid: maybe invalid dv%d data\n", dv->ver);
  1084. }
  1085.  
  1086. /* ----------------------------------------------------------- */
  1087. static int Edid_ParsingY420VDBBlock(struct rx_cap *prxcap,
  1088.                     unsigned char *buf)
  1089. {
  1090.     unsigned char tag = 0, ext_tag = 0, data_end = 0;
  1091.     unsigned int pos = 0;
  1092.     int i = 0, found = 0;
  1093.  
  1094.     tag = (buf[pos] >> 5) & 0x7;
  1095.     data_end = (buf[pos] & 0x1f)+1;
  1096.     pos++;
  1097.     ext_tag = buf[pos];
  1098.  
  1099.     if ((tag != 0x7) || (ext_tag != 0xe))
  1100.         goto INVALID_Y420VDB;
  1101.  
  1102.     pos++;
  1103.     while (pos < data_end) {
  1104.         if (prxcap->VIC_count < VIC_MAX_NUM) {
  1105.             for (i = 0; i < prxcap->VIC_count; i++) {
  1106.                 if (prxcap->VIC[i] == buf[pos]) {
  1107.                     prxcap->VIC[i] =
  1108.                     HDMITX_VIC420_OFFSET + buf[pos];
  1109.                     found = 1;
  1110.                     /* Here we do not break,because
  1111.                      *  some EDID may have the same
  1112.                      *  repeated VICs
  1113.                      */
  1114.                 }
  1115.             }
  1116.             if (found == 0) {
  1117.                 prxcap->VIC[prxcap->VIC_count] =
  1118.                 HDMITX_VIC420_OFFSET + buf[pos];
  1119.                 prxcap->VIC_count++;
  1120.             }
  1121.         }
  1122.         pos++;
  1123.     }
  1124.  
  1125.     return 0;
  1126.  
  1127. INVALID_Y420VDB:
  1128.     pr_info("[%s] it's not a valid y420vdb!\n", __func__);
  1129.     return -1;
  1130. }
  1131.  
  1132. static int Edid_ParsingDRMStaticBlock(struct rx_cap *prxcap,
  1133.                       unsigned char *buf)
  1134. {
  1135.     unsigned char tag = 0, ext_tag = 0, data_end = 0;
  1136.     unsigned int pos = 0;
  1137.  
  1138.     tag = (buf[pos] >> 5) & 0x7;
  1139.     data_end = (buf[pos] & 0x1f);
  1140.     memset(prxcap->hdr_rawdata, 0, 7);
  1141.     memcpy(prxcap->hdr_rawdata, buf, data_end + 1);
  1142.     pos++;
  1143.     ext_tag = buf[pos];
  1144.     if ((tag != HDMI_EDID_BLOCK_TYPE_EXTENDED_TAG)
  1145.         || (ext_tag != EXTENSION_DRM_STATIC_TAG))
  1146.         goto INVALID_DRM_STATIC;
  1147.     pos++;
  1148.     prxcap->hdr_sup_eotf_sdr = !!(buf[pos] & (0x1 << 0));
  1149.     prxcap->hdr_sup_eotf_hdr = !!(buf[pos] & (0x1 << 1));
  1150.     prxcap->hdr_sup_eotf_smpte_st_2084 = !!(buf[pos] & (0x1 << 2));
  1151.     prxcap->hdr_sup_eotf_hlg = !!(buf[pos] & (0x1 << 3));
  1152.     pos++;
  1153.     prxcap->hdr_sup_SMD_type1 = !!(buf[pos] & (0x1 << 0));
  1154.     pos++;
  1155.     if (data_end == 3)
  1156.         return 0;
  1157.     if (data_end == 4) {
  1158.         prxcap->hdr_lum_max = buf[pos];
  1159.         return 0;
  1160.     }
  1161.     if (data_end == 5) {
  1162.         prxcap->hdr_lum_max = buf[pos];
  1163.         prxcap->hdr_lum_avg = buf[pos + 1];
  1164.         return 0;
  1165.     }
  1166.     if (data_end == 6) {
  1167.         prxcap->hdr_lum_max = buf[pos];
  1168.         prxcap->hdr_lum_avg = buf[pos + 1];
  1169.         prxcap->hdr_lum_min = buf[pos + 2];
  1170.         return 0;
  1171.     }
  1172.     return 0;
  1173. INVALID_DRM_STATIC:
  1174.     pr_info("[%s] it's not a valid DRM STATIC BLOCK\n", __func__);
  1175.     return -1;
  1176. }
  1177.  
  1178. static int Edid_ParsingDRMDynamicBlock(struct rx_cap *prxcap,
  1179.                        unsigned char *buf)
  1180. {
  1181.     unsigned char tag = 0, ext_tag = 0, data_end = 0;
  1182.     unsigned int pos = 0;
  1183.     unsigned int type;
  1184.     unsigned int type_length;
  1185.     unsigned int i;
  1186.     unsigned int num;
  1187.  
  1188.     tag = (buf[pos] >> 5) & 0x7;
  1189.     data_end = (buf[pos] & 0x1f);
  1190.     pos++;
  1191.     ext_tag = buf[pos];
  1192.     if ((tag != HDMI_EDID_BLOCK_TYPE_EXTENDED_TAG)
  1193.         || (ext_tag != EXTENSION_DRM_DYNAMIC_TAG))
  1194.         goto INVALID_DRM_DYNAMIC;
  1195.     pos++;
  1196.     data_end--;/*extended tag code byte doesn't need*/
  1197.  
  1198.     while (data_end) {
  1199.         type_length = buf[pos];
  1200.         pos++;
  1201.         type = (buf[pos + 1] << 8) | buf[pos];
  1202.         pos += 2;
  1203.         switch (type) {
  1204.         case TS_103_433_SPEC_TYPE:
  1205.             num = 1;
  1206.             break;
  1207.         case ITU_T_H265_SPEC_TYPE:
  1208.             num = 2;
  1209.             break;
  1210.         case TYPE_4_HDR_METADATA_TYPE:
  1211.             num = 3;
  1212.             break;
  1213.         case TYPE_1_HDR_METADATA_TYPE:
  1214.         default:
  1215.             num = 0;
  1216.             break;
  1217.         }
  1218.         prxcap->hdr_dynamic_info[num].hd_len = type_length;
  1219.         prxcap->hdr_dynamic_info[num].type = type;
  1220.         prxcap->hdr_dynamic_info[num].support_flags = buf[pos];
  1221.         pos++;
  1222.         for (i = 0; i < type_length - 3; i++) {
  1223.             prxcap->hdr_dynamic_info[num].optional_fields[i]
  1224.                 = buf[pos];
  1225.             pos++;
  1226.         }
  1227.         data_end = data_end - (type_length + 1);
  1228.     }
  1229.  
  1230.     return 0;
  1231. INVALID_DRM_DYNAMIC:
  1232.     pr_info("[%s] it's not a valid DRM DYNAMIC BLOCK\n", __func__);
  1233.     return -1;
  1234. }
  1235.  
  1236. static int Edid_ParsingVFPDB(struct rx_cap *prxcap, unsigned char *buf)
  1237. {
  1238.     unsigned int len = buf[0] & 0x1f;
  1239.     enum hdmi_vic svr = HDMI_Unknown;
  1240.  
  1241.     if (buf[1] != EXTENSION_VFPDB_TAG)
  1242.         return 0;
  1243.     if (len < 2)
  1244.         return 0;
  1245.  
  1246.     svr = buf[2];
  1247.     if (((svr >= 1) && (svr <= 127)) ||
  1248.         ((svr >= 193) && (svr <= 253))) {
  1249.         prxcap->flag_vfpdb = 1;
  1250.         prxcap->preferred_mode = svr;
  1251.         pr_info("preferred mode 0 srv %d\n", prxcap->preferred_mode);
  1252.         return 1;
  1253.     }
  1254.     if ((svr >= 129) && (svr <= 144)) {
  1255.         prxcap->flag_vfpdb = 1;
  1256.         prxcap->preferred_mode = prxcap->dtd[svr - 129].vic;
  1257.         pr_info("preferred mode 0 dtd %d\n", prxcap->preferred_mode);
  1258.         return 1;
  1259.     }
  1260.     return 0;
  1261. }
  1262.  
  1263. /* ----------------------------------------------------------- */
  1264. static int Edid_ParsingY420CMDBBlock(struct hdmitx_info *info,
  1265.     unsigned char *buf)
  1266. {
  1267.     unsigned char tag = 0, ext_tag = 0, length = 0, data_end = 0;
  1268.     unsigned int pos = 0, i = 0;
  1269.  
  1270.     tag = (buf[pos] >> 5) & 0x7;
  1271.     length = buf[pos] & 0x1f;
  1272.     data_end = length + 1;
  1273.     pos++;
  1274.     ext_tag = buf[pos];
  1275.  
  1276.     if ((tag != 0x7) || (ext_tag != 0xf))
  1277.         goto INVALID_Y420CMDB;
  1278.  
  1279.     if (length == 1) {
  1280.         info->y420_all_vic = 1;
  1281.         return 0;
  1282.     }
  1283.  
  1284.     info->bitmap_length = 0;
  1285.     info->bitmap_valid = 0;
  1286.     memset(info->y420cmdb_bitmap, 0x00, Y420CMDB_MAX);
  1287.  
  1288.     pos++;
  1289.     if (pos < data_end) {
  1290.         info->bitmap_length = data_end - pos;
  1291.         info->bitmap_valid = 1;
  1292.     }
  1293.     while (pos < data_end) {
  1294.         if (i < Y420CMDB_MAX)
  1295.             info->y420cmdb_bitmap[i] = buf[pos];
  1296.         pos++;
  1297.         i++;
  1298.     }
  1299.  
  1300.     return 0;
  1301.  
  1302. INVALID_Y420CMDB:
  1303.     pr_info("[%s] it's not a valid y420cmdb!\n", __func__);
  1304.     return -1;
  1305.  
  1306. }
  1307.  
  1308. static int Edid_Y420CMDB_fill_all_vic(struct hdmitx_dev *hdmitx_device)
  1309. {
  1310.     struct rx_cap *rxcap = &hdmitx_device->rxcap;
  1311.     struct hdmitx_info *info = &hdmitx_device->hdmi_info;
  1312.     unsigned int count = rxcap->VIC_count;
  1313.     unsigned int a, b;
  1314.  
  1315.     if (info->y420_all_vic != 1)
  1316.         return 1;
  1317.  
  1318.     a = count/8;
  1319.     a = (a >= Y420CMDB_MAX)?Y420CMDB_MAX:a;
  1320.     b = count%8;
  1321.  
  1322.     if (a > 0)
  1323.         memset(&(info->y420cmdb_bitmap[0]), 0xff, a);
  1324.  
  1325.     if ((b != 0) && (a < Y420CMDB_MAX))
  1326.         info->y420cmdb_bitmap[a] = (((1 << b) - 1) << (8-b));
  1327.  
  1328.     info->bitmap_length = (b == 0) ? a : (a + 1);
  1329.     info->bitmap_valid = (info->bitmap_length != 0)?1:0;
  1330.  
  1331.     return 0;
  1332. }
  1333.  
  1334. static int Edid_Y420CMDB_PostProcess(struct hdmitx_dev *hdmitx_device)
  1335. {
  1336.     unsigned int i = 0, j = 0, valid = 0;
  1337.     struct rx_cap *rxcap = &hdmitx_device->rxcap;
  1338.     struct hdmitx_info *info = &hdmitx_device->hdmi_info;
  1339.     unsigned char *p = NULL;
  1340.  
  1341.     if (info->y420_all_vic == 1)
  1342.         Edid_Y420CMDB_fill_all_vic(hdmitx_device);
  1343.  
  1344.     if (info->bitmap_valid == 0)
  1345.         goto PROCESS_END;
  1346.  
  1347.     for (i = 0; i < info->bitmap_length; i++) {
  1348.         p = &(info->y420cmdb_bitmap[i]);
  1349.         for (j = 0; j < 8; j++) {
  1350.             valid = ((*p >> j) & 0x1);
  1351.             if (valid != 0) {
  1352.                 rxcap->VIC[rxcap->VIC_count] =
  1353.                 HDMITX_VIC420_OFFSET + rxcap->VIC[i*8+j];
  1354.                 rxcap->VIC_count++;
  1355.             }
  1356.         }
  1357.     }
  1358.  
  1359. PROCESS_END:
  1360.     return 0;
  1361. }
  1362.  
  1363. static void Edid_Y420CMDB_Reset(struct hdmitx_info *info)
  1364. {
  1365.     info->bitmap_valid = 0;
  1366.     info->bitmap_length = 0;
  1367.     info->y420_all_vic = 0;
  1368.     memset(info->y420cmdb_bitmap, 0x00, Y420CMDB_MAX);
  1369. }
  1370.  
  1371. /* ----------------------------------------------------------- */
  1372. int Edid_ParsingCEADataBlockCollection(struct hdmitx_dev *hdmitx_device,
  1373.     unsigned char *buff)
  1374. {
  1375.     unsigned char AddrTag, D, Addr, Data;
  1376.     int temp_addr;
  1377.     int len;
  1378.     struct hdmitx_info *info = &(hdmitx_device->hdmi_info);
  1379.     struct rx_cap *prxcap = &hdmitx_device->rxcap;
  1380.  
  1381.     /* Byte number offset d where Detailed Timing data begins */
  1382.     D = buff[2];
  1383.     Addr = 4;
  1384.  
  1385.     AddrTag = Addr;
  1386.     do {
  1387.         Data = buff[AddrTag];
  1388.         switch (Data&0xE0) {
  1389.         case VIDEO_TAG:
  1390.             if ((Addr + (Data&0x1f)) < D) {
  1391.                 Edid_ParsingVideoDATABlock(info, buff,
  1392.                     Addr + 1, (Data & 0x1F));
  1393.                 len = (Data & 0x1f) + 1;
  1394.                 if ((prxcap->vsd.len + len) > MAX_RAW_LEN)
  1395.                     break;
  1396.                 memcpy(&prxcap->vsd.raw[prxcap->vsd.len],
  1397.                        &buff[AddrTag], len);
  1398.                 prxcap->vsd.len += len;
  1399.             }
  1400.             break;
  1401.  
  1402.         case AUDIO_TAG:
  1403.             /* rx_set_receiver_edid(&buff[AddrTag], len); */
  1404.             if ((Addr + (Data&0x1f)) < D)
  1405.                 Edid_ParsingAudioDATABlock(info, buff,
  1406.                     Addr + 1, (Data & 0x1F));
  1407.             len = (Data & 0x1f) + 1;
  1408.             if ((prxcap->asd.len + len) > MAX_RAW_LEN)
  1409.                 break;
  1410.             memcpy(&prxcap->asd.raw[prxcap->asd.len],
  1411.                    &buff[AddrTag], len);
  1412.             prxcap->asd.len += len;
  1413.             break;
  1414.  
  1415.         case SPEAKER_TAG:
  1416.             if ((Addr + (Data&0x1f)) < D)
  1417.                 Edid_ParsingSpeakerDATABlock(info, buff,
  1418.                     Addr + 1);
  1419.             break;
  1420.  
  1421.         case VENDOR_TAG:
  1422.             if ((Addr + (Data&0x1f)) < D) {
  1423.                 if ((buff[Addr + 1] != 0x03) ||
  1424.                     (buff[Addr + 2] != 0x0c) ||
  1425.                     (buff[Addr + 3] != 0x00)) {
  1426.                     info->auth_state = HDCP_NO_AUTH;
  1427.                 }
  1428.                 if ((Data&0x1f) > 5) {
  1429.                     if (buff[Addr + 6] & 0x80)
  1430.                         info->support_ai_flag = 1;
  1431.                 }
  1432.             }
  1433.             break;
  1434.  
  1435.         default:
  1436.         break;
  1437.         }
  1438.         Addr += (Data & 0x1F);   /* next Tag Address */
  1439.         AddrTag = ++Addr;
  1440.         Data = buff[Addr];
  1441.         temp_addr =   Addr + (Data & 0x1F);
  1442.         if (temp_addr >= D) /* force to break; */
  1443.             break;
  1444.     } while (Addr < D);
  1445.  
  1446.     return 0;
  1447. }
  1448.  
  1449. /* ----------------------------------------------------------- */
  1450.  
  1451. /* parse Sink 3D information */
  1452. static int hdmitx_edid_3d_parse(struct rx_cap *prxcap, unsigned char *dat,
  1453.                 unsigned int size)
  1454. {
  1455.     int j = 0;
  1456.     unsigned int base = 0;
  1457.     unsigned int pos = base + 1;
  1458.  
  1459.     if (dat[base] & (1 << 7))
  1460.         pos += 2;
  1461.     if (dat[base] & (1 << 6))
  1462.         pos += 2;
  1463.     if (dat[base] & (1 << 5)) {
  1464.         prxcap->threeD_present = dat[pos] >> 7;
  1465.         prxcap->threeD_Multi_present = (dat[pos] >> 5) & 0x3;
  1466.         pos += 1;
  1467.         prxcap->hdmi_vic_LEN = dat[pos] >> 5;
  1468.         prxcap->HDMI_3D_LEN = dat[pos] & 0x1f;
  1469.         pos += prxcap->hdmi_vic_LEN + 1;
  1470.  
  1471.         if (prxcap->threeD_Multi_present == 0x01) {
  1472.             prxcap->threeD_Structure_ALL_15_0 =
  1473.                 (dat[pos] << 8) + dat[pos+1];
  1474.             prxcap->threeD_MASK_15_0 = 0;
  1475.             pos += 2;
  1476.         }
  1477.         if (prxcap->threeD_Multi_present == 0x02) {
  1478.             prxcap->threeD_Structure_ALL_15_0 =
  1479.                 (dat[pos] << 8) + dat[pos+1];
  1480.             pos += 2;
  1481.             prxcap->threeD_MASK_15_0 =
  1482.                 (dat[pos] << 8) + dat[pos + 1];
  1483.             pos += 2;
  1484.         }
  1485.     }
  1486.     while (pos < size) {
  1487.         if ((dat[pos] & 0xf) < 0x8) {
  1488.             /* frame packing */
  1489.             if ((dat[pos] & 0xf) == T3D_FRAME_PACKING)
  1490.                 prxcap->support_3d_format[prxcap->VIC[((dat[pos]
  1491.                     & 0xf0) >> 4)]].frame_packing = 1;
  1492.             /* top and bottom */
  1493.             if ((dat[pos] & 0xf) == T3D_TAB)
  1494.                 prxcap->support_3d_format[prxcap->VIC[((dat[pos]
  1495.                     & 0xf0) >> 4)]].top_and_bottom = 1;
  1496.             pos += 1;
  1497.         } else {
  1498.             /* SidebySide */
  1499.             if ((dat[pos] & 0xf) == T3D_SBS_HALF)
  1500.                 if ((dat[pos+1] >> 4) < 0xb)
  1501.                     prxcap->support_3d_format[prxcap->VIC[
  1502.                         ((dat[pos] & 0xf0) >> 4)]]
  1503.                         .side_by_side = 1;
  1504.             pos += 2;
  1505.         }
  1506.     }
  1507.     if (prxcap->threeD_MASK_15_0 == 0) {
  1508.         for (j = 0; (j < 16) && (j < prxcap->VIC_count); j++) {
  1509.             prxcap->support_3d_format[prxcap->VIC[j]].frame_packing
  1510.                 = 1;
  1511.             prxcap->support_3d_format[prxcap->VIC[j]].top_and_bottom
  1512.                 = 1;
  1513.             prxcap->support_3d_format[prxcap->VIC[j]].side_by_side
  1514.                 = 1;
  1515.         }
  1516.     } else {
  1517.         for (j = 0; j < 16; j++) {
  1518.             if (((prxcap->threeD_MASK_15_0) >> j) & 0x1) {
  1519.                 /* frame packing */
  1520.                 if (prxcap->threeD_Structure_ALL_15_0
  1521.                     & (1 << 0))
  1522.                     prxcap->support_3d_format[prxcap->
  1523.                         VIC[j]].frame_packing = 1;
  1524.                 /* top and bottom */
  1525.                 if (prxcap->threeD_Structure_ALL_15_0
  1526.                     & (1 << 6))
  1527.                     prxcap->support_3d_format[prxcap->
  1528.                         VIC[j]].top_and_bottom = 1;
  1529.                 /* top and bottom */
  1530.                 if (prxcap->threeD_Structure_ALL_15_0
  1531.                     & (1 << 8))
  1532.                     prxcap->support_3d_format[prxcap->
  1533.                         VIC[j]].side_by_side = 1;
  1534.             }
  1535.         }
  1536.     }
  1537.     return 1;
  1538. }
  1539.  
  1540. /* parse Sink 4k2k information */
  1541. static void hdmitx_edid_4k2k_parse(struct rx_cap *prxcap, unsigned char *dat,
  1542.                    unsigned int size)
  1543. {
  1544.     if ((size > 4) || (size == 0)) {
  1545.         pr_info(EDID
  1546.             "4k2k in edid out of range, SIZE = %d\n",
  1547.             size);
  1548.         return;
  1549.     }
  1550.     while (size--) {
  1551.         if (*dat == 1)
  1552.             prxcap->VIC[prxcap->VIC_count] = HDMI_4k2k_30;
  1553.         else if (*dat == 2)
  1554.             prxcap->VIC[prxcap->VIC_count] = HDMI_4k2k_25;
  1555.         else if (*dat == 3)
  1556.             prxcap->VIC[prxcap->VIC_count] = HDMI_4k2k_24;
  1557.         else if (*dat == 4)
  1558.             prxcap->VIC[prxcap->VIC_count] = HDMI_4k2k_smpte_24;
  1559.         else
  1560.             ;
  1561.         dat++;
  1562.         prxcap->VIC_count++;
  1563.     }
  1564. }
  1565.  
  1566. static void get_latency(struct rx_cap *prxcap, unsigned char *val)
  1567. {
  1568.     if (val[0] == 0)
  1569.         prxcap->vLatency = LATENCY_INVALID_UNKNOWN;
  1570.     else if (val[0] == 0xFF)
  1571.         prxcap->vLatency = LATENCY_NOT_SUPPORT;
  1572.     else
  1573.         prxcap->vLatency = (val[0] - 1) * 2;
  1574.  
  1575.     if (val[1] == 0)
  1576.         prxcap->aLatency = LATENCY_INVALID_UNKNOWN;
  1577.     else if (val[1] == 0xFF)
  1578.         prxcap->aLatency = LATENCY_NOT_SUPPORT;
  1579.     else
  1580.         prxcap->aLatency = (val[1] - 1) * 2;
  1581. }
  1582.  
  1583. static void get_ilatency(struct rx_cap *prxcap, unsigned char *val)
  1584. {
  1585.     if (val[0] == 0)
  1586.         prxcap->i_vLatency = LATENCY_INVALID_UNKNOWN;
  1587.     else if (val[0] == 0xFF)
  1588.         prxcap->i_vLatency = LATENCY_NOT_SUPPORT;
  1589.     else
  1590.         prxcap->i_vLatency = val[0] * 2 - 1;
  1591.  
  1592.     if (val[1] == 0)
  1593.         prxcap->i_aLatency = LATENCY_INVALID_UNKNOWN;
  1594.     else if (val[1] == 0xFF)
  1595.         prxcap->i_aLatency = LATENCY_NOT_SUPPORT;
  1596.     else
  1597.         prxcap->i_aLatency = val[1] * 2 - 1;
  1598. }
  1599.  
  1600. static int hdmitx_edid_block_parse(struct hdmitx_dev *hdmitx_device,
  1601.     unsigned char *blockbuf)
  1602. {
  1603.     unsigned char offset, end;
  1604.     unsigned char count;
  1605.     unsigned char tag;
  1606.     int i, tmp, idx;
  1607.     unsigned char *vfpdb_offset = NULL;
  1608.     struct rx_cap *prxcap = &hdmitx_device->rxcap;
  1609.     unsigned int aud_flag = 0;
  1610.  
  1611.     pr_info("hdmi_debug: entered hdmitx_edid_block_parse()\n");
  1612.    
  1613.     if (blockbuf[0] != 0x02)
  1614.         return -1; /* not a CEA BLOCK. */
  1615.     end = blockbuf[2]; /* CEA description. */
  1616.     prxcap->native_Mode = blockbuf[3];
  1617.     prxcap->number_of_dtd += blockbuf[3] & 0xf;
  1618.  
  1619.     prxcap->native_VIC = 0xff;
  1620.  
  1621.     Edid_Y420CMDB_Reset(&(hdmitx_device->hdmi_info));
  1622.  
  1623.     for (offset = 4 ; offset < end ; ) {
  1624.         tag = blockbuf[offset] >> 5;
  1625.         count = blockbuf[offset] & 0x1f;
  1626.         pr_info("hdmi_debug: entered EDID block-type switch\n");
  1627.         switch (tag) {
  1628.         case HDMI_EDID_BLOCK_TYPE_AUDIO:
  1629.             aud_flag = 1;
  1630.             tmp = count / 3;
  1631.             idx = prxcap->AUD_count;
  1632.             prxcap->AUD_count += tmp;
  1633.             offset++;
  1634.             for (i = 0 ; i < tmp; i++) {
  1635.                 prxcap->RxAudioCap[idx + i].audio_format_code =
  1636.                     (blockbuf[offset + i * 3] >> 3) & 0xf;
  1637.                 prxcap->RxAudioCap[idx + i].channel_num_max =
  1638.                     blockbuf[offset + i * 3] & 0x7;
  1639.                 prxcap->RxAudioCap[idx + i].freq_cc =
  1640.                     blockbuf[offset + i * 3 + 1] & 0x7f;
  1641.                 prxcap->RxAudioCap[idx + i].cc3 =
  1642.                     blockbuf[offset + i * 3 + 2];
  1643.             }
  1644.             offset += count;
  1645.             break;
  1646.  
  1647.         case HDMI_EDID_BLOCK_TYPE_VIDEO:
  1648.             offset++;
  1649.             for (i = 0 ; i < count ; i++) {
  1650.                 unsigned char VIC;
  1651.  
  1652.                 VIC = blockbuf[offset + i] & (~0x80);
  1653.                 prxcap->VIC[prxcap->VIC_count] = VIC;
  1654.                 if (blockbuf[offset + i] & 0x80)
  1655.                     prxcap->native_VIC = VIC;
  1656.                 prxcap->VIC_count++;
  1657.             }
  1658.             offset += count;
  1659.             break;
  1660.  
  1661.         case HDMI_EDID_BLOCK_TYPE_VENDER:
  1662.             pr_info("hdmi_debug: EDID block-type switch, case HDMI_EDID_BLOCK_TYPE_VENDER\n");
  1663.             offset++;
  1664.             if ((blockbuf[offset] == 0x03) &&
  1665.                 (blockbuf[offset + 1] == 0x0c) &&
  1666.                 (blockbuf[offset + 2] == 0x00)) {
  1667.                 prxcap->ieeeoui = HDMI_IEEEOUI;
  1668.                 prxcap->ColorDeepSupport =
  1669.                     (count > 5) ? blockbuf[offset + 5] : 0;
  1670.                 set_vsdb_dc_cap(prxcap);
  1671.                 prxcap->Max_TMDS_Clock1 =
  1672.                     (count > 6) ? blockbuf[offset + 6] : 0;
  1673.                 pr_info("hdmi_debug: Max_TMDS_Clock1: %d\n", prxcap->Max_TMDS_Clock1);
  1674.                 if (tmds1) {
  1675.                     pr_info("hdmi_debug: forcing Max_TMDS_Clock1 per bootargs");
  1676.                     pr_info("hdmi_debug: set to min x*5 > 594 to pass later sup_2160p60hz checks");
  1677.                     prxcap->Max_TMDS_Clock1 = tmds1;
  1678.                     pr_info("hdmi_debug: Max_TMDS_Clock1 now: %d\n", prxcap->Max_TMDS_Clock1);
  1679.                 }
  1680.                
  1681.                 if (count > 7) {
  1682.                     tmp = blockbuf[offset + 7];
  1683.                     idx = offset + 8;
  1684.                     if (tmp & (1<<6)) {
  1685.                         unsigned char val[2];
  1686.  
  1687.                         val[0] = blockbuf[idx];
  1688.                         val[1] = blockbuf[idx + 1];
  1689.                         get_latency(prxcap, val);
  1690.                         idx += 2;
  1691.                     }
  1692.                     if (tmp & (1<<7)) {
  1693.                         unsigned char val[2];
  1694.  
  1695.                         val[0] = blockbuf[idx];
  1696.                         val[1] = blockbuf[idx + 1];
  1697.                         get_ilatency(prxcap, val);
  1698.                         idx += 2;
  1699.                     }
  1700.                     if (tmp & (1<<5)) {
  1701.                         idx += 1;
  1702.                         /* valid 4k */
  1703.                     if (blockbuf[idx] & 0xe0) {
  1704.                         pr_info("hdmi_debug: found valid 4k\n");
  1705.                         hdmitx_edid_4k2k_parse(
  1706.                             prxcap,
  1707.                             &blockbuf[idx + 1],
  1708.                             blockbuf[idx] >> 5);
  1709.                     }
  1710.                     /* valid 3D */
  1711.                     if (blockbuf[idx - 1] & 0xe0) {
  1712.                         pr_info("hdmi_debug: found valid 3D\n");
  1713.                         hdmitx_edid_3d_parse(
  1714.                             prxcap,
  1715.                             &blockbuf[offset + 7],
  1716.                             count - 7);
  1717.                     }
  1718.                     }
  1719.                 }
  1720.             } else if ((blockbuf[offset] == 0xd8) &&
  1721.                 (blockbuf[offset + 1] == 0x5d) &&
  1722.                 (blockbuf[offset + 2] == 0xc4)) {
  1723.                 prxcap->hf_ieeeoui = HF_IEEEOUI;
  1724.                 prxcap->Max_TMDS_Clock2 = blockbuf[offset + 4];
  1725.                 if (tmds2) {
  1726.                     pr_info("hdmi_debug: forcing Max_TMDS_Clock2 per bootargs");
  1727.                     pr_info("hdmi_debug: set to min x*5 > 594 to pass later sup_2160p60hz checks");
  1728.                     prxcap->Max_TMDS_Clock2 = tmds2;
  1729.                     pr_info("hdmi_debug: Max_TMDS_Clock2 now: %d\n", prxcap->Max_TMDS_Clock2);
  1730.                 }
  1731.                 prxcap->scdc_present =
  1732.                     !!(blockbuf[offset + 5] & (1 << 7));
  1733.                 prxcap->scdc_rr_capable =
  1734.                     !!(blockbuf[offset + 5] & (1 << 6));
  1735.                 prxcap->lte_340mcsc_scramble =
  1736.                     !!(blockbuf[offset + 5] & (1 << 3));
  1737.                 set_vsdb_dc_420_cap(&hdmitx_device->rxcap,
  1738.                             &blockbuf[offset]);
  1739.                 if (count > 7) {
  1740.                     unsigned char b7 = blockbuf[offset + 7];
  1741.  
  1742.                     prxcap->allm = !!(b7 & (1 << 1));
  1743.                 }
  1744.             }
  1745.  
  1746.             offset += count; /* ignore the remaind. */
  1747.             break;
  1748.  
  1749.         case HDMI_EDID_BLOCK_TYPE_SPEAKER:
  1750.             offset++;
  1751.             prxcap->RxSpeakerAllocation = blockbuf[offset];
  1752.             offset += count;
  1753.             break;
  1754.  
  1755.         case HDMI_EDID_BLOCK_TYPE_VESA:
  1756.             offset++;
  1757.             offset += count;
  1758.             break;
  1759.  
  1760.         case HDMI_EDID_BLOCK_TYPE_EXTENDED_TAG:
  1761.             {
  1762.                 unsigned char ext_tag = 0;
  1763.                 unsigned char *t = NULL;
  1764.                 unsigned char v = 0;
  1765.                
  1766.                 pr_info("hdmi_debug: EDID block-type switch, case HDMI_EDID_BLOCK_TYPE_EXTENDED_TAG\n");
  1767.                 ext_tag = blockbuf[offset + 1];
  1768.                 switch (ext_tag) {
  1769.                 case EXTENSION_VENDOR_SPECIFIC:
  1770.                     pr_info("hdmi_debug: EDID block-type switch, subcase EXTENSION_VENDOR_SPECIFIC\n");
  1771.                     t = &blockbuf[offset];
  1772.                     if (!hdmitx_device->hdr_priority)
  1773.                         Edid_ParsingVendSpec(prxcap, t);
  1774.                     break;
  1775.                 case EXTENSION_COLORMETRY_TAG:
  1776.                     prxcap->colorimetry_data =
  1777.                         blockbuf[offset + 2];
  1778.                     break;
  1779.                 case EXTENSION_DRM_STATIC_TAG:
  1780.                     t = &blockbuf[offset];
  1781.                     Edid_ParsingDRMStaticBlock(prxcap, t);
  1782.                     v = (blockbuf[offset] & 0x1f) + 1;
  1783.                     rx_set_hdr_lumi(&blockbuf[offset], v);
  1784.                     break;
  1785.                 case EXTENSION_DRM_DYNAMIC_TAG:
  1786.                     t = &blockbuf[offset];
  1787.                     Edid_ParsingDRMDynamicBlock(prxcap, t);
  1788.                     break;
  1789.                 case EXTENSION_VFPDB_TAG:
  1790. /* Just record VFPDB offset address, call Edid_ParsingVFPDB() after DTD
  1791.  * parsing, in case that
  1792.  * SVR >=129 and SVR <=144, Interpret as the Kth DTD in the EDID,
  1793.  * where K = SVR – 128 (for K=1 to 16)
  1794.  */
  1795.                     vfpdb_offset = &blockbuf[offset];
  1796.                     break;
  1797.                 case EXTENSION_Y420_VDB_TAG:
  1798.                     t = &blockbuf[offset];
  1799.                     Edid_ParsingY420VDBBlock(prxcap, t);
  1800.                     break;
  1801.                 case EXTENSION_Y420_CMDB_TAG:
  1802.                     Edid_ParsingY420CMDBBlock(
  1803.                         &(hdmitx_device->hdmi_info),
  1804.                         &blockbuf[offset]);
  1805.                     break;
  1806.                 default:
  1807.                     break;
  1808.                 }
  1809.             }
  1810.             offset += count+1;
  1811.             break;
  1812.  
  1813.         case HDMI_EDID_BLOCK_TYPE_RESERVED:
  1814.             offset++;
  1815.             offset += count;
  1816.             break;
  1817.  
  1818.         case HDMI_EDID_BLOCK_TYPE_RESERVED2:
  1819.             offset++;
  1820.             offset += count;
  1821.             break;
  1822.  
  1823.         default:
  1824.             break;
  1825.         }
  1826.     }
  1827.  
  1828.     if (aud_flag == 0)
  1829.         hdmitx_edid_set_default_aud(hdmitx_device);
  1830.  
  1831.     Edid_Y420CMDB_PostProcess(hdmitx_device);
  1832.     hdmitx_device->vic_count = prxcap->VIC_count;
  1833.  
  1834.     idx = blockbuf[3] & 0xf;
  1835.     for (i = 0; i < idx; i++)
  1836.         Edid_DTD_parsing(prxcap, &blockbuf[blockbuf[2] + i * 18]);
  1837.     if (vfpdb_offset)
  1838.         Edid_ParsingVFPDB(prxcap, vfpdb_offset);
  1839.  
  1840.     return 0;
  1841. }
  1842.  
  1843. static void hdmitx_edid_set_default_aud(struct hdmitx_dev *hdev)
  1844. {
  1845.     struct rx_cap *prxcap = &hdev->rxcap;
  1846.  
  1847.     /* if AUD_count not equal to 0, no need default value */
  1848.     if (prxcap->AUD_count)
  1849.         return;
  1850.  
  1851.     prxcap->AUD_count = 1;
  1852.     prxcap->RxAudioCap[0].audio_format_code = 1; /* PCM */
  1853.     prxcap->RxAudioCap[0].channel_num_max = 1; /* 2ch */
  1854.     prxcap->RxAudioCap[0].freq_cc = 7; /* 32/44.1/48 kHz */
  1855.     prxcap->RxAudioCap[0].cc3 = 1; /* 16bit */
  1856. }
  1857.  
  1858. /* add default VICs for DVI case */
  1859. static void hdmitx_edid_set_default_vic(struct hdmitx_dev *hdmitx_device)
  1860. {
  1861.     struct rx_cap *prxcap = &hdmitx_device->rxcap;
  1862.  
  1863.     prxcap->VIC_count = 0x3;
  1864.     prxcap->VIC[0] = HDMI_720x480p60_16x9;
  1865.     prxcap->VIC[1] = HDMI_1280x720p60_16x9;
  1866.     prxcap->VIC[2] = HDMI_1920x1080p60_16x9;
  1867.     prxcap->native_VIC = HDMI_720x480p60_16x9;
  1868.     hdmitx_device->vic_count = prxcap->VIC_count;
  1869.     pr_info(EDID "set default vic\n");
  1870. }
  1871.  
  1872. #if 0
  1873. #define PRINT_HASH(hash)    \
  1874.     {           \
  1875.         pr_info("%s:%d ", __func__, __LINE__); int __i; \
  1876.         for (__i = 0; __i < 20; __i++)  \
  1877.             pr_info("%02x,", hash[__i]);    \
  1878.             pr_info("\n");\
  1879.     }
  1880. #else
  1881. #define PRINT_HASH(hash)
  1882. #endif
  1883.  
  1884. static int edid_hash_calc(unsigned char *hash, const char *data,
  1885.     unsigned int len)
  1886. {
  1887. #if 0
  1888.     struct scatterlist sg;
  1889.  
  1890.     struct crypto_hash *tfm;
  1891.     struct hash_desc desc;
  1892.  
  1893.     tfm = crypto_alloc_hash("sha1", 0, CRYPTO_ALG_ASYNC);
  1894.     PRINT_HASH(hash);
  1895.     if (IS_ERR(tfm))
  1896.         return -EINVAL;
  1897.  
  1898.     PRINT_HASH(hash);
  1899.     /* ... set up the scatterlists ... */
  1900.     sg_init_one(&sg, (u8 *) data, len);
  1901.     desc.tfm = tfm;
  1902.     desc.flags = 0;
  1903.  
  1904.  
  1905.  
  1906.     if (crypto_hash_digest(&desc, &sg, len, hash))
  1907.         return -EINVAL;
  1908.  
  1909.     err = crypto_ahash_digest(req);
  1910.     ahash_request_zero(req);
  1911.  
  1912.     PRINT_HASH(hash);
  1913.     crypto_free_hash(tfm);
  1914. #endif
  1915.     return 1;
  1916. }
  1917.  
  1918. static int hdmitx_edid_search_IEEEOUI(char *buf)
  1919. {
  1920.     int i;
  1921.  
  1922.     for (i = 0; i < 0x180; i++) {
  1923.         if ((buf[i] == 0x03) && (buf[i+1] == 0x0c) &&
  1924.             (buf[i+2] == 0x00))
  1925.             return 1;
  1926.     }
  1927.     return 0;
  1928. }
  1929.  
  1930. /* check EDID strictly */
  1931. static int edid_check_valid(unsigned char *buf)
  1932. {
  1933.     unsigned int chksum = 0;
  1934.     unsigned int i = 0;
  1935.  
  1936.     /* check block 0 first 8 bytes */
  1937.     if ((buf[0] != 0) && (buf[7] != 0))
  1938.         return 0;
  1939.     for (i = 1; i < 7; i++) {
  1940.         if (buf[i] != 0xff)
  1941.             return 0;
  1942.     }
  1943.  
  1944.     /* check block 0 checksum */
  1945.     for (chksum = 0, i = 0; i < 0x80; i++)
  1946.         chksum += buf[i];
  1947.  
  1948.     if ((chksum & 0xff) != 0)
  1949.         return 0;
  1950.  
  1951.     /* check Extension flag at block 0 */
  1952.     if (buf[0x7e] == 0)
  1953.         return 0;
  1954.  
  1955.     /* check block 1 extension tag */
  1956.     if (!((buf[0x80] == 0x2) || (buf[0x80] == 0xf0)))
  1957.         return 0;
  1958.  
  1959.     /* check block 1 checksum */
  1960.     for (chksum = 0, i = 0x80; i < 0x100; i++)
  1961.         chksum += buf[i];
  1962.  
  1963.     if ((chksum & 0xff) != 0)
  1964.         return 0;
  1965.  
  1966.     return 1;
  1967. }
  1968.  
  1969. /* retrun 1 valid edid */
  1970. int check_dvi_hdmi_edid_valid(unsigned char *buf)
  1971. {
  1972.     unsigned int chksum = 0;
  1973.     unsigned int i = 0;
  1974.  
  1975.     /* check block 0 first 8 bytes */
  1976.     if ((buf[0] != 0) && (buf[7] != 0))
  1977.         return 0;
  1978.     for (i = 1; i < 7; i++) {
  1979.         if (buf[i] != 0xff)
  1980.             return 0;
  1981.     }
  1982.  
  1983.     /* check block 0 checksum */
  1984.     for (chksum = 0, i = 0; i < 0x80; i++)
  1985.         chksum += buf[i];
  1986.     if ((chksum & 0xff) != 0)
  1987.         return 0;
  1988.  
  1989.     if (buf[0x7e] == 0)/* check Extension flag at block 0 */
  1990.         return 1;
  1991.     /* check block 1 extension tag */
  1992.     else if (!((buf[0x80] == 0x2) || (buf[0x80] == 0xf0)))
  1993.         return 0;
  1994.  
  1995.     /* check block 1 checksum */
  1996.     for (chksum = 0, i = 0x80; i < 0x100; i++)
  1997.         chksum += buf[i];
  1998.     if ((chksum & 0xff) != 0)
  1999.         return 0;
  2000.  
  2001.     /* check block 2 checksum */
  2002.     if (buf[0x7e] > 1) {
  2003.         for (chksum = 0, i = 0x100; i < 0x180; i++)
  2004.             chksum += buf[i];
  2005.         if ((chksum & 0xff) != 0)
  2006.             return 0;
  2007.     }
  2008.  
  2009.     /* check block 3 checksum */
  2010.     if (buf[0x7e] > 2) {
  2011.         for (chksum = 0, i = 0x180; i < 0x200; i++)
  2012.             chksum += buf[i];
  2013.         if ((chksum & 0xff) != 0)
  2014.             return 0;
  2015.     }
  2016.  
  2017.     return 1;
  2018. }
  2019.  
  2020. static void Edid_ManufactureDateParse(struct rx_cap *prxcap,
  2021.                       unsigned char *data)
  2022. {
  2023.     if (data == NULL)
  2024.         return;
  2025.  
  2026.     /* week:
  2027.      *  0: not specified
  2028.      *  0x1~0x36: valid week
  2029.      *  0x37~0xfe: reserved
  2030.      *  0xff: model year is specified
  2031.      */
  2032.     if ((data[0] == 0) || ((data[0] >= 0x37) && (data[0] <= 0xfe)))
  2033.         prxcap->manufacture_week = 0;
  2034.     else
  2035.         prxcap->manufacture_week = data[0];
  2036.  
  2037.     /* year:
  2038.      *  0x0~0xf: reserved
  2039.      *  0x10~0xff: year of manufacture,
  2040.      *      or model year(if specified by week=0xff)
  2041.      */
  2042.     prxcap->manufacture_year =
  2043.         (data[1] <= 0xf)?0:data[1];
  2044. }
  2045.  
  2046. static void Edid_VersionParse(struct rx_cap *prxcap,
  2047.                   unsigned char *data)
  2048. {
  2049.     if (data == NULL)
  2050.         return;
  2051.  
  2052.     /*
  2053.      *  0x1: edid version 1
  2054.      *  0x0,0x2~0xff: reserved
  2055.      */
  2056.     prxcap->edid_version = (data[0] == 0x1) ? 1 : 0;
  2057.  
  2058.     /*
  2059.      *  0x0~0x4: revision number
  2060.      *  0x5~0xff: reserved
  2061.      */
  2062.     prxcap->edid_revision = (data[1] < 0x5) ? data[1] : 0;
  2063. }
  2064.  
  2065. static void Edid_PhyscialSizeParse(struct rx_cap *pRxCap,
  2066.         unsigned char *data)
  2067. {
  2068.     if ((data[0] != 0) && (data[1] != 0)) {
  2069.         pRxCap->physcial_weight = data[0];
  2070.         pRxCap->physcial_height = data[1];
  2071.     }
  2072. }
  2073.  
  2074. /* if edid block 0 are all zeros, then consider RX as HDMI device */
  2075. static int edid_zero_data(unsigned char *buf)
  2076. {
  2077.     int sum = 0;
  2078.     int i = 0;
  2079.  
  2080.     for (i = 0; i < 128; i++)
  2081.         sum += buf[i];
  2082.  
  2083.     if (sum == 0) {
  2084.         pr_info("hdmi_debug: assuming HDMI device\n");
  2085.         return 1;
  2086.     } else {
  2087.         pr_info("hdmi_debug: not assuming HDMI device\n");
  2088.         return 0;
  2089.     }
  2090. }
  2091.  
  2092. static void dump_dtd_info(struct dtd *t)
  2093. {
  2094.     pr_info(EDID "%s[%d]\n", __func__, __LINE__);
  2095.     /*pr_info("hdmi_debug: entered dump_dtd_info()\n");*/
  2096. #define PR(a) pr_info(EDID "%s: %d\n", #a, t->a)
  2097.     PR(pixel_clock);
  2098.     PR(h_active);
  2099.     PR(h_blank);
  2100.     PR(v_active);
  2101.     PR(v_blank);
  2102.     PR(h_sync_offset);
  2103.     PR(h_sync);
  2104.     PR(v_sync_offset);
  2105.     PR(v_sync);
  2106. }
  2107.  
  2108. static void Edid_DTD_parsing(struct rx_cap *prxcap, unsigned char *data)
  2109. {
  2110.     struct hdmi_format_para *para = NULL;
  2111.     struct dtd *t = &prxcap->dtd[prxcap->dtd_idx];
  2112.  
  2113.     memset(t, 0, sizeof(struct dtd));
  2114.     t->pixel_clock = data[0] + (data[1] << 8);
  2115.     t->h_active = (((data[4] >> 4) & 0xf) << 8) + data[2];
  2116.     t->h_blank = ((data[4] & 0xf) << 8) + data[3];
  2117.     t->v_active = (((data[7] >> 4) & 0xf) << 8) + data[5];
  2118.     t->v_blank = ((data[7] & 0xf) << 8) + data[6];
  2119.     t->h_sync_offset = (((data[11] >> 6) & 0x3) << 8) + data[8];
  2120.     t->h_sync = (((data[11] >> 4) & 0x3) << 8) + data[9];
  2121.     t->v_sync_offset = (((data[11] >> 2) & 0x3) << 4) +
  2122.         ((data[10] >> 4) & 0xf);
  2123.     t->v_sync = (((data[11] >> 0) & 0x3) << 4) + ((data[10] >> 0) & 0xf);
  2124. /*
  2125.  * Special handling of 1080i60hz, 1080i50hz
  2126.  */
  2127.     if ((t->pixel_clock == 7425) && (t->h_active == 1920) &&
  2128.         (t->v_active == 1080)) {
  2129.         t->v_active = t->v_active / 2;
  2130.         t->v_blank = t->v_blank / 2;
  2131.     }
  2132. /*
  2133.  * Special handling of 480i60hz, 576i50hz
  2134.  */
  2135.     /*pr_info("hdmi_debug: suppressing the special_handling_of_480i60hz,_576i50hz routine\n");
  2136.     pr_info("hdmi_debug: because this routine triggers on 1440 horizontal resolution, which we have...\n");
  2137.     pr_info("hdmi_debug: and (((t->flags) >> 1) & 0x3) == 0)\n");
  2138.     pr_info("hdmi_debug: we don't know how to print t->flags; we get error: has type 'struct hdmi_format_para *' trying to print as percent_d\n");*/
  2139.     /*if (((((t->flags) >> 1) & 0x3) == 0) && (t->h_active == 1440)) {
  2140.         if (t->pixel_clock == 2700)
  2141.             goto next;
  2142.         if ((t->pixel_clock - 2700) < 10)
  2143.             t->pixel_clock = 2702;
  2144. next:
  2145.         t->v_active = t->v_active / 2;
  2146.         t->v_blank = t->v_blank / 2;
  2147.     }*/
  2148. /*
  2149.  * call hdmi_match_dtd_paras() to check t is matched with VIC
  2150.  */
  2151.     para = hdmi_match_dtd_paras(t);
  2152.     /*pr_info("hdmi_debug: \"para\" is the return value of hdmi_match_dtd_paras() - what c file is this in? (not this [hdmi_tx_edid.c])\n");
  2153.     pr_info("hdmi_debug: we don't know how to print para; we get error: has type 'struct hdmi_format_para *' trying to print as percent_d\n");
  2154.     pr_info("hdmi_debug: is a pointer? how does one print the value(s) of the pointer target?\n");*/
  2155.     if (para) {
  2156.         t->vic = para->vic;
  2157.         prxcap->preferred_mode = prxcap->dtd[0].vic; /* Select dtd0 */
  2158.         pr_info(EDID "get dtd%d vic: %d\n",
  2159.             prxcap->dtd_idx, para->vic);
  2160.         prxcap->dtd_idx++;
  2161.     } else {
  2162.         /*pr_info("hdmi_debug: tdump_dtd_info being called because no var/obj \"para\" (or para is 0)\n");
  2163.         pr_info("hdmi_debug: otherwise we would be setting the preferred mode to the first dtd VIC\n");*/
  2164.         dump_dtd_info(t);
  2165.     }
  2166. }
  2167.  
  2168. static void edid_check_pcm_declare(struct rx_cap *prxcap)
  2169. {
  2170.     int idx_pcm = 0;
  2171.     int i;
  2172.  
  2173.     if (!prxcap->AUD_count)
  2174.         return;
  2175.  
  2176.     /* Try to find more than 1 PCMs, RxAudioCap[0] is always basic audio */
  2177.     for (i = 1; i < prxcap->AUD_count; i++) {
  2178.         if (prxcap->RxAudioCap[i].audio_format_code ==
  2179.             prxcap->RxAudioCap[0].audio_format_code) {
  2180.             idx_pcm = i;
  2181.             break;
  2182.         }
  2183.     }
  2184.  
  2185.     /* Remove basic audio */
  2186.     if (idx_pcm) {
  2187.         for (i = 0; i < prxcap->AUD_count - 1; i++)
  2188.             memcpy(&prxcap->RxAudioCap[i],
  2189.                    &prxcap->RxAudioCap[i + 1],
  2190.                    sizeof(struct rx_audiocap));
  2191.         /* Clear the last audio declaration */
  2192.         memset(&prxcap->RxAudioCap[i], 0, sizeof(struct rx_audiocap));
  2193.         prxcap->AUD_count--;
  2194.     }
  2195. }
  2196.  
  2197. static void hdrinfo_to_vinfo(struct vinfo_s *info, struct rx_cap *prxcap)
  2198. {
  2199.     unsigned int  k, l;
  2200.     /*static hdr*/
  2201.     info->hdr_info.hdr_support =
  2202.         (prxcap->hdr_sup_eotf_sdr << 0) |
  2203.         (prxcap->hdr_sup_eotf_hdr << 1) |
  2204.         (prxcap->hdr_sup_eotf_smpte_st_2084 << 2) |
  2205.         (prxcap->hdr_sup_eotf_hlg << 3);
  2206.     memcpy(info->hdr_info.rawdata, prxcap->hdr_rawdata, 7);
  2207.     /*dynamic hdr*/
  2208.     for (l = 0; l < 4; l++) {
  2209.         if (prxcap->hdr_dynamic_info[l].type == 0) {
  2210.             memset(&info->hdr_info.dynamic_info[l],
  2211.                 0, sizeof(struct hdr_dynamic));
  2212.             continue;
  2213.         }
  2214.         info->hdr_info.dynamic_info[l].type =
  2215.             prxcap->hdr_dynamic_info[l].type;
  2216.         info->hdr_info.dynamic_info[l].of_len =
  2217.             prxcap->hdr_dynamic_info[l].hd_len - 3;
  2218.         info->hdr_info.dynamic_info[l].support_flags =
  2219.             prxcap->hdr_dynamic_info[l].support_flags;
  2220.         for (k = 0; k < (prxcap->hdr_dynamic_info[l].hd_len - 3); k++) {
  2221.             info->hdr_info.dynamic_info[l].optional_fields[k] =
  2222.                 prxcap->hdr_dynamic_info[l].optional_fields[k];
  2223.         }
  2224.     }
  2225.     /*hdr 10+*/
  2226.     memcpy(&info->hdr_info.hdr10plus_info,
  2227.            &prxcap->hdr10plus_info, sizeof(struct hdr10_plus_info));
  2228.  
  2229.     info->hdr_info.colorimetry_support =
  2230.         prxcap->colorimetry_data;
  2231.     info->hdr_info.lumi_max = prxcap->hdr_lum_max;
  2232.     info->hdr_info.lumi_avg = prxcap->hdr_lum_avg;
  2233.     info->hdr_info.lumi_min = prxcap->hdr_lum_min;
  2234.     pr_info(EDID "update rx hdr info %x at edid parsing\n",
  2235.         info->hdr_info.hdr_support);
  2236. }
  2237.  
  2238. static bool is_4k60_supported(struct rx_cap *prxcap)
  2239. {
  2240.     int i = 0;
  2241.     pr_info("hdmi_debug: checking 4k support\n");
  2242.  
  2243.     if (!prxcap) {
  2244.         pr_info("hdmi_debug: no 4k support detected (no !prxcap)\n");
  2245.         return false;
  2246.     }
  2247.  
  2248.     for (i = 0; (i < prxcap->VIC_count) && (i < VIC_MAX_NUM); i++) {
  2249.         if (((prxcap->VIC[i] & 0xff) == HDMI_3840x2160p50_16x9) ||
  2250.             ((prxcap->VIC[i] & 0xff) == HDMI_3840x2160p60_16x9)) {
  2251.             pr_info("hdmi_debug: 4k support detected (HDMI_3840x2160p50_16x9 or HDMI_3840x2160p60_16x9)\n");
  2252.             return true;
  2253.         }
  2254.     }
  2255.     return false;
  2256. }
  2257.  
  2258. static void rxlatency_to_vinfo(struct vinfo_s *info, struct rx_cap *rx)
  2259. {
  2260.     if (!info || !rx)
  2261.         return;
  2262.     info->rx_latency.vLatency = rx->vLatency;
  2263.     info->rx_latency.aLatency = rx->aLatency;
  2264.     info->rx_latency.i_vLatency = rx->i_vLatency;
  2265.     info->rx_latency.i_aLatency = rx->i_aLatency;
  2266. }
  2267.  
  2268. static void Edid_Descriptor_PMT(struct rx_cap *prxcap,
  2269.                 struct vesa_standard_timing *t,
  2270.                 unsigned char *data)
  2271. {
  2272.     struct hdmi_format_para *para = NULL;
  2273.  
  2274.     t->tmds_clk = data[0] + (data[1] << 8);
  2275.     t->hactive = data[2] + (((data[4] >> 4) & 0xf) << 8);
  2276.     t->hblank = data[3] + ((data[4] & 0xf) << 8);
  2277.     t->vactive = data[5] + (((data[7] >> 4) & 0xf) << 8);
  2278.     t->vblank = data[6] + ((data[7] & 0xf) << 8);
  2279.     para = hdmi_get_vesa_paras(t);
  2280.     if (para && ((para->vic) < (HDMI_3840x2160p60_64x27 + 1))) {
  2281.         prxcap->native_VIC = para->vic;
  2282.         pr_info("hdmitx: get PMT vic: %d\n", para->vic);
  2283.     }
  2284.     if (para && ((para->vic) >= HDMITX_VESA_OFFSET))
  2285.         store_vesa_idx(prxcap, para->vic);
  2286. }
  2287.  
  2288. static void Edid_Descriptor_PMT2(struct rx_cap *prxcap,
  2289.                  struct vesa_standard_timing *t,
  2290.                  unsigned char *data)
  2291. {
  2292.     struct hdmi_format_para *para = NULL;
  2293.  
  2294.     t->tmds_clk = data[0] + (data[1] << 8);
  2295.     t->hactive = data[2] + (((data[4] >> 4) & 0xf) << 8);
  2296.     t->hblank = data[3] + ((data[4] & 0xf) << 8);
  2297.     t->vactive = data[5] + (((data[7] >> 4) & 0xf) << 8);
  2298.     t->vblank = data[6] + ((data[7] & 0xf) << 8);
  2299.     para = hdmi_get_vesa_paras(t);
  2300.     if (para && ((para->vic) >= HDMITX_VESA_OFFSET))
  2301.         store_vesa_idx(prxcap, para->vic);
  2302. }
  2303.  
  2304. static void Edid_CVT_timing_3bytes(struct rx_cap *prxcap,
  2305.                    struct vesa_standard_timing *t,
  2306.                    const unsigned char *data)
  2307. {
  2308.     struct hdmi_format_para *para = NULL;
  2309.  
  2310.     t->hactive = ((data[0] + (((data[1] >> 4) & 0xf) << 8)) + 1) * 2;
  2311.     switch ((data[1] >> 2) & 0x3) {
  2312.     case 0:
  2313.         t->vactive = t->hactive * 3 / 4;
  2314.         break;
  2315.     case 1:
  2316.         t->vactive = t->hactive * 9 / 16;
  2317.         break;
  2318.     case 2:
  2319.         t->vactive = t->hactive * 5 / 8;
  2320.         break;
  2321.     case 3:
  2322.     default:
  2323.         t->vactive = t->hactive * 3 / 5;
  2324.         break;
  2325.     }
  2326.     switch ((data[2] >> 5) & 0x3) {
  2327.     case 0:
  2328.         t->hsync = 50;
  2329.         break;
  2330.     case 1:
  2331.         t->hsync = 60;
  2332.         break;
  2333.     case 2:
  2334.         t->hsync = 75;
  2335.         break;
  2336.     case 3:
  2337.     default:
  2338.         t->hsync = 85;
  2339.         break;
  2340.     }
  2341.     para = hdmi_get_vesa_paras(t);
  2342.     if (para)
  2343.         t->vesa_timing = para->vic;
  2344. }
  2345.  
  2346. static void Edid_CVT_timing(struct rx_cap *prxcap, unsigned char *data)
  2347. {
  2348.     int i;
  2349.     struct vesa_standard_timing t;
  2350.  
  2351.     for (i = 0; i < 4; i++) {
  2352.         memset(&t, 0, sizeof(struct vesa_standard_timing));
  2353.         Edid_CVT_timing_3bytes(prxcap, &t, &data[i * 3]);
  2354.         if (t.vesa_timing)
  2355.             store_vesa_idx(prxcap, t.vesa_timing);
  2356.     }
  2357. }
  2358.  
  2359. int hdmitx_edid_parse(struct hdmitx_dev *hdmitx_device)
  2360. {
  2361.     unsigned char CheckSum;
  2362.     unsigned char zero_numbers;
  2363.     unsigned char BlockCount;
  2364.     unsigned char *EDID_buf;
  2365.     int i, j, ret_val;
  2366.     int idx[4];
  2367.     struct rx_cap *prxcap = &hdmitx_device->rxcap;
  2368.     struct dv_info *dv = &hdmitx_device->rxcap.dv_info;
  2369.     struct vinfo_s *info = NULL;
  2370.     unsigned int max_tmds_clk = 0;
  2371.  
  2372.     if (check_dvi_hdmi_edid_valid(hdmitx_device->EDID_buf)) {
  2373.         EDID_buf = hdmitx_device->EDID_buf;
  2374.         hdmitx_device->edid_parsing = 1;
  2375.         memcpy(hdmitx_device->EDID_buf1, hdmitx_device->EDID_buf,
  2376.             EDID_MAX_BLOCK * 128);
  2377.     } else
  2378.         EDID_buf = hdmitx_device->EDID_buf1;
  2379.  
  2380.     if (check_dvi_hdmi_edid_valid(hdmitx_device->EDID_buf1))
  2381.         hdmitx_device->edid_parsing = 1;
  2382.  
  2383.     hdmitx_device->edid_ptr = EDID_buf;
  2384.     pr_info(EDID "EDID Parser:\n");
  2385.     /* Calculate the EDID hash for special use */
  2386.     memset(hdmitx_device->EDID_hash, 0,
  2387.         ARRAY_SIZE(hdmitx_device->EDID_hash));
  2388.     edid_hash_calc(hdmitx_device->EDID_hash, hdmitx_device->EDID_buf, 256);
  2389.  
  2390.     ret_val = Edid_DecodeHeader(&hdmitx_device->hdmi_info, &EDID_buf[0]);
  2391.  
  2392.     for (i = 0, CheckSum = 0 ; i < 128 ; i++) {
  2393.         CheckSum += EDID_buf[i];
  2394.         CheckSum &= 0xFF;
  2395.     }
  2396.  
  2397.     if (CheckSum != 0)
  2398.         pr_info(EDID "PLUGIN_DVI_OUT\n");
  2399.  
  2400.     Edid_ParsingIDManufacturerName(&hdmitx_device->rxcap, &EDID_buf[8]);
  2401.     Edid_ParsingIDProductCode(&hdmitx_device->rxcap, &EDID_buf[0x0A]);
  2402.     Edid_ParsingIDSerialNumber(&hdmitx_device->rxcap, &EDID_buf[0x0C]);
  2403.  
  2404.     Edid_EstablishedTimings(&hdmitx_device->rxcap, &EDID_buf[0x23]);
  2405.     Edid_StandardTiming(&hdmitx_device->rxcap, &EDID_buf[0x26], 8);
  2406.  
  2407.     Edid_ManufactureDateParse(&hdmitx_device->rxcap, &EDID_buf[16]);
  2408.  
  2409.     Edid_VersionParse(&hdmitx_device->rxcap, &EDID_buf[18]);
  2410.  
  2411.     Edid_PhyscialSizeParse(&hdmitx_device->rxcap, &EDID_buf[21]);
  2412.  
  2413.     Edid_DecodeStandardTiming(&hdmitx_device->hdmi_info, &EDID_buf[26], 8);
  2414.     Edid_ParseCEADetailedTimingDescriptors(&hdmitx_device->hdmi_info,
  2415.         4, 0x36, &EDID_buf[0]);
  2416.  
  2417.     BlockCount = EDID_buf[0x7E];
  2418.     hdmitx_device->rxcap.blk0_chksum = EDID_buf[0x7F];
  2419.  
  2420.     if (BlockCount == 0) {
  2421.         pr_info(EDID "EDID BlockCount=0\n");
  2422.         hdmitx_edid_set_default_vic(hdmitx_device);
  2423.  
  2424.         /* DVI case judgement: only contains one block and
  2425.          * checksum valid
  2426.          */
  2427.         CheckSum = 0;
  2428.         zero_numbers = 0;
  2429.         for (i = 0; i < 128; i++) {
  2430.             CheckSum += EDID_buf[i];
  2431.             if (EDID_buf[i] == 0)
  2432.                 zero_numbers++;
  2433.         }
  2434.         pr_info(EDID "edid blk0 checksum:%d ext_flag:%d\n",
  2435.             CheckSum, EDID_buf[0x7e]);
  2436.         if ((CheckSum & 0xff) == 0)
  2437.             hdmitx_device->rxcap.ieeeoui = 0;
  2438.         else
  2439.             hdmitx_device->rxcap.ieeeoui = HDMI_IEEEOUI;
  2440.         if (zero_numbers > 120)
  2441.             hdmitx_device->rxcap.ieeeoui = HDMI_IEEEOUI;
  2442.  
  2443.         return 0; /* do nothing. */
  2444.     }
  2445.  
  2446.     /* Note: some DVI monitor have more than 1 block */
  2447.     if ((BlockCount == 1) && (EDID_buf[0x81] == 1)) {
  2448.         hdmitx_device->rxcap.ieeeoui = 0;
  2449.         hdmitx_device->rxcap.VIC_count = 0x3;
  2450.         hdmitx_device->rxcap.VIC[0] = HDMI_720x480p60_16x9;
  2451.         hdmitx_device->rxcap.VIC[1] = HDMI_1280x720p60_16x9;
  2452.         hdmitx_device->rxcap.VIC[2] = HDMI_1920x1080p60_16x9;
  2453.         hdmitx_device->rxcap.native_VIC = HDMI_720x480p60_16x9;
  2454.         hdmitx_device->vic_count = hdmitx_device->rxcap.VIC_count;
  2455.         pr_info(EDID "set default vic\n");
  2456.         return 0;
  2457.     } else if (BlockCount > EDID_MAX_BLOCK) {
  2458.         BlockCount = EDID_MAX_BLOCK;
  2459.     }
  2460.  
  2461.     for (i = 1 ; i <= BlockCount ; i++) {
  2462.         if ((BlockCount > 1) && (i == 1))
  2463.             CheckSum = 0;      /* ignore the block1 data */
  2464.         else {
  2465.             if (((BlockCount == 1) && (i == 1)) ||
  2466.                 ((BlockCount > 1) && (i == 2)))
  2467.                 Edid_Parse_check_HDMI_VSDB(
  2468.                     hdmitx_device,
  2469.                     &EDID_buf[i * 128]);
  2470.  
  2471.             for (j = 0, CheckSum = 0 ; j < 128 ; j++) {
  2472.                 CheckSum += EDID_buf[i*128 + j];
  2473.                 CheckSum &= 0xFF;
  2474.             }
  2475.             if (CheckSum == 0) {
  2476.                 Edid_MonitorCapable861(
  2477.                     &hdmitx_device->hdmi_info,
  2478.                     EDID_buf[i * 128 + 3]);
  2479.                 ret_val = Edid_ParsingCEADataBlockCollection(
  2480.                     hdmitx_device, &EDID_buf[i * 128]);
  2481.                 Edid_ParseCEADetailedTimingDescriptors(
  2482.                     &hdmitx_device->hdmi_info, 5,
  2483.                     EDID_buf[i * 128 + 2],
  2484.                     &EDID_buf[i * 128]);
  2485.             }
  2486.         }
  2487.  
  2488.         hdmitx_edid_block_parse(hdmitx_device, &(EDID_buf[i*128]));
  2489.     }
  2490.  
  2491.     /* EDID parsing complete - check if 4k60/50 DV can truly be supported */
  2492.     pr_info("hdmi_debug: checking 4k60/50 DV support\n");
  2493.     dv = &prxcap->dv_info;
  2494.     pr_info("hdmi_debug: dv->ieeeoui is: %d and dv->ver is: %d\n", dv->ieeeoui, dv->ver);
  2495.     pr_info("hdmi_debug: we need to see DV_IEEE_OUI and version lower than or equal to 2\n");
  2496.     pr_info("hdmi_debug: to engage the routine that works with Max_TMDS_Clocks 1 & 2\n");
  2497.     pr_info("hdmi_debug: and quintuples either of them to set the max_tmds_clk value\n");
  2498.     pr_info("hdmi_debug: ... forcing DV_IEEE_OUI\n");
  2499.     dv->ieeeoui = DV_IEEE_OUI; /*marker*/
  2500.     if ((dv->ieeeoui == DV_IEEE_OUI) && (dv->ver <= 2)) {
  2501.         pr_info("hdmi_debug: (dv->ieeeoui == DV_IEEE_OUI) && (dv->ver <= 2)\n");
  2502.         pr_info("hdmi_debug: dv->ieeeoui: %d\n", dv->ieeeoui);
  2503.         pr_info("hdmi_debug: dv->ver: %d\n", dv->ver);
  2504.         /* check max tmds rate to determine if 4k60 DV can truly be supported.*/
  2505.         pr_info("hdmi_debug: checking for Max_TMDS_Clock2\n");
  2506.         if (tmds2) {
  2507.             pr_info("hdmi_debug: forcing Max_TMDS_Clock2 per bootargs");
  2508.             pr_info("hdmi_debug: set to min x*5 > 594 to pass later sup_2160p60hz checks");
  2509.             prxcap->Max_TMDS_Clock2 = tmds2;
  2510.             pr_info("hdmi_debug: Max_TMDS_Clock2 now: %d\n", prxcap->Max_TMDS_Clock2);
  2511.         }
  2512.         if (prxcap->Max_TMDS_Clock2) {
  2513.             pr_info("hdmi_debug: found Max_TMDS_Clock2: %d\n", prxcap->Max_TMDS_Clock2);
  2514.             max_tmds_clk = prxcap->Max_TMDS_Clock2 * 5;
  2515.             pr_info("hdmi_debug: max_tmds_clk set to *5: %d\n", max_tmds_clk);
  2516.         } else {
  2517.             /* Default min is 74.25 / 5 */
  2518.             pr_info("hdmi_debug: didn't find Max_TMDS_Clock2, using Max_TMDS_Clock1\n");
  2519.             if (prxcap->Max_TMDS_Clock1 < 0xf) {
  2520.                 pr_info("hdmi_debug: Max_TMDS_Clock1 < 0xf: %d\n", prxcap->Max_TMDS_Clock1);
  2521.                 prxcap->Max_TMDS_Clock1 = 0x1e;
  2522.                 pr_info("hdmi_debug: changing Max_TMDS_Clock1 value to: %d\n", prxcap->Max_TMDS_Clock1);
  2523.             }
  2524.             max_tmds_clk = prxcap->Max_TMDS_Clock1 * 5;
  2525.             pr_info("hdmi_debug: max_tmds_clk set to Max_TMDS_Clock1 * 5: %d\n", max_tmds_clk);
  2526.         }
  2527.         if (dv->ver == 0)
  2528.             dv->sup_2160p60hz = dv->sup_2160p60hz &&
  2529.                         (max_tmds_clk >= 594);
  2530.  
  2531.         if ((dv->ver == 1) && (dv->length == 0xB)) {
  2532.             if (dv->low_latency == 0x00) {
  2533.                 /*standard mode */
  2534.                 dv->sup_2160p60hz = dv->sup_2160p60hz &&
  2535.                             (max_tmds_clk >= 594);
  2536.             } else if (dv->low_latency == 0x01) {
  2537.                 /* both standard and LL are supported. 4k60 LL DV support should/can be determined using video formats supported in the E-EDID as flag sup_2160p60hz might not be set.*/
  2538.                 if ((dv->sup_2160p60hz ||
  2539.                      is_4k60_supported(prxcap)) &&
  2540.                      (max_tmds_clk >= 594))
  2541.                     dv->sup_2160p60hz = 1;
  2542.                 else
  2543.                     dv->sup_2160p60hz = 0;
  2544.             }
  2545.         }
  2546.  
  2547.         if ((dv->ver == 1) && (dv->length == 0xE))
  2548.             dv->sup_2160p60hz = dv->sup_2160p60hz &&
  2549.                         (max_tmds_clk >= 594);
  2550.  
  2551.         if (dv->ver == 2) {
  2552.             /* 4k60 DV support should be determined using video
  2553.              * formats supported in the EEDID as flag sup_2160p60hz
  2554.              * is not applicable for VSVDB V2.
  2555.              */
  2556.             if (is_4k60_supported(prxcap) && (max_tmds_clk >= 594)) {
  2557.                 dv->sup_2160p60hz = 1; pr_info("hdmi_debug: dv->sup_2160p60hz: %d\n", dv->sup_2160p60hz);
  2558.             } else {
  2559.                 dv->sup_2160p60hz = 0; pr_info("hdmi_debug: dv->sup_2160p60hz: %d\n", dv->sup_2160p60hz);
  2560.             }
  2561.         }
  2562.         if (dvsup) {
  2563.             pr_info("hdmi_debug: forcing dv->sup_2160p60hz = %d per bootargs\n", dvsup);
  2564.             dv->sup_2160p60hz = dvsup;
  2565.         }
  2566.     }
  2567.     edid_check_pcm_declare(&hdmitx_device->rxcap);
  2568. /*
  2569.  * Because DTDs are not able to represent some Video Formats, which can be
  2570.  * represented as SVDs and might be preferred by Sinks, the first DTD in the
  2571.  * base EDID data structure and the first SVD in the first CEA Extension can
  2572.  * differ. When the first DTD and SVD do not match and the total number of
  2573.  * DTDs defining Native Video Formats in the whole EDID is zero, the first
  2574.  * SVD shall take precedence.
  2575.  */
  2576.     if (!prxcap->flag_vfpdb && (prxcap->preferred_mode != prxcap->VIC[0]) &&
  2577.         (prxcap->number_of_dtd == 0)) {
  2578.         pr_info(EDID "change preferred_mode from %d to %d\n",
  2579.             prxcap->preferred_mode, prxcap->VIC[0]);
  2580.         prxcap->preferred_mode = prxcap->VIC[0];
  2581.     }
  2582.  
  2583.     idx[0] = EDID_DETAILED_TIMING_DES_BLOCK0_POS;
  2584.     idx[1] = EDID_DETAILED_TIMING_DES_BLOCK1_POS;
  2585.     idx[2] = EDID_DETAILED_TIMING_DES_BLOCK2_POS;
  2586.     idx[3] = EDID_DETAILED_TIMING_DES_BLOCK3_POS;
  2587.     for (i = 0; i < 4; i++) {
  2588.         if ((EDID_buf[idx[i]]) && (EDID_buf[idx[i] + 1])) {
  2589.             struct vesa_standard_timing t;
  2590.  
  2591.             memset(&t, 0, sizeof(struct vesa_standard_timing));
  2592.             if (i == 0)
  2593.                 Edid_Descriptor_PMT(prxcap, &t,
  2594.                             &EDID_buf[idx[i]]);
  2595.             if (i == 1)
  2596.                 Edid_Descriptor_PMT2(prxcap, &t,
  2597.                              &EDID_buf[idx[i]]);
  2598.             continue;
  2599.         }
  2600.         switch (EDID_buf[idx[i] + 3]) {
  2601.         case TAG_STANDARD_TIMINGS:
  2602.             Edid_StandardTiming(prxcap, &EDID_buf[idx[i] + 5], 6);
  2603.             break;
  2604.         case TAG_CVT_TIMING_CODES:
  2605.             Edid_CVT_timing(prxcap, &EDID_buf[idx[i] + 6]);
  2606.             break;
  2607.         case TAG_ESTABLISHED_TIMING_III:
  2608.             Edid_StandardTimingIII(prxcap, &EDID_buf[idx[i] + 6]);
  2609.             break;
  2610.         case TAG_RANGE_LIMITS:
  2611.             break;
  2612.         case TAG_DISPLAY_PRODUCT_NAME_STRING:
  2613.             Edid_ReceiverProductNameParse(prxcap,
  2614.                               &EDID_buf[idx[i] + 5]);
  2615.             break;
  2616.         default:
  2617.             break;
  2618.         }
  2619.     }
  2620.  
  2621.     if (hdmitx_edid_search_IEEEOUI(&EDID_buf[128])) {
  2622.         prxcap->ieeeoui = HDMI_IEEEOUI;
  2623.         pr_info(EDID "find IEEEOUT\n");
  2624.         pr_info("hdmi_debug: found IEEEOUT, setting prxcap->ieeeoui = HDMI_IEEEOUI\n");
  2625.     } else {
  2626.         prxcap->ieeeoui = 0x0;
  2627.         pr_info(EDID "not find IEEEOUT\n");
  2628.         pr_info("hdmi_debug: not find IEEEOUT, setting prxcap->ieeeoui = 0x0\n");
  2629.     }
  2630.  
  2631.     if ((prxcap->ieeeoui != HDMI_IEEEOUI) || (prxcap->ieeeoui == 0x0) ||
  2632.         (prxcap->VIC_count == 0))
  2633.         hdmitx_edid_set_default_vic(hdmitx_device);
  2634.  
  2635.     /* strictly DVI device judgement */
  2636.     /* valid EDID & no audio tag & no IEEEOUI */
  2637.     if (edid_check_valid(&EDID_buf[0]) &&
  2638.         !hdmitx_edid_search_IEEEOUI(&EDID_buf[128])) {
  2639.         prxcap->ieeeoui = 0x0;
  2640.         pr_info(EDID "sink is DVI device\n");
  2641.     } else
  2642.         prxcap->ieeeoui = HDMI_IEEEOUI;
  2643.  
  2644.     if (edid_zero_data(EDID_buf))
  2645.         prxcap->ieeeoui = HDMI_IEEEOUI;
  2646.  
  2647.     if ((!prxcap->AUD_count) && (!prxcap->ieeeoui))
  2648.         hdmitx_edid_set_default_aud(hdmitx_device);
  2649.  
  2650.     edid_save_checkvalue(EDID_buf, BlockCount + 1, prxcap);
  2651.  
  2652.     i = hdmitx_edid_dump(hdmitx_device, (char *)(hdmitx_device->tmp_buf),
  2653.         HDMI_TMP_BUF_SIZE);
  2654.     hdmitx_device->tmp_buf[i] = 0;
  2655.  
  2656.     if (!hdmitx_edid_check_valid_blocks(&EDID_buf[0])) {
  2657.         prxcap->ieeeoui = HDMI_IEEEOUI;
  2658.         pr_info(EDID "Invalid edid, assuming RX is an HDMI device\n");
  2659.     }
  2660.     /* update RX HDR information */
  2661.     info = get_current_vinfo();
  2662.     if (info) {
  2663.         /*update hdmi checksum to vout*/
  2664.         memcpy(info->hdmichecksum, prxcap->chksum, 10);
  2665.         if (!((strncmp(info->name, "480cvbs", 7) == 0) ||
  2666.         (strncmp(info->name, "576cvbs", 7) == 0) ||
  2667.         (strncmp(info->name, "null", 4) == 0))) {
  2668.             hdrinfo_to_vinfo(info, prxcap);
  2669.             rxlatency_to_vinfo(info, prxcap);
  2670.         }
  2671.     }
  2672.     /* if sup_2160p60hz of dv is true, check the MAX_TMDS*/
  2673.     if (dv->sup_2160p60hz) {
  2674.         pr_info("hdmi_debug: dv->sup_2160p60hz exists\n");
  2675.         pr_info("hdmi_debug: need prxcap->Max_TMDS_Clock2 * 5 >= 590\n");
  2676.         pr_info("hdmi_debug: or dv->sup_2160p60hz is turned off next\n");
  2677.         pr_info("hdmi_debug: checking...\n");
  2678.         if (prxcap->Max_TMDS_Clock2 * 5 < 590) {
  2679.             pr_info("... not passed\n");
  2680.             dv->sup_2160p60hz = 0;
  2681.             pr_info(EDID "clearing sup_2160p60hz\n");
  2682.         } else {
  2683.             pr_info("... passed\n");
  2684.         }
  2685.     } else {
  2686.         pr_info("hdmi_debug: dv->sup_2160p60hz does not exist\n");
  2687.     }
  2688.     return 0;
  2689.  
  2690. }
  2691.  
  2692. static struct dispmode_vic dispmode_vic_tab[] = {
  2693.     {"480i60hz", HDMI_480i60_16x9},
  2694.     {"480p60hz", HDMI_480p60_16x9},
  2695.     {"576i50hz", HDMI_576i50_16x9},
  2696.     {"576p50hz", HDMI_576p50_16x9},
  2697.     {"720p50hz", HDMI_720p50},
  2698.     {"720p60hz", HDMI_720p60},
  2699.     {"1080i50hz", HDMI_1080i50},
  2700.     {"1080i60hz", HDMI_1080i60},
  2701.     {"1080p50hz", HDMI_1080p50},
  2702.     {"1080p30hz", HDMI_1080p30},
  2703.     {"1080p25hz", HDMI_1080p25},
  2704.     {"1080p24hz", HDMI_1080p24},
  2705.     {"1080p60hz", HDMI_1080p60},
  2706.     {"2560x1080p50hz", HDMI_2560x1080p50_64x27},
  2707.     {"2560x1080p60hz", HDMI_2560x1080p60_64x27},
  2708.     {"2160p30hz", HDMI_4k2k_30},
  2709.     {"2160p25hz", HDMI_4k2k_25},
  2710.     {"2160p24hz", HDMI_4k2k_24},
  2711.     {"smpte24hz", HDMI_4k2k_smpte_24},
  2712.     {"smpte25hz", HDMI_4096x2160p25_256x135},
  2713.     {"smpte30hz", HDMI_4096x2160p30_256x135},
  2714.     {"smpte50hz420", HDMI_4096x2160p50_256x135_Y420},
  2715.     {"smpte60hz420", HDMI_4096x2160p60_256x135_Y420},
  2716.     {"2160p60hz420", HDMI_3840x2160p60_16x9_Y420},
  2717.     {"2160p50hz420", HDMI_3840x2160p50_16x9_Y420},
  2718.     {"smpte50hz", HDMI_4096x2160p50_256x135},
  2719.     {"smpte60hz", HDMI_4096x2160p60_256x135},
  2720.     {"2160p60hz", HDMI_4k2k_60},
  2721.     {"2160p50hz", HDMI_4k2k_50},
  2722.     {"640x480p60hz", HDMIV_640x480p60hz},
  2723.     {"800x480p60hz", HDMIV_800x480p60hz},
  2724.     {"800x600p60hz", HDMIV_800x600p60hz},
  2725.     {"852x480p60hz", HDMIV_852x480p60hz},
  2726.     {"854x480p60hz", HDMIV_854x480p60hz},
  2727.     {"1024x600p60hz", HDMIV_1024x600p60hz},
  2728.     {"1024x768p60hz", HDMIV_1024x768p60hz},
  2729.     {"1152x864p75hz", HDMIV_1152x864p75hz},
  2730.     {"1280x600p60hz", HDMIV_1280x600p60hz},
  2731.     {"1280x768p60hz", HDMIV_1280x768p60hz},
  2732.     {"1280x800p60hz", HDMIV_1280x800p60hz},
  2733.     {"1280x960p60hz", HDMIV_1280x960p60hz},
  2734.     {"1280x1024p60hz", HDMIV_1280x1024p60hz},
  2735.     {"1280x1024", HDMIV_1280x1024p60hz}, /* alias of "1280x1024p60hz" */
  2736.     {"1360x768p60hz", HDMIV_1360x768p60hz},
  2737.     {"1366x768p60hz", HDMIV_1366x768p60hz},
  2738.     {"1400x1050p60hz", HDMIV_1400x1050p60hz},
  2739.     {"1440x900p60hz", HDMIV_1440x900p60hz},
  2740.     {"1440x2560p60hz", HDMIV_1440x2560p60hz},
  2741.     {"1600x900p60hz", HDMIV_1600x900p60hz},
  2742.     {"1600x1200p60hz", HDMIV_1600x1200p60hz},
  2743.     {"1680x1050p60hz", HDMIV_1680x1050p60hz},
  2744.     {"1920x1200p60hz", HDMIV_1920x1200p60hz},
  2745.     {"2160x1200p90hz", HDMIV_2160x1200p90hz},
  2746.     {"2560x1080p60hz", HDMIV_2560x1080p60hz},
  2747.     {"2560x1440p60hz", HDMIV_2560x1440p60hz},
  2748.     {"2560x1600p60hz", HDMIV_2560x1600p60hz},
  2749.     {"3440x1440p60hz", HDMIV_3440x1440p60hz},
  2750. #if defined(CONFIG_ARCH_MESON64_ODROID_COMMON)
  2751.     {"480x320p60hz", HDMI_480x320p60_4x3},
  2752.     {"480x272p60hz", HDMI_480x272p60_4x3},
  2753.     {"480x800p60hz", HDMI_480x800p60_4x3},
  2754.     {"custombuilt", HDMI_CUSTOMBUILT},
  2755. #endif
  2756. };
  2757.  
  2758. int hdmitx_edid_VIC_support(enum hdmi_vic vic)
  2759. {
  2760.     int i;
  2761.  
  2762.     for (i = 0; i < ARRAY_SIZE(dispmode_vic_tab); i++) {
  2763.         if (vic == dispmode_vic_tab[i].VIC)
  2764.             return 1;
  2765.     }
  2766.  
  2767.     return 0;
  2768. }
  2769.  
  2770. enum hdmi_vic hdmitx_edid_vic_tab_map_vic(const char *disp_mode)
  2771. {
  2772.     enum hdmi_vic vic = HDMI_Unknown;
  2773.     int i;
  2774.  
  2775.     for (i = 0; i < ARRAY_SIZE(dispmode_vic_tab); i++) {
  2776.         if (strncmp(disp_mode, dispmode_vic_tab[i].disp_mode,
  2777.             strlen(dispmode_vic_tab[i].disp_mode)) == 0) {
  2778.             vic = dispmode_vic_tab[i].VIC;
  2779.             break;
  2780.         }
  2781.     }
  2782.  
  2783.     if (vic == HDMI_Unknown) {
  2784.         pr_info(EDID "not find mapped vic\n");
  2785.         pr_info("hdmi_debug: vic == HDMI_Unknown\n");
  2786.     }
  2787.     return vic;
  2788. }
  2789.  
  2790. const char *hdmitx_edid_vic_tab_map_string(enum hdmi_vic vic)
  2791. {
  2792.     int i;
  2793.     const char *disp_str = NULL;
  2794.  
  2795.     for (i = 0; i < ARRAY_SIZE(dispmode_vic_tab); i++) {
  2796.         if (vic == dispmode_vic_tab[i].VIC) {
  2797.             disp_str = dispmode_vic_tab[i].disp_mode;
  2798.             break;
  2799.         }
  2800.     }
  2801.  
  2802.     return disp_str;
  2803. }
  2804.  
  2805. const char *hdmitx_edid_vic_to_string(enum hdmi_vic vic)
  2806. {
  2807.     int i;
  2808.     const char *disp_str = NULL;
  2809.  
  2810.     for (i = 0; i < ARRAY_SIZE(dispmode_vic_tab); i++) {
  2811.         if (vic == dispmode_vic_tab[i].VIC) {
  2812.             disp_str = dispmode_vic_tab[i].disp_mode;
  2813.             break;
  2814.         }
  2815.     }
  2816.  
  2817.     return disp_str;
  2818. }
  2819.  
  2820. static bool is_rx_support_y420(struct hdmitx_dev *hdev)
  2821. {
  2822.     enum hdmi_vic vic = HDMI_Unknown;
  2823.  
  2824.     vic = hdmitx_edid_get_VIC(hdev, "2160p60hz420", 0);
  2825.     if (vic != HDMI_Unknown)
  2826.         return 1;
  2827.  
  2828.     vic = hdmitx_edid_get_VIC(hdev, "2160p50hz420", 0);
  2829.     if (vic != HDMI_Unknown)
  2830.         return 1;
  2831.  
  2832.     vic = hdmitx_edid_get_VIC(hdev, "smpte60hz420", 0);
  2833.     if (vic != HDMI_Unknown)
  2834.         return 1;
  2835.  
  2836.     vic = hdmitx_edid_get_VIC(hdev, "smpte50hz420", 0);
  2837.     if (vic != HDMI_Unknown)
  2838.         return 1;
  2839.  
  2840.     return 0;
  2841. }
  2842.  
  2843. /* With some TVs' EDIDs, some reported information may be ambiguous,
  2844.  * such as the EDID declares it supports 2160p60hz(Y444 8bit), but there is no valid
  2845.  * Max_TMDS_Clock2 to indicate that it can support a 5.94G signal.
  2846.  */
  2847. bool hdmitx_edid_check_valid_mode(struct hdmitx_dev *hdev,
  2848.     struct hdmi_format_para *para)
  2849. {
  2850.     bool valid = 0;
  2851.     struct rx_cap *prxcap = NULL;
  2852.     const struct dv_info *dv = &hdev->rxcap.dv_info;
  2853.     unsigned int rx_max_tmds_clk = 0;
  2854.     unsigned int calc_tmds_clk = 0;
  2855.     int i = 0;
  2856.     int svd_flag = 0;
  2857.     /* Default max color depth is 24 bit */
  2858.     enum hdmi_color_depth rx_y444_max_dc = COLORDEPTH_24B;
  2859.     enum hdmi_color_depth rx_y422_max_dc = COLORDEPTH_24B;
  2860.     enum hdmi_color_depth rx_y420_max_dc = COLORDEPTH_24B;
  2861.     enum hdmi_color_depth rx_rgb_max_dc = COLORDEPTH_24B;
  2862.    
  2863.     pr_info("hdmi_debug: entered hdmitx_edid_check_valid_mode()\n");
  2864.     pr_info("hdmi_debug: only called from hdmi_tx_main.c - once\n");
  2865.  
  2866.     if (!hdev || !para) {
  2867.         pr_info("hdmi_debug: no hdev or para vars/objs, returning 0\n");
  2868.         return 0;
  2869.     }
  2870.  
  2871.     if (strcmp(para->sname, "invalid") == 0) {
  2872.         pr_info("hdmi_debug: strcmp(para->sname, \"invalid\") == 0), returning 0\n");
  2873.         return 0;
  2874.     }
  2875.     /* exclude such as: 2160p60hz YCbCr444 10bit */
  2876.     switch (para->vic) {
  2877.     case HDMI_3840x2160p50_16x9:
  2878.     case HDMI_3840x2160p60_16x9:
  2879.     case HDMI_4096x2160p50_256x135:
  2880.     case HDMI_4096x2160p60_256x135:
  2881.     case HDMI_3840x2160p50_64x27:
  2882.     case HDMI_3840x2160p60_64x27:
  2883.         if ((para->cs == COLORSPACE_RGB444) ||
  2884.             (para->cs == COLORSPACE_YUV444))
  2885.             if (para->cd != COLORDEPTH_24B)
  2886.                 return 0;
  2887.         break;
  2888.     case HDMI_720x480i60_16x9:
  2889.     case HDMI_720x576i50_16x9:
  2890.         if (para->cs == COLORSPACE_YUV422)
  2891.             return 0;
  2892.     default:
  2893.         break;
  2894.     }
  2895.  
  2896.     prxcap = &hdev->rxcap;
  2897.  
  2898.     /* DVI case, only 8bit */
  2899.     if (prxcap->ieeeoui != HDMI_IEEEOUI) {
  2900.         if (para->cd != COLORDEPTH_24B)
  2901.             return 0;
  2902.     }
  2903.  
  2904.     /* target mode is not contained at RX SVD */
  2905.     for (i = 0; (i < prxcap->VIC_count) && (i < VIC_MAX_NUM); i++) {
  2906.         if ((para->vic & 0xff) == (prxcap->VIC[i] & 0xff))
  2907.             svd_flag = 1;
  2908.     }
  2909.     if (svd_flag == 0)
  2910.         return 0;
  2911.  
  2912.     /* Get RX Max_TMDS_Clock */
  2913.     pr_info("hdmi_debug: checking Max_TMDS_Clock2\n");
  2914.     if (prxcap->Max_TMDS_Clock2) {
  2915.         pr_info("hdmi_debug: found Max_TMDS_Clock2: %d\n", prxcap->Max_TMDS_Clock2);
  2916.         rx_max_tmds_clk = prxcap->Max_TMDS_Clock2 * 5;
  2917.         pr_info("hdmi_debug: setting rx_max_tmds_clk to 5*prxcap->Max_TMDS_Clock2: %d\n", rx_max_tmds_clk);
  2918.     } else {
  2919.         pr_info("hdmi_debug: no Max_TMDS_Clock2 found\n");
  2920.         /* Default min is 74.25 / 5 */
  2921.         if (prxcap->Max_TMDS_Clock1 < 0xf) {
  2922.             prxcap->Max_TMDS_Clock1 = 0x1e;
  2923.             pr_info("hdmi_debug: Max_TMDS_Clock1 < 0xf, re-setting Max_TMDS_Clock1: %d\n", prxcap->Max_TMDS_Clock1);
  2924.         } else {
  2925.             pr_info("hdmi_debug: prxcap->Max_TMDS_Clock1 !< 0xf, Max_TMDS_Clock1: %d\n", prxcap->Max_TMDS_Clock1);
  2926.         }
  2927.         rx_max_tmds_clk = prxcap->Max_TMDS_Clock1 * 5;
  2928.         pr_info("hdmi_debug: setting rx_max_tmds_clk to 5*prxcap->Max_TMDS_Clock1: %d\n", rx_max_tmds_clk);
  2929.     }
  2930.  
  2931.     calc_tmds_clk = para->tmds_clk;
  2932.     if (para->cs == COLORSPACE_YUV420) {
  2933.         calc_tmds_clk = calc_tmds_clk / 2;
  2934.         pr_info("hdmi_debug: para->cs == COLORSPACE_YUV420, halving calc_tmds_clk to: %d\n", calc_tmds_clk);
  2935.     }
  2936.     if (para->cs != COLORSPACE_YUV422) {
  2937.         pr_info("hdmi_debug: para->cs != COLORSPACE_YUV422\n");
  2938.         switch (para->cd) {
  2939.         case COLORDEPTH_30B:
  2940.             calc_tmds_clk = calc_tmds_clk * 5 / 4;
  2941.             pr_info("hdmi_debug: COLORDEPTH_30B, setting calc_tmds_clk * 5/4: %d\n", calc_tmds_clk);
  2942.             break;
  2943.         case COLORDEPTH_36B:
  2944.             calc_tmds_clk = calc_tmds_clk * 3 / 2;
  2945.             pr_info("hdmi_debug: COLORDEPTH_36B, setting calc_tmds_clk * 3/2: %d\n", calc_tmds_clk);
  2946.             break;
  2947.         case COLORDEPTH_48B:
  2948.             calc_tmds_clk = calc_tmds_clk * 2;
  2949.             pr_info("hdmi_debug: COLORDEPTH_48B, setting calc_tmds_clk * 2: %d\n", calc_tmds_clk);
  2950.             break;
  2951.         case COLORDEPTH_24B:
  2952.         default:
  2953.             calc_tmds_clk = calc_tmds_clk * 1;
  2954.             pr_info("hdmi_debug: COLORDEPTH default, setting calc_tmds_clk * 1: %d\n", calc_tmds_clk);
  2955.             break;
  2956.         }
  2957.     }
  2958.     calc_tmds_clk = calc_tmds_clk / 1000;
  2959.     pr_info("RX tmds clk: %d   Calc clk: %d\n", rx_max_tmds_clk,
  2960.         calc_tmds_clk);
  2961.     if (calc_tmds_clk < rx_max_tmds_clk)
  2962.         valid = 1;
  2963.     else
  2964.         return 0;
  2965.  
  2966.     if (para->cs == COLORSPACE_YUV444) {
  2967.         /* Rx may not support Y444 */
  2968.         if (!(prxcap->native_Mode & (1 << 5)))
  2969.             return 0;
  2970.         if ((prxcap->dc_y444 && prxcap->dc_30bit)
  2971.             || (dv->sup_10b_12b_444 == 0x1))
  2972.             rx_y444_max_dc = COLORDEPTH_30B;
  2973.         if ((prxcap->dc_y444 && prxcap->dc_36bit)
  2974.             || (dv->sup_10b_12b_444 == 0x2))
  2975.             rx_y444_max_dc = COLORDEPTH_36B;
  2976.         if (para->cd <= rx_y444_max_dc)
  2977.             valid = 1;
  2978.         else
  2979.             valid = 0;
  2980.         return valid;
  2981.     }
  2982.     if (para->cs == COLORSPACE_YUV422) {
  2983.         /* Rx may not support Y422 */
  2984.         if (!(prxcap->native_Mode & (1 << 4)))
  2985.             return 0;
  2986.         if (prxcap->dc_y444 && prxcap->dc_30bit)
  2987.             rx_y422_max_dc = COLORDEPTH_30B;
  2988.         if ((prxcap->dc_y444 && prxcap->dc_36bit)
  2989.             || (dv->sup_yuv422_12bit))
  2990.             rx_y422_max_dc = COLORDEPTH_36B;
  2991.         if (para->cd <= rx_y422_max_dc)
  2992.             valid = 1;
  2993.         else
  2994.             valid = 0;
  2995.         return valid;
  2996.     }
  2997.     if (para->cs == COLORSPACE_RGB444) {
  2998.         /* Always assume RX supports RGB444 */
  2999.         if ((prxcap->dc_30bit) || (dv->sup_10b_12b_444 == 0x1))
  3000.             rx_rgb_max_dc = COLORDEPTH_30B;
  3001.         if ((prxcap->dc_36bit) || (dv->sup_10b_12b_444 == 0x2))
  3002.             rx_rgb_max_dc = COLORDEPTH_36B;
  3003.         if (para->cd <= rx_rgb_max_dc)
  3004.             valid = 1;
  3005.         else
  3006.             valid = 0;
  3007.         return valid;
  3008.     }
  3009.     if (para->cs == COLORSPACE_YUV420) {
  3010.         if (!is_rx_support_y420(hdev))
  3011.             return 0;
  3012.         if (prxcap->dc_30bit_420)
  3013.             rx_y420_max_dc = COLORDEPTH_30B;
  3014.         if (prxcap->dc_36bit_420)
  3015.             rx_y420_max_dc = COLORDEPTH_36B;
  3016.         if (para->cd <= rx_y420_max_dc)
  3017.             valid = 1;
  3018.         else
  3019.             valid = 0;
  3020.         return valid;
  3021.     }
  3022.  
  3023.     return valid;
  3024. }
  3025.  
  3026. /* force_flag: 0 means check with RX's edid */
  3027. /* 1 means no check wich RX's edid */
  3028. enum hdmi_vic hdmitx_edid_get_VIC(struct hdmitx_dev *hdev,
  3029.     const char *disp_mode, char force_flag)
  3030. {
  3031.     struct rx_cap *prxcap = &hdev->rxcap;
  3032.     int  j;
  3033.     enum hdmi_vic vic = hdmitx_edid_vic_tab_map_vic(disp_mode);
  3034.    
  3035.     pr_info("hdmi_debug: entered hdmitx_edid_get_VIC()\n");
  3036.     pr_info("hdmi_debug: don't_check_RX's_edid is set to: %d\n", force_flag);
  3037.  
  3038.     if (vic != HDMI_Unknown) {
  3039.         if (force_flag == 0) {
  3040.             for (j = 0 ; j < prxcap->VIC_count ; j++) {
  3041.                 if (prxcap->VIC[j] == vic)
  3042.                     break;
  3043.             }
  3044.             if (j >= prxcap->VIC_count)
  3045.                 vic = HDMI_Unknown;
  3046.         }
  3047.     }
  3048.     return vic;
  3049. }
  3050.  
  3051. const char *hdmitx_edid_get_native_VIC(struct hdmitx_dev *hdmitx_device)
  3052. {
  3053.     struct rx_cap *prxcap = &hdmitx_device->rxcap;
  3054.  
  3055.     return hdmitx_edid_vic_to_string(prxcap->native_VIC);
  3056. }
  3057.  
  3058. /* Clear HDMI Hardware Module EDID RAM and EDID Buffer */
  3059. void hdmitx_edid_ram_buffer_clear(struct hdmitx_dev *hdmitx_device)
  3060. {
  3061.     unsigned int i = 0;
  3062.    
  3063.     pr_info("hdmi_debug: clearing hdmi hw module's EDID RAM and buffer\n");
  3064.    
  3065.     /* Clear HDMI Hardware Module EDID RAM */
  3066.     hdmitx_device->hwop.cntlddc(hdmitx_device, DDC_EDID_CLEAR_RAM, 0);
  3067.  
  3068.     /* Clear EDID Buffer */
  3069.     for (i = 0; i < EDID_MAX_BLOCK*128; i++)
  3070.         hdmitx_device->EDID_buf[i] = 0;
  3071.     for (i = 0; i < EDID_MAX_BLOCK*128; i++)
  3072.         hdmitx_device->EDID_buf1[i] = 0;
  3073. }
  3074.  
  3075. /* Clear the Parse result of HDMI Sink's EDID. */
  3076. void hdmitx_edid_clear(struct hdmitx_dev *hdmitx_device)
  3077. {
  3078.     char tmp[2] = {0};
  3079.     struct rx_cap *prxcap = &hdmitx_device->rxcap;
  3080.  
  3081.     memset(prxcap, 0, sizeof(struct rx_cap));
  3082.  
  3083.     pr_info("hdmi_debug: clearing EDID parse result\n");
  3084.  
  3085.     /* Note: in most cases, we think that rx is tv and the default
  3086.      * IEEEOUI is HDMI Identifier
  3087.      */
  3088.     prxcap->ieeeoui = HDMI_IEEEOUI;
  3089.  
  3090.     hdmitx_device->vic_count = 0;
  3091.     hdmitx_device->hdmi_info.vsdb_phy_addr.a = 0;
  3092.     hdmitx_device->hdmi_info.vsdb_phy_addr.b = 0;
  3093.     hdmitx_device->hdmi_info.vsdb_phy_addr.c = 0;
  3094.     hdmitx_device->hdmi_info.vsdb_phy_addr.d = 0;
  3095.     hdmitx_device->hdmi_info.vsdb_phy_addr.valid = 0;
  3096.     memset(&vsdb_local, 0, sizeof(struct vsdb_phyaddr));
  3097.     memset(&hdmitx_device->EDID_hash[0], 0,
  3098.         sizeof(hdmitx_device->EDID_hash));
  3099.     hdmitx_device->edid_parsing = 0;
  3100.     hdmitx_edid_set_default_aud(hdmitx_device);
  3101.     rx_set_hdr_lumi(&tmp[0], 2);
  3102.     rx_set_receiver_edid(&tmp[0], 2);
  3103. }
  3104.  
  3105. /*
  3106.  * print one block data of edid
  3107.  */
  3108. #define TMP_EDID_BUF_SIZE   (256+8)
  3109. static void hdmitx_edid_blk_print(unsigned char *blk, unsigned int blk_idx)
  3110. {
  3111.     unsigned int i, pos;
  3112.     unsigned char *tmp_buf = NULL;
  3113.  
  3114.     tmp_buf = kmalloc(TMP_EDID_BUF_SIZE, GFP_KERNEL);
  3115.     if (!tmp_buf)
  3116.         return;
  3117.  
  3118.     memset(tmp_buf, 0, TMP_EDID_BUF_SIZE);
  3119.     pr_info(EDID "blk%d raw data\n", blk_idx);
  3120.     for (i = 0, pos = 0; i < 128; i++) {
  3121.         pos += sprintf(tmp_buf + pos, "%02x", blk[i]);
  3122.         if (((i+1) & 0x1f) == 0)    /* print 32bytes a line */
  3123.             pos += sprintf(tmp_buf + pos, "\n");
  3124.     }
  3125.     pos += sprintf(tmp_buf + pos, "\n");
  3126.     pr_info(EDID "\n%s\n", tmp_buf);
  3127.     kfree(tmp_buf);
  3128. }
  3129.  
  3130. /*
  3131.  * check EDID buf contains valid block numbers
  3132.  */
  3133. static unsigned int hdmitx_edid_check_valid_blocks(unsigned char *buf)
  3134. {
  3135.     unsigned int valid_blk_no = 0;
  3136.     unsigned int i = 0, j = 0;
  3137.     unsigned int tmp_chksum = 0;
  3138.  
  3139.     for (j = 0; j < EDID_MAX_BLOCK; j++) {
  3140.         for (i = 0; i < 128; i++)
  3141.             tmp_chksum += buf[i + j*128];
  3142.         if (tmp_chksum != 0) {
  3143.             valid_blk_no++;
  3144.             if ((tmp_chksum & 0xff) == 0)
  3145.                 pr_info(EDID "check sum valid\n");
  3146.             else
  3147.                 pr_info(EDID "check sum invalid\n");
  3148.         }
  3149.         tmp_chksum = 0;
  3150.     }
  3151.     pr_info("hdmi_debug: hdmitx_edid_check_valid_blocks(): valid_blk_no: %d\n", valid_blk_no);
  3152.     return valid_blk_no;
  3153. }
  3154.  
  3155. /*
  3156.  * suppose DDC read EDID two times successfully,
  3157.  * then compare EDID_buf and EDID_buf1.
  3158.  * if same, just print out EDID_buf raw data, else print out 2 buffers
  3159.  */
  3160. void hdmitx_edid_buf_compare_print(struct hdmitx_dev *hdmitx_device)
  3161. {
  3162.     unsigned int i = 0;
  3163.     unsigned int err_no = 0;
  3164.     unsigned char *buf0 = hdmitx_device->EDID_buf;
  3165.     unsigned char *buf1 = hdmitx_device->EDID_buf1;
  3166.     unsigned int valid_blk_no = 0;
  3167.     unsigned int blk_idx = 0;
  3168.  
  3169.     for (i = 0; i < EDID_MAX_BLOCK*128; i++) {
  3170.         if (buf0[i] != buf1[i])
  3171.             err_no++;
  3172.     }
  3173.  
  3174.     if (err_no == 0) {
  3175.         /* calculate valid edid block numbers */
  3176.         valid_blk_no = hdmitx_edid_check_valid_blocks(buf0);
  3177.  
  3178.         if (valid_blk_no == 0)
  3179.             pr_info(EDID "raw data are all zeroes\n");
  3180.         else {
  3181.             for (blk_idx = 0; blk_idx < valid_blk_no; blk_idx++)
  3182.                 hdmitx_edid_blk_print(&buf0[blk_idx*128],
  3183.                     blk_idx);
  3184.         }
  3185.     } else {
  3186.         pr_info(EDID "%d errors between two reading\n", err_no);
  3187.         valid_blk_no = hdmitx_edid_check_valid_blocks(buf0);
  3188.         for (blk_idx = 0; blk_idx < valid_blk_no; blk_idx++)
  3189.             hdmitx_edid_blk_print(&buf0[blk_idx*128], blk_idx);
  3190.  
  3191.         valid_blk_no = hdmitx_edid_check_valid_blocks(buf1);
  3192.         for (blk_idx = 0; blk_idx < valid_blk_no; blk_idx++)
  3193.             hdmitx_edid_blk_print(&buf1[blk_idx*128], blk_idx);
  3194.     }
  3195. }
  3196.  
  3197. int hdmitx_edid_dump(struct hdmitx_dev *hdmitx_device, char *buffer,
  3198.     int buffer_len)
  3199. {
  3200.     int i, pos = 0;
  3201.     struct rx_cap *prxcap = &hdmitx_device->rxcap;
  3202.  
  3203.     pos += snprintf(buffer+pos, buffer_len-pos,
  3204.         "Rx Manufacturer Name: %s\n", prxcap->IDManufacturerName);
  3205.     pos += snprintf(buffer+pos, buffer_len-pos,
  3206.         "Rx Product Code: %02x%02x\n",
  3207.         prxcap->IDProductCode[0],
  3208.         prxcap->IDProductCode[1]);
  3209.     pos += snprintf(buffer+pos, buffer_len-pos,
  3210.         "Rx Serial Number: %02x%02x%02x%02x\n",
  3211.         prxcap->IDSerialNumber[0],
  3212.         prxcap->IDSerialNumber[1],
  3213.         prxcap->IDSerialNumber[2],
  3214.         prxcap->IDSerialNumber[3]);
  3215.     pos += snprintf(buffer+pos, buffer_len-pos,
  3216.         "Rx Product Name: %s\n", prxcap->ReceiverProductName);
  3217.  
  3218.     pos += snprintf(buffer+pos, buffer_len-pos,
  3219.         "Manufacture Week: %d\n", prxcap->manufacture_week);
  3220.     pos += snprintf(buffer+pos, buffer_len-pos,
  3221.         "Manufacture Year: %d\n", prxcap->manufacture_year + 1990);
  3222.  
  3223.     pos += snprintf(buffer+pos, buffer_len-pos,
  3224.         "Physcial size(cm): %d x %d\n",
  3225.         prxcap->physcial_weight, prxcap->physcial_height);
  3226.  
  3227.     pos += snprintf(buffer+pos, buffer_len-pos,
  3228.         "EDID Version: %d.%d\n",
  3229.         prxcap->edid_version, prxcap->edid_revision);
  3230.  
  3231.     pos += snprintf(buffer+pos, buffer_len-pos,
  3232.         "EDID block number: 0x%x\n", hdmitx_device->EDID_buf[0x7e]);
  3233.     pos += snprintf(buffer+pos, buffer_len-pos,
  3234.         "blk0 chksum: 0x%02x\n", prxcap->blk0_chksum);
  3235.  
  3236.     pos += snprintf(buffer+pos, buffer_len-pos,
  3237.         "Source Physical Address[a.b.c.d]: %x.%x.%x.%x\n",
  3238.         hdmitx_device->hdmi_info.vsdb_phy_addr.a,
  3239.         hdmitx_device->hdmi_info.vsdb_phy_addr.b,
  3240.         hdmitx_device->hdmi_info.vsdb_phy_addr.c,
  3241.         hdmitx_device->hdmi_info.vsdb_phy_addr.d);
  3242.  
  3243.     pos += snprintf(buffer+pos, buffer_len-pos,
  3244.         "native Mode %x, VIC (native %d):\n",
  3245.         prxcap->native_Mode, prxcap->native_VIC);
  3246.  
  3247.     pos += snprintf(buffer+pos, buffer_len-pos,
  3248.         "ColorDeepSupport %x\n", prxcap->ColorDeepSupport);
  3249.  
  3250.     for (i = 0 ; i < prxcap->VIC_count ; i++) {
  3251.         pos += snprintf(buffer+pos, buffer_len-pos, "%d ",
  3252.         prxcap->VIC[i]);
  3253.     }
  3254.     pos += snprintf(buffer+pos, buffer_len-pos, "\n");
  3255.     pos += snprintf(buffer+pos, buffer_len-pos,
  3256.         "Audio {format, channel, freq, cce}\n");
  3257.     for (i = 0; i < prxcap->AUD_count; i++) {
  3258.         pos += snprintf(buffer+pos, buffer_len-pos,
  3259.             "{%d, %d, %x, %x}\n",
  3260.             prxcap->RxAudioCap[i].audio_format_code,
  3261.             prxcap->RxAudioCap[i].channel_num_max,
  3262.             prxcap->RxAudioCap[i].freq_cc,
  3263.             prxcap->RxAudioCap[i].cc3);
  3264.     }
  3265.     pos += snprintf(buffer+pos, buffer_len-pos,
  3266.         "Speaker Allocation: %x\n", prxcap->RxSpeakerAllocation);
  3267.     pos += snprintf(buffer+pos, buffer_len-pos,
  3268.         "Vendor: 0x%x ( %s device)\n",
  3269.         prxcap->ieeeoui, (prxcap->ieeeoui) ? "HDMI" : "DVI");
  3270.    
  3271.     pos += snprintf(buffer+pos, buffer_len-pos,
  3272.         "MaxTMDSClock1 %d MHz\n", prxcap->Max_TMDS_Clock1 * 5);
  3273.  
  3274.     if (prxcap->hf_ieeeoui) {
  3275.         pos += snprintf(buffer+pos, buffer_len-pos, "Vendor2: 0x%x\n",
  3276.             prxcap->hf_ieeeoui);
  3277.         pos += snprintf(buffer+pos, buffer_len-pos,
  3278.             "MaxTMDSClock2 %d MHz\n", prxcap->Max_TMDS_Clock2 * 5);
  3279.     }
  3280.  
  3281.     if (prxcap->allm)
  3282.         pos += snprintf(buffer+pos, buffer_len-pos, "ALLM: %x\n",
  3283.             prxcap->allm);
  3284.  
  3285.     pos += snprintf(buffer+pos, buffer_len-pos, "vLatency: ");
  3286.     if (prxcap->vLatency == LATENCY_INVALID_UNKNOWN)
  3287.         pos += snprintf(buffer+pos, buffer_len-pos,
  3288.                 " Invalid/Unknown\n");
  3289.     else if (prxcap->vLatency == LATENCY_NOT_SUPPORT)
  3290.         pos += snprintf(buffer+pos, buffer_len-pos,
  3291.             " UnSupported\n");
  3292.     else
  3293.         pos += snprintf(buffer+pos, buffer_len-pos,
  3294.             " %d\n", prxcap->vLatency);
  3295.  
  3296.     pos += snprintf(buffer+pos, buffer_len-pos, "aLatency: ");
  3297.     if (prxcap->aLatency == LATENCY_INVALID_UNKNOWN)
  3298.         pos += snprintf(buffer+pos, buffer_len-pos,
  3299.                 " Invalid/Unknown\n");
  3300.     else if (prxcap->aLatency == LATENCY_NOT_SUPPORT)
  3301.         pos += snprintf(buffer+pos, buffer_len-pos,
  3302.             " UnSupported\n");
  3303.     else
  3304.         pos += snprintf(buffer+pos, buffer_len-pos, " %d\n",
  3305.             prxcap->aLatency);
  3306.  
  3307.     pos += snprintf(buffer+pos, buffer_len-pos, "i_vLatency: ");
  3308.     if (prxcap->i_vLatency == LATENCY_INVALID_UNKNOWN)
  3309.         pos += snprintf(buffer+pos, buffer_len-pos,
  3310.                 " Invalid/Unknown\n");
  3311.     else if (prxcap->i_vLatency == LATENCY_NOT_SUPPORT)
  3312.         pos += snprintf(buffer+pos, buffer_len-pos,
  3313.             " UnSupported\n");
  3314.     else
  3315.         pos += snprintf(buffer+pos, buffer_len-pos, " %d\n",
  3316.             prxcap->i_vLatency);
  3317.  
  3318.     pos += snprintf(buffer+pos, buffer_len-pos, "i_aLatency: ");
  3319.     if (prxcap->i_aLatency == LATENCY_INVALID_UNKNOWN)
  3320.         pos += snprintf(buffer+pos, buffer_len-pos,
  3321.                 " Invalid/Unknown\n");
  3322.     else if (prxcap->i_aLatency == LATENCY_NOT_SUPPORT)
  3323.         pos += snprintf(buffer+pos, buffer_len-pos,
  3324.             " UnSupported\n");
  3325.     else
  3326.         pos += snprintf(buffer+pos, buffer_len-pos, " %d\n",
  3327.             prxcap->i_aLatency);
  3328.  
  3329.     if (prxcap->colorimetry_data)
  3330.         pos += snprintf(buffer+pos, buffer_len-pos,
  3331.             "ColorMetry: 0x%x\n", prxcap->colorimetry_data);
  3332.     pos += snprintf(buffer+pos, buffer_len-pos, "SCDC: %x\n",
  3333.         prxcap->scdc_present);
  3334.     pos += snprintf(buffer+pos, buffer_len-pos, "RR_Cap: %x\n",
  3335.         prxcap->scdc_rr_capable);
  3336.     pos += snprintf(buffer+pos, buffer_len-pos, "LTE_340M_Scramble: %x\n",
  3337.         prxcap->lte_340mcsc_scramble);
  3338.  
  3339.     if (prxcap->dv_info.ieeeoui == 0x00d046)
  3340.         pos += snprintf(buffer+pos, buffer_len-pos,
  3341.             "  DolbyVision%d", prxcap->dv_info.ver);
  3342.     if (prxcap->hdr_sup_eotf_smpte_st_2084)
  3343.         pos += snprintf(buffer+pos, buffer_len-pos, "  HDR");
  3344.     if (prxcap->dc_y444 || prxcap->dc_30bit || prxcap->dc_30bit_420)
  3345.         pos += snprintf(buffer+pos, buffer_len-pos, "  DeepColor");
  3346.     pos += snprintf(buffer+pos, buffer_len-pos, "\n");
  3347.  
  3348.     /* for checkvalue which maybe used by application to adjust
  3349.      * whether edid is changed
  3350.      */
  3351.     pos += snprintf(buffer+pos, buffer_len-pos,
  3352.         "checkvalue: 0x%02x%02x%02x%02x\n",
  3353.             edid_checkvalue[0],
  3354.             edid_checkvalue[1],
  3355.             edid_checkvalue[2],
  3356.             edid_checkvalue[3]);
  3357.  
  3358.     return pos;
  3359. }
Advertisement
Add Comment
Please, Sign In to add comment