Skip to content

Commit bbf3e61

Browse files
vijendarmukundabroonie
authored andcommitted
ASoC: amd: ps: add machine select and register code
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>
1 parent c76f3b1 commit bbf3e61

2 files changed

Lines changed: 84 additions & 1 deletion

File tree

sound/soc/amd/ps/acp63.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,11 @@ struct sdw_dma_ring_buf_reg {
219219
* @pdm_dev: ACP PDM controller platform device
220220
* @dmic_codec: platform device for DMIC Codec
221221
* sdw_dma_dev: platform device for SoundWire DMA controller
222+
* @mach_dev: platform device for machine driver to support ACP PDM/SoundWire configuration
222223
* @acp_lock: used to protect acp common registers
223224
* @info: SoundWire AMD information found in ACPI tables
224225
* @sdw: SoundWire context for all SoundWire manager instances
226+
* @machine: ACPI machines for SoundWire interface
225227
* @is_sdw_dev: flag set to true when any SoundWire manager instances are available
226228
* @is_pdm_dev: flag set to true when ACP PDM controller exists
227229
* @is_pdm_config: flat set to true when PDM configuration is selected from BIOS
@@ -239,10 +241,12 @@ struct acp63_dev_data {
239241
struct platform_device *pdm_dev;
240242
struct platform_device *dmic_codec_dev;
241243
struct platform_device *sdw_dma_dev;
244+
struct platform_device *mach_dev;
242245
struct mutex acp_lock; /* protect shared registers */
243246
struct sdw_amd_acpi_info info;
244247
/* sdw context allocated by SoundWire driver */
245248
struct sdw_amd_ctx *sdw;
249+
struct snd_soc_acpi_mach *machines;
246250
bool is_sdw_dev;
247251
bool is_pdm_dev;
248252
bool is_pdm_config;

sound/soc/amd/ps/pci-ps.c

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/pm_runtime.h>
1818
#include <linux/iopoll.h>
1919
#include <linux/soundwire/sdw_amd.h>
20+
#include "../mach-config.h"
2021

2122
#include "acp63.h"
2223

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

282283
return 0;
283284
}
285+
286+
static struct snd_soc_acpi_mach *acp63_sdw_machine_select(struct device *dev)
287+
{
288+
struct snd_soc_acpi_mach *mach;
289+
const struct snd_soc_acpi_link_adr *link;
290+
struct acp63_dev_data *acp_data = dev_get_drvdata(dev);
291+
int ret, i;
292+
293+
if (acp_data->info.count) {
294+
ret = sdw_amd_get_slave_info(acp_data->sdw);
295+
if (ret) {
296+
dev_dbg(dev, "failed to read slave information\n");
297+
return NULL;
298+
}
299+
for (mach = acp_data->machines; mach; mach++) {
300+
if (!mach->links)
301+
break;
302+
link = mach->links;
303+
for (i = 0; i < acp_data->info.count && link->num_adr; link++, i++) {
304+
if (!snd_soc_acpi_sdw_link_slaves_found(dev, link,
305+
acp_data->sdw->ids,
306+
acp_data->sdw->num_slaves))
307+
break;
308+
}
309+
if (i == acp_data->info.count || !link->num_adr)
310+
break;
311+
}
312+
if (mach && mach->link_mask) {
313+
mach->mach_params.links = mach->links;
314+
mach->mach_params.link_mask = mach->link_mask;
315+
return mach;
316+
}
317+
}
318+
dev_dbg(dev, "No SoundWire machine driver found\n");
319+
return NULL;
320+
}
284321
#else
285322
static int acp_scan_sdw_devices(struct device *dev, u64 addr)
286323
{
@@ -296,8 +333,44 @@ static int amd_sdw_exit(struct acp63_dev_data *acp_data)
296333
{
297334
return 0;
298335
}
336+
337+
static struct snd_soc_acpi_mach *acp63_sdw_machine_select(struct device *dev)
338+
{
339+
return NULL;
340+
}
299341
#endif
300342

343+
static int acp63_machine_register(struct device *dev)
344+
{
345+
struct snd_soc_acpi_mach *mach;
346+
struct acp63_dev_data *adata = dev_get_drvdata(dev);
347+
int size;
348+
349+
if (adata->is_sdw_dev && adata->is_sdw_config) {
350+
size = sizeof(*adata->machines);
351+
mach = acp63_sdw_machine_select(dev);
352+
if (mach) {
353+
adata->mach_dev = platform_device_register_data(dev, mach->drv_name,
354+
PLATFORM_DEVID_NONE, mach,
355+
size);
356+
if (IS_ERR(adata->mach_dev)) {
357+
dev_err(dev,
358+
"cannot register Machine device for SoundWire Interface\n");
359+
return PTR_ERR(adata->mach_dev);
360+
}
361+
}
362+
363+
} else if (adata->is_pdm_dev && !adata->is_sdw_dev && adata->is_pdm_config) {
364+
adata->mach_dev = platform_device_register_data(dev, "acp_ps_mach",
365+
PLATFORM_DEVID_NONE, NULL, 0);
366+
if (IS_ERR(adata->mach_dev)) {
367+
dev_err(dev, "cannot register amd_ps_mach device\n");
368+
return PTR_ERR(adata->mach_dev);
369+
}
370+
}
371+
return 0;
372+
}
373+
301374
static int get_acp63_device_config(struct pci_dev *pci, struct acp63_dev_data *acp_data)
302375
{
303376
struct acpi_device *pdm_dev;
@@ -526,7 +599,11 @@ static int snd_acp63_probe(struct pci_dev *pci,
526599
dev_err(&pci->dev, "ACP platform devices creation failed\n");
527600
goto de_init;
528601
}
529-
602+
ret = acp63_machine_register(&pci->dev);
603+
if (ret) {
604+
dev_err(&pci->dev, "ACP machine register failed\n");
605+
goto de_init;
606+
}
530607
skip_pdev_creation:
531608
device_set_wakeup_enable(&pci->dev, true);
532609
pm_runtime_set_autosuspend_delay(&pci->dev, ACP_SUSPEND_DELAY_MS);
@@ -640,6 +717,8 @@ static void snd_acp63_remove(struct pci_dev *pci)
640717
platform_device_unregister(adata->pdm_dev);
641718
platform_device_unregister(adata->dmic_codec_dev);
642719
}
720+
if (adata->mach_dev)
721+
platform_device_unregister(adata->mach_dev);
643722
ret = acp63_deinit(adata->acp63_base, &pci->dev);
644723
if (ret)
645724
dev_err(&pci->dev, "ACP de-init failed\n");

0 commit comments

Comments
 (0)