Skip to content

Commit

Permalink
ASoC: SOF: amd: add code for invoking soundwire manager helper functions
Browse files Browse the repository at this point in the history
Add code for invoking Soundwire manager helper functions
when SoundWire configuration is selected.

Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
Link: https://msgid.link/r/20240129055147.1493853-8-Vijendar.Mukunda@amd.com
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Vijendar Mukunda authored and Mark Brown committed Jan 30, 2024
1 parent c1263c7 commit d948218
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 2 deletions.
17 changes: 17 additions & 0 deletions sound/soc/sof/amd/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,23 @@ config SND_SOC_SOF_ACP_PROBES
This option is not user-selectable but automatically handled by
'select' statements at a higher level

config SND_SOC_SOF_AMD_SOUNDWIRE_LINK_BASELINE
tristate
select SOUNDWIRE_AMD if SND_SOC_SOF_AMD_SOUNDWIRE != n
select SND_AMD_SOUNDWIRE_ACPI if ACPI

config SND_SOC_SOF_AMD_SOUNDWIRE
tristate "SOF support for SoundWire based AMD platforms"
default SND_SOC_SOF_AMD_SOUNDWIRE_LINK_BASELINE
depends on SND_SOC_SOF_AMD_SOUNDWIRE_LINK_BASELINE
depends on ACPI && SOUNDWIRE
depends on !(SOUNDWIRE=m && SND_SOC_SOF_AMD_SOUNDWIRE_LINK_BASELINE=y)
help
This adds support for SoundWire with Sound Open Firmware
for AMD platforms.
Say Y if you want to enable SoundWire links with SOF.
If unsure select "N".

config SND_SOC_SOF_AMD_ACP63
tristate "SOF support for ACP6.3 platform"
depends on SND_SOC_SOF_PCI
Expand Down
99 changes: 98 additions & 1 deletion sound/soc/sof/amd/acp.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,81 @@ int amd_sof_acp_resume(struct snd_sof_dev *sdev)
}
EXPORT_SYMBOL_NS(amd_sof_acp_resume, SND_SOC_SOF_AMD_COMMON);

#if IS_ENABLED(CONFIG_SND_SOC_SOF_AMD_SOUNDWIRE)
static int acp_sof_scan_sdw_devices(struct snd_sof_dev *sdev, u64 addr)
{
struct acpi_device *sdw_dev;
struct acp_dev_data *acp_data;
const struct sof_amd_acp_desc *desc = get_chip_info(sdev->pdata);

if (!addr)
return -ENODEV;

acp_data = sdev->pdata->hw_pdata;
sdw_dev = acpi_find_child_device(ACPI_COMPANION(sdev->dev), addr, 0);
if (!sdw_dev)
return -ENODEV;

acp_data->info.handle = sdw_dev->handle;
acp_data->info.count = desc->sdw_max_link_count;

return amd_sdw_scan_controller(&acp_data->info);
}

static int amd_sof_sdw_probe(struct snd_sof_dev *sdev)
{
struct acp_dev_data *acp_data;
struct sdw_amd_res sdw_res;
int ret;

acp_data = sdev->pdata->hw_pdata;

memset(&sdw_res, 0, sizeof(sdw_res));
sdw_res.addr = acp_data->addr;
sdw_res.reg_range = acp_data->reg_range;
sdw_res.handle = acp_data->info.handle;
sdw_res.parent = sdev->dev;
sdw_res.dev = sdev->dev;
sdw_res.acp_lock = &acp_data->acp_lock;
sdw_res.count = acp_data->info.count;
sdw_res.link_mask = acp_data->info.link_mask;
sdw_res.mmio_base = sdev->bar[ACP_DSP_BAR];

ret = sdw_amd_probe(&sdw_res, &acp_data->sdw);
if (ret)
dev_err(sdev->dev, "SoundWire probe failed\n");
return ret;
}

static int amd_sof_sdw_exit(struct snd_sof_dev *sdev)
{
struct acp_dev_data *acp_data;

acp_data = sdev->pdata->hw_pdata;
if (acp_data->sdw)
sdw_amd_exit(acp_data->sdw);
acp_data->sdw = NULL;

return 0;
}

#else
static int acp_sof_scan_sdw_devices(struct snd_sof_dev *sdev, u64 addr)
{
return 0;
}

static int amd_sof_sdw_probe(struct snd_sof_dev *sdev)
{
return 0;
}

static int amd_sof_sdw_exit(struct snd_sof_dev *sdev)
{
return 0;
}
#endif

int amd_sof_acp_probe(struct snd_sof_dev *sdev)
{
struct pci_dev *pci = to_pci_dev(sdev->dev);
Expand Down Expand Up @@ -527,7 +602,9 @@ int amd_sof_acp_probe(struct snd_sof_dev *sdev)
}

pci_set_master(pci);

adata->addr = addr;
adata->reg_range = chip->reg_end_addr - chip->reg_start_addr;
mutex_init(&adata->acp_lock);
sdev->pdata->hw_pdata = adata;
adata->smn_dev = pci_get_device(PCI_VENDOR_ID_AMD, chip->host_bridge_id, NULL);
if (!adata->smn_dev) {
Expand All @@ -549,6 +626,21 @@ int amd_sof_acp_probe(struct snd_sof_dev *sdev)
if (ret < 0)
goto free_ipc_irq;

/* scan SoundWire capabilities exposed by DSDT */
ret = acp_sof_scan_sdw_devices(sdev, chip->sdw_acpi_dev_addr);
if (ret < 0) {
dev_dbg(sdev->dev, "skipping SoundWire, not detected with ACPI scan\n");
goto skip_soundwire;
}
ret = amd_sof_sdw_probe(sdev);
if (ret < 0) {
dev_err(sdev->dev, "error: SoundWire probe error\n");
free_irq(sdev->ipc_irq, sdev);
pci_dev_put(adata->smn_dev);
return ret;
}

skip_soundwire:
sdev->dsp_box.offset = 0;
sdev->dsp_box.size = BOX_SIZE_512;

Expand Down Expand Up @@ -596,6 +688,9 @@ void amd_sof_acp_remove(struct snd_sof_dev *sdev)
if (adata->smn_dev)
pci_dev_put(adata->smn_dev);

if (adata->sdw)
amd_sof_sdw_exit(sdev);

if (sdev->ipc_irq)
free_irq(sdev->ipc_irq, sdev);

Expand All @@ -607,4 +702,6 @@ void amd_sof_acp_remove(struct snd_sof_dev *sdev)
EXPORT_SYMBOL_NS(amd_sof_acp_remove, SND_SOC_SOF_AMD_COMMON);

MODULE_DESCRIPTION("AMD ACP sof driver");
MODULE_IMPORT_NS(SOUNDWIRE_AMD_INIT);
MODULE_IMPORT_NS(SND_AMD_SOUNDWIRE_ACPI);
MODULE_LICENSE("Dual BSD/GPL");
15 changes: 14 additions & 1 deletion sound/soc/sof/amd/acp.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#define __SOF_AMD_ACP_H

#include <linux/dmi.h>

#include <linux/soundwire/sdw_amd.h>
#include "../sof-priv.h"
#include "../sof-audio.h"

Expand Down Expand Up @@ -191,6 +191,10 @@ struct sof_amd_acp_desc {
u32 acp_clkmux_sel;
u32 fusion_dsp_offset;
u32 probe_reg_offset;
u32 reg_start_addr;
u32 reg_end_addr;
u32 sdw_max_link_count;
u64 sdw_acpi_dev_addr;
};

/* Common device data struct for ACP devices */
Expand All @@ -199,6 +203,12 @@ struct acp_dev_data {
const struct firmware *fw_dbin;
/* DMIC device */
struct platform_device *dmic_dev;
/* mutex lock to protect ACP common registers access */
struct mutex acp_lock;
/* ACPI information stored between scan and probe steps */
struct sdw_amd_acpi_info info;
/* sdw context allocated by SoundWire driver */
struct sdw_amd_ctx *sdw;
unsigned int fw_bin_size;
unsigned int fw_data_bin_size;
unsigned int fw_sram_data_bin_size;
Expand All @@ -207,6 +217,9 @@ struct acp_dev_data {
const char *fw_sram_data_bin;
u32 fw_bin_page_count;
u32 fw_data_bin_page_count;
u32 addr;
u32 reg_range;
u32 blk_type;
dma_addr_t sha_dma_addr;
u8 *bin_buf;
dma_addr_t dma_addr;
Expand Down

0 comments on commit d948218

Please sign in to comment.