Skip to content

Commit 02eba0b

Browse files
clivempopcornmix
authored andcommitted
Allo Piano DAC boards: Initial 2 channel (stereo) support (#1645)
Add initial 2 channel (stereo) support for Allo Piano DAC (2.0/2.1) boards, using allo-piano-dac-pcm512x-audio overlay and allo-piano-dac ALSA ASoC machine driver. NB. The initial support is 2 channel (stereo) ONLY! (The Piano DAC 2.1 will only support 2 channel (stereo) left/right output, pending an update to the upstream pcm512x codec driver, which will have to be submitted via upstream. With the initial downstream support, provided by this patch, the Piano DAC 2.1 subwoofer outputs will not function.) Signed-off-by: Baswaraj K <[email protected]> Signed-off-by: Clive Messer <[email protected]> Tested-by: Clive Messer <[email protected]>
1 parent d0278ef commit 02eba0b

File tree

8 files changed

+230
-0
lines changed

8 files changed

+230
-0
lines changed

arch/arm/boot/dts/overlays/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ dtbo-$(RPI_DT_OVERLAYS) += adau1977-adc.dtbo
1616
dtbo-$(RPI_DT_OVERLAYS) += ads1015.dtbo
1717
dtbo-$(RPI_DT_OVERLAYS) += ads7846.dtbo
1818
dtbo-$(RPI_DT_OVERLAYS) += akkordion-iqdacplus.dtbo
19+
dtbo-$(RPI_DT_OVERLAYS) += allo-piano-dac-pcm512x-audio.dtbo
1920
dtbo-$(RPI_DT_OVERLAYS) += at86rf233.dtbo
2021
dtbo-$(RPI_DT_OVERLAYS) += audioinjector-wm8731-audio.dtbo
2122
dtbo-$(RPI_DT_OVERLAYS) += audremap.dtbo

arch/arm/boot/dts/overlays/README

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,26 @@ Params: 24db_digital_gain Allow gain to be applied via the PCM512x codec
235235
that does not result in clipping/distortion!)
236236

237237

238+
Name: allo-piano-dac-pcm512x-audio
239+
Info: Configures the Allo Piano DAC (2.0/2.1) audio cards.
240+
(NB. This initial support is for 2.0 channel audio ONLY! ie. stereo.
241+
The subwoofer outputs on the Piano 2.1 are not currently supported!)
242+
Load: dtoverlay=allo-piano-dac-pcm512x-audio,<param>
243+
Params: 24db_digital_gain Allow gain to be applied via the PCM512x codec
244+
Digital volume control.
245+
(The default behaviour is that the Digital
246+
volume control is limited to a maximum of
247+
0dB. ie. it can attenuate but not provide
248+
gain. For most users, this will be desired
249+
as it will prevent clipping. By appending
250+
the 24db_digital_gain parameter, the Digital
251+
volume control will allow up to 24dB of
252+
gain. If this parameter is enabled, it is the
253+
responsibility of the user to ensure that
254+
the Digital volume control is set to a value
255+
that does not result in clipping/distortion!)
256+
257+
238258
Name: at86rf233
239259
Info: Configures the Atmel AT86RF233 802.15.4 low-power WPAN transceiver,
240260
connected to spi0.0
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Definitions for Allo Piano DAC (2.0/2.1) boards
3+
*
4+
* NB. The Piano DAC 2.1 board contains 2x TI PCM5142 DAC's. One DAC is stereo
5+
* (left/right) and the other provides a subwoofer output, using DSP on the
6+
* chip for digital high/low pass crossover.
7+
* The initial support for this hardware, that doesn't require any codec driver
8+
* modifications, uses only one DAC chip for stereo (left/right) output, the
9+
* chip with 0x4c slave address. The other chip at 0x4d is currently ignored!
10+
*/
11+
12+
/dts-v1/;
13+
/plugin/;
14+
15+
/ {
16+
compatible = "brcm,bcm2708";
17+
18+
fragment@0 {
19+
target = <&i2s>;
20+
__overlay__ {
21+
status = "okay";
22+
};
23+
};
24+
25+
fragment@1 {
26+
target = <&i2c1>;
27+
__overlay__ {
28+
#address-cells = <1>;
29+
#size-cells = <0>;
30+
status = "okay";
31+
32+
pcm5142@4c {
33+
#sound-dai-cells = <0>;
34+
compatible = "ti,pcm5142";
35+
reg = <0x4c>;
36+
status = "okay";
37+
};
38+
};
39+
};
40+
41+
fragment@2 {
42+
target = <&sound>;
43+
piano_dac: __overlay__ {
44+
compatible = "allo,piano-dac";
45+
i2s-controller = <&i2s>;
46+
status = "okay";
47+
};
48+
};
49+
50+
__overrides__ {
51+
24db_digital_gain =
52+
<&piano_dac>,"allo,24db_digital_gain?";
53+
};
54+
};

arch/arm/configs/bcm2709_defconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,7 @@ CONFIG_SND_BCM2708_SOC_ADAU1977_ADC=m
877877
CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD=m
878878
CONFIG_SND_DIGIDAC1_SOUNDCARD=m
879879
CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO=m
880+
CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC=m
880881
CONFIG_SND_SOC_ADAU1701=m
881882
CONFIG_SND_SOC_WM8804_I2C=m
882883
CONFIG_SND_SIMPLE_CARD=m

arch/arm/configs/bcmrpi_defconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,7 @@ CONFIG_SND_BCM2708_SOC_ADAU1977_ADC=m
868868
CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD=m
869869
CONFIG_SND_DIGIDAC1_SOUNDCARD=m
870870
CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO=m
871+
CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC=m
871872
CONFIG_SND_SOC_ADAU1701=m
872873
CONFIG_SND_SOC_WM8804_I2C=m
873874
CONFIG_SND_SIMPLE_CARD=m

sound/soc/bcm/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,10 @@ config SND_BCM2708_SOC_DIONAUDIO_LOCO
114114
select SND_SOC_PCM5102a
115115
help
116116
Say Y or M if you want to add support for Dion Audio LOCO.
117+
118+
config SND_BCM2708_SOC_ALLO_PIANO_DAC
119+
tristate "Support for Allo Piano DAC"
120+
depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
121+
select SND_SOC_PCM512x_I2C
122+
help
123+
Say Y or M if you want to add support for Allo Piano DAC.

sound/soc/bcm/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ snd-soc-raspidac3-objs := raspidac3.o
1919
snd-soc-audioinjector-pi-soundcard-objs := audioinjector-pi-soundcard.o
2020
snd-soc-digidac1-soundcard-objs := digidac1-soundcard.o
2121
snd-soc-dionaudio-loco-objs := dionaudio_loco.o
22+
snd-soc-allo-piano-dac-objs := allo-piano-dac.o
2223

2324
obj-$(CONFIG_SND_BCM2708_SOC_ADAU1977_ADC) += snd-soc-adau1977-adc.o
2425
obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
@@ -35,3 +36,4 @@ obj-$(CONFIG_SND_BCM2708_SOC_RASPIDAC3) += snd-soc-raspidac3.o
3536
obj-$(CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD) += snd-soc-audioinjector-pi-soundcard.o
3637
obj-$(CONFIG_SND_DIGIDAC1_SOUNDCARD) += snd-soc-digidac1-soundcard.o
3738
obj-$(CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO) += snd-soc-dionaudio-loco.o
39+
obj-$(CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC) += snd-soc-allo-piano-dac.o

sound/soc/bcm/allo-piano-dac.c

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
/*
2+
* ALSA ASoC Machine Driver for Allo Piano DAC
3+
*
4+
* Author: Baswaraj K <[email protected]>
5+
* Copyright 2016
6+
* based on code by Daniel Matuschek <[email protected]>
7+
* based on code by Florian Meier <[email protected]>
8+
*
9+
* This program is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU General Public License
11+
* version 2 as published by the Free Software Foundation.
12+
*
13+
* This program is distributed in the hope that it will be useful, but
14+
* WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
* General Public License for more details.
17+
*/
18+
19+
#include <linux/module.h>
20+
#include <linux/platform_device.h>
21+
22+
#include <sound/core.h>
23+
#include <sound/pcm.h>
24+
#include <sound/pcm_params.h>
25+
#include <sound/soc.h>
26+
27+
static bool digital_gain_0db_limit = true;
28+
29+
static int snd_allo_piano_dac_init(struct snd_soc_pcm_runtime *rtd)
30+
{
31+
if (digital_gain_0db_limit) {
32+
int ret;
33+
struct snd_soc_card *card = rtd->card;
34+
35+
ret = snd_soc_limit_volume(card, "Digital Playback Volume",
36+
207);
37+
if (ret < 0)
38+
dev_warn(card->dev, "Failed to set volume limit: %d\n",
39+
ret);
40+
}
41+
42+
return 0;
43+
}
44+
45+
static int snd_allo_piano_dac_hw_params(
46+
struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
47+
{
48+
struct snd_soc_pcm_runtime *rtd = substream->private_data;
49+
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
50+
51+
unsigned int sample_bits =
52+
snd_pcm_format_physical_width(params_format(params));
53+
54+
return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
55+
}
56+
57+
/* machine stream operations */
58+
static struct snd_soc_ops snd_allo_piano_dac_ops = {
59+
.hw_params = snd_allo_piano_dac_hw_params,
60+
};
61+
62+
static struct snd_soc_dai_link snd_allo_piano_dac_dai[] = {
63+
{
64+
.name = "Piano DAC",
65+
.stream_name = "Piano DAC HiFi",
66+
.cpu_dai_name = "bcm2708-i2s.0",
67+
.codec_dai_name = "pcm512x-hifi",
68+
.platform_name = "bcm2708-i2s.0",
69+
.codec_name = "pcm512x.1-004c",
70+
.dai_fmt = SND_SOC_DAIFMT_I2S |
71+
SND_SOC_DAIFMT_NB_NF |
72+
SND_SOC_DAIFMT_CBS_CFS,
73+
.ops = &snd_allo_piano_dac_ops,
74+
.init = snd_allo_piano_dac_init,
75+
},
76+
};
77+
78+
/* audio machine driver */
79+
static struct snd_soc_card snd_allo_piano_dac = {
80+
.name = "PianoDAC",
81+
.owner = THIS_MODULE,
82+
.dai_link = snd_allo_piano_dac_dai,
83+
.num_links = ARRAY_SIZE(snd_allo_piano_dac_dai),
84+
};
85+
86+
static int snd_allo_piano_dac_probe(struct platform_device *pdev)
87+
{
88+
int ret = 0;
89+
90+
snd_allo_piano_dac.dev = &pdev->dev;
91+
92+
if (pdev->dev.of_node) {
93+
struct device_node *i2s_node;
94+
struct snd_soc_dai_link *dai;
95+
96+
dai = &snd_allo_piano_dac_dai[0];
97+
i2s_node = of_parse_phandle(pdev->dev.of_node,
98+
"i2s-controller", 0);
99+
100+
if (i2s_node) {
101+
dai->cpu_dai_name = NULL;
102+
dai->cpu_of_node = i2s_node;
103+
dai->platform_name = NULL;
104+
dai->platform_of_node = i2s_node;
105+
}
106+
107+
digital_gain_0db_limit = !of_property_read_bool(
108+
pdev->dev.of_node, "allo,24db_digital_gain");
109+
}
110+
111+
ret = snd_soc_register_card(&snd_allo_piano_dac);
112+
if (ret)
113+
dev_err(&pdev->dev,
114+
"snd_soc_register_card() failed: %d\n", ret);
115+
116+
return ret;
117+
}
118+
119+
static int snd_allo_piano_dac_remove(struct platform_device *pdev)
120+
{
121+
return snd_soc_unregister_card(&snd_allo_piano_dac);
122+
}
123+
124+
static const struct of_device_id snd_allo_piano_dac_of_match[] = {
125+
{ .compatible = "allo,piano-dac", },
126+
{ /* sentinel */ },
127+
};
128+
MODULE_DEVICE_TABLE(of, snd_allo_piano_dac_of_match);
129+
130+
static struct platform_driver snd_allo_piano_dac_driver = {
131+
.driver = {
132+
.name = "snd-allo-piano-dac",
133+
.owner = THIS_MODULE,
134+
.of_match_table = snd_allo_piano_dac_of_match,
135+
},
136+
.probe = snd_allo_piano_dac_probe,
137+
.remove = snd_allo_piano_dac_remove,
138+
};
139+
140+
module_platform_driver(snd_allo_piano_dac_driver);
141+
142+
MODULE_AUTHOR("Baswaraj K <[email protected]>");
143+
MODULE_DESCRIPTION("ALSA ASoC Machine Driver for Allo Piano DAC");
144+
MODULE_LICENSE("GPL v2");

0 commit comments

Comments
 (0)