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 static const struct snd_soc_dapm_widget atmel_asoc_wm8904_dapm_widgets
[] = {
22 SND_SOC_DAPM_HP("Headphone Jack", NULL
),
23 SND_SOC_DAPM_MIC("Mic", NULL
),
24 SND_SOC_DAPM_LINE("Line In Jack", NULL
),
27 static int atmel_asoc_wm8904_hw_params(struct snd_pcm_substream
*substream
,
28 struct snd_pcm_hw_params
*params
)
30 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
31 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
34 ret
= snd_soc_dai_set_pll(codec_dai
, WM8904_FLL_MCLK
, WM8904_FLL_MCLK
,
35 32768, params_rate(params
) * 256);
37 pr_err("%s - failed to set wm8904 codec PLL.", __func__
);
42 * As here wm8904 use FLL output as its system clock
43 * so calling set_sysclk won't care freq parameter
46 ret
= snd_soc_dai_set_sysclk(codec_dai
, WM8904_CLK_FLL
,
49 pr_err("%s -failed to set wm8904 SYSCLK\n", __func__
);
56 static struct snd_soc_ops atmel_asoc_wm8904_ops
= {
57 .hw_params
= atmel_asoc_wm8904_hw_params
,
60 static struct snd_soc_dai_link atmel_asoc_wm8904_dailink
= {
62 .stream_name
= "WM8904 PCM",
63 .codec_dai_name
= "wm8904-hifi",
64 .dai_fmt
= SND_SOC_DAIFMT_I2S
65 | SND_SOC_DAIFMT_NB_NF
66 | SND_SOC_DAIFMT_CBM_CFM
,
67 .ops
= &atmel_asoc_wm8904_ops
,
70 static struct snd_soc_card atmel_asoc_wm8904_card
= {
71 .name
= "atmel_asoc_wm8904",
73 .dai_link
= &atmel_asoc_wm8904_dailink
,
75 .dapm_widgets
= atmel_asoc_wm8904_dapm_widgets
,
76 .num_dapm_widgets
= ARRAY_SIZE(atmel_asoc_wm8904_dapm_widgets
),
80 static int atmel_asoc_wm8904_dt_init(struct platform_device
*pdev
)
82 struct device_node
*np
= pdev
->dev
.of_node
;
83 struct device_node
*codec_np
, *cpu_np
;
84 struct snd_soc_card
*card
= &atmel_asoc_wm8904_card
;
85 struct snd_soc_dai_link
*dailink
= &atmel_asoc_wm8904_dailink
;
89 dev_err(&pdev
->dev
, "only device tree supported\n");
93 ret
= snd_soc_of_parse_card_name(card
, "atmel,model");
95 dev_err(&pdev
->dev
, "failed to parse card name\n");
99 ret
= snd_soc_of_parse_audio_routing(card
, "atmel,audio-routing");
101 dev_err(&pdev
->dev
, "failed to parse audio routing\n");
105 cpu_np
= of_parse_phandle(np
, "atmel,ssc-controller", 0);
107 dev_err(&pdev
->dev
, "failed to get dai and pcm info\n");
111 dailink
->cpu_of_node
= cpu_np
;
112 dailink
->platform_of_node
= cpu_np
;
115 codec_np
= of_parse_phandle(np
, "atmel,audio-codec", 0);
117 dev_err(&pdev
->dev
, "failed to get codec info\n");
121 dailink
->codec_of_node
= codec_np
;
122 of_node_put(codec_np
);
127 static int atmel_asoc_wm8904_probe(struct platform_device
*pdev
)
129 struct snd_soc_card
*card
= &atmel_asoc_wm8904_card
;
130 struct snd_soc_dai_link
*dailink
= &atmel_asoc_wm8904_dailink
;
133 card
->dev
= &pdev
->dev
;
134 ret
= atmel_asoc_wm8904_dt_init(pdev
);
136 dev_err(&pdev
->dev
, "failed to init dt info\n");
140 id
= of_alias_get_id((struct device_node
*)dailink
->cpu_of_node
, "ssc");
141 ret
= atmel_ssc_set_audio(id
);
143 dev_err(&pdev
->dev
, "failed to set SSC %d for audio\n", id
);
147 ret
= snd_soc_register_card(card
);
149 dev_err(&pdev
->dev
, "snd_soc_register_card failed\n");
156 atmel_ssc_put_audio(id
);
160 static int atmel_asoc_wm8904_remove(struct platform_device
*pdev
)
162 struct snd_soc_card
*card
= platform_get_drvdata(pdev
);
163 struct snd_soc_dai_link
*dailink
= &atmel_asoc_wm8904_dailink
;
166 id
= of_alias_get_id((struct device_node
*)dailink
->cpu_of_node
, "ssc");
168 snd_soc_unregister_card(card
);
169 atmel_ssc_put_audio(id
);
175 static const struct of_device_id atmel_asoc_wm8904_dt_ids
[] = {
176 { .compatible
= "atmel,asoc-wm8904", },
179 MODULE_DEVICE_TABLE(of
, atmel_asoc_wm8904_dt_ids
);
182 static struct platform_driver atmel_asoc_wm8904_driver
= {
184 .name
= "atmel-wm8904-audio",
185 .of_match_table
= of_match_ptr(atmel_asoc_wm8904_dt_ids
),
186 .pm
= &snd_soc_pm_ops
,
188 .probe
= atmel_asoc_wm8904_probe
,
189 .remove
= atmel_asoc_wm8904_remove
,
192 module_platform_driver(atmel_asoc_wm8904_driver
);
194 /* Module information */
195 MODULE_AUTHOR("Bo Shen <voice.shen@atmel.com>");
196 MODULE_DESCRIPTION("ALSA SoC machine driver for Atmel EK with WM8904 codec");
197 MODULE_LICENSE("GPL");