acp-da7219-max98357a.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  1. // SPDX-License-Identifier: MIT
  2. //
  3. // Machine driver for AMD ACP Audio engine using DA7219, RT5682 & MAX98357 codec
  4. //
  5. //Copyright 2017-2021 Advanced Micro Devices, Inc.
  6. #include <sound/core.h>
  7. #include <sound/soc.h>
  8. #include <sound/pcm.h>
  9. #include <sound/pcm_params.h>
  10. #include <sound/soc-dapm.h>
  11. #include <sound/jack.h>
  12. #include <linux/clk.h>
  13. #include <linux/gpio.h>
  14. #include <linux/module.h>
  15. #include <linux/regulator/machine.h>
  16. #include <linux/regulator/driver.h>
  17. #include <linux/i2c.h>
  18. #include <linux/input.h>
  19. #include <linux/acpi.h>
  20. #include "acp.h"
  21. #include "../codecs/da7219.h"
  22. #include "../codecs/da7219-aad.h"
  23. #include "../codecs/rt5682.h"
  24. #define CZ_PLAT_CLK 48000000
  25. #define DUAL_CHANNEL 2
  26. #define RT5682_PLL_FREQ (48000 * 512)
  27. static struct snd_soc_jack cz_jack;
  28. static struct clk *da7219_dai_wclk;
  29. static struct clk *da7219_dai_bclk;
  30. static struct clk *rt5682_dai_wclk;
  31. static struct clk *rt5682_dai_bclk;
  32. void *acp_soc_is_rltk_max(struct device *dev);
  33. static int cz_da7219_init(struct snd_soc_pcm_runtime *rtd)
  34. {
  35. int ret;
  36. struct snd_soc_card *card = rtd->card;
  37. struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
  38. struct snd_soc_component *component = codec_dai->component;
  39. dev_info(rtd->dev, "codec dai name = %s\n", codec_dai->name);
  40. ret = snd_soc_dai_set_sysclk(codec_dai, DA7219_CLKSRC_MCLK,
  41. CZ_PLAT_CLK, SND_SOC_CLOCK_IN);
  42. if (ret < 0) {
  43. dev_err(rtd->dev, "can't set codec sysclk: %d\n", ret);
  44. return ret;
  45. }
  46. ret = snd_soc_dai_set_pll(codec_dai, 0, DA7219_SYSCLK_PLL,
  47. CZ_PLAT_CLK, DA7219_PLL_FREQ_OUT_98304);
  48. if (ret < 0) {
  49. dev_err(rtd->dev, "can't set codec pll: %d\n", ret);
  50. return ret;
  51. }
  52. da7219_dai_wclk = devm_clk_get(component->dev, "da7219-dai-wclk");
  53. if (IS_ERR(da7219_dai_wclk))
  54. return PTR_ERR(da7219_dai_wclk);
  55. da7219_dai_bclk = devm_clk_get(component->dev, "da7219-dai-bclk");
  56. if (IS_ERR(da7219_dai_bclk))
  57. return PTR_ERR(da7219_dai_bclk);
  58. ret = snd_soc_card_jack_new(card, "Headset Jack",
  59. SND_JACK_HEADSET | SND_JACK_LINEOUT |
  60. SND_JACK_BTN_0 | SND_JACK_BTN_1 |
  61. SND_JACK_BTN_2 | SND_JACK_BTN_3,
  62. &cz_jack);
  63. if (ret) {
  64. dev_err(card->dev, "HP jack creation failed %d\n", ret);
  65. return ret;
  66. }
  67. snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
  68. snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_1, KEY_VOLUMEUP);
  69. snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN);
  70. snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_3, KEY_VOICECOMMAND);
  71. da7219_aad_jack_det(component, &cz_jack);
  72. return 0;
  73. }
  74. static int da7219_clk_enable(struct snd_pcm_substream *substream)
  75. {
  76. int ret = 0;
  77. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  78. /*
  79. * Set wclk to 48000 because the rate constraint of this driver is
  80. * 48000. ADAU7002 spec: "The ADAU7002 requires a BCLK rate that is
  81. * minimum of 64x the LRCLK sample rate." DA7219 is the only clk
  82. * source so for all codecs we have to limit bclk to 64X lrclk.
  83. */
  84. clk_set_rate(da7219_dai_wclk, 48000);
  85. clk_set_rate(da7219_dai_bclk, 48000 * 64);
  86. ret = clk_prepare_enable(da7219_dai_bclk);
  87. if (ret < 0) {
  88. dev_err(rtd->dev, "can't enable master clock %d\n", ret);
  89. return ret;
  90. }
  91. return ret;
  92. }
  93. static void da7219_clk_disable(void)
  94. {
  95. clk_disable_unprepare(da7219_dai_bclk);
  96. }
  97. static int cz_rt5682_init(struct snd_soc_pcm_runtime *rtd)
  98. {
  99. int ret;
  100. struct snd_soc_card *card = rtd->card;
  101. struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
  102. struct snd_soc_component *component = codec_dai->component;
  103. dev_info(codec_dai->dev, "codec dai name = %s\n", codec_dai->name);
  104. /* Set codec sysclk */
  105. ret = snd_soc_dai_set_sysclk(codec_dai, RT5682_SCLK_S_PLL2,
  106. RT5682_PLL_FREQ, SND_SOC_CLOCK_IN);
  107. if (ret < 0) {
  108. dev_err(codec_dai->dev,
  109. "Failed to set rt5682 SYSCLK: %d\n", ret);
  110. return ret;
  111. }
  112. /* set codec PLL */
  113. ret = snd_soc_dai_set_pll(codec_dai, RT5682_PLL2, RT5682_PLL2_S_MCLK,
  114. CZ_PLAT_CLK, RT5682_PLL_FREQ);
  115. if (ret < 0) {
  116. dev_err(codec_dai->dev, "can't set rt5682 PLL: %d\n", ret);
  117. return ret;
  118. }
  119. rt5682_dai_wclk = devm_clk_get(component->dev, "rt5682-dai-wclk");
  120. if (IS_ERR(rt5682_dai_wclk))
  121. return PTR_ERR(rt5682_dai_wclk);
  122. rt5682_dai_bclk = devm_clk_get(component->dev, "rt5682-dai-bclk");
  123. if (IS_ERR(rt5682_dai_bclk))
  124. return PTR_ERR(rt5682_dai_bclk);
  125. ret = snd_soc_card_jack_new(card, "Headset Jack",
  126. SND_JACK_HEADSET | SND_JACK_LINEOUT |
  127. SND_JACK_BTN_0 | SND_JACK_BTN_1 |
  128. SND_JACK_BTN_2 | SND_JACK_BTN_3,
  129. &cz_jack);
  130. if (ret) {
  131. dev_err(card->dev, "HP jack creation failed %d\n", ret);
  132. return ret;
  133. }
  134. snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
  135. snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_1, KEY_VOLUMEUP);
  136. snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN);
  137. snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_3, KEY_VOICECOMMAND);
  138. ret = snd_soc_component_set_jack(component, &cz_jack, NULL);
  139. if (ret) {
  140. dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret);
  141. return ret;
  142. }
  143. return 0;
  144. }
  145. static int rt5682_clk_enable(struct snd_pcm_substream *substream)
  146. {
  147. int ret;
  148. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  149. /*
  150. * Set wclk to 48000 because the rate constraint of this driver is
  151. * 48000. ADAU7002 spec: "The ADAU7002 requires a BCLK rate that is
  152. * minimum of 64x the LRCLK sample rate." RT5682 is the only clk
  153. * source so for all codecs we have to limit bclk to 64X lrclk.
  154. */
  155. ret = clk_set_rate(rt5682_dai_wclk, 48000);
  156. if (ret) {
  157. dev_err(rtd->dev, "Error setting wclk rate: %d\n", ret);
  158. return ret;
  159. }
  160. ret = clk_set_rate(rt5682_dai_bclk, 48000 * 64);
  161. if (ret) {
  162. dev_err(rtd->dev, "Error setting bclk rate: %d\n", ret);
  163. return ret;
  164. }
  165. ret = clk_prepare_enable(rt5682_dai_wclk);
  166. if (ret < 0) {
  167. dev_err(rtd->dev, "can't enable wclk %d\n", ret);
  168. return ret;
  169. }
  170. return ret;
  171. }
  172. static void rt5682_clk_disable(void)
  173. {
  174. clk_disable_unprepare(rt5682_dai_wclk);
  175. }
  176. static const unsigned int channels[] = {
  177. DUAL_CHANNEL,
  178. };
  179. static const unsigned int rates[] = {
  180. 48000,
  181. };
  182. static const struct snd_pcm_hw_constraint_list constraints_rates = {
  183. .count = ARRAY_SIZE(rates),
  184. .list = rates,
  185. .mask = 0,
  186. };
  187. static const struct snd_pcm_hw_constraint_list constraints_channels = {
  188. .count = ARRAY_SIZE(channels),
  189. .list = channels,
  190. .mask = 0,
  191. };
  192. static int cz_da7219_play_startup(struct snd_pcm_substream *substream)
  193. {
  194. struct snd_pcm_runtime *runtime = substream->runtime;
  195. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  196. struct snd_soc_card *card = rtd->card;
  197. struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
  198. /*
  199. * On this platform for PCM device we support stereo
  200. */
  201. runtime->hw.channels_max = DUAL_CHANNEL;
  202. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
  203. &constraints_channels);
  204. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
  205. &constraints_rates);
  206. machine->play_i2s_instance = I2S_SP_INSTANCE;
  207. return da7219_clk_enable(substream);
  208. }
  209. static int cz_da7219_cap_startup(struct snd_pcm_substream *substream)
  210. {
  211. struct snd_pcm_runtime *runtime = substream->runtime;
  212. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  213. struct snd_soc_card *card = rtd->card;
  214. struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
  215. /*
  216. * On this platform for PCM device we support stereo
  217. */
  218. runtime->hw.channels_max = DUAL_CHANNEL;
  219. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
  220. &constraints_channels);
  221. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
  222. &constraints_rates);
  223. machine->cap_i2s_instance = I2S_SP_INSTANCE;
  224. machine->capture_channel = CAP_CHANNEL1;
  225. return da7219_clk_enable(substream);
  226. }
  227. static int cz_max_startup(struct snd_pcm_substream *substream)
  228. {
  229. struct snd_pcm_runtime *runtime = substream->runtime;
  230. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  231. struct snd_soc_card *card = rtd->card;
  232. struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
  233. /*
  234. * On this platform for PCM device we support stereo
  235. */
  236. runtime->hw.channels_max = DUAL_CHANNEL;
  237. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
  238. &constraints_channels);
  239. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
  240. &constraints_rates);
  241. machine->play_i2s_instance = I2S_BT_INSTANCE;
  242. return da7219_clk_enable(substream);
  243. }
  244. static int cz_dmic0_startup(struct snd_pcm_substream *substream)
  245. {
  246. struct snd_pcm_runtime *runtime = substream->runtime;
  247. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  248. struct snd_soc_card *card = rtd->card;
  249. struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
  250. /*
  251. * On this platform for PCM device we support stereo
  252. */
  253. runtime->hw.channels_max = DUAL_CHANNEL;
  254. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
  255. &constraints_channels);
  256. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
  257. &constraints_rates);
  258. machine->cap_i2s_instance = I2S_BT_INSTANCE;
  259. return da7219_clk_enable(substream);
  260. }
  261. static int cz_dmic1_startup(struct snd_pcm_substream *substream)
  262. {
  263. struct snd_pcm_runtime *runtime = substream->runtime;
  264. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  265. struct snd_soc_card *card = rtd->card;
  266. struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
  267. /*
  268. * On this platform for PCM device we support stereo
  269. */
  270. runtime->hw.channels_max = DUAL_CHANNEL;
  271. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
  272. &constraints_channels);
  273. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
  274. &constraints_rates);
  275. machine->cap_i2s_instance = I2S_SP_INSTANCE;
  276. machine->capture_channel = CAP_CHANNEL0;
  277. return da7219_clk_enable(substream);
  278. }
  279. static void cz_da7219_shutdown(struct snd_pcm_substream *substream)
  280. {
  281. da7219_clk_disable();
  282. }
  283. static int cz_rt5682_play_startup(struct snd_pcm_substream *substream)
  284. {
  285. struct snd_pcm_runtime *runtime = substream->runtime;
  286. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  287. struct snd_soc_card *card = rtd->card;
  288. struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
  289. /*
  290. * On this platform for PCM device we support stereo
  291. */
  292. runtime->hw.channels_max = DUAL_CHANNEL;
  293. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
  294. &constraints_channels);
  295. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
  296. &constraints_rates);
  297. machine->play_i2s_instance = I2S_SP_INSTANCE;
  298. return rt5682_clk_enable(substream);
  299. }
  300. static int cz_rt5682_cap_startup(struct snd_pcm_substream *substream)
  301. {
  302. struct snd_pcm_runtime *runtime = substream->runtime;
  303. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  304. struct snd_soc_card *card = rtd->card;
  305. struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
  306. /*
  307. * On this platform for PCM device we support stereo
  308. */
  309. runtime->hw.channels_max = DUAL_CHANNEL;
  310. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
  311. &constraints_channels);
  312. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
  313. &constraints_rates);
  314. machine->cap_i2s_instance = I2S_SP_INSTANCE;
  315. machine->capture_channel = CAP_CHANNEL1;
  316. return rt5682_clk_enable(substream);
  317. }
  318. static int cz_rt5682_max_startup(struct snd_pcm_substream *substream)
  319. {
  320. struct snd_pcm_runtime *runtime = substream->runtime;
  321. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  322. struct snd_soc_card *card = rtd->card;
  323. struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
  324. /*
  325. * On this platform for PCM device we support stereo
  326. */
  327. runtime->hw.channels_max = DUAL_CHANNEL;
  328. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
  329. &constraints_channels);
  330. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
  331. &constraints_rates);
  332. machine->play_i2s_instance = I2S_BT_INSTANCE;
  333. return rt5682_clk_enable(substream);
  334. }
  335. static int cz_rt5682_dmic0_startup(struct snd_pcm_substream *substream)
  336. {
  337. struct snd_pcm_runtime *runtime = substream->runtime;
  338. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  339. struct snd_soc_card *card = rtd->card;
  340. struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
  341. /*
  342. * On this platform for PCM device we support stereo
  343. */
  344. runtime->hw.channels_max = DUAL_CHANNEL;
  345. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
  346. &constraints_channels);
  347. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
  348. &constraints_rates);
  349. machine->cap_i2s_instance = I2S_BT_INSTANCE;
  350. return rt5682_clk_enable(substream);
  351. }
  352. static int cz_rt5682_dmic1_startup(struct snd_pcm_substream *substream)
  353. {
  354. struct snd_pcm_runtime *runtime = substream->runtime;
  355. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  356. struct snd_soc_card *card = rtd->card;
  357. struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
  358. /*
  359. * On this platform for PCM device we support stereo
  360. */
  361. runtime->hw.channels_max = DUAL_CHANNEL;
  362. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
  363. &constraints_channels);
  364. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
  365. &constraints_rates);
  366. machine->cap_i2s_instance = I2S_SP_INSTANCE;
  367. machine->capture_channel = CAP_CHANNEL0;
  368. return rt5682_clk_enable(substream);
  369. }
  370. static void cz_rt5682_shutdown(struct snd_pcm_substream *substream)
  371. {
  372. rt5682_clk_disable();
  373. }
  374. static const struct snd_soc_ops cz_da7219_play_ops = {
  375. .startup = cz_da7219_play_startup,
  376. .shutdown = cz_da7219_shutdown,
  377. };
  378. static const struct snd_soc_ops cz_da7219_cap_ops = {
  379. .startup = cz_da7219_cap_startup,
  380. .shutdown = cz_da7219_shutdown,
  381. };
  382. static const struct snd_soc_ops cz_max_play_ops = {
  383. .startup = cz_max_startup,
  384. .shutdown = cz_da7219_shutdown,
  385. };
  386. static const struct snd_soc_ops cz_dmic0_cap_ops = {
  387. .startup = cz_dmic0_startup,
  388. .shutdown = cz_da7219_shutdown,
  389. };
  390. static const struct snd_soc_ops cz_dmic1_cap_ops = {
  391. .startup = cz_dmic1_startup,
  392. .shutdown = cz_da7219_shutdown,
  393. };
  394. static const struct snd_soc_ops cz_rt5682_play_ops = {
  395. .startup = cz_rt5682_play_startup,
  396. .shutdown = cz_rt5682_shutdown,
  397. };
  398. static const struct snd_soc_ops cz_rt5682_cap_ops = {
  399. .startup = cz_rt5682_cap_startup,
  400. .shutdown = cz_rt5682_shutdown,
  401. };
  402. static const struct snd_soc_ops cz_rt5682_max_play_ops = {
  403. .startup = cz_rt5682_max_startup,
  404. .shutdown = cz_rt5682_shutdown,
  405. };
  406. static const struct snd_soc_ops cz_rt5682_dmic0_cap_ops = {
  407. .startup = cz_rt5682_dmic0_startup,
  408. .shutdown = cz_rt5682_shutdown,
  409. };
  410. static const struct snd_soc_ops cz_rt5682_dmic1_cap_ops = {
  411. .startup = cz_rt5682_dmic1_startup,
  412. .shutdown = cz_rt5682_shutdown,
  413. };
  414. SND_SOC_DAILINK_DEF(designware1,
  415. DAILINK_COMP_ARRAY(COMP_CPU("designware-i2s.1.auto")));
  416. SND_SOC_DAILINK_DEF(designware2,
  417. DAILINK_COMP_ARRAY(COMP_CPU("designware-i2s.2.auto")));
  418. SND_SOC_DAILINK_DEF(designware3,
  419. DAILINK_COMP_ARRAY(COMP_CPU("designware-i2s.3.auto")));
  420. SND_SOC_DAILINK_DEF(dlgs,
  421. DAILINK_COMP_ARRAY(COMP_CODEC("i2c-DLGS7219:00", "da7219-hifi")));
  422. SND_SOC_DAILINK_DEF(rt5682,
  423. DAILINK_COMP_ARRAY(COMP_CODEC("i2c-10EC5682:00", "rt5682-aif1")));
  424. SND_SOC_DAILINK_DEF(mx,
  425. DAILINK_COMP_ARRAY(COMP_CODEC("MX98357A:00", "HiFi")));
  426. SND_SOC_DAILINK_DEF(adau,
  427. DAILINK_COMP_ARRAY(COMP_CODEC("ADAU7002:00", "adau7002-hifi")));
  428. SND_SOC_DAILINK_DEF(platform,
  429. DAILINK_COMP_ARRAY(COMP_PLATFORM("acp_audio_dma.0.auto")));
  430. static struct snd_soc_dai_link cz_dai_7219_98357[] = {
  431. {
  432. .name = "amd-da7219-play",
  433. .stream_name = "Playback",
  434. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
  435. | SND_SOC_DAIFMT_CBP_CFP,
  436. .init = cz_da7219_init,
  437. .dpcm_playback = 1,
  438. .stop_dma_first = 1,
  439. .ops = &cz_da7219_play_ops,
  440. SND_SOC_DAILINK_REG(designware1, dlgs, platform),
  441. },
  442. {
  443. .name = "amd-da7219-cap",
  444. .stream_name = "Capture",
  445. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
  446. | SND_SOC_DAIFMT_CBP_CFP,
  447. .dpcm_capture = 1,
  448. .stop_dma_first = 1,
  449. .ops = &cz_da7219_cap_ops,
  450. SND_SOC_DAILINK_REG(designware2, dlgs, platform),
  451. },
  452. {
  453. .name = "amd-max98357-play",
  454. .stream_name = "HiFi Playback",
  455. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
  456. | SND_SOC_DAIFMT_CBP_CFP,
  457. .dpcm_playback = 1,
  458. .stop_dma_first = 1,
  459. .ops = &cz_max_play_ops,
  460. SND_SOC_DAILINK_REG(designware3, mx, platform),
  461. },
  462. {
  463. /* C panel DMIC */
  464. .name = "dmic0",
  465. .stream_name = "DMIC0 Capture",
  466. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
  467. | SND_SOC_DAIFMT_CBP_CFP,
  468. .dpcm_capture = 1,
  469. .stop_dma_first = 1,
  470. .ops = &cz_dmic0_cap_ops,
  471. SND_SOC_DAILINK_REG(designware3, adau, platform),
  472. },
  473. {
  474. /* A/B panel DMIC */
  475. .name = "dmic1",
  476. .stream_name = "DMIC1 Capture",
  477. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
  478. | SND_SOC_DAIFMT_CBP_CFP,
  479. .dpcm_capture = 1,
  480. .stop_dma_first = 1,
  481. .ops = &cz_dmic1_cap_ops,
  482. SND_SOC_DAILINK_REG(designware2, adau, platform),
  483. },
  484. };
  485. static struct snd_soc_dai_link cz_dai_5682_98357[] = {
  486. {
  487. .name = "amd-rt5682-play",
  488. .stream_name = "Playback",
  489. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
  490. | SND_SOC_DAIFMT_CBP_CFP,
  491. .init = cz_rt5682_init,
  492. .dpcm_playback = 1,
  493. .stop_dma_first = 1,
  494. .ops = &cz_rt5682_play_ops,
  495. SND_SOC_DAILINK_REG(designware1, rt5682, platform),
  496. },
  497. {
  498. .name = "amd-rt5682-cap",
  499. .stream_name = "Capture",
  500. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
  501. | SND_SOC_DAIFMT_CBP_CFP,
  502. .dpcm_capture = 1,
  503. .stop_dma_first = 1,
  504. .ops = &cz_rt5682_cap_ops,
  505. SND_SOC_DAILINK_REG(designware2, rt5682, platform),
  506. },
  507. {
  508. .name = "amd-max98357-play",
  509. .stream_name = "HiFi Playback",
  510. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
  511. | SND_SOC_DAIFMT_CBP_CFP,
  512. .dpcm_playback = 1,
  513. .stop_dma_first = 1,
  514. .ops = &cz_rt5682_max_play_ops,
  515. SND_SOC_DAILINK_REG(designware3, mx, platform),
  516. },
  517. {
  518. /* C panel DMIC */
  519. .name = "dmic0",
  520. .stream_name = "DMIC0 Capture",
  521. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
  522. | SND_SOC_DAIFMT_CBP_CFP,
  523. .dpcm_capture = 1,
  524. .stop_dma_first = 1,
  525. .ops = &cz_rt5682_dmic0_cap_ops,
  526. SND_SOC_DAILINK_REG(designware3, adau, platform),
  527. },
  528. {
  529. /* A/B panel DMIC */
  530. .name = "dmic1",
  531. .stream_name = "DMIC1 Capture",
  532. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
  533. | SND_SOC_DAIFMT_CBP_CFP,
  534. .dpcm_capture = 1,
  535. .stop_dma_first = 1,
  536. .ops = &cz_rt5682_dmic1_cap_ops,
  537. SND_SOC_DAILINK_REG(designware2, adau, platform),
  538. },
  539. };
  540. static const struct snd_soc_dapm_widget cz_widgets[] = {
  541. SND_SOC_DAPM_HP("Headphones", NULL),
  542. SND_SOC_DAPM_SPK("Speakers", NULL),
  543. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  544. SND_SOC_DAPM_MIC("Int Mic", NULL),
  545. };
  546. static const struct snd_soc_dapm_route cz_audio_route[] = {
  547. {"Headphones", NULL, "HPL"},
  548. {"Headphones", NULL, "HPR"},
  549. {"MIC", NULL, "Headset Mic"},
  550. {"Speakers", NULL, "Speaker"},
  551. {"PDM_DAT", NULL, "Int Mic"},
  552. };
  553. static const struct snd_soc_dapm_route cz_rt5682_audio_route[] = {
  554. {"Headphones", NULL, "HPOL"},
  555. {"Headphones", NULL, "HPOR"},
  556. {"IN1P", NULL, "Headset Mic"},
  557. {"Speakers", NULL, "Speaker"},
  558. {"PDM_DAT", NULL, "Int Mic"},
  559. };
  560. static const struct snd_kcontrol_new cz_mc_controls[] = {
  561. SOC_DAPM_PIN_SWITCH("Headphones"),
  562. SOC_DAPM_PIN_SWITCH("Speakers"),
  563. SOC_DAPM_PIN_SWITCH("Headset Mic"),
  564. SOC_DAPM_PIN_SWITCH("Int Mic"),
  565. };
  566. static struct snd_soc_card cz_card = {
  567. .name = "acpd7219m98357",
  568. .owner = THIS_MODULE,
  569. .dai_link = cz_dai_7219_98357,
  570. .num_links = ARRAY_SIZE(cz_dai_7219_98357),
  571. .dapm_widgets = cz_widgets,
  572. .num_dapm_widgets = ARRAY_SIZE(cz_widgets),
  573. .dapm_routes = cz_audio_route,
  574. .num_dapm_routes = ARRAY_SIZE(cz_audio_route),
  575. .controls = cz_mc_controls,
  576. .num_controls = ARRAY_SIZE(cz_mc_controls),
  577. };
  578. static struct snd_soc_card cz_rt5682_card = {
  579. .name = "acpr5682m98357",
  580. .owner = THIS_MODULE,
  581. .dai_link = cz_dai_5682_98357,
  582. .num_links = ARRAY_SIZE(cz_dai_5682_98357),
  583. .dapm_widgets = cz_widgets,
  584. .num_dapm_widgets = ARRAY_SIZE(cz_widgets),
  585. .dapm_routes = cz_rt5682_audio_route,
  586. .controls = cz_mc_controls,
  587. .num_controls = ARRAY_SIZE(cz_mc_controls),
  588. };
  589. void *acp_soc_is_rltk_max(struct device *dev)
  590. {
  591. const struct acpi_device_id *match;
  592. match = acpi_match_device(dev->driver->acpi_match_table, dev);
  593. if (!match)
  594. return NULL;
  595. return (void *)match->driver_data;
  596. }
  597. static struct regulator_consumer_supply acp_da7219_supplies[] = {
  598. REGULATOR_SUPPLY("VDD", "i2c-DLGS7219:00"),
  599. REGULATOR_SUPPLY("VDDMIC", "i2c-DLGS7219:00"),
  600. REGULATOR_SUPPLY("VDDIO", "i2c-DLGS7219:00"),
  601. REGULATOR_SUPPLY("IOVDD", "ADAU7002:00"),
  602. };
  603. static struct regulator_init_data acp_da7219_data = {
  604. .constraints = {
  605. .always_on = 1,
  606. },
  607. .num_consumer_supplies = ARRAY_SIZE(acp_da7219_supplies),
  608. .consumer_supplies = acp_da7219_supplies,
  609. };
  610. static struct regulator_config acp_da7219_cfg = {
  611. .init_data = &acp_da7219_data,
  612. };
  613. static struct regulator_ops acp_da7219_ops = {
  614. };
  615. static const struct regulator_desc acp_da7219_desc = {
  616. .name = "reg-fixed-1.8V",
  617. .type = REGULATOR_VOLTAGE,
  618. .owner = THIS_MODULE,
  619. .ops = &acp_da7219_ops,
  620. .fixed_uV = 1800000, /* 1.8V */
  621. .n_voltages = 1,
  622. };
  623. static int cz_probe(struct platform_device *pdev)
  624. {
  625. int ret;
  626. struct snd_soc_card *card;
  627. struct acp_platform_info *machine;
  628. struct regulator_dev *rdev;
  629. struct device *dev = &pdev->dev;
  630. card = (struct snd_soc_card *)acp_soc_is_rltk_max(dev);
  631. if (!card)
  632. return -ENODEV;
  633. if (!strcmp(card->name, "acpd7219m98357")) {
  634. acp_da7219_cfg.dev = &pdev->dev;
  635. rdev = devm_regulator_register(&pdev->dev, &acp_da7219_desc,
  636. &acp_da7219_cfg);
  637. if (IS_ERR(rdev)) {
  638. dev_err(&pdev->dev, "Failed to register regulator: %d\n",
  639. (int)PTR_ERR(rdev));
  640. return -EINVAL;
  641. }
  642. }
  643. machine = devm_kzalloc(&pdev->dev, sizeof(struct acp_platform_info),
  644. GFP_KERNEL);
  645. if (!machine)
  646. return -ENOMEM;
  647. card->dev = &pdev->dev;
  648. platform_set_drvdata(pdev, card);
  649. snd_soc_card_set_drvdata(card, machine);
  650. ret = devm_snd_soc_register_card(&pdev->dev, card);
  651. if (ret) {
  652. return dev_err_probe(&pdev->dev, ret,
  653. "devm_snd_soc_register_card(%s) failed\n",
  654. card->name);
  655. }
  656. acp_bt_uart_enable = !device_property_read_bool(&pdev->dev,
  657. "bt-pad-enable");
  658. return 0;
  659. }
  660. #ifdef CONFIG_ACPI
  661. static const struct acpi_device_id cz_audio_acpi_match[] = {
  662. { "AMD7219", (unsigned long)&cz_card },
  663. { "AMDI5682", (unsigned long)&cz_rt5682_card},
  664. {},
  665. };
  666. MODULE_DEVICE_TABLE(acpi, cz_audio_acpi_match);
  667. #endif
  668. static struct platform_driver cz_pcm_driver = {
  669. .driver = {
  670. .name = "cz-da7219-max98357a",
  671. .acpi_match_table = ACPI_PTR(cz_audio_acpi_match),
  672. .pm = &snd_soc_pm_ops,
  673. },
  674. .probe = cz_probe,
  675. };
  676. module_platform_driver(cz_pcm_driver);
  677. MODULE_AUTHOR("[email protected]");
  678. MODULE_AUTHOR("[email protected]");
  679. MODULE_DESCRIPTION("DA7219, RT5682 & MAX98357A audio support");
  680. MODULE_LICENSE("GPL v2");