diff options
author | Nicolas Ferre <nicolas.ferre@atmel.com> | 2013-07-30 06:32:03 -0400 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2013-08-06 13:11:09 -0400 |
commit | fdbcb3cba54b29a37dfe42acdc0e72c543e0807d (patch) | |
tree | 05e27faf0dcea5c452366a9f33a09a4943ac75a1 /sound/soc/atmel | |
parent | 52f19b14ec18f3166e43cda6a16bb39ffb376053 (diff) |
ASoC: atmel: machine driver for at91sam9x5-wm8731 boards
Description of the Asoc machine driver for an at91sam9x5 based board
with a wm8731 audio DAC. Wm8731 is clocked by a crystal and used as a
master on the SSC/I2S interface. Its connections are a headphone jack
and an Line input jack.
[Richard: this is based on an old patch from Nicolas that I forward
ported and reworked to use only device tree]
Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
Diffstat (limited to 'sound/soc/atmel')
-rw-r--r-- | sound/soc/atmel/Kconfig | 10 | ||||
-rw-r--r-- | sound/soc/atmel/Makefile | 2 | ||||
-rw-r--r-- | sound/soc/atmel/sam9x5_wm8731.c | 208 |
3 files changed, 220 insertions, 0 deletions
diff --git a/sound/soc/atmel/Kconfig b/sound/soc/atmel/Kconfig index 986323b4caad..e48d38a1b95c 100644 --- a/sound/soc/atmel/Kconfig +++ b/sound/soc/atmel/Kconfig | |||
@@ -43,6 +43,16 @@ config SND_ATMEL_SOC_WM8904 | |||
43 | Say Y if you want to add support for Atmel ASoC driver for boards using | 43 | Say Y if you want to add support for Atmel ASoC driver for boards using |
44 | WM8904 codec. | 44 | WM8904 codec. |
45 | 45 | ||
46 | config SND_AT91_SOC_SAM9X5_WM8731 | ||
47 | tristate "SoC Audio support for WM8731-based at91sam9x5 board" | ||
48 | depends on ATMEL_SSC && SND_ATMEL_SOC && SOC_AT91SAM9X5 | ||
49 | select SND_ATMEL_SOC_SSC | ||
50 | select SND_ATMEL_SOC_DMA | ||
51 | select SND_SOC_WM8731 | ||
52 | help | ||
53 | Say Y if you want to add support for audio SoC on an | ||
54 | at91sam9x5 based board that is using WM8731 codec. | ||
55 | |||
46 | config SND_AT91_SOC_AFEB9260 | 56 | config SND_AT91_SOC_AFEB9260 |
47 | tristate "SoC Audio support for AFEB9260 board" | 57 | tristate "SoC Audio support for AFEB9260 board" |
48 | depends on ARCH_AT91 && ATMEL_SSC && ARCH_AT91 && MACH_AFEB9260 && SND_ATMEL_SOC | 58 | depends on ARCH_AT91 && ATMEL_SSC && ARCH_AT91 && MACH_AFEB9260 && SND_ATMEL_SOC |
diff --git a/sound/soc/atmel/Makefile b/sound/soc/atmel/Makefile index 922d4da57109..5baabc8bde3a 100644 --- a/sound/soc/atmel/Makefile +++ b/sound/soc/atmel/Makefile | |||
@@ -12,7 +12,9 @@ obj-$(CONFIG_SND_ATMEL_SOC_SSC) += snd-soc-atmel_ssc_dai.o | |||
12 | # AT91 Machine Support | 12 | # AT91 Machine Support |
13 | snd-soc-sam9g20-wm8731-objs := sam9g20_wm8731.o | 13 | snd-soc-sam9g20-wm8731-objs := sam9g20_wm8731.o |
14 | snd-atmel-soc-wm8904-objs := atmel_wm8904.o | 14 | snd-atmel-soc-wm8904-objs := atmel_wm8904.o |
15 | snd-soc-sam9x5-wm8731-objs := sam9x5_wm8731.o | ||
15 | 16 | ||
16 | obj-$(CONFIG_SND_AT91_SOC_SAM9G20_WM8731) += snd-soc-sam9g20-wm8731.o | 17 | obj-$(CONFIG_SND_AT91_SOC_SAM9G20_WM8731) += snd-soc-sam9g20-wm8731.o |
17 | obj-$(CONFIG_SND_ATMEL_SOC_WM8904) += snd-atmel-soc-wm8904.o | 18 | obj-$(CONFIG_SND_ATMEL_SOC_WM8904) += snd-atmel-soc-wm8904.o |
19 | obj-$(CONFIG_SND_AT91_SOC_SAM9X5_WM8731) += snd-soc-sam9x5-wm8731.o | ||
18 | obj-$(CONFIG_SND_AT91_SOC_AFEB9260) += snd-soc-afeb9260.o | 20 | obj-$(CONFIG_SND_AT91_SOC_AFEB9260) += snd-soc-afeb9260.o |
diff --git a/sound/soc/atmel/sam9x5_wm8731.c b/sound/soc/atmel/sam9x5_wm8731.c new file mode 100644 index 000000000000..992ae38d5a15 --- /dev/null +++ b/sound/soc/atmel/sam9x5_wm8731.c | |||
@@ -0,0 +1,208 @@ | |||
1 | /* | ||
2 | * sam9x5_wm8731 -- SoC audio for AT91SAM9X5-based boards | ||
3 | * that are using WM8731 as codec. | ||
4 | * | ||
5 | * Copyright (C) 2011 Atmel, | ||
6 | * Nicolas Ferre <nicolas.ferre@atmel.com> | ||
7 | * | ||
8 | * Copyright (C) 2013 Paratronic, | ||
9 | * Richard Genoud <richard.genoud@gmail.com> | ||
10 | * | ||
11 | * Based on sam9g20_wm8731.c by: | ||
12 | * Sedji Gaouaou <sedji.gaouaou@atmel.com> | ||
13 | * | ||
14 | * This program is free software; you can redistribute it and/or modify it | ||
15 | * under the terms of the GNU General Public License as published by the | ||
16 | * Free Software Foundation; either version 2 of the License, or (at your | ||
17 | * option) any later version. | ||
18 | * | ||
19 | */ | ||
20 | #include <linux/of.h> | ||
21 | #include <linux/export.h> | ||
22 | #include <linux/module.h> | ||
23 | #include <linux/mod_devicetable.h> | ||
24 | #include <linux/platform_device.h> | ||
25 | #include <linux/device.h> | ||
26 | |||
27 | #include <sound/soc.h> | ||
28 | #include <sound/soc-dai.h> | ||
29 | #include <sound/soc-dapm.h> | ||
30 | |||
31 | #include "../codecs/wm8731.h" | ||
32 | #include "atmel_ssc_dai.h" | ||
33 | |||
34 | |||
35 | #define MCLK_RATE 12288000 | ||
36 | |||
37 | #define DRV_NAME "sam9x5-snd-wm8731" | ||
38 | |||
39 | struct sam9x5_drvdata { | ||
40 | int ssc_id; | ||
41 | }; | ||
42 | |||
43 | /* | ||
44 | * Logic for a wm8731 as connected on a at91sam9x5ek based board. | ||
45 | */ | ||
46 | static int sam9x5_wm8731_init(struct snd_soc_pcm_runtime *rtd) | ||
47 | { | ||
48 | struct snd_soc_dai *codec_dai = rtd->codec_dai; | ||
49 | struct device *dev = rtd->dev; | ||
50 | int ret; | ||
51 | |||
52 | dev_dbg(dev, "ASoC: %s called\n", __func__); | ||
53 | |||
54 | /* set the codec system clock for DAC and ADC */ | ||
55 | ret = snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK_XTAL, | ||
56 | MCLK_RATE, SND_SOC_CLOCK_IN); | ||
57 | if (ret < 0) { | ||
58 | dev_err(dev, "ASoC: Failed to set WM8731 SYSCLK: %d\n", ret); | ||
59 | return ret; | ||
60 | } | ||
61 | |||
62 | return 0; | ||
63 | } | ||
64 | |||
65 | /* | ||
66 | * Audio paths on at91sam9x5ek board: | ||
67 | * | ||
68 | * |A| ------------> | | ---R----> Headphone Jack | ||
69 | * |T| <----\ | WM | ---L--/ | ||
70 | * |9| ---> CLK <--> | 8731 | <--R----- Line In Jack | ||
71 | * |1| <------------ | | <--L--/ | ||
72 | */ | ||
73 | static const struct snd_soc_dapm_widget sam9x5_dapm_widgets[] = { | ||
74 | SND_SOC_DAPM_HP("Headphone Jack", NULL), | ||
75 | SND_SOC_DAPM_LINE("Line In Jack", NULL), | ||
76 | }; | ||
77 | |||
78 | static int sam9x5_wm8731_driver_probe(struct platform_device *pdev) | ||
79 | { | ||
80 | struct device_node *np = pdev->dev.of_node; | ||
81 | struct device_node *codec_np, *cpu_np; | ||
82 | struct snd_soc_card *card; | ||
83 | struct snd_soc_dai_link *dai; | ||
84 | struct sam9x5_drvdata *priv; | ||
85 | int ret; | ||
86 | |||
87 | if (!np) { | ||
88 | dev_err(&pdev->dev, "No device node supplied\n"); | ||
89 | return -EINVAL; | ||
90 | } | ||
91 | |||
92 | card = devm_kzalloc(&pdev->dev, sizeof(*card), GFP_KERNEL); | ||
93 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); | ||
94 | dai = devm_kzalloc(&pdev->dev, sizeof(*dai), GFP_KERNEL); | ||
95 | if (!dai || !card || !priv) { | ||
96 | ret = -ENOMEM; | ||
97 | goto out; | ||
98 | } | ||
99 | |||
100 | card->dev = &pdev->dev; | ||
101 | card->owner = THIS_MODULE; | ||
102 | card->dai_link = dai; | ||
103 | card->num_links = 1; | ||
104 | card->dapm_widgets = sam9x5_dapm_widgets; | ||
105 | card->num_dapm_widgets = ARRAY_SIZE(sam9x5_dapm_widgets); | ||
106 | dai->name = "WM8731"; | ||
107 | dai->stream_name = "WM8731 PCM"; | ||
108 | dai->codec_dai_name = "wm8731-hifi"; | ||
109 | dai->init = sam9x5_wm8731_init; | ||
110 | dai->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | ||
111 | | SND_SOC_DAIFMT_CBM_CFM; | ||
112 | |||
113 | ret = snd_soc_of_parse_card_name(card, "atmel,model"); | ||
114 | if (ret) { | ||
115 | dev_err(&pdev->dev, "atmel,model node missing\n"); | ||
116 | goto out; | ||
117 | } | ||
118 | |||
119 | ret = snd_soc_of_parse_audio_routing(card, "atmel,audio-routing"); | ||
120 | if (ret) { | ||
121 | dev_err(&pdev->dev, "atmel,audio-routing node missing\n"); | ||
122 | goto out; | ||
123 | } | ||
124 | |||
125 | codec_np = of_parse_phandle(np, "atmel,audio-codec", 0); | ||
126 | if (!codec_np) { | ||
127 | dev_err(&pdev->dev, "atmel,audio-codec node missing\n"); | ||
128 | ret = -EINVAL; | ||
129 | goto out; | ||
130 | } | ||
131 | |||
132 | dai->codec_of_node = codec_np; | ||
133 | |||
134 | cpu_np = of_parse_phandle(np, "atmel,ssc-controller", 0); | ||
135 | if (!cpu_np) { | ||
136 | dev_err(&pdev->dev, "atmel,ssc-controller node missing\n"); | ||
137 | ret = -EINVAL; | ||
138 | goto out; | ||
139 | } | ||
140 | dai->cpu_of_node = cpu_np; | ||
141 | dai->platform_of_node = cpu_np; | ||
142 | |||
143 | priv->ssc_id = of_alias_get_id(cpu_np, "ssc"); | ||
144 | |||
145 | ret = atmel_ssc_set_audio(priv->ssc_id); | ||
146 | if (ret != 0) { | ||
147 | dev_err(&pdev->dev, | ||
148 | "ASoC: Failed to set SSC %d for audio: %d\n", | ||
149 | ret, priv->ssc_id); | ||
150 | goto out; | ||
151 | } | ||
152 | |||
153 | of_node_put(codec_np); | ||
154 | of_node_put(cpu_np); | ||
155 | |||
156 | platform_set_drvdata(pdev, card); | ||
157 | |||
158 | ret = snd_soc_register_card(card); | ||
159 | if (ret) { | ||
160 | dev_err(&pdev->dev, | ||
161 | "ASoC: Platform device allocation failed\n"); | ||
162 | goto out_put_audio; | ||
163 | } | ||
164 | |||
165 | dev_dbg(&pdev->dev, "ASoC: %s ok\n", __func__); | ||
166 | |||
167 | return ret; | ||
168 | |||
169 | out_put_audio: | ||
170 | atmel_ssc_put_audio(priv->ssc_id); | ||
171 | out: | ||
172 | return ret; | ||
173 | } | ||
174 | |||
175 | static int sam9x5_wm8731_driver_remove(struct platform_device *pdev) | ||
176 | { | ||
177 | struct snd_soc_card *card = platform_get_drvdata(pdev); | ||
178 | struct sam9x5_drvdata *priv = card->drvdata; | ||
179 | |||
180 | snd_soc_unregister_card(card); | ||
181 | atmel_ssc_put_audio(priv->ssc_id); | ||
182 | |||
183 | return 0; | ||
184 | } | ||
185 | |||
186 | static const struct of_device_id sam9x5_wm8731_of_match[] = { | ||
187 | { .compatible = "atmel,sam9x5-wm8731-audio", }, | ||
188 | {}, | ||
189 | }; | ||
190 | MODULE_DEVICE_TABLE(of, sam9x5_wm8731_of_match); | ||
191 | |||
192 | static struct platform_driver sam9x5_wm8731_driver = { | ||
193 | .driver = { | ||
194 | .name = DRV_NAME, | ||
195 | .owner = THIS_MODULE, | ||
196 | .of_match_table = of_match_ptr(sam9x5_wm8731_of_match), | ||
197 | }, | ||
198 | .probe = sam9x5_wm8731_driver_probe, | ||
199 | .remove = sam9x5_wm8731_driver_remove, | ||
200 | }; | ||
201 | module_platform_driver(sam9x5_wm8731_driver); | ||
202 | |||
203 | /* Module information */ | ||
204 | MODULE_AUTHOR("Nicolas Ferre <nicolas.ferre@atmel.com>"); | ||
205 | MODULE_AUTHOR("Richard Genoud <richard.genoud@gmail.com>"); | ||
206 | MODULE_DESCRIPTION("ALSA SoC machine driver for AT91SAM9x5 - WM8731"); | ||
207 | MODULE_LICENSE("GPL"); | ||
208 | MODULE_ALIAS("platform:" DRV_NAME); | ||