2 * atmel_wm8904 - Atmel ASoC driver for boards with WM8904 codec.
4 * Copyright (C) 2012 Atmel
6 * Author: Bo Shen <voice.shen@atmel.com>
11 #include <linux/clk.h>
12 #include <linux/module.h>
14 #include <linux/of_device.h>
16 #include <sound/soc.h>
18 #include "../codecs/wm8904.h"
19 #include "atmel_ssc_dai.h"
21 #define MCLK_RATE 32768
23 static struct clk
*mclk
;
25 static const struct snd_soc_dapm_widget atmel_asoc_wm8904_dapm_widgets
[] = {
26 SND_SOC_DAPM_HP("Headphone Jack", NULL
),
27 SND_SOC_DAPM_MIC("Mic", NULL
),
28 SND_SOC_DAPM_LINE("Line In Jack", NULL
),
31 static int atmel_asoc_wm8904_hw_params(struct snd_pcm_substream
*substream
,
32 struct snd_pcm_hw_params
*params
)
34 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
35 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
38 ret
= snd_soc_dai_set_pll(codec_dai
, WM8904_FLL_MCLK
, WM8904_FLL_MCLK
,
39 32768, params_rate(params
) * 256);
41 pr_err("%s - failed to set wm8904 codec PLL.", __func__
);
46 * As here wm8904 use FLL output as its system clock
47 * so calling set_sysclk won't care freq parameter
50 ret
= snd_soc_dai_set_sysclk(codec_dai
, WM8904_CLK_FLL
,
53 pr_err("%s -failed to set wm8904 SYSCLK\n", __func__
);
60 static struct snd_soc_ops atmel_asoc_wm8904_ops
= {
61 .hw_params
= atmel_asoc_wm8904_hw_params
,
64 static int atmel_set_bias_level(struct snd_soc_card
*card
,
65 struct snd_soc_dapm_context
*dapm
,
66 enum snd_soc_bias_level level
)
68 if (dapm
->bias_level
== SND_SOC_BIAS_STANDBY
) {
70 case SND_SOC_BIAS_PREPARE
:
71 clk_prepare_enable(mclk
);
73 case SND_SOC_BIAS_OFF
:
74 clk_disable_unprepare(mclk
);
84 static struct snd_soc_dai_link atmel_asoc_wm8904_dailink
= {
86 .stream_name
= "WM8904 PCM",
87 .codec_dai_name
= "wm8904-hifi",
88 .dai_fmt
= SND_SOC_DAIFMT_I2S
89 | SND_SOC_DAIFMT_NB_NF
90 | SND_SOC_DAIFMT_CBM_CFM
,
91 .ops
= &atmel_asoc_wm8904_ops
,
94 static struct snd_soc_card atmel_asoc_wm8904_card
= {
95 .name
= "atmel_asoc_wm8904",
97 .set_bias_level
= atmel_set_bias_level
,
98 .dai_link
= &atmel_asoc_wm8904_dailink
,
100 .dapm_widgets
= atmel_asoc_wm8904_dapm_widgets
,
101 .num_dapm_widgets
= ARRAY_SIZE(atmel_asoc_wm8904_dapm_widgets
),
102 .fully_routed
= true,
105 static int atmel_asoc_wm8904_dt_init(struct platform_device
*pdev
)
107 struct device_node
*np
= pdev
->dev
.of_node
;
108 struct device_node
*codec_np
, *cpu_np
;
109 struct snd_soc_card
*card
= &atmel_asoc_wm8904_card
;
110 struct snd_soc_dai_link
*dailink
= &atmel_asoc_wm8904_dailink
;
114 dev_err(&pdev
->dev
, "only device tree supported\n");
118 ret
= snd_soc_of_parse_card_name(card
, "atmel,model");
120 dev_err(&pdev
->dev
, "failed to parse card name\n");
124 ret
= snd_soc_of_parse_audio_routing(card
, "atmel,audio-routing");
126 dev_err(&pdev
->dev
, "failed to parse audio routing\n");
130 cpu_np
= of_parse_phandle(np
, "atmel,ssc-controller", 0);
132 dev_err(&pdev
->dev
, "failed to get dai and pcm info\n");
136 dailink
->cpu_of_node
= cpu_np
;
137 dailink
->platform_of_node
= cpu_np
;
140 codec_np
= of_parse_phandle(np
, "atmel,audio-codec", 0);
142 dev_err(&pdev
->dev
, "failed to get codec info\n");
146 dailink
->codec_of_node
= codec_np
;
147 of_node_put(codec_np
);
152 static int atmel_asoc_wm8904_probe(struct platform_device
*pdev
)
154 struct snd_soc_card
*card
= &atmel_asoc_wm8904_card
;
155 struct snd_soc_dai_link
*dailink
= &atmel_asoc_wm8904_dailink
;
159 card
->dev
= &pdev
->dev
;
160 ret
= atmel_asoc_wm8904_dt_init(pdev
);
162 dev_err(&pdev
->dev
, "failed to init dt info\n");
166 id
= of_alias_get_id((struct device_node
*)dailink
->cpu_of_node
, "ssc");
167 ret
= atmel_ssc_set_audio(id
);
169 dev_err(&pdev
->dev
, "failed to set SSC %d for audio\n", id
);
173 mclk
= clk_get(NULL
, "pck0");
175 dev_err(&pdev
->dev
, "failed to get pck0\n");
180 clk_src
= clk_get(NULL
, "clk32k");
181 if (IS_ERR(clk_src
)) {
182 dev_err(&pdev
->dev
, "failed to get clk32k\n");
183 ret
= PTR_ERR(clk_src
);
187 ret
= clk_set_parent(mclk
, clk_src
);
190 dev_err(&pdev
->dev
, "failed to set MCLK parent\n");
194 dev_info(&pdev
->dev
, "setting pck0 to %dHz\n", MCLK_RATE
);
195 clk_set_rate(mclk
, MCLK_RATE
);
197 ret
= snd_soc_register_card(card
);
199 dev_err(&pdev
->dev
, "snd_soc_register_card failed\n");
206 atmel_ssc_put_audio(id
);
210 static int atmel_asoc_wm8904_remove(struct platform_device
*pdev
)
212 struct snd_soc_card
*card
= platform_get_drvdata(pdev
);
213 struct snd_soc_dai_link
*dailink
= &atmel_asoc_wm8904_dailink
;
216 id
= of_alias_get_id((struct device_node
*)dailink
->cpu_of_node
, "ssc");
218 snd_soc_unregister_card(card
);
219 atmel_ssc_put_audio(id
);
225 static const struct of_device_id atmel_asoc_wm8904_dt_ids
[] = {
226 { .compatible
= "atmel,asoc-wm8904", },
231 static struct platform_driver atmel_asoc_wm8904_driver
= {
233 .name
= "atmel-wm8904-audio",
234 .owner
= THIS_MODULE
,
235 .of_match_table
= of_match_ptr(atmel_asoc_wm8904_dt_ids
),
237 .probe
= atmel_asoc_wm8904_probe
,
238 .remove
= atmel_asoc_wm8904_remove
,
241 module_platform_driver(atmel_asoc_wm8904_driver
);
243 /* Module information */
244 MODULE_AUTHOR("Bo Shen <voice.shen@atmel.com>");
245 MODULE_DESCRIPTION("ALSA SoC machine driver for Atmel EK with WM8904 codec");
246 MODULE_LICENSE("GPL");