Skip to content

Commit b6cf89f

Browse files
Yaojen_Changjamess-huang
authored andcommitted
Porting Rpi DAC for PecanPi DAC
Change-Id: Ide97175d39b288a11c6bfb41f81b522c0fcfc678 Reviewed-on: https://tp-biosrd-v02/gerrit/85490 Reviewed-by: Jamess Huang(黃以民) <Jamess_Huang@asus.com> Tested-by: Jamess Huang(黃以民) <Jamess_Huang@asus.com>
1 parent 5b8b06f commit b6cf89f

File tree

9 files changed

+257
-0
lines changed

9 files changed

+257
-0
lines changed

arch/arm/boot/dts/overlays/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ dtbo-$(CONFIG_ARCH_ROCKCHIP) += \
1212
iqaudio-digi-wm8804-audio.dtbo \
1313
justboom-dac.dtbo \
1414
justboom-digi.dtbo \
15+
rpi-dac.dtbo \
1516
seeed-2mic-voicecard.dtbo \
1617
waveshare35a-tinker.dtbo \
1718
waveshare32b-tinker.dtbo \
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Definitions for RPi DAC
2+
/dts-v1/;
3+
/plugin/;
4+
5+
/ {
6+
compatible = "rockchip,rk3288";
7+
8+
fragment@0 {
9+
target-path ="/sound-simple-card";
10+
__overlay__ {
11+
status = "disabled";
12+
};
13+
};
14+
15+
fragment@1 {
16+
target-path = "/";
17+
__overlay__ {
18+
pcm1794a-codec {
19+
#sound-dai-cells = <0>;
20+
compatible = "ti,pcm1794a";
21+
status = "okay";
22+
};
23+
};
24+
};
25+
26+
fragment@2 {
27+
target-path = "/sound-ext-card";
28+
__overlay__ {
29+
compatible = "rpi,rpi-dac";
30+
i2s-controller = <&i2s>;
31+
status = "okay";
32+
};
33+
};
34+
35+
fragment@3 {
36+
target = <&hdmi>;
37+
__overlay__ {
38+
hdmi-i2s-audio-disable;
39+
};
40+
};
41+
};

arch/arm/configs/miniarm-rk3288_defconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ CONFIG_SND_SOC_IQAUDIO_DAC=y
609609
CONFIG_SND_SOC_IQAUDIO_DIGI=y
610610
CONFIG_SND_SOC_JUSTBOOM_DAC=y
611611
CONFIG_SND_SOC_JUSTBOOM_DIGI=y
612+
CONFIG_SND_SOC_RPI_DAC=y
612613
CONFIG_SND_SOC_ROCKCHIP=y
613614
CONFIG_SND_SOC_ROCKCHIP_SPDIF=y
614615
CONFIG_SND_SOC_ROCKCHIP_MAX98090=y

sound/soc/codecs/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ config SND_SOC_ALL_CODECS
9090
select SND_SOC_HDMI_CODEC
9191
select SND_SOC_PCM1681 if I2C
9292
select SND_SOC_PCM1792A if SPI_MASTER
93+
select SND_SOC_PCM1794A
9394
select SND_SOC_PCM3008
9495
select SND_SOC_PCM5102A
9596
select SND_SOC_PCM512x_I2C if I2C
@@ -561,6 +562,9 @@ config SND_SOC_PCM1792A
561562
tristate "Texas Instruments PCM1792A CODEC"
562563
depends on SPI_MASTER
563564

565+
config SND_SOC_PCM1794A
566+
tristate
567+
564568
config SND_SOC_PCM3008
565569
tristate
566570

sound/soc/codecs/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ snd-soc-nau8825-objs := nau8825.o
8787
snd-soc-hdmi-codec-objs := hdmi-codec.o
8888
snd-soc-pcm1681-objs := pcm1681.o
8989
snd-soc-pcm1792a-codec-objs := pcm1792a.o
90+
snd-soc-pcm1794a-objs := pcm1794a.o
9091
snd-soc-pcm3008-objs := pcm3008.o
9192
snd-soc-pcm5102a-objs := pcm5102a.o
9293
snd-soc-pcm512x-objs := pcm512x.o
@@ -302,6 +303,7 @@ obj-$(CONFIG_SND_SOC_NAU8825) += snd-soc-nau8825.o
302303
obj-$(CONFIG_SND_SOC_HDMI_CODEC) += snd-soc-hdmi-codec.o
303304
obj-$(CONFIG_SND_SOC_PCM1681) += snd-soc-pcm1681.o
304305
obj-$(CONFIG_SND_SOC_PCM1792A) += snd-soc-pcm1792a-codec.o
306+
obj-$(CONFIG_SND_SOC_PCM1794A) += snd-soc-pcm1794a.o
305307
obj-$(CONFIG_SND_SOC_PCM3008) += snd-soc-pcm3008.o
306308
obj-$(CONFIG_SND_SOC_PCM5102A) += snd-soc-pcm5102a.o
307309
obj-$(CONFIG_SND_SOC_PCM512x) += snd-soc-pcm512x.o

sound/soc/codecs/pcm1794a.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Driver for the PCM1794A codec
3+
*
4+
* Author: Florian Meier <florian.meier@koalo.de>
5+
* Copyright 2013
6+
*
7+
* This program is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU General Public License
9+
* version 2 as published by the Free Software Foundation.
10+
*
11+
* This program is distributed in the hope that it will be useful, but
12+
* WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* General Public License for more details.
15+
*/
16+
17+
18+
#include <linux/init.h>
19+
#include <linux/module.h>
20+
#include <linux/platform_device.h>
21+
22+
#include <sound/soc.h>
23+
24+
static struct snd_soc_dai_driver pcm1794a_dai = {
25+
.name = "pcm1794a-hifi",
26+
.playback = {
27+
.channels_min = 2,
28+
.channels_max = 2,
29+
.rates = SNDRV_PCM_RATE_8000_192000,
30+
.formats = SNDRV_PCM_FMTBIT_S16_LE |
31+
SNDRV_PCM_FMTBIT_S24_LE
32+
},
33+
};
34+
35+
static struct snd_soc_codec_driver soc_codec_dev_pcm1794a;
36+
37+
static int pcm1794a_probe(struct platform_device *pdev)
38+
{
39+
return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pcm1794a,
40+
&pcm1794a_dai, 1);
41+
}
42+
43+
static int pcm1794a_remove(struct platform_device *pdev)
44+
{
45+
snd_soc_unregister_codec(&pdev->dev);
46+
return 0;
47+
}
48+
49+
static const struct of_device_id pcm1794a_of_match[] = {
50+
{ .compatible = "ti,pcm1794a", },
51+
{ }
52+
};
53+
MODULE_DEVICE_TABLE(of, pcm1794a_of_match);
54+
55+
static struct platform_driver pcm1794a_codec_driver = {
56+
.probe = pcm1794a_probe,
57+
.remove = pcm1794a_remove,
58+
.driver = {
59+
.name = "pcm1794a-codec",
60+
.owner = THIS_MODULE,
61+
.of_match_table = of_match_ptr(pcm1794a_of_match),
62+
},
63+
};
64+
65+
module_platform_driver(pcm1794a_codec_driver);
66+
67+
MODULE_DESCRIPTION("ASoC PCM1794A codec driver");
68+
MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
69+
MODULE_LICENSE("GPL v2");

sound/soc/rockchip/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ config SND_SOC_JUSTBOOM_DIGI
191191
help
192192
Say Y or M if you want to add support for JustBoom Digi.
193193

194+
config SND_SOC_RPI_DAC
195+
tristate "Support for rpi simple soundcard DAC"
196+
select SND_SOC_PCM1794A
197+
help
198+
Say Y or M if you want to add support for rpi simple soundcard DAC.
199+
194200
config SND_SOC_GOOGLEVOICEHAT_CARD
195201
tristate "Support for Google voice HAT sound card"
196202
select SND_SOC_VOICEHAT

sound/soc/rockchip/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ snd-soc-iqaudio-dac-objs := iqaudio-dac.o
3939
snd-soc-iqaudio-digi-objs := iqaudio-digi.o
4040
snd-soc-justboom-dac-objs := justboom-dac.o
4141
snd-soc-justboom-digi-objs := justboom-digi.o
42+
snd-soc-rpi-dac-objs := rpi-dac.o
4243
snd-soc-googlevoicehat-soundcard-objs := googlevoicehat-soundcard.o
4344
snd-soc-googlevoicehat-codec-objs := googlevoicehat-codec.o
4445
snd-soc-audioinjector-octo-soundcard-objs := audioinjector-octo-soundcard.o
@@ -61,6 +62,7 @@ obj-$(CONFIG_SND_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
6162
obj-$(CONFIG_SND_SOC_IQAUDIO_DIGI) += snd-soc-iqaudio-digi.o
6263
obj-$(CONFIG_SND_SOC_JUSTBOOM_DAC) += snd-soc-justboom-dac.o
6364
obj-$(CONFIG_SND_SOC_JUSTBOOM_DIGI) += snd-soc-justboom-digi.o
65+
obj-$(CONFIG_SND_SOC_RPI_DAC) += snd-soc-rpi-dac.o
6466
obj-$(CONFIG_SND_SOC_GOOGLEVOICEHAT_CARD) += snd-soc-googlevoicehat-soundcard.o
6567
obj-$(CONFIG_SND_SOC_GOOGLEVOICEHAT_CARD) += snd-soc-googlevoicehat-codec.o
6668
obj-$(CONFIG_SND_SOC_SEEEDVOICEHAT_CARD) += seeedvoicehat/

sound/soc/rockchip/rpi-dac.c

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*
2+
* ASoC Driver for RPi-DAC.
3+
*
4+
* Author: Florian Meier <florian.meier@koalo.de>
5+
* Copyright 2013
6+
*
7+
* This program is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU General Public License
9+
* version 2 as published by the Free Software Foundation.
10+
*
11+
* This program is distributed in the hope that it will be useful, but
12+
* WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* General Public License for more details.
15+
*/
16+
17+
#include <linux/module.h>
18+
#include <linux/platform_device.h>
19+
20+
#include <sound/core.h>
21+
#include <sound/pcm.h>
22+
#include <sound/pcm_params.h>
23+
#include <sound/soc.h>
24+
#include <sound/jack.h>
25+
26+
#ifdef ROCKCHIP_AUDIO
27+
#define ROCKCHIP_I2S_MCLK 128
28+
#endif
29+
30+
static int snd_rpi_rpi_dac_init(struct snd_soc_pcm_runtime *rtd)
31+
{
32+
return 0;
33+
}
34+
35+
static int snd_rpi_rpi_dac_hw_params(struct snd_pcm_substream *substream,
36+
struct snd_pcm_hw_params *params)
37+
{
38+
struct snd_soc_pcm_runtime *rtd = substream->private_data;
39+
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
40+
41+
#ifdef ROCKCHIP_AUDIO
42+
unsigned int mclk = params_rate(params) * ROCKCHIP_I2S_MCLK;
43+
44+
return snd_soc_dai_set_sysclk(cpu_dai, 0, mclk, SND_SOC_CLOCK_OUT);
45+
#else
46+
unsigned int sample_bits = snd_pcm_format_physical_width(params_format(params));
47+
48+
return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
49+
#endif
50+
}
51+
52+
/* machine stream operations */
53+
static struct snd_soc_ops snd_rpi_rpi_dac_ops = {
54+
.hw_params = snd_rpi_rpi_dac_hw_params,
55+
};
56+
57+
static struct snd_soc_dai_link snd_rpi_rpi_dac_dai[] = {
58+
{
59+
.name = "RPi-DAC",
60+
.stream_name = "RPi-DAC HiFi",
61+
.cpu_dai_name = "bcm2708-i2s.0",
62+
.codec_dai_name = "pcm1794a-hifi",
63+
.platform_name = "bcm2708-i2s.0",
64+
.codec_name = "pcm1794a-codec",
65+
.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
66+
SND_SOC_DAIFMT_CBS_CFS,
67+
.ops = &snd_rpi_rpi_dac_ops,
68+
.init = snd_rpi_rpi_dac_init,
69+
},
70+
};
71+
72+
/* audio machine driver */
73+
static struct snd_soc_card snd_rpi_rpi_dac = {
74+
.name = "snd_rpi_rpi_dac",
75+
.owner = THIS_MODULE,
76+
.dai_link = snd_rpi_rpi_dac_dai,
77+
.num_links = ARRAY_SIZE(snd_rpi_rpi_dac_dai),
78+
};
79+
80+
static int snd_rpi_rpi_dac_probe(struct platform_device *pdev)
81+
{
82+
int ret = 0;
83+
84+
snd_rpi_rpi_dac.dev = &pdev->dev;
85+
86+
if (pdev->dev.of_node) {
87+
struct device_node *i2s_node;
88+
struct snd_soc_dai_link *dai = &snd_rpi_rpi_dac_dai[0];
89+
i2s_node = of_parse_phandle(pdev->dev.of_node, "i2s-controller", 0);
90+
91+
if (i2s_node) {
92+
dai->cpu_dai_name = NULL;
93+
dai->cpu_of_node = i2s_node;
94+
dai->platform_name = NULL;
95+
dai->platform_of_node = i2s_node;
96+
}
97+
}
98+
99+
ret = snd_soc_register_card(&snd_rpi_rpi_dac);
100+
if (ret)
101+
dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
102+
103+
return ret;
104+
}
105+
106+
static int snd_rpi_rpi_dac_remove(struct platform_device *pdev)
107+
{
108+
return snd_soc_unregister_card(&snd_rpi_rpi_dac);
109+
}
110+
111+
static const struct of_device_id snd_rpi_rpi_dac_of_match[] = {
112+
{ .compatible = "rpi,rpi-dac", },
113+
{},
114+
};
115+
MODULE_DEVICE_TABLE(of, snd_rpi_rpi_dac_of_match);
116+
117+
static struct platform_driver snd_rpi_rpi_dac_driver = {
118+
.driver = {
119+
.name = "snd-rpi-dac",
120+
.owner = THIS_MODULE,
121+
.of_match_table = snd_rpi_rpi_dac_of_match,
122+
},
123+
.probe = snd_rpi_rpi_dac_probe,
124+
.remove = snd_rpi_rpi_dac_remove,
125+
};
126+
127+
module_platform_driver(snd_rpi_rpi_dac_driver);
128+
129+
MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
130+
MODULE_DESCRIPTION("ASoC Driver for RPi-DAC");
131+
MODULE_LICENSE("GPL v2");

0 commit comments

Comments
 (0)