ASoC: SOF: imx: Add code to manage DSP related clocks
authorDaniel Baluta <daniel.baluta@nxp.com>
Fri, 19 Nov 2021 09:43:15 +0000 (11:43 +0200)
committerMark Brown <broonie@kernel.org>
Mon, 22 Nov 2021 15:40:08 +0000 (15:40 +0000)
We need at least 3 clocks in order to power up and access
DSP core registers found on i.MX8QM, i.MX8QXP and i.MX8MP
platforms.

Add code to request these clocks and enable them at probe. Next
patches will add PM support which will only activate clocks when
DSP is used.

DSP clocks are already documented in
Documentation/devicetree/bindings/dsp/fsl,dsp.yaml

We choose to add:
* imx8_parse_clocks
* imx8_enable_clocks
* imx8_disable_clocks

wrappers because in the future DSP will need to take care about the
clocks of other related Audio IPs (e.g SAI, ESAI).

Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
Reviewed-by: Paul Olaru <paul.olaru@oss.nxp.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://lore.kernel.org/r/20211119094319.81674-2-daniel.baluta@oss.nxp.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/sof/imx/imx-common.c
sound/soc/sof/imx/imx-common.h
sound/soc/sof/imx/imx8.c
sound/soc/sof/imx/imx8m.c

index 8826ef94f04a33ed56ce2bfd40417d1bf702b1f6..9371e9062cb14ffe06c1ce0cfb051b105be14901 100644 (file)
@@ -74,4 +74,28 @@ void imx8_dump(struct snd_sof_dev *sdev, u32 flags)
 }
 EXPORT_SYMBOL(imx8_dump);
 
+int imx8_parse_clocks(struct snd_sof_dev *sdev, struct imx_clocks *clks)
+{
+       int ret;
+
+       ret = devm_clk_bulk_get(sdev->dev, clks->num_dsp_clks, clks->dsp_clks);
+       if (ret)
+               dev_err(sdev->dev, "Failed to request DSP clocks\n");
+
+       return ret;
+}
+EXPORT_SYMBOL(imx8_parse_clocks);
+
+int imx8_enable_clocks(struct snd_sof_dev *sdev, struct imx_clocks *clks)
+{
+       return clk_bulk_prepare_enable(clks->num_dsp_clks, clks->dsp_clks);
+}
+EXPORT_SYMBOL(imx8_enable_clocks);
+
+void imx8_disable_clocks(struct snd_sof_dev *sdev, struct imx_clocks *clks)
+{
+       clk_bulk_disable_unprepare(clks->num_dsp_clks, clks->dsp_clks);
+}
+EXPORT_SYMBOL(imx8_disable_clocks);
+
 MODULE_LICENSE("Dual BSD/GPL");
index 1cc7d6704182503418100c36ce30a84cdb87e14e..ec4b3a5c7496a5655cf3e5a0733be56a282b5a76 100644 (file)
@@ -3,6 +3,8 @@
 #ifndef __IMX_COMMON_H__
 #define __IMX_COMMON_H__
 
+#include <linux/clk.h>
+
 #define EXCEPT_MAX_HDR_SIZE    0x400
 #define IMX8_STACK_DUMP_SIZE 32
 
@@ -13,4 +15,13 @@ void imx8_get_registers(struct snd_sof_dev *sdev,
 
 void imx8_dump(struct snd_sof_dev *sdev, u32 flags);
 
+struct imx_clocks {
+       struct clk_bulk_data *dsp_clks;
+       int num_dsp_clks;
+};
+
+int imx8_parse_clocks(struct snd_sof_dev *sdev, struct imx_clocks *clks);
+int imx8_enable_clocks(struct snd_sof_dev *sdev, struct imx_clocks *clks);
+void imx8_disable_clocks(struct snd_sof_dev *sdev, struct imx_clocks *clks);
+
 #endif
index 0aeb44d0acc7e40ddd5e6db38726e73ccb6ed6fa..32f852cbba30d1f4ba5705d441ce7a7058f18b87 100644 (file)
 #define MBOX_OFFSET    0x800000
 #define MBOX_SIZE      0x1000
 
+/* DSP clocks */
+static struct clk_bulk_data imx8_dsp_clks[] = {
+       { .id = "ipg" },
+       { .id = "ocram" },
+       { .id = "core" },
+};
+
 struct imx8_priv {
        struct device *dev;
        struct snd_sof_dev *sdev;
@@ -57,6 +64,7 @@ struct imx8_priv {
        struct device **pd_dev;
        struct device_link **link;
 
+       struct imx_clocks *clks;
 };
 
 static int imx8_get_mailbox_offset(struct snd_sof_dev *sdev)
@@ -188,6 +196,10 @@ static int imx8_probe(struct snd_sof_dev *sdev)
        if (!priv)
                return -ENOMEM;
 
+       priv->clks = devm_kzalloc(&pdev->dev, sizeof(*priv->clks), GFP_KERNEL);
+       if (!priv->clks)
+               return -ENOMEM;
+
        sdev->pdata->hw_pdata = priv;
        priv->dev = sdev->dev;
        priv->sdev = sdev;
@@ -300,6 +312,16 @@ static int imx8_probe(struct snd_sof_dev *sdev)
        /* set default mailbox offset for FW ready message */
        sdev->dsp_box.offset = MBOX_OFFSET;
 
+       /* init clocks info */
+       priv->clks->dsp_clks = imx8_dsp_clks;
+       priv->clks->num_dsp_clks = ARRAY_SIZE(imx8_dsp_clks);
+
+       ret = imx8_parse_clocks(sdev, priv->clks);
+       if (ret < 0)
+               goto exit_pdev_unregister;
+
+       imx8_enable_clocks(sdev, priv->clks);
+
        return 0;
 
 exit_pdev_unregister:
@@ -318,6 +340,7 @@ static int imx8_remove(struct snd_sof_dev *sdev)
        struct imx8_priv *priv = sdev->pdata->hw_pdata;
        int i;
 
+       imx8_disable_clocks(sdev, priv->clks);
        platform_device_unregister(priv->ipc_dev);
 
        for (i = 0; i < priv->num_domains; i++) {
index f454a5d0a87e9a43d5bd6542bdab95f197c71685..ab40c0bdf7963939e8a26cd9a285ffb6a4b92f68 100644 (file)
 #define MBOX_OFFSET    0x800000
 #define MBOX_SIZE      0x1000
 
+static struct clk_bulk_data imx8m_dsp_clks[] = {
+       { .id = "ipg" },
+       { .id = "ocram" },
+       { .id = "core" },
+};
+
 struct imx8m_priv {
        struct device *dev;
        struct snd_sof_dev *sdev;
@@ -30,6 +36,8 @@ struct imx8m_priv {
        /* DSP IPC handler */
        struct imx_dsp_ipc *dsp_ipc;
        struct platform_device *ipc_dev;
+
+       struct imx_clocks *clks;
 };
 
 static int imx8m_get_mailbox_offset(struct snd_sof_dev *sdev)
@@ -108,6 +116,10 @@ static int imx8m_probe(struct snd_sof_dev *sdev)
        if (!priv)
                return -ENOMEM;
 
+       priv->clks = devm_kzalloc(&pdev->dev, sizeof(*priv->clks), GFP_KERNEL);
+       if (!priv->clks)
+               return -ENOMEM;
+
        sdev->pdata->hw_pdata = priv;
        priv->dev = sdev->dev;
        priv->sdev = sdev;
@@ -175,6 +187,16 @@ static int imx8m_probe(struct snd_sof_dev *sdev)
        /* set default mailbox offset for FW ready message */
        sdev->dsp_box.offset = MBOX_OFFSET;
 
+       /* init clocks info */
+       priv->clks->dsp_clks = imx8m_dsp_clks;
+       priv->clks->num_dsp_clks = ARRAY_SIZE(imx8m_dsp_clks);
+
+       ret = imx8_parse_clocks(sdev, priv->clks);
+       if (ret < 0)
+               goto exit_pdev_unregister;
+
+       imx8_enable_clocks(sdev, priv->clks);
+
        return 0;
 
 exit_pdev_unregister:
@@ -186,6 +208,7 @@ static int imx8m_remove(struct snd_sof_dev *sdev)
 {
        struct imx8m_priv *priv = sdev->pdata->hw_pdata;
 
+       imx8_disable_clocks(sdev, priv->clks);
        platform_device_unregister(priv->ipc_dev);
 
        return 0;