ASoC: bcm_2835: Simplify mono guard by returning error on mono
Subsystems (4)
PATCH 1/1 ASoC: bcm_2835: Simplify mono guard by returning error on mono
This patch simplifies the bcm2835_i2s.c code when the driver returns error on mono channel requests. It does this by testing for mono instead of using a switch statement to test for stereo.
The bcm2835_i2s driver can only work in stereo mode. Whilst leaving the driver entirel compliant with the I2S protocol, it simplifies the code by removing a few redundant lines of code.
--- sound/soc/bcm/bcm2835-i2s.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
sound/soc/bcm/bcm2835-i2s.c +9 -8
@@ -310,15 +310,16 @@ static int bcm2835_i2s_hw_params(struct snd_pcm_substream *substream, ch1pos = data_delay; ch2pos = bclk_ratio /2 + data_delay; -switch (params_channels (params)) { -case 2 : - format =BCM2835_I2S_CH1 (format) |BCM2835_I2S_CH2 (format); - format |=BCM2835_I2S_CH1 (BCM2835_I2S_CHPOS (ch1pos)); - format |=BCM2835_I2S_CH2 (BCM2835_I2S_CHPOS (ch2pos)); -break ; -default : +/* C +* Check we aren't setting channel 2 on a mono stream. +* We currently only support stereo +*/ +if (params_channels (params) ==1 )return -EINVAL ; - } + + format =BCM2835_I2S_CH1 (format) |BCM2835_I2S_CH2 (format); + format |=BCM2835_I2S_CH1 (BCM2835_I2S_CHPOS (ch1pos)); + format |=BCM2835_I2S_CH2 (BCM2835_I2S_CHPOS (ch2pos));/* * Set format for both streams.
Signature · 1 line
2.7.4
I don't really see why it simplifies the code.
Actually, the number of lines is even increased by this patch. And the logic will fail if ever params_channels would return something larger than 2.
Greetings,
Florian
Quoted 43 lines · Matt Flax
This patch simplifies the
bcm2835_i2s.ccode when the driver returns error on mono channel requests. It does this by testing for mono instead of using a switch statement to test for stereo.The
bcm2835_i2sdriver can only work in stereo mode. Whilst leaving the driver entirel compliant with the I2S protocol, it simplifies the code by removing a few redundant lines of code.Signed-off-by Matt Flax <[email protected]>--- sound/soc/bcm/bcm2835-i2s.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)sound/soc/bcm/bcm2835-i2s.c +9
-8@@ -310,15 +310,16 @@ static int bcm2835_i2s_hw_params(struct snd_pcm_substream *substream, ch1pos = data_delay; ch2pos = bclk_ratio /2 + data_delay; -switch (params_channels (params)) { -case 2 : - format =BCM2835_I2S_CH1 (format) |BCM2835_I2S_CH2 (format); - format |=BCM2835_I2S_CH1 (BCM2835_I2S_CHPOS (ch1pos)); - format |=BCM2835_I2S_CH2 (BCM2835_I2S_CHPOS (ch2pos)); -break ; -default : +/* C +* Check we aren't setting channel 2 on a mono stream. +* We currently only support stereo +*/ +if (params_channels (params) ==1 )return -EINVAL ; - } + + format =BCM2835_I2S_CH1 (format) |BCM2835_I2S_CH2 (format); + format |=BCM2835_I2S_CH1 (BCM2835_I2S_CHPOS (ch1pos)); + format |=BCM2835_I2S_CH2 (BCM2835_I2S_CHPOS (ch2pos));/* * Set format for both streams.
Quoted 6 lines · Florian Kauer
I don't really see why it simplifies the code.
Actually, the number of lines is even increased by this patch. And the logic will fail if everparams_channelswould return something larger than 2.
The actual lines of code (excluding comments has shrunk from 9 to 5) - there is no point arguing that. The clock cycle count to execute the same logic has been reduced.
The channel count can't be larger then 2 because channels_min = channels_max = 2, check the bcm2835_i2s.c file.
If channel count is ever != 2 then someone is intentionally hacking - that is beyond our control and in the interests of the hackers - good luck to them.
This patch simplifies the code base and is entirely equivalent to the code it is replacing.
This patch is still entirely I2S compliant.
Is anyone interested in reducing code complexity ?
Matt
Quoted 50 lines · Matt Flax
Quoted 42 lines
This patch simplifies the
bcm2835_i2s.ccode when the driver returns error on mono channel requests. It does this by testing for mono instead of using a switch statement to test for stereo.The
bcm2835_i2sdriver can only work in stereo mode. Whilst leaving the driver entirel compliant with the I2S protocol, it simplifies the code by removing a few redundant lines of code.Signed-off-by Matt Flax <[email protected]>--- sound/soc/bcm/bcm2835-i2s.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)sound/soc/bcm/bcm2835-i2s.c +9
-8@@ -310,15 +310,16 @@ static int bcm2835_i2s_hw_params(structsnd_pcm_substream *substream, ch1pos = data_delay; ch2pos = bclk_ratio /2 + data_delay; -switch (params_channels (params)) { -case 2 : - format =BCM2835_I2S_CH1 (format) |BCM2835_I2S_CH2 (format); - format |=BCM2835_I2S_CH1 (BCM2835_I2S_CHPOS (ch1pos)); - format |=BCM2835_I2S_CH2 (BCM2835_I2S_CHPOS (ch2pos)); -break ; -default : +/* C +* Check we aren't setting channel 2 on a mono stream. +* We currently only support stereo +*/ +if (params_channels (params) ==1 )return -EINVAL ; - } + + format =BCM2835_I2S_CH1 (format) |BCM2835_I2S_CH2 (format); + format |=BCM2835_I2S_CH1 (BCM2835_I2S_CHPOS (ch1pos)); + format |=BCM2835_I2S_CH2 (BCM2835_I2S_CHPOS (ch2pos));/* Quoted 2 lines
* Set format for both streams.
_______________________________________________
Alsa-devel mailing list
Alsa-devel at alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Quoted 9 lines · Matt Flax
This patch simplifies the
bcm2835_i2s.ccode when the driver returns error on mono channel requests. It does this by testing for mono instead of using a switch statement to test for stereo.The
bcm2835_i2sdriver can only work in stereo mode. Whilst leaving the driver entirel compliant with the I2S protocol, it simplifies the code by removing a few redundant lines of code.Signed-off-by Matt Flax <[email protected]>
I'm against this, it removes the semantics that I2S can only do 2 channels from the code part. Without looking at the rest of the code one could get the impression that bcm2835-i2s could support all layouts except 1 channel.
so long,
Hias
Quoted 36 lines
--- sound/soc/bcm/bcm2835-i2s.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)sound/soc/bcm/bcm2835-i2s.c +9
-8@@ -310,15 +310,16 @@ static int bcm2835_i2s_hw_params(struct snd_pcm_substream *substream, ch1pos = data_delay; ch2pos = bclk_ratio /2 + data_delay; -switch (params_channels (params)) { -case 2 : - format =BCM2835_I2S_CH1 (format) |BCM2835_I2S_CH2 (format); - format |=BCM2835_I2S_CH1 (BCM2835_I2S_CHPOS (ch1pos)); - format |=BCM2835_I2S_CH2 (BCM2835_I2S_CHPOS (ch2pos)); -break ; -default : +/* C +* Check we aren't setting channel 2 on a mono stream. +* We currently only support stereo +*/ +if (params_channels (params) ==1 )return -EINVAL ; - } + + format =BCM2835_I2S_CH1 (format) |BCM2835_I2S_CH2 (format); + format |=BCM2835_I2S_CH1 (BCM2835_I2S_CHPOS (ch1pos)); + format |=BCM2835_I2S_CH2 (BCM2835_I2S_CHPOS (ch2pos));/* * Set format for both streams. Signature · 1 line
2.7.4
Quoted 9 lines · Matthias Reichl
Quoted 8 lines · Matt Flax
This patch simplifies the
bcm2835_i2s.ccode when the driver returns error on mono channel requests. It does this by testing for mono instead of using a switch statement to test for stereo.The
bcm2835_i2sdriver can only work in stereo mode. Whilst leaving the driver entirel compliant with the I2S protocol, it simplifies the code by removing a few redundant lines of code.
Quoted 6 lines
Quoted 1 line
Signed-off-by Matt Flax <[email protected]>I'm against this, it removes the semantics that I2S can only do 2 channels from the code part. Without looking at the rest of the code one could get the impression that bcm2835-i2s could support all layouts except 1 channel.
The comment clearly states :
/* * Check we aren't setting channel 2 on a mono stream. * We currently only support stereo */
How could anyone possibly think that it would support "all layouts except 1 channel" ?
I have reduced the clock cycle count to implement the same logic in code. I have clearly indicated that we ONLY support stereo channel counts.
In my opinion this code is simpler, easier to read and makes more sense.
thanks
Matt
Quoted 40 lines
Quoted 36 lines
--- sound/soc/bcm/bcm2835-i2s.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)sound/soc/bcm/bcm2835-i2s.c +9
-8@@ -310,15 +310,16 @@ static int bcm2835_i2s_hw_params(struct snd_pcm_substream *substream, ch1pos = data_delay; ch2pos = bclk_ratio /2 + data_delay; -switch (params_channels (params)) { -case 2 : - format =BCM2835_I2S_CH1 (format) |BCM2835_I2S_CH2 (format); - format |=BCM2835_I2S_CH1 (BCM2835_I2S_CHPOS (ch1pos)); - format |=BCM2835_I2S_CH2 (BCM2835_I2S_CHPOS (ch2pos)); -break ; -default : +/* C +* Check we aren't setting channel 2 on a mono stream. +* We currently only support stereo +*/ +if (params_channels (params) ==1 )return -EINVAL ; - } + + format =BCM2835_I2S_CH1 (format) |BCM2835_I2S_CH2 (format); + format |=BCM2835_I2S_CH1 (BCM2835_I2S_CHPOS (ch1pos)); + format |=BCM2835_I2S_CH2 (BCM2835_I2S_CHPOS (ch2pos));/* * Set format for both streams. Signature · 1 line
2.7.4_______________________________________________
Alsa-devel mailing list
Alsa-devel at alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Quoted 26 lines · Matt Flax
Quoted 9 lines · Matthias Reichl
Quoted 8 lines · Matt Flax
This patch simplifies the
bcm2835_i2s.ccode when the driver returns error on mono channel requests. It does this by testing for mono instead of using a switch statement to test for stereo.The
bcm2835_i2sdriver can only work in stereo mode. Whilst leaving the driver entirel compliant with the I2S protocol, it simplifies the code by removing a few redundant lines of code.Quoted 6 lines
Quoted 1 line
Signed-off-by Matt Flax <[email protected]>I'm against this, it removes the semantics that I2S can only do 2 channels from the code part. Without looking at the rest of the code one could get the impression that bcm2835-i2s could support all layouts except 1 channel.
The comment clearly states :
/* * Check we aren't setting channel 2 on a mono stream. * We currently only support stereo */
Quoted 7 lines
How could anyone possibly think that it would support "all layouts except 1 channel" ?
I have reduced the clock cycle count to implement the same logic in code. I have clearly indicated that we ONLY support stereo channel counts.
In my opinion this code is simpler, easier to read and makes more sense.
In the current implementation this is obvious without looking into comments.
It's also odd that you write "We currently only support stereo" in the comments but then implement a "fail on channels == 1".
If you want to simplify the code and keep it readable you could do it this way - this also preserves semantics of the code:
/* Only stereo is supported - but this is obvious and the comment can be removed */ if (params_channels(params) != 2)
return -EINVAL;
I don't see a pressing need to change to the current upstream driver, the code is fine and readable as well.
so long,
Hias
Quoted 44 lines
thanks
MattQuoted 38 lines
Quoted 34 lines
--- sound/soc/bcm/bcm2835-i2s.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)sound/soc/bcm/bcm2835-i2s.c +9
-8@@ -310,15 +310,16 @@ static int bcm2835_i2s_hw_params(struct snd_pcm_substream *substream, ch1pos = data_delay; ch2pos = bclk_ratio /2 + data_delay; -switch (params_channels (params)) { -case 2 : - format =BCM2835_I2S_CH1 (format) |BCM2835_I2S_CH2 (format); - format |=BCM2835_I2S_CH1 (BCM2835_I2S_CHPOS (ch1pos)); - format |=BCM2835_I2S_CH2 (BCM2835_I2S_CHPOS (ch2pos)); -break ; -default : +/* C +* Check we aren't setting channel 2 on a mono stream. +* We currently only support stereo +*/ +if (params_channels (params) ==1 )return -EINVAL ; - } + + format =BCM2835_I2S_CH1 (format) |BCM2835_I2S_CH2 (format); + format |=BCM2835_I2S_CH1 (BCM2835_I2S_CHPOS (ch1pos)); + format |=BCM2835_I2S_CH2 (BCM2835_I2S_CHPOS (ch2pos));/* * Set format for both streams. Signature · 1 line
2.7.4_______________________________________________
Alsa-devel mailing list
Alsa-devel at alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel