scripts/getver.sh: avoid use of git rev-list --count
[openwrt/staging/dedeckeh.git] / target / linux / brcm2708 / patches-4.4 / 0326-ARM-adau1977-adc-Add-basic-machine-driver-for-adau19.patch
1 From 347d4cf757e6f093860048fe69737c29f5adcd0f Mon Sep 17 00:00:00 2001
2 From: Andrey Grodzovsky <andrey2805@gmail.com>
3 Date: Tue, 3 May 2016 22:10:59 -0400
4 Subject: [PATCH 326/381] ARM: adau1977-adc: Add basic machine driver for
5 adau1977 codec driver.
6
7 This commit adds basic support for the codec usage including: Device tree overlay,
8 binding I2S bus and setting I2S mode, clock source and frequency setting according
9 to spec.
10
11 Signed-off-by: Andrey Grodzovsky <andrey2805@gmail.com>
12 ---
13 arch/arm/boot/dts/overlays/Makefile | 1 +
14 arch/arm/boot/dts/overlays/README | 7 ++
15 .../arm/boot/dts/overlays/adau1977-adc-overlay.dts | 53 +++++++++
16 arch/arm/configs/bcm2709_defconfig | 1 +
17 arch/arm/configs/bcmrpi_defconfig | 1 +
18 sound/soc/bcm/Kconfig | 7 ++
19 sound/soc/bcm/Makefile | 2 +
20 sound/soc/bcm/adau1977-adc.c | 125 +++++++++++++++++++++
21 8 files changed, 197 insertions(+)
22 create mode 100644 arch/arm/boot/dts/overlays/adau1977-adc-overlay.dts
23 create mode 100644 sound/soc/bcm/adau1977-adc.c
24
25 --- a/arch/arm/boot/dts/overlays/Makefile
26 +++ b/arch/arm/boot/dts/overlays/Makefile
27 @@ -12,6 +12,7 @@ ifeq ($(CONFIG_ARCH_BCM2835),y)
28 RPI_DT_OVERLAYS=y
29 endif
30
31 +dtbo-$(RPI_DT_OVERLAYS) += adau1977-adc.dtbo
32 dtbo-$(RPI_DT_OVERLAYS) += ads7846.dtbo
33 dtbo-$(RPI_DT_OVERLAYS) += akkordion-iqdacplus.dtbo
34 dtbo-$(RPI_DT_OVERLAYS) += at86rf233.dtbo
35 --- a/arch/arm/boot/dts/overlays/README
36 +++ b/arch/arm/boot/dts/overlays/README
37 @@ -161,6 +161,13 @@ Params:
38 and the other i2c baudrate parameters.
39
40
41 +Name: adau1977-adc
42 +Info: Overlay for activation of ADAU1977 ADC codec over I2C for control
43 + and I2S for data.
44 +Load: dtoverlay=adau1977-adc
45 +Params: <None>
46 +
47 +
48 Name: ads7846
49 Info: ADS7846 Touch controller
50 Load: dtoverlay=ads7846,<param>=<val>
51 --- /dev/null
52 +++ b/arch/arm/boot/dts/overlays/adau1977-adc-overlay.dts
53 @@ -0,0 +1,53 @@
54 +// Definitions for ADAU1977 ADC
55 +/dts-v1/;
56 +/plugin/;
57 +
58 +/ {
59 + compatible = "brcm,bcm2708";
60 +
61 + fragment@0 {
62 + target = <&soc>;
63 +
64 + __overlay__ {
65 + codec_supply: fixedregulator@0 {
66 + compatible = "regulator-fixed";
67 + regulator-name = "AVDD";
68 + regulator-min-microvolt = <3300000>;
69 + regulator-max-microvolt = <3300000>;
70 + };
71 + };
72 + };
73 +
74 + fragment@1 {
75 + target = <&i2c>;
76 +
77 + __overlay__ {
78 + #address-cells = <1>;
79 + #size-cells = <0>;
80 + status = "okay";
81 +
82 + adau1977: codec@11 {
83 + compatible = "adi,adau1977";
84 + reg = <0x11>;
85 + reset-gpios = <&gpio 5 0>;
86 + AVDD-supply = <&codec_supply>;
87 + };
88 + };
89 + };
90 +
91 + fragment@2 {
92 + target = <&i2s>;
93 + __overlay__ {
94 + status = "okay";
95 + };
96 + };
97 +
98 + fragment@3 {
99 + target = <&sound>;
100 + __overlay__ {
101 + compatible = "adi,adau1977-adc";
102 + i2s-controller = <&i2s>;
103 + status = "okay";
104 + };
105 + };
106 +};
107 --- a/arch/arm/configs/bcm2709_defconfig
108 +++ b/arch/arm/configs/bcm2709_defconfig
109 @@ -861,6 +861,7 @@ CONFIG_SND_BCM2708_SOC_BOOMBERRY_DAC=m
110 CONFIG_SND_BCM2708_SOC_BOOMBERRY_DIGI=m
111 CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
112 CONFIG_SND_BCM2708_SOC_RASPIDAC3=m
113 +CONFIG_SND_BCM2708_SOC_ADAU1977_ADC=m
114 CONFIG_SND_SOC_ADAU1701=m
115 CONFIG_SND_SOC_WM8804_I2C=m
116 CONFIG_SND_SIMPLE_CARD=m
117 --- a/arch/arm/configs/bcmrpi_defconfig
118 +++ b/arch/arm/configs/bcmrpi_defconfig
119 @@ -853,6 +853,7 @@ CONFIG_SND_BCM2708_SOC_BOOMBERRY_DAC=m
120 CONFIG_SND_BCM2708_SOC_BOOMBERRY_DIGI=m
121 CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
122 CONFIG_SND_BCM2708_SOC_RASPIDAC3=m
123 +CONFIG_SND_BCM2708_SOC_ADAU1977_ADC=m
124 CONFIG_SND_SOC_ADAU1701=m
125 CONFIG_SND_SOC_WM8804_I2C=m
126 CONFIG_SND_SIMPLE_CARD=m
127 --- a/sound/soc/bcm/Kconfig
128 +++ b/sound/soc/bcm/Kconfig
129 @@ -78,3 +78,10 @@ config SND_BCM2708_SOC_RASPIDAC3
130 select SND_SOC_TPA6130A2
131 help
132 Say Y or M if you want to add support for RaspiDAC Rev.3x.
133 +
134 +config SND_BCM2708_SOC_ADAU1977_ADC
135 + tristate "Support for ADAU1977 ADC"
136 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
137 + select SND_SOC_ADAU1977_I2C
138 + help
139 + Say Y or M if you want to add support for ADAU1977 ADC.
140 --- a/sound/soc/bcm/Makefile
141 +++ b/sound/soc/bcm/Makefile
142 @@ -4,6 +4,7 @@ snd-soc-bcm2835-i2s-objs := bcm2835-i2s.
143 obj-$(CONFIG_SND_BCM2835_SOC_I2S) += snd-soc-bcm2835-i2s.o
144
145 # BCM2708 Machine Support
146 +snd-soc-adau1977-adc-objs := adau1977-adc.o
147 snd-soc-hifiberry-dac-objs := hifiberry_dac.o
148 snd-soc-hifiberry-dacplus-objs := hifiberry_dacplus.o
149 snd-soc-hifiberry-digi-objs := hifiberry_digi.o
150 @@ -15,6 +16,7 @@ snd-soc-rpi-proto-objs := rpi-proto.o
151 snd-soc-iqaudio-dac-objs := iqaudio-dac.o
152 snd-soc-raspidac3-objs := raspidac3.o
153
154 +obj-$(CONFIG_SND_BCM2708_SOC_ADAU1977_ADC) += snd-soc-adau1977-adc.o
155 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
156 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
157 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o
158 --- /dev/null
159 +++ b/sound/soc/bcm/adau1977-adc.c
160 @@ -0,0 +1,125 @@
161 +/*
162 + * ASoC Driver for ADAU1977 ADC
163 + *
164 + * Author: Andrey Grodzovsky <andrey2805@gmail.com>
165 + * Copyright 2016
166 + *
167 + * This file is based on hifibery_dac driver by Florian Meier.
168 + *
169 + * This program is free software; you can redistribute it and/or
170 + * modify it under the terms of the GNU General Public License
171 + * version 2 as published by the Free Software Foundation.
172 + *
173 + * This program is distributed in the hope that it will be useful, but
174 + * WITHOUT ANY WARRANTY; without even the implied warranty of
175 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
176 + * General Public License for more details.
177 + */
178 +
179 +#include <linux/module.h>
180 +#include <linux/platform_device.h>
181 +
182 +#include <sound/core.h>
183 +#include <sound/pcm.h>
184 +#include <sound/pcm_params.h>
185 +#include <sound/soc.h>
186 +#include <sound/jack.h>
187 +
188 +enum adau1977_clk_id {
189 + ADAU1977_SYSCLK,
190 +};
191 +
192 +enum adau1977_sysclk_src {
193 + ADAU1977_SYSCLK_SRC_MCLK,
194 + ADAU1977_SYSCLK_SRC_LRCLK,
195 +};
196 +
197 +static int eval_adau1977_init(struct snd_soc_pcm_runtime *rtd)
198 +{
199 + int ret;
200 + struct snd_soc_dai *codec_dai = rtd->codec_dai;
201 +
202 + ret = snd_soc_dai_set_tdm_slot(codec_dai, 0, 0, 0, 0);
203 + if (ret < 0)
204 + return ret;
205 +
206 + return snd_soc_codec_set_sysclk(rtd->codec, ADAU1977_SYSCLK,
207 + ADAU1977_SYSCLK_SRC_MCLK, 11289600, SND_SOC_CLOCK_IN);
208 +}
209 +
210 +static struct snd_soc_dai_link snd_rpi_adau1977_dai[] = {
211 + {
212 + .name = "adau1977",
213 + .stream_name = "ADAU1977",
214 + .cpu_dai_name = "bcm2708-i2s.0",
215 + .codec_dai_name = "adau1977-hifi",
216 + .platform_name = "bcm2708-i2s.0",
217 + .codec_name = "adau1977.1-0011",
218 + .init = eval_adau1977_init,
219 + .dai_fmt = SND_SOC_DAIFMT_I2S |
220 + SND_SOC_DAIFMT_NB_NF |
221 + SND_SOC_DAIFMT_CBM_CFM,
222 + },
223 +};
224 +
225 +/* audio machine driver */
226 +static struct snd_soc_card snd_adau1977_adc = {
227 + .name = "snd_rpi_adau1977_adc",
228 + .owner = THIS_MODULE,
229 + .dai_link = snd_rpi_adau1977_dai,
230 + .num_links = ARRAY_SIZE(snd_rpi_adau1977_dai),
231 +};
232 +
233 +static int snd_adau1977_adc_probe(struct platform_device *pdev)
234 +{
235 + int ret = 0;
236 +
237 + snd_adau1977_adc.dev = &pdev->dev;
238 + if (pdev->dev.of_node) {
239 + struct device_node *i2s_node;
240 + struct snd_soc_dai_link *dai = &snd_rpi_adau1977_dai[0];
241 + i2s_node = of_parse_phandle(pdev->dev.of_node,
242 + "i2s-controller", 0);
243 +
244 + if (i2s_node) {
245 + dai->cpu_dai_name = NULL;
246 + dai->cpu_of_node = i2s_node;
247 + dai->platform_name = NULL;
248 + dai->platform_of_node = i2s_node;
249 + }
250 + }
251 +
252 + ret = snd_soc_register_card(&snd_adau1977_adc);
253 + if (ret)
254 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
255 +
256 + return ret;
257 +}
258 +
259 +static int snd_adau1977_adc_remove(struct platform_device *pdev)
260 +{
261 + return snd_soc_unregister_card(&snd_adau1977_adc);
262 +}
263 +
264 +static const struct of_device_id snd_adau1977_adc_of_match[] = {
265 + { .compatible = "adi,adau1977-adc", },
266 + {},
267 +};
268 +
269 +MODULE_DEVICE_TABLE(of, snd_adau1977_adc_of_match);
270 +
271 +static struct platform_driver snd_adau1977_adc_driver = {
272 + .driver = {
273 + .name = "snd-adau1977-adc",
274 + .owner = THIS_MODULE,
275 + .of_match_table = snd_adau1977_adc_of_match,
276 + },
277 + .probe = snd_adau1977_adc_probe,
278 + .remove = snd_adau1977_adc_remove,
279 +};
280 +
281 +module_platform_driver(snd_adau1977_adc_driver);
282 +
283 +MODULE_AUTHOR("Andrey Grodzovsky <andrey2805@gmail.com>");
284 +MODULE_DESCRIPTION("ASoC Driver for ADAU1977 ADC");
285 +MODULE_LICENSE("GPL v2");