kernel: bump 4.14 to 4.14.113
[oweals/openwrt.git] / target / linux / brcm2708 / patches-4.9 / 950-0075-Add-driver-for-rpi-proto.patch
1 From b351d2ffe294c9d5e8cde9caa3a94017ecec81d9 Mon Sep 17 00:00:00 2001
2 From: Waldemar Brodkorb <wbrodkorb@conet.de>
3 Date: Wed, 25 Mar 2015 09:26:17 +0100
4 Subject: [PATCH] Add driver for rpi-proto
5
6 Forward port of 3.10.x driver from https://github.com/koalo
7 We are using a custom board and would like to use rpi 3.18.x
8 kernel. Patch works fine for our embedded system.
9
10 URL to the audio chip:
11 http://www.mikroe.com/add-on-boards/audio-voice/audio-codec-proto/
12
13 Playback tested with devicetree enabled.
14
15 Signed-off-by: Waldemar Brodkorb <wbrodkorb@conet.de>
16 ---
17  sound/soc/bcm/Kconfig     |   7 +++
18  sound/soc/bcm/Makefile    |   2 +
19  sound/soc/bcm/rpi-proto.c | 154 ++++++++++++++++++++++++++++++++++++++++++++++
20  3 files changed, 163 insertions(+)
21  create mode 100644 sound/soc/bcm/rpi-proto.c
22
23 --- a/sound/soc/bcm/Kconfig
24 +++ b/sound/soc/bcm/Kconfig
25 @@ -52,6 +52,13 @@ config SND_BCM2708_SOC_RPI_DAC
26          help
27           Say Y or M if you want to add support for RPi-DAC.
28  
29 +config SND_BCM2708_SOC_RPI_PROTO
30 +       tristate "Support for Rpi-PROTO"
31 +       depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
32 +       select SND_SOC_WM8731
33 +       help
34 +         Say Y or M if you want to add support for Audio Codec Board PROTO (WM8731).
35 +
36  config SND_BCM2708_SOC_IQAUDIO_DAC
37         tristate "Support for IQaudIO-DAC"
38         depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
39 --- a/sound/soc/bcm/Makefile
40 +++ b/sound/soc/bcm/Makefile
41 @@ -14,6 +14,7 @@ snd-soc-hifiberry-dac-objs := hifiberry_
42  snd-soc-hifiberry-dacplus-objs := hifiberry_dacplus.o
43  snd-soc-hifiberry-digi-objs := hifiberry_digi.o
44  snd-soc-rpi-dac-objs := rpi-dac.o
45 +snd-soc-rpi-proto-objs := rpi-proto.o
46  snd-soc-iqaudio-dac-objs := iqaudio-dac.o
47  
48  obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) += snd-soc-hifiberry-amp.o
49 @@ -21,4 +22,5 @@ obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_D
50  obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
51  obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o
52  obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
53 +obj-$(CONFIG_SND_BCM2708_SOC_RPI_PROTO) += snd-soc-rpi-proto.o
54  obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
55 --- /dev/null
56 +++ b/sound/soc/bcm/rpi-proto.c
57 @@ -0,0 +1,154 @@
58 +/*
59 + * ASoC driver for PROTO AudioCODEC (with a WM8731)
60 + * connected to a Raspberry Pi
61 + *
62 + * Author:      Florian Meier, <koalo@koalo.de>
63 + *           Copyright 2013
64 + *
65 + * This program is free software; you can redistribute it and/or modify
66 + * it under the terms of the GNU General Public License version 2 as
67 + * published by the Free Software Foundation.
68 + */
69 +
70 +#include <linux/module.h>
71 +#include <linux/platform_device.h>
72 +
73 +#include <sound/core.h>
74 +#include <sound/pcm.h>
75 +#include <sound/soc.h>
76 +#include <sound/jack.h>
77 +
78 +#include "../codecs/wm8731.h"
79 +
80 +static const unsigned int wm8731_rates_12288000[] = {
81 +       8000, 32000, 48000, 96000,
82 +};
83 +
84 +static struct snd_pcm_hw_constraint_list wm8731_constraints_12288000 = {
85 +       .list = wm8731_rates_12288000,
86 +       .count = ARRAY_SIZE(wm8731_rates_12288000),
87 +};
88 +
89 +static int snd_rpi_proto_startup(struct snd_pcm_substream *substream)
90 +{
91 +       /* Setup constraints, because there is a 12.288 MHz XTAL on the board */
92 +       snd_pcm_hw_constraint_list(substream->runtime, 0,
93 +                               SNDRV_PCM_HW_PARAM_RATE,
94 +                               &wm8731_constraints_12288000);
95 +       return 0;
96 +}
97 +
98 +static int snd_rpi_proto_hw_params(struct snd_pcm_substream *substream,
99 +                                      struct snd_pcm_hw_params *params)
100 +{
101 +       struct snd_soc_pcm_runtime *rtd = substream->private_data;
102 +       struct snd_soc_codec *codec = rtd->codec;
103 +       struct snd_soc_dai *codec_dai = rtd->codec_dai;
104 +       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
105 +       int sysclk = 12288000; /* This is fixed on this board */
106 +
107 +       /* Set proto bclk */
108 +       int ret = snd_soc_dai_set_bclk_ratio(cpu_dai,32*2);
109 +       if (ret < 0){
110 +               dev_err(codec->dev,
111 +                               "Failed to set BCLK ratio %d\n", ret);
112 +               return ret;
113 +       }
114 +
115 +       /* Set proto sysclk */
116 +       ret = snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK_XTAL,
117 +                       sysclk, SND_SOC_CLOCK_IN);
118 +       if (ret < 0) {
119 +               dev_err(codec->dev,
120 +                               "Failed to set WM8731 SYSCLK: %d\n", ret);
121 +               return ret;
122 +       }
123 +
124 +       return 0;
125 +}
126 +
127 +/* machine stream operations */
128 +static struct snd_soc_ops snd_rpi_proto_ops = {
129 +       .startup = snd_rpi_proto_startup,
130 +       .hw_params = snd_rpi_proto_hw_params,
131 +};
132 +
133 +static struct snd_soc_dai_link snd_rpi_proto_dai[] = {
134 +{
135 +       .name           = "WM8731",
136 +       .stream_name    = "WM8731 HiFi",
137 +       .cpu_dai_name   = "bcm2708-i2s.0",
138 +       .codec_dai_name = "wm8731-hifi",
139 +       .platform_name  = "bcm2708-i2s.0",
140 +       .codec_name     = "wm8731.1-001a",
141 +       .dai_fmt        = SND_SOC_DAIFMT_I2S
142 +                               | SND_SOC_DAIFMT_NB_NF
143 +                               | SND_SOC_DAIFMT_CBM_CFM,
144 +       .ops            = &snd_rpi_proto_ops,
145 +},
146 +};
147 +
148 +/* audio machine driver */
149 +static struct snd_soc_card snd_rpi_proto = {
150 +       .name           = "snd_rpi_proto",
151 +       .owner          = THIS_MODULE,
152 +       .dai_link       = snd_rpi_proto_dai,
153 +       .num_links      = ARRAY_SIZE(snd_rpi_proto_dai),
154 +};
155 +
156 +static int snd_rpi_proto_probe(struct platform_device *pdev)
157 +{
158 +       int ret = 0;
159 +
160 +       snd_rpi_proto.dev = &pdev->dev;
161 +
162 +       if (pdev->dev.of_node) {
163 +               struct device_node *i2s_node;
164 +               struct snd_soc_dai_link *dai = &snd_rpi_proto_dai[0];
165 +               i2s_node = of_parse_phandle(pdev->dev.of_node,
166 +                                           "i2s-controller", 0);
167 +
168 +               if (i2s_node) {
169 +                       dai->cpu_dai_name = NULL;
170 +                       dai->cpu_of_node = i2s_node;
171 +                       dai->platform_name = NULL;
172 +                       dai->platform_of_node = i2s_node;
173 +               }
174 +       }
175 +
176 +       ret = snd_soc_register_card(&snd_rpi_proto);
177 +       if (ret) {
178 +               dev_err(&pdev->dev,
179 +                               "snd_soc_register_card() failed: %d\n", ret);
180 +       }
181 +
182 +       return ret;
183 +}
184 +
185 +
186 +static int snd_rpi_proto_remove(struct platform_device *pdev)
187 +{
188 +       return snd_soc_unregister_card(&snd_rpi_proto);
189 +}
190 +
191 +static const struct of_device_id snd_rpi_proto_of_match[] = {
192 +       { .compatible = "rpi,rpi-proto", },
193 +       {},
194 +};
195 +MODULE_DEVICE_TABLE(of, snd_rpi_proto_of_match);
196 +
197 +static struct platform_driver snd_rpi_proto_driver = {
198 +       .driver = {
199 +               .name   = "snd-rpi-proto",
200 +               .owner  = THIS_MODULE,
201 +               .of_match_table = snd_rpi_proto_of_match,
202 +       },
203 +       .probe    = snd_rpi_proto_probe,
204 +       .remove  = snd_rpi_proto_remove,
205 +};
206 +
207 +module_platform_driver(snd_rpi_proto_driver);
208 +
209 +MODULE_AUTHOR("Florian Meier");
210 +MODULE_DESCRIPTION("ASoC Driver for Raspberry Pi connected to PROTO board (WM8731)");
211 +MODULE_LICENSE("GPL");