Sound support for at91sam9x5-wm8731 based boards
Subsystems (6)
v5 cover Sound support for at91sam9x5-wm8731 based boards
Hi,
This patchset add sound on the at91sam9x5ek board.
It's based on Nicolas Ferre's work in the 2.6.39 atmel patch for sam9x5:
https://github.com/linux4sam/linux-at91/commit/0aa157c9e71ccccf3abc30fa37eb5c95b392978d
It needs Bo Chen's patchset on the generic dmaengine (topic/atmel branch on Mark's sound tree) and the SSC interrupts disabled (cf
http://www.spinics.net/lists/arm-kernel/msg256901.html)
Outstanding issue:
If this machine driver will support more SoCs maybe we should name it differently.
It has been tested on at91sam9g35ek, and should work on g15, g25, x25 and x35 also.
patches applies on next-20130711
[I let the original signed-off from Nicolas and Uwe in place, I don't know if I should replace them by something like "originaly-signed-off-by" since the code has been changed.]
Changes from v4:
* Move the rates constraints into the codec
* Hard code the DAI format since it cannot be changed anyway (and
remove the DT bindings accordingly)
* Add some consistency in the functions naming (sam9x5ek/at91sam9x5ek/sam9x5)
* Retrieve the SSC id from the SSC controller phandle
* Clarify the atmel-ssc.txt documentation
* Develop audio-routing documentation
* Tidy up the includes in the machine driver
Changes from v3:
* Remove the use of macros in device tree documentation.
Changes from v2:
* Change atmel,sam9x5-audio-wm8731 to atmel,sam9x5-wm8731-audio for
consistency with sam9g20 machine driver.
* Use the snd_pcm_hw_constraint() API as suggested by Mark and Lars-Peter.
* Remove the unnecessary snd_soc_dapm_sync() call as Lars-Peter suggested.
* Add documentation for machine driver DT binding.
* Update atmel-ssc DT binding documentation.
* Add GPL license instead of just the "GPL" word (hope that's ok !)
Changes from v1-RFC:
* drop patches on SSC since Bo Chen already did the work
* reorder patches to have the machine driver first
* drop code already handled by the ASoC framework
* drop unneeded SND_ATMEL_SOC_PDC config selection
* use static snd_soc_card and snd_soc_dai_link structures.
Best regards,
Richard.
Nicolas Ferre (1):
sound: sam9x5_wm8731: machine driver for at91sam9x5 wm8731 boards
Richard Genoud (6):
sound: codec: wm8731: add rates constraints
Documentation: DT: update atmel SSC with DMA binding
ARM: AT91: DTS: sam9x5: add SSC DMA parameters
ARM: AT91: DTS: sam9x5ek: add WM8731 codec
ARM: AT91: DTS: sam9x5ek: enable SSC
ARM: AT91: DTS: sam9x5ek: add sound configuration
.../devicetree/bindings/misc/atmel-ssc.txt | 23 ++- .../bindings/sound/atmel-sam9x5-wm8731-audio.txt | 41 ++++ arch/arm/boot/dts/at91sam9x5.dtsi | 3 + arch/arm/boot/dts/at91sam9x5ek.dtsi | 24 +++ sound/soc/atmel/Kconfig | 10 + sound/soc/atmel/Makefile | 2 + sound/soc/atmel/sam9x5_wm8731.c | 207 ++++++++++++++++++++ sound/soc/codecs/wm8731.c | 57 +++++- 8 files changed, 363 insertions(+), 4 deletions(-) create mode 100644 Documentation/devicetree/bindings/sound/atmel-sam9x5-wm8731-audio.txt create mode 100644 sound/soc/atmel/sam9x5_wm8731.c
Signature · 1 line
1.7.10.4
PATCH v5 1/7 sound: codec: wm8731: add rates constraints
Depending on the mclk (or crystal) selected, the wm8731 codec have some constraints on its data sampling rates:
e.g. with a 12.288MHz or 18.432MHz crystal, the authorized rates are 8KHz, 32KHz, 48KHz and 96KHz.
--- sound/soc/codecs/wm8731.c | 57 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 3 deletions(-)
sound/soc/codecs/wm8731.c +54 -3
@@ -45,6 +45,7 @@ static const char *wm8731_supply_names[WM8731_NUM_SUPPLIES] = {struct wm8731_priv {struct regmap *regmap;struct regulator_bulk_data supplies[WM8731_NUM_SUPPLIES ]; +const struct snd_pcm_hw_constraint_list *constraints;unsigned int sysclk;int sysclk_type;int playback_fs;
@@ -290,6 +291,36 @@ static const struct _coeff_div coeff_div[] = { {12000000, 88200, 136, 0xf, 0x1, 0x1}, }; +/* rates constraints */ +static const unsigned int wm8731_rates_12000000[] = { +8000 ,32000 ,44100 ,48000 ,96000 ,88200 , +}; + +static const unsigned int wm8731_rates_12288000_18432000[] = { +8000 ,32000 ,48000 ,96000 , +}; + +static const unsigned int wm8731_rates_11289600_16934400[] = { +8000 ,44100 ,88200 , +}; + +static const struct snd_pcm_hw_constraint_list wm8731_constraints_12000000 = { + .list = wm8731_rates_12000000, + .count =ARRAY_SIZE (wm8731_rates_12000000), +}; + +static const +struct snd_pcm_hw_constraint_list wm8731_constraints_12288000_18432000 = { + .list = wm8731_rates_12288000_18432000, + .count =ARRAY_SIZE (wm8731_rates_12288000_18432000), +}; + +static const +struct snd_pcm_hw_constraint_list wm8731_constraints_11289600_16934400 = { + .list = wm8731_rates_11289600_16934400, + .count =ARRAY_SIZE (wm8731_rates_11289600_16934400), +}; +static inline int get_coeff (int mclk,int rate) {int i;
@@ -362,17 +393,23 @@ static int wm8731_set_dai_sysclk(struct snd_soc_dai *codec_dai, }switch (freq) { -case 11289600 :case 12000000 : + wm8731->constraints = &wm8731_constraints_12000000; +break ;case 12288000 : -case 16934400 :case 18432000 : - wm8731->sysclk = freq; + wm8731->constraints = &wm8731_constraints_12288000_18432000; +break ; +case 16934400 : +case 11289600 : + wm8731->constraints = &wm8731_constraints_11289600_16934400;break ;default :return -EINVAL ; } + wm8731->sysclk = freq; +snd_soc_dapm_sync (&codec->dapm);return 0 ;
@@ -475,12 +512,26 @@ static int wm8731_set_bias_level(struct snd_soc_codec *codec,return 0 ; } +static int wm8731_startup (struct snd_pcm_substream *substream, +struct snd_soc_dai *dai) +{ +struct wm8731_priv *wm8731 =snd_soc_codec_get_drvdata (dai->codec); + +if (wm8731->constraints) +snd_pcm_hw_constraint_list (substream->runtime,0 , +SNDRV_PCM_HW_PARAM_RATE , + wm8731->constraints); + +return 0 ; +} +#define WM8731_RATES SNDRV_PCM_RATE_8000_96000#define WM8731_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ SNDRV_PCM_FMTBIT_S24_LE)static const struct snd_soc_dai_ops wm8731_dai_ops = { + .startup = wm8731_startup, .hw_params = wm8731_hw_params, .digital_mute = wm8731_mute, .set_sysclk = wm8731_set_dai_sysclk,
Signature · 1 line
1.7.10.4
PATCH v5 2/7 sound: sam9x5_wm8731: machine driver for at91sam9x5 wm8731 boards
In reply to Richard GenoudFrom: Nicolas Ferre <[email protected]>
Description of the Asoc machine driver for an at91sam9x5 based board with a wm8731 audio DAC. Wm8731 is clocked by a crystal and used as a master on the SSC/I2S interface. Its connections are a headphone jack and an Line input jack.
[Richard: this is based on an old patch from Nicolas that I forward ported and reworked to use only device tree]
--- .../bindings/sound/atmel-sam9x5-wm8731-audio.txt | 41 ++++ sound/soc/atmel/Kconfig | 10 + sound/soc/atmel/Makefile | 2 + sound/soc/atmel/sam9x5_wm8731.c | 207 ++++++++++++++++++++ 4 files changed, 260 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/atmel-sam9x5-wm8731-audio.txt create mode 100644 sound/soc/atmel/sam9x5_wm8731.c
Documentation/devicetree/bindings/sound/atmel-sam9x5-wm8731-audio.txt new file +41 -0
@@ -0,0 +1,41 @@ +* Atmel at91sam9x5ek wm8731 audio complex + +Required properties: + - compatible: "atmel,sam9x5-wm8731-audio" + - atmel,model: The user-visible name of this sound complex. + - atmel,ssc-controller: The phandle of the SSC controller + - atmel,audio-codec: The phandle of the WM8731 audio codec + - atmel,audio-routing: A list of the connections between audio components. + Each entry is a pair of strings, the first being the connection's sink, + the second being the connection's source. + +Available audio endpoints for the audio-routing table: + +Board connectors: + * Headphone Jack + * Line In Jack + +sam9x5 pins: + * LOUT + * ROUT + * LHPOUT + * RHPOUT + * LLINEIN + * RLINEIN + * MICIN + +Example: +sound { + compatible = "atmel,sam9x5-wm8731-audio"; + + atmel,model = "wm8731 @ AT91SAM9X5EK"; + + atmel,audio-routing = + "Headphone Jack", "RHPOUT", + "Headphone Jack", "LHPOUT", + "LLINEIN", "Line In Jack", + "RLINEIN", "Line In Jack"; + + atmel,ssc-controller = <&ssc0>; + atmel,audio-codec = <&wm8731>; +};
sound/soc/atmel/Kconfig +10 -0
@@ -33,6 +33,16 @@ config SND_AT91_SOC_SAM9G20_WM8731 Say Y if you want to add support for SoC audio on WM8731-based AT91sam9g20 evaluation board. +config SND_AT91_SOC_SAM9X5_WM8731 + tristate "SoC Audio support for WM8731-based at91sam9x5 board" + depends on ATMEL_SSC && SND_ATMEL_SOC && SOC_AT91SAM9X5 + select SND_ATMEL_SOC_SSC + select SND_ATMEL_SOC_DMA + select SND_SOC_WM8731 + help + Say Y if you want to add support for audio SoC on an + at91sam9x5 based board that is using WM8731 codec. + config SND_AT91_SOC_AFEB9260 tristate "SoC Audio support for AFEB9260 board" depends on ARCH_AT91 && ATMEL_SSC && ARCH_AT91 && MACH_AFEB9260 && SND_ATMEL_SOC
sound/soc/atmel/Makefile +2 -0
@@ -11,6 +11,8 @@ obj-$(CONFIG_SND_ATMEL_SOC_SSC) += snd-soc-atmel_ssc_dai.o # AT91 Machine Support snd-soc-sam9g20-wm8731-objs := sam9g20_wm8731.o +snd-soc-sam9x5-wm8731-objs := sam9x5_wm8731.o obj-$(CONFIG_SND_AT91_SOC_SAM9G20_WM8731) += snd-soc-sam9g20-wm8731.o +obj-$(CONFIG_SND_AT91_SOC_SAM9X5_WM8731) += snd-soc-sam9x5-wm8731.o obj-$(CONFIG_SND_AT91_SOC_AFEB9260) += snd-soc-afeb9260.o
sound/soc/atmel/sam9x5_wm8731.c new file +207 -0
207 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH v5 3/7 Documentation: DT: update atmel SSC with DMA binding
In reply to Richard GenoudAs atmel-ssc can be used with DMA, the documentation should be updated. Also, a configuration DMA example is given.
--- .../devicetree/bindings/misc/atmel-ssc.txt | 23 +++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/misc/atmel-ssc.txt +22 -1
@@ -7,9 +7,30 @@ Required properties: - reg: Should contain SSC registers location and length - interrupts: Should contain SSC interrupt -Example: + +Required properties for devices compatible with "atmel,at91sam9g45-ssc": +- dmas: DMA specifier, consisting of a phandle to DMA controller node, + the memory interface and SSC DMA channel ID (for tx and rx). + See Documentation/devicetree/bindings/dma/atmel-dma.txt for details. +- dma-names: Must be "tx", "rx". + +Examples: +- PDC transfer: ssc0: ssc@fffbc000 { compatible = "atmel,at91rm9200-ssc"; reg = <0xfffbc000 0x4000>; interrupts = <14 4 5>; }; + +- DMA transfer: +ssc0: ssc@f0010000 { + compatible = "atmel,at91sam9g45-ssc"; + reg = <0xf0010000 0x4000>; + interrupts = <28 4 5>; + dmas = <&dma0 1 13>, + <&dma0 1 14>; + dma-names = "tx", "rx"; + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_ssc0_tx &pinctrl_ssc0_rx>; + status = "disabled"; +};
Signature · 1 line
1.7.10.4
PATCH v5 4/7 ARM: AT91: DTS: sam9x5: add SSC DMA parameters
In reply to Richard Genoud--- arch/arm/boot/dts/at91sam9x5.dtsi | 3 +++ 1 file changed, 3 insertions(+)
arch/arm/boot/dts/at91sam9x5.dtsi +3 -0
@@ -542,6 +542,9 @@ compatible = "atmel,at91sam9g45-ssc"; reg = <0xf0010000 0x4000>; interrupts = <28 IRQ_TYPE_LEVEL_HIGH 5>; + dmas = <&dma0 1 AT91_DMA_CFG_PER_ID(13)>, + <&dma0 1 AT91_DMA_CFG_PER_ID(14)>; + dma-names = "tx", "rx"; pinctrl-names = "default"; pinctrl-0 = <&pinctrl_ssc0_tx &pinctrl_ssc0_rx>; status = "disabled";
Signature · 1 line
1.7.10.4
PATCH v5 5/7 ARM: AT91: DTS: sam9x5ek: add WM8731 codec
In reply to Richard GenoudThe WM8731 codec on sam9x5ek board is on i2c, address 1A
--- arch/arm/boot/dts/at91sam9x5ek.dtsi | 5 +++++ 1 file changed, 5 insertions(+)
arch/arm/boot/dts/at91sam9x5ek.dtsi +5 -0
@@ -59,6 +59,11 @@ i2c0: i2c@f8010000 { status = "okay"; + + wm8731: wm8731@1a { + compatible = "wm8731"; + reg = <0x1a>; + }; }; pinctrl@fffff400 {
Signature · 1 line
1.7.10.4
PATCH v5 6/7 ARM: AT91: DTS: sam9x5ek: enable SSC
In reply to Richard GenoudEnable the SSC needed for the WM8731 codec
--- arch/arm/boot/dts/at91sam9x5ek.dtsi | 4 ++++ 1 file changed, 4 insertions(+)
arch/arm/boot/dts/at91sam9x5ek.dtsi +4 -0
@@ -95,6 +95,10 @@ watchdog@fffffe40 { status = "okay"; }; + + ssc0: ssc@f0010000 { + status = "okay"; + }; }; usb0: ohci@00600000 {
Signature · 1 line
1.7.10.4
PATCH v5 7/7 ARM: AT91: DTS: sam9x5ek: add sound configuration
In reply to Richard GenoudThe sam9x5ek board has 2 jacks:
headphone wired on RHPOUT/LHPOUT of the wm8731
line in wired on LLINEIN/RLINEIN of the wm8731
--- arch/arm/boot/dts/at91sam9x5ek.dtsi | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
arch/arm/boot/dts/at91sam9x5ek.dtsi +15 -0
@@ -113,4 +113,19 @@ status = "okay"; }; }; + + sound { + compatible = "atmel,sam9x5-wm8731-audio"; + + atmel,model = "wm8731 @ AT91SAM9X5EK"; + + atmel,audio-routing = + "Headphone Jack", "RHPOUT", + "Headphone Jack", "LHPOUT", + "LLINEIN", "Line In Jack", + "RLINEIN", "Line In Jack"; + + atmel,ssc-controller = <&ssc0>; + atmel,audio-codec = <&wm8731>; + }; };
Signature · 1 line
1.7.10.4
Mark Brown
maintainerRe: [PATCH v5 1/7] sound: codec: wm8731: add rates constraints
In reply to Richard GenoudOn Thu, Jul 11, 2013 at 06:15:53PM +0200, Richard Genoud wrote:
Please always try to use commit logs that look like normal commit logs for the subsystem.
Quoted 8 lines
sound/soc/codecs/wm8731.c +2
-2switch (freq) { -case 11289600 :case 12000000 : + wm8731->constraints = &wm8731_constraints_12000000; +break ;case 12288000 : -case 16934400 :case 18432000 :
sound/soc/codecs/wm8731.c static int wm8731_set_dai_sysclk(struct snd_soc_dai *codec_dai, · line 409
Quoted 10 lines
sound/soc/codecs/wm8731.c +5
-1- wm8731->sysclk = freq; + wm8731->constraints = &wm8731_constraints_12288000_18432000; +break ; +case 16934400 : +case 11289600 : + wm8731->constraints = &wm8731_constraints_11289600_16934400;break ;default :return -EINVAL ; }
This isn't going to work with systems which have a variable clock as the input to the CODEC. If it's imposing constraints the driver needs to allow setting the clock to zero as a way of removing constraints (and any existing drivers should be updated to do this if needed).
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Mark Brown
maintainerRe: [PATCH v5 2/7] sound: sam9x5_wm8731: machine driver for at91sam9x5 wm8731 boards
In reply to Richard GenoudQuoted 3 lines · Richard Genoud
From: Nicolas Ferre <[email protected]>
Description of the Asoc machine driver for an at91sam9x5 based board
ASoC.
Quoted 8 lines
+sam9x5 pins:
+ * LOUT
+ * ROUT
+ * LHPOUT
+ * RHPOUT
+ * LLINEIN
+ * RLINEIN
+ * MICIN
These aren't pins on the CPU, they're pins on the CODEC, and you should be adding this to the binding document for the CODEC and referring to that rather than having them in each individual binding document. This also helps if any new variants are added (not that this is likely for the WM8731).
Quoted 1 line
+static struct
sam9x5_drvdatasam9x5_priv;
Why is this a global static?
sound/soc/atmel/sam9x5_wm8731.c line 162
Quoted 8 lines
sound/soc/atmel/sam9x5_wm8731.c new file +7
-0+ ret =snd_soc_register_card (&snd_soc_sam9x5); +if (ret) { +dev_err (&pdev->dev, +"ASoC: Platform device allocation failed\n" ); + goto out_put_audio; + } +platform_set_drvdata (pdev, &snd_soc_sam9x5);
It should be being dynamically allocated and retrieved as driver data when needed.
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v5 1/7] sound: codec: wm8731: add rates constraints
In reply to Mark Brown2013/7/12 Mark Brown <[email protected]>:
Quoted 4 lines · Richard Genoud
Please always try to use commit logs that look like normal commit logs for the subsystem.
Ok, I'll pay attention to that.
Quoted 19 lines
Quoted 8 lines
switch (freq) {sound/soc/codecs/wm8731.c +2
-2-case 11289600 :case 12000000 : + wm8731->constraints = &wm8731_constraints_12000000; +break ;case 12288000 : -case 16934400 :case 18432000 :sound/soc/codecs/wm8731.c static int wm8731_set_dai_sysclk(struct snd_soc_dai *codec_dai, · line 409
Quoted 10 lines
sound/soc/codecs/wm8731.c +5
-1- wm8731->sysclk = freq; + wm8731->constraints = &wm8731_constraints_12288000_18432000; +break ; +case 16934400 : +case 11289600 : + wm8731->constraints = &wm8731_constraints_11289600_16934400;break ;default :return -EINVAL ; }
Quoted 4 lines
This isn't going to work with systems which have a variable clock as the input to the CODEC. If it's imposing constraints the driver needs to allow setting the clock to zero as a way of removing constraints (and any existing drivers should be updated to do this if needed).
Maybe I'm wrong, but I didn't find any system using variable clock with this codec.
The sam9g20ek (soc/atmel/sam9g20_wm8731.c) is not using a crystal, but it's using a fixed clock anyway.
But there's soc/pxa/corgi.c and soc/pxa/poodle.c that puzzle me. They seems to use a crystal, but they are setting a different sysclk depending on the rate.
That seems wrong, but as I'm a newbie in ASoC...
Re: [PATCH v5 2/7] sound: sam9x5_wm8731: machine driver for at91sam9x5 wm8731 boards
In reply to Mark Brown2013/7/12 Mark Brown <[email protected]>:
Quoted 16 lines · Richard Genoud
Quoted 3 lines
From: Nicolas Ferre <[email protected]>
Description of the Asoc machine driver for an at91sam9x5 based board
ASoC.
Quoted 8 lines
+sam9x5 pins:
+ * LOUT
+ * ROUT
+ * LHPOUT
+ * RHPOUT
+ * LLINEIN
+ * RLINEIN
+ * MICIN
Quoted 5 lines
These aren't pins on the CPU, they're pins on the CODEC, and you should be adding this to the binding document for the CODEC and referring to that rather than having them in each individual binding document. This also helps if any new variants are added (not that this is likely for the WM8731).
ok, I'll move that
Quoted 12 lines
Quoted 2 lines
+static struct
sam9x5_drvdatasam9x5_priv;Why is this a global static?
Quoted 6 lines
sound/soc/atmel/sam9x5_wm8731.c new file +6
-0+ ret =snd_soc_register_card (&snd_soc_sam9x5); +if (ret) { +dev_err (&pdev->dev, +"ASoC: Platform device allocation failed\n" ); + goto out_put_audio; + }
Quoted 4 lines
Quoted 1 line
+
platform_set_drvdata(pdev, &snd_soc_sam9x5);It should be being dynamically allocated and retrieved as driver data when needed.
ok.
Thanks !
Signature · 1 line
for me, ck means con kolivas and not calvin klein... does it mean I'm a geek ?
Mark Brown
maintainerRe: [PATCH v5 1/7] sound: codec: wm8731: add rates constraints
In reply to Richard GenoudQuoted 9 lines · Richard Genoud
2013/7/12 Mark Brown <[email protected]>:
Quoted 4 lines
This isn't going to work with systems which have a variable clock as the input to the CODEC. If it's imposing constraints the driver needs to allow setting the clock to zero as a way of removing constraints (and any existing drivers should be updated to do this if needed).
Maybe I'm wrong, but I didn't find any system using variable clock with this codec.
The driver should be written with that possibility in mind even if there were no users; it only takes a couple of lines of code.
Quoted 6 lines
The sam9g20ek (
soc/atmel/sam9g20_wm8731.c) is not using a crystal, but it's using a fixed clock anyway.
But there'ssoc/pxa/corgi.candsoc/pxa/poodle.cthat puzzle me. They seems to use a crystal, but they are setting a different sysclk depending on the rate.
That seems wrong, but as I'm a newbie in ASoC...
Note that the CPU is clock master for those - it's going to be outputting a clock based on the sample rate selected automatically. These boards would be broken by your change as it stands.