ASoC: pcm: Properly initialize hw->rate_max
Subsystems (3)
PATCH 1/5 ASoC: pcm: Properly initialize hw->rate_max
If none of the components (CODEC or CPU DAI) sets a maximum sample rate we'll end up with the rate_max field of the runtime hardware set to 0. (Note that it is still possible for the components to constrain the supported sample rates using other methods, e.g. setting a list constraint) If rate_max is 0 this means that the sound card doesn't support any rates at all, which is not the desired result. So initialize rate_max to UINT_MAX. For symmetry reasons also set rate_min to 0.
--- sound/soc/soc-pcm.c | 3 +++ 1 file changed, 3 insertions(+)
sound/soc/soc-pcm.c +3 -0
@@ -252,6 +252,9 @@ static void soc_pcm_init_runtime_hw(struct snd_pcm_runtime *runtime, & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS)) hw->rates |= codec_stream->rates; + hw->rate_min =0 ; + hw->rate_max =UINT_MAX ; +snd_pcm_limit_hw_rates (runtime); hw->rate_min =max (hw->rate_min, cpu_stream->rate_min);
Signature · 1 line
1.8.0
PATCH 2/5 ASoC: fsl: Don't mix SNDRV_PCM_RATE_CONTINUOUS with specific rates
SNDRV_PCM_RATE_CONTINUOUS means that all rates (possibly limited to a certain interval) are supported. There is no need to manually set other rate bits.
--- sound/soc/fsl/fsl_ssi.c | 3 +-- sound/soc/fsl/mpc5200_psc_i2s.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-)
sound/soc/fsl/fsl_ssi.c +1 -2
@@ -81,8 +81,7 @@ static inline void write_ssi_mask(u32 __iomem *addr, u32 clear, u32 set)* ALSA that we support all rates and let the codec driver decide what rates * are really supported. */ -#define FSLSSI_I2S_RATES (SNDRV_PCM_RATE_5512 | SNDRV_PCM_RATE_8000_192000 | \ - SNDRV_PCM_RATE_CONTINUOUS) +#define FSLSSI_I2S_RATES SNDRV_PCM_RATE_CONTINUOUS/** * FSLSSI_I2S_FORMATS: audio formats supported by the SSI
sound/soc/fsl/mpc5200_psc_i2s.c +1 -2
@@ -26,8 +26,7 @@* ALSA that we support all rates and let the codec driver decide what rates * are really supported. */ -#define PSC_I2S_RATES (SNDRV_PCM_RATE_5512 | SNDRV_PCM_RATE_8000_192000 | \ - SNDRV_PCM_RATE_CONTINUOUS) +#define PSC_I2S_RATES SNDRV_PCM_RATE_CONTINUOUS/** * PSC_I2S_FORMATS: audio formats supported by the PSC I2S mode
Signature · 1 line
1.8.0
PATCH 3/5 ASoC: s6000: Don't mix SNDRV_PCM_RATE_CONTINUOUS with specific rates
In reply to Lars-Peter ClausenSNDRV_PCM_RATE_CONTINUOUS means that all rates (possibly limited to a certain interval) are supported. There is no need to manually set other rate bits.
--- sound/soc/s6000/s6000-i2s.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
sound/soc/s6000/s6000-i2s.c +1 -2
@@ -405,8 +405,7 @@ static int s6000_i2s_dai_probe(struct snd_soc_dai *dai)return 0 ; } -#define S6000_I2S_RATES (SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_5512 | \ - SNDRV_PCM_RATE_8000_192000) +#define S6000_I2S_RATES SNDRV_PCM_RATE_CONTINUOUS#define S6000_I2S_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE)static const struct snd_soc_dai_ops s6000_i2s_dai_ops = {
Signature · 6 lines
1.8.0 _______________________________________________ Alsa-devel mailing list [email protected] http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
PATCH 4/5 ALSA: Add helper function for intersecting two rate masks
In reply to Lars-Peter ClausenA bit of special care is necessary when creating the intersection of two rate masks. This comes from the special meaning of the SNDRV_PCM_RATE_CONTINUOUS and SNDRV_PCM_RATE_KNOT bits, which needs special handling when intersecting two rate masks. SNDRV_PCM_RATE_CONTINUOUS means the hardware supports all rates in a specific interval. SNDRV_PCM_RATE_KNOT means the hardware supports a set of discrete rates specified by a list constraint. For all other cases the supported rates are specified directly in the rate mask.
--- include/sound/pcm.h | 2 ++ sound/core/pcm_misc.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+)
include/sound/pcm.h +2 -0
@@ -901,6 +901,8 @@ extern const struct snd_pcm_hw_constraint_list snd_pcm_known_rates;int snd_pcm_limit_hw_rates (struct snd_pcm_runtime *runtime);unsigned int snd_pcm_rate_to_rate_bit (unsigned int rate);unsigned int snd_pcm_rate_bit_to_rate (unsigned int rate_bit); +unsigned int snd_pcm_rate_mask_intersect (unsigned int rates_a, +unsigned int rates_b);static inline void snd_pcm_set_runtime_buffer (struct snd_pcm_substream *substream,struct snd_dma_buffer *bufp)
sound/core/pcm_misc.c +39 -0
@@ -514,3 +514,42 @@ unsigned int snd_pcm_rate_bit_to_rate(unsigned int rate_bit)return 0 ; }EXPORT_SYMBOL (snd_pcm_rate_bit_to_rate); + +static unsigned int snd_pcm_rate_mask_sanitize (unsigned int rates) +{ +if (rates &SNDRV_PCM_RATE_CONTINUOUS ) +return SNDRV_PCM_RATE_CONTINUOUS ; +else if (rates &SNDRV_PCM_RATE_KNOT ) +return SNDRV_PCM_RATE_KNOT ; +return rates; +} + +/** +* snd_pcm_rate_mask_intersect - computes the intersection between two rate masks +* @rates_a: The first rate mask +* @rates_b: The second rate mask +* +* This function computes the rates that are supported by both rate masks passed +* to the function. It will take care of the special handling of +* SNDRV_PCM_RATE_CONTINUOUS and SNDRV_PCM_RATE_KNOT. +* +* Return: A rate mask containing the rates that are supported by both rates_a +* and rates_b. +*/ +unsigned int snd_pcm_rate_mask_intersect (unsigned int rates_a, +unsigned int rates_b) +{ + rates_a =snd_pcm_rate_mask_sanitize (rates_a); + rates_b =snd_pcm_rate_mask_sanitize (rates_b); + +if (rates_a &SNDRV_PCM_RATE_CONTINUOUS ) +return rates_b; +else if (rates_b &SNDRV_PCM_RATE_CONTINUOUS ) +return rates_a; +else if (rates_a &SNDRV_PCM_RATE_KNOT ) +return rates_b; +else if (rates_b &SNDRV_PCM_RATE_KNOT ) +return rates_a; +return rates_a & rates_b; +} +EXPORT_SYMBOL (snd_pcm_rate_mask_intersect);
Signature · 1 line
1.8.0
Re: [PATCH 4/5] ALSA: Add helper function for intersecting two rate masks
At Fri, 10 Jan 2014 16:06:35 +0100,
Quoted 65 lines · Lars-Peter Clausen
A bit of special care is necessary when creating the intersection of two rate masks. This comes from the special meaning of the
SNDRV_PCM_RATE_CONTINUOUSandSNDRV_PCM_RATE_KNOTbits, which needs special handling when intersecting two rate masks.SNDRV_PCM_RATE_CONTINUOUSmeans the hardware supports all rates in a specific interval.SNDRV_PCM_RATE_KNOTmeans the hardware supports a set of discrete rates specified by a list constraint. For all other cases the supported rates are specified directly in the rate mask.Signed-off-by Lars-Peter Clausen <[email protected]>--- include/sound/pcm.h | 2 ++ sound/core/pcm_misc.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+)include/sound/pcm.h +2
-0@@ -901,6 +901,8 @@ extern const struct snd_pcm_hw_constraint_list snd_pcm_known_rates;int snd_pcm_limit_hw_rates (struct snd_pcm_runtime *runtime);unsigned int snd_pcm_rate_to_rate_bit (unsigned int rate);unsigned int snd_pcm_rate_bit_to_rate (unsigned int rate_bit); +unsigned int snd_pcm_rate_mask_intersect (unsigned int rates_a, +unsigned int rates_b);static inline void snd_pcm_set_runtime_buffer (struct snd_pcm_substream *substream,struct snd_dma_buffer *bufp)sound/core/pcm_misc.c +29
-0@@ -514,3 +514,42 @@ unsigned int snd_pcm_rate_bit_to_rate(unsigned int rate_bit)return 0 ; }EXPORT_SYMBOL (snd_pcm_rate_bit_to_rate); + +static unsigned int snd_pcm_rate_mask_sanitize (unsigned int rates) +{ +if (rates &SNDRV_PCM_RATE_CONTINUOUS ) +return SNDRV_PCM_RATE_CONTINUOUS ; +else if (rates &SNDRV_PCM_RATE_KNOT ) +return SNDRV_PCM_RATE_KNOT ; +return rates; +} + +/** +* snd_pcm_rate_mask_intersect - computes the intersection between two rate masks +* @rates_a: The first rate mask +* @rates_b: The second rate mask +* +* This function computes the rates that are supported by both rate masks passed +* to the function. It will take care of the special handling of +* SNDRV_PCM_RATE_CONTINUOUS and SNDRV_PCM_RATE_KNOT. +* +* Return: A rate mask containing the rates that are supported by both rates_a +* and rates_b. +*/ +unsigned int snd_pcm_rate_mask_intersect (unsigned int rates_a, +unsigned int rates_b) +{ + rates_a =snd_pcm_rate_mask_sanitize (rates_a); + rates_b =snd_pcm_rate_mask_sanitize (rates_b); + +if (rates_a &SNDRV_PCM_RATE_CONTINUOUS )
sound/core/pcm_misc.c unsigned int snd_pcm_rate_bit_to_rate(unsigned int rate_bit) · line 555
Quoted 10 lines
sound/core/pcm_misc.c +10
-0+return rates_b; + else if (rates_b & SNDRV_PCM_RATE_CONTINUOUS) + return rates_a; + else if (rates_a & SNDRV_PCM_RATE_KNOT) + return rates_b; + else if (rates_b & SNDRV_PCM_RATE_KNOT) + return rates_a; +return rates_a & rates_b; +} +EXPORT_SYMBOL (snd_pcm_rate_mask_intersect);
We can use EXPORT_SYMBOL_GPL() for new functions safely.
I suppose this patchset will go through ASoC tree? Then take my ack:
thanks,
Takashi
Re: [PATCH 4/5] ALSA: Add helper function for intersecting two rate masks
Quoted 71 lines · Takashi Iwai
At Fri, 10 Jan 2014 16:06:35 +0100,
Quoted 69 lines · Lars-Peter Clausen
A bit of special care is necessary when creating the intersection of two rate masks. This comes from the special meaning of the
SNDRV_PCM_RATE_CONTINUOUSandSNDRV_PCM_RATE_KNOTbits, which needs special handling when intersecting two rate masks.SNDRV_PCM_RATE_CONTINUOUSmeans the hardware supports all rates in a specific interval.SNDRV_PCM_RATE_KNOTmeans the hardware supports a set of discrete rates specified by a list constraint. For all other cases the supported rates are specified directly in the rate mask.Signed-off-by Lars-Peter Clausen <[email protected]>--- include/sound/pcm.h | 2 ++ sound/core/pcm_misc.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+)include/sound/pcm.h +2
-0@@ -901,6 +901,8 @@ extern const struct snd_pcm_hw_constraint_list snd_pcm_known_rates;int snd_pcm_limit_hw_rates (struct snd_pcm_runtime *runtime);unsigned int snd_pcm_rate_to_rate_bit (unsigned int rate);unsigned int snd_pcm_rate_bit_to_rate (unsigned int rate_bit); +unsigned int snd_pcm_rate_mask_intersect (unsigned int rates_a, +unsigned int rates_b);static inline void snd_pcm_set_runtime_buffer (struct snd_pcm_substream *substream,struct snd_dma_buffer *bufp)sound/core/pcm_misc.c +33
-0@@ -514,3 +514,42 @@ unsigned int snd_pcm_rate_bit_to_rate(unsigned int rate_bit)return 0 ; }EXPORT_SYMBOL (snd_pcm_rate_bit_to_rate); + +static unsigned int snd_pcm_rate_mask_sanitize (unsigned int rates) +{ +if (rates &SNDRV_PCM_RATE_CONTINUOUS ) +return SNDRV_PCM_RATE_CONTINUOUS ; +else if (rates &SNDRV_PCM_RATE_KNOT ) +return SNDRV_PCM_RATE_KNOT ; +return rates; +} + +/** +* snd_pcm_rate_mask_intersect - computes the intersection between two rate masks +* @rates_a: The first rate mask +* @rates_b: The second rate mask +* +* This function computes the rates that are supported by both rate masks passed +* to the function. It will take care of the special handling of +* SNDRV_PCM_RATE_CONTINUOUS and SNDRV_PCM_RATE_KNOT. +* +* Return: A rate mask containing the rates that are supported by both rates_a +* and rates_b. +*/ +unsigned int snd_pcm_rate_mask_intersect (unsigned int rates_a, +unsigned int rates_b) +{ + rates_a =snd_pcm_rate_mask_sanitize (rates_a); + rates_b =snd_pcm_rate_mask_sanitize (rates_b); + +if (rates_a &SNDRV_PCM_RATE_CONTINUOUS ) +return rates_b; +else if (rates_b &SNDRV_PCM_RATE_CONTINUOUS ) +return rates_a; +else if (rates_a &SNDRV_PCM_RATE_KNOT )
Quoted 8 lines
sound/core/pcm_misc.c unsigned int snd_pcm_rate_bit_to_rate(unsigned int rate_bit) · line 555
Quoted 6 lines
sound/core/pcm_misc.c +6
-0+return rates_b; + else if (rates_b & SNDRV_PCM_RATE_KNOT) + return rates_a; +return rates_a & rates_b; +} +EXPORT_SYMBOL (snd_pcm_rate_mask_intersect);We can use
EXPORT_SYMBOL_GPL()for new functions safely.
Ok, I'll change that.
Quoted 4 lines
I suppose this patchset will go through ASoC tree? Then take my ack:
Reviewed-by Takashi Iwai <[email protected]>
Thanks.
PATCH 5/5 ASoC: pcm: Use snd_pcm_rate_mask_intersect() helper
In reply to Lars-Peter ClausenInstead of open-coding the intersecting of two rate masks (and getting slightly wrong for some of the corner cases) use the new snd_pcm_rate_mask_intersect() helper function.
--- sound/soc/soc-pcm.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
sound/soc/soc-pcm.c +2 -7
@@ -244,13 +244,8 @@ static void soc_pcm_init_runtime_hw(struct snd_pcm_runtime *runtime, hw->formats &= codec_stream->formats & cpu_stream->formats; else hw->formats = codec_stream->formats & cpu_stream->formats; - hw->rates = codec_stream->rates & cpu_stream->rates; -if (codec_stream->rates - & (SNDRV_PCM_RATE_KNOT |SNDRV_PCM_RATE_CONTINUOUS )) - hw->rates |= cpu_stream->rates; -if (cpu_stream->rates - & (SNDRV_PCM_RATE_KNOT |SNDRV_PCM_RATE_CONTINUOUS )) - hw->rates |= codec_stream->rates; + hw->rates =snd_pcm_rate_mask_intersect (codec_stream->rates, + cpu_stream->rates); hw->rate_min =0 ; hw->rate_max =UINT_MAX ;
Signature · 1 line
1.8.0