All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ASoC: omap3beagle: Add dai link for McBSP2 master configuration (CLKS source)
@ 2012-02-28  7:55 Peter Ujfalusi
  2012-02-28  8:36 ` Jarkko Nikula
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Ujfalusi @ 2012-02-28  7:55 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown
  Cc: alsa-devel, Grazvydas Ignotas, Jarkko Nikula, Steve Sakoman

Create new dai link so we can choose between two different modes of operation:
PCM0: twl4030 master, McBSP2 slave (current configuration)
PCM1: twl4030 slave, McBSP2 slave (SRG source is from CLKS pin)

This will help us tracking down, and test different setups on Beagle board.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
Hello,

While tracking down an issue regported by Grazvydas Ignotas regarding to the
McBSP move series (Pandora setup was not working) I have noticed that we can
use the Beagle board in a similar way as Pandora uses it (McBSP master, twl4030
slave, CLKS pin is connected to twl4030 256*FS clock output).
With this patch we can switch between the two modes by playing on hw:0,0 or on
hw:0,1.

I will add the third option later where McBSP is the master, but the clock for
SRG is coming from internal source.

This patch depends on the McBSP rewrite series (OMAP/ASoC: Move and merge McBSP
driver under ASoC)
http://mailman.alsa-project.org/pipermail/alsa-devel/2012-February/049628.html

Regards,
Peter

 sound/soc/omap/omap3beagle.c |  110 ++++++++++++++++++++++++++++++++++++++----
 1 files changed, 100 insertions(+), 10 deletions(-)

diff --git a/sound/soc/omap/omap3beagle.c b/sound/soc/omap/omap3beagle.c
index 2830dfd..a2f9130 100644
--- a/sound/soc/omap/omap3beagle.c
+++ b/sound/soc/omap/omap3beagle.c
@@ -34,6 +34,7 @@
 #include "omap-mcbsp.h"
 #include "omap-pcm.h"
 
+/* McBSP2 slave, TWL4030 master */
 static int omap3beagle_hw_params(struct snd_pcm_substream *substream,
 	struct snd_pcm_hw_params *params)
 {
@@ -80,6 +81,14 @@ static int omap3beagle_hw_params(struct snd_pcm_substream *substream,
 		return ret;
 	}
 
+	/* Set McBSP clock to PER_96M_FCLK */
+	ret = snd_soc_dai_set_sysclk(cpu_dai, OMAP_MCBSP_SYSCLK_CLKS_FCLK,
+				     96000000, SND_SOC_CLOCK_IN);
+	if (ret < 0) {
+		printk(KERN_ERR "can't set cpu system clock\n");
+		return ret;
+	}
+
 	return 0;
 }
 
@@ -87,23 +96,104 @@ static struct snd_soc_ops omap3beagle_ops = {
 	.hw_params = omap3beagle_hw_params,
 };
 
+/* McBSP2 master, TWL4030 slave */
+static int omap3beagle_slave_hw_params(struct snd_pcm_substream *substream,
+	struct snd_pcm_hw_params *params)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_dai *codec_dai = rtd->codec_dai;
+	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+	unsigned int fmt;
+	int ret;
+
+	switch (params_channels(params)) {
+	case 2: /* Stereo I2S mode */
+		fmt =	SND_SOC_DAIFMT_I2S |
+			SND_SOC_DAIFMT_NB_NF |
+			SND_SOC_DAIFMT_CBS_CFS;
+		break;
+	case 4: /* Four channel TDM mode */
+		fmt =	SND_SOC_DAIFMT_DSP_A |
+			SND_SOC_DAIFMT_IB_NF |
+			SND_SOC_DAIFMT_CBS_CFS;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	/* Set codec DAI configuration */
+	ret = snd_soc_dai_set_fmt(codec_dai, fmt);
+	if (ret < 0) {
+		printk(KERN_ERR "can't set codec DAI configuration\n");
+		return ret;
+	}
+
+	/* Set cpu DAI configuration */
+	ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
+	if (ret < 0) {
+		printk(KERN_ERR "can't set cpu DAI configuration\n");
+		return ret;
+	}
+
+	/* Set the codec system clock for DAC and ADC */
+	ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
+				     SND_SOC_CLOCK_IN);
+	if (ret < 0) {
+		printk(KERN_ERR "can't set codec system clock\n");
+		return ret;
+	}
+
+	/* Set McBSP clock to external (CLKS) */
+	ret = snd_soc_dai_set_sysclk(cpu_dai, OMAP_MCBSP_SYSCLK_CLKS_EXT,
+				     256 * params_rate(params),
+				     SND_SOC_CLOCK_IN);
+	if (ret < 0) {
+		printk(KERN_ERR "can't set cpu system clock\n");
+		return ret;
+	}
+
+	ret = snd_soc_dai_set_clkdiv(cpu_dai, OMAP_MCBSP_CLKGDV, 8);
+	if (ret < 0) {
+		printk(KERN_ERR "can't set SRG clock divider\n");
+		return ret;
+	}
+
+	return 0;
+}
+
+static struct snd_soc_ops omap3beagle_slave_ops = {
+	.hw_params = omap3beagle_slave_hw_params,
+};
+
 /* Digital audio interface glue - connects codec <--> CPU */
-static struct snd_soc_dai_link omap3beagle_dai = {
-	.name = "TWL4030",
-	.stream_name = "TWL4030",
-	.cpu_dai_name = "omap-mcbsp.2",
-	.platform_name = "omap-pcm-audio",
-	.codec_dai_name = "twl4030-hifi",
-	.codec_name = "twl4030-codec",
-	.ops = &omap3beagle_ops,
+static struct snd_soc_dai_link omap3beagle_dai[] = {
+	{
+		/* McBSP2 slave, TWL4030 master configuration */
+		.name = "TWL4030 master",
+		.stream_name = "TWL4030 master",
+		.cpu_dai_name = "omap-mcbsp.2",
+		.platform_name = "omap-pcm-audio",
+		.codec_dai_name = "twl4030-hifi",
+		.codec_name = "twl4030-codec",
+		.ops = &omap3beagle_ops,
+	}, {
+		/* McBSP2 master, TWL4030 slave configuration */
+		.name = "TWL4030 slave",
+		.stream_name = "TWL4030 slave",
+		.cpu_dai_name = "omap-mcbsp.2",
+		.platform_name = "omap-pcm-audio",
+		.codec_dai_name = "twl4030-hifi",
+		.codec_name = "twl4030-codec",
+		.ops = &omap3beagle_slave_ops,
+	},
 };
 
 /* Audio machine driver */
 static struct snd_soc_card snd_soc_omap3beagle = {
 	.name = "omap3beagle",
 	.owner = THIS_MODULE,
-	.dai_link = &omap3beagle_dai,
-	.num_links = 1,
+	.dai_link = omap3beagle_dai,
+	.num_links = ARRAY_SIZE(omap3beagle_dai),
 };
 
 static struct platform_device *omap3beagle_snd_device;
-- 
1.7.8.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] ASoC: omap3beagle: Add dai link for McBSP2 master configuration (CLKS source)
  2012-02-28  7:55 [PATCH] ASoC: omap3beagle: Add dai link for McBSP2 master configuration (CLKS source) Peter Ujfalusi
@ 2012-02-28  8:36 ` Jarkko Nikula
  2012-02-28  9:11   ` Peter Ujfalusi
  0 siblings, 1 reply; 4+ messages in thread
From: Jarkko Nikula @ 2012-02-28  8:36 UTC (permalink / raw)
  To: Peter Ujfalusi
  Cc: Steve Sakoman, alsa-devel, Mark Brown, Liam Girdwood,
	Grazvydas Ignotas

On 02/28/2012 09:55 AM, Peter Ujfalusi wrote:
> Create new dai link so we can choose between two different modes of operation:
> PCM0: twl4030 master, McBSP2 slave (current configuration)
> PCM1: twl4030 slave, McBSP2 slave (SRG source is from CLKS pin)
> 
> This will help us tracking down, and test different setups on Beagle board.
> 
> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
> ---
> Hello,
> 
> While tracking down an issue regported by Grazvydas Ignotas regarding to the
> McBSP move series (Pandora setup was not working) I have noticed that we can
> use the Beagle board in a similar way as Pandora uses it (McBSP master, twl4030
> slave, CLKS pin is connected to twl4030 256*FS clock output).
> With this patch we can switch between the two modes by playing on hw:0,0 or on
> hw:0,1.
> 
> I will add the third option later where McBSP is the master, but the clock for
> SRG is coming from internal source.
> 
> This patch depends on the McBSP rewrite series (OMAP/ASoC: Move and merge McBSP
> driver under ASoC)
> http://mailman.alsa-project.org/pipermail/alsa-devel/2012-February/049628.html
> 
Is this something that is better to stay in list archives not under
version control? This looks to me as a developer debug feature.

-- 
Jarkko

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ASoC: omap3beagle: Add dai link for McBSP2 master configuration (CLKS source)
  2012-02-28  8:36 ` Jarkko Nikula
@ 2012-02-28  9:11   ` Peter Ujfalusi
  2012-02-28  9:36     ` Jarkko Nikula
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Ujfalusi @ 2012-02-28  9:11 UTC (permalink / raw)
  To: Jarkko Nikula
  Cc: Steve Sakoman, alsa-devel, Mark Brown, Liam Girdwood,
	Grazvydas Ignotas

On 02/28/2012 10:36 AM, Jarkko Nikula wrote:
> Is this something that is better to stay in list archives not under
> version control? This looks to me as a developer debug feature.

Good question...
Right now I'm not sure if this patch has practical use at the moment.
It does not hurt to be in the tree since the default PCM does not
change. But it might confuse users.
Either way is good for me.

-- 
Péter

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ASoC: omap3beagle: Add dai link for McBSP2 master configuration (CLKS source)
  2012-02-28  9:11   ` Peter Ujfalusi
@ 2012-02-28  9:36     ` Jarkko Nikula
  0 siblings, 0 replies; 4+ messages in thread
From: Jarkko Nikula @ 2012-02-28  9:36 UTC (permalink / raw)
  To: Peter Ujfalusi
  Cc: Steve Sakoman, alsa-devel, Mark Brown, Liam Girdwood,
	Grazvydas Ignotas

On 02/28/2012 11:11 AM, Peter Ujfalusi wrote:
> On 02/28/2012 10:36 AM, Jarkko Nikula wrote:
>> Is this something that is better to stay in list archives not under
>> version control? This looks to me as a developer debug feature.
> 
> Good question...
> Right now I'm not sure if this patch has practical use at the moment.
> It does not hurt to be in the tree since the default PCM does not
> change. But it might confuse users.
> Either way is good for me.
> 
Related useful reference knowledge is mux settings for other McBSP pins
that are routed to beagle extension port pins. Might be good to have
those documented somewhere for system builders reference.

-- 
Jarkko

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-02-28  9:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-28  7:55 [PATCH] ASoC: omap3beagle: Add dai link for McBSP2 master configuration (CLKS source) Peter Ujfalusi
2012-02-28  8:36 ` Jarkko Nikula
2012-02-28  9:11   ` Peter Ujfalusi
2012-02-28  9:36     ` Jarkko Nikula

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.