brcm2708: add kernel 4.14 support
[openwrt/staging/lynxis.git] / target / linux / brcm2708 / patches-4.14 / 950-0085-Add-support-for-Fe-Pi-audio-sound-card.-1867.patch
1 From 5ab1ef51caf57e4419bdc6fe1e59ea99dd54ce09 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 085/454] 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 sound/soc/bcm/Kconfig | 7 ++
13 sound/soc/bcm/Makefile | 2 +
14 sound/soc/bcm/fe-pi-audio.c | 158 ++++++++++++++++++++++++++++++++++++
15 3 files changed, 167 insertions(+)
16 create mode 100644 sound/soc/bcm/fe-pi-audio.c
17
18 --- a/sound/soc/bcm/Kconfig
19 +++ b/sound/soc/bcm/Kconfig
20 @@ -162,6 +162,13 @@ config SND_BCM2708_SOC_ALLO_BOSS_DAC
21 help
22 Say Y or M if you want to add support for Allo Boss DAC.
23
24 +config SND_BCM2708_SOC_FE_PI_AUDIO
25 + tristate "Support for Fe-Pi-Audio"
26 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
27 + select SND_SOC_SGTL5000
28 + help
29 + Say Y or M if you want to add support for Fe-Pi-Audio.
30 +
31 config SND_PISOUND
32 tristate "Support for Blokas Labs pisound"
33 depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
34 --- a/sound/soc/bcm/Makefile
35 +++ b/sound/soc/bcm/Makefile
36 @@ -30,6 +30,7 @@ snd-soc-allo-boss-dac-objs := allo-boss-
37 snd-soc-allo-piano-dac-objs := allo-piano-dac.o
38 snd-soc-allo-piano-dac-plus-objs := allo-piano-dac-plus.o
39 snd-soc-pisound-objs := pisound.o
40 +snd-soc-fe-pi-audio-objs := fe-pi-audio.o
41
42 obj-$(CONFIG_SND_BCM2708_SOC_ADAU1977_ADC) += snd-soc-adau1977-adc.o
43 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) += snd-soc-hifiberry-amp.o
44 @@ -52,3 +53,4 @@ obj-$(CONFIG_SND_BCM2708_SOC_ALLO_BOSS_D
45 obj-$(CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC) += snd-soc-allo-piano-dac.o
46 obj-$(CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC_PLUS) += snd-soc-allo-piano-dac-plus.o
47 obj-$(CONFIG_SND_PISOUND) += snd-soc-pisound.o
48 +obj-$(CONFIG_SND_BCM2708_SOC_FE_PI_AUDIO) += snd-soc-fe-pi-audio.o
49 --- /dev/null
50 +++ b/sound/soc/bcm/fe-pi-audio.c
51 @@ -0,0 +1,158 @@
52 +/*
53 + * ASoC Driver for Fe-Pi Audio Sound Card
54 + *
55 + * Author: Henry Kupis <kuupaz@gmail.com>
56 + * Copyright 2016
57 + * based on code by Florian Meier <florian.meier@koalo.de>
58 + * based on code by Shawn Guo <shawn.guo@linaro.org>
59 + *
60 + * This program is free software; you can redistribute it and/or
61 + * modify it under the terms of the GNU General Public License
62 + * version 2 as published by the Free Software Foundation.
63 + *
64 + * This program is distributed in the hope that it will be useful, but
65 + * WITHOUT ANY WARRANTY; without even the implied warranty of
66 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
67 + * General Public License for more details.
68 + */
69 +
70 +#include <linux/module.h>
71 +#include <linux/platform_device.h>
72 +#include <linux/io.h>
73 +
74 +#include <sound/core.h>
75 +#include <sound/pcm.h>
76 +#include <sound/pcm_params.h>
77 +#include <sound/soc.h>
78 +#include <sound/jack.h>
79 +
80 +#include "../codecs/sgtl5000.h"
81 +
82 +static int snd_fe_pi_audio_init(struct snd_soc_pcm_runtime *rtd)
83 +{
84 + struct snd_soc_card *card = rtd->card;
85 + struct snd_soc_codec *codec = rtd->codec;
86 +
87 + snd_soc_dapm_force_enable_pin(&card->dapm, "LO");
88 + snd_soc_dapm_force_enable_pin(&card->dapm, "ADC");
89 + snd_soc_dapm_force_enable_pin(&card->dapm, "DAC");
90 + snd_soc_dapm_force_enable_pin(&card->dapm, "HP");
91 + snd_soc_update_bits(codec, SGTL5000_CHIP_ANA_POWER,
92 + SGTL5000_VAG_POWERUP, SGTL5000_VAG_POWERUP);
93 +
94 + return 0;
95 +}
96 +
97 +static int snd_fe_pi_audio_hw_params(struct snd_pcm_substream *substream,
98 + struct snd_pcm_hw_params *params)
99 +{
100 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
101 + struct device *dev = rtd->card->dev;
102 + struct snd_soc_dai *codec_dai = rtd->codec_dai;
103 +
104 + int ret;
105 +
106 + /* Set SGTL5000's SYSCLK */
107 + ret = snd_soc_dai_set_sysclk(codec_dai, SGTL5000_SYSCLK, 12288000, SND_SOC_CLOCK_IN);
108 + if (ret) {
109 + dev_err(dev, "could not set codec driver clock params\n");
110 + return ret;
111 + }
112 +
113 + return 0;
114 +}
115 +
116 +
117 +static struct snd_soc_ops snd_fe_pi_audio_ops = {
118 + .hw_params = snd_fe_pi_audio_hw_params,
119 +};
120 +
121 +static struct snd_soc_dai_link snd_fe_pi_audio_dai[] = {
122 + {
123 + .name = "FE-PI",
124 + .stream_name = "Fe-Pi HiFi",
125 + .cpu_dai_name = "bcm2708-i2s.0",
126 + .codec_dai_name = "sgtl5000",
127 + .platform_name = "bcm2708-i2s.0",
128 + .codec_name = "sgtl5000.1-000a",
129 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
130 + SND_SOC_DAIFMT_CBM_CFM,
131 + .ops = &snd_fe_pi_audio_ops,
132 + .init = snd_fe_pi_audio_init,
133 + },
134 +};
135 +
136 +static const struct snd_soc_dapm_route fe_pi_audio_dapm_routes[] = {
137 + {"ADC", NULL, "Mic Bias"},
138 +};
139 +
140 +
141 +static struct snd_soc_card fe_pi_audio = {
142 + .name = "Fe-Pi Audio",
143 + .owner = THIS_MODULE,
144 + .dai_link = snd_fe_pi_audio_dai,
145 + .num_links = ARRAY_SIZE(snd_fe_pi_audio_dai),
146 +
147 + .dapm_routes = fe_pi_audio_dapm_routes,
148 + .num_dapm_routes = ARRAY_SIZE(fe_pi_audio_dapm_routes),
149 +};
150 +
151 +static int snd_fe_pi_audio_probe(struct platform_device *pdev)
152 +{
153 + int ret = 0;
154 + struct snd_soc_card *card = &fe_pi_audio;
155 + struct device_node *np = pdev->dev.of_node;
156 + struct device_node *i2s_node;
157 + struct snd_soc_dai_link *dai = &snd_fe_pi_audio_dai[0];
158 +
159 + fe_pi_audio.dev = &pdev->dev;
160 +
161 + i2s_node = of_parse_phandle(np, "i2s-controller", 0);
162 + if (!i2s_node) {
163 + dev_err(&pdev->dev, "i2s_node phandle missing or invalid\n");
164 + return -EINVAL;
165 + }
166 +
167 + dai->cpu_dai_name = NULL;
168 + dai->cpu_of_node = i2s_node;
169 + dai->platform_name = NULL;
170 + dai->platform_of_node = i2s_node;
171 +
172 + of_node_put(i2s_node);
173 +
174 + card->dev = &pdev->dev;
175 + platform_set_drvdata(pdev, card);
176 +
177 + ret = snd_soc_register_card(card);
178 + if (ret && ret != -EPROBE_DEFER)
179 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
180 +
181 + return ret;
182 +}
183 +
184 +static int snd_fe_pi_audio_remove(struct platform_device *pdev)
185 +{
186 + return snd_soc_unregister_card(&fe_pi_audio);
187 +}
188 +
189 +static const struct of_device_id snd_fe_pi_audio_of_match[] = {
190 + { .compatible = "fe-pi,fe-pi-audio", },
191 + {},
192 +};
193 +MODULE_DEVICE_TABLE(of, snd_fe_pi_audio_of_match);
194 +
195 +static struct platform_driver snd_fe_pi_audio_driver = {
196 + .driver = {
197 + .name = "snd-fe-pi-audio",
198 + .owner = THIS_MODULE,
199 + .of_match_table = snd_fe_pi_audio_of_match,
200 + },
201 + .probe = snd_fe_pi_audio_probe,
202 + .remove = snd_fe_pi_audio_remove,
203 +};
204 +
205 +module_platform_driver(snd_fe_pi_audio_driver);
206 +
207 +MODULE_AUTHOR("Henry Kupis <fe-pi@cox.net>");
208 +MODULE_DESCRIPTION("ASoC Driver for Fe-Pi Audio");
209 +MODULE_LICENSE("GPL v2");