tm2_wm5110.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. /*
  2. * Copyright (C) 2015 - 2016 Samsung Electronics Co., Ltd.
  3. *
  4. * Authors: Inha Song <ideal.song@samsung.com>
  5. * Sylwester Nawrocki <s.nawrocki@samsung.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. */
  12. #include <linux/clk.h>
  13. #include <linux/gpio.h>
  14. #include <linux/gpio/consumer.h>
  15. #include <linux/module.h>
  16. #include <linux/of.h>
  17. #include <sound/pcm_params.h>
  18. #include <sound/soc.h>
  19. #include "i2s.h"
  20. #include "../codecs/wm5110.h"
  21. /*
  22. * The source clock is XCLKOUT with its mux set to the external fixed rate
  23. * oscillator (XXTI).
  24. */
  25. #define MCLK_RATE 24000000U
  26. #define TM2_DAI_AIF1 0
  27. #define TM2_DAI_AIF2 1
  28. struct tm2_machine_priv {
  29. struct snd_soc_component *component;
  30. unsigned int sysclk_rate;
  31. struct gpio_desc *gpio_mic_bias;
  32. };
  33. static int tm2_start_sysclk(struct snd_soc_card *card)
  34. {
  35. struct tm2_machine_priv *priv = snd_soc_card_get_drvdata(card);
  36. struct snd_soc_component *component = priv->component;
  37. int ret;
  38. ret = snd_soc_component_set_pll(component, WM5110_FLL1_REFCLK,
  39. ARIZONA_FLL_SRC_MCLK1,
  40. MCLK_RATE,
  41. priv->sysclk_rate);
  42. if (ret < 0) {
  43. dev_err(component->dev, "Failed to set FLL1 source: %d\n", ret);
  44. return ret;
  45. }
  46. ret = snd_soc_component_set_pll(component, WM5110_FLL1,
  47. ARIZONA_FLL_SRC_MCLK1,
  48. MCLK_RATE,
  49. priv->sysclk_rate);
  50. if (ret < 0) {
  51. dev_err(component->dev, "Failed to start FLL1: %d\n", ret);
  52. return ret;
  53. }
  54. ret = snd_soc_component_set_sysclk(component, ARIZONA_CLK_SYSCLK,
  55. ARIZONA_CLK_SRC_FLL1,
  56. priv->sysclk_rate,
  57. SND_SOC_CLOCK_IN);
  58. if (ret < 0) {
  59. dev_err(component->dev, "Failed to set SYSCLK source: %d\n", ret);
  60. return ret;
  61. }
  62. return 0;
  63. }
  64. static int tm2_stop_sysclk(struct snd_soc_card *card)
  65. {
  66. struct tm2_machine_priv *priv = snd_soc_card_get_drvdata(card);
  67. struct snd_soc_component *component = priv->component;
  68. int ret;
  69. ret = snd_soc_component_set_pll(component, WM5110_FLL1, 0, 0, 0);
  70. if (ret < 0) {
  71. dev_err(component->dev, "Failed to stop FLL1: %d\n", ret);
  72. return ret;
  73. }
  74. ret = snd_soc_component_set_sysclk(component, ARIZONA_CLK_SYSCLK,
  75. ARIZONA_CLK_SRC_FLL1, 0, 0);
  76. if (ret < 0) {
  77. dev_err(component->dev, "Failed to stop SYSCLK: %d\n", ret);
  78. return ret;
  79. }
  80. return 0;
  81. }
  82. static int tm2_aif1_hw_params(struct snd_pcm_substream *substream,
  83. struct snd_pcm_hw_params *params)
  84. {
  85. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  86. struct snd_soc_component *component = rtd->codec_dai->component;
  87. struct tm2_machine_priv *priv = snd_soc_card_get_drvdata(rtd->card);
  88. switch (params_rate(params)) {
  89. case 4000:
  90. case 8000:
  91. case 12000:
  92. case 16000:
  93. case 24000:
  94. case 32000:
  95. case 48000:
  96. case 96000:
  97. case 192000:
  98. /* Highest possible SYSCLK frequency: 147.456MHz */
  99. priv->sysclk_rate = 147456000U;
  100. break;
  101. case 11025:
  102. case 22050:
  103. case 44100:
  104. case 88200:
  105. case 176400:
  106. /* Highest possible SYSCLK frequency: 135.4752 MHz */
  107. priv->sysclk_rate = 135475200U;
  108. break;
  109. default:
  110. dev_err(component->dev, "Not supported sample rate: %d\n",
  111. params_rate(params));
  112. return -EINVAL;
  113. }
  114. return tm2_start_sysclk(rtd->card);
  115. }
  116. static struct snd_soc_ops tm2_aif1_ops = {
  117. .hw_params = tm2_aif1_hw_params,
  118. };
  119. static int tm2_aif2_hw_params(struct snd_pcm_substream *substream,
  120. struct snd_pcm_hw_params *params)
  121. {
  122. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  123. struct snd_soc_component *component = rtd->codec_dai->component;
  124. unsigned int asyncclk_rate;
  125. int ret;
  126. switch (params_rate(params)) {
  127. case 8000:
  128. case 12000:
  129. case 16000:
  130. /* Highest possible ASYNCCLK frequency: 49.152MHz */
  131. asyncclk_rate = 49152000U;
  132. break;
  133. case 11025:
  134. /* Highest possible ASYNCCLK frequency: 45.1584 MHz */
  135. asyncclk_rate = 45158400U;
  136. break;
  137. default:
  138. dev_err(component->dev, "Not supported sample rate: %d\n",
  139. params_rate(params));
  140. return -EINVAL;
  141. }
  142. ret = snd_soc_component_set_pll(component, WM5110_FLL2_REFCLK,
  143. ARIZONA_FLL_SRC_MCLK1,
  144. MCLK_RATE,
  145. asyncclk_rate);
  146. if (ret < 0) {
  147. dev_err(component->dev, "Failed to set FLL2 source: %d\n", ret);
  148. return ret;
  149. }
  150. ret = snd_soc_component_set_pll(component, WM5110_FLL2,
  151. ARIZONA_FLL_SRC_MCLK1,
  152. MCLK_RATE,
  153. asyncclk_rate);
  154. if (ret < 0) {
  155. dev_err(component->dev, "Failed to start FLL2: %d\n", ret);
  156. return ret;
  157. }
  158. ret = snd_soc_component_set_sysclk(component, ARIZONA_CLK_ASYNCCLK,
  159. ARIZONA_CLK_SRC_FLL2,
  160. asyncclk_rate,
  161. SND_SOC_CLOCK_IN);
  162. if (ret < 0) {
  163. dev_err(component->dev, "Failed to set ASYNCCLK source: %d\n", ret);
  164. return ret;
  165. }
  166. return 0;
  167. }
  168. static int tm2_aif2_hw_free(struct snd_pcm_substream *substream)
  169. {
  170. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  171. struct snd_soc_component *component = rtd->codec_dai->component;
  172. int ret;
  173. /* disable FLL2 */
  174. ret = snd_soc_component_set_pll(component, WM5110_FLL2, ARIZONA_FLL_SRC_MCLK1,
  175. 0, 0);
  176. if (ret < 0)
  177. dev_err(component->dev, "Failed to stop FLL2: %d\n", ret);
  178. return ret;
  179. }
  180. static struct snd_soc_ops tm2_aif2_ops = {
  181. .hw_params = tm2_aif2_hw_params,
  182. .hw_free = tm2_aif2_hw_free,
  183. };
  184. static int tm2_hdmi_hw_params(struct snd_pcm_substream *substream,
  185. struct snd_pcm_hw_params *params)
  186. {
  187. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  188. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  189. unsigned int bfs;
  190. int bitwidth, ret;
  191. bitwidth = snd_pcm_format_width(params_format(params));
  192. if (bitwidth < 0) {
  193. dev_err(rtd->card->dev, "Invalid bit-width: %d\n", bitwidth);
  194. return bitwidth;
  195. }
  196. switch (bitwidth) {
  197. case 48:
  198. bfs = 64;
  199. break;
  200. case 16:
  201. bfs = 32;
  202. break;
  203. default:
  204. dev_err(rtd->card->dev, "Unsupported bit-width: %d\n", bitwidth);
  205. return -EINVAL;
  206. }
  207. switch (params_rate(params)) {
  208. case 48000:
  209. case 96000:
  210. case 192000:
  211. break;
  212. default:
  213. dev_err(rtd->card->dev, "Unsupported sample rate: %d\n",
  214. params_rate(params));
  215. return -EINVAL;
  216. }
  217. ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_OPCLK,
  218. 0, SAMSUNG_I2S_OPCLK_PCLK);
  219. if (ret < 0)
  220. return ret;
  221. ret = snd_soc_dai_set_clkdiv(cpu_dai, SAMSUNG_I2S_DIV_BCLK, bfs);
  222. if (ret < 0)
  223. return ret;
  224. return 0;
  225. }
  226. static struct snd_soc_ops tm2_hdmi_ops = {
  227. .hw_params = tm2_hdmi_hw_params,
  228. };
  229. static int tm2_mic_bias(struct snd_soc_dapm_widget *w,
  230. struct snd_kcontrol *kcontrol, int event)
  231. {
  232. struct snd_soc_card *card = w->dapm->card;
  233. struct tm2_machine_priv *priv = snd_soc_card_get_drvdata(card);
  234. switch (event) {
  235. case SND_SOC_DAPM_PRE_PMU:
  236. gpiod_set_value_cansleep(priv->gpio_mic_bias, 1);
  237. break;
  238. case SND_SOC_DAPM_POST_PMD:
  239. gpiod_set_value_cansleep(priv->gpio_mic_bias, 0);
  240. break;
  241. }
  242. return 0;
  243. }
  244. static int tm2_set_bias_level(struct snd_soc_card *card,
  245. struct snd_soc_dapm_context *dapm,
  246. enum snd_soc_bias_level level)
  247. {
  248. struct snd_soc_pcm_runtime *rtd;
  249. rtd = snd_soc_get_pcm_runtime(card, card->dai_link[0].name);
  250. if (dapm->dev != rtd->codec_dai->dev)
  251. return 0;
  252. switch (level) {
  253. case SND_SOC_BIAS_STANDBY:
  254. if (card->dapm.bias_level == SND_SOC_BIAS_OFF)
  255. tm2_start_sysclk(card);
  256. break;
  257. case SND_SOC_BIAS_OFF:
  258. tm2_stop_sysclk(card);
  259. break;
  260. default:
  261. break;
  262. }
  263. return 0;
  264. }
  265. static struct snd_soc_aux_dev tm2_speaker_amp_dev;
  266. static int tm2_late_probe(struct snd_soc_card *card)
  267. {
  268. struct tm2_machine_priv *priv = snd_soc_card_get_drvdata(card);
  269. struct snd_soc_dai_link_component dlc = { 0 };
  270. unsigned int ch_map[] = { 0, 1 };
  271. struct snd_soc_dai *amp_pdm_dai;
  272. struct snd_soc_pcm_runtime *rtd;
  273. struct snd_soc_dai *aif1_dai;
  274. struct snd_soc_dai *aif2_dai;
  275. int ret;
  276. rtd = snd_soc_get_pcm_runtime(card, card->dai_link[TM2_DAI_AIF1].name);
  277. aif1_dai = rtd->codec_dai;
  278. priv->component = rtd->codec_dai->component;
  279. ret = snd_soc_dai_set_sysclk(aif1_dai, ARIZONA_CLK_SYSCLK, 0, 0);
  280. if (ret < 0) {
  281. dev_err(aif1_dai->dev, "Failed to set SYSCLK: %d\n", ret);
  282. return ret;
  283. }
  284. rtd = snd_soc_get_pcm_runtime(card, card->dai_link[TM2_DAI_AIF2].name);
  285. aif2_dai = rtd->codec_dai;
  286. ret = snd_soc_dai_set_sysclk(aif2_dai, ARIZONA_CLK_ASYNCCLK, 0, 0);
  287. if (ret < 0) {
  288. dev_err(aif2_dai->dev, "Failed to set ASYNCCLK: %d\n", ret);
  289. return ret;
  290. }
  291. dlc.of_node = tm2_speaker_amp_dev.codec_of_node;
  292. amp_pdm_dai = snd_soc_find_dai(&dlc);
  293. if (!amp_pdm_dai)
  294. return -ENODEV;
  295. /* Set the MAX98504 V/I sense PDM Tx DAI channel mapping */
  296. ret = snd_soc_dai_set_channel_map(amp_pdm_dai, ARRAY_SIZE(ch_map),
  297. ch_map, 0, NULL);
  298. if (ret < 0)
  299. return ret;
  300. ret = snd_soc_dai_set_tdm_slot(amp_pdm_dai, 0x3, 0x0, 2, 16);
  301. if (ret < 0)
  302. return ret;
  303. return 0;
  304. }
  305. static const struct snd_kcontrol_new tm2_controls[] = {
  306. SOC_DAPM_PIN_SWITCH("HP"),
  307. SOC_DAPM_PIN_SWITCH("SPK"),
  308. SOC_DAPM_PIN_SWITCH("RCV"),
  309. SOC_DAPM_PIN_SWITCH("VPS"),
  310. SOC_DAPM_PIN_SWITCH("HDMI"),
  311. SOC_DAPM_PIN_SWITCH("Main Mic"),
  312. SOC_DAPM_PIN_SWITCH("Sub Mic"),
  313. SOC_DAPM_PIN_SWITCH("Third Mic"),
  314. SOC_DAPM_PIN_SWITCH("Headset Mic"),
  315. };
  316. static const struct snd_soc_dapm_widget tm2_dapm_widgets[] = {
  317. SND_SOC_DAPM_HP("HP", NULL),
  318. SND_SOC_DAPM_SPK("SPK", NULL),
  319. SND_SOC_DAPM_SPK("RCV", NULL),
  320. SND_SOC_DAPM_LINE("VPS", NULL),
  321. SND_SOC_DAPM_LINE("HDMI", NULL),
  322. SND_SOC_DAPM_MIC("Main Mic", tm2_mic_bias),
  323. SND_SOC_DAPM_MIC("Sub Mic", NULL),
  324. SND_SOC_DAPM_MIC("Third Mic", NULL),
  325. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  326. };
  327. static const struct snd_soc_component_driver tm2_component = {
  328. .name = "tm2-audio",
  329. };
  330. static struct snd_soc_dai_driver tm2_ext_dai[] = {
  331. {
  332. .name = "Voice call",
  333. .playback = {
  334. .channels_min = 1,
  335. .channels_max = 4,
  336. .rate_min = 8000,
  337. .rate_max = 48000,
  338. .rates = (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |
  339. SNDRV_PCM_RATE_48000),
  340. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  341. },
  342. .capture = {
  343. .channels_min = 1,
  344. .channels_max = 4,
  345. .rate_min = 8000,
  346. .rate_max = 48000,
  347. .rates = (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |
  348. SNDRV_PCM_RATE_48000),
  349. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  350. },
  351. },
  352. {
  353. .name = "Bluetooth",
  354. .playback = {
  355. .channels_min = 1,
  356. .channels_max = 4,
  357. .rate_min = 8000,
  358. .rate_max = 16000,
  359. .rates = (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000),
  360. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  361. },
  362. .capture = {
  363. .channels_min = 1,
  364. .channels_max = 2,
  365. .rate_min = 8000,
  366. .rate_max = 16000,
  367. .rates = (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000),
  368. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  369. },
  370. },
  371. };
  372. static struct snd_soc_dai_link tm2_dai_links[] = {
  373. {
  374. .name = "WM5110 AIF1",
  375. .stream_name = "HiFi Primary",
  376. .cpu_dai_name = SAMSUNG_I2S_DAI,
  377. .codec_dai_name = "wm5110-aif1",
  378. .ops = &tm2_aif1_ops,
  379. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  380. SND_SOC_DAIFMT_CBM_CFM,
  381. }, {
  382. .name = "WM5110 Voice",
  383. .stream_name = "Voice call",
  384. .cpu_dai_name = SAMSUNG_I2S_DAI,
  385. .codec_dai_name = "wm5110-aif2",
  386. .ops = &tm2_aif2_ops,
  387. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  388. SND_SOC_DAIFMT_CBM_CFM,
  389. .ignore_suspend = 1,
  390. }, {
  391. .name = "WM5110 BT",
  392. .stream_name = "Bluetooth",
  393. .cpu_dai_name = SAMSUNG_I2S_DAI,
  394. .codec_dai_name = "wm5110-aif3",
  395. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  396. SND_SOC_DAIFMT_CBM_CFM,
  397. .ignore_suspend = 1,
  398. }, {
  399. .name = "HDMI",
  400. .stream_name = "i2s1",
  401. .ops = &tm2_hdmi_ops,
  402. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  403. SND_SOC_DAIFMT_CBS_CFS,
  404. }
  405. };
  406. static struct snd_soc_card tm2_card = {
  407. .owner = THIS_MODULE,
  408. .dai_link = tm2_dai_links,
  409. .controls = tm2_controls,
  410. .num_controls = ARRAY_SIZE(tm2_controls),
  411. .dapm_widgets = tm2_dapm_widgets,
  412. .num_dapm_widgets = ARRAY_SIZE(tm2_dapm_widgets),
  413. .aux_dev = &tm2_speaker_amp_dev,
  414. .num_aux_devs = 1,
  415. .late_probe = tm2_late_probe,
  416. .set_bias_level = tm2_set_bias_level,
  417. };
  418. static int tm2_probe(struct platform_device *pdev)
  419. {
  420. struct device_node *cpu_dai_node[2] = {};
  421. struct device_node *codec_dai_node[2] = {};
  422. const char *cells_name = NULL;
  423. struct device *dev = &pdev->dev;
  424. struct snd_soc_card *card = &tm2_card;
  425. struct tm2_machine_priv *priv;
  426. struct of_phandle_args args;
  427. int num_codecs, ret, i;
  428. priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  429. if (!priv)
  430. return -ENOMEM;
  431. snd_soc_card_set_drvdata(card, priv);
  432. card->dev = dev;
  433. priv->gpio_mic_bias = devm_gpiod_get(dev, "mic-bias", GPIOD_OUT_HIGH);
  434. if (IS_ERR(priv->gpio_mic_bias)) {
  435. dev_err(dev, "Failed to get mic bias gpio\n");
  436. return PTR_ERR(priv->gpio_mic_bias);
  437. }
  438. ret = snd_soc_of_parse_card_name(card, "model");
  439. if (ret < 0) {
  440. dev_err(dev, "Card name is not specified\n");
  441. return ret;
  442. }
  443. ret = snd_soc_of_parse_audio_routing(card, "samsung,audio-routing");
  444. if (ret < 0) {
  445. dev_err(dev, "Audio routing is not specified or invalid\n");
  446. return ret;
  447. }
  448. card->aux_dev[0].codec_of_node = of_parse_phandle(dev->of_node,
  449. "audio-amplifier", 0);
  450. if (!card->aux_dev[0].codec_of_node) {
  451. dev_err(dev, "audio-amplifier property invalid or missing\n");
  452. return -EINVAL;
  453. }
  454. num_codecs = of_count_phandle_with_args(dev->of_node, "audio-codec",
  455. NULL);
  456. /* Skip the HDMI link if not specified in DT */
  457. if (num_codecs > 1) {
  458. card->num_links = ARRAY_SIZE(tm2_dai_links);
  459. cells_name = "#sound-dai-cells";
  460. } else {
  461. card->num_links = ARRAY_SIZE(tm2_dai_links) - 1;
  462. }
  463. for (i = 0; i < num_codecs; i++) {
  464. struct of_phandle_args args;
  465. ret = of_parse_phandle_with_args(dev->of_node, "i2s-controller",
  466. cells_name, i, &args);
  467. if (ret) {
  468. dev_err(dev, "i2s-controller property parse error: %d\n", i);
  469. ret = -EINVAL;
  470. goto dai_node_put;
  471. }
  472. cpu_dai_node[i] = args.np;
  473. codec_dai_node[i] = of_parse_phandle(dev->of_node,
  474. "audio-codec", i);
  475. if (!codec_dai_node[i]) {
  476. dev_err(dev, "audio-codec property parse error\n");
  477. ret = -EINVAL;
  478. goto dai_node_put;
  479. }
  480. }
  481. /* Initialize WM5110 - I2S and HDMI - I2S1 DAI links */
  482. for (i = 0; i < card->num_links; i++) {
  483. unsigned int dai_index = 0; /* WM5110 */
  484. card->dai_link[i].cpu_name = NULL;
  485. card->dai_link[i].platform_name = NULL;
  486. if (num_codecs > 1 && i == card->num_links - 1)
  487. dai_index = 1; /* HDMI */
  488. card->dai_link[i].codec_of_node = codec_dai_node[dai_index];
  489. card->dai_link[i].cpu_of_node = cpu_dai_node[dai_index];
  490. card->dai_link[i].platform_of_node = cpu_dai_node[dai_index];
  491. }
  492. if (num_codecs > 1) {
  493. /* HDMI DAI link (I2S1) */
  494. i = card->num_links - 1;
  495. ret = of_parse_phandle_with_fixed_args(dev->of_node,
  496. "audio-codec", 0, 1, &args);
  497. if (ret) {
  498. dev_err(dev, "audio-codec property parse error\n");
  499. goto dai_node_put;
  500. }
  501. ret = snd_soc_get_dai_name(&args, &card->dai_link[i].codec_dai_name);
  502. if (ret) {
  503. dev_err(dev, "Unable to get codec_dai_name\n");
  504. goto dai_node_put;
  505. }
  506. }
  507. ret = devm_snd_soc_register_component(dev, &tm2_component,
  508. tm2_ext_dai, ARRAY_SIZE(tm2_ext_dai));
  509. if (ret < 0) {
  510. dev_err(dev, "Failed to register component: %d\n", ret);
  511. goto dai_node_put;
  512. }
  513. ret = devm_snd_soc_register_card(dev, card);
  514. if (ret < 0) {
  515. dev_err(dev, "Failed to register card: %d\n", ret);
  516. goto dai_node_put;
  517. }
  518. dai_node_put:
  519. for (i = 0; i < num_codecs; i++) {
  520. of_node_put(codec_dai_node[i]);
  521. of_node_put(cpu_dai_node[i]);
  522. }
  523. of_node_put(card->aux_dev[0].codec_of_node);
  524. return ret;
  525. }
  526. static int tm2_pm_prepare(struct device *dev)
  527. {
  528. struct snd_soc_card *card = dev_get_drvdata(dev);
  529. return tm2_stop_sysclk(card);
  530. }
  531. static void tm2_pm_complete(struct device *dev)
  532. {
  533. struct snd_soc_card *card = dev_get_drvdata(dev);
  534. tm2_start_sysclk(card);
  535. }
  536. static const struct dev_pm_ops tm2_pm_ops = {
  537. .prepare = tm2_pm_prepare,
  538. .suspend = snd_soc_suspend,
  539. .resume = snd_soc_resume,
  540. .complete = tm2_pm_complete,
  541. .freeze = snd_soc_suspend,
  542. .thaw = snd_soc_resume,
  543. .poweroff = snd_soc_poweroff,
  544. .restore = snd_soc_resume,
  545. };
  546. static const struct of_device_id tm2_of_match[] = {
  547. { .compatible = "samsung,tm2-audio" },
  548. { },
  549. };
  550. MODULE_DEVICE_TABLE(of, tm2_of_match);
  551. static struct platform_driver tm2_driver = {
  552. .driver = {
  553. .name = "tm2-audio",
  554. .pm = &tm2_pm_ops,
  555. .of_match_table = tm2_of_match,
  556. },
  557. .probe = tm2_probe,
  558. };
  559. module_platform_driver(tm2_driver);
  560. MODULE_AUTHOR("Inha Song <ideal.song@samsung.com>");
  561. MODULE_DESCRIPTION("ALSA SoC Exynos TM2 Audio Support");
  562. MODULE_LICENSE("GPL v2");