Skip to contentSkip to conversation

ALSA:ATMEL: common arch for audio via ssc(patch 3/3: adding directories)

PATCH Sedji Gaouaou 5 participants 12 messages Sep 26, 2008

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

This last patch contains the board specific files.
I have not changed playpaq_wm8510.c, and I did few changes on eti_b1_wm8731.c.

Regards,
Sedji

sound/soc/atmel/eti_b1_wm8731.c new file +353 -0
new file mode 100644
index 0000000..afa1aaf
@@ -0,0 +1,353 @@
+/*
+ * eti_b1_wm8731  --  SoC audio for AT91RM9200-based Endrelia ETI_B1 board.
+ *
+ * Author:	Frank Mandarino <[email protected]>
+ *		Endrelia Technologies Inc.
+ * Created:	Mar 29, 2006
+ *
+ * Based on corgi.c by:
+ *
+ * Copyright 2005 Wolfson Microelectronics PLC.
+ * Copyright 2005 Openedhand Ltd.
+ *
+ * Authors: Liam Girdwood <[email protected]>
+ *          Richard Purdie <[email protected]>
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/kernel.h>
+#include <linux/clk.h>
+#include <linux/timer.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+
+#include <mach/hardware.h>
+#include <mach/gpio.h>
+
+#include "../codecs/wm8731.h"
+#include "atmel_pcm.h"
+#include "atmel_ssc_dai.h"
+
+#if 0
+#define	DBG(x...)	printk(KERN_INFO "eti_b1_wm8731: " x)
+#else
+#define	DBG(x...)
+#endif
+
+static struct clk *pck1_clk;
+static struct clk *pllb_clk;
+
+
+static int eti_b1_startup(struct snd_pcm_substream *substream)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
+	struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
+	int ret;
+
+	/* cpu clock is the AT91 master clock sent to the SSC */
+	ret = snd_soc_dai_set_sysclk(cpu_dai, ATMEL_SYSCLK_MCK,
+		60000000, SND_SOC_CLOCK_IN);
+	if (ret < 0)
+		return ret;
+
+	/* codec system clock is supplied by PCK1, set to 12MHz */
+	ret = snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK,
+		12000000, SND_SOC_CLOCK_IN);
+	if (ret < 0)
+		return ret;
+
+	/* Start PCK1 clock. */
+	clk_enable(pck1_clk);
+	DBG("pck1 started\n");
+
+	return 0;
+}
+
+static void eti_b1_shutdown(struct snd_pcm_substream *substream)
+{
+	/* Stop PCK1 clock. */
+	clk_disable(pck1_clk);
+	DBG("pck1 stopped\n");
+}
+
+static int eti_b1_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->dai->codec_dai;
+	struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
+	int ret;
+
+#ifdef CONFIG_SND_AT91_SOC_ETI_SLAVE
+	unsigned int rate;
+	int cmr_div, period;
+
+	/* set codec DAI configuration */
+	ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
+		SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
+	if (ret < 0)
+		return ret;
+
+	/* set cpu DAI configuration */
+	ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
+		SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
+	if (ret < 0)
+		return ret;
+
+	/*
+	 * The SSC clock dividers depend on the sample rate.  The CMR.DIV
+	 * field divides the system master clock MCK to drive the SSC TK
+	 * signal which provides the codec BCLK.  The TCMR.PERIOD and
+	 * RCMR.PERIOD fields further divide the BCLK signal to drive
+	 * the SSC TF and RF signals which provide the codec DACLRC and
+	 * ADCLRC clocks.
+	 *
+	 * The dividers were determined through trial and error, where a
+	 * CMR.DIV value is chosen such that the resulting BCLK value is
+	 * divisible, or almost divisible, by (2 * sample rate), and then
+	 * the TCMR.PERIOD or RCMR.PERIOD is BCLK / (2 * sample rate) - 1.
+	 */
+	rate = params_rate(params);
+
+	switch (rate) {
+	case 8000:
+		cmr_div = 25;	/* BCLK = 60MHz/(2*25) = 1.2MHz */
+		period = 74;	/* LRC = BCLK/(2*(74+1)) = 8000Hz */
+		break;
+	case 32000:
+		cmr_div = 7;	/* BCLK = 60MHz/(2*7) ~= 4.28571428MHz */
+		period = 66;	/* LRC = BCLK/(2*(66+1)) = 31982.942Hz */
+		break;
+	case 48000:
+		cmr_div = 13;	/* BCLK = 60MHz/(2*13) ~= 2.3076923MHz */
+		period = 23;	/* LRC = BCLK/(2*(23+1)) = 48076.923Hz */
+		break;
+	default:
+		printk(KERN_WARNING "unsupported rate %d"
+				" on ETI-B1 board\n", rate);
+		return -EINVAL;
+	}
+
+	/* set the MCK divider for BCLK */
+	ret = snd_soc_dai_set_clkdiv(cpu_dai, ATMEL_SSC_CMR_DIV, cmr_div);
+	if (ret < 0)
+		return ret;
+
+	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+		/* set the BCLK divider for DACLRC */
+		ret = snd_soc_dai_set_clkdiv(cpu_dai,
+						ATMEL_SSC_TCMR_PERIOD, period);
+	} else {
+		/* set the BCLK divider for ADCLRC */
+		ret = snd_soc_dai_set_clkdiv(cpu_dai,
+						ATMEL_SSC_RCMR_PERIOD, period);
+	}
+	if (ret < 0)
+		return ret;
+
+#else /* CONFIG_SND_AT91_SOC_ETI_SLAVE */
+	/*
+	 * Codec in Master Mode.
+	 */
+
+	/* set codec DAI configuration */
+	ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
+		SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
+	if (ret < 0)
+		return ret;
+
+	/* set cpu DAI configuration */
+	ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
+		SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
+	if (ret < 0)
+		return ret;
+
+#endif /* CONFIG_SND_AT91_SOC_ETI_SLAVE */
+
+	return 0;
+}
+
+static struct snd_soc_ops eti_b1_ops = {
+	.startup = eti_b1_startup,
+	.hw_params = eti_b1_hw_params,
+	.shutdown = eti_b1_shutdown,
+};
+
+
+static const struct snd_soc_dapm_widget eti_b1_dapm_widgets[] = {
+	SND_SOC_DAPM_MIC("Int Mic", NULL),
+	SND_SOC_DAPM_SPK("Ext Spk", NULL),
+};
+
+static const struct snd_soc_dapm_route intercon[] = {
+
+	/* speaker connected to LHPOUT */
+	{"Ext Spk", NULL, "LHPOUT"},
+
+	/* mic is connected to Mic Jack, with WM8731 Mic Bias */
+	{"MICIN", NULL, "Mic Bias"},
+	{"Mic Bias", NULL, "Int Mic"},
+};
+
+/*
+ * Logic for a wm8731 as connected on a Endrelia ETI-B1 board.
+ */
+static int eti_b1_wm8731_init(struct snd_soc_codec *codec)
+{
+	DBG("eti_b1_wm8731_init() called\n");
+
+	/* Add specific widgets */
+	snd_soc_dapm_new_controls(codec, eti_b1_dapm_widgets,
+				  ARRAY_SIZE(eti_b1_dapm_widgets));
+
+	/* Set up specific audio path interconnects */
+	snd_soc_dapm_add_route(codec, intercon, ARRAY_SIZE(intercon));
+
+	/* not connected */
+	snd_soc_dapm_disable_pin(codec, "RLINEIN");
+	snd_soc_dapm_disable_pin(codec, "LLINEIN");
+
+	/* always connected */
+	snd_soc_dapm_enable_pin(codec, "Int Mic");
+	snd_soc_dapm_enable_pin(codec, "Ext Spk");
+
+	snd_soc_dapm_sync(codec);
+
+	return 0;
+}
+
+static struct snd_soc_dai_link eti_b1_dai = {
+	.name = "WM8731",
+	.stream_name = "WM8731 PCM",
+	.cpu_dai = &atmel_ssc_dai[1],
+	.codec_dai = &wm8731_dai,
+	.init = eti_b1_wm8731_init,
+	.ops = &eti_b1_ops,
+};
+
+static struct snd_soc_machine snd_soc_machine_eti_b1 = {
+	.name = "ETI_B1_WM8731",
+	.dai_link = &eti_b1_dai,
+	.num_links = 1,
+};
+
+static struct wm8731_setup_data eti_b1_wm8731_setup = {
+	.i2c_address = 0x1a,
+};
+
+static struct snd_soc_device eti_b1_snd_devdata = {
+	.machine = &snd_soc_machine_eti_b1,
+	.platform = &atmel_soc_platform,
+	.codec_dev = &soc_codec_dev_wm8731,
+	.codec_data = &eti_b1_wm8731_setup,
+};
+
+static struct platform_device *eti_b1_snd_device;
+
+static int __init eti_b1_init(void)
+{
+	int ret;
+	struct atmel_ssc_periph *ssc = eti_b1_dai.cpu_dai->private_data;
+	struct ssc_device *ssc = NULL;
+
+	/*
+	 * Request SSC device
+	 */
+	ssc = ssc_request(1);
+	if (IS_ERR(ssc)) {
+		ret = PTR_ERR(ssc);
+		ssc = NULL;
+		goto err_ssc;
+	}
+	ssc_p->ssc = ssc;
+
+	eti_b1_snd_device = platform_device_alloc("soc-audio", -1);
+	if (!eti_b1_snd_device) {
+		DBG("platform device allocation failed\n");
+		ret = -ENOMEM;
+		goto fail_io_unmap;
+	}
+
+	platform_set_drvdata(eti_b1_snd_device, &eti_b1_snd_devdata);
+	eti_b1_snd_devdata.dev = &eti_b1_snd_device->dev;
+
+	ret = platform_device_add(eti_b1_snd_device);
+	if (ret) {
+		DBG("platform device add failed\n");
+		platform_device_put(eti_b1_snd_device);
+		goto fail_io_unmap;
+	}
+
+	at91_set_A_periph(AT91_PIN_PB6, 0);	/* TF1 */
+	at91_set_A_periph(AT91_PIN_PB7, 0);	/* TK1 */
+	at91_set_A_periph(AT91_PIN_PB8, 0);	/* TD1 */
+	at91_set_A_periph(AT91_PIN_PB9, 0);	/* RD1 */
+/*	at91_set_A_periph(AT91_PIN_PB10, 0);*/	/* RK1 */
+	at91_set_A_periph(AT91_PIN_PB11, 0);	/* RF1 */
+
+	/*
+	 * Set PCK1 parent to PLLB and its rate to 12 Mhz.
+	 */
+	pllb_clk = clk_get(NULL, "pllb");
+	pck1_clk = clk_get(NULL, "pck1");
+
+	clk_set_parent(pck1_clk, pllb_clk);
+	clk_set_rate(pck1_clk, 12000000);
+
+	DBG("MCLK rate %luHz\n", clk_get_rate(pck1_clk));
+
+	/* assign the GPIO pin to PCK1 */
+	at91_set_B_periph(AT91_PIN_PA24, 0);
+
+#ifdef CONFIG_SND_AT91_SOC_ETI_SLAVE
+	printk(KERN_INFO "eti_b1_wm8731: Codec in Slave Mode\n");
+#else
+	printk(KERN_INFO "eti_b1_wm8731: Codec in Master Mode\n");
+#endif
+	return ret;
+err_ssc:
+	return ret;
+fail_io_unmap:
+	iounmap(ssc->base);
+fail_release_mem:
+	release_mem_region(AT91RM9200_BASE_SSC1, SZ_16K);
+	return ret;
+}
+
+static void __exit eti_b1_exit(void)
+{
+	struct atmel_ssc_periph *ssc_p = eti_b1_dai.cpu_dai->private_data;
+	struct ssc_device *ssc;
+
+	clk_put(pck1_clk);
+	clk_put(pllb_clk);
+
+	if (ssc_p != NULL) {
+		ssc = ssc_p->ssc;
+		if (ssc != NULL)
+			ssc_free(ssc);
+		ssc_p->ssc = NULL;
+	}
+
+	platform_device_unregister(eti_b1_snd_device);
+}
+
+module_init(eti_b1_init);
+module_exit(eti_b1_exit);
+
+/* Module information */
+MODULE_AUTHOR("Frank Mandarino <[email protected]>");
+MODULE_DESCRIPTION("ALSA SoC ETI-B1-WM8731");
+MODULE_LICENSE("GPL");
sound/soc/atmel/playpaq_wm8510.c new file +522 -0

522 lines not on this page · raw message

sound/soc/atmel/sam9g20_wm8731.c new file +328 -0

328 lines not on this page · raw message

#1 lore raw
Quoted 3 lines · Sedji Gaouaou

This last patch contains the board specific files. I have not changed playpaq_wm8510.c, and I did few changes on eti_b1_wm8731.c.

It'd be better to submit this as two separate patches, one making the modifications to eti_b1_wm8731.c and another doing the simple code move (in either order). This would make it easier to review the changes - due to the file move they're not really visible in the current patch.

It'd also be good to see acks from Frank and Geoffrey since I can't test any of this.

Thanks for doing this work - it looks good, unifying the support for the AT91 and AVR32 platforms is a substantial win and it's good to see Atmel contributing this support.

#2 lore raw

Hi Mark,

Quoted 10 lines · Mark Brown
Quoted 3 lines · Sedji Gaouaou

This last patch contains the board specific files. I have not changed playpaq_wm8510.c, and I did few changes on eti_b1_wm8731.c.

It'd be better to submit this as two separate patches, one making the modifications to eti_b1_wm8731.c and another doing the simple code move (in either order). This would make it easier to review the changes - due to the file move they're not really visible in the current patch.

Quoted 7 lines

It'd also be good to see acks from Frank and Geoffrey since I can't test any of this.

Thanks for doing this work - it looks good, unifying the support for the AT91 and AVR32 platforms is a substantial win and it's good to see Atmel contributing this support.

Unfortunately I can't test this code on eti nor avr boards since we don't have any here. So any test would be much appreciated indeed.

Furthermore I didn't change the i2c initialization since I don't know what is the status of the patch(I tried this one:
http://git.kernel.org/?p=linux/kernel/git/tiwai/sound-2.6.git;a=commitdiff;h=be99827ea333eb15560a8b52ba57a2dce1bdfbb8
but I not sure whether it is complete or not?

I have send a first patch which is removing the two directories(at91 and at32), but I am not sure it is the proper way to do it.(it seems that it is blocked by the moderator).

I will work on your comments and I will send another patch.

Regards,
Sedji

#3 lore raw
Quoted 4 lines · Sedji Gaouaou

Furthermore I didn't change the i2c initialization since I don't know what is the status of the patch(I tried this one:
http://git.kernel.org/?p=linux/kernel/git/tiwai/sound-2.6.git;a=commitdiff;h=be99827ea333eb15560a8b52ba57a2dce1bdfbb8
but I not sure whether it is complete or not?

I'm not sure exactly what your concern is here? Anything you submit needs to be against what's in Takashi's tree.

Quoted 3 lines

I have send a first patch which is removing the two directories(at91 and at32), but I am not sure it is the proper way to do it.(it seems that it is blocked by the moderator).

The patch was just too large for the mailing list and got trapped by the size limits. It's probably better to make that the final patch of the series but it doesn't make a huge amount of difference overall.

#4 lore raw

At Fri, 26 Sep 2008 14:15:29 +0100,

Quoted 11 lines · Mark Brown
Quoted 4 lines · Sedji Gaouaou

Furthermore I didn't change the i2c initialization since I don't know what is the status of the patch(I tried this one:
http://git.kernel.org/?p=linux/kernel/git/tiwai/sound-2.6.git;a=commitdiff;h=be99827ea333eb15560a8b52ba57a2dce1bdfbb8
but I not sure whether it is complete or not?

I'm not sure exactly what your concern is here? Anything you submit needs to be against what's in Takashi's tree.

Quoted 7 lines
Quoted 3 lines

I have send a first patch which is removing the two directories(at91 and at32), but I am not sure it is the proper way to do it.(it seems that it is blocked by the moderator).

The patch was just too large for the mailing list and got trapped by the size limits. It's probably better to make that the final patch of the series but it doesn't make a huge amount of difference overall.

To be noted, git can handle renames well. So, one commit should include both removal of at*/ and addition atmel/, instead of separating them, which breaks the history.

And, if we need to rename the files, let me apply it later, after merging all other topic branches for 2.6.28. The rename patch will be applied at last.

Other changes like for eti_b1_wm8731.c can be separated patches as Mark suggested. This one can be applied beforehand at any time (suppose it's independent from renames).

BTW, I also didn't get the first one (although I expect it's just removal of them). Please add my address to Cc at the next post.

thanks,

Takashi

#5 lore raw
Quoted 3 lines · Takashi Iwai

To be noted, git can handle renames well. So, one commit should include both removal of at*/ and addition atmel/, instead of separating them, which breaks the history.

Yeah - I didn't mention this since I fear that it's going to break the history anyway due to the merge, unfortunately. There's quite a lot of textual differences between the code for the two architectures that are being merged, though mostly insubstantial ones.

If you do post everything as a single patch please use git format-patch -M which will hopefully produce a much more legible patch for review. If you're not using git to generate the patch then it might be best to stick with submitting separately for ease of review. In that case I guess either myself or Takashi could squash the patches together in git to try to preserve as much of the history as we can.

#6 lore raw
In reply to Mark Brown
Quoted 7 lines · Mark Brown
Quoted 3 lines · Sedji Gaouaou

This last patch contains the board specific files. I have not changed playpaq_wm8510.c, and I did few changes on eti_b1_wm8731.c.

It'd also be good to see acks from Frank and Geoffrey since I can't test any of this.

I can't test this out right away, as I'm not working on the AVR32 project right now. I'll try to give it a whirl next week.

Quoted 3 lines

Thanks for doing this work - it looks good, unifying the support for the AT91 and AVR32 platforms is a substantial win and it's good to see Atmel contributing this support.

Thanks from me, as well.

---
Geoffrey

#7 lore raw
In reply to Mark Brown
Quoted 10 lines · Mark Brown
Quoted 3 lines · Sedji Gaouaou

This last patch contains the board specific files. I have not changed playpaq_wm8510.c, and I did few changes on eti_b1_wm8731.c.

It'd be better to submit this as two separate patches, one making the modifications to eti_b1_wm8731.c and another doing the simple code move (in either order). This would make it easier to review the changes - due to the file move they're not really visible in the current patch.

Quoted 6 lines

It'd also be good to see acks from Frank and Geoffrey since I can't test any of this.

Thanks for doing this work - it looks good, unifying the support for the AT91 and AVR32 platforms is a substantial win and it's good to see Atmel contributing this support.

Sedji,

Thanks very much for your effort in creating the common Atmel SCC audio driver.

I would very much like to test your new ASoC platform driver, but unfortunately this will have to wait until we can upgrade the kernel in our product.

That being said, I am wondering if it is worth keeping eti_b1_wm8731.c in the kernel.

I originally included eti_b1_wm8731.c in the kernel as an example of a machine driver for others who wanted to use the AT91 ASoC driver. The ETI_B1 board is specific to our product and we have no plans to ever sell it.

Now that there are other Atmel ASoC machine drivers in the kernel, and given the fact that our company does not have the resources to actively maintain it, I think the eti_b1_wm8731.c driver should be removed.

This reduces the effort in maintaining ASoC, as eti_b1_wm8731.c would no longer have to be kept up-to-date with ASoC changes. It also eases the pressure on me to test ASoC updates against eti_b1_wm8731.c as they are made.

So unless you or Mark feels the eti_b1_wm8731.c driver should remain in the kernel source, I'll submit a patch to remove it after your patches are in place.

Regards,
../fam

Signature · 3 lines
Frank Mandarino                                fmandarino(a)endrelia.com
Endrelia Technologies Inc.
Toronto, Ontario, Canada
#8 lore raw
Quoted 4 lines · Frank Mandarino

Now that there are other Atmel ASoC machine drivers in the kernel, and given the fact that our company does not have the resources to actively maintain it, I think the eti_b1_wm8731.c driver should be removed.

Quoted 8 lines

This reduces the effort in maintaining ASoC, as eti_b1_wm8731.c would no longer have to be kept up-to-date with ASoC changes. It also eases the pressure on me to test ASoC updates against eti_b1_wm8731.c as they are made.

So unless you or Mark feels the eti_b1_wm8731.c driver should remain in the kernel source, I'll submit a patch to remove it after your patches are in place.

Sounds like a plan - may be just as well to submit the patch now given that Sedji is modifying the driver anyway, it might make his life slightly easier?

#9 lore raw
Quoted 11 lines · Mark Brown
Quoted 8 lines · Frank Mandarino

Now that there are other Atmel ASoC machine drivers in the kernel, and given the fact that our company does not have the resources to actively maintain it, I think the eti_b1_wm8731.c driver should be removed.

This reduces the effort in maintaining ASoC, as eti_b1_wm8731.c would no longer have to be kept up-to-date with ASoC changes. It also eases the pressure on me to test ASoC updates against eti_b1_wm8731.c as they are made.

Quoted 7 lines
Quoted 3 lines

So unless you or Mark feels the eti_b1_wm8731.c driver should remain in the kernel source, I'll submit a patch to remove it after your patches are in place.

Sounds like a plan - may be just as well to submit the patch now given that Sedji is modifying the driver anyway, it might make his life slightly easier?

I have no problem submitting a patch sooner, but it might be a few days before I can start on this.

I'll leave it up to Sedji to decide if I should wait until he is done or not.

../fam

Signature · 3 lines
Frank Mandarino                                fmandarino(a)endrelia.com
Endrelia Technologies Inc.
Toronto, Ontario, Canada
#10 lore raw
Quoted 8 lines · Frank Mandarino

I have no problem submitting a patch sooner, but it might be a few days before I can start on this.

I'll leave it up to Sedji to decide if I should wait until he is done or not.

../fam

If you can submit your patch it will be great(whenever you can will be good).
From now I will work considering that you have removed the eti files,
and I will send my patch once you will have send yours.
Is that ok?

Regards,
Sedji

#11 lore raw
Quoted 5 lines · Sedji Gaouaou

If you can submit your patch it will be great(whenever you can will be good).
From now I will work considering that you have removed the eti files, and I will send my patch once you will have send yours.
Is that ok?

Fine with me. I'll do it as soon as I can.

Regards,
../fam

Signature · 3 lines
Frank Mandarino                                fmandarino(a)endrelia.com
Endrelia Technologies Inc.
Toronto, Ontario, Canada