Skip to content

Commit ef83dd3

Browse files
Angus_Wangjamess-huang
authored andcommitted
Porting JustBoom audio HATs.
Change-Id: Ie3a7b4e42be6caa9028fa7609ed580493f106775 Reviewed-on: https://tp-biosrd-v02/gerrit/81613 Reviewed-by: Jamess Huang(黃以民) <Jamess_Huang@asus.com> Tested-by: Jamess Huang(黃以民) <Jamess_Huang@asus.com>
1 parent 1f672c8 commit ef83dd3

File tree

8 files changed

+499
-0
lines changed

8 files changed

+499
-0
lines changed

arch/arm/boot/dts/overlays/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ dtbo-$(CONFIG_ARCH_ROCKCHIP) += \
99
iqaudio-dac.dtbo \
1010
iqaudio-dacplus.dtbo \
1111
iqaudio-digi-wm8804-audio.dtbo \
12+
justboom-dac.dtbo \
13+
justboom-digi.dtbo \
1214
waveshare35a-tinker.dtbo \
1315
waveshare32b-tinker.dtbo \
1416
pps-gpio.dtbo \
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/dts-v1/;
2+
/plugin/;
3+
4+
/ {
5+
compatible = "rockchip,rk3288";
6+
7+
fragment@0 {
8+
target-path ="/sound-simple-card";
9+
__overlay__ {
10+
status = "disabled";
11+
};
12+
};
13+
14+
fragment@1 {
15+
target = <&i2c1>;
16+
__overlay__ {
17+
#address-cells = <1>;
18+
#size-cells = <0>;
19+
status = "okay";
20+
21+
pcm5122@4d {
22+
#sound-dai-cells = <0>;
23+
compatible = "ti,pcm5122";
24+
reg = <0x4d>;
25+
AVDD-supply = <&vdd_3v3_reg>;
26+
DVDD-supply = <&vdd_3v3_reg>;
27+
CPVDD-supply = <&vdd_3v3_reg>;
28+
status = "okay";
29+
};
30+
};
31+
};
32+
33+
fragment@2 {
34+
target-path = "/sound-ext-card";
35+
frag2: __overlay__ {
36+
compatible = "justboom,justboom-dac";
37+
i2s-controller = <&i2s>;
38+
status = "okay";
39+
};
40+
};
41+
42+
__overrides__ {
43+
24db_digital_gain = <&frag2>,"justboom,24db_digital_gain?";
44+
};
45+
};
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/dts-v1/;
2+
/plugin/;
3+
4+
/ {
5+
compatible = "rockchip,rk3288";
6+
7+
fragment@0 {
8+
target-path ="/sound-simple-card";
9+
__overlay__ {
10+
status = "disabled";
11+
};
12+
};
13+
14+
fragment@1 {
15+
target = <&i2c1>;
16+
__overlay__ {
17+
#address-cells = <1>;
18+
#size-cells = <0>;
19+
status = "okay";
20+
21+
wm8804@3b {
22+
#sound-dai-cells = <0>;
23+
compatible = "wlf,wm8804";
24+
reg = <0x3b>;
25+
PVDD-supply = <&vdd_3v3_reg>;
26+
DVDD-supply = <&vdd_3v3_reg>;
27+
status = "okay";
28+
};
29+
};
30+
};
31+
32+
fragment@2 {
33+
target-path = "/sound-ext-card";
34+
__overlay__ {
35+
compatible = "justboom,justboom-digi";
36+
i2s-controller = <&i2s>;
37+
status = "okay";
38+
};
39+
};
40+
};

arch/arm/configs/miniarm-rk3288_defconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,8 @@ CONFIG_SND_SOC_HIFIBERRY_DACPLUS=y
557557
CONFIG_SND_SOC_HIFIBERRY_DIGI=y
558558
CONFIG_SND_SOC_IQAUDIO_DAC=y
559559
CONFIG_SND_SOC_IQAUDIO_DIGI=y
560+
CONFIG_SND_SOC_JUSTBOOM_DAC=y
561+
CONFIG_SND_SOC_JUSTBOOM_DIGI=y
560562
CONFIG_SND_SOC_ROCKCHIP=y
561563
CONFIG_SND_SOC_ROCKCHIP_SPDIF=y
562564
CONFIG_SND_SOC_ROCKCHIP_MAX98090=y

sound/soc/rockchip/Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,15 @@ config SND_SOC_IQAUDIO_DIGI
131131
select SND_SOC_WM8804_I2C
132132
help
133133
Say Y or M if you want to add support for IQAudIO Digital IO board.
134+
135+
config SND_SOC_JUSTBOOM_DAC
136+
tristate "Support for JustBoom DAC"
137+
select SND_SOC_PCM512x_I2C
138+
help
139+
Say Y or M if you want to add support for JustBoom DAC.
140+
141+
config SND_SOC_JUSTBOOM_DIGI
142+
tristate "Support for JustBoom Digi"
143+
select SND_SOC_WM8804_I2C
144+
help
145+
Say Y or M if you want to add support for JustBoom Digi.

sound/soc/rockchip/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ snd-soc-hifiberry-dacplus-objs := hifiberry_dacplus.o
2222
snd-soc-hifiberry-digi-objs := hifiberry_digi.o
2323
snd-soc-iqaudio-dac-objs := iqaudio-dac.o
2424
snd-soc-iqaudio-digi-objs := iqaudio-digi.o
25+
snd-soc-justboom-dac-objs := justboom-dac.o
26+
snd-soc-justboom-digi-objs := justboom-digi.o
2527

2628
obj-$(CONFIG_SND_SOC_ROCKCHIP_DA7219) += snd-soc-rockchip-da7219.o
2729
obj-$(CONFIG_SND_SOC_ROCKCHIP_HDMI_ANALOG) += snd-soc-rockchip-hdmi-analog.o
@@ -36,3 +38,5 @@ obj-$(CONFIG_SND_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
3638
obj-$(CONFIG_SND_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o
3739
obj-$(CONFIG_SND_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
3840
obj-$(CONFIG_SND_SOC_IQAUDIO_DIGI) += snd-soc-iqaudio-digi.o
41+
obj-$(CONFIG_SND_SOC_JUSTBOOM_DAC) += snd-soc-justboom-dac.o
42+
obj-$(CONFIG_SND_SOC_JUSTBOOM_DIGI) += snd-soc-justboom-digi.o

sound/soc/rockchip/justboom-dac.c

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
/*
2+
* ASoC Driver for JustBoom DAC Raspberry Pi HAT Sound Card
3+
*
4+
* Author: Milan Neskovic
5+
* Copyright 2016
6+
* based on code by Daniel Matuschek <info@crazy-audio.com>
7+
* based on code by Florian Meier <florian.meier@koalo.de>
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+
#include <sound/jack.h>
27+
28+
#include "../codecs/pcm512x.h"
29+
30+
#ifdef ROCKCHIP_AUDIO
31+
#define ROCKCHIP_I2S_MCLK 512
32+
#endif
33+
34+
static bool digital_gain_0db_limit = true;
35+
36+
static int snd_rpi_justboom_dac_init(struct snd_soc_pcm_runtime *rtd)
37+
{
38+
struct snd_soc_codec *codec = rtd->codec;
39+
snd_soc_update_bits(codec, PCM512x_GPIO_EN, 0x08, 0x08);
40+
snd_soc_update_bits(codec, PCM512x_GPIO_OUTPUT_4, 0xf, 0x02);
41+
snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
42+
43+
if (digital_gain_0db_limit)
44+
{
45+
int ret;
46+
struct snd_soc_card *card = rtd->card;
47+
48+
ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
49+
if (ret < 0)
50+
dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
51+
}
52+
53+
return 0;
54+
}
55+
56+
static int snd_rpi_justboom_dac_hw_params(struct snd_pcm_substream *substream,
57+
struct snd_pcm_hw_params *params)
58+
{
59+
struct snd_soc_pcm_runtime *rtd = substream->private_data;
60+
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
61+
/*return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);*/
62+
#ifdef ROCKCHIP_AUDIO
63+
unsigned int mclk = params_rate(params) * ROCKCHIP_I2S_MCLK;
64+
return snd_soc_dai_set_sysclk(cpu_dai, 0, mclk, SND_SOC_CLOCK_OUT);
65+
#else
66+
unsigned int sample_bits =
67+
snd_pcm_format_physical_width(params_format(params));
68+
return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
69+
#endif
70+
}
71+
72+
static int snd_rpi_justboom_dac_startup(struct snd_pcm_substream *substream) {
73+
struct snd_soc_pcm_runtime *rtd = substream->private_data;
74+
struct snd_soc_codec *codec = rtd->codec;
75+
snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
76+
return 0;
77+
}
78+
79+
static void snd_rpi_justboom_dac_shutdown(struct snd_pcm_substream *substream) {
80+
struct snd_soc_pcm_runtime *rtd = substream->private_data;
81+
struct snd_soc_codec *codec = rtd->codec;
82+
snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x00);
83+
}
84+
85+
/* machine stream operations */
86+
static struct snd_soc_ops snd_rpi_justboom_dac_ops = {
87+
.hw_params = snd_rpi_justboom_dac_hw_params,
88+
.startup = snd_rpi_justboom_dac_startup,
89+
.shutdown = snd_rpi_justboom_dac_shutdown,
90+
};
91+
92+
static struct snd_soc_dai_link snd_rpi_justboom_dac_dai[] = {
93+
{
94+
.name = "JustBoom DAC",
95+
.stream_name = "JustBoom DAC HiFi",
96+
.cpu_dai_name = "bcm2708-i2s.0",
97+
.codec_dai_name = "pcm512x-hifi",
98+
.platform_name = "bcm2708-i2s.0",
99+
.codec_name = "pcm512x.1-004d",
100+
.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
101+
SND_SOC_DAIFMT_CBS_CFS,
102+
.ops = &snd_rpi_justboom_dac_ops,
103+
.init = snd_rpi_justboom_dac_init,
104+
},
105+
};
106+
107+
/* audio machine driver */
108+
static struct snd_soc_card snd_rpi_justboom_dac = {
109+
.name = "snd_rpi_justboom_dac",
110+
.driver_name = "JustBoomDac",
111+
.owner = THIS_MODULE,
112+
.dai_link = snd_rpi_justboom_dac_dai,
113+
.num_links = ARRAY_SIZE(snd_rpi_justboom_dac_dai),
114+
};
115+
116+
static int snd_rpi_justboom_dac_probe(struct platform_device *pdev)
117+
{
118+
int ret = 0;
119+
120+
snd_rpi_justboom_dac.dev = &pdev->dev;
121+
122+
if (pdev->dev.of_node) {
123+
struct device_node *i2s_node;
124+
struct snd_soc_dai_link *dai = &snd_rpi_justboom_dac_dai[0];
125+
i2s_node = of_parse_phandle(pdev->dev.of_node,
126+
"i2s-controller", 0);
127+
128+
if (i2s_node) {
129+
dai->cpu_dai_name = NULL;
130+
dai->cpu_of_node = i2s_node;
131+
dai->platform_name = NULL;
132+
dai->platform_of_node = i2s_node;
133+
}
134+
135+
digital_gain_0db_limit = !of_property_read_bool(
136+
pdev->dev.of_node, "justboom,24db_digital_gain");
137+
}
138+
139+
ret = snd_soc_register_card(&snd_rpi_justboom_dac);
140+
if (ret && ret != -EPROBE_DEFER)
141+
dev_err(&pdev->dev,
142+
"snd_soc_register_card() failed: %d\n", ret);
143+
144+
return ret;
145+
}
146+
147+
static int snd_rpi_justboom_dac_remove(struct platform_device *pdev)
148+
{
149+
return snd_soc_unregister_card(&snd_rpi_justboom_dac);
150+
}
151+
152+
static const struct of_device_id snd_rpi_justboom_dac_of_match[] = {
153+
{ .compatible = "justboom,justboom-dac", },
154+
{},
155+
};
156+
MODULE_DEVICE_TABLE(of, snd_rpi_justboom_dac_of_match);
157+
158+
static struct platform_driver snd_rpi_justboom_dac_driver = {
159+
.driver = {
160+
.name = "snd-rpi-justboom-dac",
161+
.owner = THIS_MODULE,
162+
.of_match_table = snd_rpi_justboom_dac_of_match,
163+
},
164+
.probe = snd_rpi_justboom_dac_probe,
165+
.remove = snd_rpi_justboom_dac_remove,
166+
};
167+
168+
module_platform_driver(snd_rpi_justboom_dac_driver);
169+
170+
MODULE_AUTHOR("Milan Neskovic <info@justboom.co>");
171+
MODULE_DESCRIPTION("ASoC Driver for JustBoom PI DAC HAT Sound Card");
172+
MODULE_LICENSE("GPL v2");

0 commit comments

Comments
 (0)