brcm2708: switch to linux 4.4 and update patches
[openwrt.git] / target / linux / brcm2708 / patches-4.1 / 0050-Adding-Device-Tree-support-for-some-RPi-audio-cards.patch
1 From 22a72f5b7b5e7444845927855d29fc26077cba36 Mon Sep 17 00:00:00 2001
2 From: popcornmix <popcornmix@gmail.com>
3 Date: Mon, 13 Apr 2015 18:45:39 +0100
4 Subject: [PATCH 050/222] Adding Device Tree support for some RPi audio cards
5
6 ---
7  arch/arm/mach-bcm2709/bcm2709.c   | 143 ++++++++++++++++++++++++++++++++++++++
8  sound/soc/bcm/hifiberry_dac.c     |  22 ++++++
9  sound/soc/bcm/hifiberry_dacplus.c |  22 ++++++
10  sound/soc/bcm/hifiberry_digi.c    |  22 ++++++
11  sound/soc/bcm/iqaudio-dac.c       |  16 +++++
12  sound/soc/codecs/pcm5102a.c       |   7 ++
13  6 files changed, 232 insertions(+)
14
15 --- a/arch/arm/mach-bcm2709/bcm2709.c
16 +++ b/arch/arm/mach-bcm2709/bcm2709.c
17 @@ -636,6 +636,115 @@ static struct platform_device bcm2835_th
18         .name = "bcm2835_thermal",
19  };
20  
21 +#if defined(CONFIG_SND_BCM2708_SOC_I2S) || defined(CONFIG_SND_BCM2708_SOC_I2S_MODULE)
22 +static struct resource bcm2708_i2s_resources[] = {
23 +       {
24 +               .start = I2S_BASE,
25 +               .end = I2S_BASE + 0x20,
26 +               .flags = IORESOURCE_MEM,
27 +       },
28 +        {
29 +               .start = PCM_CLOCK_BASE,
30 +               .end = PCM_CLOCK_BASE + 0x02,
31 +               .flags = IORESOURCE_MEM,
32 +       }
33 +};
34 +
35 +static struct platform_device bcm2708_i2s_device = {
36 +       .name = "bcm2708-i2s",
37 +       .id = 0,
38 +       .num_resources = ARRAY_SIZE(bcm2708_i2s_resources),
39 +       .resource = bcm2708_i2s_resources,
40 +};
41 +#endif
42 +
43 +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC_MODULE)
44 +static struct platform_device snd_hifiberry_dac_device = {
45 +        .name = "snd-hifiberry-dac",
46 +        .id = 0,
47 +        .num_resources = 0,
48 +};
49 +
50 +static struct platform_device snd_pcm5102a_codec_device = {
51 +        .name = "pcm5102a-codec",
52 +        .id = -1,
53 +        .num_resources = 0,
54 +};
55 +#endif
56 +
57 +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS_MODULE)
58 +static struct platform_device snd_rpi_hifiberry_dacplus_device = {
59 +        .name = "snd-rpi-hifiberry-dacplus",
60 +        .id = 0,
61 +        .num_resources = 0,
62 +};
63 +
64 +static struct i2c_board_info __initdata snd_pcm512x_hbdacplus_i2c_devices[] = {
65 +        {
66 +                I2C_BOARD_INFO("pcm5122", 0x4d)
67 +        },
68 +};
69 +#endif
70 +
71 +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI_MODULE)
72 +static struct platform_device snd_hifiberry_digi_device = {
73 +        .name = "snd-hifiberry-digi",
74 +        .id = 0,
75 +        .num_resources = 0,
76 +};
77 +
78 +static struct i2c_board_info __initdata snd_wm8804_i2c_devices[] = {
79 +        {
80 +                I2C_BOARD_INFO("wm8804", 0x3b)
81 +        },
82 +};
83 +
84 +#endif
85 +
86 +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP_MODULE)
87 +static struct platform_device snd_hifiberry_amp_device = {
88 +        .name = "snd-hifiberry-amp",
89 +        .id = 0,
90 +        .num_resources = 0,
91 +};
92 +
93 +static struct i2c_board_info __initdata snd_tas5713_i2c_devices[] = {
94 +        {
95 +                I2C_BOARD_INFO("tas5713", 0x1b)
96 +        },
97 +};
98 +#endif
99 +
100 +#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
101 +static struct platform_device snd_rpi_dac_device = {
102 +        .name = "snd-rpi-dac",
103 +        .id = 0,
104 +        .num_resources = 0,
105 +};
106 +
107 +static struct platform_device snd_pcm1794a_codec_device = {
108 +        .name = "pcm1794a-codec",
109 +        .id = -1,
110 +        .num_resources = 0,
111 +};
112 +#endif
113 +
114 +
115 +#if defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) || defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC_MODULE)
116 +static struct platform_device snd_rpi_iqaudio_dac_device = {
117 +        .name = "snd-rpi-iqaudio-dac",
118 +        .id = 0,
119 +        .num_resources = 0,
120 +};
121 +
122 +// Use the actual device name rather than generic driver name
123 +static struct i2c_board_info __initdata snd_pcm512x_i2c_devices[] = {
124 +       {
125 +               I2C_BOARD_INFO("pcm5122", 0x4c)
126 +       },
127 +};
128 +#endif
129 +
130  int __init bcm_register_device(struct platform_device *pdev)
131  {
132         int ret;
133 @@ -800,6 +909,40 @@ void __init bcm2709_init(void)
134  
135         bcm_register_device_dt(&bcm2835_thermal_device);
136  
137 +#if defined(CONFIG_SND_BCM2708_SOC_I2S) || defined(CONFIG_SND_BCM2708_SOC_I2S_MODULE)
138 +       bcm_register_device_dt(&bcm2708_i2s_device);
139 +#endif
140 +
141 +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC_MODULE)
142 +        bcm_register_device_dt(&snd_hifiberry_dac_device);
143 +        bcm_register_device_dt(&snd_pcm5102a_codec_device);
144 +#endif
145 +
146 +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS_MODULE)
147 +        bcm_register_device_dt(&snd_rpi_hifiberry_dacplus_device);
148 +        i2c_register_board_info_dt(1, snd_pcm512x_hbdacplus_i2c_devices, ARRAY_SIZE(snd_pcm512x_hbdacplus_i2c_devices));
149 +#endif
150 +
151 +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI_MODULE)
152 +        bcm_register_device_dt(&snd_hifiberry_digi_device);
153 +        i2c_register_board_info_dt(1, snd_wm8804_i2c_devices, ARRAY_SIZE(snd_wm8804_i2c_devices));
154 +#endif
155 +
156 +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP_MODULE)
157 +        bcm_register_device_dt(&snd_hifiberry_amp_device);
158 +        i2c_register_board_info_dt(1, snd_tas5713_i2c_devices, ARRAY_SIZE(snd_tas5713_i2c_devices));
159 +#endif
160 +
161 +#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
162 +        bcm_register_device_dt(&snd_rpi_dac_device);
163 +        bcm_register_device_dt(&snd_pcm1794a_codec_device);
164 +#endif
165 +
166 +#if defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) || defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC_MODULE)
167 +        bcm_register_device_dt(&snd_rpi_iqaudio_dac_device);
168 +        i2c_register_board_info_dt(1, snd_pcm512x_i2c_devices, ARRAY_SIZE(snd_pcm512x_i2c_devices));
169 +#endif
170 +
171         if (!use_dt) {
172                 for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
173                         struct amba_device *d = amba_devs[i];
174 --- a/sound/soc/bcm/hifiberry_dac.c
175 +++ b/sound/soc/bcm/hifiberry_dac.c
176 @@ -72,6 +72,21 @@ static int snd_rpi_hifiberry_dac_probe(s
177         int ret = 0;
178  
179         snd_rpi_hifiberry_dac.dev = &pdev->dev;
180 +
181 +       if (pdev->dev.of_node) {
182 +           struct device_node *i2s_node;
183 +           struct snd_soc_dai_link *dai = &snd_rpi_hifiberry_dac_dai[0];
184 +           i2s_node = of_parse_phandle(pdev->dev.of_node,
185 +                                       "i2s-controller", 0);
186 +
187 +           if (i2s_node) {
188 +               dai->cpu_dai_name = NULL;
189 +               dai->cpu_of_node = i2s_node;
190 +               dai->platform_name = NULL;
191 +               dai->platform_of_node = i2s_node;
192 +           }
193 +       }
194 +
195         ret = snd_soc_register_card(&snd_rpi_hifiberry_dac);
196         if (ret)
197                 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
198 @@ -84,10 +99,17 @@ static int snd_rpi_hifiberry_dac_remove(
199         return snd_soc_unregister_card(&snd_rpi_hifiberry_dac);
200  }
201  
202 +static const struct of_device_id snd_rpi_hifiberry_dac_of_match[] = {
203 +       { .compatible = "hifiberry,hifiberry-dac", },
204 +       {},
205 +};
206 +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_dac_of_match);
207 +
208  static struct platform_driver snd_rpi_hifiberry_dac_driver = {
209          .driver = {
210                  .name   = "snd-hifiberry-dac",
211                  .owner  = THIS_MODULE,
212 +               .of_match_table = snd_rpi_hifiberry_dac_of_match,
213          },
214          .probe          = snd_rpi_hifiberry_dac_probe,
215          .remove         = snd_rpi_hifiberry_dac_remove,
216 --- a/sound/soc/bcm/hifiberry_dacplus.c
217 +++ b/sound/soc/bcm/hifiberry_dacplus.c
218 @@ -90,6 +90,21 @@ static int snd_rpi_hifiberry_dacplus_pro
219         int ret = 0;
220  
221         snd_rpi_hifiberry_dacplus.dev = &pdev->dev;
222 +
223 +       if (pdev->dev.of_node) {
224 +           struct device_node *i2s_node;
225 +           struct snd_soc_dai_link *dai = &snd_rpi_hifiberry_dacplus_dai[0];
226 +           i2s_node = of_parse_phandle(pdev->dev.of_node,
227 +                                       "i2s-controller", 0);
228 +
229 +           if (i2s_node) {
230 +               dai->cpu_dai_name = NULL;
231 +               dai->cpu_of_node = i2s_node;
232 +               dai->platform_name = NULL;
233 +               dai->platform_of_node = i2s_node;
234 +           }
235 +       }
236 +
237         ret = snd_soc_register_card(&snd_rpi_hifiberry_dacplus);
238         if (ret)
239                 dev_err(&pdev->dev,
240 @@ -103,10 +118,17 @@ static int snd_rpi_hifiberry_dacplus_rem
241         return snd_soc_unregister_card(&snd_rpi_hifiberry_dacplus);
242  }
243  
244 +static const struct of_device_id snd_rpi_hifiberry_dacplus_of_match[] = {
245 +       { .compatible = "hifiberry,hifiberry-dacplus", },
246 +       {},
247 +};
248 +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_dacplus_of_match);
249 +
250  static struct platform_driver snd_rpi_hifiberry_dacplus_driver = {
251         .driver = {
252                 .name   = "snd-rpi-hifiberry-dacplus",
253                 .owner  = THIS_MODULE,
254 +               .of_match_table = snd_rpi_hifiberry_dacplus_of_match,
255         },
256         .probe          = snd_rpi_hifiberry_dacplus_probe,
257         .remove         = snd_rpi_hifiberry_dacplus_remove,
258 --- a/sound/soc/bcm/hifiberry_digi.c
259 +++ b/sound/soc/bcm/hifiberry_digi.c
260 @@ -173,6 +173,21 @@ static int snd_rpi_hifiberry_digi_probe(
261         int ret = 0;
262  
263         snd_rpi_hifiberry_digi.dev = &pdev->dev;
264 +
265 +       if (pdev->dev.of_node) {
266 +           struct device_node *i2s_node;
267 +           struct snd_soc_dai_link *dai = &snd_rpi_hifiberry_digi_dai[0];
268 +           i2s_node = of_parse_phandle(pdev->dev.of_node,
269 +                                       "i2s-controller", 0);
270 +
271 +           if (i2s_node) {
272 +               dai->cpu_dai_name = NULL;
273 +               dai->cpu_of_node = i2s_node;
274 +               dai->platform_name = NULL;
275 +               dai->platform_of_node = i2s_node;
276 +           }
277 +       }
278 +
279         ret = snd_soc_register_card(&snd_rpi_hifiberry_digi);
280         if (ret)
281                 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
282 @@ -185,10 +200,17 @@ static int snd_rpi_hifiberry_digi_remove
283         return snd_soc_unregister_card(&snd_rpi_hifiberry_digi);
284  }
285  
286 +static const struct of_device_id snd_rpi_hifiberry_digi_of_match[] = {
287 +       { .compatible = "hifiberry,hifiberry-digi", },
288 +       {},
289 +};
290 +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_digi_of_match);
291 +
292  static struct platform_driver snd_rpi_hifiberry_digi_driver = {
293         .driver = {
294                 .name   = "snd-hifiberry-digi",
295                 .owner  = THIS_MODULE,
296 +               .of_match_table = snd_rpi_hifiberry_digi_of_match,
297         },
298         .probe          = snd_rpi_hifiberry_digi_probe,
299         .remove         = snd_rpi_hifiberry_digi_remove,
300 --- a/sound/soc/bcm/iqaudio-dac.c
301 +++ b/sound/soc/bcm/iqaudio-dac.c
302 @@ -82,6 +82,21 @@ static int snd_rpi_iqaudio_dac_probe(str
303         int ret = 0;
304  
305         snd_rpi_iqaudio_dac.dev = &pdev->dev;
306 +
307 +       if (pdev->dev.of_node) {
308 +           struct device_node *i2s_node;
309 +           struct snd_soc_dai_link *dai = &snd_rpi_iqaudio_dac_dai[0];
310 +           i2s_node = of_parse_phandle(pdev->dev.of_node,
311 +                                       "i2s-controller", 0);
312 +
313 +           if (i2s_node) {
314 +               dai->cpu_dai_name = NULL;
315 +               dai->cpu_of_node = i2s_node;
316 +               dai->platform_name = NULL;
317 +               dai->platform_of_node = i2s_node;
318 +           }
319 +       }
320 +
321         ret = snd_soc_register_card(&snd_rpi_iqaudio_dac);
322         if (ret)
323                 dev_err(&pdev->dev,
324 @@ -99,6 +114,7 @@ static const struct of_device_id iqaudio
325         { .compatible = "iqaudio,iqaudio-dac", },
326         {},
327  };
328 +MODULE_DEVICE_TABLE(of, iqaudio_of_match);
329  
330  static struct platform_driver snd_rpi_iqaudio_dac_driver = {
331         .driver = {
332 --- a/sound/soc/codecs/pcm5102a.c
333 +++ b/sound/soc/codecs/pcm5102a.c
334 @@ -47,12 +47,19 @@ static int pcm5102a_remove(struct platfo
335         return 0;
336  }
337  
338 +static const struct of_device_id pcm5102a_of_match[] = {
339 +       { .compatible = "ti,pcm5102a", },
340 +       { }
341 +};
342 +MODULE_DEVICE_TABLE(of, pcm5102a_of_match);
343 +
344  static struct platform_driver pcm5102a_codec_driver = {
345         .probe          = pcm5102a_probe,
346         .remove         = pcm5102a_remove,
347         .driver         = {
348                 .name   = "pcm5102a-codec",
349                 .owner  = THIS_MODULE,
350 +               .of_match_table = pcm5102a_of_match,
351         },
352  };
353