ASoC: sun4i-codec: Add support for A31 Codec
Subsystems (4)
v3 cover ASoC: sun4i-codec: Add support for A31 Codec
Hi everyone,
This is v3 of my Allwinner A31 audio codec support series. These are the remaining driver patches not yet merged, with 1 new fix, and the dts file patches.
The A31's internal codec is similar (in terms of DMA, interface and control layouts) to the one found in the A10/A13/A20 SoCs. However it has more external inputs and outputs, the mixer controls are now stereo (left/right separated), and it also has some audio processing features (not supported yet).
Changes since v2:
- Added patch """ASoC: sun4i-codec: Add "Right Mixer" to "Line Out Mono Diff." route""" which fixes line out when all the sources have their left channel muted.
- Dropped unused codec_pa_pin from A31 hummingbird dts patch. In the past we always provided a pinmux setting for GPIOs used, to avoid accidentally muxing a pin that was already used for GPIO, or vice versa. The pinctrl subsystem now supports exclusive use of a pin for GPIO, which the sunxi platform wants to migrate to. This drops the requirement of the explicit pinmux setting for GPIOs.
- Added Maxime's Acked-by for the two existing patches from v2.
After these are merged I plan to submit patches to support the audio codec found in Allwinner's A23 and H3 SoCs.
Regards
ChenYu
Chen-Yu Tsai (6):
ASoC: sun4i-codec: Add support for optional reset control to quirks
ASoC: sun4i-codec: Add support for A31 ADC capture path
ASoC: sun4i-codec: Add "Right Mixer" to "Line Out Mono Diff." route
ARM: dts: sun6i: Add audio codec device node
ARM: dts: sun6i: hummingbird: Enable internal audio codec
ARM: dts: sun6i: sina31s: Enable internal audio codec
arch/arm/boot/dts/sun6i-a31-hummingbird.dts | 13 ++++ arch/arm/boot/dts/sun6i-a31.dtsi | 13 ++++ arch/arm/boot/dts/sun6i-a31s-sina31s.dts | 8 +++ sound/soc/sunxi/sun4i-codec.c | 94 ++++++++++++++++++++++++++++- 4 files changed, 127 insertions(+), 1 deletion(-)
Signature · 1 line
2.10.2
PATCH v3 1/6 ASoC: sun4i-codec: Add support for optional reset control to quirks
The later Allwinner SoCs have a dedicated reset controller, and peripherals have dedicated reset controls which need to be deasserted before the associated peripheral can be used.
Add support for this to the quirks structure and probe/remove functions.
--- sound/soc/sunxi/sun4i-codec.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)
sound/soc/sunxi/sun4i-codec.c +27 -1
@@ -30,6 +30,7 @@#include <linux/of_platform.h> #include <linux/clk.h> #include <linux/regmap.h> +#include <linux/reset.h> #include <linux/gpio/consumer.h> #include <sound/core.h>
@@ -217,6 +218,7 @@ struct sun4i_codec {struct regmap *regmap;struct clk *clk_apb;struct clk *clk_module; +struct reset_control *rst;struct gpio_desc *gpio_pa;/* ADC_FIFOC register is at different offset on different SoCs */
@@ -1167,6 +1169,7 @@ struct sun4i_codec_quirks {struct reg_field reg_adc_fifoc;/* used for regmap_field */ unsigned int reg_dac_txdata;/* TX FIFO offset for DMA config */ unsigned int reg_adc_rxdata;/* RX FIFO offset for DMA config */ +bool has_reset; };static const struct sun4i_codec_quirks sun4i_codec_quirks = {
@@ -1262,6 +1265,14 @@ static int sun4i_codec_probe(struct platform_device *pdev)return PTR_ERR (scodec->clk_module); } +if (quirks->has_reset) { + scodec->rst =devm_reset_control_get (&pdev->dev,NULL ); +if (IS_ERR (scodec->rst)) { +dev_err (&pdev->dev,"Failed to get reset control\n" ); +return PTR_ERR (scodec->rst); + } + }; + scodec->gpio_pa =devm_gpiod_get_optional (&pdev->dev,"allwinner,pa" ,GPIOD_OUT_LOW );if (IS_ERR (scodec->gpio_pa)) {
@@ -1288,6 +1299,16 @@ static int sun4i_codec_probe(struct platform_device *pdev)return -EINVAL ; } +/* Deassert the reset control */ +if (scodec->rst) { + ret =reset_control_deassert (scodec->rst); +if (ret) { +dev_err (&pdev->dev, +"Failed to deassert the reset control\n" ); + goto err_clk_disable; + } + } +/* DMA configuration for TX FIFO */ scodec->playback_dma_data.addr = res->start + quirks->reg_dac_txdata; scodec->playback_dma_data.maxburst =8 ;
@@ -1302,7 +1323,7 @@ static int sun4i_codec_probe(struct platform_device *pdev) &sun4i_codec_dai, 1);if (ret) {dev_err (&pdev->dev,"Failed to register our codec\n" ); - goto err_clk_disable; + goto err_assert_reset; } ret = devm_snd_soc_register_component(&pdev->dev,
@@ -1339,6 +1360,9 @@ static int sun4i_codec_probe(struct platform_device *pdev) err_unregister_codec:snd_soc_unregister_codec (&pdev->dev); +err_assert_reset: +if (scodec->rst) +reset_control_assert (scodec->rst); err_clk_disable:clk_disable_unprepare (scodec->clk_apb);return ret;
@@ -1351,6 +1375,8 @@ static int sun4i_codec_remove(struct platform_device *pdev)snd_soc_unregister_card (card);snd_soc_unregister_codec (&pdev->dev); +if (scodec->rst) +reset_control_assert (scodec->rst);clk_disable_unprepare (scodec->clk_apb);return 0 ;
Signature · 1 line
2.10.2
PATCH v3 2/6 ASoC: sun4i-codec: Add support for A31 ADC capture path
In reply to Chen-Yu TsaiThe A31's internal codec capture path has a mixer in front of the ADC for each channel, capable of selecting various inputs, including microphones, line in, phone in, and the main output mixer.
This patch adds the various controls, widgets and routes needed for audio capture from the already supported inputs on the A31.
--- sound/soc/sunxi/sun4i-codec.c | 65 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+)
sound/soc/sunxi/sun4i-codec.c +65 -0
@@ -788,6 +788,30 @@ static const struct snd_kcontrol_new sun6i_codec_mixer_controls[] = { SUN6I_CODEC_OM_DACA_CTRL_RMIX_MIC2, 1, 0), }; +/* ADC mixer controls */ +static const struct snd_kcontrol_new sun6i_codec_adc_mixer_controls[] = { +SOC_DAPM_DOUBLE ("Mixer Capture Switch" , +SUN6I_CODEC_ADC_ACTL , +SUN6I_CODEC_ADC_ACTL_LADCMIX_OMIXL , +SUN6I_CODEC_ADC_ACTL_RADCMIX_OMIXR ,1 ,0 ), +SOC_DAPM_DOUBLE ("Mixer Reversed Capture Switch" , +SUN6I_CODEC_ADC_ACTL , +SUN6I_CODEC_ADC_ACTL_LADCMIX_OMIXR , +SUN6I_CODEC_ADC_ACTL_RADCMIX_OMIXL ,1 ,0 ), +SOC_DAPM_DOUBLE ("Line In Capture Switch" , +SUN6I_CODEC_ADC_ACTL , +SUN6I_CODEC_ADC_ACTL_LADCMIX_LINEINL , +SUN6I_CODEC_ADC_ACTL_RADCMIX_LINEINR ,1 ,0 ), +SOC_DAPM_DOUBLE ("Mic1 Capture Switch" , +SUN6I_CODEC_ADC_ACTL , +SUN6I_CODEC_ADC_ACTL_LADCMIX_MIC1 , +SUN6I_CODEC_ADC_ACTL_RADCMIX_MIC1 ,1 ,0 ), +SOC_DAPM_DOUBLE ("Mic2 Capture Switch" , +SUN6I_CODEC_ADC_ACTL , +SUN6I_CODEC_ADC_ACTL_LADCMIX_MIC2 , +SUN6I_CODEC_ADC_ACTL_RADCMIX_MIC2 ,1 ,0 ), +}; +/* headphone controls */ static const char *const sun6i_codec_hp_src_enum_text[] = {"DAC" ,"Mixer" ,
@@ -887,6 +911,10 @@ static const struct snd_kcontrol_new sun6i_codec_codec_widgets[] = {SOC_SINGLE_TLV ("Mic2 Boost Volume" ,SUN6I_CODEC_MIC_CTRL ,SUN6I_CODEC_MIC_CTRL_MIC2BOOST ,0x7 ,0 , sun6i_codec_mic_gain_scale), +SOC_DOUBLE_TLV ("ADC Capture Volume" , +SUN6I_CODEC_ADC_ACTL ,SUN6I_CODEC_ADC_ACTL_ADCLG , +SUN6I_CODEC_ADC_ACTL_ADCRG ,0x7 ,0 , + sun6i_codec_out_mixer_pregain_scale), }; static const struct snd_soc_dapm_widget sun6i_codec_codec_dapm_widgets[] = {
@@ -912,6 +940,23 @@ static const struct snd_soc_dapm_widget sun6i_codec_codec_dapm_widgets[] = {/* Line In */ SND_SOC_DAPM_INPUT ("LINEIN" ), +/* Digital parts of the ADCs */ +SND_SOC_DAPM_SUPPLY ("ADC Enable" ,SUN6I_CODEC_ADC_FIFOC , +SUN6I_CODEC_ADC_FIFOC_EN_AD ,0 , +NULL ,0 ), + +/* Analog parts of the ADCs */ +SND_SOC_DAPM_ADC ("Left ADC" ,"Codec Capture" ,SUN6I_CODEC_ADC_ACTL , +SUN6I_CODEC_ADC_ACTL_ADCLEN ,0 ), +SND_SOC_DAPM_ADC ("Right ADC" ,"Codec Capture" ,SUN6I_CODEC_ADC_ACTL , +SUN6I_CODEC_ADC_ACTL_ADCREN ,0 ), + +/* ADC Mixers */ +SOC_MIXER_ARRAY ("Left ADC Mixer" ,SND_SOC_NOPM ,0 ,0 , + sun6i_codec_adc_mixer_controls), +SOC_MIXER_ARRAY ("Right ADC Mixer" ,SND_SOC_NOPM ,0 ,0 , + sun6i_codec_adc_mixer_controls), +/* Digital parts of the DACs */ SND_SOC_DAPM_SUPPLY("DAC Enable", SUN4I_CODEC_DAC_DPC, SUN4I_CODEC_DAC_DPC_EN_DA, 0,
@@ -975,6 +1020,20 @@ static const struct snd_soc_dapm_route sun6i_codec_codec_dapm_routes[] = { { "Right Mixer", "Mic1 Playback Switch", "Mic1 Amplifier" }, { "Right Mixer", "Mic2 Playback Switch", "Mic2 Amplifier" }, +/* Left ADC Mixer Routes */ + { "Left ADC Mixer", "Mixer Capture Switch", "Left Mixer" }, + { "Left ADC Mixer", "Mixer Reversed Capture Switch", "Right Mixer" }, + { "Left ADC Mixer", "Line In Capture Switch", "LINEIN" }, + { "Left ADC Mixer", "Mic1 Capture Switch", "Mic1 Amplifier" }, + { "Left ADC Mixer", "Mic2 Capture Switch", "Mic2 Amplifier" }, + +/* Right ADC Mixer Routes */ + { "Right ADC Mixer", "Mixer Capture Switch", "Right Mixer" }, + { "Right ADC Mixer", "Mixer Reversed Capture Switch", "Left Mixer" }, + { "Right ADC Mixer", "Line In Capture Switch", "LINEIN" }, + { "Right ADC Mixer", "Mic1 Capture Switch", "Mic1 Amplifier" }, + { "Right ADC Mixer", "Mic2 Capture Switch", "Mic2 Amplifier" }, +/* Headphone Routes */ { "Headphone Source Playback Route", "DAC", "Left DAC" }, { "Headphone Source Playback Route", "DAC", "Right DAC" },
@@ -989,6 +1048,12 @@ static const struct snd_soc_dapm_route sun6i_codec_codec_dapm_routes[] = { { "Line Out Source Playback Route", "Stereo", "Right Mixer" }, { "Line Out Source Playback Route", "Mono Differential", "Left Mixer" }, { "LINEOUT", NULL, "Line Out Source Playback Route" }, + +/* ADC Routes */ + { "Left ADC", NULL, "ADC Enable" }, + { "Right ADC", NULL, "ADC Enable" }, + { "Left ADC", NULL, "Left ADC Mixer" }, + { "Right ADC", NULL, "Right ADC Mixer" }, }; static struct snd_soc_codec_driver sun6i_codec_codec = {
Signature · 1 line
2.10.2
PATCH v3 3/6 ASoC: sun4i-codec: Add "Right Mixer" to "Line Out Mono Diff." route
In reply to Chen-Yu TsaiThe mono differential output for "Line Out" downmixes the stereo audio from the mixer, instead of just taking the left channel.
Add a route from the "Right Mixer" to "Line Out Source Playback Route" through the "Mono Differential" path, so DAPM doesn't shut down everything if the left channel is muted.
playback")
--- sound/soc/sunxi/sun4i-codec.c | 1 + 1 file changed, 1 insertion(+)
sound/soc/sunxi/sun4i-codec.c +1 -0
@@ -1047,6 +1047,7 @@ static const struct snd_soc_dapm_route sun6i_codec_codec_dapm_routes[] = { { "Line Out Source Playback Route", "Stereo", "Left Mixer" }, { "Line Out Source Playback Route", "Stereo", "Right Mixer" }, { "Line Out Source Playback Route", "Mono Differential", "Left Mixer" }, + { "Line Out Source Playback Route", "Mono Differential", "Right Mixer" }, { "LINEOUT", NULL, "Line Out Source Playback Route" }, /* ADC Routes */
Signature · 1 line
2.10.2
Mark Brown
maintainerApplied "ASoC: sun4i-codec: Add "Right Mixer" to "Line Out Mono Diff." route" to the asoc tree
The patch
ASoC: sun4i-codec: Add "Right Mixer" to "Line Out Mono Diff." route
has been applied to the asoc tree at
git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 1 line
From
19426bdedb72b965db0ebf2106e95e9eeb3b5935Mon Sep 17 00:00:00 2001
From: Chen-Yu Tsai <[email protected]>
Date: Sun, 8 Jan 2017 02:57:06 +0800
Subject: [PATCH] ASoC: sun4i-codec: Add "Right Mixer" to "Line Out Mono Diff."
route
The mono differential output for "Line Out" downmixes the stereo audio from the mixer, instead of just taking the left channel.
Add a route from the "Right Mixer" to "Line Out Source Playback Route" through the "Mono Differential" path, so DAPM doesn't shut down everything if the left channel is muted.
playback")
--- sound/soc/sunxi/sun4i-codec.c | 1 + 1 file changed, 1 insertion(+)
sound/soc/sunxi/sun4i-codec.c +1 -0
@@ -1058,6 +1058,7 @@ static const struct snd_soc_dapm_route sun6i_codec_codec_dapm_routes[] = { { "Line Out Source Playback Route", "Stereo", "Left Mixer" }, { "Line Out Source Playback Route", "Stereo", "Right Mixer" }, { "Line Out Source Playback Route", "Mono Differential", "Left Mixer" }, + { "Line Out Source Playback Route", "Mono Differential", "Right Mixer" }, { "LINEOUT", NULL, "Line Out Source Playback Route" }, /* ADC Routes */
Signature · 1 line
2.11.0
PATCH v3 4/6 ARM: dts: sun6i: Add audio codec device node
In reply to Chen-Yu TsaiThe A31 SoC includes the Allwinner audio codec, capable of 24-bit playback up to 192 kHz and 24-bit capture up to 48 kHz.
--- arch/arm/boot/dts/sun6i-a31.dtsi | 13 +++++++++++++ 1 file changed, 13 insertions(+)
arch/arm/boot/dts/sun6i-a31.dtsi +13 -0
@@ -784,6 +784,19 @@ reset-names = "ahb"; }; + codec: codec@01c22c00 { + #sound-dai-cells = <0>; + compatible = "allwinner,sun6i-a31-codec"; + reg = <0x01c22c00 0x98>; + interrupts = <GIC_SPI 29 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&ccu CLK_APB1_CODEC>, <&ccu CLK_CODEC>; + clock-names = "apb", "codec"; + resets = <&ccu RST_APB1_CODEC>; + dmas = <&dma 15>, <&dma 15>; + dma-names = "rx", "tx"; + status = "disabled"; + }; + timer@01c60000 { compatible = "allwinner,sun6i-a31-hstimer", "allwinner,sun7i-a20-hstimer";
Signature · 1 line
2.10.2
Re: [PATCH v3 4/6] ARM: dts: sun6i: Add audio codec device node
Quoted 13 lines · Chen-Yu Tsai
The A31 SoC includes the Allwinner audio codec, capable of 24-bit playback up to 192 kHz and 24-bit capture up to 48 kHz.
Signed-off-by Chen-Yu Tsai <[email protected]>--- arch/arm/boot/dts/sun6i-a31.dtsi | 13 +++++++++++++ 1 file changed, 13 insertions(+)arch/arm/boot/dts/sun6i-a31.dtsi +0
-0
arch/arm/boot/dts/sun6i-a31.dtsi line 790
Quoted 7 lines
arch/arm/boot/dts/sun6i-a31.dtsi +4
-0@@ -784,6 +784,19 @@ reset-names = "ahb"; }; + codec: codec@01c22c00 { + #sound-dai-cells = <0>; + compatible = "allwinner,sun6i-a31-codec"; + reg = <0x01c22c00 0x98>;
The memory mapped region is 0x400. I fixed this and applied.
Thanks!
Maxime
Signature · 3 lines
Maxime Ripard, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
PATCH v3 5/6 ARM: dts: sun6i: hummingbird: Enable internal audio codec
In reply to Chen-Yu TsaiThe Hummingbird A31 has headset and line in audio jacks and an onboard mic routed to the pins for the SoC's internal codec. The line out pins are routed to an onboard speaker amp, whose output is available on a pin header.
--- arch/arm/boot/dts/sun6i-a31-hummingbird.dts | 13 +++++++++++++ 1 file changed, 13 insertions(+)
arch/arm/boot/dts/sun6i-a31-hummingbird.dts +13 -0
@@ -69,6 +69,19 @@ }; }; +&codec { + allwinner,audio-routing = + "Headphone", "HP", + "Speaker", "LINEOUT", + "LINEIN", "Line In", + "MIC1", "Mic", + "MIC2", "Headset Mic", + "Mic", "MBIAS", + "Headset Mic", "HBIAS"; + allwinner,pa-gpios = <&pio 7 22 GPIO_ACTIVE_HIGH>; /* PH22 */ + status = "okay"; +}; + &cpu0 { cpu-supply = <®_dcdc3>; };
Signature · 6 lines
2.10.2 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Maxime Ripard
AppliedRe: [PATCH v3 5/6] ARM: dts: sun6i: hummingbird: Enable internal audio codec
Quoted 6 lines · Chen-Yu Tsai
The Hummingbird A31 has headset and line in audio jacks and an onboard mic routed to the pins for the SoC's internal codec. The line out pins are routed to an onboard speaker amp, whose output is available on a pin header.
Signed-off-by Chen-Yu Tsai <[email protected]>
Applied, thanks!
Maxime
Signature · 3 lines
Maxime Ripard, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
PATCH v3 6/6 ARM: dts: sun6i: sina31s: Enable internal audio codec
In reply to Chen-Yu TsaiThe SinA31s routes the SoC's LINEOUT pins to a line out jack, and MIC1 to a microphone jack, with MBIAS providing phantom power.
--- arch/arm/boot/dts/sun6i-a31s-sina31s.dts | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/arm/boot/dts/sun6i-a31s-sina31s.dts +8 -0
@@ -65,6 +65,14 @@ }; }; +&codec { + allwinner,audio-routing = + "Line Out", "LINEOUT", + "MIC1", "Mic", + "Mic", "MBIAS"; + status = "okay"; +}; + &ehci0 { /* USB 2.0 4 port hub IC */ status = "okay";
Signature · 1 line
2.10.2
Maxime Ripard
AppliedRe: [PATCH v3 6/6] ARM: dts: sun6i: sina31s: Enable internal audio codec
Quoted 4 lines · Chen-Yu Tsai
The SinA31s routes the SoC's LINEOUT pins to a line out jack, and MIC1 to a microphone jack, with MBIAS providing phantom power.
Signed-off-by Chen-Yu Tsai <[email protected]>
Applied, thanks!
Maxime
Signature · 3 lines
Maxime Ripard, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com