MLK-20391: v4l2: hdmi rx: Add hdmi cable plugin status check
authorSandor Yu <Sandor.yu@nxp.com>
Fri, 16 Nov 2018 08:26:44 +0000 (16:26 +0800)
committerSandor Yu <Sandor.yu@nxp.com>
Fri, 19 Apr 2019 02:40:50 +0000 (10:40 +0800)
Added hdmi cable plugin status check in v4l2 api function.

Signed-off-by: Sandor Yu <Sandor.yu@nxp.com>
drivers/media/platform/imx8/hdmi/mxc-hdmi-rx.c
drivers/media/platform/imx8/hdmi/mxc-hdmi-rx.h

index 449f10f..43cee86 100644 (file)
@@ -292,6 +292,11 @@ static int mxc_hdmi_g_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *a)
        struct mxc_hdmi_rx_dev *hdmi_rx = imx_sd_to_hdmi(sd);
        int ret = 0;
 
+       if (hdmi_rx->cable_plugin == false) {
+               dev_warn(&hdmi_rx->pdev->dev, "No Cable Connected!\n");
+               return -EINVAL;
+       }
+
        switch (a->type) {
        /* This is the only case currently handled. */
        case V4L2_BUF_TYPE_VIDEO_CAPTURE:
@@ -327,6 +332,11 @@ static int mxc_hdmi_s_stream(struct v4l2_subdev *sd, int enable)
        u32 val;
 
        dev_dbg(&hdmi_rx->pdev->dev, "%s\n", __func__);
+       if (hdmi_rx->cable_plugin == false) {
+               dev_warn(&hdmi_rx->pdev->dev, "No Cable Connected!\n");
+               return -EINVAL;
+       }
+
        mxc_hdmi_pixel_link_encoder(hdmi_rx);
 
        if (enable) {
@@ -375,7 +385,7 @@ static int mxc_hdmi_enum_framesizes(struct v4l2_subdev *sd,
 {
        struct mxc_hdmi_rx_dev *hdmi_rx = imx_sd_to_hdmi(sd);
 
-       if (fse->index > 1)
+       if (fse->index > 1 || hdmi_rx->cable_plugin == false)
                return -EINVAL;
 
        fse->min_width = hdmi_rx->timings->timings.bt.width;
@@ -426,6 +436,11 @@ static int mxc_hdmi_get_format(struct v4l2_subdev *sd,
        struct mxc_hdmi_rx_dev *hdmi_rx = imx_sd_to_hdmi(sd);
        struct v4l2_mbus_framefmt *mbusformat = &sdformat->format;
 
+       if (hdmi_rx->cable_plugin == false) {
+               dev_warn(&hdmi_rx->pdev->dev, "No Cable Connected!\n");
+               return -EINVAL;
+       }
+
        if (sdformat->pad != MXC_HDMI_RX_PAD_SOURCE)
                return -EINVAL;
 
@@ -728,6 +743,7 @@ static void hpd5v_work_func(struct work_struct *work)
                enable_irq(hdmi_rx->irq[HPD5V_IRQ_OUT]);
                sprintf(event_string, "EVENT=hdmirxin");
                kobject_uevent_env(&hdmi_rx->pdev->dev.kobj, KOBJ_CHANGE, envp);
+               hdmi_rx->cable_plugin = true;
 #ifdef CONFIG_IMX_HDP_CEC
                if (hdmi_rx->is_cec) {
                        mxc_hdmi_cec_init(hdmi_rx);
@@ -747,6 +763,7 @@ static void hpd5v_work_func(struct work_struct *work)
                kobject_uevent_env(&hdmi_rx->pdev->dev.kobj, KOBJ_CHANGE, envp);
                enable_irq(hdmi_rx->irq[HPD5V_IRQ_IN]);
                CDN_API_MainControl_blocking(&hdmi_rx->state, 0, &sts);
+               hdmi_rx->cable_plugin = false;
        } else
                pr_warn("HDMI RX Cable State unknow\n");
 
@@ -876,8 +893,10 @@ static int mxc_hdmi_probe(struct platform_device *pdev)
                        goto failed;
                }
                /* Cable Disconnedted, enable Plug in IRQ */
-               if (hpd == 0)
+               if (hpd == 0) {
                        enable_irq(hdmi_rx->irq[HPD5V_IRQ_IN]);
+                       hdmi_rx->cable_plugin = false;
+               }
        }
        if (hdmi_rx->irq[HPD5V_IRQ_OUT] > 0) {
                irq_set_status_flags(hdmi_rx->irq[HPD5V_IRQ_OUT], IRQ_NOAUTOEN);
@@ -894,6 +913,7 @@ static int mxc_hdmi_probe(struct platform_device *pdev)
                        hdmirx_startup(&hdmi_rx->state);
                        /* Cable Connected, enable Plug out IRQ */
                        enable_irq(hdmi_rx->irq[HPD5V_IRQ_OUT]);
+                       hdmi_rx->cable_plugin = true;
                }
        }
 
index 11afb99..5541361 100644 (file)
@@ -121,6 +121,7 @@ struct mxc_hdmi_rx_dev {
        u8 hdmi_vic;
     u8 pixel_encoding;
        u8 color_depth;
+       bool cable_plugin;
 
        u8 is_cec;
        struct imx_cec_dev cec;