PXA SSP and external clocked I2S again
Subsystems (5)
Hi,
as denoted yesterday, we've spend some more time on the PXA/SSP/I2S issue and would like to share conclusions about out utterly frustrating trial-and-error sessions during the last days, especially as reference for everyone who tries to get a similar setup running.
The situation on our board is: we have a tunable master clock generator, a CS4270 codec and an PXA303 connected to each other. In order to use the master clock, the PXA needs to be set to an external clock mode and for the CS4270 to operate properly, we need to provide a full 64 bits I2S stream, even though not all of the data bits (in fact, currently only 16 of them per channel) carry data.
The above thing was not possible with the pxa-ssp's current approach as it entirely relyed on the network mode and the time slots mechanism which is - according to the datasheets - supposed to do exactly this, but which simply doesn't work at all. It might work for existing boards without our constrains, but that's more or less due to coincidence.
Hence, we switched over to non-network mode and fiddled around with the PSP bits a lot until we found a mode that fits our needs, at least as long as we let the PXA be master in the game (which we did for test purposes).
As soon as the clock direction changes (codec takes over control for LRCLK and bitclk), the PSP feature fails badly again. The final solution is now to never ever set the PXA to a real slave mode (DAIFMT_CBM_CFM) but only provide the master clock to its input pin (SSPEXTCLK), set the clock config to SSP_CLK_EXT and let the PXA derive the other clocks from that one internally.
Another thing is: ALSA doesn't currently provide a way to configure a DAI format where the I2S protocol has more clock bits than data bits. One of the upcoming series of 4 patches adds them.
Best regards,
Daniel
PATCH 1/4 pxa-ssp: fix name of register bit
A bit in PXA's SSCR0 register was erroneously named ADC but its name is in fact ADC (audio clock select).
--- arch/arm/mach-pxa/include/mach/regs-ssp.h | 2 +- sound/soc/pxa/pxa-ssp.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)
arch/arm/mach-pxa/include/mach/regs-ssp.h +1 -1
@@ -50,7 +50,7 @@#define SSCR0_TUM (1 << 23)/* Transmit FIFO underrun interrupt mask */ #define SSCR0_FRDC (0x07000000)/* Frame rate divider control (mask) */ #define SSCR0_SlotsPerFrm (x) (((x) - 1) << 24)/* Time slots per frame [1..8] */ -#define SSCR0_ADC (1 << 30)/* Audio clock select */ +#define SSCR0_ACS (1 << 30)/* Audio clock select */ #define SSCR0_MOD (1 << 31)/* Mode (normal or network) */ #endif
sound/soc/pxa/pxa-ssp.c +3 -3
@@ -300,7 +300,7 @@ static int pxa_ssp_set_dai_sysclk(struct snd_soc_dai *cpu_dai,int val;u32 sscr0 =ssp_read_reg (ssp,SSCR0 ) & - ~(SSCR0_ECS |SSCR0_NCS |SSCR0_MOD |SSCR0_ADC ); + ~(SSCR0_ECS |SSCR0_NCS |SSCR0_MOD |SSCR0_ACS ); dev_dbg(&ssp->pdev->dev, "pxa_ssp_set_dai_sysclk id: %d, clk_id %d, freq %d\n",
@@ -328,7 +328,7 @@ static int pxa_ssp_set_dai_sysclk(struct snd_soc_dai *cpu_dai,case PXA_SSP_CLK_AUDIO : priv->sysclk =0 ;ssp_set_scr (&priv->dev,1 ); - sscr0 |=SSCR0_ADC ; + sscr0 |=SSCR0_ACS ;break ;default :return -ENODEV ;
@@ -524,7 +524,7 @@ static int pxa_ssp_set_dai_fmt(struct snd_soc_dai *cpu_dai,/* reset port settings */ sscr0 =ssp_read_reg (ssp,SSCR0 ) & - (SSCR0_ECS |SSCR0_NCS |SSCR0_MOD |SSCR0_ADC ); + (SSCR0_ECS |SSCR0_NCS |SSCR0_MOD |SSCR0_ACS ); sscr1 =SSCR1_RxTresh (8 ) |SSCR1_TxTresh (7 ); sspsp =0 ;
Signature · 1 line
1.6.1.3
PATCH 2/4 soc-dai: add bitfields for hardware I2S formats
This patch adds bitfields for I2S serial formats that differ from the amount of data actually sent on the line. Some codecs (namely the cs4270) require 64 sysclks being sent during each frame period, even though the number of acutal data bits might be less.
--- include/sound/soc-dai.h | 20 ++++++++++++++++---- 1 files changed, 16 insertions(+), 4 deletions(-)
include/sound/soc-dai.h +16 -4
@@ -85,10 +85,22 @@ struct snd_pcm_substream;#define SND_SOC_DAIFMT_CBM_CFS (2 << 12)/* codec clk master & frame slave */ #define SND_SOC_DAIFMT_CBS_CFS (3 << 12)/* codec clk & frm slave */ -#define SND_SOC_DAIFMT_FORMAT_MASK 0x000f -#define SND_SOC_DAIFMT_CLOCK_MASK 0x00f0 -#define SND_SOC_DAIFMT_INV_MASK 0x0f00 -#define SND_SOC_DAIFMT_MASTER_MASK 0xf000 +/* +* DAI hardware frame formats. +* +* Independently, these bits the define the audio format on the +* pysical channel in case it differs from the audio sample the +* DAI is configured to +*/ +#define SND_SOC_DAIFMT_FF_SAMPLE (0 << 16) +#define SND_SOC_DAIFMT_FF_I2S_16 (1 << 16) +#define SND_SOC_DAIFMT_FF_I2S_32 (2 << 16) + +#define SND_SOC_DAIFMT_FORMAT_MASK 0x0000f +#define SND_SOC_DAIFMT_CLOCK_MASK 0x000f0 +#define SND_SOC_DAIFMT_INV_MASK 0x00f00 +#define SND_SOC_DAIFMT_MASTER_MASK 0x0f000 +#define SND_SOC_DAIFMT_FRAME_FORMAT_MASK 0xf0000/* * Master Clock Directions
Signature · 1 line
1.6.1.3
PATCH 3/4 pxa-ssp: don't touch ssp registers when stream is running
In pxa_ssp_set_dai_fmt(), don't modify the SSP registers in case the stream is already running. With that patch applied, loop-thru tests like 'acrecord -f cd | aplay -f cd' succeed.
--- sound/soc/pxa/pxa-ssp.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
sound/soc/pxa/pxa-ssp.c +4 -0
@@ -521,6 +521,10 @@ static int pxa_ssp_set_dai_fmt(struct snd_soc_dai *cpu_dai,u32 sscr0;u32 sscr1;u32 sspsp; + +/* we can only change the settings if the port is not in use */ +if (ssp_read_reg (ssp,SSCR0 ) &SSCR0_SSE ) +return 0 ;/* reset port settings */ sscr0 = ssp_read_reg(ssp, SSCR0) &
Signature · 1 line
1.6.1.3
PATCH 4/4 pxa-ssp: switch from network mode to psp
This patch uses the SSP's PSP functionality to provide I2S timings. The particular problem is that even though the datasheets state it should be possbible, there is no mode which uses the network feature with its associated time slots in a sane way to do what we need.
Hence, in order to have full 64 bit I2S on the wire, we need to fiddle around with the SSP and the timing paramters a lot. There are some constants left in the code which can't be replaced by names because the true meaning of their registers remains nebulous.
--- sound/soc/pxa/pxa-ssp.c | 39 +++++++++++++++++++++------------------ 1 files changed, 21 insertions(+), 18 deletions(-)
sound/soc/pxa/pxa-ssp.c +21 -18
@@ -319,6 +319,7 @@ static int pxa_ssp_set_dai_sysclk(struct snd_soc_dai *cpu_dai,break ;case PXA_SSP_CLK_EXT : priv->sysclk = freq; +ssp_set_scr (&priv->dev,4 ); sscr0 |=SSCR0_ECS ;break ;case PXA_SSP_CLK_NET :
@@ -551,17 +552,13 @@ static int pxa_ssp_set_dai_fmt(struct snd_soc_dai *cpu_dai,switch (fmt &SND_SOC_DAIFMT_FORMAT_MASK ) {case SND_SOC_DAIFMT_I2S : - sscr0 |=SSCR0_MOD |SSCR0_PSP ; + sscr0 |=SSCR0_PSP ; sscr1 |=SSCR1_RWOT |SSCR1_TRAIL ;switch (fmt &SND_SOC_DAIFMT_INV_MASK ) {case SND_SOC_DAIFMT_NB_NF : - sspsp |=SSPSP_FSRT ;break ;case SND_SOC_DAIFMT_NB_IF : - sspsp |=SSPSP_SFRMP |SSPSP_FSRT ; -break ; -case SND_SOC_DAIFMT_IB_IF : sspsp |=SSPSP_SFRMP ;break ;default :
@@ -652,33 +649,39 @@ static int pxa_ssp_hw_params(struct snd_pcm_substream *substream,break ;case SNDRV_PCM_FORMAT_S24_LE : sscr0 |= (SSCR0_EDSS |SSCR0_DataSize (8 )); -/* we must be in network mode (2 slots) for 24 bit stereo */ break ;case SNDRV_PCM_FORMAT_S32_LE : sscr0 |= (SSCR0_EDSS |SSCR0_DataSize (16 )); -/* we must be in network mode (2 slots) for 32 bit stereo */ break ; }ssp_write_reg (ssp,SSCR0 , sscr0);switch (priv->dai_fmt &SND_SOC_DAIFMT_FORMAT_MASK ) {case SND_SOC_DAIFMT_I2S : -/* Cleared when the DAI format is set */ - sspsp =ssp_read_reg (ssp,SSPSP ) |SSPSP_SFRMWDTH (width); + sspsp =ssp_read_reg (ssp,SSPSP ); + +switch (priv->dai_fmt &SND_SOC_DAIFMT_FRAME_FORMAT_MASK ) { +case SND_SOC_DAIFMT_FF_I2S_32 : +/* These values are all found out by trying and +* failing a lot. PXA's SSP is all black magic and +* does not work like described in any datasheet. +*/ + sspsp |=SSPSP_SFRMWDTH (32 ); + sspsp |=SSPSP_SFRMDLY (32 *2 ); + sspsp |=SSPSP_EDMYSTOP (3 ); + sspsp |=SSPSP_DMYSTOP (3 ); + sspsp |=SSPSP_DMYSTRT (1 ); +break ; +default : +/* Cleared when the DAI format is set */ + sspsp |=SSPSP_SFRMWDTH (width); +break ; + }ssp_write_reg (ssp,SSPSP , sspsp); -break ;default :break ; } -/* We always use a network mode so we always require TDM slots -* - complain loudly and fail if they've not been set up yet. -*/ -if (!(ssp_read_reg (ssp,SSTSA ) &0xf )) { -dev_err (&ssp->pdev->dev,"No TDM timeslot configured\n" ); -return -EINVAL ; - } -dump_registers (ssp);return 0 ;
Signature · 1 line
1.6.1.3
Re: [PATCH 4/4] pxa-ssp: switch from network mode to psp
Quoted 25 lines · Daniel Mack
This patch uses the SSP's PSP functionality to provide I2S timings. The particular problem is that even though the datasheets state it should be possbible, there is no mode which uses the network feature with its associated time slots in a sane way to do what we need.
Hence, in order to have full 64 bit I2S on the wire, we need to fiddle around with the SSP and the timing paramters a lot. There are some constants left in the code which can't be replaced by names because the true meaning of their registers remains nebulous.
Signed-off-by Daniel Mack <[email protected]>Signed-off-by Tim Ruetz <[email protected]>Cc Mark Brown <[email protected]>Cc Liam Girdwood <[email protected]>Cc Philipp Zabel <[email protected]>---
sound/soc/pxa/pxa-ssp.c | 39 +++++++++++++++++++++------------------1 files changed, 21 insertions(+), 18 deletions(-)sound/soc/pxa/pxa-ssp.c +0
-0@@ -319,6 +319,7 @@ static int pxa_ssp_set_dai_sysclk(struct snd_soc_dai *cpu_dai, break;
Quoted 3 lines
case
PXA_SSP_CLK_EXT:
priv->sysclk = freq;
+ssp_set_scr(&priv->dev, 4);
Shouldn't this be somehow set by set_dai_clkdiv instead?
Quoted 11 lines
sscr0 |=
SSCR0_ECS;
break;
casePXA_SSP_CLK_NET:sound/soc/pxa/pxa-ssp.c +0
-0@@ -551,17 +552,13 @@ static int pxa_ssp_set_dai_fmt(struct snd_soc_dai *cpu_dai, switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {case
SND_SOC_DAIFMT_I2S:- sscr0 |= SSCR0_MOD | SSCR0_PSP; + sscr0 |= SSCR0_PSP; sscr1 |= SSCR1_RWOT | SSCR1_TRAIL;
Quoted 10 lines
switch (fmt &
SND_SOC_DAIFMT_INV_MASK) { caseSND_SOC_DAIFMT_NB_NF:
- sspsp |=SSPSP_FSRT; break;
caseSND_SOC_DAIFMT_NB_IF:
- sspsp |=SSPSP_SFRMP|SSPSP_FSRT;
- break;
- caseSND_SOC_DAIFMT_IB_IF:
sspsp |=SSPSP_SFRMP; break;
Removal of SSPSP_FSRT from NB/IB selection seems to be correct from the docs. Can you check if IB could be properly handled by setting SCMODE(1)?
Quoted 6 lines
default:
sound/soc/pxa/pxa-ssp.c +0
-0@@ -652,33 +649,39 @@ static int pxa_ssp_hw_params(struct snd_pcm_substream *substream, break;case
SNDRV_PCM_FORMAT_S24_LE:
sscr0 |= (SSCR0_EDSS|SSCR0_DataSize(8));
- /* we must be in network mode (2 slots) for 24 bit stereo */
This is still dubious ...S24_LE is 24-bit sound LSB-aligned in 32-bit frames, so DataSize should be 32 here.
Quoted 4 lines
break;
caseSNDRV_PCM_FORMAT_S32_LE:
sscr0 |= (SSCR0_EDSS|SSCR0_DataSize(16));
- /* we must be in network mode (2 slots) for 32 bit stereo */
How is it possible to send 64bit in one frame otherwise?
Quoted 16 lines
break;
}
ssp_write_reg(ssp, SSCR0, sscr0);switch (
priv->dai_fmt&SND_SOC_DAIFMT_FORMAT_MASK) { caseSND_SOC_DAIFMT_I2S:
- /* Cleared when the DAI format is set */
- sspsp =ssp_read_reg(ssp, SSPSP)|SSPSP_SFRMWDTH(width);
+ sspsp =ssp_read_reg(ssp, SSPSP);
+
+ switch (priv->dai_fmt&SND_SOC_DAIFMT_FRAME_FORMAT_MASK) {
+ caseSND_SOC_DAIFMT_FF_I2S_32:
+ /* These values are all found out by trying and
+ * failing a lot. PXA's SSP is all black magic and
+ * does not work like described in any datasheet.
+ */
Quoted 5 lines
+ sspsp |= SSPSP_SFRMWDTH(32); + sspsp |= SSPSP_SFRMDLY(32 * 2); + sspsp |= SSPSP_EDMYSTOP(3); + sspsp |= SSPSP_DMYSTOP(3); + sspsp |= SSPSP_DMYSTRT(1);
Wha?! Amazing. And this really works?
How the hell can this result in 16 bits of data followed by 16 bits of zeroes, twice :)
Quoted 4 lines
+ break;
+ default:
+ /* Cleared when the DAI format is set */
+ sspsp |=SSPSP_SFRMWDTH(width);
Not good for DSP_A/B.
Quoted 18 lines
+ break;
+ }
ssp_write_reg(ssp, SSPSP, sspsp);
- break;
default:
break;
}- /* We always use a network mode so we always require TDM slots
- * - complain loudly and fail if they've not been set up yet.
- */
- if (!(ssp_read_reg(ssp, SSTSA) &0xf)) {
-dev_err(&ssp->pdev->dev, "No TDM timeslot configured\n");
- return-EINVAL;
- }
-
dump_registers(ssp);
Quoted 5 lines
return 0;
--
1.6.1.3
regards
Philipp
Re: [PATCH 4/4] pxa-ssp: switch from network mode to psp
Hi Philipp,
Quoted 11 lines · pHilipp Zabel
Quoted 9 lines
sound/soc/pxa/pxa-ssp.c +0
-0@@ -319,6 +319,7 @@ static int pxa_ssp_set_dai_sysclk(struct snd_soc_dai *cpu_dai, break;case
PXA_SSP_CLK_EXT:
priv->sysclk = freq;
+ssp_set_scr(&priv->dev, 4);Shouldn't this be somehow set by
set_dai_clkdivinstead?
This is actually a very common case - MCLK is BCLK*4, so I put it here. We could still move it to some more configurable place if it turns out we need to configure it per board.
Quoted 11 lines
Quoted 10 lines
switch (fmt &
SND_SOC_DAIFMT_INV_MASK) { caseSND_SOC_DAIFMT_NB_NF:
- sspsp |=SSPSP_FSRT; break;
caseSND_SOC_DAIFMT_NB_IF:
- sspsp |=SSPSP_SFRMP|SSPSP_FSRT;
- break;
- caseSND_SOC_DAIFMT_IB_IF:
sspsp |=SSPSP_SFRMP; break;
Quoted 1 line
Removal of
SSPSP_FSRTfrom NB/IB selection seems to be correct from the docs.
SSPSP_FSRT has a totally different meaning according to the PXA3xx docs, but I'll have a look at the PXA2x specs - maybe we need a special case here. Unfortunately, I'm not able to quote from PXA3x specs here due to NDA restrictions.
Quoted 1 line
Can you check if IB could be properly handled by setting SCMODE(1)?
Can't follow that - what are you referring to here?
Quoted 10 lines
Quoted 6 lines
default:
sound/soc/pxa/pxa-ssp.c +0
-0@@ -652,33 +649,39 @@ static int pxa_ssp_hw_params(struct snd_pcm_substream *substream, break;case
SNDRV_PCM_FORMAT_S24_LE:
sscr0 |= (SSCR0_EDSS|SSCR0_DataSize(8));
- /* we must be in network mode (2 slots) for 24 bit stereo */This is still dubious ...
S24_LEis 24-bit sound LSB-aligned in 32-bit frames, so DataSize should be 32 here.
I didn't test that, and I didn't change it either - I just removed the comment, as we're not running in network mode anymore.
Quoted 6 lines
Quoted 4 lines
break;
caseSNDRV_PCM_FORMAT_S32_LE:
sscr0 |= (SSCR0_EDSS|SSCR0_DataSize(16));
- /* we must be in network mode (2 slots) for 32 bit stereo */How is it possible to send 64bit in one frame otherwise?
We're not running in network mode anymore - things are different now :)
Quoted 12 lines
Quoted 11 lines
+ switch (
priv->dai_fmt&SND_SOC_DAIFMT_FRAME_FORMAT_MASK) {
+ caseSND_SOC_DAIFMT_FF_I2S_32:
+ /* These values are all found out by trying and
+ * failing a lot. PXA's SSP is all black magic and
+ * does not work like described in any datasheet.
+ */+ sspsp |= SSPSP_SFRMWDTH(32); + sspsp |= SSPSP_SFRMDLY(32 * 2); + sspsp |= SSPSP_EDMYSTOP(3); + sspsp |= SSPSP_DMYSTOP(3); + sspsp |= SSPSP_DMYSTRT(1);
Quoted 3 lines
Wha?! Amazing. And this really works?
How the hell can this result in 16 bits of data followed by 16 bits of zeroes, twice :)
Don't ask :) If we could explain in detail what these registers mean, I'd rather make them macro values, but unfortunately, the comment is correct ...
Quoted 7 lines
Quoted 5 lines
+ break;
+ default:
+ /* Cleared when the DAI format is set */
+ sspsp |=SSPSP_SFRMWDTH(width);Not good for DSP_A/B.
This is the SND_SOC_DAIFMT_I2S case, so DSP modes will be unaffected.
Could you try the patches on your board?
Thanks,
Daniel
Re: [PATCH 4/4] pxa-ssp: switch from network mode to psp
Quoted 11 lines · Daniel Mack
Quoted 11 lines
Quoted 10 lines
switch (fmt &
SND_SOC_DAIFMT_INV_MASK) { caseSND_SOC_DAIFMT_NB_NF:
- sspsp |=SSPSP_FSRT; break;
caseSND_SOC_DAIFMT_NB_IF:
- sspsp |=SSPSP_SFRMP|SSPSP_FSRT;
- break;
- caseSND_SOC_DAIFMT_IB_IF:
sspsp |=SSPSP_SFRMP; break;
Quoted 5 lines
Quoted 1 line
Removal of
SSPSP_FSRTfrom NB/IB selection seems to be correct from the docs.
SSPSP_FSRThas a totally different meaning according to the PXA3xx docs, but I'll have a look at the PXA2x specs - maybe we need a special case here.
Sorry, got you wrong. I compared that to the PXA27x spec and it turns out that this bit has no different meaning there. So it is definitely wrong to use it for inverting the bitclk, no special case needed.
Daniel
Re: [PATCH 4/4] pxa-ssp: switch from network mode to psp
In reply to Daniel MackQuoted 7 lines · Daniel Mack
Quoted 1 line · pHilipp Zabel
Shouldn't this be somehow set by
set_dai_clkdivinstead?This is actually a very common case - MCLK is BCLK*4, so I put it here. We could still move it to some more configurable place if it turns out we need to configure it per board.
It's a common option but far from universal - apart from anything else normally the MCLK requirement is a multiple of the sampling frequency rather than the bitclock rate so the ratio with BCLK will often vary with sample size. I've seen devices able to operate as low as 64fs and IIRC I've seen things up to 512fs, though 256fs is more common.
Re: [PATCH 4/4] pxa-ssp: switch from network mode to psp
Quoted 11 lines · Mark Brown
Quoted 5 lines
Quoted 1 line
Shouldn't this be somehow set by
set_dai_clkdivinstead?This is actually a very common case - MCLK is BCLK*4, so I put it here. We could still move it to some more configurable place if it turns out we need to configure it per board.
It's a common option but far from universal - apart from anything else normally the MCLK requirement is a multiple of the sampling frequency rather than the bitclock rate so the ratio with BCLK will often vary with sample size. I've seen devices able to operate as low as 64fs and IIRC I've seen things up to 512fs, though 256fs is more common.
Ok, agreed. I moved that to my board file (using DIV_SCR) and will drop that piece in the next patches.
Daniel
Re: [PATCH 4/4] pxa-ssp: switch from network mode to psp
In reply to Daniel MackQuoted 90 lines · Daniel Mack
Hi Philipp,
Quoted 11 lines · pHilipp Zabel
Quoted 9 lines
sound/soc/pxa/pxa-ssp.c +0
-0@@ -319,6 +319,7 @@ static int pxa_ssp_set_dai_sysclk(struct snd_soc_dai *cpu_dai, break;case
PXA_SSP_CLK_EXT:
priv->sysclk = freq;
+ssp_set_scr(&priv->dev, 4);Shouldn't this be somehow set by
set_dai_clkdivinstead?This is actually a very common case - MCLK is BCLK*4, so I put it here. We could still move it to some more configurable place if it turns out we need to configure it per board.
Quoted 11 lines
Quoted 10 lines
switch (fmt &
SND_SOC_DAIFMT_INV_MASK) { caseSND_SOC_DAIFMT_NB_NF:
- sspsp |=SSPSP_FSRT; break;
caseSND_SOC_DAIFMT_NB_IF:
- sspsp |=SSPSP_SFRMP|SSPSP_FSRT;
- break;
- caseSND_SOC_DAIFMT_IB_IF:
sspsp |=SSPSP_SFRMP; break;Quoted 1 line
Removal of
SSPSP_FSRTfrom NB/IB selection seems to be correct from the docs.
SSPSP_FSRThas a totally different meaning according to the PXA3xx docs, but I'll have a look at the PXA2x specs - maybe we need a special case here. Unfortunately, I'm not able to quote from PXA3x specs here due to NDA restrictions.Quoted 1 line
Can you check if IB could be properly handled by setting SCMODE(1)?
Can't follow that - what are you referring to here?
Quoted 10 lines
Quoted 6 lines
default:
sound/soc/pxa/pxa-ssp.c +0
-0@@ -652,33 +649,39 @@ static int pxa_ssp_hw_params(struct snd_pcm_substream *substream, break;case
SNDRV_PCM_FORMAT_S24_LE:
sscr0 |= (SSCR0_EDSS|SSCR0_DataSize(8));
- /* we must be in network mode (2 slots) for 24 bit stereo */This is still dubious ...
S24_LEis 24-bit sound LSB-aligned in 32-bit frames, so DataSize should be 32 here.I didn't test that, and I didn't change it either - I just removed the comment, as we're not running in network mode anymore.
Quoted 6 lines
Quoted 4 lines
break;
caseSNDRV_PCM_FORMAT_S32_LE:
sscr0 |= (SSCR0_EDSS|SSCR0_DataSize(16));
- /* we must be in network mode (2 slots) for 32 bit stereo */How is it possible to send 64bit in one frame otherwise?
We're not running in network mode anymore - things are different now :)
Quoted 12 lines
Quoted 11 lines
+ switch (
priv->dai_fmt&SND_SOC_DAIFMT_FRAME_FORMAT_MASK) {
+ caseSND_SOC_DAIFMT_FF_I2S_32:
+ /* These values are all found out by trying and
+ * failing a lot. PXA's SSP is all black magic and
+ * does not work like described in any datasheet.
+ */+ sspsp |= SSPSP_SFRMWDTH(32); + sspsp |= SSPSP_SFRMDLY(32 * 2); + sspsp |= SSPSP_EDMYSTOP(3); + sspsp |= SSPSP_DMYSTOP(3); + sspsp |= SSPSP_DMYSTRT(1);Quoted 3 lines
Wha?! Amazing. And this really works?
How the hell can this result in 16 bits of data followed by 16 bits of zeroes, twice :)Don't ask :) If we could explain in detail what these registers mean, I'd rather make them macro values, but unfortunately, the comment is correct ...
Quoted 6 lines
Quoted 5 lines
+ break;
+ default:
+ /* Cleared when the DAI format is set */
+ sspsp |=SSPSP_SFRMWDTH(width);
Quoted 5 lines
Quoted 1 line
Not good for DSP_A/B.
This is the
SND_SOC_DAIFMT_I2Scase, so DSP modes will be unaffected.Could you try the patches on your board?
Done. They don't interfere with my setup.
regards
Philipp
Re: [PATCH 4/4] pxa-ssp: switch from network mode to psp
In reply to Daniel MackReview
Quoted 12 lines · Daniel Mack
(quoted diff) +12
-0+ switch (priv->dai_fmt & SND_SOC_DAIFMT_FRAME_FORMAT_MASK) { + case SND_SOC_DAIFMT_FF_I2S_32: + /* These values are all found out by trying and + * failing a lot. PXA's SSP is all black magic and + * does not work like described in any datasheet. + */ + sspsp |= SSPSP_SFRMWDTH(32); + sspsp |= SSPSP_SFRMDLY(32 * 2); + sspsp |= SSPSP_EDMYSTOP(3); + sspsp |= SSPSP_DMYSTOP(3); + sspsp |= SSPSP_DMYSTRT(1); + break;
*sigh*
I just saw that one of these bit fields we write to here is only available on PXA3xx - so we probably need the whole logic to be different for PXA2xx which makes everthing a lot more complicated.
Anyway, could the patch below be taken?
Thanks,
Daniel
Quoted 1 line
From
44ef06d5209b498249da5c0cc7e0bc86355f9904Mon Sep 17 00:00:00 2001
From: Daniel Mack <[email protected]>
Date: Thu, 5 Mar 2009 14:13:11 +0100
Subject: [PATCH] pxa-ssp: add two more bitfields
Add two more bitfields for the PSP register. As they seem to exist for PXA3xx only, define them conditionally.
--- arch/arm/mach-pxa/include/mach/regs-ssp.h | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
arch/arm/mach-pxa/include/mach/regs-ssp.h +5 -0
@@ -109,6 +109,11 @@#define SSSR_TINT (1 << 19)/* Receiver Time-out Interrupt */ #define SSSR_PINT (1 << 18)/* Peripheral Trailing Byte Interrupt */ +#if defined(CONFIG_PXA3xx) +#define SSPSP_EDMYSTOP (x) ((x) << 28)/* Extended Dummy Stop */ +#define SSPSP_EDMYSTRT (x) ((x) << 26)/* Extended Dummy Start */ +#endif +#define SSPSP_FSRT (1 << 25)/* Frame Sync Relative Timing */ #define SSPSP_DMYSTOP (x) ((x) << 23)/* Dummy Stop */ #define SSPSP_SFRMWDTH (x) ((x) << 16)/* Serial Frame Width */
Signature · 1 line
1.6.1.3
Re: [PATCH 4/4] pxa-ssp: switch from network mode to psp
Quoted 3 lines · Daniel Mack
I just saw that one of these bit fields we write to here is only available on PXA3xx - so we probably need the whole logic to be different for PXA2xx which makes everthing a lot more complicated.
At some point it's going to be better to just split the function using these into PXA2xx and PXA3xx variants.
Quoted 1 line
Anyway, could the patch below be taken?
Yes, sure. Will apply.
Re: [PATCH 3/4] pxa-ssp: don't touch ssp registers when stream is running
In reply to Daniel Macksound/soc/pxa/pxa-ssp.c static int pxa_ssp_set_dai_fmt(struct snd_soc_dai *cpu_dai, · line 527
Quoted 7 lines · Daniel Mack
In
pxa_ssp_set_dai_fmt(), don't modify the SSP registers in case the stream is already running. With that patch applied, loop-thru tests like 'acrecord -f cd | aplay -f cd' succeed.sound/soc/pxa/pxa-ssp.c +3
-0+/* we can only change the settings if the port is not in use */ +if (ssp_read_reg (ssp,SSCR0 ) &SSCR0_SSE ) +return 0 ;
I'd expect an error to be reported here - if we needed to change the settings and can't things could go wrong. Ideally it'd check to see if the DAI format was being changed and only error if it was.
Re: [PATCH 3/4] pxa-ssp: don't touch ssp registers when stream is running
Quoted 11 lines · Mark Brown
sound/soc/pxa/pxa-ssp.c static int pxa_ssp_set_dai_fmt(struct snd_soc_dai *cpu_dai, · line 527
Quoted 7 lines
In
pxa_ssp_set_dai_fmt(), don't modify the SSP registers in case the stream is already running. With that patch applied, loop-thru tests like 'acrecord -f cd | aplay -f cd' succeed.sound/soc/pxa/pxa-ssp.c +3
-0+/* we can only change the settings if the port is not in use */ +if (ssp_read_reg (ssp,SSCR0 ) &SSCR0_SSE ) +return 0 ;I'd expect an error to be reported here - if we needed to change the settings and can't things could go wrong. Ideally it'd check to see if the DAI format was being changed and only error if it was.
In my tests, pxa_ssp_set_dai_fmt() was simply called twice, once for the input, once for the ouput. Hence I believed a silent exit in such a case fine. Does 'arecord -f cd | aplay -f cd' work for you?
Daniel
Re: [PATCH 3/4] pxa-ssp: don't touch ssp registers when stream is running
Quoted 8 lines · Daniel Mack
Quoted 3 lines · Mark Brown
I'd expect an error to be reported here - if we needed to change the settings and can't things could go wrong. Ideally it'd check to see if the DAI format was being changed and only error if it was.
In my tests,
pxa_ssp_set_dai_fmt()was simply called twice, once for the input, once for the ouput. Hence I believed a silent exit in such a case
That'll be because you weren't changing the DAI format - hence my comment about only erroring if the format is changed.
Quoted 1 line
fine. Does 'arecord -f cd | aplay -f cd' work for you?
It won't, but that's because I don't have hardware that can play back cd format audio through the SSP port :)
Re: [PATCH 3/4] pxa-ssp: don't touch ssp registers when stream is running
Quoted 7 lines · Mark Brown
Quoted 5 lines · Daniel Mack
Quoted 3 lines · Mark Brown
I'd expect an error to be reported here - if we needed to change the settings and can't things could go wrong. Ideally it'd check to see if the DAI format was being changed and only error if it was.
Quoted 5 lines
Quoted 2 lines
In my tests,
pxa_ssp_set_dai_fmt()was simply called twice, once for the input, once for the ouput. Hence I believed a silent exit in such a caseThat'll be because you weren't changing the DAI format - hence my comment about only erroring if the format is changed.
Ok, that makes sense. We should probably do something silimar in set_hw_params() were we also currently exit silently in case of running streams.
I'll post a new set soon when we sorted out more things on the other patches.
Daniel
Re: [PATCH 3/4] pxa-ssp: don't touch ssp registers when stream is running
Hi Mark,
Quoted 11 lines · Daniel Mack
Quoted 10 lines · Mark Brown
Quoted 8 lines · Daniel Mack
Quoted 3 lines · Mark Brown
I'd expect an error to be reported here - if we needed to change the settings and can't things could go wrong. Ideally it'd check to see if the DAI format was being changed and only error if it was.
In my tests,
pxa_ssp_set_dai_fmt()was simply called twice, once for the input, once for the ouput. Hence I believed a silent exit in such a case
Quoted 6 lines
Quoted 2 lines
That'll be because you weren't changing the DAI format - hence my comment about only erroring if the format is changed.
Ok, that makes sense. We should probably do something silimar in
set_hw_params()were we also currently exit silently in case of running streams.
Could you have a look on the patch below please - does that look better?
Thanks,
Daniel
Quoted 1 line
From
b0399b4d42265313768044ab6bb5754162b70fd5Mon Sep 17 00:00:00 2001
From: Daniel Mack <[email protected]>
Date: Tue, 10 Mar 2009 16:36:58 +0100
Subject: [PATCH 2/2] pxa-ssp: don't touch registers if stream is running
In pxa_ssp_set_dai_fmt(), check whether there is anything to do at all. If there would be but the SSP port is in use already, bail out.
--- sound/soc/pxa/pxa-ssp.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)
sound/soc/pxa/pxa-ssp.c +11 -0
@@ -525,6 +525,17 @@ static int pxa_ssp_set_dai_fmt(struct snd_soc_dai *cpu_dai,u32 sscr1;u32 sspsp; +/* check if we need to change anything at all */ +if (priv->dai_fmt == fmt) +return 0 ; + +/* we can only change the settings if the port is not in use */ +if (ssp_read_reg (ssp,SSCR0 ) &SSCR0_SSE ) { +dev_err (&ssp->pdev->dev, +"can't change hardware dai format: stream is in use" ); +return -EINVAL ; + } +/* reset port settings */ sscr0 =ssp_read_reg (ssp,SSCR0 ) & (SSCR0_ECS |SSCR0_NCS |SSCR0_MOD |SSCR0_ACS );
Signature · 1 line
1.6.2
Re: [PATCH 3/4] pxa-ssp: don't touch ssp registers when stream is running
Quoted 1 line · Daniel Mack
Could you have a look on the patch below please - does that look better?
Looks good, I'll apply this.
Re: [PATCH 2/4] soc-dai: add bitfields for hardware I2S formats
In reply to Daniel MackQuoted 4 lines · Daniel Mack
This patch adds bitfields for I2S serial formats that differ from the amount of data actually sent on the line. Some codecs (namely the cs4270) require 64 sysclks being sent during each frame period, even though the number of acutal data bits might be less.
Hrm. This is normally handled via the clock divider interface - it's often much more straightforward to work with when dealing with devices with very flexible clocking, especially if there are more than two devices on the link. Have you considered handling this through that, perhaps through adding a virtual thing to configure (eg, a PXA_SSP_FRAME_CLOCKS)? Normally this would be a network mode but it seems clear that that has some issues on this hardware and an alternative solution is required.
The other downside of this approach is that it makes all existing drivers theoretically instabuggy in that they don't reject invalid configurations, although that's not such a big issue since it really only makes life easier when writing board drivers.
I guess cs4270.c ought to be enforcing this if it's added...
include/sound/soc-dai.h struct snd_pcm_substream; · line 97
Quoted 3 lines
include/sound/soc-dai.h +3
-0+#define SND_SOC_DAIFMT_FF_SAMPLE (0 << 16) +#define SND_SOC_DAIFMT_FF_I2S_16 (1 << 16) +#define SND_SOC_DAIFMT_FF_I2S_32 (2 << 16)
FF_SAMPLE should probably be FF_UNSPEC or something to preserve the existing semantics.
FF_I2S should probably be something else since something might need this for non-I2S devices - _BIT, perhaps?
Re: [PATCH 2/4] soc-dai: add bitfields for hardware I2S formats
Hi Mark,
Quoted 6 lines · Mark Brown
Quoted 4 lines · Daniel Mack
This patch adds bitfields for I2S serial formats that differ from the amount of data actually sent on the line. Some codecs (namely the cs4270) require 64 sysclks being sent during each frame period, even though the number of acutal data bits might be less.
Quoted 6 lines
Hrm. This is normally handled via the clock divider interface - it's often much more straightforward to work with when dealing with devices with very flexible clocking, especially if there are more than two devices on the link. Have you considered handling this through that, perhaps through adding a virtual thing to configure (eg, a
PXA_SSP_FRAME_CLOCKS)?
I thought about that but then I condidered it's actually the wrong place for such a setting. I see two statements the board file has to make:
1) "We need to have 64 bits per frame for the codec"
2) "The sample data you'll be finding in the FIFO is 16 bits"
It could be possible to express that in clk division rations, but it is actually a lot more straight forward to make that setting once rather then changing it over and over again.
Quoted 8 lines
Normally this would be a network mode but it
seems clear that that has some issues on this hardware and an alternative solution is required.The other downside of this approach is that it makes all existing drivers theoretically instabuggy in that they don't reject invalid configurations, although that's not such a big issue since it really only makes life easier when writing board drivers.
Well, it won't break things - the worst thing that can happen is that things are silently ignored. That bitfield was meant to be extended, wasn't it ;)
Quoted 1 line
I guess
cs4270.cought to be enforcing this if it's added...
cs4270.c would need that flag to be set or fail otherwise. Don't know if that really makes life easier for board support files that are not mainline. Want me to do that?
Quoted 6 lines
include/sound/soc-dai.h struct snd_pcm_substream; · line 97
Quoted 3 lines
include/sound/soc-dai.h +3
-0+#define SND_SOC_DAIFMT_FF_SAMPLE (0 << 16) +#define SND_SOC_DAIFMT_FF_I2S_16 (1 << 16) +#define SND_SOC_DAIFMT_FF_I2S_32 (2 << 16)
FF_SAMPLEshould probably beFF_UNSPECor something to preserve the existing semantics.
Could do that, yes.
Quoted 2 lines
FF_I2Sshould probably be something else since something might need this for non-I2S devices -_BIT, perhaps?
For non-I2S devices, we could re-use the same bit space as they will never appear in the same format word anyway, right?
Anyway, I'm totally open to any other approach, this one just seems most straight forward :)
Thanks,
Daniel
Re: [PATCH 2/4] soc-dai: add bitfields for hardware I2S formats
Quoted 8 lines · Daniel Mack
Quoted 3 lines · Mark Brown
devices on the link. Have you considered handling this through that, perhaps through adding a virtual thing to configure (eg, a
PXA_SSP_FRAME_CLOCKS)?I thought about that but then I condidered it's actually the wrong place for such a setting. I see two statements the board file has to make:
The other option would be to use the TDM mode interface to set this up since that's roughly what it is; my main concern here is that we already have two ways of doing this and I'd like to try to keep the number down for consistency.
Quoted 3 lines
It could be possible to express that in clk division rations, but it is actually a lot more straight forward to make that setting once rather then changing it over and over again.
I think it's all much of a muchness in terms of complexity whatever option is chosen.
Quoted 5 lines
Quoted 1 line
I guess
cs4270.cought to be enforcing this if it's added...
cs4270.cwould need that flag to be set or fail otherwise. Don't know if that really makes life easier for board support files that are not mainline. Want me to do that?
If this gets merged it's probably for the best (at least when it's in slave mode). Or add a hint to that effect.
Quoted 5 lines
Quoted 2 lines
FF_I2Sshould probably be something else since something might need this for non-I2S devices -_BIT, perhaps?For non-I2S devices, we could re-use the same bit space as they will never appear in the same format word anyway, right?
Yes, I'm just thinking we should be able to use the same name for this with every format.
Re: [PATCH 2/4] soc-dai: add bitfields for hardware I2S formats
Quoted 6 lines · Mark Brown
Quoted 5 lines · Mark Brown
Quoted 4 lines
devices on the link. Have you considered handling this through that, perhaps through adding a virtual thing to configure (eg, a
PXA_SSP_FRAME_CLOCKS)?
Quoted 7 lines
Quoted 2 lines
I thought about that but then I condidered it's actually the wrong place for such a setting. I see two statements the board file has to make:
The other option would be to use the TDM mode interface to set this up since that's roughly what it is; my main concern here is that we already have two ways of doing this and I'd like to try to keep the number down for consistency.
Probably a matter of taste, but IMO TDM mode is not the place either. Userspace could decide sending out 24bit samples out of a sudden (which the CPU DAI might accept) and in this case, you'd need some special logic in the board file again to set up deviders, time slots etc, right?
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
I guess
cs4270.cought to be enforcing this if it's added...
cs4270.cwould need that flag to be set or fail otherwise. Don't know if that really makes life easier for board support files that are not mainline. Want me to do that?If this gets merged it's probably for the best (at least when it's in slave mode). Or add a hint to that effect.
It a hard requirement for the master mode only. I'll add a warning for this case.
Quoted 5 lines
Quoted 2 lines
For non-I2S devices, we could re-use the same bit space as they will never appear in the same format word anyway, right?
Yes, I'm just thinking we should be able to use the same name for this with every format.
Ok, I now call them SND_SOC_DAIFMT_FF_{UNSPEC,16BIT,24BIT,32BIT}. Are you fine with these names?
Daniel
Re: [PATCH 2/4] soc-dai: add bitfields for hardware I2S formats
Quoted 11 lines · Daniel Mack
Quoted 4 lines · Mark Brown
The other option would be to use the TDM mode interface to set this up since that's roughly what it is; my main concern here is that we already have two ways of doing this and I'd like to try to keep the number down for consistency.
Probably a matter of taste, but IMO TDM mode is not the place either. Userspace could decide sending out 24bit samples out of a sudden (which the CPU DAI might accept) and in this case, you'd need some special logic in the board file again to set up deviders, time slots etc, right?
That's why the clocking interface is generally used here - it's more orthogonal.
Quoted 5 lines
Quoted 2 lines
Yes, I'm just thinking we should be able to use the same name for this with every format.
Ok, I now call them SND_SOC_DAIFMT_FF_{UNSPEC,16BIT,24BIT,32BIT}. Are you fine with these names?
Yes, though I'd still prefer to use an existing interface rather than add a new one.
Re: [PATCH 2/4] soc-dai: add bitfields for hardware I2S formats
Quoted 5 lines · Mark Brown
Quoted 4 lines
Quoted 4 lines
The other option would be to use the TDM mode interface to set this up since that's roughly what it is; my main concern here is that we already have two ways of doing this and I'd like to try to keep the number down for consistency.
Quoted 7 lines
Quoted 4 lines
Probably a matter of taste, but IMO TDM mode is not the place either. Userspace could decide sending out 24bit samples out of a sudden (which the CPU DAI might accept) and in this case, you'd need some special logic in the board file again to set up deviders, time slots etc, right?
That's why the clocking interface is generally used here - it's more orthogonal.
Hmm, how would you express 24 sample bits with 32 clocks per channel? I might not have gotten your point yet - could you provide an example?
Daniel
Re: [PATCH 2/4] soc-dai: add bitfields for hardware I2S formats
Quoted 7 lines · Daniel Mack
Quoted 2 lines · Mark Brown
That's why the clocking interface is generally used here - it's more orthogonal.
Hmm, how would you express 24 sample bits with 32 clocks per channel? I might not have gotten your point yet - could you provide an example?
You could add a "clock" which is the number of clocks per channel. It doesn't need to correspond to a literal clock in the hardware, it'd just provide a way of setting this number.
Re: [PATCH 2/4] soc-dai: add bitfields for hardware I2S formats
In reply to Daniel MackQuoted 11 lines · Daniel Mack
Quoted 10 lines · Mark Brown
Quoted 9 lines
Quoted 4 lines
The other option would be to use the TDM mode interface to set this up since that's roughly what it is; my main concern here is that we already have two ways of doing this and I'd like to try to keep the number down for consistency.
Probably a matter of taste, but IMO TDM mode is not the place either. Userspace could decide sending out 24bit samples out of a sudden (which the CPU DAI might accept) and in this case, you'd need some special logic in the board file again to set up deviders, time slots etc, right?
Quoted 5 lines
Quoted 2 lines
That's why the clocking interface is generally used here - it's more orthogonal.
Hmm, how would you express 24 sample bits with 32 clocks per channel? I might not have gotten your point yet - could you provide an example?
I'm still a bit confused by the alsa formats and how they interact with the SSP formats.
Do I understand correctly that S24_3LE (24-bit packed in 3 bytes) can't be supported due to limitations in (at least PXA27x's) DMA engine?
So the remaining 24-bit formats are S24_LE and S32_LE anyway, both of which are 24-bit packed in 32 bits (either LSB or MSB aligned).
regards
Philipp
Mark Brown
AppliedRe: [PATCH 1/4] pxa-ssp: fix name of register bit
In reply to Daniel MackQuoted 2 lines · Daniel Mack
A bit in PXA's SSCR0 register was erroneously named ADC but its name is in fact ADC (audio clock select).
Applied, but I think I spot a typo in the changelog (which I've fixed). :)