drm: bridge/dw_hdmi: add switch state to support hdmi audio
authorBin Yang <yangbin@rock-chips.com>
Thu, 9 Feb 2017 10:15:30 +0000 (18:15 +0800)
committerHuang, Tao <huangtao@rock-chips.com>
Mon, 13 Feb 2017 07:02:09 +0000 (15:02 +0800)
Change-Id: Ib8122f9cc913d2cd15b92a3d6c57c7edf77d0483
Signed-off-by: Bin Yang <yangbin@rock-chips.com>
drivers/gpu/drm/bridge/dw-hdmi.c

index 0ddc7b7da990492a7b575f62b9a637e67c35dab0..0153be6ffbd48387ed5ecc28bb69c879af40a0fa 100644 (file)
@@ -30,6 +30,9 @@
 #include <drm/drm_edid.h>
 #include <drm/drm_encoder_slave.h>
 #include <drm/bridge/dw_hdmi.h>
+#ifdef CONFIG_SWITCH
+#include <linux/switch.h>
+#endif
 
 #include "dw-hdmi.h"
 #include "dw-hdmi-audio.h"
@@ -213,6 +216,10 @@ struct dw_hdmi {
        unsigned int audio_n;
        bool audio_enable;
 
+#ifdef CONFIG_SWITCH
+       struct switch_dev switchdev;
+#endif
+
        void (*write)(struct dw_hdmi *hdmi, u8 val, int offset);
        u8 (*read)(struct dw_hdmi *hdmi, int offset);
 };
@@ -1942,6 +1949,12 @@ static irqreturn_t dw_hdmi_irq(int irq, void *dev_id)
                dev_dbg(hdmi->dev, "EVENT=%s\n",
                        phy_int_pol & HDMI_PHY_HPD ? "plugin" : "plugout");
                drm_helper_hpd_irq_event(hdmi->bridge->dev);
+#ifdef CONFIG_SWITCH
+               if (phy_int_pol & HDMI_PHY_HPD)
+                       switch_set_state(&hdmi->switchdev, 1);
+               else
+                       switch_set_state(&hdmi->switchdev, 0);
+#endif
        }
 
        hdmi_writeb(hdmi, intr_stat, HDMI_IH_PHY_STAT0);
@@ -2132,6 +2145,11 @@ int dw_hdmi_bind(struct device *dev, struct device *master,
        if (ret)
                goto err_iahb;
 
+#ifdef CONFIG_SWITCH
+       hdmi->switchdev.name = "hdmi";
+       switch_dev_register(&hdmi->switchdev);
+#endif
+
        hdmi_writeb(hdmi, ~(HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE),
                    HDMI_IH_MUTE_PHY_STAT0);
 
@@ -2200,6 +2218,9 @@ void dw_hdmi_unbind(struct device *dev, struct device *master, void *data)
        /* Disable all interrupts */
        hdmi_writeb(hdmi, ~0, HDMI_IH_MUTE_PHY_STAT0);
 
+#ifdef CONFIG_SWITCH
+       switch_dev_unregister(&hdmi->switchdev);
+#endif
        hdmi->connector.funcs->destroy(&hdmi->connector);
        hdmi->encoder->funcs->destroy(hdmi->encoder);