Skip to contentSkip to conversation

ASoC: sgtl5000: Allow the codec to work in slave mode

PATCH In review Fabio Estevam 3 participants 9 messages Sep 18, 2014 – Oct 2, 2014

Subsystems (3)
lore
Share & tools
lore

Fabio Estevam

author maintainer
#0 lore raw

PATCH 1/1 ASoC: sgtl5000: Allow the codec to work in slave mode

From: Fabio Estevam <[email protected]>

When configuring sgtl5000 to work in slave mode the following error is seen:

root@freescale /$ aplay dtmf_mono_16b_48000.wav

[   11.406460] random: nonblocking pool is initialized
[   11.600461] sgtl5000 1-000a: PLL not supported in slave mode
[   11.609052] sgtl5000 1-000a: ASoC: can't set sgtl5000 hw params: -22

ALSA lib pcm_direct.c:980:(snd1_pcm_direct_initialize_slave) unable to install hw params ALSA lib pcm_dmix.c:1030:(snd_pcm_dmix_open) unable to initialize slave
aplay: main:660: audio open error: Invalid argument

Do not error out when sgtl5000_set_clock() reaches the default path for slave mode.

While at it, fix a typo in the comment.

Tested on a imx53-qsb configured as ssi in master and sgtl5000 as slave.

---
 sound/soc/codecs/sgtl5000.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
sound/soc/codecs/sgtl5000.c +1 -5
index a604a22..b641ed1 100644
@@ -619,14 +619,10 @@ static int sgtl5000_set_clock(struct snd_soc_codec *codec, int frame_rate)
 			SGTL5000_MCLK_FREQ_SHIFT;
 		break;
 	default:
-		/* if mclk not satisify the divider, use pll */
+		/* if mclk not satisfy the divider, use pll */
 		if (sgtl5000->master) {
 			clk_ctl |= SGTL5000_MCLK_FREQ_PLL <<
 				SGTL5000_MCLK_FREQ_SHIFT;
-		} else {
-			dev_err(codec->dev,
-				"PLL not supported in slave mode\n");
-			return -EINVAL;
 		}
 	}
 
Signature · 1 line
1.9.1
maintainer
#1 lore raw

sound/soc/codecs/sgtl5000.c static int sgtl5000_set_clock(struct snd_soc_codec *codec, int frame_rate) · line 627

Quoted 12 lines · Fabio Estevam
sound/soc/codecs/sgtl5000.c +1 -5
 	default:
-		/* if mclk not satisify the divider, use pll */
+		/* if mclk not satisfy the divider, use pll */
 		if (sgtl5000->master) {
 			clk_ctl |= SGTL5000_MCLK_FREQ_PLL <<
 				SGTL5000_MCLK_FREQ_SHIFT;
-		} else {
-			dev_err(codec->dev,
-				"PLL not supported in slave mode\n");
-			return -EINVAL;
 		}
 	}

Are you sure that the configuration that results is valid? Typically the requirements for MCLK to other clock ratios are very similar for master and slave modes, it's just that it tends to be a lot more obvious when things go wrong in master mode since directly visible clocks tend to go wrong as opposed to performance problems. Are the dividers that we can't get configuration for purely for generating BCLK/LRCLK in master mode or are they for other things?

author maintainer
#2 lore raw

Hi Mark,

Quoted 15 lines · Mark Brown

sound/soc/codecs/sgtl5000.c static int sgtl5000_set_clock(struct snd_soc_codec *codec, int frame_rate) · line 627

Quoted 12 lines · Fabio Estevam

default:

sound/soc/codecs/sgtl5000.c +1 -5
-             /* if mclk not satisify the divider, use pll */
+             /* if mclk not satisfy the divider, use pll */
              if (sgtl5000->master) {
                      clk_ctl |= SGTL5000_MCLK_FREQ_PLL <<
                              SGTL5000_MCLK_FREQ_SHIFT;
-             } else {
-                     dev_err(codec->dev,
-                             "PLL not supported in slave mode\n");
-                     return -EINVAL;
              }
      }
Quoted 7 lines

Are you sure that the configuration that results is valid? Typically the requirements for MCLK to other clock ratios are very similar for master and slave modes, it's just that it tends to be a lot more obvious when things go wrong in master mode since directly visible clocks tend to go wrong as opposed to performance problems. Are the dividers that we can't get configuration for purely for generating BCLK/LRCLK in master mode or are they for other things?

Tested sgtl5000 slave mode with different sampling rates and it plays well.

Any particular register I should monitor?

Sorry, but I guess I did not understand your last question.

maintainer
#3 lore raw
Quoted 10 lines · Fabio Estevam
Quoted 7 lines · Mark Brown

Are you sure that the configuration that results is valid? Typically the requirements for MCLK to other clock ratios are very similar for master and slave modes, it's just that it tends to be a lot more obvious when things go wrong in master mode since directly visible clocks tend to go wrong as opposed to performance problems. Are the dividers that we can't get configuration for purely for generating BCLK/LRCLK in master mode or are they for other things?

Quoted 3 lines

Tested sgtl5000 slave mode with different sampling rates and it plays well.

Any particular register I should monitor?

Did you just listen or did you measure the performance?

Quoted 1 line

Sorry, but I guess I did not understand your last question.

I'm really not sure how to simplify it... clearly we're skipping some configuration here, what does it do - is it purely for generating BCLK and LRCLK?

#4 lore raw

Hi Mark

Quoted 15 lines · Mark Brown
Quoted 10 lines · Fabio Estevam
Quoted 7 lines · Mark Brown

Are you sure that the configuration that results is valid? Typically the requirements for MCLK to other clock ratios are very similar for master and slave modes, it's just that it tends to be a lot more obvious when things go wrong in master mode since directly visible clocks tend to go wrong as opposed to performance problems. Are the dividers that we can't get configuration for purely for generating BCLK/LRCLK in master mode or are they for other things?

Quoted 3 lines

Tested sgtl5000 slave mode with different sampling rates and it plays well.

Any particular register I should monitor?

Quoted 7 lines

Did you just listen or did you measure the performance?

Quoted 1 line

Sorry, but I guess I did not understand your last question.

I'm really not sure how to simplify it... clearly we're skipping some configuration here, what does it do - is it purely for generating BCLK and LRCLK?

Are you talking about clock_in and sigma-delta? So no the bclk and lrclk but the clkin of the codec.

Michael

Quoted 6 lines

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

Signature · 4 lines
| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |
maintainer
#5 lore raw
Quoted 6 lines · Michael Trimarchi
Quoted 3 lines · Mark Brown
Quoted 1 line

Any particular register I should monitor?

Did you just listen or did you measure the performance?

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Sorry, but I guess I did not understand your last question.

I'm really not sure how to simplify it... clearly we're skipping some configuration here, what does it do - is it purely for generating BCLK and LRCLK?

Are you talking about clock_in and sigma-delta? So no the bclk and lrclk but the clkin of the codec.

I'm sorry but I can't parse what you're saying terribly clearly - please bear in mind that I don't know anything about this device, that's one of the reasons I'm having to ask questions here. If the configuration that is being skipped is not about generating BCLK and LRCLK then it seems like it's going to be wanted in slave mode as well as master.

author maintainer
#6 lore raw

Hi Mark,

Quoted 13 lines · Mark Brown
Quoted 11 lines · Michael Trimarchi
Quoted 9 lines · Mark Brown
Quoted 1 line

Any particular register I should monitor?

Did you just listen or did you measure the performance?

Quoted 1 line

Sorry, but I guess I did not understand your last question.

I'm really not sure how to simplify it... clearly we're skipping some configuration here, what does it do - is it purely for generating BCLK and LRCLK?

Quoted 8 lines
Quoted 2 lines

Are you talking about clock_in and sigma-delta? So no the bclk and lrclk but the clkin of the codec.

I'm sorry but I can't parse what you're saying terribly clearly - please bear in mind that I don't know anything about this device, that's one of the reasons I'm having to ask questions here. If the configuration that is being skipped is not about generating BCLK and LRCLK then it seems like it's going to be wanted in slave mode as well as master.

This patch does not skip any configuration. It just remove the error case for sgtl5000 in slave mode.

Not sure why the error case was there in the first place, as I think sgtl5000 slave mode has never been tested before.

maintainer
#7 lore raw
Quoted 8 lines · Fabio Estevam
Quoted 5 lines · Mark Brown

I'm sorry but I can't parse what you're saying terribly clearly - please bear in mind that I don't know anything about this device, that's one of the reasons I'm having to ask questions here. If the configuration that is being skipped is not about generating BCLK and LRCLK then it seems like it's going to be wanted in slave mode as well as master.

Quoted 5 lines

This patch does not skip any configuration. It just remove the error case for sgtl5000 in slave mode.

Not sure why the error case was there in the first place, as I think sgtl5000 slave mode has never been tested before.

The comment says "if mclk not satisfy the divider, use pll" and then does in fact skip configuring the PLL (or at least a register change which looks like it does that). Looking at the code it seems like there's a requirement for MCLK to be one of the standard multiples of the sample rate.

author maintainer
#8 lore raw
Quoted 5 lines · Mark Brown

The comment says "if mclk not satisfy the divider, use pll" and then does in fact skip configuring the PLL (or at least a register change which looks like it does that). Looking at the code it seems like there's a requirement for MCLK to be one of the standard multiples of the sample rate.

Ok, got it now.

For sgtl5000 to operate in slave mode it can only work in "Synchronous SYS_MCLK input" mode.

In this mode only the following rates can be supported: 256*Fs, 384*Fs, 512*Fs.

On the board I was testing this I was getting a ratio of 233, so the original code returned -EINVAL.

So the current behaviour looks correct.

We could improve the 'PLL not supported in slave mode' error message though putting the actual ratio we got.

Will send a patch for this shortly.