ASoC: amd: acp: add code for scanning acp pdm controller

Add common code for scanning acp pdm controller and create
platform device for the same.

Signed-off-by: Syed Saba Kareem <Syed.SabaKareem@amd.com>
Link: https://lore.kernel.org/r/20231021145110.478744-6-Syed.SabaKareem@amd.com
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Syed Saba Kareem 2023-10-21 20:20:47 +05:30 committed by Mark Brown
parent d4c2d5391d
commit 3a94c8ad0a
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0
5 changed files with 86 additions and 1 deletions

View File

@ -16,6 +16,10 @@
#include <linux/pci.h>
#include <linux/export.h>
#define ACP_RENOIR_PDM_ADDR 0x02
#define ACP_REMBRANDT_PDM_ADDR 0x03
#define ACP63_PDM_ADDR 0x02
void acp_enable_interrupts(struct acp_dev_data *adata)
{
struct acp_resource *rsrc = adata->rsrc;
@ -348,4 +352,52 @@ int smn_read(struct pci_dev *dev, u32 smn_addr)
}
EXPORT_SYMBOL_NS_GPL(smn_read, SND_SOC_ACP_COMMON);
int check_acp_pdm(struct pci_dev *pci, struct acp_chip_info *chip)
{
struct acpi_device *pdm_dev;
const union acpi_object *obj;
u32 pdm_addr, val;
val = readl(chip->base + ACP_PIN_CONFIG);
switch (val) {
case ACP_CONFIG_4:
case ACP_CONFIG_5:
case ACP_CONFIG_6:
case ACP_CONFIG_7:
case ACP_CONFIG_8:
case ACP_CONFIG_10:
case ACP_CONFIG_11:
case ACP_CONFIG_12:
case ACP_CONFIG_13:
case ACP_CONFIG_14:
break;
default:
return -EINVAL;
}
switch (chip->acp_rev) {
case ACP3X_DEV:
pdm_addr = ACP_RENOIR_PDM_ADDR;
break;
case ACP6X_DEV:
pdm_addr = ACP_REMBRANDT_PDM_ADDR;
break;
case ACP63_DEV:
pdm_addr = ACP63_PDM_ADDR;
break;
default:
return -EINVAL;
}
pdm_dev = acpi_find_child_device(ACPI_COMPANION(&pci->dev), pdm_addr, 0);
if (pdm_dev) {
if (!acpi_dev_get_property(pdm_dev, "acp-audio-device-type",
ACPI_TYPE_INTEGER, &obj) &&
obj->integer.value == pdm_addr)
return 0;
}
return -ENODEV;
}
EXPORT_SYMBOL_NS_GPL(check_acp_pdm, SND_SOC_ACP_COMMON);
MODULE_LICENSE("Dual BSD/GPL");

View File

@ -55,7 +55,7 @@ static int acp_pci_probe(struct pci_dev *pci, const struct pci_device_id *pci_id
int ret;
flag = snd_amd_acp_find_config(pci);
if (flag != FLAG_AMD_LEGACY)
if (flag != FLAG_AMD_LEGACY && flag != FLAG_AMD_LEGACY_ONLY_DMIC)
return -ENODEV;
chip = devm_kzalloc(&pci->dev, sizeof(*chip), GFP_KERNEL);
@ -129,6 +129,13 @@ static int acp_pci_probe(struct pci_dev *pci, const struct pci_device_id *pci_id
}
}
if (flag == FLAG_AMD_LEGACY_ONLY_DMIC) {
ret = check_acp_pdm(pci, chip);
if (ret < 0)
goto skip_pdev_creation;
}
chip->flag = flag;
memset(&pdevinfo, 0, sizeof(pdevinfo));
pdevinfo.name = chip->name;
@ -145,6 +152,8 @@ static int acp_pci_probe(struct pci_dev *pci, const struct pci_device_id *pci_id
ret = PTR_ERR(pdev);
goto unregister_dmic_dev;
}
skip_pdev_creation:
chip->chip_pdev = pdev;
dev_set_drvdata(&pci->dev, chip);
pm_runtime_set_autosuspend_delay(&pci->dev, 2000);

View File

@ -133,6 +133,7 @@ struct acp_chip_info {
unsigned int acp_rev; /* ACP Revision id */
void __iomem *base; /* ACP memory PCI base */
struct platform_device *chip_pdev;
unsigned int flag; /* Distinguish b/w Legacy or Only PDM */
};
struct acp_stream {
@ -188,6 +189,25 @@ struct acp_dev_data {
u32 xfer_rx_resolution[3];
};
enum acp_config {
ACP_CONFIG_0 = 0,
ACP_CONFIG_1,
ACP_CONFIG_2,
ACP_CONFIG_3,
ACP_CONFIG_4,
ACP_CONFIG_5,
ACP_CONFIG_6,
ACP_CONFIG_7,
ACP_CONFIG_8,
ACP_CONFIG_9,
ACP_CONFIG_10,
ACP_CONFIG_11,
ACP_CONFIG_12,
ACP_CONFIG_13,
ACP_CONFIG_14,
ACP_CONFIG_15,
};
extern const struct snd_soc_dai_ops asoc_acp_cpu_dai_ops;
extern const struct snd_soc_dai_ops acp_dmic_dai_ops;
@ -214,6 +234,8 @@ void restore_acp_pdm_params(struct snd_pcm_substream *substream,
int restore_acp_i2s_params(struct snd_pcm_substream *substream,
struct acp_dev_data *adata, struct acp_stream *stream);
int check_acp_pdm(struct pci_dev *pci, struct acp_chip_info *chip);
static inline u64 acp_get_byte_count(struct acp_dev_data *adata, int dai_id, int direction)
{
u64 byte_count = 0, low = 0, high = 0;

View File

@ -19,6 +19,7 @@
#define ACP_PGFSM_STATUS 0x1420
#define ACP_SOFT_RESET 0x1000
#define ACP_CONTROL 0x1004
#define ACP_PIN_CONFIG 0x1440
#define ACP_EXTERNAL_INTR_REG_ADDR(adata, offset, ctrl) \
(adata->acp_base + adata->rsrc->irq_reg_offset + offset + (ctrl * 0x04))

View File

@ -15,6 +15,7 @@
#define FLAG_AMD_SOF BIT(1)
#define FLAG_AMD_SOF_ONLY_DMIC BIT(2)
#define FLAG_AMD_LEGACY BIT(3)
#define FLAG_AMD_LEGACY_ONLY_DMIC BIT(4)
#define ACP_PCI_DEV_ID 0x15E2