1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * atmel_wm8904 - Atmel ASoC driver for boards with WM8904 codec.
5 * Copyright (C) 2012 Atmel
7 * Author: Bo Shen <voice.shen@atmel.com>
10 #include <linux/clk.h>
11 #include <linux/module.h>
13 #include <linux/of_device.h>
15 #include <sound/soc.h>
17 #include "../codecs/wm8904.h"
18 #include "atmel_ssc_dai.h"
20 static const struct snd_soc_dapm_widget atmel_asoc_wm8904_dapm_widgets
[] = {
21 SND_SOC_DAPM_HP("Headphone Jack", NULL
),
22 SND_SOC_DAPM_MIC("Mic", NULL
),
23 SND_SOC_DAPM_LINE("Line In Jack", NULL
),
26 static int atmel_asoc_wm8904_hw_params(struct snd_pcm_substream
*substream
,
27 struct snd_pcm_hw_params
*params
)
29 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
30 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
33 ret
= snd_soc_dai_set_pll(codec_dai
, WM8904_FLL_MCLK
, WM8904_FLL_MCLK
,
34 32768, params_rate(params
) * 256);
36 pr_err("%s - failed to set wm8904 codec PLL.", __func__
);
41 * As here wm8904 use FLL output as its system clock
42 * so calling set_sysclk won't care freq parameter
45 ret
= snd_soc_dai_set_sysclk(codec_dai
, WM8904_CLK_FLL
,
48 pr_err("%s -failed to set wm8904 SYSCLK\n", __func__
);
55 static const struct snd_soc_ops atmel_asoc_wm8904_ops
= {
56 .hw_params
= atmel_asoc_wm8904_hw_params
,
59 SND_SOC_DAILINK_DEFS(pcm
,
60 DAILINK_COMP_ARRAY(COMP_EMPTY()),
61 DAILINK_COMP_ARRAY(COMP_CODEC(NULL
, "wm8904-hifi")),
62 DAILINK_COMP_ARRAY(COMP_EMPTY()));
64 static struct snd_soc_dai_link atmel_asoc_wm8904_dailink
= {
66 .stream_name
= "WM8904 PCM",
67 .dai_fmt
= SND_SOC_DAIFMT_I2S
68 | SND_SOC_DAIFMT_NB_NF
69 | SND_SOC_DAIFMT_CBM_CFM
,
70 .ops
= &atmel_asoc_wm8904_ops
,
71 SND_SOC_DAILINK_REG(pcm
),
74 static struct snd_soc_card atmel_asoc_wm8904_card
= {
75 .name
= "atmel_asoc_wm8904",
77 .dai_link
= &atmel_asoc_wm8904_dailink
,
79 .dapm_widgets
= atmel_asoc_wm8904_dapm_widgets
,
80 .num_dapm_widgets
= ARRAY_SIZE(atmel_asoc_wm8904_dapm_widgets
),
84 static int atmel_asoc_wm8904_dt_init(struct platform_device
*pdev
)
86 struct device_node
*np
= pdev
->dev
.of_node
;
87 struct device_node
*codec_np
, *cpu_np
;
88 struct snd_soc_card
*card
= &atmel_asoc_wm8904_card
;
89 struct snd_soc_dai_link
*dailink
= &atmel_asoc_wm8904_dailink
;
93 dev_err(&pdev
->dev
, "only device tree supported\n");
97 ret
= snd_soc_of_parse_card_name(card
, "atmel,model");
99 dev_err(&pdev
->dev
, "failed to parse card name\n");
103 ret
= snd_soc_of_parse_audio_routing(card
, "atmel,audio-routing");
105 dev_err(&pdev
->dev
, "failed to parse audio routing\n");
109 cpu_np
= of_parse_phandle(np
, "atmel,ssc-controller", 0);
111 dev_err(&pdev
->dev
, "failed to get dai and pcm info\n");
115 dailink
->cpus
->of_node
= cpu_np
;
116 dailink
->platforms
->of_node
= cpu_np
;
119 codec_np
= of_parse_phandle(np
, "atmel,audio-codec", 0);
121 dev_err(&pdev
->dev
, "failed to get codec info\n");
125 dailink
->codecs
->of_node
= codec_np
;
126 of_node_put(codec_np
);
131 static int atmel_asoc_wm8904_probe(struct platform_device
*pdev
)
133 struct snd_soc_card
*card
= &atmel_asoc_wm8904_card
;
134 struct snd_soc_dai_link
*dailink
= &atmel_asoc_wm8904_dailink
;
137 card
->dev
= &pdev
->dev
;
138 ret
= atmel_asoc_wm8904_dt_init(pdev
);
140 dev_err(&pdev
->dev
, "failed to init dt info\n");
144 id
= of_alias_get_id((struct device_node
*)dailink
->cpus
->of_node
, "ssc");
145 ret
= atmel_ssc_set_audio(id
);
147 dev_err(&pdev
->dev
, "failed to set SSC %d for audio\n", id
);
151 ret
= snd_soc_register_card(card
);
153 dev_err(&pdev
->dev
, "snd_soc_register_card failed\n");
160 atmel_ssc_put_audio(id
);
164 static int atmel_asoc_wm8904_remove(struct platform_device
*pdev
)
166 struct snd_soc_card
*card
= platform_get_drvdata(pdev
);
167 struct snd_soc_dai_link
*dailink
= &atmel_asoc_wm8904_dailink
;
170 id
= of_alias_get_id((struct device_node
*)dailink
->cpus
->of_node
, "ssc");
172 snd_soc_unregister_card(card
);
173 atmel_ssc_put_audio(id
);
179 static const struct of_device_id atmel_asoc_wm8904_dt_ids
[] = {
180 { .compatible
= "atmel,asoc-wm8904", },
183 MODULE_DEVICE_TABLE(of
, atmel_asoc_wm8904_dt_ids
);
186 static struct platform_driver atmel_asoc_wm8904_driver
= {
188 .name
= "atmel-wm8904-audio",
189 .of_match_table
= of_match_ptr(atmel_asoc_wm8904_dt_ids
),
190 .pm
= &snd_soc_pm_ops
,
192 .probe
= atmel_asoc_wm8904_probe
,
193 .remove
= atmel_asoc_wm8904_remove
,
196 module_platform_driver(atmel_asoc_wm8904_driver
);
198 /* Module information */
199 MODULE_AUTHOR("Bo Shen <voice.shen@atmel.com>");
200 MODULE_DESCRIPTION("ALSA SoC machine driver for Atmel EK with WM8904 codec");
201 MODULE_LICENSE("GPL");