ASoC: Handle ignore_pmdown_time for CODEC to CODEC links
Subsystems (6)
Lars-Peter Clausen
maintainerPATCH 1/7 ASoC: Handle ignore_pmdown_time for CODEC to CODEC links
For CODEC to CODEC links we should only immediately power down if both CODECs are configured to ignore the power down delay. Factor the logic for this into a helper function that can be used for both compressed and normal PCMs.
--- include/sound/soc.h | 2 ++ sound/soc/soc-compress.c | 3 +-- sound/soc/soc-pcm.c | 27 +++++++++++++++++++++++++-- 3 files changed, 28 insertions(+), 4 deletions(-)
include/sound/soc.h +2 -0
@@ -413,6 +413,8 @@ struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card,struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime (struct snd_soc_card *card,const char *dai_link); +bool snd_soc_runtime_ignore_pmdown_time (struct snd_soc_pcm_runtime *rtd); +/* Utility functions to get clock rates from various things */ int snd_soc_calc_frame_size (int sample_size,int channels,int tdm_slots);int snd_soc_params_to_frame_size (struct snd_pcm_hw_params *params);
sound/soc/soc-compress.c +1 -2
@@ -235,8 +235,7 @@ static int soc_compr_free(struct snd_compr_stream *cstream) cpu_dai->runtime =NULL ;if (cstream->direction ==SND_COMPRESS_PLAYBACK ) { -if (!rtd->pmdown_time || codec->ignore_pmdown_time || - rtd->dai_link->ignore_pmdown_time) { +if (snd_soc_runtime_ignore_pmdown_time (rtd)) {snd_soc_dapm_stream_event (rtd,SNDRV_PCM_STREAM_PLAYBACK ,SND_SOC_DAPM_STREAM_STOP );
sound/soc/soc-pcm.c +25 -2
@@ -35,6 +35,30 @@#define DPCM_MAX_BE_USERS 8/** +* snd_soc_runtime_ignore_pmdown_time() - Check whether to ignore the power down delay +* @rtd: The ASoC PCM runtime that should be checked. +* +* This function checks whether the power down delay should be ignored for a +* specific PCM runtime. Returns true if the delay is 0, if it the DAI link has +* been configured to ignore the delay, or if none of the components benefits +* from having the delay. +*/ +bool snd_soc_runtime_ignore_pmdown_time (struct snd_soc_pcm_runtime *rtd) +{ +bool ignore = true; + +if (!rtd->pmdown_time || rtd->dai_link->ignore_pmdown_time) +return true; + +if (rtd->cpu_dai->codec) + ignore &= rtd->cpu_dai->codec->ignore_pmdown_time; + + ignore &= rtd->codec_dai->codec->ignore_pmdown_time; + +return ignore; +} + +/** * snd_soc_set_runtime_hwparams - set the runtime hardware parameters * @substream: the pcm substream * @hw: the hardware parameters
@@ -496,8 +520,7 @@ static int soc_pcm_close(struct snd_pcm_substream *substream) cpu_dai->runtime =NULL ;if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) { -if (!rtd->pmdown_time || codec->ignore_pmdown_time || - rtd->dai_link->ignore_pmdown_time) { +if (snd_soc_runtime_ignore_pmdown_time (rtd)) {/* powered down playback stream now */ snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_PLAYBACK,
Signature · 1 line
1.8.0
Lars-Peter Clausen
maintainerPATCH 2/7 ASoC: Add helper functions for PCM runtime 'active' management
We have the same code that increments and decrements the active field of the various PCM runtime components (all with the same bugs). Factor this out into common helper functions.
--- include/sound/soc.h | 2 ++ sound/soc/soc-compress.c | 62 +++++++--------------------------- sound/soc/soc-pcm.c | 86 +++++++++++++++++++++++++++++++++++------------- 3 files changed, 78 insertions(+), 72 deletions(-)
include/sound/soc.h +2 -0
@@ -414,6 +414,8 @@ struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card, const char *dai_link);bool snd_soc_runtime_ignore_pmdown_time (struct snd_soc_pcm_runtime *rtd); +void snd_soc_runtime_activate (struct snd_soc_pcm_runtime *rtd,int stream); +void snd_soc_runtime_deactivate (struct snd_soc_pcm_runtime *rtd,int stream);/* Utility functions to get clock rates from various things */ int snd_soc_calc_frame_size (int sample_size,int channels,int tdm_slots);
sound/soc/soc-compress.c +12 -50
111 lines not on this page · raw message
sound/soc/soc-pcm.c +64 -22
107 lines not on this page · raw message
Signature · 1 line
1.8.0
Lars-Peter Clausen
maintainerPATCH 3/7 ASoC: Fix active count tracking for CODEC to CODEC links
In reply to Lars-Peter ClausenFor CODEC to CODEC links we need to make sure to also manage the 'active' field of the cpu_dai CODEC.
--- sound/soc/soc-pcm.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
sound/soc/soc-pcm.c +6 -2
@@ -61,7 +61,9 @@ void snd_soc_runtime_activate(struct snd_soc_pcm_runtime *rtd, int stream) cpu_dai->active++; codec_dai->active++; - rtd->codec->active++; +if (cpu_dai->codec) + cpu_dai->codec->active++; + codec_dai->codec->active++; }/**
@@ -91,7 +93,9 @@ void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream) cpu_dai->active--; codec_dai->active--; - rtd->codec->active--; +if (cpu_dai->codec) + cpu_dai->codec->active--; + codec_dai->codec->active--; }/**
Signature · 1 line
1.8.0
Lars-Peter Clausen
maintainerPATCH 4/7 ASoC: Add helper function to check whether a CODEC is active
In reply to Lars-Peter ClausenInstead of directly checking the 'active' field of the CODEC struct add a new helper function that will return either true or false depending on whether the CODEC is active. This will make the migration to the component level easier.
The patch also updates all CODEC drivers that check the active attribute to use the new helper function.
--- include/sound/soc.h | 5 +++++ sound/soc/codecs/adav80x.c | 4 ++-- sound/soc/codecs/tlv320aic23.c | 2 +- sound/soc/codecs/tlv320dac33.c | 2 +- sound/soc/codecs/uda1380.c | 2 +- sound/soc/codecs/wl1273.c | 2 +- sound/soc/codecs/wm8711.c | 2 +- sound/soc/codecs/wm8753.c | 4 ++-- 8 files changed, 14 insertions(+), 9 deletions(-)
include/sound/soc.h +5 -0
@@ -1172,6 +1172,11 @@ static inline bool snd_soc_volsw_is_stereo(struct soc_mixer_control *mc)return 1 ; } +static inline bool snd_soc_codec_is_active (struct snd_soc_codec *codec) +{ +return codec->active !=0 ; +} +int snd_soc_util_init (void );void snd_soc_util_exit (void );
sound/soc/codecs/adav80x.c +2 -2
@@ -722,7 +722,7 @@ static int adav80x_dai_startup(struct snd_pcm_substream *substream,struct snd_soc_codec *codec = dai->codec;struct adav80x *adav80x =snd_soc_codec_get_drvdata (codec); -if (!codec->active || !adav80x->rate) +if (!snd_soc_codec_is_active (codec) || !adav80x->rate)return 0 ; return snd_pcm_hw_constraint_minmax(substream->runtime,
@@ -735,7 +735,7 @@ static void adav80x_dai_shutdown(struct snd_pcm_substream *substream,struct snd_soc_codec *codec = dai->codec;struct adav80x *adav80x =snd_soc_codec_get_drvdata (codec); -if (!codec->active) +if (!snd_soc_codec_is_active (codec)) adav80x->rate =0 ; }
sound/soc/codecs/tlv320aic23.c +1 -1
@@ -400,7 +400,7 @@ static void tlv320aic23_shutdown(struct snd_pcm_substream *substream,struct aic23 *aic23 =snd_soc_codec_get_drvdata (codec);/* deactivate */ -if (!codec->active) { +if (!snd_soc_codec_is_active (codec)) {udelay (50 );snd_soc_write (codec,TLV320AIC23_ACTIVE ,0x0 ); }
sound/soc/codecs/tlv320dac33.c +1 -1
@@ -461,7 +461,7 @@ static int dac33_set_fifo_mode(struct snd_kcontrol *kcontrol,if (dac33->fifo_mode == ucontrol->value.integer.value[0 ])return 0 ;/* Do not allow changes while stream is running*/ -if (codec->active) +if (snd_soc_codec_is_active (codec))return -EPERM ; if (ucontrol->value.integer.value[0] < 0 ||
sound/soc/codecs/uda1380.c +1 -1
@@ -108,7 +108,7 @@ static int uda1380_write(struct snd_soc_codec *codec, unsigned int reg,/* the interpolator & decimator regs must only be written when the * codec DAI is active. */ -if (!codec->active && (reg >=UDA1380_MVOL )) +if (!snd_soc_codec_is_active (codec) && (reg >=UDA1380_MVOL ))return 0 ;pr_debug ("uda1380: hw write %x val %x\n" , reg, value);if (codec->hw_write (codec->control_data, data,3 ) ==3 ) {
sound/soc/codecs/wl1273.c +1 -1
@@ -197,7 +197,7 @@ static int snd_wl1273_set_audio_route(struct snd_kcontrol *kcontrol,return 0 ;/* Do not allow changes while stream is running */ -if (codec->active) +if (snd_soc_codec_is_active (codec))return -EPERM ; if (ucontrol->value.integer.value[0] < 0 ||
sound/soc/codecs/wm8711.c +1 -1
@@ -201,7 +201,7 @@ static void wm8711_shutdown(struct snd_pcm_substream *substream,struct snd_soc_codec *codec = dai->codec;/* deactivate */ -if (!codec->active) { +if (!snd_soc_codec_is_active (codec)) {udelay (50 );snd_soc_write (codec,WM8711_ACTIVE ,0x0 ); }
sound/soc/codecs/wm8753.c +2 -2
@@ -251,7 +251,7 @@ static int wm8753_set_dai(struct snd_kcontrol *kcontrol,if (wm8753->dai_func == ucontrol->value.integer.value[0 ])return 0 ; -if (codec->active) +if (snd_soc_codec_is_active (codec))return -EBUSY ; ioctl =snd_soc_read (codec,WM8753_IOCTL );
@@ -1314,7 +1314,7 @@ static int wm8753_mute(struct snd_soc_dai *dai, int mute)/* the digital mute covers the HiFi and Voice DAC's on the WM8753. * make sure we check if they are not both active when we mute */ if (mute && wm8753->dai_func ==1 ) { -if (!codec->active) +if (!snd_soc_codec_is_active (codec))snd_soc_write (codec,WM8753_DAC , mute_reg |0x8 ); }else {if (mute)
Signature · 1 line
1.8.0
Lars-Peter Clausen
maintainerPATCH 5/7 ASoC: Add component pointer to the DAI struct
In reply to Lars-Peter ClausenKeep track of which component registered a DAI. We'll need this as componentization progresses.
--- include/sound/soc-dai.h | 1 + sound/soc/soc-core.c | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-)
include/sound/soc-dai.h +1 -0
@@ -270,6 +270,7 @@ struct snd_soc_dai {/* parent platform/codec */ struct snd_soc_platform *platform;struct snd_soc_codec *codec; +struct snd_soc_component *component;struct snd_soc_card *card;
sound/soc/soc-core.c +12 -6
@@ -3884,11 +3884,13 @@ static inline char *fmt_multiple_name(struct device *dev,/** * snd_soc_register_dai - Register a DAI with the ASoC core * -* @dai: DAI to register +* @component: The component the DAIs are registered for +* @dai_drv: DAI driver to use for the DAIs */ -static int snd_soc_register_dai (struct device *dev, +static int snd_soc_register_dai (struct snd_soc_component *component,struct snd_soc_dai_driver *dai_drv) { +struct device *dev = component->dev;struct snd_soc_codec *codec;struct snd_soc_dai *dai;
@@ -3905,6 +3907,7 @@ static int snd_soc_register_dai(struct device *dev,return -ENOMEM ; } + dai->component = component; dai->dev = dev; dai->driver = dai_drv; dai->dapm.dev = dev;
@@ -3962,12 +3965,14 @@ found:/** * snd_soc_register_dais - Register multiple DAIs with the ASoC core * -* @dai: Array of DAIs to register +* @component: The component the DAIs are registered for +* @dai_drv: DAI driver to use for the DAIs * @count: Number of DAIs */ -static int snd_soc_register_dais (struct device *dev, +static int snd_soc_register_dais (struct snd_soc_component *component,struct snd_soc_dai_driver *dai_drv,size_t count) { +struct device *dev = component->dev;struct snd_soc_codec *codec;struct snd_soc_dai *dai;int i, ret =0 ;
@@ -3990,6 +3995,7 @@ static int snd_soc_register_dais(struct device *dev, goto err; } + dai->component = component; dai->dev = dev; dai->driver = &dai_drv[i];if (dai->driver->id)
@@ -4086,9 +4092,9 @@ __snd_soc_register_component(struct device *dev,* since it had been used snd_soc_register_dais(), */ if ((1 == num_dai) && allow_single_dai) - ret =snd_soc_register_dai (dev, dai_drv); + ret =snd_soc_register_dai (cmpnt, dai_drv);else - ret =snd_soc_register_dais (dev, dai_drv, num_dai); + ret =snd_soc_register_dais (cmpnt, dai_drv, num_dai);if (ret <0 ) {dev_err (dev,"ASoC: Failed to regster DAIs: %d\n" , ret); goto error_component_name;
Signature · 1 line
1.8.0
Lars-Peter Clausen
maintainerPATCH 6/7 ASoC: Move active count from CODEC to component
In reply to Lars-Peter ClausenThere is no reason why active count tracking should only be done for CODECs but not for other components. Moving the active count from the snd_soc_codec struct to the snd_soc_component struct reduces the differences between CODECs and other components and will eventually allow component to component DAI links (Which is a prerequisite for converting CODECs to components).
--- include/sound/soc.h | 12 ++++++++++-- sound/soc/soc-pcm.c | 10 ++++------ 2 files changed, 14 insertions(+), 8 deletions(-)
include/sound/soc.h +10 -2
@@ -660,6 +660,9 @@ struct snd_soc_component {const char *name;int id;struct device *dev; + +unsigned int active; +struct list_head list;struct snd_soc_dai_driver *dai_drv;
@@ -687,7 +690,6 @@ struct snd_soc_codec {/* runtime */ struct snd_ac97 *ac97;/* for ad-hoc ac97 devices */ -unsigned int active; unsigned int cache_bypass:1; /* Suppress access to the cache */ unsigned int suspended:1; /* Codec is in suspend PM state */ unsigned int probed:1; /* Codec has been probed */
@@ -1172,9 +1174,15 @@ static inline bool snd_soc_volsw_is_stereo(struct soc_mixer_control *mc)return 1 ; } +static inline bool snd_soc_component_is_active ( +struct snd_soc_component *component) +{ +return component->active !=0 ; +} +static inline bool snd_soc_codec_is_active (struct snd_soc_codec *codec) { -return codec->active !=0 ; +return snd_soc_component_is_active (&codec->component); }int snd_soc_util_init (void );
sound/soc/soc-pcm.c +4 -6
@@ -61,9 +61,8 @@ void snd_soc_runtime_activate(struct snd_soc_pcm_runtime *rtd, int stream) cpu_dai->active++; codec_dai->active++; -if (cpu_dai->codec) - cpu_dai->codec->active++; - codec_dai->codec->active++; + cpu_dai->component->active++; + codec_dai->component->active++; }/**
@@ -93,9 +92,8 @@ void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream) cpu_dai->active--; codec_dai->active--; -if (cpu_dai->codec) - cpu_dai->codec->active--; - codec_dai->codec->active--; + cpu_dai->component->active--; + codec_dai->component->active--; }/**
Signature · 1 line
1.8.0
Lars-Peter Clausen
maintainerPATCH 7/7 ASoC: Move ignore_pmdown_time from CODEC to component
In reply to Lars-Peter ClausenIn preparation for componentization move the ignore_pmdown_time field from the snd_soc_codec struct to the snd_soc_component struct. Set it to true for non CODEC components for now.
--- include/sound/soc.h | 3 ++- sound/soc/soc-core.c | 4 +++- sound/soc/soc-pcm.c | 10 ++-------- 3 files changed, 7 insertions(+), 10 deletions(-)
include/sound/soc.h +2 -1
@@ -663,6 +663,8 @@ struct snd_soc_component {unsigned int active; + unsigned int ignore_pmdown_time:1; /* pmdown_time is ignored at stop */ +struct list_head list;struct snd_soc_dai_driver *dai_drv;
@@ -715,7 +717,6 @@ struct snd_soc_codec {/* dapm */ struct snd_soc_dapm_context dapm; - unsigned int ignore_pmdown_time:1; /* pmdown_time is ignored at stop */#ifdef CONFIG_DEBUG_FS struct dentry *debugfs_codec_root;
sound/soc/soc-core.c +3 -1
@@ -4127,6 +4127,8 @@ int snd_soc_register_component(struct device *dev,return -ENOMEM ; } + cmpnt->ignore_pmdown_time = true; +return __snd_soc_register_component (dev, cmpnt, cmpnt_drv, dai_drv, num_dai, true); }
@@ -4325,7 +4327,7 @@ int snd_soc_register_codec(struct device *dev, codec->volatile_register = codec_drv->volatile_register; codec->readable_register = codec_drv->readable_register; codec->writable_register = codec_drv->writable_register; - codec->ignore_pmdown_time = codec_drv->ignore_pmdown_time; + codec->component.ignore_pmdown_time = codec_drv->ignore_pmdown_time; codec->dapm.bias_level =SND_SOC_BIAS_OFF ; codec->dapm.dev = dev; codec->dapm.codec = codec;
sound/soc/soc-pcm.c +2 -8
@@ -107,17 +107,11 @@ void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream)*/ bool snd_soc_runtime_ignore_pmdown_time (struct snd_soc_pcm_runtime *rtd) { -bool ignore = true; -if (!rtd->pmdown_time || rtd->dai_link->ignore_pmdown_time)return true; -if (rtd->cpu_dai->codec) - ignore &= rtd->cpu_dai->codec->ignore_pmdown_time; - - ignore &= rtd->codec_dai->codec->ignore_pmdown_time; - -return ignore; +return rtd->cpu_dai->component->ignore_pmdown_time && + rtd->codec_dai->component->ignore_pmdown_time; }/**
Signature · 1 line
1.8.0
Quoted 3 lines · Lars-Peter Clausen
For CODEC to CODEC links we should only immediately power down if both CODECs are configured to ignore the power down delay. Factor the logic for this into a helper function that can be used for both compressed and normal PCMs.
Applied all, thanks.