[media] s5p-mfc: Use clock gating only on MFC v5 hardware
authorMarek Szyprowski <m.szyprowski@samsung.com>
Thu, 10 Nov 2016 10:31:23 +0000 (08:31 -0200)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>
Wed, 16 Nov 2016 18:40:13 +0000 (16:40 -0200)
Newer MFC hardware have internal clock gating feature, so additional
software-triggered clock gating sometimes causes misbehavior of the MFC
firmware and results in freeze or crash. This patch changes the driver
to use software-triggered clock gating only when working with v5 MFC
hardware, where it has been proven to work properly.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
drivers/media/platform/s5p-mfc/s5p_mfc.c
drivers/media/platform/s5p-mfc/s5p_mfc_common.h
drivers/media/platform/s5p-mfc/s5p_mfc_pm.c

index 9f73ba1cc9c358311bc633505832a50120a623fc..ba6e2c5bca05b864ecf39e65e994ce294a49b765 100644 (file)
@@ -1442,6 +1442,7 @@ static struct s5p_mfc_variant mfc_drvdata_v5 = {
        .buf_size       = &buf_size_v5,
        .buf_align      = &mfc_buf_align_v5,
        .fw_name[0]     = "s5p-mfc.fw",
+       .use_clock_gating = true,
 };
 
 static struct s5p_mfc_buf_size_v6 mfc_buf_size_v6 = {
index 46b99f28cbd7c0fef29e2b20a743215f7bf89c04..c068ee3ece6ef48ea6a4ed1a9a0dd0c86283e38f 100644 (file)
@@ -199,6 +199,7 @@ struct s5p_mfc_buf {
 struct s5p_mfc_pm {
        struct clk      *clock;
        struct clk      *clock_gate;
+       bool            use_clock_gating;
        atomic_t        power;
        struct device   *device;
 };
@@ -235,6 +236,7 @@ struct s5p_mfc_variant {
        struct s5p_mfc_buf_size *buf_size;
        struct s5p_mfc_buf_align *buf_align;
        char    *fw_name[MFC_FW_MAX_VERSIONS];
+       bool            use_clock_gating;
 };
 
 /**
index 930dc2dddae66c2bd0f757000cef5037828c87cc..b5806ab7ac3180a1a6b2c0c8e1ed853e89e6cf32 100644 (file)
@@ -37,6 +37,7 @@ int s5p_mfc_init_pm(struct s5p_mfc_dev *dev)
 
        pm = &dev->pm;
        p_dev = dev;
+       pm->use_clock_gating = dev->variant->use_clock_gating;
        pm->clock_gate = clk_get(&dev->plat_dev->dev, MFC_GATE_CLK_NAME);
        if (IS_ERR(pm->clock_gate)) {
                mfc_err("Failed to get clock-gating control\n");
@@ -108,6 +109,8 @@ int s5p_mfc_clock_on(void)
        atomic_inc(&clk_ref);
        mfc_debug(3, "+ %d\n", atomic_read(&clk_ref));
 #endif
+       if (!pm->use_clock_gating)
+               return 0;
        if (!IS_ERR_OR_NULL(pm->clock_gate))
                ret = clk_enable(pm->clock_gate);
        return ret;
@@ -119,22 +122,32 @@ void s5p_mfc_clock_off(void)
        atomic_dec(&clk_ref);
        mfc_debug(3, "- %d\n", atomic_read(&clk_ref));
 #endif
+       if (!pm->use_clock_gating)
+               return;
        if (!IS_ERR_OR_NULL(pm->clock_gate))
                clk_disable(pm->clock_gate);
 }
 
 int s5p_mfc_power_on(void)
 {
+       int ret = 0;
+
 #ifdef CONFIG_PM
-       return pm_runtime_get_sync(pm->device);
+       ret = pm_runtime_get_sync(pm->device);
+       if (ret)
+               return ret;
 #else
        atomic_set(&pm->power, 1);
-       return 0;
 #endif
+       if (!pm->use_clock_gating && !IS_ERR_OR_NULL(pm->clock_gate))
+               ret = clk_enable(pm->clock_gate);
+       return ret;
 }
 
 int s5p_mfc_power_off(void)
 {
+       if (!pm->use_clock_gating && !IS_ERR_OR_NULL(pm->clock_gate))
+               clk_disable(pm->clock_gate);
 #ifdef CONFIG_PM
        return pm_runtime_put_sync(pm->device);
 #else