2021-04-08 02:11:52

by Peng Fan (OSS)

[permalink] [raw]
Subject: [PATCH V3 0/8] remoteproc: imx_rproc: support i.MX7ULP/8MN/8MP

From: Peng Fan <[email protected]>

V3:
Add A-b tag for Patch 1/2
Fix the checkpatch warning for Patch 6,8

V2:
Patch 1/8, use fsl as vendor, typo fix
Because patchset [1] has v2 version, patch 5,6,7,8 are adapted that
change.

This patchset is to support i.MX7ULP/8MN/8MP, also includes a patch to
parse fsl,auto-boot
This patchset depends on [1]

[1] https://patchwork.kernel.org/project/linux-remoteproc/cover/
[email protected]/

Peng Fan (8):
dt-bindings: remoteproc: imx_rproc: add fsl,auto-boot property
dt-bindings: remoteproc: imx_rproc: add i.MX7ULP support
dt-bindings: remoteproc: imx_rproc: support i.MX8MN/P
remoteproc: imx_rproc: make clk optional
remoteproc: imx_rproc: parse fsl,auto-boot
remoteproc: imx_rproc: initial support for mutilple start/stop method
remoteproc: imx_rproc: support i.MX7ULP
remoteproc: imx_rproc: support i.MX8MN/P

.../bindings/remoteproc/fsl,imx-rproc.yaml | 11 +-
drivers/remoteproc/imx_rproc.c | 170 +++++++++++++++---
2 files changed, 159 insertions(+), 22 deletions(-)

--
2.30.0


2021-04-08 02:11:52

by Peng Fan (OSS)

[permalink] [raw]
Subject: [PATCH V3 1/8] dt-bindings: remoteproc: imx_rproc: add fsl,auto-boot property

From: Peng Fan <[email protected]>

Add an optional property "fsl,auto-boot" to indicate remote processor
auto boot.

Signed-off-by: Peng Fan <[email protected]>
Acked-by: Rob Herring <[email protected]>
---
.../devicetree/bindings/remoteproc/fsl,imx-rproc.yaml | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml b/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
index 208a628f8d6c..b13bf8d70488 100644
--- a/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
+++ b/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
@@ -49,6 +49,12 @@ properties:
minItems: 1
maxItems: 32

+ fsl,auto-boot:
+ $ref: /schemas/types.yaml#/definitions/flag
+ description:
+ Indicate whether need to load the default firmware and start the remote
+ processor automatically.
+
required:
- compatible
- clocks
--
2.30.0

2021-04-08 02:11:53

by Peng Fan (OSS)

[permalink] [raw]
Subject: [PATCH V3 5/8] remoteproc: imx_rproc: parse fsl,auto-boot

From: Peng Fan <[email protected]>

Parse fsl,auto-boot to indicate whether need remoteproc framework
auto boot or not.

When remote processor is booted before Linux Kernel up, do not parse
fsl,auto-boot. So add an entry to store the working mode of remote
processor. Currently only IMX_RPROC_NORMAL, IMX_RPROC_EARLY_BOOT.

Signed-off-by: Peng Fan <[email protected]>
---
drivers/remoteproc/imx_rproc.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index ca17f520d904..c576e12d3817 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -83,6 +83,16 @@ struct imx_rproc_dcfg {
size_t att_size;
};

+enum imx_rproc_mode {
+ /* Linux load/kick remote core */
+ IMX_RPROC_NORMAL,
+ /*
+ * remote core booted before kicking Linux, and remote core
+ * could be stopped & restarted by Linux
+ */
+ IMX_RPROC_EARLY_BOOT,
+};
+
struct imx_rproc {
struct device *dev;
struct regmap *regmap;
@@ -96,6 +106,7 @@ struct imx_rproc {
struct work_struct rproc_work;
struct workqueue_struct *workqueue;
void __iomem *rsc_table;
+ enum imx_rproc_mode mode;
};

static const struct imx_rproc_att imx_rproc_att_imx8mq[] = {
@@ -565,14 +576,18 @@ static int imx_rproc_detect_mode(struct imx_rproc *priv)
int ret;
u32 val;

+ priv->mode = IMX_RPROC_NORMAL;
+
ret = regmap_read(priv->regmap, dcfg->src_reg, &val);
if (ret) {
dev_err(dev, "Failed to read src\n");
return ret;
}

- if (!(val & dcfg->src_stop))
+ if (!(val & dcfg->src_stop)) {
+ priv->mode = IMX_RPROC_EARLY_BOOT;
priv->rproc->state = RPROC_DETACHED;
+ }

return 0;
}
@@ -654,6 +669,9 @@ static int imx_rproc_probe(struct platform_device *pdev)

INIT_WORK(&priv->rproc_work, imx_rproc_vq_work);

+ if (priv->mode == IMX_RPROC_NORMAL)
+ rproc->auto_boot = of_property_read_bool(np, "fsl,auto-boot");
+
ret = rproc_add(rproc);
if (ret) {
dev_err(dev, "rproc_add failed\n");
--
2.30.0

2021-04-08 02:12:02

by Peng Fan (OSS)

[permalink] [raw]
Subject: [PATCH V3 4/8] remoteproc: imx_rproc: make clk optional

From: Peng Fan <[email protected]>

To i.MX7ULP, M4 is the master to control everything, so it not need
clk from A7.

Reviewed-by: Richard Zhu <[email protected]>
Signed-off-by: Peng Fan <[email protected]>
---
drivers/remoteproc/imx_rproc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index d6338872c6db..ca17f520d904 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -635,7 +635,7 @@ static int imx_rproc_probe(struct platform_device *pdev)
if (ret)
goto err_put_mbox;

- priv->clk = devm_clk_get(dev, NULL);
+ priv->clk = devm_clk_get_optional(dev, NULL);
if (IS_ERR(priv->clk)) {
dev_err(dev, "Failed to get clock\n");
ret = PTR_ERR(priv->clk);
--
2.30.0

2021-04-08 02:12:23

by Peng Fan (OSS)

[permalink] [raw]
Subject: [PATCH V3 6/8] remoteproc: imx_rproc: initial support for mutilple start/stop method

From: Peng Fan <[email protected]>

Add three methods IMX_RPROC_NONE(no need start/stop), IMX_RPROC_MMIO
(start/stop through mmio) and IMX_RPROC_SMC(start/stop through ARM SMCCC).

The current SoCs supported are all using IMX_RPROC_MMIO, add a restrict
in probe that only SoCs using IMX_RPROC_MMIO needs syscon regmap to
access registers.

Signed-off-by: Peng Fan <[email protected]>
---
drivers/remoteproc/imx_rproc.c | 50 +++++++++++++++++++++++-----------
1 file changed, 34 insertions(+), 16 deletions(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index c576e12d3817..a7fa9d7fc2d1 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -74,6 +74,15 @@ struct imx_rproc_att {
int flags;
};

+/* Remote core start/stop method */
+enum imx_rproc_method {
+ IMX_RPROC_NONE,
+ /* Through syscon regmap */
+ IMX_RPROC_MMIO,
+ /* Through ARM SMCCC */
+ IMX_RPROC_SMC,
+};
+
struct imx_rproc_dcfg {
u32 src_reg;
u32 src_mask;
@@ -81,6 +90,7 @@ struct imx_rproc_dcfg {
u32 src_stop;
const struct imx_rproc_att *att;
size_t att_size;
+ enum imx_rproc_method method;
};

enum imx_rproc_mode {
@@ -194,6 +204,7 @@ static const struct imx_rproc_dcfg imx_rproc_cfg_imx8mq = {
.src_stop = IMX7D_M4_STOP,
.att = imx_rproc_att_imx8mq,
.att_size = ARRAY_SIZE(imx_rproc_att_imx8mq),
+ .method = IMX_RPROC_MMIO,
};

static const struct imx_rproc_dcfg imx_rproc_cfg_imx7d = {
@@ -203,6 +214,7 @@ static const struct imx_rproc_dcfg imx_rproc_cfg_imx7d = {
.src_stop = IMX7D_M4_STOP,
.att = imx_rproc_att_imx7d,
.att_size = ARRAY_SIZE(imx_rproc_att_imx7d),
+ .method = IMX_RPROC_MMIO,
};

static const struct imx_rproc_dcfg imx_rproc_cfg_imx6sx = {
@@ -212,6 +224,7 @@ static const struct imx_rproc_dcfg imx_rproc_cfg_imx6sx = {
.src_stop = IMX6SX_M4_STOP,
.att = imx_rproc_att_imx6sx,
.att_size = ARRAY_SIZE(imx_rproc_att_imx6sx),
+ .method = IMX_RPROC_MMIO,
};

static int imx_rproc_start(struct rproc *rproc)
@@ -578,15 +591,17 @@ static int imx_rproc_detect_mode(struct imx_rproc *priv)

priv->mode = IMX_RPROC_NORMAL;

- ret = regmap_read(priv->regmap, dcfg->src_reg, &val);
- if (ret) {
- dev_err(dev, "Failed to read src\n");
- return ret;
- }
+ if (priv->regmap) {
+ ret = regmap_read(priv->regmap, dcfg->src_reg, &val);
+ if (ret) {
+ dev_err(dev, "Failed to read src\n");
+ return ret;
+ }

- if (!(val & dcfg->src_stop)) {
- priv->mode = IMX_RPROC_EARLY_BOOT;
- priv->rproc->state = RPROC_DETACHED;
+ if (!(val & dcfg->src_stop)) {
+ priv->rproc->state = RPROC_DETACHED;
+ priv->mode = IMX_RPROC_EARLY_BOOT;
+ }
}

return 0;
@@ -600,16 +615,9 @@ static int imx_rproc_probe(struct platform_device *pdev)
struct rproc *rproc;
struct regmap_config config = { .name = "imx-rproc" };
const struct imx_rproc_dcfg *dcfg;
- struct regmap *regmap;
+ struct regmap *regmap = NULL;
int ret;

- regmap = syscon_regmap_lookup_by_phandle(np, "syscon");
- if (IS_ERR(regmap)) {
- dev_err(dev, "failed to find syscon\n");
- return PTR_ERR(regmap);
- }
- regmap_attach_dev(dev, regmap, &config);
-
/* set some other name then imx */
rproc = rproc_alloc(dev, "imx-rproc", &imx_rproc_ops,
NULL, sizeof(*priv));
@@ -622,6 +630,16 @@ static int imx_rproc_probe(struct platform_device *pdev)
goto err_put_rproc;
}

+ if (dcfg->method == IMX_RPROC_MMIO) {
+ regmap = syscon_regmap_lookup_by_phandle(np, "syscon");
+ if (IS_ERR(regmap)) {
+ dev_err(dev, "failed to find syscon\n");
+ ret = PTR_ERR(regmap);
+ goto err_put_rproc;
+ }
+ regmap_attach_dev(dev, regmap, &config);
+ }
+
priv = rproc->priv;
priv->rproc = rproc;
priv->regmap = regmap;
--
2.30.0

2021-04-08 02:12:38

by Peng Fan (OSS)

[permalink] [raw]
Subject: [PATCH V3 7/8] remoteproc: imx_rproc: support i.MX7ULP

From: Peng Fan <[email protected]>

i.MX7ULP A7 core runs under control of M4 core, M4 core starts by ROM
and powers most serivces used by A7 core, so A7 core has no power to
start and stop M4 core.

Signed-off-by: Peng Fan <[email protected]>
---
drivers/remoteproc/imx_rproc.c | 25 ++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index a7fa9d7fc2d1..b911a7539897 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -147,6 +147,14 @@ static const struct imx_rproc_att imx_rproc_att_imx8mq[] = {
{ 0x40000000, 0x40000000, 0x80000000, 0 },
};

+static const struct imx_rproc_att imx_rproc_att_imx7ulp[] = {
+ {0x1FFD0000, 0x1FFD0000, 0x30000, ATT_OWN},
+ {0x20000000, 0x20000000, 0x10000, ATT_OWN},
+ {0x2F000000, 0x2F000000, 0x20000, ATT_OWN},
+ {0x2F020000, 0x2F020000, 0x20000, ATT_OWN},
+ {0x60000000, 0x60000000, 0x40000000, 0}
+};
+
static const struct imx_rproc_att imx_rproc_att_imx7d[] = {
/* dev addr , sys addr , size , flags */
/* OCRAM_S (M4 Boot code) - alias */
@@ -207,6 +215,12 @@ static const struct imx_rproc_dcfg imx_rproc_cfg_imx8mq = {
.method = IMX_RPROC_MMIO,
};

+static const struct imx_rproc_dcfg imx_rproc_cfg_imx7ulp = {
+ .att = imx_rproc_att_imx7ulp,
+ .att_size = ARRAY_SIZE(imx_rproc_att_imx7ulp),
+ .method = IMX_RPROC_NONE,
+};
+
static const struct imx_rproc_dcfg imx_rproc_cfg_imx7d = {
.src_reg = IMX7D_SRC_SCR,
.src_mask = IMX7D_M4_RST_MASK,
@@ -598,12 +612,16 @@ static int imx_rproc_detect_mode(struct imx_rproc *priv)
return ret;
}

- if (!(val & dcfg->src_stop)) {
- priv->rproc->state = RPROC_DETACHED;
+ if (!(val & dcfg->src_stop))
priv->mode = IMX_RPROC_EARLY_BOOT;
- }
}

+ if (dcfg->method == IMX_RPROC_NONE)
+ priv->mode = IMX_RPROC_EARLY_BOOT;
+
+ if (priv->mode == IMX_RPROC_EARLY_BOOT)
+ priv->rproc->state = RPROC_DETACHED;
+
return 0;
}

@@ -724,6 +742,7 @@ static int imx_rproc_remove(struct platform_device *pdev)
}

static const struct of_device_id imx_rproc_of_match[] = {
+ { .compatible = "fsl,imx7ulp-cm4", .data = &imx_rproc_cfg_imx7ulp },
{ .compatible = "fsl,imx7d-cm4", .data = &imx_rproc_cfg_imx7d },
{ .compatible = "fsl,imx6sx-cm4", .data = &imx_rproc_cfg_imx6sx },
{ .compatible = "fsl,imx8mq-cm4", .data = &imx_rproc_cfg_imx8mq },
--
2.30.0

2021-04-08 02:12:58

by Peng Fan (OSS)

[permalink] [raw]
Subject: [PATCH V3 8/8] remoteproc: imx_rproc: support i.MX8MN/P

From: Peng Fan <[email protected]>

Add i.MX8MN/P remote processor(Cortex-M7) support, we are using ARM
SMCCC to start/stop M core, not using regmap interface.

Signed-off-by: Peng Fan <[email protected]>
---
drivers/remoteproc/imx_rproc.c | 89 +++++++++++++++++++++++++++++++---
1 file changed, 82 insertions(+), 7 deletions(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index b911a7539897..9351626f09c0 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -3,6 +3,7 @@
* Copyright (c) 2017 Pengutronix, Oleksij Rempel <[email protected]>
*/

+#include <linux/arm-smccc.h>
#include <linux/clk.h>
#include <linux/err.h>
#include <linux/interrupt.h>
@@ -50,6 +51,11 @@

#define IMX_RPROC_MEM_MAX 32

+#define IMX_SIP_RPROC 0xC2000005
+#define IMX_SIP_RPROC_START 0x00
+#define IMX_SIP_RPROC_STARTED 0x01
+#define IMX_SIP_RPROC_STOP 0x02
+
/**
* struct imx_rproc_mem - slim internal memory structure
* @cpu_addr: MPU virtual address of the memory region
@@ -119,6 +125,36 @@ struct imx_rproc {
enum imx_rproc_mode mode;
};

+static const struct imx_rproc_att imx_rproc_att_imx8mn[] = {
+ /* dev addr , sys addr , size , flags */
+ /* ITCM */
+ { 0x00000000, 0x007E0000, 0x00020000, ATT_OWN },
+ /* OCRAM_S */
+ { 0x00180000, 0x00180000, 0x00009000, 0 },
+ /* OCRAM */
+ { 0x00900000, 0x00900000, 0x00020000, 0 },
+ /* OCRAM */
+ { 0x00920000, 0x00920000, 0x00020000, 0 },
+ /* OCRAM */
+ { 0x00940000, 0x00940000, 0x00050000, 0 },
+ /* QSPI Code - alias */
+ { 0x08000000, 0x08000000, 0x08000000, 0 },
+ /* DDR (Code) - alias */
+ { 0x10000000, 0x40000000, 0x0FFE0000, 0 },
+ /* DTCM */
+ { 0x20000000, 0x00800000, 0x00020000, ATT_OWN },
+ /* OCRAM_S - alias */
+ { 0x20180000, 0x00180000, 0x00008000, ATT_OWN },
+ /* OCRAM */
+ { 0x20200000, 0x00900000, 0x00020000, ATT_OWN },
+ /* OCRAM */
+ { 0x20220000, 0x00920000, 0x00020000, ATT_OWN },
+ /* OCRAM */
+ { 0x20240000, 0x00940000, 0x00040000, ATT_OWN },
+ /* DDR (Data) */
+ { 0x40000000, 0x40000000, 0x80000000, 0 },
+};
+
static const struct imx_rproc_att imx_rproc_att_imx8mq[] = {
/* dev addr , sys addr , size , flags */
/* TCML - alias */
@@ -205,6 +241,12 @@ static const struct imx_rproc_att imx_rproc_att_imx6sx[] = {
{ 0x80000000, 0x80000000, 0x60000000, 0 },
};

+static const struct imx_rproc_dcfg imx_rproc_cfg_imx8mn = {
+ .att = imx_rproc_att_imx8mn,
+ .att_size = ARRAY_SIZE(imx_rproc_att_imx8mn),
+ .method = IMX_RPROC_SMC,
+};
+
static const struct imx_rproc_dcfg imx_rproc_cfg_imx8mq = {
.src_reg = IMX7D_SRC_SCR,
.src_mask = IMX7D_M4_RST_MASK,
@@ -246,12 +288,24 @@ static int imx_rproc_start(struct rproc *rproc)
struct imx_rproc *priv = rproc->priv;
const struct imx_rproc_dcfg *dcfg = priv->dcfg;
struct device *dev = priv->dev;
+ struct arm_smccc_res res;
int ret;

- ret = regmap_update_bits(priv->regmap, dcfg->src_reg,
- dcfg->src_mask, dcfg->src_start);
+ switch (dcfg->method) {
+ case IMX_RPROC_MMIO:
+ ret = regmap_update_bits(priv->regmap, dcfg->src_reg, dcfg->src_mask,
+ dcfg->src_start);
+ break;
+ case IMX_RPROC_SMC:
+ arm_smccc_smc(IMX_SIP_RPROC, IMX_SIP_RPROC_START, 0, 0, 0, 0, 0, 0, &res);
+ ret = res.a0;
+ break;
+ default:
+ return -EOPNOTSUPP;
+ }
+
if (ret)
- dev_err(dev, "Failed to enable M4!\n");
+ dev_err(dev, "Failed to enable remote cores!\n");

return ret;
}
@@ -261,12 +315,26 @@ static int imx_rproc_stop(struct rproc *rproc)
struct imx_rproc *priv = rproc->priv;
const struct imx_rproc_dcfg *dcfg = priv->dcfg;
struct device *dev = priv->dev;
+ struct arm_smccc_res res;
int ret;

- ret = regmap_update_bits(priv->regmap, dcfg->src_reg,
- dcfg->src_mask, dcfg->src_stop);
+ switch (dcfg->method) {
+ case IMX_RPROC_MMIO:
+ ret = regmap_update_bits(priv->regmap, dcfg->src_reg, dcfg->src_mask,
+ dcfg->src_stop);
+ break;
+ case IMX_RPROC_SMC:
+ arm_smccc_smc(IMX_SIP_RPROC, IMX_SIP_RPROC_STOP, 0, 0, 0, 0, 0, 0, &res);
+ ret = res.a0;
+ if (res.a1)
+ dev_info(dev, "Not in wfi, force stopped\n");
+ break;
+ default:
+ return -EOPNOTSUPP;
+ }
+
if (ret)
- dev_err(dev, "Failed to stop M4!\n");
+ dev_err(dev, "Failed to stop remote cores\n");

return ret;
}
@@ -600,6 +668,7 @@ static int imx_rproc_detect_mode(struct imx_rproc *priv)
{
const struct imx_rproc_dcfg *dcfg = priv->dcfg;
struct device *dev = priv->dev;
+ struct arm_smccc_res res;
int ret;
u32 val;

@@ -616,8 +685,12 @@ static int imx_rproc_detect_mode(struct imx_rproc *priv)
priv->mode = IMX_RPROC_EARLY_BOOT;
}

- if (dcfg->method == IMX_RPROC_NONE)
+ if (dcfg->method == IMX_RPROC_NONE) {
priv->mode = IMX_RPROC_EARLY_BOOT;
+ } else if (dcfg->method == IMX_RPROC_SMC) {
+ arm_smccc_smc(IMX_SIP_RPROC, IMX_SIP_RPROC_STARTED, 0, 0, 0, 0, 0, 0, &res);
+ priv->mode = res.a0 ? IMX_RPROC_EARLY_BOOT : IMX_RPROC_NORMAL;
+ }

if (priv->mode == IMX_RPROC_EARLY_BOOT)
priv->rproc->state = RPROC_DETACHED;
@@ -747,6 +820,8 @@ static const struct of_device_id imx_rproc_of_match[] = {
{ .compatible = "fsl,imx6sx-cm4", .data = &imx_rproc_cfg_imx6sx },
{ .compatible = "fsl,imx8mq-cm4", .data = &imx_rproc_cfg_imx8mq },
{ .compatible = "fsl,imx8mm-cm4", .data = &imx_rproc_cfg_imx8mq },
+ { .compatible = "fsl,imx8mn-cm7", .data = &imx_rproc_cfg_imx8mn },
+ { .compatible = "fsl,imx8mp-cm7", .data = &imx_rproc_cfg_imx8mn },
{},
};
MODULE_DEVICE_TABLE(of, imx_rproc_of_match);
--
2.30.0

2021-04-13 22:11:07

by Mathieu Poirier

[permalink] [raw]
Subject: Re: [PATCH V3 5/8] remoteproc: imx_rproc: parse fsl,auto-boot

On Thu, Apr 08, 2021 at 09:54:55AM +0800, [email protected] wrote:
> From: Peng Fan <[email protected]>
>
> Parse fsl,auto-boot to indicate whether need remoteproc framework
> auto boot or not.
>
> When remote processor is booted before Linux Kernel up, do not parse
> fsl,auto-boot. So add an entry to store the working mode of remote
> processor. Currently only IMX_RPROC_NORMAL, IMX_RPROC_EARLY_BOOT.
>
> Signed-off-by: Peng Fan <[email protected]>
> ---
> drivers/remoteproc/imx_rproc.c | 20 +++++++++++++++++++-
> 1 file changed, 19 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
> index ca17f520d904..c576e12d3817 100644
> --- a/drivers/remoteproc/imx_rproc.c
> +++ b/drivers/remoteproc/imx_rproc.c
> @@ -83,6 +83,16 @@ struct imx_rproc_dcfg {
> size_t att_size;
> };
>
> +enum imx_rproc_mode {
> + /* Linux load/kick remote core */
> + IMX_RPROC_NORMAL,
> + /*
> + * remote core booted before kicking Linux, and remote core
> + * could be stopped & restarted by Linux
> + */
> + IMX_RPROC_EARLY_BOOT,
> +};
> +

As far as I can see a new mode to track the state of the remote processor is not
needed. rproc->state can do that for you.

> struct imx_rproc {
> struct device *dev;
> struct regmap *regmap;
> @@ -96,6 +106,7 @@ struct imx_rproc {
> struct work_struct rproc_work;
> struct workqueue_struct *workqueue;
> void __iomem *rsc_table;
> + enum imx_rproc_mode mode;
> };
>
> static const struct imx_rproc_att imx_rproc_att_imx8mq[] = {
> @@ -565,14 +576,18 @@ static int imx_rproc_detect_mode(struct imx_rproc *priv)
> int ret;
> u32 val;
>
> + priv->mode = IMX_RPROC_NORMAL;
> +
> ret = regmap_read(priv->regmap, dcfg->src_reg, &val);
> if (ret) {
> dev_err(dev, "Failed to read src\n");
> return ret;
> }
>
> - if (!(val & dcfg->src_stop))
> + if (!(val & dcfg->src_stop)) {
> + priv->mode = IMX_RPROC_EARLY_BOOT;
> priv->rproc->state = RPROC_DETACHED;
> + }
>
> return 0;
> }
> @@ -654,6 +669,9 @@ static int imx_rproc_probe(struct platform_device *pdev)
>
> INIT_WORK(&priv->rproc_work, imx_rproc_vq_work);
>
> + if (priv->mode == IMX_RPROC_NORMAL)
> + rproc->auto_boot = of_property_read_bool(np, "fsl,auto-boot");
> +

if (rproc->state == RPROC_DETACHED)

> ret = rproc_add(rproc);
> if (ret) {
> dev_err(dev, "rproc_add failed\n");
> --
> 2.30.0
>

2021-04-13 22:14:49

by Mathieu Poirier

[permalink] [raw]
Subject: Re: [PATCH V3 6/8] remoteproc: imx_rproc: initial support for mutilple start/stop method

On Thu, Apr 08, 2021 at 09:54:56AM +0800, [email protected] wrote:
> From: Peng Fan <[email protected]>
>
> Add three methods IMX_RPROC_NONE(no need start/stop), IMX_RPROC_MMIO
> (start/stop through mmio) and IMX_RPROC_SMC(start/stop through ARM SMCCC).
>
> The current SoCs supported are all using IMX_RPROC_MMIO, add a restrict
> in probe that only SoCs using IMX_RPROC_MMIO needs syscon regmap to
> access registers.
>
> Signed-off-by: Peng Fan <[email protected]>
> ---
> drivers/remoteproc/imx_rproc.c | 50 +++++++++++++++++++++++-----------
> 1 file changed, 34 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
> index c576e12d3817..a7fa9d7fc2d1 100644
> --- a/drivers/remoteproc/imx_rproc.c
> +++ b/drivers/remoteproc/imx_rproc.c
> @@ -74,6 +74,15 @@ struct imx_rproc_att {
> int flags;
> };
>
> +/* Remote core start/stop method */
> +enum imx_rproc_method {
> + IMX_RPROC_NONE,
> + /* Through syscon regmap */
> + IMX_RPROC_MMIO,
> + /* Through ARM SMCCC */
> + IMX_RPROC_SMC,
> +};
> +
> struct imx_rproc_dcfg {
> u32 src_reg;
> u32 src_mask;
> @@ -81,6 +90,7 @@ struct imx_rproc_dcfg {
> u32 src_stop;
> const struct imx_rproc_att *att;
> size_t att_size;
> + enum imx_rproc_method method;
> };
>
> enum imx_rproc_mode {
> @@ -194,6 +204,7 @@ static const struct imx_rproc_dcfg imx_rproc_cfg_imx8mq = {
> .src_stop = IMX7D_M4_STOP,
> .att = imx_rproc_att_imx8mq,
> .att_size = ARRAY_SIZE(imx_rproc_att_imx8mq),
> + .method = IMX_RPROC_MMIO,
> };
>
> static const struct imx_rproc_dcfg imx_rproc_cfg_imx7d = {
> @@ -203,6 +214,7 @@ static const struct imx_rproc_dcfg imx_rproc_cfg_imx7d = {
> .src_stop = IMX7D_M4_STOP,
> .att = imx_rproc_att_imx7d,
> .att_size = ARRAY_SIZE(imx_rproc_att_imx7d),
> + .method = IMX_RPROC_MMIO,
> };
>
> static const struct imx_rproc_dcfg imx_rproc_cfg_imx6sx = {
> @@ -212,6 +224,7 @@ static const struct imx_rproc_dcfg imx_rproc_cfg_imx6sx = {
> .src_stop = IMX6SX_M4_STOP,
> .att = imx_rproc_att_imx6sx,
> .att_size = ARRAY_SIZE(imx_rproc_att_imx6sx),
> + .method = IMX_RPROC_MMIO,
> };
>
> static int imx_rproc_start(struct rproc *rproc)
> @@ -578,15 +591,17 @@ static int imx_rproc_detect_mode(struct imx_rproc *priv)
>
> priv->mode = IMX_RPROC_NORMAL;
>
> - ret = regmap_read(priv->regmap, dcfg->src_reg, &val);
> - if (ret) {
> - dev_err(dev, "Failed to read src\n");
> - return ret;
> - }
> + if (priv->regmap) {
> + ret = regmap_read(priv->regmap, dcfg->src_reg, &val);
> + if (ret) {
> + dev_err(dev, "Failed to read src\n");
> + return ret;
> + }
>
> - if (!(val & dcfg->src_stop)) {
> - priv->mode = IMX_RPROC_EARLY_BOOT;
> - priv->rproc->state = RPROC_DETACHED;
> + if (!(val & dcfg->src_stop)) {
> + priv->rproc->state = RPROC_DETACHED;
> + priv->mode = IMX_RPROC_EARLY_BOOT;
> + }
> }
>
> return 0;
> @@ -600,16 +615,9 @@ static int imx_rproc_probe(struct platform_device *pdev)
> struct rproc *rproc;
> struct regmap_config config = { .name = "imx-rproc" };
> const struct imx_rproc_dcfg *dcfg;
> - struct regmap *regmap;
> + struct regmap *regmap = NULL;
> int ret;
>
> - regmap = syscon_regmap_lookup_by_phandle(np, "syscon");
> - if (IS_ERR(regmap)) {
> - dev_err(dev, "failed to find syscon\n");
> - return PTR_ERR(regmap);
> - }
> - regmap_attach_dev(dev, regmap, &config);
> -
> /* set some other name then imx */
> rproc = rproc_alloc(dev, "imx-rproc", &imx_rproc_ops,
> NULL, sizeof(*priv));
> @@ -622,6 +630,16 @@ static int imx_rproc_probe(struct platform_device *pdev)
> goto err_put_rproc;
> }
>
> + if (dcfg->method == IMX_RPROC_MMIO) {
> + regmap = syscon_regmap_lookup_by_phandle(np, "syscon");
> + if (IS_ERR(regmap)) {
> + dev_err(dev, "failed to find syscon\n");
> + ret = PTR_ERR(regmap);
> + goto err_put_rproc;
> + }
> + regmap_attach_dev(dev, regmap, &config);
> + }

I would move this to imx_rproc_detect_mode() and get rid of the "if
(priv->regmap)" that is there.

> +
> priv = rproc->priv;
> priv->rproc = rproc;
> priv->regmap = regmap;
> --
> 2.30.0
>

2021-04-13 22:17:56

by Mathieu Poirier

[permalink] [raw]
Subject: Re: [PATCH V3 7/8] remoteproc: imx_rproc: support i.MX7ULP

On Thu, Apr 08, 2021 at 09:54:57AM +0800, [email protected] wrote:
> From: Peng Fan <[email protected]>
>
> i.MX7ULP A7 core runs under control of M4 core, M4 core starts by ROM
> and powers most serivces used by A7 core, so A7 core has no power to
> start and stop M4 core.
>
> Signed-off-by: Peng Fan <[email protected]>
> ---
> drivers/remoteproc/imx_rproc.c | 25 ++++++++++++++++++++++---
> 1 file changed, 22 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
> index a7fa9d7fc2d1..b911a7539897 100644
> --- a/drivers/remoteproc/imx_rproc.c
> +++ b/drivers/remoteproc/imx_rproc.c
> @@ -147,6 +147,14 @@ static const struct imx_rproc_att imx_rproc_att_imx8mq[] = {
> { 0x40000000, 0x40000000, 0x80000000, 0 },
> };
>
> +static const struct imx_rproc_att imx_rproc_att_imx7ulp[] = {
> + {0x1FFD0000, 0x1FFD0000, 0x30000, ATT_OWN},
> + {0x20000000, 0x20000000, 0x10000, ATT_OWN},
> + {0x2F000000, 0x2F000000, 0x20000, ATT_OWN},
> + {0x2F020000, 0x2F020000, 0x20000, ATT_OWN},
> + {0x60000000, 0x60000000, 0x40000000, 0}
> +};
> +
> static const struct imx_rproc_att imx_rproc_att_imx7d[] = {
> /* dev addr , sys addr , size , flags */
> /* OCRAM_S (M4 Boot code) - alias */
> @@ -207,6 +215,12 @@ static const struct imx_rproc_dcfg imx_rproc_cfg_imx8mq = {
> .method = IMX_RPROC_MMIO,
> };
>
> +static const struct imx_rproc_dcfg imx_rproc_cfg_imx7ulp = {
> + .att = imx_rproc_att_imx7ulp,
> + .att_size = ARRAY_SIZE(imx_rproc_att_imx7ulp),
> + .method = IMX_RPROC_NONE,
> +};
> +
> static const struct imx_rproc_dcfg imx_rproc_cfg_imx7d = {
> .src_reg = IMX7D_SRC_SCR,
> .src_mask = IMX7D_M4_RST_MASK,
> @@ -598,12 +612,16 @@ static int imx_rproc_detect_mode(struct imx_rproc *priv)
> return ret;
> }
>
> - if (!(val & dcfg->src_stop)) {
> - priv->rproc->state = RPROC_DETACHED;
> + if (!(val & dcfg->src_stop))
> priv->mode = IMX_RPROC_EARLY_BOOT;
> - }
> }
>
> + if (dcfg->method == IMX_RPROC_NONE)
> + priv->mode = IMX_RPROC_EARLY_BOOT;

As I pointed out there is no need for priv->mode. Just declare a boolean
variable that is local to this function and use it to determine the state of the
remote processor:

if (dcfg->method == IMX_RPROC_NONE)
early_boot = true;

if (early_boot)
priv->rproc->state = RPROC_DETACHED;

> +
> + if (priv->mode == IMX_RPROC_EARLY_BOOT)
> + priv->rproc->state = RPROC_DETACHED;
> +
> return 0;
> }
>
> @@ -724,6 +742,7 @@ static int imx_rproc_remove(struct platform_device *pdev)
> }
>
> static const struct of_device_id imx_rproc_of_match[] = {
> + { .compatible = "fsl,imx7ulp-cm4", .data = &imx_rproc_cfg_imx7ulp },
> { .compatible = "fsl,imx7d-cm4", .data = &imx_rproc_cfg_imx7d },
> { .compatible = "fsl,imx6sx-cm4", .data = &imx_rproc_cfg_imx6sx },
> { .compatible = "fsl,imx8mq-cm4", .data = &imx_rproc_cfg_imx8mq },
> --
> 2.30.0
>

2021-04-13 22:29:33

by Mathieu Poirier

[permalink] [raw]
Subject: Re: [PATCH V3 8/8] remoteproc: imx_rproc: support i.MX8MN/P

On Thu, Apr 08, 2021 at 09:54:58AM +0800, [email protected] wrote:
> From: Peng Fan <[email protected]>
>
> Add i.MX8MN/P remote processor(Cortex-M7) support, we are using ARM
> SMCCC to start/stop M core, not using regmap interface.
>
> Signed-off-by: Peng Fan <[email protected]>
> ---
> drivers/remoteproc/imx_rproc.c | 89 +++++++++++++++++++++++++++++++---
> 1 file changed, 82 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
> index b911a7539897..9351626f09c0 100644
> --- a/drivers/remoteproc/imx_rproc.c
> +++ b/drivers/remoteproc/imx_rproc.c
> @@ -3,6 +3,7 @@
> * Copyright (c) 2017 Pengutronix, Oleksij Rempel <[email protected]>
> */
>
> +#include <linux/arm-smccc.h>
> #include <linux/clk.h>
> #include <linux/err.h>
> #include <linux/interrupt.h>
> @@ -50,6 +51,11 @@
>
> #define IMX_RPROC_MEM_MAX 32
>
> +#define IMX_SIP_RPROC 0xC2000005
> +#define IMX_SIP_RPROC_START 0x00
> +#define IMX_SIP_RPROC_STARTED 0x01
> +#define IMX_SIP_RPROC_STOP 0x02
> +
> /**
> * struct imx_rproc_mem - slim internal memory structure
> * @cpu_addr: MPU virtual address of the memory region
> @@ -119,6 +125,36 @@ struct imx_rproc {
> enum imx_rproc_mode mode;
> };
>
> +static const struct imx_rproc_att imx_rproc_att_imx8mn[] = {
> + /* dev addr , sys addr , size , flags */
> + /* ITCM */
> + { 0x00000000, 0x007E0000, 0x00020000, ATT_OWN },
> + /* OCRAM_S */
> + { 0x00180000, 0x00180000, 0x00009000, 0 },
> + /* OCRAM */
> + { 0x00900000, 0x00900000, 0x00020000, 0 },
> + /* OCRAM */
> + { 0x00920000, 0x00920000, 0x00020000, 0 },
> + /* OCRAM */
> + { 0x00940000, 0x00940000, 0x00050000, 0 },
> + /* QSPI Code - alias */
> + { 0x08000000, 0x08000000, 0x08000000, 0 },
> + /* DDR (Code) - alias */
> + { 0x10000000, 0x40000000, 0x0FFE0000, 0 },
> + /* DTCM */
> + { 0x20000000, 0x00800000, 0x00020000, ATT_OWN },
> + /* OCRAM_S - alias */
> + { 0x20180000, 0x00180000, 0x00008000, ATT_OWN },
> + /* OCRAM */
> + { 0x20200000, 0x00900000, 0x00020000, ATT_OWN },
> + /* OCRAM */
> + { 0x20220000, 0x00920000, 0x00020000, ATT_OWN },
> + /* OCRAM */
> + { 0x20240000, 0x00940000, 0x00040000, ATT_OWN },
> + /* DDR (Data) */
> + { 0x40000000, 0x40000000, 0x80000000, 0 },
> +};
> +
> static const struct imx_rproc_att imx_rproc_att_imx8mq[] = {
> /* dev addr , sys addr , size , flags */
> /* TCML - alias */
> @@ -205,6 +241,12 @@ static const struct imx_rproc_att imx_rproc_att_imx6sx[] = {
> { 0x80000000, 0x80000000, 0x60000000, 0 },
> };
>
> +static const struct imx_rproc_dcfg imx_rproc_cfg_imx8mn = {
> + .att = imx_rproc_att_imx8mn,
> + .att_size = ARRAY_SIZE(imx_rproc_att_imx8mn),
> + .method = IMX_RPROC_SMC,
> +};
> +
> static const struct imx_rproc_dcfg imx_rproc_cfg_imx8mq = {
> .src_reg = IMX7D_SRC_SCR,
> .src_mask = IMX7D_M4_RST_MASK,
> @@ -246,12 +288,24 @@ static int imx_rproc_start(struct rproc *rproc)
> struct imx_rproc *priv = rproc->priv;
> const struct imx_rproc_dcfg *dcfg = priv->dcfg;
> struct device *dev = priv->dev;
> + struct arm_smccc_res res;
> int ret;
>
> - ret = regmap_update_bits(priv->regmap, dcfg->src_reg,
> - dcfg->src_mask, dcfg->src_start);
> + switch (dcfg->method) {
> + case IMX_RPROC_MMIO:
> + ret = regmap_update_bits(priv->regmap, dcfg->src_reg, dcfg->src_mask,
> + dcfg->src_start);
> + break;
> + case IMX_RPROC_SMC:
> + arm_smccc_smc(IMX_SIP_RPROC, IMX_SIP_RPROC_START, 0, 0, 0, 0, 0, 0, &res);
> + ret = res.a0;
> + break;
> + default:
> + return -EOPNOTSUPP;
> + }
> +
> if (ret)
> - dev_err(dev, "Failed to enable M4!\n");
> + dev_err(dev, "Failed to enable remote cores!\n");
>
> return ret;
> }
> @@ -261,12 +315,26 @@ static int imx_rproc_stop(struct rproc *rproc)
> struct imx_rproc *priv = rproc->priv;
> const struct imx_rproc_dcfg *dcfg = priv->dcfg;
> struct device *dev = priv->dev;
> + struct arm_smccc_res res;
> int ret;
>
> - ret = regmap_update_bits(priv->regmap, dcfg->src_reg,
> - dcfg->src_mask, dcfg->src_stop);
> + switch (dcfg->method) {
> + case IMX_RPROC_MMIO:
> + ret = regmap_update_bits(priv->regmap, dcfg->src_reg, dcfg->src_mask,
> + dcfg->src_stop);
> + break;
> + case IMX_RPROC_SMC:
> + arm_smccc_smc(IMX_SIP_RPROC, IMX_SIP_RPROC_STOP, 0, 0, 0, 0, 0, 0, &res);
> + ret = res.a0;
> + if (res.a1)
> + dev_info(dev, "Not in wfi, force stopped\n");
> + break;
> + default:
> + return -EOPNOTSUPP;
> + }
> +
> if (ret)
> - dev_err(dev, "Failed to stop M4!\n");
> + dev_err(dev, "Failed to stop remote cores\n");
>
> return ret;
> }
> @@ -600,6 +668,7 @@ static int imx_rproc_detect_mode(struct imx_rproc *priv)
> {
> const struct imx_rproc_dcfg *dcfg = priv->dcfg;
> struct device *dev = priv->dev;
> + struct arm_smccc_res res;
> int ret;
> u32 val;
>
> @@ -616,8 +685,12 @@ static int imx_rproc_detect_mode(struct imx_rproc *priv)
> priv->mode = IMX_RPROC_EARLY_BOOT;
> }
>
> - if (dcfg->method == IMX_RPROC_NONE)
> + if (dcfg->method == IMX_RPROC_NONE) {
> priv->mode = IMX_RPROC_EARLY_BOOT;
> + } else if (dcfg->method == IMX_RPROC_SMC) {
> + arm_smccc_smc(IMX_SIP_RPROC, IMX_SIP_RPROC_STARTED, 0, 0, 0, 0, 0, 0, &res);
> + priv->mode = res.a0 ? IMX_RPROC_EARLY_BOOT : IMX_RPROC_NORMAL;
> + }

When all patches have been applied this function is really hard to read. I
suggest using a switch() statement like you did in imx_rproc_start() and
imx_rproc_stop().

Thanks,
Mathieu

>
> if (priv->mode == IMX_RPROC_EARLY_BOOT)
> priv->rproc->state = RPROC_DETACHED;
> @@ -747,6 +820,8 @@ static const struct of_device_id imx_rproc_of_match[] = {
> { .compatible = "fsl,imx6sx-cm4", .data = &imx_rproc_cfg_imx6sx },
> { .compatible = "fsl,imx8mq-cm4", .data = &imx_rproc_cfg_imx8mq },
> { .compatible = "fsl,imx8mm-cm4", .data = &imx_rproc_cfg_imx8mq },
> + { .compatible = "fsl,imx8mn-cm7", .data = &imx_rproc_cfg_imx8mn },
> + { .compatible = "fsl,imx8mp-cm7", .data = &imx_rproc_cfg_imx8mn },
> {},
> };
> MODULE_DEVICE_TABLE(of, imx_rproc_of_match);
> --
> 2.30.0
>

2021-04-14 04:12:54

by Mathieu Poirier

[permalink] [raw]
Subject: Re: [PATCH V3 4/8] remoteproc: imx_rproc: make clk optional

On Thu, Apr 08, 2021 at 09:54:54AM +0800, [email protected] wrote:
> From: Peng Fan <[email protected]>
>
> To i.MX7ULP, M4 is the master to control everything, so it not need
> clk from A7.
>
> Reviewed-by: Richard Zhu <[email protected]>
> Signed-off-by: Peng Fan <[email protected]>
> ---
> drivers/remoteproc/imx_rproc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
> index d6338872c6db..ca17f520d904 100644
> --- a/drivers/remoteproc/imx_rproc.c
> +++ b/drivers/remoteproc/imx_rproc.c
> @@ -635,7 +635,7 @@ static int imx_rproc_probe(struct platform_device *pdev)
> if (ret)
> goto err_put_mbox;
>
> - priv->clk = devm_clk_get(dev, NULL);
> + priv->clk = devm_clk_get_optional(dev, NULL);

Overnight the clock becomes optional for all remote processors? Why not call
devm_clk_get() or devm_clk_get_optional() based on the remote processor type in
a new function called imx_rproc_clk_get()?

> if (IS_ERR(priv->clk)) {
> dev_err(dev, "Failed to get clock\n");
> ret = PTR_ERR(priv->clk);
> --
> 2.30.0
>

2021-04-15 13:51:37

by Peng Fan (OSS)

[permalink] [raw]
Subject: RE: [PATCH V3 8/8] remoteproc: imx_rproc: support i.MX8MN/P

> Subject: Re: [PATCH V3 8/8] remoteproc: imx_rproc: support i.MX8MN/P

Hi Mathieu,

Your all comments are good suggestion in the patchset, I not reply your
comment one by one for each patch. In V4 patchset, hope I have fixed
all the issues you pointed.

Thanks for your reviewing.

Thanks,
Peng.

>
> On Thu, Apr 08, 2021 at 09:54:58AM +0800, [email protected] wrote:
> > From: Peng Fan <[email protected]>
> >
> > Add i.MX8MN/P remote processor(Cortex-M7) support, we are using ARM
> > SMCCC to start/stop M core, not using regmap interface.
> >
> > Signed-off-by: Peng Fan <[email protected]>
> > ---
> > drivers/remoteproc/imx_rproc.c | 89
> > +++++++++++++++++++++++++++++++---
> > 1 file changed, 82 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/remoteproc/imx_rproc.c
> > b/drivers/remoteproc/imx_rproc.c index b911a7539897..9351626f09c0
> > 100644
> > --- a/drivers/remoteproc/imx_rproc.c
> > +++ b/drivers/remoteproc/imx_rproc.c
> > @@ -3,6 +3,7 @@
> > * Copyright (c) 2017 Pengutronix, Oleksij Rempel
> <[email protected]>
> > */
> >
> > +#include <linux/arm-smccc.h>
> > #include <linux/clk.h>
> > #include <linux/err.h>
> > #include <linux/interrupt.h>
> > @@ -50,6 +51,11 @@
> >
> > #define IMX_RPROC_MEM_MAX 32
> >
> > +#define IMX_SIP_RPROC 0xC2000005
> > +#define IMX_SIP_RPROC_START 0x00
> > +#define IMX_SIP_RPROC_STARTED 0x01
> > +#define IMX_SIP_RPROC_STOP 0x02
> > +
> > /**
> > * struct imx_rproc_mem - slim internal memory structure
> > * @cpu_addr: MPU virtual address of the memory region @@ -119,6
> > +125,36 @@ struct imx_rproc {
> > enum imx_rproc_mode mode;
> > };
> >
> > +static const struct imx_rproc_att imx_rproc_att_imx8mn[] = {
> > + /* dev addr , sys addr , size , flags */
> > + /* ITCM */
> > + { 0x00000000, 0x007E0000, 0x00020000, ATT_OWN },
> > + /* OCRAM_S */
> > + { 0x00180000, 0x00180000, 0x00009000, 0 },
> > + /* OCRAM */
> > + { 0x00900000, 0x00900000, 0x00020000, 0 },
> > + /* OCRAM */
> > + { 0x00920000, 0x00920000, 0x00020000, 0 },
> > + /* OCRAM */
> > + { 0x00940000, 0x00940000, 0x00050000, 0 },
> > + /* QSPI Code - alias */
> > + { 0x08000000, 0x08000000, 0x08000000, 0 },
> > + /* DDR (Code) - alias */
> > + { 0x10000000, 0x40000000, 0x0FFE0000, 0 },
> > + /* DTCM */
> > + { 0x20000000, 0x00800000, 0x00020000, ATT_OWN },
> > + /* OCRAM_S - alias */
> > + { 0x20180000, 0x00180000, 0x00008000, ATT_OWN },
> > + /* OCRAM */
> > + { 0x20200000, 0x00900000, 0x00020000, ATT_OWN },
> > + /* OCRAM */
> > + { 0x20220000, 0x00920000, 0x00020000, ATT_OWN },
> > + /* OCRAM */
> > + { 0x20240000, 0x00940000, 0x00040000, ATT_OWN },
> > + /* DDR (Data) */
> > + { 0x40000000, 0x40000000, 0x80000000, 0 }, };
> > +
> > static const struct imx_rproc_att imx_rproc_att_imx8mq[] = {
> > /* dev addr , sys addr , size , flags */
> > /* TCML - alias */
> > @@ -205,6 +241,12 @@ static const struct imx_rproc_att
> imx_rproc_att_imx6sx[] = {
> > { 0x80000000, 0x80000000, 0x60000000, 0 }, };
> >
> > +static const struct imx_rproc_dcfg imx_rproc_cfg_imx8mn = {
> > + .att = imx_rproc_att_imx8mn,
> > + .att_size = ARRAY_SIZE(imx_rproc_att_imx8mn),
> > + .method = IMX_RPROC_SMC,
> > +};
> > +
> > static const struct imx_rproc_dcfg imx_rproc_cfg_imx8mq = {
> > .src_reg = IMX7D_SRC_SCR,
> > .src_mask = IMX7D_M4_RST_MASK,
> > @@ -246,12 +288,24 @@ static int imx_rproc_start(struct rproc *rproc)
> > struct imx_rproc *priv = rproc->priv;
> > const struct imx_rproc_dcfg *dcfg = priv->dcfg;
> > struct device *dev = priv->dev;
> > + struct arm_smccc_res res;
> > int ret;
> >
> > - ret = regmap_update_bits(priv->regmap, dcfg->src_reg,
> > - dcfg->src_mask, dcfg->src_start);
> > + switch (dcfg->method) {
> > + case IMX_RPROC_MMIO:
> > + ret = regmap_update_bits(priv->regmap, dcfg->src_reg,
> dcfg->src_mask,
> > + dcfg->src_start);
> > + break;
> > + case IMX_RPROC_SMC:
> > + arm_smccc_smc(IMX_SIP_RPROC, IMX_SIP_RPROC_START, 0, 0, 0,
> 0, 0, 0, &res);
> > + ret = res.a0;
> > + break;
> > + default:
> > + return -EOPNOTSUPP;
> > + }
> > +
> > if (ret)
> > - dev_err(dev, "Failed to enable M4!\n");
> > + dev_err(dev, "Failed to enable remote cores!\n");
> >
> > return ret;
> > }
> > @@ -261,12 +315,26 @@ static int imx_rproc_stop(struct rproc *rproc)
> > struct imx_rproc *priv = rproc->priv;
> > const struct imx_rproc_dcfg *dcfg = priv->dcfg;
> > struct device *dev = priv->dev;
> > + struct arm_smccc_res res;
> > int ret;
> >
> > - ret = regmap_update_bits(priv->regmap, dcfg->src_reg,
> > - dcfg->src_mask, dcfg->src_stop);
> > + switch (dcfg->method) {
> > + case IMX_RPROC_MMIO:
> > + ret = regmap_update_bits(priv->regmap, dcfg->src_reg,
> dcfg->src_mask,
> > + dcfg->src_stop);
> > + break;
> > + case IMX_RPROC_SMC:
> > + arm_smccc_smc(IMX_SIP_RPROC, IMX_SIP_RPROC_STOP, 0, 0, 0, 0,
> 0, 0, &res);
> > + ret = res.a0;
> > + if (res.a1)
> > + dev_info(dev, "Not in wfi, force stopped\n");
> > + break;
> > + default:
> > + return -EOPNOTSUPP;
> > + }
> > +
> > if (ret)
> > - dev_err(dev, "Failed to stop M4!\n");
> > + dev_err(dev, "Failed to stop remote cores\n");
> >
> > return ret;
> > }
> > @@ -600,6 +668,7 @@ static int imx_rproc_detect_mode(struct imx_rproc
> > *priv) {
> > const struct imx_rproc_dcfg *dcfg = priv->dcfg;
> > struct device *dev = priv->dev;
> > + struct arm_smccc_res res;
> > int ret;
> > u32 val;
> >
> > @@ -616,8 +685,12 @@ static int imx_rproc_detect_mode(struct
> imx_rproc *priv)
> > priv->mode = IMX_RPROC_EARLY_BOOT;
> > }
> >
> > - if (dcfg->method == IMX_RPROC_NONE)
> > + if (dcfg->method == IMX_RPROC_NONE) {
> > priv->mode = IMX_RPROC_EARLY_BOOT;
> > + } else if (dcfg->method == IMX_RPROC_SMC) {
> > + arm_smccc_smc(IMX_SIP_RPROC, IMX_SIP_RPROC_STARTED, 0, 0,
> 0, 0, 0, 0, &res);
> > + priv->mode = res.a0 ? IMX_RPROC_EARLY_BOOT :
> IMX_RPROC_NORMAL;
> > + }
>
> When all patches have been applied this function is really hard to read. I
> suggest using a switch() statement like you did in imx_rproc_start() and
> imx_rproc_stop().
>
> Thanks,
> Mathieu
>
> >
> > if (priv->mode == IMX_RPROC_EARLY_BOOT)
> > priv->rproc->state = RPROC_DETACHED; @@ -747,6 +820,8 @@
> static
> > const struct of_device_id imx_rproc_of_match[] = {
> > { .compatible = "fsl,imx6sx-cm4", .data = &imx_rproc_cfg_imx6sx },
> > { .compatible = "fsl,imx8mq-cm4", .data = &imx_rproc_cfg_imx8mq },
> > { .compatible = "fsl,imx8mm-cm4", .data = &imx_rproc_cfg_imx8mq },
> > + { .compatible = "fsl,imx8mn-cm7", .data = &imx_rproc_cfg_imx8mn },
> > + { .compatible = "fsl,imx8mp-cm7", .data = &imx_rproc_cfg_imx8mn },
> > {},
> > };
> > MODULE_DEVICE_TABLE(of, imx_rproc_of_match);
> > --
> > 2.30.0
> >