Skip to content

Commit 2a8c686

Browse files
Fe-Pipopcornmix
authored andcommitted
Add support for Fe-Pi audio sound card. (#1867)
Fe-Pi Audio Sound Card is based on NXP SGTL5000 codec. Mechanical specification of the board is the same the Raspberry Pi Zero. 3.5mm jacks for Headphone/Mic, Line In, and Line Out. Signed-off-by: Henry Kupis <[email protected]>
1 parent 0fe9f38 commit 2a8c686

File tree

3 files changed

+167
-0
lines changed

3 files changed

+167
-0
lines changed

sound/soc/bcm/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ config SND_BCM2708_SOC_ALLO_PIANO_DAC
148148
help
149149
Say Y or M if you want to add support for Allo Piano DAC.
150150

151+
config SND_BCM2708_SOC_FE_PI_AUDIO
152+
tristate "Support for Fe-Pi-Audio"
153+
depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
154+
select SND_SOC_SGTL5000
155+
help
156+
Say Y or M if you want to add support for Fe-Pi-Audio.
157+
151158
config SND_PISOUND
152159
tristate "Support for Blokas Labs pisound"
153160
depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S

sound/soc/bcm/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ snd-soc-dionaudio-loco-objs := dionaudio_loco.o
2828
snd-soc-dionaudio-loco-v2-objs := dionaudio_loco-v2.o
2929
snd-soc-allo-piano-dac-objs := allo-piano-dac.o
3030
snd-soc-pisound-objs := pisound.o
31+
snd-soc-fe-pi-audio-objs := fe-pi-audio.o
3132

3233
obj-$(CONFIG_SND_BCM2708_SOC_ADAU1977_ADC) += snd-soc-adau1977-adc.o
3334
obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) += snd-soc-hifiberry-amp.o
@@ -48,3 +49,4 @@ obj-$(CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO) += snd-soc-dionaudio-loco.o
4849
obj-$(CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO_V2) += snd-soc-dionaudio-loco-v2.o
4950
obj-$(CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC) += snd-soc-allo-piano-dac.o
5051
obj-$(CONFIG_SND_PISOUND) += snd-soc-pisound.o
52+
obj-$(CONFIG_SND_BCM2708_SOC_FE_PI_AUDIO) += snd-soc-fe-pi-audio.o

sound/soc/bcm/fe-pi-audio.c

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/*
2+
* ASoC Driver for Fe-Pi Audio Sound Card
3+
*
4+
* Author: Henry Kupis <[email protected]>
5+
* Copyright 2016
6+
* based on code by Florian Meier <[email protected]>
7+
* based on code by Shawn Guo <[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+
#include <linux/io.h>
22+
23+
#include <sound/core.h>
24+
#include <sound/pcm.h>
25+
#include <sound/pcm_params.h>
26+
#include <sound/soc.h>
27+
#include <sound/jack.h>
28+
29+
#include "../codecs/sgtl5000.h"
30+
31+
static int snd_fe_pi_audio_init(struct snd_soc_pcm_runtime *rtd)
32+
{
33+
struct snd_soc_card *card = rtd->card;
34+
struct snd_soc_codec *codec = rtd->codec;
35+
36+
snd_soc_dapm_force_enable_pin(&card->dapm, "LO");
37+
snd_soc_dapm_force_enable_pin(&card->dapm, "ADC");
38+
snd_soc_dapm_force_enable_pin(&card->dapm, "DAC");
39+
snd_soc_dapm_force_enable_pin(&card->dapm, "HP");
40+
snd_soc_update_bits(codec, SGTL5000_CHIP_ANA_POWER,
41+
SGTL5000_VAG_POWERUP, SGTL5000_VAG_POWERUP);
42+
43+
return 0;
44+
}
45+
46+
static int snd_fe_pi_audio_hw_params(struct snd_pcm_substream *substream,
47+
struct snd_pcm_hw_params *params)
48+
{
49+
struct snd_soc_pcm_runtime *rtd = substream->private_data;
50+
struct device *dev = rtd->card->dev;
51+
struct snd_soc_dai *codec_dai = rtd->codec_dai;
52+
53+
int ret;
54+
55+
/* Set SGTL5000's SYSCLK */
56+
ret = snd_soc_dai_set_sysclk(codec_dai, SGTL5000_SYSCLK, 12288000, SND_SOC_CLOCK_IN);
57+
if (ret) {
58+
dev_err(dev, "could not set codec driver clock params\n");
59+
return ret;
60+
}
61+
62+
return 0;
63+
}
64+
65+
66+
static struct snd_soc_ops snd_fe_pi_audio_ops = {
67+
.hw_params = snd_fe_pi_audio_hw_params,
68+
};
69+
70+
static struct snd_soc_dai_link snd_fe_pi_audio_dai[] = {
71+
{
72+
.name = "FE-PI",
73+
.stream_name = "Fe-Pi HiFi",
74+
.cpu_dai_name = "bcm2708-i2s.0",
75+
.codec_dai_name = "sgtl5000",
76+
.platform_name = "bcm2708-i2s.0",
77+
.codec_name = "sgtl5000.1-000a",
78+
.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
79+
SND_SOC_DAIFMT_CBM_CFM,
80+
.ops = &snd_fe_pi_audio_ops,
81+
.init = snd_fe_pi_audio_init,
82+
},
83+
};
84+
85+
static const struct snd_soc_dapm_route fe_pi_audio_dapm_routes[] = {
86+
{"ADC", NULL, "Mic Bias"},
87+
};
88+
89+
90+
static struct snd_soc_card fe_pi_audio = {
91+
.name = "Fe-Pi Audio",
92+
.owner = THIS_MODULE,
93+
.dai_link = snd_fe_pi_audio_dai,
94+
.num_links = ARRAY_SIZE(snd_fe_pi_audio_dai),
95+
96+
.dapm_routes = fe_pi_audio_dapm_routes,
97+
.num_dapm_routes = ARRAY_SIZE(fe_pi_audio_dapm_routes),
98+
};
99+
100+
static int snd_fe_pi_audio_probe(struct platform_device *pdev)
101+
{
102+
int ret = 0;
103+
struct snd_soc_card *card = &fe_pi_audio;
104+
struct device_node *np = pdev->dev.of_node;
105+
struct device_node *i2s_node;
106+
struct snd_soc_dai_link *dai = &snd_fe_pi_audio_dai[0];
107+
108+
fe_pi_audio.dev = &pdev->dev;
109+
110+
i2s_node = of_parse_phandle(np, "i2s-controller", 0);
111+
if (!i2s_node) {
112+
dev_err(&pdev->dev, "i2s_node phandle missing or invalid\n");
113+
return -EINVAL;
114+
}
115+
116+
dai->cpu_dai_name = NULL;
117+
dai->cpu_of_node = i2s_node;
118+
dai->platform_name = NULL;
119+
dai->platform_of_node = i2s_node;
120+
121+
of_node_put(i2s_node);
122+
123+
card->dev = &pdev->dev;
124+
platform_set_drvdata(pdev, card);
125+
126+
ret = snd_soc_register_card(card);
127+
if (ret && ret != -EPROBE_DEFER)
128+
dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
129+
130+
return ret;
131+
}
132+
133+
static int snd_fe_pi_audio_remove(struct platform_device *pdev)
134+
{
135+
return snd_soc_unregister_card(&fe_pi_audio);
136+
}
137+
138+
static const struct of_device_id snd_fe_pi_audio_of_match[] = {
139+
{ .compatible = "fe-pi,fe-pi-audio", },
140+
{},
141+
};
142+
MODULE_DEVICE_TABLE(of, snd_fe_pi_audio_of_match);
143+
144+
static struct platform_driver snd_fe_pi_audio_driver = {
145+
.driver = {
146+
.name = "snd-fe-pi-audio",
147+
.owner = THIS_MODULE,
148+
.of_match_table = snd_fe_pi_audio_of_match,
149+
},
150+
.probe = snd_fe_pi_audio_probe,
151+
.remove = snd_fe_pi_audio_remove,
152+
};
153+
154+
module_platform_driver(snd_fe_pi_audio_driver);
155+
156+
MODULE_AUTHOR("Henry Kupis <[email protected]>");
157+
MODULE_DESCRIPTION("ASoC Driver for Fe-Pi Audio");
158+
MODULE_LICENSE("GPL v2");

0 commit comments

Comments
 (0)