treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / sound / soc / atmel / atmel_wm8904.c
blob776b27d3686e72ab2071468eb36bb7afa6adec92
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * atmel_wm8904 - Atmel ASoC driver for boards with WM8904 codec.
5 * Copyright (C) 2012 Atmel
7 * Author: Bo Shen <voice.shen@atmel.com>
8 */
10 #include <linux/clk.h>
11 #include <linux/module.h>
12 #include <linux/of.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;
31 int ret;
33 ret = snd_soc_dai_set_pll(codec_dai, WM8904_FLL_MCLK, WM8904_FLL_MCLK,
34 32768, params_rate(params) * 256);
35 if (ret < 0) {
36 pr_err("%s - failed to set wm8904 codec PLL.", __func__);
37 return ret;
41 * As here wm8904 use FLL output as its system clock
42 * so calling set_sysclk won't care freq parameter
43 * then we pass 0
45 ret = snd_soc_dai_set_sysclk(codec_dai, WM8904_CLK_FLL,
46 0, SND_SOC_CLOCK_IN);
47 if (ret < 0) {
48 pr_err("%s -failed to set wm8904 SYSCLK\n", __func__);
49 return ret;
52 return 0;
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 = {
65 .name = "WM8904",
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",
76 .owner = THIS_MODULE,
77 .dai_link = &atmel_asoc_wm8904_dailink,
78 .num_links = 1,
79 .dapm_widgets = atmel_asoc_wm8904_dapm_widgets,
80 .num_dapm_widgets = ARRAY_SIZE(atmel_asoc_wm8904_dapm_widgets),
81 .fully_routed = true,
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;
90 int ret;
92 if (!np) {
93 dev_err(&pdev->dev, "only device tree supported\n");
94 return -EINVAL;
97 ret = snd_soc_of_parse_card_name(card, "atmel,model");
98 if (ret) {
99 dev_err(&pdev->dev, "failed to parse card name\n");
100 return ret;
103 ret = snd_soc_of_parse_audio_routing(card, "atmel,audio-routing");
104 if (ret) {
105 dev_err(&pdev->dev, "failed to parse audio routing\n");
106 return ret;
109 cpu_np = of_parse_phandle(np, "atmel,ssc-controller", 0);
110 if (!cpu_np) {
111 dev_err(&pdev->dev, "failed to get dai and pcm info\n");
112 ret = -EINVAL;
113 return ret;
115 dailink->cpus->of_node = cpu_np;
116 dailink->platforms->of_node = cpu_np;
117 of_node_put(cpu_np);
119 codec_np = of_parse_phandle(np, "atmel,audio-codec", 0);
120 if (!codec_np) {
121 dev_err(&pdev->dev, "failed to get codec info\n");
122 ret = -EINVAL;
123 return ret;
125 dailink->codecs->of_node = codec_np;
126 of_node_put(codec_np);
128 return 0;
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;
135 int id, ret;
137 card->dev = &pdev->dev;
138 ret = atmel_asoc_wm8904_dt_init(pdev);
139 if (ret) {
140 dev_err(&pdev->dev, "failed to init dt info\n");
141 return ret;
144 id = of_alias_get_id((struct device_node *)dailink->cpus->of_node, "ssc");
145 ret = atmel_ssc_set_audio(id);
146 if (ret != 0) {
147 dev_err(&pdev->dev, "failed to set SSC %d for audio\n", id);
148 return ret;
151 ret = snd_soc_register_card(card);
152 if (ret) {
153 dev_err(&pdev->dev, "snd_soc_register_card failed\n");
154 goto err_set_audio;
157 return 0;
159 err_set_audio:
160 atmel_ssc_put_audio(id);
161 return ret;
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;
168 int id;
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);
175 return 0;
178 #ifdef CONFIG_OF
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);
184 #endif
186 static struct platform_driver atmel_asoc_wm8904_driver = {
187 .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");