waipio.c 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #include <linux/clk.h>
  7. #include <linux/delay.h>
  8. #include <linux/gpio.h>
  9. #include <linux/of_gpio.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/slab.h>
  12. #include <linux/io.h>
  13. #include <linux/module.h>
  14. #include <linux/input.h>
  15. #include <linux/of_device.h>
  16. #include <linux/soc/qcom/fsa4480-i2c.h>
  17. #include <linux/pm_qos.h>
  18. #include <sound/control.h>
  19. #include <sound/core.h>
  20. #include <sound/soc.h>
  21. #include <sound/soc-dapm.h>
  22. #include <sound/pcm.h>
  23. #include <sound/pcm_params.h>
  24. #include <sound/info.h>
  25. #include <soc/snd_event.h>
  26. #include <dsp/audio_prm.h>
  27. #include <soc/swr-common.h>
  28. #include <soc/soundwire.h>
  29. #include "device_event.h"
  30. #include "asoc/msm-cdc-pinctrl.h"
  31. #include "asoc/wcd-mbhc-v2.h"
  32. #include "codecs/wcd938x/wcd938x-mbhc.h"
  33. #include "codecs/wsa883x/wsa883x.h"
  34. #include "codecs/wcd938x/wcd938x.h"
  35. #include "codecs/lpass-cdc/lpass-cdc.h"
  36. #include <bindings/audio-codec-port-types.h>
  37. #include "codecs/lpass-cdc/lpass-cdc-wsa-macro.h"
  38. #include "waipio-port-config.h"
  39. #include "msm-audio-defs.h"
  40. #include "msm_common.h"
  41. #include "msm_dailink.h"
  42. #define DRV_NAME "waipio-asoc-snd"
  43. #define __CHIPSET__ "WAIPIO "
  44. #define MSM_DAILINK_NAME(name) (__CHIPSET__#name)
  45. #define WCD9XXX_MBHC_DEF_RLOADS 5
  46. #define WCD9XXX_MBHC_DEF_BUTTONS 8
  47. #define CODEC_EXT_CLK_RATE 9600000
  48. #define DEV_NAME_STR_LEN 32
  49. #define WCD_MBHC_HS_V_MAX 1600
  50. #define WCN_CDC_SLIM_RX_CH_MAX 2
  51. #define WCN_CDC_SLIM_TX_CH_MAX 2
  52. #define WCN_CDC_SLIM_TX_CH_MAX_LITO 3
  53. /* Number of WSAs */
  54. #define MONO_SPEAKER 1
  55. #define STEREO_SPEAKER 2
  56. #define QUAD_SPEAKER 4
  57. struct msm_asoc_mach_data {
  58. struct snd_info_entry *codec_root;
  59. struct msm_common_pdata *common_pdata;
  60. int usbc_en2_gpio; /* used by gpio driver API */
  61. struct device_node *dmic01_gpio_p; /* used by pinctrl API */
  62. struct device_node *dmic23_gpio_p; /* used by pinctrl API */
  63. struct device_node *dmic45_gpio_p; /* used by pinctrl API */
  64. struct pinctrl *usbc_en2_gpio_p; /* used by pinctrl API */
  65. bool is_afe_config_done;
  66. struct device_node *fsa_handle;
  67. struct clk *lpass_audio_hw_vote;
  68. int core_audio_vote_count;
  69. u32 wsa_max_devs;
  70. int wcd_disabled;
  71. int (*get_dev_num)(struct snd_soc_component *);
  72. int backend_used;
  73. struct prm_earpa_hw_intf_config upd_config;
  74. };
  75. static bool is_initial_boot;
  76. static bool codec_reg_done;
  77. static struct snd_soc_card snd_soc_card_waipio_msm;
  78. static int dmic_0_1_gpio_cnt;
  79. static int dmic_2_3_gpio_cnt;
  80. static int dmic_4_5_gpio_cnt;
  81. static void *def_wcd_mbhc_cal(void);
  82. static int msm_rx_tx_codec_init(struct snd_soc_pcm_runtime*);
  83. static int msm_int_wsa_init(struct snd_soc_pcm_runtime*);
  84. /*
  85. * Need to report LINEIN
  86. * if R/L channel impedance is larger than 5K ohm
  87. */
  88. static struct wcd_mbhc_config wcd_mbhc_cfg = {
  89. .read_fw_bin = false,
  90. .calibration = NULL,
  91. .detect_extn_cable = true,
  92. .mono_stero_detection = false,
  93. .swap_gnd_mic = NULL,
  94. .hs_ext_micbias = true,
  95. .key_code[0] = KEY_MEDIA,
  96. .key_code[1] = KEY_VOICECOMMAND,
  97. .key_code[2] = KEY_VOLUMEUP,
  98. .key_code[3] = KEY_VOLUMEDOWN,
  99. .key_code[4] = 0,
  100. .key_code[5] = 0,
  101. .key_code[6] = 0,
  102. .key_code[7] = 0,
  103. .linein_th = 5000,
  104. .moisture_en = false,
  105. .mbhc_micbias = MIC_BIAS_2,
  106. .anc_micbias = MIC_BIAS_2,
  107. .enable_anc_mic_detect = false,
  108. .moisture_duty_cycle_en = true,
  109. };
  110. static bool msm_usbc_swap_gnd_mic(struct snd_soc_component *component, bool active)
  111. {
  112. struct snd_soc_card *card = component->card;
  113. struct msm_asoc_mach_data *pdata =
  114. snd_soc_card_get_drvdata(card);
  115. if (!pdata->fsa_handle)
  116. return false;
  117. return fsa4480_switch_event(pdata->fsa_handle, FSA_MIC_GND_SWAP);
  118. }
  119. static void msm_parse_upd_configuration(struct platform_device *pdev,
  120. struct msm_asoc_mach_data *pdata)
  121. {
  122. int ret = 0;
  123. u32 dt_values[2];
  124. if (!pdev || !pdata)
  125. return;
  126. ret = of_property_read_string(pdev->dev.of_node,
  127. "qcom,upd_backends_used", &pdata->upd_config.backend_used);
  128. if (ret) {
  129. pr_debug("%s:could not find %s entry in dt\n",
  130. __func__, "qcom,upd_backends_used");
  131. return;
  132. }
  133. ret = of_property_read_u32_array(pdev->dev.of_node,
  134. "qcom,upd_lpass_reg_addr", dt_values, MAX_EARPA_REG);
  135. if (ret) {
  136. pr_debug("%s: could not find %s entry in dt\n",
  137. __func__, "qcom,upd_lpass_reg_addr");
  138. return;
  139. } else {
  140. pdata->upd_config.ear_pa_hw_reg_cfg.lpass_cdc_rx0_rx_path_ctl_phy_addr =
  141. dt_values[0];
  142. pdata->upd_config.ear_pa_hw_reg_cfg.lpass_wr_fifo_reg_phy_addr =
  143. dt_values[1];
  144. }
  145. ret = of_property_read_u32(pdev->dev.of_node,
  146. "qcom,upd_ear_pa_reg_addr", &pdata->upd_config.ear_pa_pkd_reg_addr);
  147. if (ret) {
  148. pr_debug("%s: could not find %s entry in dt\n",
  149. __func__, "qcom,upd_ear_pa_reg_addr");
  150. }
  151. }
  152. static void msm_set_upd_config(struct snd_soc_pcm_runtime *rtd)
  153. {
  154. int val1 = 0, val2 = 0, ret = 0;
  155. u8 dev_num = 0;
  156. struct snd_soc_component *component = NULL;
  157. struct msm_asoc_mach_data *pdata = NULL;
  158. if (!rtd) {
  159. pr_err("%s: rtd is NULL\n", __func__);
  160. return;
  161. }
  162. pdata = snd_soc_card_get_drvdata(rtd->card);
  163. if (!pdata) {
  164. pr_err("%s: pdata is NULL\n", __func__);
  165. return;
  166. }
  167. if (!pdata->upd_config.ear_pa_hw_reg_cfg.lpass_cdc_rx0_rx_path_ctl_phy_addr ||
  168. !pdata->upd_config.ear_pa_hw_reg_cfg.lpass_wr_fifo_reg_phy_addr ||
  169. !pdata->upd_config.ear_pa_pkd_reg_addr) {
  170. pr_err("%s: upd static configuration is not set\n", __func__);
  171. return;
  172. }
  173. if (!strcmp(pdata->upd_config.backend_used, "wsa")) {
  174. if (pdata->wsa_max_devs > 0) {
  175. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.1");
  176. if (!component) {
  177. pr_err("%s: %s component is NULL\n", __func__,
  178. "wsa-codec.1");
  179. return;
  180. }
  181. }
  182. } else {
  183. component = snd_soc_rtdcom_lookup(rtd, WCD938X_DRV_NAME);
  184. if (!component) {
  185. component = snd_soc_rtdcom_lookup(rtd, WCD937X_DRV_NAME);
  186. if (!component) {
  187. pr_err("%s component is NULL\n", __func__);
  188. return;
  189. }
  190. }
  191. }
  192. if (!strcmp(pdata->upd_config.backend_used, "wsa")) {
  193. pdata->get_dev_num = wsa883x_codec_get_dev_num;
  194. }
  195. else {
  196. if(!strncmp(component->driver->name, WCD937X_DRV_NAME,
  197. strlen(WCD937X_DRV_NAME))){
  198. pdata->get_dev_num = wcd937x_codec_get_dev_num;
  199. } else if(!strncmp(component->driver->name, WCD938X_DRV_NAME,
  200. strlen(WCD938X_DRV_NAME))){
  201. pdata->get_dev_num = wcd938x_codec_get_dev_num;
  202. }
  203. }
  204. if (!pdata->get_dev_num) {
  205. pr_err("%s: get_dev_num is NULL\n", __func__);
  206. return;
  207. }
  208. dev_num = pdata->get_dev_num(component);
  209. if (dev_num < 0 || dev_num > 6) {
  210. pr_err("%s: invalid slave dev num : %d\n", __func__,
  211. dev_num);
  212. return;
  213. }
  214. pdata->upd_config.ear_pa_pkd_cfg.ear_pa_enable_pkd_reg_addr =
  215. pdata->upd_config.ear_pa_pkd_reg_addr & 0xFFFF;
  216. pdata->upd_config.ear_pa_pkd_cfg.ear_pa_disable_pkd_reg_addr =
  217. pdata->upd_config.ear_pa_pkd_reg_addr & 0xFFFF;
  218. val1 = val2 = 0;
  219. /* bits 16:19 carry command id */
  220. val1 |= 1 << 16;
  221. /* bits 20:23 carry swr device number */
  222. val1 |= dev_num << 20;
  223. /*
  224. * bits 24:31 carry 8 bit data to disable or enable ear pa
  225. * for wcd 7bit is global enable bit - 1 -enable. 0 - disable
  226. * for wsa 0bit is global enable bit - 1 -enable, 0 - disable
  227. */
  228. val2 = val1;
  229. if (!strcmp(pdata->upd_config.backend_used, "wsa"))
  230. val1 |= 1 << 24;
  231. else
  232. val1 |= 1 << 31;
  233. pdata->upd_config.ear_pa_pkd_cfg.ear_pa_enable_pkd_reg_addr |= val1;
  234. pdata->upd_config.ear_pa_pkd_cfg.ear_pa_disable_pkd_reg_addr |= val2;
  235. ret = audio_prm_set_cdc_earpa_duty_cycling_req(&pdata->upd_config, 1);
  236. if (ret < 0)
  237. pr_err("%s: upd cdc duty cycling registration failed\n", __func__);
  238. }
  239. static struct snd_soc_ops msm_common_be_ops = {
  240. .hw_params = msm_common_snd_hw_params,
  241. .startup = msm_common_snd_startup,
  242. .shutdown = msm_common_snd_shutdown,
  243. };
  244. static int msm_dmic_event(struct snd_soc_dapm_widget *w,
  245. struct snd_kcontrol *kcontrol, int event)
  246. {
  247. struct msm_asoc_mach_data *pdata = NULL;
  248. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  249. int ret = 0;
  250. u32 dmic_idx;
  251. int *dmic_gpio_cnt;
  252. struct device_node *dmic_gpio;
  253. char *wname;
  254. wname = strpbrk(w->name, "012345");
  255. if (!wname) {
  256. dev_err(component->dev, "%s: widget not found\n", __func__);
  257. return -EINVAL;
  258. }
  259. ret = kstrtouint(wname, 10, &dmic_idx);
  260. if (ret < 0) {
  261. dev_err(component->dev, "%s: Invalid DMIC line on the codec\n",
  262. __func__);
  263. return -EINVAL;
  264. }
  265. pdata = snd_soc_card_get_drvdata(component->card);
  266. switch (dmic_idx) {
  267. case 0:
  268. case 1:
  269. dmic_gpio_cnt = &dmic_0_1_gpio_cnt;
  270. dmic_gpio = pdata->dmic01_gpio_p;
  271. break;
  272. case 2:
  273. case 3:
  274. dmic_gpio_cnt = &dmic_2_3_gpio_cnt;
  275. dmic_gpio = pdata->dmic23_gpio_p;
  276. break;
  277. case 4:
  278. case 5:
  279. dmic_gpio_cnt = &dmic_4_5_gpio_cnt;
  280. dmic_gpio = pdata->dmic45_gpio_p;
  281. break;
  282. default:
  283. dev_err(component->dev, "%s: Invalid DMIC Selection\n",
  284. __func__);
  285. return -EINVAL;
  286. }
  287. dev_dbg(component->dev, "%s: event %d DMIC%d dmic_gpio_cnt %d\n",
  288. __func__, event, dmic_idx, *dmic_gpio_cnt);
  289. switch (event) {
  290. case SND_SOC_DAPM_PRE_PMU:
  291. (*dmic_gpio_cnt)++;
  292. if (*dmic_gpio_cnt == 1) {
  293. ret = msm_cdc_pinctrl_select_active_state(
  294. dmic_gpio);
  295. if (ret < 0) {
  296. pr_err("%s: gpio set cannot be activated %sd",
  297. __func__, "dmic_gpio");
  298. return ret;
  299. }
  300. }
  301. break;
  302. case SND_SOC_DAPM_POST_PMD:
  303. (*dmic_gpio_cnt)--;
  304. if (*dmic_gpio_cnt == 0) {
  305. ret = msm_cdc_pinctrl_select_sleep_state(
  306. dmic_gpio);
  307. if (ret < 0) {
  308. pr_err("%s: gpio set cannot be de-activated %sd",
  309. __func__, "dmic_gpio");
  310. return ret;
  311. }
  312. }
  313. break;
  314. default:
  315. pr_err("%s: invalid DAPM event %d\n", __func__, event);
  316. return -EINVAL;
  317. }
  318. return 0;
  319. }
  320. static const struct snd_soc_dapm_widget msm_int_dapm_widgets[] = {
  321. SND_SOC_DAPM_MIC("Analog Mic1", NULL),
  322. SND_SOC_DAPM_MIC("Analog Mic2", NULL),
  323. SND_SOC_DAPM_MIC("Analog Mic3", NULL),
  324. SND_SOC_DAPM_MIC("Analog Mic4", NULL),
  325. SND_SOC_DAPM_MIC("Analog Mic5", NULL),
  326. SND_SOC_DAPM_MIC("Digital Mic0", msm_dmic_event),
  327. SND_SOC_DAPM_MIC("Digital Mic1", msm_dmic_event),
  328. SND_SOC_DAPM_MIC("Digital Mic2", msm_dmic_event),
  329. SND_SOC_DAPM_MIC("Digital Mic3", msm_dmic_event),
  330. SND_SOC_DAPM_MIC("Digital Mic4", msm_dmic_event),
  331. SND_SOC_DAPM_MIC("Digital Mic5", msm_dmic_event),
  332. SND_SOC_DAPM_MIC("Digital Mic6", NULL),
  333. SND_SOC_DAPM_MIC("Digital Mic7", NULL),
  334. };
  335. static int msm_wcn_init(struct snd_soc_pcm_runtime *rtd)
  336. {
  337. unsigned int rx_ch[WCN_CDC_SLIM_RX_CH_MAX] = {157, 158};
  338. unsigned int tx_ch[WCN_CDC_SLIM_TX_CH_MAX] = {159, 160};
  339. struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
  340. int ret = 0;
  341. ret = snd_soc_dai_set_channel_map(codec_dai, ARRAY_SIZE(tx_ch),
  342. tx_ch, ARRAY_SIZE(rx_ch), rx_ch);
  343. if (ret)
  344. return ret;
  345. msm_common_dai_link_init(rtd);
  346. return ret;
  347. }
  348. static struct snd_info_entry *msm_snd_info_create_subdir(struct module *mod,
  349. const char *name,
  350. struct snd_info_entry *parent)
  351. {
  352. struct snd_info_entry *entry;
  353. entry = snd_info_create_module_entry(mod, name, parent);
  354. if (!entry)
  355. return NULL;
  356. entry->mode = S_IFDIR | 0555;
  357. if (snd_info_register(entry) < 0) {
  358. snd_info_free_entry(entry);
  359. return NULL;
  360. }
  361. return entry;
  362. }
  363. static void *def_wcd_mbhc_cal(void)
  364. {
  365. void *wcd_mbhc_cal;
  366. struct wcd_mbhc_btn_detect_cfg *btn_cfg;
  367. u16 *btn_high;
  368. wcd_mbhc_cal = kzalloc(WCD_MBHC_CAL_SIZE(WCD_MBHC_DEF_BUTTONS,
  369. WCD9XXX_MBHC_DEF_RLOADS), GFP_KERNEL);
  370. if (!wcd_mbhc_cal)
  371. return NULL;
  372. WCD_MBHC_CAL_PLUG_TYPE_PTR(wcd_mbhc_cal)->v_hs_max = WCD_MBHC_HS_V_MAX;
  373. WCD_MBHC_CAL_BTN_DET_PTR(wcd_mbhc_cal)->num_btn = WCD_MBHC_DEF_BUTTONS;
  374. btn_cfg = WCD_MBHC_CAL_BTN_DET_PTR(wcd_mbhc_cal);
  375. btn_high = ((void *)&btn_cfg->_v_btn_low) +
  376. (sizeof(btn_cfg->_v_btn_low[0]) * btn_cfg->num_btn);
  377. btn_high[0] = 75;
  378. btn_high[1] = 150;
  379. btn_high[2] = 237;
  380. btn_high[3] = 500;
  381. btn_high[4] = 500;
  382. btn_high[5] = 500;
  383. btn_high[6] = 500;
  384. btn_high[7] = 500;
  385. return wcd_mbhc_cal;
  386. }
  387. /* Digital audio interface glue - connects codec <---> CPU */
  388. static struct snd_soc_dai_link msm_common_be_dai_links[] = {
  389. /* Proxy Tx BACK END DAI Link */
  390. {
  391. .name = LPASS_BE_RT_PROXY_PCM_TX,
  392. .stream_name = LPASS_BE_RT_PROXY_PCM_TX,
  393. .capture_only = 1,
  394. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  395. SND_SOC_DPCM_TRIGGER_POST},
  396. .ignore_suspend = 1,
  397. .ops = &msm_common_be_ops,
  398. SND_SOC_DAILINK_REG(proxy_tx),
  399. },
  400. /* Proxy Rx BACK END DAI Link */
  401. {
  402. .name = LPASS_BE_RT_PROXY_PCM_RX,
  403. .stream_name = LPASS_BE_RT_PROXY_PCM_RX,
  404. .playback_only = 1,
  405. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  406. SND_SOC_DPCM_TRIGGER_POST},
  407. .ignore_pmdown_time = 1,
  408. .ignore_suspend = 1,
  409. .ops = &msm_common_be_ops,
  410. SND_SOC_DAILINK_REG(proxy_rx),
  411. },
  412. {
  413. .name = LPASS_BE_USB_AUDIO_RX,
  414. .stream_name = LPASS_BE_USB_AUDIO_RX,
  415. .playback_only = 1,
  416. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  417. SND_SOC_DPCM_TRIGGER_POST},
  418. .ignore_pmdown_time = 1,
  419. .ignore_suspend = 1,
  420. .ops = &msm_common_be_ops,
  421. SND_SOC_DAILINK_REG(usb_audio_rx),
  422. },
  423. {
  424. .name = LPASS_BE_USB_AUDIO_TX,
  425. .stream_name = LPASS_BE_USB_AUDIO_TX,
  426. .capture_only = 1,
  427. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  428. SND_SOC_DPCM_TRIGGER_POST},
  429. .ignore_suspend = 1,
  430. .ops = &msm_common_be_ops,
  431. SND_SOC_DAILINK_REG(usb_audio_tx),
  432. },
  433. {
  434. .name = LPASS_BE_PCM_DUMMY_TX_0,
  435. .stream_name = LPASS_BE_PCM_DUMMY_TX_0,
  436. .capture_only = 1,
  437. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  438. SND_SOC_DPCM_TRIGGER_POST},
  439. .ignore_suspend = 1,
  440. .ops = &msm_common_be_ops,
  441. SND_SOC_DAILINK_REG(pcm_dummy_tx0),
  442. },
  443. };
  444. static struct snd_soc_dai_link msm_wcn_be_dai_links[] = {
  445. {
  446. .name = LPASS_BE_SLIMBUS_7_RX,
  447. .stream_name = LPASS_BE_SLIMBUS_7_RX,
  448. .playback_only = 1,
  449. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  450. SND_SOC_DPCM_TRIGGER_POST},
  451. .init = &msm_wcn_init,
  452. .ops = &msm_common_be_ops,
  453. /* dai link has playback support */
  454. .ignore_pmdown_time = 1,
  455. .ignore_suspend = 1,
  456. SND_SOC_DAILINK_REG(slimbus_7_rx),
  457. },
  458. {
  459. .name = LPASS_BE_SLIMBUS_7_TX,
  460. .stream_name = LPASS_BE_SLIMBUS_7_TX,
  461. .capture_only = 1,
  462. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  463. SND_SOC_DPCM_TRIGGER_POST},
  464. .ops = &msm_common_be_ops,
  465. .ignore_suspend = 1,
  466. SND_SOC_DAILINK_REG(slimbus_7_tx),
  467. },
  468. };
  469. static struct snd_soc_dai_link ext_disp_be_dai_link[] = {
  470. /* DISP PORT BACK END DAI Link */
  471. {
  472. .name = LPASS_BE_DISPLAY_PORT_RX,
  473. .stream_name = LPASS_BE_DISPLAY_PORT_RX,
  474. .playback_only = 1,
  475. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  476. SND_SOC_DPCM_TRIGGER_POST},
  477. .ignore_pmdown_time = 1,
  478. .ignore_suspend = 1,
  479. SND_SOC_DAILINK_REG(display_port),
  480. },
  481. };
  482. static struct snd_soc_dai_link msm_wsa_cdc_dma_be_dai_links[] = {
  483. /* WSA CDC DMA Backend DAI Links */
  484. {
  485. .name = LPASS_BE_WSA_CDC_DMA_RX_0,
  486. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_0,
  487. .playback_only = 1,
  488. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  489. SND_SOC_DPCM_TRIGGER_POST},
  490. .ignore_pmdown_time = 1,
  491. .ignore_suspend = 1,
  492. .ops = &msm_common_be_ops,
  493. SND_SOC_DAILINK_REG(wsa_dma_rx0),
  494. .init = &msm_int_wsa_init,
  495. },
  496. {
  497. .name = LPASS_BE_WSA_CDC_DMA_RX_1,
  498. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_1,
  499. .playback_only = 1,
  500. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  501. SND_SOC_DPCM_TRIGGER_POST},
  502. .ignore_pmdown_time = 1,
  503. .ignore_suspend = 1,
  504. .ops = &msm_common_be_ops,
  505. SND_SOC_DAILINK_REG(wsa_dma_rx1),
  506. },
  507. {
  508. .name = LPASS_BE_WSA_CDC_DMA_TX_1,
  509. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_1,
  510. .capture_only = 1,
  511. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  512. SND_SOC_DPCM_TRIGGER_POST},
  513. .ignore_suspend = 1,
  514. .ops = &msm_common_be_ops,
  515. SND_SOC_DAILINK_REG(wsa_dma_tx1),
  516. },
  517. {
  518. .name = LPASS_BE_WSA_CDC_DMA_TX_0,
  519. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_0,
  520. .capture_only = 1,
  521. .ignore_suspend = 1,
  522. .ops = &msm_common_be_ops,
  523. /* .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, */
  524. SND_SOC_DAILINK_REG(vi_feedback),
  525. },
  526. {
  527. .name = LPASS_BE_WSA_CDC_DMA_RX_0_VIRT,
  528. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_0_VIRT,
  529. .playback_only = 1,
  530. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  531. SND_SOC_DPCM_TRIGGER_POST},
  532. .ignore_pmdown_time = 1,
  533. .ignore_suspend = 1,
  534. .ops = &msm_common_be_ops,
  535. SND_SOC_DAILINK_REG(wsa_dma_rx0),
  536. .init = &msm_int_wsa_init,
  537. },
  538. };
  539. static struct snd_soc_dai_link msm_wsa2_cdc_dma_be_dai_links[] = {
  540. /* WSA2 CDC DMA Backend DAI Links */
  541. {
  542. .name = LPASS_BE_WSA2_CDC_DMA_RX_0,
  543. .stream_name = LPASS_BE_WSA2_CDC_DMA_RX_0,
  544. .playback_only = 1,
  545. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  546. SND_SOC_DPCM_TRIGGER_POST},
  547. .ignore_pmdown_time = 1,
  548. .ignore_suspend = 1,
  549. .ops = &msm_common_be_ops,
  550. SND_SOC_DAILINK_REG(wsa2_dma_rx0),
  551. },
  552. {
  553. .name = LPASS_BE_WSA2_CDC_DMA_RX_1,
  554. .stream_name = LPASS_BE_WSA2_CDC_DMA_RX_1,
  555. .playback_only = 1,
  556. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  557. SND_SOC_DPCM_TRIGGER_POST},
  558. .ignore_pmdown_time = 1,
  559. .ignore_suspend = 1,
  560. .ops = &msm_common_be_ops,
  561. SND_SOC_DAILINK_REG(wsa2_dma_rx1),
  562. },
  563. {
  564. .name = LPASS_BE_WSA2_CDC_DMA_TX_1,
  565. .stream_name = LPASS_BE_WSA2_CDC_DMA_TX_1,
  566. .capture_only = 1,
  567. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  568. SND_SOC_DPCM_TRIGGER_POST},
  569. .ignore_suspend = 1,
  570. .ops = &msm_common_be_ops,
  571. SND_SOC_DAILINK_REG(wsa2_dma_tx1),
  572. },
  573. {
  574. .name = LPASS_BE_WSA2_CDC_DMA_TX_0,
  575. .stream_name = LPASS_BE_WSA2_CDC_DMA_TX_0,
  576. .capture_only = 1,
  577. .ignore_suspend = 1,
  578. .ops = &msm_common_be_ops,
  579. /* .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, */
  580. SND_SOC_DAILINK_REG(wsa2_vi_feedback),
  581. },
  582. };
  583. static struct snd_soc_dai_link msm_wsa_wsa2_cdc_dma_be_dai_links[] = {
  584. /* WSA CDC DMA Backend DAI Links */
  585. {
  586. .name = LPASS_BE_WSA_CDC_DMA_RX_0,
  587. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_0,
  588. .playback_only = 1,
  589. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  590. SND_SOC_DPCM_TRIGGER_POST},
  591. .ignore_pmdown_time = 1,
  592. .ignore_suspend = 1,
  593. .ops = &msm_common_be_ops,
  594. SND_SOC_DAILINK_REG(wsa_wsa2_dma_rx0),
  595. .init = &msm_int_wsa_init,
  596. },
  597. {
  598. .name = LPASS_BE_WSA_CDC_DMA_RX_1,
  599. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_1,
  600. .playback_only = 1,
  601. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  602. SND_SOC_DPCM_TRIGGER_POST},
  603. .ignore_pmdown_time = 1,
  604. .ignore_suspend = 1,
  605. .ops = &msm_common_be_ops,
  606. SND_SOC_DAILINK_REG(wsa_wsa2_dma_rx1),
  607. },
  608. {
  609. .name = LPASS_BE_WSA_CDC_DMA_TX_1,
  610. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_1,
  611. .capture_only = 1,
  612. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  613. SND_SOC_DPCM_TRIGGER_POST},
  614. .ignore_suspend = 1,
  615. .ops = &msm_common_be_ops,
  616. SND_SOC_DAILINK_REG(wsa_wsa2_dma_tx1),
  617. },
  618. {
  619. .name = LPASS_BE_WSA_CDC_DMA_TX_0,
  620. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_0,
  621. .capture_only = 1,
  622. .ignore_suspend = 1,
  623. .ops = &msm_common_be_ops,
  624. /* .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, */
  625. SND_SOC_DAILINK_REG(wsa_wsa2_vi_feedback),
  626. },
  627. };
  628. static struct snd_soc_dai_link msm_rx_tx_cdc_dma_be_dai_links[] = {
  629. /* RX CDC DMA Backend DAI Links */
  630. {
  631. .name = LPASS_BE_RX_CDC_DMA_RX_0,
  632. .stream_name = LPASS_BE_RX_CDC_DMA_RX_0,
  633. .playback_only = 1,
  634. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  635. SND_SOC_DPCM_TRIGGER_POST},
  636. .ignore_pmdown_time = 1,
  637. .ignore_suspend = 1,
  638. .ops = &msm_common_be_ops,
  639. SND_SOC_DAILINK_REG(rx_dma_rx0),
  640. .init = &msm_rx_tx_codec_init,
  641. },
  642. {
  643. .name = LPASS_BE_RX_CDC_DMA_RX_1,
  644. .stream_name = LPASS_BE_RX_CDC_DMA_RX_1,
  645. .playback_only = 1,
  646. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  647. SND_SOC_DPCM_TRIGGER_POST},
  648. .ignore_pmdown_time = 1,
  649. .ignore_suspend = 1,
  650. .ops = &msm_common_be_ops,
  651. SND_SOC_DAILINK_REG(rx_dma_rx1),
  652. },
  653. {
  654. .name = LPASS_BE_RX_CDC_DMA_RX_2,
  655. .stream_name = LPASS_BE_RX_CDC_DMA_RX_2,
  656. .playback_only = 1,
  657. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  658. SND_SOC_DPCM_TRIGGER_POST},
  659. .ignore_pmdown_time = 1,
  660. .ignore_suspend = 1,
  661. .ops = &msm_common_be_ops,
  662. SND_SOC_DAILINK_REG(rx_dma_rx2),
  663. },
  664. {
  665. .name = LPASS_BE_RX_CDC_DMA_RX_3,
  666. .stream_name = LPASS_BE_RX_CDC_DMA_RX_3,
  667. .playback_only = 1,
  668. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  669. SND_SOC_DPCM_TRIGGER_POST},
  670. .ignore_pmdown_time = 1,
  671. .ignore_suspend = 1,
  672. .ops = &msm_common_be_ops,
  673. SND_SOC_DAILINK_REG(rx_dma_rx3),
  674. },
  675. {
  676. .name = LPASS_BE_RX_CDC_DMA_RX_5,
  677. .stream_name = LPASS_BE_RX_CDC_DMA_RX_5,
  678. .playback_only = 1,
  679. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  680. SND_SOC_DPCM_TRIGGER_POST},
  681. .ignore_pmdown_time = 1,
  682. .ignore_suspend = 1,
  683. .ops = &msm_common_be_ops,
  684. SND_SOC_DAILINK_REG(rx_dma_rx5),
  685. },
  686. {
  687. .name = LPASS_BE_RX_CDC_DMA_RX_6,
  688. .stream_name = LPASS_BE_RX_CDC_DMA_RX_6,
  689. .playback_only = 1,
  690. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  691. SND_SOC_DPCM_TRIGGER_POST},
  692. .ignore_pmdown_time = 1,
  693. .ignore_suspend = 1,
  694. .ops = &msm_common_be_ops,
  695. SND_SOC_DAILINK_REG(rx_dma_rx6),
  696. },
  697. /* TX CDC DMA Backend DAI Links */
  698. {
  699. .name = LPASS_BE_TX_CDC_DMA_TX_3,
  700. .stream_name = LPASS_BE_TX_CDC_DMA_TX_3,
  701. .capture_only = 1,
  702. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  703. SND_SOC_DPCM_TRIGGER_POST},
  704. .ignore_suspend = 1,
  705. .ops = &msm_common_be_ops,
  706. SND_SOC_DAILINK_REG(tx_dma_tx3),
  707. },
  708. {
  709. .name = LPASS_BE_TX_CDC_DMA_TX_4,
  710. .stream_name = LPASS_BE_TX_CDC_DMA_TX_4,
  711. .capture_only = 1,
  712. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  713. SND_SOC_DPCM_TRIGGER_POST},
  714. .ignore_suspend = 1,
  715. .ops = &msm_common_be_ops,
  716. SND_SOC_DAILINK_REG(tx_dma_tx4),
  717. },
  718. };
  719. static struct snd_soc_dai_link msm_va_cdc_dma_be_dai_links[] = {
  720. {
  721. .name = LPASS_BE_VA_CDC_DMA_TX_0,
  722. .stream_name = LPASS_BE_VA_CDC_DMA_TX_0,
  723. .capture_only = 1,
  724. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  725. SND_SOC_DPCM_TRIGGER_POST},
  726. .ignore_suspend = 1,
  727. .ops = &msm_common_be_ops,
  728. SND_SOC_DAILINK_REG(va_dma_tx0),
  729. },
  730. {
  731. .name = LPASS_BE_VA_CDC_DMA_TX_1,
  732. .stream_name = LPASS_BE_VA_CDC_DMA_TX_1,
  733. .capture_only = 1,
  734. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  735. SND_SOC_DPCM_TRIGGER_POST},
  736. .ignore_suspend = 1,
  737. .ops = &msm_common_be_ops,
  738. SND_SOC_DAILINK_REG(va_dma_tx1),
  739. },
  740. {
  741. .name = LPASS_BE_VA_CDC_DMA_TX_2,
  742. .stream_name = LPASS_BE_VA_CDC_DMA_TX_2,
  743. .capture_only = 1,
  744. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  745. SND_SOC_DPCM_TRIGGER_POST},
  746. .ignore_suspend = 1,
  747. .ops = &msm_common_be_ops,
  748. SND_SOC_DAILINK_REG(va_dma_tx2),
  749. },
  750. };
  751. /*
  752. * I2S interface pinctrl mapping
  753. * ------------------------------------
  754. * Primary - pri_mi2s
  755. * Secondary - lpi_i2s3
  756. * Tertiary - tert_mi2s
  757. * Quaternary - quat_mi2s (lpi_i2s0)
  758. * Quinary - lpi_i2s1
  759. * Senary - lpi_i2s2
  760. * ------------------------------------
  761. */
  762. static struct snd_soc_dai_link msm_mi2s_dai_links[] = {
  763. {
  764. .name = LPASS_BE_PRI_MI2S_RX,
  765. .stream_name = LPASS_BE_PRI_MI2S_RX,
  766. .playback_only = 1,
  767. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  768. SND_SOC_DPCM_TRIGGER_POST},
  769. .ops = &msm_common_be_ops,
  770. .ignore_suspend = 1,
  771. .ignore_pmdown_time = 1,
  772. SND_SOC_DAILINK_REG(pri_mi2s_rx),
  773. },
  774. {
  775. .name = LPASS_BE_PRI_MI2S_TX,
  776. .stream_name = LPASS_BE_PRI_MI2S_TX,
  777. .capture_only = 1,
  778. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  779. SND_SOC_DPCM_TRIGGER_POST},
  780. .ops = &msm_common_be_ops,
  781. .ignore_suspend = 1,
  782. SND_SOC_DAILINK_REG(pri_mi2s_tx),
  783. },
  784. {
  785. .name = LPASS_BE_SEC_MI2S_RX,
  786. .stream_name = LPASS_BE_SEC_MI2S_RX,
  787. .playback_only = 1,
  788. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  789. SND_SOC_DPCM_TRIGGER_POST},
  790. .ops = &msm_common_be_ops,
  791. .ignore_suspend = 1,
  792. .ignore_pmdown_time = 1,
  793. SND_SOC_DAILINK_REG(sec_mi2s_rx),
  794. },
  795. {
  796. .name = LPASS_BE_SEC_MI2S_TX,
  797. .stream_name = LPASS_BE_SEC_MI2S_TX,
  798. .capture_only = 1,
  799. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  800. SND_SOC_DPCM_TRIGGER_POST},
  801. .ops = &msm_common_be_ops,
  802. .ignore_suspend = 1,
  803. SND_SOC_DAILINK_REG(sec_mi2s_tx),
  804. },
  805. {
  806. .name = LPASS_BE_TERT_MI2S_RX,
  807. .stream_name = LPASS_BE_TERT_MI2S_RX,
  808. .playback_only = 1,
  809. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  810. SND_SOC_DPCM_TRIGGER_POST},
  811. .ops = &msm_common_be_ops,
  812. .ignore_suspend = 1,
  813. .ignore_pmdown_time = 1,
  814. SND_SOC_DAILINK_REG(tert_mi2s_rx),
  815. },
  816. {
  817. .name = LPASS_BE_TERT_MI2S_TX,
  818. .stream_name = LPASS_BE_TERT_MI2S_TX,
  819. .capture_only = 1,
  820. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  821. SND_SOC_DPCM_TRIGGER_POST},
  822. .ops = &msm_common_be_ops,
  823. .ignore_suspend = 1,
  824. SND_SOC_DAILINK_REG(tert_mi2s_tx),
  825. },
  826. {
  827. .name = LPASS_BE_QUAT_MI2S_RX,
  828. .stream_name = LPASS_BE_QUAT_MI2S_RX,
  829. .playback_only = 1,
  830. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  831. SND_SOC_DPCM_TRIGGER_POST},
  832. .ops = &msm_common_be_ops,
  833. .ignore_suspend = 1,
  834. .ignore_pmdown_time = 1,
  835. SND_SOC_DAILINK_REG(quat_mi2s_rx),
  836. },
  837. {
  838. .name = LPASS_BE_QUAT_MI2S_TX,
  839. .stream_name = LPASS_BE_QUAT_MI2S_TX,
  840. .capture_only = 1,
  841. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  842. SND_SOC_DPCM_TRIGGER_POST},
  843. .ops = &msm_common_be_ops,
  844. .ignore_suspend = 1,
  845. SND_SOC_DAILINK_REG(quat_mi2s_tx),
  846. },
  847. {
  848. .name = LPASS_BE_QUIN_MI2S_RX,
  849. .stream_name = LPASS_BE_QUIN_MI2S_RX,
  850. .playback_only = 1,
  851. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  852. SND_SOC_DPCM_TRIGGER_POST},
  853. .ops = &msm_common_be_ops,
  854. .ignore_suspend = 1,
  855. .ignore_pmdown_time = 1,
  856. SND_SOC_DAILINK_REG(quin_mi2s_rx),
  857. },
  858. {
  859. .name = LPASS_BE_QUIN_MI2S_TX,
  860. .stream_name = LPASS_BE_QUIN_MI2S_TX,
  861. .capture_only = 1,
  862. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  863. SND_SOC_DPCM_TRIGGER_POST},
  864. .ops = &msm_common_be_ops,
  865. .ignore_suspend = 1,
  866. SND_SOC_DAILINK_REG(quin_mi2s_tx),
  867. },
  868. {
  869. .name = LPASS_BE_SEN_MI2S_RX,
  870. .stream_name = LPASS_BE_SEN_MI2S_RX,
  871. .playback_only = 1,
  872. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  873. SND_SOC_DPCM_TRIGGER_POST},
  874. .ops = &msm_common_be_ops,
  875. .ignore_suspend = 1,
  876. .ignore_pmdown_time = 1,
  877. SND_SOC_DAILINK_REG(sen_mi2s_rx),
  878. },
  879. {
  880. .name = LPASS_BE_SEN_MI2S_TX,
  881. .stream_name = LPASS_BE_SEN_MI2S_TX,
  882. .capture_only = 1,
  883. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  884. SND_SOC_DPCM_TRIGGER_POST},
  885. .ops = &msm_common_be_ops,
  886. .ignore_suspend = 1,
  887. SND_SOC_DAILINK_REG(sen_mi2s_tx),
  888. },
  889. };
  890. static struct snd_soc_dai_link msm_tdm_dai_links[] = {
  891. {
  892. .name = LPASS_BE_PRI_TDM_RX_0,
  893. .stream_name = LPASS_BE_PRI_TDM_RX_0,
  894. .playback_only = 1,
  895. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  896. SND_SOC_DPCM_TRIGGER_POST},
  897. .ops = &msm_common_be_ops,
  898. .ignore_suspend = 1,
  899. .ignore_pmdown_time = 1,
  900. SND_SOC_DAILINK_REG(pri_tdm_rx_0),
  901. },
  902. {
  903. .name = LPASS_BE_PRI_TDM_TX_0,
  904. .stream_name = LPASS_BE_PRI_TDM_TX_0,
  905. .capture_only = 1,
  906. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  907. SND_SOC_DPCM_TRIGGER_POST},
  908. .ops = &msm_common_be_ops,
  909. .ignore_suspend = 1,
  910. SND_SOC_DAILINK_REG(pri_tdm_tx_0),
  911. },
  912. {
  913. .name = LPASS_BE_SEC_TDM_RX_0,
  914. .stream_name = LPASS_BE_SEC_TDM_RX_0,
  915. .playback_only = 1,
  916. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  917. SND_SOC_DPCM_TRIGGER_POST},
  918. .ops = &msm_common_be_ops,
  919. .ignore_suspend = 1,
  920. .ignore_pmdown_time = 1,
  921. SND_SOC_DAILINK_REG(sec_tdm_rx_0),
  922. },
  923. {
  924. .name = LPASS_BE_SEC_TDM_TX_0,
  925. .stream_name = LPASS_BE_SEC_TDM_TX_0,
  926. .capture_only = 1,
  927. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  928. SND_SOC_DPCM_TRIGGER_POST},
  929. .ops = &msm_common_be_ops,
  930. .ignore_suspend = 1,
  931. SND_SOC_DAILINK_REG(sec_tdm_tx_0),
  932. },
  933. {
  934. .name = LPASS_BE_TERT_TDM_RX_0,
  935. .stream_name = LPASS_BE_TERT_TDM_RX_0,
  936. .playback_only = 1,
  937. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  938. SND_SOC_DPCM_TRIGGER_POST},
  939. .ops = &msm_common_be_ops,
  940. .ignore_suspend = 1,
  941. .ignore_pmdown_time = 1,
  942. SND_SOC_DAILINK_REG(tert_tdm_rx_0),
  943. },
  944. {
  945. .name = LPASS_BE_TERT_TDM_TX_0,
  946. .stream_name = LPASS_BE_TERT_TDM_TX_0,
  947. .capture_only = 1,
  948. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  949. SND_SOC_DPCM_TRIGGER_POST},
  950. .ops = &msm_common_be_ops,
  951. .ignore_suspend = 1,
  952. SND_SOC_DAILINK_REG(tert_tdm_tx_0),
  953. },
  954. {
  955. .name = LPASS_BE_QUAT_TDM_RX_0,
  956. .stream_name = LPASS_BE_QUAT_TDM_RX_0,
  957. .playback_only = 1,
  958. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  959. SND_SOC_DPCM_TRIGGER_POST},
  960. .ops = &msm_common_be_ops,
  961. .ignore_suspend = 1,
  962. .ignore_pmdown_time = 1,
  963. SND_SOC_DAILINK_REG(quat_tdm_rx_0),
  964. },
  965. {
  966. .name = LPASS_BE_QUAT_TDM_TX_0,
  967. .stream_name = LPASS_BE_QUAT_TDM_TX_0,
  968. .capture_only = 1,
  969. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  970. SND_SOC_DPCM_TRIGGER_POST},
  971. .ops = &msm_common_be_ops,
  972. .ignore_suspend = 1,
  973. SND_SOC_DAILINK_REG(quat_tdm_tx_0),
  974. },
  975. {
  976. .name = LPASS_BE_QUIN_TDM_RX_0,
  977. .stream_name = LPASS_BE_QUIN_TDM_RX_0,
  978. .playback_only = 1,
  979. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  980. SND_SOC_DPCM_TRIGGER_POST},
  981. .ops = &msm_common_be_ops,
  982. .ignore_suspend = 1,
  983. .ignore_pmdown_time = 1,
  984. SND_SOC_DAILINK_REG(quin_tdm_rx_0),
  985. },
  986. {
  987. .name = LPASS_BE_QUIN_TDM_TX_0,
  988. .stream_name = LPASS_BE_QUIN_TDM_TX_0,
  989. .capture_only = 1,
  990. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  991. SND_SOC_DPCM_TRIGGER_POST},
  992. .ops = &msm_common_be_ops,
  993. .ignore_suspend = 1,
  994. SND_SOC_DAILINK_REG(quin_tdm_tx_0),
  995. },
  996. {
  997. .name = LPASS_BE_SEN_TDM_RX_0,
  998. .stream_name = LPASS_BE_SEN_TDM_RX_0,
  999. .playback_only = 1,
  1000. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1001. SND_SOC_DPCM_TRIGGER_POST},
  1002. .ops = &msm_common_be_ops,
  1003. .ignore_suspend = 1,
  1004. .ignore_pmdown_time = 1,
  1005. SND_SOC_DAILINK_REG(sen_tdm_rx_0),
  1006. },
  1007. {
  1008. .name = LPASS_BE_SEN_TDM_TX_0,
  1009. .stream_name = LPASS_BE_SEN_TDM_TX_0,
  1010. .capture_only = 1,
  1011. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1012. SND_SOC_DPCM_TRIGGER_POST},
  1013. .ops = &msm_common_be_ops,
  1014. .ignore_suspend = 1,
  1015. SND_SOC_DAILINK_REG(sen_tdm_tx_0),
  1016. },
  1017. };
  1018. static struct snd_soc_dai_link msm_waipio_dai_links[
  1019. ARRAY_SIZE(msm_wsa_cdc_dma_be_dai_links) +
  1020. ARRAY_SIZE(msm_wsa2_cdc_dma_be_dai_links) +
  1021. ARRAY_SIZE(msm_wsa_wsa2_cdc_dma_be_dai_links) +
  1022. ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links) +
  1023. ARRAY_SIZE(msm_va_cdc_dma_be_dai_links) +
  1024. ARRAY_SIZE(ext_disp_be_dai_link) +
  1025. ARRAY_SIZE(msm_common_be_dai_links) +
  1026. ARRAY_SIZE(msm_wcn_be_dai_links) +
  1027. ARRAY_SIZE(msm_mi2s_dai_links) +
  1028. ARRAY_SIZE(msm_tdm_dai_links)];
  1029. static int msm_populate_dai_link_component_of_node(
  1030. struct snd_soc_card *card)
  1031. {
  1032. int i, j, index, ret = 0;
  1033. struct device *cdev = card->dev;
  1034. struct snd_soc_dai_link *dai_link = card->dai_link;
  1035. struct device_node *np = NULL;
  1036. int codecs_enabled = 0;
  1037. struct snd_soc_dai_link_component *codecs_comp = NULL;
  1038. if (!cdev) {
  1039. dev_err(cdev, "%s: Sound card device memory NULL\n", __func__);
  1040. return -ENODEV;
  1041. }
  1042. for (i = 0; i < card->num_links; i++) {
  1043. if (dai_link[i].init == NULL)
  1044. dai_link[i].init = &msm_common_dai_link_init;
  1045. /* populate codec_of_node for snd card dai links */
  1046. if (dai_link[i].num_codecs > 0) {
  1047. for (j = 0; j < dai_link[i].num_codecs; j++) {
  1048. if (dai_link[i].codecs[j].of_node ||
  1049. !dai_link[i].codecs[j].name)
  1050. continue;
  1051. index = of_property_match_string(cdev->of_node,
  1052. "asoc-codec-names",
  1053. dai_link[i].codecs[j].name);
  1054. if (index < 0)
  1055. continue;
  1056. np = of_parse_phandle(cdev->of_node,
  1057. "asoc-codec",
  1058. index);
  1059. if (!np) {
  1060. dev_err(cdev, "%s: retrieving phandle for codec %s failed\n",
  1061. __func__,
  1062. dai_link[i].codecs[j].name);
  1063. ret = -ENODEV;
  1064. goto err;
  1065. }
  1066. dai_link[i].codecs[j].of_node = np;
  1067. dai_link[i].codecs[j].name = NULL;
  1068. }
  1069. }
  1070. }
  1071. /* In multi-codec scenario, check if codecs are enabled for this platform */
  1072. for (i = 0; i < card->num_links; i++) {
  1073. codecs_enabled = 0;
  1074. if (dai_link[i].num_codecs > 1) {
  1075. for (j = 0; j < dai_link[i].num_codecs; j++) {
  1076. if (!dai_link[i].codecs[j].of_node)
  1077. continue;
  1078. np = dai_link[i].codecs[j].of_node;
  1079. if (!of_device_is_available(np)) {
  1080. dev_err(cdev, "%s: codec is disabled: %s\n",
  1081. __func__,
  1082. np->full_name);
  1083. dai_link[i].codecs[j].of_node = NULL;
  1084. continue;
  1085. }
  1086. codecs_enabled++;
  1087. }
  1088. if (codecs_enabled > 0 &&
  1089. codecs_enabled < dai_link[i].num_codecs) {
  1090. codecs_comp = devm_kzalloc(cdev,
  1091. sizeof(struct snd_soc_dai_link_component)
  1092. * codecs_enabled, GFP_KERNEL);
  1093. if (!codecs_comp) {
  1094. dev_err(cdev, "%s: %s dailink codec component alloc failed\n",
  1095. __func__, dai_link[i].name);
  1096. ret = -ENOMEM;
  1097. goto err;
  1098. }
  1099. index = 0;
  1100. for (j = 0; j < dai_link[i].num_codecs; j++) {
  1101. if(dai_link[i].codecs[j].of_node) {
  1102. codecs_comp[index].of_node =
  1103. dai_link[i].codecs[j].of_node;
  1104. codecs_comp[index].dai_name =
  1105. dai_link[i].codecs[j].dai_name;
  1106. codecs_comp[index].name = NULL;
  1107. index++;
  1108. }
  1109. }
  1110. dai_link[i].codecs = codecs_comp;
  1111. dai_link[i].num_codecs = codecs_enabled;
  1112. }
  1113. }
  1114. }
  1115. err:
  1116. return ret;
  1117. }
  1118. static int msm_audrx_stub_init(struct snd_soc_pcm_runtime *rtd)
  1119. {
  1120. return 0;
  1121. }
  1122. static int msm_snd_stub_hw_params(struct snd_pcm_substream *substream,
  1123. struct snd_pcm_hw_params *params)
  1124. {
  1125. return 0;
  1126. }
  1127. static struct snd_soc_ops msm_stub_be_ops = {
  1128. .hw_params = msm_snd_stub_hw_params,
  1129. };
  1130. struct snd_soc_card snd_soc_card_stub_msm = {
  1131. .name = "waipio-stub-snd-card",
  1132. };
  1133. static struct snd_soc_dai_link msm_stub_be_dai_links[] = {
  1134. /* Backend DAI Links */
  1135. {
  1136. .name = LPASS_BE_PRI_AUXPCM_RX,
  1137. .stream_name = LPASS_BE_PRI_AUXPCM_RX,
  1138. .playback_only = 1,
  1139. .init = &msm_audrx_stub_init,
  1140. .ignore_pmdown_time = 1,
  1141. .ignore_suspend = 1,
  1142. .ops = &msm_stub_be_ops,
  1143. SND_SOC_DAILINK_REG(auxpcm_rx),
  1144. },
  1145. {
  1146. .name = LPASS_BE_PRI_AUXPCM_TX,
  1147. .stream_name = LPASS_BE_PRI_AUXPCM_TX,
  1148. .capture_only = 1,
  1149. .ignore_suspend = 1,
  1150. .ops = &msm_stub_be_ops,
  1151. SND_SOC_DAILINK_REG(auxpcm_tx),
  1152. },
  1153. };
  1154. static struct snd_soc_dai_link msm_stub_dai_links[
  1155. ARRAY_SIZE(msm_stub_be_dai_links)];
  1156. static const struct of_device_id waipio_asoc_machine_of_match[] = {
  1157. { .compatible = "qcom,waipio-asoc-snd",
  1158. .data = "codec"},
  1159. { .compatible = "qcom,waipio-asoc-snd-stub",
  1160. .data = "stub_codec"},
  1161. {},
  1162. };
  1163. static int msm_snd_card_late_probe(struct snd_soc_card *card)
  1164. {
  1165. struct snd_soc_component *component = NULL;
  1166. struct snd_soc_pcm_runtime *rtd;
  1167. struct msm_asoc_mach_data *pdata;
  1168. int ret = 0;
  1169. void *mbhc_calibration;
  1170. pdata = snd_soc_card_get_drvdata(card);
  1171. if (!pdata)
  1172. return -EINVAL;
  1173. if (pdata->wcd_disabled)
  1174. return 0;
  1175. rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
  1176. if (!rtd) {
  1177. dev_err(card->dev,
  1178. "%s: snd_soc_get_pcm_runtime for %s failed!\n",
  1179. __func__, card->dai_link[0]);
  1180. return -EINVAL;
  1181. }
  1182. component = snd_soc_rtdcom_lookup(rtd, WCD938X_DRV_NAME);
  1183. if (!component) {
  1184. pr_err("%s component is NULL\n", __func__);
  1185. return -EINVAL;
  1186. }
  1187. mbhc_calibration = def_wcd_mbhc_cal();
  1188. if (!mbhc_calibration)
  1189. return -ENOMEM;
  1190. wcd_mbhc_cfg.calibration = mbhc_calibration;
  1191. ret = wcd938x_mbhc_hs_detect(component, &wcd_mbhc_cfg);
  1192. if (ret) {
  1193. dev_err(component->dev, "%s: mbhc hs detect failed, err:%d\n",
  1194. __func__, ret);
  1195. goto err_hs_detect;
  1196. }
  1197. return 0;
  1198. err_hs_detect:
  1199. kfree(mbhc_calibration);
  1200. return ret;
  1201. }
  1202. static struct snd_soc_card *populate_snd_card_dailinks(struct device *dev, int wsa_max_devs)
  1203. {
  1204. struct snd_soc_card *card = NULL;
  1205. struct snd_soc_dai_link *dailink = NULL;
  1206. int total_links = 0;
  1207. int rc = 0;
  1208. u32 val = 0;
  1209. const struct of_device_id *match;
  1210. match = of_match_node(waipio_asoc_machine_of_match, dev->of_node);
  1211. if (!match) {
  1212. dev_err(dev, "%s: No DT match found for sound card\n",
  1213. __func__);
  1214. return NULL;
  1215. }
  1216. if (!strcmp(match->data, "codec")) {
  1217. card = &snd_soc_card_waipio_msm;
  1218. /* late probe uses dai link at index '0' to get wcd component */
  1219. memcpy(msm_waipio_dai_links + total_links,
  1220. msm_rx_tx_cdc_dma_be_dai_links,
  1221. sizeof(msm_rx_tx_cdc_dma_be_dai_links));
  1222. total_links +=
  1223. ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links);
  1224. switch (wsa_max_devs) {
  1225. case MONO_SPEAKER:
  1226. case STEREO_SPEAKER:
  1227. memcpy(msm_waipio_dai_links + total_links,
  1228. msm_wsa_cdc_dma_be_dai_links,
  1229. sizeof(msm_wsa_cdc_dma_be_dai_links));
  1230. total_links += ARRAY_SIZE(msm_wsa_cdc_dma_be_dai_links);
  1231. break;
  1232. case QUAD_SPEAKER:
  1233. memcpy(msm_waipio_dai_links + total_links,
  1234. msm_wsa2_cdc_dma_be_dai_links,
  1235. sizeof(msm_wsa2_cdc_dma_be_dai_links));
  1236. total_links += ARRAY_SIZE(msm_wsa2_cdc_dma_be_dai_links);
  1237. memcpy(msm_waipio_dai_links + total_links,
  1238. msm_wsa_wsa2_cdc_dma_be_dai_links,
  1239. sizeof(msm_wsa_wsa2_cdc_dma_be_dai_links));
  1240. total_links += ARRAY_SIZE(msm_wsa_wsa2_cdc_dma_be_dai_links);
  1241. break;
  1242. default:
  1243. dev_dbg(dev,
  1244. "%s: Unexpected number of WSAs, wsa_max_devs: %d\n",
  1245. __func__, wsa_max_devs);
  1246. break;
  1247. }
  1248. memcpy(msm_waipio_dai_links + total_links,
  1249. msm_va_cdc_dma_be_dai_links,
  1250. sizeof(msm_va_cdc_dma_be_dai_links));
  1251. total_links += ARRAY_SIZE(msm_va_cdc_dma_be_dai_links);
  1252. memcpy(msm_waipio_dai_links + total_links,
  1253. msm_common_be_dai_links,
  1254. sizeof(msm_common_be_dai_links));
  1255. total_links += ARRAY_SIZE(msm_common_be_dai_links);
  1256. rc = of_property_read_u32(dev->of_node,
  1257. "qcom,mi2s-audio-intf", &val);
  1258. if (!rc && val) {
  1259. memcpy(msm_waipio_dai_links + total_links,
  1260. msm_mi2s_dai_links,
  1261. sizeof(msm_mi2s_dai_links));
  1262. total_links += ARRAY_SIZE(msm_mi2s_dai_links);
  1263. }
  1264. rc = of_property_read_u32(dev->of_node,
  1265. "qcom,tdm-audio-intf", &val);
  1266. if (!rc && val) {
  1267. memcpy(msm_waipio_dai_links + total_links,
  1268. msm_tdm_dai_links,
  1269. sizeof(msm_tdm_dai_links));
  1270. total_links += ARRAY_SIZE(msm_tdm_dai_links);
  1271. }
  1272. rc = of_property_read_u32(dev->of_node,
  1273. "qcom,ext-disp-audio-rx", &val);
  1274. if (!rc && val) {
  1275. dev_dbg(dev, "%s(): ext disp audio support present\n",
  1276. __func__);
  1277. memcpy(msm_waipio_dai_links + total_links,
  1278. ext_disp_be_dai_link,
  1279. sizeof(ext_disp_be_dai_link));
  1280. total_links += ARRAY_SIZE(ext_disp_be_dai_link);
  1281. }
  1282. rc = of_property_read_u32(dev->of_node, "qcom,wcn-bt", &val);
  1283. if (!rc && val) {
  1284. dev_dbg(dev, "%s(): WCN BT support present\n",
  1285. __func__);
  1286. memcpy(msm_waipio_dai_links + total_links,
  1287. msm_wcn_be_dai_links,
  1288. sizeof(msm_wcn_be_dai_links));
  1289. total_links += ARRAY_SIZE(msm_wcn_be_dai_links);
  1290. }
  1291. dailink = msm_waipio_dai_links;
  1292. } else if(!strcmp(match->data, "stub_codec")) {
  1293. card = &snd_soc_card_stub_msm;
  1294. memcpy(msm_stub_dai_links,
  1295. msm_stub_be_dai_links,
  1296. sizeof(msm_stub_be_dai_links));
  1297. dailink = msm_stub_dai_links;
  1298. total_links = ARRAY_SIZE(msm_stub_be_dai_links);
  1299. }
  1300. if (card) {
  1301. card->dai_link = dailink;
  1302. card->num_links = total_links;
  1303. card->late_probe = msm_snd_card_late_probe;
  1304. }
  1305. return card;
  1306. }
  1307. static int msm_int_wsa_init(struct snd_soc_pcm_runtime *rtd)
  1308. {
  1309. u8 spkleft_ports[WSA883X_MAX_SWR_PORTS] = {0, 1, 2, 3};
  1310. u8 spkright_ports[WSA883X_MAX_SWR_PORTS] = {0, 1, 2, 3};
  1311. u8 spkleft_port_types[WSA883X_MAX_SWR_PORTS] = {SPKR_L, SPKR_L_COMP,
  1312. SPKR_L_BOOST, SPKR_L_VI};
  1313. u8 spkright_port_types[WSA883X_MAX_SWR_PORTS] = {SPKR_R, SPKR_R_COMP,
  1314. SPKR_R_BOOST, SPKR_R_VI};
  1315. unsigned int ch_rate[WSA883X_MAX_SWR_PORTS] = {SWR_CLK_RATE_2P4MHZ, SWR_CLK_RATE_0P6MHZ,
  1316. SWR_CLK_RATE_0P3MHZ, SWR_CLK_RATE_1P2MHZ};
  1317. unsigned int ch_mask[WSA883X_MAX_SWR_PORTS] = {0x1, 0xF, 0x3, 0x3};
  1318. struct snd_soc_component *component = NULL;
  1319. struct msm_asoc_mach_data *pdata =
  1320. snd_soc_card_get_drvdata(rtd->card);
  1321. if (pdata->wsa_max_devs > 0) {
  1322. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.1");
  1323. if (!component) {
  1324. pr_err("%s: wsa-codec.1 component is NULL\n", __func__);
  1325. return -EINVAL;
  1326. }
  1327. wsa883x_set_channel_map(component, &spkleft_ports[0],
  1328. WSA883X_MAX_SWR_PORTS, &ch_mask[0],
  1329. &ch_rate[0], &spkleft_port_types[0]);
  1330. wsa883x_codec_info_create_codec_entry(pdata->codec_root,
  1331. component);
  1332. }
  1333. /* If current platform has more than one WSA */
  1334. if (pdata->wsa_max_devs > 1) {
  1335. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.2");
  1336. if (!component) {
  1337. pr_err("%s: wsa-codec.2 component is NULL\n", __func__);
  1338. return -EINVAL;
  1339. }
  1340. wsa883x_set_channel_map(component, &spkright_ports[0],
  1341. WSA883X_MAX_SWR_PORTS, &ch_mask[0],
  1342. &ch_rate[0], &spkright_port_types[0]);
  1343. wsa883x_codec_info_create_codec_entry(pdata->codec_root,
  1344. component);
  1345. }
  1346. if (pdata->wsa_max_devs > 2) {
  1347. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.3");
  1348. if (!component) {
  1349. pr_err("%s: wsa-codec.3 component is NULL\n", __func__);
  1350. return -EINVAL;
  1351. }
  1352. wsa883x_set_channel_map(component, &spkleft_ports[0],
  1353. WSA883X_MAX_SWR_PORTS, &ch_mask[0],
  1354. &ch_rate[0], &spkleft_port_types[0]);
  1355. wsa883x_codec_info_create_codec_entry(pdata->codec_root,
  1356. component);
  1357. }
  1358. if (pdata->wsa_max_devs > 3) {
  1359. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.4");
  1360. if (!component) {
  1361. pr_err("%s: wsa-codec.4 component is NULL\n", __func__);
  1362. return -EINVAL;
  1363. }
  1364. wsa883x_set_channel_map(component, &spkright_ports[0],
  1365. WSA883X_MAX_SWR_PORTS, &ch_mask[0],
  1366. &ch_rate[0], &spkright_port_types[0]);
  1367. wsa883x_codec_info_create_codec_entry(pdata->codec_root,
  1368. component);
  1369. }
  1370. msm_common_dai_link_init(rtd);
  1371. return 0;
  1372. }
  1373. static int msm_rx_tx_codec_init(struct snd_soc_pcm_runtime *rtd)
  1374. {
  1375. int codec_variant = -1;
  1376. struct snd_soc_component *component = NULL;
  1377. struct snd_soc_component *lpass_cdc_component = NULL;
  1378. struct snd_soc_dapm_context *dapm = NULL;
  1379. struct snd_info_entry *entry = NULL;
  1380. struct snd_card *card = NULL;
  1381. struct msm_asoc_mach_data *pdata =
  1382. snd_soc_card_get_drvdata(rtd->card);
  1383. int ret = 0;
  1384. lpass_cdc_component = snd_soc_rtdcom_lookup(rtd, "lpass-cdc");
  1385. if (!lpass_cdc_component) {
  1386. pr_err("%s: could not find component for lpass-cdc\n",
  1387. __func__);
  1388. return ret;
  1389. }
  1390. dapm = snd_soc_component_get_dapm(lpass_cdc_component);
  1391. snd_soc_dapm_new_controls(dapm, msm_int_dapm_widgets,
  1392. ARRAY_SIZE(msm_int_dapm_widgets));
  1393. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic0");
  1394. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic1");
  1395. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic2");
  1396. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic3");
  1397. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic4");
  1398. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic5");
  1399. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic6");
  1400. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic7");
  1401. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic1");
  1402. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic2");
  1403. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic3");
  1404. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic4");
  1405. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic5");
  1406. lpass_cdc_set_port_map(lpass_cdc_component, ARRAY_SIZE(sm_port_map), sm_port_map);
  1407. card = rtd->card->snd_card;
  1408. if (!pdata->codec_root) {
  1409. entry = msm_snd_info_create_subdir(card->module, "codecs",
  1410. card->proc_root);
  1411. if (!entry) {
  1412. pr_debug("%s: Cannot create codecs module entry\n",
  1413. __func__);
  1414. return ret;
  1415. }
  1416. pdata->codec_root = entry;
  1417. }
  1418. lpass_cdc_info_create_codec_entry(pdata->codec_root, lpass_cdc_component);
  1419. lpass_cdc_register_wake_irq(lpass_cdc_component, false);
  1420. if (pdata->wcd_disabled)
  1421. goto done;
  1422. component = snd_soc_rtdcom_lookup(rtd, WCD938X_DRV_NAME);
  1423. if (!component) {
  1424. pr_err("%s could not find component for %s\n",
  1425. __func__, WCD938X_DRV_NAME);
  1426. return -EINVAL;
  1427. }
  1428. dapm = snd_soc_component_get_dapm(component);
  1429. card = component->card->snd_card;
  1430. snd_soc_dapm_ignore_suspend(dapm, "EAR");
  1431. snd_soc_dapm_ignore_suspend(dapm, "AUX");
  1432. snd_soc_dapm_ignore_suspend(dapm, "HPHL");
  1433. snd_soc_dapm_ignore_suspend(dapm, "HPHR");
  1434. snd_soc_dapm_ignore_suspend(dapm, "AMIC1");
  1435. snd_soc_dapm_ignore_suspend(dapm, "AMIC2");
  1436. snd_soc_dapm_ignore_suspend(dapm, "AMIC3");
  1437. snd_soc_dapm_ignore_suspend(dapm, "AMIC4");
  1438. snd_soc_dapm_sync(dapm);
  1439. pdata = snd_soc_card_get_drvdata(component->card);
  1440. if (!pdata->codec_root) {
  1441. entry = msm_snd_info_create_subdir(card->module, "codecs",
  1442. card->proc_root);
  1443. if (!entry) {
  1444. dev_dbg(component->dev, "%s: Cannot create codecs module entry\n",
  1445. __func__);
  1446. return 0;
  1447. }
  1448. pdata->codec_root = entry;
  1449. }
  1450. wcd938x_info_create_codec_entry(pdata->codec_root, component);
  1451. codec_variant = wcd938x_get_codec_variant(component);
  1452. dev_dbg(component->dev, "%s: variant %d\n", __func__, codec_variant);
  1453. if (codec_variant == WCD9385)
  1454. ret = lpass_cdc_rx_set_fir_capability(lpass_cdc_component, true);
  1455. else
  1456. ret = lpass_cdc_rx_set_fir_capability(lpass_cdc_component, false);
  1457. if (ret < 0) {
  1458. dev_err(component->dev, "%s: set fir capability failed: %d\n",
  1459. __func__, ret);
  1460. return ret;
  1461. }
  1462. done:
  1463. codec_reg_done = true;
  1464. msm_common_dai_link_init(rtd);
  1465. return ret;
  1466. }
  1467. static int waipio_ssr_enable(struct device *dev, void *data)
  1468. {
  1469. struct platform_device *pdev = to_platform_device(dev);
  1470. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1471. struct snd_soc_pcm_runtime *rtd = NULL, *rtd_wcd = NULL, *rtd_wsa = NULL;
  1472. struct msm_asoc_mach_data *pdata = NULL;
  1473. int ret = 0;
  1474. if (!card) {
  1475. dev_err(dev, "%s: card is NULL\n", __func__);
  1476. ret = -EINVAL;
  1477. goto err;
  1478. }
  1479. if (!strcmp(card->name, "waipio-stub-snd-card")) {
  1480. /* TODO */
  1481. dev_dbg(dev, "%s: TODO \n", __func__);
  1482. }
  1483. snd_card_notify_user(SND_CARD_STATUS_ONLINE);
  1484. dev_dbg(dev, "%s: setting snd_card to ONLINE\n", __func__);
  1485. pdata = snd_soc_card_get_drvdata(card);
  1486. if (!pdata) {
  1487. dev_dbg(dev, "%s: pdata is NULL \n", __func__);
  1488. goto err;
  1489. }
  1490. rtd_wcd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
  1491. if (!rtd_wcd) {
  1492. dev_dbg(dev,
  1493. "%s: snd_soc_get_pcm_runtime for %s failed!\n",
  1494. __func__, card->dai_link[0]);
  1495. }
  1496. if (pdata->wsa_max_devs > 0) {
  1497. rtd_wsa = snd_soc_get_pcm_runtime(card,
  1498. &card->dai_link[ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links)]);
  1499. if (!rtd_wsa) {
  1500. dev_dbg(dev,
  1501. "%s: snd_soc_get_pcm_runtime for %s failed!\n",
  1502. __func__, card->dai_link[ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links)]);
  1503. }
  1504. }
  1505. /* set UPD configuration */
  1506. if(!pdata->upd_config.backend_used) {
  1507. dev_dbg(dev,
  1508. "%s: upd- backend_used is NULL\n", __func__);
  1509. goto err;
  1510. }
  1511. if (!strcmp(pdata->upd_config.backend_used, "wsa")) {
  1512. if (!rtd_wsa)
  1513. goto err;
  1514. else
  1515. rtd = rtd_wsa;
  1516. } else if(!strcmp(pdata->upd_config.backend_used, "wcd")) {
  1517. if (!rtd_wcd &&!pdata->wcd_disabled)
  1518. goto err;
  1519. else
  1520. rtd = rtd_wcd;
  1521. } else {
  1522. dev_err(card->dev, "%s: Invalid backend to set UPD config\n",
  1523. __func__);
  1524. goto err;
  1525. }
  1526. msm_set_upd_config(rtd);
  1527. err:
  1528. return ret;
  1529. }
  1530. static void waipio_ssr_disable(struct device *dev, void *data)
  1531. {
  1532. struct platform_device *pdev = to_platform_device(dev);
  1533. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1534. if (!card) {
  1535. dev_err(dev, "%s: card is NULL\n", __func__);
  1536. return;
  1537. }
  1538. dev_dbg(dev, "%s: setting snd_card to OFFLINE\n", __func__);
  1539. snd_card_notify_user(SND_CARD_STATUS_OFFLINE);
  1540. if (!strcmp(card->name, "waipio-stub-snd-card")) {
  1541. /* TODO */
  1542. dev_dbg(dev, "%s: TODO \n", __func__);
  1543. }
  1544. }
  1545. static const struct snd_event_ops waipio_ssr_ops = {
  1546. .enable = waipio_ssr_enable,
  1547. .disable = waipio_ssr_disable,
  1548. };
  1549. static int msm_audio_ssr_compare(struct device *dev, void *data)
  1550. {
  1551. struct device_node *node = data;
  1552. dev_dbg(dev, "%s: dev->of_node = 0x%p, node = 0x%p\n",
  1553. __func__, dev->of_node, node);
  1554. return (dev->of_node && dev->of_node == node);
  1555. }
  1556. static int msm_audio_ssr_register(struct device *dev)
  1557. {
  1558. struct device_node *np = dev->of_node;
  1559. struct snd_event_clients *ssr_clients = NULL;
  1560. struct device_node *node = NULL;
  1561. int ret = 0;
  1562. int i = 0;
  1563. for (i = 0; ; i++) {
  1564. node = of_parse_phandle(np, "qcom,msm_audio_ssr_devs", i);
  1565. if (!node)
  1566. break;
  1567. snd_event_mstr_add_client(&ssr_clients,
  1568. msm_audio_ssr_compare, node);
  1569. }
  1570. ret = snd_event_master_register(dev, &waipio_ssr_ops,
  1571. ssr_clients, NULL);
  1572. if (!ret)
  1573. snd_event_notify(dev, SND_EVENT_UP);
  1574. return ret;
  1575. }
  1576. struct msm_common_pdata *msm_common_get_pdata(struct snd_soc_card *card)
  1577. {
  1578. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  1579. if (!pdata)
  1580. return NULL;
  1581. return pdata->common_pdata;
  1582. }
  1583. void msm_common_set_pdata(struct snd_soc_card *card,
  1584. struct msm_common_pdata *common_pdata)
  1585. {
  1586. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  1587. if (!pdata)
  1588. return;
  1589. pdata->common_pdata = common_pdata;
  1590. }
  1591. static int msm_asoc_machine_probe(struct platform_device *pdev)
  1592. {
  1593. struct snd_soc_card *card = NULL;
  1594. struct msm_asoc_mach_data *pdata = NULL;
  1595. int ret = 0;
  1596. struct clk *lpass_audio_hw_vote = NULL;
  1597. if (!pdev->dev.of_node) {
  1598. dev_err(&pdev->dev, "%s: No platform supplied from device tree\n", __func__);
  1599. return -EINVAL;
  1600. }
  1601. pdata = devm_kzalloc(&pdev->dev,
  1602. sizeof(struct msm_asoc_mach_data), GFP_KERNEL);
  1603. if (!pdata)
  1604. return -ENOMEM;
  1605. of_property_read_u32(pdev->dev.of_node,
  1606. "qcom,wcd-disabled",
  1607. &pdata->wcd_disabled);
  1608. /* Get maximum WSA device count for this platform */
  1609. ret = of_property_read_u32(pdev->dev.of_node,
  1610. "qcom,wsa-max-devs", &pdata->wsa_max_devs);
  1611. if (ret) {
  1612. dev_info(&pdev->dev,
  1613. "%s: wsa-max-devs property missing in DT %s, ret = %d\n",
  1614. __func__, pdev->dev.of_node->full_name, ret);
  1615. pdata->wsa_max_devs = 0;
  1616. }
  1617. card = populate_snd_card_dailinks(&pdev->dev, pdata->wsa_max_devs);
  1618. if (!card) {
  1619. dev_err(&pdev->dev, "%s: Card uninitialized\n", __func__);
  1620. ret = -EINVAL;
  1621. goto err;
  1622. }
  1623. card->dev = &pdev->dev;
  1624. platform_set_drvdata(pdev, card);
  1625. snd_soc_card_set_drvdata(card, pdata);
  1626. ret = snd_soc_of_parse_card_name(card, "qcom,model");
  1627. if (ret) {
  1628. dev_err(&pdev->dev, "%s: parse card name failed, err:%d\n",
  1629. __func__, ret);
  1630. goto err;
  1631. }
  1632. ret = snd_soc_of_parse_audio_routing(card, "qcom,audio-routing");
  1633. if (ret) {
  1634. dev_err(&pdev->dev, "%s: parse audio routing failed, err:%d\n",
  1635. __func__, ret);
  1636. goto err;
  1637. }
  1638. ret = msm_populate_dai_link_component_of_node(card);
  1639. if (ret) {
  1640. ret = -EPROBE_DEFER;
  1641. goto err;
  1642. }
  1643. /* parse upd configuration */
  1644. msm_parse_upd_configuration(pdev, pdata);
  1645. ret = devm_snd_soc_register_card(&pdev->dev, card);
  1646. if (ret == -EPROBE_DEFER) {
  1647. if (codec_reg_done)
  1648. ret = -EINVAL;
  1649. goto err;
  1650. } else if (ret) {
  1651. dev_err(&pdev->dev, "%s: snd_soc_register_card failed (%d)\n",
  1652. __func__, ret);
  1653. goto err;
  1654. }
  1655. dev_info(&pdev->dev, "%s: Sound card %s registered\n",
  1656. __func__, card->name);
  1657. if (wcd_mbhc_cfg.enable_usbc_analog)
  1658. wcd_mbhc_cfg.swap_gnd_mic = msm_usbc_swap_gnd_mic;
  1659. pdata->fsa_handle = of_parse_phandle(pdev->dev.of_node,
  1660. "fsa4480-i2c-handle", 0);
  1661. if (!pdata->fsa_handle)
  1662. dev_dbg(&pdev->dev, "property %s not detected in node %s\n",
  1663. "fsa4480-i2c-handle", pdev->dev.of_node->full_name);
  1664. pdata->dmic01_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1665. "qcom,cdc-dmic01-gpios",
  1666. 0);
  1667. pdata->dmic23_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1668. "qcom,cdc-dmic23-gpios",
  1669. 0);
  1670. pdata->dmic45_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1671. "qcom,cdc-dmic45-gpios",
  1672. 0);
  1673. if (pdata->dmic01_gpio_p)
  1674. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic01_gpio_p, false);
  1675. if (pdata->dmic23_gpio_p)
  1676. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic23_gpio_p, false);
  1677. if (pdata->dmic45_gpio_p)
  1678. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic45_gpio_p, false);
  1679. msm_common_snd_init(pdev, card);
  1680. /* Register LPASS audio hw vote */
  1681. lpass_audio_hw_vote = devm_clk_get(&pdev->dev, "lpass_audio_hw_vote");
  1682. if (IS_ERR(lpass_audio_hw_vote)) {
  1683. ret = PTR_ERR(lpass_audio_hw_vote);
  1684. dev_dbg(&pdev->dev, "%s: clk get %s failed %d\n",
  1685. __func__, "lpass_audio_hw_vote", ret);
  1686. lpass_audio_hw_vote = NULL;
  1687. ret = 0;
  1688. }
  1689. pdata->lpass_audio_hw_vote = lpass_audio_hw_vote;
  1690. pdata->core_audio_vote_count = 0;
  1691. ret = msm_audio_ssr_register(&pdev->dev);
  1692. if (ret)
  1693. pr_err("%s: Registration with SND event FWK failed ret = %d\n",
  1694. __func__, ret);
  1695. is_initial_boot = true;
  1696. /* change card status to ONLINE */
  1697. dev_dbg(&pdev->dev, "%s: setting snd_card to ONLINE\n", __func__);
  1698. snd_card_set_card_status(SND_CARD_STATUS_ONLINE);
  1699. return 0;
  1700. err:
  1701. devm_kfree(&pdev->dev, pdata);
  1702. return ret;
  1703. }
  1704. static int msm_asoc_machine_remove(struct platform_device *pdev)
  1705. {
  1706. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1707. struct msm_asoc_mach_data *pdata = NULL;
  1708. struct msm_common_pdata *common_pdata = NULL;
  1709. if (card)
  1710. pdata = snd_soc_card_get_drvdata(card);
  1711. if (pdata)
  1712. common_pdata = pdata->common_pdata;
  1713. msm_common_snd_deinit(common_pdata);
  1714. snd_event_master_deregister(&pdev->dev);
  1715. snd_soc_unregister_card(card);
  1716. return 0;
  1717. }
  1718. static struct platform_driver waipio_asoc_machine_driver = {
  1719. .driver = {
  1720. .name = DRV_NAME,
  1721. .owner = THIS_MODULE,
  1722. .pm = &snd_soc_pm_ops,
  1723. .of_match_table = waipio_asoc_machine_of_match,
  1724. .suppress_bind_attrs = true,
  1725. },
  1726. .probe = msm_asoc_machine_probe,
  1727. .remove = msm_asoc_machine_remove,
  1728. };
  1729. static int __init msm_asoc_machine_init(void)
  1730. {
  1731. snd_card_sysfs_init();
  1732. return platform_driver_register(&waipio_asoc_machine_driver);
  1733. }
  1734. module_init(msm_asoc_machine_init);
  1735. static void __exit msm_asoc_machine_exit(void)
  1736. {
  1737. platform_driver_unregister(&waipio_asoc_machine_driver);
  1738. }
  1739. module_exit(msm_asoc_machine_exit);
  1740. MODULE_SOFTDEP("pre: bt_fm_slim");
  1741. MODULE_DESCRIPTION("ALSA SoC msm");
  1742. MODULE_LICENSE("GPL v2");
  1743. MODULE_ALIAS("platform:" DRV_NAME);
  1744. MODULE_DEVICE_TABLE(of, waipio_asoc_machine_of_match);