Skip to contentSkip to conversation

mpc5200 audio rework for AC97

PATCH Superseded Jon Smirl 5 participants 35 messages May 23, 2009 – May 25, 2009

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jon Smirl

author
#0 lore raw

v2 cover mpc5200 audio rework for AC97

The following series implements audio support for the mpc5200. It adds an AC97 driver and STAC9766 codec driver. Board support for the Efika and Phytec pcm030 are also included.

Mark is not enthused about soc-of-simple.c so rather than extend it for AC97 I altered the drivers to not use it. Instead they use the old way of manually binding everything. Mark would like to see OF binding more closely integrated to the core. Once a proper solution for OF binding is agreed upon it is easy to convert the existing drivers. A first step would be converting the existing codec drivers so that they can be dynamically loaded.

Grant, please check over the spin locking on register access. I'm not clear on why and when the registers have to be protected.

Once these basic drivers are in-kernel and more people are testing them, I can add more features like pause/resume, power management, etc based on feedback.

I2S will get examined in more detail for the next kernel cycle. Our multi-channel prototype I2S hardware is just about working. Once I get the multi-channel hardware I will implement and heavily test a lot more I2S capability.

---

Jon Smirl (9):
Support for AC97 on Phytec pmc030 base board. Fabric bindings for STAC9766 on the Efika
AC97 driver for mpc5200
Codec for STAC9766 used on the Efika
Main rewite of the mpc5200 audio DMA code
Add a few more mpc5200 PSC defines
Rename the PSC functions to DMA
Basic split of mpc5200 DMA code out from mpc5200_psc_i2s Register the wm9712 DAIs on module load

 sound/soc/fsl/Kconfig               |   31 +
 sound/soc/fsl/Makefile              |    7 
 sound/soc/fsl/efika-audio-fabric.c  |   94 ++++
 sound/soc/fsl/mpc5200_dma.c         |  635 ++++++++++++++++++++++++++++++
 sound/soc/fsl/mpc5200_dma.h         |   80 ++++
 sound/soc/fsl/mpc5200_psc_ac97.c    |  394 ++++++++++++++++++
 sound/soc/fsl/mpc5200_psc_ac97.h    |   15 +
 sound/soc/fsl/mpc5200_psc_i2s.c     |  750 ++---------------------------------
 sound/soc/fsl/mpc5200_psc_i2s.h     |   12 +
 sound/soc/fsl/pcm030-audio-fabric.c |   94 ++++
 10 files changed, 1414 insertions(+), 698 deletions(-)
 create mode 100644 sound/soc/fsl/efika-audio-fabric.c
 create mode 100644 sound/soc/fsl/mpc5200_dma.c
 create mode 100644 sound/soc/fsl/mpc5200_dma.h
 create mode 100644 sound/soc/fsl/mpc5200_psc_ac97.c
 create mode 100644 sound/soc/fsl/mpc5200_psc_ac97.h
 create mode 100644 sound/soc/fsl/mpc5200_psc_i2s.h
 create mode 100644 sound/soc/fsl/pcm030-audio-fabric.c
Signature · 2 lines
Jon Smirl
[email protected]
author
#1 lore raw

PATCH v2 1/9 Register the wm9712 DAIs on module load

Register the wm9712 DAIs on module load

---

 0 files changed, 0 insertions(+), 0 deletions(-)
sound/soc/codecs/wm9712.c +12 -0
index 1fd4e88..49ad987 100644
@@ -742,6 +742,18 @@ struct snd_soc_codec_device soc_codec_dev_wm9712 = {
 };
 EXPORT_SYMBOL_GPL(soc_codec_dev_wm9712);
 
+static int __init wm9712_modinit(void)
+{
+	return snd_soc_register_dais(wm9712_dai, ARRAY_SIZE(wm9712_dai));
+}
+module_init(wm9712_modinit);
+
+static void __exit wm9712_exit(void)
+{
+	snd_soc_unregister_dais(wm9712_dai, ARRAY_SIZE(wm9712_dai));
+}
+module_exit(wm9712_exit);
+
 MODULE_DESCRIPTION("ASoC WM9711/WM9712 driver");
 MODULE_AUTHOR("Liam Girdwood");
 MODULE_LICENSE("GPL");
#2 lore raw

Re: [PATCH V2 1/9] Register the wm9712 DAIs on module load

Quoted 3 lines · Jon Smirl

Register the wm9712 DAIs on module load

Why do you wish to do this - ASoC does not require or use DAI registration for AC97 CODECs?

author
#3 lore raw

Re: [PATCH V2 1/9] Register the wm9712 DAIs on module load

Quoted 8 lines · Mark Brown
Quoted 3 lines · Jon Smirl

Register the wm9712 DAIs on module load

Why do you wish to do this - ASoC does not require or use DAI registration for AC97 CODECs?

Then what is wrong with my binding code? If I take out the registration my bind fails.

static struct snd_soc_dai_link pcm030_fabric_dai[] = {

{
	.name = "AC97",
	.stream_name = "AC97 Analog",
	.codec_dai = &wm9712_dai[WM9712_DAI_AC97_HIFI],
	.cpu_dai = &psc_ac97_dai[MPC5200_AC97_NORMAL],
},
{
	.name = "AC97",
	.stream_name = "AC97 IEC958",
	.codec_dai = &wm9712_dai[WM9712_DAI_AC97_AUX],
	.cpu_dai = &psc_ac97_dai[MPC5200_AC97_SPDIF],
},

};

static __init int pcm030_fabric_init(void)

{
	struct platform_device *pdev;
	int rc;

	if (!machine_is_compatible("phytec,pcm030"))
		return -ENODEV;

	card.platform = &mpc5200_audio_dma_platform;
	card.name = "pcm030";
	card.dai_link = pcm030_fabric_dai;
	card.num_links = ARRAY_SIZE(pcm030_fabric_dai);

	device.card = &card;
	device.codec_dev = &soc_codec_dev_wm9712;

	pdev = platform_device_alloc("soc-audio", 1);
	if (!pdev) {
		pr_err("pcm030_fabric_init: platform_device_alloc() failed\n");
		return -ENODEV;
	}

	platform_set_drvdata(pdev, &device);
	device.dev = &pdev->dev;

	rc = platform_device_add(pdev);
	if (rc) {
		pr_err("pcm030_fabric_init: platform_device_add() failed\n");
		return -ENODEV;
	}
	return 0;
}

Advanced Linux Sound Architecture Driver Version 1.0.19.
No device for DAI stac9766 analog
No device for DAI stac9766 IEC958
No device for DAI tas5504
irq: irq 129 on host /soc5200@f0000000/interrupt-controller@500 mapped to virtual irq 129
irq: irq 194 on host /soc5200@f0000000/interrupt-controller@500 mapped to virtual irq 194
irq: irq 195 on host /soc5200@f0000000/interrupt-controller@500 mapped to virtual irq 195
mpc5200-psc-ac97 f0002000.ac97: Codec ID is 574d 4c12
ALSA device list:
No soundcards found.

Signature · 2 lines
Jon Smirl
[email protected]
author
#4 lore raw

Re: [PATCH V2 1/9] Register the wm9712 DAIs on module load

Output with SOC DEBUG turned on:

Advanced Linux Sound Architecture Driver Version 1.0.19.
No device for DAI stac9766 analog
Registered DAI 'stac9766 analog'
No device for DAI stac9766 IEC958
Registered DAI 'stac9766 IEC958'
No device for DAI tas5504
Registered DAI 'tas5504'
Registered platform 'mpc5200-psc-audio'
irq: irq 129 on host /soc5200@f0000000/interrupt-controller@500 mapped to virtual irq 129
irq: irq 194 on host /soc5200@f0000000/interrupt-controller@500 mapped to virtual irq 194
irq: irq 195 on host /soc5200@f0000000/interrupt-controller@500 mapped to virtual irq 195
Registered DAI 'AC97'
Registered DAI 'SPDIF'
mpc5200-psc-ac97 f0002000.ac97: Codec ID is 574d 4c12 soc-audio soc-audio.1: DAI AC97 HiFi not registered soc-audio soc-audio.1: Registered card 'pcm030'
ALSA device list:
No soundcards found.

Signature · 2 lines
Jon Smirl
[email protected]
#5 lore raw

Re: [alsa-devel] [PATCH V2 1/9] Register the wm9712 DAIs on module load

In reply to Jon Smirl
Quoted 7 lines · Jon Smirl

On Sun, May 24, 2009 at 7:11 AM, Mark Brown

Quoted 2 lines

Why do you wish to do this - ASoC does not require or use DAI registration for AC97 CODECs?

Then what is wrong with my binding code? If I take out the registration my bind fails.

It appears that the problem here is that your CPU DAI isn't marked as an ac97 DAI by having ac97_control set so the core expects the codec to instantiate prior to the card. Setting ac97_control ought to fix the problem, but obviously I can't test.

When looking at problems like this it's worth taking a step back and looking at why the existing code is the way that it is when considering if you've found the right fix. In this case AC97 is fairly widely used and there are also a number of WM9712 users but neither WM9712 or any of the other AC97 CODEC drivers ever register their DAIs. That should be an indication that either things probably should work without a change to existing code or things are completely broken and something wider than a change in a single driver is required in order to get things working.

author
#6 lore raw

PATCH v2 2/9 Basic split of mpc5200 DMA code out from mpc5200_psc_i2s

In reply to Jon Smirl

Basic split of mpc5200 DMA code out from i2s into a standalone file.

---
 sound/soc/fsl/Kconfig           |    4 
 sound/soc/fsl/Makefile          |    2 
 sound/soc/fsl/mpc5200_dma.c     |  458 +++++++++++++++++++++++++++++++++++++
 sound/soc/fsl/mpc5200_dma.h     |   81 +++++++
 sound/soc/fsl/mpc5200_psc_i2s.c |  485 ---------------------------------------
 5 files changed, 547 insertions(+), 483 deletions(-)
 create mode 100644 sound/soc/fsl/mpc5200_dma.c
 create mode 100644 sound/soc/fsl/mpc5200_dma.h
sound/soc/fsl/Kconfig +4 -0
index 9fc9082..dc79bdf 100644
@@ -1,5 +1,8 @@
 config SND_SOC_OF_SIMPLE
 	tristate
+	
+config SND_MPC52xx_DMA
+	tristate
 
 # ASoC platform support for the Freescale MPC8610 SOC.  This compiles drivers
 # for the SSI and the Elo DMA controller.  You will still need to select
@@ -23,6 +26,7 @@ config SND_SOC_MPC5200_I2S
 	tristate "Freescale MPC5200 PSC in I2S mode driver"
 	depends on PPC_MPC52xx && PPC_BESTCOMM
 	select SND_SOC_OF_SIMPLE
+	select SND_MPC52xx_DMA
 	select PPC_BESTCOMM_GEN_BD
 	help
 	  Say Y here to support the MPC5200 PSCs in I2S mode.
sound/soc/fsl/Makefile +2 -0
index f85134c..7731ef2 100644
@@ -10,5 +10,7 @@ snd-soc-fsl-ssi-objs := fsl_ssi.o
 snd-soc-fsl-dma-objs := fsl_dma.o
 obj-$(CONFIG_SND_SOC_MPC8610) += snd-soc-fsl-ssi.o snd-soc-fsl-dma.o
 
+# MPC5200 Platform Support
+obj-$(CONFIG_SND_MPC52xx_DMA) += mpc5200_dma.o
 obj-$(CONFIG_SND_SOC_MPC5200_I2S) += mpc5200_psc_i2s.o
 
sound/soc/fsl/mpc5200_dma.c new file +458 -0

458 lines not on this page · raw message

sound/soc/fsl/mpc5200_dma.h new file +81 -0

81 lines not on this page · raw message

sound/soc/fsl/mpc5200_psc_i2s.c +2 -483

509 lines not on this page · raw message

Acked-by on v2 2/9
#7 lore raw

Re: [PATCH V2 2/9] Basic split of mpc5200 DMA code out from mpc5200_psc_i2s

Quoted 3 lines · Jon Smirl

Basic split of mpc5200 DMA code out from i2s into a standalone file.

I haven't looked in detail, but I'm okay with this in principle.

g.

Quoted 1,113 lines

---
 sound/soc/fsl/Kconfig           |    4
 sound/soc/fsl/Makefile          |    2 sound/soc/fsl/mpc5200_dma.c     |  458 +++++++++++++++++++++++++++++++++++++ sound/soc/fsl/mpc5200_dma.h     |   81 +++++++ sound/soc/fsl/mpc5200_psc_i2s.c |  485 ---------------------------------------

 5 files changed, 547 insertions(+), 483 deletions(-)

 create mode 100644 sound/soc/fsl/mpc5200_dma.c
 create mode 100644 sound/soc/fsl/mpc5200_dma.h

sound/soc/fsl/Kconfig +0 -0
index 9fc9082..dc79bdf 100644
@@ -1,5 +1,8 @@

 config SND_SOC_OF_SIMPLE
       tristate

sound/soc/fsl/Kconfig +3 -0
+
+config SND_MPC52xx_DMA
+       tristate

 # ASoC platform support for the Freescale MPC8610 SOC.  This compiles drivers

 # for the SSI and the Elo DMA controller.  You will still need to select
sound/soc/fsl/Kconfig +0 -0
@@ -23,6 +26,7 @@ config SND_SOC_MPC5200_I2S

       tristate "Freescale MPC5200 PSC in I2S mode driver" depends on PPC_MPC52xx && PPC_BESTCOMM select SND_SOC_OF_SIMPLE
+       select SND_MPC52xx_DMA
       select PPC_BESTCOMM_GEN_BD
       help
         Say Y here to support the MPC5200 PSCs in I2S mode.

sound/soc/fsl/Makefile +0 -0
index f85134c..7731ef2 100644
@@ -10,5 +10,7 @@ snd-soc-fsl-ssi-objs := fsl_ssi.o

 snd-soc-fsl-dma-objs := fsl_dma.o obj-$(CONFIG_SND_SOC_MPC8610) += snd-soc-fsl-ssi.o snd-soc-fsl-dma.o

sound/soc/fsl/Makefile +2 -0
+# MPC5200 Platform Support
+obj-$(CONFIG_SND_MPC52xx_DMA) += mpc5200_dma.o

 obj-$(CONFIG_SND_SOC_MPC5200_I2S) += mpc5200_psc_i2s.o

sound/soc/fsl/mpc5200_dma.c new file +458 -0
new file mode 100644
index 0000000..4bae8d6
@@ -0,0 +1,458 @@
+/*
+ * Freescale MPC5200 PSC DMA
+ * ALSA SoC Platform driver
+ *
+ * Copyright (C) 2008 Secret Lab Technologies Ltd.
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/interrupt.h>
+#include <linux/device.h>
+#include <linux/delay.h>
+#include <linux/of_device.h>
+#include <linux/of_platform.h>
+#include <linux/dma-mapping.h>
+
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/initval.h>
+#include <sound/soc.h>
+#include <sound/soc-of-simple.h>
+
+#include <sysdev/bestcomm/bestcomm.h>
+#include <sysdev/bestcomm/gen_bd.h>
+#include <asm/mpc52xx_psc.h>
+
+#include "mpc5200_dma.h"
+
+MODULE_AUTHOR("Grant Likely <[email protected]>");
+MODULE_DESCRIPTION("Freescale MPC5200 PSC in DMA mode ASoC Driver");
+MODULE_LICENSE("GPL");
+
+/*
+ * Interrupt handlers
+ */
+static irqreturn_t psc_i2s_status_irq(int irq, void *_psc_i2s)
+{
+       struct psc_i2s *psc_i2s = _psc_i2s;
+       struct mpc52xx_psc __iomem *regs = psc_i2s->psc_regs;
+       u16 isr;
+
+       isr = in_be16(&regs->mpc52xx_psc_isr);
+
+       /* Playback underrun error */
+       if (psc_i2s->playback.active && (isr & MPC52xx_PSC_IMR_TXEMP))
+               psc_i2s->stats.underrun_count++;
+
+       /* Capture overrun error */
+       if (psc_i2s->capture.active && (isr & MPC52xx_PSC_IMR_ORERR))
+               psc_i2s->stats.overrun_count++;
+
+       out_8(&regs->command, 4 << 4);  /* reset the error status */
+
+       return IRQ_HANDLED;
+}
+
+/**
+ * psc_i2s_bcom_enqueue_next_buffer - Enqueue another audio buffer
+ * @s: pointer to stream private data structure
+ *
+ * Enqueues another audio period buffer into the bestcomm queue.
+ *
+ * Note: The routine must only be called when there is space available in
+ * the queue.  Otherwise the enqueue will fail and the audio ring buffer
+ * will get out of sync
+ */
+static void psc_i2s_bcom_enqueue_next_buffer(struct psc_i2s_stream *s)
+{
+       struct bcom_bd *bd;
+
+       /* Prepare and enqueue the next buffer descriptor */
+       bd = bcom_prepare_next_buffer(s->bcom_task);
+       bd->status = s->period_bytes;
+       bd->data[0] = s->period_next_pt;
+       bcom_submit_next_buffer(s->bcom_task, NULL);
+
+       /* Update for next period */
+       s->period_next_pt += s->period_bytes;
+       if (s->period_next_pt >= s->period_end)
+               s->period_next_pt = s->period_start;
+}
+
+/* Bestcomm DMA irq handler */
+static irqreturn_t psc_i2s_bcom_irq(int irq, void *_psc_i2s_stream)
+{
+       struct psc_i2s_stream *s = _psc_i2s_stream;
+
+       /* For each finished period, dequeue the completed period buffer
+        * and enqueue a new one in it's place. */
+       while (bcom_buffer_done(s->bcom_task)) {
+               bcom_retrieve_buffer(s->bcom_task, NULL, NULL);
+               s->period_current_pt += s->period_bytes;
+               if (s->period_current_pt >= s->period_end)
+                       s->period_current_pt = s->period_start;
+               psc_i2s_bcom_enqueue_next_buffer(s);
+               bcom_enable(s->bcom_task);
+       }
+
+       /* If the stream is active, then also inform the PCM middle layer
+        * of the period finished event. */
+       if (s->active)
+               snd_pcm_period_elapsed(s->stream);
+
+       return IRQ_HANDLED;
+}
+
+/**
+ * psc_i2s_startup: create a new substream
+ *
+ * This is the first function called when a stream is opened.
+ *
+ * If this is the first stream open, then grab the IRQ and program most of
+ * the PSC registers.
+ */
+int psc_i2s_startup(struct snd_pcm_substream *substream,
+                          struct snd_soc_dai *dai)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct psc_i2s *psc_i2s = rtd->dai->cpu_dai->private_data;
+       int rc;
+
+       dev_dbg(psc_i2s->dev, "psc_i2s_startup(substream=%p)\n", substream);
+
+       if (!psc_i2s->playback.active &&
+           !psc_i2s->capture.active) {
+               /* Setup the IRQs */
+               rc = request_irq(psc_i2s->irq, &psc_i2s_status_irq, IRQF_SHARED,
+                                "psc-i2s-status", psc_i2s);
+               rc |= request_irq(psc_i2s->capture.irq,
+                                 &psc_i2s_bcom_irq, IRQF_SHARED,
+                                 "psc-i2s-capture", &psc_i2s->capture);
+               rc |= request_irq(psc_i2s->playback.irq,
+                                 &psc_i2s_bcom_irq, IRQF_SHARED,
+                                 "psc-i2s-playback", &psc_i2s->playback);
+               if (rc) {
+                       free_irq(psc_i2s->irq, psc_i2s);
+                       free_irq(psc_i2s->capture.irq,
+                                &psc_i2s->capture);
+                       free_irq(psc_i2s->playback.irq,
+                                &psc_i2s->playback);
+                       return -ENODEV;
+               }
+       }
+
+       return 0;
+}
+
+int psc_i2s_hw_free(struct snd_pcm_substream *substream,
+                          struct snd_soc_dai *dai)
+{
+       snd_pcm_set_runtime_buffer(substream, NULL);
+       return 0;
+}
+
+/**
+ * psc_i2s_trigger: start and stop the DMA transfer.
+ *
+ * This function is called by ALSA to start, stop, pause, and resume the DMA
+ * transfer of data.
+ */
+int psc_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
+                          struct snd_soc_dai *dai)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct psc_i2s *psc_i2s = rtd->dai->cpu_dai->private_data;
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct psc_i2s_stream *s;
+       struct mpc52xx_psc __iomem *regs = psc_i2s->psc_regs;
+       u16 imr;
+       u8 psc_cmd;
+       unsigned long flags;
+
+       if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE)
+               s = &psc_i2s->capture;
+       else
+               s = &psc_i2s->playback;
+
+       dev_dbg(psc_i2s->dev, "psc_i2s_trigger(substream=%p, cmd=%i)"
+               " stream_id=%i\n",
+               substream, cmd, substream->pstr->stream);
+
+       switch (cmd) {
+       case SNDRV_PCM_TRIGGER_START:
+               s->period_bytes = frames_to_bytes(runtime,
+                                                 runtime->period_size);
+               s->period_start = virt_to_phys(runtime->dma_area);
+               s->period_end = s->period_start +
+                               (s->period_bytes * runtime->periods);
+               s->period_next_pt = s->period_start;
+               s->period_current_pt = s->period_start;
+               s->active = 1;
+
+               /* First; reset everything */
+               if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE) {
+                       out_8(&regs->command, MPC52xx_PSC_RST_RX);
+                       out_8(&regs->command, MPC52xx_PSC_RST_ERR_STAT);
+               } else {
+                       out_8(&regs->command, MPC52xx_PSC_RST_TX);
+                       out_8(&regs->command, MPC52xx_PSC_RST_ERR_STAT);
+               }
+
+               /* Next, fill up the bestcomm bd queue and enable DMA.
+                * This will begin filling the PSC's fifo. */
+               if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE)
+                       bcom_gen_bd_rx_reset(s->bcom_task);
+               else
+                       bcom_gen_bd_tx_reset(s->bcom_task);
+               while (!bcom_queue_full(s->bcom_task))
+                       psc_i2s_bcom_enqueue_next_buffer(s);
+               bcom_enable(s->bcom_task);
+
+               /* Due to errata in the i2s mode; need to line up enabling
+                * the transmitter with a transition on the frame sync
+                * line */
+
+               spin_lock_irqsave(&psc_i2s->lock, flags);
+               /* first make sure it is low */
+               while ((in_8(&regs->ipcr_acr.ipcr) & 0x80) != 0)
+                       ;
+               /* then wait for the transition to high */
+               while ((in_8(&regs->ipcr_acr.ipcr) & 0x80) == 0)
+                       ;
+               /* Finally, enable the PSC.
+                * Receiver must always be enabled; even when we only want
+                * transmit.  (see 15.3.2.3 of MPC5200B User's Guide) */
+               psc_cmd = MPC52xx_PSC_RX_ENABLE;
+               if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK)
+                       psc_cmd |= MPC52xx_PSC_TX_ENABLE;
+               out_8(&regs->command, psc_cmd);
+               spin_unlock_irqrestore(&psc_i2s->lock, flags);
+
+               break;
+
+       case SNDRV_PCM_TRIGGER_STOP:
+               /* Turn off the PSC */
+               s->active = 0;
+               if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE) {
+                       if (!psc_i2s->playback.active) {
+                               out_8(&regs->command, 2 << 4);  /* reset rx */
+                               out_8(&regs->command, 3 << 4);  /* reset tx */
+                               out_8(&regs->command, 4 << 4);  /* reset err */
+                       }
+               } else {
+                       out_8(&regs->command, 3 << 4);  /* reset tx */
+                       out_8(&regs->command, 4 << 4);  /* reset err */
+                       if (!psc_i2s->capture.active)
+                               out_8(&regs->command, 2 << 4);  /* reset rx */
+               }
+
+               bcom_disable(s->bcom_task);
+               while (!bcom_queue_empty(s->bcom_task))
+                       bcom_retrieve_buffer(s->bcom_task, NULL, NULL);
+
+               break;
+
+       default:
+               dev_dbg(psc_i2s->dev, "invalid command\n");
+               return -EINVAL;
+       }
+
+       /* Update interrupt enable settings */
+       imr = 0;
+       if (psc_i2s->playback.active)
+               imr |= MPC52xx_PSC_IMR_TXEMP;
+       if (psc_i2s->capture.active)
+               imr |= MPC52xx_PSC_IMR_ORERR;
+       out_be16(&regs->isr_imr.imr, imr);
+
+       return 0;
+}
+
+/**
+ * psc_i2s_shutdown: shutdown the data transfer on a stream
+ *
+ * Shutdown the PSC if there are no other substreams open.
+ */
+void psc_i2s_shutdown(struct snd_pcm_substream *substream,
+                            struct snd_soc_dai *dai)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct psc_i2s *psc_i2s = rtd->dai->cpu_dai->private_data;
+
+       dev_dbg(psc_i2s->dev, "psc_i2s_shutdown(substream=%p)\n", substream);
+
+       /*
+        * If this is the last active substream, disable the PSC and release
+        * the IRQ.
+        */
+       if (!psc_i2s->playback.active &&
+           !psc_i2s->capture.active) {
+
+               /* Disable all interrupts and reset the PSC */
+               out_be16(&psc_i2s->psc_regs->isr_imr.imr, 0);
+               out_8(&psc_i2s->psc_regs->command, 3 << 4); /* reset tx */
+               out_8(&psc_i2s->psc_regs->command, 2 << 4); /* reset rx */
+               out_8(&psc_i2s->psc_regs->command, 1 << 4); /* reset mode */
+               out_8(&psc_i2s->psc_regs->command, 4 << 4); /* reset error */
+
+               /* Release irqs */
+               free_irq(psc_i2s->irq, psc_i2s);
+               free_irq(psc_i2s->capture.irq, &psc_i2s->capture);
+               free_irq(psc_i2s->playback.irq, &psc_i2s->playback);
+       }
+}
+
+/* ---------------------------------------------------------------------
+ * The PSC DMA 'ASoC platform' driver
+ *
+ * Can be referenced by an 'ASoC machine' driver
+ * This driver only deals with the audio bus; it doesn't have any
+ * interaction with the attached codec
+ */
+
+static const struct snd_pcm_hardware psc_i2s_pcm_hardware = {
+       .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID |
+               SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
+               SNDRV_PCM_INFO_BATCH,
+       .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_BE |
+                  SNDRV_PCM_FMTBIT_S24_BE | SNDRV_PCM_FMTBIT_S32_BE,
+       .rate_min = 8000,
+       .rate_max = 48000,
+       .channels_min = 2,
+       .channels_max = 2,
+       .period_bytes_max       = 1024 * 1024,
+       .period_bytes_min       = 32,
+       .periods_min            = 2,
+       .periods_max            = 256,
+       .buffer_bytes_max       = 2 * 1024 * 1024,
+       .fifo_size              = 0,
+};
+
+static int psc_i2s_pcm_open(struct snd_pcm_substream *substream)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct psc_i2s *psc_i2s = rtd->dai->cpu_dai->private_data;
+       struct psc_i2s_stream *s;
+
+       dev_dbg(psc_i2s->dev, "psc_i2s_pcm_open(substream=%p)\n", substream);
+
+       if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE)
+               s = &psc_i2s->capture;
+       else
+               s = &psc_i2s->playback;
+
+       snd_soc_set_runtime_hwparams(substream, &psc_i2s_pcm_hardware);
+
+       s->stream = substream;
+       return 0;
+}
+
+static int psc_i2s_pcm_close(struct snd_pcm_substream *substream)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct psc_i2s *psc_i2s = rtd->dai->cpu_dai->private_data;
+       struct psc_i2s_stream *s;
+
+       dev_dbg(psc_i2s->dev, "psc_i2s_pcm_close(substream=%p)\n", substream);
+
+       if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE)
+               s = &psc_i2s->capture;
+       else
+               s = &psc_i2s->playback;
+
+       s->stream = NULL;
+       return 0;
+}
+
+static snd_pcm_uframes_t
+psc_i2s_pcm_pointer(struct snd_pcm_substream *substream)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct psc_i2s *psc_i2s = rtd->dai->cpu_dai->private_data;
+       struct psc_i2s_stream *s;
+       dma_addr_t count;
+
+       if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE)
+               s = &psc_i2s->capture;
+       else
+               s = &psc_i2s->playback;
+
+       count = s->period_current_pt - s->period_start;
+
+       return bytes_to_frames(substream->runtime, count);
+}
+
+static struct snd_pcm_ops psc_i2s_pcm_ops = {
+       .open           = psc_i2s_pcm_open,
+       .close          = psc_i2s_pcm_close,
+       .ioctl          = snd_pcm_lib_ioctl,
+       .pointer        = psc_i2s_pcm_pointer,
+};
+
+static u64 psc_i2s_pcm_dmamask = 0xffffffff;
+static int psc_i2s_pcm_new(struct snd_card *card, struct snd_soc_dai *dai,
+                          struct snd_pcm *pcm)
+{
+       struct snd_soc_pcm_runtime *rtd = pcm->private_data;
+       size_t size = psc_i2s_pcm_hardware.buffer_bytes_max;
+       int rc = 0;
+
+       dev_dbg(rtd->socdev->dev, "psc_i2s_pcm_new(card=%p, dai=%p, pcm=%p)\n",
+               card, dai, pcm);
+
+       if (!card->dev->dma_mask)
+               card->dev->dma_mask = &psc_i2s_pcm_dmamask;
+       if (!card->dev->coherent_dma_mask)
+               card->dev->coherent_dma_mask = 0xffffffff;
+
+       if (pcm->streams[0].substream) {
+               rc = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, pcm->dev, size,
+                                       &pcm->streams[0].substream->dma_buffer);
+               if (rc)
+                       goto playback_alloc_err;
+       }
+
+       if (pcm->streams[1].substream) {
+               rc = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, pcm->dev, size,
+                                       &pcm->streams[1].substream->dma_buffer);
+               if (rc)
+                       goto capture_alloc_err;
+       }
+
+       return 0;
+
+ capture_alloc_err:
+       if (pcm->streams[0].substream)
+               snd_dma_free_pages(&pcm->streams[0].substream->dma_buffer);
+ playback_alloc_err:
+       dev_err(card->dev, "Cannot allocate buffer(s)\n");
+       return -ENOMEM;
+}
+
+static void psc_i2s_pcm_free(struct snd_pcm *pcm)
+{
+       struct snd_soc_pcm_runtime *rtd = pcm->private_data;
+       struct snd_pcm_substream *substream;
+       int stream;
+
+       dev_dbg(rtd->socdev->dev, "psc_i2s_pcm_free(pcm=%p)\n", pcm);
+
+       for (stream = 0; stream < 2; stream++) {
+               substream = pcm->streams[stream].substream;
+               if (substream) {
+                       snd_dma_free_pages(&substream->dma_buffer);
+                       substream->dma_buffer.area = NULL;
+                       substream->dma_buffer.addr = 0;
+               }
+       }
+}
+
+struct snd_soc_platform psc_i2s_pcm_soc_platform = {
+       .name           = "mpc5200-psc-audio",
+       .pcm_ops        = &psc_i2s_pcm_ops,
+       .pcm_new        = &psc_i2s_pcm_new,
+       .pcm_free       = &psc_i2s_pcm_free,
+};
+
sound/soc/fsl/mpc5200_dma.h new file +81 -0
new file mode 100644
index 0000000..9a19e8a
@@ -0,0 +1,81 @@
+/*
+ * Freescale MPC5200 Audio DMA driver
+ */
+
+#ifndef __SOUND_SOC_FSL_MPC5200_DMA_H__
+#define __SOUND_SOC_FSL_MPC5200_DMA_H__
+
+/**
+ * psc_i2s_stream - Data specific to a single stream (playback or capture)
+ * @active:            flag indicating if the stream is active
+ * @psc_i2s:           pointer back to parent psc_i2s data structure
+ * @bcom_task:         bestcomm task structure
+ * @irq:               irq number for bestcomm task
+ * @period_start:      physical address of start of DMA region
+ * @period_end:                physical address of end of DMA region
+ * @period_next_pt:    physical address of next DMA buffer to enqueue
+ * @period_bytes:      size of DMA period in bytes
+ */
+struct psc_i2s_stream {
+       int active;
+       struct psc_i2s *psc_i2s;
+       struct bcom_task *bcom_task;
+       int irq;
+       struct snd_pcm_substream *stream;
+       dma_addr_t period_start;
+       dma_addr_t period_end;
+       dma_addr_t period_next_pt;
+       dma_addr_t period_current_pt;
+       int period_bytes;
+};
+
+/**
+ * psc_i2s - Private driver data
+ * @name: short name for this device ("PSC0", "PSC1", etc)
+ * @psc_regs: pointer to the PSC's registers
+ * @fifo_regs: pointer to the PSC's FIFO registers
+ * @irq: IRQ of this PSC
+ * @dev: struct device pointer
+ * @dai: the CPU DAI for this device
+ * @sicr: Base value used in serial interface control register; mode is ORed
+ *        with this value.
+ * @playback: Playback stream context data
+ * @capture: Capture stream context data
+ */
+struct psc_i2s {
+       char name[32];
+       struct mpc52xx_psc __iomem *psc_regs;
+       struct mpc52xx_psc_fifo __iomem *fifo_regs;
+       unsigned int irq;
+       struct device *dev;
+       struct snd_soc_dai dai;
+       spinlock_t lock;
+       u32 sicr;
+
+       /* per-stream data */
+       struct psc_i2s_stream playback;
+       struct psc_i2s_stream capture;
+
+       /* Statistics */
+       struct {
+               int overrun_count;
+               int underrun_count;
+       } stats;
+};
+
+
+int psc_i2s_startup(struct snd_pcm_substream *substream,
+                          struct snd_soc_dai *dai);
+
+int psc_i2s_hw_free(struct snd_pcm_substream *substream,
+                          struct snd_soc_dai *dai);
+
+void psc_i2s_shutdown(struct snd_pcm_substream *substream,
+                            struct snd_soc_dai *dai);
+
+int psc_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
+                          struct snd_soc_dai *dai);
+
+extern struct snd_soc_platform psc_i2s_pcm_soc_platform;
+
+#endif /* __SOUND_SOC_FSL_MPC5200_DMA_H__ */
sound/soc/fsl/mpc5200_psc_i2s.c +2 -483
index 1111c71..8974b53 100644
@@ -25,6 +25,8 @@
  #include <sysdev/bestcomm/gen_bd.h>
  #include <asm/mpc52xx_psc.h>
 
+#include "mpc5200_dma.h"
+
  MODULE_AUTHOR("Grant Likely <[email protected]>");
  MODULE_DESCRIPTION("Freescale MPC5200 PSC in I2S mode ASoC Driver");
  MODULE_LICENSE("GPL");
@@ -47,179 +49,6 @@ MODULE_LICENSE("GPL");
                         SNDRV_PCM_FMTBIT_S24_BE | SNDRV_PCM_FMTBIT_S24_BE | \
                         SNDRV_PCM_FMTBIT_S32_BE)
 
-/**
- * psc_i2s_stream - Data specific to a single stream (playback or capture)
- * @active:            flag indicating if the stream is active
- * @psc_i2s:           pointer back to parent psc_i2s data structure
- * @bcom_task:         bestcomm task structure
- * @irq:               irq number for bestcomm task
- * @period_start:      physical address of start of DMA region
- * @period_end:                physical address of end of DMA region
- * @period_next_pt:    physical address of next DMA buffer to enqueue
- * @period_bytes:      size of DMA period in bytes
- */
-struct psc_i2s_stream {
-       int active;
-       struct psc_i2s *psc_i2s;
-       struct bcom_task *bcom_task;
-       int irq;
-       struct snd_pcm_substream *stream;
-       dma_addr_t period_start;
-       dma_addr_t period_end;
-       dma_addr_t period_next_pt;
-       dma_addr_t period_current_pt;
-       int period_bytes;
-};
-
-/**
- * psc_i2s - Private driver data
- * @name: short name for this device ("PSC0", "PSC1", etc)
- * @psc_regs: pointer to the PSC's registers
- * @fifo_regs: pointer to the PSC's FIFO registers
- * @irq: IRQ of this PSC
- * @dev: struct device pointer
- * @dai: the CPU DAI for this device
- * @sicr: Base value used in serial interface control register; mode is ORed
- *        with this value.
- * @playback: Playback stream context data
- * @capture: Capture stream context data
- */
-struct psc_i2s {
-       char name[32];
-       struct mpc52xx_psc __iomem *psc_regs;
-       struct mpc52xx_psc_fifo __iomem *fifo_regs;
-       unsigned int irq;
-       struct device *dev;
-       struct snd_soc_dai dai;
-       spinlock_t lock;
-       u32 sicr;
-
-       /* per-stream data */
-       struct psc_i2s_stream playback;
-       struct psc_i2s_stream capture;
-
-       /* Statistics */
-       struct {
-               int overrun_count;
-               int underrun_count;
-       } stats;
-};
-
-/*
- * Interrupt handlers
- */
-static irqreturn_t psc_i2s_status_irq(int irq, void *_psc_i2s)
-{
-       struct psc_i2s *psc_i2s = _psc_i2s;
-       struct mpc52xx_psc __iomem *regs = psc_i2s->psc_regs;
-       u16 isr;
-
-       isr = in_be16(&regs->mpc52xx_psc_isr);
-
-       /* Playback underrun error */
-       if (psc_i2s->playback.active && (isr & MPC52xx_PSC_IMR_TXEMP))
-               psc_i2s->stats.underrun_count++;
-
-       /* Capture overrun error */
-       if (psc_i2s->capture.active && (isr & MPC52xx_PSC_IMR_ORERR))
-               psc_i2s->stats.overrun_count++;
-
-       out_8(&regs->command, 4 << 4);  /* reset the error status */
-
-       return IRQ_HANDLED;
-}
-
-/**
- * psc_i2s_bcom_enqueue_next_buffer - Enqueue another audio buffer
- * @s: pointer to stream private data structure
- *
- * Enqueues another audio period buffer into the bestcomm queue.
- *
- * Note: The routine must only be called when there is space available in
- * the queue.  Otherwise the enqueue will fail and the audio ring buffer
- * will get out of sync
- */
-static void psc_i2s_bcom_enqueue_next_buffer(struct psc_i2s_stream *s)
-{
-       struct bcom_bd *bd;
-
-       /* Prepare and enqueue the next buffer descriptor */
-       bd = bcom_prepare_next_buffer(s->bcom_task);
-       bd->status = s->period_bytes;
-       bd->data[0] = s->period_next_pt;
-       bcom_submit_next_buffer(s->bcom_task, NULL);
-
-       /* Update for next period */
-       s->period_next_pt += s->period_bytes;
-       if (s->period_next_pt >= s->period_end)
-               s->period_next_pt = s->period_start;
-}
-
-/* Bestcomm DMA irq handler */
-static irqreturn_t psc_i2s_bcom_irq(int irq, void *_psc_i2s_stream)
-{
-       struct psc_i2s_stream *s = _psc_i2s_stream;
-
-       /* For each finished period, dequeue the completed period buffer
-        * and enqueue a new one in it's place. */
-       while (bcom_buffer_done(s->bcom_task)) {
-               bcom_retrieve_buffer(s->bcom_task, NULL, NULL);
-               s->period_current_pt += s->period_bytes;
-               if (s->period_current_pt >= s->period_end)
-                       s->period_current_pt = s->period_start;
-               psc_i2s_bcom_enqueue_next_buffer(s);
-               bcom_enable(s->bcom_task);
-       }
-
-       /* If the stream is active, then also inform the PCM middle layer
-        * of the period finished event. */
-       if (s->active)
-               snd_pcm_period_elapsed(s->stream);
-
-       return IRQ_HANDLED;
-}
-
-/**
- * psc_i2s_startup: create a new substream
- *
- * This is the first function called when a stream is opened.
- *
- * If this is the first stream open, then grab the IRQ and program most of
- * the PSC registers.
- */
-static int psc_i2s_startup(struct snd_pcm_substream *substream,
-                          struct snd_soc_dai *dai)
-{
-       struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct psc_i2s *psc_i2s = rtd->dai->cpu_dai->private_data;
-       int rc;
-
-       dev_dbg(psc_i2s->dev, "psc_i2s_startup(substream=%p)\n", substream);
-
-       if (!psc_i2s->playback.active &&
-           !psc_i2s->capture.active) {
-               /* Setup the IRQs */
-               rc = request_irq(psc_i2s->irq, &psc_i2s_status_irq, IRQF_SHARED,
-                                "psc-i2s-status", psc_i2s);
-               rc |= request_irq(psc_i2s->capture.irq,
-                                 &psc_i2s_bcom_irq, IRQF_SHARED,
-                                 "psc-i2s-capture", &psc_i2s->capture);
-               rc |= request_irq(psc_i2s->playback.irq,
-                                 &psc_i2s_bcom_irq, IRQF_SHARED,
-                                 "psc-i2s-playback", &psc_i2s->playback);
-               if (rc) {
-                       free_irq(psc_i2s->irq, psc_i2s);
-                       free_irq(psc_i2s->capture.irq,
-                                &psc_i2s->capture);
-                       free_irq(psc_i2s->playback.irq,
-                                &psc_i2s->playback);
-                       return -ENODEV;
-               }
-       }
-
-       return 0;
-}
-
  static int psc_i2s_hw_params(struct snd_pcm_substream *substream,
                                 struct snd_pcm_hw_params *params,
                                 struct snd_soc_dai *dai)
@@ -258,164 +87,6 @@ static int psc_i2s_hw_params(struct snd_pcm_substream *substream,
        return 0;
  }
 
-static int psc_i2s_hw_free(struct snd_pcm_substream *substream,
-                          struct snd_soc_dai *dai)
-{
-       snd_pcm_set_runtime_buffer(substream, NULL);
-       return 0;
-}
-
-/**
- * psc_i2s_trigger: start and stop the DMA transfer.
- *
- * This function is called by ALSA to start, stop, pause, and resume the DMA
- * transfer of data.
- */
-static int psc_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
-                          struct snd_soc_dai *dai)
-{
-       struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct psc_i2s *psc_i2s = rtd->dai->cpu_dai->private_data;
-       struct snd_pcm_runtime *runtime = substream->runtime;
-       struct psc_i2s_stream *s;
-       struct mpc52xx_psc __iomem *regs = psc_i2s->psc_regs;
-       u16 imr;
-       u8 psc_cmd;
-       unsigned long flags;
-
-       if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE)
-               s = &psc_i2s->capture;
-       else
-               s = &psc_i2s->playback;
-
-       dev_dbg(psc_i2s->dev, "psc_i2s_trigger(substream=%p, cmd=%i)"
-               " stream_id=%i\n",
-               substream, cmd, substream->pstr->stream);
-
-       switch (cmd) {
-       case SNDRV_PCM_TRIGGER_START:
-               s->period_bytes = frames_to_bytes(runtime,
-                                                 runtime->period_size);
-               s->period_start = virt_to_phys(runtime->dma_area);
-               s->period_end = s->period_start +
-                               (s->period_bytes * runtime->periods);
-               s->period_next_pt = s->period_start;
-               s->period_current_pt = s->period_start;
-               s->active = 1;
-
-               /* First; reset everything */
-               if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE) {
-                       out_8(&regs->command, MPC52xx_PSC_RST_RX);
-                       out_8(&regs->command, MPC52xx_PSC_RST_ERR_STAT);
-               } else {
-                       out_8(&regs->command, MPC52xx_PSC_RST_TX);
-                       out_8(&regs->command, MPC52xx_PSC_RST_ERR_STAT);
-               }
-
-               /* Next, fill up the bestcomm bd queue and enable DMA.
-                * This will begin filling the PSC's fifo. */
-               if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE)
-                       bcom_gen_bd_rx_reset(s->bcom_task);
-               else
-                       bcom_gen_bd_tx_reset(s->bcom_task);
-               while (!bcom_queue_full(s->bcom_task))
-                       psc_i2s_bcom_enqueue_next_buffer(s);
-               bcom_enable(s->bcom_task);
-
-               /* Due to errata in the i2s mode; need to line up enabling
-                * the transmitter with a transition on the frame sync
-                * line */
-
-               spin_lock_irqsave(&psc_i2s->lock, flags);
-               /* first make sure it is low */
-               while ((in_8(&regs->ipcr_acr.ipcr) & 0x80) != 0)
-                       ;
-               /* then wait for the transition to high */
-               while ((in_8(&regs->ipcr_acr.ipcr) & 0x80) == 0)
-                       ;
-               /* Finally, enable the PSC.
-                * Receiver must always be enabled; even when we only want
-                * transmit.  (see 15.3.2.3 of MPC5200B User's Guide) */
-               psc_cmd = MPC52xx_PSC_RX_ENABLE;
-               if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK)
-                       psc_cmd |= MPC52xx_PSC_TX_ENABLE;
-               out_8(&regs->command, psc_cmd);
-               spin_unlock_irqrestore(&psc_i2s->lock, flags);
-
-               break;
-
-       case SNDRV_PCM_TRIGGER_STOP:
-               /* Turn off the PSC */
-               s->active = 0;
-               if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE) {
-                       if (!psc_i2s->playback.active) {
-                               out_8(&regs->command, 2 << 4);  /* reset rx */
-                               out_8(&regs->command, 3 << 4);  /* reset tx */
-                               out_8(&regs->command, 4 << 4);  /* reset err */
-                       }
-               } else {
-                       out_8(&regs->command, 3 << 4);  /* reset tx */
-                       out_8(&regs->command, 4 << 4);  /* reset err */
-                       if (!psc_i2s->capture.active)
-                               out_8(&regs->command, 2 << 4);  /* reset rx */
-               }
-
-               bcom_disable(s->bcom_task);
-               while (!bcom_queue_empty(s->bcom_task))
-                       bcom_retrieve_buffer(s->bcom_task, NULL, NULL);
-
-               break;
-
-       default:
-               dev_dbg(psc_i2s->dev, "invalid command\n");
-               return -EINVAL;
-       }
-
-       /* Update interrupt enable settings */
-       imr = 0;
-       if (psc_i2s->playback.active)
-               imr |= MPC52xx_PSC_IMR_TXEMP;
-       if (psc_i2s->capture.active)
-               imr |= MPC52xx_PSC_IMR_ORERR;
-       out_be16(&regs->isr_imr.imr, imr);
-
-       return 0;
-}
-
-/**
- * psc_i2s_shutdown: shutdown the data transfer on a stream
- *
- * Shutdown the PSC if there are no other substreams open.
- */
-static void psc_i2s_shutdown(struct snd_pcm_substream *substream,
-                            struct snd_soc_dai *dai)
-{
-       struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct psc_i2s *psc_i2s = rtd->dai->cpu_dai->private_data;
-
-       dev_dbg(psc_i2s->dev, "psc_i2s_shutdown(substream=%p)\n", substream);
-
-       /*
-        * If this is the last active substream, disable the PSC and release
-        * the IRQ.
-        */
-       if (!psc_i2s->playback.active &&
-           !psc_i2s->capture.active) {
-
-               /* Disable all interrupts and reset the PSC */
-               out_be16(&psc_i2s->psc_regs->isr_imr.imr, 0);
-               out_8(&psc_i2s->psc_regs->command, 3 << 4); /* reset tx */
-               out_8(&psc_i2s->psc_regs->command, 2 << 4); /* reset rx */
-               out_8(&psc_i2s->psc_regs->command, 1 << 4); /* reset mode */
-               out_8(&psc_i2s->psc_regs->command, 4 << 4); /* reset error */
-
-               /* Release irqs */
-               free_irq(psc_i2s->irq, psc_i2s);
-               free_irq(psc_i2s->capture.irq, &psc_i2s->capture);
-               free_irq(psc_i2s->playback.irq, &psc_i2s->playback);
-       }
-}
-
  /**
  * psc_i2s_set_sysclk: set the clock frequency and direction
  *
@@ -495,158 +166,6 @@ static struct snd_soc_dai psc_i2s_dai_template = {
  };
 
  /* ---------------------------------------------------------------------
- * The PSC I2S 'ASoC platform' driver
- *
- * Can be referenced by an 'ASoC machine' driver
- * This driver only deals with the audio bus; it doesn't have any
- * interaction with the attached codec
- */
-
-static const struct snd_pcm_hardware psc_i2s_pcm_hardware = {
-       .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID |
-               SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
-               SNDRV_PCM_INFO_BATCH,
-       .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_BE |
-                  SNDRV_PCM_FMTBIT_S24_BE | SNDRV_PCM_FMTBIT_S32_BE,
-       .rate_min = 8000,
-       .rate_max = 48000,
-       .channels_min = 2,
-       .channels_max = 2,
-       .period_bytes_max       = 1024 * 1024,
-       .period_bytes_min       = 32,
-       .periods_min            = 2,
-       .periods_max            = 256,
-       .buffer_bytes_max       = 2 * 1024 * 1024,
-       .fifo_size              = 0,
-};
-
-static int psc_i2s_pcm_open(struct snd_pcm_substream *substream)
-{
-       struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct psc_i2s *psc_i2s = rtd->dai->cpu_dai->private_data;
-       struct psc_i2s_stream *s;
-
-       dev_dbg(psc_i2s->dev, "psc_i2s_pcm_open(substream=%p)\n", substream);
-
-       if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE)
-               s = &psc_i2s->capture;
-       else
-               s = &psc_i2s->playback;
-
-       snd_soc_set_runtime_hwparams(substream, &psc_i2s_pcm_hardware);
-
-       s->stream = substream;
-       return 0;
-}
-
-static int psc_i2s_pcm_close(struct snd_pcm_substream *substream)
-{
-       struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct psc_i2s *psc_i2s = rtd->dai->cpu_dai->private_data;
-       struct psc_i2s_stream *s;
-
-       dev_dbg(psc_i2s->dev, "psc_i2s_pcm_close(substream=%p)\n", substream);
-
-       if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE)
-               s = &psc_i2s->capture;
-       else
-               s = &psc_i2s->playback;
-
-       s->stream = NULL;
-       return 0;
-}
-
-static snd_pcm_uframes_t
-psc_i2s_pcm_pointer(struct snd_pcm_substream *substream)
-{
-       struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct psc_i2s *psc_i2s = rtd->dai->cpu_dai->private_data;
-       struct psc_i2s_stream *s;
-       dma_addr_t count;
-
-       if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE)
-               s = &psc_i2s->capture;
-       else
-               s = &psc_i2s->playback;
-
-       count = s->period_current_pt - s->period_start;
-
-       return bytes_to_frames(substream->runtime, count);
-}
-
-static struct snd_pcm_ops psc_i2s_pcm_ops = {
-       .open           = psc_i2s_pcm_open,
-       .close          = psc_i2s_pcm_close,
-       .ioctl          = snd_pcm_lib_ioctl,
-       .pointer        = psc_i2s_pcm_pointer,
-};
-
-static u64 psc_i2s_pcm_dmamask = 0xffffffff;
-static int psc_i2s_pcm_new(struct snd_card *card, struct snd_soc_dai *dai,
-                          struct snd_pcm *pcm)
-{
-       struct snd_soc_pcm_runtime *rtd = pcm->private_data;
-       size_t size = psc_i2s_pcm_hardware.buffer_bytes_max;
-       int rc = 0;
-
-       dev_dbg(rtd->socdev->dev, "psc_i2s_pcm_new(card=%p, dai=%p, pcm=%p)\n",
-               card, dai, pcm);
-
-       if (!card->dev->dma_mask)
-               card->dev->dma_mask = &psc_i2s_pcm_dmamask;
-       if (!card->dev->coherent_dma_mask)
-               card->dev->coherent_dma_mask = 0xffffffff;
-
-       if (pcm->streams[0].substream) {
-               rc = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, pcm->dev, size,
-                                       &pcm->streams[0].substream->dma_buffer);
-               if (rc)
-                       goto playback_alloc_err;
-       }
-
-       if (pcm->streams[1].substream) {
-               rc = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, pcm->dev, size,
-                                       &pcm->streams[1].substream->dma_buffer);
-               if (rc)
-                       goto capture_alloc_err;
-       }
-
-       return 0;
-
- capture_alloc_err:
-       if (pcm->streams[0].substream)
-               snd_dma_free_pages(&pcm->streams[0].substream->dma_buffer);
- playback_alloc_err:
-       dev_err(card->dev, "Cannot allocate buffer(s)\n");
-       return -ENOMEM;
-}
-
-static void psc_i2s_pcm_free(struct snd_pcm *pcm)
-{
-       struct snd_soc_pcm_runtime *rtd = pcm->private_data;
-       struct snd_pcm_substream *substream;
-       int stream;
-
-       dev_dbg(rtd->socdev->dev, "psc_i2s_pcm_free(pcm=%p)\n", pcm);
-
-       for (stream = 0; stream < 2; stream++) {
-               substream = pcm->streams[stream].substream;
-               if (substream) {
-                       snd_dma_free_pages(&substream->dma_buffer);
-                       substream->dma_buffer.area = NULL;
-                       substream->dma_buffer.addr = 0;
-               }
-       }
-}
-
-struct snd_soc_platform psc_i2s_pcm_soc_platform = {
-       .name           = "mpc5200-psc-audio",
-       .pcm_ops        = &psc_i2s_pcm_ops,
-       .pcm_new        = &psc_i2s_pcm_new,
-       .pcm_free       = &psc_i2s_pcm_free,
-};
-
-/* ---------------------------------------------------------------------
  * Sysfs attributes for debugging
  */
 
Signature · 2 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
author
#8 lore raw

PATCH v2 3/9 Rename the PSC functions to DMA

In reply to Jon Smirl

Rename the functions in the mpc5200 DMA file from i2s based names to dma ones to reflect the file they are in.

---
 sound/soc/fsl/mpc5200_dma.c     |  194 ++++++++++++++++++++-------------------
 sound/soc/fsl/mpc5200_dma.h     |   26 +++--
 sound/soc/fsl/mpc5200_psc_i2s.c |  160 ++++++++++++++++----------------
 3 files changed, 190 insertions(+), 190 deletions(-)
sound/soc/fsl/mpc5200_dma.c +97 -97
index 4bae8d6..6850392 100644
@@ -34,21 +34,21 @@ MODULE_LICENSE("GPL");
 /*
  * Interrupt handlers
  */
-static irqreturn_t psc_i2s_status_irq(int irq, void *_psc_i2s)
+static irqreturn_t psc_dma_status_irq(int irq, void *_psc_dma)
 {
-	struct psc_i2s *psc_i2s = _psc_i2s;
-	struct mpc52xx_psc __iomem *regs = psc_i2s->psc_regs;
+	struct psc_dma *psc_dma = _psc_dma;
+	struct mpc52xx_psc __iomem *regs = psc_dma->psc_regs;
 	u16 isr;
 
 	isr = in_be16(&regs->mpc52xx_psc_isr);
 
 	/* Playback underrun error */
-	if (psc_i2s->playback.active && (isr & MPC52xx_PSC_IMR_TXEMP))
-		psc_i2s->stats.underrun_count++;
+	if (psc_dma->playback.active && (isr & MPC52xx_PSC_IMR_TXEMP))
+		psc_dma->stats.underrun_count++;
 
 	/* Capture overrun error */
-	if (psc_i2s->capture.active && (isr & MPC52xx_PSC_IMR_ORERR))
-		psc_i2s->stats.overrun_count++;
+	if (psc_dma->capture.active && (isr & MPC52xx_PSC_IMR_ORERR))
+		psc_dma->stats.overrun_count++;
 
 	out_8(&regs->command, 4 << 4);	/* reset the error status */
 
@@ -56,7 +56,7 @@ static irqreturn_t psc_i2s_status_irq(int irq, void *_psc_i2s)
 }
 
 /**
- * psc_i2s_bcom_enqueue_next_buffer - Enqueue another audio buffer
+ * psc_dma_bcom_enqueue_next_buffer - Enqueue another audio buffer
  * @s: pointer to stream private data structure
  *
  * Enqueues another audio period buffer into the bestcomm queue.
@@ -65,7 +65,7 @@ static irqreturn_t psc_i2s_status_irq(int irq, void *_psc_i2s)
  * the queue.  Otherwise the enqueue will fail and the audio ring buffer
  * will get out of sync
  */
-static void psc_i2s_bcom_enqueue_next_buffer(struct psc_i2s_stream *s)
+static void psc_dma_bcom_enqueue_next_buffer(struct psc_dma_stream *s)
 {
 	struct bcom_bd *bd;
 
@@ -82,9 +82,9 @@ static void psc_i2s_bcom_enqueue_next_buffer(struct psc_i2s_stream *s)
 }
 
 /* Bestcomm DMA irq handler */
-static irqreturn_t psc_i2s_bcom_irq(int irq, void *_psc_i2s_stream)
+static irqreturn_t psc_dma_bcom_irq(int irq, void *_psc_dma_stream)
 {
-	struct psc_i2s_stream *s = _psc_i2s_stream;
+	struct psc_dma_stream *s = _psc_dma_stream;
 
 	/* For each finished period, dequeue the completed period buffer
 	 * and enqueue a new one in it's place. */
@@ -93,7 +93,7 @@ static irqreturn_t psc_i2s_bcom_irq(int irq, void *_psc_i2s_stream)
 		s->period_current_pt += s->period_bytes;
 		if (s->period_current_pt >= s->period_end)
 			s->period_current_pt = s->period_start;
-		psc_i2s_bcom_enqueue_next_buffer(s);
+		psc_dma_bcom_enqueue_next_buffer(s);
 		bcom_enable(s->bcom_task);
 	}
 
@@ -106,39 +106,39 @@ static irqreturn_t psc_i2s_bcom_irq(int irq, void *_psc_i2s_stream)
 }
 
 /**
- * psc_i2s_startup: create a new substream
+ * psc_dma_startup: create a new substream
  *
  * This is the first function called when a stream is opened.
  *
  * If this is the first stream open, then grab the IRQ and program most of
  * the PSC registers.
  */
-int psc_i2s_startup(struct snd_pcm_substream *substream,
+int psc_dma_startup(struct snd_pcm_substream *substream,
 			   struct snd_soc_dai *dai)
 {
 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
-	struct psc_i2s *psc_i2s = rtd->dai->cpu_dai->private_data;
+	struct psc_dma *psc_dma = rtd->dai->cpu_dai->private_data;
 	int rc;
 
-	dev_dbg(psc_i2s->dev, "psc_i2s_startup(substream=%p)\n", substream);
+	dev_dbg(psc_dma->dev, "psc_dma_startup(substream=%p)\n", substream);
 
-	if (!psc_i2s->playback.active &&
-	    !psc_i2s->capture.active) {
+	if (!psc_dma->playback.active &&
+	    !psc_dma->capture.active) {
 		/* Setup the IRQs */
-		rc = request_irq(psc_i2s->irq, &psc_i2s_status_irq, IRQF_SHARED,
-				 "psc-i2s-status", psc_i2s);
-		rc |= request_irq(psc_i2s->capture.irq,
-				  &psc_i2s_bcom_irq, IRQF_SHARED,
-				  "psc-i2s-capture", &psc_i2s->capture);
-		rc |= request_irq(psc_i2s->playback.irq,
-				  &psc_i2s_bcom_irq, IRQF_SHARED,
-				  "psc-i2s-playback", &psc_i2s->playback);
+		rc = request_irq(psc_dma->irq, &psc_dma_status_irq, IRQF_SHARED,
+				 "psc-dma-status", psc_dma);
+		rc |= request_irq(psc_dma->capture.irq,
+				  &psc_dma_bcom_irq, IRQF_SHARED,
+				  "psc-dma-capture", &psc_dma->capture);
+		rc |= request_irq(psc_dma->playback.irq,
+				  &psc_dma_bcom_irq, IRQF_SHARED,
+				  "psc-dma-playback", &psc_dma->playback);
 		if (rc) {
-			free_irq(psc_i2s->irq, psc_i2s);
-			free_irq(psc_i2s->capture.irq,
-				 &psc_i2s->capture);
-			free_irq(psc_i2s->playback.irq,
-				 &psc_i2s->playback);
+			free_irq(psc_dma->irq, psc_dma);
+			free_irq(psc_dma->capture.irq,
+				 &psc_dma->capture);
+			free_irq(psc_dma->playback.irq,
+				 &psc_dma->playback);
 			return -ENODEV;
 		}
 	}
@@ -146,7 +146,7 @@ int psc_i2s_startup(struct snd_pcm_substream *substream,
 	return 0;
 }
 
-int psc_i2s_hw_free(struct snd_pcm_substream *substream,
+int psc_dma_hw_free(struct snd_pcm_substream *substream,
 			   struct snd_soc_dai *dai)
 {
 	snd_pcm_set_runtime_buffer(substream, NULL);
@@ -154,29 +154,29 @@ int psc_i2s_hw_free(struct snd_pcm_substream *substream,
 }
 
 /**
- * psc_i2s_trigger: start and stop the DMA transfer.
+ * psc_dma_trigger: start and stop the DMA transfer.
  *
  * This function is called by ALSA to start, stop, pause, and resume the DMA
  * transfer of data.
  */
-int psc_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
+int psc_dma_trigger(struct snd_pcm_substream *substream, int cmd,
 			   struct snd_soc_dai *dai)
 {
 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
-	struct psc_i2s *psc_i2s = rtd->dai->cpu_dai->private_data;
+	struct psc_dma *psc_dma = rtd->dai->cpu_dai->private_data;
 	struct snd_pcm_runtime *runtime = substream->runtime;
-	struct psc_i2s_stream *s;
-	struct mpc52xx_psc __iomem *regs = psc_i2s->psc_regs;
+	struct psc_dma_stream *s;
+	struct mpc52xx_psc __iomem *regs = psc_dma->psc_regs;
 	u16 imr;
 	u8 psc_cmd;
 	unsigned long flags;
 
 	if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE)
-		s = &psc_i2s->capture;
+		s = &psc_dma->capture;
 	else
-		s = &psc_i2s->playback;
+		s = &psc_dma->playback;
 
-	dev_dbg(psc_i2s->dev, "psc_i2s_trigger(substream=%p, cmd=%i)"
+	dev_dbg(psc_dma->dev, "psc_dma_trigger(substream=%p, cmd=%i)"
 		" stream_id=%i\n",
 		substream, cmd, substream->pstr->stream);
 
@@ -207,14 +207,14 @@ int psc_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
 		else
 			bcom_gen_bd_tx_reset(s->bcom_task);
 		while (!bcom_queue_full(s->bcom_task))
-			psc_i2s_bcom_enqueue_next_buffer(s);
+			psc_dma_bcom_enqueue_next_buffer(s);
 		bcom_enable(s->bcom_task);
 
-		/* Due to errata in the i2s mode; need to line up enabling
+		/* Due to errata in the dma mode; need to line up enabling
 		 * the transmitter with a transition on the frame sync
 		 * line */
 
-		spin_lock_irqsave(&psc_i2s->lock, flags);
+		spin_lock_irqsave(&psc_dma->lock, flags);
 		/* first make sure it is low */
 		while ((in_8(&regs->ipcr_acr.ipcr) & 0x80) != 0)
 			;
@@ -228,7 +228,7 @@ int psc_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
 		if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK)
 			psc_cmd |= MPC52xx_PSC_TX_ENABLE;
 		out_8(&regs->command, psc_cmd);
-		spin_unlock_irqrestore(&psc_i2s->lock, flags);
+		spin_unlock_irqrestore(&psc_dma->lock, flags);
 
 		break;
 
@@ -236,7 +236,7 @@ int psc_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
 		/* Turn off the PSC */
 		s->active = 0;
 		if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE) {
-			if (!psc_i2s->playback.active) {
+			if (!psc_dma->playback.active) {
 				out_8(&regs->command, 2 << 4);	/* reset rx */
 				out_8(&regs->command, 3 << 4);	/* reset tx */
 				out_8(&regs->command, 4 << 4);	/* reset err */
@@ -244,7 +244,7 @@ int psc_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
 		} else {
 			out_8(&regs->command, 3 << 4);	/* reset tx */
 			out_8(&regs->command, 4 << 4);	/* reset err */
-			if (!psc_i2s->capture.active)
+			if (!psc_dma->capture.active)
 				out_8(&regs->command, 2 << 4);	/* reset rx */
 		}
 
@@ -255,15 +255,15 @@ int psc_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
 		break;
 
 	default:
-		dev_dbg(psc_i2s->dev, "invalid command\n");
+		dev_dbg(psc_dma->dev, "invalid command\n");
 		return -EINVAL;
 	}
 
 	/* Update interrupt enable settings */
 	imr = 0;
-	if (psc_i2s->playback.active)
+	if (psc_dma->playback.active)
 		imr |= MPC52xx_PSC_IMR_TXEMP;
-	if (psc_i2s->capture.active)
+	if (psc_dma->capture.active)
 		imr |= MPC52xx_PSC_IMR_ORERR;
 	out_be16(&regs->isr_imr.imr, imr);
 
@@ -271,36 +271,36 @@ int psc_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
 }
 
 /**
- * psc_i2s_shutdown: shutdown the data transfer on a stream
+ * psc_dma_shutdown: shutdown the data transfer on a stream
  *
  * Shutdown the PSC if there are no other substreams open.
  */
-void psc_i2s_shutdown(struct snd_pcm_substream *substream,
+void psc_dma_shutdown(struct snd_pcm_substream *substream,
 			     struct snd_soc_dai *dai)
 {
 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
-	struct psc_i2s *psc_i2s = rtd->dai->cpu_dai->private_data;
+	struct psc_dma *psc_dma = rtd->dai->cpu_dai->private_data;
 
-	dev_dbg(psc_i2s->dev, "psc_i2s_shutdown(substream=%p)\n", substream);
+	dev_dbg(psc_dma->dev, "psc_dma_shutdown(substream=%p)\n", substream);
 
 	/*
 	 * If this is the last active substream, disable the PSC and release
 	 * the IRQ.
 	 */
-	if (!psc_i2s->playback.active &&
-	    !psc_i2s->capture.active) {
+	if (!psc_dma->playback.active &&
+	    !psc_dma->capture.active) {
 
 		/* Disable all interrupts and reset the PSC */
-		out_be16(&psc_i2s->psc_regs->isr_imr.imr, 0);
-		out_8(&psc_i2s->psc_regs->command, 3 << 4); /* reset tx */
-		out_8(&psc_i2s->psc_regs->command, 2 << 4); /* reset rx */
-		out_8(&psc_i2s->psc_regs->command, 1 << 4); /* reset mode */
-		out_8(&psc_i2s->psc_regs->command, 4 << 4); /* reset error */
+		out_be16(&psc_dma->psc_regs->isr_imr.imr, 0);
+		out_8(&psc_dma->psc_regs->command, 3 << 4); /* reset tx */
+		out_8(&psc_dma->psc_regs->command, 2 << 4); /* reset rx */
+		out_8(&psc_dma->psc_regs->command, 1 << 4); /* reset mode */
+		out_8(&psc_dma->psc_regs->command, 4 << 4); /* reset error */
 
 		/* Release irqs */
-		free_irq(psc_i2s->irq, psc_i2s);
-		free_irq(psc_i2s->capture.irq, &psc_i2s->capture);
-		free_irq(psc_i2s->playback.irq, &psc_i2s->playback);
+		free_irq(psc_dma->irq, psc_dma);
+		free_irq(psc_dma->capture.irq, &psc_dma->capture);
+		free_irq(psc_dma->playback.irq, &psc_dma->playback);
 	}
 }
 
@@ -312,7 +312,7 @@ void psc_i2s_shutdown(struct snd_pcm_substream *substream,
  * interaction with the attached codec
  */
 
-static const struct snd_pcm_hardware psc_i2s_pcm_hardware = {
+static const struct snd_pcm_hardware psc_dma_pcm_hardware = {
 	.info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID |
 		SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
 		SNDRV_PCM_INFO_BATCH,
@@ -330,80 +330,80 @@ static const struct snd_pcm_hardware psc_i2s_pcm_hardware = {
 	.fifo_size		= 0,
 };
 
-static int psc_i2s_pcm_open(struct snd_pcm_substream *substream)
+static int psc_dma_pcm_open(struct snd_pcm_substream *substream)
 {
 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
-	struct psc_i2s *psc_i2s = rtd->dai->cpu_dai->private_data;
-	struct psc_i2s_stream *s;
+	struct psc_dma *psc_dma = rtd->dai->cpu_dai->private_data;
+	struct psc_dma_stream *s;
 
-	dev_dbg(psc_i2s->dev, "psc_i2s_pcm_open(substream=%p)\n", substream);
+	dev_dbg(psc_dma->dev, "psc_dma_pcm_open(substream=%p)\n", substream);
 
 	if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE)
-		s = &psc_i2s->capture;
+		s = &psc_dma->capture;
 	else
-		s = &psc_i2s->playback;
+		s = &psc_dma->playback;
 
-	snd_soc_set_runtime_hwparams(substream, &psc_i2s_pcm_hardware);
+	snd_soc_set_runtime_hwparams(substream, &psc_dma_pcm_hardware);
 
 	s->stream = substream;
 	return 0;
 }
 
-static int psc_i2s_pcm_close(struct snd_pcm_substream *substream)
+static int psc_dma_pcm_close(struct snd_pcm_substream *substream)
 {
 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
-	struct psc_i2s *psc_i2s = rtd->dai->cpu_dai->private_data;
-	struct psc_i2s_stream *s;
+	struct psc_dma *psc_dma = rtd->dai->cpu_dai->private_data;
+	struct psc_dma_stream *s;
 
-	dev_dbg(psc_i2s->dev, "psc_i2s_pcm_close(substream=%p)\n", substream);
+	dev_dbg(psc_dma->dev, "psc_dma_pcm_close(substream=%p)\n", substream);
 
 	if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE)
-		s = &psc_i2s->capture;
+		s = &psc_dma->capture;
 	else
-		s = &psc_i2s->playback;
+		s = &psc_dma->playback;
 
 	s->stream = NULL;
 	return 0;
 }
 
 static snd_pcm_uframes_t
-psc_i2s_pcm_pointer(struct snd_pcm_substream *substream)
+psc_dma_pcm_pointer(struct snd_pcm_substream *substream)
 {
 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
-	struct psc_i2s *psc_i2s = rtd->dai->cpu_dai->private_data;
-	struct psc_i2s_stream *s;
+	struct psc_dma *psc_dma = rtd->dai->cpu_dai->private_data;
+	struct psc_dma_stream *s;
 	dma_addr_t count;
 
 	if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE)
-		s = &psc_i2s->capture;
+		s = &psc_dma->capture;
 	else
-		s = &psc_i2s->playback;
+		s = &psc_dma->playback;
 
 	count = s->period_current_pt - s->period_start;
 
 	return bytes_to_frames(substream->runtime, count);
 }
 
-static struct snd_pcm_ops psc_i2s_pcm_ops = {
-	.open		= psc_i2s_pcm_open,
-	.close		= psc_i2s_pcm_close,
+static struct snd_pcm_ops psc_dma_pcm_ops = {
+	.open		= psc_dma_pcm_open,
+	.close		= psc_dma_pcm_close,
 	.ioctl		= snd_pcm_lib_ioctl,
-	.pointer	= psc_i2s_pcm_pointer,
+	.pointer	= psc_dma_pcm_pointer,
 };
 
-static u64 psc_i2s_pcm_dmamask = 0xffffffff;
-static int psc_i2s_pcm_new(struct snd_card *card, struct snd_soc_dai *dai,
+static u64 psc_dma_pcm_dmamask = 0xffffffff;
+static int psc_dma_pcm_new(struct snd_card *card, struct snd_soc_dai *dai,
 			   struct snd_pcm *pcm)
 {
 	struct snd_soc_pcm_runtime *rtd = pcm->private_data;
-	size_t size = psc_i2s_pcm_hardware.buffer_bytes_max;
+	size_t size = psc_dma_pcm_hardware.buffer_bytes_max;
 	int rc = 0;
 
-	dev_dbg(rtd->socdev->dev, "psc_i2s_pcm_new(card=%p, dai=%p, pcm=%p)\n",
+	dev_dbg(rtd->socdev->dev, "psc_dma_pcm_new(card=%p, dai=%p, pcm=%p)\n",
 		card, dai, pcm);
 
 	if (!card->dev->dma_mask)
-		card->dev->dma_mask = &psc_i2s_pcm_dmamask;
+		card->dev->dma_mask = &psc_dma_pcm_dmamask;
 	if (!card->dev->coherent_dma_mask)
 		card->dev->coherent_dma_mask = 0xffffffff;
 
@@ -431,13 +431,13 @@ static int psc_i2s_pcm_new(struct snd_card *card, struct snd_soc_dai *dai,
 	return -ENOMEM;
 }
 
-static void psc_i2s_pcm_free(struct snd_pcm *pcm)
+static void psc_dma_pcm_free(struct snd_pcm *pcm)
 {
 	struct snd_soc_pcm_runtime *rtd = pcm->private_data;
 	struct snd_pcm_substream *substream;
 	int stream;
 
-	dev_dbg(rtd->socdev->dev, "psc_i2s_pcm_free(pcm=%p)\n", pcm);
+	dev_dbg(rtd->socdev->dev, "psc_dma_pcm_free(pcm=%p)\n", pcm);
 
 	for (stream = 0; stream < 2; stream++) {
 		substream = pcm->streams[stream].substream;
@@ -449,10 +449,10 @@ static void psc_i2s_pcm_free(struct snd_pcm *pcm)
 	}
 }
 
-struct snd_soc_platform psc_i2s_pcm_soc_platform = {
+struct snd_soc_platform psc_dma_pcm_soc_platform = {
 	.name		= "mpc5200-psc-audio",
-	.pcm_ops	= &psc_i2s_pcm_ops,
-	.pcm_new	= &psc_i2s_pcm_new,
-	.pcm_free	= &psc_i2s_pcm_free,
+	.pcm_ops	= &psc_dma_pcm_ops,
+	.pcm_new	= &psc_dma_pcm_new,
+	.pcm_free	= &psc_dma_pcm_free,
 };
 
sound/soc/fsl/mpc5200_dma.h +13 -13
index 9a19e8a..a33232c 100644
@@ -6,9 +6,9 @@
 #define __SOUND_SOC_FSL_MPC5200_DMA_H__
 
 /**
- * psc_i2s_stream - Data specific to a single stream (playback or capture)
+ * psc_dma_stream - Data specific to a single stream (playback or capture)
  * @active:		flag indicating if the stream is active
- * @psc_i2s:		pointer back to parent psc_i2s data structure
+ * @psc_dma:		pointer back to parent psc_dma data structure
  * @bcom_task:		bestcomm task structure
  * @irq:		irq number for bestcomm task
  * @period_start:	physical address of start of DMA region
@@ -16,9 +16,9 @@
  * @period_next_pt:	physical address of next DMA buffer to enqueue
  * @period_bytes:	size of DMA period in bytes
  */
-struct psc_i2s_stream {
+struct psc_dma_stream {
 	int active;
-	struct psc_i2s *psc_i2s;
+	struct psc_dma *psc_dma;
 	struct bcom_task *bcom_task;
 	int irq;
 	struct snd_pcm_substream *stream;
@@ -30,7 +30,7 @@ struct psc_i2s_stream {
 };
 
 /**
- * psc_i2s - Private driver data
+ * psc_dma - Private driver data
  * @name: short name for this device ("PSC0", "PSC1", etc)
  * @psc_regs: pointer to the PSC's registers
  * @fifo_regs: pointer to the PSC's FIFO registers
@@ -42,7 +42,7 @@ struct psc_i2s_stream {
  * @playback: Playback stream context data
  * @capture: Capture stream context data
  */
-struct psc_i2s {
+struct psc_dma {
 	char name[32];
 	struct mpc52xx_psc __iomem *psc_regs;
 	struct mpc52xx_psc_fifo __iomem *fifo_regs;
@@ -53,8 +53,8 @@ struct psc_i2s {
 	u32 sicr;
 
 	/* per-stream data */
-	struct psc_i2s_stream playback;
-	struct psc_i2s_stream capture;
+	struct psc_dma_stream playback;
+	struct psc_dma_stream capture;
 
 	/* Statistics */
 	struct {
@@ -64,18 +64,18 @@ struct psc_i2s {
 };
 
 
-int psc_i2s_startup(struct snd_pcm_substream *substream,
+int psc_dma_startup(struct snd_pcm_substream *substream,
 			   struct snd_soc_dai *dai);
 
-int psc_i2s_hw_free(struct snd_pcm_substream *substream,
+int psc_dma_hw_free(struct snd_pcm_substream *substream,
 			   struct snd_soc_dai *dai);
 
-void psc_i2s_shutdown(struct snd_pcm_substream *substream,
+void psc_dma_shutdown(struct snd_pcm_substream *substream,
 			     struct snd_soc_dai *dai);
 
-int psc_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
+int psc_dma_trigger(struct snd_pcm_substream *substream, int cmd,
 			   struct snd_soc_dai *dai);
 
-extern struct snd_soc_platform psc_i2s_pcm_soc_platform;
+extern struct snd_soc_platform psc_dma_pcm_soc_platform;
 
 #endif /* __SOUND_SOC_FSL_MPC5200_DMA_H__ */
sound/soc/fsl/mpc5200_psc_i2s.c +80 -80

288 lines not on this page · raw message

#9 lore raw

Re: [PATCH V2 3/9] Rename the PSC functions to DMA

Quoted 1 line · Jon Smirl

Rename the functions in the mpc5200 DMA file from i2s based names to dma ones to reflect the file they are in.

I'm OK with both these refactoring patches if Grant is - Grant, if I could get your ack I'd like to merge these as soon as possible since they're very big changes and it'd cut down on review effort.

Acked-by
#10 lore raw

Re: [PATCH V2 3/9] Rename the PSC functions to DMA

Quoted 6 lines · Mark Brown
Quoted 1 line · Jon Smirl

Rename the functions in the mpc5200 DMA file from i2s based names to dma ones to reflect the file they are in.

I'm OK with both these refactoring patches if Grant is - Grant, if I could get your ack I'd like to merge these as soon as possible since they're very big changes and it'd cut down on review effort.

Signature · 2 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
author
#11 lore raw

PATCH v2 4/9 Add a few more mpc5200 PSC defines

In reply to Jon Smirl

Add a few more mpc5200 PSC defines. More bit fields defines for mpc5200 PSC registers. This patch is going in via Grant's tree.

---

 0 files changed, 0 insertions(+), 0 deletions(-)
arch/powerpc/include/asm/mpc52xx_psc.h +11 -0
index a218da6..fb84120 100644
@@ -28,6 +28,10 @@
 #define MPC52xx_PSC_MAXNUM	6
 
 /* Programmable Serial Controller (PSC) status register bits */
+#define MPC52xx_PSC_SR_UNEX_RX	0x0001
+#define MPC52xx_PSC_SR_DATA_VAL	0x0002
+#define MPC52xx_PSC_SR_DATA_OVR	0x0004
+#define MPC52xx_PSC_SR_CMDSEND	0x0008
 #define MPC52xx_PSC_SR_CDE	0x0080
 #define MPC52xx_PSC_SR_RXRDY	0x0100
 #define MPC52xx_PSC_SR_RXFULL	0x0200
@@ -61,6 +65,12 @@
 #define MPC52xx_PSC_RXTX_FIFO_EMPTY	0x0001
 
 /* PSC interrupt status/mask bits */
+#define MPC52xx_PSC_IMR_UNEX_RX_SLOT 0x0001
+#define MPC52xx_PSC_IMR_DATA_VALID	0x0002
+#define MPC52xx_PSC_IMR_DATA_OVR	0x0004
+#define MPC52xx_PSC_IMR_CMD_SEND	0x0008
+#define MPC52xx_PSC_IMR_ERROR		0x0040
+#define MPC52xx_PSC_IMR_DEOF		0x0080
 #define MPC52xx_PSC_IMR_TXRDY		0x0100
 #define MPC52xx_PSC_IMR_RXRDY		0x0200
 #define MPC52xx_PSC_IMR_DB		0x0400
@@ -117,6 +127,7 @@
 #define MPC52xx_PSC_SICR_SIM_FIR		(0x6 << 24)
 #define MPC52xx_PSC_SICR_SIM_CODEC_24		(0x7 << 24)
 #define MPC52xx_PSC_SICR_SIM_CODEC_32		(0xf << 24)
+#define MPC52xx_PSC_SICR_AWR			(1 << 30)
 #define MPC52xx_PSC_SICR_GENCLK			(1 << 23)
 #define MPC52xx_PSC_SICR_I2S			(1 << 22)
 #define MPC52xx_PSC_SICR_CLKPOL			(1 << 21)
Acked-by on v2 4/9
#12 lore raw

Re: [PATCH V2 4/9] Add a few more mpc5200 PSC defines

Quoted 3 lines · Jon Smirl

Add a few more mpc5200 PSC defines. More bit fields defines for mpc5200 PSC registers. This patch is going in via Grant's tree.

Quoted 41 lines

---

 0 files changed, 0 insertions(+), 0 deletions(-)
arch/powerpc/include/asm/mpc52xx_psc.h +11 -0
index a218da6..fb84120 100644
@@ -28,6 +28,10 @@
  #define MPC52xx_PSC_MAXNUM     6
 
  /* Programmable Serial Controller (PSC) status register bits */
+#define MPC52xx_PSC_SR_UNEX_RX 0x0001
+#define MPC52xx_PSC_SR_DATA_VAL        0x0002
+#define MPC52xx_PSC_SR_DATA_OVR        0x0004
+#define MPC52xx_PSC_SR_CMDSEND 0x0008
  #define MPC52xx_PSC_SR_CDE     0x0080
  #define MPC52xx_PSC_SR_RXRDY   0x0100
  #define MPC52xx_PSC_SR_RXFULL  0x0200
@@ -61,6 +65,12 @@
  #define MPC52xx_PSC_RXTX_FIFO_EMPTY    0x0001
 
  /* PSC interrupt status/mask bits */
+#define MPC52xx_PSC_IMR_UNEX_RX_SLOT 0x0001
+#define MPC52xx_PSC_IMR_DATA_VALID     0x0002
+#define MPC52xx_PSC_IMR_DATA_OVR       0x0004
+#define MPC52xx_PSC_IMR_CMD_SEND       0x0008
+#define MPC52xx_PSC_IMR_ERROR          0x0040
+#define MPC52xx_PSC_IMR_DEOF           0x0080
  #define MPC52xx_PSC_IMR_TXRDY          0x0100
  #define MPC52xx_PSC_IMR_RXRDY          0x0200
  #define MPC52xx_PSC_IMR_DB             0x0400
@@ -117,6 +127,7 @@
  #define MPC52xx_PSC_SICR_SIM_FIR               (0x6 << 24)
  #define MPC52xx_PSC_SICR_SIM_CODEC_24          (0x7 << 24)
  #define MPC52xx_PSC_SICR_SIM_CODEC_32          (0xf << 24)
+#define MPC52xx_PSC_SICR_AWR                   (1 << 30)
  #define MPC52xx_PSC_SICR_GENCLK                        (1 << 23)
  #define MPC52xx_PSC_SICR_I2S                   (1 << 22)
  #define MPC52xx_PSC_SICR_CLKPOL                        (1 << 21)
Signature · 2 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
#13 lore raw

Re: [PATCH V2 4/9] Add a few more mpc5200 PSC defines

Quoted 6 lines · Grant Likely
Quoted 3 lines · Jon Smirl

Add a few more mpc5200 PSC defines. More bit fields defines for mpc5200 PSC registers. This patch is going in via Grant's tree.

Jon's commit log says this is going in via your tree - is that the case or should I apply it to ASoC?

#14 lore raw

Re: [PATCH V2 4/9] Add a few more mpc5200 PSC defines

Quoted 10 lines · Mark Brown
Quoted 6 lines · Grant Likely
Quoted 3 lines · Jon Smirl

Add a few more mpc5200 PSC defines. More bit fields defines for mpc5200 PSC registers. This patch is going in via Grant's tree.

Jon's commit log says this is going in via your tree - is that the case or should I apply it to ASoC?

Nothing else needs it in MPC5200 land and I haven't applied it to my tree yet. Go ahead and add it to the ASoC tree.

g.

Signature · 2 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
#15 lore raw

Re: [PATCH V2 4/9] Add a few more mpc5200 PSC defines

Quoted 2 lines · Grant Likely

Nothing else needs it in MPC5200 land and I haven't applied it to my tree yet. Go ahead and add it to the ASoC tree.

OK, applied this and the two refactoring patches - thanks!

author
#16 lore raw

PATCH v2 5/9 Main rewite of the mpc5200 audio DMA code

In reply to Jon Smirl

Rewrite the mpc5200 audio DMA code to support both I2S and AC97. Make it more robust.

---
 sound/soc/fsl/Kconfig           |    1 
 sound/soc/fsl/mpc5200_dma.c     |  505 ++++++++++++++++++++++++++-------------
 sound/soc/fsl/mpc5200_dma.h     |   29 +-
 sound/soc/fsl/mpc5200_psc_i2s.c |  243 +++----------------
 sound/soc/fsl/mpc5200_psc_i2s.h |   12 +
 5 files changed, 407 insertions(+), 383 deletions(-)
 create mode 100644 sound/soc/fsl/mpc5200_psc_i2s.h
sound/soc/fsl/Kconfig +0 -1
index dc79bdf..1918c78 100644
@@ -25,7 +25,6 @@ config SND_SOC_MPC8610_HPCD
 config SND_SOC_MPC5200_I2S
 	tristate "Freescale MPC5200 PSC in I2S mode driver"
 	depends on PPC_MPC52xx && PPC_BESTCOMM
-	select SND_SOC_OF_SIMPLE
 	select SND_MPC52xx_DMA
 	select PPC_BESTCOMM_GEN_BD
 	help
sound/soc/fsl/mpc5200_dma.c +341 -164

710 lines not on this page · raw message

sound/soc/fsl/mpc5200_dma.h +14 -15
index a33232c..3b2ded9 100644
@@ -5,8 +5,10 @@
 #ifndef __SOUND_SOC_FSL_MPC5200_DMA_H__
 #define __SOUND_SOC_FSL_MPC5200_DMA_H__
 
+#define PSC_STREAM_NAME_LEN 32
+
 /**
- * psc_dma_stream - Data specific to a single stream (playback or capture)
+ * psc_ac97_stream - Data specific to a single stream (playback or capture)
  * @active:		flag indicating if the stream is active
  * @psc_dma:		pointer back to parent psc_dma data structure
  * @bcom_task:		bestcomm task structure
@@ -17,6 +19,9 @@
  * @period_bytes:	size of DMA period in bytes
  */
 struct psc_dma_stream {
+	struct snd_pcm_runtime *runtime;
+	snd_pcm_uframes_t appl_ptr;
+
 	int active;
 	struct psc_dma *psc_dma;
 	struct bcom_task *bcom_task;
@@ -27,6 +32,7 @@ struct psc_dma_stream {
 	dma_addr_t period_next_pt;
 	dma_addr_t period_current_pt;
 	int period_bytes;
+	int period_size;
 };
 
 /**
@@ -48,9 +54,12 @@ struct psc_dma {
 	struct mpc52xx_psc_fifo __iomem *fifo_regs;
 	unsigned int irq;
 	struct device *dev;
-	struct snd_soc_dai dai;
 	spinlock_t lock;
 	u32 sicr;
+	uint sysclk;
+	int imr;
+	int id;
+	unsigned int slots;
 
 	/* per-stream data */
 	struct psc_dma_stream playback;
@@ -63,19 +72,9 @@ struct psc_dma {
 	} stats;
 };
 
+int mpc5200_audio_dma_create(struct of_device *op);
+int mpc5200_audio_dma_destroy(struct of_device *op);
 
-int psc_dma_startup(struct snd_pcm_substream *substream,
-			   struct snd_soc_dai *dai);
-
-int psc_dma_hw_free(struct snd_pcm_substream *substream,
-			   struct snd_soc_dai *dai);
-
-void psc_dma_shutdown(struct snd_pcm_substream *substream,
-			     struct snd_soc_dai *dai);
-
-int psc_dma_trigger(struct snd_pcm_substream *substream, int cmd,
-			   struct snd_soc_dai *dai);
-
-extern struct snd_soc_platform psc_dma_pcm_soc_platform;
+extern struct snd_soc_platform mpc5200_audio_dma_platform;
 
 #endif /* __SOUND_SOC_FSL_MPC5200_DMA_H__ */
sound/soc/fsl/mpc5200_psc_i2s.c +40 -203

327 lines not on this page · raw message

sound/soc/fsl/mpc5200_psc_i2s.h new file +12 -0
new file mode 100644
index 0000000..ce55e07
@@ -0,0 +1,12 @@
+/*
+ * Freescale MPC5200 PSC in I2S mode
+ * ALSA SoC Digital Audio Interface (DAI) driver
+ *
+ */
+
+#ifndef __SOUND_SOC_FSL_MPC52xx_PSC_I2S_H__
+#define __SOUND_SOC_FSL_MPC52xx_PSC_I2S_H__
+
+extern struct snd_soc_dai psc_i2s_dai[];
+
+#endif /* __SOUND_SOC_FSL_MPC52xx_PSC_I2S_H__ */
#17 lore raw

Re: [PATCH V2 5/9] Main rewite of the mpc5200 audio DMA code

On Sat, May 23, 2009 at 07:13:05PM -0400, Jon Smirl wrote:

This is all basically OK bearing in mind that I know nothing about the hardware. A couple of things, though:

Quoted 3 lines

+/* ---------------------------------------------------------------------
+ * Sysfs attributes for debugging
+ */

These look like they may be better placed in debugfs?

Quoted 6 lines
sound/soc/fsl/mpc5200_dma.c +4 -0
+EXPORT_SYMBOL_GPL(mpc5200_audio_dma_create);
 
+EXPORT_SYMBOL_GPL(mpc5200_audio_dma_destroy);
 
+static int __init mpc5200_soc_platform_init(void)
+{

sound/soc/fsl/mpc5200_dma.c static void psc_dma_pcm_free(struct snd_pcm *pcm) · line 631

Quoted 10 lines
sound/soc/fsl/mpc5200_dma.c +9 -0
+	/* Tell the ASoC OF helpers about it */
+	return snd_soc_register_platform(&mpc5200_audio_dma_platform);
+}
+module_init(mpc5200_soc_platform_init);
 
+static void __exit mpc5200_soc_platform_exit(void)
+{
+	snd_soc_unregister_platform(&mpc5200_audio_dma_platform);
+}
+module_exit(mpc5200_soc_platform_exit);

This all looks a bit odd - I'd expect to see the platform registering with the core when it is probed rather than on module load. Looking at the code it appears that you're automatically instantiating the DMA driver from the node for the DAI? If that is the case then you ought to be calling the platform registration functions from the dma_create() and dma_destroy() functions instead.

#18 lore raw

Re: [PATCH V2 5/9] Main rewite of the mpc5200 audio DMA code

In reply to Jon Smirl
Quoted 1 line

Rewrite the mpc5200 audio DMA code to support both I2S and AC97. Make it more robust.

Why is it more robust?

Signature · 2 lines
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://ozlabs.org/mailman/listinfo/linuxppc-dev

author
#19 lore raw

Re: [PATCH V2 5/9] Main rewite of the mpc5200 audio DMA code

Quoted 3 lines · Wolfram Sang
Quoted 1 line

Rewrite the mpc5200 audio DMA code to support both I2S and AC97. Make it more robust.

Why is it more robust?

I've implemented retries for when the AC97 hardware doesn't reset on first try. About 10% of the time both the Efika and pcm030 AC97 codecs don't reset on first try and need to be poked multiple times. Failure is indicated by not having the link clock start ticking. Every once in a while even five pokes won't get the link started and I have to power cycle.

I don't have an oscilloscope, after I get these basic drivers in maybe someone can put a scope on this and figure out why reset is failing. I've read the various datasheets and I believe my reset pulses have the correct timings.

Quoted 14 lines

--
Pengutronix e.K.                           | Wolfram Sang                | Industrial Linux Solutions                 | http://www.pengutronix.de/  |

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkoZmA0ACgkQD27XaX1/VRvugwCgsluxfp1rJH2MVFMTH6Yqo8bX dnIAn1z0QRIFEUJa0XpGFE937siwf8Cy
=M0wP
-----END PGP SIGNATURE-----

Signature · 2 lines
Jon Smirl
[email protected]
#20 lore raw

Re: [PATCH V2 5/9] Main rewite of the mpc5200 audio DMA code

Quoted 12 lines · Jon Smirl
Quoted 3 lines · Wolfram Sang
Quoted 1 line

Rewrite the mpc5200 audio DMA code to support both I2S and AC97. Make it more robust.

Why is it more robust?

I've implemented retries for when the AC97 hardware doesn't reset on first try. About 10% of the time both the Efika and pcm030 AC97 codecs don't reset on first try and need to be poked multiple times. Failure is indicated by not having the link clock start ticking. Every once in a while even five pokes won't get the link started and I have to power cycle.

Quoted 4 lines

I don't have an oscilloscope, after I get these basic drivers in maybe someone can put a scope on this and figure out why reset is failing. I've read the various datasheets and I believe my reset pulses have the correct timings.

That's good to know. In fact, I think a summary of this should go into the patch description.

Signature · 2 lines
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://ozlabs.org/mailman/listinfo/linuxppc-dev

#21 lore raw

Re: [PATCH V2 5/9] Main rewite of the mpc5200 audio DMA code

In reply to Jon Smirl

Jon,

Quoted 4 lines · Jon Smirl
Quoted 3 lines · Wolfram Sang
Quoted 2 lines

Rewrite the mpc5200 audio DMA code to support both I2S and AC97. Make it more robust.

Quoted 8 lines
Quoted 1 line

Why is it more robust?

I've implemented retries for when the AC97 hardware doesn't reset on first try. About 10% of the time both the Efika and pcm030 AC97 codecs don't reset on first try and need to be poked multiple times. Failure is indicated by not having the link clock start ticking. Every once in a while even five pokes won't get the link started and I have to power cycle.

Do you know this (from our website)?

"The AC97 mixer needs a hardware patch to make it wake up from power down mode. Download here the instruction how to do so."

http://www.pengutronix.de/oselas/bsp/phytec/download/phyCORE-MPC5200B-tiny/TN-015e_1.pdf

jbe

Signature · 4 lines
Pengutronix e.K.                              | Juergen Beisert             |
Linux Solutions for Science and Industry      | Phone: +49-8766-939 228     |
Vertretung Sued/Muenchen, Germany             | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686              | http://www.pengutronix.de/  |
#22 lore raw

Re: [PATCH V2 5/9] Main rewite of the mpc5200 audio DMA code

Quoted 6 lines · Juergen Beisert

Do you know this (from our website)?

"The AC97 mixer needs a hardware patch to make it wake up from power down mode. Download here the instruction how to do so."

http://www.pengutronix.de/oselas/bsp/phytec/download/phyCORE-MPC5200B-tiny/TN-015e_1.pdf

This modification should not be required - a warm reset should be enough to bring the AC97 link up. The current ASoC driver for the WM9712 will do this automatically - the expectation for non-ASoC systems is that the warm reset will always be issued.

That said, I'd be surprised if it were the same problem given that iterating cold resets appears to resolve whatever the issues is.

author
#23 lore raw

PATCH v2 6/9 Codec for STAC9766 used on the Efika

In reply to Jon Smirl

AC97 codec for STAC9766 used on the Efika.
Datasheet: http://www.idt.com/products/getDoc.cfm?docID=13134007

---

 0 files changed, 0 insertions(+), 0 deletions(-)
sound/soc/codecs/Kconfig +4 -0
index 7f78b65..cb07d9b 100644
@@ -19,6 +19,7 @@ config SND_SOC_ALL_CODECS
 	select SND_SOC_CS4270 if I2C
 	select SND_SOC_PCM3008
 	select SND_SOC_SSM2602 if I2C
+	select SND_SOC_STAC9766 if SND_SOC_AC97_BUS
 	select SND_SOC_TLV320AIC23 if I2C
 	select SND_SOC_TLV320AIC26 if SPI_MASTER
 	select SND_SOC_TLV320AIC3X if I2C
@@ -93,6 +94,9 @@ config SND_SOC_PCM3008
 config SND_SOC_SSM2602
 	tristate
 
+config SND_SOC_STAC9766
+	tristate
+
 config SND_SOC_TLV320AIC23
 	tristate
 
sound/soc/codecs/Makefile +2 -0
index 70c55fa..46c007c 100644
@@ -7,6 +7,7 @@ snd-soc-cs4270-objs := cs4270.o
 snd-soc-l3-objs := l3.o
 snd-soc-pcm3008-objs := pcm3008.o
 snd-soc-ssm2602-objs := ssm2602.o
+snd-soc-stac9766-objs := stac9766.o
 snd-soc-tlv320aic23-objs := tlv320aic23.o
 snd-soc-tlv320aic26-objs := tlv320aic26.o
 snd-soc-tlv320aic3x-objs := tlv320aic3x.o
@@ -42,6 +43,7 @@ obj-$(CONFIG_SND_SOC_CS4270)	+= snd-soc-cs4270.o
 obj-$(CONFIG_SND_SOC_L3)	+= snd-soc-l3.o
 obj-$(CONFIG_SND_SOC_PCM3008)	+= snd-soc-pcm3008.o
 obj-$(CONFIG_SND_SOC_SSM2602)	+= snd-soc-ssm2602.o
+obj-$(CONFIG_SND_SOC_STAC9766)	+= snd-soc-stac9766.o
 obj-$(CONFIG_SND_SOC_TLV320AIC23)	+= snd-soc-tlv320aic23.o
 obj-$(CONFIG_SND_SOC_TLV320AIC26)	+= snd-soc-tlv320aic26.o
 obj-$(CONFIG_SND_SOC_TLV320AIC3X)	+= snd-soc-tlv320aic3x.o
sound/soc/codecs/stac9766.c new file +470 -0

470 lines not on this page · raw message

sound/soc/codecs/stac9766.h new file +21 -0
new file mode 100644
index 0000000..65642eb
@@ -0,0 +1,21 @@
+/*
+ * stac9766.h  --  STAC9766 Soc Audio driver
+ */
+
+#ifndef _STAC9766_H
+#define _STAC9766_H
+
+#define AC97_STAC_PAGE0 0x1000
+#define AC97_STAC_DA_CONTROL (AC97_STAC_PAGE0 | 0x6A)
+#define AC97_STAC_ANALOG_SPECIAL (AC97_STAC_PAGE0 | 0x6E)
+#define AC97_STAC_STEREO_MIC 0x78
+
+/* STAC9766 DAI ID's */
+#define STAC9766_DAI_AC97_ANALOG		0
+#define STAC9766_DAI_AC97_DIGITAL		1
+
+extern struct snd_soc_dai stac9766_dai[];
+extern struct snd_soc_codec_device soc_codec_dev_stac9766;
+
+
+#endif
#24 lore raw

Re: [PATCH V2 6/9] Codec for STAC9766 used on the Efika

Quoted 4 lines · Jon Smirl

AC97 codec for STAC9766 used on the Efika.
Datasheet: http://www.idt.com/products/getDoc.cfm?docID=13134007

This looks mostly good, a couple of issues below. I'll apply the patch but please submit a followup patch for resume as discussed below.

sound/soc/codecs/stac9766.c line 219

Quoted 2 lines
sound/soc/codecs/stac9766.c new file +2 -0
+static int ac97_digital_trigger(struct snd_pcm_substream *substream,
+								int cmd, struct snd_soc_dai *dai)

Very strange indentation here...

Quoted 6 lines
sound/soc/codecs/stac9766.c new file +5 -0
+static int stac9766_codec_resume(struct platform_device *pdev)
+{
 
+	/* give the codec an AC97 warm reset to start the link */
+reset:
+	if (reset > 5) {

sound/soc/codecs/stac9766.c line 297

Quoted 10 lines
sound/soc/codecs/stac9766.c new file +10 -0
+		printk(KERN_ERR "stac9766 failed to resume");
+		return -EIO;
+	}
+	codec->ac97->bus->ops->warm_reset(codec->ac97);
+	id = soc_ac97_ops.read(codec->ac97, AC97_VENDOR_ID2);
+	if (id != 0x4c13) {
+		stac9766_reset(codec, 0);
+		reset++;
+		goto reset;
+	}

As I said last time I'd this looks like it should be using the reset function that you've provided?

The loop is new since last time and seems very suspicious - are you sure that this is a CODEC problem that's being worked around and not an issue with the AC97 controller or with the specific system starting up the master clock for the CODEC after resume? If it's an issue with the controler then it'd be better to fix it there so that all CODEC drivers get the benefit. If it's a CODEC issue a comment explaining the problem would be helpful since it's not the sort of issue I'd expect to see in a CODEC. The fact that it's not needed on initial boot suggests something controller or external clock related.

Either way, it'd be much clearer to rewrite it using a for or while loop rather than a goto. Please submit a followup patch fixing at least this issue.

sound/soc/codecs/stac9766.c line 466

Quoted 11 lines
sound/soc/codecs/stac9766.c new file +11 -0
+static int __init stac9766_modinit(void)
+{
+	return snd_soc_register_dais(stac9766_dai, ARRAY_SIZE(stac9766_dai));
+}
+module_init(stac9766_modinit);
+
+static void __exit stac9766_exit(void)
+{
+	snd_soc_unregister_dais(stac9766_dai, ARRAY_SIZE(stac9766_dai));
+}
+module_exit(stac9766_exit);

These are not needed for AC97 CODECs, ASoC doesn't wait for them to probe. I'll apply a patch removing these.

author
#25 lore raw

PATCH v2 7/9 AC97 driver for mpc5200

In reply to Jon Smirl

AC97 driver for mpc5200

---
 sound/soc/fsl/Kconfig            |   11 +
 sound/soc/fsl/Makefile           |    1 
 sound/soc/fsl/mpc5200_psc_ac97.c |  394 ++++++++++++++++++++++++++++++++++++++
 sound/soc/fsl/mpc5200_psc_ac97.h |   15 +
 4 files changed, 421 insertions(+), 0 deletions(-)
 create mode 100644 sound/soc/fsl/mpc5200_psc_ac97.c
 create mode 100644 sound/soc/fsl/mpc5200_psc_ac97.h
sound/soc/fsl/Kconfig +11 -0
index 1918c78..3bce952 100644
@@ -29,3 +29,14 @@ config SND_SOC_MPC5200_I2S
 	select PPC_BESTCOMM_GEN_BD
 	help
 	  Say Y here to support the MPC5200 PSCs in I2S mode.
+
+config SND_SOC_MPC5200_AC97
+	tristate "Freescale MPC5200 PSC in AC97 mode driver"
+	depends on PPC_MPC52xx && PPC_BESTCOMM
+	select AC97_BUS
+	select SND_MPC52xx_DMA
+	select PPC_BESTCOMM_GEN_BD
+	help
+	  Say Y here to support the MPC5200 PSCs in AC97 mode.
+
+
sound/soc/fsl/Makefile +1 -0
index 7731ef2..14631a1 100644
@@ -13,4 +13,5 @@ obj-$(CONFIG_SND_SOC_MPC8610) += snd-soc-fsl-ssi.o snd-soc-fsl-dma.o
 # MPC5200 Platform Support
 obj-$(CONFIG_SND_MPC52xx_DMA) += mpc5200_dma.o
 obj-$(CONFIG_SND_SOC_MPC5200_I2S) += mpc5200_psc_i2s.o
+obj-$(CONFIG_SND_SOC_MPC5200_AC97) += mpc5200_psc_ac97.o
 
sound/soc/fsl/mpc5200_psc_ac97.c new file +394 -0

394 lines not on this page · raw message

sound/soc/fsl/mpc5200_psc_ac97.h new file +15 -0
new file mode 100644
index 0000000..4bc18c3
@@ -0,0 +1,15 @@
+/*
+ * Freescale MPC5200 PSC in AC97 mode
+ * ALSA SoC Digital Audio Interface (DAI) driver
+ *
+ */
+
+#ifndef __SOUND_SOC_FSL_MPC52xx_PSC_AC97_H__
+#define __SOUND_SOC_FSL_MPC52xx_PSC_AC97_H__
+
+extern struct snd_soc_dai psc_ac97_dai[];
+
+#define MPC5200_AC97_NORMAL 0
+#define MPC5200_AC97_SPDIF 1
+
+#endif /* __SOUND_SOC_FSL_MPC52xx_PSC_AC97_H__ */
#26 lore raw

Re: [PATCH V2 7/9] AC97 driver for mpc5200

Quoted 5 lines · Jon Smirl
sound/soc/fsl/mpc5200_psc_ac97.c new file +5 -0
+#ifdef CONFIG_PM
+static int psc_ac97_suspend(struct snd_soc_dai *dai)
+{
+	return 0;
+}

sound/soc/fsl/mpc5200_psc_ac97.c line 142

Quoted 10 lines
sound/soc/fsl/mpc5200_psc_ac97.c new file +10 -0
+
+static int psc_ac97_resume(struct snd_soc_dai *dai)
+{
+	return 0;
+}
+
+#else
+#define psc_ac97_suspend	NULL
+#define psc_ac97_resume	NULL
+#endif

These can all just be removed, they can be added later if they are implemented.

sound/soc/fsl/mpc5200_psc_ac97.c line 149

Quoted 6 lines
sound/soc/fsl/mpc5200_psc_ac97.c new file +6 -0
+static int psc_ac97_hw_analog_params(struct snd_pcm_substream *substream,
+				 struct snd_pcm_hw_params *params,
+				 struct snd_soc_dai *dai)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct psc_dma *psc_dma = rtd->dai->cpu_dai->private_data;

Note that cpu_dai is passed in as an argument here - this didn't used to be the case which is why most drivers fish it out of rtd but that's not required any more.

sound/soc/fsl/mpc5200_psc_ac97.c line 197

Quoted 2 lines
sound/soc/fsl/mpc5200_psc_ac97.c new file +2 -0
+static int psc_ac97_trigger(struct snd_pcm_substream *substream, int cmd,
+								 struct snd_soc_dai *dai)

Again with the odd indentation.

sound/soc/fsl/mpc5200_psc_ac97.c line 293

Quoted 9 lines
sound/soc/fsl/mpc5200_psc_ac97.c new file +8 -0
+static int __devinit psc_ac97_of_probe(struct of_device *op,
+				      const struct of_device_id *match)
+{
 
+	rc = snd_soc_register_dais(psc_ac97_dai, ARRAY_SIZE(psc_ac97_dai));
+	if (rc != 0) {
+		pr_err("Failed to register DAI\n");
+		return 0;
+	}

I'd expect to see the error passed back to the caller here? I'd also expect to see this happening right at the end of this function after you're happy everything else has worked, otherwise the core might try to start using the half-initialised driver.

Quoted 11 lines
sound/soc/fsl/mpc5200_psc_ac97.c new file +11 -0
+	/* AC97 clock is generated by the codec.
+	 * Ensure that it starts ticking after codec reset.
+	 */
+	max_reset = 0;
+reset:
+	if (max_reset++ > 5) {
+		dev_err(&op->dev, "AC97 codec failed to reset\n");
+		mpc5200_audio_dma_destroy(op);
+		return -ENODEV;
+	}
+

sound/soc/fsl/mpc5200_psc_ac97.c line 332

Quoted 10 lines
sound/soc/fsl/mpc5200_psc_ac97.c new file +10 -0
+	psc_ac97_cold_reset(&ac97);
+	psc_ac97_warm_reset(&ac97);
+
+	/* first make sure it is low */
+	timeout = 0;
+	while ((in_8(&regs->ipcr_acr.ipcr) & 0x80) != 0) {
+		udelay(1);
+		if (timeout++ > 1000)
+			goto reset;
+	}

This looks awfully similar to the logic in the resume function of your CODEC driver... In general an ASoC AC97 DAI driver shouldn't be trying to bring the CODEC up like this, it should normally leave that up to the CODEC driver. This is mostly because some system designers do strange and wonderful things with clocking which require some system specific code to either bring up the master clock for the codec before it'll reset or reconfigure the clocking to something standard.

The issue with the use of goto rather than a real loop also applies here.

sound/soc/fsl/mpc5200_psc_ac97.c line 339

Quoted 7 lines
sound/soc/fsl/mpc5200_psc_ac97.c new file +7 -0
+	/* then wait for the transition to high */
+	timeout = 0;
+	while ((in_8(&regs->ipcr_acr.ipcr) & 0x80) == 0) {
+		udelay(1);
+		if (timeout++ > 1000)
+			psc_ac97_warm_reset(&ac97);
+	}

Shouldn't this be integrated into the warm reset operation (or to put it another way, why wouldn't a warm reset want to do this)?

sound/soc/fsl/mpc5200_psc_ac97.c line 347

Quoted 8 lines
sound/soc/fsl/mpc5200_psc_ac97.c new file +8 -0
+
+	/* Go */
+	out_8(&regs->command, MPC52xx_PSC_TX_ENABLE | MPC52xx_PSC_RX_ENABLE);
+
+	id1 = psc_ac97_read(&ac97, AC97_VENDOR_ID1);
+	id2 = psc_ac97_read(&ac97, AC97_VENDOR_ID2);
+
+	dev_info(&op->dev, "Codec ID is %04x %04x\n", id1, id2);

You really can't rely on this working in general system designs - like I say, some platforms will require additional work to bring the CODEC up. I'd just remove it, it's purely for information anyway. The out_8() probably ought to be moved into the ASoC probe() function (called once the card is coming up).

author
#27 lore raw

PATCH v2 8/9 Fabric bindings for STAC9766 on the Efika

In reply to Jon Smirl

Fabric bindings for STAC9766 AC97 codec on the Efika.

---
 sound/soc/fsl/Kconfig              |    8 +++
 sound/soc/fsl/Makefile             |    3 +
 sound/soc/fsl/efika-audio-fabric.c |   94 ++++++++++++++++++++++++++++++++++++
 3 files changed, 105 insertions(+), 0 deletions(-)
 create mode 100644 sound/soc/fsl/efika-audio-fabric.c
sound/soc/fsl/Kconfig +8 -0
index 3bce952..edd8516 100644
@@ -39,4 +39,12 @@ config SND_SOC_MPC5200_AC97
 	help
 	  Say Y here to support the MPC5200 PSCs in AC97 mode.
 
+config SND_MPC52xx_SOC_EFIKA
+	tristate "SoC AC97 Audio support for bbplan Efika and STAC9766"
+	depends on PPC_EFIKA
+	select SND_SOC_MPC5200_AC97
+	select SND_SOC_STAC9766
+	help
+	  Say Y if you want to add support for sound on the Efika.
+
 
sound/soc/fsl/Makefile +3 -0
index 14631a1..f406470 100644
@@ -15,3 +15,6 @@ obj-$(CONFIG_SND_MPC52xx_DMA) += mpc5200_dma.o
 obj-$(CONFIG_SND_SOC_MPC5200_I2S) += mpc5200_psc_i2s.o
 obj-$(CONFIG_SND_SOC_MPC5200_AC97) += mpc5200_psc_ac97.o
 
+# MPC5200 Machine Support
+obj-$(CONFIG_SND_MPC52xx_SOC_EFIKA) += efika-audio-fabric.o
+
sound/soc/fsl/efika-audio-fabric.c new file +94 -0

94 lines not on this page · raw message

#28 lore raw

Re: [PATCH V2 8/9] Fabric bindings for STAC9766 on the Efika

Quoted 3 lines · Jon Smirl

Fabric bindings for STAC9766 AC97 codec on the Efika.

This is OK, but obviously depends on previous patches so I'll not apply it just yet. You might want to run it (and many of your other patches) through checkpatch, though. One nit:

sound/soc/fsl/efika-audio-fabric.c line 85

Quoted 3 lines
sound/soc/fsl/efika-audio-fabric.c new file +3 -0
+static __exit void efika_fabric_exit(void)
+{
+}

This should either do something or be removed.

author
#29 lore raw

PATCH v2 9/9 Support for AC97 on Phytec pmc030 base board.

In reply to Jon Smirl

Support for AC97 on Phytec pmc030 base board. A wm9712 AC97 codec is used.

---
 sound/soc/fsl/Kconfig               |    7 +++
 sound/soc/fsl/Makefile              |    1 
 sound/soc/fsl/pcm030-audio-fabric.c |   94 +++++++++++++++++++++++++++++++++++
 3 files changed, 102 insertions(+), 0 deletions(-)
 create mode 100644 sound/soc/fsl/pcm030-audio-fabric.c
sound/soc/fsl/Kconfig +7 -0
index edd8516..5080e3e 100644
@@ -47,4 +47,11 @@ config SND_MPC52xx_SOC_EFIKA
 	help
 	  Say Y if you want to add support for sound on the Efika.
 
+config SND_MPC52xx_SOC_PCM030
+	tristate "SoC AC97 Audio support for Phytec pcm030 and WM9712"
+	depends on PPC_MPC5200_SIMPLE
+	select SND_SOC_MPC5200_AC97
+	select SND_SOC_WM9712
+	help
+	  Say Y if you want to add support for sound on the Phytec pcm030 baseboard.
 
sound/soc/fsl/Makefile +1 -0
index f406470..5806d11 100644
@@ -17,4 +17,5 @@ obj-$(CONFIG_SND_SOC_MPC5200_AC97) += mpc5200_psc_ac97.o
 
 # MPC5200 Machine Support
 obj-$(CONFIG_SND_MPC52xx_SOC_EFIKA) += efika-audio-fabric.o
+obj-$(CONFIG_SND_MPC52xx_SOC_PCM030) += pcm030-audio-fabric.o
 
sound/soc/fsl/pcm030-audio-fabric.c new file +94 -0

94 lines not on this page · raw message

#30 lore raw

Re: [PATCH V2 9/9] Support for AC97 on Phytec pmc030 base board.

Quoted 3 lines · Jon Smirl

Support for AC97 on Phytec pmc030 base board. A wm9712 AC97 codec is used.

Same comments as for the previous driver - it's OK once the AC97 DAI driver goes in.

author
#31 lore raw
In reply to Jon Smirl
Quoted 1 line · Jon Smirl

The following series implements audio support for the mpc5200. It adds an AC97 driver and STAC9766 codec driver. Board support for the Efika and Phytec pcm030 are also included.

Series is based on branch for-2.6.31 commit
0154724d487586241c1ad57cfd348ed2ff2274e2 at
git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound-2.6.git

Signature · 2 lines
Jon Smirl
[email protected]
#32 lore raw
In reply to Jon Smirl

On Sat, May 23, 2009 at 07:12:55PM -0400, Jon Smirl wrote:

[Jon, could you please fix the word wrapping in your MUA, there's none at all which makes it more difficult than it needs to be to respond to your e-mail.]

Quoted 4 lines

Mark is not enthused about soc-of-simple.c so rather than extend it for AC97 I altered the drivers to not use it. Instead they use the old way of manually binding everything. Mark would like to see OF binding more closely integrated to the core. Once a proper solution for OF

I really don't feel that this reflects the issues I had with the code well. There are two basic issues here:

- You had been trying to represent the AC97 CODEC drivers as platform devices which is not a good approach, largely since AC97 is a real bus and should be represented as such.

- soc-of-simple really should be merged into the core now, there's no need to have to add changes to individual drivers any more since drivers are already regstering with the core.

These two points are basically unrelated except in that your motiviation for doing the platform device thing was trying to fit your machine drivers into the existing soc-of-simple framework. It's the changes to the cross-platform AC97 drivers that were causing real problems, soc-of-simple is only an issue in that using it motivates these other changes.

Quoted 3 lines

binding is agreed upon it is easy to convert the existing drivers. A first step would be converting the existing codec drivers so that they can be dynamically loaded.

I'm not aware of any CODEC drivers which can't currently be built and used as modules. If you mean "load via the normal device model" then yes, that'd be very good (and is in progress) but it's another issue and as I explained last time AC97 poses particular problems there.

author
#33 lore raw
Quoted 5 lines · Mark Brown

I'm not aware of any CODEC drivers which can't currently be built and used as modules. =A0If you mean "load via the normal device model" then yes, that'd be very good (and is in progress) but it's another issue and as I explained last time AC97 poses particular problems there.

I mean "load via the normal device model". For example the AC97 drivers need to be loadable by the codec id. There's no entry in scripts/mod/file2alias.c for dynamically loading the modules. They don't have an id_table.

My AC97 driver is detecting the codec id and printing it before trying to access the codec driver. I can convert that to a load_module() call when the drivers are ready.

The core needs to detect if a specific codec id can't be supported to fall back to the generic AC97 driver.

--=20
Jon Smirl
[email protected]

#34 lore raw
Quoted 3 lines · Jon Smirl

My AC97 driver is detecting the codec id and printing it before trying to access the codec driver. I can convert that to a load_module() call when the drivers are ready.

No, your AC97 driver shouldn't be doing any of this at all - it should be leaving any enumeration of the hardware up to the machine driver and the core. In so far as it is standardised the process for probing AC97 is something that can be implemented in terms of the operations exported by the DAI so it should be done in the core for all AC97 DAIs. Where standardised probing can't work it needs to be machine specific anyway.