mt8192-mt6359-rt1015-rt5682.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  1. // SPDX-License-Identifier: GPL-2.0
  2. //
  3. // mt8192-mt6359-rt1015-rt5682.c --
  4. // MT8192-MT6359-RT1015-RT6358 ALSA SoC machine driver
  5. //
  6. // Copyright (c) 2020 MediaTek Inc.
  7. // Author: Jiaxin Yu <[email protected]>
  8. //
  9. #include <linux/input.h>
  10. #include <linux/module.h>
  11. #include <linux/of_device.h>
  12. #include <linux/pm_runtime.h>
  13. #include <sound/jack.h>
  14. #include <sound/pcm_params.h>
  15. #include <sound/rt5682.h>
  16. #include <sound/soc.h>
  17. #include "../../codecs/mt6359.h"
  18. #include "../../codecs/rt1015.h"
  19. #include "../../codecs/rt5682.h"
  20. #include "../common/mtk-afe-platform-driver.h"
  21. #include "mt8192-afe-common.h"
  22. #include "mt8192-afe-clk.h"
  23. #include "mt8192-afe-gpio.h"
  24. #define DRIVER_NAME "mt8192_mt6359"
  25. #define RT1015_CODEC_DAI "rt1015-aif"
  26. #define RT1015_DEV0_NAME "rt1015.1-0028"
  27. #define RT1015_DEV1_NAME "rt1015.1-0029"
  28. #define RT1015_RT5682_CARD_NAME "mt8192_mt6359_rt1015_rt5682"
  29. #define RT1015P_RT5682_CARD_NAME "mt8192_mt6359_rt1015p_rt5682"
  30. #define RT1015P_RT5682S_CARD_NAME "mt8192_mt6359_rt1015p_rt5682s"
  31. #define RT1015_RT5682_OF_NAME "mediatek,mt8192_mt6359_rt1015_rt5682"
  32. #define RT1015P_RT5682_OF_NAME "mediatek,mt8192_mt6359_rt1015p_rt5682"
  33. #define RT1015P_RT5682S_OF_NAME "mediatek,mt8192_mt6359_rt1015p_rt5682s"
  34. struct mt8192_mt6359_priv {
  35. struct snd_soc_jack headset_jack;
  36. struct snd_soc_jack hdmi_jack;
  37. };
  38. /* Headset jack detection DAPM pins */
  39. static struct snd_soc_jack_pin mt8192_jack_pins[] = {
  40. {
  41. .pin = "Headphone Jack",
  42. .mask = SND_JACK_HEADPHONE,
  43. },
  44. {
  45. .pin = "Headset Mic",
  46. .mask = SND_JACK_MICROPHONE,
  47. },
  48. };
  49. static int mt8192_rt1015_i2s_hw_params(struct snd_pcm_substream *substream,
  50. struct snd_pcm_hw_params *params)
  51. {
  52. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  53. struct snd_soc_card *card = rtd->card;
  54. struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
  55. struct snd_soc_dai *codec_dai;
  56. unsigned int rate = params_rate(params);
  57. unsigned int mclk_fs_ratio = 128;
  58. unsigned int mclk_fs = rate * mclk_fs_ratio;
  59. int ret, i;
  60. for_each_rtd_codec_dais(rtd, i, codec_dai) {
  61. ret = snd_soc_dai_set_pll(codec_dai, 0,
  62. RT1015_PLL_S_BCLK,
  63. params_rate(params) * 64,
  64. params_rate(params) * 256);
  65. if (ret) {
  66. dev_err(card->dev, "failed to set pll\n");
  67. return ret;
  68. }
  69. ret = snd_soc_dai_set_sysclk(codec_dai,
  70. RT1015_SCLK_S_PLL,
  71. params_rate(params) * 256,
  72. SND_SOC_CLOCK_IN);
  73. if (ret) {
  74. dev_err(card->dev, "failed to set sysclk\n");
  75. return ret;
  76. }
  77. }
  78. return snd_soc_dai_set_sysclk(cpu_dai, 0, mclk_fs, SND_SOC_CLOCK_OUT);
  79. }
  80. static int mt8192_rt5682x_i2s_hw_params(struct snd_pcm_substream *substream,
  81. struct snd_pcm_hw_params *params)
  82. {
  83. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  84. struct snd_soc_card *card = rtd->card;
  85. struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
  86. struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
  87. unsigned int rate = params_rate(params);
  88. unsigned int mclk_fs_ratio = 128;
  89. unsigned int mclk_fs = rate * mclk_fs_ratio;
  90. int bitwidth;
  91. int ret;
  92. bitwidth = snd_pcm_format_width(params_format(params));
  93. if (bitwidth < 0) {
  94. dev_err(card->dev, "invalid bit width: %d\n", bitwidth);
  95. return bitwidth;
  96. }
  97. ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x00, 0x0, 0x2, bitwidth);
  98. if (ret) {
  99. dev_err(card->dev, "failed to set tdm slot\n");
  100. return ret;
  101. }
  102. ret = snd_soc_dai_set_pll(codec_dai, RT5682_PLL1,
  103. RT5682_PLL1_S_BCLK1,
  104. params_rate(params) * 64,
  105. params_rate(params) * 512);
  106. if (ret) {
  107. dev_err(card->dev, "failed to set pll\n");
  108. return ret;
  109. }
  110. ret = snd_soc_dai_set_sysclk(codec_dai,
  111. RT5682_SCLK_S_PLL1,
  112. params_rate(params) * 512,
  113. SND_SOC_CLOCK_IN);
  114. if (ret) {
  115. dev_err(card->dev, "failed to set sysclk\n");
  116. return ret;
  117. }
  118. return snd_soc_dai_set_sysclk(cpu_dai, 0, mclk_fs, SND_SOC_CLOCK_OUT);
  119. }
  120. static const struct snd_soc_ops mt8192_rt1015_i2s_ops = {
  121. .hw_params = mt8192_rt1015_i2s_hw_params,
  122. };
  123. static const struct snd_soc_ops mt8192_rt5682x_i2s_ops = {
  124. .hw_params = mt8192_rt5682x_i2s_hw_params,
  125. };
  126. static int mt8192_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime *rtd)
  127. {
  128. struct snd_soc_component *cmpnt_afe =
  129. snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
  130. struct snd_soc_component *cmpnt_codec =
  131. asoc_rtd_to_codec(rtd, 0)->component;
  132. struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe);
  133. struct mt8192_afe_private *afe_priv = afe->platform_priv;
  134. int phase;
  135. unsigned int monitor;
  136. int test_done_1, test_done_2, test_done_3;
  137. int cycle_1, cycle_2, cycle_3;
  138. int prev_cycle_1, prev_cycle_2, prev_cycle_3;
  139. int chosen_phase_1, chosen_phase_2, chosen_phase_3;
  140. int counter;
  141. int mtkaif_calib_ok;
  142. dev_info(afe->dev, "%s(), start\n", __func__);
  143. pm_runtime_get_sync(afe->dev);
  144. mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA, 1);
  145. mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA, 0);
  146. mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA_CH34, 1);
  147. mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA_CH34, 0);
  148. mt6359_mtkaif_calibration_enable(cmpnt_codec);
  149. /* set clock protocol 2 */
  150. regmap_update_bits(afe->regmap, AFE_AUD_PAD_TOP, 0xff, 0x38);
  151. regmap_update_bits(afe->regmap, AFE_AUD_PAD_TOP, 0xff, 0x39);
  152. /* set test type to synchronizer pulse */
  153. regmap_update_bits(afe_priv->topckgen,
  154. CKSYS_AUD_TOP_CFG, 0xffff, 0x4);
  155. mtkaif_calib_ok = true;
  156. afe_priv->mtkaif_calibration_num_phase = 42; /* mt6359: 0 ~ 42 */
  157. afe_priv->mtkaif_chosen_phase[0] = -1;
  158. afe_priv->mtkaif_chosen_phase[1] = -1;
  159. afe_priv->mtkaif_chosen_phase[2] = -1;
  160. for (phase = 0;
  161. phase <= afe_priv->mtkaif_calibration_num_phase &&
  162. mtkaif_calib_ok;
  163. phase++) {
  164. mt6359_set_mtkaif_calibration_phase(cmpnt_codec,
  165. phase, phase, phase);
  166. regmap_update_bits(afe_priv->topckgen,
  167. CKSYS_AUD_TOP_CFG, 0x1, 0x1);
  168. test_done_1 = 0;
  169. test_done_2 = 0;
  170. test_done_3 = 0;
  171. cycle_1 = -1;
  172. cycle_2 = -1;
  173. cycle_3 = -1;
  174. counter = 0;
  175. while (test_done_1 == 0 ||
  176. test_done_2 == 0 ||
  177. test_done_3 == 0) {
  178. regmap_read(afe_priv->topckgen,
  179. CKSYS_AUD_TOP_MON, &monitor);
  180. test_done_1 = (monitor >> 28) & 0x1;
  181. test_done_2 = (monitor >> 29) & 0x1;
  182. test_done_3 = (monitor >> 30) & 0x1;
  183. if (test_done_1 == 1)
  184. cycle_1 = monitor & 0xf;
  185. if (test_done_2 == 1)
  186. cycle_2 = (monitor >> 4) & 0xf;
  187. if (test_done_3 == 1)
  188. cycle_3 = (monitor >> 8) & 0xf;
  189. /* handle if never test done */
  190. if (++counter > 10000) {
  191. dev_err(afe->dev, "%s(), test fail, cycle_1 %d, cycle_2 %d, cycle_3 %d, monitor 0x%x\n",
  192. __func__,
  193. cycle_1, cycle_2, cycle_3, monitor);
  194. mtkaif_calib_ok = false;
  195. break;
  196. }
  197. }
  198. if (phase == 0) {
  199. prev_cycle_1 = cycle_1;
  200. prev_cycle_2 = cycle_2;
  201. prev_cycle_3 = cycle_3;
  202. }
  203. if (cycle_1 != prev_cycle_1 &&
  204. afe_priv->mtkaif_chosen_phase[0] < 0) {
  205. afe_priv->mtkaif_chosen_phase[0] = phase - 1;
  206. afe_priv->mtkaif_phase_cycle[0] = prev_cycle_1;
  207. }
  208. if (cycle_2 != prev_cycle_2 &&
  209. afe_priv->mtkaif_chosen_phase[1] < 0) {
  210. afe_priv->mtkaif_chosen_phase[1] = phase - 1;
  211. afe_priv->mtkaif_phase_cycle[1] = prev_cycle_2;
  212. }
  213. if (cycle_3 != prev_cycle_3 &&
  214. afe_priv->mtkaif_chosen_phase[2] < 0) {
  215. afe_priv->mtkaif_chosen_phase[2] = phase - 1;
  216. afe_priv->mtkaif_phase_cycle[2] = prev_cycle_3;
  217. }
  218. regmap_update_bits(afe_priv->topckgen,
  219. CKSYS_AUD_TOP_CFG, 0x1, 0x0);
  220. if (afe_priv->mtkaif_chosen_phase[0] >= 0 &&
  221. afe_priv->mtkaif_chosen_phase[1] >= 0 &&
  222. afe_priv->mtkaif_chosen_phase[2] >= 0)
  223. break;
  224. }
  225. if (afe_priv->mtkaif_chosen_phase[0] < 0)
  226. chosen_phase_1 = 0;
  227. else
  228. chosen_phase_1 = afe_priv->mtkaif_chosen_phase[0];
  229. if (afe_priv->mtkaif_chosen_phase[1] < 0)
  230. chosen_phase_2 = 0;
  231. else
  232. chosen_phase_2 = afe_priv->mtkaif_chosen_phase[1];
  233. if (afe_priv->mtkaif_chosen_phase[2] < 0)
  234. chosen_phase_3 = 0;
  235. else
  236. chosen_phase_3 = afe_priv->mtkaif_chosen_phase[2];
  237. mt6359_set_mtkaif_calibration_phase(cmpnt_codec,
  238. chosen_phase_1,
  239. chosen_phase_2,
  240. chosen_phase_3);
  241. /* disable rx fifo */
  242. regmap_update_bits(afe->regmap, AFE_AUD_PAD_TOP, 0xff, 0x38);
  243. mt6359_mtkaif_calibration_disable(cmpnt_codec);
  244. mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA, 1);
  245. mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA, 0);
  246. mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA_CH34, 1);
  247. mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA_CH34, 0);
  248. pm_runtime_put(afe->dev);
  249. dev_info(afe->dev, "%s(), mtkaif_chosen_phase[0/1/2]:%d/%d/%d\n",
  250. __func__,
  251. afe_priv->mtkaif_chosen_phase[0],
  252. afe_priv->mtkaif_chosen_phase[1],
  253. afe_priv->mtkaif_chosen_phase[2]);
  254. return 0;
  255. }
  256. static int mt8192_mt6359_init(struct snd_soc_pcm_runtime *rtd)
  257. {
  258. struct snd_soc_component *cmpnt_afe =
  259. snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
  260. struct snd_soc_component *cmpnt_codec =
  261. asoc_rtd_to_codec(rtd, 0)->component;
  262. struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe);
  263. struct mt8192_afe_private *afe_priv = afe->platform_priv;
  264. /* set mtkaif protocol */
  265. mt6359_set_mtkaif_protocol(cmpnt_codec,
  266. MT6359_MTKAIF_PROTOCOL_2_CLK_P2);
  267. afe_priv->mtkaif_protocol = MTKAIF_PROTOCOL_2_CLK_P2;
  268. /* mtkaif calibration */
  269. mt8192_mt6359_mtkaif_calibration(rtd);
  270. return 0;
  271. }
  272. static int mt8192_rt5682_init(struct snd_soc_pcm_runtime *rtd)
  273. {
  274. struct snd_soc_component *cmpnt_afe =
  275. snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
  276. struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe);
  277. struct snd_soc_component *cmpnt_codec =
  278. asoc_rtd_to_codec(rtd, 0)->component;
  279. struct mt8192_mt6359_priv *priv = snd_soc_card_get_drvdata(rtd->card);
  280. struct snd_soc_jack *jack = &priv->headset_jack;
  281. int ret;
  282. ret = mt8192_dai_i2s_set_share(afe, "I2S8", "I2S9");
  283. if (ret) {
  284. dev_err(rtd->dev, "Failed to set up shared clocks\n");
  285. return ret;
  286. }
  287. ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",
  288. SND_JACK_HEADSET | SND_JACK_BTN_0 |
  289. SND_JACK_BTN_1 | SND_JACK_BTN_2 |
  290. SND_JACK_BTN_3,
  291. jack, mt8192_jack_pins,
  292. ARRAY_SIZE(mt8192_jack_pins));
  293. if (ret) {
  294. dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
  295. return ret;
  296. }
  297. snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
  298. snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
  299. snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
  300. snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
  301. return snd_soc_component_set_jack(cmpnt_codec, jack, NULL);
  302. };
  303. static int mt8192_mt6359_hdmi_init(struct snd_soc_pcm_runtime *rtd)
  304. {
  305. struct snd_soc_component *cmpnt_codec =
  306. asoc_rtd_to_codec(rtd, 0)->component;
  307. struct mt8192_mt6359_priv *priv = snd_soc_card_get_drvdata(rtd->card);
  308. int ret;
  309. ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT,
  310. &priv->hdmi_jack);
  311. if (ret) {
  312. dev_err(rtd->dev, "HDMI Jack creation failed: %d\n", ret);
  313. return ret;
  314. }
  315. return snd_soc_component_set_jack(cmpnt_codec, &priv->hdmi_jack, NULL);
  316. }
  317. static int mt8192_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
  318. struct snd_pcm_hw_params *params)
  319. {
  320. /* fix BE i2s format to S24_LE, clean param mask first */
  321. snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT),
  322. 0, (__force unsigned int)SNDRV_PCM_FORMAT_LAST);
  323. params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
  324. return 0;
  325. }
  326. static int
  327. mt8192_mt6359_cap1_startup(struct snd_pcm_substream *substream)
  328. {
  329. static const unsigned int channels[] = {
  330. 1, 2, 4
  331. };
  332. static const struct snd_pcm_hw_constraint_list constraints_channels = {
  333. .count = ARRAY_SIZE(channels),
  334. .list = channels,
  335. .mask = 0,
  336. };
  337. static const unsigned int rates[] = {
  338. 8000, 16000, 32000, 48000, 96000, 192000
  339. };
  340. static const struct snd_pcm_hw_constraint_list constraints_rates = {
  341. .count = ARRAY_SIZE(rates),
  342. .list = rates,
  343. .mask = 0,
  344. };
  345. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  346. struct snd_pcm_runtime *runtime = substream->runtime;
  347. int ret;
  348. ret = snd_pcm_hw_constraint_list(runtime, 0,
  349. SNDRV_PCM_HW_PARAM_CHANNELS,
  350. &constraints_channels);
  351. if (ret < 0) {
  352. dev_err(rtd->dev, "hw_constraint_list channels failed\n");
  353. return ret;
  354. }
  355. ret = snd_pcm_hw_constraint_list(runtime, 0,
  356. SNDRV_PCM_HW_PARAM_RATE,
  357. &constraints_rates);
  358. if (ret < 0) {
  359. dev_err(rtd->dev, "hw_constraint_list rate failed\n");
  360. return ret;
  361. }
  362. return 0;
  363. }
  364. static const struct snd_soc_ops mt8192_mt6359_capture1_ops = {
  365. .startup = mt8192_mt6359_cap1_startup,
  366. };
  367. static int
  368. mt8192_mt6359_rt5682_startup(struct snd_pcm_substream *substream)
  369. {
  370. static const unsigned int channels[] = {
  371. 1, 2
  372. };
  373. static const struct snd_pcm_hw_constraint_list constraints_channels = {
  374. .count = ARRAY_SIZE(channels),
  375. .list = channels,
  376. .mask = 0,
  377. };
  378. static const unsigned int rates[] = {
  379. 48000
  380. };
  381. static const struct snd_pcm_hw_constraint_list constraints_rates = {
  382. .count = ARRAY_SIZE(rates),
  383. .list = rates,
  384. .mask = 0,
  385. };
  386. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  387. struct snd_pcm_runtime *runtime = substream->runtime;
  388. int ret;
  389. ret = snd_pcm_hw_constraint_list(runtime, 0,
  390. SNDRV_PCM_HW_PARAM_CHANNELS,
  391. &constraints_channels);
  392. if (ret < 0) {
  393. dev_err(rtd->dev, "hw_constraint_list channels failed\n");
  394. return ret;
  395. }
  396. ret = snd_pcm_hw_constraint_list(runtime, 0,
  397. SNDRV_PCM_HW_PARAM_RATE,
  398. &constraints_rates);
  399. if (ret < 0) {
  400. dev_err(rtd->dev, "hw_constraint_list rate failed\n");
  401. return ret;
  402. }
  403. return 0;
  404. }
  405. static const struct snd_soc_ops mt8192_mt6359_rt5682_ops = {
  406. .startup = mt8192_mt6359_rt5682_startup,
  407. };
  408. /* FE */
  409. SND_SOC_DAILINK_DEFS(playback1,
  410. DAILINK_COMP_ARRAY(COMP_CPU("DL1")),
  411. DAILINK_COMP_ARRAY(COMP_DUMMY()),
  412. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  413. SND_SOC_DAILINK_DEFS(playback12,
  414. DAILINK_COMP_ARRAY(COMP_CPU("DL12")),
  415. DAILINK_COMP_ARRAY(COMP_DUMMY()),
  416. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  417. SND_SOC_DAILINK_DEFS(playback2,
  418. DAILINK_COMP_ARRAY(COMP_CPU("DL2")),
  419. DAILINK_COMP_ARRAY(COMP_DUMMY()),
  420. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  421. SND_SOC_DAILINK_DEFS(playback3,
  422. DAILINK_COMP_ARRAY(COMP_CPU("DL3")),
  423. DAILINK_COMP_ARRAY(COMP_DUMMY()),
  424. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  425. SND_SOC_DAILINK_DEFS(playback4,
  426. DAILINK_COMP_ARRAY(COMP_CPU("DL4")),
  427. DAILINK_COMP_ARRAY(COMP_DUMMY()),
  428. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  429. SND_SOC_DAILINK_DEFS(playback5,
  430. DAILINK_COMP_ARRAY(COMP_CPU("DL5")),
  431. DAILINK_COMP_ARRAY(COMP_DUMMY()),
  432. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  433. SND_SOC_DAILINK_DEFS(playback6,
  434. DAILINK_COMP_ARRAY(COMP_CPU("DL6")),
  435. DAILINK_COMP_ARRAY(COMP_DUMMY()),
  436. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  437. SND_SOC_DAILINK_DEFS(playback7,
  438. DAILINK_COMP_ARRAY(COMP_CPU("DL7")),
  439. DAILINK_COMP_ARRAY(COMP_DUMMY()),
  440. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  441. SND_SOC_DAILINK_DEFS(playback8,
  442. DAILINK_COMP_ARRAY(COMP_CPU("DL8")),
  443. DAILINK_COMP_ARRAY(COMP_DUMMY()),
  444. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  445. SND_SOC_DAILINK_DEFS(playback9,
  446. DAILINK_COMP_ARRAY(COMP_CPU("DL9")),
  447. DAILINK_COMP_ARRAY(COMP_DUMMY()),
  448. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  449. SND_SOC_DAILINK_DEFS(capture1,
  450. DAILINK_COMP_ARRAY(COMP_CPU("UL1")),
  451. DAILINK_COMP_ARRAY(COMP_DUMMY()),
  452. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  453. SND_SOC_DAILINK_DEFS(capture2,
  454. DAILINK_COMP_ARRAY(COMP_CPU("UL2")),
  455. DAILINK_COMP_ARRAY(COMP_DUMMY()),
  456. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  457. SND_SOC_DAILINK_DEFS(capture3,
  458. DAILINK_COMP_ARRAY(COMP_CPU("UL3")),
  459. DAILINK_COMP_ARRAY(COMP_DUMMY()),
  460. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  461. SND_SOC_DAILINK_DEFS(capture4,
  462. DAILINK_COMP_ARRAY(COMP_CPU("UL4")),
  463. DAILINK_COMP_ARRAY(COMP_DUMMY()),
  464. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  465. SND_SOC_DAILINK_DEFS(capture5,
  466. DAILINK_COMP_ARRAY(COMP_CPU("UL5")),
  467. DAILINK_COMP_ARRAY(COMP_DUMMY()),
  468. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  469. SND_SOC_DAILINK_DEFS(capture6,
  470. DAILINK_COMP_ARRAY(COMP_CPU("UL6")),
  471. DAILINK_COMP_ARRAY(COMP_DUMMY()),
  472. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  473. SND_SOC_DAILINK_DEFS(capture7,
  474. DAILINK_COMP_ARRAY(COMP_CPU("UL7")),
  475. DAILINK_COMP_ARRAY(COMP_DUMMY()),
  476. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  477. SND_SOC_DAILINK_DEFS(capture8,
  478. DAILINK_COMP_ARRAY(COMP_CPU("UL8")),
  479. DAILINK_COMP_ARRAY(COMP_DUMMY()),
  480. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  481. SND_SOC_DAILINK_DEFS(capture_mono1,
  482. DAILINK_COMP_ARRAY(COMP_CPU("UL_MONO_1")),
  483. DAILINK_COMP_ARRAY(COMP_DUMMY()),
  484. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  485. SND_SOC_DAILINK_DEFS(capture_mono2,
  486. DAILINK_COMP_ARRAY(COMP_CPU("UL_MONO_2")),
  487. DAILINK_COMP_ARRAY(COMP_DUMMY()),
  488. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  489. SND_SOC_DAILINK_DEFS(capture_mono3,
  490. DAILINK_COMP_ARRAY(COMP_CPU("UL_MONO_3")),
  491. DAILINK_COMP_ARRAY(COMP_DUMMY()),
  492. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  493. SND_SOC_DAILINK_DEFS(playback_hdmi,
  494. DAILINK_COMP_ARRAY(COMP_CPU("HDMI")),
  495. DAILINK_COMP_ARRAY(COMP_DUMMY()),
  496. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  497. /* BE */
  498. SND_SOC_DAILINK_DEFS(primary_codec,
  499. DAILINK_COMP_ARRAY(COMP_CPU("ADDA")),
  500. DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
  501. "mt6359-snd-codec-aif1"),
  502. COMP_CODEC("dmic-codec",
  503. "dmic-hifi")),
  504. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  505. SND_SOC_DAILINK_DEFS(primary_codec_ch34,
  506. DAILINK_COMP_ARRAY(COMP_CPU("ADDA_CH34")),
  507. DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
  508. "mt6359-snd-codec-aif2")),
  509. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  510. SND_SOC_DAILINK_DEFS(ap_dmic,
  511. DAILINK_COMP_ARRAY(COMP_CPU("AP_DMIC")),
  512. DAILINK_COMP_ARRAY(COMP_DUMMY()),
  513. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  514. SND_SOC_DAILINK_DEFS(ap_dmic_ch34,
  515. DAILINK_COMP_ARRAY(COMP_CPU("AP_DMIC_CH34")),
  516. DAILINK_COMP_ARRAY(COMP_DUMMY()),
  517. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  518. SND_SOC_DAILINK_DEFS(i2s0,
  519. DAILINK_COMP_ARRAY(COMP_CPU("I2S0")),
  520. DAILINK_COMP_ARRAY(COMP_DUMMY()),
  521. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  522. SND_SOC_DAILINK_DEFS(i2s1,
  523. DAILINK_COMP_ARRAY(COMP_CPU("I2S1")),
  524. DAILINK_COMP_ARRAY(COMP_DUMMY()),
  525. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  526. SND_SOC_DAILINK_DEFS(i2s2,
  527. DAILINK_COMP_ARRAY(COMP_CPU("I2S2")),
  528. DAILINK_COMP_ARRAY(COMP_DUMMY()),
  529. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  530. SND_SOC_DAILINK_DEFS(i2s3,
  531. DAILINK_COMP_ARRAY(COMP_CPU("I2S3")),
  532. DAILINK_COMP_ARRAY(COMP_EMPTY()),
  533. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  534. SND_SOC_DAILINK_DEFS(i2s5,
  535. DAILINK_COMP_ARRAY(COMP_CPU("I2S5")),
  536. DAILINK_COMP_ARRAY(COMP_DUMMY()),
  537. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  538. SND_SOC_DAILINK_DEFS(i2s6,
  539. DAILINK_COMP_ARRAY(COMP_CPU("I2S6")),
  540. DAILINK_COMP_ARRAY(COMP_DUMMY()),
  541. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  542. SND_SOC_DAILINK_DEFS(i2s7,
  543. DAILINK_COMP_ARRAY(COMP_CPU("I2S7")),
  544. DAILINK_COMP_ARRAY(COMP_DUMMY()),
  545. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  546. SND_SOC_DAILINK_DEFS(i2s8,
  547. DAILINK_COMP_ARRAY(COMP_CPU("I2S8")),
  548. DAILINK_COMP_ARRAY(COMP_EMPTY()),
  549. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  550. SND_SOC_DAILINK_DEFS(i2s9,
  551. DAILINK_COMP_ARRAY(COMP_CPU("I2S9")),
  552. DAILINK_COMP_ARRAY(COMP_EMPTY()),
  553. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  554. SND_SOC_DAILINK_DEFS(connsys_i2s,
  555. DAILINK_COMP_ARRAY(COMP_CPU("CONNSYS_I2S")),
  556. DAILINK_COMP_ARRAY(COMP_DUMMY()),
  557. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  558. SND_SOC_DAILINK_DEFS(pcm1,
  559. DAILINK_COMP_ARRAY(COMP_CPU("PCM 1")),
  560. DAILINK_COMP_ARRAY(COMP_DUMMY()),
  561. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  562. SND_SOC_DAILINK_DEFS(pcm2,
  563. DAILINK_COMP_ARRAY(COMP_CPU("PCM 2")),
  564. DAILINK_COMP_ARRAY(COMP_DUMMY()),
  565. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  566. SND_SOC_DAILINK_DEFS(tdm,
  567. DAILINK_COMP_ARRAY(COMP_CPU("TDM")),
  568. DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "i2s-hifi")),
  569. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  570. static struct snd_soc_dai_link mt8192_mt6359_dai_links[] = {
  571. /* Front End DAI links */
  572. {
  573. .name = "Playback_1",
  574. .stream_name = "Playback_1",
  575. .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
  576. SND_SOC_DPCM_TRIGGER_PRE},
  577. .dynamic = 1,
  578. .dpcm_playback = 1,
  579. SND_SOC_DAILINK_REG(playback1),
  580. },
  581. {
  582. .name = "Playback_12",
  583. .stream_name = "Playback_12",
  584. .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
  585. SND_SOC_DPCM_TRIGGER_PRE},
  586. .dynamic = 1,
  587. .dpcm_playback = 1,
  588. SND_SOC_DAILINK_REG(playback12),
  589. },
  590. {
  591. .name = "Playback_2",
  592. .stream_name = "Playback_2",
  593. .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
  594. SND_SOC_DPCM_TRIGGER_PRE},
  595. .dynamic = 1,
  596. .dpcm_playback = 1,
  597. SND_SOC_DAILINK_REG(playback2),
  598. },
  599. {
  600. .name = "Playback_3",
  601. .stream_name = "Playback_3",
  602. .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
  603. SND_SOC_DPCM_TRIGGER_PRE},
  604. .dynamic = 1,
  605. .dpcm_playback = 1,
  606. .ops = &mt8192_mt6359_rt5682_ops,
  607. SND_SOC_DAILINK_REG(playback3),
  608. },
  609. {
  610. .name = "Playback_4",
  611. .stream_name = "Playback_4",
  612. .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
  613. SND_SOC_DPCM_TRIGGER_PRE},
  614. .dynamic = 1,
  615. .dpcm_playback = 1,
  616. SND_SOC_DAILINK_REG(playback4),
  617. },
  618. {
  619. .name = "Playback_5",
  620. .stream_name = "Playback_5",
  621. .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
  622. SND_SOC_DPCM_TRIGGER_PRE},
  623. .dynamic = 1,
  624. .dpcm_playback = 1,
  625. SND_SOC_DAILINK_REG(playback5),
  626. },
  627. {
  628. .name = "Playback_6",
  629. .stream_name = "Playback_6",
  630. .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
  631. SND_SOC_DPCM_TRIGGER_PRE},
  632. .dynamic = 1,
  633. .dpcm_playback = 1,
  634. SND_SOC_DAILINK_REG(playback6),
  635. },
  636. {
  637. .name = "Playback_7",
  638. .stream_name = "Playback_7",
  639. .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
  640. SND_SOC_DPCM_TRIGGER_PRE},
  641. .dynamic = 1,
  642. .dpcm_playback = 1,
  643. SND_SOC_DAILINK_REG(playback7),
  644. },
  645. {
  646. .name = "Playback_8",
  647. .stream_name = "Playback_8",
  648. .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
  649. SND_SOC_DPCM_TRIGGER_PRE},
  650. .dynamic = 1,
  651. .dpcm_playback = 1,
  652. SND_SOC_DAILINK_REG(playback8),
  653. },
  654. {
  655. .name = "Playback_9",
  656. .stream_name = "Playback_9",
  657. .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
  658. SND_SOC_DPCM_TRIGGER_PRE},
  659. .dynamic = 1,
  660. .dpcm_playback = 1,
  661. SND_SOC_DAILINK_REG(playback9),
  662. },
  663. {
  664. .name = "Capture_1",
  665. .stream_name = "Capture_1",
  666. .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
  667. SND_SOC_DPCM_TRIGGER_PRE},
  668. .dynamic = 1,
  669. .dpcm_capture = 1,
  670. .ops = &mt8192_mt6359_capture1_ops,
  671. SND_SOC_DAILINK_REG(capture1),
  672. },
  673. {
  674. .name = "Capture_2",
  675. .stream_name = "Capture_2",
  676. .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
  677. SND_SOC_DPCM_TRIGGER_PRE},
  678. .dynamic = 1,
  679. .dpcm_capture = 1,
  680. .ops = &mt8192_mt6359_rt5682_ops,
  681. SND_SOC_DAILINK_REG(capture2),
  682. },
  683. {
  684. .name = "Capture_3",
  685. .stream_name = "Capture_3",
  686. .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
  687. SND_SOC_DPCM_TRIGGER_PRE},
  688. .dynamic = 1,
  689. .dpcm_capture = 1,
  690. SND_SOC_DAILINK_REG(capture3),
  691. },
  692. {
  693. .name = "Capture_4",
  694. .stream_name = "Capture_4",
  695. .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
  696. SND_SOC_DPCM_TRIGGER_PRE},
  697. .dynamic = 1,
  698. .dpcm_capture = 1,
  699. SND_SOC_DAILINK_REG(capture4),
  700. },
  701. {
  702. .name = "Capture_5",
  703. .stream_name = "Capture_5",
  704. .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
  705. SND_SOC_DPCM_TRIGGER_PRE},
  706. .dynamic = 1,
  707. .dpcm_capture = 1,
  708. SND_SOC_DAILINK_REG(capture5),
  709. },
  710. {
  711. .name = "Capture_6",
  712. .stream_name = "Capture_6",
  713. .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
  714. SND_SOC_DPCM_TRIGGER_PRE},
  715. .dynamic = 1,
  716. .dpcm_capture = 1,
  717. SND_SOC_DAILINK_REG(capture6),
  718. },
  719. {
  720. .name = "Capture_7",
  721. .stream_name = "Capture_7",
  722. .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
  723. SND_SOC_DPCM_TRIGGER_PRE},
  724. .dynamic = 1,
  725. .dpcm_capture = 1,
  726. SND_SOC_DAILINK_REG(capture7),
  727. },
  728. {
  729. .name = "Capture_8",
  730. .stream_name = "Capture_8",
  731. .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
  732. SND_SOC_DPCM_TRIGGER_PRE},
  733. .dynamic = 1,
  734. .dpcm_capture = 1,
  735. SND_SOC_DAILINK_REG(capture8),
  736. },
  737. {
  738. .name = "Capture_Mono_1",
  739. .stream_name = "Capture_Mono_1",
  740. .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
  741. SND_SOC_DPCM_TRIGGER_PRE},
  742. .dynamic = 1,
  743. .dpcm_capture = 1,
  744. SND_SOC_DAILINK_REG(capture_mono1),
  745. },
  746. {
  747. .name = "Capture_Mono_2",
  748. .stream_name = "Capture_Mono_2",
  749. .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
  750. SND_SOC_DPCM_TRIGGER_PRE},
  751. .dynamic = 1,
  752. .dpcm_capture = 1,
  753. SND_SOC_DAILINK_REG(capture_mono2),
  754. },
  755. {
  756. .name = "Capture_Mono_3",
  757. .stream_name = "Capture_Mono_3",
  758. .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
  759. SND_SOC_DPCM_TRIGGER_PRE},
  760. .dynamic = 1,
  761. .dpcm_capture = 1,
  762. SND_SOC_DAILINK_REG(capture_mono3),
  763. },
  764. {
  765. .name = "playback_hdmi",
  766. .stream_name = "Playback_HDMI",
  767. .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
  768. SND_SOC_DPCM_TRIGGER_PRE},
  769. .dynamic = 1,
  770. .dpcm_playback = 1,
  771. SND_SOC_DAILINK_REG(playback_hdmi),
  772. },
  773. /* Back End DAI links */
  774. {
  775. .name = "Primary Codec",
  776. .no_pcm = 1,
  777. .dpcm_playback = 1,
  778. .dpcm_capture = 1,
  779. .ignore_suspend = 1,
  780. .init = mt8192_mt6359_init,
  781. SND_SOC_DAILINK_REG(primary_codec),
  782. },
  783. {
  784. .name = "Primary Codec CH34",
  785. .no_pcm = 1,
  786. .dpcm_playback = 1,
  787. .dpcm_capture = 1,
  788. .ignore_suspend = 1,
  789. SND_SOC_DAILINK_REG(primary_codec_ch34),
  790. },
  791. {
  792. .name = "AP_DMIC",
  793. .no_pcm = 1,
  794. .dpcm_capture = 1,
  795. .ignore_suspend = 1,
  796. SND_SOC_DAILINK_REG(ap_dmic),
  797. },
  798. {
  799. .name = "AP_DMIC_CH34",
  800. .no_pcm = 1,
  801. .dpcm_capture = 1,
  802. .ignore_suspend = 1,
  803. SND_SOC_DAILINK_REG(ap_dmic_ch34),
  804. },
  805. {
  806. .name = "I2S0",
  807. .no_pcm = 1,
  808. .dpcm_capture = 1,
  809. .ignore_suspend = 1,
  810. .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
  811. SND_SOC_DAILINK_REG(i2s0),
  812. },
  813. {
  814. .name = "I2S1",
  815. .no_pcm = 1,
  816. .dpcm_playback = 1,
  817. .ignore_suspend = 1,
  818. .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
  819. SND_SOC_DAILINK_REG(i2s1),
  820. },
  821. {
  822. .name = "I2S2",
  823. .no_pcm = 1,
  824. .dpcm_capture = 1,
  825. .ignore_suspend = 1,
  826. .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
  827. SND_SOC_DAILINK_REG(i2s2),
  828. },
  829. {
  830. .name = "I2S3",
  831. .no_pcm = 1,
  832. .dpcm_playback = 1,
  833. .ignore_suspend = 1,
  834. .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
  835. SND_SOC_DAILINK_REG(i2s3),
  836. },
  837. {
  838. .name = "I2S5",
  839. .no_pcm = 1,
  840. .dpcm_playback = 1,
  841. .ignore_suspend = 1,
  842. .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
  843. SND_SOC_DAILINK_REG(i2s5),
  844. },
  845. {
  846. .name = "I2S6",
  847. .no_pcm = 1,
  848. .dpcm_capture = 1,
  849. .ignore_suspend = 1,
  850. .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
  851. SND_SOC_DAILINK_REG(i2s6),
  852. },
  853. {
  854. .name = "I2S7",
  855. .no_pcm = 1,
  856. .dpcm_playback = 1,
  857. .ignore_suspend = 1,
  858. .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
  859. SND_SOC_DAILINK_REG(i2s7),
  860. },
  861. {
  862. .name = "I2S8",
  863. .no_pcm = 1,
  864. .dpcm_capture = 1,
  865. .ignore_suspend = 1,
  866. .init = mt8192_rt5682_init,
  867. .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
  868. SND_SOC_DAILINK_REG(i2s8),
  869. .ops = &mt8192_rt5682x_i2s_ops,
  870. },
  871. {
  872. .name = "I2S9",
  873. .no_pcm = 1,
  874. .dpcm_playback = 1,
  875. .ignore_suspend = 1,
  876. .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
  877. SND_SOC_DAILINK_REG(i2s9),
  878. .ops = &mt8192_rt5682x_i2s_ops,
  879. },
  880. {
  881. .name = "CONNSYS_I2S",
  882. .no_pcm = 1,
  883. .dpcm_capture = 1,
  884. .ignore_suspend = 1,
  885. SND_SOC_DAILINK_REG(connsys_i2s),
  886. },
  887. {
  888. .name = "PCM 1",
  889. .no_pcm = 1,
  890. .dpcm_playback = 1,
  891. .dpcm_capture = 1,
  892. .ignore_suspend = 1,
  893. SND_SOC_DAILINK_REG(pcm1),
  894. },
  895. {
  896. .name = "PCM 2",
  897. .no_pcm = 1,
  898. .dpcm_playback = 1,
  899. .dpcm_capture = 1,
  900. .ignore_suspend = 1,
  901. SND_SOC_DAILINK_REG(pcm2),
  902. },
  903. {
  904. .name = "TDM",
  905. .no_pcm = 1,
  906. .dai_fmt = SND_SOC_DAIFMT_DSP_A |
  907. SND_SOC_DAIFMT_IB_NF |
  908. SND_SOC_DAIFMT_CBM_CFM,
  909. .dpcm_playback = 1,
  910. .ignore_suspend = 1,
  911. .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
  912. .ignore = 1,
  913. .init = mt8192_mt6359_hdmi_init,
  914. SND_SOC_DAILINK_REG(tdm),
  915. },
  916. };
  917. static const struct snd_soc_dapm_widget
  918. mt8192_mt6359_rt1015_rt5682_widgets[] = {
  919. SND_SOC_DAPM_SPK("Left Spk", NULL),
  920. SND_SOC_DAPM_SPK("Right Spk", NULL),
  921. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  922. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  923. SND_SOC_DAPM_OUTPUT("TDM Out"),
  924. };
  925. static const struct snd_soc_dapm_route mt8192_mt6359_rt1015_rt5682_routes[] = {
  926. /* speaker */
  927. { "Left Spk", NULL, "Left SPO" },
  928. { "Right Spk", NULL, "Right SPO" },
  929. /* headset */
  930. { "Headphone Jack", NULL, "HPOL" },
  931. { "Headphone Jack", NULL, "HPOR" },
  932. { "IN1P", NULL, "Headset Mic" },
  933. /* TDM */
  934. { "TDM Out", NULL, "TDM" },
  935. };
  936. static const struct snd_kcontrol_new mt8192_mt6359_rt1015_rt5682_controls[] = {
  937. SOC_DAPM_PIN_SWITCH("Left Spk"),
  938. SOC_DAPM_PIN_SWITCH("Right Spk"),
  939. SOC_DAPM_PIN_SWITCH("Headphone Jack"),
  940. SOC_DAPM_PIN_SWITCH("Headset Mic"),
  941. };
  942. static struct snd_soc_codec_conf rt1015_amp_conf[] = {
  943. {
  944. .dlc = COMP_CODEC_CONF(RT1015_DEV0_NAME),
  945. .name_prefix = "Left",
  946. },
  947. {
  948. .dlc = COMP_CODEC_CONF(RT1015_DEV1_NAME),
  949. .name_prefix = "Right",
  950. },
  951. };
  952. static struct snd_soc_card mt8192_mt6359_rt1015_rt5682_card = {
  953. .name = RT1015_RT5682_CARD_NAME,
  954. .driver_name = DRIVER_NAME,
  955. .owner = THIS_MODULE,
  956. .dai_link = mt8192_mt6359_dai_links,
  957. .num_links = ARRAY_SIZE(mt8192_mt6359_dai_links),
  958. .controls = mt8192_mt6359_rt1015_rt5682_controls,
  959. .num_controls = ARRAY_SIZE(mt8192_mt6359_rt1015_rt5682_controls),
  960. .dapm_widgets = mt8192_mt6359_rt1015_rt5682_widgets,
  961. .num_dapm_widgets = ARRAY_SIZE(mt8192_mt6359_rt1015_rt5682_widgets),
  962. .dapm_routes = mt8192_mt6359_rt1015_rt5682_routes,
  963. .num_dapm_routes = ARRAY_SIZE(mt8192_mt6359_rt1015_rt5682_routes),
  964. .codec_conf = rt1015_amp_conf,
  965. .num_configs = ARRAY_SIZE(rt1015_amp_conf),
  966. };
  967. static const struct snd_soc_dapm_widget mt8192_mt6359_rt1015p_rt5682x_widgets[] = {
  968. SND_SOC_DAPM_SPK("Speakers", NULL),
  969. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  970. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  971. };
  972. static const struct snd_soc_dapm_route mt8192_mt6359_rt1015p_rt5682x_routes[] = {
  973. /* speaker */
  974. { "Speakers", NULL, "Speaker" },
  975. /* headset */
  976. { "Headphone Jack", NULL, "HPOL" },
  977. { "Headphone Jack", NULL, "HPOR" },
  978. { "IN1P", NULL, "Headset Mic" },
  979. };
  980. static const struct snd_kcontrol_new mt8192_mt6359_rt1015p_rt5682x_controls[] = {
  981. SOC_DAPM_PIN_SWITCH("Speakers"),
  982. SOC_DAPM_PIN_SWITCH("Headphone Jack"),
  983. SOC_DAPM_PIN_SWITCH("Headset Mic"),
  984. };
  985. static struct snd_soc_card mt8192_mt6359_rt1015p_rt5682x_card = {
  986. .driver_name = DRIVER_NAME,
  987. .owner = THIS_MODULE,
  988. .dai_link = mt8192_mt6359_dai_links,
  989. .num_links = ARRAY_SIZE(mt8192_mt6359_dai_links),
  990. .controls = mt8192_mt6359_rt1015p_rt5682x_controls,
  991. .num_controls = ARRAY_SIZE(mt8192_mt6359_rt1015p_rt5682x_controls),
  992. .dapm_widgets = mt8192_mt6359_rt1015p_rt5682x_widgets,
  993. .num_dapm_widgets = ARRAY_SIZE(mt8192_mt6359_rt1015p_rt5682x_widgets),
  994. .dapm_routes = mt8192_mt6359_rt1015p_rt5682x_routes,
  995. .num_dapm_routes = ARRAY_SIZE(mt8192_mt6359_rt1015p_rt5682x_routes),
  996. };
  997. static int mt8192_mt6359_card_set_be_link(struct snd_soc_card *card,
  998. struct snd_soc_dai_link *link,
  999. struct device_node *node,
  1000. char *link_name)
  1001. {
  1002. int ret;
  1003. if (node && strcmp(link->name, link_name) == 0) {
  1004. ret = snd_soc_of_get_dai_link_codecs(card->dev, node, link);
  1005. if (ret < 0) {
  1006. dev_err_probe(card->dev, ret, "get dai link codecs fail\n");
  1007. return ret;
  1008. }
  1009. }
  1010. return 0;
  1011. }
  1012. static int mt8192_mt6359_dev_probe(struct platform_device *pdev)
  1013. {
  1014. struct snd_soc_card *card;
  1015. struct device_node *platform_node, *hdmi_codec, *headset_codec, *speaker_codec;
  1016. int ret, i;
  1017. struct snd_soc_dai_link *dai_link;
  1018. struct mt8192_mt6359_priv *priv;
  1019. card = (struct snd_soc_card *)of_device_get_match_data(&pdev->dev);
  1020. if (!card)
  1021. return -EINVAL;
  1022. card->dev = &pdev->dev;
  1023. if (of_device_is_compatible(pdev->dev.of_node, RT1015P_RT5682_OF_NAME))
  1024. card->name = RT1015P_RT5682_CARD_NAME;
  1025. else if (of_device_is_compatible(pdev->dev.of_node, RT1015P_RT5682S_OF_NAME))
  1026. card->name = RT1015P_RT5682S_CARD_NAME;
  1027. else
  1028. dev_dbg(&pdev->dev, "No need to set card name\n");
  1029. hdmi_codec = of_parse_phandle(pdev->dev.of_node, "mediatek,hdmi-codec", 0);
  1030. if (!hdmi_codec)
  1031. dev_dbg(&pdev->dev, "The machine has no hdmi-codec\n");
  1032. platform_node = of_parse_phandle(pdev->dev.of_node, "mediatek,platform", 0);
  1033. if (!platform_node) {
  1034. ret = -EINVAL;
  1035. dev_err_probe(&pdev->dev, ret, "Property 'platform' missing or invalid\n");
  1036. goto err_platform_node;
  1037. }
  1038. speaker_codec = of_get_child_by_name(pdev->dev.of_node, "speaker-codecs");
  1039. if (!speaker_codec) {
  1040. ret = -EINVAL;
  1041. dev_err_probe(&pdev->dev, ret, "Property 'speaker-codecs' missing or invalid\n");
  1042. goto err_speaker_codec;
  1043. }
  1044. headset_codec = of_get_child_by_name(pdev->dev.of_node, "headset-codec");
  1045. if (!headset_codec) {
  1046. ret = -EINVAL;
  1047. dev_err_probe(&pdev->dev, ret, "Property 'headset-codec' missing or invalid\n");
  1048. goto err_headset_codec;
  1049. }
  1050. for_each_card_prelinks(card, i, dai_link) {
  1051. ret = mt8192_mt6359_card_set_be_link(card, dai_link, speaker_codec, "I2S3");
  1052. if (ret) {
  1053. dev_err_probe(&pdev->dev, ret, "%s set speaker_codec fail\n",
  1054. dai_link->name);
  1055. goto err_probe;
  1056. }
  1057. ret = mt8192_mt6359_card_set_be_link(card, dai_link, headset_codec, "I2S8");
  1058. if (ret) {
  1059. dev_err_probe(&pdev->dev, ret, "%s set headset_codec fail\n",
  1060. dai_link->name);
  1061. goto err_probe;
  1062. }
  1063. ret = mt8192_mt6359_card_set_be_link(card, dai_link, headset_codec, "I2S9");
  1064. if (ret) {
  1065. dev_err_probe(&pdev->dev, ret, "%s set headset_codec fail\n",
  1066. dai_link->name);
  1067. goto err_probe;
  1068. }
  1069. if (hdmi_codec && strcmp(dai_link->name, "TDM") == 0) {
  1070. dai_link->codecs->of_node = hdmi_codec;
  1071. dai_link->ignore = 0;
  1072. }
  1073. if (strcmp(dai_link->codecs[0].dai_name, RT1015_CODEC_DAI) == 0)
  1074. dai_link->ops = &mt8192_rt1015_i2s_ops;
  1075. if (!dai_link->platforms->name)
  1076. dai_link->platforms->of_node = platform_node;
  1077. }
  1078. priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
  1079. if (!priv) {
  1080. ret = -ENOMEM;
  1081. goto err_probe;
  1082. }
  1083. snd_soc_card_set_drvdata(card, priv);
  1084. ret = mt8192_afe_gpio_init(&pdev->dev);
  1085. if (ret) {
  1086. dev_err_probe(&pdev->dev, ret, "%s init gpio error\n", __func__);
  1087. goto err_probe;
  1088. }
  1089. ret = devm_snd_soc_register_card(&pdev->dev, card);
  1090. if (ret)
  1091. dev_err_probe(&pdev->dev, ret, "%s snd_soc_register_card fail\n", __func__);
  1092. err_probe:
  1093. of_node_put(headset_codec);
  1094. err_headset_codec:
  1095. of_node_put(speaker_codec);
  1096. err_speaker_codec:
  1097. of_node_put(platform_node);
  1098. err_platform_node:
  1099. of_node_put(hdmi_codec);
  1100. return ret;
  1101. }
  1102. #ifdef CONFIG_OF
  1103. static const struct of_device_id mt8192_mt6359_dt_match[] = {
  1104. {
  1105. .compatible = RT1015_RT5682_OF_NAME,
  1106. .data = &mt8192_mt6359_rt1015_rt5682_card,
  1107. },
  1108. {
  1109. .compatible = RT1015P_RT5682_OF_NAME,
  1110. .data = &mt8192_mt6359_rt1015p_rt5682x_card,
  1111. },
  1112. {
  1113. .compatible = RT1015P_RT5682S_OF_NAME,
  1114. .data = &mt8192_mt6359_rt1015p_rt5682x_card,
  1115. },
  1116. {}
  1117. };
  1118. #endif
  1119. static const struct dev_pm_ops mt8192_mt6359_pm_ops = {
  1120. .poweroff = snd_soc_poweroff,
  1121. .restore = snd_soc_resume,
  1122. };
  1123. static struct platform_driver mt8192_mt6359_driver = {
  1124. .driver = {
  1125. .name = DRIVER_NAME,
  1126. #ifdef CONFIG_OF
  1127. .of_match_table = mt8192_mt6359_dt_match,
  1128. #endif
  1129. .pm = &mt8192_mt6359_pm_ops,
  1130. },
  1131. .probe = mt8192_mt6359_dev_probe,
  1132. };
  1133. module_platform_driver(mt8192_mt6359_driver);
  1134. /* Module information */
  1135. MODULE_DESCRIPTION("MT8192-MT6359 ALSA SoC machine driver");
  1136. MODULE_AUTHOR("Jiaxin Yu <[email protected]>");
  1137. MODULE_LICENSE("GPL v2");
  1138. MODULE_ALIAS("mt8192_mt6359 soc card");