ASoC: simple-card-utils: add asoc_simple_card_set_dailink_name()
[deliverable/linux.git] / sound / soc / generic / simple-card.c
CommitLineData
f2390880
KM
1/*
2 * ASoC simple sound card support
3 *
4 * Copyright (C) 2012 Renesas Solutions Corp.
5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
fa558c28 11#include <linux/clk.h>
6ff62eed 12#include <linux/device.h>
3fe24032 13#include <linux/gpio.h>
f2390880 14#include <linux/module.h>
fa558c28 15#include <linux/of.h>
3fe24032 16#include <linux/of_gpio.h>
f2390880 17#include <linux/platform_device.h>
ca919fe4 18#include <linux/string.h>
3fe24032 19#include <sound/jack.h>
f2390880 20#include <sound/simple_card.h>
6ff62eed
XL
21#include <sound/soc-dai.h>
22#include <sound/soc.h>
f2390880 23
9eac3618
KM
24struct asoc_simple_jack {
25 struct snd_soc_jack jack;
26 struct snd_soc_jack_pin pin;
27 struct snd_soc_jack_gpio gpio;
28};
29
45fce594
JFM
30struct simple_card_data {
31 struct snd_soc_card snd_card;
cf7dc23c
JFM
32 struct simple_dai_props {
33 struct asoc_simple_dai cpu_dai;
34 struct asoc_simple_dai codec_dai;
85a4bfd8 35 unsigned int mclk_fs;
cf7dc23c 36 } *dai_props;
2942a0e2 37 unsigned int mclk_fs;
9eac3618
KM
38 struct asoc_simple_jack hp_jack;
39 struct asoc_simple_jack mic_jack;
cf7dc23c 40 struct snd_soc_dai_link dai_link[]; /* dynamically allocated */
45fce594
JFM
41};
42
f531913f 43#define simple_priv_to_dev(priv) ((priv)->snd_card.dev)
9810f537
KM
44#define simple_priv_to_link(priv, i) ((priv)->snd_card.dai_link + i)
45#define simple_priv_to_props(priv, i) ((priv)->dai_props + i)
f531913f 46
548563fa
KM
47#define PREFIX "simple-audio-card,"
48
9eac3618
KM
49#define asoc_simple_card_init_hp(card, sjack, prefix)\
50 asoc_simple_card_init_jack(card, sjack, 1, prefix)
51#define asoc_simple_card_init_mic(card, sjack, prefix)\
52 asoc_simple_card_init_jack(card, sjack, 0, prefix)
53static int asoc_simple_card_init_jack(struct snd_soc_card *card,
54 struct asoc_simple_jack *sjack,
55 int is_hp, char *prefix)
56{
57 struct device *dev = card->dev;
58 enum of_gpio_flags flags;
59 char prop[128];
60 char *pin_name;
61 char *gpio_name;
62 int mask;
63 int det;
64
65 sjack->gpio.gpio = -ENOENT;
66
67 if (is_hp) {
68 snprintf(prop, sizeof(prop), "%shp-det-gpio", prefix);
69 pin_name = "Headphones";
70 gpio_name = "Headphone detection";
71 mask = SND_JACK_HEADPHONE;
72 } else {
73 snprintf(prop, sizeof(prop), "%smic-det-gpio", prefix);
74 pin_name = "Mic Jack";
75 gpio_name = "Mic detection";
76 mask = SND_JACK_MICROPHONE;
77 }
78
79 det = of_get_named_gpio_flags(dev->of_node, prop, 0, &flags);
80 if (det == -EPROBE_DEFER)
81 return -EPROBE_DEFER;
82
83 if (gpio_is_valid(det)) {
84 sjack->pin.pin = pin_name;
85 sjack->pin.mask = mask;
86
87 sjack->gpio.name = gpio_name;
88 sjack->gpio.report = mask;
89 sjack->gpio.gpio = det;
90 sjack->gpio.invert = !!(flags & OF_GPIO_ACTIVE_LOW);
91 sjack->gpio.debounce_time = 150;
92
93 snd_soc_card_jack_new(card, pin_name, mask,
94 &sjack->jack,
95 &sjack->pin, 1);
96
97 snd_soc_jack_add_gpios(&sjack->jack, 1,
98 &sjack->gpio);
99 }
100
101 return 0;
102}
103
104static void asoc_simple_card_remove_jack(struct asoc_simple_jack *sjack)
105{
106 if (gpio_is_valid(sjack->gpio.gpio))
107 snd_soc_jack_free_gpios(&sjack->jack, 1, &sjack->gpio);
108}
109
f9911803
JS
110static int asoc_simple_card_startup(struct snd_pcm_substream *substream)
111{
112 struct snd_soc_pcm_runtime *rtd = substream->private_data;
113 struct simple_card_data *priv = snd_soc_card_get_drvdata(rtd->card);
114 struct simple_dai_props *dai_props =
1a497983 115 &priv->dai_props[rtd->num];
f9911803
JS
116 int ret;
117
118 ret = clk_prepare_enable(dai_props->cpu_dai.clk);
119 if (ret)
120 return ret;
121
122 ret = clk_prepare_enable(dai_props->codec_dai.clk);
123 if (ret)
124 clk_disable_unprepare(dai_props->cpu_dai.clk);
125
126 return ret;
127}
128
129static void asoc_simple_card_shutdown(struct snd_pcm_substream *substream)
130{
131 struct snd_soc_pcm_runtime *rtd = substream->private_data;
132 struct simple_card_data *priv = snd_soc_card_get_drvdata(rtd->card);
133 struct simple_dai_props *dai_props =
1a497983 134 &priv->dai_props[rtd->num];
f9911803
JS
135
136 clk_disable_unprepare(dai_props->cpu_dai.clk);
137
138 clk_disable_unprepare(dai_props->codec_dai.clk);
139}
140
2942a0e2
AL
141static int asoc_simple_card_hw_params(struct snd_pcm_substream *substream,
142 struct snd_pcm_hw_params *params)
143{
144 struct snd_soc_pcm_runtime *rtd = substream->private_data;
145 struct snd_soc_dai *codec_dai = rtd->codec_dai;
e2257971 146 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
2942a0e2 147 struct simple_card_data *priv = snd_soc_card_get_drvdata(rtd->card);
1a497983 148 struct simple_dai_props *dai_props = &priv->dai_props[rtd->num];
85a4bfd8 149 unsigned int mclk, mclk_fs = 0;
2942a0e2
AL
150 int ret = 0;
151
85a4bfd8
AP
152 if (priv->mclk_fs)
153 mclk_fs = priv->mclk_fs;
154 else if (dai_props->mclk_fs)
155 mclk_fs = dai_props->mclk_fs;
156
157 if (mclk_fs) {
158 mclk = params_rate(params) * mclk_fs;
2942a0e2
AL
159 ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
160 SND_SOC_CLOCK_IN);
e2257971
AP
161 if (ret && ret != -ENOTSUPP)
162 goto err;
163
164 ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk,
165 SND_SOC_CLOCK_OUT);
166 if (ret && ret != -ENOTSUPP)
167 goto err;
2942a0e2 168 }
ee43a1a0 169 return 0;
e2257971 170err:
2942a0e2
AL
171 return ret;
172}
173
174static struct snd_soc_ops asoc_simple_card_ops = {
f9911803
JS
175 .startup = asoc_simple_card_startup,
176 .shutdown = asoc_simple_card_shutdown,
2942a0e2
AL
177 .hw_params = asoc_simple_card_hw_params,
178};
179
a4a2992c 180static int __asoc_simple_card_dai_init(struct snd_soc_dai *dai,
30d0341e 181 struct asoc_simple_dai *set)
a4a2992c 182{
4763ebe2 183 int ret;
a4a2992c 184
4763ebe2 185 if (set->sysclk) {
a4a2992c 186 ret = snd_soc_dai_set_sysclk(dai, 0, set->sysclk, 0);
4763ebe2
XL
187 if (ret && ret != -ENOTSUPP) {
188 dev_err(dai->dev, "simple-card: set_sysclk error\n");
189 goto err;
190 }
191 }
192
6ff62eed 193 if (set->slots) {
6131084a
JS
194 ret = snd_soc_dai_set_tdm_slot(dai,
195 set->tx_slot_mask,
196 set->rx_slot_mask,
6ff62eed
XL
197 set->slots,
198 set->slot_width);
199 if (ret && ret != -ENOTSUPP) {
200 dev_err(dai->dev, "simple-card: set_tdm_slot error\n");
201 goto err;
202 }
203 }
204
4763ebe2 205 ret = 0;
a4a2992c 206
4763ebe2 207err:
a4a2992c
KM
208 return ret;
209}
210
f2390880
KM
211static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd)
212{
781cbebe 213 struct simple_card_data *priv = snd_soc_card_get_drvdata(rtd->card);
f2390880
KM
214 struct snd_soc_dai *codec = rtd->codec_dai;
215 struct snd_soc_dai *cpu = rtd->cpu_dai;
6a91a17b 216 struct simple_dai_props *dai_props;
1a497983 217 int ret;
f2390880 218
1a497983 219 dai_props = &priv->dai_props[rtd->num];
6a91a17b 220 ret = __asoc_simple_card_dai_init(codec, &dai_props->codec_dai);
a4a2992c
KM
221 if (ret < 0)
222 return ret;
f2390880 223
6a91a17b 224 ret = __asoc_simple_card_dai_init(cpu, &dai_props->cpu_dai);
a4a2992c
KM
225 if (ret < 0)
226 return ret;
f2390880 227
9eac3618
KM
228 ret = asoc_simple_card_init_hp(rtd->card, &priv->hp_jack, PREFIX);
229 if (ret < 0)
230 return ret;
231
232 ret = asoc_simple_card_init_mic(rtd->card, &priv->hp_jack, PREFIX);
233 if (ret < 0)
234 return ret;
3fe24032 235
f2390880
KM
236 return 0;
237}
238
fa558c28
KM
239static int
240asoc_simple_card_sub_parse_of(struct device_node *np,
241 struct asoc_simple_dai *dai,
8ea21348 242 struct device_node **p_node,
7c7b9cf5
KM
243 const char **name,
244 int *args_count)
fa558c28 245{
7c7b9cf5 246 struct of_phandle_args args;
fa558c28 247 struct clk *clk;
c7099eb1 248 u32 val;
fa558c28
KM
249 int ret;
250
5fb9cb16
KM
251 if (!np)
252 return 0;
253
fa558c28 254 /*
0dd4fc3c 255 * Get node via "sound-dai = <&phandle port>"
fa558c28
KM
256 * it will be used as xxx_of_node on soc_bind_dai_link()
257 */
7c7b9cf5
KM
258 ret = of_parse_phandle_with_args(np, "sound-dai",
259 "#sound-dai-cells", 0, &args);
260 if (ret)
261 return ret;
262
263 *p_node = args.np;
264
265 if (args_count)
266 *args_count = args.args_count;
fa558c28 267
0dd4fc3c 268 /* Get dai->name */
5fb9cb16
KM
269 if (name) {
270 ret = snd_soc_of_get_dai_name(np, name);
271 if (ret < 0)
272 return ret;
273 }
274
275 if (!dai)
276 return 0;
fa558c28 277
0dd4fc3c 278 /* Parse TDM slot */
6131084a
JS
279 ret = snd_soc_of_parse_tdm_slot(np, &dai->tx_slot_mask,
280 &dai->rx_slot_mask,
281 &dai->slots, &dai->slot_width);
6ff62eed 282 if (ret)
e512e001 283 return ret;
6ff62eed 284
fa558c28 285 /*
0dd4fc3c
XL
286 * Parse dai->sysclk come from "clocks = <&xxx>"
287 * (if system has common clock)
fa558c28 288 * or "system-clock-frequency = <xxx>"
71467e46 289 * or device's module clock.
fa558c28 290 */
71467e46
XL
291 if (of_property_read_bool(np, "clocks")) {
292 clk = of_clk_get(np, 0);
293 if (IS_ERR(clk)) {
294 ret = PTR_ERR(clk);
e512e001 295 return ret;
71467e46
XL
296 }
297
298 dai->sysclk = clk_get_rate(clk);
f9911803 299 dai->clk = clk;
c7099eb1
JS
300 } else if (!of_property_read_u32(np, "system-clock-frequency", &val)) {
301 dai->sysclk = val;
71467e46 302 } else {
88a60e55 303 clk = of_clk_get(args.np, 0);
e2a19ac6
XL
304 if (!IS_ERR(clk))
305 dai->sysclk = clk_get_rate(clk);
71467e46 306 }
fa558c28 307
e512e001 308 return 0;
fa558c28
KM
309}
310
2d82eeb0 311static int asoc_simple_card_dai_link_of(struct device_node *node,
f531913f 312 struct simple_card_data *priv,
9810f537 313 int idx,
2d82eeb0 314 bool is_top_level_node)
6a91a17b 315{
f531913f 316 struct device *dev = simple_priv_to_dev(priv);
9810f537
KM
317 struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, idx);
318 struct simple_dai_props *dai_props = simple_priv_to_props(priv, idx);
1b5721b2 319 struct device_node *cpu = NULL;
e0ae225b 320 struct device_node *plat = NULL;
1b5721b2 321 struct device_node *codec = NULL;
b3ca11ff
JS
322 char *name;
323 char prop[128];
324 char *prefix = "";
7c7b9cf5 325 int ret, cpu_args;
85a4bfd8 326 u32 val;
6a91a17b 327
2080437d 328 /* For single DAI link & old style of DT node */
64872215 329 if (is_top_level_node)
548563fa 330 prefix = PREFIX;
b3ca11ff 331
b3ca11ff 332 snprintf(prop, sizeof(prop), "%scpu", prefix);
1b5721b2
KM
333 cpu = of_get_child_by_name(node, prop);
334
e0ae225b
JN
335 snprintf(prop, sizeof(prop), "%splat", prefix);
336 plat = of_get_child_by_name(node, prop);
337
1b5721b2
KM
338 snprintf(prop, sizeof(prop), "%scodec", prefix);
339 codec = of_get_child_by_name(node, prop);
340
341 if (!cpu || !codec) {
b3ca11ff 342 ret = -EINVAL;
966b8063 343 dev_err(dev, "%s: Can't find %s DT node\n", __func__, prop);
b3ca11ff 344 goto dai_link_of_err;
6a91a17b 345 }
b3ca11ff 346
cecdef36
KM
347 ret = asoc_simple_card_parse_daifmt(dev, node, codec,
348 prefix, &dai_link->dai_fmt);
1b5721b2
KM
349 if (ret < 0)
350 goto dai_link_of_err;
351
85a4bfd8
AP
352 if (!of_property_read_u32(node, "mclk-fs", &val))
353 dai_props->mclk_fs = val;
354
1b5721b2 355 ret = asoc_simple_card_sub_parse_of(cpu, &dai_props->cpu_dai,
b3ca11ff 356 &dai_link->cpu_of_node,
7c7b9cf5
KM
357 &dai_link->cpu_dai_name,
358 &cpu_args);
6a91a17b 359 if (ret < 0)
b3ca11ff
JS
360 goto dai_link_of_err;
361
1b5721b2 362 ret = asoc_simple_card_sub_parse_of(codec, &dai_props->codec_dai,
b3ca11ff 363 &dai_link->codec_of_node,
7c7b9cf5 364 &dai_link->codec_dai_name, NULL);
b3ca11ff
JS
365 if (ret < 0)
366 goto dai_link_of_err;
367
5fb9cb16
KM
368 ret = asoc_simple_card_sub_parse_of(plat, NULL,
369 &dai_link->platform_of_node,
370 NULL, NULL);
371 if (ret < 0)
372 goto dai_link_of_err;
373
b3ca11ff 374 if (!dai_link->cpu_dai_name || !dai_link->codec_dai_name) {
781cbebe
NC
375 ret = -EINVAL;
376 goto dai_link_of_err;
b3ca11ff
JS
377 }
378
5fb9cb16
KM
379 /* Assumes platform == cpu */
380 if (!dai_link->platform_of_node)
e0ae225b 381 dai_link->platform_of_node = dai_link->cpu_of_node;
b3ca11ff 382
0dd4fc3c 383 /* DAI link name is created from CPU/CODEC dai name */
b3ca11ff
JS
384 name = devm_kzalloc(dev,
385 strlen(dai_link->cpu_dai_name) +
386 strlen(dai_link->codec_dai_name) + 2,
387 GFP_KERNEL);
31f3032c
VT
388 if (!name) {
389 ret = -ENOMEM;
390 goto dai_link_of_err;
391 }
392
b3ca11ff
JS
393 sprintf(name, "%s-%s", dai_link->cpu_dai_name,
394 dai_link->codec_dai_name);
395 dai_link->name = dai_link->stream_name = name;
2942a0e2 396 dai_link->ops = &asoc_simple_card_ops;
a5960bd5 397 dai_link->init = asoc_simple_card_dai_init;
b3ca11ff
JS
398
399 dev_dbg(dev, "\tname : %s\n", dai_link->stream_name);
1efb53a2
LPC
400 dev_dbg(dev, "\tformat : %04x\n", dai_link->dai_fmt);
401 dev_dbg(dev, "\tcpu : %s / %d\n",
b3ca11ff 402 dai_link->cpu_dai_name,
b3ca11ff 403 dai_props->cpu_dai.sysclk);
1efb53a2 404 dev_dbg(dev, "\tcodec : %s / %d\n",
b3ca11ff 405 dai_link->codec_dai_name,
b3ca11ff
JS
406 dai_props->codec_dai.sysclk);
407
179949bc 408 /*
0dd4fc3c
XL
409 * In soc_bind_dai_link() will check cpu name after
410 * of_node matching if dai_link has cpu_dai_name.
411 * but, it will never match if name was created by
412 * fmt_single_name() remove cpu_dai_name if cpu_args
413 * was 0. See:
179949bc
KM
414 * fmt_single_name()
415 * fmt_multiple_name()
416 */
7c7b9cf5
KM
417 if (!cpu_args)
418 dai_link->cpu_dai_name = NULL;
179949bc 419
b3ca11ff 420dai_link_of_err:
1b5721b2
KM
421 of_node_put(cpu);
422 of_node_put(codec);
423
6a91a17b
JFM
424 return ret;
425}
426
fa558c28 427static int asoc_simple_card_parse_of(struct device_node *node,
f531913f 428 struct simple_card_data *priv)
fa558c28 429{
f531913f 430 struct device *dev = simple_priv_to_dev(priv);
c7099eb1 431 u32 val;
d4c22094 432 int ret;
fa558c28 433
2080437d
XL
434 if (!node)
435 return -EINVAL;
436
0dd4fc3c 437 /* Parse the card name from DT */
548563fa 438 snd_soc_of_parse_card_name(&priv->snd_card, PREFIX "name");
2772555b 439
0dd4fc3c 440 /* The off-codec widgets */
548563fa 441 if (of_property_read_bool(node, PREFIX "widgets")) {
9d681f5b 442 ret = snd_soc_of_parse_audio_simple_widgets(&priv->snd_card,
548563fa 443 PREFIX "widgets");
9d681f5b
XL
444 if (ret)
445 return ret;
446 }
447
d4c22094 448 /* DAPM routes */
548563fa 449 if (of_property_read_bool(node, PREFIX "routing")) {
b367a325 450 ret = snd_soc_of_parse_audio_routing(&priv->snd_card,
548563fa 451 PREFIX "routing");
f87a3e82
XL
452 if (ret)
453 return ret;
454 }
d4c22094 455
2942a0e2 456 /* Factor to mclk, used in hw_params() */
548563fa 457 ret = of_property_read_u32(node, PREFIX "mclk-fs", &val);
c7099eb1
JS
458 if (ret == 0)
459 priv->mclk_fs = val;
2942a0e2 460
b3ca11ff
JS
461 dev_dbg(dev, "New simple-card: %s\n", priv->snd_card.name ?
462 priv->snd_card.name : "");
463
2080437d 464 /* Single/Muti DAI link(s) & New style of DT node */
548563fa 465 if (of_get_child_by_name(node, PREFIX "dai-link")) {
b3ca11ff 466 struct device_node *np = NULL;
a44a750e
KM
467 int i = 0;
468
469 for_each_child_of_node(node, np) {
b3ca11ff 470 dev_dbg(dev, "\tlink %d:\n", i);
f531913f 471 ret = asoc_simple_card_dai_link_of(np, priv,
9810f537 472 i, false);
b3ca11ff
JS
473 if (ret < 0) {
474 of_node_put(np);
475 return ret;
476 }
a44a750e 477 i++;
6a91a17b 478 }
b3ca11ff 479 } else {
2080437d 480 /* For single DAI link & old style of DT node */
9810f537 481 ret = asoc_simple_card_dai_link_of(node, priv, 0, true);
6a91a17b 482 if (ret < 0)
b3ca11ff 483 return ret;
6a91a17b 484 }
dd41e0c4 485
2772555b 486 if (!priv->snd_card.name)
b3ca11ff 487 priv->snd_card.name = priv->snd_card.dai_link->name;
f687d900 488
fa558c28
KM
489 return 0;
490}
491
0dd4fc3c 492/* Decrease the reference count of the device nodes */
7ddfdb5c 493static int asoc_simple_card_unref(struct snd_soc_card *card)
e512e001 494{
e512e001 495 struct snd_soc_dai_link *dai_link;
e512e001
JFM
496 int num_links;
497
498 for (num_links = 0, dai_link = card->dai_link;
499 num_links < card->num_links;
500 num_links++, dai_link++) {
0099c762
JFM
501 of_node_put(dai_link->cpu_of_node);
502 of_node_put(dai_link->codec_of_node);
e512e001
JFM
503 }
504 return 0;
505}
506
f2390880
KM
507static int asoc_simple_card_probe(struct platform_device *pdev)
508{
45fce594 509 struct simple_card_data *priv;
5ca8ba41 510 struct snd_soc_dai_link *dai_link;
fa558c28 511 struct device_node *np = pdev->dev.of_node;
f89983ef 512 struct device *dev = &pdev->dev;
2080437d 513 int num_links, ret;
6a91a17b 514
0dd4fc3c 515 /* Get the number of DAI links */
548563fa 516 if (np && of_get_child_by_name(np, PREFIX "dai-link"))
6a91a17b 517 num_links = of_get_child_count(np);
2080437d 518 else
6a91a17b 519 num_links = 1;
f2390880 520
0dd4fc3c 521 /* Allocate the private data and the DAI link array */
cf7dc23c 522 priv = devm_kzalloc(dev,
6a91a17b 523 sizeof(*priv) + sizeof(*dai_link) * num_links,
cf7dc23c 524 GFP_KERNEL);
ca65b492 525 if (!priv)
ca919fe4
XL
526 return -ENOMEM;
527
0dd4fc3c 528 /* Init snd_soc_card */
ca65b492
JFM
529 priv->snd_card.owner = THIS_MODULE;
530 priv->snd_card.dev = dev;
cf7dc23c 531 dai_link = priv->dai_link;
ca65b492 532 priv->snd_card.dai_link = dai_link;
6a91a17b 533 priv->snd_card.num_links = num_links;
201a0eac 534
0dd4fc3c 535 /* Get room for the other properties */
cf7dc23c 536 priv->dai_props = devm_kzalloc(dev,
6a91a17b 537 sizeof(*priv->dai_props) * num_links,
cf7dc23c
JFM
538 GFP_KERNEL);
539 if (!priv->dai_props)
540 return -ENOMEM;
541
fa558c28 542 if (np && of_device_is_available(np)) {
ca919fe4 543
f531913f 544 ret = asoc_simple_card_parse_of(np, priv);
ca919fe4
XL
545 if (ret < 0) {
546 if (ret != -EPROBE_DEFER)
547 dev_err(dev, "parse error %d\n", ret);
e512e001 548 goto err;
fa558c28 549 }
6a91a17b 550
fa558c28 551 } else {
ca65b492
JFM
552 struct asoc_simple_card_info *cinfo;
553
554 cinfo = dev->platform_data;
555 if (!cinfo) {
34787d0a
XL
556 dev_err(dev, "no info for asoc-simple-card\n");
557 return -EINVAL;
558 }
fa558c28 559
781cbebe
NC
560 if (!cinfo->name ||
561 !cinfo->codec_dai.name ||
562 !cinfo->codec ||
563 !cinfo->platform ||
7722f830
JFM
564 !cinfo->cpu_dai.name) {
565 dev_err(dev, "insufficient asoc_simple_card_info settings\n");
566 return -EINVAL;
567 }
2bee9914 568
12ffa6fc 569 priv->snd_card.name = (cinfo->card) ? cinfo->card : cinfo->name;
5ca8ba41
JFM
570 dai_link->name = cinfo->name;
571 dai_link->stream_name = cinfo->name;
572 dai_link->platform_name = cinfo->platform;
573 dai_link->codec_name = cinfo->codec;
52008472
JFM
574 dai_link->cpu_dai_name = cinfo->cpu_dai.name;
575 dai_link->codec_dai_name = cinfo->codec_dai.name;
1efb53a2 576 dai_link->dai_fmt = cinfo->daifmt;
a5960bd5 577 dai_link->init = asoc_simple_card_dai_init;
cf7dc23c
JFM
578 memcpy(&priv->dai_props->cpu_dai, &cinfo->cpu_dai,
579 sizeof(priv->dai_props->cpu_dai));
580 memcpy(&priv->dai_props->codec_dai, &cinfo->codec_dai,
581 sizeof(priv->dai_props->codec_dai));
81985bd6 582
f2390880
KM
583 }
584
ca65b492 585 snd_soc_card_set_drvdata(&priv->snd_card, priv);
f2390880 586
e512e001 587 ret = devm_snd_soc_register_card(&pdev->dev, &priv->snd_card);
e3c4a28b
XL
588 if (ret >= 0)
589 return ret;
e512e001
JFM
590
591err:
7ddfdb5c 592 asoc_simple_card_unref(&priv->snd_card);
e512e001 593 return ret;
f2390880
KM
594}
595
e3c4a28b
XL
596static int asoc_simple_card_remove(struct platform_device *pdev)
597{
3fe24032
DR
598 struct snd_soc_card *card = platform_get_drvdata(pdev);
599 struct simple_card_data *priv = snd_soc_card_get_drvdata(card);
600
9eac3618
KM
601 asoc_simple_card_remove_jack(&priv->hp_jack);
602 asoc_simple_card_remove_jack(&priv->mic_jack);
3fe24032 603
7ddfdb5c 604 return asoc_simple_card_unref(card);
e3c4a28b
XL
605}
606
fa558c28
KM
607static const struct of_device_id asoc_simple_of_match[] = {
608 { .compatible = "simple-audio-card", },
609 {},
610};
611MODULE_DEVICE_TABLE(of, asoc_simple_of_match);
612
f2390880
KM
613static struct platform_driver asoc_simple_card = {
614 .driver = {
781cbebe 615 .name = "asoc-simple-card",
7c376711 616 .pm = &snd_soc_pm_ops,
fa558c28 617 .of_match_table = asoc_simple_of_match,
f2390880 618 },
781cbebe 619 .probe = asoc_simple_card_probe,
e3c4a28b 620 .remove = asoc_simple_card_remove,
f2390880
KM
621};
622
623module_platform_driver(asoc_simple_card);
624
c445be35 625MODULE_ALIAS("platform:asoc-simple-card");
f2390880
KM
626MODULE_LICENSE("GPL");
627MODULE_DESCRIPTION("ASoC Simple Sound Card");
628MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");
This page took 0.516167 seconds and 5 git commands to generate.