wm8960-soundcard.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. // SPDX-License-Identifier: GPL-2.0
  2. //
  3. // ASoC simple sound card support
  4. //
  5. // Copyright (C) 2012 Renesas Solutions Corp.
  6. // Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  7. #include <linux/clk.h>
  8. #include <linux/device.h>
  9. #include <linux/module.h>
  10. #include <linux/of.h>
  11. #include <linux/of_device.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/string.h>
  14. #include <sound/simple_card.h>
  15. #include <sound/soc-dai.h>
  16. #include <sound/soc.h>
  17. #define DPCM_SELECTABLE 1
  18. #define DAI "sound-dai"
  19. #define CELL "#sound-dai-cells"
  20. #define PREFIX "simple-audio-card,"
  21. static const struct snd_soc_ops simple_ops = {
  22. .startup = asoc_simple_startup,
  23. .shutdown = asoc_simple_shutdown,
  24. .hw_params = asoc_simple_hw_params,
  25. };
  26. static int asoc_simple_parse_dai(struct device_node *node,
  27. struct snd_soc_dai_link_component *dlc,
  28. int *is_single_link)
  29. {
  30. struct of_phandle_args args;
  31. int ret;
  32. if (!node)
  33. return 0;
  34. /*
  35. * Get node via "sound-dai = <&phandle port>"
  36. * it will be used as xxx_of_node on soc_bind_dai_link()
  37. */
  38. ret = of_parse_phandle_with_args(node, DAI, CELL, 0, &args);
  39. if (ret)
  40. return ret;
  41. /*
  42. * FIXME
  43. *
  44. * Here, dlc->dai_name is pointer to CPU/Codec DAI name.
  45. * If user unbinded CPU or Codec driver, but not for Sound Card,
  46. * dlc->dai_name is keeping unbinded CPU or Codec
  47. * driver's pointer.
  48. *
  49. * If user re-bind CPU or Codec driver again, ALSA SoC will try
  50. * to rebind Card via snd_soc_try_rebind_card(), but because of
  51. * above reason, it might can't bind Sound Card.
  52. * Because Sound Card is pointing to released dai_name pointer.
  53. *
  54. * To avoid this rebind Card issue,
  55. * 1) It needs to alloc memory to keep dai_name eventhough
  56. * CPU or Codec driver was unbinded, or
  57. * 2) user need to rebind Sound Card everytime
  58. * if he unbinded CPU or Codec.
  59. */
  60. ret = snd_soc_of_get_dai_name(node, &dlc->dai_name);
  61. if (ret < 0)
  62. return ret;
  63. dlc->of_node = args.np;
  64. if (is_single_link)
  65. *is_single_link = !args.args_count;
  66. return 0;
  67. }
  68. static void simple_parse_convert(struct device *dev,
  69. struct device_node *np,
  70. struct asoc_simple_data *adata)
  71. {
  72. struct device_node *top = dev->of_node;
  73. struct device_node *node = of_get_parent(np);
  74. asoc_simple_parse_convert(dev, top, PREFIX, adata);
  75. asoc_simple_parse_convert(dev, node, PREFIX, adata);
  76. asoc_simple_parse_convert(dev, node, NULL, adata);
  77. asoc_simple_parse_convert(dev, np, NULL, adata);
  78. of_node_put(node);
  79. }
  80. static void simple_parse_mclk_fs(struct device_node *top,
  81. struct device_node *cpu,
  82. struct device_node *codec,
  83. struct simple_dai_props *props,
  84. char *prefix)
  85. {
  86. struct device_node *node = of_get_parent(cpu);
  87. char prop[128];
  88. snprintf(prop, sizeof(prop), "%smclk-fs", PREFIX);
  89. of_property_read_u32(top, prop, &props->mclk_fs);
  90. snprintf(prop, sizeof(prop), "%smclk-fs", prefix);
  91. of_property_read_u32(node, prop, &props->mclk_fs);
  92. of_property_read_u32(cpu, prop, &props->mclk_fs);
  93. of_property_read_u32(codec, prop, &props->mclk_fs);
  94. of_node_put(node);
  95. }
  96. static int simple_dai_link_of_dpcm(struct asoc_simple_priv *priv,
  97. struct device_node *np,
  98. struct device_node *codec,
  99. struct link_info *li,
  100. bool is_top)
  101. {
  102. struct device *dev = simple_priv_to_dev(priv);
  103. struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link);
  104. struct simple_dai_props *dai_props = simple_priv_to_props(priv, li->link);
  105. struct asoc_simple_dai *dai;
  106. struct snd_soc_dai_link_component *cpus = dai_link->cpus;
  107. struct snd_soc_dai_link_component *codecs = dai_link->codecs;
  108. struct device_node *top = dev->of_node;
  109. struct device_node *node = of_get_parent(np);
  110. char *prefix = "";
  111. int ret;
  112. /*
  113. * |CPU |Codec : turn
  114. * CPU |Pass |return
  115. * Codec |return|Pass
  116. * np
  117. */
  118. if (li->cpu == (np == codec))
  119. return 0;
  120. dev_dbg(dev, "link_of DPCM (%pOF)\n", np);
  121. li->link++;
  122. /* For single DAI link & old style of DT node */
  123. if (is_top)
  124. prefix = PREFIX;
  125. if (li->cpu) {
  126. int is_single_links = 0;
  127. /* BE is dummy */
  128. codecs->of_node = NULL;
  129. codecs->dai_name = "snd-soc-dummy-dai";
  130. codecs->name = "snd-soc-dummy";
  131. /* FE settings */
  132. dai_link->dynamic = 1;
  133. dai_link->dpcm_merged_format = 1;
  134. dai =
  135. dai_props->cpu_dai = &priv->dais[li->dais++];
  136. ret = asoc_simple_parse_cpu(np, dai_link, &is_single_links);
  137. if (ret)
  138. goto out_put_node;
  139. ret = asoc_simple_parse_clk_cpu(dev, np, dai_link, dai);
  140. if (ret < 0)
  141. goto out_put_node;
  142. ret = asoc_simple_set_dailink_name(dev, dai_link,
  143. "fe.%s",
  144. cpus->dai_name);
  145. if (ret < 0)
  146. goto out_put_node;
  147. asoc_simple_canonicalize_cpu(dai_link, is_single_links);
  148. } else {
  149. struct snd_soc_codec_conf *cconf;
  150. /* FE is dummy */
  151. cpus->of_node = NULL;
  152. cpus->dai_name = "snd-soc-dummy-dai";
  153. cpus->name = "snd-soc-dummy";
  154. /* BE settings */
  155. dai_link->no_pcm = 1;
  156. dai_link->be_hw_params_fixup = asoc_simple_be_hw_params_fixup;
  157. dai =
  158. dai_props->codec_dai = &priv->dais[li->dais++];
  159. cconf =
  160. dai_props->codec_conf = &priv->codec_conf[li->conf++];
  161. ret = asoc_simple_parse_codec(np, dai_link);
  162. if (ret < 0)
  163. goto out_put_node;
  164. ret = asoc_simple_parse_clk_codec(dev, np, dai_link, dai);
  165. if (ret < 0)
  166. goto out_put_node;
  167. ret = asoc_simple_set_dailink_name(dev, dai_link,
  168. "be.%s",
  169. codecs->dai_name);
  170. if (ret < 0)
  171. goto out_put_node;
  172. /* check "prefix" from top node */
  173. snd_soc_of_parse_node_prefix(top, cconf, codecs->of_node,
  174. PREFIX "prefix");
  175. snd_soc_of_parse_node_prefix(node, cconf, codecs->of_node,
  176. "prefix");
  177. snd_soc_of_parse_node_prefix(np, cconf, codecs->of_node,
  178. "prefix");
  179. }
  180. simple_parse_convert(dev, np, &dai_props->adata);
  181. simple_parse_mclk_fs(top, np, codec, dai_props, prefix);
  182. asoc_simple_canonicalize_platform(dai_link);
  183. ret = asoc_simple_parse_tdm(np, dai);
  184. if (ret)
  185. goto out_put_node;
  186. ret = asoc_simple_parse_daifmt(dev, node, codec,
  187. prefix, &dai_link->dai_fmt);
  188. if (ret < 0)
  189. goto out_put_node;
  190. dai_link->dpcm_playback = 1;
  191. dai_link->dpcm_capture = 1;
  192. dai_link->ops = &simple_ops;
  193. dai_link->init = asoc_simple_dai_init;
  194. out_put_node:
  195. of_node_put(node);
  196. return ret;
  197. }
  198. static int simple_dai_link_of(struct asoc_simple_priv *priv,
  199. struct device_node *np,
  200. struct device_node *codec,
  201. struct link_info *li,
  202. bool is_top)
  203. {
  204. struct device *dev = simple_priv_to_dev(priv);
  205. struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link);
  206. struct simple_dai_props *dai_props = simple_priv_to_props(priv, li->link);
  207. struct asoc_simple_dai *cpu_dai;
  208. struct asoc_simple_dai *codec_dai;
  209. struct device_node *top = dev->of_node;
  210. struct device_node *cpu = NULL;
  211. struct device_node *node = NULL;
  212. struct device_node *plat = NULL;
  213. char prop[128];
  214. char *prefix = "";
  215. int ret, single_cpu;
  216. /*
  217. * |CPU |Codec : turn
  218. * CPU |Pass |return
  219. * Codec |return|return
  220. * np
  221. */
  222. if (!li->cpu || np == codec)
  223. return 0;
  224. cpu = np;
  225. node = of_get_parent(np);
  226. li->link++;
  227. dev_dbg(dev, "link_of (%pOF)\n", node);
  228. /* For single DAI link & old style of DT node */
  229. if (is_top)
  230. prefix = PREFIX;
  231. snprintf(prop, sizeof(prop), "%splat", prefix);
  232. plat = of_get_child_by_name(node, prop);
  233. cpu_dai =
  234. dai_props->cpu_dai = &priv->dais[li->dais++];
  235. codec_dai =
  236. dai_props->codec_dai = &priv->dais[li->dais++];
  237. ret = asoc_simple_parse_daifmt(dev, node, codec,
  238. prefix, &dai_link->dai_fmt);
  239. if (ret < 0)
  240. goto dai_link_of_err;
  241. simple_parse_mclk_fs(top, cpu, codec, dai_props, prefix);
  242. ret = asoc_simple_parse_cpu(cpu, dai_link, &single_cpu);
  243. if (ret < 0)
  244. goto dai_link_of_err;
  245. ret = asoc_simple_parse_codec(codec, dai_link);
  246. if (ret < 0)
  247. goto dai_link_of_err;
  248. ret = asoc_simple_parse_platform(plat, dai_link);
  249. if (ret < 0)
  250. goto dai_link_of_err;
  251. ret = asoc_simple_parse_tdm(cpu, cpu_dai);
  252. if (ret < 0)
  253. goto dai_link_of_err;
  254. ret = asoc_simple_parse_tdm(codec, codec_dai);
  255. if (ret < 0)
  256. goto dai_link_of_err;
  257. ret = asoc_simple_parse_clk_cpu(dev, cpu, dai_link, cpu_dai);
  258. if (ret < 0)
  259. goto dai_link_of_err;
  260. ret = asoc_simple_parse_clk_codec(dev, codec, dai_link, codec_dai);
  261. if (ret < 0)
  262. goto dai_link_of_err;
  263. ret = asoc_simple_set_dailink_name(dev, dai_link,
  264. "%s-%s",
  265. dai_link->cpus->dai_name,
  266. dai_link->codecs->dai_name);
  267. if (ret < 0)
  268. goto dai_link_of_err;
  269. dai_link->ops = &simple_ops;
  270. dai_link->init = asoc_simple_dai_init;
  271. asoc_simple_canonicalize_cpu(dai_link, single_cpu);
  272. asoc_simple_canonicalize_platform(dai_link);
  273. dai_link_of_err:
  274. of_node_put(plat);
  275. of_node_put(node);
  276. return ret;
  277. }
  278. static int simple_for_each_link(struct asoc_simple_priv *priv,
  279. struct link_info *li,
  280. int (*func_noml)(struct asoc_simple_priv *priv,
  281. struct device_node *np,
  282. struct device_node *codec,
  283. struct link_info *li, bool is_top),
  284. int (*func_dpcm)(struct asoc_simple_priv *priv,
  285. struct device_node *np,
  286. struct device_node *codec,
  287. struct link_info *li, bool is_top))
  288. {
  289. struct device *dev = simple_priv_to_dev(priv);
  290. struct device_node *top = dev->of_node;
  291. struct device_node *node;
  292. uintptr_t dpcm_selectable = (uintptr_t)of_device_get_match_data(dev);
  293. bool is_top = 0;
  294. int ret = 0;
  295. /* Check if it has dai-link */
  296. node = of_get_child_by_name(top, PREFIX "dai-link");
  297. if (!node) {
  298. node = of_node_get(top);
  299. is_top = 1;
  300. }
  301. /* loop for all dai-link */
  302. do {
  303. struct asoc_simple_data adata;
  304. struct device_node *codec;
  305. struct device_node *np;
  306. int num = of_get_child_count(node);
  307. /* get codec */
  308. codec = of_get_child_by_name(node, is_top ?
  309. PREFIX "codec" : "codec");
  310. if (!codec) {
  311. ret = -ENODEV;
  312. goto error;
  313. }
  314. /* get convert-xxx property */
  315. memset(&adata, 0, sizeof(adata));
  316. for_each_child_of_node(node, np)
  317. simple_parse_convert(dev, np, &adata);
  318. /* loop for all CPU/Codec node */
  319. for_each_child_of_node(node, np) {
  320. /*
  321. * It is DPCM
  322. * if it has many CPUs,
  323. * or has convert-xxx property
  324. */
  325. if (dpcm_selectable &&
  326. (num > 2 ||
  327. adata.convert_rate || adata.convert_channels))
  328. ret = func_dpcm(priv, np, codec, li, is_top);
  329. /* else normal sound */
  330. else
  331. ret = func_noml(priv, np, codec, li, is_top);
  332. if (ret < 0) {
  333. of_node_put(codec);
  334. of_node_put(np);
  335. goto error;
  336. }
  337. }
  338. of_node_put(codec);
  339. node = of_get_next_child(top, node);
  340. } while (!is_top && node);
  341. error:
  342. of_node_put(node);
  343. return ret;
  344. }
  345. static int simple_parse_aux_devs(struct device_node *node,
  346. struct asoc_simple_priv *priv)
  347. {
  348. struct device *dev = simple_priv_to_dev(priv);
  349. struct device_node *aux_node;
  350. struct snd_soc_card *card = simple_priv_to_card(priv);
  351. int i, n, len;
  352. if (!of_find_property(node, PREFIX "aux-devs", &len))
  353. return 0; /* Ok to have no aux-devs */
  354. n = len / sizeof(__be32);
  355. if (n <= 0)
  356. return -EINVAL;
  357. card->aux_dev = devm_kcalloc(dev,
  358. n, sizeof(*card->aux_dev), GFP_KERNEL);
  359. if (!card->aux_dev)
  360. return -ENOMEM;
  361. for (i = 0; i < n; i++) {
  362. aux_node = of_parse_phandle(node, PREFIX "aux-devs", i);
  363. if (!aux_node)
  364. return -EINVAL;
  365. card->aux_dev[i].dlc.of_node = aux_node;
  366. }
  367. card->num_aux_devs = n;
  368. return 0;
  369. }
  370. static int simple_parse_of(struct asoc_simple_priv *priv)
  371. {
  372. struct device *dev = simple_priv_to_dev(priv);
  373. struct device_node *top = dev->of_node;
  374. struct snd_soc_card *card = simple_priv_to_card(priv);
  375. struct link_info li;
  376. int ret;
  377. if (!top)
  378. return -EINVAL;
  379. ret = asoc_simple_parse_widgets(card, PREFIX);
  380. if (ret < 0)
  381. return ret;
  382. ret = asoc_simple_parse_routing(card, PREFIX);
  383. if (ret < 0)
  384. return ret;
  385. ret = asoc_simple_parse_pin_switches(card, PREFIX);
  386. if (ret < 0)
  387. return ret;
  388. /* Single/Muti DAI link(s) & New style of DT node */
  389. memset(&li, 0, sizeof(li));
  390. for (li.cpu = 1; li.cpu >= 0; li.cpu--) {
  391. /*
  392. * Detect all CPU first, and Detect all Codec 2nd.
  393. *
  394. * In Normal sound case, all DAIs are detected
  395. * as "CPU-Codec".
  396. *
  397. * In DPCM sound case,
  398. * all CPUs are detected as "CPU-dummy", and
  399. * all Codecs are detected as "dummy-Codec".
  400. * To avoid random sub-device numbering,
  401. * detect "dummy-Codec" in last;
  402. */
  403. ret = simple_for_each_link(priv, &li,
  404. simple_dai_link_of,
  405. simple_dai_link_of_dpcm);
  406. if (ret < 0)
  407. return ret;
  408. }
  409. ret = asoc_simple_parse_card_name(card, PREFIX);
  410. if (ret < 0)
  411. return ret;
  412. ret = simple_parse_aux_devs(top, priv);
  413. return ret;
  414. }
  415. static int simple_count_noml(struct asoc_simple_priv *priv,
  416. struct device_node *np,
  417. struct device_node *codec,
  418. struct link_info *li, bool is_top)
  419. {
  420. li->dais++; /* CPU or Codec */
  421. if (np != codec)
  422. li->link++; /* CPU-Codec */
  423. return 0;
  424. }
  425. static int simple_count_dpcm(struct asoc_simple_priv *priv,
  426. struct device_node *np,
  427. struct device_node *codec,
  428. struct link_info *li, bool is_top)
  429. {
  430. li->dais++; /* CPU or Codec */
  431. li->link++; /* CPU-dummy or dummy-Codec */
  432. if (np == codec)
  433. li->conf++;
  434. return 0;
  435. }
  436. static void simple_get_dais_count(struct asoc_simple_priv *priv,
  437. struct link_info *li)
  438. {
  439. struct device *dev = simple_priv_to_dev(priv);
  440. struct device_node *top = dev->of_node;
  441. /*
  442. * link_num : number of links.
  443. * CPU-Codec / CPU-dummy / dummy-Codec
  444. * dais_num : number of DAIs
  445. * ccnf_num : number of codec_conf
  446. * same number for "dummy-Codec"
  447. *
  448. * ex1)
  449. * CPU0 --- Codec0 link : 5
  450. * CPU1 --- Codec1 dais : 7
  451. * CPU2 -/ ccnf : 1
  452. * CPU3 --- Codec2
  453. *
  454. * => 5 links = 2xCPU-Codec + 2xCPU-dummy + 1xdummy-Codec
  455. * => 7 DAIs = 4xCPU + 3xCodec
  456. * => 1 ccnf = 1xdummy-Codec
  457. *
  458. * ex2)
  459. * CPU0 --- Codec0 link : 5
  460. * CPU1 --- Codec1 dais : 6
  461. * CPU2 -/ ccnf : 1
  462. * CPU3 -/
  463. *
  464. * => 5 links = 1xCPU-Codec + 3xCPU-dummy + 1xdummy-Codec
  465. * => 6 DAIs = 4xCPU + 2xCodec
  466. * => 1 ccnf = 1xdummy-Codec
  467. *
  468. * ex3)
  469. * CPU0 --- Codec0 link : 6
  470. * CPU1 -/ dais : 6
  471. * CPU2 --- Codec1 ccnf : 2
  472. * CPU3 -/
  473. *
  474. * => 6 links = 0xCPU-Codec + 4xCPU-dummy + 2xdummy-Codec
  475. * => 6 DAIs = 4xCPU + 2xCodec
  476. * => 2 ccnf = 2xdummy-Codec
  477. *
  478. * ex4)
  479. * CPU0 --- Codec0 (convert-rate) link : 3
  480. * CPU1 --- Codec1 dais : 4
  481. * ccnf : 1
  482. *
  483. * => 3 links = 1xCPU-Codec + 1xCPU-dummy + 1xdummy-Codec
  484. * => 4 DAIs = 2xCPU + 2xCodec
  485. * => 1 ccnf = 1xdummy-Codec
  486. */
  487. if (!top) {
  488. li->link = 1;
  489. li->dais = 2;
  490. li->conf = 0;
  491. return;
  492. }
  493. simple_for_each_link(priv, li,
  494. simple_count_noml,
  495. simple_count_dpcm);
  496. dev_dbg(dev, "link %d, dais %d, ccnf %d\n",
  497. li->link, li->dais, li->conf);
  498. }
  499. static int simple_soc_probe(struct snd_soc_card *card)
  500. {
  501. struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(card);
  502. int ret;
  503. ret = asoc_simple_init_hp(card, &priv->hp_jack, PREFIX);
  504. if (ret < 0)
  505. return ret;
  506. ret = asoc_simple_init_mic(card, &priv->mic_jack, PREFIX);
  507. if (ret < 0)
  508. return ret;
  509. return 0;
  510. }
  511. static int asoc_simple_probe(struct platform_device *pdev)
  512. {
  513. struct asoc_simple_priv *priv;
  514. struct device *dev = &pdev->dev;
  515. struct device_node *np = dev->of_node;
  516. struct snd_soc_card *card;
  517. struct link_info li;
  518. int ret;
  519. /* Allocate the private data and the DAI link array */
  520. priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  521. if (!priv)
  522. return -ENOMEM;
  523. card = simple_priv_to_card(priv);
  524. card->owner = THIS_MODULE;
  525. card->dev = dev;
  526. card->probe = simple_soc_probe;
  527. memset(&li, 0, sizeof(li));
  528. simple_get_dais_count(priv, &li);
  529. if (!li.link || !li.dais)
  530. return -EINVAL;
  531. ret = asoc_simple_init_priv(priv, &li);
  532. if (ret < 0)
  533. return ret;
  534. if (np && of_device_is_available(np)) {
  535. ret = simple_parse_of(priv);
  536. if (ret < 0) {
  537. if (ret != -EPROBE_DEFER)
  538. dev_err(dev, "parse error %d\n", ret);
  539. goto err;
  540. }
  541. } else {
  542. struct asoc_simple_card_info *cinfo;
  543. struct snd_soc_dai_link_component *cpus;
  544. struct snd_soc_dai_link_component *codecs;
  545. struct snd_soc_dai_link_component *platform;
  546. struct snd_soc_dai_link *dai_link = priv->dai_link;
  547. struct simple_dai_props *dai_props = priv->dai_props;
  548. int dai_idx = 0;
  549. cinfo = dev->platform_data;
  550. if (!cinfo) {
  551. dev_err(dev, "no info for asoc-simple-card\n");
  552. return -EINVAL;
  553. }
  554. if (!cinfo->name ||
  555. !cinfo->codec_dai.name ||
  556. !cinfo->codec ||
  557. !cinfo->platform ||
  558. !cinfo->cpu_dai.name) {
  559. dev_err(dev, "insufficient asoc_simple_card_info settings\n");
  560. return -EINVAL;
  561. }
  562. dai_props->cpu_dai = &priv->dais[dai_idx++];
  563. dai_props->codec_dai = &priv->dais[dai_idx++];
  564. cpus = dai_link->cpus;
  565. cpus->dai_name = cinfo->cpu_dai.name;
  566. codecs = dai_link->codecs;
  567. codecs->name = cinfo->codec;
  568. codecs->dai_name = cinfo->codec_dai.name;
  569. platform = dai_link->platforms;
  570. platform->name = cinfo->platform;
  571. card->name = (cinfo->card) ? cinfo->card : cinfo->name;
  572. dai_link->name = cinfo->name;
  573. dai_link->stream_name = cinfo->name;
  574. dai_link->dai_fmt = cinfo->daifmt;
  575. dai_link->init = asoc_simple_dai_init;
  576. memcpy(dai_props->cpu_dai, &cinfo->cpu_dai,
  577. sizeof(*dai_props->cpu_dai));
  578. memcpy(dai_props->codec_dai, &cinfo->codec_dai,
  579. sizeof(*dai_props->codec_dai));
  580. }
  581. snd_soc_card_set_drvdata(card, priv);
  582. asoc_simple_debug_info(priv);
  583. ret = devm_snd_soc_register_card(dev, card);
  584. if (ret < 0)
  585. goto err;
  586. return 0;
  587. err:
  588. asoc_simple_clean_reference(card);
  589. return ret;
  590. }
  591. static int asoc_simple_remove(struct platform_device *pdev)
  592. {
  593. struct snd_soc_card *card = platform_get_drvdata(pdev);
  594. return asoc_simple_clean_reference(card);
  595. }
  596. static const struct of_device_id simple_of_match[] = {
  597. { .compatible = "simple-audio-card", },
  598. { .compatible = "simple-scu-audio-card",
  599. .data = (void *)DPCM_SELECTABLE },
  600. {},
  601. };
  602. MODULE_DEVICE_TABLE(of, simple_of_match);
  603. static struct platform_driver asoc_simple_card = {
  604. .driver = {
  605. .name = "asoc-simple-card",
  606. .pm = &snd_soc_pm_ops,
  607. .of_match_table = simple_of_match,
  608. },
  609. .probe = asoc_simple_probe,
  610. .remove = asoc_simple_remove,
  611. };
  612. module_platform_driver(asoc_simple_card);
  613. MODULE_ALIAS("platform:asoc-simple-card");
  614. MODULE_LICENSE("GPL v2");
  615. MODULE_DESCRIPTION("ASoC wm8960 Sound Card");
  616. MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");