Skip to contentSkip to conversation

ASoC: DaVinci: Added support for cpu clocking I2S

PATCH In review Raffaele Recalcati 3 participants 7 messages Jun 28, 2010 – Jun 30, 2010

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ASoC: DaVinci: Added support for cpu clocking I2S

From: Raffaele Recalcati <[email protected]>

Added audio playback support with [frame sync master - clock master] mode and with [frame sync master - clock slave].

1. SND_SOC_DAIFMT_CBS_CFS (the cpu generates clock and frame sync) I need to clarify how the McBSP is clocked internally. Reading sprufi3a-1.pdf (TMS320DM36x DMSoC Multichannel Buffered Serial Port (McBSP) Interface) at "2.5.3 Data Clock Generation" paragraph this info not appears really clear if we are in the case of "McBSP internal input clock".
I hope some Ti developers can help me.
There is a FIXME message in the patch.

i2s_fast_clock switch can be used to have better approximate or symmetric waveforms.
clk_input_pin board info can be used to select it depending on hw connections

2. SND_SOC_DAIFMT_CBS_CFM (the cpu get clock from external pin and generates frame sync)
Clock slave can be important when the external codec need system clock and bit clock synchronized (tested with uda1345).

3. We haven't changed the evmdm365 support (due also to CPLD that doesn't help to understand) We don't know in this mode if audio stereo works on evmdm365. Probably it does.

This patch has been developed against the
http://git.kernel.org/pub/scm/linux/kernel/git/khilman/linux-davinci.git
git tree and has been tested on bmx board (similar to dm365 evm, but using uda1345 as external audio codec).

---
 arch/arm/mach-davinci/include/mach/asp.h |   16 ++++
 sound/soc/davinci/davinci-i2s.c          |  126 ++++++++++++++++++++++++++----
 2 files changed, 128 insertions(+), 14 deletions(-)
arch/arm/mach-davinci/include/mach/asp.h +16 -0
index 834725f..f9b6da2 100644
@@ -63,6 +63,16 @@ struct snd_platform_data {
 	unsigned sram_size_playback;
 	unsigned sram_size_capture;
 
+	/*
+	 * This define works when both clock and FS are output for the cpu
+	 * and makes clock very fast (FS is not simmetrical, but sampling
+	 * frequency is better approximated
+	 */
+	int i2s_fast_clock;
+
+	/* To be used when cpu gets clock from extenal pin */
+	int clk_input_pin;
+
 	/* McASP specific fields */
 	int tdm_slots;
 	u8 op_mode;
@@ -78,6 +88,12 @@ enum {
 	MCASP_VERSION_2,	/* DA8xx/OMAPL1x */
 };
 
+enum {
+	MCBSP_CLKR = 0,		/* DM365 */
+	MCBSP_CLKS,
+};
+
+
 #define INACTIVE_MODE	0
 #define TX_MODE		1
 #define RX_MODE		2
sound/soc/davinci/davinci-i2s.c +112 -14

214 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#1 lore raw
Quoted 1 line · Raffaele Recalcati

From: Raffaele Recalcati <[email protected]>

It's still very hard to understand what this patch is supposed to do. As previously mentioned this would probably be a lot clearer if you split this into multiple patches, for example one adding support for the fast clock mode, one adding support for selecting the pin used for any external clock and then further patches with any other changes.

I strongly suggest looking at the commit messages for other patches in the kernel and trying to follow a similar style.

Quoted 2 lines

Added audio playback support with [frame sync master - clock master] mode and with [frame sync master - clock slave].

What are these modes - which clock are you talking about?

Quoted 2 lines

i2s_fast_clock switch can be used to have better approximate or symmetric waveforms.

Why would someone choose not to use this?

Quoted 7 lines

clk_input_pin board info can be used to select it depending on hw connections

3. We haven't changed the evmdm365 support (due also to CPLD that doesn't help to understand) We don't know in this mode if audio stereo works on evmdm365. Probably it does.

This is what makes me unsure if you're trying to add new modes or not - if you're adding new modes then I'd expect that existing boards would be unaffected with any changes to use the new feature being easily seperable.

arch/arm/mach-davinci/include/mach/asp.h struct snd_platform_data { · line 68

Quoted 3 lines
arch/arm/mach-davinci/include/mach/asp.h +3 -0
+	/*
+	 * This define works when both clock and FS are output for the cpu
+	 * and makes clock very fast (FS is not simmetrical, but sampling

symmetrical.

arch/arm/mach-davinci/include/mach/asp.h struct snd_platform_data { · line 71

Quoted 3 lines
arch/arm/mach-davinci/include/mach/asp.h +3 -0
+	 * frequency is better approximated
+	 */
+	int i2s_fast_clock;

Is this a bool?

arch/arm/mach-davinci/include/mach/asp.h struct snd_platform_data { · line 75

Quoted 3 lines
arch/arm/mach-davinci/include/mach/asp.h +3 -0
+	/* To be used when cpu gets clock from extenal pin */
+	int clk_input_pin;
+

How would one use this?

Quoted 8 lines
sound/soc/davinci/davinci-i2s.c +2 -5
 	case SND_SOC_DAIFMT_CBM_CFS:
-		/* McBSP CLKR pin is the input for the Sample Rate Generator.
-		 * McBSP FSR and FSX are driven by the Sample Rate Generator. */
-		pcr = DAVINCI_MCBSP_PCR_SCLKME |
-			DAVINCI_MCBSP_PCR_FSXM |
-			DAVINCI_MCBSP_PCR_FSRM;
+		pcr = DAVINCI_MCBSP_PCR_FSRM | DAVINCI_MCBSP_PCR_FSXM;
+		if (dev->clk_input_pin == MCBSP_CLKS)

sound/soc/davinci/davinci-i2s.c static int davinci_i2s_set_dai_fmt(struct snd_soc_dai *cpu_dai, · line 294

Quoted 10 lines
sound/soc/davinci/davinci-i2s.c +10 -0
+			pcr |= DAVINCI_MCBSP_PCR_CLKXM |
+				DAVINCI_MCBSP_PCR_CLKRM;
+		else
+			/*
+			 * McBSP CLKR pin is the input for the Sample Rate
+			 * Generator.
+			 * McBSP FSR and FSX are driven by the Sample Rate
+			 * Generator.
+			 */
+			pcr |= DAVINCI_MCBSP_PCR_SCLKME;

This looks like you need a switch statement for the clock selection.

sound/soc/davinci/davinci-i2s.c static int davinci_i2s_set_dai_fmt(struct snd_soc_dai *cpu_dai, · line 403

Quoted 10 lines
sound/soc/davinci/davinci-i2s.c +10 -0
+static int davinci_i2s_dai_set_clkdiv(struct snd_soc_dai *cpu_dai,
+				int div_id, int div)
+{
+	struct davinci_mcbsp_dev *dev = cpu_dai->private_data;
+	int srgr;
+
+	dev->clk_div = div;
+	return 0;
+}
+

I would add a clock ID here in case someone wants to configure another clock in the patch.

sound/soc/davinci/davinci-i2s.c static int davinci_i2s_hw_params(struct snd_pcm_substream *substream, · line 433

Quoted 1 line
sound/soc/davinci/davinci-i2s.c +1 -0
+	if (master == SND_SOC_DAIFMT_CBS_CFS) {

Use a switch staetment for this too.

sound/soc/davinci/davinci-i2s.c static int davinci_i2s_hw_params(struct snd_pcm_substream *substream, · line 434

Quoted 1 line
sound/soc/davinci/davinci-i2s.c +1 -0
+		clk = clk_get(NULL, "pll1_sysclk6");

You're doing a clk_get() every time you go through here but never freeing it - it would seem better to just do the clk_get() at startup. I'd also expect this to be doing a clk_get() using the struct device for the DAI so that the driver can function even if the clock tree for a new SoC is different.

sound/soc/davinci/davinci-i2s.c static int davinci_i2s_hw_params(struct snd_pcm_substream *substream, · line 436

Quoted 2 lines
sound/soc/davinci/davinci-i2s.c +2 -0
+		if (clk)
+			freq = clk_get_rate(clk);

clk_get() returns an error pointer on error, not NULL, and...

sound/soc/davinci/davinci-i2s.c static int davinci_i2s_hw_params(struct snd_pcm_substream *substream, · line 437

Quoted 1 line
sound/soc/davinci/davinci-i2s.c +1 -0
+		freq = 122000000; /* FIXME ask to Texas */

...this presumably ought to be in an else clause (or perhaps just not using this clocking at all if you can't find the clock?).

sound/soc/davinci/davinci-i2s.c static int davinci_i2s_hw_params(struct snd_pcm_substream *substream, · line 462

Quoted 2 lines
sound/soc/davinci/davinci-i2s.c +2 -0
+	} else if (master == SND_SOC_DAIFMT_CBM_CFS) {
+		/* Clock given on CLKS */

What if the user selected a different clock source?

Review

Quoted 2 lines
(quoted diff) +2 -0
+		if (master == SND_SOC_DAIFMT_CBS_CFS ||
+				master == SND_SOC_DAIFMT_CBS_CFM) {

Again, switch statement.

Review

Quoted 2 lines
(quoted diff) +2 -0
+	if (master == SND_SOC_DAIFMT_CBS_CFS ||
+			master == SND_SOC_DAIFMT_CBS_CFM) {

Here too.

#2 lore raw

2010/6/28 Mark Brown <[email protected]>

Quoted 9 lines · Raffaele Recalcati
Quoted 1 line

From: Raffaele Recalcati <[email protected]>

It's still very hard to understand what this patch is supposed to do. As previously mentioned this would probably be a lot clearer if you split this into multiple patches, for example one adding support for the fast clock mode, one adding support for selecting the pin used for any external clock and then further patches with any other changes.

Looking at other paches, they are simpler than mine. I'll try to split it, hoping to obtain the final result.

Quoted 10 lines

I strongly suggest looking at the commit messages for other patches in the kernel and trying to follow a similar style.

Quoted 1 line

Added audio playback support with [frame sync master - clock master]

mode

Quoted 1 line

and with [frame sync master - clock slave].

What are these modes - which clock are you talking about?

McBSP i2s interface to external codec.

Quoted 6 lines
Quoted 3 lines

i2s_fast_clock switch can be used to have better approximate or symmetric waveforms.

Why would someone choose not to use this?

I was not sure if symmetric waveform can be a must.
In general I think it is better a non symmetric, but better approximate, waveform.
Anyway, it is better to have the possibility to choose in my opinion, because I have not so much experience in i2s communication.

Quoted 6 lines
Quoted 5 lines

clk_input_pin board info can be used to select it depending on hw connections

3. We haven't changed the evmdm365 support (due also to CPLD that

doesn't

Quoted 9 lines
Quoted 3 lines

help to understand)
We don't know in this mode if audio stereo works on evmdm365. Probably it does.

This is what makes me unsure if you're trying to add new modes or not - if you're adding new modes then I'd expect that existing boards would be unaffected with any changes to use the new feature being easily seperable.

Some tests are needed, but it requires time.
I'll try try to make some tests on evmdm365, but I'm not sure to have time to do it.

Quoted 6 lines

arch/arm/mach-davinci/include/mach/asp.h struct snd_platform_data { · line 68

Quoted 3 lines
arch/arm/mach-davinci/include/mach/asp.h +3 -0
+     /*
+      * This define works when both clock and FS are output for the cpu
+      * and makes clock very fast (FS is not simmetrical, but sampling

symmetrical.

thx

Quoted 7 lines

arch/arm/mach-davinci/include/mach/asp.h struct snd_platform_data { · line 71

Quoted 4 lines
arch/arm/mach-davinci/include/mach/asp.h +3 -0
+      * frequency is better approximated
+      */
+     int i2s_fast_clock;

Is this a bool?

yes, I'll change it.

Quoted 7 lines

arch/arm/mach-davinci/include/mach/asp.h struct snd_platform_data { · line 75

Quoted 4 lines
arch/arm/mach-davinci/include/mach/asp.h +3 -0
+     /* To be used when cpu gets clock from extenal pin */
+     int clk_input_pin;
+

How would one use this?

looking at 2.5 Clock, Frames, and Data in you can select MCBSP_CLKS or other input clock pins.

Quoted 1 line

From board file you can select the possibilites:

static struct snd_platform_data dm365_bmx_snd_data[] = {
        {
        },
        {
                .i2s_fast_clock = 0,
                .clk_input_pin = MCBSP_CLKS,
        },
};

If not set, it works as evm works, that is the default mode.

Quoted 21 lines
Quoted 2 lines

case SND_SOC_DAIFMT_CBM_CFS:
- /* McBSP CLKR pin is the input for the Sample Rate

Generator.

Quoted 1 line

- * McBSP FSR and FSX are driven by the Sample Rate

Generator. */

Quoted 5 lines
sound/soc/davinci/davinci-i2s.c +2 -3
-             pcr = DAVINCI_MCBSP_PCR_SCLKME |
-                     DAVINCI_MCBSP_PCR_FSXM |
-                     DAVINCI_MCBSP_PCR_FSRM;
+             pcr = DAVINCI_MCBSP_PCR_FSRM | DAVINCI_MCBSP_PCR_FSXM;
+             if (dev->clk_input_pin == MCBSP_CLKS)

sound/soc/davinci/davinci-i2s.c static int davinci_i2s_set_dai_fmt(struct snd_soc_dai *cpu_dai, · line 294

Quoted 10 lines
sound/soc/davinci/davinci-i2s.c +10 -0
+                     pcr |= DAVINCI_MCBSP_PCR_CLKXM |
+                             DAVINCI_MCBSP_PCR_CLKRM;
+             else
+                     /*
+                      * McBSP CLKR pin is the input for the Sample Rate
+                      * Generator.
+                      * McBSP FSR and FSX are driven by the Sample Rate
+                      * Generator.
+                      */
+                     pcr |= DAVINCI_MCBSP_PCR_SCLKME;
Quoted 2 lines

This looks like you need a switch statement for the clock selection.

ok.

Quoted 5 lines
Quoted 5 lines
sound/soc/davinci/davinci-i2s.c +5 -0
+static int davinci_i2s_dai_set_clkdiv(struct snd_soc_dai *cpu_dai,
+                             int div_id, int div)
+{
+     struct davinci_mcbsp_dev *dev = cpu_dai->private_data;
+     int srgr;
Quoted 9 lines

sound/soc/davinci/davinci-i2s.c static int davinci_i2s_set_dai_fmt(struct snd_soc_dai *cpu_dai, · line 403

Quoted 5 lines
sound/soc/davinci/davinci-i2s.c +5 -0
+
+     dev->clk_div = div;
+     return 0;
+}
+

I would add a clock ID here in case someone wants to configure another clock in the patch.

Can you explain better,
please?

Quoted 10 lines
Quoted 2 lines

+ if (master == SND_SOC_DAIFMT_CBS_CFS) {

Use a switch staetment for this too.

Quoted 1 line

+ clk = clk_get(NULL, "pll1_sysclk6");

You're doing a clk_get() every time you go through here but never freeing it - it would seem better to just do the clk_get() at startup.

Thx for this.
I think it could create problems, right?
I can do it in the probe, I think, similarly to other drivers.

Quoted 4 lines

I'd also expect this to be doing a clk_get() using the struct device for the DAI so that the driver can function even if the clock tree for a new.. SoC is different.

Sorry, I don't understand, can you explain me better?

Quoted 6 lines

sound/soc/davinci/davinci-i2s.c static int davinci_i2s_hw_params(struct snd_pcm_substream *substream, · line 436

Quoted 3 lines
sound/soc/davinci/davinci-i2s.c +2 -0
+             if (clk)
+                     freq = clk_get_rate(clk);

clk_get() returns an error pointer on error, not NULL, and...

gueSsing that I have to use this example code:

        aemif_clk = clk_get(NULL, "aemif");
        if (IS_ERR(aemif_clk))
                return;

I'll do it.

Quoted 6 lines
Quoted 2 lines

+ freq = 122000000; /* FIXME ask to Texas */

...this presumably ought to be in an else clause (or perhaps just not using this clocking at all if you can't find the clock?).

freq is used to obtain clk_div.
The real problem is that, as explained in the manual, it is not clear its value.
I hope someone can help!!

Quoted 6 lines

sound/soc/davinci/davinci-i2s.c static int davinci_i2s_hw_params(struct snd_pcm_substream *substream, · line 462

Quoted 3 lines
sound/soc/davinci/davinci-i2s.c +2 -0
+     } else if (master == SND_SOC_DAIFMT_CBM_CFS) {
+             /* Clock given on CLKS */

What if the user selected a different clock source?

I need another check,
right!

Quoted 6 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+             if (master == SND_SOC_DAIFMT_CBS_CFS ||
+                             master == SND_SOC_DAIFMT_CBS_CFM) {

Again, switch statement.

ok

Quoted 6 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+     if (master == SND_SOC_DAIFMT_CBS_CFS ||
+                     master == SND_SOC_DAIFMT_CBS_CFM) {

Here too.

again.

Conclusion
I split patches and I do fixes above.
Than I'll submit again and wait for new info.

The freq problem is describe here below, but it is not clear to me:

Quoted 1 line

From *TMS320DM36x DMSoC Multichannel Buffered Serial Port User's Guide (Rev.

A) <http://www.ti.com/litv/pdf/sprufi3a>*
2.5.3 Data Clock Generation
When the receive/transmit clock mode is set to 1 (CLK(R/X)M = 1 in the pin control register (PCR)), the
data clocks (CLK(R/X)) are driven by the internal sample rate generator output clock, CLKG. You can
select for the receiver and transmitter from a variety of data bit clocks including:
• The input clock to the sample rate generator, which can be either the internal clock source or a
dedicated external clock source via the MCBSP_CLKX, MCBSP_CLKR, or MCBSP_CLKS pins. The
McBSP internal clock is the CPU/6 clock. See Section 2.5.3.1 for details on the source of the McBSP
internal clock.
• The input clock source (internal clock source or external clock MCBSP_CLKX/MCBSP_CLKR/MCBSP_CLKS) to the sample rate generator can be divided-down by a
programmable value (CLKGDV bit in the sample rate generator register (SRGR)) to drive CLKG.
Regardless of the source to the sample rate generator, the rising edge of CLKSRG (see Figure 5)
generates CLKG and FSG.

CPU/6 is not clear.

regards,
Raffaele

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#3 lore raw
Quoted 27 lines

The freq problem is describe here below, but it is not clear to me:

From *TMS320DM36x DMSoC Multichannel Buffered Serial Port User's Guide (Rev. A) <http://www.ti.com/litv/pdf/sprufi3a>*
2.5.3 Data Clock Generation
When the receive/transmit clock mode is set to 1 (CLK(R/X)M = 1 in the pin control register (PCR)), the
data clocks (CLK(R/X)) are driven by the internal sample rate generator output clock, CLKG. You can
select for the receiver and transmitter from a variety of data bit clocks including:
? The input clock to the sample rate generator, which can be either the internal clock source or a
dedicated external clock source via the MCBSP_CLKX, MCBSP_CLKR, or MCBSP_CLKS pins. The
McBSP internal clock is the CPU/6 clock. See Section 2.5.3.1 for details on the source of the McBSP
internal clock.
? The input clock source (internal clock source or external clock MCBSP_CLKX/MCBSP_CLKR/MCBSP_CLKS) to the sample rate generator can be divided-down by a
programmable value (CLKGDV bit in the sample rate generator register (SRGR)) to drive CLKG.
Regardless of the source to the sample rate generator, the rising edge of CLKSRG (see Figure 5)
generates CLKG and FSG.

Quoted 2 lines

CPU/6 is not clear.

Reading better the documentation the point seems now clear.
We have pllc1 sysclk4 that is the clock of McBSP peripheral.
And so it was abviously this frequency to be used when McBSP has to generate the clock.
Sorry..

Raffaele
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20100630/cd36af45/attachment.html>

#4 lore raw
In reply to Raffaele Recalcati
Quoted 9 lines · Raffaele Recalcati

2010/6/28 Mark Brown <[email protected]>

Quoted 5 lines

It's still very hard to understand what this patch is supposed to do. As previously mentioned this would probably be a lot clearer if you split this into multiple patches, for example one adding support for the fast clock mode, one adding support for selecting the pin used for any external clock and then further patches with any other changes.

Looking at other paches, they are simpler than mine.

The big problem is you're just making some general (and not particularly clear) statements about features without saying anything concrete about what the patch actually does - is there a bug being fixed, a feature implemented, or what?

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Added audio playback support with [frame sync master - clock master]

mode

Quoted 1 line

and with [frame sync master - clock slave].

What are these modes - which clock are you talking about?

McBSP i2s interface to external codec.

Perhaps you mean the bit clock on the I2S interface? There are multiple clocks on the actual I2S link itself, and often people lump in the master clock for the I2S interface into the interface itself.

Quoted 10 lines
Quoted 4 lines
Quoted 2 lines

i2s_fast_clock switch can be used to have better approximate or symmetric waveforms.

Why would someone choose not to use this?

I was not sure if symmetric waveform can be a must.
In general I think it is better a non symmetric, but better approximate, waveform.
Anyway, it is better to have the possibility to choose in my opinion, because I have not so much experience in i2s communication.

If I understand this correctly when you say "approximate" what you mean is "approximate clock rate" so the tradeoff is between the accuracy of the rate generated and the duty cycle of the output signal?

Quoted 7 lines
Quoted 4 lines

arch/arm/mach-davinci/include/mach/asp.h struct snd_platform_data { · line 74

Quoted 2 lines
arch/arm/mach-davinci/include/mach/asp.h +2 -0
+     /* To be used when cpu gets clock from extenal pin */
+     int clk_input_pin;

How would one use this?

looking at 2.5 Clock, Frames, and Data in you can select MCBSP_CLKS or other input clock pins.

You need to put this in the comments.

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
sound/soc/davinci/davinci-i2s.c +4 -0
+static int davinci_i2s_dai_set_clkdiv(struct snd_soc_dai *cpu_dai,
+                             int div_id, int div)
+{
+     struct davinci_mcbsp_dev *dev = cpu_dai->private_data;
Quoted 8 lines

sound/soc/davinci/davinci-i2s.c static int davinci_i2s_set_dai_fmt(struct snd_soc_dai *cpu_dai, · line 402

Quoted 5 lines
sound/soc/davinci/davinci-i2s.c +5 -0
+     int srgr;
+
+     dev->clk_div = div;
+     return 0;
+}

I would add a clock ID here in case someone wants to configure another clock in the patch.

Quoted 2 lines

Can you explain better,
please?

You need to require a value for div_id.

Quoted 5 lines
Quoted 3 lines

I'd also expect this to be doing a clk_get() using the struct device for the DAI so that the driver can function even if the clock tree for a new.. SoC is different.

Sorry, I don't understand, can you explain me better?

clk_get() takes two parameters, a struct device and a name. You should be using a clock specified in terms of a particular device, not one with a NULL pointer for the struct device.

Quoted 9 lines
Quoted 4 lines
Quoted 1 line

+ freq = 122000000; /* FIXME ask to Texas */

...this presumably ought to be in an else clause (or perhaps just not using this clocking at all if you can't find the clock?).

freq is used to obtain clk_div.
The real problem is that, as explained in the manual, it is not clear its value.
I hope someone can help!!

I would very strongly expect that the division would be from the clock rate of the source clock which you can obtain by using clk_get().

#5 lore raw
In reply to Raffaele Recalcati

sound/soc/davinci/davinci-i2s.c static int davinci_i2s_hw_params(struct snd_pcm_substream *substream, · line 443

Quoted 2 lines · Raffaele Recalcati
sound/soc/davinci/davinci-i2s.c +2 -0
+		if (dev->i2s_fast_clock) {
+			clk_div = 256;

can you have
f = (freq / params->rate_num) * params->rate_den;

sound/soc/davinci/davinci-i2s.c static int davinci_i2s_hw_params(struct snd_pcm_substream *substream, · line 447

Quoted 4 lines
sound/soc/davinci/davinci-i2s.c +4 -0
+			do {
+				framesize = (freq / (--clk_div)) /
+					    params->rate_num *
+					    params->rate_den;

and

				framesize = f / (--clk_div);

sound/soc/davinci/davinci-i2s.c static int davinci_i2s_hw_params(struct snd_pcm_substream *substream, · line 450

Quoted 3 lines
sound/soc/davinci/davinci-i2s.c +3 -0
+			} while (((framesize < 33) || (framesize > 4095)) &&
+				 (clk_div));
+			clk_div--;

looks like clk_div can go negative here, should the above while say (clk_div > 1)

Quoted 10 lines
sound/soc/davinci/davinci-i2s.c +10 -0
+			srgr |= DAVINCI_MCBSP_SRGR_FPER(framesize - 1);
+		} else {
+			/* symmetric waveforms */
+			clk_div = freq / (mcbsp_word_length * 16) /
+				  params->rate_num * params->rate_den;
+			srgr |= DAVINCI_MCBSP_SRGR_FPER(mcbsp_word_length *
+							16 - 1);
+		}
+		clk_div &= 0xFF;
+		srgr |= clk_div;
#6 lore raw

2010/6/28 Troy Kisky <[email protected]>

Quoted 19 lines

sound/soc/davinci/davinci-i2s.c static int davinci_i2s_hw_params(struct snd_pcm_substream *substream, · line 443

Quoted 2 lines · Raffaele Recalcati
sound/soc/davinci/davinci-i2s.c +2 -0
+             if (dev->i2s_fast_clock) {
+                     clk_div = 256;

can you have
f = (freq / params->rate_num) * params->rate_den;

sound/soc/davinci/davinci-i2s.c static int davinci_i2s_hw_params(struct snd_pcm_substream *substream, · line 447

Quoted 4 lines
sound/soc/davinci/davinci-i2s.c +4 -0
+                     do {
+                             framesize = (freq / (--clk_div)) /
+                                         params->rate_num *
+                                         params->rate_den;

and

                               framesize = f / (--clk_div);
Quoted 1 line

+ } while (((framesize < 33) || (framesize > 4095))

&&

sound/soc/davinci/davinci-i2s.c static int davinci_i2s_hw_params(struct snd_pcm_substream *substream, · line 450

Quoted 2 lines
sound/soc/davinci/davinci-i2s.c +2 -0
+                              (clk_div));
+                     clk_div--;

looks like clk_div can go negative here, should the above while say (clk_div > 1)

sound/soc/davinci/davinci-i2s.c static int davinci_i2s_hw_params(struct snd_pcm_substream *substream, · line 449

Quoted 2 lines
sound/soc/davinci/davinci-i2s.c +2 -0
+                     } while (((framesize < 33) || (framesize > 4095)) &&
+                              (clk_div));

only if clk_div not null stay inside the while.

Quoted 1 line

+ clk_div--;

and here can at minumum be 0, not negative.

Quoted 11 lines

sound/soc/davinci/davinci-i2s.c static int davinci_i2s_hw_params(struct snd_pcm_substream *substream, · line 460

Quoted 10 lines
sound/soc/davinci/davinci-i2s.c +10 -0
+                     srgr |= DAVINCI_MCBSP_SRGR_FPER(framesize - 1);
+             } else {
+                     /* symmetric waveforms */
+                     clk_div = freq / (mcbsp_word_length * 16) /
+                               params->rate_num * params->rate_den;
+                     srgr |= DAVINCI_MCBSP_SRGR_FPER(mcbsp_word_length *
+                                                     16 - 1);
+             }
+             clk_div &= 0xFF;
+             srgr |= clk_div;

so, dividing for (CLKGDV + 1) it is ok.

Raffaele