brcm2708: switch to linux 4.4 and update patches
[openwrt.git] / target / linux / brcm2708 / patches-4.4 / 0065-ASoC-Add-support-for-Rpi-DAC.patch
1 From 698c90d19c77b07426d8b5825d7053b8ba5d8bc3 Mon Sep 17 00:00:00 2001
2 From: Florian Meier <florian.meier@koalo.de>
3 Date: Fri, 22 Nov 2013 19:21:34 +0100
4 Subject: [PATCH 065/156] ASoC: Add support for Rpi-DAC
5
6 ---
7  sound/soc/bcm/Kconfig       |   7 +++
8  sound/soc/bcm/Makefile      |   2 +
9  sound/soc/bcm/rpi-dac.c     | 118 ++++++++++++++++++++++++++++++++++++++++++++
10  sound/soc/codecs/Kconfig    |   9 ++++
11  sound/soc/codecs/Makefile   |   2 +
12  sound/soc/codecs/pcm1794a.c |  69 ++++++++++++++++++++++++++
13  6 files changed, 207 insertions(+)
14  create mode 100644 sound/soc/bcm/rpi-dac.c
15  create mode 100644 sound/soc/codecs/pcm1794a.c
16
17 --- a/sound/soc/bcm/Kconfig
18 +++ b/sound/soc/bcm/Kconfig
19 @@ -14,3 +14,10 @@ config SND_BCM2708_SOC_HIFIBERRY_DAC
20          select SND_SOC_PCM5102A
21          help
22           Say Y or M if you want to add support for HifiBerry DAC.
23 +
24 +config SND_BCM2708_SOC_RPI_DAC
25 +        tristate "Support for RPi-DAC"
26 +        depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
27 +        select SND_SOC_PCM1794A
28 +        help
29 +         Say Y or M if you want to add support for RPi-DAC.
30 --- a/sound/soc/bcm/Makefile
31 +++ b/sound/soc/bcm/Makefile
32 @@ -5,5 +5,7 @@ obj-$(CONFIG_SND_BCM2835_SOC_I2S) += snd
33  
34  # BCM2708 Machine Support
35  snd-soc-hifiberry-dac-objs := hifiberry_dac.o
36 +snd-soc-rpi-dac-objs := rpi-dac.o
37  
38  obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
39 +obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
40 --- /dev/null
41 +++ b/sound/soc/bcm/rpi-dac.c
42 @@ -0,0 +1,118 @@
43 +/*
44 + * ASoC Driver for RPi-DAC.
45 + *
46 + * Author:     Florian Meier <florian.meier@koalo.de>
47 + *             Copyright 2013
48 + *
49 + * This program is free software; you can redistribute it and/or
50 + * modify it under the terms of the GNU General Public License
51 + * version 2 as published by the Free Software Foundation.
52 + *
53 + * This program is distributed in the hope that it will be useful, but
54 + * WITHOUT ANY WARRANTY; without even the implied warranty of
55 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
56 + * General Public License for more details.
57 + */
58 +
59 +#include <linux/module.h>
60 +#include <linux/platform_device.h>
61 +
62 +#include <sound/core.h>
63 +#include <sound/pcm.h>
64 +#include <sound/pcm_params.h>
65 +#include <sound/soc.h>
66 +#include <sound/jack.h>
67 +
68 +static int snd_rpi_rpi_dac_init(struct snd_soc_pcm_runtime *rtd)
69 +{
70 +       return 0;
71 +}
72 +
73 +static int snd_rpi_rpi_dac_hw_params(struct snd_pcm_substream *substream,
74 +                                      struct snd_pcm_hw_params *params)
75 +{
76 +       struct snd_soc_pcm_runtime *rtd = substream->private_data;
77 +       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
78 +
79 +       return snd_soc_dai_set_bclk_ratio(cpu_dai, 32*2);
80 +}
81 +
82 +/* machine stream operations */
83 +static struct snd_soc_ops snd_rpi_rpi_dac_ops = {
84 +       .hw_params = snd_rpi_rpi_dac_hw_params,
85 +};
86 +
87 +static struct snd_soc_dai_link snd_rpi_rpi_dac_dai[] = {
88 +{
89 +       .name           = "RPi-DAC",
90 +       .stream_name    = "RPi-DAC HiFi",
91 +       .cpu_dai_name   = "bcm2708-i2s.0",
92 +       .codec_dai_name = "pcm1794a-hifi",
93 +       .platform_name  = "bcm2708-i2s.0",
94 +       .codec_name     = "pcm1794a-codec",
95 +       .dai_fmt        = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
96 +                               SND_SOC_DAIFMT_CBS_CFS,
97 +       .ops            = &snd_rpi_rpi_dac_ops,
98 +       .init           = snd_rpi_rpi_dac_init,
99 +},
100 +};
101 +
102 +/* audio machine driver */
103 +static struct snd_soc_card snd_rpi_rpi_dac = {
104 +       .name         = "snd_rpi_rpi_dac",
105 +       .dai_link     = snd_rpi_rpi_dac_dai,
106 +       .num_links    = ARRAY_SIZE(snd_rpi_rpi_dac_dai),
107 +};
108 +
109 +static int snd_rpi_rpi_dac_probe(struct platform_device *pdev)
110 +{
111 +       int ret = 0;
112 +
113 +       snd_rpi_rpi_dac.dev = &pdev->dev;
114 +       
115 +       if (pdev->dev.of_node) {
116 +               struct device_node *i2s_node;
117 +               struct snd_soc_dai_link *dai = &snd_rpi_rpi_dac_dai[0];
118 +               i2s_node = of_parse_phandle(pdev->dev.of_node, "i2s-controller", 0);
119 +
120 +               if (i2s_node) {
121 +                       dai->cpu_dai_name = NULL;
122 +                       dai->cpu_of_node = i2s_node;
123 +                       dai->platform_name = NULL;
124 +                       dai->platform_of_node = i2s_node;
125 +               }
126 +       }
127 +       
128 +       ret = snd_soc_register_card(&snd_rpi_rpi_dac);
129 +       if (ret)
130 +               dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
131 +
132 +       return ret;
133 +}
134 +
135 +static int snd_rpi_rpi_dac_remove(struct platform_device *pdev)
136 +{
137 +       return snd_soc_unregister_card(&snd_rpi_rpi_dac);
138 +}
139 +
140 +static const struct of_device_id snd_rpi_rpi_dac_of_match[] = {
141 +       { .compatible = "rpi,rpi-dac", },
142 +       {},
143 +};
144 +MODULE_DEVICE_TABLE(of, snd_rpi_rpi_dac_of_match);
145 +
146 +static struct platform_driver snd_rpi_rpi_dac_driver = {
147 +        .driver = {
148 +                .name   = "snd-rpi-dac",
149 +                .owner  = THIS_MODULE,
150 +                .of_match_table = snd_rpi_rpi_dac_of_match,
151 +        },
152 +        .probe          = snd_rpi_rpi_dac_probe,
153 +        .remove         = snd_rpi_rpi_dac_remove,
154 +};
155 +
156 +module_platform_driver(snd_rpi_rpi_dac_driver);
157 +
158 +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
159 +MODULE_DESCRIPTION("ASoC Driver for RPi-DAC");
160 +MODULE_LICENSE("GPL v2");
161 --- a/sound/soc/codecs/Kconfig
162 +++ b/sound/soc/codecs/Kconfig
163 @@ -90,6 +90,7 @@ config SND_SOC_ALL_CODECS
164         select SND_SOC_RT286 if I2C
165         select SND_SOC_RT298 if I2C
166         select SND_SOC_PCM5102A if I2C
167 +       select SND_SOC_PCM1794A if I2C
168         select SND_SOC_RT5631 if I2C
169         select SND_SOC_RT5640 if I2C
170         select SND_SOC_RT5645 if I2C
171 @@ -550,6 +551,14 @@ config SND_SOC_RT298
172         tristate
173         depends on I2C
174  
175 +config SND_SOC_RT298
176 +       tristate
177 +       depends on I2C
178 +
179 +config SND_SOC_PCM1794A
180 +       tristate
181 +       depends on I2C
182 +
183  config SND_SOC_PCM5102A
184         tristate
185         depends on I2C
186 --- a/sound/soc/codecs/Makefile
187 +++ b/sound/soc/codecs/Makefile
188 @@ -85,6 +85,7 @@ snd-soc-rl6231-objs := rl6231.o
189  snd-soc-rl6347a-objs := rl6347a.o
190  snd-soc-rt286-objs := rt286.o
191  snd-soc-rt298-objs := rt298.o
192 +snd-soc-pcm1794a-objs := pcm1794a.o
193  snd-soc-pcm5102a-objs := pcm5102a.o
194  snd-soc-rt5631-objs := rt5631.o
195  snd-soc-rt5640-objs := rt5640.o
196 @@ -281,6 +282,7 @@ obj-$(CONFIG_SND_SOC_RL6231)        += snd-soc-
197  obj-$(CONFIG_SND_SOC_RL6347A)  += snd-soc-rl6347a.o
198  obj-$(CONFIG_SND_SOC_RT286)    += snd-soc-rt286.o
199  obj-$(CONFIG_SND_SOC_RT298)    += snd-soc-rt298.o
200 +obj-$(CONFIG_SND_SOC_PCM1794A) += snd-soc-pcm1794a.o
201  obj-$(CONFIG_SND_SOC_PCM5102A) += snd-soc-pcm5102a.o
202  obj-$(CONFIG_SND_SOC_RT5631)   += snd-soc-rt5631.o
203  obj-$(CONFIG_SND_SOC_RT5640)   += snd-soc-rt5640.o
204 --- /dev/null
205 +++ b/sound/soc/codecs/pcm1794a.c
206 @@ -0,0 +1,69 @@
207 +/*
208 + * Driver for the PCM1794A codec
209 + *
210 + * Author:     Florian Meier <florian.meier@koalo.de>
211 + *             Copyright 2013
212 + *
213 + * This program is free software; you can redistribute it and/or
214 + * modify it under the terms of the GNU General Public License
215 + * version 2 as published by the Free Software Foundation.
216 + *
217 + * This program is distributed in the hope that it will be useful, but
218 + * WITHOUT ANY WARRANTY; without even the implied warranty of
219 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
220 + * General Public License for more details.
221 + */
222 +
223 +
224 +#include <linux/init.h>
225 +#include <linux/module.h>
226 +#include <linux/platform_device.h>
227 +
228 +#include <sound/soc.h>
229 +
230 +static struct snd_soc_dai_driver pcm1794a_dai = {
231 +       .name = "pcm1794a-hifi",
232 +       .playback = {
233 +               .channels_min = 2,
234 +               .channels_max = 2,
235 +               .rates = SNDRV_PCM_RATE_8000_192000,
236 +               .formats = SNDRV_PCM_FMTBIT_S16_LE |
237 +                          SNDRV_PCM_FMTBIT_S24_LE
238 +       },
239 +};
240 +
241 +static struct snd_soc_codec_driver soc_codec_dev_pcm1794a;
242 +
243 +static int pcm1794a_probe(struct platform_device *pdev)
244 +{
245 +       return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pcm1794a,
246 +                       &pcm1794a_dai, 1);
247 +}
248 +
249 +static int pcm1794a_remove(struct platform_device *pdev)
250 +{
251 +       snd_soc_unregister_codec(&pdev->dev);
252 +       return 0;
253 +}
254 +
255 +static const struct of_device_id pcm1794a_of_match[] = {
256 +       { .compatible = "ti,pcm1794a", },
257 +       { }
258 +};
259 +MODULE_DEVICE_TABLE(of, pcm1794a_of_match);
260 +
261 +static struct platform_driver pcm1794a_codec_driver = {
262 +       .probe          = pcm1794a_probe,
263 +       .remove         = pcm1794a_remove,
264 +       .driver         = {
265 +               .name   = "pcm1794a-codec",
266 +               .owner  = THIS_MODULE,
267 +               .of_match_table = of_match_ptr(pcm1794a_of_match),
268 +       },
269 +};
270 +
271 +module_platform_driver(pcm1794a_codec_driver);
272 +
273 +MODULE_DESCRIPTION("ASoC PCM1794A codec driver");
274 +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
275 +MODULE_LICENSE("GPL v2");