Skip to content

Commit bec3faa

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 23b8bb3 commit bec3faa

File tree

3 files changed

+153
-0
lines changed

3 files changed

+153
-0
lines changed

sound/soc/bcm/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,10 @@ config SND_BCM2708_SOC_DIONAUDIO_LOCO
116116
select SND_SOC_PCM5102a
117117
help
118118
Say Y or M if you want to add support for Dion Audio LOCO.
119+
120+
config SND_BCM2708_SOC_ALLO_PIANO_DAC
121+
tristate "Support for Allo Piano DAC"
122+
depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
123+
select SND_SOC_PCM512x_I2C
124+
help
125+
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
@@ -23,6 +23,7 @@ snd-soc-raspidac3-objs := raspidac3.o
2323
snd-soc-audioinjector-pi-soundcard-objs := audioinjector-pi-soundcard.o
2424
snd-soc-digidac1-soundcard-objs := digidac1-soundcard.o
2525
snd-soc-dionaudio-loco-objs := dionaudio_loco.o
26+
snd-soc-allo-piano-dac-objs := allo-piano-dac.o
2627

2728
obj-$(CONFIG_SND_BCM2708_SOC_ADAU1977_ADC) += snd-soc-adau1977-adc.o
2829
obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
@@ -38,3 +39,4 @@ obj-$(CONFIG_SND_BCM2708_SOC_RASPIDAC3) += snd-soc-raspidac3.o
3839
obj-$(CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD) += snd-soc-audioinjector-pi-soundcard.o
3940
obj-$(CONFIG_SND_DIGIDAC1_SOUNDCARD) += snd-soc-digidac1-soundcard.o
4041
obj-$(CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO) += snd-soc-dionaudio-loco.o
42+
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)