[alsa-devel] [PATCH 00/18] ALSA: Add helper function to add single value constraint
Apologies if you got this series twice, forgot to Cc the mailinglist on the first try.
This series introduces a new helper function which can be used to constrain a configuration parameter to a single. So far the recommended and most efficient way to do this was to set a min-max constraint with the same value for minimum and maximum. It is not necessarily immediately obvious though that this is the right way to do things and some driver have come up with different ways to achieve the same effect, e.g. by installing a list constraint with a single item. This is less efficient since list constraints are dynamic constraints which needed to be re-evaluated multiple times at runtime while a min-max constraint is a static constraint.
The function introduced in this patch series is called snd_pcm_hw_constraint_single() which hopefully is semantically more expressive and makes it clear that this is the function to use when setting a single value constraint.
All existing drivers that want to set a single value constraint are update to use the new helper function.
- Lars
Lars-Peter Clausen (18): ALSA: Add helper function to add single value constraint ALSA: korg1212: Use snd_pcm_hw_constraint_single() ALAA: lx6464es: Use snd_pcm_hw_constraint_single() ALSA: rme32: Use snd_pcm_hw_constraint_single() ALSA: rme96: Use snd_pcm_hw_constraint_single() ALSA: rme9652: Use snd_pcm_hw_constraint_single() ASoC: adav80x: Use snd_pcm_hw_constraint_single() ASoC: twl4030: Use snd_pcm_hw_constraint_single() ASoC: uda134x: Use snd_pcm_hw_constraint_single() ASoC: wl1273: Use snd_pcm_hw_constraint_single() ASoC: n810: Use snd_pcm_hw_constraint_single() ASoC: rx51: Use snd_pcm_hw_constraint_single() ASoC: pcm: Use snd_pcm_hw_constraint_single() ASoC: ux500: Use snd_pcm_hw_constraint_single() ASoC: bytcr_rt5640: Use snd_pcm_hw_constraint_single() ASoC: cht_bsw_max98090: Use snd_pcm_hw_constraint_single() ASoC: cht_bsw_rt5645: Use snd_pcm_hw_constraint_single() ASoC: cht_bsw_rt5672: Use snd_pcm_hw_constraint_single()
include/sound/pcm.h | 16 ++++++++++++++++ sound/pci/korg1212/korg1212.c | 8 +++++--- sound/pci/lx6464es/lx6464es.c | 4 ++-- sound/pci/rme32.c | 4 ++-- sound/pci/rme96.c | 8 ++++---- sound/pci/rme9652/hdspm.c | 9 ++++----- sound/soc/codecs/adav80x.c | 4 ++-- sound/soc/codecs/twl4030.c | 13 +++++-------- sound/soc/codecs/uda134x.c | 6 ++---- sound/soc/codecs/wl1273.c | 9 ++++----- sound/soc/intel/boards/bytcr_rt5640.c | 14 ++------------ sound/soc/intel/boards/cht_bsw_max98090_ti.c | 14 ++------------ sound/soc/intel/boards/cht_bsw_rt5645.c | 14 ++------------ sound/soc/intel/boards/cht_bsw_rt5672.c | 14 ++------------ sound/soc/omap/n810.c | 3 +-- sound/soc/omap/rx51.c | 3 +-- sound/soc/soc-pcm.c | 10 ++++------ sound/soc/ux500/ux500_msp_dai.c | 4 ++-- 18 files changed, 62 insertions(+), 95 deletions(-)
The recommended and most efficient way to constraint a configuration parameter to a single value is to set the minimum and maximum allowed values to the same value, i.e. calling snd_pcm_hw_constraint_minmax() with the same value for min and max.
It is not necessarily obvious though that this is the approach that should be taken and some drivers have come up with other ways of solving this problem, e.g. installing a list constraint with a single item. List constraints are dynamic constraints though and hence less efficient than the static min-max constraint.
This patch introduces a new helper function called snd_pcm_hw_constraint_single() which only takes a single value has the same effect as calling snd_pcm_hw_constraint_minmax() with the same values for min and max. But it is hopefully semantically more expressive, making it clear that this is the preferred way of setting a single value constraint.
Signed-off-by: Lars-Peter Clausen lars@metafoo.de --- include/sound/pcm.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
diff --git a/include/sound/pcm.h b/include/sound/pcm.h index 2882ddd..b767666 100644 --- a/include/sound/pcm.h +++ b/include/sound/pcm.h @@ -1028,6 +1028,22 @@ int snd_pcm_hw_rule_add(struct snd_pcm_runtime *runtime, snd_pcm_hw_rule_func_t func, void *private, int dep, ...);
+/** + * snd_pcm_hw_constraint_single() - Constrain parameter to a single value + * @runtime: PCM runtime instance + * @var: The hw_params variable to constrain + * @val: The value to constrain to + * + * Return: Positive if the value is changed, zero if it's not changed, or a + * negative error code. + */ +static inline int snd_pcm_hw_constraint_single( + struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var, + unsigned int val) +{ + return snd_pcm_hw_constraint_minmax(runtime, var, val, val); +} + int snd_pcm_format_signed(snd_pcm_format_t format); int snd_pcm_format_unsigned(snd_pcm_format_t format); int snd_pcm_format_linear(snd_pcm_format_t format);
Use the new snd_pcm_hw_constraint_single() helper function instead of calling snd_pcm_hw_constraint_minmax() with the same value for min and max to install a constraint that limits the possible configuration values to a single value. Using snd_pcm_hw_constraint_single() makes the indented result clearer.
While we are at it also fix some code style issues in the affected lines.
Signed-off-by: Lars-Peter Clausen lars@metafoo.de --- sound/pci/korg1212/korg1212.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/sound/pci/korg1212/korg1212.c b/sound/pci/korg1212/korg1212.c index 7acbc21..9e1ad11 100644 --- a/sound/pci/korg1212/korg1212.c +++ b/sound/pci/korg1212/korg1212.c @@ -1394,7 +1394,9 @@ static int snd_korg1212_playback_open(struct snd_pcm_substream *substream)
spin_unlock_irqrestore(&korg1212->lock, flags);
- snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, kPlayBufferFrames, kPlayBufferFrames); + snd_pcm_hw_constraint_single(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, + kPlayBufferFrames); + return 0; }
@@ -1422,8 +1424,8 @@ static int snd_korg1212_capture_open(struct snd_pcm_substream *substream)
spin_unlock_irqrestore(&korg1212->lock, flags);
- snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, - kPlayBufferFrames, kPlayBufferFrames); + snd_pcm_hw_constraint_single(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, + kPlayBufferFrames); return 0; }
Use the new snd_pcm_hw_constraint_single() helper function instead of calling snd_pcm_hw_constraint_minmax() with the same value for min and max to install a constraint that limits the possible configuration values to a single value. Using snd_pcm_hw_constraint_single() makes the indented result clearer.
Signed-off-by: Lars-Peter Clausen lars@metafoo.de --- sound/pci/lx6464es/lx6464es.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sound/pci/lx6464es/lx6464es.c b/sound/pci/lx6464es/lx6464es.c index cba89be..8b8e2e5 100644 --- a/sound/pci/lx6464es/lx6464es.c +++ b/sound/pci/lx6464es/lx6464es.c @@ -234,8 +234,8 @@ static int lx_pcm_open(struct snd_pcm_substream *substream)
/* the clock rate cannot be changed */ board_rate = chip->board_sample_rate; - err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_RATE, - board_rate, board_rate); + err = snd_pcm_hw_constraint_single(runtime, SNDRV_PCM_HW_PARAM_RATE, + board_rate);
if (err < 0) { dev_warn(chip->card->dev, "could not constrain periods\n");
Use the new snd_pcm_hw_constraint_single() helper function instead of calling snd_pcm_hw_constraint_minmax() with the same value for min and max to install a constraint that limits the possible configuration values to a single value. Using snd_pcm_hw_constraint_single() makes the indented result clearer.
Signed-off-by: Lars-Peter Clausen lars@metafoo.de --- sound/pci/rme32.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sound/pci/rme32.c b/sound/pci/rme32.c index 23d7f5d..cd94ac5 100644 --- a/sound/pci/rme32.c +++ b/sound/pci/rme32.c @@ -831,9 +831,9 @@ static struct snd_pcm_hw_constraint_list hw_constraints_period_bytes = { static void snd_rme32_set_buffer_constraint(struct rme32 *rme32, struct snd_pcm_runtime *runtime) { if (! rme32->fullduplex_mode) { - snd_pcm_hw_constraint_minmax(runtime, + snd_pcm_hw_constraint_single(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, - RME32_BUFFER_SIZE, RME32_BUFFER_SIZE); + RME32_BUFFER_SIZE); snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, &hw_constraints_period_bytes);
Use the new snd_pcm_hw_constraint_single() helper function instead of calling snd_pcm_hw_constraint_minmax() with the same value for min and max to install a constraint that limits the possible configuration values to a single value. Using snd_pcm_hw_constraint_single() makes the indented result clearer.
Signed-off-by: Lars-Peter Clausen lars@metafoo.de --- sound/pci/rme96.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/sound/pci/rme96.c b/sound/pci/rme96.c index 2306ccf..714df90 100644 --- a/sound/pci/rme96.c +++ b/sound/pci/rme96.c @@ -1152,13 +1152,13 @@ rme96_set_buffer_size_constraint(struct rme96 *rme96, { unsigned int size;
- snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, - RME96_BUFFER_SIZE, RME96_BUFFER_SIZE); + snd_pcm_hw_constraint_single(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, + RME96_BUFFER_SIZE); if ((size = rme96->playback_periodsize) != 0 || (size = rme96->capture_periodsize) != 0) - snd_pcm_hw_constraint_minmax(runtime, + snd_pcm_hw_constraint_single(runtime, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, - size, size); + size); else snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
Use the new snd_pcm_hw_constraint_single() helper function instead of calling snd_pcm_hw_constraint_minmax() with the same value for min and max to install a constraint that limits the possible configuration values to a single value. Using snd_pcm_hw_constraint_single() makes the indented result clearer.
Signed-off-by: Lars-Peter Clausen lars@metafoo.de --- sound/pci/rme9652/hdspm.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c index cb666c7..8bc8016 100644 --- a/sound/pci/rme9652/hdspm.c +++ b/sound/pci/rme9652/hdspm.c @@ -6080,18 +6080,17 @@ static int snd_hdspm_open(struct snd_pcm_substream *substream) SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 32, 4096); /* RayDAT & AIO have a fixed buffer of 16384 samples per channel */ - snd_pcm_hw_constraint_minmax(runtime, + snd_pcm_hw_constraint_single(runtime, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, - 16384, 16384); + 16384); break;
default: snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 64, 8192); - snd_pcm_hw_constraint_minmax(runtime, - SNDRV_PCM_HW_PARAM_PERIODS, - 2, 2); + snd_pcm_hw_constraint_single(runtime, + SNDRV_PCM_HW_PARAM_PERIODS, 2); break; }
Use the new snd_pcm_hw_constraint_single() helper function instead of calling snd_pcm_hw_constraint_minmax() with the same value for min and max to install a constraint that limits the possible configuration values to a single value. Using snd_pcm_hw_constraint_single() makes the indented result clearer.
Signed-off-by: Lars-Peter Clausen lars@metafoo.de --- sound/soc/codecs/adav80x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sound/soc/codecs/adav80x.c b/sound/soc/codecs/adav80x.c index 198c924..acff8d6 100644 --- a/sound/soc/codecs/adav80x.c +++ b/sound/soc/codecs/adav80x.c @@ -728,8 +728,8 @@ static int adav80x_dai_startup(struct snd_pcm_substream *substream, if (!snd_soc_codec_is_active(codec) || !adav80x->rate) return 0;
- return snd_pcm_hw_constraint_minmax(substream->runtime, - SNDRV_PCM_HW_PARAM_RATE, adav80x->rate, adav80x->rate); + return snd_pcm_hw_constraint_single(substream->runtime, + SNDRV_PCM_HW_PARAM_RATE, adav80x->rate); }
static void adav80x_dai_shutdown(struct snd_pcm_substream *substream,
Use the new snd_pcm_hw_constraint_single() helper function instead of calling snd_pcm_hw_constraint_minmax() with the same value for min and max to install a constraint that limits the possible configuration values to a single value. Using snd_pcm_hw_constraint_single() makes the indented result clearer and is slightly shorter.
Signed-off-by: Lars-Peter Clausen lars@metafoo.de --- sound/soc/codecs/twl4030.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c index 2713e18..a5a4e9f 100644 --- a/sound/soc/codecs/twl4030.c +++ b/sound/soc/codecs/twl4030.c @@ -1612,19 +1612,16 @@ static void twl4030_constraints(struct twl4030_priv *twl4030, return;
/* Set the constraints according to the already configured stream */ - snd_pcm_hw_constraint_minmax(slv_substream->runtime, + snd_pcm_hw_constraint_single(slv_substream->runtime, SNDRV_PCM_HW_PARAM_RATE, - twl4030->rate, twl4030->rate);
- snd_pcm_hw_constraint_minmax(slv_substream->runtime, + snd_pcm_hw_constraint_single(slv_substream->runtime, SNDRV_PCM_HW_PARAM_SAMPLE_BITS, - twl4030->sample_bits, twl4030->sample_bits);
- snd_pcm_hw_constraint_minmax(slv_substream->runtime, + snd_pcm_hw_constraint_single(slv_substream->runtime, SNDRV_PCM_HW_PARAM_CHANNELS, - twl4030->channels, twl4030->channels); }
@@ -1669,9 +1666,9 @@ static int twl4030_startup(struct snd_pcm_substream *substream, /* In option2 4 channel is not supported, set the * constraint for the first stream for channels, the * second stream will 'inherit' this cosntraint */ - snd_pcm_hw_constraint_minmax(substream->runtime, + snd_pcm_hw_constraint_single(substream->runtime, SNDRV_PCM_HW_PARAM_CHANNELS, - 2, 2); + 2); } twl4030->master_substream = substream; }
On 10/18/2015 04:39 PM, Lars-Peter Clausen wrote:
Use the new snd_pcm_hw_constraint_single() helper function instead of calling snd_pcm_hw_constraint_minmax() with the same value for min and max to install a constraint that limits the possible configuration values to a single value. Using snd_pcm_hw_constraint_single() makes the indented result clearer and is slightly shorter.
Signed-off-by: Lars-Peter Clausen lars@metafoo.de
Acked-by: Peter Ujfalusi peter.ujfalusi@ti.com
sound/soc/codecs/twl4030.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c index 2713e18..a5a4e9f 100644 --- a/sound/soc/codecs/twl4030.c +++ b/sound/soc/codecs/twl4030.c @@ -1612,19 +1612,16 @@ static void twl4030_constraints(struct twl4030_priv *twl4030, return;
/* Set the constraints according to the already configured stream */
- snd_pcm_hw_constraint_minmax(slv_substream->runtime,
- snd_pcm_hw_constraint_single(slv_substream->runtime, SNDRV_PCM_HW_PARAM_RATE,
twl4030->rate, twl4030->rate);
snd_pcm_hw_constraint_minmax(slv_substream->runtime,
- snd_pcm_hw_constraint_single(slv_substream->runtime, SNDRV_PCM_HW_PARAM_SAMPLE_BITS,
twl4030->sample_bits, twl4030->sample_bits);
snd_pcm_hw_constraint_minmax(slv_substream->runtime,
- snd_pcm_hw_constraint_single(slv_substream->runtime, SNDRV_PCM_HW_PARAM_CHANNELS,
twl4030->channels, twl4030->channels);
}
@@ -1669,9 +1666,9 @@ static int twl4030_startup(struct snd_pcm_substream *substream, /* In option2 4 channel is not supported, set the * constraint for the first stream for channels, the * second stream will 'inherit' this cosntraint */
snd_pcm_hw_constraint_minmax(substream->runtime,
snd_pcm_hw_constraint_single(substream->runtime, SNDRV_PCM_HW_PARAM_CHANNELS,
2, 2);
} twl4030->master_substream = substream; }2);
Use the new snd_pcm_hw_constraint_single() helper function instead of calling snd_pcm_hw_constraint_minmax() with the same value for min and max to install a constraint that limits the possible configuration values to a single value. Using snd_pcm_hw_constraint_single() makes the indented result clearer and is slightly shorter.
Signed-off-by: Lars-Peter Clausen lars@metafoo.de --- sound/soc/codecs/uda134x.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/sound/soc/codecs/uda134x.c b/sound/soc/codecs/uda134x.c index e190263..e4c694c 100644 --- a/sound/soc/codecs/uda134x.c +++ b/sound/soc/codecs/uda134x.c @@ -150,14 +150,12 @@ static int uda134x_startup(struct snd_pcm_substream *substream, master_runtime->sample_bits, master_runtime->rate);
- snd_pcm_hw_constraint_minmax(substream->runtime, + snd_pcm_hw_constraint_single(substream->runtime, SNDRV_PCM_HW_PARAM_RATE, - master_runtime->rate, master_runtime->rate);
- snd_pcm_hw_constraint_minmax(substream->runtime, + snd_pcm_hw_constraint_single(substream->runtime, SNDRV_PCM_HW_PARAM_SAMPLE_BITS, - master_runtime->sample_bits, master_runtime->sample_bits);
uda134x->slave_substream = substream;
Use the new snd_pcm_hw_constraint_single() helper function instead of calling snd_pcm_hw_constraint_minmax() with the same value for min and max to install a constraint that limits the possible configuration values to a single value. Using snd_pcm_hw_constraint_single() makes the indented result clearer.
Signed-off-by: Lars-Peter Clausen lars@metafoo.de --- sound/soc/codecs/wl1273.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/sound/soc/codecs/wl1273.c b/sound/soc/codecs/wl1273.c index 80fb1dc..7693c11 100644 --- a/sound/soc/codecs/wl1273.c +++ b/sound/soc/codecs/wl1273.c @@ -307,11 +307,10 @@ static int wl1273_startup(struct snd_pcm_substream *substream,
switch (wl1273->mode) { case WL1273_MODE_BT: - snd_pcm_hw_constraint_minmax(substream->runtime, - SNDRV_PCM_HW_PARAM_RATE, - 8000, 8000); - snd_pcm_hw_constraint_minmax(substream->runtime, - SNDRV_PCM_HW_PARAM_CHANNELS, 1, 1); + snd_pcm_hw_constraint_single(substream->runtime, + SNDRV_PCM_HW_PARAM_RATE, 8000); + snd_pcm_hw_constraint_single(substream->runtime, + SNDRV_PCM_HW_PARAM_CHANNELS, 1); break; case WL1273_MODE_FM_RX: if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
Use the new snd_pcm_hw_constraint_single() helper function instead of calling snd_pcm_hw_constraint_minmax() with the same value for min and max to install a constraint that limits the possible configuration values to a single value. Using snd_pcm_hw_constraint_single() makes the indented result clearer and is slightly shorter.
Signed-off-by: Lars-Peter Clausen lars@metafoo.de --- sound/soc/omap/n810.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/sound/soc/omap/n810.c b/sound/soc/omap/n810.c index dcb5336..190f868 100644 --- a/sound/soc/omap/n810.c +++ b/sound/soc/omap/n810.c @@ -99,8 +99,7 @@ static int n810_startup(struct snd_pcm_substream *substream) struct snd_pcm_runtime *runtime = substream->runtime; struct snd_soc_pcm_runtime *rtd = substream->private_data;
- snd_pcm_hw_constraint_minmax(runtime, - SNDRV_PCM_HW_PARAM_CHANNELS, 2, 2); + snd_pcm_hw_constraint_single(runtime, SNDRV_PCM_HW_PARAM_CHANNELS, 2);
n810_ext_control(&rtd->card->dapm); return clk_prepare_enable(sys_clkout2);
On 10/18/2015 04:39 PM, Lars-Peter Clausen wrote:
Use the new snd_pcm_hw_constraint_single() helper function instead of calling snd_pcm_hw_constraint_minmax() with the same value for min and max to install a constraint that limits the possible configuration values to a single value. Using snd_pcm_hw_constraint_single() makes the indented result clearer and is slightly shorter.
Signed-off-by: Lars-Peter Clausen lars@metafoo.de
sound/soc/omap/n810.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/sound/soc/omap/n810.c b/sound/soc/omap/n810.c index dcb5336..190f868 100644 --- a/sound/soc/omap/n810.c +++ b/sound/soc/omap/n810.c @@ -99,8 +99,7 @@ static int n810_startup(struct snd_pcm_substream *substream) struct snd_pcm_runtime *runtime = substream->runtime; struct snd_soc_pcm_runtime *rtd = substream->private_data;
- snd_pcm_hw_constraint_minmax(runtime,
SNDRV_PCM_HW_PARAM_CHANNELS, 2, 2);
snd_pcm_hw_constraint_single(runtime, SNDRV_PCM_HW_PARAM_CHANNELS, 2);
n810_ext_control(&rtd->card->dapm); return clk_prepare_enable(sys_clkout2);
Acked-by: Jarkko Nikula jarkko.nikula@bitmer.com
Use the new snd_pcm_hw_constraint_single() helper function instead of calling snd_pcm_hw_constraint_minmax() with the same value for min and max to install a constraint that limits the possible configuration values to a single value. Using snd_pcm_hw_constraint_single() makes the indented result clearer and is slightly shorter.
Signed-off-by: Lars-Peter Clausen lars@metafoo.de --- sound/soc/omap/rx51.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/sound/soc/omap/rx51.c b/sound/soc/omap/rx51.c index 3bebfb1..20728d0 100644 --- a/sound/soc/omap/rx51.c +++ b/sound/soc/omap/rx51.c @@ -107,8 +107,7 @@ static int rx51_startup(struct snd_pcm_substream *substream) struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_card *card = rtd->card;
- snd_pcm_hw_constraint_minmax(runtime, - SNDRV_PCM_HW_PARAM_CHANNELS, 2, 2); + snd_pcm_hw_constraint_single(runtime, SNDRV_PCM_HW_PARAM_CHANNELS, 2); rx51_ext_control(&card->dapm);
return 0;
On 10/18/2015 04:39 PM, Lars-Peter Clausen wrote:
Use the new snd_pcm_hw_constraint_single() helper function instead of calling snd_pcm_hw_constraint_minmax() with the same value for min and max to install a constraint that limits the possible configuration values to a single value. Using snd_pcm_hw_constraint_single() makes the indented result clearer and is slightly shorter.
Signed-off-by: Lars-Peter Clausen lars@metafoo.de
sound/soc/omap/rx51.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/sound/soc/omap/rx51.c b/sound/soc/omap/rx51.c index 3bebfb1..20728d0 100644 --- a/sound/soc/omap/rx51.c +++ b/sound/soc/omap/rx51.c @@ -107,8 +107,7 @@ static int rx51_startup(struct snd_pcm_substream *substream) struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_card *card = rtd->card;
- snd_pcm_hw_constraint_minmax(runtime,
SNDRV_PCM_HW_PARAM_CHANNELS, 2, 2);
snd_pcm_hw_constraint_single(runtime, SNDRV_PCM_HW_PARAM_CHANNELS, 2); rx51_ext_control(&card->dapm);
return 0;
Acked-by: Jarkko Nikula jarkko.nikula@bitmer.com Tested-by: Jarkko Nikula jarkko.nikula@bitmer.com
Use the new snd_pcm_hw_constraint_single() helper function instead of calling snd_pcm_hw_constraint_minmax() with the same value for min and max to install a constraint that limits the possible configuration values to a single value. Using snd_pcm_hw_constraint_single() makes the indented result clearer and is slightly shorter.
Signed-off-by: Lars-Peter Clausen lars@metafoo.de --- sound/soc/soc-pcm.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index 3173958..c86dc96 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -200,9 +200,9 @@ static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream, dev_dbg(soc_dai->dev, "ASoC: Symmetry forces %dHz rate\n", soc_dai->rate);
- ret = snd_pcm_hw_constraint_minmax(substream->runtime, + ret = snd_pcm_hw_constraint_single(substream->runtime, SNDRV_PCM_HW_PARAM_RATE, - soc_dai->rate, soc_dai->rate); + soc_dai->rate); if (ret < 0) { dev_err(soc_dai->dev, "ASoC: Unable to apply rate constraint: %d\n", @@ -216,9 +216,8 @@ static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream, dev_dbg(soc_dai->dev, "ASoC: Symmetry forces %d channel(s)\n", soc_dai->channels);
- ret = snd_pcm_hw_constraint_minmax(substream->runtime, + ret = snd_pcm_hw_constraint_single(substream->runtime, SNDRV_PCM_HW_PARAM_CHANNELS, - soc_dai->channels, soc_dai->channels); if (ret < 0) { dev_err(soc_dai->dev, @@ -233,9 +232,8 @@ static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream, dev_dbg(soc_dai->dev, "ASoC: Symmetry forces %d sample bits\n", soc_dai->sample_bits);
- ret = snd_pcm_hw_constraint_minmax(substream->runtime, + ret = snd_pcm_hw_constraint_single(substream->runtime, SNDRV_PCM_HW_PARAM_SAMPLE_BITS, - soc_dai->sample_bits, soc_dai->sample_bits); if (ret < 0) { dev_err(soc_dai->dev,
Use the new snd_pcm_hw_constraint_single() helper function instead of calling snd_pcm_hw_constraint_minmax() with the same value for min and max to install a constraint that limits the possible configuration values to a single value. Using snd_pcm_hw_constraint_single() makes the indented result clearer.
Signed-off-by: Lars-Peter Clausen lars@metafoo.de --- sound/soc/ux500/ux500_msp_dai.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sound/soc/ux500/ux500_msp_dai.c b/sound/soc/ux500/ux500_msp_dai.c index 6ba8ae9..6d5698b 100644 --- a/sound/soc/ux500/ux500_msp_dai.c +++ b/sound/soc/ux500/ux500_msp_dai.c @@ -522,9 +522,9 @@ static int ux500_msp_dai_hw_params(struct snd_pcm_substream *substream, slots_active = hweight32(mask); dev_dbg(dai->dev, "TDM-slots active: %d", slots_active);
- snd_pcm_hw_constraint_minmax(runtime, + snd_pcm_hw_constraint_single(runtime, SNDRV_PCM_HW_PARAM_CHANNELS, - slots_active, slots_active); + slots_active); break;
default:
Use the new snd_pcm_hw_constraint_single() helper function rather than installing a list constraint with a single value. Since snd_pcm_hw_constraint_single() sets a static constraint while snd_pcm_hw_constraint_list() sets a dynamic constraint the former is slightly more efficient and it also needs less code.
Signed-off-by: Lars-Peter Clausen lars@metafoo.de --- sound/soc/intel/boards/bytcr_rt5640.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)
diff --git a/sound/soc/intel/boards/bytcr_rt5640.c b/sound/soc/intel/boards/bytcr_rt5640.c index c445312..7a5c9a3 100644 --- a/sound/soc/intel/boards/bytcr_rt5640.c +++ b/sound/soc/intel/boards/bytcr_rt5640.c @@ -117,20 +117,10 @@ static int byt_codec_fixup(struct snd_soc_pcm_runtime *rtd, return 0; }
-static unsigned int rates_48000[] = { - 48000, -}; - -static struct snd_pcm_hw_constraint_list constraints_48000 = { - .count = ARRAY_SIZE(rates_48000), - .list = rates_48000, -}; - static int byt_aif1_startup(struct snd_pcm_substream *substream) { - return snd_pcm_hw_constraint_list(substream->runtime, 0, - SNDRV_PCM_HW_PARAM_RATE, - &constraints_48000); + return snd_pcm_hw_constraint_single(substream->runtime, + SNDRV_PCM_HW_PARAM_RATE, 48000); }
static struct snd_soc_ops byt_aif1_ops = {
Use the new snd_pcm_hw_constraint_single() helper function rather than installing a list constraint with a single value. Since snd_pcm_hw_constraint_single() sets a static constraint while snd_pcm_hw_constraint_list() sets a dynamic constraint the former is slightly more efficient and it also needs less code.
Signed-off-by: Lars-Peter Clausen lars@metafoo.de --- sound/soc/intel/boards/cht_bsw_max98090_ti.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)
diff --git a/sound/soc/intel/boards/cht_bsw_max98090_ti.c b/sound/soc/intel/boards/cht_bsw_max98090_ti.c index 49f4869..4e2fcf1 100644 --- a/sound/soc/intel/boards/cht_bsw_max98090_ti.c +++ b/sound/soc/intel/boards/cht_bsw_max98090_ti.c @@ -193,20 +193,10 @@ static int cht_codec_fixup(struct snd_soc_pcm_runtime *rtd, return 0; }
-static unsigned int rates_48000[] = { - 48000, -}; - -static struct snd_pcm_hw_constraint_list constraints_48000 = { - .count = ARRAY_SIZE(rates_48000), - .list = rates_48000, -}; - static int cht_aif1_startup(struct snd_pcm_substream *substream) { - return snd_pcm_hw_constraint_list(substream->runtime, 0, - SNDRV_PCM_HW_PARAM_RATE, - &constraints_48000); + return snd_pcm_hw_constraint_single(substream->runtime, + SNDRV_PCM_HW_PARAM_RATE, 48000); }
static int cht_max98090_headset_init(struct snd_soc_component *component)
Use the new snd_pcm_hw_constraint_single() helper function rather than installing a list constraint with a single value. Since snd_pcm_hw_constraint_single() sets a static constraint while snd_pcm_hw_constraint_list() sets a dynamic constraint the former is slightly more efficient and it also needs less code.
Signed-off-by: Lars-Peter Clausen lars@metafoo.de --- sound/soc/intel/boards/cht_bsw_rt5645.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)
diff --git a/sound/soc/intel/boards/cht_bsw_rt5645.c b/sound/soc/intel/boards/cht_bsw_rt5645.c index 7be8461..38d65a3 100644 --- a/sound/soc/intel/boards/cht_bsw_rt5645.c +++ b/sound/soc/intel/boards/cht_bsw_rt5645.c @@ -235,20 +235,10 @@ static int cht_codec_fixup(struct snd_soc_pcm_runtime *rtd, return 0; }
-static unsigned int rates_48000[] = { - 48000, -}; - -static struct snd_pcm_hw_constraint_list constraints_48000 = { - .count = ARRAY_SIZE(rates_48000), - .list = rates_48000, -}; - static int cht_aif1_startup(struct snd_pcm_substream *substream) { - return snd_pcm_hw_constraint_list(substream->runtime, 0, - SNDRV_PCM_HW_PARAM_RATE, - &constraints_48000); + return snd_pcm_hw_constraint_single(substream->runtime, + SNDRV_PCM_HW_PARAM_RATE, 48000); }
static struct snd_soc_ops cht_aif1_ops = {
Use the new snd_pcm_hw_constraint_single() helper function rather than installing a list constraint with a single value. Since snd_pcm_hw_constraint_single() sets a static constraint while snd_pcm_hw_constraint_list() sets a dynamic constraint the former is slightly more efficient and it also needs less code.
Signed-off-by: Lars-Peter Clausen lars@metafoo.de --- sound/soc/intel/boards/cht_bsw_rt5672.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)
diff --git a/sound/soc/intel/boards/cht_bsw_rt5672.c b/sound/soc/intel/boards/cht_bsw_rt5672.c index 23fe040..5621ccd 100644 --- a/sound/soc/intel/boards/cht_bsw_rt5672.c +++ b/sound/soc/intel/boards/cht_bsw_rt5672.c @@ -222,20 +222,10 @@ static int cht_codec_fixup(struct snd_soc_pcm_runtime *rtd, return 0; }
-static unsigned int rates_48000[] = { - 48000, -}; - -static struct snd_pcm_hw_constraint_list constraints_48000 = { - .count = ARRAY_SIZE(rates_48000), - .list = rates_48000, -}; - static int cht_aif1_startup(struct snd_pcm_substream *substream) { - return snd_pcm_hw_constraint_list(substream->runtime, 0, - SNDRV_PCM_HW_PARAM_RATE, - &constraints_48000); + return snd_pcm_hw_constraint_single(substream->runtime, + SNDRV_PCM_HW_PARAM_RATE, 48000); }
static struct snd_soc_ops cht_aif1_ops = {
On Sun, 18 Oct 2015 15:39:15 +0200, Lars-Peter Clausen wrote:
Apologies if you got this series twice, forgot to Cc the mailinglist on the first try.
This series introduces a new helper function which can be used to constrain a configuration parameter to a single. So far the recommended and most efficient way to do this was to set a min-max constraint with the same value for minimum and maximum. It is not necessarily immediately obvious though that this is the right way to do things and some driver have come up with different ways to achieve the same effect, e.g. by installing a list constraint with a single item. This is less efficient since list constraints are dynamic constraints which needed to be re-evaluated multiple times at runtime while a min-max constraint is a static constraint.
The function introduced in this patch series is called snd_pcm_hw_constraint_single() which hopefully is semantically more expressive and makes it clear that this is the function to use when setting a single value constraint.
All existing drivers that want to set a single value constraint are update to use the new helper function.
Looks good to me. I suppose I'd take all these (including ASoC ones) through my tree as it adds a new API function. Mark are you OK with it?
thanks,
Takashi
- Lars
Lars-Peter Clausen (18): ALSA: Add helper function to add single value constraint ALSA: korg1212: Use snd_pcm_hw_constraint_single() ALAA: lx6464es: Use snd_pcm_hw_constraint_single() ALSA: rme32: Use snd_pcm_hw_constraint_single() ALSA: rme96: Use snd_pcm_hw_constraint_single() ALSA: rme9652: Use snd_pcm_hw_constraint_single() ASoC: adav80x: Use snd_pcm_hw_constraint_single() ASoC: twl4030: Use snd_pcm_hw_constraint_single() ASoC: uda134x: Use snd_pcm_hw_constraint_single() ASoC: wl1273: Use snd_pcm_hw_constraint_single() ASoC: n810: Use snd_pcm_hw_constraint_single() ASoC: rx51: Use snd_pcm_hw_constraint_single() ASoC: pcm: Use snd_pcm_hw_constraint_single() ASoC: ux500: Use snd_pcm_hw_constraint_single() ASoC: bytcr_rt5640: Use snd_pcm_hw_constraint_single() ASoC: cht_bsw_max98090: Use snd_pcm_hw_constraint_single() ASoC: cht_bsw_rt5645: Use snd_pcm_hw_constraint_single() ASoC: cht_bsw_rt5672: Use snd_pcm_hw_constraint_single()
include/sound/pcm.h | 16 ++++++++++++++++ sound/pci/korg1212/korg1212.c | 8 +++++--- sound/pci/lx6464es/lx6464es.c | 4 ++-- sound/pci/rme32.c | 4 ++-- sound/pci/rme96.c | 8 ++++---- sound/pci/rme9652/hdspm.c | 9 ++++----- sound/soc/codecs/adav80x.c | 4 ++-- sound/soc/codecs/twl4030.c | 13 +++++-------- sound/soc/codecs/uda134x.c | 6 ++---- sound/soc/codecs/wl1273.c | 9 ++++----- sound/soc/intel/boards/bytcr_rt5640.c | 14 ++------------ sound/soc/intel/boards/cht_bsw_max98090_ti.c | 14 ++------------ sound/soc/intel/boards/cht_bsw_rt5645.c | 14 ++------------ sound/soc/intel/boards/cht_bsw_rt5672.c | 14 ++------------ sound/soc/omap/n810.c | 3 +-- sound/soc/omap/rx51.c | 3 +-- sound/soc/soc-pcm.c | 10 ++++------ sound/soc/ux500/ux500_msp_dai.c | 4 ++-- 18 files changed, 62 insertions(+), 95 deletions(-)
-- 2.1.4
On Mon, 19 Oct 2015 07:37:04 +0200, Takashi Iwai wrote:
On Sun, 18 Oct 2015 15:39:15 +0200, Lars-Peter Clausen wrote:
Apologies if you got this series twice, forgot to Cc the mailinglist on the first try.
This series introduces a new helper function which can be used to constrain a configuration parameter to a single. So far the recommended and most efficient way to do this was to set a min-max constraint with the same value for minimum and maximum. It is not necessarily immediately obvious though that this is the right way to do things and some driver have come up with different ways to achieve the same effect, e.g. by installing a list constraint with a single item. This is less efficient since list constraints are dynamic constraints which needed to be re-evaluated multiple times at runtime while a min-max constraint is a static constraint.
The function introduced in this patch series is called snd_pcm_hw_constraint_single() which hopefully is semantically more expressive and makes it clear that this is the function to use when setting a single value constraint.
All existing drivers that want to set a single value constraint are update to use the new helper function.
Looks good to me. I suppose I'd take all these (including ASoC ones) through my tree as it adds a new API function. Mark are you OK with it?
I created topic/hw-constraint-single branch in sound git tree containing all these patches. I'm going to keep it for a while for further acks and merge later.
thanks,
Takashi
On Tue, Oct 20, 2015 at 11:00:15AM +0200, Takashi Iwai wrote:
I created topic/hw-constraint-single branch in sound git tree containing all these patches. I'm going to keep it for a while for further acks and merge later.
Acked-by: Mark Brown broonie@kernel.org
:/
participants (5)
-
Jarkko Nikula
-
Lars-Peter Clausen
-
Mark Brown
-
Peter Ujfalusi
-
Takashi Iwai