simple-card.c 18 KB

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