ASoC: SDCA: export PM helpers keyed on sdca_class_drv

The class PM callbacks pull sdca_class_drv out of drvdata, so the
built-in class_sdw_driver owns the drvdata slot. That works for the
generic case but blocks codec drivers that want to embed
sdca_class_drv in their own private struct -- they need drvdata for
their codec priv.

Split the four callbacks into exported helpers that take a
struct sdca_class_drv * directly:

  sdca_class_system_suspend()
  sdca_class_system_resume()
  sdca_class_runtime_suspend()
  sdca_class_runtime_resume()

Codec drivers can now compose these into their own dev_pm_ops without
going through drvdata.

For the built-in class_sdw_driver, add small dev_pm_ops wrappers that
fetch drv from drvdata and wire them into sdca_class_pm_ops. The ops
struct itself stays private to this file; codec drivers build their
own dev_pm_ops from the four exported helpers above.

No functional change: the built-in class_sdw_driver keeps the same PM
semantics; only the internal plumbing shifts to operate on
sdca_class_drv instead of struct device *dev.

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-3-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:43 +01:00 committed by Mark Brown
parent 677507a530
commit 0985313a2a
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0
3 changed files with 78 additions and 19 deletions

View File

@ -32,4 +32,18 @@ struct sdca_class_drv {
struct work_struct boot_work;
};
/*
* 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:
*
* static int wcd_runtime_suspend(struct device *dev) {
* struct wcd_priv *priv = dev_get_drvdata(dev);
* return sdca_class_runtime_suspend(&priv->class);
* }
*/
int sdca_class_runtime_suspend(struct sdca_class_drv *drv);
int sdca_class_runtime_resume(struct sdca_class_drv *drv);
int sdca_class_system_suspend(struct sdca_class_drv *drv);
int sdca_class_system_resume(struct sdca_class_drv *drv);
#endif /* __SDCA_CLASS_H__ */

View File

@ -20,7 +20,7 @@
#include <sound/sdca_function.h>
#include <sound/sdca_interrupts.h>
#include <sound/sdca_regmap.h>
#include "sdca_class.h"
#include <sound/sdca_class.h>
#define CLASS_SDW_ATTACH_TIMEOUT_MS 5000
@ -194,30 +194,41 @@ static void class_sdw_remove(struct sdw_slave *sdw)
cancel_work_sync(&drv->boot_work);
}
static int class_suspend(struct device *dev)
/**
* sdca_class_system_suspend - SDCA class system suspend helper
* @drv: caller-owned sdca_class_drv.
*
* Codec drivers compose this into their own dev_pm_ops. Disables the
* SoundWire interrupt and forces runtime suspend of the underlying
* class regmap.
*/
int sdca_class_system_suspend(struct sdca_class_drv *drv)
{
struct sdca_class_drv *drv = dev_get_drvdata(dev);
int ret;
disable_irq(drv->sdw->irq);
ret = pm_runtime_force_suspend(dev);
ret = pm_runtime_force_suspend(drv->dev);
if (ret) {
dev_err(dev, "failed to force suspend: %d\n", ret);
dev_err(drv->dev, "failed to force suspend: %d\n", ret);
return ret;
}
return 0;
}
EXPORT_SYMBOL_NS_GPL(sdca_class_system_suspend, "SND_SOC_SDCA_CLASS");
static int class_resume(struct device *dev)
/**
* sdca_class_system_resume - SDCA class system resume helper
* @drv: caller-owned sdca_class_drv.
*/
int sdca_class_system_resume(struct sdca_class_drv *drv)
{
struct sdca_class_drv *drv = dev_get_drvdata(dev);
int ret;
ret = pm_runtime_force_resume(dev);
ret = pm_runtime_force_resume(drv->dev);
if (ret) {
dev_err(dev, "failed to force resume: %d\n", ret);
dev_err(drv->dev, "failed to force resume: %d\n", ret);
return ret;
}
@ -225,11 +236,14 @@ static int class_resume(struct device *dev)
return 0;
}
EXPORT_SYMBOL_NS_GPL(sdca_class_system_resume, "SND_SOC_SDCA_CLASS");
static int class_runtime_suspend(struct device *dev)
/**
* sdca_class_runtime_suspend - SDCA class runtime suspend helper
* @drv: caller-owned sdca_class_drv.
*/
int sdca_class_runtime_suspend(struct sdca_class_drv *drv)
{
struct sdca_class_drv *drv = dev_get_drvdata(dev);
/*
* Whilst the driver doesn't power the chip down here, going into runtime
* suspend lets the SoundWire bus power down, which means the driver
@ -239,10 +253,14 @@ static int class_runtime_suspend(struct device *dev)
return 0;
}
EXPORT_SYMBOL_NS_GPL(sdca_class_runtime_suspend, "SND_SOC_SDCA_CLASS");
static int class_runtime_resume(struct device *dev)
/**
* sdca_class_runtime_resume - SDCA class runtime resume helper
* @drv: caller-owned sdca_class_drv.
*/
int sdca_class_runtime_resume(struct sdca_class_drv *drv)
{
struct sdca_class_drv *drv = dev_get_drvdata(dev);
int ret;
ret = sdw_slave_wait_for_init(drv->sdw, CLASS_SDW_ATTACH_TIMEOUT_MS);
@ -265,10 +283,37 @@ static int class_runtime_resume(struct device *dev)
return ret;
}
EXPORT_SYMBOL_NS_GPL(sdca_class_runtime_resume, "SND_SOC_SDCA_CLASS");
static const struct dev_pm_ops class_pm_ops = {
SYSTEM_SLEEP_PM_OPS(class_suspend, class_resume)
RUNTIME_PM_OPS(class_runtime_suspend, class_runtime_resume, NULL)
/*
* Convenience dev_pm_ops used by the built-in class_sdw_driver, which
* stashes its sdca_class_drv in drvdata directly. Codec drivers that
* embed sdca_class_drv in their own priv compose their own dev_pm_ops
* using the sdca_class_*_suspend/resume helpers above.
*/
static int class_pm_system_suspend(struct device *dev)
{
return sdca_class_system_suspend(dev_get_drvdata(dev));
}
static int class_pm_system_resume(struct device *dev)
{
return sdca_class_system_resume(dev_get_drvdata(dev));
}
static int class_pm_runtime_suspend(struct device *dev)
{
return sdca_class_runtime_suspend(dev_get_drvdata(dev));
}
static int class_pm_runtime_resume(struct device *dev)
{
return sdca_class_runtime_resume(dev_get_drvdata(dev));
}
static const struct dev_pm_ops sdca_class_pm_ops = {
SYSTEM_SLEEP_PM_OPS(class_pm_system_suspend, class_pm_system_resume)
RUNTIME_PM_OPS(class_pm_runtime_suspend, class_pm_runtime_resume, NULL)
};
static const struct sdw_device_id class_sdw_id[] = {
@ -282,7 +327,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,

View File

@ -26,7 +26,7 @@
#include <sound/soc-component.h>
#include <sound/soc-dai.h>
#include <sound/soc.h>
#include "sdca_class.h"
#include <sound/sdca_class.h>
#include "sdca_function_device.h"
struct class_function_drv {