ath79: add support for COMFAST CF-E130N v2
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-4.19 / 950-0080-Add-support-for-Fe-Pi-audio-sound-card.-1867.patch
1 From 8ed265197d7a8f9c1a328d262bfe91050716ad76 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 sound/soc/bcm/fe-pi-audio.c | 152 ++++++++++++++++++++++++++++++++++++
13 1 file changed, 152 insertions(+)
14 create mode 100644 sound/soc/bcm/fe-pi-audio.c
15
16 --- /dev/null
17 +++ b/sound/soc/bcm/fe-pi-audio.c
18 @@ -0,0 +1,152 @@
19 +/*
20 + * ASoC Driver for Fe-Pi Audio Sound Card
21 + *
22 + * Author: Henry Kupis <kuupaz@gmail.com>
23 + * Copyright 2016
24 + * based on code by Florian Meier <florian.meier@koalo.de>
25 + * based on code by Shawn Guo <shawn.guo@linaro.org>
26 + *
27 + * This program is free software; you can redistribute it and/or
28 + * modify it under the terms of the GNU General Public License
29 + * version 2 as published by the Free Software Foundation.
30 + *
31 + * This program is distributed in the hope that it will be useful, but
32 + * WITHOUT ANY WARRANTY; without even the implied warranty of
33 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
34 + * General Public License for more details.
35 + */
36 +
37 +#include <linux/module.h>
38 +#include <linux/platform_device.h>
39 +#include <linux/io.h>
40 +
41 +#include <sound/core.h>
42 +#include <sound/pcm.h>
43 +#include <sound/pcm_params.h>
44 +#include <sound/soc.h>
45 +#include <sound/jack.h>
46 +
47 +#include "../codecs/sgtl5000.h"
48 +
49 +static int snd_fe_pi_audio_init(struct snd_soc_pcm_runtime *rtd)
50 +{
51 + struct snd_soc_card *card = rtd->card;
52 + struct snd_soc_component *component = rtd->codec_dai->component;
53 +
54 + snd_soc_dapm_force_enable_pin(&card->dapm, "LO");
55 + snd_soc_dapm_force_enable_pin(&card->dapm, "ADC");
56 + snd_soc_dapm_force_enable_pin(&card->dapm, "DAC");
57 + snd_soc_dapm_force_enable_pin(&card->dapm, "HP");
58 + snd_soc_component_update_bits(component, SGTL5000_CHIP_ANA_POWER,
59 + SGTL5000_VAG_POWERUP, SGTL5000_VAG_POWERUP);
60 +
61 + return 0;
62 +}
63 +
64 +static int snd_fe_pi_audio_hw_params(struct snd_pcm_substream *substream,
65 + struct snd_pcm_hw_params *params)
66 +{
67 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
68 + struct device *dev = rtd->card->dev;
69 + struct snd_soc_dai *codec_dai = rtd->codec_dai;
70 +
71 + int ret;
72 +
73 + /* Set SGTL5000's SYSCLK */
74 + ret = snd_soc_dai_set_sysclk(codec_dai, SGTL5000_SYSCLK, 12288000, SND_SOC_CLOCK_IN);
75 + if (ret) {
76 + dev_err(dev, "could not set codec driver clock params\n");
77 + return ret;
78 + }
79 +
80 + return 0;
81 +}
82 +
83 +
84 +static struct snd_soc_ops snd_fe_pi_audio_ops = {
85 + .hw_params = snd_fe_pi_audio_hw_params,
86 +};
87 +
88 +static struct snd_soc_dai_link snd_fe_pi_audio_dai[] = {
89 + {
90 + .name = "FE-PI",
91 + .stream_name = "Fe-Pi HiFi",
92 + .cpu_dai_name = "bcm2708-i2s.0",
93 + .codec_dai_name = "sgtl5000",
94 + .platform_name = "bcm2708-i2s.0",
95 + .codec_name = "sgtl5000.1-000a",
96 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
97 + SND_SOC_DAIFMT_CBM_CFM,
98 + .ops = &snd_fe_pi_audio_ops,
99 + .init = snd_fe_pi_audio_init,
100 + },
101 +};
102 +
103 +static const struct snd_soc_dapm_route fe_pi_audio_dapm_routes[] = {
104 + {"ADC", NULL, "Mic Bias"},
105 +};
106 +
107 +
108 +static struct snd_soc_card fe_pi_audio = {
109 + .name = "Fe-Pi Audio",
110 + .owner = THIS_MODULE,
111 + .dai_link = snd_fe_pi_audio_dai,
112 + .num_links = ARRAY_SIZE(snd_fe_pi_audio_dai),
113 +
114 + .dapm_routes = fe_pi_audio_dapm_routes,
115 + .num_dapm_routes = ARRAY_SIZE(fe_pi_audio_dapm_routes),
116 +};
117 +
118 +static int snd_fe_pi_audio_probe(struct platform_device *pdev)
119 +{
120 + int ret = 0;
121 + struct snd_soc_card *card = &fe_pi_audio;
122 + struct device_node *np = pdev->dev.of_node;
123 + struct device_node *i2s_node;
124 + struct snd_soc_dai_link *dai = &snd_fe_pi_audio_dai[0];
125 +
126 + fe_pi_audio.dev = &pdev->dev;
127 +
128 + i2s_node = of_parse_phandle(np, "i2s-controller", 0);
129 + if (!i2s_node) {
130 + dev_err(&pdev->dev, "i2s_node phandle missing or invalid\n");
131 + return -EINVAL;
132 + }
133 +
134 + dai->cpu_dai_name = NULL;
135 + dai->cpu_of_node = i2s_node;
136 + dai->platform_name = NULL;
137 + dai->platform_of_node = i2s_node;
138 +
139 + of_node_put(i2s_node);
140 +
141 + card->dev = &pdev->dev;
142 + platform_set_drvdata(pdev, card);
143 +
144 + ret = devm_snd_soc_register_card(&pdev->dev, card);
145 + if (ret && ret != -EPROBE_DEFER)
146 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
147 +
148 + return ret;
149 +}
150 +
151 +static const struct of_device_id snd_fe_pi_audio_of_match[] = {
152 + { .compatible = "fe-pi,fe-pi-audio", },
153 + {},
154 +};
155 +MODULE_DEVICE_TABLE(of, snd_fe_pi_audio_of_match);
156 +
157 +static struct platform_driver snd_fe_pi_audio_driver = {
158 + .driver = {
159 + .name = "snd-fe-pi-audio",
160 + .owner = THIS_MODULE,
161 + .of_match_table = snd_fe_pi_audio_of_match,
162 + },
163 + .probe = snd_fe_pi_audio_probe,
164 +};
165 +
166 +module_platform_driver(snd_fe_pi_audio_driver);
167 +
168 +MODULE_AUTHOR("Henry Kupis <fe-pi@cox.net>");
169 +MODULE_DESCRIPTION("ASoC Driver for Fe-Pi Audio");
170 +MODULE_LICENSE("GPL v2");