[PATCH v3 1/2] can: m_can: Move mram init to mcan device setup

From: Vivek Yadav
Date: Wed Nov 23 2022 - 00:31:12 EST


When we try to access the mcan message ram addresses, hclk is
gated by any other drivers or disabled, because of that probe gets
failed.

Move the mram init functionality to mcan device setup called by
mcan class register from mcan probe function, by that time clocks
are enabled.

Signed-off-by: Chandrasekar R <rcsekar@xxxxxxxxxxx>
Signed-off-by: Vivek Yadav <vivek.2311@xxxxxxxxxxx>
---
drivers/net/can/m_can/m_can.c | 4 ++--
drivers/net/can/m_can/m_can.h | 1 +
drivers/net/can/m_can/m_can_platform.c | 21 +++++++++++++++++----
3 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index a776cab1a5a4..5956f0b4d5b1 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -1516,9 +1516,9 @@ static int m_can_dev_setup(struct m_can_classdev *cdev)
}

if (cdev->ops->init)
- cdev->ops->init(cdev);
+ err = cdev->ops->init(cdev);

- return 0;
+ return err;
}

static void m_can_stop(struct net_device *dev)
diff --git a/drivers/net/can/m_can/m_can.h b/drivers/net/can/m_can/m_can.h
index 401410022823..c6e77b93f4a2 100644
--- a/drivers/net/can/m_can/m_can.h
+++ b/drivers/net/can/m_can/m_can.h
@@ -93,6 +93,7 @@ struct m_can_classdev {
int is_peripheral;

struct mram_cfg mcfg[MRAM_CFG_NUM];
+ bool mram_cfg_flag;
};

struct m_can_classdev *m_can_class_allocate_dev(struct device *dev, int sizeof_priv);
diff --git a/drivers/net/can/m_can/m_can_platform.c b/drivers/net/can/m_can/m_can_platform.c
index b5a5bedb3116..1a65b0d256fb 100644
--- a/drivers/net/can/m_can/m_can_platform.c
+++ b/drivers/net/can/m_can/m_can_platform.c
@@ -67,11 +67,28 @@ static int iomap_write_fifo(struct m_can_classdev *cdev, int offset,
return 0;
}

+static int plat_init(struct m_can_classdev *cdev)
+{
+ int ret = 0;
+
+ if (!cdev->mram_cfg_flag) {
+ /* Initialize mcan message ram */
+ ret = m_can_init_ram(cdev);
+ if (ret)
+ return ret;
+
+ cdev->mram_cfg_flag = true;
+ }
+
+ return 0;
+}
+
static struct m_can_ops m_can_plat_ops = {
.read_reg = iomap_read_reg,
.write_reg = iomap_write_reg,
.write_fifo = iomap_write_fifo,
.read_fifo = iomap_read_fifo,
+ .init = plat_init,
};

static int m_can_plat_probe(struct platform_device *pdev)
@@ -140,10 +157,6 @@ static int m_can_plat_probe(struct platform_device *pdev)

platform_set_drvdata(pdev, mcan_class);

- ret = m_can_init_ram(mcan_class);
- if (ret)
- goto probe_fail;
-
pm_runtime_enable(mcan_class->dev);
ret = m_can_class_register(mcan_class);
if (ret)
--
2.17.1