rk3399_gru_sound.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Rockchip machine ASoC driver for boards using MAX98357A/RT5514/DA7219
  4. *
  5. * Copyright (c) 2016, ROCKCHIP CORPORATION. All rights reserved.
  6. */
  7. #include <linux/module.h>
  8. #include <linux/platform_device.h>
  9. #include <linux/slab.h>
  10. #include <linux/gpio.h>
  11. #include <linux/of_gpio.h>
  12. #include <linux/delay.h>
  13. #include <linux/spi/spi.h>
  14. #include <linux/i2c.h>
  15. #include <linux/input.h>
  16. #include <sound/core.h>
  17. #include <sound/jack.h>
  18. #include <sound/pcm.h>
  19. #include <sound/pcm_params.h>
  20. #include <sound/soc.h>
  21. #include "rockchip_i2s.h"
  22. #include "../codecs/da7219.h"
  23. #include "../codecs/da7219-aad.h"
  24. #include "../codecs/rt5514.h"
  25. #define DRV_NAME "rk3399-gru-sound"
  26. #define SOUND_FS 256
  27. static unsigned int dmic_wakeup_delay;
  28. static struct snd_soc_jack rockchip_sound_jack;
  29. /* Headset jack detection DAPM pins */
  30. static struct snd_soc_jack_pin rockchip_sound_jack_pins[] = {
  31. {
  32. .pin = "Headphones",
  33. .mask = SND_JACK_HEADPHONE,
  34. },
  35. {
  36. .pin = "Headset Mic",
  37. .mask = SND_JACK_MICROPHONE,
  38. },
  39. };
  40. static const struct snd_soc_dapm_widget rockchip_dapm_widgets[] = {
  41. SND_SOC_DAPM_HP("Headphones", NULL),
  42. SND_SOC_DAPM_SPK("Speakers", NULL),
  43. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  44. SND_SOC_DAPM_MIC("Int Mic", NULL),
  45. SND_SOC_DAPM_LINE("HDMI", NULL),
  46. };
  47. static const struct snd_kcontrol_new rockchip_controls[] = {
  48. SOC_DAPM_PIN_SWITCH("Headphones"),
  49. SOC_DAPM_PIN_SWITCH("Speakers"),
  50. SOC_DAPM_PIN_SWITCH("Headset Mic"),
  51. SOC_DAPM_PIN_SWITCH("Int Mic"),
  52. SOC_DAPM_PIN_SWITCH("HDMI"),
  53. };
  54. static int rockchip_sound_max98357a_hw_params(struct snd_pcm_substream *substream,
  55. struct snd_pcm_hw_params *params)
  56. {
  57. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  58. unsigned int mclk;
  59. int ret;
  60. mclk = params_rate(params) * SOUND_FS;
  61. ret = snd_soc_dai_set_sysclk(asoc_rtd_to_cpu(rtd, 0), 0, mclk, 0);
  62. if (ret) {
  63. dev_err(rtd->card->dev, "%s() error setting sysclk to %u: %d\n",
  64. __func__, mclk, ret);
  65. return ret;
  66. }
  67. return 0;
  68. }
  69. static int rockchip_sound_rt5514_hw_params(struct snd_pcm_substream *substream,
  70. struct snd_pcm_hw_params *params)
  71. {
  72. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  73. struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
  74. struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
  75. unsigned int mclk;
  76. int ret;
  77. mclk = params_rate(params) * SOUND_FS;
  78. ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk,
  79. SND_SOC_CLOCK_OUT);
  80. if (ret < 0) {
  81. dev_err(rtd->card->dev, "Can't set cpu clock out %d\n", ret);
  82. return ret;
  83. }
  84. ret = snd_soc_dai_set_sysclk(codec_dai, RT5514_SCLK_S_MCLK,
  85. mclk, SND_SOC_CLOCK_IN);
  86. if (ret) {
  87. dev_err(rtd->card->dev, "%s() error setting sysclk to %u: %d\n",
  88. __func__, params_rate(params) * 512, ret);
  89. return ret;
  90. }
  91. /* Wait for DMIC stable */
  92. msleep(dmic_wakeup_delay);
  93. return 0;
  94. }
  95. static int rockchip_sound_da7219_hw_params(struct snd_pcm_substream *substream,
  96. struct snd_pcm_hw_params *params)
  97. {
  98. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  99. struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
  100. struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
  101. int mclk, ret;
  102. /* in bypass mode, the mclk has to be one of the frequencies below */
  103. switch (params_rate(params)) {
  104. case 8000:
  105. case 16000:
  106. case 24000:
  107. case 32000:
  108. case 48000:
  109. case 64000:
  110. case 96000:
  111. mclk = 12288000;
  112. break;
  113. case 11025:
  114. case 22050:
  115. case 44100:
  116. case 88200:
  117. mclk = 11289600;
  118. break;
  119. default:
  120. return -EINVAL;
  121. }
  122. ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk,
  123. SND_SOC_CLOCK_OUT);
  124. if (ret < 0) {
  125. dev_err(codec_dai->dev, "Can't set cpu clock out %d\n", ret);
  126. return ret;
  127. }
  128. ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
  129. SND_SOC_CLOCK_IN);
  130. if (ret < 0) {
  131. dev_err(codec_dai->dev, "Can't set codec clock in %d\n", ret);
  132. return ret;
  133. }
  134. ret = snd_soc_dai_set_pll(codec_dai, 0, DA7219_SYSCLK_MCLK, 0, 0);
  135. if (ret < 0) {
  136. dev_err(codec_dai->dev, "Can't set pll sysclk mclk %d\n", ret);
  137. return ret;
  138. }
  139. return 0;
  140. }
  141. static struct snd_soc_jack cdn_dp_card_jack;
  142. static int rockchip_sound_cdndp_init(struct snd_soc_pcm_runtime *rtd)
  143. {
  144. struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
  145. struct snd_soc_card *card = rtd->card;
  146. int ret;
  147. /* Enable jack detection. */
  148. ret = snd_soc_card_jack_new(card, "DP Jack", SND_JACK_LINEOUT,
  149. &cdn_dp_card_jack);
  150. if (ret) {
  151. dev_err(card->dev, "Can't create DP Jack %d\n", ret);
  152. return ret;
  153. }
  154. return snd_soc_component_set_jack(component, &cdn_dp_card_jack, NULL);
  155. }
  156. static int rockchip_sound_da7219_init(struct snd_soc_pcm_runtime *rtd)
  157. {
  158. struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
  159. struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
  160. int ret;
  161. /* We need default MCLK and PLL settings for the accessory detection */
  162. ret = snd_soc_dai_set_sysclk(codec_dai, 0, 12288000,
  163. SND_SOC_CLOCK_IN);
  164. if (ret < 0) {
  165. dev_err(codec_dai->dev, "Init can't set codec clock in %d\n", ret);
  166. return ret;
  167. }
  168. ret = snd_soc_dai_set_pll(codec_dai, 0, DA7219_SYSCLK_MCLK, 0, 0);
  169. if (ret < 0) {
  170. dev_err(codec_dai->dev, "Init can't set pll sysclk mclk %d\n", ret);
  171. return ret;
  172. }
  173. /* Enable Headset and 4 Buttons Jack detection */
  174. ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",
  175. SND_JACK_HEADSET | SND_JACK_LINEOUT |
  176. SND_JACK_BTN_0 | SND_JACK_BTN_1 |
  177. SND_JACK_BTN_2 | SND_JACK_BTN_3,
  178. &rockchip_sound_jack,
  179. rockchip_sound_jack_pins,
  180. ARRAY_SIZE(rockchip_sound_jack_pins));
  181. if (ret) {
  182. dev_err(rtd->card->dev, "New Headset Jack failed! (%d)\n", ret);
  183. return ret;
  184. }
  185. snd_jack_set_key(
  186. rockchip_sound_jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
  187. snd_jack_set_key(
  188. rockchip_sound_jack.jack, SND_JACK_BTN_1, KEY_VOLUMEUP);
  189. snd_jack_set_key(
  190. rockchip_sound_jack.jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN);
  191. snd_jack_set_key(
  192. rockchip_sound_jack.jack, SND_JACK_BTN_3, KEY_VOICECOMMAND);
  193. da7219_aad_jack_det(component, &rockchip_sound_jack);
  194. return 0;
  195. }
  196. static int rockchip_sound_dmic_hw_params(struct snd_pcm_substream *substream,
  197. struct snd_pcm_hw_params *params)
  198. {
  199. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  200. unsigned int mclk;
  201. int ret;
  202. mclk = params_rate(params) * SOUND_FS;
  203. ret = snd_soc_dai_set_sysclk(asoc_rtd_to_cpu(rtd, 0), 0, mclk, 0);
  204. if (ret) {
  205. dev_err(rtd->card->dev, "%s() error setting sysclk to %u: %d\n",
  206. __func__, mclk, ret);
  207. return ret;
  208. }
  209. /* Wait for DMIC stable */
  210. msleep(dmic_wakeup_delay);
  211. return 0;
  212. }
  213. static int rockchip_sound_startup(struct snd_pcm_substream *substream)
  214. {
  215. struct snd_pcm_runtime *runtime = substream->runtime;
  216. runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
  217. return snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_RATE,
  218. 8000, 96000);
  219. }
  220. static const struct snd_soc_ops rockchip_sound_max98357a_ops = {
  221. .startup = rockchip_sound_startup,
  222. .hw_params = rockchip_sound_max98357a_hw_params,
  223. };
  224. static const struct snd_soc_ops rockchip_sound_rt5514_ops = {
  225. .startup = rockchip_sound_startup,
  226. .hw_params = rockchip_sound_rt5514_hw_params,
  227. };
  228. static const struct snd_soc_ops rockchip_sound_da7219_ops = {
  229. .startup = rockchip_sound_startup,
  230. .hw_params = rockchip_sound_da7219_hw_params,
  231. };
  232. static const struct snd_soc_ops rockchip_sound_dmic_ops = {
  233. .startup = rockchip_sound_startup,
  234. .hw_params = rockchip_sound_dmic_hw_params,
  235. };
  236. static struct snd_soc_card rockchip_sound_card = {
  237. .name = "rk3399-gru-sound",
  238. .owner = THIS_MODULE,
  239. .dapm_widgets = rockchip_dapm_widgets,
  240. .num_dapm_widgets = ARRAY_SIZE(rockchip_dapm_widgets),
  241. .controls = rockchip_controls,
  242. .num_controls = ARRAY_SIZE(rockchip_controls),
  243. };
  244. enum {
  245. DAILINK_CDNDP,
  246. DAILINK_DA7219,
  247. DAILINK_DMIC,
  248. DAILINK_MAX98357A,
  249. DAILINK_RT5514,
  250. DAILINK_RT5514_DSP,
  251. };
  252. SND_SOC_DAILINK_DEFS(cdndp,
  253. DAILINK_COMP_ARRAY(COMP_EMPTY()),
  254. DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "spdif-hifi")),
  255. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  256. SND_SOC_DAILINK_DEFS(da7219,
  257. DAILINK_COMP_ARRAY(COMP_EMPTY()),
  258. DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "da7219-hifi")),
  259. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  260. SND_SOC_DAILINK_DEFS(dmic,
  261. DAILINK_COMP_ARRAY(COMP_EMPTY()),
  262. DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "dmic-hifi")),
  263. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  264. SND_SOC_DAILINK_DEFS(max98357a,
  265. DAILINK_COMP_ARRAY(COMP_EMPTY()),
  266. DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "HiFi")),
  267. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  268. SND_SOC_DAILINK_DEFS(rt5514,
  269. DAILINK_COMP_ARRAY(COMP_EMPTY()),
  270. DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "rt5514-aif1")),
  271. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  272. SND_SOC_DAILINK_DEFS(rt5514_dsp,
  273. DAILINK_COMP_ARRAY(COMP_EMPTY()),
  274. DAILINK_COMP_ARRAY(COMP_DUMMY()),
  275. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  276. static const struct snd_soc_dai_link rockchip_dais[] = {
  277. [DAILINK_CDNDP] = {
  278. .name = "DP",
  279. .stream_name = "DP PCM",
  280. .init = rockchip_sound_cdndp_init,
  281. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  282. SND_SOC_DAIFMT_CBS_CFS,
  283. SND_SOC_DAILINK_REG(cdndp),
  284. },
  285. [DAILINK_DA7219] = {
  286. .name = "DA7219",
  287. .stream_name = "DA7219 PCM",
  288. .init = rockchip_sound_da7219_init,
  289. .ops = &rockchip_sound_da7219_ops,
  290. /* set da7219 as slave */
  291. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  292. SND_SOC_DAIFMT_CBS_CFS,
  293. SND_SOC_DAILINK_REG(da7219),
  294. },
  295. [DAILINK_DMIC] = {
  296. .name = "DMIC",
  297. .stream_name = "DMIC PCM",
  298. .ops = &rockchip_sound_dmic_ops,
  299. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  300. SND_SOC_DAIFMT_CBS_CFS,
  301. SND_SOC_DAILINK_REG(dmic),
  302. },
  303. [DAILINK_MAX98357A] = {
  304. .name = "MAX98357A",
  305. .stream_name = "MAX98357A PCM",
  306. .ops = &rockchip_sound_max98357a_ops,
  307. /* set max98357a as slave */
  308. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  309. SND_SOC_DAIFMT_CBS_CFS,
  310. SND_SOC_DAILINK_REG(max98357a),
  311. },
  312. [DAILINK_RT5514] = {
  313. .name = "RT5514",
  314. .stream_name = "RT5514 PCM",
  315. .ops = &rockchip_sound_rt5514_ops,
  316. /* set rt5514 as slave */
  317. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  318. SND_SOC_DAIFMT_CBS_CFS,
  319. SND_SOC_DAILINK_REG(rt5514),
  320. },
  321. /* RT5514 DSP for voice wakeup via spi bus */
  322. [DAILINK_RT5514_DSP] = {
  323. .name = "RT5514 DSP",
  324. .stream_name = "Wake on Voice",
  325. SND_SOC_DAILINK_REG(rt5514_dsp),
  326. },
  327. };
  328. static const struct snd_soc_dapm_route rockchip_sound_cdndp_routes[] = {
  329. /* Output */
  330. {"HDMI", NULL, "TX"},
  331. };
  332. static const struct snd_soc_dapm_route rockchip_sound_da7219_routes[] = {
  333. /* Output */
  334. {"Headphones", NULL, "HPL"},
  335. {"Headphones", NULL, "HPR"},
  336. /* Input */
  337. {"MIC", NULL, "Headset Mic"},
  338. };
  339. static const struct snd_soc_dapm_route rockchip_sound_dmic_routes[] = {
  340. /* Input */
  341. {"DMic", NULL, "Int Mic"},
  342. };
  343. static const struct snd_soc_dapm_route rockchip_sound_max98357a_routes[] = {
  344. /* Output */
  345. {"Speakers", NULL, "Speaker"},
  346. };
  347. static const struct snd_soc_dapm_route rockchip_sound_rt5514_routes[] = {
  348. /* Input */
  349. {"DMIC1L", NULL, "Int Mic"},
  350. {"DMIC1R", NULL, "Int Mic"},
  351. };
  352. struct rockchip_sound_route {
  353. const struct snd_soc_dapm_route *routes;
  354. int num_routes;
  355. };
  356. static const struct rockchip_sound_route rockchip_routes[] = {
  357. [DAILINK_CDNDP] = {
  358. .routes = rockchip_sound_cdndp_routes,
  359. .num_routes = ARRAY_SIZE(rockchip_sound_cdndp_routes),
  360. },
  361. [DAILINK_DA7219] = {
  362. .routes = rockchip_sound_da7219_routes,
  363. .num_routes = ARRAY_SIZE(rockchip_sound_da7219_routes),
  364. },
  365. [DAILINK_DMIC] = {
  366. .routes = rockchip_sound_dmic_routes,
  367. .num_routes = ARRAY_SIZE(rockchip_sound_dmic_routes),
  368. },
  369. [DAILINK_MAX98357A] = {
  370. .routes = rockchip_sound_max98357a_routes,
  371. .num_routes = ARRAY_SIZE(rockchip_sound_max98357a_routes),
  372. },
  373. [DAILINK_RT5514] = {
  374. .routes = rockchip_sound_rt5514_routes,
  375. .num_routes = ARRAY_SIZE(rockchip_sound_rt5514_routes),
  376. },
  377. [DAILINK_RT5514_DSP] = {},
  378. };
  379. struct dailink_match_data {
  380. const char *compatible;
  381. struct bus_type *bus_type;
  382. };
  383. static const struct dailink_match_data dailink_match[] = {
  384. [DAILINK_CDNDP] = {
  385. .compatible = "rockchip,rk3399-cdn-dp",
  386. },
  387. [DAILINK_DA7219] = {
  388. .compatible = "dlg,da7219",
  389. },
  390. [DAILINK_DMIC] = {
  391. .compatible = "dmic-codec",
  392. },
  393. [DAILINK_MAX98357A] = {
  394. .compatible = "maxim,max98357a",
  395. },
  396. [DAILINK_RT5514] = {
  397. .compatible = "realtek,rt5514",
  398. .bus_type = &i2c_bus_type,
  399. },
  400. [DAILINK_RT5514_DSP] = {
  401. .compatible = "realtek,rt5514",
  402. .bus_type = &spi_bus_type,
  403. },
  404. };
  405. static int rockchip_sound_codec_node_match(struct device_node *np_codec)
  406. {
  407. struct device *dev;
  408. int i;
  409. for (i = 0; i < ARRAY_SIZE(dailink_match); i++) {
  410. if (!of_device_is_compatible(np_codec,
  411. dailink_match[i].compatible))
  412. continue;
  413. if (dailink_match[i].bus_type) {
  414. dev = bus_find_device_by_of_node(dailink_match[i].bus_type,
  415. np_codec);
  416. if (!dev)
  417. continue;
  418. put_device(dev);
  419. }
  420. return i;
  421. }
  422. return -1;
  423. }
  424. static int rockchip_sound_of_parse_dais(struct device *dev,
  425. struct snd_soc_card *card)
  426. {
  427. struct device_node *np_cpu, *np_cpu0, *np_cpu1;
  428. struct device_node *np_codec;
  429. struct snd_soc_dai_link *dai;
  430. struct snd_soc_dapm_route *routes;
  431. int i, index;
  432. int num_routes;
  433. card->dai_link = devm_kzalloc(dev, sizeof(rockchip_dais),
  434. GFP_KERNEL);
  435. if (!card->dai_link)
  436. return -ENOMEM;
  437. num_routes = 0;
  438. for (i = 0; i < ARRAY_SIZE(rockchip_routes); i++)
  439. num_routes += rockchip_routes[i].num_routes;
  440. routes = devm_kcalloc(dev, num_routes, sizeof(*routes),
  441. GFP_KERNEL);
  442. if (!routes)
  443. return -ENOMEM;
  444. card->dapm_routes = routes;
  445. np_cpu0 = of_parse_phandle(dev->of_node, "rockchip,cpu", 0);
  446. np_cpu1 = of_parse_phandle(dev->of_node, "rockchip,cpu", 1);
  447. card->num_dapm_routes = 0;
  448. card->num_links = 0;
  449. for (i = 0; i < ARRAY_SIZE(rockchip_dais); i++) {
  450. np_codec = of_parse_phandle(dev->of_node,
  451. "rockchip,codec", i);
  452. if (!np_codec)
  453. break;
  454. if (!of_device_is_available(np_codec))
  455. continue;
  456. index = rockchip_sound_codec_node_match(np_codec);
  457. if (index < 0)
  458. continue;
  459. switch (index) {
  460. case DAILINK_CDNDP:
  461. np_cpu = np_cpu1;
  462. break;
  463. case DAILINK_RT5514_DSP:
  464. np_cpu = np_codec;
  465. break;
  466. default:
  467. np_cpu = np_cpu0;
  468. break;
  469. }
  470. if (!np_cpu) {
  471. dev_err(dev, "Missing 'rockchip,cpu' for %s\n",
  472. rockchip_dais[index].name);
  473. return -EINVAL;
  474. }
  475. dai = &card->dai_link[card->num_links++];
  476. *dai = rockchip_dais[index];
  477. if (!dai->codecs->name)
  478. dai->codecs->of_node = np_codec;
  479. dai->platforms->of_node = np_cpu;
  480. dai->cpus->of_node = np_cpu;
  481. if (card->num_dapm_routes + rockchip_routes[index].num_routes >
  482. num_routes) {
  483. dev_err(dev, "Too many routes\n");
  484. return -EINVAL;
  485. }
  486. memcpy(routes + card->num_dapm_routes,
  487. rockchip_routes[index].routes,
  488. rockchip_routes[index].num_routes * sizeof(*routes));
  489. card->num_dapm_routes += rockchip_routes[index].num_routes;
  490. }
  491. return 0;
  492. }
  493. static int rockchip_sound_probe(struct platform_device *pdev)
  494. {
  495. struct snd_soc_card *card = &rockchip_sound_card;
  496. int ret;
  497. ret = rockchip_sound_of_parse_dais(&pdev->dev, card);
  498. if (ret < 0) {
  499. dev_err(&pdev->dev, "Failed to parse dais: %d\n", ret);
  500. return ret;
  501. }
  502. /* Set DMIC wakeup delay */
  503. ret = device_property_read_u32(&pdev->dev, "dmic-wakeup-delay-ms",
  504. &dmic_wakeup_delay);
  505. if (ret) {
  506. dmic_wakeup_delay = 0;
  507. dev_dbg(&pdev->dev,
  508. "no optional property 'dmic-wakeup-delay-ms' found, default: no delay\n");
  509. }
  510. card->dev = &pdev->dev;
  511. return devm_snd_soc_register_card(&pdev->dev, card);
  512. }
  513. static const struct of_device_id rockchip_sound_of_match[] = {
  514. { .compatible = "rockchip,rk3399-gru-sound", },
  515. {},
  516. };
  517. static struct platform_driver rockchip_sound_driver = {
  518. .probe = rockchip_sound_probe,
  519. .driver = {
  520. .name = DRV_NAME,
  521. .of_match_table = rockchip_sound_of_match,
  522. #ifdef CONFIG_PM
  523. .pm = &snd_soc_pm_ops,
  524. #endif
  525. },
  526. };
  527. module_platform_driver(rockchip_sound_driver);
  528. MODULE_AUTHOR("Xing Zheng <[email protected]>");
  529. MODULE_DESCRIPTION("Rockchip ASoC Machine Driver");
  530. MODULE_LICENSE("GPL v2");
  531. MODULE_ALIAS("platform:" DRV_NAME);
  532. MODULE_DEVICE_TABLE(of, rockchip_sound_of_match);