ASOC: amd: acp: Add generic PDM and PCI driver support for ACP
Subsystems (3)
PATCH v2 1/6 ASoC: amd: acp: Add generic support for PDM controller on ACP
In reply to Ajit Kumar PandeyAdd driver module for PDM controller on ACP IP block. Expose dai ops to configure ACP_WOV_PDM_BLOCK registers on ACP. Such dai ops will be used by platform specific driver module to register dmic related dai with ASoC.
--- sound/soc/amd/acp/Kconfig | 3 + sound/soc/amd/acp/Makefile | 2 + sound/soc/amd/acp/acp-pdm.c | 181 +++++++++++++++++++++++++++ sound/soc/amd/acp/amd.h | 9 +- sound/soc/amd/acp/chip_offset_byte.h | 20 +++ 5 files changed, 214 insertions(+), 1 deletion(-) create mode 100644 sound/soc/amd/acp/acp-pdm.c
sound/soc/amd/acp/Kconfig +3 -0
@@ -15,6 +15,9 @@ config SND_SOC_AMD_ACP_COMMON if SND_SOC_AMD_ACP_COMMON +config SND_SOC_AMD_ACP_PDM + tristate + config SND_SOC_AMD_ACP_I2S tristate
sound/soc/amd/acp/Makefile +2 -0
@@ -7,6 +7,7 @@ #common acp driver snd-acp-pcm-objs := acp-platform.o snd-acp-i2s-objs := acp-i2s.o +snd-acp-pdm-objs := acp-pdm.o #platform specific driver snd-acp-renoir-objs := acp-renoir.o
@@ -18,6 +19,7 @@ snd-acp-sof-mach-objs := acp-sof-mach.o obj-$(CONFIG_SND_SOC_AMD_ACP_PCM) += snd-acp-pcm.o obj-$(CONFIG_SND_SOC_AMD_ACP_I2S) += snd-acp-i2s.o +obj-$(CONFIG_SND_SOC_AMD_ACP_PDM) += snd-acp-pdm.o obj-$(CONFIG_SND_AMD_ASOC_RENOIR) += snd-acp-renoir.o
sound/soc/amd/acp/acp-pdm.c new file +181 -0
181 lines not on this page · raw message
sound/soc/amd/acp/amd.h +8 -1
@@ -17,8 +17,9 @@#define I2S_SP_INSTANCE 0x00#define I2S_BT_INSTANCE 0x01 +#define DMIC_INSTANCE 0x02 -#define MEM_WINDOW_START 0x4000000 +#define MEM_WINDOW_START 0x4080000#define ACP_I2S_REG_START 0x1242400#define ACP_I2S_REG_END 0x1242810
@@ -38,6 +39,7 @@#define ACP_SRAM_SP_CP_PTE_OFFSET 0x100#define ACP_SRAM_BT_PB_PTE_OFFSET 0x200#define ACP_SRAM_BT_CP_PTE_OFFSET 0x300 +#define ACP_SRAM_PDM_PTE_OFFSET 0x400#define PAGE_SIZE_4K_ENABLE 0x2#define I2S_SP_TX_MEM_WINDOW_START 0x4000000
@@ -96,6 +98,7 @@ struct acp_dev_data { };extern const struct snd_soc_dai_ops asoc_acp_cpu_dai_ops; +extern const struct snd_soc_dai_ops acp_dmic_dai_ops;int asoc_acp_i2s_probe (struct snd_soc_dai *dai);int acp_platform_register (struct device *dev);
@@ -131,6 +134,10 @@ static inline u64 acp_get_byte_count(struct acp_dev_data *adata, int dai_id, int high =readl (adata->acp_base +ACP_I2S_RX_LINEARPOSITIONCNTR_HIGH ); low =readl (adata->acp_base +ACP_I2S_RX_LINEARPOSITIONCNTR_LOW );break ; +case DMIC_INSTANCE : + high =readl (adata->acp_base +ACP_WOV_RX_LINEARPOSITIONCNTR_HIGH ); + low =readl (adata->acp_base +ACP_WOV_RX_LINEARPOSITIONCNTR_LOW ); +break ;default :dev_err (adata->dev,"Invalid dai id %x\n" , dai_id);return -EINVAL ;
sound/soc/amd/acp/chip_offset_byte.h +20 -0
@@ -73,4 +73,24 @@#define ACP_BTTDM_ITER 0x280C#define ACP_BTTDM_TXFRMT 0x2810 +/* Registers from ACP_WOV_PDM block */ + +#define ACP_WOV_PDM_ENABLE 0x2C04 +#define ACP_WOV_PDM_DMA_ENABLE 0x2C08 +#define ACP_WOV_RX_RINGBUFADDR 0x2C0C +#define ACP_WOV_RX_RINGBUFSIZE 0x2C10 +#define ACP_WOV_RX_LINKPOSITIONCNTR 0x2C14 +#define ACP_WOV_RX_LINEARPOSITIONCNTR_HIGH 0x2C18 +#define ACP_WOV_RX_LINEARPOSITIONCNTR_LOW 0x2C1C +#define ACP_WOV_RX_INTR_WATERMARK_SIZE 0x2C20 +#define ACP_WOV_PDM_FIFO_FLUSH 0x2C24 +#define ACP_WOV_PDM_NO_OF_CHANNELS 0x2C28 +#define ACP_WOV_PDM_DECIMATION_FACTOR 0x2C2C +#define ACP_WOV_PDM_VAD_CTRL 0x2C30 +#define ACP_WOV_BUFFER_STATUS 0x2C58 +#define ACP_WOV_MISC_CTRL 0x2C5C +#define ACP_WOV_CLK_CTRL 0x2C60 +#define ACP_PDM_VAD_DYNAMIC_CLK_GATING_EN 0x2C64 +#define ACP_WOV_ERROR_STATUS_REGISTER 0x2C68 +#endif
Signature · 1 line
2.25.1
PATCH v2 2/6 ASoC: amd: acp: Add PDM controller based dmic dai for Renoir
In reply to Ajit Kumar PandeyRenoir ACP IP has a PDM controller block. Add DMIC dai instance in dai_driver struct to enable dmic capture support on Renoir platform.
--- sound/soc/amd/acp/Kconfig | 1 + sound/soc/amd/acp/acp-renoir.c | 13 +++++++++++++ 2 files changed, 14 insertions(+)
sound/soc/amd/acp/Kconfig +1 -0
@@ -29,6 +29,7 @@ config SND_AMD_ASOC_RENOIR tristate "AMD ACP ASOC Renoir Support" select SND_SOC_AMD_ACP_PCM select SND_SOC_AMD_ACP_I2S + select SND_SOC_AMD_ACP_PDM depends on X86 && PCI help This option enables Renoir I2S support on AMD platform.
sound/soc/amd/acp/acp-renoir.c +13 -0
@@ -97,6 +97,19 @@ static struct snd_soc_dai_driver acp_renoir_dai[] = { .ops = &asoc_acp_cpu_dai_ops, .probe = &asoc_acp_i2s_probe, }, +{ + .name = "acp-pdm-dmic", + .id = DMIC_INSTANCE, + .capture = { + .rates = SNDRV_PCM_RATE_8000_48000, + .formats = SNDRV_PCM_FMTBIT_S32_LE, + .channels_min = 2, + .channels_max = 2, + .rate_min = 8000, + .rate_max = 48000, + }, + .ops = &acp_dmic_dai_ops, +}, };static int renoir_audio_probe (struct platform_device *pdev)
Signature · 1 line
2.25.1
PATCH v2 3/6 ASoC: amd: acp: Add generic PCI driver module for ACP device
In reply to Ajit Kumar PandeyAudio Co-processor or ACP IP block on AMD's SOC is connected via PCI bus interface, hence needs to be register as a PCI device. We have same PCI device ID across multiple SOC's but with different revision id for PCI hw. Add a generic PCI driver module for ACP that registers ACP as a PCI device and also register a platform device based on pci revision id. Any SOC's specific configuration for ACP block will be done in platform driver probe. We have added an initial support for ACP revision id 3 or ACP3X device.
--- sound/soc/amd/acp/Kconfig | 6 ++ sound/soc/amd/acp/Makefile | 2 + sound/soc/amd/acp/acp-pci.c | 160 ++++++++++++++++++++++++++++++++++++ sound/soc/amd/acp/amd.h | 14 ++++ sound/soc/amd/mach-config.h | 1 + 5 files changed, 183 insertions(+) create mode 100644 sound/soc/amd/acp/acp-pci.c
sound/soc/amd/acp/Kconfig +6 -0
@@ -25,6 +25,12 @@ config SND_SOC_AMD_ACP_PCM tristate select SND_SOC_ACPI if ACPI +config SND_SOC_AMD_ACP_PCI + tristate "AMD ACP PCI Driver Support" + depends on X86 && PCI + help + This options enables generic PCI driver for ACP device. + config SND_AMD_ASOC_RENOIR tristate "AMD ACP ASOC Renoir Support" select SND_SOC_AMD_ACP_PCM
sound/soc/amd/acp/Makefile +2 -0
@@ -8,6 +8,7 @@ snd-acp-pcm-objs := acp-platform.o snd-acp-i2s-objs := acp-i2s.o snd-acp-pdm-objs := acp-pdm.o +snd-acp-pci-objs := acp-pci.o #platform specific driver snd-acp-renoir-objs := acp-renoir.o
@@ -20,6 +21,7 @@ snd-acp-sof-mach-objs := acp-sof-mach.o obj-$(CONFIG_SND_SOC_AMD_ACP_PCM) += snd-acp-pcm.o obj-$(CONFIG_SND_SOC_AMD_ACP_I2S) += snd-acp-i2s.o obj-$(CONFIG_SND_SOC_AMD_ACP_PDM) += snd-acp-pdm.o +obj-$(CONFIG_SND_SOC_AMD_ACP_PCI) += snd-acp-pci.o obj-$(CONFIG_SND_AMD_ASOC_RENOIR) += snd-acp-renoir.o
sound/soc/amd/acp/acp-pci.c new file +160 -0
160 lines not on this page · raw message
sound/soc/amd/acp/amd.h +14 -0
@@ -12,9 +12,14 @@#define __AMD_ACP_H#include <sound/pcm.h> +#include <sound/soc.h> #include <sound/soc-acpi.h> +#include <sound/soc-dai.h> +#include "chip_offset_byte.h" +#define ACP3X_DEV 3 +#define I2S_SP_INSTANCE 0x00#define I2S_BT_INSTANCE 0x01#define DMIC_INSTANCE 0x02
@@ -70,6 +75,12 @@#define ACP_MAX_STREAM 6 +struct acp_chip_info { +char *name;/* Platform name */ +unsigned int acp_rev;/* ACP Revision id */ +void __iomem *base;/* ACP memory PCI base */ +}; +struct acp_stream {struct snd_pcm_substream *substream;int irq_bit;
@@ -106,6 +117,9 @@ int acp_platform_unregister(struct device *dev);int acp_machine_select (struct acp_dev_data *adata); +/* Machine configuration */ +int snd_amd_acp_find_config (struct pci_dev *pci); +static inline u64 acp_get_byte_count (struct acp_dev_data *adata,int dai_id,int direction) {u64 byte_count, low =0 , high =0 ;
sound/soc/amd/mach-config.h +1 -0
@@ -14,6 +14,7 @@#define FLAG_AMD_SOF BIT(1)#define FLAG_AMD_SOF_ONLY_DMIC BIT(2) +#define FLAG_AMD_LEGACY BIT(3)#define ACP_PCI_DEV_ID 0x15E2
Signature · 1 line
2.25.1
v2 cover ASOC: amd: acp: Add generic PDM and PCI driver support for ACP
changes since v1:
PATCH 3/6 - Added platform_unregister() for error case
Ajit Kumar Pandey (6):
ASoC: amd: acp: Add generic support for PDM controller on ACP
ASoC: amd: acp: Add PDM controller based dmic dai for Renoir
ASoC: amd: acp: Add generic PCI driver module for ACP device
ASoC: amd: acp: Add ACP init()/deinit() callback for Renoir.
ASoC: amd: acp: acp-legacy: Add DMIC dai link support for Renoir
ASoC: amd: renoir: Add check for acp configuration flags.
sound/soc/amd/acp/Kconfig | 10 ++ sound/soc/amd/acp/Makefile | 4 + sound/soc/amd/acp/acp-legacy-mach.c | 4 +- sound/soc/amd/acp/acp-mach-common.c | 15 +++ sound/soc/amd/acp/acp-pci.c | 160 +++++++++++++++++++++++ sound/soc/amd/acp/acp-pdm.c | 181 ++++++++++++++++++++++++++ sound/soc/amd/acp/acp-renoir.c | 183 +++++++++++++++++++++++++++ sound/soc/amd/acp/amd.h | 23 +++- sound/soc/amd/acp/chip_offset_byte.h | 26 ++++ sound/soc/amd/mach-config.h | 1 + sound/soc/amd/renoir/rn-pci-acp3x.c | 7 +- sound/soc/amd/renoir/rn_acp3x.h | 3 + 12 files changed, 613 insertions(+), 4 deletions(-) create mode 100644 sound/soc/amd/acp/acp-pci.c create mode 100644 sound/soc/amd/acp/acp-pdm.c
Signature · 1 line
2.25.1
PATCH v2 4/6 ASoC: amd: acp: Add ACP init()/deinit() callback for Renoir.
ACP hardware has PGFSM control registers that can be configured to power On/Off the ACP IP block. Add acp init()/de_init() callbacks in renoir platform driver probe()/remove() respectively to power on and off ACP IP block on ACP3X device.
--- sound/soc/amd/acp/acp-renoir.c | 170 +++++++++++++++++++++++++++ sound/soc/amd/acp/chip_offset_byte.h | 6 + 2 files changed, 176 insertions(+)
sound/soc/amd/acp/acp-renoir.c +170 -0
@@ -25,6 +25,19 @@#define DRV_NAME "acp_asoc_renoir" +#define ACP_SOFT_RST_DONE_MASK 0x00010001 + +#define ACP_PWR_ON_MASK 0x01 +#define ACP_PWR_OFF_MASK 0x00 +#define ACP_PGFSM_STAT_MASK 0x03 +#define ACP_POWERED_ON 0x00 +#define ACP_PWR_ON_IN_PROGRESS 0x01 +#define ACP_POWERED_OFF 0x02 + + +#define ACP_ERROR_MASK 0x20000000 +#define ACP_EXT_INTR_STAT_CLEAR_MASK 0xFFFFFFFF +static struct snd_soc_acpi_codecs amp_rt1019 = { .num_codecs =1 , .codecs = {"10EC1019" }
@@ -112,11 +125,154 @@ static struct snd_soc_dai_driver acp_renoir_dai[] = { }, }; +static int acp3x_power_on (void __iomem *base) +{ +u32 val; +int timeout =0 ; + + val =readl (base +ACP_PGFSM_STATUS ); + +if (val ==ACP_POWERED_ON ) +return 0 ; + +if ((val &ACP_PGFSM_STAT_MASK ) !=ACP_PWR_ON_IN_PROGRESS ) +writel (ACP_PWR_ON_MASK , base +ACP_PGFSM_CONTROL ); + +while (++timeout <500 ) { + val =readl (base +ACP_PGFSM_STATUS ); +if (!val) +return 0 ; +udelay (1 ); + } + +return -ETIMEDOUT ; +} + +static int acp3x_power_off (void __iomem *base) +{ +u32 val; +int timeout =0 ; + +writel (ACP_PWR_OFF_MASK , base +ACP_PGFSM_CONTROL ); + +while (++timeout <500 ) { + val =readl (base +ACP_PGFSM_STATUS ); +if ((val &ACP_PGFSM_STAT_MASK ) ==ACP_POWERED_OFF ) +return 0 ; +udelay (1 ); + } + +return -ETIMEDOUT ; +} + +static int acp3x_reset (void __iomem *base) +{ +u32 val; +int timeout =0 ; + +writel (1 , base +ACP_SOFT_RESET ); + +while (++timeout <500 ) { + val =readl (base +ACP_SOFT_RESET ); +if (val &ACP_SOFT_RST_DONE_MASK ) +break ; +cpu_relax (); + } + +writel (0 , base +ACP_SOFT_RESET ); + + timeout =0 ; +while (++timeout <500 ) { + val =readl (base +ACP_SOFT_RESET ); +if (!val) +return 0 ; +cpu_relax (); + } + +return -ETIMEDOUT ; +} + +static void acp3x_enable_interrupts (void __iomem *base) +{ +u32 ext_intr_ctrl; + +writel (0x01 , base +ACP_EXTERNAL_INTR_ENB ); + ext_intr_ctrl =readl (base +ACP_EXTERNAL_INTR_CNTL ); + ext_intr_ctrl |=ACP_ERROR_MASK ; +writel (ext_intr_ctrl, base +ACP_EXTERNAL_INTR_CNTL ); +} + +static void acp3x_disable_interrupts (void __iomem *base) +{ +writel (ACP_EXT_INTR_STAT_CLEAR_MASK , base +ACP_EXTERNAL_INTR_STAT ); +writel (0x00 , base +ACP_EXTERNAL_INTR_ENB ); +} + +static int rn_acp_init (void __iomem *base) +{ +int ret; + +/* power on */ + ret =acp3x_power_on (base); +if (ret) +return ret; + +writel (0x01 , base +ACP_CONTROL ); + +/* Reset */ + ret =acp3x_reset (base); +if (ret) +return ret; + +acp3x_enable_interrupts (base); + +return 0 ; +} + +static int rn_acp_deinit (void __iomem *base) +{ +int ret =0 ; + +acp3x_disable_interrupts (base); + +/* Reset */ + ret =acp3x_reset (base); +if (ret) +return ret; + +writel (0x00 , base +ACP_CONTROL ); + +/* power off */ + ret =acp3x_power_off (base); +if (ret) +return ret; + +return 0 ; +}static int renoir_audio_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev; +struct acp_chip_info *chip;struct acp_dev_data *adata;struct resource *res; +int ret; + + chip =dev_get_platdata (&pdev->dev); +if (!chip || !chip->base) { +dev_err (&pdev->dev,"ACP chip data is NULL\n" ); +return -ENODEV ; + } + +if (chip->acp_rev !=ACP3X_DEV ) { +dev_err (&pdev->dev,"Un-supported ACP Revision %d\n" , chip->acp_rev); +return -ENODEV ; + } + + ret =rn_acp_init (chip->base); +if (ret) { +dev_err (&pdev->dev,"ACP Init failed\n" ); +return -EINVAL ; + } adata =devm_kzalloc (dev,sizeof (struct acp_dev_data ),GFP_KERNEL );if (!adata)
@@ -155,6 +311,20 @@ static int renoir_audio_probe(struct platform_device *pdev)static int renoir_audio_remove (struct platform_device *pdev) {struct device *dev = &pdev->dev; +struct acp_chip_info *chip; +int ret; + + chip =dev_get_platdata (&pdev->dev); +if (!chip || !chip->base) { +dev_err (&pdev->dev,"ACP chip data is NULL\n" ); +return -ENODEV ; + } + + ret =rn_acp_deinit (chip->base); +if (ret) { +dev_err (&pdev->dev,"ACP de-init Failed\n" ); +return -EINVAL ; + }acp_platform_unregister (dev);return 0 ;
sound/soc/amd/acp/chip_offset_byte.h +6 -0
@@ -14,6 +14,12 @@#define ACPAXI2AXI_ATU_CTRL 0xC40#define ACPAXI2AXI_ATU_PAGE_SIZE_GRP_5 0xC20#define ACPAXI2AXI_ATU_BASE_ADDR_GRP_5 0xC24 + +#define ACP_PGFSM_CONTROL 0x141C +#define ACP_PGFSM_STATUS 0x1420 +#define ACP_SOFT_RESET 0x1000 +#define ACP_CONTROL 0x1004 +#define ACP_EXTERNAL_INTR_ENB 0x1800#define ACP_EXTERNAL_INTR_CNTL 0x1804#define ACP_EXTERNAL_INTR_STAT 0x1808
Signature · 1 line
2.25.1
PATCH v2 5/6 ASoC: amd: acp: acp-legacy: Add DMIC dai link support for Renoir
In reply to Ajit Kumar PandeyAdd DMIC related dai link for pdm-dmic dai on Renoir platform with generic dmic codec dai.
--- sound/soc/amd/acp/acp-legacy-mach.c | 4 ++-- sound/soc/amd/acp/acp-mach-common.c | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-)
sound/soc/amd/acp/acp-legacy-mach.c +2 -2
@@ -23,10 +23,10 @@static struct acp_card_drvdata rt5682_rt1019_data = { .hs_cpu_id =I2S_SP , .amp_cpu_id =I2S_SP , - .dmic_cpu_id =NONE , + .dmic_cpu_id =DMIC , .hs_codec_id =RT5682 , .amp_codec_id =RT1019 , - .dmic_codec_id =NONE , + .dmic_codec_id =DMIC , .gpio_spkr_en =EN_SPKR_GPIO_GB , };
sound/soc/amd/acp/acp-mach-common.c +15 -0
@@ -438,6 +438,8 @@ SND_SOC_DAILINK_DEF(sof_sp, DAILINK_COMP_ARRAY(COMP_CPU("acp-sof-sp")));SND_SOC_DAILINK_DEF (sof_dmic,DAILINK_COMP_ARRAY (COMP_CPU ("acp-sof-dmic" ))); +SND_SOC_DAILINK_DEF (pdm_dmic, +DAILINK_COMP_ARRAY (COMP_CPU ("acp-pdm-dmic" )));int acp_sofdsp_dai_links_create (struct snd_soc_card *card) {
@@ -613,6 +615,19 @@ int acp_legacy_dai_links_create(struct snd_soc_card *card) links[i].ops = &acp_card_maxim_ops; links[i].init = acp_card_maxim_init; } + i++; + } + +if (drv_data->dmic_cpu_id ==DMIC ) { + links[i].name ="acp-dmic-codec" ; + links[i].id =DMIC_BE_ID ; + links[i].codecs = dmic_codec; + links[i].num_codecs =ARRAY_SIZE (dmic_codec); + links[i].cpus = pdm_dmic; + links[i].num_cpus =ARRAY_SIZE (pdm_dmic); + links[i].platforms = platform_component; + links[i].num_platforms =ARRAY_SIZE (platform_component); + links[i].dpcm_capture =1 ; } card->dai_link = links;
Signature · 1 line
2.25.1
PATCH v2 6/6 ASoC: amd: renoir: Add check for acp configuration flags.
In reply to Ajit Kumar PandeyWe have SOF and generic ACP support enabled for Renoir platforms on some machines. Since we have same PCI id used for probing, add check for machine configuration flag to avoid conflict with newer pci drivers. Such machine flag has been initialized via dmi match on few Chrome machines. If no flag is specified probe and register older platform device.
--- sound/soc/amd/renoir/rn-pci-acp3x.c | 7 ++++++- sound/soc/amd/renoir/rn_acp3x.h | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-)
sound/soc/amd/renoir/rn-pci-acp3x.c +6 -1
@@ -212,10 +212,15 @@ static int snd_rn_acp_probe(struct pci_dev *pci,acpi_integer dmic_status;#endif const struct dmi_system_id *dmi_id; -unsigned int irqflags; +unsigned int irqflags, flag;int ret, index;u32 addr; +/* Return if acp config flag is defined */ + flag =snd_amd_acp_find_config (pci); +if (flag) +return -ENODEV ; +/* Renoir device check */ if (pci->revision !=0x01 )return -ENODEV ;
sound/soc/amd/renoir/rn_acp3x.h +3 -0
@@ -88,3 +88,6 @@ static inline void rn_writel(u32 val, void __iomem *base_addr) {writel (val, base_addr -ACP_PHY_BASE_ADDRESS ); } + +/* Machine configuration */ +int snd_amd_acp_find_config (struct pci_dev *pci);
Signature · 1 line
2.25.1
Re: [PATCH v2 1/6] ASoC: amd: acp: Add generic support for PDM controller on ACP
In reply to Ajit Kumar Pandeycouple of nit-picks:
sound/soc/amd/acp/acp-pdm.c line 6
Quoted 12 lines
sound/soc/amd/acp/acp-pdm.c new file +6
-0@@ -0,0 +1,181 @@ +// 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.
2022?
Quoted 7 lines
sound/soc/amd/acp/acp-pdm.c new file +7
-0+// +// Authors: Ajit Kumar Pandey <[email protected]> +// Vijendar Mukunda <[email protected]> +// + +/* +* Generic Hardware interface for ACP Audio PDM controller
sound/soc/amd/acp/acp-pdm.c line 23
Quoted 10 lines
sound/soc/amd/acp/acp-pdm.c new file +10
-0+*/ + +#include <linux/platform_device.h> +#include <linux/module.h> +#include <linux/err.h> +#include <linux/io.h> +#include <sound/pcm_params.h> +#include <sound/soc.h> +#include <sound/soc-dai.h> +#include <linux/dma-mapping.h>
alphabetical order?
Quoted 28 lines
sound/soc/amd/acp/acp-pdm.c new file +28
-0+ +#include "amd.h" + +#define DRV_NAME "acp-pdm" + +#define PDM_DMA_STAT 0x10 +#define PDM_DMA_INTR_MASK 0x10000 +#define PDM_DEC_64 0x2 +#define PDM_CLK_FREQ_MASK 0x07 +#define PDM_MISC_CTRL_MASK 0x10 +#define PDM_ENABLE 0x01 +#define PDM_DISABLE 0x00 +#define DMA_EN_MASK 0x02 +#define DELAY_US 5 +#define PDM_TIMEOUT 1000 + +static int acp_dmic_dai_trigger (struct snd_pcm_substream *substream, +int cmd,struct snd_soc_dai *dai) +{ +struct acp_stream *stream = substream->runtime->private_data; +struct device *dev = dai->component->dev; +struct acp_dev_data *adata =dev_get_drvdata (dev); +u32 physical_addr, size_dmic, period_bytes; +unsigned int dma_enable; +int ret =0 ; + + period_bytes =frames_to_bytes (substream->runtime, + substream->runtime->period_size);
sound/soc/amd/acp/acp-pdm.c line 61
Quoted 10 lines
sound/soc/amd/acp/acp-pdm.c new file +10
-0+ size_dmic =frames_to_bytes (substream->runtime, + substream->runtime->buffer_size); + + physical_addr = stream->reg_offset +MEM_WINDOW_START ; + +/* Init DMIC Ring buffer */ +writel (physical_addr, adata->acp_base +ACP_WOV_RX_RINGBUFADDR ); +writel (size_dmic, adata->acp_base +ACP_WOV_RX_RINGBUFSIZE ); +writel (period_bytes, adata->acp_base +ACP_WOV_RX_INTR_WATERMARK_SIZE ); +writel (0x01 , adata->acp_base +ACPAXI2AXI_ATU_CTRL );
could this be done in a .prepare step?
Quoted 18 lines
sound/soc/amd/acp/acp-pdm.c new file +18
-0+ +switch (cmd) { +case SNDRV_PCM_TRIGGER_START : +case SNDRV_PCM_TRIGGER_RESUME : +case SNDRV_PCM_TRIGGER_PAUSE_RELEASE : + dma_enable =readl (adata->acp_base +ACP_WOV_PDM_DMA_ENABLE ); +if (!(dma_enable &DMA_EN_MASK )) { +writel (PDM_ENABLE , adata->acp_base +ACP_WOV_PDM_ENABLE ); +writel (PDM_ENABLE , adata->acp_base +ACP_WOV_PDM_DMA_ENABLE ); + } + + ret =readl_poll_timeout_atomic (adata->acp_base +ACP_WOV_PDM_DMA_ENABLE , + dma_enable, (dma_enable &DMA_EN_MASK ), +DELAY_US ,PDM_TIMEOUT ); +break ; +case SNDRV_PCM_TRIGGER_STOP : +case SNDRV_PCM_TRIGGER_SUSPEND : +case SNDRV_PCM_TRIGGER_PAUSE_PUSH :
sound/soc/amd/acp/acp-pdm.c line 89
Quoted 10 lines
sound/soc/amd/acp/acp-pdm.c new file +10
-0+ dma_enable =readl (adata->acp_base +ACP_WOV_PDM_DMA_ENABLE ); +if ((dma_enable &DMA_EN_MASK )) { +writel (PDM_DISABLE , adata->acp_base +ACP_WOV_PDM_ENABLE ); +writel (PDM_DISABLE , adata->acp_base +ACP_WOV_PDM_DMA_ENABLE ); + + } + + ret =readl_poll_timeout_atomic (adata->acp_base +ACP_WOV_PDM_DMA_ENABLE , + dma_enable, !(dma_enable &DMA_EN_MASK ), +DELAY_US ,PDM_TIMEOUT );
is the _atomic needed?
Quoted 11 lines
sound/soc/amd/acp/acp-pdm.c new file +11
-0+break ; +default : + ret = -EINVAL ; +break ; + } + +return ret; +} + +static int acp_dmic_hwparams (struct snd_pcm_substream *substream, +struct snd_pcm_hw_params *hwparams,struct snd_soc_dai *dai)
sound/soc/amd/acp/acp-pdm.c line 110
Quoted 10 lines
sound/soc/amd/acp/acp-pdm.c new file +10
-0+{ +struct device *dev = dai->component->dev; +struct acp_dev_data *adata =dev_get_drvdata (dev); +unsigned int dmic_ctrl, channels, ch_mask; + +/* Enable default DMIC clk */ +writel (PDM_CLK_FREQ_MASK , adata->acp_base +ACP_WOV_CLK_CTRL ); + dmic_ctrl =readl (adata->acp_base +ACP_WOV_MISC_CTRL ); + dmic_ctrl |=PDM_MISC_CTRL_MASK ; +writel (dmic_ctrl, adata->acp_base +ACP_WOV_MISC_CTRL );
.hw_params can be called multiple times, should this clock handling be done in a .prepare step?
Or alternatively in .startup - this doesn't seem to depend on hardware parameters?
Quoted 19 lines
sound/soc/amd/acp/acp-pdm.c new file +19
-0+ + channels =params_channels (hwparams); +switch (channels) { +case 2 : + ch_mask =0 ; +break ; +case 4 : + ch_mask =1 ; +break ; +case 6 : + ch_mask =2 ; +break ; +default : +dev_err (dev,"Invalid channels %d\n" , channels); +return -EINVAL ; + } + +if (params_format (hwparams) !=SNDRV_PCM_FORMAT_S32_LE ) { +dev_err (dai->dev,"Invalid format:%d\n" ,params_format (hwparams));
sound/soc/amd/acp/acp-pdm.c line 180
Quoted 10 lines
sound/soc/amd/acp/acp-pdm.c new file +9
-0+return -EINVAL ; + } + +writel (ch_mask, adata->acp_base +ACP_WOV_PDM_NO_OF_CHANNELS ); +writel (PDM_DEC_64 , adata->acp_base +ACP_WOV_PDM_DECIMATION_FACTOR ); + +return 0 ; +} +MODULE_LICENSE ("GPL v2" );
"GPL" is enough
Re: [PATCH v2 3/6] ASoC: amd: acp: Add generic PCI driver module for ACP device
In reply to Ajit Kumar Pandeysound/soc/amd/acp/acp-pci.c line 6
Quoted 13 lines
sound/soc/amd/acp/acp-pci.c new file +6
-0@@ -0,0 +1,160 @@ +// 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.
2022?
Re: [PATCH v2 5/6] ASoC: amd: acp: acp-legacy: Add DMIC dai link support for Renoir
In reply to Ajit Kumar PandeyQuoted 8 lines
sound/soc/amd/acp/acp-legacy-mach.c +0
-0
sound/soc/amd/acp/acp-legacy-mach.c line 29
Quoted 9 lines
sound/soc/amd/acp/acp-legacy-mach.c +2
-2@@ -23,10 +23,10 @@static struct acp_card_drvdata rt5682_rt1019_data = { .hs_cpu_id =I2S_SP , .amp_cpu_id =I2S_SP , - .dmic_cpu_id =NONE , + .dmic_cpu_id =DMIC , .hs_codec_id =RT5682 , .amp_codec_id =RT1019 , - .dmic_codec_id =NONE , + .dmic_codec_id =DMIC ,
this definition is not used?
Quoted 37 lines
sound/soc/amd/acp/acp-legacy-mach.c +0
-0.gpio_spkr_en = EN_SPKR_GPIO_GB, };sound/soc/amd/acp/acp-mach-common.c +15
-0@@ -438,6 +438,8 @@ SND_SOC_DAILINK_DEF(sof_sp, DAILINK_COMP_ARRAY(COMP_CPU("acp-sof-sp")));SND_SOC_DAILINK_DEF (sof_dmic,DAILINK_COMP_ARRAY (COMP_CPU ("acp-sof-dmic" ))); +SND_SOC_DAILINK_DEF (pdm_dmic, +DAILINK_COMP_ARRAY (COMP_CPU ("acp-pdm-dmic" )));int acp_sofdsp_dai_links_create (struct snd_soc_card *card) {@@ -613,6 +615,19 @@ int acp_legacy_dai_links_create(struct snd_soc_card *card) links[i].ops = &acp_card_maxim_ops; links[i].init = acp_card_maxim_init; } + i++; + } + +if (drv_data->dmic_cpu_id ==DMIC ) { + links[i].name ="acp-dmic-codec" ; + links[i].id =DMIC_BE_ID ; + links[i].codecs = dmic_codec; + links[i].num_codecs =ARRAY_SIZE (dmic_codec); + links[i].cpus = pdm_dmic; + links[i].num_cpus =ARRAY_SIZE (pdm_dmic); + links[i].platforms = platform_component; + links[i].num_platforms =ARRAY_SIZE (platform_component); + links[i].dpcm_capture =1 ; } card->dai_link = links;
Re: [PATCH v2 4/6] ASoC: amd: acp: Add ACP init()/deinit() callback for Renoir.
In reply to Ajit Kumar PandeyQuoted 48 lines · Ajit Kumar Pandey
ACP hardware has PGFSM control registers that can be configured to power On/Off the ACP IP block. Add acp init()/de_init() callbacks in renoir platform driver probe()/remove() respectively to power on and off ACP IP block on ACP3X device.
Signed-off-by Ajit Kumar Pandey <[email protected]>--- sound/soc/amd/acp/acp-renoir.c | 170 +++++++++++++++++++++++++++ sound/soc/amd/acp/chip_offset_byte.h | 6 + 2 files changed, 176 insertions(+)sound/soc/amd/acp/acp-renoir.c +22
-0@@ -25,6 +25,19 @@#define DRV_NAME "acp_asoc_renoir" +#define ACP_SOFT_RST_DONE_MASK 0x00010001 + +#define ACP_PWR_ON_MASK 0x01 +#define ACP_PWR_OFF_MASK 0x00 +#define ACP_PGFSM_STAT_MASK 0x03 +#define ACP_POWERED_ON 0x00 +#define ACP_PWR_ON_IN_PROGRESS 0x01 +#define ACP_POWERED_OFF 0x02 + + +#define ACP_ERROR_MASK 0x20000000 +#define ACP_EXT_INTR_STAT_CLEAR_MASK 0xFFFFFFFF +static struct snd_soc_acpi_codecs amp_rt1019 = { .num_codecs =1 , .codecs = {"10EC1019" }@@ -112,11 +125,154 @@ static struct snd_soc_dai_driver acp_renoir_dai[] = { }, }; +static int acp3x_power_on (void __iomem *base) +{ +u32 val; +int timeout =0 ; + + val =readl (base +ACP_PGFSM_STATUS ); + +if (val ==ACP_POWERED_ON ) +return 0 ;
sound/soc/amd/acp/acp-renoir.c static struct snd_soc_dai_driver acp_renoir_dai[] = { · line 146
Quoted 10 lines
sound/soc/amd/acp/acp-renoir.c +10
-0+ +if ((val &ACP_PGFSM_STAT_MASK ) !=ACP_PWR_ON_IN_PROGRESS ) +writel (ACP_PWR_ON_MASK , base +ACP_PGFSM_CONTROL ); + +while (++timeout <500 ) { + val =readl (base +ACP_PGFSM_STATUS ); +if (!val) +return 0 ; +udelay (1 ); + }
Can this while loop perhaps be replaced with readl_poll_timeout? Similarly for cases below?
Quoted 170 lines
sound/soc/amd/acp/acp-renoir.c +138
-0+ +return -ETIMEDOUT ; +} + +static int acp3x_power_off (void __iomem *base) +{ +u32 val; +int timeout =0 ; + +writel (ACP_PWR_OFF_MASK , base +ACP_PGFSM_CONTROL ); + +while (++timeout <500 ) { + val =readl (base +ACP_PGFSM_STATUS ); +if ((val &ACP_PGFSM_STAT_MASK ) ==ACP_POWERED_OFF ) +return 0 ; +udelay (1 ); + } + +return -ETIMEDOUT ; +} + +static int acp3x_reset (void __iomem *base) +{ +u32 val; +int timeout =0 ; + +writel (1 , base +ACP_SOFT_RESET ); + +while (++timeout <500 ) { + val =readl (base +ACP_SOFT_RESET ); +if (val &ACP_SOFT_RST_DONE_MASK ) +break ; +cpu_relax (); + } + +writel (0 , base +ACP_SOFT_RESET ); + + timeout =0 ; +while (++timeout <500 ) { + val =readl (base +ACP_SOFT_RESET ); +if (!val) +return 0 ; +cpu_relax (); + } + +return -ETIMEDOUT ; +} + +static void acp3x_enable_interrupts (void __iomem *base) +{ +u32 ext_intr_ctrl; + +writel (0x01 , base +ACP_EXTERNAL_INTR_ENB ); + ext_intr_ctrl =readl (base +ACP_EXTERNAL_INTR_CNTL ); + ext_intr_ctrl |=ACP_ERROR_MASK ; +writel (ext_intr_ctrl, base +ACP_EXTERNAL_INTR_CNTL ); +} + +static void acp3x_disable_interrupts (void __iomem *base) +{ +writel (ACP_EXT_INTR_STAT_CLEAR_MASK , base +ACP_EXTERNAL_INTR_STAT ); +writel (0x00 , base +ACP_EXTERNAL_INTR_ENB ); +} + +static int rn_acp_init (void __iomem *base) +{ +int ret; + +/* power on */ + ret =acp3x_power_on (base); +if (ret) +return ret; + +writel (0x01 , base +ACP_CONTROL ); + +/* Reset */ + ret =acp3x_reset (base); +if (ret) +return ret; + +acp3x_enable_interrupts (base); + +return 0 ; +} + +static int rn_acp_deinit (void __iomem *base) +{ +int ret =0 ; + +acp3x_disable_interrupts (base); + +/* Reset */ + ret =acp3x_reset (base); +if (ret) +return ret; + +writel (0x00 , base +ACP_CONTROL ); + +/* power off */ + ret =acp3x_power_off (base); +if (ret) +return ret; + +return 0 ; +}static int renoir_audio_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev; +struct acp_chip_info *chip;struct acp_dev_data *adata;struct resource *res; +int ret; + + chip =dev_get_platdata (&pdev->dev); +if (!chip || !chip->base) { +dev_err (&pdev->dev,"ACP chip data is NULL\n" ); +return -ENODEV ; + } + +if (chip->acp_rev !=ACP3X_DEV ) { +dev_err (&pdev->dev,"Un-supported ACP Revision %d\n" , chip->acp_rev); +return -ENODEV ; + } + + ret =rn_acp_init (chip->base); +if (ret) { +dev_err (&pdev->dev,"ACP Init failed\n" ); +return -EINVAL ; + } adata =devm_kzalloc (dev,sizeof (struct acp_dev_data ),GFP_KERNEL );if (!adata)@@ -155,6 +311,20 @@ static int renoir_audio_probe(struct platform_device *pdev)static int renoir_audio_remove (struct platform_device *pdev) {struct device *dev = &pdev->dev; +struct acp_chip_info *chip; +int ret; + + chip =dev_get_platdata (&pdev->dev); +if (!chip || !chip->base) { +dev_err (&pdev->dev,"ACP chip data is NULL\n" ); +return -ENODEV ; + } + + ret =rn_acp_deinit (chip->base); +if (ret) { +dev_err (&pdev->dev,"ACP de-init Failed\n" ); +return -EINVAL ; + }acp_platform_unregister (dev);return 0 ;sound/soc/amd/acp/chip_offset_byte.h +6
-0@@ -14,6 +14,12 @@#define ACPAXI2AXI_ATU_CTRL 0xC40#define ACPAXI2AXI_ATU_PAGE_SIZE_GRP_5 0xC20#define ACPAXI2AXI_ATU_BASE_ADDR_GRP_5 0xC24 + +#define ACP_PGFSM_CONTROL 0x141C +#define ACP_PGFSM_STATUS 0x1420 +#define ACP_SOFT_RESET 0x1000 +#define ACP_CONTROL 0x1004 +#define ACP_EXTERNAL_INTR_ENB 0x1800#define ACP_EXTERNAL_INTR_CNTL 0x1804#define ACP_EXTERNAL_INTR_STAT 0x1808
kernel test robot
build botRe: [PATCH v2 6/6] ASoC: amd: renoir: Add check for acp configuration flags.
In reply to Ajit Kumar PandeyThank you for the patch! Yet something to improve:
Hi Ajit,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on broonie-sound/for-next]
[also build test ERROR on next-20220116]
[cannot apply to v5.16]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Ajit-Kumar-Pandey/ASOC-amd-acp-Add-generic-PDM-and-PCI-driver-support-for-ACP/20220114-003620 base: https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next config: x86_64-randconfig-a015-20220109 (https://download.01.org/0day-ci/archive/20220117/202201170622.pgphaezk-lkp(a)intel.com/config) compiler: gcc-9 (Debian 9.3.0-22) 9.3.0 reproduce (this is a W=1 build): # https://github.com/0day-ci/linux/commit/bc740a222d4191f55c5f7a197e919e94a5f63419 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Ajit-Kumar-Pandey/ASOC-amd-acp-Add-generic-PDM-and-PCI-driver-support-for-ACP/20220114-003620 git checkout bc740a222d4191f55c5f7a197e919e94a5f63419 # save the config file to linux build tree mkdir build_dir make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>, old ones prefixed by <<):
>> ERROR: modpost: "snd_amd_acp_find_config" [sound/soc/amd/renoir/snd-rn-pci-acp3x.ko] undefined!
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botRe: [PATCH v2 6/6] ASoC: amd: renoir: Add check for acp configuration flags.
In reply to Ajit Kumar PandeyThank you for the patch! Yet something to improve:
Hi Ajit,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on broonie-sound/for-next]
[also build test ERROR on next-20220117]
[cannot apply to v5.16]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Ajit-Kumar-Pandey/ASOC-amd-acp-Add-generic-PDM-and-PCI-driver-support-for-ACP/20220114-003620 base: https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next config: x86_64-randconfig-r014-20211215 (https://download.01.org/0day-ci/archive/20220117/202201171356.6vrZs5rw-lkp(a)intel.com/config) compiler: gcc-9 (Debian 9.3.0-22) 9.3.0 reproduce (this is a W=1 build): # https://github.com/0day-ci/linux/commit/bc740a222d4191f55c5f7a197e919e94a5f63419 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Ajit-Kumar-Pandey/ASOC-amd-acp-Add-generic-PDM-and-PCI-driver-support-for-ACP/20220114-003620 git checkout bc740a222d4191f55c5f7a197e919e94a5f63419 # save the config file to linux build tree mkdir build_dir make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
vmlinux.o: warning: objtool: do_machine_check()+0xb08: call to queue_task_work() leaves .noinstr.text section vmlinux.o: warning: objtool: enter_from_user_mode()+0x52: call to on_thread_stack() leaves .noinstr.text section vmlinux.o: warning: objtool: syscall_enter_from_user_mode()+0x59: call to on_thread_stack() leaves .noinstr.text section vmlinux.o: warning: objtool: syscall_enter_from_user_mode_prepare()+0x52: call to on_thread_stack() leaves .noinstr.text section vmlinux.o: warning: objtool: irqentry_enter_from_user_mode()+0x52: call to on_thread_stack() leaves .noinstr.text section
ld: sound/soc/amd/renoir/rn-pci-acp3x.o: in function `snd_rn_acp_probe':
>> sound/soc/amd/renoir/rn-pci-acp3x.c:220: undefined reference to `snd_amd_acp_find_config'
vim +220 sound/soc/amd/renoir/rn-pci-acp3x.c
204
205 static int snd_rn_acp_probe(struct pci_dev *pci,
206 const struct pci_device_id *pci_id)
207 {
208 struct acp_dev_data *adata;
209 struct platform_device_info pdevinfo[ACP_DEVS];
210 #if defined(CONFIG_ACPI)
211 acpi_handle handle;
212 acpi_integer dmic_status;
213 #endif
214 const struct dmi_system_id *dmi_id;
215 unsigned int irqflags, flag;
216 int ret, index;
217 u32 addr;
218
219 /* Return if acp config flag is defined */
> 220 flag = snd_amd_acp_find_config(pci);
221 if (flag)
222 return -ENODEV;
223
224 /* Renoir device check */
225 if (pci->revision != 0x01)
226 return -ENODEV;
227
228 if (pci_enable_device(pci)) {
229 dev_err(&pci->dev, "pci_enable_device failed\n");
230 return -ENODEV;
231 }
232
233 ret = pci_request_regions(pci, "AMD ACP3x audio");
234 if (ret < 0) {
235 dev_err(&pci->dev, "pci_request_regions failed\n");
236 goto disable_pci;
237 }
238
239 adata = devm_kzalloc(&pci->dev, sizeof(struct acp_dev_data),
240 GFP_KERNEL);
241 if (!adata) {
242 ret = -ENOMEM;
243 goto release_regions;
244 }
245
246 /* check for msi interrupt support */
247 ret = pci_enable_msi(pci);
248 if (ret)
249 /* msi is not enabled */
250 irqflags = IRQF_SHARED;
251 else
252 /* msi is enabled */
253 irqflags = 0;
254
255 addr = pci_resource_start(pci, 0);
256 adata->acp_base = devm_ioremap(&pci->dev, addr,
257 pci_resource_len(pci, 0));
258 if (!adata->acp_base) {
259 ret = -ENOMEM;
260 goto disable_msi;
261 }
262 pci_set_master(pci);
263 pci_set_drvdata(pci, adata);
264 ret = rn_acp_init(adata->acp_base);
265 if (ret)
266 goto disable_msi;
267
268 if (!dmic_acpi_check) {
269 ret = -ENODEV;
270 goto de_init;
271 } else if (dmic_acpi_check == ACP_DMIC_AUTO) {
272 #if defined(CONFIG_ACPI)
273 handle = ACPI_HANDLE(&pci->dev);
274 ret = acpi_evaluate_integer(handle, "_WOV", NULL, &dmic_status);
275 if (ACPI_FAILURE(ret)) {
276 ret = -ENODEV;
277 goto de_init;
278 }
279 if (!dmic_status) {
280 ret = -ENODEV;
281 goto de_init;
282 }
283 #endif
284 dmi_id = dmi_first_match(rn_acp_quirk_table);
285 if (dmi_id && !dmi_id->driver_data) {
286 dev_info(&pci->dev, "ACPI settings override using DMI (ACP mic is not present)");
287 ret = -ENODEV;
288 goto de_init;
289 }
290 }
291
292 adata->res = devm_kzalloc(&pci->dev,
293 sizeof(struct resource) * 2,
294 GFP_KERNEL);
295 if (!adata->res) {
296 ret = -ENOMEM;
297 goto de_init;
298 }
299
300 adata->res[0].name = "acp_pdm_iomem";
301 adata->res[0].flags = IORESOURCE_MEM;
302 adata->res[0].start = addr;
303 adata->res[0].end = addr + (ACP_REG_END - ACP_REG_START);
304 adata->res[1].name = "acp_pdm_irq";
305 adata->res[1].flags = IORESOURCE_IRQ;
306 adata->res[1].start = pci->irq;
307 adata->res[1].end = pci->irq;
308
309 memset(&pdevinfo, 0, sizeof(pdevinfo));
310 pdevinfo[0].name = "acp_rn_pdm_dma";
311 pdevinfo[0].id = 0;
312 pdevinfo[0].parent = &pci->dev;
313 pdevinfo[0].num_res = 2;
314 pdevinfo[0].res = adata->res;
315 pdevinfo[0].data = &irqflags;
316 pdevinfo[0].size_data = sizeof(irqflags);
317
318 pdevinfo[1].name = "dmic-codec";
319 pdevinfo[1].id = 0;
320 pdevinfo[1].parent = &pci->dev;
321 pdevinfo[2].name = "acp_pdm_mach";
322 pdevinfo[2].id = 0;
323 pdevinfo[2].parent = &pci->dev;
324 for (index = 0; index < ACP_DEVS; index++) {
325 adata->pdev[index] =
326 platform_device_register_full(&pdevinfo[index]);
327 if (IS_ERR(adata->pdev[index])) {
328 dev_err(&pci->dev, "cannot register %s device\n",
329 pdevinfo[index].name);
330 ret = PTR_ERR(adata->pdev[index]);
331 goto unregister_devs;
332 }
333 }
334 pm_runtime_set_autosuspend_delay(&pci->dev, ACP_SUSPEND_DELAY_MS);
335 pm_runtime_use_autosuspend(&pci->dev);
336 pm_runtime_put_noidle(&pci->dev);
337 pm_runtime_allow(&pci->dev);
338 return 0;
339
340 unregister_devs:
341 for (index = 0; index < ACP_DEVS; index++)
342 platform_device_unregister(adata->pdev[index]);
343 de_init:
344 if (rn_acp_deinit(adata->acp_base))
345 dev_err(&pci->dev, "ACP de-init failed\n");
346 disable_msi:
347 pci_disable_msi(pci);
348 release_regions:
349 pci_release_regions(pci);
350 disable_pci:
351 pci_disable_device(pci);
352
353 return ret;
354 }
355
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Re: [PATCH v2 1/6] ASoC: amd: acp: Add generic support for PDM controller on ACP
In reply to Pierre-Louis BossartQuoted 168 lines · Pierre-Louis Bossart
[CAUTION: External Email]
couple of nit-picks:
sound/soc/amd/acp/acp-pdm.c line 6
Quoted 12 lines
sound/soc/amd/acp/acp-pdm.c new file +6
-0@@ -0,0 +1,181 @@ +// 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. 2022?
Quoted 7 lines
sound/soc/amd/acp/acp-pdm.c new file +7
-0+// +// Authors: Ajit Kumar Pandey <[email protected]> +// Vijendar Mukunda <[email protected]> +// + +/* +* Generic Hardware interface for ACP Audio PDM controller sound/soc/amd/acp/acp-pdm.c line 23
Quoted 10 lines
sound/soc/amd/acp/acp-pdm.c new file +10
-0+*/ + +#include <linux/platform_device.h> +#include <linux/module.h> +#include <linux/err.h> +#include <linux/io.h> +#include <sound/pcm_params.h> +#include <sound/soc.h> +#include <sound/soc-dai.h> +#include <linux/dma-mapping.h> alphabetical order?
Quoted 28 lines
sound/soc/amd/acp/acp-pdm.c new file +28
-0+ +#include "amd.h" + +#define DRV_NAME "acp-pdm" + +#define PDM_DMA_STAT 0x10 +#define PDM_DMA_INTR_MASK 0x10000 +#define PDM_DEC_64 0x2 +#define PDM_CLK_FREQ_MASK 0x07 +#define PDM_MISC_CTRL_MASK 0x10 +#define PDM_ENABLE 0x01 +#define PDM_DISABLE 0x00 +#define DMA_EN_MASK 0x02 +#define DELAY_US 5 +#define PDM_TIMEOUT 1000 + +static int acp_dmic_dai_trigger (struct snd_pcm_substream *substream, +int cmd,struct snd_soc_dai *dai) +{ +struct acp_stream *stream = substream->runtime->private_data; +struct device *dev = dai->component->dev; +struct acp_dev_data *adata =dev_get_drvdata (dev); +u32 physical_addr, size_dmic, period_bytes; +unsigned int dma_enable; +int ret =0 ; + + period_bytes =frames_to_bytes (substream->runtime, + substream->runtime->period_size);sound/soc/amd/acp/acp-pdm.c line 61
Quoted 10 lines
sound/soc/amd/acp/acp-pdm.c new file +10
-0+ size_dmic =frames_to_bytes (substream->runtime, + substream->runtime->buffer_size); + + physical_addr = stream->reg_offset +MEM_WINDOW_START ; + +/* Init DMIC Ring buffer */ +writel (physical_addr, adata->acp_base +ACP_WOV_RX_RINGBUFADDR ); +writel (size_dmic, adata->acp_base +ACP_WOV_RX_RINGBUFSIZE ); +writel (period_bytes, adata->acp_base +ACP_WOV_RX_INTR_WATERMARK_SIZE ); +writel (0x01 , adata->acp_base +ACPAXI2AXI_ATU_CTRL );could this be done in a .prepare step?
Quoted 18 lines
sound/soc/amd/acp/acp-pdm.c new file +18
-0+ +switch (cmd) { +case SNDRV_PCM_TRIGGER_START : +case SNDRV_PCM_TRIGGER_RESUME : +case SNDRV_PCM_TRIGGER_PAUSE_RELEASE : + dma_enable =readl (adata->acp_base +ACP_WOV_PDM_DMA_ENABLE ); +if (!(dma_enable &DMA_EN_MASK )) { +writel (PDM_ENABLE , adata->acp_base +ACP_WOV_PDM_ENABLE ); +writel (PDM_ENABLE , adata->acp_base +ACP_WOV_PDM_DMA_ENABLE ); + } + + ret =readl_poll_timeout_atomic (adata->acp_base +ACP_WOV_PDM_DMA_ENABLE , + dma_enable, (dma_enable &DMA_EN_MASK ), +DELAY_US ,PDM_TIMEOUT ); +break ; +case SNDRV_PCM_TRIGGER_STOP : +case SNDRV_PCM_TRIGGER_SUSPEND : +case SNDRV_PCM_TRIGGER_PAUSE_PUSH :sound/soc/amd/acp/acp-pdm.c line 89
Quoted 10 lines
sound/soc/amd/acp/acp-pdm.c new file +10
-0+ dma_enable =readl (adata->acp_base +ACP_WOV_PDM_DMA_ENABLE ); +if ((dma_enable &DMA_EN_MASK )) { +writel (PDM_DISABLE , adata->acp_base +ACP_WOV_PDM_ENABLE ); +writel (PDM_DISABLE , adata->acp_base +ACP_WOV_PDM_DMA_ENABLE ); + + } + + ret =readl_poll_timeout_atomic (adata->acp_base +ACP_WOV_PDM_DMA_ENABLE , + dma_enable, !(dma_enable &DMA_EN_MASK ), +DELAY_US ,PDM_TIMEOUT );is the
_atomicneeded?Quoted 11 lines
sound/soc/amd/acp/acp-pdm.c new file +11
-0+break ; +default : + ret = -EINVAL ; +break ; + } + +return ret; +} + +static int acp_dmic_hwparams (struct snd_pcm_substream *substream, +struct snd_pcm_hw_params *hwparams,struct snd_soc_dai *dai)sound/soc/amd/acp/acp-pdm.c line 110
Quoted 10 lines
sound/soc/amd/acp/acp-pdm.c new file +10
-0+{ +struct device *dev = dai->component->dev; +struct acp_dev_data *adata =dev_get_drvdata (dev); +unsigned int dmic_ctrl, channels, ch_mask; + +/* Enable default DMIC clk */ +writel (PDM_CLK_FREQ_MASK , adata->acp_base +ACP_WOV_CLK_CTRL ); + dmic_ctrl =readl (adata->acp_base +ACP_WOV_MISC_CTRL ); + dmic_ctrl |=PDM_MISC_CTRL_MASK ; +writel (dmic_ctrl, adata->acp_base +ACP_WOV_MISC_CTRL );.hw_params can be called multiple times, should this clock handling be done in a .prepare step?
Or alternatively in .startup - this doesn't seem to depend on hardware parameters?
Quoted 27 lines
sound/soc/amd/acp/acp-pdm.c new file +27
-0+ + channels =params_channels (hwparams); +switch (channels) { +case 2 : + ch_mask =0 ; +break ; +case 4 : + ch_mask =1 ; +break ; +case 6 : + ch_mask =2 ; +break ; +default : +dev_err (dev,"Invalid channels %d\n" , channels); +return -EINVAL ; + } + +if (params_format (hwparams) !=SNDRV_PCM_FORMAT_S32_LE ) { +dev_err (dai->dev,"Invalid format:%d\n" ,params_format (hwparams)); +return -EINVAL ; + } + +writel (ch_mask, adata->acp_base +ACP_WOV_PDM_NO_OF_CHANNELS ); +writel (PDM_DEC_64 , adata->acp_base +ACP_WOV_PDM_DECIMATION_FACTOR ); + +return 0 ; +}
Quoted 5 lines
sound/soc/amd/acp/acp-pdm.c line 180
Quoted 1 line
sound/soc/amd/acp/acp-pdm.c new file +1
-0+MODULE_LICENSE ("GPL v2" );"GPL" is enough
Thanks, will try to adopt commnets in v3 patch chain
Re: [PATCH v2 4/6] ASoC: amd: acp: Add ACP init()/deinit() callback for Renoir.
In reply to Amadeusz SławińskiQuoted 231 lines · Amadeusz Sławiński
[CAUTION: External Email]
Quoted 49 lines · Ajit Kumar Pandey
ACP hardware has PGFSM control registers that can be configured to power On/Off the ACP IP block. Add acp init()/de_init() callbacks in renoir platform driver probe()/remove() respectively to power on and off ACP IP block on ACP3X device.
Signed-off-by Ajit Kumar Pandey <[email protected]>---
sound/soc/amd/acp/acp-renoir.c | 170 +++++++++++++++++++++++++++sound/soc/amd/acp/chip_offset_byte.h| 6 +2 files changed, 176 insertions(+)sound/soc/amd/acp/acp-renoir.c +22
-0@@ -25,6 +25,19 @@ #define DRV_NAME "acp_asoc_renoir" +#define ACP_SOFT_RST_DONE_MASK 0x00010001 + +#define ACP_PWR_ON_MASK 0x01 +#define ACP_PWR_OFF_MASK 0x00 +#define ACP_PGFSM_STAT_MASK 0x03 +#define ACP_POWERED_ON 0x00 +#define ACP_PWR_ON_IN_PROGRESS 0x01 +#define ACP_POWERED_OFF 0x02 + + +#define ACP_ERROR_MASK 0x20000000 +#define ACP_EXT_INTR_STAT_CLEAR_MASK 0xFFFFFFFF + static struct snd_soc_acpi_codecs amp_rt1019 = { .num_codecs = 1, .codecs = {"10EC1019"}@@ -112,11 +125,154 @@ static struct snd_soc_dai_driver acp_renoir_dai[] = { }, }; +static int acp3x_power_on (void __iomem *base) +{ + u32 val; + int timeout = 0; + + val = readl(base + ACP_PGFSM_STATUS); + + if (val == ACP_POWERED_ON) + return 0;sound/soc/amd/acp/acp-renoir.c static struct snd_soc_dai_driver · line 147
Quoted 10 lines
sound/soc/amd/acp/acp-renoir.c +10
-0+ + if ((val & ACP_PGFSM_STAT_MASK) != ACP_PWR_ON_IN_PROGRESS) + writel(ACP_PWR_ON_MASK, base + ACP_PGFSM_CONTROL); + + while (++timeout < 500) { + val = readl(base + ACP_PGFSM_STATUS); + if (!val) + return 0; + udelay(1); + }Can this while loop perhaps be replaced with
readl_poll_timeout? Similarly for cases below?Quoted 165 lines
sound/soc/amd/acp/acp-renoir.c +124
-0+ + return -ETIMEDOUT; +} + +static int acp3x_power_off (void __iomem *base) +{ + u32 val; + int timeout = 0; + + writel(ACP_PWR_OFF_MASK, base + ACP_PGFSM_CONTROL); + + while (++timeout < 500) { + val = readl(base + ACP_PGFSM_STATUS); + if ((val & ACP_PGFSM_STAT_MASK) == ACP_POWERED_OFF) + return 0; + udelay(1); + } + + return -ETIMEDOUT; +} + +static int acp3x_reset (void __iomem *base) +{ + u32 val; + int timeout = 0; + + writel(1, base + ACP_SOFT_RESET); + + while (++timeout < 500) { + val = readl(base + ACP_SOFT_RESET); + if (val & ACP_SOFT_RST_DONE_MASK) + break; + cpu_relax(); + } + + writel(0, base + ACP_SOFT_RESET); + + timeout = 0; + while (++timeout < 500) { + val = readl(base + ACP_SOFT_RESET); + if (!val) + return 0; + cpu_relax(); + } + + return -ETIMEDOUT; +} + +static void acp3x_enable_interrupts (void __iomem *base) +{ + u32 ext_intr_ctrl; + + writel(0x01, base + ACP_EXTERNAL_INTR_ENB); + ext_intr_ctrl = readl(base + ACP_EXTERNAL_INTR_CNTL); + ext_intr_ctrl |= ACP_ERROR_MASK; + writel(ext_intr_ctrl, base + ACP_EXTERNAL_INTR_CNTL); +} + +static void acp3x_disable_interrupts (void __iomem *base) +{ + writel(ACP_EXT_INTR_STAT_CLEAR_MASK, base +ACP_EXTERNAL_INTR_STAT ); + writel(0x00, base + ACP_EXTERNAL_INTR_ENB); +} + +static int rn_acp_init (void __iomem *base) +{ + int ret; + + /* power on */ + ret = acp3x_power_on(base); + if (ret) + return ret; + + writel(0x01, base + ACP_CONTROL); + + /* Reset */ + ret = acp3x_reset(base); + if (ret) + return ret; + + acp3x_enable_interrupts(base); + + return 0; +} + +static int rn_acp_deinit (void __iomem *base) +{ + int ret = 0; + + acp3x_disable_interrupts(base); + + /* Reset */ + ret = acp3x_reset(base); + if (ret) + return ret; + + writel(0x00, base + ACP_CONTROL); + + /* power off */ + ret = acp3x_power_off(base); + if (ret) + return ret; + + return 0; +} static int renoir_audio_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; + struct acp_chip_info *chip; struct acp_dev_data *adata; struct resource *res; + int ret; + + chip = dev_get_platdata(&pdev->dev); + if (!chip || !chip->base) { + dev_err(&pdev->dev, "ACP chip data is NULL\n"); + return -ENODEV; + } + + if (chip->acp_rev != ACP3X_DEV) { + dev_err(&pdev->dev, "Un-supported ACP Revision %d\n", chip->acp_rev); + return -ENODEV; + } + + ret = rn_acp_init(chip->base); + if (ret) { + dev_err(&pdev->dev, "ACP Init failed\n"); + return -EINVAL; + }adata =
devm_kzalloc(dev, sizeof(struct acp_dev_data), GFP_KERNEL); if (!adata)sound/soc/amd/acp/acp-renoir.c +14
-0@@ -155,6 +311,20 @@ static int renoir_audio_probe(struct platform_device *pdev) static int renoir_audio_remove(struct platform_device *pdev) { struct device *dev = &pdev->dev; + struct acp_chip_info *chip; + int ret; + + chip = dev_get_platdata(&pdev->dev); + if (!chip || !chip->base) { + dev_err(&pdev->dev, "ACP chip data is NULL\n"); + return -ENODEV; + } + + ret = rn_acp_deinit(chip->base); + if (ret) { + dev_err(&pdev->dev, "ACP de-init Failed\n"); + return -EINVAL; + } acp_platform_unregister(dev);return 0;
sound/soc/amd/acp/chip_offset_byte.h +1
-0@@ -14,6 +14,12 @@ #define ACPAXI2AXI_ATU_CTRL 0xC40 #define ACPAXI2AXI_ATU_PAGE_SIZE_GRP_5 0xC20 #define ACPAXI2AXI_ATU_BASE_ADDR_GRP_5 0xC24 +
Quoted 9 lines
sound/soc/amd/acp/chip_offset_byte.h line 25
Quoted 8 lines
sound/soc/amd/acp/chip_offset_byte.h +5
-0+#define ACP_PGFSM_CONTROL 0x141C +#define ACP_PGFSM_STATUS 0x1420 +#define ACP_SOFT_RESET 0x1000 +#define ACP_CONTROL 0x1004 + #define ACP_EXTERNAL_INTR_ENB 0x1800 #define ACP_EXTERNAL_INTR_CNTL 0x1804 #define ACP_EXTERNAL_INTR_STAT 0x1808
ok will improvise this in next patch chain