ASoC: SDCA: expose class SoundWire probe/remove as library

Split the internal class_sdw_probe/class_sdw_remove functions into
caller-friendly library helpers:

  sdca_class_probe(sdw, drv)
  sdca_class_remove(drv)

The class_sdw_probe/class_sdw_remove callbacks of the built-in
class_sdw_driver are now thin wrappers that allocate a bare
sdca_class_drv, stash it in drvdata, and defer to the exported
helpers.

The exported sdca_class_probe() takes a caller-owned struct
sdca_class_drv * so codec-specific SoundWire drivers can embed the
class state in their own priv struct, own dev_set_drvdata() themselves,
and avoid a second allocation.  No functional change for the built-in
driver.

This lays the groundwork for codec-specific SDCA SoundWire drivers
that want to compose the class-side probe with their own quirks; the
next patches add the class_ops mechanism on top.

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
Reviewed-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Link: https://patch.msgid.link/20260925161049.758913-4-srinivas.kandagatla@oss.qualcomm.com
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Srinivas Kandagatla 2026-09-25 17:10:44 +01:00 committed by Mark Brown
parent 0985313a2a
commit a60f1ac41f
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0
2 changed files with 57 additions and 9 deletions

View File

@ -32,6 +32,10 @@ struct sdca_class_drv {
struct work_struct boot_work;
};
/* Library helpers used by codec-specific SDCA SoundWire drivers. */
int sdca_class_probe(struct sdw_slave *sdw, struct sdca_class_drv *drv);
void sdca_class_remove(struct sdca_class_drv *drv);
/*
* PM helpers. Codec drivers embed sdca_class_drv in their own priv,
* own dev_set_drvdata(), and compose these into their own dev_pm_ops:

View File

@ -136,18 +136,31 @@ 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
* @drv: caller-allocated sdca_class_drv storage. The caller (a codec
* driver, or the built-in class_sdw_driver in this file) owns the
* allocation and sets its own dev_set_drvdata() -- the framework
* does not touch drvdata. Typically embedded in the codec's own
* priv struct so codec drivers can keep per-slave state.
*
* Codec-specific SoundWire drivers call this from their .probe after
* allocating a struct sdca_class_drv (usually embedded in their own
* priv) and setting drvdata to their priv. The framework fills in the
* sdca_class_drv fields, sets up the class regmap, and queues the
* deferred boot work.
*/
int sdca_class_probe(struct sdw_slave *sdw, struct sdca_class_drv *drv)
{
struct device *dev = &sdw->dev;
struct regmap_config *dev_config;
struct sdca_class_drv *drv;
int ret;
sdca_lookup_swft(sdw);
drv = devm_kzalloc(dev, sizeof(*drv), GFP_KERNEL);
if (!drv)
return -ENOMEM;
return -EINVAL;
dev_config = devm_kmemdup(dev, &class_dev_regmap_config,
sizeof(*dev_config), GFP_KERNEL);
@ -159,8 +172,6 @@ static int class_sdw_probe(struct sdw_slave *sdw, const struct sdw_device_id *id
mutex_init(&drv->regmap_lock);
mutex_init(&drv->init_lock);
dev_set_drvdata(drv->dev, drv);
INIT_WORK(&drv->boot_work, class_boot_work);
dev_config->lock_arg = &drv->regmap_lock;
@ -185,13 +196,46 @@ 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)
{
struct sdca_class_drv *drv;
/*
* Pure-generic SDCA parts: no codec priv to embed, so allocate a
* bare sdca_class_drv here and stash it in drvdata for the
* built-in PM ops to fetch.
*/
drv = devm_kzalloc(&sdw->dev, sizeof(*drv), GFP_KERNEL);
if (!drv)
return -ENOMEM;
dev_set_drvdata(&sdw->dev, drv);
return sdca_class_probe(sdw, drv);
}
/**
* sdca_class_remove - SDCA class SoundWire slave remove helper
* @drv: caller-owned sdca_class_drv (the one handed to sdca_class_probe()).
*
* Cancels the deferred boot work so devres can safely free @drv and the
* embedding codec priv without racing class_boot_work. Codec-specific
* SoundWire drivers that call sdca_class_probe() must call this from
* their .remove with the same drv pointer they passed to probe.
*/
void sdca_class_remove(struct sdca_class_drv *drv)
{
cancel_work_sync(&drv->boot_work);
}
EXPORT_SYMBOL_NS_GPL(sdca_class_remove, "SND_SOC_SDCA_CLASS");
static void class_sdw_remove(struct sdw_slave *sdw)
{
struct device *dev = &sdw->dev;
struct sdca_class_drv *drv = dev_get_drvdata(dev);
struct sdca_class_drv *drv = dev_get_drvdata(&sdw->dev);
cancel_work_sync(&drv->boot_work);
sdca_class_remove(drv);
}
/**