kalama.c 53 KB

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