AC97 driver for mpc5200
v5 cover AC97 driver for mpc5200
Version 5. Modified to use spin_event_timeout() as originally written.
---
Jon Smirl (5):
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
powerpc: introduce macro spin_event_timeout()
arch/powerpc/include/asm/delay.h | 33 +++ sound/soc/fsl/Kconfig | 27 ++ sound/soc/fsl/Makefile | 5 sound/soc/fsl/efika-audio-fabric.c | 90 +++++++ sound/soc/fsl/mpc5200_dma.c | 442 ++++++++++++++++++++++------------- sound/soc/fsl/mpc5200_dma.h | 33 +-- sound/soc/fsl/mpc5200_psc_ac97.c | 331 ++++++++++++++++++++++++++ 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 | 90 +++++++ 11 files changed, 934 insertions(+), 391 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]
PATCH v5 1/5 powerpc: introduce macro spin_event_timeout()
The macro spin_event_timeout() takes a condition and timeout value (in microseconds) as parameters. It spins until either the condition is true or the timeout expires. It returns the result of the condition when the loop was terminated.
This primary purpose of this macro is to poll on a hardware register until a status bit changes. The timeout ensures that the loop still terminates if the bit doesn't change as expected. This macro makes it easier for driver developers to perform this kind of operation properly.
--- arch/powerpc/include/asm/delay.h | 33 +++++++++++++++++++++++++++++++++ 1 files changed, 33 insertions(+), 0 deletions(-)
arch/powerpc/include/asm/delay.h +33 -0
@@ -2,8 +2,11 @@#define _ASM_POWERPC_DELAY_H#ifdef __KERNEL__ +#include <asm/time.h> +/* * Copyright 1996, Paul Mackerras. +* Copyright (C) 2009 Freescale Semiconductor, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License
@@ -30,5 +33,35 @@ extern void udelay(unsigned long usecs);#define mdelay (n) udelay((n) * 1000)#endif +/** +* spin_event_timeout - spin until a condition gets true or a timeout elapses +* @condition: a C expression to evalate +* @timeout: timeout, in microseconds +* @delay: the number of microseconds to delay between eache evaluation of +* @condition +* @rc: the last value of the condition +* +* The process spins until the condition evaluates to true (non-zero) or the +* timeout elapses. Upon exit, @rc contains the value of the condition. This +* allows you to test the condition without incurring any side effects. +* +* This primary purpose of this macro is to poll on a hardware register +* until a status bit changes. The timeout ensures that the loop still +* terminates even if the bit never changes. The delay is for devices that +* need a delay in between successive reads. +* +* gcc will optimize out the if-statement if @delay is a constant. +*/ +#define spin_event_timeout (condition, timeout, delay, rc) \ +{ \ + unsigned long __loops = tb_ticks_per_usec * timeout; \ + unsigned long __start = get_tbl(); \ + while (!(rc = (condition)) && (tb_ticks_since(__start) <= __loops)) \ + if (delay) \ + udelay(delay); \ + else \ + cpu_relax(); \ +} +#endif /* __KERNEL__ */ #endif /* _ASM_POWERPC_DELAY_H */
Re: [PATCH V5 1/5] powerpc: introduce macro spin_event_timeout()
Quoted 4 lines · Jon Smirl
The macro
spin_event_timeout()takes a condition and timeout value (in microseconds) as parameters. It spins until either the condition is true or the timeout expires. It returns the result of the condition when the loop was terminated.
As previously mentioned you need to submit any changes you want to make here as incremental patches against the PowerPC tree rather than as an entire new patch. If you are forwarding on copies of the patch you really ought to preserve Timur's authorship too with a From line in the mail.
Re: [PATCH V5 1/5] powerpc: introduce macro spin_event_timeout()
Quoted 11 lines · Mark Brown
Quoted 4 lines · Jon Smirl
The macro
spin_event_timeout()takes a condition and timeout value (in microseconds) as parameters. It spins until either the condition is true or the timeout expires. It returns the result of the condition when the loop was terminated.As previously mentioned you need to submit any changes you want to make here as incremental patches against the PowerPC tree rather than as an entire new patch. If you are forwarding on copies of the patch you really ought to preserve Timur's authorship too with a From line in the mail.
I have reverted back to TImur's original patch so you can just drop this patch if that is easier for you.
You'll just need to coordinate the landing so that things land in the right order.
Signature · 2 lines
Jon Smirl [email protected]
Re: [PATCH V5 1/5] powerpc: introduce macro spin_event_timeout()
Quoted 8 lines · Jon Smirl
On Tue, May 26, 2009 at 9:03 AM, Mark Brown
Quoted 5 lines
As previously mentioned you need to submit any changes you want to make here as incremental patches against the PowerPC tree rather than as an entire new patch. ?If you are forwarding on copies of the patch you really ought to preserve Timur's authorship too with a From line in the mail.
Quoted 4 lines
I have reverted back to TImur's original patch so you can just drop this patch if that is easier for you.
You'll just need to coordinate the landing so that things land in the right order.
Like I say, since it's a new driver I'm just going to ignore the ordering since it'll sort itself out in the merge window and we're rather close to that. Worst case something that doesn't build isn't that much different from something that isn't there in terms of usability.
PATCH v5 2/5 Main rewite of the mpc5200 audio DMA code
In reply to Jon SmirlRewrite the mpc5200 audio DMA code to support both I2S and AC97.
--- sound/soc/fsl/Kconfig | 1 sound/soc/fsl/mpc5200_dma.c | 442 ++++++++++++++++++++++++--------------- 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, 344 insertions(+), 391 deletions(-) create mode 100644 sound/soc/fsl/mpc5200_psc_i2s.h
sound/soc/fsl/Kconfig +0 -1
@@ -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 +274 -168
644 lines not on this page · raw message
sound/soc/fsl/mpc5200_dma.h +16 -17
@@ -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
@@ -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__ */
PATCH v5 3/5 AC97 driver for mpc5200
In reply to Jon SmirlAC97 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 | 331 ++++++++++++++++++++++++++++++++++++++ sound/soc/fsl/mpc5200_psc_ac97.h | 15 ++ 4 files changed, 358 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
@@ -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
@@ -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 +331 -0
331 lines not on this page · raw message
sound/soc/fsl/mpc5200_psc_ac97.h new file +15 -0
@@ -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__ */
sound/soc/fsl/mpc5200_psc_ac97.c line 89
Quoted 7 lines · Jon Smirl
sound/soc/fsl/mpc5200_psc_ac97.c new file +7
-0+static void psc_ac97_warm_reset (struct snd_ac97 *ac97) +{ +int rc; +struct mpc52xx_psc __iomem *regs = psc_dma->psc_regs; + +out_be32 (®s->sicr, psc_dma->sicr | MPC52xx_PSC_SICR_AWR); +spin_event_timeout (0 ,3 ,0 , rc);
I still think you should use udelay() here. spin_event_timeout(<constant>) will just reduce to a udelay() call anyway. In addition, there's no "event" that you're waiting for.
Signature · 2 lines
Timur Tabi Linux kernel developer at Freescale
PATCH v5 4/5 Support for AC97 on Phytec pmc030 base board.
In reply to Jon SmirlSupport 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 | 90 +++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 0 deletions(-) create mode 100644 sound/soc/fsl/pcm030-audio-fabric.c
sound/soc/fsl/Kconfig +7 -0
@@ -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
@@ -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 +90 -0
90 lines not on this page · raw message
PATCH v5 5/5 Fabric bindings for STAC9766 on the Efika
In reply to Jon SmirlFabric 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 | 90 ++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 0 deletions(-) create mode 100644 sound/soc/fsl/efika-audio-fabric.c
sound/soc/fsl/Kconfig +8 -0
@@ -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
@@ -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 +90 -0
90 lines not on this page · raw message