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