linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vijendar Mukunda <vijendar.mukunda@amd.com>
To: <broonie@kernel.org>, <alsa-devel@alsa-project.org>
Cc: <Alexander.Deucher@amd.com>, <Sunil-kumar.Dommati@amd.com>,
	"Vijendar Mukunda" <Vijendar.Mukunda@amd.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	"Vijendar Mukunda" <vijendar.mukunda@amd.com>,
	open list <linux-kernel@vger.kernel.org>
Subject: [PATCH 04/12] ASoC: amd: create acp5x platform devices
Date: Wed, 7 Jul 2021 11:26:15 +0530	[thread overview]
Message-ID: <20210707055623.27371-5-vijendar.mukunda@amd.com> (raw)
In-Reply-To: <20210707055623.27371-1-vijendar.mukunda@amd.com>

From: Vijendar Mukunda <Vijendar.Mukunda@amd.com>

ACP5.x IP has multiple I2S controllers and DMA controller.
Create platform devices for I2S HS controller instance, I2S SP controller
instance and DMA contrller.
Pass PCI resources like MMIO, irq to these platform devices.

Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
---
 sound/soc/amd/vangogh/acp5x.h     | 10 ++++
 sound/soc/amd/vangogh/pci-acp5x.c | 95 ++++++++++++++++++++++++++++++-
 2 files changed, 102 insertions(+), 3 deletions(-)

diff --git a/sound/soc/amd/vangogh/acp5x.h b/sound/soc/amd/vangogh/acp5x.h
index 11b555306958..365e80b56ff9 100644
--- a/sound/soc/amd/vangogh/acp5x.h
+++ b/sound/soc/amd/vangogh/acp5x.h
@@ -22,6 +22,16 @@
 #define ACP_ERR_INTR_MASK	0x20000000
 #define ACP_EXT_INTR_STAT_CLEAR_MASK 0xFFFFFFFF
 
+#define ACP5x_DEVS 0x03
+#define	ACP5x_REG_START	0x1240000
+#define	ACP5x_REG_END	0x1250200
+#define ACP5x_I2STDM_REG_START	0x1242400
+#define ACP5x_I2STDM_REG_END	0x1242410
+#define ACP5x_HS_TDM_REG_START	0x1242814
+#define ACP5x_HS_TDM_REG_END	0x1242824
+#define I2S_MODE 0x00
+#define ACP5x_I2S_MODE 0x00
+
 static inline u32 acp_readl(void __iomem *base_addr)
 {
 	return readl(base_addr - ACP5x_PHY_BASE_ADDRESS);
diff --git a/sound/soc/amd/vangogh/pci-acp5x.c b/sound/soc/amd/vangogh/pci-acp5x.c
index dbe8fef3e294..2779423f7cd3 100644
--- a/sound/soc/amd/vangogh/pci-acp5x.c
+++ b/sound/soc/amd/vangogh/pci-acp5x.c
@@ -8,6 +8,8 @@
 #include <linux/module.h>
 #include <linux/io.h>
 #include <linux/delay.h>
+#include <linux/platform_device.h>
+#include <linux/interrupt.h>
 
 #include "acp5x.h"
 
@@ -17,6 +19,9 @@ MODULE_PARM_DESC(acp_power_gating, "acp power gating flag");
 
 struct acp5x_dev_data {
 	void __iomem *acp5x_base;
+	bool acp5x_audio_mode;
+	struct resource *res;
+	struct platform_device *pdev[3];
 };
 
 static int acp5x_power_on(void __iomem *acp5x_base)
@@ -143,9 +148,12 @@ static int snd_acp5x_probe(struct pci_dev *pci,
 			   const struct pci_device_id *pci_id)
 {
 	struct acp5x_dev_data *adata;
-	int ret;
-	u32 addr;
+	struct platform_device_info pdevinfo[3];
+	unsigned int irqflags;
+	int ret, i;
+	u32 addr, val;
 
+	irqflags = IRQF_SHARED;
 	if (pci->revision != 0x50)
 		return -ENODEV;
 
@@ -179,6 +187,83 @@ static int snd_acp5x_probe(struct pci_dev *pci,
 	if (ret)
 		goto release_regions;
 
+	val = acp_readl(adata->acp5x_base + ACP_PIN_CONFIG);
+	switch (val) {
+	case I2S_MODE:
+		adata->res = devm_kzalloc(&pci->dev,
+					  sizeof(struct resource) * 4,
+					  GFP_KERNEL);
+		if (!adata->res) {
+			ret = -ENOMEM;
+			goto de_init;
+		}
+
+		adata->res[0].name = "acp5x_i2s_iomem";
+		adata->res[0].flags = IORESOURCE_MEM;
+		adata->res[0].start = addr;
+		adata->res[0].end = addr + (ACP5x_REG_END - ACP5x_REG_START);
+
+		adata->res[1].name = "acp5x_i2s_sp";
+		adata->res[1].flags = IORESOURCE_MEM;
+		adata->res[1].start = addr + ACP5x_I2STDM_REG_START;
+		adata->res[1].end = addr + ACP5x_I2STDM_REG_END;
+
+		adata->res[2].name = "acp5x_i2s_hs";
+		adata->res[2].flags = IORESOURCE_MEM;
+		adata->res[2].start = addr + ACP5x_HS_TDM_REG_START;
+		adata->res[2].end = addr + ACP5x_HS_TDM_REG_END;
+
+		adata->res[3].name = "acp5x_i2s_irq";
+		adata->res[3].flags = IORESOURCE_IRQ;
+		adata->res[3].start = pci->irq;
+		adata->res[3].end = adata->res[3].start;
+
+		adata->acp5x_audio_mode = ACP5x_I2S_MODE;
+
+		memset(&pdevinfo, 0, sizeof(pdevinfo));
+		pdevinfo[0].name = "acp5x_i2s_dma";
+		pdevinfo[0].id = 0;
+		pdevinfo[0].parent = &pci->dev;
+		pdevinfo[0].num_res = 4;
+		pdevinfo[0].res = &adata->res[0];
+		pdevinfo[0].data = &irqflags;
+		pdevinfo[0].size_data = sizeof(irqflags);
+
+		pdevinfo[1].name = "acp5x_i2s_playcap";
+		pdevinfo[1].id = 0;
+		pdevinfo[1].parent = &pci->dev;
+		pdevinfo[1].num_res = 1;
+		pdevinfo[1].res = &adata->res[1];
+
+		pdevinfo[2].name = "acp5x_i2s_playcap";
+		pdevinfo[2].id = 1;
+		pdevinfo[2].parent = &pci->dev;
+		pdevinfo[2].num_res = 1;
+		pdevinfo[2].res = &adata->res[2];
+
+		for (i = 0; i < ACP5x_DEVS; i++) {
+			adata->pdev[i] =
+				platform_device_register_full(&pdevinfo[i]);
+			if (IS_ERR(adata->pdev[i])) {
+				dev_err(&pci->dev, "cannot register %s device\n",
+					pdevinfo[i].name);
+				ret = PTR_ERR(adata->pdev[i]);
+				goto unregister_devs;
+			}
+		}
+		break;
+	default:
+		dev_info(&pci->dev, "ACP audio mode : %d\n", val);
+	}
+	return 0;
+
+unregister_devs:
+	if (val == I2S_MODE)
+		for (i = 0; i < ACP5x_DEVS; i++)
+			platform_device_unregister(adata->pdev[i]);
+de_init:
+	if (acp5x_deinit(adata->acp5x_base))
+		dev_err(&pci->dev, "ACP de-init failed\n");
 release_regions:
 	pci_release_regions(pci);
 disable_pci:
@@ -190,9 +275,13 @@ static int snd_acp5x_probe(struct pci_dev *pci,
 static void snd_acp5x_remove(struct pci_dev *pci)
 {
 	struct acp5x_dev_data *adata;
-	int ret;
+	int i, ret;
 
 	adata = pci_get_drvdata(pci);
+	if (adata->acp5x_audio_mode == ACP5x_I2S_MODE) {
+		for (i = 0; i < ACP5x_DEVS; i++)
+			platform_device_unregister(adata->pdev[i]);
+	}
 	ret = acp5x_deinit(adata->acp5x_base);
 	if (ret)
 		dev_err(&pci->dev, "ACP de-init failed\n");
-- 
2.17.1


  parent reply	other threads:[~2021-07-07  5:40 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20210707055623.27371-1-vijendar.mukunda@amd.com>
2021-07-07  5:56 ` [PATCH 01/12] ASoC: amd: add Vangogh ACP5x IP register header Vijendar Mukunda
2021-07-07  5:56 ` [PATCH 02/12] ASoC: amd: add Vangogh ACP PCI driver Vijendar Mukunda
2021-07-07 16:17   ` Mark Brown
2021-07-08 14:07     ` Mukunda,Vijendar
2021-07-07  5:56 ` [PATCH 03/12] add acp5x init/de-init functions Vijendar Mukunda
2021-07-07 16:15   ` Pierre-Louis Bossart
2021-07-08 13:30     ` Mukunda,Vijendar
2021-07-07  5:56 ` Vijendar Mukunda [this message]
2021-07-07 16:22   ` [PATCH 04/12] ASoC: amd: create acp5x platform devices Mark Brown
2021-07-08 15:02     ` Mukunda,Vijendar
2021-07-07  5:56 ` [PATCH 05/12] ASoC: amd: add ACP5x PCM platform driver Vijendar Mukunda
2021-07-07 16:17   ` Pierre-Louis Bossart
2021-07-08 13:31     ` Mukunda,Vijendar
2021-07-07 16:24   ` Mark Brown
2021-07-08 11:57     ` Mukunda,Vijendar
2021-07-07  5:56 ` [PATCH 06/12] ASoC: amd: irq handler changes for ACP5x PCM dma driver Vijendar Mukunda
2021-07-07 16:20   ` Pierre-Louis Bossart
2021-07-08 13:32     ` Mukunda,Vijendar
2021-07-07  5:56 ` [PATCH 07/12] ASoC: amd: add ACP5x pcm dma driver ops Vijendar Mukunda
2021-07-07 16:27   ` Pierre-Louis Bossart
2021-07-08 11:56     ` Mukunda,Vijendar
2021-07-07 16:30   ` Mark Brown
2021-07-08 11:43     ` Mukunda,Vijendar
2021-07-07  5:56 ` [PATCH 08/12] ASoC: amd: add vangogh i2s controller driver Vijendar Mukunda
2021-07-07  5:56 ` [PATCH 09/12] ASoC: amd: add vangogh i2s dai driver ops Vijendar Mukunda
2021-07-07 16:35   ` Mark Brown
2021-07-08 11:30     ` Mukunda,Vijendar
2021-07-07  5:56 ` [PATCH 10/12] ASoC: amd: add vangogh pci driver pm ops Vijendar Mukunda
2021-07-07 16:34   ` Pierre-Louis Bossart
2021-07-08 11:41     ` Mukunda,Vijendar
2021-07-13  6:36       ` Mukunda,Vijendar
2021-07-14 16:23         ` Mark Brown
2021-07-15 23:49           ` Mukunda,Vijendar
2021-07-07  5:56 ` [PATCH 11/12] ASoc: amd: add vangogh i2s dma " Vijendar Mukunda
2021-07-07  5:56 ` [PATCH 12/12] ASoC: amd: enable vangogh acp5x driver build Vijendar Mukunda
2021-07-07  9:00   ` kernel test robot
2021-07-08 14:08     ` Mukunda,Vijendar
     [not found] <20210716150809.21450-1-vijendar.mukunda@amd.com>
2021-07-16 15:08 ` [PATCH 04/12] ASoC: amd: create acp5x platform devices Vijendar Mukunda

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210707055623.27371-5-vijendar.mukunda@amd.com \
    --to=vijendar.mukunda@amd.com \
    --cc=Alexander.Deucher@amd.com \
    --cc=Sunil-kumar.Dommati@amd.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).