[RFC PATCH 3/8] ASoC: SDCA: expose class helpers with hw_ops for non-DisCo platforms

From: Srinivas Kandagatla

Date: Wed Jul 22 2026 - 19:47:01 EST


On ARM/DT platforms without ACPI/DisCo, sdca_lookup_functions() is a
no-op and num_functions stays 0. Introduce struct sdca_class_hw_ops
with hw_init and get_function_data callbacks so codec drivers can
supply pre-populated sdca_function_data and toggle supplies/reset at
probe time.

Convert the class SoundWire probe into an exported library helper
sdca_class_probe(sdw, hw_ops) and export sdca_class_read_prop() and
sdca_class_pm_ops. Codec-specific SoundWire drivers can register their
own sdw_driver and call these helpers from their probe. The built-in
class_sdw_driver stays for generic SDCA parts that need no per-device
quirks (hw_ops = NULL).

For non-DisCo boots, the class helper injects the driver-supplied
function descriptors into sdca_device_data so sdca_dev_register_functions()
can create the auxiliary devices, and the auxiliary function driver uses
get_function_data() as a fallback source of per-entity data when the
firmware node is absent.

Assisted-by: Claude:claude-opus-4-7
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@xxxxxxxxxxxxxxxx>
---
sound/soc/sdca/sdca_class.c | 83 +++++++++++++++++++++++++--
sound/soc/sdca/sdca_class.h | 30 ++++++++++
sound/soc/sdca/sdca_class_function.c | 40 ++++++++++++-
sound/soc/sdca/sdca_function_device.c | 2 +-
4 files changed, 146 insertions(+), 9 deletions(-)

diff --git a/sound/soc/sdca/sdca_class.c b/sound/soc/sdca/sdca_class.c
index 8d7b007a068f..c9a4cce77557 100644
--- a/sound/soc/sdca/sdca_class.c
+++ b/sound/soc/sdca/sdca_class.c
@@ -24,7 +24,15 @@

#define CLASS_SDW_ATTACH_TIMEOUT_MS 5000

-static int class_read_prop(struct sdw_slave *sdw)
+/**
+ * sdca_class_read_prop - fill SDCA-common SoundWire slave properties
+ * @sdw: SoundWire slave
+ *
+ * Exported so codec-specific SoundWire drivers can invoke the SDCA
+ * common property setup from their own sdw_slave_ops.read_prop, and
+ * then apply codec-specific overrides inline.
+ */
+int sdca_class_read_prop(struct sdw_slave *sdw)
{
struct sdw_slave_prop *prop = &sdw->prop;

@@ -36,9 +44,10 @@ static int class_read_prop(struct sdw_slave *sdw)

return 0;
}
+EXPORT_SYMBOL_NS_GPL(sdca_class_read_prop, "SND_SOC_SDCA_CLASS");

static const struct sdw_slave_ops class_sdw_ops = {
- .read_prop = class_read_prop,
+ .read_prop = sdca_class_read_prop,
};

static void class_regmap_lock(void *data)
@@ -136,9 +145,23 @@ static void class_boot_work(struct work_struct *work)
pm_runtime_put_sync(drv->dev);
}

-static int class_sdw_probe(struct sdw_slave *sdw, const struct sdw_device_id *id)
+/**
+ * sdca_class_probe - SDCA class SoundWire slave probe helper
+ * @sdw: SoundWire slave
+ * @hw_ops: optional device-specific hw_ops (may be NULL for pure-generic
+ * SDCA parts that need no quirks)
+ *
+ * Exported so codec-specific SoundWire drivers can call this from their
+ * own sdw_driver.probe. For codecs with quirks, pass the codec's
+ * sdca_class_hw_ops so hw_init, DT function injection, and PDE hooks
+ * are wired up. For pure-generic SDCA parts (used by the built-in
+ * class_sdw_driver in this file), pass NULL.
+ */
+int sdca_class_probe(struct sdw_slave *sdw,
+ const struct sdca_class_hw_ops *hw_ops)
{
struct device *dev = &sdw->dev;
+ struct sdca_device_data *data = &sdw->sdca_data;
struct regmap_config *dev_config;
struct sdca_class_drv *drv;
int ret;
@@ -156,11 +179,47 @@ static int class_sdw_probe(struct sdw_slave *sdw, const struct sdw_device_id *id

drv->dev = dev;
drv->sdw = sdw;
+ drv->hw_ops = hw_ops;
mutex_init(&drv->regmap_lock);
mutex_init(&drv->init_lock);

dev_set_drvdata(drv->dev, drv);

+ /*
+ * On ARM platforms without ACPI/DisCo tables, sdca_lookup_functions()
+ * is a no-op and num_functions stays 0. Inject the function descriptors
+ * from the device-specific static data so sdca_dev_register_functions()
+ * can create the auxiliary devices.
+ */
+ if (data->num_functions == 0 && hw_ops && hw_ops->get_function_data) {
+ struct sdca_function_data *fdata;
+ unsigned int num = 0;
+ unsigned int i;
+
+ fdata = hw_ops->get_function_data(&num);
+ if (!fdata || num == 0 || num > SDCA_MAX_FUNCTION_COUNT)
+ return -EINVAL;
+
+ for (i = 0; i < num; i++) {
+ if (!fdata[i].desc)
+ return -EINVAL;
+ data->function[i].type = fdata[i].desc->type;
+ data->function[i].adr = fdata[i].desc->adr;
+ data->function[i].name = fdata[i].desc->name;
+ data->function[i].node = NULL;
+ }
+ data->num_functions = num;
+
+ dev_info(dev, "no DisCo/ACPI functions found, injected %u descriptor(s)\n",
+ num);
+ }
+
+ if (hw_ops && hw_ops->hw_init) {
+ ret = hw_ops->hw_init(sdw);
+ if (ret)
+ return dev_err_probe(dev, ret, "hw_init failed\n");
+ }
+
INIT_WORK(&drv->boot_work, class_boot_work);

dev_config->lock_arg = &drv->regmap_lock;
@@ -185,6 +244,13 @@ static int class_sdw_probe(struct sdw_slave *sdw, const struct sdw_device_id *id

return 0;
}
+EXPORT_SYMBOL_NS_GPL(sdca_class_probe, "SND_SOC_SDCA_CLASS");
+
+static int class_sdw_probe(struct sdw_slave *sdw, const struct sdw_device_id *id)
+{
+ /* Pure-generic SDCA parts: no per-device hw_ops. */
+ return sdca_class_probe(sdw, NULL);
+}

static void class_sdw_remove(struct sdw_slave *sdw)
{
@@ -266,11 +332,18 @@ static int class_runtime_resume(struct device *dev)
return ret;
}

-static const struct dev_pm_ops class_pm_ops = {
+const struct dev_pm_ops sdca_class_pm_ops = {
SYSTEM_SLEEP_PM_OPS(class_suspend, class_resume)
RUNTIME_PM_OPS(class_runtime_suspend, class_runtime_resume, NULL)
};
+EXPORT_SYMBOL_NS_GPL(sdca_class_pm_ops, "SND_SOC_SDCA_CLASS");

+/*
+ * Built-in class driver for SDCA parts that need no per-device quirks.
+ * Codecs that need hw_ops (hw_init, DT function injection, PDE / jack
+ * hooks, etc.) register their own sdw_driver and call
+ * sdca_class_probe(slave, &their_hw_ops) from their .probe.
+ */
static const struct sdw_device_id class_sdw_id[] = {
SDW_SLAVE_ENTRY(0x01FA, 0x4245, 0),
SDW_SLAVE_ENTRY(0x01FA, 0x4249, 0),
@@ -282,7 +355,7 @@ MODULE_DEVICE_TABLE(sdw, class_sdw_id);
static struct sdw_driver class_sdw_driver = {
.driver = {
.name = "sdca_class",
- .pm = pm_ptr(&class_pm_ops),
+ .pm = pm_ptr(&sdca_class_pm_ops),
},

.probe = class_sdw_probe,
diff --git a/sound/soc/sdca/sdca_class.h b/sound/soc/sdca/sdca_class.h
index 57f7f8d08f49..74db9d4ce4a2 100644
--- a/sound/soc/sdca/sdca_class.h
+++ b/sound/soc/sdca/sdca_class.h
@@ -15,10 +15,32 @@
#include <linux/workqueue.h>

struct device;
+struct dev_pm_ops;
struct regmap;
struct sdw_slave;
struct sdca_function_data;

+/**
+ * struct sdca_class_hw_ops - optional device-specific hardware callbacks
+ * @hw_init: called during probe to enable supplies, toggle reset GPIO, etc.
+ * @get_function_data: called when no DisCo/ACPI firmware node is available
+ * (e.g. DT/ARM platforms) to supply pre-populated static function
+ * data in place of sdca_parse_function(). Returns a pointer to
+ * an array of struct sdca_function_data and stores the number
+ * of entries in @num (must be > 0 and <= SDCA_MAX_FUNCTION_COUNT).
+ * May be NULL.
+ *
+ * Codec-specific SoundWire drivers pass a pointer to this struct to
+ * sdca_class_probe() from their sdw_driver.probe. Codec-specific
+ * SoundWire slave property overrides live directly in the codec's
+ * sdw_slave_ops.read_prop, which should call sdca_class_read_prop() to
+ * fill the SDCA-common bits first.
+ */
+struct sdca_class_hw_ops {
+ int (*hw_init)(struct sdw_slave *slave);
+ struct sdca_function_data *(*get_function_data)(unsigned int *num);
+};
+
struct sdca_class_drv {
struct device *dev;
struct regmap *dev_regmap;
@@ -26,10 +48,18 @@ struct sdca_class_drv {

struct sdca_interrupt_info *irq_info;

+ const struct sdca_class_hw_ops *hw_ops;
+
struct mutex regmap_lock;
/* Serialise function initialisations */
struct mutex init_lock;
struct work_struct boot_work;
};

+/* Library helpers used by codec-specific SDCA SoundWire drivers. */
+int sdca_class_read_prop(struct sdw_slave *sdw);
+int sdca_class_probe(struct sdw_slave *sdw,
+ const struct sdca_class_hw_ops *hw_ops);
+extern const struct dev_pm_ops sdca_class_pm_ops;
+
#endif /* __SDCA_CLASS_H__ */
diff --git a/sound/soc/sdca/sdca_class_function.c b/sound/soc/sdca/sdca_class_function.c
index 1496a15f7d2a..905c96ed6172 100644
--- a/sound/soc/sdca/sdca_class_function.c
+++ b/sound/soc/sdca/sdca_class_function.c
@@ -329,9 +329,43 @@ static int class_function_probe(struct auxiliary_device *auxdev,
drv->core = core;
drv->function = &sdev->function;

- ret = sdca_parse_function(dev, core->sdw, drv->function);
- if (ret)
- return ret;
+ if (drv->function->desc->node) {
+ ret = sdca_parse_function(dev, core->sdw, drv->function);
+ if (ret)
+ return ret;
+ } else if (core->hw_ops && core->hw_ops->get_function_data) {
+ /*
+ * No DisCo/ACPI firmware node available (e.g. DT/ARM platform).
+ * Use pre-populated static function data supplied by the
+ * device-specific hw_ops instead of sdca_parse_function().
+ * The callback returns an array of function_data entries;
+ * pick the one matching this auxdev's function type.
+ */
+ struct sdca_function_data *fdata;
+ unsigned int num = 0;
+ unsigned int i;
+
+ fdata = core->hw_ops->get_function_data(&num);
+ if (!fdata || num == 0)
+ return -EINVAL;
+
+ for (i = 0; i < num; i++) {
+ if (fdata[i].desc &&
+ fdata[i].desc->type == sdev->function.desc->type) {
+ *drv->function = fdata[i];
+ drv->function->desc = sdev->function.desc;
+ break;
+ }
+ }
+ if (i == num) {
+ dev_err(dev, "no matching function data for type 0x%x\n",
+ sdev->function.desc->type);
+ return -EINVAL;
+ }
+ } else {
+ dev_err(dev, "no firmware node and no get_function_data hook\n");
+ return -EINVAL;
+ }

ndefaults = sdca_regmap_count_constants(dev, drv->function);
if (ndefaults < 0)
diff --git a/sound/soc/sdca/sdca_function_device.c b/sound/soc/sdca/sdca_function_device.c
index b5ca98283a88..9fecfcfdbb6d 100644
--- a/sound/soc/sdca/sdca_function_device.c
+++ b/sound/soc/sdca/sdca_function_device.c
@@ -46,7 +46,7 @@ static struct sdca_dev *sdca_dev_register(struct device *parent,
auxdev = &sdev->auxdev;
auxdev->name = function_desc->name;
auxdev->dev.parent = parent;
- auxdev->dev.fwnode = function_desc->node;
+ auxdev->dev.fwnode = function_desc->node ?: dev_fwnode(parent);
auxdev->dev.release = sdca_dev_release;

sdev->function.desc = function_desc;
--
2.53.0