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>
14 #include <sound/soc.h>
16 #include "../codecs/wm8904.h"
17 #include "atmel_ssc_dai.h"
19 static const struct snd_soc_dapm_widget atmel_asoc_wm8904_dapm_widgets
[] = {
20 SND_SOC_DAPM_HP("Headphone Jack", NULL
),
21 SND_SOC_DAPM_MIC("Mic", NULL
),
22 SND_SOC_DAPM_LINE("Line In Jack", NULL
),
25 static int atmel_asoc_wm8904_hw_params(struct snd_pcm_substream
*substream
,
26 struct snd_pcm_hw_params
*params
)
28 struct snd_soc_pcm_runtime
*rtd
= snd_soc_substream_to_rtd(substream
);
29 struct snd_soc_dai
*codec_dai
= snd_soc_rtd_to_codec(rtd
, 0);
32 ret
= snd_soc_dai_set_pll(codec_dai
, WM8904_FLL_MCLK
, WM8904_FLL_MCLK
,
33 32768, params_rate(params
) * 256);
35 pr_err("%s - failed to set wm8904 codec PLL.", __func__
);
40 * As here wm8904 use FLL output as its system clock
41 * so calling set_sysclk won't care freq parameter
44 ret
= snd_soc_dai_set_sysclk(codec_dai
, WM8904_CLK_FLL
,
47 pr_err("%s -failed to set wm8904 SYSCLK\n", __func__
);
54 static const struct snd_soc_ops atmel_asoc_wm8904_ops
= {
55 .hw_params
= atmel_asoc_wm8904_hw_params
,
58 SND_SOC_DAILINK_DEFS(pcm
,
59 DAILINK_COMP_ARRAY(COMP_EMPTY()),
60 DAILINK_COMP_ARRAY(COMP_CODEC(NULL
, "wm8904-hifi")),
61 DAILINK_COMP_ARRAY(COMP_EMPTY()));
63 static struct snd_soc_dai_link atmel_asoc_wm8904_dailink
= {
65 .stream_name
= "WM8904 PCM",
66 .dai_fmt
= SND_SOC_DAIFMT_I2S
67 | SND_SOC_DAIFMT_NB_NF
68 | SND_SOC_DAIFMT_CBP_CFP
,
69 .ops
= &atmel_asoc_wm8904_ops
,
70 SND_SOC_DAILINK_REG(pcm
),
73 static struct snd_soc_card atmel_asoc_wm8904_card
= {
74 .name
= "atmel_asoc_wm8904",
76 .dai_link
= &atmel_asoc_wm8904_dailink
,
78 .dapm_widgets
= atmel_asoc_wm8904_dapm_widgets
,
79 .num_dapm_widgets
= ARRAY_SIZE(atmel_asoc_wm8904_dapm_widgets
),
83 static int atmel_asoc_wm8904_dt_init(struct platform_device
*pdev
)
85 struct device_node
*np
= pdev
->dev
.of_node
;
86 struct device_node
*codec_np
, *cpu_np
;
87 struct snd_soc_card
*card
= &atmel_asoc_wm8904_card
;
88 struct snd_soc_dai_link
*dailink
= &atmel_asoc_wm8904_dailink
;
92 dev_err(&pdev
->dev
, "only device tree supported\n");
96 ret
= snd_soc_of_parse_card_name(card
, "atmel,model");
98 dev_err(&pdev
->dev
, "failed to parse card name\n");
102 ret
= snd_soc_of_parse_audio_routing(card
, "atmel,audio-routing");
104 dev_err(&pdev
->dev
, "failed to parse audio routing\n");
108 cpu_np
= of_parse_phandle(np
, "atmel,ssc-controller", 0);
110 dev_err(&pdev
->dev
, "failed to get dai and pcm info\n");
114 dailink
->cpus
->of_node
= cpu_np
;
115 dailink
->platforms
->of_node
= cpu_np
;
118 codec_np
= of_parse_phandle(np
, "atmel,audio-codec", 0);
120 dev_err(&pdev
->dev
, "failed to get codec info\n");
124 dailink
->codecs
->of_node
= codec_np
;
125 of_node_put(codec_np
);
130 static int atmel_asoc_wm8904_probe(struct platform_device
*pdev
)
132 struct snd_soc_card
*card
= &atmel_asoc_wm8904_card
;
133 struct snd_soc_dai_link
*dailink
= &atmel_asoc_wm8904_dailink
;
136 card
->dev
= &pdev
->dev
;
137 ret
= atmel_asoc_wm8904_dt_init(pdev
);
139 dev_err(&pdev
->dev
, "failed to init dt info\n");
143 id
= of_alias_get_id((struct device_node
*)dailink
->cpus
->of_node
, "ssc");
144 ret
= atmel_ssc_set_audio(id
);
146 dev_err(&pdev
->dev
, "failed to set SSC %d for audio\n", id
);
150 ret
= snd_soc_register_card(card
);
152 dev_err(&pdev
->dev
, "snd_soc_register_card failed\n");
159 atmel_ssc_put_audio(id
);
163 static void atmel_asoc_wm8904_remove(struct platform_device
*pdev
)
165 struct snd_soc_card
*card
= platform_get_drvdata(pdev
);
166 struct snd_soc_dai_link
*dailink
= &atmel_asoc_wm8904_dailink
;
169 id
= of_alias_get_id((struct device_node
*)dailink
->cpus
->of_node
, "ssc");
171 snd_soc_unregister_card(card
);
172 atmel_ssc_put_audio(id
);
176 static const struct of_device_id atmel_asoc_wm8904_dt_ids
[] = {
177 { .compatible
= "atmel,asoc-wm8904", },
180 MODULE_DEVICE_TABLE(of
, atmel_asoc_wm8904_dt_ids
);
183 static struct platform_driver atmel_asoc_wm8904_driver
= {
185 .name
= "atmel-wm8904-audio",
186 .of_match_table
= of_match_ptr(atmel_asoc_wm8904_dt_ids
),
187 .pm
= &snd_soc_pm_ops
,
189 .probe
= atmel_asoc_wm8904_probe
,
190 .remove
= atmel_asoc_wm8904_remove
,
193 module_platform_driver(atmel_asoc_wm8904_driver
);
195 /* Module information */
196 MODULE_AUTHOR("Bo Shen <voice.shen@atmel.com>");
197 MODULE_DESCRIPTION("ALSA SoC machine driver for Atmel EK with WM8904 codec");
198 MODULE_LICENSE("GPL");