Skip to content

Commit 9cd196c

Browse files
committed
ARM: adau1977-adc: Add basic machine driver for adau1977 codec driver.
This commit adds basic support for the codec usage including: Device tree overlay, binding I2S bus and setting I2S mode, clock source and frequency setting according to spec. Signed-off-by: Andrey Grodzovsky <[email protected]>
1 parent f6f3129 commit 9cd196c

File tree

8 files changed

+199
-0
lines changed

8 files changed

+199
-0
lines changed

arch/arm/boot/dts/overlays/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ ifeq ($(CONFIG_ARCH_BCM2835),y)
1212
RPI_DT_OVERLAYS=y
1313
endif
1414

15+
dtbo-$(RPI_DT_OVERLAYS) += adau1977-adc.dtbo
1516
dtbo-$(RPI_DT_OVERLAYS) += ads7846.dtbo
1617
dtbo-$(RPI_DT_OVERLAYS) += akkordion-iqdacplus.dtbo
1718
dtbo-$(RPI_DT_OVERLAYS) += at86rf233.dtbo

arch/arm/boot/dts/overlays/README

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ Params:
161161
and the other i2c baudrate parameters.
162162

163163

164+
Name: adau1977-adc
165+
Info: Overlay for activation of ADAU1977 ADC codec over I2C for control
166+
and I2S for data.
167+
Load: dtoverlay=adau1977-adc
168+
Params: <None>
169+
170+
164171
Name: ads7846
165172
Info: ADS7846 Touch controller
166173
Load: dtoverlay=ads7846,<param>=<val>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Definitions for ADAU1977 ADC
2+
/dts-v1/;
3+
/plugin/;
4+
5+
/ {
6+
compatible = "brcm,bcm2708";
7+
8+
fragment@0 {
9+
target = <&soc>;
10+
11+
__overlay__ {
12+
codec_supply: fixedregulator@0 {
13+
compatible = "regulator-fixed";
14+
regulator-name = "AVDD";
15+
regulator-min-microvolt = <3300000>;
16+
regulator-max-microvolt = <3300000>;
17+
};
18+
};
19+
};
20+
21+
fragment@1 {
22+
target = <&i2c>;
23+
24+
__overlay__ {
25+
#address-cells = <1>;
26+
#size-cells = <0>;
27+
status = "okay";
28+
29+
adau1977: codec@11 {
30+
compatible = "adi,adau1977";
31+
reg = <0x11>;
32+
reset-gpios = <&gpio 5 0>;
33+
AVDD-supply = <&codec_supply>;
34+
};
35+
};
36+
};
37+
38+
fragment@2 {
39+
target = <&i2s>;
40+
__overlay__ {
41+
status = "okay";
42+
};
43+
};
44+
45+
fragment@3 {
46+
target = <&sound>;
47+
__overlay__ {
48+
compatible = "adi,adau1977-adc";
49+
i2s-controller = <&i2s>;
50+
status = "okay";
51+
};
52+
};
53+
};

arch/arm/configs/bcm2709_defconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,7 @@ CONFIG_SND_BCM2708_SOC_BOOMBERRY_DAC=m
861861
CONFIG_SND_BCM2708_SOC_BOOMBERRY_DIGI=m
862862
CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
863863
CONFIG_SND_BCM2708_SOC_RASPIDAC3=m
864+
CONFIG_SND_BCM2708_SOC_ADAU1977_ADC=m
864865
CONFIG_SND_SOC_ADAU1701=m
865866
CONFIG_SND_SOC_WM8804_I2C=m
866867
CONFIG_SND_SIMPLE_CARD=m

arch/arm/configs/bcmrpi_defconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,7 @@ CONFIG_SND_BCM2708_SOC_BOOMBERRY_DAC=m
853853
CONFIG_SND_BCM2708_SOC_BOOMBERRY_DIGI=m
854854
CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
855855
CONFIG_SND_BCM2708_SOC_RASPIDAC3=m
856+
CONFIG_SND_BCM2708_SOC_ADAU1977_ADC=m
856857
CONFIG_SND_SOC_ADAU1701=m
857858
CONFIG_SND_SOC_WM8804_I2C=m
858859
CONFIG_SND_SIMPLE_CARD=m

sound/soc/bcm/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,10 @@ config SND_BCM2708_SOC_RASPIDAC3
7878
select SND_SOC_TPA6130A2
7979
help
8080
Say Y or M if you want to add support for RaspiDAC Rev.3x.
81+
82+
config SND_BCM2708_SOC_ADAU1977_ADC
83+
tristate "Support for ADAU1977 ADC"
84+
depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
85+
select SND_SOC_ADAU1977_I2C
86+
help
87+
Say Y or M if you want to add support for ADAU1977 ADC.

sound/soc/bcm/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ snd-soc-bcm2835-i2s-objs := bcm2835-i2s.o
44
obj-$(CONFIG_SND_BCM2835_SOC_I2S) += snd-soc-bcm2835-i2s.o
55

66
# BCM2708 Machine Support
7+
snd-soc-adau1977-adc-objs := adau1977-adc.o
78
snd-soc-hifiberry-dac-objs := hifiberry_dac.o
89
snd-soc-hifiberry-dacplus-objs := hifiberry_dacplus.o
910
snd-soc-hifiberry-digi-objs := hifiberry_digi.o
@@ -15,6 +16,7 @@ snd-soc-rpi-proto-objs := rpi-proto.o
1516
snd-soc-iqaudio-dac-objs := iqaudio-dac.o
1617
snd-soc-raspidac3-objs := raspidac3.o
1718

19+
obj-$(CONFIG_SND_BCM2708_SOC_ADAU1977_ADC) += snd-soc-adau1977-adc.o
1820
obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
1921
obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
2022
obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o

sound/soc/bcm/adau1977-adc.c

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*
2+
* ASoC Driver for ADAU1977 ADC
3+
*
4+
* Author: Andrey Grodzovsky <[email protected]>
5+
* Copyright 2016
6+
*
7+
* This file is based on hifibery_dac driver by Florian Meier.
8+
*
9+
* This program is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU General Public License
11+
* version 2 as published by the Free Software Foundation.
12+
*
13+
* This program is distributed in the hope that it will be useful, but
14+
* WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
* General Public License for more details.
17+
*/
18+
19+
#include <linux/module.h>
20+
#include <linux/platform_device.h>
21+
22+
#include <sound/core.h>
23+
#include <sound/pcm.h>
24+
#include <sound/pcm_params.h>
25+
#include <sound/soc.h>
26+
#include <sound/jack.h>
27+
28+
enum adau1977_clk_id {
29+
ADAU1977_SYSCLK,
30+
};
31+
32+
enum adau1977_sysclk_src {
33+
ADAU1977_SYSCLK_SRC_MCLK,
34+
ADAU1977_SYSCLK_SRC_LRCLK,
35+
};
36+
37+
static int eval_adau1977_init(struct snd_soc_pcm_runtime *rtd)
38+
{
39+
int ret;
40+
struct snd_soc_dai *codec_dai = rtd->codec_dai;
41+
42+
ret = snd_soc_dai_set_tdm_slot(codec_dai, 0, 0, 0, 0);
43+
if (ret < 0)
44+
return ret;
45+
46+
return snd_soc_codec_set_sysclk(rtd->codec, ADAU1977_SYSCLK,
47+
ADAU1977_SYSCLK_SRC_MCLK, 11289600, SND_SOC_CLOCK_IN);
48+
}
49+
50+
static struct snd_soc_dai_link snd_rpi_adau1977_dai[] = {
51+
{
52+
.name = "adau1977",
53+
.stream_name = "ADAU1977",
54+
.cpu_dai_name = "bcm2708-i2s.0",
55+
.codec_dai_name = "adau1977-hifi",
56+
.platform_name = "bcm2708-i2s.0",
57+
.codec_name = "adau1977.1-0011",
58+
.init = eval_adau1977_init,
59+
.dai_fmt = SND_SOC_DAIFMT_I2S |
60+
SND_SOC_DAIFMT_NB_NF |
61+
SND_SOC_DAIFMT_CBM_CFM,
62+
},
63+
};
64+
65+
/* audio machine driver */
66+
static struct snd_soc_card snd_adau1977_adc = {
67+
.name = "snd_rpi_adau1977_adc",
68+
.owner = THIS_MODULE,
69+
.dai_link = snd_rpi_adau1977_dai,
70+
.num_links = ARRAY_SIZE(snd_rpi_adau1977_dai),
71+
};
72+
73+
static int snd_adau1977_adc_probe(struct platform_device *pdev)
74+
{
75+
int ret = 0;
76+
77+
snd_adau1977_adc.dev = &pdev->dev;
78+
dev_info(&pdev->dev,"%s:%d\n",__func__,__LINE__);
79+
if (pdev->dev.of_node) {
80+
struct device_node *i2s_node;
81+
struct snd_soc_dai_link *dai = &snd_rpi_adau1977_dai[0];
82+
i2s_node = of_parse_phandle(pdev->dev.of_node,
83+
"i2s-controller", 0);
84+
85+
if (i2s_node) {
86+
dai->cpu_dai_name = NULL;
87+
dai->cpu_of_node = i2s_node;
88+
dai->platform_name = NULL;
89+
dai->platform_of_node = i2s_node;
90+
}
91+
}
92+
93+
ret = snd_soc_register_card(&snd_adau1977_adc);
94+
dev_info(&pdev->dev,"%s:%d\n",__func__,__LINE__);
95+
if (ret)
96+
dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
97+
98+
return ret;
99+
}
100+
101+
static int snd_adau1977_adc_remove(struct platform_device *pdev)
102+
{
103+
return snd_soc_unregister_card(&snd_adau1977_adc);
104+
}
105+
106+
static const struct of_device_id snd_adau1977_adc_of_match[] = {
107+
{ .compatible = "adi,adau1977-adc", },
108+
{},
109+
};
110+
111+
MODULE_DEVICE_TABLE(of, snd_adau1977_adc_of_match);
112+
113+
static struct platform_driver snd_adau1977_adc_driver = {
114+
.driver = {
115+
.name = "snd-adau1977-adc",
116+
.owner = THIS_MODULE,
117+
.of_match_table = snd_adau1977_adc_of_match,
118+
},
119+
.probe = snd_adau1977_adc_probe,
120+
.remove = snd_adau1977_adc_remove,
121+
};
122+
123+
module_platform_driver(snd_adau1977_adc_driver);
124+
125+
MODULE_AUTHOR("Andrey Grodzovsky <[email protected]>");
126+
MODULE_DESCRIPTION("ASoC Driver for ADAU1977 ADC");
127+
MODULE_LICENSE("GPL v2");

0 commit comments

Comments
 (0)