All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/12] soundwire/SOF: add SoundWire Interface support for AMD SOF stack
@ 2023-12-21  7:35 Vijendar Mukunda
  2023-12-21  7:35 ` [PATCH 01/12] ASoC/soundwire: implement generic api for scanning amd soundwire controller Vijendar Mukunda
                   ` (13 more replies)
  0 siblings, 14 replies; 24+ messages in thread
From: Vijendar Mukunda @ 2023-12-21  7:35 UTC (permalink / raw)
  To: broonie, vkoul
  Cc: alsa-devel, Basavaraj.Hiregoudar, Sunil-kumar.Dommati,
	pierre-louis.bossart, vinod.koul, venkataprasad.potturu,
	Vijendar Mukunda

This patch series is to redesign existing platform device
creation logic for SoundWire managers and Implement generic
functions for SoundWire manager probe, start and exit sequence
which are common for both Legacy(NO DSP enabled) and SOF stack,
and add SoundWire Interface support for AMD SOF stack
(ACP 6.3 based platforms).

Vijendar Mukunda (12):
  ASoC/soundwire: implement generic api for scanning amd soundwire
    controller
  drivers: soundwire: refactor amd soundwire manager device node
    creation
  drivers: soundwire: implement function to extract slave information
  drivers: soundwire: refactor soundwire pads enable
  drivers: soundwire: refactor register mask structure
  ASoC: SOF: amd: add code for invoking soundwire manager helper
    functions
  ASoC: SOF: amd: add interrupt handling for SoundWire manager devices
  ASoC: SOF: amd: Add Soundwire DAI configuration support for AMD
    platforms
  ASoC: SOF: amd: add machine select logic for soundwire based platforms
  ASoC: SOF: amd: update descriptor fields for acp6.3 based platform
  ASoC: SOF: amd: select soundwire dependency flag for acp6.3 based
    platform
  ASoC: SOF: amd: refactor acp driver pm ops

 drivers/soundwire/Makefile         |   2 +-
 drivers/soundwire/amd_init.c       | 235 +++++++++++++++++++++++++++++
 drivers/soundwire/amd_init.h       |  13 ++
 drivers/soundwire/amd_manager.c    |  41 +----
 drivers/soundwire/amd_manager.h    |  12 +-
 include/linux/soundwire/sdw_amd.h  |  79 ++++++++--
 include/sound/sof/dai-amd.h        |   7 +
 include/sound/sof/dai.h            |   2 +
 include/uapi/sound/sof/tokens.h    |   4 +
 sound/soc/amd/acp/Kconfig          |   7 +
 sound/soc/amd/acp/Makefile         |   2 +
 sound/soc/amd/acp/amd-sdw-acpi.c   |  62 ++++++++
 sound/soc/sof/amd/Kconfig          |  18 +++
 sound/soc/sof/amd/acp-common.c     |  65 +++++++-
 sound/soc/sof/amd/acp-dsp-offset.h |  10 ++
 sound/soc/sof/amd/acp.c            | 202 ++++++++++++++++++++++++-
 sound/soc/sof/amd/acp.h            |  26 +++-
 sound/soc/sof/amd/pci-acp63.c      |   7 +
 sound/soc/sof/ipc3-pcm.c           |  25 +++
 sound/soc/sof/ipc3-topology.c      |  40 +++++
 sound/soc/sof/sof-audio.h          |   1 +
 sound/soc/sof/topology.c           |   5 +
 22 files changed, 798 insertions(+), 67 deletions(-)
 create mode 100644 drivers/soundwire/amd_init.c
 create mode 100644 drivers/soundwire/amd_init.h
 create mode 100644 sound/soc/amd/acp/amd-sdw-acpi.c

-- 
2.34.1


^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 01/12] ASoC/soundwire: implement generic api for scanning amd soundwire controller
  2023-12-21  7:35 [PATCH 00/12] soundwire/SOF: add SoundWire Interface support for AMD SOF stack Vijendar Mukunda
@ 2023-12-21  7:35 ` Vijendar Mukunda
  2023-12-21  7:35 ` [PATCH 02/12] drivers: soundwire: refactor amd soundwire manager device node creation Vijendar Mukunda
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 24+ messages in thread
From: Vijendar Mukunda @ 2023-12-21  7:35 UTC (permalink / raw)
  To: broonie, vkoul
  Cc: alsa-devel, Basavaraj.Hiregoudar, Sunil-kumar.Dommati,
	pierre-louis.bossart, vinod.koul, venkataprasad.potturu,
	Vijendar Mukunda, Bard Liao, Sanyog Kale, Liam Girdwood,
	Jaroslav Kysela, Takashi Iwai, Syed Saba Kareem, Arnd Bergmann,
	Marian Postevca, open list,
	open list:SOUND - SOC LAYER / DYNAMIC AUDIO POWER MANAGEM...

Implement generic function for scanning SoundWire controller.
Same function will be used for legacy and sof stack for AMD platforms.

Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
---
 include/linux/soundwire/sdw_amd.h | 15 ++++++++
 sound/soc/amd/acp/Kconfig         |  7 ++++
 sound/soc/amd/acp/Makefile        |  2 +
 sound/soc/amd/acp/amd-sdw-acpi.c  | 62 +++++++++++++++++++++++++++++++
 4 files changed, 86 insertions(+)
 create mode 100644 sound/soc/amd/acp/amd-sdw-acpi.c

diff --git a/include/linux/soundwire/sdw_amd.h b/include/linux/soundwire/sdw_amd.h
index ceecad74aef9..41dd64941cef 100644
--- a/include/linux/soundwire/sdw_amd.h
+++ b/include/linux/soundwire/sdw_amd.h
@@ -6,6 +6,7 @@
 #ifndef __SDW_AMD_H
 #define __SDW_AMD_H
 
+#include <linux/acpi.h>
 #include <linux/soundwire/sdw.h>
 
 /* AMD pm_runtime quirk definitions */
@@ -106,4 +107,18 @@ struct amd_sdw_manager {
 
 	struct sdw_amd_dai_runtime **dai_runtime_array;
 };
+
+/**
+ * struct sdw_amd_acpi_info - Soundwire AMD information found in ACPI tables
+ * @handle: ACPI controller handle
+ * @count: maximum no of soundwire manager links supported on AMD platform.
+ * @link_mask: bit-wise mask listing links enabled by BIOS menu
+ */
+struct sdw_amd_acpi_info {
+	acpi_handle handle;
+	int count;
+	u32 link_mask;
+};
+
+int amd_sdw_scan_controller(struct sdw_amd_acpi_info *info);
 #endif
diff --git a/sound/soc/amd/acp/Kconfig b/sound/soc/amd/acp/Kconfig
index 84c963241dc5..b3105ba9c3a3 100644
--- a/sound/soc/amd/acp/Kconfig
+++ b/sound/soc/amd/acp/Kconfig
@@ -101,6 +101,13 @@ config SND_SOC_AMD_MACH_COMMON
 	help
 	  This option enables common Machine driver module for ACP.
 
+config SND_AMD_SOUNDWIRE_ACPI
+	tristate "AMD SoundWire ACPI Support"
+	depends on ACPI
+	help
+	  This options enables ACPI helper functions for SoundWire
+	  interface for AMD platforms.
+
 config SND_SOC_AMD_LEGACY_MACH
 	tristate "AMD Legacy Machine Driver Support"
 	depends on X86 && PCI && I2C
diff --git a/sound/soc/amd/acp/Makefile b/sound/soc/amd/acp/Makefile
index ff5f7893b81e..1fd581a2aa33 100644
--- a/sound/soc/amd/acp/Makefile
+++ b/sound/soc/amd/acp/Makefile
@@ -10,6 +10,7 @@ snd-acp-i2s-objs     := acp-i2s.o
 snd-acp-pdm-objs     := acp-pdm.o
 snd-acp-legacy-common-objs   := acp-legacy-common.o
 snd-acp-pci-objs     := acp-pci.o
+snd-amd-sdw-acpi-objs := amd-sdw-acpi.o
 
 #platform specific driver
 snd-acp-renoir-objs     := acp-renoir.o
@@ -33,6 +34,7 @@ obj-$(CONFIG_SND_AMD_ASOC_REMBRANDT) += snd-acp-rembrandt.o
 obj-$(CONFIG_SND_AMD_ASOC_ACP63) += snd-acp63.o
 obj-$(CONFIG_SND_AMD_ASOC_ACP70) += snd-acp70.o
 
+obj-$(CONFIG_SND_AMD_SOUNDWIRE_ACPI) += snd-amd-sdw-acpi.o
 obj-$(CONFIG_SND_SOC_AMD_MACH_COMMON) += snd-acp-mach.o
 obj-$(CONFIG_SND_SOC_AMD_LEGACY_MACH) += snd-acp-legacy-mach.o
 obj-$(CONFIG_SND_SOC_AMD_SOF_MACH) += snd-acp-sof-mach.o
diff --git a/sound/soc/amd/acp/amd-sdw-acpi.c b/sound/soc/amd/acp/amd-sdw-acpi.c
new file mode 100644
index 000000000000..babd841d3296
--- /dev/null
+++ b/sound/soc/amd/acp/amd-sdw-acpi.c
@@ -0,0 +1,62 @@
+// 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) 2023 Advanced Micro Devices, Inc. All rights reserved.
+//
+// Authors: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
+
+/*
+ * SDW AMD ACPI scan helper function
+ */
+
+#include <linux/acpi.h>
+#include <linux/bits.h>
+#include <linux/bitfield.h>
+#include <linux/device.h>
+#include <linux/errno.h>
+#include <linux/export.h>
+#include <linux/fwnode.h>
+#include <linux/module.h>
+#include <linux/soundwire/sdw_amd.h>
+#include <linux/string.h>
+
+int amd_sdw_scan_controller(struct sdw_amd_acpi_info *info)
+{
+	struct acpi_device *adev = acpi_fetch_acpi_dev(info->handle);
+	u32 sdw_bitmap = 0;
+	u8 count = 0;
+	int ret;
+
+	if (!adev)
+		return -EINVAL;
+
+	/* Found controller, find links supported */
+	ret = fwnode_property_read_u32_array(acpi_fwnode_handle(adev),
+					     "mipi-sdw-manager-list", &sdw_bitmap, 1);
+	if (ret) {
+		dev_err(&adev->dev,
+			"Failed to read mipi-sdw-manager-list: %d\n", ret);
+		return -EINVAL;
+	}
+	count = hweight32(sdw_bitmap);
+	/* Check count is within bounds */
+	if (count > info->count) {
+		dev_err(&adev->dev, "Manager count %d exceeds max %d\n",
+			count, info->count);
+		return -EINVAL;
+	}
+
+	if (!count) {
+		dev_dbg(&adev->dev, "No SoundWire Managers detected\n");
+		return -EINVAL;
+	}
+	dev_dbg(&adev->dev, "ACPI reports %d SoundWire Manager devices\n", count);
+	info->link_mask = sdw_bitmap;
+	return 0;
+}
+EXPORT_SYMBOL_NS(amd_sdw_scan_controller, SND_AMD_SOUNDWIRE_ACPI);
+
+MODULE_LICENSE("Dual BSD/GPL");
+MODULE_DESCRIPTION("AMD SoundWire ACPI helpers");
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 02/12] drivers: soundwire: refactor amd soundwire manager device node creation
  2023-12-21  7:35 [PATCH 00/12] soundwire/SOF: add SoundWire Interface support for AMD SOF stack Vijendar Mukunda
  2023-12-21  7:35 ` [PATCH 01/12] ASoC/soundwire: implement generic api for scanning amd soundwire controller Vijendar Mukunda
@ 2023-12-21  7:35 ` Vijendar Mukunda
  2023-12-21 16:34   ` Vinod Koul
  2023-12-21  7:35 ` [PATCH 03/12] drivers: soundwire: implement function to extract slave information Vijendar Mukunda
                   ` (11 subsequent siblings)
  13 siblings, 1 reply; 24+ messages in thread
From: Vijendar Mukunda @ 2023-12-21  7:35 UTC (permalink / raw)
  To: broonie, vkoul
  Cc: alsa-devel, Basavaraj.Hiregoudar, Sunil-kumar.Dommati,
	pierre-louis.bossart, vinod.koul, venkataprasad.potturu,
	Vijendar Mukunda, Bard Liao, Sanyog Kale, open list

Refactor amd SoundWire manager device node creation logic and
implement generic functions to have a common functionality for
SoundWire manager platform device creation, start and exit sequence
for both legacy(NO DSP) and SOF stack for AMD platforms.
These functions will be invoked from legacy and SOF stack.

Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
---
 drivers/soundwire/Makefile        |   2 +-
 drivers/soundwire/amd_init.c      | 147 ++++++++++++++++++++++++++++++
 drivers/soundwire/amd_init.h      |  13 +++
 drivers/soundwire/amd_manager.c   |  16 +---
 include/linux/soundwire/sdw_amd.h |  54 ++++++++++-
 5 files changed, 218 insertions(+), 14 deletions(-)
 create mode 100644 drivers/soundwire/amd_init.c
 create mode 100644 drivers/soundwire/amd_init.h

diff --git a/drivers/soundwire/Makefile b/drivers/soundwire/Makefile
index 657f5888a77b..e80a2c2cf3e7 100644
--- a/drivers/soundwire/Makefile
+++ b/drivers/soundwire/Makefile
@@ -20,7 +20,7 @@ soundwire-bus-y += irq.o
 endif
 
 #AMD driver
-soundwire-amd-y :=	amd_manager.o
+soundwire-amd-y := amd_init.o amd_manager.o
 obj-$(CONFIG_SOUNDWIRE_AMD) += soundwire-amd.o
 
 #Cadence Objs
diff --git a/drivers/soundwire/amd_init.c b/drivers/soundwire/amd_init.c
new file mode 100644
index 000000000000..d732ab0bfd59
--- /dev/null
+++ b/drivers/soundwire/amd_init.c
@@ -0,0 +1,147 @@
+// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
+/*
+ * SoundWire AMD Manager Initialize routines
+ *
+ * Initializes and creates SDW devices based on ACPI and Hardware values
+ *
+ * Copyright 2023 Advanced Micro Devices, Inc.
+ */
+
+#include <linux/acpi.h>
+#include <linux/export.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+
+#include "amd_init.h"
+
+static int sdw_amd_cleanup(struct sdw_amd_ctx *ctx)
+{
+	int i;
+
+	for (i = 0; i < ctx->count; i++) {
+		if (!(ctx->link_mask & BIT(i)))
+			continue;
+		platform_device_unregister(ctx->pdev[i]);
+	}
+
+	return 0;
+}
+
+static struct sdw_amd_ctx *sdw_amd_probe_controller(struct sdw_amd_res *res)
+{
+	struct sdw_amd_ctx *ctx;
+	struct acpi_device *adev;
+	struct resource *sdw_res;
+	struct acp_sdw_pdata sdw_pdata[2];
+	struct platform_device_info pdevinfo[2];
+	u32 link_mask;
+	int count, index;
+
+	if (!res)
+		return NULL;
+
+	adev = acpi_fetch_acpi_dev(res->handle);
+	if (!adev)
+		return NULL;
+
+	if (!res->count)
+		return NULL;
+
+	count = res->count;
+	dev_dbg(&adev->dev, "Creating %d SDW Link devices\n", count);
+
+	/*
+	 * we need to alloc/free memory manually and can't use devm:
+	 * this routine may be called from a workqueue, and not from
+	 * the parent .probe.
+	 * If devm_ was used, the memory might never be freed on errors.
+	 */
+	ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
+	if (!ctx)
+		return NULL;
+
+	ctx->count = count;
+	ctx->link_mask = res->link_mask;
+	sdw_res = kzalloc(sizeof(*sdw_res), GFP_KERNEL);
+	if (!sdw_res) {
+		kfree(ctx);
+		return NULL;
+	}
+	sdw_res->flags = IORESOURCE_MEM;
+	sdw_res->start = res->addr;
+	sdw_res->end = res->addr + res->reg_range;
+	memset(&pdevinfo, 0, sizeof(pdevinfo));
+	link_mask = ctx->link_mask;
+	for (index = 0; index < count; index++) {
+		if (!(link_mask & BIT(index)))
+			continue;
+
+		sdw_pdata[index].instance = index;
+		sdw_pdata[index].acp_sdw_lock = res->acp_lock;
+		pdevinfo[index].name = "amd_sdw_manager";
+		pdevinfo[index].id = index;
+		pdevinfo[index].parent = res->parent;
+		pdevinfo[index].num_res = 1;
+		pdevinfo[index].res = sdw_res;
+		pdevinfo[index].data = &sdw_pdata[index];
+		pdevinfo[index].size_data = sizeof(struct acp_sdw_pdata);
+		pdevinfo[index].fwnode = acpi_fwnode_handle(adev);
+		ctx->pdev[index] = platform_device_register_full(&pdevinfo[index]);
+		if (IS_ERR(ctx->pdev[index]))
+			goto err;
+	}
+	kfree(sdw_res);
+	return ctx;
+err:
+	while (index--) {
+		if (!(link_mask & BIT(index)))
+			continue;
+
+		platform_device_unregister(ctx->pdev[index]);
+	}
+
+	kfree(sdw_res);
+	kfree(ctx);
+	return NULL;
+}
+
+static int sdw_amd_startup(struct sdw_amd_ctx *ctx)
+{
+	struct amd_sdw_manager *amd_manager;
+	int i, ret;
+
+	/* Startup SDW Manager devices */
+	for (i = 0; i < ctx->count; i++) {
+		if (!(ctx->link_mask & BIT(i)))
+			continue;
+		amd_manager = dev_get_drvdata(&ctx->pdev[i]->dev);
+		ret = amd_sdw_manager_start(amd_manager);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
+int sdw_amd_probe(struct sdw_amd_res *res, struct sdw_amd_ctx **sdw_ctx)
+{
+	*sdw_ctx = sdw_amd_probe_controller(res);
+	if (!*sdw_ctx)
+		return -ENODEV;
+
+	return sdw_amd_startup(*sdw_ctx);
+}
+EXPORT_SYMBOL_NS(sdw_amd_probe, SOUNDWIRE_AMD_INIT);
+
+void sdw_amd_exit(struct sdw_amd_ctx *ctx)
+{
+	sdw_amd_cleanup(ctx);
+	kfree(ctx->ids);
+	kfree(ctx);
+}
+EXPORT_SYMBOL_NS(sdw_amd_exit, SOUNDWIRE_AMD_INIT);
+
+MODULE_AUTHOR("Vijendar.Mukunda@amd.com");
+MODULE_DESCRIPTION("AMD SoundWire Init Library");
+MODULE_LICENSE("Dual BSD/GPL");
diff --git a/drivers/soundwire/amd_init.h b/drivers/soundwire/amd_init.h
new file mode 100644
index 000000000000..f710703ffae9
--- /dev/null
+++ b/drivers/soundwire/amd_init.h
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
+/*
+ * Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
+ */
+
+#ifndef __AMD_INIT_H
+#define __AMD_INIT_H
+
+#include <linux/soundwire/sdw_amd.h>
+
+int amd_sdw_manager_start(struct amd_sdw_manager *amd_manager);
+
+#endif
diff --git a/drivers/soundwire/amd_manager.c b/drivers/soundwire/amd_manager.c
index 3a99f6dcdfaf..c27b0b0f33a6 100644
--- a/drivers/soundwire/amd_manager.c
+++ b/drivers/soundwire/amd_manager.c
@@ -19,6 +19,7 @@
 #include <sound/pcm_params.h>
 #include <sound/soc.h>
 #include "bus.h"
+#include "amd_init.h"
 #include "amd_manager.h"
 
 #define DRV_NAME "amd_sdw_manager"
@@ -864,10 +865,8 @@ static void amd_sdw_irq_thread(struct work_struct *work)
 	writel(0x00, amd_manager->mmio + ACP_SW_STATE_CHANGE_STATUS_0TO7);
 }
 
-static void amd_sdw_probe_work(struct work_struct *work)
+int amd_sdw_manager_start(struct amd_sdw_manager *amd_manager)
 {
-	struct amd_sdw_manager *amd_manager = container_of(work, struct amd_sdw_manager,
-							   probe_work);
 	struct sdw_master_prop *prop;
 	int ret;
 
@@ -876,11 +875,11 @@ static void amd_sdw_probe_work(struct work_struct *work)
 		amd_enable_sdw_pads(amd_manager);
 		ret = amd_init_sdw_manager(amd_manager);
 		if (ret)
-			return;
+			return ret;
 		amd_enable_sdw_interrupts(amd_manager);
 		ret = amd_enable_sdw_manager(amd_manager);
 		if (ret)
-			return;
+			return ret;
 		amd_sdw_set_frameshape(amd_manager);
 	}
 	/* Enable runtime PM */
@@ -889,6 +888,7 @@ static void amd_sdw_probe_work(struct work_struct *work)
 	pm_runtime_mark_last_busy(amd_manager->dev);
 	pm_runtime_set_active(amd_manager->dev);
 	pm_runtime_enable(amd_manager->dev);
+	return 0;
 }
 
 static int amd_sdw_manager_probe(struct platform_device *pdev)
@@ -964,11 +964,6 @@ static int amd_sdw_manager_probe(struct platform_device *pdev)
 	dev_set_drvdata(dev, amd_manager);
 	INIT_WORK(&amd_manager->amd_sdw_irq_thread, amd_sdw_irq_thread);
 	INIT_WORK(&amd_manager->amd_sdw_work, amd_sdw_update_slave_status_work);
-	INIT_WORK(&amd_manager->probe_work, amd_sdw_probe_work);
-	/*
-	 * Instead of having lengthy probe sequence, use deferred probe.
-	 */
-	schedule_work(&amd_manager->probe_work);
 	return 0;
 }
 
@@ -978,7 +973,6 @@ static void amd_sdw_manager_remove(struct platform_device *pdev)
 	int ret;
 
 	pm_runtime_disable(&pdev->dev);
-	cancel_work_sync(&amd_manager->probe_work);
 	amd_disable_sdw_interrupts(amd_manager);
 	sdw_bus_master_delete(&amd_manager->bus);
 	ret = amd_disable_sdw_manager(amd_manager);
diff --git a/include/linux/soundwire/sdw_amd.h b/include/linux/soundwire/sdw_amd.h
index 41dd64941cef..064174c2f401 100644
--- a/include/linux/soundwire/sdw_amd.h
+++ b/include/linux/soundwire/sdw_amd.h
@@ -26,6 +26,7 @@
 #define AMD_SDW_POWER_OFF_MODE		2
 #define ACP_SDW0	0
 #define ACP_SDW1	1
+#define AMD_SDW_MAX_MANAGER_COUNT	2
 
 struct acp_sdw_pdata {
 	u16 instance;
@@ -63,7 +64,6 @@ struct sdw_amd_dai_runtime {
  * @reg_mask: register mask structure per manager instance
  * @amd_sdw_irq_thread: SoundWire manager irq workqueue
  * @amd_sdw_work: peripheral status work queue
- * @probe_work: SoundWire manager probe workqueue
  * @acp_sdw_lock: mutex to protect acp share register access
  * @status: peripheral devices status array
  * @num_din_ports: number of input ports
@@ -87,7 +87,6 @@ struct amd_sdw_manager {
 	struct sdw_manager_reg_mask *reg_mask;
 	struct work_struct amd_sdw_irq_thread;
 	struct work_struct amd_sdw_work;
-	struct work_struct probe_work;
 	/* mutex to protect acp common register access */
 	struct mutex *acp_sdw_lock;
 
@@ -120,5 +119,56 @@ struct sdw_amd_acpi_info {
 	u32 link_mask;
 };
 
+/**
+ * struct sdw_amd_ctx - context allocated by the controller
+ * driver probe
+ * @count: link count
+ * @num_slaves: total number of devices exposed across all enabled links
+ * @link_mask: bit-wise mask listing SoundWire links reported by the
+ * Controller
+ * @ids: array of slave_id, representing Slaves exposed across all enabled
+ * links
+ * @pdev: platform device structure
+ */
+struct sdw_amd_ctx {
+	int count;
+	int num_slaves;
+	u32 link_mask;
+	struct sdw_extended_slave_id *ids;
+	struct platform_device *pdev[AMD_SDW_MAX_MANAGER_COUNT];
+};
+
+/**
+ * struct sdw_amd_res - Soundwire AMD global resource structure,
+ * typically populated by the DSP driver/Legacy driver
+ *
+ * @addr: acp pci device resource start address
+ * @reg_range: ACP register range
+ * @link_mask: bit-wise mask listing links selected by the DSP driver/
+ * legacy driver
+ * @count: link count
+ * @mmio_base: mmio base of SoundWire registers
+ * @handle: ACPI parent handle
+ * @parent: parent device
+ * @dev: device implementing hwparams and free callbacks
+ * @acp_lock: mutex protecting acp common registers access
+ */
+struct sdw_amd_res {
+	u32 addr;
+	u32 reg_range;
+	u32 link_mask;
+	int count;
+	void __iomem *mmio_base;
+	acpi_handle handle;
+	struct device *parent;
+	struct device *dev;
+	/* use to protect acp common registers access */
+	struct mutex *acp_lock;
+};
+
+int sdw_amd_probe(struct sdw_amd_res *res, struct sdw_amd_ctx **ctx);
+
+void sdw_amd_exit(struct sdw_amd_ctx *ctx);
+
 int amd_sdw_scan_controller(struct sdw_amd_acpi_info *info);
 #endif
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 03/12] drivers: soundwire: implement function to extract slave information
  2023-12-21  7:35 [PATCH 00/12] soundwire/SOF: add SoundWire Interface support for AMD SOF stack Vijendar Mukunda
  2023-12-21  7:35 ` [PATCH 01/12] ASoC/soundwire: implement generic api for scanning amd soundwire controller Vijendar Mukunda
  2023-12-21  7:35 ` [PATCH 02/12] drivers: soundwire: refactor amd soundwire manager device node creation Vijendar Mukunda
@ 2023-12-21  7:35 ` Vijendar Mukunda
  2023-12-21  7:35 ` [PATCH 04/12] drivers: soundwire: refactor soundwire pads enable Vijendar Mukunda
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 24+ messages in thread
From: Vijendar Mukunda @ 2023-12-21  7:35 UTC (permalink / raw)
  To: broonie, vkoul
  Cc: alsa-devel, Basavaraj.Hiregoudar, Sunil-kumar.Dommati,
	pierre-louis.bossart, vinod.koul, venkataprasad.potturu,
	Vijendar Mukunda, Bard Liao, Sanyog Kale, open list

Implement function to extract slaves information connected on the bus.
This information is required during machine select logic.
This function will be called from machine select logic code.

Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
---
 drivers/soundwire/amd_init.c      | 43 +++++++++++++++++++++++++++++++
 include/linux/soundwire/sdw_amd.h |  2 ++
 2 files changed, 45 insertions(+)

diff --git a/drivers/soundwire/amd_init.c b/drivers/soundwire/amd_init.c
index d732ab0bfd59..5c9569d9ad01 100644
--- a/drivers/soundwire/amd_init.c
+++ b/drivers/soundwire/amd_init.c
@@ -142,6 +142,49 @@ void sdw_amd_exit(struct sdw_amd_ctx *ctx)
 }
 EXPORT_SYMBOL_NS(sdw_amd_exit, SOUNDWIRE_AMD_INIT);
 
+int sdw_amd_get_slave_info(struct sdw_amd_ctx *ctx)
+{
+	struct amd_sdw_manager *amd_manager;
+	struct sdw_bus *bus;
+	struct sdw_slave *slave;
+	struct list_head *node;
+	int index;
+	int i = 0;
+	int num_slaves = 0;
+
+	for (index = 0; index < ctx->count; index++) {
+		if (!(ctx->link_mask & BIT(index)))
+			continue;
+		amd_manager = dev_get_drvdata(&ctx->pdev[index]->dev);
+		if (!amd_manager)
+			return -ENODEV;
+		bus = &amd_manager->bus;
+		/* Calculate number of slaves */
+		list_for_each(node, &bus->slaves)
+			num_slaves++;
+	}
+
+	ctx->ids = kcalloc(num_slaves, sizeof(*ctx->ids), GFP_KERNEL);
+	if (!ctx->ids)
+		return -ENOMEM;
+	ctx->num_slaves = num_slaves;
+	for (index = 0; index < ctx->count; index++) {
+		if (!(ctx->link_mask & BIT(index)))
+			continue;
+		amd_manager = dev_get_drvdata(&ctx->pdev[index]->dev);
+		if (amd_manager) {
+			bus = &amd_manager->bus;
+			list_for_each_entry(slave, &bus->slaves, node) {
+				ctx->ids[i].id = slave->id;
+				ctx->ids[i].link_id = bus->link_id;
+				i++;
+			}
+		}
+	}
+	return 0;
+}
+EXPORT_SYMBOL_NS(sdw_amd_get_slave_info, SOUNDWIRE_AMD_INIT);
+
 MODULE_AUTHOR("Vijendar.Mukunda@amd.com");
 MODULE_DESCRIPTION("AMD SoundWire Init Library");
 MODULE_LICENSE("Dual BSD/GPL");
diff --git a/include/linux/soundwire/sdw_amd.h b/include/linux/soundwire/sdw_amd.h
index 064174c2f401..47b6cea356ff 100644
--- a/include/linux/soundwire/sdw_amd.h
+++ b/include/linux/soundwire/sdw_amd.h
@@ -170,5 +170,7 @@ int sdw_amd_probe(struct sdw_amd_res *res, struct sdw_amd_ctx **ctx);
 
 void sdw_amd_exit(struct sdw_amd_ctx *ctx);
 
+int sdw_amd_get_slave_info(struct sdw_amd_ctx *ctx);
+
 int amd_sdw_scan_controller(struct sdw_amd_acpi_info *info);
 #endif
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 04/12] drivers: soundwire: refactor soundwire pads enable
  2023-12-21  7:35 [PATCH 00/12] soundwire/SOF: add SoundWire Interface support for AMD SOF stack Vijendar Mukunda
                   ` (2 preceding siblings ...)
  2023-12-21  7:35 ` [PATCH 03/12] drivers: soundwire: implement function to extract slave information Vijendar Mukunda
@ 2023-12-21  7:35 ` Vijendar Mukunda
  2023-12-21 16:38   ` Vinod Koul
  2023-12-21  7:35 ` [PATCH 05/12] drivers: soundwire: refactor register mask structure Vijendar Mukunda
                   ` (9 subsequent siblings)
  13 siblings, 1 reply; 24+ messages in thread
From: Vijendar Mukunda @ 2023-12-21  7:35 UTC (permalink / raw)
  To: broonie, vkoul
  Cc: alsa-devel, Basavaraj.Hiregoudar, Sunil-kumar.Dommati,
	pierre-louis.bossart, vinod.koul, venkataprasad.potturu,
	Vijendar Mukunda, Bard Liao, Sanyog Kale, open list

As sdw pads enable sequence is executed only once, invoke it
from probe sequence.

Program required pads for both manager instances
based on link_mask during probe sequence. This will avoid
acquiring mutex lock.
Remove unnecessary delay after programming ACP_SW_PAD_KEEPER_EN
register.

Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
---
 drivers/soundwire/amd_init.c    | 45 +++++++++++++++++++++++++++++++++
 drivers/soundwire/amd_manager.c | 18 -------------
 2 files changed, 45 insertions(+), 18 deletions(-)

diff --git a/drivers/soundwire/amd_init.c b/drivers/soundwire/amd_init.c
index 5c9569d9ad01..b3b3c7266384 100644
--- a/drivers/soundwire/amd_init.c
+++ b/drivers/soundwire/amd_init.c
@@ -15,6 +15,47 @@
 
 #include "amd_init.h"
 
+#define ACP_PAD_PULLDOWN_CTRL				0x0001448
+#define ACP_SW_PAD_KEEPER_EN				0x0001454
+#define AMD_SDW_PAD_PULLDOWN_CTRL_ENABLE_MASK		0x7f9a
+#define AMD_SDW0_PAD_PULLDOWN_CTRL_ENABLE_MASK		0x7f9f
+#define AMD_SDW1_PAD_PULLDOWN_CTRL_ENABLE_MASK		0x7ffa
+#define AMD_SDW0_PAD_EN_MASK				1
+#define AMD_SDW1_PAD_EN_MASK				0x10
+#define AMD_SDW_PAD_EN_MASK	(AMD_SDW0_PAD_EN_MASK | AMD_SDW1_PAD_EN_MASK)
+
+static int amd_enable_sdw_pads(void __iomem *mmio, u32 link_mask, struct device *dev)
+{
+	u32 val;
+	u32 pad_keeper_en_mask, pad_pulldown_ctrl_mask;
+
+	switch (link_mask) {
+	case 1:
+		pad_keeper_en_mask = AMD_SDW0_PAD_EN_MASK;
+		pad_pulldown_ctrl_mask = AMD_SDW0_PAD_PULLDOWN_CTRL_ENABLE_MASK;
+		break;
+	case 2:
+		pad_keeper_en_mask = AMD_SDW1_PAD_EN_MASK;
+		pad_pulldown_ctrl_mask = AMD_SDW1_PAD_PULLDOWN_CTRL_ENABLE_MASK;
+		break;
+	case 3:
+		pad_keeper_en_mask = AMD_SDW_PAD_EN_MASK;
+		pad_pulldown_ctrl_mask = AMD_SDW_PAD_PULLDOWN_CTRL_ENABLE_MASK;
+		break;
+	default:
+		dev_err(dev, "No SDW Links are enabled\n");
+		return -ENODEV;
+	}
+
+	val = readl(mmio + ACP_SW_PAD_KEEPER_EN);
+	val |= pad_keeper_en_mask;
+	writel(val, mmio + ACP_SW_PAD_KEEPER_EN);
+	val = readl(mmio + ACP_PAD_PULLDOWN_CTRL);
+	val &= pad_pulldown_ctrl_mask;
+	writel(val, mmio + ACP_PAD_PULLDOWN_CTRL);
+	return 0;
+}
+
 static int sdw_amd_cleanup(struct sdw_amd_ctx *ctx)
 {
 	int i;
@@ -37,6 +78,7 @@ static struct sdw_amd_ctx *sdw_amd_probe_controller(struct sdw_amd_res *res)
 	struct platform_device_info pdevinfo[2];
 	u32 link_mask;
 	int count, index;
+	int ret;
 
 	if (!res)
 		return NULL;
@@ -50,6 +92,9 @@ static struct sdw_amd_ctx *sdw_amd_probe_controller(struct sdw_amd_res *res)
 
 	count = res->count;
 	dev_dbg(&adev->dev, "Creating %d SDW Link devices\n", count);
+	ret = amd_enable_sdw_pads(res->mmio_base, res->link_mask, res->parent);
+	if (ret)
+		return NULL;
 
 	/*
 	 * we need to alloc/free memory manually and can't use devm:
diff --git a/drivers/soundwire/amd_manager.c b/drivers/soundwire/amd_manager.c
index c27b0b0f33a6..1427cccfc309 100644
--- a/drivers/soundwire/amd_manager.c
+++ b/drivers/soundwire/amd_manager.c
@@ -26,23 +26,6 @@
 
 #define to_amd_sdw(b)	container_of(b, struct amd_sdw_manager, bus)
 
-static void amd_enable_sdw_pads(struct amd_sdw_manager *amd_manager)
-{
-	u32 sw_pad_pulldown_val;
-	u32 val;
-
-	mutex_lock(amd_manager->acp_sdw_lock);
-	val = readl(amd_manager->acp_mmio + ACP_SW_PAD_KEEPER_EN);
-	val |= amd_manager->reg_mask->sw_pad_enable_mask;
-	writel(val, amd_manager->acp_mmio + ACP_SW_PAD_KEEPER_EN);
-	usleep_range(1000, 1500);
-
-	sw_pad_pulldown_val = readl(amd_manager->acp_mmio + ACP_PAD_PULLDOWN_CTRL);
-	sw_pad_pulldown_val &= amd_manager->reg_mask->sw_pad_pulldown_mask;
-	writel(sw_pad_pulldown_val, amd_manager->acp_mmio + ACP_PAD_PULLDOWN_CTRL);
-	mutex_unlock(amd_manager->acp_sdw_lock);
-}
-
 static int amd_init_sdw_manager(struct amd_sdw_manager *amd_manager)
 {
 	u32 val;
@@ -872,7 +855,6 @@ int amd_sdw_manager_start(struct amd_sdw_manager *amd_manager)
 
 	prop = &amd_manager->bus.prop;
 	if (!prop->hw_disabled) {
-		amd_enable_sdw_pads(amd_manager);
 		ret = amd_init_sdw_manager(amd_manager);
 		if (ret)
 			return ret;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 05/12] drivers: soundwire: refactor register mask structure
  2023-12-21  7:35 [PATCH 00/12] soundwire/SOF: add SoundWire Interface support for AMD SOF stack Vijendar Mukunda
                   ` (3 preceding siblings ...)
  2023-12-21  7:35 ` [PATCH 04/12] drivers: soundwire: refactor soundwire pads enable Vijendar Mukunda
@ 2023-12-21  7:35 ` Vijendar Mukunda
  2023-12-21  7:35 ` [PATCH 06/12] ASoC: SOF: amd: add code for invoking soundwire manager helper functions Vijendar Mukunda
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 24+ messages in thread
From: Vijendar Mukunda @ 2023-12-21  7:35 UTC (permalink / raw)
  To: broonie, vkoul
  Cc: alsa-devel, Basavaraj.Hiregoudar, Sunil-kumar.Dommati,
	pierre-louis.bossart, vinod.koul, venkataprasad.potturu,
	Vijendar Mukunda, Bard Liao, Sanyog Kale, open list

register mask array structure is no longer needed as except
interrupt control masks, rest of the register masks are not
used in code.

use array for interrupt masks instead of structure.

Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
---
 drivers/soundwire/amd_manager.c   |  7 ++-----
 drivers/soundwire/amd_manager.h   | 12 ++----------
 include/linux/soundwire/sdw_amd.h |  8 --------
 3 files changed, 4 insertions(+), 23 deletions(-)

diff --git a/drivers/soundwire/amd_manager.c b/drivers/soundwire/amd_manager.c
index 1427cccfc309..36dab5099989 100644
--- a/drivers/soundwire/amd_manager.c
+++ b/drivers/soundwire/amd_manager.c
@@ -86,12 +86,11 @@ static int amd_disable_sdw_manager(struct amd_sdw_manager *amd_manager)
 
 static void amd_enable_sdw_interrupts(struct amd_sdw_manager *amd_manager)
 {
-	struct sdw_manager_reg_mask *reg_mask = amd_manager->reg_mask;
 	u32 val;
 
 	mutex_lock(amd_manager->acp_sdw_lock);
 	val = readl(amd_manager->acp_mmio + ACP_EXTERNAL_INTR_CNTL(amd_manager->instance));
-	val |= reg_mask->acp_sdw_intr_mask;
+	val |= sdw_manager_reg_mask_array[amd_manager->instance];
 	writel(val, amd_manager->acp_mmio + ACP_EXTERNAL_INTR_CNTL(amd_manager->instance));
 	mutex_unlock(amd_manager->acp_sdw_lock);
 
@@ -104,12 +103,11 @@ static void amd_enable_sdw_interrupts(struct amd_sdw_manager *amd_manager)
 
 static void amd_disable_sdw_interrupts(struct amd_sdw_manager *amd_manager)
 {
-	struct sdw_manager_reg_mask *reg_mask = amd_manager->reg_mask;
 	u32 val;
 
 	mutex_lock(amd_manager->acp_sdw_lock);
 	val = readl(amd_manager->acp_mmio + ACP_EXTERNAL_INTR_CNTL(amd_manager->instance));
-	val &= ~reg_mask->acp_sdw_intr_mask;
+	val &= ~sdw_manager_reg_mask_array[amd_manager->instance];
 	writel(val, amd_manager->acp_mmio + ACP_EXTERNAL_INTR_CNTL(amd_manager->instance));
 	mutex_unlock(amd_manager->acp_sdw_lock);
 
@@ -922,7 +920,6 @@ static int amd_sdw_manager_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	amd_manager->reg_mask = &sdw_manager_reg_mask_array[amd_manager->instance];
 	params = &amd_manager->bus.params;
 	params->max_dr_freq = AMD_SDW_DEFAULT_CLK_FREQ * 2;
 	params->curr_dr_freq = AMD_SDW_DEFAULT_CLK_FREQ * 2;
diff --git a/drivers/soundwire/amd_manager.h b/drivers/soundwire/amd_manager.h
index 5f040151a259..82c3183ab215 100644
--- a/drivers/soundwire/amd_manager.h
+++ b/drivers/soundwire/amd_manager.h
@@ -243,16 +243,8 @@ static struct sdw_manager_dp_reg sdw1_manager_dp_reg[AMD_SDW1_MAX_DAI] =  {
 	 ACP_SW_AUDIO1_RX_OFFSET, ACP_SW_AUDIO1_RX_CHANNEL_ENABLE_DP0}
 };
 
-static struct sdw_manager_reg_mask sdw_manager_reg_mask_array[2] =  {
-	{
-		AMD_SDW0_PAD_KEEPER_EN_MASK,
-		AMD_SDW0_PAD_PULLDOWN_CTRL_ENABLE_MASK,
-		AMD_SDW0_EXT_INTR_MASK
-	},
-	{
-		AMD_SDW1_PAD_KEEPER_EN_MASK,
-		AMD_SDW1_PAD_PULLDOWN_CTRL_ENABLE_MASK,
+static u32 sdw_manager_reg_mask_array[AMD_SDW_MAX_MANAGER_COUNT] =  {
+		AMD_SDW0_EXT_INTR_MASK,
 		AMD_SDW1_EXT_INTR_MASK
-	}
 };
 #endif
diff --git a/include/linux/soundwire/sdw_amd.h b/include/linux/soundwire/sdw_amd.h
index 47b6cea356ff..56dab6fc9d3a 100644
--- a/include/linux/soundwire/sdw_amd.h
+++ b/include/linux/soundwire/sdw_amd.h
@@ -34,12 +34,6 @@ struct acp_sdw_pdata {
 	struct mutex *acp_sdw_lock;
 };
 
-struct sdw_manager_reg_mask {
-	u32 sw_pad_enable_mask;
-	u32 sw_pad_pulldown_mask;
-	u32 acp_sdw_intr_mask;
-};
-
 /**
  * struct sdw_amd_dai_runtime: AMD sdw dai runtime  data
  *
@@ -61,7 +55,6 @@ struct sdw_amd_dai_runtime {
  * @dev: linux device
  * @mmio: SoundWire registers mmio base
  * @acp_mmio: acp registers mmio base
- * @reg_mask: register mask structure per manager instance
  * @amd_sdw_irq_thread: SoundWire manager irq workqueue
  * @amd_sdw_work: peripheral status work queue
  * @acp_sdw_lock: mutex to protect acp share register access
@@ -84,7 +77,6 @@ struct amd_sdw_manager {
 	void __iomem *mmio;
 	void __iomem *acp_mmio;
 
-	struct sdw_manager_reg_mask *reg_mask;
 	struct work_struct amd_sdw_irq_thread;
 	struct work_struct amd_sdw_work;
 	/* mutex to protect acp common register access */
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 06/12] ASoC: SOF: amd: add code for invoking soundwire manager helper functions
  2023-12-21  7:35 [PATCH 00/12] soundwire/SOF: add SoundWire Interface support for AMD SOF stack Vijendar Mukunda
                   ` (4 preceding siblings ...)
  2023-12-21  7:35 ` [PATCH 05/12] drivers: soundwire: refactor register mask structure Vijendar Mukunda
@ 2023-12-21  7:35 ` Vijendar Mukunda
  2023-12-21  7:35 ` [PATCH 07/12] ASoC: SOF: amd: add interrupt handling for SoundWire manager devices Vijendar Mukunda
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 24+ messages in thread
From: Vijendar Mukunda @ 2023-12-21  7:35 UTC (permalink / raw)
  To: broonie, vkoul
  Cc: alsa-devel, Basavaraj.Hiregoudar, Sunil-kumar.Dommati,
	pierre-louis.bossart, vinod.koul, venkataprasad.potturu,
	Vijendar Mukunda, Liam Girdwood, Peter Ujfalusi, Bard Liao,
	Ranjani Sridharan, Daniel Baluta, Kai Vehmanen, Jaroslav Kysela,
	Takashi Iwai, V sujith kumar Reddy, Mastan Katragadda,
	Rander Wang,
	moderated list:SOUND - SOUND OPEN FIRMWARE (SOF) DRIVERS,
	open list:SOUND - SOC LAYER / DYNAMIC AUDIO POWER MANAGEM...,
	open list

Add code for invoking Soundwire manager helper functions
when SoundWire configuration is selected.

Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
---
 sound/soc/sof/amd/Kconfig | 17 +++++++
 sound/soc/sof/amd/acp.c   | 99 ++++++++++++++++++++++++++++++++++++++-
 sound/soc/sof/amd/acp.h   | 15 +++++-
 3 files changed, 129 insertions(+), 2 deletions(-)

diff --git a/sound/soc/sof/amd/Kconfig b/sound/soc/sof/amd/Kconfig
index 19c5e27a193f..1cea1d75130c 100644
--- a/sound/soc/sof/amd/Kconfig
+++ b/sound/soc/sof/amd/Kconfig
@@ -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
diff --git a/sound/soc/sof/amd/acp.c b/sound/soc/sof/amd/acp.c
index 32a741fcb84f..f24cd6b7490f 100644
--- a/sound/soc/sof/amd/acp.c
+++ b/sound/soc/sof/amd/acp.c
@@ -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);
@@ -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) {
@@ -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;
 
@@ -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);
 
@@ -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");
diff --git a/sound/soc/sof/amd/acp.h b/sound/soc/sof/amd/acp.h
index c645aee216fd..e88d01330ec7 100644
--- a/sound/soc/sof/amd/acp.h
+++ b/sound/soc/sof/amd/acp.h
@@ -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"
 
@@ -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 */
@@ -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;
@@ -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;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 07/12] ASoC: SOF: amd: add interrupt handling for SoundWire manager devices
  2023-12-21  7:35 [PATCH 00/12] soundwire/SOF: add SoundWire Interface support for AMD SOF stack Vijendar Mukunda
                   ` (5 preceding siblings ...)
  2023-12-21  7:35 ` [PATCH 06/12] ASoC: SOF: amd: add code for invoking soundwire manager helper functions Vijendar Mukunda
@ 2023-12-21  7:35 ` Vijendar Mukunda
  2023-12-21  7:35 ` [PATCH 08/12] ASoC: SOF: amd: Add Soundwire DAI configuration support for AMD platforms Vijendar Mukunda
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 24+ messages in thread
From: Vijendar Mukunda @ 2023-12-21  7:35 UTC (permalink / raw)
  To: broonie, vkoul
  Cc: alsa-devel, Basavaraj.Hiregoudar, Sunil-kumar.Dommati,
	pierre-louis.bossart, vinod.koul, venkataprasad.potturu,
	Vijendar Mukunda, Liam Girdwood, Peter Ujfalusi, Bard Liao,
	Ranjani Sridharan, Daniel Baluta, Kai Vehmanen, Jaroslav Kysela,
	Takashi Iwai, V sujith kumar Reddy, Mastan Katragadda,
	Rander Wang,
	moderated list:SOUND - SOUND OPEN FIRMWARE (SOF) DRIVERS,
	open list:SOUND - SOC LAYER / DYNAMIC AUDIO POWER MANAGEM...,
	open list

Add support for interrupt handling for soundwire manager platform
devices.

Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
---
 sound/soc/sof/amd/acp-dsp-offset.h |  4 ++++
 sound/soc/sof/amd/acp.c            | 38 +++++++++++++++++++++++++++++-
 sound/soc/sof/amd/acp.h            |  5 ++++
 3 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/sound/soc/sof/amd/acp-dsp-offset.h b/sound/soc/sof/amd/acp-dsp-offset.h
index a913f1cc4c80..7ba6492b8e99 100644
--- a/sound/soc/sof/amd/acp-dsp-offset.h
+++ b/sound/soc/sof/amd/acp-dsp-offset.h
@@ -78,6 +78,10 @@
 #define ACP5X_AXI2DAGB_SEM_0			0x1884
 #define ACP6X_AXI2DAGB_SEM_0			0x1874
 
+/* ACP common registers to report errors related to I2S & SoundWire interfaces */
+#define ACP_SW0_I2S_ERROR_REASON		0x18B4
+#define ACP_SW1_I2S_ERROR_REASON		0x1A50
+
 /* Registers from ACP_SHA block */
 #define ACP_SHA_DSP_FW_QUALIFIER		0x1C70
 #define ACP_SHA_DMA_CMD				0x1CB0
diff --git a/sound/soc/sof/amd/acp.c b/sound/soc/sof/amd/acp.c
index f24cd6b7490f..7a34faae9889 100644
--- a/sound/soc/sof/amd/acp.c
+++ b/sound/soc/sof/amd/acp.c
@@ -375,10 +375,13 @@ static irqreturn_t acp_irq_thread(int irq, void *context)
 
 static irqreturn_t acp_irq_handler(int irq, void *dev_id)
 {
+	struct amd_sdw_manager *amd_manager;
 	struct snd_sof_dev *sdev = dev_id;
 	const struct sof_amd_acp_desc *desc = get_chip_info(sdev->pdata);
+	struct acp_dev_data *adata = sdev->pdata->hw_pdata;
 	unsigned int base = desc->dsp_intr_base;
 	unsigned int val;
+	int irq_flag = 0;
 
 	val = snd_sof_dsp_read(sdev, ACP_DSP_BAR, base + DSP_SW_INTR_STAT_OFFSET);
 	if (val & ACP_DSP_TO_HOST_IRQ) {
@@ -387,7 +390,38 @@ static irqreturn_t acp_irq_handler(int irq, void *dev_id)
 		return IRQ_WAKE_THREAD;
 	}
 
-	return IRQ_NONE;
+	val = snd_sof_dsp_read(sdev, ACP_DSP_BAR, desc->ext_intr_stat);
+	if (val & ACP_SDW0_IRQ_MASK) {
+		amd_manager = dev_get_drvdata(&adata->sdw->pdev[0]->dev);
+		snd_sof_dsp_write(sdev, ACP_DSP_BAR, desc->ext_intr_stat, ACP_SDW0_IRQ_MASK);
+		if (amd_manager)
+			schedule_work(&amd_manager->amd_sdw_irq_thread);
+		irq_flag = 1;
+	}
+
+	if (val & ACP_ERROR_IRQ_MASK) {
+		snd_sof_dsp_write(sdev, ACP_DSP_BAR, desc->ext_intr_stat, ACP_ERROR_IRQ_MASK);
+		snd_sof_dsp_write(sdev, ACP_DSP_BAR, base + ACP_SW0_I2S_ERROR_REASON, 0);
+		snd_sof_dsp_write(sdev, ACP_DSP_BAR, base + ACP_SW1_I2S_ERROR_REASON, 0);
+		snd_sof_dsp_write(sdev, ACP_DSP_BAR, base + ACP_ERROR_STATUS, 0);
+		irq_flag = 1;
+	}
+
+	if (desc->ext_intr_stat1) {
+		val = snd_sof_dsp_read(sdev, ACP_DSP_BAR, desc->ext_intr_stat1);
+		if (val & ACP_SDW1_IRQ_MASK) {
+			amd_manager = dev_get_drvdata(&adata->sdw->pdev[1]->dev);
+			snd_sof_dsp_write(sdev, ACP_DSP_BAR, desc->ext_intr_stat1,
+					  ACP_SDW1_IRQ_MASK);
+			if (amd_manager)
+				schedule_work(&amd_manager->amd_sdw_irq_thread);
+			irq_flag = 1;
+		}
+	}
+	if (irq_flag)
+		return IRQ_HANDLED;
+	else
+		return IRQ_NONE;
 }
 
 static int acp_power_on(struct snd_sof_dev *sdev)
@@ -443,6 +477,8 @@ static int acp_reset(struct snd_sof_dev *sdev)
 	if (desc->ext_intr_enb)
 		snd_sof_dsp_write(sdev, ACP_DSP_BAR, desc->ext_intr_enb, 0x01);
 
+	if (desc->ext_intr_cntl)
+		snd_sof_dsp_write(sdev, ACP_DSP_BAR, desc->ext_intr_cntl, ACP_ERROR_IRQ_MASK);
 	return ret;
 }
 
diff --git a/sound/soc/sof/amd/acp.h b/sound/soc/sof/amd/acp.h
index e88d01330ec7..2058dae32659 100644
--- a/sound/soc/sof/amd/acp.h
+++ b/sound/soc/sof/amd/acp.h
@@ -93,6 +93,9 @@
 #define PROBE_STATUS_BIT			BIT(31)
 
 #define ACP_FIRMWARE_SIGNATURE			0x100
+#define ACP_ERROR_IRQ_MASK			BIT(29)
+#define ACP_SDW0_IRQ_MASK			BIT(21)
+#define ACP_SDW1_IRQ_MASK			BIT(2)
 #define ACP_DEFAULT_SRAM_LENGTH			0x00080000
 #define ACP_SRAM_PAGE_COUNT			128
 
@@ -184,7 +187,9 @@ struct sof_amd_acp_desc {
 	unsigned int host_bridge_id;
 	u32 pgfsm_base;
 	u32 ext_intr_enb;
+	u32 ext_intr_cntl;
 	u32 ext_intr_stat;
+	u32 ext_intr_stat1;
 	u32 dsp_intr_base;
 	u32 sram_pte_offset;
 	u32 hw_semaphore_offset;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 08/12] ASoC: SOF: amd: Add Soundwire DAI configuration support for AMD platforms
  2023-12-21  7:35 [PATCH 00/12] soundwire/SOF: add SoundWire Interface support for AMD SOF stack Vijendar Mukunda
                   ` (6 preceding siblings ...)
  2023-12-21  7:35 ` [PATCH 07/12] ASoC: SOF: amd: add interrupt handling for SoundWire manager devices Vijendar Mukunda
@ 2023-12-21  7:35 ` Vijendar Mukunda
  2023-12-21  7:35 ` [PATCH 09/12] ASoC: SOF: amd: add machine select logic for soundwire based platforms Vijendar Mukunda
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 24+ messages in thread
From: Vijendar Mukunda @ 2023-12-21  7:35 UTC (permalink / raw)
  To: broonie, vkoul
  Cc: alsa-devel, Basavaraj.Hiregoudar, Sunil-kumar.Dommati,
	pierre-louis.bossart, vinod.koul, venkataprasad.potturu,
	Vijendar Mukunda, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
	Peter Ujfalusi, Bard Liao, Ranjani Sridharan, Daniel Baluta,
	Kai Vehmanen, Rander Wang, Jyri Sarha, Curtis Malainey,
	open list:SOUND - SOC LAYER / DYNAMIC AUDIO POWER MANAGEM...,
	open list,
	moderated list:SOUND - SOUND OPEN FIRMWARE (SOF) DRIVERS

Add support for configuring AMD Soundwire DAI from topology.

Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
---
 include/sound/sof/dai-amd.h     |  7 ++++++
 include/sound/sof/dai.h         |  2 ++
 include/uapi/sound/sof/tokens.h |  4 ++++
 sound/soc/sof/ipc3-pcm.c        | 25 +++++++++++++++++++++
 sound/soc/sof/ipc3-topology.c   | 40 +++++++++++++++++++++++++++++++++
 sound/soc/sof/sof-audio.h       |  1 +
 sound/soc/sof/topology.c        |  5 +++++
 7 files changed, 84 insertions(+)

diff --git a/include/sound/sof/dai-amd.h b/include/sound/sof/dai-amd.h
index 9df7ac824efe..59cd014392c1 100644
--- a/include/sound/sof/dai-amd.h
+++ b/include/sound/sof/dai-amd.h
@@ -26,4 +26,11 @@ struct sof_ipc_dai_acpdmic_params {
 	uint32_t pdm_ch;
 } __packed;
 
+/* ACP_SDW Configuration Request - SOF_IPC_DAI_AMD_SDW_CONFIG */
+struct sof_ipc_dai_acp_sdw_params {
+	struct sof_ipc_hdr hdr;
+	u32 rate;
+	u32 channels;
+} __packed;
+
 #endif
diff --git a/include/sound/sof/dai.h b/include/sound/sof/dai.h
index 4773a5f616a4..0764a80c17a9 100644
--- a/include/sound/sof/dai.h
+++ b/include/sound/sof/dai.h
@@ -89,6 +89,7 @@ enum sof_ipc_dai_type {
 	SOF_DAI_AMD_SP_VIRTUAL,		/**< AMD ACP SP VIRTUAL */
 	SOF_DAI_AMD_HS_VIRTUAL,		/**< AMD ACP HS VIRTUAL */
 	SOF_DAI_IMX_MICFIL,		/** < i.MX MICFIL PDM */
+	SOF_DAI_AMD_SDW,		/**< AMD ACP SDW */
 };
 
 /* general purpose DAI configuration */
@@ -119,6 +120,7 @@ struct sof_ipc_dai_config {
 		struct sof_ipc_dai_acp_params acphs;
 		struct sof_ipc_dai_mtk_afe_params afe;
 		struct sof_ipc_dai_micfil_params micfil;
+		struct sof_ipc_dai_acp_sdw_params acp_sdw;
 	};
 } __packed;
 
diff --git a/include/uapi/sound/sof/tokens.h b/include/uapi/sound/sof/tokens.h
index ee5708934614..6bf00c09d30d 100644
--- a/include/uapi/sound/sof/tokens.h
+++ b/include/uapi/sound/sof/tokens.h
@@ -218,4 +218,8 @@
 #define SOF_TKN_IMX_MICFIL_RATE			2000
 #define SOF_TKN_IMX_MICFIL_CH			2001
 
+/* ACP SDW */
+#define SOF_TKN_AMD_ACP_SDW_RATE		2100
+#define SOF_TKN_AMD_ACP_SDW_CH			2101
+
 #endif
diff --git a/sound/soc/sof/ipc3-pcm.c b/sound/soc/sof/ipc3-pcm.c
index 330f04bcd75d..35769dd7905e 100644
--- a/sound/soc/sof/ipc3-pcm.c
+++ b/sound/soc/sof/ipc3-pcm.c
@@ -395,6 +395,31 @@ static int sof_ipc3_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd,
 		dev_dbg(component->dev, "MICFIL PDM channels_min: %d channels_max: %d\n",
 			channels->min, channels->max);
 		break;
+	case SOF_DAI_AMD_SDW:
+		/* change the default trigger sequence as per HW implementation */
+		for_each_dpcm_fe(rtd, SNDRV_PCM_STREAM_PLAYBACK, dpcm) {
+			struct snd_soc_pcm_runtime *fe = dpcm->fe;
+
+			fe->dai_link->trigger[SNDRV_PCM_STREAM_PLAYBACK] =
+					SND_SOC_DPCM_TRIGGER_POST;
+		}
+
+		for_each_dpcm_fe(rtd, SNDRV_PCM_STREAM_CAPTURE, dpcm) {
+			struct snd_soc_pcm_runtime *fe = dpcm->fe;
+
+			fe->dai_link->trigger[SNDRV_PCM_STREAM_CAPTURE] =
+					SND_SOC_DPCM_TRIGGER_POST;
+		}
+		rate->min = private->dai_config->acp_sdw.rate;
+		rate->max = private->dai_config->acp_sdw.rate;
+		channels->min = private->dai_config->acp_sdw.channels;
+		channels->max = private->dai_config->acp_sdw.channels;
+
+		dev_dbg(component->dev,
+			"AMD_SDW rate_min: %d rate_max: %d\n", rate->min, rate->max);
+		dev_dbg(component->dev, "AMD_SDW channels_min: %d channels_max: %d\n",
+			channels->min, channels->max);
+		break;
 	default:
 		dev_err(component->dev, "Invalid DAI type %d\n", private->dai_config->type);
 		break;
diff --git a/sound/soc/sof/ipc3-topology.c b/sound/soc/sof/ipc3-topology.c
index a8832a1c1a24..0970dbdfa78a 100644
--- a/sound/soc/sof/ipc3-topology.c
+++ b/sound/soc/sof/ipc3-topology.c
@@ -298,6 +298,14 @@ static const struct sof_topology_token micfil_pdm_tokens[] = {
 		offsetof(struct sof_ipc_dai_micfil_params, pdm_ch)},
 };
 
+/* ACP_SDW */
+static const struct sof_topology_token acp_sdw_tokens[] = {
+	{SOF_TKN_AMD_ACP_SDW_RATE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
+		offsetof(struct sof_ipc_dai_acp_sdw_params, rate)},
+	{SOF_TKN_AMD_ACP_SDW_CH, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
+		offsetof(struct sof_ipc_dai_acp_sdw_params, channels)},
+};
+
 /* Core tokens */
 static const struct sof_topology_token core_tokens[] = {
 	{SOF_TKN_COMP_CORE_ID, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
@@ -336,6 +344,7 @@ static const struct sof_token_info ipc3_token_list[SOF_TOKEN_COUNT] = {
 	[SOF_ACPI2S_TOKENS]   = {"ACPI2S tokens", acpi2s_tokens, ARRAY_SIZE(acpi2s_tokens)},
 	[SOF_MICFIL_TOKENS] = {"MICFIL PDM tokens",
 		micfil_pdm_tokens, ARRAY_SIZE(micfil_pdm_tokens)},
+	[SOF_ACP_SDW_TOKENS]   = {"ACP_SDW tokens", acp_sdw_tokens, ARRAY_SIZE(acp_sdw_tokens)},
 };
 
 /**
@@ -1315,6 +1324,34 @@ static int sof_link_acp_hs_load(struct snd_soc_component *scomp, struct snd_sof_
 	return 0;
 }
 
+static int sof_link_acp_sdw_load(struct snd_soc_component *scomp, struct snd_sof_dai_link *slink,
+				 struct sof_ipc_dai_config *config, struct snd_sof_dai *dai)
+{
+	struct sof_dai_private_data *private = dai->private;
+	u32 size = sizeof(*config);
+	int ret;
+
+	/* parse the required set of ACP_SDW tokens based on num_hw_cfgs */
+	ret = sof_update_ipc_object(scomp, &config->acp_sdw, SOF_ACP_SDW_TOKENS, slink->tuples,
+				    slink->num_tuples, size, slink->num_hw_configs);
+	if (ret < 0)
+		return ret;
+
+	/* init IPC */
+	config->hdr.size = size;
+	dev_dbg(scomp->dev, "ACP SDW config rate %d channels %d\n",
+		config->acp_sdw.rate, config->acp_sdw.channels);
+
+	/* set config for all DAI's with name matching the link name */
+	dai->number_configs = 1;
+	dai->current_config = 0;
+	private->dai_config = kmemdup(config, size, GFP_KERNEL);
+	if (!private->dai_config)
+		return -ENOMEM;
+
+	return 0;
+}
+
 static int sof_link_afe_load(struct snd_soc_component *scomp, struct snd_sof_dai_link *slink,
 			     struct sof_ipc_dai_config *config, struct snd_sof_dai *dai)
 {
@@ -1629,6 +1666,9 @@ static int sof_ipc3_widget_setup_comp_dai(struct snd_sof_widget *swidget)
 		case SOF_DAI_MEDIATEK_AFE:
 			ret = sof_link_afe_load(scomp, slink, config, dai);
 			break;
+		case SOF_DAI_AMD_SDW:
+			ret = sof_link_acp_sdw_load(scomp, slink, config, dai);
+			break;
 		default:
 			break;
 		}
diff --git a/sound/soc/sof/sof-audio.h b/sound/soc/sof/sof-audio.h
index 8874ee5f557f..f98242a404db 100644
--- a/sound/soc/sof/sof-audio.h
+++ b/sound/soc/sof/sof-audio.h
@@ -276,6 +276,7 @@ enum sof_tokens {
 	SOF_ACPDMIC_TOKENS,
 	SOF_ACPI2S_TOKENS,
 	SOF_MICFIL_TOKENS,
+	SOF_ACP_SDW_TOKENS,
 
 	/* this should be the last */
 	SOF_TOKEN_COUNT,
diff --git a/sound/soc/sof/topology.c b/sound/soc/sof/topology.c
index 617a225fff24..25fb0d1443b6 100644
--- a/sound/soc/sof/topology.c
+++ b/sound/soc/sof/topology.c
@@ -297,6 +297,7 @@ static const struct sof_dai_types sof_dais[] = {
 	{"ACPSP_VIRTUAL", SOF_DAI_AMD_SP_VIRTUAL},
 	{"ACPHS_VIRTUAL", SOF_DAI_AMD_HS_VIRTUAL},
 	{"MICFIL", SOF_DAI_IMX_MICFIL},
+	{"ACP_SDW", SOF_DAI_AMD_SDW},
 
 };
 
@@ -1968,6 +1969,10 @@ static int sof_link_load(struct snd_soc_component *scomp, int index, struct snd_
 		token_id = SOF_MICFIL_TOKENS;
 		num_tuples += token_list[SOF_MICFIL_TOKENS].count;
 		break;
+	case SOF_DAI_AMD_SDW:
+		token_id = SOF_ACP_SDW_TOKENS;
+		num_tuples += token_list[SOF_ACP_SDW_TOKENS].count;
+		break;
 	default:
 		break;
 	}
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 09/12] ASoC: SOF: amd: add machine select logic for soundwire based platforms
  2023-12-21  7:35 [PATCH 00/12] soundwire/SOF: add SoundWire Interface support for AMD SOF stack Vijendar Mukunda
                   ` (7 preceding siblings ...)
  2023-12-21  7:35 ` [PATCH 08/12] ASoC: SOF: amd: Add Soundwire DAI configuration support for AMD platforms Vijendar Mukunda
@ 2023-12-21  7:35 ` Vijendar Mukunda
  2023-12-21  7:35 ` [PATCH 10/12] ASoC: SOF: amd: update descriptor fields for acp6.3 based platform Vijendar Mukunda
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 24+ messages in thread
From: Vijendar Mukunda @ 2023-12-21  7:35 UTC (permalink / raw)
  To: broonie, vkoul
  Cc: alsa-devel, Basavaraj.Hiregoudar, Sunil-kumar.Dommati,
	pierre-louis.bossart, vinod.koul, venkataprasad.potturu,
	Vijendar Mukunda, Liam Girdwood, Peter Ujfalusi, Bard Liao,
	Ranjani Sridharan, Daniel Baluta, Kai Vehmanen, Jaroslav Kysela,
	Takashi Iwai, V sujith kumar Reddy, Wang Jinchao,
	moderated list:SOUND - SOUND OPEN FIRMWARE (SOF) DRIVERS,
	open list:SOUND - SOC LAYER / DYNAMIC AUDIO POWER MANAGEM...,
	open list

Add machine select logic for soundwire endpoints for AMD platforms.

Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
---
 sound/soc/sof/amd/acp-common.c | 65 +++++++++++++++++++++++++++++++---
 1 file changed, 61 insertions(+), 4 deletions(-)

diff --git a/sound/soc/sof/amd/acp-common.c b/sound/soc/sof/amd/acp-common.c
index 2d72c6d55dc8..0fc4e20ec673 100644
--- a/sound/soc/sof/amd/acp-common.c
+++ b/sound/soc/sof/amd/acp-common.c
@@ -118,16 +118,72 @@ void amd_sof_dump(struct snd_sof_dev *sdev, u32 flags)
 				 &panic_info, stack, AMD_STACK_DUMP_SIZE);
 }
 
+#if IS_ENABLED(CONFIG_SND_SOC_SOF_AMD_SOUNDWIRE)
+static int amd_sof_sdw_get_slave_info(struct snd_sof_dev *sdev)
+{
+	struct acp_dev_data *acp_data = sdev->pdata->hw_pdata;
+
+	return sdw_amd_get_slave_info(acp_data->sdw);
+}
+
+static struct snd_soc_acpi_mach *amd_sof_sdw_machine_select(struct snd_sof_dev *sdev)
+{
+	struct snd_soc_acpi_mach *mach;
+	const struct snd_soc_acpi_link_adr *link;
+	struct acp_dev_data *acp_data = sdev->pdata->hw_pdata;
+	int ret, i;
+
+	if (acp_data->info.count) {
+		ret = amd_sof_sdw_get_slave_info(sdev);
+		if (ret) {
+			dev_info(sdev->dev, "failed to read slave information\n");
+			return NULL;
+		}
+		for (mach = sdev->pdata->desc->alt_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(sdev->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;
+			mach->mach_params.platform = dev_name(sdev->dev);
+			return mach;
+		}
+	}
+	dev_info(sdev->dev, "No SoundWire machine driver found\n");
+	return NULL;
+}
+
+#else
+static struct snd_soc_acpi_mach *amd_sof_sdw_machine_select(struct snd_sof_dev *sdev)
+{
+	return NULL;
+}
+#endif
+
 struct snd_soc_acpi_mach *amd_sof_machine_select(struct snd_sof_dev *sdev)
 {
 	struct snd_sof_pdata *sof_pdata = sdev->pdata;
 	const struct sof_dev_desc *desc = sof_pdata->desc;
-	struct snd_soc_acpi_mach *mach;
+	struct snd_soc_acpi_mach *mach = NULL;
 
-	mach = snd_soc_acpi_find_machine(desc->machines);
+	if (desc->machines)
+		mach = snd_soc_acpi_find_machine(desc->machines);
 	if (!mach) {
-		dev_warn(sdev->dev, "No matching ASoC machine driver found\n");
-		return NULL;
+		mach = amd_sof_sdw_machine_select(sdev);
+		if (!mach) {
+			dev_warn(sdev->dev, "No matching ASoC machine driver found\n");
+			return NULL;
+		}
 	}
 
 	sof_pdata->tplg_filename = mach->sof_tplg_filename;
@@ -204,5 +260,6 @@ EXPORT_SYMBOL_NS(sof_acp_common_ops, SND_SOC_SOF_AMD_COMMON);
 
 MODULE_IMPORT_NS(SND_SOC_SOF_AMD_COMMON);
 MODULE_IMPORT_NS(SND_SOC_SOF_XTENSA);
+MODULE_IMPORT_NS(SOUNDWIRE_AMD_INIT);
 MODULE_DESCRIPTION("ACP SOF COMMON Driver");
 MODULE_LICENSE("Dual BSD/GPL");
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 10/12] ASoC: SOF: amd: update descriptor fields for acp6.3 based platform
  2023-12-21  7:35 [PATCH 00/12] soundwire/SOF: add SoundWire Interface support for AMD SOF stack Vijendar Mukunda
                   ` (8 preceding siblings ...)
  2023-12-21  7:35 ` [PATCH 09/12] ASoC: SOF: amd: add machine select logic for soundwire based platforms Vijendar Mukunda
@ 2023-12-21  7:35 ` Vijendar Mukunda
  2023-12-21  7:35 ` [PATCH 11/12] ASoC: SOF: amd: select soundwire dependency flag " Vijendar Mukunda
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 24+ messages in thread
From: Vijendar Mukunda @ 2023-12-21  7:35 UTC (permalink / raw)
  To: broonie, vkoul
  Cc: alsa-devel, Basavaraj.Hiregoudar, Sunil-kumar.Dommati,
	pierre-louis.bossart, vinod.koul, venkataprasad.potturu,
	Vijendar Mukunda, Liam Girdwood, Peter Ujfalusi, Bard Liao,
	Ranjani Sridharan, Daniel Baluta, Kai Vehmanen, Jaroslav Kysela,
	Takashi Iwai, V sujith kumar Reddy, Mastan Katragadda,
	Rander Wang,
	moderated list:SOUND - SOUND OPEN FIRMWARE (SOF) DRIVERS,
	open list:SOUND - SOC LAYER / DYNAMIC AUDIO POWER MANAGEM...,
	open list

Update acp descriptor fields for acp6.3 version based platform.

Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
---
 sound/soc/sof/amd/acp-dsp-offset.h | 3 +++
 sound/soc/sof/amd/acp.h            | 2 ++
 sound/soc/sof/amd/pci-acp63.c      | 7 +++++++
 3 files changed, 12 insertions(+)

diff --git a/sound/soc/sof/amd/acp-dsp-offset.h b/sound/soc/sof/amd/acp-dsp-offset.h
index 7ba6492b8e99..c1bdc028a61a 100644
--- a/sound/soc/sof/amd/acp-dsp-offset.h
+++ b/sound/soc/sof/amd/acp-dsp-offset.h
@@ -65,7 +65,10 @@
 /* Registers from ACP_INTR block */
 #define ACP3X_EXT_INTR_STAT			0x1808
 #define ACP5X_EXT_INTR_STAT			0x1808
+#define ACP6X_EXTERNAL_INTR_ENB			0x1A00
+#define ACP6X_EXTERNAL_INTR_CNTL		0x1A04
 #define ACP6X_EXT_INTR_STAT                     0x1A0C
+#define ACP6X_EXT_INTR_STAT1			0x1A10
 
 #define ACP3X_DSP_SW_INTR_BASE			0x1814
 #define ACP5X_DSP_SW_INTR_BASE			0x1814
diff --git a/sound/soc/sof/amd/acp.h b/sound/soc/sof/amd/acp.h
index 2058dae32659..e94713d7ff1d 100644
--- a/sound/soc/sof/amd/acp.h
+++ b/sound/soc/sof/amd/acp.h
@@ -96,8 +96,10 @@
 #define ACP_ERROR_IRQ_MASK			BIT(29)
 #define ACP_SDW0_IRQ_MASK			BIT(21)
 #define ACP_SDW1_IRQ_MASK			BIT(2)
+#define SDW_ACPI_ADDR_ACP63			5
 #define ACP_DEFAULT_SRAM_LENGTH			0x00080000
 #define ACP_SRAM_PAGE_COUNT			128
+#define ACP6X_SDW_MAX_MANAGER_COUNT		2
 
 enum clock_source {
 	ACP_CLOCK_96M = 0,
diff --git a/sound/soc/sof/amd/pci-acp63.c b/sound/soc/sof/amd/pci-acp63.c
index bceb94ac80a9..eeaa12cceb23 100644
--- a/sound/soc/sof/amd/pci-acp63.c
+++ b/sound/soc/sof/amd/pci-acp63.c
@@ -31,12 +31,19 @@ static const struct sof_amd_acp_desc acp63_chip_info = {
 	.rev		= 6,
 	.host_bridge_id = HOST_BRIDGE_ACP63,
 	.pgfsm_base	= ACP6X_PGFSM_BASE,
+	.ext_intr_enb = ACP6X_EXTERNAL_INTR_ENB,
+	.ext_intr_cntl = ACP6X_EXTERNAL_INTR_CNTL,
 	.ext_intr_stat	= ACP6X_EXT_INTR_STAT,
+	.ext_intr_stat1	= ACP6X_EXT_INTR_STAT1,
 	.dsp_intr_base	= ACP6X_DSP_SW_INTR_BASE,
 	.sram_pte_offset = ACP6X_SRAM_PTE_OFFSET,
 	.hw_semaphore_offset = ACP6X_AXI2DAGB_SEM_0,
 	.fusion_dsp_offset = ACP6X_DSP_FUSION_RUNSTALL,
 	.probe_reg_offset = ACP6X_FUTURE_REG_ACLK_0,
+	.sdw_max_link_count = ACP6X_SDW_MAX_MANAGER_COUNT,
+	.sdw_acpi_dev_addr = SDW_ACPI_ADDR_ACP63,
+	.reg_start_addr = ACP6x_REG_START,
+	.reg_end_addr = ACP6x_REG_END,
 };
 
 static const struct sof_dev_desc acp63_desc = {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 11/12] ASoC: SOF: amd: select soundwire dependency flag for acp6.3 based platform
  2023-12-21  7:35 [PATCH 00/12] soundwire/SOF: add SoundWire Interface support for AMD SOF stack Vijendar Mukunda
                   ` (9 preceding siblings ...)
  2023-12-21  7:35 ` [PATCH 10/12] ASoC: SOF: amd: update descriptor fields for acp6.3 based platform Vijendar Mukunda
@ 2023-12-21  7:35 ` Vijendar Mukunda
  2023-12-21  7:35 ` [PATCH 12/12] ASoC: SOF: amd: refactor acp driver pm ops Vijendar Mukunda
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 24+ messages in thread
From: Vijendar Mukunda @ 2023-12-21  7:35 UTC (permalink / raw)
  To: broonie, vkoul
  Cc: alsa-devel, Basavaraj.Hiregoudar, Sunil-kumar.Dommati,
	pierre-louis.bossart, vinod.koul, venkataprasad.potturu,
	Vijendar Mukunda, Liam Girdwood, Peter Ujfalusi, Bard Liao,
	Ranjani Sridharan, Daniel Baluta, Kai Vehmanen, Jaroslav Kysela,
	Takashi Iwai, V sujith kumar Reddy,
	moderated list:SOUND - SOUND OPEN FIRMWARE (SOF) DRIVERS,
	open list:SOUND - SOC LAYER / DYNAMIC AUDIO POWER MANAGEM...,
	open list

Select SoundWire dependency flag for acp6.3 based platform for SoundWire
configuration.

Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
---
 sound/soc/sof/amd/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sound/soc/sof/amd/Kconfig b/sound/soc/sof/amd/Kconfig
index 1cea1d75130c..c3bbe6c70fb2 100644
--- a/sound/soc/sof/amd/Kconfig
+++ b/sound/soc/sof/amd/Kconfig
@@ -81,6 +81,7 @@ config SND_SOC_SOF_AMD_ACP63
 	tristate "SOF support for ACP6.3 platform"
 	depends on SND_SOC_SOF_PCI
 	select SND_SOC_SOF_AMD_COMMON
+	select SND_SOC_SOF_AMD_SOUNDWIRE_LINK_BASELINE
 	help
 	  Select this option for SOF support on
 	  AMD ACP6.3 version based platforms.
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 12/12] ASoC: SOF: amd: refactor acp driver pm ops
  2023-12-21  7:35 [PATCH 00/12] soundwire/SOF: add SoundWire Interface support for AMD SOF stack Vijendar Mukunda
                   ` (10 preceding siblings ...)
  2023-12-21  7:35 ` [PATCH 11/12] ASoC: SOF: amd: select soundwire dependency flag " Vijendar Mukunda
@ 2023-12-21  7:35 ` Vijendar Mukunda
  2023-12-21  8:27 ` [PATCH 00/12] soundwire/SOF: add SoundWire Interface support for AMD SOF stack Pierre-Louis Bossart
  2024-01-09 12:41 ` Mukunda,Vijendar
  13 siblings, 0 replies; 24+ messages in thread
From: Vijendar Mukunda @ 2023-12-21  7:35 UTC (permalink / raw)
  To: broonie, vkoul
  Cc: alsa-devel, Basavaraj.Hiregoudar, Sunil-kumar.Dommati,
	pierre-louis.bossart, vinod.koul, venkataprasad.potturu,
	Vijendar Mukunda, Liam Girdwood, Peter Ujfalusi, Bard Liao,
	Ranjani Sridharan, Daniel Baluta, Kai Vehmanen, Jaroslav Kysela,
	Takashi Iwai, V sujith kumar Reddy, Mastan Katragadda,
	moderated list:SOUND - SOUND OPEN FIRMWARE (SOF) DRIVERS,
	open list:SOUND - SOC LAYER / DYNAMIC AUDIO POWER MANAGEM...,
	open list

Refactor acp driver pm ops to support SoundWire interface.

When SoundWire configuration is enabled, In case of ClockStopMode,
DSP soft reset should be applied and for rest of the scenarios
acp init/deinit sequence should be invoked.

Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
---
 sound/soc/sof/amd/acp-dsp-offset.h |  3 ++
 sound/soc/sof/amd/acp.c            | 65 +++++++++++++++++++++++++++---
 sound/soc/sof/amd/acp.h            |  4 ++
 3 files changed, 67 insertions(+), 5 deletions(-)

diff --git a/sound/soc/sof/amd/acp-dsp-offset.h b/sound/soc/sof/amd/acp-dsp-offset.h
index c1bdc028a61a..59afbe2e0f42 100644
--- a/sound/soc/sof/amd/acp-dsp-offset.h
+++ b/sound/soc/sof/amd/acp-dsp-offset.h
@@ -103,4 +103,7 @@
 /* Cache window registers */
 #define ACP_DSP0_CACHE_OFFSET0			0x0420
 #define ACP_DSP0_CACHE_SIZE0			0x0424
+
+#define ACP_SW0_EN				0x3000
+#define ACP_SW1_EN				0x3C00
 #endif
diff --git a/sound/soc/sof/amd/acp.c b/sound/soc/sof/amd/acp.c
index 7a34faae9889..920fead2d93d 100644
--- a/sound/soc/sof/amd/acp.c
+++ b/sound/soc/sof/amd/acp.c
@@ -482,6 +482,31 @@ static int acp_reset(struct snd_sof_dev *sdev)
 	return ret;
 }
 
+static int acp_dsp_reset(struct snd_sof_dev *sdev)
+{
+	unsigned int val;
+	int ret;
+
+	snd_sof_dsp_write(sdev, ACP_DSP_BAR, ACP_SOFT_RESET, ACP_DSP_ASSERT_RESET);
+
+	ret = snd_sof_dsp_read_poll_timeout(sdev, ACP_DSP_BAR, ACP_SOFT_RESET, val,
+					    val & ACP_DSP_SOFT_RESET_DONE_MASK,
+					    ACP_REG_POLL_INTERVAL, ACP_REG_POLL_TIMEOUT_US);
+	if (ret < 0) {
+		dev_err(sdev->dev, "timeout asserting reset\n");
+		return ret;
+	}
+
+	snd_sof_dsp_write(sdev, ACP_DSP_BAR, ACP_SOFT_RESET, ACP_DSP_RELEASE_RESET);
+
+	ret = snd_sof_dsp_read_poll_timeout(sdev, ACP_DSP_BAR, ACP_SOFT_RESET, val, !val,
+					    ACP_REG_POLL_INTERVAL, ACP_REG_POLL_TIMEOUT_US);
+	if (ret < 0)
+		dev_err(sdev->dev, "timeout in releasing reset\n");
+
+	return ret;
+}
+
 static int acp_init(struct snd_sof_dev *sdev)
 {
 	int ret;
@@ -498,10 +523,34 @@ static int acp_init(struct snd_sof_dev *sdev)
 	return acp_reset(sdev);
 }
 
+static bool check_acp_sdw_enable_status(struct snd_sof_dev *sdev)
+{
+	struct acp_dev_data *acp_data;
+	u32 sdw0_en, sdw1_en;
+
+	acp_data = sdev->pdata->hw_pdata;
+	if (!acp_data->sdw)
+		return false;
+
+	sdw0_en = snd_sof_dsp_read(sdev, ACP_DSP_BAR, ACP_SW0_EN);
+	sdw1_en = snd_sof_dsp_read(sdev, ACP_DSP_BAR, ACP_SW1_EN);
+	acp_data->sdw_en_stat = sdw0_en || sdw1_en;
+	return acp_data->sdw_en_stat;
+}
+
 int amd_sof_acp_suspend(struct snd_sof_dev *sdev, u32 target_state)
 {
 	int ret;
 
+	/* When acp_reset() function is invoked, it will apply ACP SOFT reset and
+	 * DSP reset. ACP Soft reset sequence will cause all ACP IP registers will
+	 * be reset to default values which will break the ClockStop Mode functionality.
+	 * Add a condition check to apply DSP reset when SoundWire ClockStop mode
+	 * is selected. For the rest of the scenarios, apply acp reset sequence.
+	 */
+	if (check_acp_sdw_enable_status(sdev))
+		return acp_dsp_reset(sdev);
+
 	ret = acp_reset(sdev);
 	if (ret) {
 		dev_err(sdev->dev, "ACP Reset failed\n");
@@ -517,13 +566,19 @@ EXPORT_SYMBOL_NS(amd_sof_acp_suspend, SND_SOC_SOF_AMD_COMMON);
 int amd_sof_acp_resume(struct snd_sof_dev *sdev)
 {
 	int ret;
+	struct acp_dev_data *acp_data;
 
-	ret = acp_init(sdev);
-	if (ret) {
-		dev_err(sdev->dev, "ACP Init failed\n");
-		return ret;
+	acp_data = sdev->pdata->hw_pdata;
+	if (!acp_data->sdw_en_stat) {
+		ret = acp_init(sdev);
+		if (ret) {
+			dev_err(sdev->dev, "ACP Init failed\n");
+			return ret;
+		}
+		return acp_memory_init(sdev);
+	} else {
+		return acp_dsp_reset(sdev);
 	}
-	return acp_memory_init(sdev);
 }
 EXPORT_SYMBOL_NS(amd_sof_acp_resume, SND_SOC_SOF_AMD_COMMON);
 
diff --git a/sound/soc/sof/amd/acp.h b/sound/soc/sof/amd/acp.h
index e94713d7ff1d..947068da39b5 100644
--- a/sound/soc/sof/amd/acp.h
+++ b/sound/soc/sof/amd/acp.h
@@ -31,6 +31,9 @@
 #define ACP_ASSERT_RESET			0x01
 #define ACP_RELEASE_RESET			0x00
 #define ACP_SOFT_RESET_DONE_MASK		0x00010001
+#define ACP_DSP_ASSERT_RESET			0x04
+#define ACP_DSP_RELEASE_RESET			0x00
+#define ACP_DSP_SOFT_RESET_DONE_MASK		0x00050004
 
 #define ACP_DSP_INTR_EN_MASK			0x00000001
 #define ACP3X_SRAM_PTE_OFFSET			0x02050000
@@ -242,6 +245,7 @@ struct acp_dev_data {
 	bool enable_fw_debug;
 	bool is_dram_in_use;
 	bool is_sram_in_use;
+	bool sdw_en_stat;
 };
 
 void memcpy_to_scratch(struct snd_sof_dev *sdev, u32 offset, unsigned int *src, size_t bytes);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [PATCH 00/12] soundwire/SOF: add SoundWire Interface support for AMD SOF stack
  2023-12-21  7:35 [PATCH 00/12] soundwire/SOF: add SoundWire Interface support for AMD SOF stack Vijendar Mukunda
                   ` (11 preceding siblings ...)
  2023-12-21  7:35 ` [PATCH 12/12] ASoC: SOF: amd: refactor acp driver pm ops Vijendar Mukunda
@ 2023-12-21  8:27 ` Pierre-Louis Bossart
  2024-01-09 12:41 ` Mukunda,Vijendar
  13 siblings, 0 replies; 24+ messages in thread
From: Pierre-Louis Bossart @ 2023-12-21  8:27 UTC (permalink / raw)
  To: Vijendar Mukunda, broonie, vkoul
  Cc: alsa-devel, Basavaraj.Hiregoudar, Sunil-kumar.Dommati,
	venkataprasad.potturu



On 12/21/23 08:35, Vijendar Mukunda wrote:
> This patch series is to redesign existing platform device
> creation logic for SoundWire managers and Implement generic
> functions for SoundWire manager probe, start and exit sequence
> which are common for both Legacy(NO DSP enabled) and SOF stack,
> and add SoundWire Interface support for AMD SOF stack
> (ACP 6.3 based platforms).
> 
> Vijendar Mukunda (12):
>   ASoC/soundwire: implement generic api for scanning amd soundwire
>     controller
>   drivers: soundwire: refactor amd soundwire manager device node
>     creation
>   drivers: soundwire: implement function to extract slave information
>   drivers: soundwire: refactor soundwire pads enable
>   drivers: soundwire: refactor register mask structure
>   ASoC: SOF: amd: add code for invoking soundwire manager helper
>     functions
>   ASoC: SOF: amd: add interrupt handling for SoundWire manager devices
>   ASoC: SOF: amd: Add Soundwire DAI configuration support for AMD
>     platforms
>   ASoC: SOF: amd: add machine select logic for soundwire based platforms
>   ASoC: SOF: amd: update descriptor fields for acp6.3 based platform
>   ASoC: SOF: amd: select soundwire dependency flag for acp6.3 based
>     platform
>   ASoC: SOF: amd: refactor acp driver pm ops

This patchset was reviewed by Bard and I in
https://github.com/thesofproject/linux/pull/4699

That said, my recommendation was to wait 2024 to send those patches,
it's rather late for code across two subsystems to be added.

>  drivers/soundwire/Makefile         |   2 +-
>  drivers/soundwire/amd_init.c       | 235 +++++++++++++++++++++++++++++
>  drivers/soundwire/amd_init.h       |  13 ++
>  drivers/soundwire/amd_manager.c    |  41 +----
>  drivers/soundwire/amd_manager.h    |  12 +-
>  include/linux/soundwire/sdw_amd.h  |  79 ++++++++--
>  include/sound/sof/dai-amd.h        |   7 +
>  include/sound/sof/dai.h            |   2 +
>  include/uapi/sound/sof/tokens.h    |   4 +
>  sound/soc/amd/acp/Kconfig          |   7 +
>  sound/soc/amd/acp/Makefile         |   2 +
>  sound/soc/amd/acp/amd-sdw-acpi.c   |  62 ++++++++
>  sound/soc/sof/amd/Kconfig          |  18 +++
>  sound/soc/sof/amd/acp-common.c     |  65 +++++++-
>  sound/soc/sof/amd/acp-dsp-offset.h |  10 ++
>  sound/soc/sof/amd/acp.c            | 202 ++++++++++++++++++++++++-
>  sound/soc/sof/amd/acp.h            |  26 +++-
>  sound/soc/sof/amd/pci-acp63.c      |   7 +
>  sound/soc/sof/ipc3-pcm.c           |  25 +++
>  sound/soc/sof/ipc3-topology.c      |  40 +++++
>  sound/soc/sof/sof-audio.h          |   1 +
>  sound/soc/sof/topology.c           |   5 +
>  22 files changed, 798 insertions(+), 67 deletions(-)
>  create mode 100644 drivers/soundwire/amd_init.c
>  create mode 100644 drivers/soundwire/amd_init.h
>  create mode 100644 sound/soc/amd/acp/amd-sdw-acpi.c
> 

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 02/12] drivers: soundwire: refactor amd soundwire manager device node creation
  2023-12-21  7:35 ` [PATCH 02/12] drivers: soundwire: refactor amd soundwire manager device node creation Vijendar Mukunda
@ 2023-12-21 16:34   ` Vinod Koul
  2023-12-22  5:32     ` Mukunda,Vijendar
  0 siblings, 1 reply; 24+ messages in thread
From: Vinod Koul @ 2023-12-21 16:34 UTC (permalink / raw)
  To: Vijendar Mukunda
  Cc: broonie, alsa-devel, Basavaraj.Hiregoudar, Sunil-kumar.Dommati,
	pierre-louis.bossart, vinod.koul, venkataprasad.potturu,
	Bard Liao, Sanyog Kale, open list

On 21-12-23, 13:05, Vijendar Mukunda wrote:

Why is the tag drivers: soundwire: ...??

should have been amd: to indicate amd driver code

> Refactor amd SoundWire manager device node creation logic and
> implement generic functions to have a common functionality for
> SoundWire manager platform device creation, start and exit sequence
> for both legacy(NO DSP) and SOF stack for AMD platforms.
> These functions will be invoked from legacy and SOF stack.
> 
> Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
> ---
>  drivers/soundwire/Makefile        |   2 +-
>  drivers/soundwire/amd_init.c      | 147 ++++++++++++++++++++++++++++++
>  drivers/soundwire/amd_init.h      |  13 +++
>  drivers/soundwire/amd_manager.c   |  16 +---
>  include/linux/soundwire/sdw_amd.h |  54 ++++++++++-
>  5 files changed, 218 insertions(+), 14 deletions(-)
>  create mode 100644 drivers/soundwire/amd_init.c
>  create mode 100644 drivers/soundwire/amd_init.h
> 
> diff --git a/drivers/soundwire/Makefile b/drivers/soundwire/Makefile
> index 657f5888a77b..e80a2c2cf3e7 100644
> --- a/drivers/soundwire/Makefile
> +++ b/drivers/soundwire/Makefile
> @@ -20,7 +20,7 @@ soundwire-bus-y += irq.o
>  endif
>  
>  #AMD driver
> -soundwire-amd-y :=	amd_manager.o
> +soundwire-amd-y := amd_init.o amd_manager.o
>  obj-$(CONFIG_SOUNDWIRE_AMD) += soundwire-amd.o
>  
>  #Cadence Objs
> diff --git a/drivers/soundwire/amd_init.c b/drivers/soundwire/amd_init.c
> new file mode 100644
> index 000000000000..d732ab0bfd59
> --- /dev/null
> +++ b/drivers/soundwire/amd_init.c
> @@ -0,0 +1,147 @@
> +// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
> +/*
> + * SoundWire AMD Manager Initialize routines
> + *
> + * Initializes and creates SDW devices based on ACPI and Hardware values
> + *
> + * Copyright 2023 Advanced Micro Devices, Inc.
> + */
> +
> +#include <linux/acpi.h>
> +#include <linux/export.h>
> +#include <linux/io.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +
> +#include "amd_init.h"
> +
> +static int sdw_amd_cleanup(struct sdw_amd_ctx *ctx)
> +{
> +	int i;
> +
> +	for (i = 0; i < ctx->count; i++) {
> +		if (!(ctx->link_mask & BIT(i)))
> +			continue;
> +		platform_device_unregister(ctx->pdev[i]);
> +	}
> +
> +	return 0;
> +}
> +
> +static struct sdw_amd_ctx *sdw_amd_probe_controller(struct sdw_amd_res *res)
> +{
> +	struct sdw_amd_ctx *ctx;
> +	struct acpi_device *adev;
> +	struct resource *sdw_res;
> +	struct acp_sdw_pdata sdw_pdata[2];
> +	struct platform_device_info pdevinfo[2];
> +	u32 link_mask;
> +	int count, index;
> +
> +	if (!res)
> +		return NULL;
> +
> +	adev = acpi_fetch_acpi_dev(res->handle);
> +	if (!adev)
> +		return NULL;
> +
> +	if (!res->count)
> +		return NULL;
> +
> +	count = res->count;
> +	dev_dbg(&adev->dev, "Creating %d SDW Link devices\n", count);
> +
> +	/*
> +	 * we need to alloc/free memory manually and can't use devm:
> +	 * this routine may be called from a workqueue, and not from
> +	 * the parent .probe.
> +	 * If devm_ was used, the memory might never be freed on errors.
> +	 */
> +	ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
> +	if (!ctx)
> +		return NULL;
> +
> +	ctx->count = count;
> +	ctx->link_mask = res->link_mask;
> +	sdw_res = kzalloc(sizeof(*sdw_res), GFP_KERNEL);
> +	if (!sdw_res) {
> +		kfree(ctx);
> +		return NULL;
> +	}
> +	sdw_res->flags = IORESOURCE_MEM;
> +	sdw_res->start = res->addr;
> +	sdw_res->end = res->addr + res->reg_range;
> +	memset(&pdevinfo, 0, sizeof(pdevinfo));
> +	link_mask = ctx->link_mask;
> +	for (index = 0; index < count; index++) {
> +		if (!(link_mask & BIT(index)))
> +			continue;
> +
> +		sdw_pdata[index].instance = index;
> +		sdw_pdata[index].acp_sdw_lock = res->acp_lock;
> +		pdevinfo[index].name = "amd_sdw_manager";
> +		pdevinfo[index].id = index;
> +		pdevinfo[index].parent = res->parent;
> +		pdevinfo[index].num_res = 1;
> +		pdevinfo[index].res = sdw_res;
> +		pdevinfo[index].data = &sdw_pdata[index];
> +		pdevinfo[index].size_data = sizeof(struct acp_sdw_pdata);
> +		pdevinfo[index].fwnode = acpi_fwnode_handle(adev);
> +		ctx->pdev[index] = platform_device_register_full(&pdevinfo[index]);
> +		if (IS_ERR(ctx->pdev[index]))
> +			goto err;
> +	}
> +	kfree(sdw_res);
> +	return ctx;
> +err:
> +	while (index--) {
> +		if (!(link_mask & BIT(index)))
> +			continue;
> +
> +		platform_device_unregister(ctx->pdev[index]);
> +	}
> +
> +	kfree(sdw_res);
> +	kfree(ctx);
> +	return NULL;
> +}
> +
> +static int sdw_amd_startup(struct sdw_amd_ctx *ctx)
> +{
> +	struct amd_sdw_manager *amd_manager;
> +	int i, ret;
> +
> +	/* Startup SDW Manager devices */
> +	for (i = 0; i < ctx->count; i++) {
> +		if (!(ctx->link_mask & BIT(i)))
> +			continue;
> +		amd_manager = dev_get_drvdata(&ctx->pdev[i]->dev);
> +		ret = amd_sdw_manager_start(amd_manager);
> +		if (ret)
> +			return ret;
> +	}
> +
> +	return 0;
> +}
> +
> +int sdw_amd_probe(struct sdw_amd_res *res, struct sdw_amd_ctx **sdw_ctx)
> +{
> +	*sdw_ctx = sdw_amd_probe_controller(res);
> +	if (!*sdw_ctx)
> +		return -ENODEV;
> +
> +	return sdw_amd_startup(*sdw_ctx);
> +}
> +EXPORT_SYMBOL_NS(sdw_amd_probe, SOUNDWIRE_AMD_INIT);
> +
> +void sdw_amd_exit(struct sdw_amd_ctx *ctx)
> +{
> +	sdw_amd_cleanup(ctx);
> +	kfree(ctx->ids);
> +	kfree(ctx);
> +}
> +EXPORT_SYMBOL_NS(sdw_amd_exit, SOUNDWIRE_AMD_INIT);
> +
> +MODULE_AUTHOR("Vijendar.Mukunda@amd.com");
> +MODULE_DESCRIPTION("AMD SoundWire Init Library");
> +MODULE_LICENSE("Dual BSD/GPL");
> diff --git a/drivers/soundwire/amd_init.h b/drivers/soundwire/amd_init.h
> new file mode 100644
> index 000000000000..f710703ffae9
> --- /dev/null
> +++ b/drivers/soundwire/amd_init.h
> @@ -0,0 +1,13 @@
> +/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
> +/*
> + * Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
> + */
> +
> +#ifndef __AMD_INIT_H
> +#define __AMD_INIT_H
> +
> +#include <linux/soundwire/sdw_amd.h>
> +
> +int amd_sdw_manager_start(struct amd_sdw_manager *amd_manager);
> +
> +#endif
> diff --git a/drivers/soundwire/amd_manager.c b/drivers/soundwire/amd_manager.c
> index 3a99f6dcdfaf..c27b0b0f33a6 100644
> --- a/drivers/soundwire/amd_manager.c
> +++ b/drivers/soundwire/amd_manager.c
> @@ -19,6 +19,7 @@
>  #include <sound/pcm_params.h>
>  #include <sound/soc.h>
>  #include "bus.h"
> +#include "amd_init.h"
>  #include "amd_manager.h"
>  
>  #define DRV_NAME "amd_sdw_manager"
> @@ -864,10 +865,8 @@ static void amd_sdw_irq_thread(struct work_struct *work)
>  	writel(0x00, amd_manager->mmio + ACP_SW_STATE_CHANGE_STATUS_0TO7);
>  }
>  
> -static void amd_sdw_probe_work(struct work_struct *work)
> +int amd_sdw_manager_start(struct amd_sdw_manager *amd_manager)
>  {
> -	struct amd_sdw_manager *amd_manager = container_of(work, struct amd_sdw_manager,
> -							   probe_work);
>  	struct sdw_master_prop *prop;
>  	int ret;
>  
> @@ -876,11 +875,11 @@ static void amd_sdw_probe_work(struct work_struct *work)
>  		amd_enable_sdw_pads(amd_manager);
>  		ret = amd_init_sdw_manager(amd_manager);
>  		if (ret)
> -			return;
> +			return ret;
>  		amd_enable_sdw_interrupts(amd_manager);
>  		ret = amd_enable_sdw_manager(amd_manager);
>  		if (ret)
> -			return;
> +			return ret;
>  		amd_sdw_set_frameshape(amd_manager);
>  	}
>  	/* Enable runtime PM */
> @@ -889,6 +888,7 @@ static void amd_sdw_probe_work(struct work_struct *work)
>  	pm_runtime_mark_last_busy(amd_manager->dev);
>  	pm_runtime_set_active(amd_manager->dev);
>  	pm_runtime_enable(amd_manager->dev);
> +	return 0;
>  }
>  
>  static int amd_sdw_manager_probe(struct platform_device *pdev)
> @@ -964,11 +964,6 @@ static int amd_sdw_manager_probe(struct platform_device *pdev)
>  	dev_set_drvdata(dev, amd_manager);
>  	INIT_WORK(&amd_manager->amd_sdw_irq_thread, amd_sdw_irq_thread);
>  	INIT_WORK(&amd_manager->amd_sdw_work, amd_sdw_update_slave_status_work);
> -	INIT_WORK(&amd_manager->probe_work, amd_sdw_probe_work);
> -	/*
> -	 * Instead of having lengthy probe sequence, use deferred probe.
> -	 */
> -	schedule_work(&amd_manager->probe_work);
>  	return 0;
>  }
>  
> @@ -978,7 +973,6 @@ static void amd_sdw_manager_remove(struct platform_device *pdev)
>  	int ret;
>  
>  	pm_runtime_disable(&pdev->dev);
> -	cancel_work_sync(&amd_manager->probe_work);
>  	amd_disable_sdw_interrupts(amd_manager);
>  	sdw_bus_master_delete(&amd_manager->bus);
>  	ret = amd_disable_sdw_manager(amd_manager);
> diff --git a/include/linux/soundwire/sdw_amd.h b/include/linux/soundwire/sdw_amd.h
> index 41dd64941cef..064174c2f401 100644
> --- a/include/linux/soundwire/sdw_amd.h
> +++ b/include/linux/soundwire/sdw_amd.h
> @@ -26,6 +26,7 @@
>  #define AMD_SDW_POWER_OFF_MODE		2
>  #define ACP_SDW0	0
>  #define ACP_SDW1	1
> +#define AMD_SDW_MAX_MANAGER_COUNT	2
>  
>  struct acp_sdw_pdata {
>  	u16 instance;
> @@ -63,7 +64,6 @@ struct sdw_amd_dai_runtime {
>   * @reg_mask: register mask structure per manager instance
>   * @amd_sdw_irq_thread: SoundWire manager irq workqueue
>   * @amd_sdw_work: peripheral status work queue
> - * @probe_work: SoundWire manager probe workqueue
>   * @acp_sdw_lock: mutex to protect acp share register access
>   * @status: peripheral devices status array
>   * @num_din_ports: number of input ports
> @@ -87,7 +87,6 @@ struct amd_sdw_manager {
>  	struct sdw_manager_reg_mask *reg_mask;
>  	struct work_struct amd_sdw_irq_thread;
>  	struct work_struct amd_sdw_work;
> -	struct work_struct probe_work;
>  	/* mutex to protect acp common register access */
>  	struct mutex *acp_sdw_lock;
>  
> @@ -120,5 +119,56 @@ struct sdw_amd_acpi_info {
>  	u32 link_mask;
>  };
>  
> +/**
> + * struct sdw_amd_ctx - context allocated by the controller
> + * driver probe
> + * @count: link count
> + * @num_slaves: total number of devices exposed across all enabled links
> + * @link_mask: bit-wise mask listing SoundWire links reported by the
> + * Controller
> + * @ids: array of slave_id, representing Slaves exposed across all enabled
> + * links
> + * @pdev: platform device structure
> + */
> +struct sdw_amd_ctx {
> +	int count;
> +	int num_slaves;
> +	u32 link_mask;
> +	struct sdw_extended_slave_id *ids;
> +	struct platform_device *pdev[AMD_SDW_MAX_MANAGER_COUNT];
> +};
> +
> +/**
> + * struct sdw_amd_res - Soundwire AMD global resource structure,
> + * typically populated by the DSP driver/Legacy driver
> + *
> + * @addr: acp pci device resource start address
> + * @reg_range: ACP register range
> + * @link_mask: bit-wise mask listing links selected by the DSP driver/
> + * legacy driver
> + * @count: link count
> + * @mmio_base: mmio base of SoundWire registers
> + * @handle: ACPI parent handle
> + * @parent: parent device
> + * @dev: device implementing hwparams and free callbacks
> + * @acp_lock: mutex protecting acp common registers access
> + */
> +struct sdw_amd_res {
> +	u32 addr;
> +	u32 reg_range;
> +	u32 link_mask;
> +	int count;
> +	void __iomem *mmio_base;
> +	acpi_handle handle;
> +	struct device *parent;
> +	struct device *dev;
> +	/* use to protect acp common registers access */
> +	struct mutex *acp_lock;
> +};
> +
> +int sdw_amd_probe(struct sdw_amd_res *res, struct sdw_amd_ctx **ctx);
> +
> +void sdw_amd_exit(struct sdw_amd_ctx *ctx);
> +
>  int amd_sdw_scan_controller(struct sdw_amd_acpi_info *info);
>  #endif
> -- 
> 2.34.1

-- 
~Vinod

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 04/12] drivers: soundwire: refactor soundwire pads enable
  2023-12-21  7:35 ` [PATCH 04/12] drivers: soundwire: refactor soundwire pads enable Vijendar Mukunda
@ 2023-12-21 16:38   ` Vinod Koul
  2023-12-22  7:15     ` Mukunda,Vijendar
  0 siblings, 1 reply; 24+ messages in thread
From: Vinod Koul @ 2023-12-21 16:38 UTC (permalink / raw)
  To: Vijendar Mukunda
  Cc: broonie, alsa-devel, Basavaraj.Hiregoudar, Sunil-kumar.Dommati,
	pierre-louis.bossart, vinod.koul, venkataprasad.potturu,
	Bard Liao, Sanyog Kale, open list

On 21-12-23, 13:05, Vijendar Mukunda wrote:
> As sdw pads enable sequence is executed only once, invoke it
> from probe sequence.
> 
> Program required pads for both manager instances
> based on link_mask during probe sequence. This will avoid
> acquiring mutex lock.

something wrong with your editor to have this formatting, you can use
upto 80 chars here!


> Remove unnecessary delay after programming ACP_SW_PAD_KEEPER_EN
> register.
> 
> Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
> ---
>  drivers/soundwire/amd_init.c    | 45 +++++++++++++++++++++++++++++++++
>  drivers/soundwire/amd_manager.c | 18 -------------
>  2 files changed, 45 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/soundwire/amd_init.c b/drivers/soundwire/amd_init.c
> index 5c9569d9ad01..b3b3c7266384 100644
> --- a/drivers/soundwire/amd_init.c
> +++ b/drivers/soundwire/amd_init.c
> @@ -15,6 +15,47 @@
>  
>  #include "amd_init.h"
>  
> +#define ACP_PAD_PULLDOWN_CTRL				0x0001448
> +#define ACP_SW_PAD_KEEPER_EN				0x0001454
> +#define AMD_SDW_PAD_PULLDOWN_CTRL_ENABLE_MASK		0x7f9a
> +#define AMD_SDW0_PAD_PULLDOWN_CTRL_ENABLE_MASK		0x7f9f
> +#define AMD_SDW1_PAD_PULLDOWN_CTRL_ENABLE_MASK		0x7ffa
> +#define AMD_SDW0_PAD_EN_MASK				1
> +#define AMD_SDW1_PAD_EN_MASK				0x10
> +#define AMD_SDW_PAD_EN_MASK	(AMD_SDW0_PAD_EN_MASK | AMD_SDW1_PAD_EN_MASK)
> +
> +static int amd_enable_sdw_pads(void __iomem *mmio, u32 link_mask, struct device *dev)
> +{
> +	u32 val;
> +	u32 pad_keeper_en_mask, pad_pulldown_ctrl_mask;
> +
> +	switch (link_mask) {
> +	case 1:
> +		pad_keeper_en_mask = AMD_SDW0_PAD_EN_MASK;
> +		pad_pulldown_ctrl_mask = AMD_SDW0_PAD_PULLDOWN_CTRL_ENABLE_MASK;
> +		break;
> +	case 2:
> +		pad_keeper_en_mask = AMD_SDW1_PAD_EN_MASK;
> +		pad_pulldown_ctrl_mask = AMD_SDW1_PAD_PULLDOWN_CTRL_ENABLE_MASK;
> +		break;
> +	case 3:
> +		pad_keeper_en_mask = AMD_SDW_PAD_EN_MASK;
> +		pad_pulldown_ctrl_mask = AMD_SDW_PAD_PULLDOWN_CTRL_ENABLE_MASK;
> +		break;
> +	default:
> +		dev_err(dev, "No SDW Links are enabled\n");
> +		return -ENODEV;
> +	}
> +
> +	val = readl(mmio + ACP_SW_PAD_KEEPER_EN);
> +	val |= pad_keeper_en_mask;
> +	writel(val, mmio + ACP_SW_PAD_KEEPER_EN);
> +	val = readl(mmio + ACP_PAD_PULLDOWN_CTRL);
> +	val &= pad_pulldown_ctrl_mask;
> +	writel(val, mmio + ACP_PAD_PULLDOWN_CTRL);

updatel() local macro?

> +	return 0;
> +}
> +
>  static int sdw_amd_cleanup(struct sdw_amd_ctx *ctx)
>  {
>  	int i;
> @@ -37,6 +78,7 @@ static struct sdw_amd_ctx *sdw_amd_probe_controller(struct sdw_amd_res *res)
>  	struct platform_device_info pdevinfo[2];
>  	u32 link_mask;
>  	int count, index;
> +	int ret;
>  
>  	if (!res)
>  		return NULL;
> @@ -50,6 +92,9 @@ static struct sdw_amd_ctx *sdw_amd_probe_controller(struct sdw_amd_res *res)
>  
>  	count = res->count;
>  	dev_dbg(&adev->dev, "Creating %d SDW Link devices\n", count);
> +	ret = amd_enable_sdw_pads(res->mmio_base, res->link_mask, res->parent);
> +	if (ret)
> +		return NULL;
>  
>  	/*
>  	 * we need to alloc/free memory manually and can't use devm:
> diff --git a/drivers/soundwire/amd_manager.c b/drivers/soundwire/amd_manager.c
> index c27b0b0f33a6..1427cccfc309 100644
> --- a/drivers/soundwire/amd_manager.c
> +++ b/drivers/soundwire/amd_manager.c
> @@ -26,23 +26,6 @@
>  
>  #define to_amd_sdw(b)	container_of(b, struct amd_sdw_manager, bus)
>  
> -static void amd_enable_sdw_pads(struct amd_sdw_manager *amd_manager)
> -{
> -	u32 sw_pad_pulldown_val;
> -	u32 val;
> -
> -	mutex_lock(amd_manager->acp_sdw_lock);
> -	val = readl(amd_manager->acp_mmio + ACP_SW_PAD_KEEPER_EN);
> -	val |= amd_manager->reg_mask->sw_pad_enable_mask;
> -	writel(val, amd_manager->acp_mmio + ACP_SW_PAD_KEEPER_EN);
> -	usleep_range(1000, 1500);
> -
> -	sw_pad_pulldown_val = readl(amd_manager->acp_mmio + ACP_PAD_PULLDOWN_CTRL);
> -	sw_pad_pulldown_val &= amd_manager->reg_mask->sw_pad_pulldown_mask;
> -	writel(sw_pad_pulldown_val, amd_manager->acp_mmio + ACP_PAD_PULLDOWN_CTRL);
> -	mutex_unlock(amd_manager->acp_sdw_lock);

so the code is copied from a GPL declared file to now and GPL + BSD one!
Have you had lawyers look into this... why change one file license ?

> -}
> -
>  static int amd_init_sdw_manager(struct amd_sdw_manager *amd_manager)
>  {
>  	u32 val;
> @@ -872,7 +855,6 @@ int amd_sdw_manager_start(struct amd_sdw_manager *amd_manager)
>  
>  	prop = &amd_manager->bus.prop;
>  	if (!prop->hw_disabled) {
> -		amd_enable_sdw_pads(amd_manager);
>  		ret = amd_init_sdw_manager(amd_manager);
>  		if (ret)
>  			return ret;
> -- 
> 2.34.1

-- 
~Vinod

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 02/12] drivers: soundwire: refactor amd soundwire manager device node creation
  2023-12-21 16:34   ` Vinod Koul
@ 2023-12-22  5:32     ` Mukunda,Vijendar
  0 siblings, 0 replies; 24+ messages in thread
From: Mukunda,Vijendar @ 2023-12-22  5:32 UTC (permalink / raw)
  To: Vinod Koul
  Cc: broonie, alsa-devel, Basavaraj.Hiregoudar, Sunil-kumar.Dommati,
	pierre-louis.bossart, vinod.koul, venkataprasad.potturu,
	Bard Liao, Sanyog Kale, open list

On 21/12/23 22:04, Vinod Koul wrote:
> On 21-12-23, 13:05, Vijendar Mukunda wrote:
>
> Why is the tag drivers: soundwire: ...??
>
> should have been amd: to indicate amd driver code
will add "amd" tag
>> Refactor amd SoundWire manager device node creation logic and
>> implement generic functions to have a common functionality for
>> SoundWire manager platform device creation, start and exit sequence
>> for both legacy(NO DSP) and SOF stack for AMD platforms.
>> These functions will be invoked from legacy and SOF stack.
>>
>> Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
>> ---
>>  drivers/soundwire/Makefile        |   2 +-
>>  drivers/soundwire/amd_init.c      | 147 ++++++++++++++++++++++++++++++
>>  drivers/soundwire/amd_init.h      |  13 +++
>>  drivers/soundwire/amd_manager.c   |  16 +---
>>  include/linux/soundwire/sdw_amd.h |  54 ++++++++++-
>>  5 files changed, 218 insertions(+), 14 deletions(-)
>>  create mode 100644 drivers/soundwire/amd_init.c
>>  create mode 100644 drivers/soundwire/amd_init.h
>>
>> diff --git a/drivers/soundwire/Makefile b/drivers/soundwire/Makefile
>> index 657f5888a77b..e80a2c2cf3e7 100644
>> --- a/drivers/soundwire/Makefile
>> +++ b/drivers/soundwire/Makefile
>> @@ -20,7 +20,7 @@ soundwire-bus-y += irq.o
>>  endif
>>  
>>  #AMD driver
>> -soundwire-amd-y :=	amd_manager.o
>> +soundwire-amd-y := amd_init.o amd_manager.o
>>  obj-$(CONFIG_SOUNDWIRE_AMD) += soundwire-amd.o
>>  
>>  #Cadence Objs
>> diff --git a/drivers/soundwire/amd_init.c b/drivers/soundwire/amd_init.c
>> new file mode 100644
>> index 000000000000..d732ab0bfd59
>> --- /dev/null
>> +++ b/drivers/soundwire/amd_init.c
>> @@ -0,0 +1,147 @@
>> +// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
>> +/*
>> + * SoundWire AMD Manager Initialize routines
>> + *
>> + * Initializes and creates SDW devices based on ACPI and Hardware values
>> + *
>> + * Copyright 2023 Advanced Micro Devices, Inc.
>> + */
>> +
>> +#include <linux/acpi.h>
>> +#include <linux/export.h>
>> +#include <linux/io.h>
>> +#include <linux/module.h>
>> +#include <linux/platform_device.h>
>> +
>> +#include "amd_init.h"
>> +
>> +static int sdw_amd_cleanup(struct sdw_amd_ctx *ctx)
>> +{
>> +	int i;
>> +
>> +	for (i = 0; i < ctx->count; i++) {
>> +		if (!(ctx->link_mask & BIT(i)))
>> +			continue;
>> +		platform_device_unregister(ctx->pdev[i]);
>> +	}
>> +
>> +	return 0;
>> +}
>> +
>> +static struct sdw_amd_ctx *sdw_amd_probe_controller(struct sdw_amd_res *res)
>> +{
>> +	struct sdw_amd_ctx *ctx;
>> +	struct acpi_device *adev;
>> +	struct resource *sdw_res;
>> +	struct acp_sdw_pdata sdw_pdata[2];
>> +	struct platform_device_info pdevinfo[2];
>> +	u32 link_mask;
>> +	int count, index;
>> +
>> +	if (!res)
>> +		return NULL;
>> +
>> +	adev = acpi_fetch_acpi_dev(res->handle);
>> +	if (!adev)
>> +		return NULL;
>> +
>> +	if (!res->count)
>> +		return NULL;
>> +
>> +	count = res->count;
>> +	dev_dbg(&adev->dev, "Creating %d SDW Link devices\n", count);
>> +
>> +	/*
>> +	 * we need to alloc/free memory manually and can't use devm:
>> +	 * this routine may be called from a workqueue, and not from
>> +	 * the parent .probe.
>> +	 * If devm_ was used, the memory might never be freed on errors.
>> +	 */
>> +	ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
>> +	if (!ctx)
>> +		return NULL;
>> +
>> +	ctx->count = count;
>> +	ctx->link_mask = res->link_mask;
>> +	sdw_res = kzalloc(sizeof(*sdw_res), GFP_KERNEL);
>> +	if (!sdw_res) {
>> +		kfree(ctx);
>> +		return NULL;
>> +	}
>> +	sdw_res->flags = IORESOURCE_MEM;
>> +	sdw_res->start = res->addr;
>> +	sdw_res->end = res->addr + res->reg_range;
>> +	memset(&pdevinfo, 0, sizeof(pdevinfo));
>> +	link_mask = ctx->link_mask;
>> +	for (index = 0; index < count; index++) {
>> +		if (!(link_mask & BIT(index)))
>> +			continue;
>> +
>> +		sdw_pdata[index].instance = index;
>> +		sdw_pdata[index].acp_sdw_lock = res->acp_lock;
>> +		pdevinfo[index].name = "amd_sdw_manager";
>> +		pdevinfo[index].id = index;
>> +		pdevinfo[index].parent = res->parent;
>> +		pdevinfo[index].num_res = 1;
>> +		pdevinfo[index].res = sdw_res;
>> +		pdevinfo[index].data = &sdw_pdata[index];
>> +		pdevinfo[index].size_data = sizeof(struct acp_sdw_pdata);
>> +		pdevinfo[index].fwnode = acpi_fwnode_handle(adev);
>> +		ctx->pdev[index] = platform_device_register_full(&pdevinfo[index]);
>> +		if (IS_ERR(ctx->pdev[index]))
>> +			goto err;
>> +	}
>> +	kfree(sdw_res);
>> +	return ctx;
>> +err:
>> +	while (index--) {
>> +		if (!(link_mask & BIT(index)))
>> +			continue;
>> +
>> +		platform_device_unregister(ctx->pdev[index]);
>> +	}
>> +
>> +	kfree(sdw_res);
>> +	kfree(ctx);
>> +	return NULL;
>> +}
>> +
>> +static int sdw_amd_startup(struct sdw_amd_ctx *ctx)
>> +{
>> +	struct amd_sdw_manager *amd_manager;
>> +	int i, ret;
>> +
>> +	/* Startup SDW Manager devices */
>> +	for (i = 0; i < ctx->count; i++) {
>> +		if (!(ctx->link_mask & BIT(i)))
>> +			continue;
>> +		amd_manager = dev_get_drvdata(&ctx->pdev[i]->dev);
>> +		ret = amd_sdw_manager_start(amd_manager);
>> +		if (ret)
>> +			return ret;
>> +	}
>> +
>> +	return 0;
>> +}
>> +
>> +int sdw_amd_probe(struct sdw_amd_res *res, struct sdw_amd_ctx **sdw_ctx)
>> +{
>> +	*sdw_ctx = sdw_amd_probe_controller(res);
>> +	if (!*sdw_ctx)
>> +		return -ENODEV;
>> +
>> +	return sdw_amd_startup(*sdw_ctx);
>> +}
>> +EXPORT_SYMBOL_NS(sdw_amd_probe, SOUNDWIRE_AMD_INIT);
>> +
>> +void sdw_amd_exit(struct sdw_amd_ctx *ctx)
>> +{
>> +	sdw_amd_cleanup(ctx);
>> +	kfree(ctx->ids);
>> +	kfree(ctx);
>> +}
>> +EXPORT_SYMBOL_NS(sdw_amd_exit, SOUNDWIRE_AMD_INIT);
>> +
>> +MODULE_AUTHOR("Vijendar.Mukunda@amd.com");
>> +MODULE_DESCRIPTION("AMD SoundWire Init Library");
>> +MODULE_LICENSE("Dual BSD/GPL");
>> diff --git a/drivers/soundwire/amd_init.h b/drivers/soundwire/amd_init.h
>> new file mode 100644
>> index 000000000000..f710703ffae9
>> --- /dev/null
>> +++ b/drivers/soundwire/amd_init.h
>> @@ -0,0 +1,13 @@
>> +/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
>> +/*
>> + * Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
>> + */
>> +
>> +#ifndef __AMD_INIT_H
>> +#define __AMD_INIT_H
>> +
>> +#include <linux/soundwire/sdw_amd.h>
>> +
>> +int amd_sdw_manager_start(struct amd_sdw_manager *amd_manager);
>> +
>> +#endif
>> diff --git a/drivers/soundwire/amd_manager.c b/drivers/soundwire/amd_manager.c
>> index 3a99f6dcdfaf..c27b0b0f33a6 100644
>> --- a/drivers/soundwire/amd_manager.c
>> +++ b/drivers/soundwire/amd_manager.c
>> @@ -19,6 +19,7 @@
>>  #include <sound/pcm_params.h>
>>  #include <sound/soc.h>
>>  #include "bus.h"
>> +#include "amd_init.h"
>>  #include "amd_manager.h"
>>  
>>  #define DRV_NAME "amd_sdw_manager"
>> @@ -864,10 +865,8 @@ static void amd_sdw_irq_thread(struct work_struct *work)
>>  	writel(0x00, amd_manager->mmio + ACP_SW_STATE_CHANGE_STATUS_0TO7);
>>  }
>>  
>> -static void amd_sdw_probe_work(struct work_struct *work)
>> +int amd_sdw_manager_start(struct amd_sdw_manager *amd_manager)
>>  {
>> -	struct amd_sdw_manager *amd_manager = container_of(work, struct amd_sdw_manager,
>> -							   probe_work);
>>  	struct sdw_master_prop *prop;
>>  	int ret;
>>  
>> @@ -876,11 +875,11 @@ static void amd_sdw_probe_work(struct work_struct *work)
>>  		amd_enable_sdw_pads(amd_manager);
>>  		ret = amd_init_sdw_manager(amd_manager);
>>  		if (ret)
>> -			return;
>> +			return ret;
>>  		amd_enable_sdw_interrupts(amd_manager);
>>  		ret = amd_enable_sdw_manager(amd_manager);
>>  		if (ret)
>> -			return;
>> +			return ret;
>>  		amd_sdw_set_frameshape(amd_manager);
>>  	}
>>  	/* Enable runtime PM */
>> @@ -889,6 +888,7 @@ static void amd_sdw_probe_work(struct work_struct *work)
>>  	pm_runtime_mark_last_busy(amd_manager->dev);
>>  	pm_runtime_set_active(amd_manager->dev);
>>  	pm_runtime_enable(amd_manager->dev);
>> +	return 0;
>>  }
>>  
>>  static int amd_sdw_manager_probe(struct platform_device *pdev)
>> @@ -964,11 +964,6 @@ static int amd_sdw_manager_probe(struct platform_device *pdev)
>>  	dev_set_drvdata(dev, amd_manager);
>>  	INIT_WORK(&amd_manager->amd_sdw_irq_thread, amd_sdw_irq_thread);
>>  	INIT_WORK(&amd_manager->amd_sdw_work, amd_sdw_update_slave_status_work);
>> -	INIT_WORK(&amd_manager->probe_work, amd_sdw_probe_work);
>> -	/*
>> -	 * Instead of having lengthy probe sequence, use deferred probe.
>> -	 */
>> -	schedule_work(&amd_manager->probe_work);
>>  	return 0;
>>  }
>>  
>> @@ -978,7 +973,6 @@ static void amd_sdw_manager_remove(struct platform_device *pdev)
>>  	int ret;
>>  
>>  	pm_runtime_disable(&pdev->dev);
>> -	cancel_work_sync(&amd_manager->probe_work);
>>  	amd_disable_sdw_interrupts(amd_manager);
>>  	sdw_bus_master_delete(&amd_manager->bus);
>>  	ret = amd_disable_sdw_manager(amd_manager);
>> diff --git a/include/linux/soundwire/sdw_amd.h b/include/linux/soundwire/sdw_amd.h
>> index 41dd64941cef..064174c2f401 100644
>> --- a/include/linux/soundwire/sdw_amd.h
>> +++ b/include/linux/soundwire/sdw_amd.h
>> @@ -26,6 +26,7 @@
>>  #define AMD_SDW_POWER_OFF_MODE		2
>>  #define ACP_SDW0	0
>>  #define ACP_SDW1	1
>> +#define AMD_SDW_MAX_MANAGER_COUNT	2
>>  
>>  struct acp_sdw_pdata {
>>  	u16 instance;
>> @@ -63,7 +64,6 @@ struct sdw_amd_dai_runtime {
>>   * @reg_mask: register mask structure per manager instance
>>   * @amd_sdw_irq_thread: SoundWire manager irq workqueue
>>   * @amd_sdw_work: peripheral status work queue
>> - * @probe_work: SoundWire manager probe workqueue
>>   * @acp_sdw_lock: mutex to protect acp share register access
>>   * @status: peripheral devices status array
>>   * @num_din_ports: number of input ports
>> @@ -87,7 +87,6 @@ struct amd_sdw_manager {
>>  	struct sdw_manager_reg_mask *reg_mask;
>>  	struct work_struct amd_sdw_irq_thread;
>>  	struct work_struct amd_sdw_work;
>> -	struct work_struct probe_work;
>>  	/* mutex to protect acp common register access */
>>  	struct mutex *acp_sdw_lock;
>>  
>> @@ -120,5 +119,56 @@ struct sdw_amd_acpi_info {
>>  	u32 link_mask;
>>  };
>>  
>> +/**
>> + * struct sdw_amd_ctx - context allocated by the controller
>> + * driver probe
>> + * @count: link count
>> + * @num_slaves: total number of devices exposed across all enabled links
>> + * @link_mask: bit-wise mask listing SoundWire links reported by the
>> + * Controller
>> + * @ids: array of slave_id, representing Slaves exposed across all enabled
>> + * links
>> + * @pdev: platform device structure
>> + */
>> +struct sdw_amd_ctx {
>> +	int count;
>> +	int num_slaves;
>> +	u32 link_mask;
>> +	struct sdw_extended_slave_id *ids;
>> +	struct platform_device *pdev[AMD_SDW_MAX_MANAGER_COUNT];
>> +};
>> +
>> +/**
>> + * struct sdw_amd_res - Soundwire AMD global resource structure,
>> + * typically populated by the DSP driver/Legacy driver
>> + *
>> + * @addr: acp pci device resource start address
>> + * @reg_range: ACP register range
>> + * @link_mask: bit-wise mask listing links selected by the DSP driver/
>> + * legacy driver
>> + * @count: link count
>> + * @mmio_base: mmio base of SoundWire registers
>> + * @handle: ACPI parent handle
>> + * @parent: parent device
>> + * @dev: device implementing hwparams and free callbacks
>> + * @acp_lock: mutex protecting acp common registers access
>> + */
>> +struct sdw_amd_res {
>> +	u32 addr;
>> +	u32 reg_range;
>> +	u32 link_mask;
>> +	int count;
>> +	void __iomem *mmio_base;
>> +	acpi_handle handle;
>> +	struct device *parent;
>> +	struct device *dev;
>> +	/* use to protect acp common registers access */
>> +	struct mutex *acp_lock;
>> +};
>> +
>> +int sdw_amd_probe(struct sdw_amd_res *res, struct sdw_amd_ctx **ctx);
>> +
>> +void sdw_amd_exit(struct sdw_amd_ctx *ctx);
>> +
>>  int amd_sdw_scan_controller(struct sdw_amd_acpi_info *info);
>>  #endif
>> -- 
>> 2.34.1


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 04/12] drivers: soundwire: refactor soundwire pads enable
  2023-12-21 16:38   ` Vinod Koul
@ 2023-12-22  7:15     ` Mukunda,Vijendar
  2023-12-22  9:21       ` Vinod Koul
  0 siblings, 1 reply; 24+ messages in thread
From: Mukunda,Vijendar @ 2023-12-22  7:15 UTC (permalink / raw)
  To: Vinod Koul
  Cc: broonie, alsa-devel, Basavaraj.Hiregoudar, Sunil-kumar.Dommati,
	pierre-louis.bossart, vinod.koul, venkataprasad.potturu,
	Bard Liao, Sanyog Kale, open list

On 21/12/23 22:08, Vinod Koul wrote:
> On 21-12-23, 13:05, Vijendar Mukunda wrote:
>> As sdw pads enable sequence is executed only once, invoke it
>> from probe sequence.
>>
>> Program required pads for both manager instances
>> based on link_mask during probe sequence. This will avoid
>> acquiring mutex lock.
> something wrong with your editor to have this formatting, you can use
> upto 80 chars here!

Will check.
>> Remove unnecessary delay after programming ACP_SW_PAD_KEEPER_EN
>> register.
>>
>> Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
>> ---
>>  drivers/soundwire/amd_init.c    | 45 +++++++++++++++++++++++++++++++++
>>  drivers/soundwire/amd_manager.c | 18 -------------
>>  2 files changed, 45 insertions(+), 18 deletions(-)
>>
>> diff --git a/drivers/soundwire/amd_init.c b/drivers/soundwire/amd_init.c
>> index 5c9569d9ad01..b3b3c7266384 100644
>> --- a/drivers/soundwire/amd_init.c
>> +++ b/drivers/soundwire/amd_init.c
>> @@ -15,6 +15,47 @@
>>  
>>  #include "amd_init.h"
>>  
>> +#define ACP_PAD_PULLDOWN_CTRL				0x0001448
>> +#define ACP_SW_PAD_KEEPER_EN				0x0001454
>> +#define AMD_SDW_PAD_PULLDOWN_CTRL_ENABLE_MASK		0x7f9a
>> +#define AMD_SDW0_PAD_PULLDOWN_CTRL_ENABLE_MASK		0x7f9f
>> +#define AMD_SDW1_PAD_PULLDOWN_CTRL_ENABLE_MASK		0x7ffa
>> +#define AMD_SDW0_PAD_EN_MASK				1
>> +#define AMD_SDW1_PAD_EN_MASK				0x10
>> +#define AMD_SDW_PAD_EN_MASK	(AMD_SDW0_PAD_EN_MASK | AMD_SDW1_PAD_EN_MASK)
>> +
>> +static int amd_enable_sdw_pads(void __iomem *mmio, u32 link_mask, struct device *dev)
>> +{
>> +	u32 val;
>> +	u32 pad_keeper_en_mask, pad_pulldown_ctrl_mask;
>> +
>> +	switch (link_mask) {
>> +	case 1:
>> +		pad_keeper_en_mask = AMD_SDW0_PAD_EN_MASK;
>> +		pad_pulldown_ctrl_mask = AMD_SDW0_PAD_PULLDOWN_CTRL_ENABLE_MASK;
>> +		break;
>> +	case 2:
>> +		pad_keeper_en_mask = AMD_SDW1_PAD_EN_MASK;
>> +		pad_pulldown_ctrl_mask = AMD_SDW1_PAD_PULLDOWN_CTRL_ENABLE_MASK;
>> +		break;
>> +	case 3:
>> +		pad_keeper_en_mask = AMD_SDW_PAD_EN_MASK;
>> +		pad_pulldown_ctrl_mask = AMD_SDW_PAD_PULLDOWN_CTRL_ENABLE_MASK;
>> +		break;
>> +	default:
>> +		dev_err(dev, "No SDW Links are enabled\n");
>> +		return -ENODEV;
>> +	}
>> +
>> +	val = readl(mmio + ACP_SW_PAD_KEEPER_EN);
>> +	val |= pad_keeper_en_mask;
>> +	writel(val, mmio + ACP_SW_PAD_KEEPER_EN);
>> +	val = readl(mmio + ACP_PAD_PULLDOWN_CTRL);
>> +	val &= pad_pulldown_ctrl_mask;
>> +	writel(val, mmio + ACP_PAD_PULLDOWN_CTRL);
> updatel() local macro?
We have identified similar update() inline function should be used in other
parts of the code with different mmio base address. We will push it as a
separate patch.

>> +	return 0;
>> +}
>> +
>>  static int sdw_amd_cleanup(struct sdw_amd_ctx *ctx)
>>  {
>>  	int i;
>> @@ -37,6 +78,7 @@ static struct sdw_amd_ctx *sdw_amd_probe_controller(struct sdw_amd_res *res)
>>  	struct platform_device_info pdevinfo[2];
>>  	u32 link_mask;
>>  	int count, index;
>> +	int ret;
>>  
>>  	if (!res)
>>  		return NULL;
>> @@ -50,6 +92,9 @@ static struct sdw_amd_ctx *sdw_amd_probe_controller(struct sdw_amd_res *res)
>>  
>>  	count = res->count;
>>  	dev_dbg(&adev->dev, "Creating %d SDW Link devices\n", count);
>> +	ret = amd_enable_sdw_pads(res->mmio_base, res->link_mask, res->parent);
>> +	if (ret)
>> +		return NULL;
>>  
>>  	/*
>>  	 * we need to alloc/free memory manually and can't use devm:
>> diff --git a/drivers/soundwire/amd_manager.c b/drivers/soundwire/amd_manager.c
>> index c27b0b0f33a6..1427cccfc309 100644
>> --- a/drivers/soundwire/amd_manager.c
>> +++ b/drivers/soundwire/amd_manager.c
>> @@ -26,23 +26,6 @@
>>  
>>  #define to_amd_sdw(b)	container_of(b, struct amd_sdw_manager, bus)
>>  
>> -static void amd_enable_sdw_pads(struct amd_sdw_manager *amd_manager)
>> -{
>> -	u32 sw_pad_pulldown_val;
>> -	u32 val;
>> -
>> -	mutex_lock(amd_manager->acp_sdw_lock);
>> -	val = readl(amd_manager->acp_mmio + ACP_SW_PAD_KEEPER_EN);
>> -	val |= amd_manager->reg_mask->sw_pad_enable_mask;
>> -	writel(val, amd_manager->acp_mmio + ACP_SW_PAD_KEEPER_EN);
>> -	usleep_range(1000, 1500);
>> -
>> -	sw_pad_pulldown_val = readl(amd_manager->acp_mmio + ACP_PAD_PULLDOWN_CTRL);
>> -	sw_pad_pulldown_val &= amd_manager->reg_mask->sw_pad_pulldown_mask;
>> -	writel(sw_pad_pulldown_val, amd_manager->acp_mmio + ACP_PAD_PULLDOWN_CTRL);
>> -	mutex_unlock(amd_manager->acp_sdw_lock);
> so the code is copied from a GPL declared file to now and GPL + BSD one!
> Have you had lawyers look into this... why change one file license ?
As per recommendations from our legal team, we have updated the license as dual
one for amd_init.c file.
We have also observed that license terms should be updated for other files as
well (amd_manager.c, amd_manager.h & sdw_amd.h) as dual one, which we have
planned to submit as a supplement patch.

>> -}
>> -
>>  static int amd_init_sdw_manager(struct amd_sdw_manager *amd_manager)
>>  {
>>  	u32 val;
>> @@ -872,7 +855,6 @@ int amd_sdw_manager_start(struct amd_sdw_manager *amd_manager)
>>  
>>  	prop = &amd_manager->bus.prop;
>>  	if (!prop->hw_disabled) {
>> -		amd_enable_sdw_pads(amd_manager);
>>  		ret = amd_init_sdw_manager(amd_manager);
>>  		if (ret)
>>  			return ret;
>> -- 
>> 2.34.1


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 04/12] drivers: soundwire: refactor soundwire pads enable
  2023-12-22  7:15     ` Mukunda,Vijendar
@ 2023-12-22  9:21       ` Vinod Koul
  2023-12-22 10:34         ` Mukunda,Vijendar
  0 siblings, 1 reply; 24+ messages in thread
From: Vinod Koul @ 2023-12-22  9:21 UTC (permalink / raw)
  To: Mukunda,Vijendar
  Cc: broonie, alsa-devel, Basavaraj.Hiregoudar, Sunil-kumar.Dommati,
	pierre-louis.bossart, vinod.koul, venkataprasad.potturu,
	Bard Liao, Sanyog Kale, open list

On 22-12-23, 12:45, Mukunda,Vijendar wrote:
> On 21/12/23 22:08, Vinod Koul wrote:

> > so the code is copied from a GPL declared file to now and GPL + BSD one!
> > Have you had lawyers look into this... why change one file license ?
> As per recommendations from our legal team, we have updated the license as dual
> one for amd_init.c file.
> We have also observed that license terms should be updated for other files as
> well (amd_manager.c, amd_manager.h & sdw_amd.h) as dual one, which we have
> planned to submit as a supplement patch.

Lets change that first before we move code from one license file to
another

Btw why would you want to do the change of license form GPL to dual?

-- 
~Vinod

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 04/12] drivers: soundwire: refactor soundwire pads enable
  2023-12-22  9:21       ` Vinod Koul
@ 2023-12-22 10:34         ` Mukunda,Vijendar
  2023-12-22 15:45           ` Vinod Koul
  0 siblings, 1 reply; 24+ messages in thread
From: Mukunda,Vijendar @ 2023-12-22 10:34 UTC (permalink / raw)
  To: Vinod Koul
  Cc: broonie, alsa-devel, Basavaraj.Hiregoudar, Sunil-kumar.Dommati,
	pierre-louis.bossart, vinod.koul, venkataprasad.potturu,
	Bard Liao, Sanyog Kale, open list

On 22/12/23 14:51, Vinod Koul wrote:
> On 22-12-23, 12:45, Mukunda,Vijendar wrote:
>> On 21/12/23 22:08, Vinod Koul wrote:
>>> so the code is copied from a GPL declared file to now and GPL + BSD one!
>>> Have you had lawyers look into this... why change one file license ?
>> As per recommendations from our legal team, we have updated the license as dual
>> one for amd_init.c file.
>> We have also observed that license terms should be updated for other files as
>> well (amd_manager.c, amd_manager.h & sdw_amd.h) as dual one, which we have
>> planned to submit as a supplement patch.
> Lets change that first before we move code from one license file to
> another
Will push the license update patch first.
>
> Btw why would you want to do the change of license form GPL to dual?
As this code being used by AMD SOF stack which uses dual license,
So we want to maintain the same license terms.
>


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 04/12] drivers: soundwire: refactor soundwire pads enable
  2023-12-22 10:34         ` Mukunda,Vijendar
@ 2023-12-22 15:45           ` Vinod Koul
  2023-12-23  2:04             ` Mukunda,Vijendar
  0 siblings, 1 reply; 24+ messages in thread
From: Vinod Koul @ 2023-12-22 15:45 UTC (permalink / raw)
  To: Mukunda,Vijendar
  Cc: broonie, alsa-devel, Basavaraj.Hiregoudar, Sunil-kumar.Dommati,
	pierre-louis.bossart, vinod.koul, venkataprasad.potturu,
	Bard Liao, Sanyog Kale, open list

On 22-12-23, 16:04, Mukunda,Vijendar wrote:
> On 22/12/23 14:51, Vinod Koul wrote:
> > On 22-12-23, 12:45, Mukunda,Vijendar wrote:
> >> On 21/12/23 22:08, Vinod Koul wrote:
> >>> so the code is copied from a GPL declared file to now and GPL + BSD one!
> >>> Have you had lawyers look into this... why change one file license ?
> >> As per recommendations from our legal team, we have updated the license as dual
> >> one for amd_init.c file.
> >> We have also observed that license terms should be updated for other files as
> >> well (amd_manager.c, amd_manager.h & sdw_amd.h) as dual one, which we have
> >> planned to submit as a supplement patch.
> > Lets change that first before we move code from one license file to
> > another
> Will push the license update patch first.
> >
> > Btw why would you want to do the change of license form GPL to dual?
> As this code being used by AMD SOF stack which uses dual license,
> So we want to maintain the same license terms.

SOF is firmware, do you share this kernel code with sofproject, that
doesnt make sense to me, maybe I am missing something

-- 
~Vinod

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 04/12] drivers: soundwire: refactor soundwire pads enable
  2023-12-22 15:45           ` Vinod Koul
@ 2023-12-23  2:04             ` Mukunda,Vijendar
  0 siblings, 0 replies; 24+ messages in thread
From: Mukunda,Vijendar @ 2023-12-23  2:04 UTC (permalink / raw)
  To: Vinod Koul
  Cc: broonie, alsa-devel, Basavaraj.Hiregoudar, Sunil-kumar.Dommati,
	pierre-louis.bossart, vinod.koul, venkataprasad.potturu,
	Bard Liao, Sanyog Kale, open list

On 22/12/23 21:15, Vinod Koul wrote:
> On 22-12-23, 16:04, Mukunda,Vijendar wrote:
>> On 22/12/23 14:51, Vinod Koul wrote:
>>> On 22-12-23, 12:45, Mukunda,Vijendar wrote:
>>>> On 21/12/23 22:08, Vinod Koul wrote:
>>>>> so the code is copied from a GPL declared file to now and GPL + BSD one!
>>>>> Have you had lawyers look into this... why change one file license ?
>>>> As per recommendations from our legal team, we have updated the license as dual
>>>> one for amd_init.c file.
>>>> We have also observed that license terms should be updated for other files as
>>>> well (amd_manager.c, amd_manager.h & sdw_amd.h) as dual one, which we have
>>>> planned to submit as a supplement patch.
>>> Lets change that first before we move code from one license file to
>>> another
>> Will push the license update patch first.
>>> Btw why would you want to do the change of license form GPL to dual?
>> As this code being used by AMD SOF stack which uses dual license,
>> So we want to maintain the same license terms.
> SOF is firmware, do you share this kernel code with sofproject, that
> doesnt make sense to me, maybe I am missing something
We meant to say this code being used by AMD sof driver stack
(sound/soc/sof/amd) which has dual license.



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 00/12] soundwire/SOF: add SoundWire Interface support for AMD SOF stack
  2023-12-21  7:35 [PATCH 00/12] soundwire/SOF: add SoundWire Interface support for AMD SOF stack Vijendar Mukunda
                   ` (12 preceding siblings ...)
  2023-12-21  8:27 ` [PATCH 00/12] soundwire/SOF: add SoundWire Interface support for AMD SOF stack Pierre-Louis Bossart
@ 2024-01-09 12:41 ` Mukunda,Vijendar
  2024-01-09 13:44   ` Mark Brown
  13 siblings, 1 reply; 24+ messages in thread
From: Mukunda,Vijendar @ 2024-01-09 12:41 UTC (permalink / raw)
  To: broonie, vkoul
  Cc: alsa-devel, Basavaraj.Hiregoudar, Sunil-kumar.Dommati,
	pierre-louis.bossart, vinod.koul, venkataprasad.potturu,
	Bard Liao

On 21/12/23 13:05, Vijendar Mukunda wrote:
> This patch series is to redesign existing platform device
> creation logic for SoundWire managers and Implement generic
> functions for SoundWire manager probe, start and exit sequence
> which are common for both Legacy(NO DSP enabled) and SOF stack,
> and add SoundWire Interface support for AMD SOF stack
> (ACP 6.3 based platforms).
>
> Vijendar Mukunda (12):
>   ASoC/soundwire: implement generic api for scanning amd soundwire
>     controller
>   
>   drivers: soundwire: implement function to extract slave information
>   drivers: soundwire: refactor soundwire pads enable
>   drivers: soundwire: refactor register mask structure
>   ASoC: SOF: amd: add code for invoking soundwire manager helper
>     functions
>   ASoC: SOF: amd: add interrupt handling for SoundWire manager devices
>   ASoC: SOF: amd: Add Soundwire DAI configuration support for AMD
>     platforms
>   ASoC: SOF: amd: add machine select logic for soundwire based platforms
>   ASoC: SOF: amd: update descriptor fields for acp6.3 based platform
>   ASoC: SOF: amd: select soundwire dependency flag for acp6.3 based
>     platform
>   ASoC: SOF: amd: refactor acp driver pm ops

We need to post v2 version patch set.
There are few patch dependencies.

"drivers: soundwire: refactor amd soundwire manager device node creation" patch
has dependency on
"ASoC/soundwire: implement generic api for scanning amd soundwire controller"

SOF patch " ASoC: SOF: amd: add code for invoking soundwire manager
helper functions" has dependency on SoundWire patch set.

As this patch series has to go in two different sub systems,
Please suggest how can we push the patch series to get it reviewed and merged
at one go. 
>
>  drivers/soundwire/Makefile         |   2 +-
>  drivers/soundwire/amd_init.c       | 235 +++++++++++++++++++++++++++++
>  drivers/soundwire/amd_init.h       |  13 ++
>  drivers/soundwire/amd_manager.c    |  41 +----
>  drivers/soundwire/amd_manager.h    |  12 +-
>  include/linux/soundwire/sdw_amd.h  |  79 ++++++++--
>  include/sound/sof/dai-amd.h        |   7 +
>  include/sound/sof/dai.h            |   2 +
>  include/uapi/sound/sof/tokens.h    |   4 +
>  sound/soc/amd/acp/Kconfig          |   7 +
>  sound/soc/amd/acp/Makefile         |   2 +
>  sound/soc/amd/acp/amd-sdw-acpi.c   |  62 ++++++++
>  sound/soc/sof/amd/Kconfig          |  18 +++
>  sound/soc/sof/amd/acp-common.c     |  65 +++++++-
>  sound/soc/sof/amd/acp-dsp-offset.h |  10 ++
>  sound/soc/sof/amd/acp.c            | 202 ++++++++++++++++++++++++-
>  sound/soc/sof/amd/acp.h            |  26 +++-
>  sound/soc/sof/amd/pci-acp63.c      |   7 +
>  sound/soc/sof/ipc3-pcm.c           |  25 +++
>  sound/soc/sof/ipc3-topology.c      |  40 +++++
>  sound/soc/sof/sof-audio.h          |   1 +
>  sound/soc/sof/topology.c           |   5 +
>  22 files changed, 798 insertions(+), 67 deletions(-)
>  create mode 100644 drivers/soundwire/amd_init.c
>  create mode 100644 drivers/soundwire/amd_init.h
>  create mode 100644 sound/soc/amd/acp/amd-sdw-acpi.c
>


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 00/12] soundwire/SOF: add SoundWire Interface support for AMD SOF stack
  2024-01-09 12:41 ` Mukunda,Vijendar
@ 2024-01-09 13:44   ` Mark Brown
  0 siblings, 0 replies; 24+ messages in thread
From: Mark Brown @ 2024-01-09 13:44 UTC (permalink / raw)
  To: Mukunda,Vijendar
  Cc: vkoul, alsa-devel, Basavaraj.Hiregoudar, Sunil-kumar.Dommati,
	pierre-louis.bossart, vinod.koul, venkataprasad.potturu,
	Bard Liao

[-- Attachment #1: Type: text/plain, Size: 505 bytes --]

On Tue, Jan 09, 2024 at 06:11:18PM +0530, Mukunda,Vijendar wrote:

> SOF patch " ASoC: SOF: amd: add code for invoking soundwire manager
> helper functions" has dependency on SoundWire patch set.

> As this patch series has to go in two different sub systems,
> Please suggest how can we push the patch series to get it reviewed and merged
> at one go. 

I'd expect Vinod to review the Soundwire bits and either ack them or
provide a pull request with them that I can fetch into the ASoC tree.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 484 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2024-01-09 13:45 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-21  7:35 [PATCH 00/12] soundwire/SOF: add SoundWire Interface support for AMD SOF stack Vijendar Mukunda
2023-12-21  7:35 ` [PATCH 01/12] ASoC/soundwire: implement generic api for scanning amd soundwire controller Vijendar Mukunda
2023-12-21  7:35 ` [PATCH 02/12] drivers: soundwire: refactor amd soundwire manager device node creation Vijendar Mukunda
2023-12-21 16:34   ` Vinod Koul
2023-12-22  5:32     ` Mukunda,Vijendar
2023-12-21  7:35 ` [PATCH 03/12] drivers: soundwire: implement function to extract slave information Vijendar Mukunda
2023-12-21  7:35 ` [PATCH 04/12] drivers: soundwire: refactor soundwire pads enable Vijendar Mukunda
2023-12-21 16:38   ` Vinod Koul
2023-12-22  7:15     ` Mukunda,Vijendar
2023-12-22  9:21       ` Vinod Koul
2023-12-22 10:34         ` Mukunda,Vijendar
2023-12-22 15:45           ` Vinod Koul
2023-12-23  2:04             ` Mukunda,Vijendar
2023-12-21  7:35 ` [PATCH 05/12] drivers: soundwire: refactor register mask structure Vijendar Mukunda
2023-12-21  7:35 ` [PATCH 06/12] ASoC: SOF: amd: add code for invoking soundwire manager helper functions Vijendar Mukunda
2023-12-21  7:35 ` [PATCH 07/12] ASoC: SOF: amd: add interrupt handling for SoundWire manager devices Vijendar Mukunda
2023-12-21  7:35 ` [PATCH 08/12] ASoC: SOF: amd: Add Soundwire DAI configuration support for AMD platforms Vijendar Mukunda
2023-12-21  7:35 ` [PATCH 09/12] ASoC: SOF: amd: add machine select logic for soundwire based platforms Vijendar Mukunda
2023-12-21  7:35 ` [PATCH 10/12] ASoC: SOF: amd: update descriptor fields for acp6.3 based platform Vijendar Mukunda
2023-12-21  7:35 ` [PATCH 11/12] ASoC: SOF: amd: select soundwire dependency flag " Vijendar Mukunda
2023-12-21  7:35 ` [PATCH 12/12] ASoC: SOF: amd: refactor acp driver pm ops Vijendar Mukunda
2023-12-21  8:27 ` [PATCH 00/12] soundwire/SOF: add SoundWire Interface support for AMD SOF stack Pierre-Louis Bossart
2024-01-09 12:41 ` Mukunda,Vijendar
2024-01-09 13:44   ` Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.