bcm27xx: add linux 5.4 support
[openwrt/staging/jogo.git] / target / linux / bcm27xx / patches-5.4 / 950-0074-Add-support-for-Fe-Pi-audio-sound-card.-1867.patch
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)
5
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.
9
10 Signed-off-by: Henry Kupis <fe-pi@cox.net>
11
12 ASoC: fe-pi-audio: use modern dai_link style
13
14 Signed-off-by: Hui Wang <hui.wang@canonical.com>
15 ---
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
19
20 --- /dev/null
21 +++ b/sound/soc/bcm/fe-pi-audio.c
22 @@ -0,0 +1,154 @@
23 +/*
24 + * ASoC Driver for Fe-Pi Audio Sound Card
25 + *
26 + * Author: Henry Kupis <kuupaz@gmail.com>
27 + * Copyright 2016
28 + * based on code by Florian Meier <florian.meier@koalo.de>
29 + * based on code by Shawn Guo <shawn.guo@linaro.org>
30 + *
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.
34 + *
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.
39 + */
40 +
41 +#include <linux/module.h>
42 +#include <linux/platform_device.h>
43 +#include <linux/io.h>
44 +
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>
50 +
51 +#include "../codecs/sgtl5000.h"
52 +
53 +static int snd_fe_pi_audio_init(struct snd_soc_pcm_runtime *rtd)
54 +{
55 + struct snd_soc_card *card = rtd->card;
56 + struct snd_soc_component *component = rtd->codec_dai->component;
57 +
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);
64 +
65 + return 0;
66 +}
67 +
68 +static int snd_fe_pi_audio_hw_params(struct snd_pcm_substream *substream,
69 + struct snd_pcm_hw_params *params)
70 +{
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;
74 +
75 + int ret;
76 +
77 + /* Set SGTL5000's SYSCLK */
78 + ret = snd_soc_dai_set_sysclk(codec_dai, SGTL5000_SYSCLK, 12288000, SND_SOC_CLOCK_IN);
79 + if (ret) {
80 + dev_err(dev, "could not set codec driver clock params\n");
81 + return ret;
82 + }
83 +
84 + return 0;
85 +}
86 +
87 +
88 +static struct snd_soc_ops snd_fe_pi_audio_ops = {
89 + .hw_params = snd_fe_pi_audio_hw_params,
90 +};
91 +
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")));
96 +
97 +static struct snd_soc_dai_link snd_fe_pi_audio_dai[] = {
98 + {
99 + .name = "FE-PI",
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),
106 + },
107 +};
108 +
109 +static const struct snd_soc_dapm_route fe_pi_audio_dapm_routes[] = {
110 + {"ADC", NULL, "Mic Bias"},
111 +};
112 +
113 +
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),
119 +
120 + .dapm_routes = fe_pi_audio_dapm_routes,
121 + .num_dapm_routes = ARRAY_SIZE(fe_pi_audio_dapm_routes),
122 +};
123 +
124 +static int snd_fe_pi_audio_probe(struct platform_device *pdev)
125 +{
126 + int ret = 0;
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];
131 +
132 + fe_pi_audio.dev = &pdev->dev;
133 +
134 + i2s_node = of_parse_phandle(np, "i2s-controller", 0);
135 + if (!i2s_node) {
136 + dev_err(&pdev->dev, "i2s_node phandle missing or invalid\n");
137 + return -EINVAL;
138 + }
139 +
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;
144 +
145 + of_node_put(i2s_node);
146 +
147 + card->dev = &pdev->dev;
148 + platform_set_drvdata(pdev, card);
149 +
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);
153 +
154 + return ret;
155 +}
156 +
157 +static const struct of_device_id snd_fe_pi_audio_of_match[] = {
158 + { .compatible = "fe-pi,fe-pi-audio", },
159 + {},
160 +};
161 +MODULE_DEVICE_TABLE(of, snd_fe_pi_audio_of_match);
162 +
163 +static struct platform_driver snd_fe_pi_audio_driver = {
164 + .driver = {
165 + .name = "snd-fe-pi-audio",
166 + .owner = THIS_MODULE,
167 + .of_match_table = snd_fe_pi_audio_of_match,
168 + },
169 + .probe = snd_fe_pi_audio_probe,
170 +};
171 +
172 +module_platform_driver(snd_fe_pi_audio_driver);
173 +
174 +MODULE_AUTHOR("Henry Kupis <fe-pi@cox.net>");
175 +MODULE_DESCRIPTION("ASoC Driver for Fe-Pi Audio");
176 +MODULE_LICENSE("GPL v2");