Commit 9178feb4 authored by Kuninori Morimoto's avatar Kuninori Morimoto Committed by Mark Brown

ASoC: add Component level suspend/resume

In current ALSA SoC, Codec only has suspend/resume feature,
but it should be supported on Component level. This patch adds it.
Signed-off-by: default avatarKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 1a653aa4
...@@ -782,6 +782,8 @@ struct snd_soc_component_driver { ...@@ -782,6 +782,8 @@ struct snd_soc_component_driver {
int (*probe)(struct snd_soc_component *); int (*probe)(struct snd_soc_component *);
void (*remove)(struct snd_soc_component *); void (*remove)(struct snd_soc_component *);
int (*suspend)(struct snd_soc_component *);
int (*resume)(struct snd_soc_component *);
/* DT */ /* DT */
int (*of_xlate_dai_name)(struct snd_soc_component *component, int (*of_xlate_dai_name)(struct snd_soc_component *component,
...@@ -808,6 +810,7 @@ struct snd_soc_component { ...@@ -808,6 +810,7 @@ struct snd_soc_component {
unsigned int ignore_pmdown_time:1; /* pmdown_time is ignored at stop */ unsigned int ignore_pmdown_time:1; /* pmdown_time is ignored at stop */
unsigned int registered_as_component:1; unsigned int registered_as_component:1;
unsigned int auxiliary:1; /* for auxiliary component of the card */ unsigned int auxiliary:1; /* for auxiliary component of the card */
unsigned int suspended:1; /* is in suspend PM state */
struct list_head list; struct list_head list;
struct list_head card_list; struct list_head card_list;
...@@ -853,6 +856,8 @@ struct snd_soc_component { ...@@ -853,6 +856,8 @@ struct snd_soc_component {
int (*probe)(struct snd_soc_component *); int (*probe)(struct snd_soc_component *);
void (*remove)(struct snd_soc_component *); void (*remove)(struct snd_soc_component *);
int (*suspend)(struct snd_soc_component *);
int (*resume)(struct snd_soc_component *);
/* machine specific init */ /* machine specific init */
int (*init)(struct snd_soc_component *component); int (*init)(struct snd_soc_component *component);
...@@ -872,7 +877,6 @@ struct snd_soc_codec { ...@@ -872,7 +877,6 @@ struct snd_soc_codec {
/* runtime */ /* runtime */
unsigned int cache_bypass:1; /* Suppress access to the cache */ unsigned int cache_bypass:1; /* Suppress access to the cache */
unsigned int suspended:1; /* Codec is in suspend PM state */
unsigned int cache_init:1; /* codec cache has been initialized */ unsigned int cache_init:1; /* codec cache has been initialized */
/* codec IO */ /* codec IO */
......
...@@ -702,43 +702,39 @@ int snd_soc_suspend(struct device *dev) ...@@ -702,43 +702,39 @@ int snd_soc_suspend(struct device *dev)
dapm_mark_endpoints_dirty(card); dapm_mark_endpoints_dirty(card);
snd_soc_dapm_sync(&card->dapm); snd_soc_dapm_sync(&card->dapm);
/* suspend all CODECs */ /* suspend all COMPONENTs */
list_for_each_entry(component, &card->component_dev_list, card_list) { list_for_each_entry(component, &card->component_dev_list, card_list) {
struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
struct snd_soc_codec *codec = snd_soc_component_to_codec(component);
if (!codec)
continue;
/* If there are paths active then the CODEC will be held with /* If there are paths active then the COMPONENT will be held with
* bias _ON and should not be suspended. */ * bias _ON and should not be suspended. */
if (!codec->suspended) { if (!component->suspended) {
switch (snd_soc_dapm_get_bias_level(dapm)) { switch (snd_soc_dapm_get_bias_level(dapm)) {
case SND_SOC_BIAS_STANDBY: case SND_SOC_BIAS_STANDBY:
/* /*
* If the CODEC is capable of idle * If the COMPONENT is capable of idle
* bias off then being in STANDBY * bias off then being in STANDBY
* means it's doing something, * means it's doing something,
* otherwise fall through. * otherwise fall through.
*/ */
if (dapm->idle_bias_off) { if (dapm->idle_bias_off) {
dev_dbg(codec->dev, dev_dbg(component->dev,
"ASoC: idle_bias_off CODEC on over suspend\n"); "ASoC: idle_bias_off CODEC on over suspend\n");
break; break;
} }
case SND_SOC_BIAS_OFF: case SND_SOC_BIAS_OFF:
if (codec->driver->suspend) if (component->suspend)
codec->driver->suspend(codec); component->suspend(component);
codec->suspended = 1; component->suspended = 1;
if (codec->component.regmap) if (component->regmap)
regcache_mark_dirty(codec->component.regmap); regcache_mark_dirty(component->regmap);
/* deactivate pins to sleep state */ /* deactivate pins to sleep state */
pinctrl_pm_select_sleep_state(codec->dev); pinctrl_pm_select_sleep_state(component->dev);
break; break;
default: default:
dev_dbg(codec->dev, dev_dbg(component->dev,
"ASoC: CODEC is on over suspend\n"); "ASoC: COMPONENT is on over suspend\n");
break; break;
} }
} }
...@@ -799,15 +795,10 @@ static void soc_resume_deferred(struct work_struct *work) ...@@ -799,15 +795,10 @@ static void soc_resume_deferred(struct work_struct *work)
} }
list_for_each_entry(component, &card->component_dev_list, card_list) { list_for_each_entry(component, &card->component_dev_list, card_list) {
struct snd_soc_codec *codec = snd_soc_component_to_codec(component); if (component->suspended) {
if (component->resume)
if (!codec) component->resume(component);
continue; component->suspended = 0;
if (codec->suspended) {
if (codec->driver->resume)
codec->driver->resume(codec);
codec->suspended = 0;
} }
} }
...@@ -2937,6 +2928,8 @@ static int snd_soc_component_initialize(struct snd_soc_component *component, ...@@ -2937,6 +2928,8 @@ static int snd_soc_component_initialize(struct snd_soc_component *component,
component->driver = driver; component->driver = driver;
component->probe = component->driver->probe; component->probe = component->driver->probe;
component->remove = component->driver->remove; component->remove = component->driver->remove;
component->suspend = component->driver->suspend;
component->resume = component->driver->resume;
dapm = &component->dapm; dapm = &component->dapm;
dapm->dev = dev; dapm->dev = dev;
...@@ -3286,6 +3279,20 @@ static void snd_soc_codec_drv_remove(struct snd_soc_component *component) ...@@ -3286,6 +3279,20 @@ static void snd_soc_codec_drv_remove(struct snd_soc_component *component)
codec->driver->remove(codec); codec->driver->remove(codec);
} }
static int snd_soc_codec_drv_suspend(struct snd_soc_component *component)
{
struct snd_soc_codec *codec = snd_soc_component_to_codec(component);
return codec->driver->suspend(codec);
}
static int snd_soc_codec_drv_resume(struct snd_soc_component *component)
{
struct snd_soc_codec *codec = snd_soc_component_to_codec(component);
return codec->driver->resume(codec);
}
static int snd_soc_codec_drv_write(struct snd_soc_component *component, static int snd_soc_codec_drv_write(struct snd_soc_component *component,
unsigned int reg, unsigned int val) unsigned int reg, unsigned int val)
{ {
...@@ -3347,6 +3354,10 @@ int snd_soc_register_codec(struct device *dev, ...@@ -3347,6 +3354,10 @@ int snd_soc_register_codec(struct device *dev,
codec->component.probe = snd_soc_codec_drv_probe; codec->component.probe = snd_soc_codec_drv_probe;
if (codec_drv->remove) if (codec_drv->remove)
codec->component.remove = snd_soc_codec_drv_remove; codec->component.remove = snd_soc_codec_drv_remove;
if (codec_drv->suspend)
codec->component.suspend = snd_soc_codec_drv_suspend;
if (codec_drv->resume)
codec->component.resume = snd_soc_codec_drv_resume;
if (codec_drv->write) if (codec_drv->write)
codec->component.write = snd_soc_codec_drv_write; codec->component.write = snd_soc_codec_drv_write;
if (codec_drv->read) if (codec_drv->read)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment