Skip to content

Commit 7894a7e

Browse files
vijendarmukundabroonie
authored andcommitted
ASoC: amd: create ACP3x PCM platform device
ACP 3x IP has I2S controller device as one of IP blocks. Create a platform device for it, so that the PCM platform driver can be bound to this device. Pass PCI resources like MMIO, irq to the platform device. Signed-off-by: Maruthi Bayyavarapu <maruthi.bayyavarapu@amd.com> Tested-by: Ravulapati Vishnu vardhan Rao <vishnuvardhanrao.ravulapati@amd.com> Signed-off-by: Vijendar Mukunda <vijendar.mukunda@amd.com> Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent e30d912 commit 7894a7e

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

sound/soc/amd/raven/acp3x.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#include "chip_offset_byte.h"
22

33
#define ACP3x_PHY_BASE_ADDRESS 0x1240000
4+
#define ACP3x_I2S_MODE 0
5+
#define ACP3x_REG_START 0x1240000
6+
#define ACP3x_REG_END 0x1250200
7+
#define I2S_MODE 0x04
48

59
static inline u32 rv_readl(void __iomem *base_addr)
610
{

sound/soc/amd/raven/pci-acp3x.c

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,26 @@
1616
#include <linux/pci.h>
1717
#include <linux/module.h>
1818
#include <linux/io.h>
19+
#include <linux/platform_device.h>
20+
#include <linux/interrupt.h>
1921

2022
#include "acp3x.h"
2123

2224
struct acp3x_dev_data {
2325
void __iomem *acp3x_base;
26+
bool acp3x_audio_mode;
27+
struct resource *res;
28+
struct platform_device *pdev;
2429
};
2530

2631
static int snd_acp3x_probe(struct pci_dev *pci,
2732
const struct pci_device_id *pci_id)
2833
{
2934
int ret;
30-
u32 addr;
35+
u32 addr, val;
3136
struct acp3x_dev_data *adata;
37+
struct platform_device_info pdevinfo;
38+
unsigned int irqflags;
3239

3340
if (pci_enable_device(pci)) {
3441
dev_err(&pci->dev, "pci_enable_device failed\n");
@@ -48,6 +55,15 @@ static int snd_acp3x_probe(struct pci_dev *pci,
4855
goto release_regions;
4956
}
5057

58+
/* check for msi interrupt support */
59+
ret = pci_enable_msi(pci);
60+
if (ret)
61+
/* msi is not enabled */
62+
irqflags = IRQF_SHARED;
63+
else
64+
/* msi is enabled */
65+
irqflags = 0;
66+
5167
addr = pci_resource_start(pci, 0);
5268
adata->acp3x_base = ioremap(addr, pci_resource_len(pci, 0));
5369
if (!adata->acp3x_base) {
@@ -56,8 +72,57 @@ static int snd_acp3x_probe(struct pci_dev *pci,
5672
}
5773
pci_set_master(pci);
5874
pci_set_drvdata(pci, adata);
75+
76+
val = rv_readl(adata->acp3x_base + mmACP_I2S_PIN_CONFIG);
77+
switch (val) {
78+
case I2S_MODE:
79+
adata->res = devm_kzalloc(&pci->dev,
80+
sizeof(struct resource) * 2,
81+
GFP_KERNEL);
82+
if (!adata->res) {
83+
ret = -ENOMEM;
84+
goto unmap_mmio;
85+
}
86+
87+
adata->res[0].name = "acp3x_i2s_iomem";
88+
adata->res[0].flags = IORESOURCE_MEM;
89+
adata->res[0].start = addr;
90+
adata->res[0].end = addr + (ACP3x_REG_END - ACP3x_REG_START);
91+
92+
adata->res[1].name = "acp3x_i2s_irq";
93+
adata->res[1].flags = IORESOURCE_IRQ;
94+
adata->res[1].start = pci->irq;
95+
adata->res[1].end = pci->irq;
96+
97+
adata->acp3x_audio_mode = ACP3x_I2S_MODE;
98+
99+
memset(&pdevinfo, 0, sizeof(pdevinfo));
100+
pdevinfo.name = "acp3x_rv_i2s";
101+
pdevinfo.id = 0;
102+
pdevinfo.parent = &pci->dev;
103+
pdevinfo.num_res = 2;
104+
pdevinfo.res = adata->res;
105+
pdevinfo.data = &irqflags;
106+
pdevinfo.size_data = sizeof(irqflags);
107+
108+
adata->pdev = platform_device_register_full(&pdevinfo);
109+
if (!adata->pdev) {
110+
dev_err(&pci->dev, "cannot register %s device\n",
111+
pdevinfo.name);
112+
ret = -ENODEV;
113+
goto unmap_mmio;
114+
}
115+
break;
116+
default:
117+
dev_err(&pci->dev, "Inavlid ACP audio mode : %d\n", val);
118+
ret = -ENODEV;
119+
goto unmap_mmio;
120+
}
59121
return 0;
60122

123+
unmap_mmio:
124+
pci_disable_msi(pci);
125+
iounmap(adata->acp3x_base);
61126
release_regions:
62127
pci_release_regions(pci);
63128
disable_pci:
@@ -70,7 +135,10 @@ static void snd_acp3x_remove(struct pci_dev *pci)
70135
{
71136
struct acp3x_dev_data *adata = pci_get_drvdata(pci);
72137

138+
platform_device_unregister(adata->pdev);
73139
iounmap(adata->acp3x_base);
140+
141+
pci_disable_msi(pci);
74142
pci_release_regions(pci);
75143
pci_disable_device(pci);
76144
}

0 commit comments

Comments
 (0)