Skip to content

Commit

Permalink
ASoC: amd: ps: add machine select and register code
Browse files Browse the repository at this point in the history
Add machine select logic for SoundWire interface and create a machine
device node based on ACP PDM/SoundWire configuration.

Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
Link: https://msgid.link/r/20240214104014.1144668-5-Vijendar.Mukunda@amd.com
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Vijendar Mukunda authored and Mark Brown committed Feb 19, 2024
1 parent c76f3b1 commit bbf3e61
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
4 changes: 4 additions & 0 deletions sound/soc/amd/ps/acp63.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,11 @@ struct sdw_dma_ring_buf_reg {
* @pdm_dev: ACP PDM controller platform device
* @dmic_codec: platform device for DMIC Codec
* sdw_dma_dev: platform device for SoundWire DMA controller
* @mach_dev: platform device for machine driver to support ACP PDM/SoundWire configuration
* @acp_lock: used to protect acp common registers
* @info: SoundWire AMD information found in ACPI tables
* @sdw: SoundWire context for all SoundWire manager instances
* @machine: ACPI machines for SoundWire interface
* @is_sdw_dev: flag set to true when any SoundWire manager instances are available
* @is_pdm_dev: flag set to true when ACP PDM controller exists
* @is_pdm_config: flat set to true when PDM configuration is selected from BIOS
Expand All @@ -239,10 +241,12 @@ struct acp63_dev_data {
struct platform_device *pdm_dev;
struct platform_device *dmic_codec_dev;
struct platform_device *sdw_dma_dev;
struct platform_device *mach_dev;
struct mutex acp_lock; /* protect shared registers */
struct sdw_amd_acpi_info info;
/* sdw context allocated by SoundWire driver */
struct sdw_amd_ctx *sdw;
struct snd_soc_acpi_mach *machines;
bool is_sdw_dev;
bool is_pdm_dev;
bool is_pdm_config;
Expand Down
81 changes: 80 additions & 1 deletion sound/soc/amd/ps/pci-ps.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <linux/pm_runtime.h>
#include <linux/iopoll.h>
#include <linux/soundwire/sdw_amd.h>
#include "../mach-config.h"

#include "acp63.h"

Expand Down Expand Up @@ -281,6 +282,42 @@ static int amd_sdw_exit(struct acp63_dev_data *acp_data)

return 0;
}

static struct snd_soc_acpi_mach *acp63_sdw_machine_select(struct device *dev)
{
struct snd_soc_acpi_mach *mach;
const struct snd_soc_acpi_link_adr *link;
struct acp63_dev_data *acp_data = dev_get_drvdata(dev);
int ret, i;

if (acp_data->info.count) {
ret = sdw_amd_get_slave_info(acp_data->sdw);
if (ret) {
dev_dbg(dev, "failed to read slave information\n");
return NULL;
}
for (mach = acp_data->machines; mach; mach++) {
if (!mach->links)
break;
link = mach->links;
for (i = 0; i < acp_data->info.count && link->num_adr; link++, i++) {
if (!snd_soc_acpi_sdw_link_slaves_found(dev, link,
acp_data->sdw->ids,
acp_data->sdw->num_slaves))
break;
}
if (i == acp_data->info.count || !link->num_adr)
break;
}
if (mach && mach->link_mask) {
mach->mach_params.links = mach->links;
mach->mach_params.link_mask = mach->link_mask;
return mach;
}
}
dev_dbg(dev, "No SoundWire machine driver found\n");
return NULL;
}
#else
static int acp_scan_sdw_devices(struct device *dev, u64 addr)
{
Expand All @@ -296,8 +333,44 @@ static int amd_sdw_exit(struct acp63_dev_data *acp_data)
{
return 0;
}

static struct snd_soc_acpi_mach *acp63_sdw_machine_select(struct device *dev)
{
return NULL;
}
#endif

static int acp63_machine_register(struct device *dev)
{
struct snd_soc_acpi_mach *mach;
struct acp63_dev_data *adata = dev_get_drvdata(dev);
int size;

if (adata->is_sdw_dev && adata->is_sdw_config) {
size = sizeof(*adata->machines);
mach = acp63_sdw_machine_select(dev);
if (mach) {
adata->mach_dev = platform_device_register_data(dev, mach->drv_name,
PLATFORM_DEVID_NONE, mach,
size);
if (IS_ERR(adata->mach_dev)) {
dev_err(dev,
"cannot register Machine device for SoundWire Interface\n");
return PTR_ERR(adata->mach_dev);
}
}

} else if (adata->is_pdm_dev && !adata->is_sdw_dev && adata->is_pdm_config) {
adata->mach_dev = platform_device_register_data(dev, "acp_ps_mach",
PLATFORM_DEVID_NONE, NULL, 0);
if (IS_ERR(adata->mach_dev)) {
dev_err(dev, "cannot register amd_ps_mach device\n");
return PTR_ERR(adata->mach_dev);
}
}
return 0;
}

static int get_acp63_device_config(struct pci_dev *pci, struct acp63_dev_data *acp_data)
{
struct acpi_device *pdm_dev;
Expand Down Expand Up @@ -526,7 +599,11 @@ static int snd_acp63_probe(struct pci_dev *pci,
dev_err(&pci->dev, "ACP platform devices creation failed\n");
goto de_init;
}

ret = acp63_machine_register(&pci->dev);
if (ret) {
dev_err(&pci->dev, "ACP machine register failed\n");
goto de_init;
}
skip_pdev_creation:
device_set_wakeup_enable(&pci->dev, true);
pm_runtime_set_autosuspend_delay(&pci->dev, ACP_SUSPEND_DELAY_MS);
Expand Down Expand Up @@ -640,6 +717,8 @@ static void snd_acp63_remove(struct pci_dev *pci)
platform_device_unregister(adata->pdm_dev);
platform_device_unregister(adata->dmic_codec_dev);
}
if (adata->mach_dev)
platform_device_unregister(adata->mach_dev);
ret = acp63_deinit(adata->acp63_base, &pci->dev);
if (ret)
dev_err(&pci->dev, "ACP de-init failed\n");
Expand Down

0 comments on commit bbf3e61

Please sign in to comment.