Skip to contentSkip to conversation

mpc5200 audio rework for AC97

PATCH In review Jon Smirl 4 participants 22 messages May 25, 2009 – May 28, 2009

Subsystems (2)
lore
Share & tools
lore

Jon Smirl

author
#0 lore raw

v3 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.

I've tried to implement the feedback received on the previous two versions.

based on commit 0bc53a67ac831ec84f730a657dbcadd80a589ef5 on broonie/for-2.6.31 at
git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound-2.6.git

---

Jon Smirl (4):
Fabric bindings for STAC9766 on the Efika Support for AC97 on Phytec pmc030 base board. AC97 driver for mpc5200
Main rewite of the mpc5200 audio DMA code

 sound/soc/fsl/Kconfig               |   27 ++
 sound/soc/fsl/Makefile              |    5 
 sound/soc/fsl/efika-audio-fabric.c  |   95 +++++++
 sound/soc/fsl/mpc5200_dma.c         |  504 +++++++++++++++++++++++------------
 sound/soc/fsl/mpc5200_dma.h         |   33 +-
 sound/soc/fsl/mpc5200_psc_ac97.c    |  392 +++++++++++++++++++++++++++
 sound/soc/fsl/mpc5200_psc_ac97.h    |   15 +
 sound/soc/fsl/mpc5200_psc_i2s.c     |  247 +++--------------
 sound/soc/fsl/mpc5200_psc_i2s.h     |   12 +
 sound/soc/fsl/pcm030-audio-fabric.c |   95 +++++++
 10 files changed, 1036 insertions(+), 389 deletions(-)
 create mode 100644 sound/soc/fsl/efika-audio-fabric.c
 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 v3 1/4 Main rewite of the mpc5200 audio DMA code

Rewrite the mpc5200 audio DMA code to support both I2S and AC97.

---
 sound/soc/fsl/Kconfig           |    1 
 sound/soc/fsl/mpc5200_dma.c     |  504 ++++++++++++++++++++++++++-------------
 sound/soc/fsl/mpc5200_dma.h     |   33 +--
 sound/soc/fsl/mpc5200_psc_i2s.c |  247 +++----------------
 sound/soc/fsl/mpc5200_psc_i2s.h |   12 +
 5 files changed, 408 insertions(+), 389 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 +338 -166

707 lines not on this page · raw message

sound/soc/fsl/mpc5200_dma.h +16 -17
index a33232c..2000803 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;
@@ -58,24 +67,14 @@ struct psc_dma {
 
 	/* Statistics */
 	struct {
-		int overrun_count;
-		int underrun_count;
+		unsigned long overrun_count;
+		unsigned long underrun_count;
 	} 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 +42 -205

331 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__ */
#2 lore raw

Re: [PATCH V3 1/4] Main rewite of the mpc5200 audio DMA code

Quoted 342 lines · Jon Smirl

Rewrite the mpc5200 audio DMA code to support both I2S and AC97.

---
 sound/soc/fsl/Kconfig           |    1 sound/soc/fsl/mpc5200_dma.c     |  504 ++++++++++++++++++++++++++------------- sound/soc/fsl/mpc5200_dma.h     |   33 +-- sound/soc/fsl/mpc5200_psc_i2s.c |  247 +++---------------- sound/soc/fsl/mpc5200_psc_i2s.h |   12 +

 5 files changed, 408 insertions(+), 389 deletions(-)

 create mode 100644 sound/soc/fsl/mpc5200_psc_i2s.h

sound/soc/fsl/Kconfig +0 -0
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 +56 -88
index 6850392..4e1f1f8 100644
@@ -3,23 +3,13 @@
  * ALSA SoC Platform driver
  *
  * Copyright (C) 2008 Secret Lab Technologies Ltd.
+ * Copyright (C) 2009 Jon Smirl, Digispeaker
  */
 
-#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>
@@ -27,10 +17,6 @@
 
  #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
  */
@@ -50,7 +36,7 @@ static irqreturn_t psc_dma_status_irq(int irq, void *_psc_dma)
        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 */
+       out_8(&regs->command, MPC52xx_PSC_RST_ERR_STAT);
 
        return IRQ_HANDLED;
  }
@@ -81,8 +67,21 @@ static void psc_dma_bcom_enqueue_next_buffer(struct psc_dma_stream *s)
                s->period_next_pt = s->period_start;
  }
 
+static void psc_dma_bcom_enqueue_tx(struct psc_dma_stream *s)
+{
+       while (s->appl_ptr < s->runtime->control->appl_ptr) {
+
+               if (bcom_queue_full(s->bcom_task))
+                       return;
+
+               s->appl_ptr += s->period_size;
+
+               psc_dma_bcom_enqueue_next_buffer(s);
+       }
+}
+
  /* Bestcomm DMA irq handler */
-static irqreturn_t psc_dma_bcom_irq(int irq, void *_psc_dma_stream)
+static irqreturn_t psc_dma_bcom_irq_tx(int irq, void *_psc_dma_stream)
  {
        struct psc_dma_stream *s = _psc_dma_stream;
 
@@ -90,12 +89,12 @@ static irqreturn_t psc_dma_bcom_irq(int irq, void *_psc_dma_stream)
         * 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_dma_bcom_enqueue_next_buffer(s);
-               bcom_enable(s->bcom_task);
        }
+       psc_dma_bcom_enqueue_tx(s);
 
        /* If the stream is active, then also inform the PCM middle layer
         * of the period finished event. */
@@ -105,49 +104,31 @@ static irqreturn_t psc_dma_bcom_irq(int irq, void *_psc_dma_stream)
        return IRQ_HANDLED;
  }
 
-/**
- * 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_dma_startup(struct snd_pcm_substream *substream,
-                          struct snd_soc_dai *dai)
+static irqreturn_t psc_dma_bcom_irq_rx(int irq, void *_psc_dma_stream)
  {
-       struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct psc_dma *psc_dma = rtd->dai->cpu_dai->private_data;
-       int rc;
+       struct psc_dma_stream *s = _psc_dma_stream;
 
-       dev_dbg(psc_dma->dev, "psc_dma_startup(substream=%p)\n", substream);
+       /* 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);
 
-       if (!psc_dma->playback.active &&
-           !psc_dma->capture.active) {
-               /* Setup the IRQs */
-               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_dma->irq, psc_dma);
-                       free_irq(psc_dma->capture.irq,
-                                &psc_dma->capture);
-                       free_irq(psc_dma->playback.irq,
-                                &psc_dma->playback);
-                       return -ENODEV;
-               }
+               s->period_current_pt += s->period_bytes;
+               if (s->period_current_pt >= s->period_end)
+                       s->period_current_pt = s->period_start;
+
+               psc_dma_bcom_enqueue_next_buffer(s);
        }
 
-       return 0;
+       /* 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;
  }
 
-int psc_dma_hw_free(struct snd_pcm_substream *substream,
-                          struct snd_soc_dai *dai)
+static int psc_dma_hw_free(struct snd_pcm_substream *substream)
  {
        snd_pcm_set_runtime_buffer(substream, NULL);
        return 0;
@@ -159,8 +140,7 @@ int psc_dma_hw_free(struct snd_pcm_substream *substream,
  * This function is called by ALSA to start, stop, pause, and resume the DMA
  * transfer of data.
  */
-int psc_dma_trigger(struct snd_pcm_substream *substream, int cmd,
-                          struct snd_soc_dai *dai)
+static int psc_dma_trigger(struct snd_pcm_substream *substream, int cmd)
  {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct psc_dma *psc_dma = rtd->dai->cpu_dai->private_data;
@@ -168,8 +148,8 @@ int psc_dma_trigger(struct snd_pcm_substream *substream, int cmd,
        struct psc_dma_stream *s;
        struct mpc52xx_psc __iomem *regs = psc_dma->psc_regs;
        u16 imr;
-       u8 psc_cmd;
        unsigned long flags;
+       int i;
 
        if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE)
                s = &psc_dma->capture;
@@ -189,68 +169,45 @@ int psc_dma_trigger(struct snd_pcm_substream *substream, int cmd,
                                (s->period_bytes * runtime->periods);
                s->period_next_pt = s->period_start;
                s->period_current_pt = s->period_start;
+               s->period_size = runtime->period_size;
                s->active = 1;
 
-               /* First; reset everything */
+               /* track appl_ptr so that we have a better chance of detecting
+                * end of stream and not over running it.
+                */
+               s->runtime = runtime;
+               s->appl_ptr = s->runtime->control->appl_ptr -
+                               (runtime->period_size * runtime->periods);
+
+               /* 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) {
-                       out_8(&regs->command, MPC52xx_PSC_RST_RX);
-                       out_8(&regs->command, MPC52xx_PSC_RST_ERR_STAT);
+                       bcom_gen_bd_rx_reset(s->bcom_task);
+                       for (i = 0; i < runtime->periods; i++)
+                               if (!bcom_queue_full(s->bcom_task))
+                                       psc_dma_bcom_enqueue_next_buffer(s);
                } else {
-                       out_8(&regs->command, MPC52xx_PSC_RST_TX);
-                       out_8(&regs->command, MPC52xx_PSC_RST_ERR_STAT);
+                       bcom_gen_bd_tx_reset(s->bcom_task);
+                       psc_dma_bcom_enqueue_tx(s);
                }
 
-               /* 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_dma_bcom_enqueue_next_buffer(s);
                bcom_enable(s->bcom_task);
 
-               /* 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_dma->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);
+               out_8(&regs->command, MPC52xx_PSC_RST_ERR_STAT);
                spin_unlock_irqrestore(&psc_dma->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_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 */
-                       }
-               } else {
-                       out_8(&regs->command, 3 << 4);  /* reset tx */
-                       out_8(&regs->command, 4 << 4);  /* reset err */
-                       if (!psc_dma->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);
+               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);

               break;

sound/soc/fsl/mpc5200_dma.c +2 -35
@@ -265,44 +222,11 @@ int psc_dma_trigger(struct snd_pcm_substream *substream, int cmd,
                imr |= MPC52xx_PSC_IMR_TXEMP;
        if (psc_dma->capture.active)
                imr |= MPC52xx_PSC_IMR_ORERR;
-       out_be16(&regs->isr_imr.imr, imr);
+       out_be16(&regs->isr_imr.imr, psc_dma->imr | imr);
 
        return 0;
  }
 
-/**
- * psc_dma_shutdown: shutdown the data transfer on a stream
- *
- * Shutdown the PSC if there are no other substreams open.
- */
-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_dma *psc_dma = rtd->dai->cpu_dai->private_data;
-
-       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_dma->playback.active &&
-           !psc_dma->capture.active) {
-
-               /* Disable all interrupts and reset the PSC */
-               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_dma->irq, psc_dma);
-               free_irq(psc_dma->capture.irq, &psc_dma->capture);
-               free_irq(psc_dma->playback.irq, &psc_dma->playback);
-       }
-}
 
  /* ---------------------------------------------------------------------
  * The PSC DMA 'ASoC platform' driver
@@ -312,62 +236,78 @@ void psc_dma_shutdown(struct snd_pcm_substream *substream,
  * interaction with the attached codec
  */
 
-static const struct snd_pcm_hardware psc_dma_pcm_hardware = {
+static const struct snd_pcm_hardware psc_dma_hardware = {
Quoted 6 lines

       .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,
+               SNDRV_PCM_FMTBIT_S24_BE | SNDRV_PCM_FMTBIT_S32_BE,

Unrelated whitespace changes?

Quoted 3 lines

+/* ---------------------------------------------------------------------
+ * Sysfs attributes for error monitoring
+ */

All this sysfs stuff should be dropped from this patch. It is an abuse of sysfs and I never should have written it this way. Feel free to put it in a separate patch so others can use it if they really need it, but I'd like it to not be kept in mainline.

g.

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

Re: [PATCH V3 1/4] Main rewite of the mpc5200 audio DMA code

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

+/* ---------------------------------------------------------------------
+ * Sysfs attributes for error monitoring
+ */

All this sysfs stuff should be dropped from this patch. It is an abuse of sysfs and I never should have written it this way. Feel free to put it in a separate patch so others can use it if they really need it, but I'd like it to not be kept in mainline.

If this is going to be kept it should be in debugfs like I said in response to the v2 posting.

#4 lore raw

Re: [PATCH V3 1/4] Main rewite of the mpc5200 audio DMA code

Quoted 7 lines · Mark Brown
Quoted 5 lines · Grant Likely
Quoted 3 lines · Jon Smirl

+/* ---------------------------------------------------------------------
+ * Sysfs attributes for error monitoring
+ */

Quoted 7 lines
Quoted 4 lines

All this sysfs stuff should be dropped from this patch.  It is an abuse of sysfs and I never should have written it this way.  Feel free to put it in a separate patch so others can use it if they really need it, but I'd like it to not be kept in mainline.

If this is going to be kept it should be in debugfs like I said in response to the v2 posting.

exactly.

g.

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

PATCH v3 2/4 AC97 driver for mpc5200

In reply to Jon Smirl

AC97 driver for mpc5200

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.

---
 sound/soc/fsl/Kconfig            |   11 +
 sound/soc/fsl/Makefile           |    1 
 sound/soc/fsl/mpc5200_psc_ac97.c |  392 ++++++++++++++++++++++++++++++++++++++
 sound/soc/fsl/mpc5200_psc_ac97.h |   15 +
 4 files changed, 419 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 +392 -0

392 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__ */
#6 lore raw

Re: [PATCH V3 2/4] AC97 driver for mpc5200

Quoted 85 lines · Jon Smirl

AC97 driver for mpc5200

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.

---
 sound/soc/fsl/Kconfig            |   11 +
 sound/soc/fsl/Makefile           |    1 sound/soc/fsl/mpc5200_psc_ac97.c |  392 ++++++++++++++++++++++++++++++++++++++ sound/soc/fsl/mpc5200_psc_ac97.h |   15 +

 4 files changed, 419 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 +0 -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.

sound/soc/fsl/Kconfig +11 -0
+
+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 +0 -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

sound/soc/fsl/Makefile +1 -0
+obj-$(CONFIG_SND_SOC_MPC5200_AC97) += mpc5200_psc_ac97.o
sound/soc/fsl/mpc5200_psc_ac97.c new file +31 -0
new file mode 100644
index 0000000..480b677
@@ -0,0 +1,392 @@
+/*
+ * linux/sound/mpc5200-ac97.c -- AC97 support for the Freescale MPC52xx chip.
+ *
+ * Copyright (C) 2009 Jon Smirl, Digispeaker
+ * Author: Jon Smirl <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/of_platform.h>
+
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+
+#include <asm/mpc52xx_psc.h>
+
+#include "mpc5200_dma.h"
+#include "mpc5200_psc_ac97.h"
+
+#define DRV_NAME "mpc5200-psc-ac97"
+
+/* ALSA only supports a single AC97 device so static is recommend here */
+static struct psc_dma *psc_dma;
+
+static unsigned short psc_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
+{

sound/soc/fsl/mpc5200_psc_ac97.c line 41

Quoted 10 lines
sound/soc/fsl/mpc5200_psc_ac97.c new file +10 -0
+       int timeout;
+       unsigned int val;
+
+       spin_lock(&psc_dma->lock);
+
+       /* Wait for it to be ready */
+       timeout = 1000;
+       while ((--timeout) && (in_be16(&psc_dma->psc_regs->sr_csr.status) &
+                                               MPC52xx_PSC_SR_CMDSEND))
+               udelay(10);

Holy unbounded latency Batman! This code waits up to 10ms for a register read!

I hate spinning, but if it must be done; I'd like to see it small. What is the worst case latency? 125us for 8000Hz bus speed? If you must spin; can a cpu_relax() be used instead of the udelay() while watch the timebase? Timur recently posted a patch which makes this easier.

http://patchwork.ozlabs.org/patch/27414/

They *should* be appearing in Ben's -next branch soon.

Quoted 4 lines
sound/soc/fsl/mpc5200_psc_ac97.c new file +4 -0
+
+       if (!timeout) {
+               pr_err("timeout on ac97 bus (rdy)\n");
+               return 0xffff;

sound/soc/fsl/mpc5200_psc_ac97.c line 55

Quoted 10 lines
sound/soc/fsl/mpc5200_psc_ac97.c new file +10 -0
+       }
+
+       /* Do the read */
+       out_be32(&psc_dma->psc_regs->ac97_cmd, (1<<31) | ((reg & 0x7f) << 24));
+
+       /* Wait for the answer */
+       timeout = 1000;
+       while ((--timeout) && !(in_be16(&psc_dma->psc_regs->sr_csr.status) &
+                                               MPC52xx_PSC_SR_DATA_VAL))
+               udelay(10);

ditto.

Quoted 5 lines
sound/soc/fsl/mpc5200_psc_ac97.c new file +5 -0
+static int psc_ac97_cold_reset_check(struct snd_ac97 *ac97)
+{
+       int max_reset, timeout;
+       struct mpc52xx_psc __iomem *regs = psc_dma->psc_regs;
+

sound/soc/fsl/mpc5200_psc_ac97.c line 123

Quoted 10 lines
sound/soc/fsl/mpc5200_psc_ac97.c new file +10 -0
+       /* AC97 clock is generated by the codec.
+        * Ensure that it starts ticking after codec reset.
+        */
+       for (max_reset = 0; max_reset < 5; max_reset++) {
+
+               /* Do a cold reset */
+               out_8(&regs->op1, MPC52xx_PSC_OP_RES);
+               udelay(10);
+               out_8(&regs->op0, MPC52xx_PSC_OP_RES);
+               udelay(50);

:-/ Don't like, but don't know if there is an alternative.

Quoted 11 lines
sound/soc/fsl/mpc5200_psc_ac97.c new file +11 -0
+
+               /* PSC recover from cold reset
+                * (cfr user manual, not sure if useful)
+                */
+               out_be32(&regs->sicr, in_be32(&regs->sicr));
+
+               psc_ac97_warm_reset(ac97);
+
+               /* first make sure AC97 clock is low */
+               for (timeout = 0; ((in_8(&regs->ipcr_acr.ipcr) & 0x80) != 0) &&
+                               (timeout < 100); timeout++)

sound/soc/fsl/mpc5200_psc_ac97.c line 144

Quoted 10 lines
sound/soc/fsl/mpc5200_psc_ac97.c new file +10 -0
+                       udelay(10);
+               if (timeout == 100)
+                       continue;
+
+               /* then wait for the transition to high */
+               for (timeout = 0; ((in_8(&regs->ipcr_acr.ipcr) & 0x80) == 0) &&
+                               (timeout < 100); timeout++)
+                       udelay(10);
+               if (timeout == 100)
+                       continue;

Using udelay makes this less accurate. Only possible reason to use a udelay is if the register cannot be polled at full speed (which is possibly the case if it adds bus contention; but I don't think it is an issue here).

g.

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

Re: [PATCH V3 2/4] AC97 driver for mpc5200

Quoted 22 lines · Grant Likely

sound/soc/fsl/mpc5200_psc_ac97.c line 41

Quoted 12 lines · Jon Smirl
sound/soc/fsl/mpc5200_psc_ac97.c new file +12 -0
+static unsigned short psc_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
+{
+       int timeout;
+       unsigned int val;
+
+       spin_lock(&psc_dma->lock);
+
+       /* Wait for it to be ready */
+       timeout = 1000;
+       while ((--timeout) && (in_be16(&psc_dma->psc_regs->sr_csr.status) &
+                                               MPC52xx_PSC_SR_CMDSEND))
+               udelay(10);

Holy unbounded latency Batman!  This code waits up to 10ms for a register read!

I hate spinning, but if it must be done; I'd like to see it small. What is the worst case latency? 125us for 8000Hz bus speed?  If you must spin; can a cpu_relax() be used instead of the udelay() while watch the timebase?  Timur recently posted a patch which makes this easier.

Quoted 3 lines

http://patchwork.ozlabs.org/patch/27414/

They *should* be appearing in Ben's -next branch soon.

The link always runs at 12.288Mhz. Each frame is 256 bits. Worst case you wait for two frames, 42us. If it doesn't respond in 42us the codec clock is not ticking ( a recurring problem I am running into). These codecs may be going into a sleep mode I don't understand, but this is not the right place to try and wake them up. I'll lower the retry counts to 10 instead of 1000.

I played around with implementing this on a kernel thread with interrupts. It can be done but the code is a lot more complex.

BTW, 8000Hz is implemented by slot stuffing. The link always runs at 12.288Mhz. The DACs are double buffered. When a sample is transfered between buffers it sets a bit on the link back to the host, and the host sends the next sample in the appropriate slot.

Quoted 70 lines
Quoted 5 lines
sound/soc/fsl/mpc5200_psc_ac97.c new file +4 -0
+
+       if (!timeout) {
+               pr_err("timeout on ac97 bus (rdy)\n");
+               return 0xffff;

sound/soc/fsl/mpc5200_psc_ac97.c line 55

Quoted 10 lines
sound/soc/fsl/mpc5200_psc_ac97.c new file +10 -0
+       }
+
+       /* Do the read */
+       out_be32(&psc_dma->psc_regs->ac97_cmd, (1<<31) | ((reg & 0x7f) << 24));
+
+       /* Wait for the answer */
+       timeout = 1000;
+       while ((--timeout) && !(in_be16(&psc_dma->psc_regs->sr_csr.status) &
+                                               MPC52xx_PSC_SR_DATA_VAL))
+               udelay(10);

ditto.

Quoted 5 lines
sound/soc/fsl/mpc5200_psc_ac97.c new file +5 -0
+static int psc_ac97_cold_reset_check(struct snd_ac97 *ac97)
+{
+       int max_reset, timeout;
+       struct mpc52xx_psc __iomem *regs = psc_dma->psc_regs;
+

sound/soc/fsl/mpc5200_psc_ac97.c line 123

Quoted 10 lines
sound/soc/fsl/mpc5200_psc_ac97.c new file +10 -0
+       /* AC97 clock is generated by the codec.
+        * Ensure that it starts ticking after codec reset.
+        */
+       for (max_reset = 0; max_reset < 5; max_reset++) {
+
+               /* Do a cold reset */
+               out_8(&regs->op1, MPC52xx_PSC_OP_RES);
+               udelay(10);
+               out_8(&regs->op0, MPC52xx_PSC_OP_RES);
+               udelay(50);

:-/  Don't like, but don't know if there is an alternative.

Quoted 11 lines
sound/soc/fsl/mpc5200_psc_ac97.c new file +11 -0
+
+               /* PSC recover from cold reset
+                * (cfr user manual, not sure if useful)
+                */
+               out_be32(&regs->sicr, in_be32(&regs->sicr));
+
+               psc_ac97_warm_reset(ac97);
+
+               /* first make sure AC97 clock is low */
+               for (timeout = 0; ((in_8(&regs->ipcr_acr.ipcr) & 0x80) != 0) &&
+                               (timeout < 100); timeout++)

sound/soc/fsl/mpc5200_psc_ac97.c line 144

Quoted 10 lines
sound/soc/fsl/mpc5200_psc_ac97.c new file +10 -0
+                       udelay(10);
+               if (timeout == 100)
+                       continue;
+
+               /* then wait for the transition to high */
+               for (timeout = 0; ((in_8(&regs->ipcr_acr.ipcr) & 0x80) == 0) &&
+                               (timeout < 100); timeout++)
+                       udelay(10);
+               if (timeout == 100)
+                       continue;

Using udelay makes this less accurate.  Only possible reason to use a udelay is if the register cannot be polled at full speed (which is possibly the case if it adds bus contention; but I don't think it is an issue here).

g.

--
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

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

Re: [PATCH V3 2/4] AC97 driver for mpc5200

Quoted 2 lines · Jon Smirl

The link always runs at 12.288Mhz. Each frame is 256 bits. Worst case you wait for two frames, 42us. If it doesn't respond in 42us the codec

Note that some embedded systems will choose to vary the AC97 link clock. The most common case is where there's a PLL on the CODEC - the CODEC will start up misclocked at whatever the input frequency it's got is and then be reclocked using register writes to configure the PLL.

#9 lore raw

Re: [PATCH V3 2/4] AC97 driver for mpc5200

In reply to Jon Smirl
Quoted 28 lines · Jon Smirl
Quoted 22 lines · Grant Likely

sound/soc/fsl/mpc5200_psc_ac97.c line 41

Quoted 12 lines · Jon Smirl
sound/soc/fsl/mpc5200_psc_ac97.c new file +12 -0
+static unsigned short psc_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
+{
+       int timeout;
+       unsigned int val;
+
+       spin_lock(&psc_dma->lock);
+
+       /* Wait for it to be ready */
+       timeout = 1000;
+       while ((--timeout) && (in_be16(&psc_dma->psc_regs->sr_csr.status) &
+                                               MPC52xx_PSC_SR_CMDSEND))
+               udelay(10);

Holy unbounded latency Batman!  This code waits up to 10ms for a register read!

I hate spinning, but if it must be done; I'd like to see it small. What is the worst case latency? 125us for 8000Hz bus speed?  If you must spin; can a cpu_relax() be used instead of the udelay() while watch the timebase?  Timur recently posted a patch which makes this easier.

Quoted 3 lines

http://patchwork.ozlabs.org/patch/27414/

They *should* be appearing in Ben's -next branch soon.

Quoted 6 lines

The link always runs at 12.288Mhz. Each frame is 256 bits. Worst case you wait for two frames, 42us. If it doesn't respond in 42us the codec clock is not ticking ( a recurring problem I am running into). These codecs may be going into a sleep mode I don't understand, but this is not the right place to try and wake them up. I'll lower the retry counts to 10 instead of 1000.

That still leaves the problem of unecessarily burning time. udelay shouldn't be passed any value larger than 1. In fact, I think udelay itself is too coarse grained. Plus, I'd rather see the timebase used as the exit condition (as mentioned in previous email).

Quoted 2 lines

I played around with implementing this on a kernel thread with interrupts. It can be done but the code is a lot more complex.

A kernel thread is definitely the wrong approach. However, if this is non-atomic context and IRQs are available, then a wait queue can be used. 42us is about 16k processor clocks. I'm not sure what the IRQ and scheduling overhead is so I don't know whether it would be a net gain or loss in performance. However, it would be a net gain in worst case latency.

Quoted 4 lines

BTW, 8000Hz is implemented by slot stuffing. The link always runs at 12.288Mhz. The DACs are double buffered. When a sample is transfered between buffers it sets a bit on the link back to the host, and the host sends the next sample in the appropriate slot.

ok.

g.

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

Re: [PATCH V3 2/4] AC97 driver for mpc5200

In reply to Jon Smirl
Quoted 6 lines · Jon Smirl

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.

This smells like either a very broken board or some issue with starting the master clock for the CODEC - if the CODEC is clocked by the AC97 controller you may need to do something to ensure that it has finished starting up before initiating the reset.

sound/soc/fsl/mpc5200_psc_ac97.c line 116

Quoted 8 lines
sound/soc/fsl/mpc5200_psc_ac97.c new file +8 -0
+static int psc_ac97_cold_reset_check(struct snd_ac97 *ac97)
+{
+	int max_reset, timeout;
+	struct mpc52xx_psc __iomem *regs = psc_dma->psc_regs;
+
+	/* AC97 clock is generated by the codec.
+	 * Ensure that it starts ticking after codec reset.
+	 */

The AC97 standard allows CODECs to come out of cold reset with the link disabled. With those CODECs this is going fail every time - they need a warm reset to come on-line.

If this really is a general issue with the AC97 controller here you'll need to do a warm reset in here. It's not ideal but extra warm resets will cause less harm than completely failing to come on-line.

sound/soc/fsl/mpc5200_psc_ac97.c line 219

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)

I keep mentioning the indentation issues with your code without seeing any response from you. If you run checkpatch over your code you'll also see a bunch of complaints about using spaces instead of tabs for indentation. It looks for all the world like you're using 4 character tabs instead of the 8 character tabs which are the kernel standard.

sound/soc/fsl/mpc5200_psc_ac97.c line 234

Quoted 12 lines
sound/soc/fsl/mpc5200_psc_ac97.c new file +12 -0
+
+	switch (cmd) {
+	case SNDRV_PCM_TRIGGER_STOP:
+		if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE)
+			psc_dma->slots &= 0xFFFF0000;
+		else
+			psc_dma->slots &= 0x0000FFFF;
+
+		spin_lock(&psc_dma->lock);
+		out_be32(&psc_dma->psc_regs->ac97_slots, psc_dma->slots);
+		spin_unlock(&psc_dma->lock);
+		break;

This locking looks wrong - I'd expect it to also cover the modification of psc_dma->slots? Otherwise it's hard to see what it buys you.

sound/soc/fsl/mpc5200_psc_ac97.c line 342

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

Your AC97 driver should not be doing this - leave it to the card and CODEC driver to bring things on line.

sound/soc/fsl/mpc5200_psc_ac97.c line 345

Quoted 3 lines
sound/soc/fsl/mpc5200_psc_ac97.c new file +3 -0
+
+	/* Go */
+	out_8(&regs->command, MPC52xx_PSC_TX_ENABLE | MPC52xx_PSC_RX_ENABLE);

As I said last time I'd expect this to be deferred to the ASoC device probe.

author
#11 lore raw

Re: [PATCH V3 2/4] AC97 driver for mpc5200

Quoted 7 lines · Mark Brown
Quoted 4 lines

+             spin_lock(&psc_dma->lock);
+             out_be32(&psc_dma->psc_regs->ac97_slots, psc_dma->slots);
+             spin_unlock(&psc_dma->lock);
+             break;

This locking looks wrong - I'd expect it to also cover the modification of psc_dma->slots?  Otherwise it's hard to see what it buys you.

Grant, why are you spin locking around register access?

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

Re: [PATCH V3 2/4] AC97 driver for mpc5200

Quoted 11 lines · Jon Smirl
Quoted 7 lines · Mark Brown
Quoted 4 lines

+             spin_lock(&psc_dma->lock);
+             out_be32(&psc_dma->psc_regs->ac97_slots, psc_dma->slots);
+             spin_unlock(&psc_dma->lock);
+             break;

This locking looks wrong - I'd expect it to also cover the modification of psc_dma->slots?  Otherwise it's hard to see what it buys you.

Grant, why are you spin locking around register access?

This lock/unlock is definitely bogus since a single register access is already atomic. Are there places in the code that I wrote where a spin_lock/unlock is done around a single register access?

g.

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

PATCH v3 3/4 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              |    3 +
 sound/soc/fsl/pcm030-audio-fabric.c |   95 +++++++++++++++++++++++++++++++++++
 3 files changed, 105 insertions(+), 0 deletions(-)
 create mode 100644 sound/soc/fsl/pcm030-audio-fabric.c
sound/soc/fsl/Kconfig +7 -0
index 3bce952..79579ae 100644
@@ -39,4 +39,11 @@ config SND_SOC_MPC5200_AC97
 	help
 	  Say Y here to support the MPC5200 PSCs in AC97 mode.
 
+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 +3 -0
index 14631a1..66d88c8 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_PCM030) += pcm030-audio-fabric.o
+
sound/soc/fsl/pcm030-audio-fabric.c new file +95 -0

95 lines not on this page · raw message

#14 lore raw

Re: [PATCH V3 3/4] Support for AC97 on Phytec pmc030 base board.

Quoted 115 lines · 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              |    3 + sound/soc/fsl/pcm030-audio-fabric.c |   95 +++++++++++++++++++++++++++++++++++

 3 files changed, 105 insertions(+), 0 deletions(-)

 create mode 100644 sound/soc/fsl/pcm030-audio-fabric.c

sound/soc/fsl/Kconfig +0 -0
index 3bce952..79579ae 100644
@@ -39,4 +39,11 @@ config SND_SOC_MPC5200_AC97

       help
         Say Y here to support the MPC5200 PSCs in AC97 mode.

sound/soc/fsl/Kconfig +7 -0
+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 +0 -0
index 14631a1..66d88c8 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

sound/soc/fsl/Makefile +3 -0
+# MPC5200 Machine Support
+obj-$(CONFIG_SND_MPC52xx_SOC_PCM030) += pcm030-audio-fabric.o
+
sound/soc/fsl/pcm030-audio-fabric.c new file +72 -0
new file mode 100644
index 0000000..2c426d5
@@ -0,0 +1,95 @@
+/*
+ * Phytec pcm030 driver for the PSC of the Freescale MPC52xx
+ * configured as AC97 interface
+ *
+ * Copyright 2008 Jon Smirl, Digispeaker
+ * Author: Jon Smirl <[email protected]>
+ *
+ * This file is licensed under the terms of the GNU General Public License
+ * version 2. This program is licensed "as is" without any warranty of any
+ * kind, whether express or implied.
+ */
+
+#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 "mpc5200_dma.h"
+#include "mpc5200_psc_ac97.h"
+#include "../codecs/wm9712.h"
+
+static struct snd_soc_device device;
+static struct snd_soc_card card;
+
+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;
+       }
+

sound/soc/fsl/pcm030-audio-fabric.c line 82

Quoted 10 lines
sound/soc/fsl/pcm030-audio-fabric.c new file +10 -0
+       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;
+}

This is ugly. I'd really rather have a generic mechanism for creating a fabric driver based on the OF data. But failing that, it seems to me that this platform device registration should be done in the platform code (arch/powerpc/platforms/52xx). Doing it in a module init looks wrong.

I was trying to do a sort of generic matching mechanism with the of simple stuff; but admittedly it was hacky and half-assed. However, I do still think it is viable to have OF hooks that kick in when codec and machine drivers are registered. If linkage data is encoded in the device tree, then generic code should be able to hook them up; pulling additional data out of the device tree as needed to configure the coded.

g.

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

Re: [PATCH V3 3/4] Support for AC97 on Phytec pmc030 base board.

Quoted 5 lines · Grant Likely

This is ugly. I'd really rather have a generic mechanism for creating a fabric driver based on the OF data. But failing that, it seems to me that this platform device registration should be done in the platform code (arch/powerpc/platforms/52xx). Doing it in a module init looks wrong.

It's ugly but it's idiomatic for ASoC until someone has time to implement multiple card support.

Quoted 2 lines

I was trying to do a sort of generic matching mechanism with the of simple stuff; but admittedly it was hacky and half-assed. However, I

It's adequate for the cases it tries to cover, it just needs to be merged into the core. The problem here is AC97 since it can't be probed until the platform comes up.

Quoted 5 lines

do still think it is viable to have OF hooks that kick in when codec and machine drivers are registered. If linkage data is encoded in the device tree, then generic code should be able to hook them up; pulling additional data out of the device tree as needed to configure the coded.

As I explained in response to Jon's original posting AC97 is a particular problem here since it can only be probed using the CPU DAI and may require machine-specific work to set it up prior to use. There's problems fixing this due to AC97 not having fully developed bus infrastructure in the kernel at the minute.

author
#16 lore raw

Re: [PATCH V3 3/4] Support for AC97 on Phytec pmc030 base board.

In reply to Grant Likely
Quoted 7 lines · Grant Likely

On Sun, May 24, 2009 at 7:38 PM, Jon Smirl <[email protected]> wrote:

This is ugly.  I'd really rather have a generic mechanism for creating a fabric driver based on the OF data.  But failing that, it seems to me that this platform device registration should be done in the platform code (arch/powerpc/platforms/52xx).  Doing it in a module init looks wrong.

I'm all for deleting it as soon as AC97 is capable of auto-loading. I thought it was better to leave it in the sound directories to keep it isolated since the intention is to remove it when possible.

BTW, my binding files are quite simple compared to mpc8610_hpcd.c.

Quoted 15 lines

I was trying to do a sort of generic matching mechanism with the of simple stuff; but admittedly it was hacky and half-assed.  However, I do still think it is viable to have OF hooks that kick in when codec and machine drivers are registered.  If linkage data is encoded in the device tree, then generic code should be able to hook them up; pulling additional data out of the device tree as needed to configure the coded.

g.

--
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

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

Re: [PATCH V3 3/4] Support for AC97 on Phytec pmc030 base board.

In reply to Jon Smirl

sound/soc/fsl/pcm030-audio-fabric.c line 86

Quoted 3 lines · Jon Smirl
sound/soc/fsl/pcm030-audio-fabric.c new file +3 -0
+static __exit void pcm030_fabric_exit(void)
+{
+}

Remove or implement, please.

author
#18 lore raw

PATCH v3 4/4 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             |    1 
 sound/soc/fsl/efika-audio-fabric.c |   95 ++++++++++++++++++++++++++++++++++++
 3 files changed, 104 insertions(+), 0 deletions(-)
 create mode 100644 sound/soc/fsl/efika-audio-fabric.c
sound/soc/fsl/Kconfig +8 -0
index 79579ae..f571c6e 100644
@@ -47,3 +47,11 @@ config SND_MPC52xx_SOC_PCM030
 	help
 	  Say Y if you want to add support for sound on the Phytec pcm030 baseboard.
 
+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 +1 -0
index 66d88c8..a83a739 100644
@@ -17,4 +17,5 @@ obj-$(CONFIG_SND_SOC_MPC5200_AC97) += mpc5200_psc_ac97.o
 
 # MPC5200 Machine Support
 obj-$(CONFIG_SND_MPC52xx_SOC_PCM030) += pcm030-audio-fabric.o
+obj-$(CONFIG_SND_MPC52xx_SOC_EFIKA) += efika-audio-fabric.o
 
sound/soc/fsl/efika-audio-fabric.c new file +95 -0

95 lines not on this page · raw message

#19 lore raw

Re: [PATCH V3 4/4] Fabric bindings for STAC9766 on the Efika

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Jon" == Jon Smirl <[email protected]> writes:

Hi,

Jon> Fabric bindings for STAC9766 AC97 codec on the Efika. Jon> Signed-off-by: Jon Smirl <[email protected]> Jon> ---

 Jon>  sound/soc/fsl/Kconfig              |    8 +++
 Jon>  sound/soc/fsl/Makefile             |    1 
 Jon>  sound/soc/fsl/efika-audio-fabric.c |   95 ++++++++++++++++++++++++++++++++++++

Jon> 3 files changed, 104 insertions(+), 0 deletions(-) Jon> create mode 100644 sound/soc/fsl/efika-audio-fabric.c

Jon> diff --git a/sound/soc/fsl/Kconfig b/sound/soc/fsl/Kconfig Jon> index 79579ae..f571c6e 100644
Jon> --- a/sound/soc/fsl/Kconfig
Jon> +++ b/sound/soc/fsl/Kconfig
Jon> @@ -47,3 +47,11 @@ config SND_MPC52xx_SOC_PCM030
Jon> help
Jon> Say Y if you want to add support for sound on the Phytec pcm030 baseboard.

Jon> +config SND_MPC52xx_SOC_EFIKA
Jon> + tristate "SoC AC97 Audio support for bbplan Efika and STAC9766"
Jon> + depends on PPC_EFIKA
Jon> + select SND_SOC_MPC5200_AC97
Jon> + select SND_SOC_STAC9766
Jon> + help
Jon> + Say Y if you want to add support for sound on the Efika.
Jon> +

Wouldn't it make more sense to make this default y when it has such specific dependencies and is so deep down in the tree - Most efika users probably want to enable this if they have enabled ALSA and SND_SOC?

Signature · 1 line
Bye, Peter Korsgaard
author
#20 lore raw

Re: [PATCH V3 4/4] Fabric bindings for STAC9766 on the Efika

Quoted 30 lines · Peter Korsgaard
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Jon" == Jon Smirl <[email protected]> writes:

Hi,

 Jon> Fabric bindings for STAC9766 AC97 codec on the Efika.
 Jon> Signed-off-by: Jon Smirl <[email protected]>
 Jon> ---
 Jon>  sound/soc/fsl/Kconfig              |    8 +++
 Jon>  sound/soc/fsl/Makefile             |    1
 Jon>  sound/soc/fsl/efika-audio-fabric.c |   95 ++++++++++++++++++++++++++++++++++++ Jon>  3 files changed, 104 insertions(+), 0 deletions(-)
 Jon>  create mode 100644 sound/soc/fsl/efika-audio-fabric.c

 Jon> diff --git a/sound/soc/fsl/Kconfig b/sound/soc/fsl/Kconfig
 Jon> index 79579ae..f571c6e 100644
 Jon> --- a/sound/soc/fsl/Kconfig
 Jon> +++ b/sound/soc/fsl/Kconfig
 Jon> @@ -47,3 +47,11 @@ config SND_MPC52xx_SOC_PCM030
 Jon>   help
 Jon>     Say Y if you want to add support for sound on the Phytec pcm030 baseboard.

 Jon> +config SND_MPC52xx_SOC_EFIKA
 Jon> + tristate "SoC AC97 Audio support for bbplan Efika and STAC9766" Jon> + depends on PPC_EFIKA
 Jon> + select SND_SOC_MPC5200_AC97
 Jon> + select SND_SOC_STAC9766
 Jon> + help
 Jon> +   Say Y if you want to add support for sound on the Efika. Jon> +

Quoted 4 lines

Wouldn't it make more sense to make this default y when it has such specific dependencies and is so deep down in the tree - Most efika users probably want to enable this if they have enabled ALSA and SND_SOC?

I can change it in the next round of updates. Right now I'd like to get some people testing it and maybe doing some patches to enhance it.

For example I know he code has a problem where about 5% of the time the codec doesn't reset right on boot. Someone needs to put an oscilloscope on the codec chip and tell me why it is failing.

Quoted 4 lines

--
Bye, Peter Korsgaard

Signature · 2 lines
Jon Smirl
[email protected]
#21 lore raw
In reply to Jon Smirl
Quoted 4 lines · 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.

I've tried to implement the feedback received on the previous two versions.

Please also add the fixes for the reset code in the CODEC driver that I asked for.