diff mbox series

[V2,02/23] ASoC: amd: acp70: add acp pci driver for ACP7.0 and ACP7.1 platforms

Message ID 20250120100130.3710412-3-Vijendar.Mukunda@amd.com (mailing list archive)
State New
Headers show
Series ASoC: amd: acp70: add soundwire and acp pdm support | expand

Commit Message

Mukunda,Vijendar Jan. 20, 2025, 10:01 a.m. UTC
ACP is a PCI audio device.
This patch adds common PCI driver to bind to this device and get PCI
resources for ACP7.0 & ACP7.1 platforms.

Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
---
 sound/soc/amd/acp70/acp70.h     |  33 +++++++++++
 sound/soc/amd/acp70/pci-acp70.c | 100 ++++++++++++++++++++++++++++++++
 2 files changed, 133 insertions(+)
 create mode 100644 sound/soc/amd/acp70/acp70.h
 create mode 100644 sound/soc/amd/acp70/pci-acp70.c

Comments

Mark Brown Jan. 20, 2025, 5:08 p.m. UTC | #1
On Mon, Jan 20, 2025 at 03:31:09PM +0530, Vijendar Mukunda wrote:

> This patch adds common PCI driver to bind to this device and get PCI
> resources for ACP7.0 & ACP7.1 platforms.

> +	ret = pci_request_regions(pci, "AMD ACP6.2 audio");
> +	if (ret < 0) {
> +		dev_err(&pci->dev, "pci_request_regions failed\n");
> +		goto disable_pci;
> +	}

Looks like there's a cut'n'paste that needed to be updated here!  I'd
suggest there might be some chance for code sharing, but I suspect the
amount of code is so trivial that it's not really worth it.
Mukunda,Vijendar Jan. 20, 2025, 5:33 p.m. UTC | #2
On 20/01/25 22:38, Mark Brown wrote:
> On Mon, Jan 20, 2025 at 03:31:09PM +0530, Vijendar Mukunda wrote:
>
>> This patch adds common PCI driver to bind to this device and get PCI
>> resources for ACP7.0 & ACP7.1 platforms.
>> +	ret = pci_request_regions(pci, "AMD ACP6.2 audio");
>> +	if (ret < 0) {
>> +		dev_err(&pci->dev, "pci_request_regions failed\n");
>> +		goto disable_pci;
>> +	}
> Looks like there's a cut'n'paste that needed to be updated here!  I'd
> suggest there might be some chance for code sharing, but I suspect the
> amount of code is so trivial that it's not really worth it.
Will update it. As platform specific changes exists along with
standard pci driver probe sequence, I don't think we really need to
go for common code here. Same time, We will improve code by
implementing common helper functions where ever it can be applicable.
diff mbox series

Patch

diff --git a/sound/soc/amd/acp70/acp70.h b/sound/soc/amd/acp70/acp70.h
new file mode 100644
index 000000000000..28a46f0c2026
--- /dev/null
+++ b/sound/soc/amd/acp70/acp70.h
@@ -0,0 +1,33 @@ 
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * ACP 7.0 platform Common header file
+ *
+ * Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
+ */
+
+#include <sound/acp70_chip_offset_byte.h>
+
+#define ACP_DEVICE_ID		0x15E2
+#define ACP70_REG_START		0x1240000
+#define ACP70_REG_END		0x125C000
+#define ACP70_PCI_REV		0x70
+#define ACP71_PCI_REV		0x71
+
+/**
+ * struct acp70_dev_data - acp pci driver context
+ * @acp70_base: acp mmio base
+ * @acp_lock: used to protect acp common registers
+ * @addr: pci ioremap address
+ * @reg_range: ACP reigister range
+ * @acp_rev : ACP PCI revision id
+ */
+
+struct acp70_dev_data {
+	void __iomem *acp70_base;
+	struct mutex acp_lock; /* protect shared registers */
+	u32 addr;
+	u32 reg_range;
+	u32 acp_rev;
+};
+
+int snd_amd_acp_find_config(struct pci_dev *pci);
diff --git a/sound/soc/amd/acp70/pci-acp70.c b/sound/soc/amd/acp70/pci-acp70.c
new file mode 100644
index 000000000000..23e47f619bd7
--- /dev/null
+++ b/sound/soc/amd/acp70/pci-acp70.c
@@ -0,0 +1,100 @@ 
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * AMD common ACP PCI driver for ACP7.0 & ACP7.1 platforms
+ *
+ * Copyright 2024 Advanced Micro Devices, Inc.
+ */
+
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/pci.h>
+#include "../mach-config.h"
+
+#include "acp70.h"
+
+static int snd_acp70_probe(struct pci_dev *pci,
+			   const struct pci_device_id *pci_id)
+{
+	struct acp70_dev_data *adata;
+	u32 addr, flag;
+	int ret;
+
+	/* Return if acp config flag is defined */
+	flag = snd_amd_acp_find_config(pci);
+	if (flag)
+		return -ENODEV;
+
+	/* Pink Sardine device check */
+	switch (pci->revision) {
+	case ACP70_PCI_REV:
+	case ACP71_PCI_REV:
+		break;
+	default:
+		dev_dbg(&pci->dev, "acp70 pci device not found\n");
+		return -ENODEV;
+	}
+	if (pci_enable_device(pci)) {
+		dev_err(&pci->dev, "pci_enable_device failed\n");
+		return -ENODEV;
+	}
+
+	ret = pci_request_regions(pci, "AMD ACP6.2 audio");
+	if (ret < 0) {
+		dev_err(&pci->dev, "pci_request_regions failed\n");
+		goto disable_pci;
+	}
+	adata = devm_kzalloc(&pci->dev, sizeof(struct acp70_dev_data),
+			     GFP_KERNEL);
+	if (!adata) {
+		ret = -ENOMEM;
+		goto release_regions;
+	}
+
+	addr = pci_resource_start(pci, 0);
+	adata->acp70_base = devm_ioremap(&pci->dev, addr,
+					 pci_resource_len(pci, 0));
+	if (!adata->acp70_base) {
+		ret = -ENOMEM;
+		goto release_regions;
+	}
+	adata->addr = addr;
+	adata->reg_range = ACP70_REG_END - ACP70_REG_START;
+	adata->acp_rev = pci->revision;
+	pci_set_master(pci);
+	pci_set_drvdata(pci, adata);
+	mutex_init(&adata->acp_lock);
+	return 0;
+release_regions:
+	pci_release_regions(pci);
+disable_pci:
+	pci_disable_device(pci);
+
+	return ret;
+}
+
+static void snd_acp70_remove(struct pci_dev *pci)
+{
+	pci_release_regions(pci);
+	pci_disable_device(pci);
+}
+
+static const struct pci_device_id snd_acp70_ids[] = {
+	{ PCI_DEVICE(PCI_VENDOR_ID_AMD, ACP_DEVICE_ID),
+	.class = PCI_CLASS_MULTIMEDIA_OTHER << 8,
+	.class_mask = 0xffffff },
+	{ 0, },
+};
+MODULE_DEVICE_TABLE(pci, snd_acp70_ids);
+
+static struct pci_driver ps_acp70_driver  = {
+	.name = KBUILD_MODNAME,
+	.id_table = snd_acp70_ids,
+	.probe = snd_acp70_probe,
+	.remove = snd_acp70_remove,
+};
+
+module_pci_driver(ps_acp70_driver);
+
+MODULE_AUTHOR("Vijendar.Mukunda@amd.com");
+MODULE_DESCRIPTION("AMD ACP7.0 PCI driver");
+MODULE_LICENSE("GPL");