]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
ASoC: SOF: amd: Add Renoir ACP HW support
authorAjit Kumar Pandey <AjitKumar.Pandey@amd.com>
Wed, 17 Nov 2021 09:37:14 +0000 (11:37 +0200)
committerMark Brown <broonie@kernel.org>
Wed, 17 Nov 2021 17:35:44 +0000 (17:35 +0000)
This patch initializes ACP HW block to support SOF on
AMD Renoir platform.

Signed-off-by: Ajit Kumar Pandey <AjitKumar.Pandey@amd.com>
Reviewed-by: Bard Liao <bard.liao@intel.com>
Reviewed-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
Link: https://lore.kernel.org/r/20211117093734.17407-2-daniel.baluta@oss.nxp.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/sof/Kconfig
sound/soc/sof/Makefile
sound/soc/sof/amd/Kconfig [new file with mode: 0644]
sound/soc/sof/amd/Makefile [new file with mode: 0644]
sound/soc/sof/amd/acp-dsp-offset.h [new file with mode: 0644]
sound/soc/sof/amd/acp.c [new file with mode: 0644]
sound/soc/sof/amd/acp.h [new file with mode: 0644]
sound/soc/sof/amd/renoir.c [new file with mode: 0644]

index b6fa659179b6026028f6cbb3dd099b4226412398..35c68192d2ceef2992b93b0c34a1ac89be81fd40 100644 (file)
@@ -225,6 +225,7 @@ config SND_SOC_SOF_PROBE_WORK_QUEUE
          When selected, the probe is handled in two steps, for example to
          avoid lockdeps if request_module is used in the probe.
 
+source "sound/soc/sof/amd/Kconfig"
 source "sound/soc/sof/imx/Kconfig"
 source "sound/soc/sof/intel/Kconfig"
 source "sound/soc/sof/xtensa/Kconfig"
index 1dac5cb4dfd647f37af2c3becf8f7d310cb2bb53..81ad8cb666e3324cec06c0642e11451081c15774 100644 (file)
@@ -22,4 +22,5 @@ obj-$(CONFIG_SND_SOC_SOF_PCI_DEV) += snd-sof-pci.o
 
 obj-$(CONFIG_SND_SOC_SOF_INTEL_TOPLEVEL) += intel/
 obj-$(CONFIG_SND_SOC_SOF_IMX_TOPLEVEL) += imx/
+obj-$(CONFIG_SND_SOC_SOF_AMD_TOPLEVEL) += amd/
 obj-$(CONFIG_SND_SOC_SOF_XTENSA) += xtensa/
diff --git a/sound/soc/sof/amd/Kconfig b/sound/soc/sof/amd/Kconfig
new file mode 100644 (file)
index 0000000..400dd5a
--- /dev/null
@@ -0,0 +1,30 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
+# This file is provided under a dual BSD/GPLv2 license. When using or
+# redistributing this file, you may do so under either license.
+#
+# Copyright(c) 2021 Advanced Micro Devices, Inc. All rights reserved.
+
+config SND_SOC_SOF_AMD_TOPLEVEL
+       tristate "SOF support for AMD audio DSPs"
+       depends on X86 || COMPILE_TEST
+       help
+         This adds support for Sound Open Firmware for AMD platforms.
+         Say Y if you have such a device.
+         If unsure select "N".
+
+if SND_SOC_SOF_AMD_TOPLEVEL
+
+config SND_SOC_SOF_AMD_COMMON
+       tristate
+       select SND_SOC_SOF
+       help
+         This option is not user-selectable but automatically handled by
+         'select' statements at a higher level
+
+config SND_SOC_SOF_AMD_RENOIR
+       tristate "SOF support for RENOIR"
+       select SND_SOC_SOF_AMD_COMMON
+       help
+         Select this option for SOF support on AMD Renoir platform
+
+endif
diff --git a/sound/soc/sof/amd/Makefile b/sound/soc/sof/amd/Makefile
new file mode 100644 (file)
index 0000000..ac2ecd2
--- /dev/null
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
+# This file is provided under a dual BSD/GPLv2 license. When using or
+# redistributing this file, you may do so under either license.
+#
+# Copyright(c) 2021 Advanced Micro Devices, Inc. All rights reserved.
+
+snd-sof-amd-acp-objs := acp.o
+snd-sof-amd-renoir-objs := renoir.o
+
+obj-$(CONFIG_SND_SOC_SOF_AMD_COMMON) += snd-sof-amd-acp.o
+obj-$(CONFIG_SND_SOC_SOF_AMD_RENOIR) +=snd-sof-amd-renoir.o
diff --git a/sound/soc/sof/amd/acp-dsp-offset.h b/sound/soc/sof/amd/acp-dsp-offset.h
new file mode 100644 (file)
index 0000000..2cc2a9a
--- /dev/null
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
+/*
+ * This file is provided under a dual BSD/GPLv2 license. When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * Copyright(c) 2021 Advanced Micro Devices, Inc. All rights reserved.
+ *
+ * Author: Ajit Kumar Pandey <AjitKumar.Pandey@amd.com>
+ */
+
+#ifndef _ACP_DSP_IP_OFFSET_H
+#define _ACP_DSP_IP_OFFSET_H
+
+#define ACP_SOFT_RESET                         0x1000
+
+/* Registers from ACP_PGFSM block */
+#define ACP_PGFSM_CONTROL                      0x141C
+#define ACP_PGFSM_STATUS                       0x1420
+
+#endif
diff --git a/sound/soc/sof/amd/acp.c b/sound/soc/sof/amd/acp.c
new file mode 100644 (file)
index 0000000..687a674
--- /dev/null
@@ -0,0 +1,118 @@
+// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
+//
+// This file is provided under a dual BSD/GPLv2 license. When using or
+// redistributing this file, you may do so under either license.
+//
+// Copyright(c) 2021 Advanced Micro Devices, Inc. All rights reserved.
+//
+// Authors: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
+//         Ajit Kumar Pandey <AjitKumar.Pandey@amd.com>
+
+/*
+ * Hardware interface for generic AMD ACP processor
+ */
+
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/pci.h>
+
+#include "../ops.h"
+#include "acp.h"
+#include "acp-dsp-offset.h"
+
+static int acp_power_on(struct snd_sof_dev *sdev)
+{
+       unsigned int val;
+       int ret;
+
+       val = snd_sof_dsp_read(sdev, ACP_DSP_BAR, ACP_PGFSM_STATUS);
+
+       if (val == ACP_POWERED_ON)
+               return 0;
+
+       if (val & ACP_PGFSM_STATUS_MASK)
+               snd_sof_dsp_write(sdev, ACP_DSP_BAR, ACP_PGFSM_CONTROL,
+                                 ACP_PGFSM_CNTL_POWER_ON_MASK);
+
+       ret = snd_sof_dsp_read_poll_timeout(sdev, ACP_DSP_BAR, ACP_PGFSM_STATUS, val, !val,
+                                           ACP_REG_POLL_INTERVAL, ACP_REG_POLL_TIMEOUT_US);
+       if (ret < 0)
+               dev_err(sdev->dev, "timeout in ACP_PGFSM_STATUS read\n");
+
+       return ret;
+}
+
+static int acp_reset(struct snd_sof_dev *sdev)
+{
+       unsigned int val;
+       int ret;
+
+       snd_sof_dsp_write(sdev, ACP_DSP_BAR, ACP_SOFT_RESET, ACP_ASSERT_RESET);
+
+       ret = snd_sof_dsp_read_poll_timeout(sdev, ACP_DSP_BAR, ACP_SOFT_RESET, val,
+                                           val & ACP_SOFT_RESET_DONE_MASK,
+                                           ACP_REG_POLL_INTERVAL, ACP_REG_POLL_TIMEOUT_US);
+       if (ret < 0) {
+               dev_err(sdev->dev, "timeout asserting reset\n");
+               return ret;
+       }
+
+       snd_sof_dsp_write(sdev, ACP_DSP_BAR, ACP_SOFT_RESET, ACP_RELEASE_RESET);
+
+       ret = snd_sof_dsp_read_poll_timeout(sdev, ACP_DSP_BAR, ACP_SOFT_RESET, val, !val,
+                                           ACP_REG_POLL_INTERVAL, ACP_REG_POLL_TIMEOUT_US);
+       if (ret < 0)
+               dev_err(sdev->dev, "timeout in releasing reset\n");
+
+       return ret;
+}
+
+static int acp_init(struct snd_sof_dev *sdev)
+{
+       int ret;
+
+       /* power on */
+       ret = acp_power_on(sdev);
+       if (ret) {
+               dev_err(sdev->dev, "ACP power on failed\n");
+               return ret;
+       }
+       /* Reset */
+       return acp_reset(sdev);
+}
+
+int amd_sof_acp_probe(struct snd_sof_dev *sdev)
+{
+       struct pci_dev *pci = to_pci_dev(sdev->dev);
+       struct acp_dev_data *adata;
+       unsigned int addr;
+
+       adata = devm_kzalloc(sdev->dev, sizeof(struct acp_dev_data),
+                            GFP_KERNEL);
+       if (!adata)
+               return -ENOMEM;
+
+       adata->dev = sdev;
+       addr = pci_resource_start(pci, ACP_DSP_BAR);
+       sdev->bar[ACP_DSP_BAR] = devm_ioremap(sdev->dev, addr, pci_resource_len(pci, ACP_DSP_BAR));
+       if (!sdev->bar[ACP_DSP_BAR]) {
+               dev_err(sdev->dev, "ioremap error\n");
+               return -ENXIO;
+       }
+
+       pci_set_master(pci);
+
+       sdev->pdata->hw_pdata = adata;
+
+       return acp_init(sdev);
+}
+EXPORT_SYMBOL_NS(amd_sof_acp_probe, SND_SOC_SOF_AMD_COMMON);
+
+int amd_sof_acp_remove(struct snd_sof_dev *sdev)
+{
+       return acp_reset(sdev);
+}
+EXPORT_SYMBOL_NS(amd_sof_acp_remove, SND_SOC_SOF_AMD_COMMON);
+
+MODULE_DESCRIPTION("AMD ACP sof driver");
+MODULE_LICENSE("Dual BSD/GPL");
diff --git a/sound/soc/sof/amd/acp.h b/sound/soc/sof/amd/acp.h
new file mode 100644 (file)
index 0000000..c7ac8f9
--- /dev/null
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
+/*
+ * This file is provided under a dual BSD/GPLv2 license. When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * Copyright(c) 2021 Advanced Micro Devices, Inc. All rights reserved.
+ *
+ * Author: Ajit Kumar Pandey <AjitKumar.Pandey@amd.com>
+ */
+
+#ifndef __SOF_AMD_ACP_H
+#define __SOF_AMD_ACP_H
+
+#define ACP_DSP_BAR    0
+
+#define ACP_REG_POLL_INTERVAL                   500
+#define ACP_REG_POLL_TIMEOUT_US                 2000
+
+#define ACP_PGFSM_CNTL_POWER_ON_MASK           0x01
+#define ACP_PGFSM_STATUS_MASK                  0x03
+#define ACP_POWERED_ON                         0x00
+#define ACP_ASSERT_RESET                       0x01
+#define ACP_RELEASE_RESET                      0x00
+#define ACP_SOFT_RESET_DONE_MASK               0x00010001
+
+/* Common device data struct for ACP devices */
+struct acp_dev_data {
+       struct snd_sof_dev  *dev;
+};
+
+/* ACP device probe/remove */
+int amd_sof_acp_probe(struct snd_sof_dev *sdev);
+int amd_sof_acp_remove(struct snd_sof_dev *sdev);
+
+extern const struct snd_sof_dsp_ops sof_renoir_ops;
+#endif
diff --git a/sound/soc/sof/amd/renoir.c b/sound/soc/sof/amd/renoir.c
new file mode 100644 (file)
index 0000000..3d1dc6c
--- /dev/null
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
+//
+// This file is provided under a dual BSD/GPLv2 license. When using or
+// redistributing this file, you may do so under either license.
+//
+// Copyright(c) 2021 Advanced Micro Devices, Inc.
+//
+// Authors: Ajit Kumar Pandey <AjitKumar.Pandey@amd.com>
+
+/*
+ * Hardware interface for Audio DSP on Renoir platform
+ */
+
+#include <linux/platform_device.h>
+#include <linux/module.h>
+
+#include "../ops.h"
+#include "acp.h"
+
+/* AMD Renoir DSP ops */
+const struct snd_sof_dsp_ops sof_renoir_ops = {
+       /* probe and remove */
+       .probe                  = amd_sof_acp_probe,
+       .remove                 = amd_sof_acp_remove,
+
+       /* Register IO */
+       .write                  = sof_io_write,
+       .read                   = sof_io_read,
+};
+EXPORT_SYMBOL(sof_renoir_ops);
+
+MODULE_IMPORT_NS(SND_SOC_SOF_AMD_COMMON);
+MODULE_DESCRIPTION("RENOIR SOF Driver");
+MODULE_LICENSE("Dual BSD/GPL");