1b87b13efd9636eecf3ec8d2843f3e0d704dfcd1
[openwrt/staging/stintel.git] /
1 From 9bbd8a3c8378eac9e605e0f37f4005583e122527 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] ARM: adau1977-adc: Add basic machine driver for adau1977
5 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 sound/soc/bcm/Kconfig | 7 +++
14 sound/soc/bcm/Makefile | 2 +
15 sound/soc/bcm/adau1977-adc.c | 125 +++++++++++++++++++++++++++++++++++++++++++
16 3 files changed, 134 insertions(+)
17 create mode 100644 sound/soc/bcm/adau1977-adc.c
18
19 --- a/sound/soc/bcm/Kconfig
20 +++ b/sound/soc/bcm/Kconfig
21 @@ -87,3 +87,10 @@ config SND_BCM2708_SOC_RASPIDAC3
22 select SND_SOC_TPA6130A2
23 help
24 Say Y or M if you want to add support for RaspiDAC Rev.3x.
25 +
26 +config SND_BCM2708_SOC_ADAU1977_ADC
27 + tristate "Support for ADAU1977 ADC"
28 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
29 + select SND_SOC_ADAU1977_I2C
30 + help
31 + Say Y or M if you want to add support for ADAU1977 ADC.
32 --- a/sound/soc/bcm/Makefile
33 +++ b/sound/soc/bcm/Makefile
34 @@ -9,6 +9,7 @@ snd-soc-cygnus-objs := cygnus-pcm.o cygn
35 obj-$(CONFIG_SND_SOC_CYGNUS) += snd-soc-cygnus.o
36
37 # BCM2708 Machine Support
38 +snd-soc-adau1977-adc-objs := adau1977-adc.o
39 snd-soc-hifiberry-amp-objs := hifiberry_amp.o
40 snd-soc-hifiberry-dac-objs := hifiberry_dac.o
41 snd-soc-hifiberry-dacplus-objs := hifiberry_dacplus.o
42 @@ -20,6 +21,7 @@ snd-soc-rpi-proto-objs := rpi-proto.o
43 snd-soc-iqaudio-dac-objs := iqaudio-dac.o
44 snd-soc-raspidac3-objs := raspidac3.o
45
46 +obj-$(CONFIG_SND_BCM2708_SOC_ADAU1977_ADC) += snd-soc-adau1977-adc.o
47 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) += snd-soc-hifiberry-amp.o
48 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
49 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
50 --- /dev/null
51 +++ b/sound/soc/bcm/adau1977-adc.c
52 @@ -0,0 +1,125 @@
53 +/*
54 + * ASoC Driver for ADAU1977 ADC
55 + *
56 + * Author: Andrey Grodzovsky <andrey2805@gmail.com>
57 + * Copyright 2016
58 + *
59 + * This file is based on hifibery_dac driver by Florian Meier.
60 + *
61 + * This program is free software; you can redistribute it and/or
62 + * modify it under the terms of the GNU General Public License
63 + * version 2 as published by the Free Software Foundation.
64 + *
65 + * This program is distributed in the hope that it will be useful, but
66 + * WITHOUT ANY WARRANTY; without even the implied warranty of
67 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
68 + * General Public License for more details.
69 + */
70 +
71 +#include <linux/module.h>
72 +#include <linux/platform_device.h>
73 +
74 +#include <sound/core.h>
75 +#include <sound/pcm.h>
76 +#include <sound/pcm_params.h>
77 +#include <sound/soc.h>
78 +#include <sound/jack.h>
79 +
80 +enum adau1977_clk_id {
81 + ADAU1977_SYSCLK,
82 +};
83 +
84 +enum adau1977_sysclk_src {
85 + ADAU1977_SYSCLK_SRC_MCLK,
86 + ADAU1977_SYSCLK_SRC_LRCLK,
87 +};
88 +
89 +static int eval_adau1977_init(struct snd_soc_pcm_runtime *rtd)
90 +{
91 + int ret;
92 + struct snd_soc_dai *codec_dai = rtd->codec_dai;
93 +
94 + ret = snd_soc_dai_set_tdm_slot(codec_dai, 0, 0, 0, 0);
95 + if (ret < 0)
96 + return ret;
97 +
98 + return snd_soc_codec_set_sysclk(rtd->codec, ADAU1977_SYSCLK,
99 + ADAU1977_SYSCLK_SRC_MCLK, 11289600, SND_SOC_CLOCK_IN);
100 +}
101 +
102 +static struct snd_soc_dai_link snd_rpi_adau1977_dai[] = {
103 + {
104 + .name = "adau1977",
105 + .stream_name = "ADAU1977",
106 + .cpu_dai_name = "bcm2708-i2s.0",
107 + .codec_dai_name = "adau1977-hifi",
108 + .platform_name = "bcm2708-i2s.0",
109 + .codec_name = "adau1977.1-0011",
110 + .init = eval_adau1977_init,
111 + .dai_fmt = SND_SOC_DAIFMT_I2S |
112 + SND_SOC_DAIFMT_NB_NF |
113 + SND_SOC_DAIFMT_CBM_CFM,
114 + },
115 +};
116 +
117 +/* audio machine driver */
118 +static struct snd_soc_card snd_adau1977_adc = {
119 + .name = "snd_rpi_adau1977_adc",
120 + .owner = THIS_MODULE,
121 + .dai_link = snd_rpi_adau1977_dai,
122 + .num_links = ARRAY_SIZE(snd_rpi_adau1977_dai),
123 +};
124 +
125 +static int snd_adau1977_adc_probe(struct platform_device *pdev)
126 +{
127 + int ret = 0;
128 +
129 + snd_adau1977_adc.dev = &pdev->dev;
130 + if (pdev->dev.of_node) {
131 + struct device_node *i2s_node;
132 + struct snd_soc_dai_link *dai = &snd_rpi_adau1977_dai[0];
133 + i2s_node = of_parse_phandle(pdev->dev.of_node,
134 + "i2s-controller", 0);
135 +
136 + if (i2s_node) {
137 + dai->cpu_dai_name = NULL;
138 + dai->cpu_of_node = i2s_node;
139 + dai->platform_name = NULL;
140 + dai->platform_of_node = i2s_node;
141 + }
142 + }
143 +
144 + ret = snd_soc_register_card(&snd_adau1977_adc);
145 + if (ret)
146 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
147 +
148 + return ret;
149 +}
150 +
151 +static int snd_adau1977_adc_remove(struct platform_device *pdev)
152 +{
153 + return snd_soc_unregister_card(&snd_adau1977_adc);
154 +}
155 +
156 +static const struct of_device_id snd_adau1977_adc_of_match[] = {
157 + { .compatible = "adi,adau1977-adc", },
158 + {},
159 +};
160 +
161 +MODULE_DEVICE_TABLE(of, snd_adau1977_adc_of_match);
162 +
163 +static struct platform_driver snd_adau1977_adc_driver = {
164 + .driver = {
165 + .name = "snd-adau1977-adc",
166 + .owner = THIS_MODULE,
167 + .of_match_table = snd_adau1977_adc_of_match,
168 + },
169 + .probe = snd_adau1977_adc_probe,
170 + .remove = snd_adau1977_adc_remove,
171 +};
172 +
173 +module_platform_driver(snd_adau1977_adc_driver);
174 +
175 +MODULE_AUTHOR("Andrey Grodzovsky <andrey2805@gmail.com>");
176 +MODULE_DESCRIPTION("ASoC Driver for ADAU1977 ADC");
177 +MODULE_LICENSE("GPL v2");