From: Chris Spencer <christopher.spencer@xxxxxxxxx> There are no clocks that the CAAM driver needs to initialise on the i.MX8. Signed-off-by: Aymen Sghaier <aymen.sghaier@xxxxxxx> Signed-off-by: Chris Spencer <christopher.spencer@xxxxxxxxx> Signed-off-by: Andrey Smirnov <andrew.smirnov@xxxxxxxxx> Cc: Chris Spencer <christopher.spencer@xxxxxxxxx> Cc: Cory Tusar <cory.tusar@xxxxxxxx> Cc: Chris Healy <cphealy@xxxxxxxxx> Cc: Lucas Stach <l.stach@xxxxxxxxxxxxxx> Cc: Horia Geantă <horia.geanta@xxxxxxx> Cc: Aymen Sghaier <aymen.sghaier@xxxxxxx> Cc: linux-crypto@xxxxxxxxxxxxxxx Cc: linux-kernel@xxxxxxxxxxxxxxx --- drivers/crypto/caam/ctrl.c | 146 +++++++++++++++++++++---------------- 1 file changed, 85 insertions(+), 61 deletions(-) diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c index fec39c35c877..39334e71a14f 100644 --- a/drivers/crypto/caam/ctrl.c +++ b/drivers/crypto/caam/ctrl.c @@ -309,6 +309,19 @@ static int deinstantiate_rng(struct device *ctrldev, int state_handle_mask) return ret; } +static void disable_clocking(struct caam_drv_private *ctrlpriv) +{ + if (of_machine_is_compatible("fsl,imx8mq")) + return; + + clk_disable_unprepare(ctrlpriv->caam_ipg); + if (ctrlpriv->caam_mem) + clk_disable_unprepare(ctrlpriv->caam_mem); + clk_disable_unprepare(ctrlpriv->caam_aclk); + if (ctrlpriv->caam_emi_slow) + clk_disable_unprepare(ctrlpriv->caam_emi_slow); +} + static int caam_remove(struct platform_device *pdev) { struct device *ctrldev; @@ -343,12 +356,8 @@ static int caam_remove(struct platform_device *pdev) iounmap(ctrl); /* shut clocks off before finalizing shutdown */ - clk_disable_unprepare(ctrlpriv->caam_ipg); - if (ctrlpriv->caam_mem) - clk_disable_unprepare(ctrlpriv->caam_mem); - clk_disable_unprepare(ctrlpriv->caam_aclk); - if (ctrlpriv->caam_emi_slow) - clk_disable_unprepare(ctrlpriv->caam_emi_slow); + disable_clocking(ctrlpriv); + return 0; } @@ -497,65 +506,38 @@ static const struct of_device_id caam_match[] = { }; MODULE_DEVICE_TABLE(of, caam_match); -/* Probe routine for CAAM top (controller) level */ -static int caam_probe(struct platform_device *pdev) +static int init_clocking(struct device *dev, struct caam_drv_private *ctrlpriv) { - int ret, ring, gen_sk, ent_delay = RTSDCTL_ENT_DLY_MIN; - u64 caam_id; - static const struct soc_device_attribute imx_soc[] = { - {.family = "Freescale i.MX"}, - {}, - }; - struct device *dev; - struct device_node *nprop, *np; - struct caam_ctrl __iomem *ctrl; - struct caam_drv_private *ctrlpriv; struct clk *clk; -#ifdef CONFIG_DEBUG_FS - struct caam_perfmon *perfmon; -#endif - u32 scfgr, comp_params; - u8 rng_vid; - int pg_size; - int BLOCK_OFFSET = 0; - - ctrlpriv = devm_kzalloc(&pdev->dev, sizeof(*ctrlpriv), GFP_KERNEL); - if (!ctrlpriv) - return -ENOMEM; - - dev = &pdev->dev; - dev_set_drvdata(dev, ctrlpriv); - nprop = pdev->dev.of_node; + int ret; - caam_imx = (bool)soc_device_match(imx_soc); + if (of_machine_is_compatible("fsl,imx8mq")) + return 0; /* Enable clocking */ - clk = caam_drv_identify_clk(&pdev->dev, "ipg"); + clk = caam_drv_identify_clk(dev, "ipg"); if (IS_ERR(clk)) { ret = PTR_ERR(clk); - dev_err(&pdev->dev, - "can't identify CAAM ipg clk: %d\n", ret); + dev_err(dev, "can't identify CAAM ipg clk: %d\n", ret); return ret; } ctrlpriv->caam_ipg = clk; if (!of_machine_is_compatible("fsl,imx7d") && !of_machine_is_compatible("fsl,imx7s")) { - clk = caam_drv_identify_clk(&pdev->dev, "mem"); + clk = caam_drv_identify_clk(dev, "mem"); if (IS_ERR(clk)) { ret = PTR_ERR(clk); - dev_err(&pdev->dev, - "can't identify CAAM mem clk: %d\n", ret); + dev_err(dev, "can't identify CAAM mem clk: %d\n", ret); return ret; } ctrlpriv->caam_mem = clk; } - clk = caam_drv_identify_clk(&pdev->dev, "aclk"); + clk = caam_drv_identify_clk(dev, "aclk"); if (IS_ERR(clk)) { ret = PTR_ERR(clk); - dev_err(&pdev->dev, - "can't identify CAAM aclk clk: %d\n", ret); + dev_err(dev, "can't identify CAAM aclk clk: %d\n", ret); return ret; } ctrlpriv->caam_aclk = clk; @@ -563,11 +545,11 @@ static int caam_probe(struct platform_device *pdev) if (!of_machine_is_compatible("fsl,imx6ul") && !of_machine_is_compatible("fsl,imx7d") && !of_machine_is_compatible("fsl,imx7s")) { - clk = caam_drv_identify_clk(&pdev->dev, "emi_slow"); + clk = caam_drv_identify_clk(dev, "emi_slow"); if (IS_ERR(clk)) { ret = PTR_ERR(clk); - dev_err(&pdev->dev, - "can't identify CAAM emi_slow clk: %d\n", ret); + dev_err(dev, "can't identify CAAM emi_slow clk: %d\n", + ret); return ret; } ctrlpriv->caam_emi_slow = clk; @@ -575,14 +557,15 @@ static int caam_probe(struct platform_device *pdev) ret = clk_prepare_enable(ctrlpriv->caam_ipg); if (ret < 0) { - dev_err(&pdev->dev, "can't enable CAAM ipg clock: %d\n", ret); + dev_err(dev, "can't enable CAAM ipg clock: %d\n", ret); return ret; } if (ctrlpriv->caam_mem) { ret = clk_prepare_enable(ctrlpriv->caam_mem); if (ret < 0) { - dev_err(&pdev->dev, "can't enable CAAM secure mem clock: %d\n", + dev_err(dev, + "can't enable CAAM secure mem clock: %d\n", ret); goto disable_caam_ipg; } @@ -590,26 +573,74 @@ static int caam_probe(struct platform_device *pdev) ret = clk_prepare_enable(ctrlpriv->caam_aclk); if (ret < 0) { - dev_err(&pdev->dev, "can't enable CAAM aclk clock: %d\n", ret); + dev_err(dev, "can't enable CAAM aclk clock: %d\n", ret); goto disable_caam_mem; } if (ctrlpriv->caam_emi_slow) { ret = clk_prepare_enable(ctrlpriv->caam_emi_slow); if (ret < 0) { - dev_err(&pdev->dev, "can't enable CAAM emi slow clock: %d\n", + dev_err(dev, "can't enable CAAM emi slow clock: %d\n", ret); goto disable_caam_aclk; } } + return 0; + +disable_caam_aclk: + clk_disable_unprepare(ctrlpriv->caam_aclk); +disable_caam_mem: + if (ctrlpriv->caam_mem) + clk_disable_unprepare(ctrlpriv->caam_mem); +disable_caam_ipg: + clk_disable_unprepare(ctrlpriv->caam_ipg); + + return ret; +} + +/* Probe routine for CAAM top (controller) level */ +static int caam_probe(struct platform_device *pdev) +{ + int ret, ring, gen_sk, ent_delay = RTSDCTL_ENT_DLY_MIN; + u64 caam_id; + static const struct soc_device_attribute imx_soc[] = { + {.family = "Freescale i.MX"}, + {}, + }; + struct device *dev; + struct device_node *nprop, *np; + struct caam_ctrl __iomem *ctrl; + struct caam_drv_private *ctrlpriv; +#ifdef CONFIG_DEBUG_FS + struct caam_perfmon *perfmon; +#endif + u32 scfgr, comp_params; + u8 rng_vid; + int pg_size; + int BLOCK_OFFSET = 0; + + ctrlpriv = devm_kzalloc(&pdev->dev, sizeof(*ctrlpriv), GFP_KERNEL); + if (!ctrlpriv) + return -ENOMEM; + + dev = &pdev->dev; + dev_set_drvdata(dev, ctrlpriv); + nprop = pdev->dev.of_node; + + caam_imx = (bool)soc_device_match(imx_soc); + + ret = init_clocking(dev, ctrlpriv); + if (ret) + return ret; + /* Get configuration properties from device tree */ /* First, get register page */ ctrl = of_iomap(nprop, 0); if (ctrl == NULL) { dev_err(dev, "caam: of_iomap() failed\n"); ret = -ENOMEM; - goto disable_caam_emi_slow; + goto disable_clocks; } caam_little_end = !(bool)(rd_reg32(&ctrl->perfmon.status) & @@ -900,16 +931,9 @@ static int caam_probe(struct platform_device *pdev) iounmap_ctrl: iounmap(ctrl); -disable_caam_emi_slow: - if (ctrlpriv->caam_emi_slow) - clk_disable_unprepare(ctrlpriv->caam_emi_slow); -disable_caam_aclk: - clk_disable_unprepare(ctrlpriv->caam_aclk); -disable_caam_mem: - if (ctrlpriv->caam_mem) - clk_disable_unprepare(ctrlpriv->caam_mem); -disable_caam_ipg: - clk_disable_unprepare(ctrlpriv->caam_ipg); +disable_clocks: + disable_clocking(ctrlpriv); + return ret; } -- 2.21.0