[PATCH 4/7] can: mcan: enable peripheral clk to access mram

From: Vivek Yadav
Date: Fri Oct 21 2022 - 08:39:38 EST


When we try to access the mcan message ram addresses, make sure hclk is
not gated by any other drivers or disabled. Enable the clock (hclk) before
accessing the mram and disable it after that.

This is required in case if by-default hclk is gated.

Signed-off-by: Ravi Patel <ravi.patel@xxxxxxxxxxx>
Signed-off-by: Vivek Yadav <vivek.2311@xxxxxxxxxxx>
---
drivers/net/can/m_can/m_can_platform.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/m_can/m_can_platform.c b/drivers/net/can/m_can/m_can_platform.c
index eee47bad0592..5aab025775f9 100644
--- a/drivers/net/can/m_can/m_can_platform.c
+++ b/drivers/net/can/m_can/m_can_platform.c
@@ -140,10 +140,17 @@ static int m_can_plat_probe(struct platform_device *pdev)

platform_set_drvdata(pdev, mcan_class);

- ret = m_can_init_ram(mcan_class);
+ /* clock needs to be enabled to access mram block */
+ ret = clk_prepare_enable(mcan_class->hclk);
if (ret)
goto probe_fail;

+ ret = m_can_init_ram(mcan_class);
+ if (ret)
+ goto mram_fail;
+
+ clk_disable_unprepare(mcan_class->hclk);
+
pm_runtime_enable(mcan_class->dev);
ret = m_can_class_register(mcan_class);
if (ret)
@@ -153,6 +160,8 @@ static int m_can_plat_probe(struct platform_device *pdev)

out_runtime_disable:
pm_runtime_disable(mcan_class->dev);
+mram_fail:
+ clk_disable_unprepare(mcan_class->hclk);
probe_fail:
m_can_class_free_dev(mcan_class->net);
return ret;
--
2.17.1