Skip to contentSkip to conversation

ASoC: simplify the SSP DMA parameters settings by run-time generation

RFC PATCH In review Eric Miao 3 participants 13 messages Apr 23, 2009

Subsystems (3)
lore
Share & tools
lore

Eric Miao

author
#0 lore raw

RFC PATCH 5/5 ASoC: simplify the SSP DMA parameters settings by run-time generation

The SSP DMA parameters can actually be easily generated at run-time since they are almost similar except for the FIFO width and direction. Another benefit is the re-use of information from 'struct ssp_device', like SSDR physical FIFO address and DRCMR register index for both directions.

---
 sound/soc/pxa/pxa-ssp.c |  206 ++++++++++-------------------------------------
 1 files changed, 43 insertions(+), 163 deletions(-)
sound/soc/pxa/pxa-ssp.c +25 -150
index 2ce4fb6..fb7235b 100644
@@ -50,139 +50,6 @@ struct ssp_priv {
 #endif
 };
 
-#define PXA2xx_SSP1_BASE	0x41000000
-#define PXA27x_SSP2_BASE	0x41700000
-#define PXA27x_SSP3_BASE	0x41900000
-#define PXA3xx_SSP4_BASE	0x41a00000
-
-static struct pxa2xx_pcm_dma_params pxa_ssp1_pcm_mono_out = {
-	.name			= "SSP1 PCM Mono out",
-	.dev_addr		= PXA2xx_SSP1_BASE + SSDR,
-	.drcmr			= &DRCMR(14),
-	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
-				  DCMD_BURST16 | DCMD_WIDTH2,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp1_pcm_mono_in = {
-	.name			= "SSP1 PCM Mono in",
-	.dev_addr		= PXA2xx_SSP1_BASE + SSDR,
-	.drcmr			= &DRCMR(13),
-	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
-				  DCMD_BURST16 | DCMD_WIDTH2,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp1_pcm_stereo_out = {
-	.name			= "SSP1 PCM Stereo out",
-	.dev_addr		= PXA2xx_SSP1_BASE + SSDR,
-	.drcmr			= &DRCMR(14),
-	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
-				  DCMD_BURST16 | DCMD_WIDTH4,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp1_pcm_stereo_in = {
-	.name			= "SSP1 PCM Stereo in",
-	.dev_addr		= PXA2xx_SSP1_BASE + SSDR,
-	.drcmr			= &DRCMR(13),
-	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
-				  DCMD_BURST16 | DCMD_WIDTH4,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp2_pcm_mono_out = {
-	.name			= "SSP2 PCM Mono out",
-	.dev_addr		= PXA27x_SSP2_BASE + SSDR,
-	.drcmr			= &DRCMR(16),
-	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
-				  DCMD_BURST16 | DCMD_WIDTH2,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp2_pcm_mono_in = {
-	.name			= "SSP2 PCM Mono in",
-	.dev_addr		= PXA27x_SSP2_BASE + SSDR,
-	.drcmr			= &DRCMR(15),
-	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
-				  DCMD_BURST16 | DCMD_WIDTH2,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp2_pcm_stereo_out = {
-	.name			= "SSP2 PCM Stereo out",
-	.dev_addr		= PXA27x_SSP2_BASE + SSDR,
-	.drcmr			= &DRCMR(16),
-	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
-				  DCMD_BURST16 | DCMD_WIDTH4,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp2_pcm_stereo_in = {
-	.name			= "SSP2 PCM Stereo in",
-	.dev_addr		= PXA27x_SSP2_BASE + SSDR,
-	.drcmr			= &DRCMR(15),
-	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
-				  DCMD_BURST16 | DCMD_WIDTH4,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp3_pcm_mono_out = {
-	.name			= "SSP3 PCM Mono out",
-	.dev_addr		= PXA27x_SSP3_BASE + SSDR,
-	.drcmr			= &DRCMR(67),
-	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
-				  DCMD_BURST16 | DCMD_WIDTH2,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp3_pcm_mono_in = {
-	.name			= "SSP3 PCM Mono in",
-	.dev_addr		= PXA27x_SSP3_BASE + SSDR,
-	.drcmr			= &DRCMR(66),
-	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
-				  DCMD_BURST16 | DCMD_WIDTH2,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp3_pcm_stereo_out = {
-	.name			= "SSP3 PCM Stereo out",
-	.dev_addr		= PXA27x_SSP3_BASE + SSDR,
-	.drcmr			= &DRCMR(67),
-	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
-				  DCMD_BURST16 | DCMD_WIDTH4,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp3_pcm_stereo_in = {
-	.name			= "SSP3 PCM Stereo in",
-	.dev_addr		= PXA27x_SSP3_BASE + SSDR,
-	.drcmr			= &DRCMR(66),
-	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
-				  DCMD_BURST16 | DCMD_WIDTH4,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp4_pcm_mono_out = {
-	.name			= "SSP4 PCM Mono out",
-	.dev_addr		= PXA3xx_SSP4_BASE + SSDR,
-	.drcmr			= &DRCMR(67),
-	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
-				  DCMD_BURST16 | DCMD_WIDTH2,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp4_pcm_mono_in = {
-	.name			= "SSP4 PCM Mono in",
-	.dev_addr		= PXA3xx_SSP4_BASE + SSDR,
-	.drcmr			= &DRCMR(66),
-	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
-				  DCMD_BURST16 | DCMD_WIDTH2,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp4_pcm_stereo_out = {
-	.name			= "SSP4 PCM Stereo out",
-	.dev_addr		= PXA3xx_SSP4_BASE + SSDR,
-	.drcmr			= &DRCMR(67),
-	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
-				  DCMD_BURST16 | DCMD_WIDTH4,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp4_pcm_stereo_in = {
-	.name			= "SSP4 PCM Stereo in",
-	.dev_addr		= PXA3xx_SSP4_BASE + SSDR,
-	.drcmr			= &DRCMR(66),
-	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
-				  DCMD_BURST16 | DCMD_WIDTH4,
-};
-
 static void dump_registers(struct ssp_device *ssp)
 {
 	dev_dbg(&ssp->pdev->dev, "SSCR0 0x%08x SSCR1 0x%08x SSTO 0x%08x\n",
@@ -194,25 +61,33 @@ static void dump_registers(struct ssp_device *ssp)
 		 ssp_read_reg(ssp, SSACD));
 }
 
-static struct pxa2xx_pcm_dma_params *ssp_dma_params[4][4] = {
-	{
-		&pxa_ssp1_pcm_mono_out, &pxa_ssp1_pcm_mono_in,
-		&pxa_ssp1_pcm_stereo_out, &pxa_ssp1_pcm_stereo_in,
-	},
-	{
-		&pxa_ssp2_pcm_mono_out, &pxa_ssp2_pcm_mono_in,
-		&pxa_ssp2_pcm_stereo_out, &pxa_ssp2_pcm_stereo_in,
-	},
-	{
-		&pxa_ssp3_pcm_mono_out, &pxa_ssp3_pcm_mono_in,
-		&pxa_ssp3_pcm_stereo_out, &pxa_ssp3_pcm_stereo_in,
-	},
-	{
-		&pxa_ssp4_pcm_mono_out, &pxa_ssp4_pcm_mono_in,
-		&pxa_ssp4_pcm_stereo_out, &pxa_ssp4_pcm_stereo_in,
-	},
+struct pxa2xx_pcm_dma_data {
+	struct pxa2xx_pcm_dma_params params;
+	char name[20];
 };
 
+static struct pxa2xx_pcm_dma_params *
+ssp_get_dma_params(struct ssp_device *ssp, int stereo, int out)
+{
+	struct pxa2xx_pcm_dma_data *dma;
+
+	dma = kzalloc(sizeof(struct pxa2xx_pcm_dma_data), GFP_KERNEL);
+	if (dma == NULL)
+		return NULL;
+
+	snprintf(dma->name, 20, "SSP%d PCM %s %s", ssp->port_id,
+			stereo ? "Stereo" : "Mono", out ? "out" : "in");
+
+	dma->params.name = dma->name;
+	dma->params.drcmr = &DRCMR(out ? ssp->drcmr_tx : ssp->drcmr_rx);
+	dma->params.dcmd = (out ? (DCMD_INCSRCADDR | DCMD_FLOWTRG) :
+				  (DCMD_INCTRGADDR | DCMD_FLOWSRC)) |
+			(stereo ? DCMD_WIDTH4 : DCMD_WIDTH2) | DCMD_BURST16;
+	dma->params.dev_addr = ssp->phys_base + SSDR;
+
+	return &dma->params;
+}
+
 static int pxa_ssp_startup(struct snd_pcm_substream *substream,
 			   struct snd_soc_dai *dai)
 {
@@ -225,6 +100,11 @@ static int pxa_ssp_startup(struct

snd_pcm_substream *substream,
clk_enable(priv->ssp->clk);
ssp_disable(priv->ssp);
}
+
+ if (cpu_dai->dma_data) {
+ kfree(cpu_dai->dma_data);
+ cpu_dai->dma_data = NULL;
+ }
return ret;
}

@@ -239,6 +119,11 @@ static void pxa_ssp_shutdown(struct snd_pcm_substream *substream,
ssp_disable(priv->ssp); clk_disable(priv->ssp->clk);
}
+
+ if (cpu_dai->dma_data) {
+ kfree(cpu_dai->dma_data);
+ cpu_dai->dma_data = NULL;
+ }
}

#ifdef CONFIG_PM
@@ -611,25 +496,20 @@ static int pxa_ssp_hw_params(struct snd_pcm_substream *substream,
struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; struct ssp_priv *priv = cpu_dai->private_data;
struct ssp_device *ssp = priv->ssp;
- int dma = 0, chn = params_channels(params);
+ int chn = params_channels(params);
u32 sscr0;
u32 sspsp;
int width = snd_pcm_format_physical_width(params_format(params)); int ttsa = ssp_read_reg(ssp, SSTSA) & 0xf;

- /* select correct DMA params */
- if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK)
- dma = 1; /* capture DMA offset is 1,3 */
- /* Network mode with one active slot (ttsa == 1) can be used
- * to force 16-bit frame width on the wire (for S16_LE), even
- * with two channels. Use 16-bit DMA transfers for this case.
- */
- if (((chn == 2) && (ttsa != 1)) || (width == 32))
- dma += 2; /* 32-bit DMA offset is 2, 16-bit is 0 */
-
- cpu_dai->dma_data = ssp_dma_params[cpu_dai->id][dma];
+ printk("%s\n", __func__);
+ /* generate correct DMA params */
+ if (cpu_dai->dma_data)
+ kfree(cpu_dai->dma_data);

- dev_dbg(&ssp->pdev->dev, "pxa_ssp_hw_params: dma %d\n", dma);
+ cpu_dai->dma_data = ssp_get_dma_params(ssp,
+ ((chn == 2) && (ttsa != 1)) || (width == 32),
+ substream->stream == SNDRV_PCM_STREAM_PLAYBACK);

/* we can only change the settings if the port is not in use */ if (ssp_read_reg(ssp, SSCR0) & SSCR0_SSE)

Signature · 6 lines
1.6.0.4

-------------------------------------------------------------------
List admin: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm-kernel
FAQ:        http://www.arm.linux.org.uk/mailinglists/faq.php
Etiquette:  http://www.arm.linux.org.uk/mailinglists/etiquette.php
#1 lore raw
Quoted 6 lines · Eric Miao

The SSP DMA parameters can actually be easily generated at run-time since they are almost similar except for the FIFO width and direction. Another benefit is the re-use of information from 'struct ssp_device', like SSDR physical FIFO address and DRCMR register index for both directions.

This looks like a win - is there any reason not to merge it without waiting for the rest of the series (I've not tested it yet)?

author
#2 lore raw
Quoted 11 lines · Mark Brown
Quoted 6 lines · Eric Miao

The SSP DMA parameters can actually be easily generated at run-time since they are almost similar except for the FIFO width and direction. Another benefit is the re-use of information from 'struct ssp_device', like SSDR physical FIFO address and DRCMR register index for both directions.

This looks like a win - is there any reason not to merge it without waiting for the rest of the series (I've not tested it yet)?

Should be no. I'll get this regenerated to be aligned with the current code. Moment.

Signature · 2 lines
Cheers
- eric
#3 lore raw
In reply to Eric Miao
Quoted 4 lines · Eric Miao

The SSP DMA parameters can actually be easily generated at run-time since they are almost similar except for the FIFO width and direction. Another benefit is the re-use of information from 'struct ssp_device', like SSDR physical FIFO address and DRCMR register index for both directions.

Yes, that does look a lot better.

Quoted 176 lines

---
 sound/soc/pxa/pxa-ssp.c |  206 ++++++++++-------------------------------------

 1 files changed, 43 insertions(+), 163 deletions(-)
sound/soc/pxa/pxa-ssp.c +4 -150
index 2ce4fb6..fb7235b 100644
@@ -50,139 +50,6 @@ struct ssp_priv {
  #endif
  };
 
-#define PXA2xx_SSP1_BASE       0x41000000
-#define PXA27x_SSP2_BASE       0x41700000
-#define PXA27x_SSP3_BASE       0x41900000
-#define PXA3xx_SSP4_BASE       0x41a00000
-
-static struct pxa2xx_pcm_dma_params pxa_ssp1_pcm_mono_out = {
-       .name                   = "SSP1 PCM Mono out",
-       .dev_addr               = PXA2xx_SSP1_BASE + SSDR,
-       .drcmr                  = &DRCMR(14),
-       .dcmd                   = DCMD_INCSRCADDR | DCMD_FLOWTRG |
-                                 DCMD_BURST16 | DCMD_WIDTH2,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp1_pcm_mono_in = {
-       .name                   = "SSP1 PCM Mono in",
-       .dev_addr               = PXA2xx_SSP1_BASE + SSDR,
-       .drcmr                  = &DRCMR(13),
-       .dcmd                   = DCMD_INCTRGADDR | DCMD_FLOWSRC |
-                                 DCMD_BURST16 | DCMD_WIDTH2,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp1_pcm_stereo_out = {
-       .name                   = "SSP1 PCM Stereo out",
-       .dev_addr               = PXA2xx_SSP1_BASE + SSDR,
-       .drcmr                  = &DRCMR(14),
-       .dcmd                   = DCMD_INCSRCADDR | DCMD_FLOWTRG |
-                                 DCMD_BURST16 | DCMD_WIDTH4,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp1_pcm_stereo_in = {
-       .name                   = "SSP1 PCM Stereo in",
-       .dev_addr               = PXA2xx_SSP1_BASE + SSDR,
-       .drcmr                  = &DRCMR(13),
-       .dcmd                   = DCMD_INCTRGADDR | DCMD_FLOWSRC |
-                                 DCMD_BURST16 | DCMD_WIDTH4,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp2_pcm_mono_out = {
-       .name                   = "SSP2 PCM Mono out",
-       .dev_addr               = PXA27x_SSP2_BASE + SSDR,
-       .drcmr                  = &DRCMR(16),
-       .dcmd                   = DCMD_INCSRCADDR | DCMD_FLOWTRG |
-                                 DCMD_BURST16 | DCMD_WIDTH2,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp2_pcm_mono_in = {
-       .name                   = "SSP2 PCM Mono in",
-       .dev_addr               = PXA27x_SSP2_BASE + SSDR,
-       .drcmr                  = &DRCMR(15),
-       .dcmd                   = DCMD_INCTRGADDR | DCMD_FLOWSRC |
-                                 DCMD_BURST16 | DCMD_WIDTH2,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp2_pcm_stereo_out = {
-       .name                   = "SSP2 PCM Stereo out",
-       .dev_addr               = PXA27x_SSP2_BASE + SSDR,
-       .drcmr                  = &DRCMR(16),
-       .dcmd                   = DCMD_INCSRCADDR | DCMD_FLOWTRG |
-                                 DCMD_BURST16 | DCMD_WIDTH4,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp2_pcm_stereo_in = {
-       .name                   = "SSP2 PCM Stereo in",
-       .dev_addr               = PXA27x_SSP2_BASE + SSDR,
-       .drcmr                  = &DRCMR(15),
-       .dcmd                   = DCMD_INCTRGADDR | DCMD_FLOWSRC |
-                                 DCMD_BURST16 | DCMD_WIDTH4,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp3_pcm_mono_out = {
-       .name                   = "SSP3 PCM Mono out",
-       .dev_addr               = PXA27x_SSP3_BASE + SSDR,
-       .drcmr                  = &DRCMR(67),
-       .dcmd                   = DCMD_INCSRCADDR | DCMD_FLOWTRG |
-                                 DCMD_BURST16 | DCMD_WIDTH2,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp3_pcm_mono_in = {
-       .name                   = "SSP3 PCM Mono in",
-       .dev_addr               = PXA27x_SSP3_BASE + SSDR,
-       .drcmr                  = &DRCMR(66),
-       .dcmd                   = DCMD_INCTRGADDR | DCMD_FLOWSRC |
-                                 DCMD_BURST16 | DCMD_WIDTH2,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp3_pcm_stereo_out = {
-       .name                   = "SSP3 PCM Stereo out",
-       .dev_addr               = PXA27x_SSP3_BASE + SSDR,
-       .drcmr                  = &DRCMR(67),
-       .dcmd                   = DCMD_INCSRCADDR | DCMD_FLOWTRG |
-                                 DCMD_BURST16 | DCMD_WIDTH4,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp3_pcm_stereo_in = {
-       .name                   = "SSP3 PCM Stereo in",
-       .dev_addr               = PXA27x_SSP3_BASE + SSDR,
-       .drcmr                  = &DRCMR(66),
-       .dcmd                   = DCMD_INCTRGADDR | DCMD_FLOWSRC |
-                                 DCMD_BURST16 | DCMD_WIDTH4,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp4_pcm_mono_out = {
-       .name                   = "SSP4 PCM Mono out",
-       .dev_addr               = PXA3xx_SSP4_BASE + SSDR,
-       .drcmr                  = &DRCMR(67),
-       .dcmd                   = DCMD_INCSRCADDR | DCMD_FLOWTRG |
-                                 DCMD_BURST16 | DCMD_WIDTH2,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp4_pcm_mono_in = {
-       .name                   = "SSP4 PCM Mono in",
-       .dev_addr               = PXA3xx_SSP4_BASE + SSDR,
-       .drcmr                  = &DRCMR(66),
-       .dcmd                   = DCMD_INCTRGADDR | DCMD_FLOWSRC |
-                                 DCMD_BURST16 | DCMD_WIDTH2,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp4_pcm_stereo_out = {
-       .name                   = "SSP4 PCM Stereo out",
-       .dev_addr               = PXA3xx_SSP4_BASE + SSDR,
-       .drcmr                  = &DRCMR(67),
-       .dcmd                   = DCMD_INCSRCADDR | DCMD_FLOWTRG |
-                                 DCMD_BURST16 | DCMD_WIDTH4,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp4_pcm_stereo_in = {
-       .name                   = "SSP4 PCM Stereo in",
-       .dev_addr               = PXA3xx_SSP4_BASE + SSDR,
-       .drcmr                  = &DRCMR(66),
-       .dcmd                   = DCMD_INCTRGADDR | DCMD_FLOWSRC |
-                                 DCMD_BURST16 | DCMD_WIDTH4,
-};
-
  static void dump_registers(struct ssp_device *ssp)
  {
        dev_dbg(&ssp->pdev->dev, "SSCR0 0x%08x SSCR1 0x%08x SSTO 0x%08x\n",
@@ -194,25 +61,33 @@ static void dump_registers(struct ssp_device *ssp)
                 ssp_read_reg(ssp, SSACD));
  }
 
-static struct pxa2xx_pcm_dma_params *ssp_dma_params[4][4] = {
-       {
-               &pxa_ssp1_pcm_mono_out, &pxa_ssp1_pcm_mono_in,
-               &pxa_ssp1_pcm_stereo_out, &pxa_ssp1_pcm_stereo_in,
-       },
-       {
-               &pxa_ssp2_pcm_mono_out, &pxa_ssp2_pcm_mono_in,
-               &pxa_ssp2_pcm_stereo_out, &pxa_ssp2_pcm_stereo_in,
-       },
-       {
-               &pxa_ssp3_pcm_mono_out, &pxa_ssp3_pcm_mono_in,
-               &pxa_ssp3_pcm_stereo_out, &pxa_ssp3_pcm_stereo_in,
-       },
-       {
-               &pxa_ssp4_pcm_mono_out, &pxa_ssp4_pcm_mono_in,
-               &pxa_ssp4_pcm_stereo_out, &pxa_ssp4_pcm_stereo_in,
-       },
+struct pxa2xx_pcm_dma_data {
+       struct pxa2xx_pcm_dma_params params;
+       char name[20];
  };
 
+static struct pxa2xx_pcm_dma_params *

sound/soc/pxa/pxa-ssp.c static void dump_registers(struct ssp_device *ssp) · line 79

Quoted 10 lines
sound/soc/pxa/pxa-ssp.c +10 -0
+ssp_get_dma_params(struct ssp_device *ssp, int stereo, int out)
+{
+       struct pxa2xx_pcm_dma_data *dma;
+
+       dma = kzalloc(sizeof(struct pxa2xx_pcm_dma_data), GFP_KERNEL);
+       if (dma == NULL)
+               return NULL;
+
+       snprintf(dma->name, 20, "SSP%d PCM %s %s", ssp->port_id,
+                       stereo ? "Stereo" : "Mono", out ? "out" : "in");

Should we change Stereo/Mono to 32-bit/16-bit here?

Quoted 49 lines
sound/soc/pxa/pxa-ssp.c +21 -0
+
+       dma->params.name = dma->name;
+       dma->params.drcmr = &DRCMR(out ? ssp->drcmr_tx : ssp->drcmr_rx);
+       dma->params.dcmd = (out ? (DCMD_INCSRCADDR | DCMD_FLOWTRG) :
+                                 (DCMD_INCTRGADDR | DCMD_FLOWSRC)) |
+                       (stereo ? DCMD_WIDTH4 : DCMD_WIDTH2) | DCMD_BURST16;
+       dma->params.dev_addr = ssp->phys_base + SSDR;
+
+       return &dma->params;
+}
+
  static int pxa_ssp_startup(struct snd_pcm_substream *substream,
                           struct snd_soc_dai *dai)
  {
@@ -225,6 +100,11 @@ static int pxa_ssp_startup(struct
 snd_pcm_substream *substream,
                clk_enable(priv->ssp->clk);
                ssp_disable(priv->ssp);
        }
+
+       if (cpu_dai->dma_data) {
+               kfree(cpu_dai->dma_data);
+               cpu_dai->dma_data = NULL;
+       }
        return ret;
  }
@@ -239,6 +119,11 @@ static void pxa_ssp_shutdown(struct
 snd_pcm_substream *substream,
                ssp_disable(priv->ssp);
                clk_disable(priv->ssp->clk);
        }
+
+       if (cpu_dai->dma_data) {
+               kfree(cpu_dai->dma_data);
+               cpu_dai->dma_data = NULL;
+       }
  }
 

 #ifdef CONFIG_PM

sound/soc/pxa/pxa-ssp.c +1 -1
@@ -611,25 +496,20 @@ static int pxa_ssp_hw_params(struct
 snd_pcm_substream *substream,
        struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
        struct ssp_priv *priv = cpu_dai->private_data;
        struct ssp_device *ssp = priv->ssp;
-       int dma = 0, chn = params_channels(params);
+       int chn = params_channels(params);
        u32 sscr0;
        u32 sspsp;

sound/soc/pxa/pxa-ssp.c static int pxa_ssp_hw_params(struct · line 627

Quoted 10 lines
sound/soc/pxa/pxa-ssp.c +0 -7
        int width = snd_pcm_format_physical_width(params_format(params));
        int ttsa = ssp_read_reg(ssp, SSTSA) & 0xf;
 
-       /* select correct DMA params */
-       if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK)
-               dma = 1; /* capture DMA offset is 1,3 */
-       /* Network mode with one active slot (ttsa == 1) can be used
-        * to force 16-bit frame width on the wire (for S16_LE), even
-        * with two channels. Use 16-bit DMA transfers for this case.
-        */

Do you think the ttsa bit below is obvious enough to warrant removal of the above comment?

Quoted 15 lines
sound/soc/pxa/pxa-ssp.c +7 -5
-       if (((chn == 2) && (ttsa != 1)) || (width == 32))
-               dma += 2; /* 32-bit DMA offset is 2, 16-bit is 0 */
-
-       cpu_dai->dma_data = ssp_dma_params[cpu_dai->id][dma];
+       printk("%s\n", __func__);
+       /* generate correct DMA params */
+       if (cpu_dai->dma_data)
+               kfree(cpu_dai->dma_data);
 
-       dev_dbg(&ssp->pdev->dev, "pxa_ssp_hw_params: dma %d\n", dma);
+       cpu_dai->dma_data = ssp_get_dma_params(ssp,
+                       ((chn == 2) && (ttsa != 1)) || (width == 32),
+                       substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
 
        /* we can only change the settings if the port is not in use */
Quoted 4 lines

       if (ssp_read_reg(ssp, SSCR0) & SSCR0_SSE)
--
1.6.0.4

regards
Philipp

author
#4 lore raw
Quoted 5 lines
Quoted 2 lines

+       snprintf(dma->name, 20, "SSP%d PCM %s %s", ssp->port_id,
+                       stereo ? "Stereo" : "Mono", out ? "out" : "in");

Should we change Stereo/Mono to 32-bit/16-bit here?

Depends on Mark, the dma->name and the comments below doesn't actually match very well ...

Quoted 52 lines
Quoted 52 lines
sound/soc/pxa/pxa-ssp.c +11 -0
+
+       dma->params.name = dma->name;
+       dma->params.drcmr = &DRCMR(out ? ssp->drcmr_tx : ssp->drcmr_rx);
+       dma->params.dcmd = (out ? (DCMD_INCSRCADDR | DCMD_FLOWTRG) :
+                                 (DCMD_INCTRGADDR | DCMD_FLOWSRC)) |
+                       (stereo ? DCMD_WIDTH4 : DCMD_WIDTH2) | DCMD_BURST16;
+       dma->params.dev_addr = ssp->phys_base + SSDR;
+
+       return &dma->params;
+}
+

 static int pxa_ssp_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
 {

(quoted diff) +10 -0
@@ -225,6 +100,11 @@ static int pxa_ssp_startup(struct
 snd_pcm_substream *substream,
                clk_enable(priv->ssp->clk);
                ssp_disable(priv->ssp);
        }
+
+       if (cpu_dai->dma_data) {
+               kfree(cpu_dai->dma_data);
+               cpu_dai->dma_data = NULL;
+       }
        return ret;
  }
@@ -239,6 +119,11 @@ static void pxa_ssp_shutdown(struct
 snd_pcm_substream *substream,
                ssp_disable(priv->ssp);
                clk_disable(priv->ssp->clk);
        }
+
+       if (cpu_dai->dma_data) {
+               kfree(cpu_dai->dma_data);
+               cpu_dai->dma_data = NULL;
+       }
  }
 

 #ifdef CONFIG_PM

(quoted diff) +1 -1
@@ -611,25 +496,20 @@ static int pxa_ssp_hw_params(struct
 snd_pcm_substream *substream,
        struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
        struct ssp_priv *priv = cpu_dai->private_data;
        struct ssp_device *ssp = priv->ssp;
-       int dma = 0, chn = params_channels(params);
+       int chn = params_channels(params);
        u32 sscr0;
        u32 sspsp;
        int width = snd_pcm_format_physical_width(params_format(params));
        int ttsa = ssp_read_reg(ssp, SSTSA) & 0xf;
 
Quoted 10 lines

Review static int pxa_ssp_hw_params(struct · line 627

Quoted 7 lines
(quoted diff) +0 -7
-       /* select correct DMA params */
-       if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK)
-               dma = 1; /* capture DMA offset is 1,3 */
-       /* Network mode with one active slot (ttsa == 1) can be used
-        * to force 16-bit frame width on the wire (for S16_LE), even
-        * with two channels. Use 16-bit DMA transfers for this case.
-        */

Do you think the ttsa bit below is obvious enough to warrant removal of the above comment?

Yes, sorry. This is a nice comment, I removed it by accident.

Quoted 24 lines
Quoted 16 lines
(quoted diff) +7 -5
-       if (((chn == 2) && (ttsa != 1)) || (width == 32))
-               dma += 2; /* 32-bit DMA offset is 2, 16-bit is 0 */
-
-       cpu_dai->dma_data = ssp_dma_params[cpu_dai->id][dma];
+       printk("%s\n", __func__);
+       /* generate correct DMA params */
+       if (cpu_dai->dma_data)
+               kfree(cpu_dai->dma_data);
 
-       dev_dbg(&ssp->pdev->dev, "pxa_ssp_hw_params: dma %d\n", dma);
+       cpu_dai->dma_data = ssp_get_dma_params(ssp,
+                       ((chn == 2) && (ttsa != 1)) || (width == 32),
+                       substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
 
        /* we can only change the settings if the port is not in use */
Quoted 4 lines

       if (ssp_read_reg(ssp, SSCR0) & SSCR0_SSE)
--
1.6.0.4

regards
Philipp

Signature · 6 lines
Cheers
- eric
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
author Reviewed-by pHilipp Zabel Reviewed-by pHilipp Zabel
#5 lore raw

Patch updated, rebased on broonie/sound-2.6/for-2.6.31:

Quoted 1 line

From 655bad8e72e3aa13f0ddf910d5f4b9f066ec9cc3 Mon Sep 17 00:00:00 2001

From: Eric Miao <[email protected]>
Date: Thu, 23 Apr 2009 10:58:34 +0800
Subject: [PATCH] ASoC: simplify the SSP DMA parameters settings by run-time generation

The SSP DMA parameters can actually be easily generated at run-time since they are almost similar except for the FIFO width and direction. Another benefit is the re-use of information from 'struct ssp_device', like SSDR physical FIFO address and DRCMR register index for both directions.

---
 sound/soc/pxa/pxa-ssp.c |  203 ++++++++++-------------------------------------
 1 files changed, 43 insertions(+), 160 deletions(-)
sound/soc/pxa/pxa-ssp.c +25 -150
index b9b61dd..fb8cacc 100644
@@ -50,139 +50,6 @@ struct ssp_priv {
 #endif
 };
 
-#define PXA2xx_SSP1_BASE	0x41000000
-#define PXA27x_SSP2_BASE	0x41700000
-#define PXA27x_SSP3_BASE	0x41900000
-#define PXA3xx_SSP4_BASE	0x41a00000
-
-static struct pxa2xx_pcm_dma_params pxa_ssp1_pcm_mono_out = {
-	.name			= "SSP1 PCM Mono out",
-	.dev_addr		= PXA2xx_SSP1_BASE + SSDR,
-	.drcmr			= &DRCMR(14),
-	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
-				  DCMD_BURST16 | DCMD_WIDTH2,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp1_pcm_mono_in = {
-	.name			= "SSP1 PCM Mono in",
-	.dev_addr		= PXA2xx_SSP1_BASE + SSDR,
-	.drcmr			= &DRCMR(13),
-	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
-				  DCMD_BURST16 | DCMD_WIDTH2,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp1_pcm_stereo_out = {
-	.name			= "SSP1 PCM Stereo out",
-	.dev_addr		= PXA2xx_SSP1_BASE + SSDR,
-	.drcmr			= &DRCMR(14),
-	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
-				  DCMD_BURST16 | DCMD_WIDTH4,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp1_pcm_stereo_in = {
-	.name			= "SSP1 PCM Stereo in",
-	.dev_addr		= PXA2xx_SSP1_BASE + SSDR,
-	.drcmr			= &DRCMR(13),
-	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
-				  DCMD_BURST16 | DCMD_WIDTH4,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp2_pcm_mono_out = {
-	.name			= "SSP2 PCM Mono out",
-	.dev_addr		= PXA27x_SSP2_BASE + SSDR,
-	.drcmr			= &DRCMR(16),
-	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
-				  DCMD_BURST16 | DCMD_WIDTH2,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp2_pcm_mono_in = {
-	.name			= "SSP2 PCM Mono in",
-	.dev_addr		= PXA27x_SSP2_BASE + SSDR,
-	.drcmr			= &DRCMR(15),
-	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
-				  DCMD_BURST16 | DCMD_WIDTH2,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp2_pcm_stereo_out = {
-	.name			= "SSP2 PCM Stereo out",
-	.dev_addr		= PXA27x_SSP2_BASE + SSDR,
-	.drcmr			= &DRCMR(16),
-	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
-				  DCMD_BURST16 | DCMD_WIDTH4,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp2_pcm_stereo_in = {
-	.name			= "SSP2 PCM Stereo in",
-	.dev_addr		= PXA27x_SSP2_BASE + SSDR,
-	.drcmr			= &DRCMR(15),
-	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
-				  DCMD_BURST16 | DCMD_WIDTH4,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp3_pcm_mono_out = {
-	.name			= "SSP3 PCM Mono out",
-	.dev_addr		= PXA27x_SSP3_BASE + SSDR,
-	.drcmr			= &DRCMR(67),
-	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
-				  DCMD_BURST16 | DCMD_WIDTH2,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp3_pcm_mono_in = {
-	.name			= "SSP3 PCM Mono in",
-	.dev_addr		= PXA27x_SSP3_BASE + SSDR,
-	.drcmr			= &DRCMR(66),
-	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
-				  DCMD_BURST16 | DCMD_WIDTH2,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp3_pcm_stereo_out = {
-	.name			= "SSP3 PCM Stereo out",
-	.dev_addr		= PXA27x_SSP3_BASE + SSDR,
-	.drcmr			= &DRCMR(67),
-	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
-				  DCMD_BURST16 | DCMD_WIDTH4,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp3_pcm_stereo_in = {
-	.name			= "SSP3 PCM Stereo in",
-	.dev_addr		= PXA27x_SSP3_BASE + SSDR,
-	.drcmr			= &DRCMR(66),
-	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
-				  DCMD_BURST16 | DCMD_WIDTH4,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp4_pcm_mono_out = {
-	.name			= "SSP4 PCM Mono out",
-	.dev_addr		= PXA3xx_SSP4_BASE + SSDR,
-	.drcmr			= &DRCMR(67),
-	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
-				  DCMD_BURST16 | DCMD_WIDTH2,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp4_pcm_mono_in = {
-	.name			= "SSP4 PCM Mono in",
-	.dev_addr		= PXA3xx_SSP4_BASE + SSDR,
-	.drcmr			= &DRCMR(66),
-	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
-				  DCMD_BURST16 | DCMD_WIDTH2,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp4_pcm_stereo_out = {
-	.name			= "SSP4 PCM Stereo out",
-	.dev_addr		= PXA3xx_SSP4_BASE + SSDR,
-	.drcmr			= &DRCMR(67),
-	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
-				  DCMD_BURST16 | DCMD_WIDTH4,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp4_pcm_stereo_in = {
-	.name			= "SSP4 PCM Stereo in",
-	.dev_addr		= PXA3xx_SSP4_BASE + SSDR,
-	.drcmr			= &DRCMR(66),
-	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
-				  DCMD_BURST16 | DCMD_WIDTH4,
-};
-
 static void dump_registers(struct ssp_device *ssp)
 {
 	dev_dbg(&ssp->pdev->dev, "SSCR0 0x%08x SSCR1 0x%08x SSTO 0x%08x\n",
@@ -194,25 +61,33 @@ static void dump_registers(struct ssp_device *ssp)
 		 ssp_read_reg(ssp, SSACD));
 }
 
-static struct pxa2xx_pcm_dma_params *ssp_dma_params[4][4] = {
-	{
-		&pxa_ssp1_pcm_mono_out, &pxa_ssp1_pcm_mono_in,
-		&pxa_ssp1_pcm_stereo_out, &pxa_ssp1_pcm_stereo_in,
-	},
-	{
-		&pxa_ssp2_pcm_mono_out, &pxa_ssp2_pcm_mono_in,
-		&pxa_ssp2_pcm_stereo_out, &pxa_ssp2_pcm_stereo_in,
-	},
-	{
-		&pxa_ssp3_pcm_mono_out, &pxa_ssp3_pcm_mono_in,
-		&pxa_ssp3_pcm_stereo_out, &pxa_ssp3_pcm_stereo_in,
-	},
-	{
-		&pxa_ssp4_pcm_mono_out, &pxa_ssp4_pcm_mono_in,
-		&pxa_ssp4_pcm_stereo_out, &pxa_ssp4_pcm_stereo_in,
-	},
+struct pxa2xx_pcm_dma_data {
+	struct pxa2xx_pcm_dma_params params;
+	char name[20];
 };
 
+static struct pxa2xx_pcm_dma_params *
+ssp_get_dma_params(struct ssp_device *ssp, int stereo, int out)
+{
+	struct pxa2xx_pcm_dma_data *dma;
+
+	dma = kzalloc(sizeof(struct pxa2xx_pcm_dma_data), GFP_KERNEL);
+	if (dma == NULL)
+		return NULL;
+
+	snprintf(dma->name, 20, "SSP%d PCM %s %s", ssp->port_id,
+			stereo ? "Stereo" : "Mono", out ? "out" : "in");
+
+	dma->params.name = dma->name;
+	dma->params.drcmr = &DRCMR(out ? ssp->drcmr_tx : ssp->drcmr_rx);
+	dma->params.dcmd = (out ? (DCMD_INCSRCADDR | DCMD_FLOWTRG) :
+				  (DCMD_INCTRGADDR | DCMD_FLOWSRC)) |
+			(stereo ? DCMD_WIDTH4 : DCMD_WIDTH2) | DCMD_BURST16;
+	dma->params.dev_addr = ssp->phys_base + SSDR;
+
+	return &dma->params;
+}
+
 static int pxa_ssp_startup(struct snd_pcm_substream *substream,
 			   struct snd_soc_dai *dai)
 {
@@ -227,6 +102,11 @@ static int pxa_ssp_startup(struct

snd_pcm_substream *substream,
clk_enable(priv->dev.ssp->clk);
ssp_disable(&priv->dev);
}
+
+ if (cpu_dai->dma_data) {
+ kfree(cpu_dai->dma_data);
+ cpu_dai->dma_data = NULL;
+ }
return ret;
}

@@ -241,6 +121,11 @@ static void pxa_ssp_shutdown(struct snd_pcm_substream *substream,
ssp_disable(&priv->dev); clk_disable(priv->dev.ssp->clk);
}
+
+ if (cpu_dai->dma_data) {
+ kfree(cpu_dai->dma_data);
+ cpu_dai->dma_data = NULL;
+ }
}

#ifdef CONFIG_PM
@@ -653,25 +538,23 @@ static int pxa_ssp_hw_params(struct snd_pcm_substream *substream,
struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; struct ssp_priv *priv = cpu_dai->private_data;
struct ssp_device *ssp = priv->dev.ssp;
- int dma = 0, chn = params_channels(params);
+ int chn = params_channels(params);
u32 sscr0;
u32 sspsp;
int width = snd_pcm_format_physical_width(params_format(params)); int ttsa = ssp_read_reg(ssp, SSTSA) & 0xf;

- /* select correct DMA params */
- if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK)
- dma = 1; /* capture DMA offset is 1,3 */
+ /* generate correct DMA params */
+ if (cpu_dai->dma_data)
+ kfree(cpu_dai->dma_data);
+
/* Network mode with one active slot (ttsa == 1) can be used
* to force 16-bit frame width on the wire (for S16_LE), even
* with two channels. Use 16-bit DMA transfers for this case. */
- if (((chn == 2) && (ttsa != 1)) || (width == 32))
- dma += 2; /* 32-bit DMA offset is 2, 16-bit is 0 */
-
- cpu_dai->dma_data = ssp_dma_params[cpu_dai->id][dma];
-
- dev_dbg(&ssp->pdev->dev, "pxa_ssp_hw_params: dma %d\n", dma);
+ cpu_dai->dma_data = ssp_get_dma_params(ssp,
+ ((chn == 2) && (ttsa != 1)) || (width == 32),
+ substream->stream == SNDRV_PCM_STREAM_PLAYBACK);

/* we can only change the settings if the port is not in use */ if (ssp_read_reg(ssp, SSCR0) & SSCR0_SSE)

Signature · 1 line
1.6.0.4

From 655bad8e72e3aa13f0ddf910d5f4b9f066ec9cc3 Mon Sep 17 00:00:00 2001
From: Eric Miao <[email protected]>
Date: Thu, 23 Apr 2009 10:58:34 +0800
Subject: [PATCH] ASoC: simplify the SSP DMA parameters settings by run-time generation

The SSP DMA parameters can actually be easily generated at run-time since they are almost similar except for the FIFO width and direction. Another benefit is the re-use of information from 'struct ssp_device', like SSDR physical FIFO address and DRCMR register index for both directions.

---
 sound/soc/pxa/pxa-ssp.c |  203 ++++++++++-------------------------------------
 1 files changed, 43 insertions(+), 160 deletions(-)
sound/soc/pxa/pxa-ssp.c +43 -160

244 lines not on this page · raw message

Signature · 1 line
1.6.0.4

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

#6 lore raw
Quoted 1 line · Eric Miao

Patch updated, rebased on broonie/sound-2.6/for-2.6.31:

Your MUA has eaten this again - I'd suggest using git send-email for sending patches, the gmail web interface appears not to be able to cope with them. I was able to fix it up by hand so I've applied and tested it - thanks!

#7 lore raw
In reply to Eric Miao
Quoted 7 lines · Eric Miao
Quoted 4 lines
Quoted 2 lines

+ ?? ?? ?? snprintf(dma->name, 20, "SSP%d PCM %s %s", ssp->port_id,
+ ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? stereo ? "Stereo" : "Mono", out ? "out" : "in");

Should we change Stereo/Mono to 32-bit/16-bit here?

Depends on Mark, the dma->name and the comments below doesn't actually match very well ...

The change seems reasonable - the text has bitrotted with respect to what actually happens.

author
#8 lore raw
Quoted 4 lines · Mark Brown
Quoted 2 lines · Eric Miao
Quoted 2 lines
Quoted 2 lines

+ ?? ?? ?? snprintf(dma->name, 20, "SSP%d PCM %s %s", ssp->port_id,
+ ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? stereo ? "Stereo" : "Mono", out ? "out" : "in");

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Should we change Stereo/Mono to 32-bit/16-bit here?

Depends on Mark, the dma->name and the comments below doesn't actually match very well ...

The change seems reasonable - the text has bitrotted with respect to what actually happens.

So that's going to change the dma->name as something below:

"SSP3 PCM 32-bit out"

Looks sane?

With the code:

+static struct pxa2xx_pcm_dma_params * +ssp_get_dma_params(struct ssp_device *ssp, int width4, int out) +{
+ struct pxa2xx_pcm_dma_data *dma;
+
+ dma = kzalloc(sizeof(struct pxa2xx_pcm_dma_data), GFP_KERNEL);
+ if (dma == NULL)
+ return NULL;
+
+ snprintf(dma->name, 20, "SSP%d PCM %s %s", ssp->port_id,
+ width4 ? "32-bit" : "16-bit", out ? "out" : "in");
+
+ dma->params.name = dma->name;
+ dma->params.drcmr = &DRCMR(out ? ssp->drcmr_tx : ssp->drcmr_rx);
+ dma->params.dcmd = (out ? (DCMD_INCSRCADDR | DCMD_FLOWTRG) :
+ (DCMD_INCTRGADDR | DCMD_FLOWSRC)) |
+ (width4 ? DCMD_WIDTH4 : DCMD_WIDTH2) | DCMD_BURST16;
+ dma->params.dev_addr = ssp->phys_base + SSDR;
+
+ return &dma->params;
+}
+

#9 lore raw
Quoted 7 lines · Eric Miao

So that's going to change the dma->name as something below:

"SSP3 PCM 32-bit out"

Looks sane?

With the code:

Yup, looks sensible - please submit an incremental patch for this.

author Reviewed-by pHilipp Zabel Reviewed-by pHilipp Zabel
#10 lore raw
Quoted 4 lines · Mark Brown
Quoted 1 line · Eric Miao

So that's going to change the dma->name as something below:

Quoted 8 lines
Quoted 5 lines

"SSP3 PCM 32-bit out"

Looks sane?

With the code:

Yup, looks sensible - please submit an incremental patch for this.

I'd prefer this being added to the original one, provided that you haven't merged and pushed to public. Patch below:

Quoted 1 line

From 3deaf3ce439790668fd3f04142326cf84cb71b39 Mon Sep 17 00:00:00 2001

From: Eric Miao <[email protected]>
Date: Thu, 23 Apr 2009 10:58:34 +0800
Subject: [PATCH] ASoC: simplify the SSP DMA parameters settings by run-time generation

The SSP DMA parameters can actually be easily generated at run-time since they are almost similar except for the FIFO width and direction. Another benefit is the re-use of information from 'struct ssp_device', like SSDR physical FIFO address and DRCMR register index for both directions.

In addition, the name of the DMA parameter has been changed to something like:

"SSP3 PCM 16-bit out" or "SSP3 PCM 32-bit in"

instead of the original "Stereo" and "Mono". This is more consistent with the code.

---
 sound/soc/pxa/pxa-ssp.c |  203 ++++++++++-------------------------------------
 1 files changed, 43 insertions(+), 160 deletions(-)
sound/soc/pxa/pxa-ssp.c +25 -150
index b9b61dd..6fc7876 100644
@@ -50,139 +50,6 @@ struct ssp_priv {
 #endif
 };
 
-#define PXA2xx_SSP1_BASE	0x41000000
-#define PXA27x_SSP2_BASE	0x41700000
-#define PXA27x_SSP3_BASE	0x41900000
-#define PXA3xx_SSP4_BASE	0x41a00000
-
-static struct pxa2xx_pcm_dma_params pxa_ssp1_pcm_mono_out = {
-	.name			= "SSP1 PCM Mono out",
-	.dev_addr		= PXA2xx_SSP1_BASE + SSDR,
-	.drcmr			= &DRCMR(14),
-	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
-				  DCMD_BURST16 | DCMD_WIDTH2,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp1_pcm_mono_in = {
-	.name			= "SSP1 PCM Mono in",
-	.dev_addr		= PXA2xx_SSP1_BASE + SSDR,
-	.drcmr			= &DRCMR(13),
-	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
-				  DCMD_BURST16 | DCMD_WIDTH2,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp1_pcm_stereo_out = {
-	.name			= "SSP1 PCM Stereo out",
-	.dev_addr		= PXA2xx_SSP1_BASE + SSDR,
-	.drcmr			= &DRCMR(14),
-	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
-				  DCMD_BURST16 | DCMD_WIDTH4,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp1_pcm_stereo_in = {
-	.name			= "SSP1 PCM Stereo in",
-	.dev_addr		= PXA2xx_SSP1_BASE + SSDR,
-	.drcmr			= &DRCMR(13),
-	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
-				  DCMD_BURST16 | DCMD_WIDTH4,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp2_pcm_mono_out = {
-	.name			= "SSP2 PCM Mono out",
-	.dev_addr		= PXA27x_SSP2_BASE + SSDR,
-	.drcmr			= &DRCMR(16),
-	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
-				  DCMD_BURST16 | DCMD_WIDTH2,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp2_pcm_mono_in = {
-	.name			= "SSP2 PCM Mono in",
-	.dev_addr		= PXA27x_SSP2_BASE + SSDR,
-	.drcmr			= &DRCMR(15),
-	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
-				  DCMD_BURST16 | DCMD_WIDTH2,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp2_pcm_stereo_out = {
-	.name			= "SSP2 PCM Stereo out",
-	.dev_addr		= PXA27x_SSP2_BASE + SSDR,
-	.drcmr			= &DRCMR(16),
-	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
-				  DCMD_BURST16 | DCMD_WIDTH4,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp2_pcm_stereo_in = {
-	.name			= "SSP2 PCM Stereo in",
-	.dev_addr		= PXA27x_SSP2_BASE + SSDR,
-	.drcmr			= &DRCMR(15),
-	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
-				  DCMD_BURST16 | DCMD_WIDTH4,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp3_pcm_mono_out = {
-	.name			= "SSP3 PCM Mono out",
-	.dev_addr		= PXA27x_SSP3_BASE + SSDR,
-	.drcmr			= &DRCMR(67),
-	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
-				  DCMD_BURST16 | DCMD_WIDTH2,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp3_pcm_mono_in = {
-	.name			= "SSP3 PCM Mono in",
-	.dev_addr		= PXA27x_SSP3_BASE + SSDR,
-	.drcmr			= &DRCMR(66),
-	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
-				  DCMD_BURST16 | DCMD_WIDTH2,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp3_pcm_stereo_out = {
-	.name			= "SSP3 PCM Stereo out",
-	.dev_addr		= PXA27x_SSP3_BASE + SSDR,
-	.drcmr			= &DRCMR(67),
-	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
-				  DCMD_BURST16 | DCMD_WIDTH4,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp3_pcm_stereo_in = {
-	.name			= "SSP3 PCM Stereo in",
-	.dev_addr		= PXA27x_SSP3_BASE + SSDR,
-	.drcmr			= &DRCMR(66),
-	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
-				  DCMD_BURST16 | DCMD_WIDTH4,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp4_pcm_mono_out = {
-	.name			= "SSP4 PCM Mono out",
-	.dev_addr		= PXA3xx_SSP4_BASE + SSDR,
-	.drcmr			= &DRCMR(67),
-	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
-				  DCMD_BURST16 | DCMD_WIDTH2,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp4_pcm_mono_in = {
-	.name			= "SSP4 PCM Mono in",
-	.dev_addr		= PXA3xx_SSP4_BASE + SSDR,
-	.drcmr			= &DRCMR(66),
-	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
-				  DCMD_BURST16 | DCMD_WIDTH2,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp4_pcm_stereo_out = {
-	.name			= "SSP4 PCM Stereo out",
-	.dev_addr		= PXA3xx_SSP4_BASE + SSDR,
-	.drcmr			= &DRCMR(67),
-	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
-				  DCMD_BURST16 | DCMD_WIDTH4,
-};
-
-static struct pxa2xx_pcm_dma_params pxa_ssp4_pcm_stereo_in = {
-	.name			= "SSP4 PCM Stereo in",
-	.dev_addr		= PXA3xx_SSP4_BASE + SSDR,
-	.drcmr			= &DRCMR(66),
-	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
-				  DCMD_BURST16 | DCMD_WIDTH4,
-};
-
 static void dump_registers(struct ssp_device *ssp)
 {
 	dev_dbg(&ssp->pdev->dev, "SSCR0 0x%08x SSCR1 0x%08x SSTO 0x%08x\n",
@@ -194,25 +61,33 @@ static void dump_registers(struct ssp_device *ssp)
 		 ssp_read_reg(ssp, SSACD));
 }
 
-static struct pxa2xx_pcm_dma_params *ssp_dma_params[4][4] = {
-	{
-		&pxa_ssp1_pcm_mono_out, &pxa_ssp1_pcm_mono_in,
-		&pxa_ssp1_pcm_stereo_out, &pxa_ssp1_pcm_stereo_in,
-	},
-	{
-		&pxa_ssp2_pcm_mono_out, &pxa_ssp2_pcm_mono_in,
-		&pxa_ssp2_pcm_stereo_out, &pxa_ssp2_pcm_stereo_in,
-	},
-	{
-		&pxa_ssp3_pcm_mono_out, &pxa_ssp3_pcm_mono_in,
-		&pxa_ssp3_pcm_stereo_out, &pxa_ssp3_pcm_stereo_in,
-	},
-	{
-		&pxa_ssp4_pcm_mono_out, &pxa_ssp4_pcm_mono_in,
-		&pxa_ssp4_pcm_stereo_out, &pxa_ssp4_pcm_stereo_in,
-	},
+struct pxa2xx_pcm_dma_data {
+	struct pxa2xx_pcm_dma_params params;
+	char name[20];
 };
 
+static struct pxa2xx_pcm_dma_params *
+ssp_get_dma_params(struct ssp_device *ssp, int width4, int out)
+{
+	struct pxa2xx_pcm_dma_data *dma;
+
+	dma = kzalloc(sizeof(struct pxa2xx_pcm_dma_data), GFP_KERNEL);
+	if (dma == NULL)
+		return NULL;
+
+	snprintf(dma->name, 20, "SSP%d PCM %s %s", ssp->port_id,
+			width4 ? "32-bit" : "16-bit", out ? "out" : "in");
+
+	dma->params.name = dma->name;
+	dma->params.drcmr = &DRCMR(out ? ssp->drcmr_tx : ssp->drcmr_rx);
+	dma->params.dcmd = (out ? (DCMD_INCSRCADDR | DCMD_FLOWTRG) :
+				  (DCMD_INCTRGADDR | DCMD_FLOWSRC)) |
+			(width4 ? DCMD_WIDTH4 : DCMD_WIDTH2) | DCMD_BURST16;
+	dma->params.dev_addr = ssp->phys_base + SSDR;
+
+	return &dma->params;
+}
+
 static int pxa_ssp_startup(struct snd_pcm_substream *substream,
 			   struct snd_soc_dai *dai)
 {
@@ -227,6 +102,11 @@ static int pxa_ssp_startup(struct

snd_pcm_substream *substream,
clk_enable(priv->dev.ssp->clk);
ssp_disable(&priv->dev);
}
+
+ if (cpu_dai->dma_data) {
+ kfree(cpu_dai->dma_data);
+ cpu_dai->dma_data = NULL;
+ }
return ret;
}

@@ -241,6 +121,11 @@ static void pxa_ssp_shutdown(struct snd_pcm_substream *substream,
ssp_disable(&priv->dev); clk_disable(priv->dev.ssp->clk);
}
+
+ if (cpu_dai->dma_data) {
+ kfree(cpu_dai->dma_data);
+ cpu_dai->dma_data = NULL;
+ }
}

#ifdef CONFIG_PM
@@ -653,25 +538,23 @@ static int pxa_ssp_hw_params(struct snd_pcm_substream *substream,
struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; struct ssp_priv *priv = cpu_dai->private_data;
struct ssp_device *ssp = priv->dev.ssp;
- int dma = 0, chn = params_channels(params);
+ int chn = params_channels(params);
u32 sscr0;
u32 sspsp;
int width = snd_pcm_format_physical_width(params_format(params)); int ttsa = ssp_read_reg(ssp, SSTSA) & 0xf;

- /* select correct DMA params */
- if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK)
- dma = 1; /* capture DMA offset is 1,3 */
+ /* generate correct DMA params */
+ if (cpu_dai->dma_data)
+ kfree(cpu_dai->dma_data);
+
/* Network mode with one active slot (ttsa == 1) can be used
* to force 16-bit frame width on the wire (for S16_LE), even
* with two channels. Use 16-bit DMA transfers for this case. */
- if (((chn == 2) && (ttsa != 1)) || (width == 32))
- dma += 2; /* 32-bit DMA offset is 2, 16-bit is 0 */
-
- cpu_dai->dma_data = ssp_dma_params[cpu_dai->id][dma];
-
- dev_dbg(&ssp->pdev->dev, "pxa_ssp_hw_params: dma %d\n", dma);
+ cpu_dai->dma_data = ssp_get_dma_params(ssp,
+ ((chn == 2) && (ttsa != 1)) || (width == 32),
+ substream->stream == SNDRV_PCM_STREAM_PLAYBACK);

/* we can only change the settings if the port is not in use */ if (ssp_read_reg(ssp, SSCR0) & SSCR0_SSE)

Signature · 1 line
1.6.0.4

From 3deaf3ce439790668fd3f04142326cf84cb71b39 Mon Sep 17 00:00:00 2001
From: Eric Miao <[email protected]>
Date: Thu, 23 Apr 2009 10:58:34 +0800
Subject: [PATCH] ASoC: simplify the SSP DMA parameters settings by run-time generation

The SSP DMA parameters can actually be easily generated at run-time since they are almost similar except for the FIFO width and direction. Another benefit is the re-use of information from 'struct ssp_device', like SSDR physical FIFO address and DRCMR register index for both directions.

In addition, the name of the DMA parameter has been changed to something like:

"SSP3 PCM 16-bit out" or "SSP3 PCM 32-bit in"

instead of the original "Stereo" and "Mono". This is more consistent with the code.

---
 sound/soc/pxa/pxa-ssp.c |  203 ++++++++++-------------------------------------
 1 files changed, 43 insertions(+), 160 deletions(-)
sound/soc/pxa/pxa-ssp.c +43 -160

244 lines not on this page · raw message

Signature · 1 line
1.6.0.4

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

#11 lore raw
Quoted 2 lines · Eric Miao

I'd prefer this being added to the original one, provided that you haven't merged and pushed to public. Patch below:

This is word wrapped again and I've already published the changes (though only minutes ago so...).

author
#12 lore raw
Quoted 8 lines · Mark Brown
Quoted 2 lines · Eric Miao

I'd prefer this being added to the original one, provided that you haven't merged and pushed to public. Patch below:

This is word wrapped again and I've already published the changes (though only minutes ago so...).

Gmail web interface, sorry. That's why I attached the original file. Now the incremental patch as attached.

Signature · 2 lines
Cheers
- eric

From e2037334d77e4826aaebf5800eee46f409b0a698 Mon Sep 17 00:00:00 2001
From: Eric Miao <[email protected]>
Date: Thu, 23 Apr 2009 17:48:56 +0800
Subject: [PATCH] ASoC: change stereo/mono to 32-bit/16-bit for pxa-ssp

The original idea came from pHilipp, and this makes the code looks more consistent.

---
 sound/soc/pxa/pxa-ssp.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
sound/soc/pxa/pxa-ssp.c +3 -3
index fb8cacc..6fc7876 100644
@@ -67,7 +67,7 @@ struct pxa2xx_pcm_dma_data {
 };
 
 static struct pxa2xx_pcm_dma_params *
-ssp_get_dma_params(struct ssp_device *ssp, int stereo, int out)
+ssp_get_dma_params(struct ssp_device *ssp, int width4, int out)
 {
 	struct pxa2xx_pcm_dma_data *dma;
 
@@ -76,13 +76,13 @@ ssp_get_dma_params(struct ssp_device *ssp, int stereo, int out)
 		return NULL;
 
 	snprintf(dma->name, 20, "SSP%d PCM %s %s", ssp->port_id,
-			stereo ? "Stereo" : "Mono", out ? "out" : "in");
+			width4 ? "32-bit" : "16-bit", out ? "out" : "in");
 
 	dma->params.name = dma->name;
 	dma->params.drcmr = &DRCMR(out ? ssp->drcmr_tx : ssp->drcmr_rx);
 	dma->params.dcmd = (out ? (DCMD_INCSRCADDR | DCMD_FLOWTRG) :
 				  (DCMD_INCTRGADDR | DCMD_FLOWSRC)) |
-			(stereo ? DCMD_WIDTH4 : DCMD_WIDTH2) | DCMD_BURST16;
+			(width4 ? DCMD_WIDTH4 : DCMD_WIDTH2) | DCMD_BURST16;
 	dma->params.dev_addr = ssp->phys_base + SSDR;
 
 	return &dma->params;
Signature · 1 line
1.6.0.4

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