sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / sound / soc / atmel / atmel_wm8904.c
blobfbc10f61eb553dfeb2d2d5bcdc98960bc75f1c3b
1 /*
2 * atmel_wm8904 - Atmel ASoC driver for boards with WM8904 codec.
4 * Copyright (C) 2012 Atmel
6 * Author: Bo Shen <voice.shen@atmel.com>
8 * GPLv2 or later
9 */
11 #include <linux/clk.h>
12 #include <linux/module.h>
13 #include <linux/of.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;
32 int ret;
34 ret = snd_soc_dai_set_pll(codec_dai, WM8904_FLL_MCLK, WM8904_FLL_MCLK,
35 32768, params_rate(params) * 256);
36 if (ret < 0) {
37 pr_err("%s - failed to set wm8904 codec PLL.", __func__);
38 return ret;
42 * As here wm8904 use FLL output as its system clock
43 * so calling set_sysclk won't care freq parameter
44 * then we pass 0
46 ret = snd_soc_dai_set_sysclk(codec_dai, WM8904_CLK_FLL,
47 0, SND_SOC_CLOCK_IN);
48 if (ret < 0) {
49 pr_err("%s -failed to set wm8904 SYSCLK\n", __func__);
50 return ret;
53 return 0;
56 static const 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 = {
61 .name = "WM8904",
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",
72 .owner = THIS_MODULE,
73 .dai_link = &atmel_asoc_wm8904_dailink,
74 .num_links = 1,
75 .dapm_widgets = atmel_asoc_wm8904_dapm_widgets,
76 .num_dapm_widgets = ARRAY_SIZE(atmel_asoc_wm8904_dapm_widgets),
77 .fully_routed = true,
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;
86 int ret;
88 if (!np) {
89 dev_err(&pdev->dev, "only device tree supported\n");
90 return -EINVAL;
93 ret = snd_soc_of_parse_card_name(card, "atmel,model");
94 if (ret) {
95 dev_err(&pdev->dev, "failed to parse card name\n");
96 return ret;
99 ret = snd_soc_of_parse_audio_routing(card, "atmel,audio-routing");
100 if (ret) {
101 dev_err(&pdev->dev, "failed to parse audio routing\n");
102 return ret;
105 cpu_np = of_parse_phandle(np, "atmel,ssc-controller", 0);
106 if (!cpu_np) {
107 dev_err(&pdev->dev, "failed to get dai and pcm info\n");
108 ret = -EINVAL;
109 return ret;
111 dailink->cpu_of_node = cpu_np;
112 dailink->platform_of_node = cpu_np;
113 of_node_put(cpu_np);
115 codec_np = of_parse_phandle(np, "atmel,audio-codec", 0);
116 if (!codec_np) {
117 dev_err(&pdev->dev, "failed to get codec info\n");
118 ret = -EINVAL;
119 return ret;
121 dailink->codec_of_node = codec_np;
122 of_node_put(codec_np);
124 return 0;
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;
131 int id, ret;
133 card->dev = &pdev->dev;
134 ret = atmel_asoc_wm8904_dt_init(pdev);
135 if (ret) {
136 dev_err(&pdev->dev, "failed to init dt info\n");
137 return ret;
140 id = of_alias_get_id((struct device_node *)dailink->cpu_of_node, "ssc");
141 ret = atmel_ssc_set_audio(id);
142 if (ret != 0) {
143 dev_err(&pdev->dev, "failed to set SSC %d for audio\n", id);
144 return ret;
147 ret = snd_soc_register_card(card);
148 if (ret) {
149 dev_err(&pdev->dev, "snd_soc_register_card failed\n");
150 goto err_set_audio;
153 return 0;
155 err_set_audio:
156 atmel_ssc_put_audio(id);
157 return ret;
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;
164 int id;
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);
171 return 0;
174 #ifdef CONFIG_OF
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);
180 #endif
182 static struct platform_driver atmel_asoc_wm8904_driver = {
183 .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");