drm/exynos: add pm_runtime to HDMI
authorGustavo Padovan <gustavo.padovan@collabora.co.uk>
Mon, 2 Nov 2015 11:39:18 +0000 (20:39 +0900)
committerInki Dae <daeinki@gmail.com>
Sun, 13 Dec 2015 13:22:44 +0000 (22:22 +0900)
Let pm_runtime handle the enabling/disabling of the device with proper
refcnt instead of rely on specific flags to track the enabled state.

Changelog v3:
- revive powered flag to keep current dpms mode

Changelog v2:
- Mofidy CONFIG_PM_SLEEP -> CONFIG_PM

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Signed-off-by: Inki Dae <inki.dae@samsung.com>
drivers/gpu/drm/exynos/exynos_hdmi.c

index 57b675563e943120a5b47a8d05b9b50260c13e02..9a955d23ab922df0a5a829f3e8ba45781bbdac8c 100644 (file)
@@ -113,7 +113,7 @@ struct hdmi_context {
        void __iomem                    *regs_hdmiphy;
        struct i2c_client               *hdmiphy_port;
        struct i2c_adapter              *ddc_adpt;
-       struct gpio_desc                *hpd_gpio;
+       struct gpio_desc                *hpd_gpio;
        int                             irq;
        struct regmap                   *pmureg;
        struct clk                      *hdmi;
@@ -1588,8 +1588,6 @@ static void hdmi_enable(struct drm_encoder *encoder)
        if (hdata->powered)
                return;
 
-       hdata->powered = true;
-
        pm_runtime_get_sync(hdata->dev);
 
        if (regulator_bulk_enable(ARRAY_SIZE(supply), hdata->regul_bulk))
@@ -1599,10 +1597,9 @@ static void hdmi_enable(struct drm_encoder *encoder)
        regmap_update_bits(hdata->pmureg, PMU_HDMI_PHY_CONTROL,
                        PMU_HDMI_PHY_ENABLE_BIT, 1);
 
-       clk_prepare_enable(hdata->hdmi);
-       clk_prepare_enable(hdata->sclk_hdmi);
-
        hdmi_conf_apply(hdata);
+
+       hdata->powered = true;
 }
 
 static void hdmi_disable(struct drm_encoder *encoder)
@@ -1633,9 +1630,6 @@ static void hdmi_disable(struct drm_encoder *encoder)
 
        cancel_delayed_work(&hdata->hotplug_work);
 
-       clk_disable_unprepare(hdata->sclk_hdmi);
-       clk_disable_unprepare(hdata->hdmi);
-
        /* reset pmu hdmiphy control bit to disable hdmiphy */
        regmap_update_bits(hdata->pmureg, PMU_HDMI_PHY_CONTROL,
                        PMU_HDMI_PHY_ENABLE_BIT, 0);
@@ -1978,12 +1972,49 @@ static int hdmi_remove(struct platform_device *pdev)
        return 0;
 }
 
+#ifdef CONFIG_PM
+static int exynos_hdmi_suspend(struct device *dev)
+{
+       struct hdmi_context *hdata = dev_get_drvdata(dev);
+
+       clk_disable_unprepare(hdata->sclk_hdmi);
+       clk_disable_unprepare(hdata->hdmi);
+
+       return 0;
+}
+
+static int exynos_hdmi_resume(struct device *dev)
+{
+       struct hdmi_context *hdata = dev_get_drvdata(dev);
+       int ret;
+
+       ret = clk_prepare_enable(hdata->hdmi);
+       if (ret < 0) {
+               DRM_ERROR("Failed to prepare_enable the hdmi clk [%d]\n", ret);
+               return ret;
+       }
+       ret = clk_prepare_enable(hdata->sclk_hdmi);
+       if (ret < 0) {
+               DRM_ERROR("Failed to prepare_enable the sclk_mixer clk [%d]\n",
+                         ret);
+               return ret;
+       }
+
+       return 0;
+}
+#endif
+
+static const struct dev_pm_ops exynos_hdmi_pm_ops = {
+       SET_RUNTIME_PM_OPS(exynos_hdmi_suspend, exynos_hdmi_resume, NULL)
+};
+
 struct platform_driver hdmi_driver = {
        .probe          = hdmi_probe,
        .remove         = hdmi_remove,
        .driver         = {
                .name   = "exynos-hdmi",
                .owner  = THIS_MODULE,
+               .pm     = &exynos_hdmi_pm_ops,
                .of_match_table = hdmi_match_types,
        },
 };