Commit 3bf4cd8b authored by Daniel Baluta's avatar Daniel Baluta Committed by Mark Brown

ASoC: SOF: imx8m: Implement reset callback

Resume common flow (System PM / Runtime PM) is like this:

    sof_resume
      -> specific device resume
      -> snd_sof_load_firmware
         -> snd_sof_dsp_reset (1)
         -> load_modules()
      -> snd_sof_run_firmware (2)

    We need to implement dsp_reset callback (1) that will actually reset
    the DSP but keep it stalled.

    In order to implement this we do the following:
            -> put DSP into reset (assert CoreReset bit from PWRCTL)
            -> stall the DSP using RunStall bit from AudioDSP_REG2 mix
            -> take DSP out of reset (de-assert CoreReset bit from PWRCTL)

    At this moment the DSP is taken out of reset and Stalled! This means
    that we can load the firmware and then start the DSP (2).

    Until now we resetted the DSP by turning down the Audiomix PD. This
    doesn't work for Runtime PM if another IP is keeping Audiomix PD up.

    By introducing dsp_reset() we no longer rely on turning off the
    audiomix to reset the DSP.
Signed-off-by: default avatarDaniel Baluta <daniel.baluta@nxp.com>
Reviewed-by: default avatarPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: default avatarKai Vehmanen <kai.vehmanen@linux.intel.com>
Link: https://lore.kernel.org/r/20211119094319.81674-6-daniel.baluta@oss.nxp.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 9ba23717
...@@ -32,6 +32,12 @@ static struct clk_bulk_data imx8m_dsp_clks[] = { ...@@ -32,6 +32,12 @@ static struct clk_bulk_data imx8m_dsp_clks[] = {
{ .id = "core" }, { .id = "core" },
}; };
/* DAP registers */
#define IMX8M_DAP_DEBUG 0x28800000
#define IMX8M_DAP_DEBUG_SIZE (64 * 1024)
#define IMX8M_DAP_PWRCTL (0x4000 + 0x3020)
#define IMX8M_PWRCTL_CORERESET BIT(16)
/* DSP audio mix registers */ /* DSP audio mix registers */
#define AudioDSP_REG0 0x100 #define AudioDSP_REG0 0x100
#define AudioDSP_REG1 0x104 #define AudioDSP_REG1 0x104
...@@ -50,6 +56,7 @@ struct imx8m_priv { ...@@ -50,6 +56,7 @@ struct imx8m_priv {
struct imx_clocks *clks; struct imx_clocks *clks;
void __iomem *dap;
struct regmap *regmap; struct regmap *regmap;
}; };
...@@ -116,6 +123,30 @@ static int imx8m_run(struct snd_sof_dev *sdev) ...@@ -116,6 +123,30 @@ static int imx8m_run(struct snd_sof_dev *sdev)
return 0; return 0;
} }
static int imx8m_reset(struct snd_sof_dev *sdev)
{
struct imx8m_priv *priv = (struct imx8m_priv *)sdev->pdata->hw_pdata;
u32 pwrctl;
/* put DSP into reset and stall */
pwrctl = readl(priv->dap + IMX8M_DAP_PWRCTL);
pwrctl |= IMX8M_PWRCTL_CORERESET;
writel(pwrctl, priv->dap + IMX8M_DAP_PWRCTL);
/* keep reset asserted for 10 cycles */
usleep_range(1, 2);
regmap_update_bits(priv->regmap, AudioDSP_REG2,
AudioDSP_REG2_RUNSTALL, AudioDSP_REG2_RUNSTALL);
/* take the DSP out of reset and keep stalled for FW loading */
pwrctl = readl(priv->dap + IMX8M_DAP_PWRCTL);
pwrctl &= ~IMX8M_PWRCTL_CORERESET;
writel(pwrctl, priv->dap + IMX8M_DAP_PWRCTL);
return 0;
}
static int imx8m_probe(struct snd_sof_dev *sdev) static int imx8m_probe(struct snd_sof_dev *sdev)
{ {
struct platform_device *pdev = struct platform_device *pdev =
...@@ -168,6 +199,13 @@ static int imx8m_probe(struct snd_sof_dev *sdev) ...@@ -168,6 +199,13 @@ static int imx8m_probe(struct snd_sof_dev *sdev)
goto exit_pdev_unregister; goto exit_pdev_unregister;
} }
priv->dap = devm_ioremap(sdev->dev, IMX8M_DAP_DEBUG, IMX8M_DAP_DEBUG_SIZE);
if (!priv->dap) {
dev_err(sdev->dev, "error: failed to map DAP debug memory area");
ret = -ENODEV;
goto exit_pdev_unregister;
}
sdev->bar[SOF_FW_BLK_TYPE_IRAM] = devm_ioremap(sdev->dev, base, size); sdev->bar[SOF_FW_BLK_TYPE_IRAM] = devm_ioremap(sdev->dev, base, size);
if (!sdev->bar[SOF_FW_BLK_TYPE_IRAM]) { if (!sdev->bar[SOF_FW_BLK_TYPE_IRAM]) {
dev_err(sdev->dev, "failed to ioremap base 0x%x size 0x%x\n", dev_err(sdev->dev, "failed to ioremap base 0x%x size 0x%x\n",
...@@ -378,6 +416,7 @@ struct snd_sof_dsp_ops sof_imx8m_ops = { ...@@ -378,6 +416,7 @@ struct snd_sof_dsp_ops sof_imx8m_ops = {
.remove = imx8m_remove, .remove = imx8m_remove,
/* DSP core boot */ /* DSP core boot */
.run = imx8m_run, .run = imx8m_run,
.reset = imx8m_reset,
/* Block IO */ /* Block IO */
.block_read = sof_block_read, .block_read = sof_block_read,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment