1 From b3d295a256e2649444f91dd8a30bfd31873e714c Mon Sep 17 00:00:00 2001
2 From: Fe-Pi <fe-pi@cox.net>
3 Date: Wed, 1 Mar 2017 04:42:43 -0700
4 Subject: [PATCH] Add support for Fe-Pi audio sound card. (#1867)
6 Fe-Pi Audio Sound Card is based on NXP SGTL5000 codec.
7 Mechanical specification of the board is the same the Raspberry Pi Zero.
8 3.5mm jacks for Headphone/Mic, Line In, and Line Out.
10 Signed-off-by: Henry Kupis <fe-pi@cox.net>
12 ASoC: fe-pi-audio: use modern dai_link style
14 Signed-off-by: Hui Wang <hui.wang@canonical.com>
16 sound/soc/bcm/fe-pi-audio.c | 154 ++++++++++++++++++++++++++++++++++++
17 1 file changed, 154 insertions(+)
18 create mode 100644 sound/soc/bcm/fe-pi-audio.c
21 +++ b/sound/soc/bcm/fe-pi-audio.c
24 + * ASoC Driver for Fe-Pi Audio Sound Card
26 + * Author: Henry Kupis <kuupaz@gmail.com>
28 + * based on code by Florian Meier <florian.meier@koalo.de>
29 + * based on code by Shawn Guo <shawn.guo@linaro.org>
31 + * This program is free software; you can redistribute it and/or
32 + * modify it under the terms of the GNU General Public License
33 + * version 2 as published by the Free Software Foundation.
35 + * This program is distributed in the hope that it will be useful, but
36 + * WITHOUT ANY WARRANTY; without even the implied warranty of
37 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
38 + * General Public License for more details.
41 +#include <linux/module.h>
42 +#include <linux/platform_device.h>
43 +#include <linux/io.h>
45 +#include <sound/core.h>
46 +#include <sound/pcm.h>
47 +#include <sound/pcm_params.h>
48 +#include <sound/soc.h>
49 +#include <sound/jack.h>
51 +#include "../codecs/sgtl5000.h"
53 +static int snd_fe_pi_audio_init(struct snd_soc_pcm_runtime *rtd)
55 + struct snd_soc_card *card = rtd->card;
56 + struct snd_soc_component *component = rtd->codec_dai->component;
58 + snd_soc_dapm_force_enable_pin(&card->dapm, "LO");
59 + snd_soc_dapm_force_enable_pin(&card->dapm, "ADC");
60 + snd_soc_dapm_force_enable_pin(&card->dapm, "DAC");
61 + snd_soc_dapm_force_enable_pin(&card->dapm, "HP");
62 + snd_soc_component_update_bits(component, SGTL5000_CHIP_ANA_POWER,
63 + SGTL5000_VAG_POWERUP, SGTL5000_VAG_POWERUP);
68 +static int snd_fe_pi_audio_hw_params(struct snd_pcm_substream *substream,
69 + struct snd_pcm_hw_params *params)
71 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
72 + struct device *dev = rtd->card->dev;
73 + struct snd_soc_dai *codec_dai = rtd->codec_dai;
77 + /* Set SGTL5000's SYSCLK */
78 + ret = snd_soc_dai_set_sysclk(codec_dai, SGTL5000_SYSCLK, 12288000, SND_SOC_CLOCK_IN);
80 + dev_err(dev, "could not set codec driver clock params\n");
88 +static struct snd_soc_ops snd_fe_pi_audio_ops = {
89 + .hw_params = snd_fe_pi_audio_hw_params,
92 +SND_SOC_DAILINK_DEFS(fe_pi,
93 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
94 + DAILINK_COMP_ARRAY(COMP_CODEC("sgtl5000.1-000a", "sgtl5000")),
95 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
97 +static struct snd_soc_dai_link snd_fe_pi_audio_dai[] = {
100 + .stream_name = "Fe-Pi HiFi",
101 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
102 + SND_SOC_DAIFMT_CBM_CFM,
103 + .ops = &snd_fe_pi_audio_ops,
104 + .init = snd_fe_pi_audio_init,
105 + SND_SOC_DAILINK_REG(fe_pi),
109 +static const struct snd_soc_dapm_route fe_pi_audio_dapm_routes[] = {
110 + {"ADC", NULL, "Mic Bias"},
114 +static struct snd_soc_card fe_pi_audio = {
115 + .name = "Fe-Pi Audio",
116 + .owner = THIS_MODULE,
117 + .dai_link = snd_fe_pi_audio_dai,
118 + .num_links = ARRAY_SIZE(snd_fe_pi_audio_dai),
120 + .dapm_routes = fe_pi_audio_dapm_routes,
121 + .num_dapm_routes = ARRAY_SIZE(fe_pi_audio_dapm_routes),
124 +static int snd_fe_pi_audio_probe(struct platform_device *pdev)
127 + struct snd_soc_card *card = &fe_pi_audio;
128 + struct device_node *np = pdev->dev.of_node;
129 + struct device_node *i2s_node;
130 + struct snd_soc_dai_link *dai = &snd_fe_pi_audio_dai[0];
132 + fe_pi_audio.dev = &pdev->dev;
134 + i2s_node = of_parse_phandle(np, "i2s-controller", 0);
136 + dev_err(&pdev->dev, "i2s_node phandle missing or invalid\n");
140 + dai->cpus->dai_name = NULL;
141 + dai->cpus->of_node = i2s_node;
142 + dai->platforms->name = NULL;
143 + dai->platforms->of_node = i2s_node;
145 + of_node_put(i2s_node);
147 + card->dev = &pdev->dev;
148 + platform_set_drvdata(pdev, card);
150 + ret = devm_snd_soc_register_card(&pdev->dev, card);
151 + if (ret && ret != -EPROBE_DEFER)
152 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
157 +static const struct of_device_id snd_fe_pi_audio_of_match[] = {
158 + { .compatible = "fe-pi,fe-pi-audio", },
161 +MODULE_DEVICE_TABLE(of, snd_fe_pi_audio_of_match);
163 +static struct platform_driver snd_fe_pi_audio_driver = {
165 + .name = "snd-fe-pi-audio",
166 + .owner = THIS_MODULE,
167 + .of_match_table = snd_fe_pi_audio_of_match,
169 + .probe = snd_fe_pi_audio_probe,
172 +module_platform_driver(snd_fe_pi_audio_driver);
174 +MODULE_AUTHOR("Henry Kupis <fe-pi@cox.net>");
175 +MODULE_DESCRIPTION("ASoC Driver for Fe-Pi Audio");
176 +MODULE_LICENSE("GPL v2");