diff options
Diffstat (limited to 'sound/soc/generic/simple-card.c')
-rw-r--r-- | sound/soc/generic/simple-card.c | 70 |
1 files changed, 36 insertions, 34 deletions
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c index c0d928138c88..2a1b1b5b5221 100644 --- a/sound/soc/generic/simple-card.c +++ b/sound/soc/generic/simple-card.c | |||
@@ -9,14 +9,12 @@ | |||
9 | * published by the Free Software Foundation. | 9 | * published by the Free Software Foundation. |
10 | */ | 10 | */ |
11 | #include <linux/clk.h> | 11 | #include <linux/clk.h> |
12 | #include <linux/module.h> | ||
12 | #include <linux/of.h> | 13 | #include <linux/of.h> |
13 | #include <linux/platform_device.h> | 14 | #include <linux/platform_device.h> |
14 | #include <linux/module.h> | 15 | #include <linux/string.h> |
15 | #include <sound/simple_card.h> | 16 | #include <sound/simple_card.h> |
16 | 17 | ||
17 | #define asoc_simple_get_card_info(p) \ | ||
18 | container_of(p->dai_link, struct asoc_simple_card_info, snd_link) | ||
19 | |||
20 | static int __asoc_simple_card_dai_init(struct snd_soc_dai *dai, | 18 | static int __asoc_simple_card_dai_init(struct snd_soc_dai *dai, |
21 | struct asoc_simple_dai *set, | 19 | struct asoc_simple_dai *set, |
22 | unsigned int daifmt) | 20 | unsigned int daifmt) |
@@ -41,7 +39,8 @@ static int __asoc_simple_card_dai_init(struct snd_soc_dai *dai, | |||
41 | 39 | ||
42 | static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd) | 40 | static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd) |
43 | { | 41 | { |
44 | struct asoc_simple_card_info *info = asoc_simple_get_card_info(rtd); | 42 | struct asoc_simple_card_info *info = |
43 | snd_soc_card_get_drvdata(rtd->card); | ||
45 | struct snd_soc_dai *codec = rtd->codec_dai; | 44 | struct snd_soc_dai *codec = rtd->codec_dai; |
46 | struct snd_soc_dai *cpu = rtd->cpu_dai; | 45 | struct snd_soc_dai *cpu = rtd->cpu_dai; |
47 | unsigned int daifmt = info->daifmt; | 46 | unsigned int daifmt = info->daifmt; |
@@ -106,12 +105,8 @@ asoc_simple_card_sub_parse_of(struct device_node *np, | |||
106 | &dai->sysclk); | 105 | &dai->sysclk); |
107 | } else { | 106 | } else { |
108 | clk = of_clk_get(*node, 0); | 107 | clk = of_clk_get(*node, 0); |
109 | if (IS_ERR(clk)) { | 108 | if (!IS_ERR(clk)) |
110 | ret = PTR_ERR(clk); | 109 | dai->sysclk = clk_get_rate(clk); |
111 | goto parse_error; | ||
112 | } | ||
113 | |||
114 | dai->sysclk = clk_get_rate(clk); | ||
115 | } | 110 | } |
116 | 111 | ||
117 | ret = 0; | 112 | ret = 0; |
@@ -138,10 +133,12 @@ static int asoc_simple_card_parse_of(struct device_node *node, | |||
138 | (SND_SOC_DAIFMT_FORMAT_MASK | SND_SOC_DAIFMT_INV_MASK); | 133 | (SND_SOC_DAIFMT_FORMAT_MASK | SND_SOC_DAIFMT_INV_MASK); |
139 | 134 | ||
140 | /* DAPM routes */ | 135 | /* DAPM routes */ |
141 | ret = snd_soc_of_parse_audio_routing(&info->snd_card, | 136 | if (of_property_read_bool(node, "simple-audio-card,routing")) { |
142 | "simple-audio-routing"); | 137 | ret = snd_soc_of_parse_audio_routing(&info->snd_card, |
143 | if (ret) | 138 | "simple-audio-card,routing"); |
144 | return ret; | 139 | if (ret) |
140 | return ret; | ||
141 | } | ||
145 | 142 | ||
146 | /* CPU sub-node */ | 143 | /* CPU sub-node */ |
147 | ret = -EINVAL; | 144 | ret = -EINVAL; |
@@ -197,34 +194,37 @@ static int asoc_simple_card_probe(struct platform_device *pdev) | |||
197 | struct device_node *np = pdev->dev.of_node; | 194 | struct device_node *np = pdev->dev.of_node; |
198 | struct device_node *of_cpu, *of_codec, *of_platform; | 195 | struct device_node *of_cpu, *of_codec, *of_platform; |
199 | struct device *dev = &pdev->dev; | 196 | struct device *dev = &pdev->dev; |
197 | int ret; | ||
200 | 198 | ||
201 | cinfo = NULL; | 199 | cinfo = NULL; |
202 | of_cpu = NULL; | 200 | of_cpu = NULL; |
203 | of_codec = NULL; | 201 | of_codec = NULL; |
204 | of_platform = NULL; | 202 | of_platform = NULL; |
203 | |||
204 | cinfo = devm_kzalloc(dev, sizeof(*cinfo), GFP_KERNEL); | ||
205 | if (!cinfo) | ||
206 | return -ENOMEM; | ||
207 | |||
205 | if (np && of_device_is_available(np)) { | 208 | if (np && of_device_is_available(np)) { |
206 | cinfo = devm_kzalloc(dev, sizeof(*cinfo), GFP_KERNEL); | 209 | cinfo->snd_card.dev = dev; |
207 | if (cinfo) { | 210 | |
208 | int ret; | 211 | ret = asoc_simple_card_parse_of(np, cinfo, dev, |
209 | cinfo->snd_card.dev = &pdev->dev; | 212 | &of_cpu, |
210 | ret = asoc_simple_card_parse_of(np, cinfo, dev, | 213 | &of_codec, |
211 | &of_cpu, | 214 | &of_platform); |
212 | &of_codec, | 215 | if (ret < 0) { |
213 | &of_platform); | 216 | if (ret != -EPROBE_DEFER) |
214 | if (ret < 0) { | 217 | dev_err(dev, "parse error %d\n", ret); |
215 | if (ret != -EPROBE_DEFER) | 218 | return ret; |
216 | dev_err(dev, "parse error %d\n", ret); | ||
217 | return ret; | ||
218 | } | ||
219 | } | 219 | } |
220 | } else { | 220 | } else { |
221 | cinfo->snd_card.dev = &pdev->dev; | 221 | if (!dev->platform_data) { |
222 | cinfo = pdev->dev.platform_data; | 222 | dev_err(dev, "no info for asoc-simple-card\n"); |
223 | } | 223 | return -EINVAL; |
224 | } | ||
224 | 225 | ||
225 | if (!cinfo) { | 226 | memcpy(cinfo, dev->platform_data, sizeof(*cinfo)); |
226 | dev_err(dev, "no info for asoc-simple-card\n"); | 227 | cinfo->snd_card.dev = dev; |
227 | return -EINVAL; | ||
228 | } | 228 | } |
229 | 229 | ||
230 | if (!cinfo->name || | 230 | if (!cinfo->name || |
@@ -259,6 +259,8 @@ static int asoc_simple_card_probe(struct platform_device *pdev) | |||
259 | cinfo->snd_card.dai_link = &cinfo->snd_link; | 259 | cinfo->snd_card.dai_link = &cinfo->snd_link; |
260 | cinfo->snd_card.num_links = 1; | 260 | cinfo->snd_card.num_links = 1; |
261 | 261 | ||
262 | snd_soc_card_set_drvdata(&cinfo->snd_card, cinfo); | ||
263 | |||
262 | return devm_snd_soc_register_card(&pdev->dev, &cinfo->snd_card); | 264 | return devm_snd_soc_register_card(&pdev->dev, &cinfo->snd_card); |
263 | } | 265 | } |
264 | 266 | ||