MLK-16184: hdmi: Add timeout check to hdmi initialize
authorSandor Yu <Sandor.yu@nxp.com>
Thu, 10 Aug 2017 10:51:10 +0000 (18:51 +0800)
committerLeonard Crestez <leonard.crestez@nxp.com>
Wed, 17 Apr 2019 23:51:34 +0000 (02:51 +0300)
Add timeout check for hdmi FW alive function to avoid
kernel booting hang for that board without HDMI FW.

CDN_API_General_Test_Echo_Ext_blocking is the first
function that calling mailbox.
Add timeout to the function to avoid kernel booting hang
for that board without HDMI ROM patch.

Signed-off-by: Sandor Yu <Sandor.yu@nxp.com>
drivers/video/fbdev/mxc/cdn_hdp/API_General.c
drivers/video/fbdev/mxc/cdn_hdp/util.h
drivers/video/fbdev/mxc/imx8_hdmi.c

index 9002d74..5958a10 100644 (file)
@@ -176,9 +176,8 @@ CDN_API_STATUS CDN_API_General_Test_Echo_Ext_blocking(uint8_t const *msg,
                                                      uint16_t num_bytes,
                                                      CDN_BUS_TYPE bus_type)
 {
-       internal_block_function(CDN_API_General_Test_Echo_Ext
-                               (msg, resp, num_bytes, bus_type)
-           );
+       internal_block_function_udelay(CDN_API_General_Test_Echo_Ext
+                               (msg, resp, num_bytes, bus_type), 1000);
 }
 
 CDN_API_STATUS CDN_API_General_getCurVersion(unsigned short *ver,
@@ -258,7 +257,7 @@ CDN_API_STATUS CDN_API_CheckAlive(void)
 
 CDN_API_STATUS CDN_API_CheckAlive_blocking(void)
 {
-       internal_block_function(CDN_API_CheckAlive());
+       internal_block_function_udelay(CDN_API_CheckAlive(), 1000);
 }
 
 CDN_API_STATUS CDN_API_MainControl(unsigned char mode, unsigned char *resp)
index 0248878..dc8fdd8 100644 (file)
  */
 
 #ifndef UTIL_H_
-# define UTIL_H_
+#define UTIL_H_
 
-# include "API_General.h"
+#include <linux/delay.h>
+#include "API_General.h"
 /**
  * \addtogroup UTILS
  * \{
@@ -67,6 +68,26 @@ do {                                             \
     return ret;                                  \
 } while (0)
 
+/**
+ * \brief expands to blocking function body
+ * \param x - function call
+ * \param y - num of loop
+ */
+# define internal_block_function_udelay(x, y)    \
+do {                                             \
+       CDN_API_STATUS ret;                          \
+       int i;                                       \
+       for (i = 0; i < y; i++) {                    \
+               ret = x;                                 \
+               if (ret == CDN_OK)                       \
+                       break;                               \
+               udelay(1);                               \
+       }                                            \
+       if (i == y)                                  \
+               printk("timeout %s\n", __func__);        \
+       return ret;                                  \
+} while (0)
+
 /**
  * \brief write message and write response (if any), non-blocking way. Also sets state.running = 0
  */
index dc0ae6c..b7dce3d 100644 (file)
@@ -117,6 +117,10 @@ static int hdmi_init(int vic, int encoding, int color_depth)
 
        ret = CDN_API_CheckAlive_blocking();
        printk("CDN_API_CheckAlive returned ret = %d\n", ret);
+       if (ret != 0) {
+               printk("NO HDMI FW running\n");
+               return -EINVAL;
+       }
 
        ret = CDN_API_General_Test_Echo_Ext_blocking(echo_msg, echo_resp,
                                                     sizeof(echo_msg),
@@ -124,6 +128,11 @@ static int hdmi_init(int vic, int encoding, int color_depth)
        printk
            ("CDN_API_General_Test_Echo_Ext_blocking - APB(ret = %d echo_resp = %s)\n",
             ret, echo_resp);
+       if (ret != 0) {
+               printk("HDMI mailbox access failed\n");
+               return -EINVAL;
+       }
+
        /* Configure PHY */
        character_freq_khz =
            phy_cfg_hdp(4, vic_mode, bps, format, pixel_clk_from_phy);
@@ -294,13 +303,17 @@ static int imx_hdmi_probe(struct platform_device *pdev)
        /* 0-480p, 1-720p, 2-1080p, 3-2160p60, 4-2160p30 */
        /* Pixel Format - 1 RGB, 2 YCbCr 444, 3 YCbCr 420 */
        if (vmode_index == 16)
-               hdmi_init(2, 1, 8);
+               ret = hdmi_init(2, 1, 8);
        else if (vmode_index == 97)
-               hdmi_init(3, 1, 8);
+               ret = hdmi_init(3, 1, 8);
        else if (vmode_index == 95)
-               hdmi_init(4, 1, 8);
+               ret = hdmi_init(4, 1, 8);
        else
-               hdmi_init(1, 1, 8);
+               ret = hdmi_init(1, 1, 8);
+
+       if (ret < 0)
+               return -EINVAL;
+
        dev_info(&pdev->dev, "i.MX HDMI driver probed\n");
        return ret;