fsl-asoc-card.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. /*
  2. * Freescale Generic ASoC Sound Card driver with ASRC
  3. *
  4. * Copyright (C) 2014 Freescale Semiconductor, Inc.
  5. *
  6. * Author: Nicolin Chen <nicoleotsuka@gmail.com>
  7. *
  8. * This file is licensed under the terms of the GNU General Public License
  9. * version 2. This program is licensed "as is" without any warranty of any
  10. * kind, whether express or implied.
  11. */
  12. #include <linux/clk.h>
  13. #include <linux/i2c.h>
  14. #include <linux/module.h>
  15. #include <linux/of_platform.h>
  16. #include <sound/pcm_params.h>
  17. #include <sound/soc.h>
  18. #include "fsl_esai.h"
  19. #include "fsl_sai.h"
  20. #include "imx-audmux.h"
  21. #include "../codecs/sgtl5000.h"
  22. #include "../codecs/wm8962.h"
  23. #include "../codecs/wm8960.h"
  24. #define RX 0
  25. #define TX 1
  26. /* Default DAI format without Master and Slave flag */
  27. #define DAI_FMT_BASE (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF)
  28. /**
  29. * CODEC private data
  30. *
  31. * @mclk_freq: Clock rate of MCLK
  32. * @mclk_id: MCLK (or main clock) id for set_sysclk()
  33. * @fll_id: FLL (or secordary clock) id for set_sysclk()
  34. * @pll_id: PLL id for set_pll()
  35. */
  36. struct codec_priv {
  37. unsigned long mclk_freq;
  38. u32 mclk_id;
  39. u32 fll_id;
  40. u32 pll_id;
  41. };
  42. /**
  43. * CPU private data
  44. *
  45. * @sysclk_freq[2]: SYSCLK rates for set_sysclk()
  46. * @sysclk_dir[2]: SYSCLK directions for set_sysclk()
  47. * @sysclk_id[2]: SYSCLK ids for set_sysclk()
  48. * @slot_width: Slot width of each frame
  49. *
  50. * Note: [1] for tx and [0] for rx
  51. */
  52. struct cpu_priv {
  53. unsigned long sysclk_freq[2];
  54. u32 sysclk_dir[2];
  55. u32 sysclk_id[2];
  56. u32 slot_width;
  57. };
  58. /**
  59. * Freescale Generic ASOC card private data
  60. *
  61. * @dai_link[3]: DAI link structure including normal one and DPCM link
  62. * @pdev: platform device pointer
  63. * @codec_priv: CODEC private data
  64. * @cpu_priv: CPU private data
  65. * @card: ASoC card structure
  66. * @sample_rate: Current sample rate
  67. * @sample_format: Current sample format
  68. * @asrc_rate: ASRC sample rate used by Back-Ends
  69. * @asrc_format: ASRC sample format used by Back-Ends
  70. * @dai_fmt: DAI format between CPU and CODEC
  71. * @name: Card name
  72. */
  73. struct fsl_asoc_card_priv {
  74. struct snd_soc_dai_link dai_link[3];
  75. struct platform_device *pdev;
  76. struct codec_priv codec_priv;
  77. struct cpu_priv cpu_priv;
  78. struct snd_soc_card card;
  79. u32 sample_rate;
  80. u32 sample_format;
  81. u32 asrc_rate;
  82. u32 asrc_format;
  83. u32 dai_fmt;
  84. char name[32];
  85. };
  86. /**
  87. * This dapm route map exsits for DPCM link only.
  88. * The other routes shall go through Device Tree.
  89. */
  90. static const struct snd_soc_dapm_route audio_map[] = {
  91. {"CPU-Playback", NULL, "ASRC-Playback"},
  92. {"Playback", NULL, "CPU-Playback"},
  93. {"ASRC-Capture", NULL, "CPU-Capture"},
  94. {"CPU-Capture", NULL, "Capture"},
  95. };
  96. /* Add all possible widgets into here without being redundant */
  97. static const struct snd_soc_dapm_widget fsl_asoc_card_dapm_widgets[] = {
  98. SND_SOC_DAPM_LINE("Line Out Jack", NULL),
  99. SND_SOC_DAPM_LINE("Line In Jack", NULL),
  100. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  101. SND_SOC_DAPM_SPK("Ext Spk", NULL),
  102. SND_SOC_DAPM_MIC("Mic Jack", NULL),
  103. SND_SOC_DAPM_MIC("AMIC", NULL),
  104. SND_SOC_DAPM_MIC("DMIC", NULL),
  105. };
  106. static int fsl_asoc_card_hw_params(struct snd_pcm_substream *substream,
  107. struct snd_pcm_hw_params *params)
  108. {
  109. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  110. struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card);
  111. bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
  112. struct cpu_priv *cpu_priv = &priv->cpu_priv;
  113. struct device *dev = rtd->card->dev;
  114. int ret;
  115. priv->sample_rate = params_rate(params);
  116. priv->sample_format = params_format(params);
  117. /*
  118. * If codec-dai is DAI Master and all configurations are already in the
  119. * set_bias_level(), bypass the remaining settings in hw_params().
  120. * Note: (dai_fmt & CBM_CFM) includes CBM_CFM and CBM_CFS.
  121. */
  122. if (priv->card.set_bias_level && priv->dai_fmt & SND_SOC_DAIFMT_CBM_CFM)
  123. return 0;
  124. /* Specific configurations of DAIs starts from here */
  125. ret = snd_soc_dai_set_sysclk(rtd->cpu_dai, cpu_priv->sysclk_id[tx],
  126. cpu_priv->sysclk_freq[tx],
  127. cpu_priv->sysclk_dir[tx]);
  128. if (ret) {
  129. dev_err(dev, "failed to set sysclk for cpu dai\n");
  130. return ret;
  131. }
  132. if (cpu_priv->slot_width) {
  133. ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2,
  134. cpu_priv->slot_width);
  135. if (ret) {
  136. dev_err(dev, "failed to set TDM slot for cpu dai\n");
  137. return ret;
  138. }
  139. }
  140. return 0;
  141. }
  142. static struct snd_soc_ops fsl_asoc_card_ops = {
  143. .hw_params = fsl_asoc_card_hw_params,
  144. };
  145. static int be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
  146. struct snd_pcm_hw_params *params)
  147. {
  148. struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card);
  149. struct snd_interval *rate;
  150. struct snd_mask *mask;
  151. rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
  152. rate->max = rate->min = priv->asrc_rate;
  153. mask = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
  154. snd_mask_none(mask);
  155. snd_mask_set(mask, priv->asrc_format);
  156. return 0;
  157. }
  158. static struct snd_soc_dai_link fsl_asoc_card_dai[] = {
  159. /* Default ASoC DAI Link*/
  160. {
  161. .name = "HiFi",
  162. .stream_name = "HiFi",
  163. .ops = &fsl_asoc_card_ops,
  164. },
  165. /* DPCM Link between Front-End and Back-End (Optional) */
  166. {
  167. .name = "HiFi-ASRC-FE",
  168. .stream_name = "HiFi-ASRC-FE",
  169. .codec_name = "snd-soc-dummy",
  170. .codec_dai_name = "snd-soc-dummy-dai",
  171. .dpcm_playback = 1,
  172. .dpcm_capture = 1,
  173. .dynamic = 1,
  174. },
  175. {
  176. .name = "HiFi-ASRC-BE",
  177. .stream_name = "HiFi-ASRC-BE",
  178. .platform_name = "snd-soc-dummy",
  179. .be_hw_params_fixup = be_hw_params_fixup,
  180. .ops = &fsl_asoc_card_ops,
  181. .dpcm_playback = 1,
  182. .dpcm_capture = 1,
  183. .no_pcm = 1,
  184. },
  185. };
  186. static int fsl_asoc_card_set_bias_level(struct snd_soc_card *card,
  187. struct snd_soc_dapm_context *dapm,
  188. enum snd_soc_bias_level level)
  189. {
  190. struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(card);
  191. struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
  192. struct codec_priv *codec_priv = &priv->codec_priv;
  193. struct device *dev = card->dev;
  194. unsigned int pll_out;
  195. int ret;
  196. if (dapm->dev != codec_dai->dev)
  197. return 0;
  198. switch (level) {
  199. case SND_SOC_BIAS_PREPARE:
  200. if (dapm->bias_level != SND_SOC_BIAS_STANDBY)
  201. break;
  202. if (priv->sample_format == SNDRV_PCM_FORMAT_S24_LE)
  203. pll_out = priv->sample_rate * 384;
  204. else
  205. pll_out = priv->sample_rate * 256;
  206. ret = snd_soc_dai_set_pll(codec_dai, codec_priv->pll_id,
  207. codec_priv->mclk_id,
  208. codec_priv->mclk_freq, pll_out);
  209. if (ret) {
  210. dev_err(dev, "failed to start FLL: %d\n", ret);
  211. return ret;
  212. }
  213. ret = snd_soc_dai_set_sysclk(codec_dai, codec_priv->fll_id,
  214. pll_out, SND_SOC_CLOCK_IN);
  215. if (ret) {
  216. dev_err(dev, "failed to set SYSCLK: %d\n", ret);
  217. return ret;
  218. }
  219. break;
  220. case SND_SOC_BIAS_STANDBY:
  221. if (dapm->bias_level != SND_SOC_BIAS_PREPARE)
  222. break;
  223. ret = snd_soc_dai_set_sysclk(codec_dai, codec_priv->mclk_id,
  224. codec_priv->mclk_freq,
  225. SND_SOC_CLOCK_IN);
  226. if (ret) {
  227. dev_err(dev, "failed to switch away from FLL: %d\n", ret);
  228. return ret;
  229. }
  230. ret = snd_soc_dai_set_pll(codec_dai, codec_priv->pll_id, 0, 0, 0);
  231. if (ret) {
  232. dev_err(dev, "failed to stop FLL: %d\n", ret);
  233. return ret;
  234. }
  235. break;
  236. default:
  237. break;
  238. }
  239. return 0;
  240. }
  241. static int fsl_asoc_card_audmux_init(struct device_node *np,
  242. struct fsl_asoc_card_priv *priv)
  243. {
  244. struct device *dev = &priv->pdev->dev;
  245. u32 int_ptcr = 0, ext_ptcr = 0;
  246. int int_port, ext_port;
  247. int ret;
  248. ret = of_property_read_u32(np, "mux-int-port", &int_port);
  249. if (ret) {
  250. dev_err(dev, "mux-int-port missing or invalid\n");
  251. return ret;
  252. }
  253. ret = of_property_read_u32(np, "mux-ext-port", &ext_port);
  254. if (ret) {
  255. dev_err(dev, "mux-ext-port missing or invalid\n");
  256. return ret;
  257. }
  258. /*
  259. * The port numbering in the hardware manual starts at 1, while
  260. * the AUDMUX API expects it starts at 0.
  261. */
  262. int_port--;
  263. ext_port--;
  264. /*
  265. * Use asynchronous mode (6 wires) for all cases.
  266. * If only 4 wires are needed, just set SSI into
  267. * synchronous mode and enable 4 PADs in IOMUX.
  268. */
  269. switch (priv->dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  270. case SND_SOC_DAIFMT_CBM_CFM:
  271. int_ptcr = IMX_AUDMUX_V2_PTCR_RFSEL(8 | ext_port) |
  272. IMX_AUDMUX_V2_PTCR_RCSEL(8 | ext_port) |
  273. IMX_AUDMUX_V2_PTCR_TFSEL(ext_port) |
  274. IMX_AUDMUX_V2_PTCR_TCSEL(ext_port) |
  275. IMX_AUDMUX_V2_PTCR_RFSDIR |
  276. IMX_AUDMUX_V2_PTCR_RCLKDIR |
  277. IMX_AUDMUX_V2_PTCR_TFSDIR |
  278. IMX_AUDMUX_V2_PTCR_TCLKDIR;
  279. break;
  280. case SND_SOC_DAIFMT_CBM_CFS:
  281. int_ptcr = IMX_AUDMUX_V2_PTCR_RCSEL(8 | ext_port) |
  282. IMX_AUDMUX_V2_PTCR_TCSEL(ext_port) |
  283. IMX_AUDMUX_V2_PTCR_RCLKDIR |
  284. IMX_AUDMUX_V2_PTCR_TCLKDIR;
  285. ext_ptcr = IMX_AUDMUX_V2_PTCR_RFSEL(8 | int_port) |
  286. IMX_AUDMUX_V2_PTCR_TFSEL(int_port) |
  287. IMX_AUDMUX_V2_PTCR_RFSDIR |
  288. IMX_AUDMUX_V2_PTCR_TFSDIR;
  289. break;
  290. case SND_SOC_DAIFMT_CBS_CFM:
  291. int_ptcr = IMX_AUDMUX_V2_PTCR_RFSEL(8 | ext_port) |
  292. IMX_AUDMUX_V2_PTCR_TFSEL(ext_port) |
  293. IMX_AUDMUX_V2_PTCR_RFSDIR |
  294. IMX_AUDMUX_V2_PTCR_TFSDIR;
  295. ext_ptcr = IMX_AUDMUX_V2_PTCR_RCSEL(8 | int_port) |
  296. IMX_AUDMUX_V2_PTCR_TCSEL(int_port) |
  297. IMX_AUDMUX_V2_PTCR_RCLKDIR |
  298. IMX_AUDMUX_V2_PTCR_TCLKDIR;
  299. break;
  300. case SND_SOC_DAIFMT_CBS_CFS:
  301. ext_ptcr = IMX_AUDMUX_V2_PTCR_RFSEL(8 | int_port) |
  302. IMX_AUDMUX_V2_PTCR_RCSEL(8 | int_port) |
  303. IMX_AUDMUX_V2_PTCR_TFSEL(int_port) |
  304. IMX_AUDMUX_V2_PTCR_TCSEL(int_port) |
  305. IMX_AUDMUX_V2_PTCR_RFSDIR |
  306. IMX_AUDMUX_V2_PTCR_RCLKDIR |
  307. IMX_AUDMUX_V2_PTCR_TFSDIR |
  308. IMX_AUDMUX_V2_PTCR_TCLKDIR;
  309. break;
  310. default:
  311. return -EINVAL;
  312. }
  313. /* Asynchronous mode can not be set along with RCLKDIR */
  314. ret = imx_audmux_v2_configure_port(int_port, 0,
  315. IMX_AUDMUX_V2_PDCR_RXDSEL(ext_port));
  316. if (ret) {
  317. dev_err(dev, "audmux internal port setup failed\n");
  318. return ret;
  319. }
  320. ret = imx_audmux_v2_configure_port(int_port, int_ptcr,
  321. IMX_AUDMUX_V2_PDCR_RXDSEL(ext_port));
  322. if (ret) {
  323. dev_err(dev, "audmux internal port setup failed\n");
  324. return ret;
  325. }
  326. ret = imx_audmux_v2_configure_port(ext_port, 0,
  327. IMX_AUDMUX_V2_PDCR_RXDSEL(int_port));
  328. if (ret) {
  329. dev_err(dev, "audmux external port setup failed\n");
  330. return ret;
  331. }
  332. ret = imx_audmux_v2_configure_port(ext_port, ext_ptcr,
  333. IMX_AUDMUX_V2_PDCR_RXDSEL(int_port));
  334. if (ret) {
  335. dev_err(dev, "audmux external port setup failed\n");
  336. return ret;
  337. }
  338. return 0;
  339. }
  340. static int fsl_asoc_card_late_probe(struct snd_soc_card *card)
  341. {
  342. struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(card);
  343. struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
  344. struct codec_priv *codec_priv = &priv->codec_priv;
  345. struct device *dev = card->dev;
  346. int ret;
  347. ret = snd_soc_dai_set_sysclk(codec_dai, codec_priv->mclk_id,
  348. codec_priv->mclk_freq, SND_SOC_CLOCK_IN);
  349. if (ret) {
  350. dev_err(dev, "failed to set sysclk in %s\n", __func__);
  351. return ret;
  352. }
  353. return 0;
  354. }
  355. static int fsl_asoc_card_probe(struct platform_device *pdev)
  356. {
  357. struct device_node *cpu_np, *codec_np, *asrc_np;
  358. struct device_node *np = pdev->dev.of_node;
  359. struct platform_device *asrc_pdev = NULL;
  360. struct platform_device *cpu_pdev;
  361. struct fsl_asoc_card_priv *priv;
  362. struct i2c_client *codec_dev;
  363. struct clk *codec_clk;
  364. const char *codec_dai_name;
  365. u32 width;
  366. int ret;
  367. priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
  368. if (!priv)
  369. return -ENOMEM;
  370. cpu_np = of_parse_phandle(np, "audio-cpu", 0);
  371. /* Give a chance to old DT binding */
  372. if (!cpu_np)
  373. cpu_np = of_parse_phandle(np, "ssi-controller", 0);
  374. codec_np = of_parse_phandle(np, "audio-codec", 0);
  375. if (!cpu_np || !codec_np) {
  376. dev_err(&pdev->dev, "phandle missing or invalid\n");
  377. ret = -EINVAL;
  378. goto fail;
  379. }
  380. cpu_pdev = of_find_device_by_node(cpu_np);
  381. if (!cpu_pdev) {
  382. dev_err(&pdev->dev, "failed to find CPU DAI device\n");
  383. ret = -EINVAL;
  384. goto fail;
  385. }
  386. codec_dev = of_find_i2c_device_by_node(codec_np);
  387. if (!codec_dev) {
  388. dev_err(&pdev->dev, "failed to find codec platform device\n");
  389. ret = -EINVAL;
  390. goto fail;
  391. }
  392. asrc_np = of_parse_phandle(np, "audio-asrc", 0);
  393. if (asrc_np)
  394. asrc_pdev = of_find_device_by_node(asrc_np);
  395. /* Get the MCLK rate only, and leave it controlled by CODEC drivers */
  396. codec_clk = clk_get(&codec_dev->dev, NULL);
  397. if (!IS_ERR(codec_clk)) {
  398. priv->codec_priv.mclk_freq = clk_get_rate(codec_clk);
  399. clk_put(codec_clk);
  400. }
  401. /* Default sample rate and format, will be updated in hw_params() */
  402. priv->sample_rate = 44100;
  403. priv->sample_format = SNDRV_PCM_FORMAT_S16_LE;
  404. /* Assign a default DAI format, and allow each card to overwrite it */
  405. priv->dai_fmt = DAI_FMT_BASE;
  406. /* Diversify the card configurations */
  407. if (of_device_is_compatible(np, "fsl,imx-audio-cs42888")) {
  408. codec_dai_name = "cs42888";
  409. priv->card.set_bias_level = NULL;
  410. priv->cpu_priv.sysclk_freq[TX] = priv->codec_priv.mclk_freq;
  411. priv->cpu_priv.sysclk_freq[RX] = priv->codec_priv.mclk_freq;
  412. priv->cpu_priv.sysclk_dir[TX] = SND_SOC_CLOCK_OUT;
  413. priv->cpu_priv.sysclk_dir[RX] = SND_SOC_CLOCK_OUT;
  414. priv->cpu_priv.slot_width = 32;
  415. priv->dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
  416. } else if (of_device_is_compatible(np, "fsl,imx-audio-sgtl5000")) {
  417. codec_dai_name = "sgtl5000";
  418. priv->codec_priv.mclk_id = SGTL5000_SYSCLK;
  419. priv->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
  420. } else if (of_device_is_compatible(np, "fsl,imx-audio-wm8962")) {
  421. codec_dai_name = "wm8962";
  422. priv->card.set_bias_level = fsl_asoc_card_set_bias_level;
  423. priv->codec_priv.mclk_id = WM8962_SYSCLK_MCLK;
  424. priv->codec_priv.fll_id = WM8962_SYSCLK_FLL;
  425. priv->codec_priv.pll_id = WM8962_FLL;
  426. priv->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
  427. } else if (of_device_is_compatible(np, "fsl,imx-audio-wm8960")) {
  428. codec_dai_name = "wm8960-hifi";
  429. priv->card.set_bias_level = fsl_asoc_card_set_bias_level;
  430. priv->codec_priv.fll_id = WM8960_SYSCLK_AUTO;
  431. priv->codec_priv.pll_id = WM8960_SYSCLK_AUTO;
  432. priv->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
  433. } else {
  434. dev_err(&pdev->dev, "unknown Device Tree compatible\n");
  435. ret = -EINVAL;
  436. goto asrc_fail;
  437. }
  438. /* Common settings for corresponding Freescale CPU DAI driver */
  439. if (strstr(cpu_np->name, "ssi")) {
  440. /* Only SSI needs to configure AUDMUX */
  441. ret = fsl_asoc_card_audmux_init(np, priv);
  442. if (ret) {
  443. dev_err(&pdev->dev, "failed to init audmux\n");
  444. goto asrc_fail;
  445. }
  446. } else if (strstr(cpu_np->name, "esai")) {
  447. priv->cpu_priv.sysclk_id[1] = ESAI_HCKT_EXTAL;
  448. priv->cpu_priv.sysclk_id[0] = ESAI_HCKR_EXTAL;
  449. } else if (strstr(cpu_np->name, "sai")) {
  450. priv->cpu_priv.sysclk_id[1] = FSL_SAI_CLK_MAST1;
  451. priv->cpu_priv.sysclk_id[0] = FSL_SAI_CLK_MAST1;
  452. }
  453. sprintf(priv->name, "%s-audio", codec_dev->name);
  454. /* Initialize sound card */
  455. priv->pdev = pdev;
  456. priv->card.dev = &pdev->dev;
  457. priv->card.name = priv->name;
  458. priv->card.dai_link = priv->dai_link;
  459. priv->card.dapm_routes = audio_map;
  460. priv->card.late_probe = fsl_asoc_card_late_probe;
  461. priv->card.num_dapm_routes = ARRAY_SIZE(audio_map);
  462. priv->card.dapm_widgets = fsl_asoc_card_dapm_widgets;
  463. priv->card.num_dapm_widgets = ARRAY_SIZE(fsl_asoc_card_dapm_widgets);
  464. memcpy(priv->dai_link, fsl_asoc_card_dai,
  465. sizeof(struct snd_soc_dai_link) * ARRAY_SIZE(priv->dai_link));
  466. ret = snd_soc_of_parse_audio_routing(&priv->card, "audio-routing");
  467. if (ret) {
  468. dev_err(&pdev->dev, "failed to parse audio-routing: %d\n", ret);
  469. goto asrc_fail;
  470. }
  471. /* Normal DAI Link */
  472. priv->dai_link[0].cpu_of_node = cpu_np;
  473. priv->dai_link[0].codec_of_node = codec_np;
  474. priv->dai_link[0].codec_dai_name = codec_dai_name;
  475. priv->dai_link[0].platform_of_node = cpu_np;
  476. priv->dai_link[0].dai_fmt = priv->dai_fmt;
  477. priv->card.num_links = 1;
  478. if (asrc_pdev) {
  479. /* DPCM DAI Links only if ASRC exsits */
  480. priv->dai_link[1].cpu_of_node = asrc_np;
  481. priv->dai_link[1].platform_of_node = asrc_np;
  482. priv->dai_link[2].codec_dai_name = codec_dai_name;
  483. priv->dai_link[2].codec_of_node = codec_np;
  484. priv->dai_link[2].cpu_of_node = cpu_np;
  485. priv->dai_link[2].dai_fmt = priv->dai_fmt;
  486. priv->card.num_links = 3;
  487. ret = of_property_read_u32(asrc_np, "fsl,asrc-rate",
  488. &priv->asrc_rate);
  489. if (ret) {
  490. dev_err(&pdev->dev, "failed to get output rate\n");
  491. ret = -EINVAL;
  492. goto asrc_fail;
  493. }
  494. ret = of_property_read_u32(asrc_np, "fsl,asrc-width", &width);
  495. if (ret) {
  496. dev_err(&pdev->dev, "failed to get output rate\n");
  497. ret = -EINVAL;
  498. goto asrc_fail;
  499. }
  500. if (width == 24)
  501. priv->asrc_format = SNDRV_PCM_FORMAT_S24_LE;
  502. else
  503. priv->asrc_format = SNDRV_PCM_FORMAT_S16_LE;
  504. }
  505. /* Finish card registering */
  506. platform_set_drvdata(pdev, priv);
  507. snd_soc_card_set_drvdata(&priv->card, priv);
  508. ret = devm_snd_soc_register_card(&pdev->dev, &priv->card);
  509. if (ret)
  510. dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
  511. asrc_fail:
  512. of_node_put(asrc_np);
  513. fail:
  514. of_node_put(codec_np);
  515. of_node_put(cpu_np);
  516. return ret;
  517. }
  518. static const struct of_device_id fsl_asoc_card_dt_ids[] = {
  519. { .compatible = "fsl,imx-audio-cs42888", },
  520. { .compatible = "fsl,imx-audio-sgtl5000", },
  521. { .compatible = "fsl,imx-audio-wm8962", },
  522. { .compatible = "fsl,imx-audio-wm8960", },
  523. {}
  524. };
  525. static struct platform_driver fsl_asoc_card_driver = {
  526. .probe = fsl_asoc_card_probe,
  527. .driver = {
  528. .name = "fsl-asoc-card",
  529. .pm = &snd_soc_pm_ops,
  530. .of_match_table = fsl_asoc_card_dt_ids,
  531. },
  532. };
  533. module_platform_driver(fsl_asoc_card_driver);
  534. MODULE_DESCRIPTION("Freescale Generic ASoC Sound Card driver with ASRC");
  535. MODULE_AUTHOR("Nicolin Chen <nicoleotsuka@gmail.com>");
  536. MODULE_ALIAS("platform:fsl-asoc-card");
  537. MODULE_LICENSE("GPL");