pineapple.c 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022-2023, 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. #if IS_ENABLED(CONFIG_QCOM_WCD_USBSS_I2C)
  17. #include <linux/soc/qcom/wcd939x-i2c.h>
  18. #endif
  19. #include <linux/pm_qos.h>
  20. #include <sound/control.h>
  21. #include <sound/core.h>
  22. #include <sound/soc.h>
  23. #include <sound/soc-dapm.h>
  24. #include <sound/pcm.h>
  25. #include <sound/pcm_params.h>
  26. #include <sound/info.h>
  27. #include <soc/snd_event.h>
  28. #include <soc/qcom/socinfo.h>
  29. #include <dsp/audio_prm.h>
  30. #include <soc/swr-common.h>
  31. #include <soc/soundwire.h>
  32. #include "device_event.h"
  33. #include "asoc/msm-cdc-pinctrl.h"
  34. #include "asoc/wcd-mbhc-v2.h"
  35. #include "codecs/wcd937x/wcd937x-mbhc.h"
  36. #include "codecs/wcd939x/wcd939x-mbhc.h"
  37. #include "codecs/wsa884x/wsa884x.h"
  38. #include "codecs/wsa883x/wsa883x.h"
  39. #include "codecs/wcd937x/wcd937x.h"
  40. #include "codecs/wcd939x/wcd939x.h"
  41. #include "codecs/lpass-cdc/lpass-cdc.h"
  42. #include <bindings/audio-codec-port-types.h>
  43. #include "codecs/lpass-cdc/lpass-cdc-wsa-macro.h"
  44. #include "pineapple-port-config.h"
  45. #include "msm-audio-defs.h"
  46. #include "msm_common.h"
  47. #include "msm_dailink.h"
  48. #define DRV_NAME "pineapple-asoc-snd"
  49. #define __CHIPSET__ "PINEAPPLE "
  50. #define MSM_DAILINK_NAME(name) (__CHIPSET__#name)
  51. #define WCD9XXX_MBHC_DEF_RLOADS 5
  52. #define WCD9XXX_MBHC_DEF_BUTTONS 8
  53. #define CODEC_EXT_CLK_RATE 9600000
  54. #define DEV_NAME_STR_LEN 32
  55. #define WCD_MBHC_HS_V_MAX 1600
  56. #define WCN_CDC_SLIM_RX_CH_MAX 2
  57. #define WCN_CDC_SLIM_TX_CH_MAX 2
  58. #define WCN_CDC_SLIM_TX_CH_MAX_LITO 3
  59. /* Number of WSAs */
  60. #define MONO_SPEAKER 1
  61. #define STEREO_SPEAKER 2
  62. #define QUAD_SPEAKER 4
  63. enum {
  64. WCD937X_DEV_INDEX,
  65. WCD939X_DEV_INDEX,
  66. };
  67. struct msm_asoc_mach_data {
  68. struct snd_info_entry *codec_root;
  69. struct msm_common_pdata *common_pdata;
  70. int usbc_en2_gpio; /* used by gpio driver API */
  71. struct device_node *dmic01_gpio_p; /* used by pinctrl API */
  72. struct device_node *dmic23_gpio_p; /* used by pinctrl API */
  73. struct device_node *dmic45_gpio_p; /* used by pinctrl API */
  74. struct device_node *dmic67_gpio_p; /* used by pinctrl API */
  75. struct pinctrl *usbc_en2_gpio_p; /* used by pinctrl API */
  76. bool is_afe_config_done;
  77. struct device_node *wcd_usbss_handle;
  78. struct clk *lpass_audio_hw_vote;
  79. int core_audio_vote_count;
  80. u32 wsa_max_devs;
  81. int wcd_disabled;
  82. int (*get_dev_num)(struct snd_soc_component *);
  83. int backend_used;
  84. struct prm_earpa_hw_intf_config upd_config;
  85. bool dedicated_wsa2; /* used to define how wsa2 slave devices are used */
  86. int wcd_used;
  87. };
  88. static bool is_initial_boot;
  89. static bool codec_reg_done;
  90. static struct snd_soc_card snd_soc_card_pineapple_msm;
  91. static int dmic_0_1_gpio_cnt;
  92. static int dmic_2_3_gpio_cnt;
  93. static int dmic_4_5_gpio_cnt;
  94. static int dmic_6_7_gpio_cnt;
  95. static void *def_wcd_mbhc_cal(void);
  96. static int msm_rx_tx_codec_init(struct snd_soc_pcm_runtime*);
  97. static int msm_int_wsa_init(struct snd_soc_pcm_runtime*);
  98. static int msm_int_wsa884x_init(struct snd_soc_pcm_runtime*);
  99. static int msm_int_wsa883x_init(struct snd_soc_pcm_runtime*);
  100. static int msm_int_wsa2_init(struct snd_soc_pcm_runtime *);
  101. static int msm_int_wsa884x_2_init(struct snd_soc_pcm_runtime *);
  102. static int msm_int_wsa883x_2_init(struct snd_soc_pcm_runtime *);
  103. /*
  104. * Need to report LINEIN
  105. * if R/L channel impedance is larger than 5K ohm
  106. */
  107. static struct wcd_mbhc_config wcd_mbhc_cfg = {
  108. .read_fw_bin = false,
  109. .calibration = NULL,
  110. .detect_extn_cable = true,
  111. .mono_stero_detection = false,
  112. .swap_gnd_mic = NULL,
  113. .hs_ext_micbias = true,
  114. .key_code[0] = KEY_MEDIA,
  115. .key_code[1] = KEY_VOICECOMMAND,
  116. .key_code[2] = KEY_VOLUMEUP,
  117. .key_code[3] = KEY_VOLUMEDOWN,
  118. .key_code[4] = 0,
  119. .key_code[5] = 0,
  120. .key_code[6] = 0,
  121. .key_code[7] = 0,
  122. .linein_th = 5000,
  123. .moisture_en = false,
  124. .mbhc_micbias = MIC_BIAS_2,
  125. .anc_micbias = MIC_BIAS_2,
  126. .enable_anc_mic_detect = false,
  127. .moisture_duty_cycle_en = true,
  128. };
  129. static bool msm_usbc_swap_gnd_mic(struct snd_soc_component *component, bool active)
  130. {
  131. bool ret = false;
  132. struct snd_soc_card *card = component->card;
  133. struct msm_asoc_mach_data *pdata =
  134. snd_soc_card_get_drvdata(card);
  135. if (!pdata->wcd_usbss_handle)
  136. return false;
  137. #if IS_ENABLED(CONFIG_QCOM_WCD_USBSS_I2C)
  138. if (wcd_mbhc_cfg.usbss_hsj_connect_enable)
  139. ret = wcd_usbss_switch_update(WCD_USBSS_GND_MIC_SWAP_HSJ,
  140. WCD_USBSS_CABLE_CONNECT);
  141. else if (wcd_mbhc_cfg.enable_usbc_analog)
  142. ret = wcd_usbss_switch_update(WCD_USBSS_GND_MIC_SWAP_AATC,
  143. WCD_USBSS_CABLE_CONNECT);
  144. #endif
  145. return ret;
  146. }
  147. static void msm_parse_upd_configuration(struct platform_device *pdev,
  148. struct msm_asoc_mach_data *pdata)
  149. {
  150. int ret = 0;
  151. u32 dt_values[2];
  152. if (!pdev || !pdata)
  153. return;
  154. ret = of_property_read_string(pdev->dev.of_node,
  155. "qcom,upd_backends_used", &pdata->upd_config.backend_used);
  156. if (ret) {
  157. pr_debug("%s:could not find %s entry in dt\n",
  158. __func__, "qcom,upd_backends_used");
  159. return;
  160. }
  161. ret = of_property_read_u32_array(pdev->dev.of_node,
  162. "qcom,upd_lpass_reg_addr", dt_values, MAX_EARPA_REG);
  163. if (ret) {
  164. pr_debug("%s: could not find %s entry in dt\n",
  165. __func__, "qcom,upd_lpass_reg_addr");
  166. return;
  167. } else {
  168. pdata->upd_config.ear_pa_hw_reg_cfg.lpass_cdc_rx0_rx_path_ctl_phy_addr =
  169. dt_values[0];
  170. pdata->upd_config.ear_pa_hw_reg_cfg.lpass_wr_fifo_reg_phy_addr =
  171. dt_values[1];
  172. }
  173. ret = of_property_read_u32(pdev->dev.of_node,
  174. "qcom,upd_ear_pa_reg_addr", &pdata->upd_config.ear_pa_pkd_reg_addr);
  175. if (ret) {
  176. pr_debug("%s: could not find %s entry in dt\n",
  177. __func__, "qcom,upd_ear_pa_reg_addr");
  178. }
  179. }
  180. static void msm_set_upd_config(struct snd_soc_pcm_runtime *rtd)
  181. {
  182. int val1 = 0, val2 = 0, ret = 0;
  183. u8 dev_num = 0;
  184. struct snd_soc_component *component = NULL;
  185. struct msm_asoc_mach_data *pdata = NULL;
  186. char wcd_name[20];
  187. if (!rtd) {
  188. pr_err_ratelimited("%s: rtd is NULL\n", __func__);
  189. return;
  190. }
  191. pdata = snd_soc_card_get_drvdata(rtd->card);
  192. if (!pdata) {
  193. pr_err_ratelimited("%s: pdata is NULL\n", __func__);
  194. return;
  195. }
  196. if (!pdata->upd_config.ear_pa_hw_reg_cfg.lpass_cdc_rx0_rx_path_ctl_phy_addr ||
  197. !pdata->upd_config.ear_pa_hw_reg_cfg.lpass_wr_fifo_reg_phy_addr ||
  198. !pdata->upd_config.ear_pa_pkd_reg_addr) {
  199. pr_err_ratelimited("%s: upd static configuration is not set\n", __func__);
  200. return;
  201. }
  202. if (!strcmp(pdata->upd_config.backend_used, "wsa")) {
  203. if (pdata->wsa_max_devs > 0) {
  204. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.1");
  205. if (!component) {
  206. pr_err("%s: %s component is NULL\n", __func__,
  207. "wsa-codec.1");
  208. return;
  209. }
  210. } else {
  211. pr_err("%s wsa_max_devs are NULL\n", __func__);
  212. return;
  213. }
  214. } else {
  215. if (pdata->wcd_used == WCD937X_DEV_INDEX)
  216. strscpy(wcd_name, WCD937X_DRV_NAME, sizeof(WCD937X_DRV_NAME));
  217. else
  218. strscpy(wcd_name, WCD939X_DRV_NAME, sizeof(WCD939X_DRV_NAME));
  219. component = snd_soc_rtdcom_lookup(rtd, wcd_name);
  220. if (!component) {
  221. pr_err("%s component is NULL\n", __func__);
  222. return;
  223. }
  224. }
  225. if (!strcmp(pdata->upd_config.backend_used, "wsa")) {
  226. if (strstr(rtd->card->name, "wsa883x"))
  227. pdata->get_dev_num = wsa883x_codec_get_dev_num;
  228. else
  229. pdata->get_dev_num = wsa884x_codec_get_dev_num;
  230. } else {
  231. if (pdata->wcd_used == WCD937X_DEV_INDEX) {
  232. pdata->get_dev_num = wcd937x_codec_get_dev_num;
  233. } else if (pdata->wcd_used == WCD939X_DEV_INDEX) {
  234. pdata->get_dev_num = wcd939x_codec_get_dev_num;
  235. }
  236. }
  237. if (!pdata->get_dev_num) {
  238. pr_err("%s: get_dev_num is NULL\n", __func__);
  239. return;
  240. }
  241. dev_num = pdata->get_dev_num(component);
  242. if (dev_num < 0 || dev_num > 6) {
  243. pr_err_ratelimited("%s: invalid slave dev num : %d\n", __func__,
  244. dev_num);
  245. return;
  246. }
  247. pdata->upd_config.ear_pa_pkd_cfg.ear_pa_enable_pkd_reg_addr =
  248. pdata->upd_config.ear_pa_pkd_reg_addr & 0xFFFF;
  249. pdata->upd_config.ear_pa_pkd_cfg.ear_pa_disable_pkd_reg_addr =
  250. pdata->upd_config.ear_pa_pkd_reg_addr & 0xFFFF;
  251. val1 = val2 = 0;
  252. /* bits 16:19 carry command id */
  253. val1 |= 1 << 16;
  254. /* bits 20:23 carry swr device number */
  255. val1 |= dev_num << 20;
  256. /*
  257. * bits 24:31 carry 8 bit data to disable or enable ear pa
  258. * for wcd 7bit is global enable bit - 1 -enable. 0 - disable
  259. * for wsa 0bit is global enable bit - 1 -enable, 0 - disable
  260. */
  261. val2 = val1;
  262. if (!strcmp(pdata->upd_config.backend_used, "wsa"))
  263. val1 |= 1 << 24;
  264. else
  265. val1 |= 1 << 31;
  266. pdata->upd_config.ear_pa_pkd_cfg.ear_pa_enable_pkd_reg_addr |= val1;
  267. pdata->upd_config.ear_pa_pkd_cfg.ear_pa_disable_pkd_reg_addr |= val2;
  268. ret = audio_prm_set_cdc_earpa_duty_cycling_req(&pdata->upd_config, 1);
  269. if (ret < 0) {
  270. pr_err_ratelimited("%s: upd cdc duty cycling registration failed\n", __func__);
  271. return;
  272. }
  273. pr_debug("%s: upd cdc duty cycling registration done successfully!\n", __func__);
  274. }
  275. static struct snd_soc_ops msm_common_be_ops = {
  276. .hw_params = msm_common_snd_hw_params,
  277. .startup = msm_common_snd_startup,
  278. .shutdown = msm_common_snd_shutdown,
  279. };
  280. static int msm_dmic_event(struct snd_soc_dapm_widget *w,
  281. struct snd_kcontrol *kcontrol, int event)
  282. {
  283. struct msm_asoc_mach_data *pdata = NULL;
  284. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  285. int ret = 0;
  286. u32 dmic_idx;
  287. int *dmic_gpio_cnt;
  288. struct device_node *dmic_gpio;
  289. char *wname;
  290. wname = strpbrk(w->name, "01234567");
  291. if (!wname) {
  292. dev_err_ratelimited(component->dev, "%s: widget not found\n", __func__);
  293. return -EINVAL;
  294. }
  295. ret = kstrtouint(wname, 10, &dmic_idx);
  296. if (ret < 0) {
  297. dev_err_ratelimited(component->dev, "%s: Invalid DMIC line on the codec\n",
  298. __func__);
  299. return -EINVAL;
  300. }
  301. pdata = snd_soc_card_get_drvdata(component->card);
  302. switch (dmic_idx) {
  303. case 0:
  304. case 1:
  305. dmic_gpio_cnt = &dmic_0_1_gpio_cnt;
  306. dmic_gpio = pdata->dmic01_gpio_p;
  307. break;
  308. case 2:
  309. case 3:
  310. dmic_gpio_cnt = &dmic_2_3_gpio_cnt;
  311. dmic_gpio = pdata->dmic23_gpio_p;
  312. break;
  313. case 4:
  314. case 5:
  315. dmic_gpio_cnt = &dmic_4_5_gpio_cnt;
  316. dmic_gpio = pdata->dmic45_gpio_p;
  317. break;
  318. case 6:
  319. case 7:
  320. dmic_gpio_cnt = &dmic_6_7_gpio_cnt;
  321. dmic_gpio = pdata->dmic67_gpio_p;
  322. break;
  323. default:
  324. dev_err_ratelimited(component->dev, "%s: Invalid DMIC Selection\n",
  325. __func__);
  326. return -EINVAL;
  327. }
  328. dev_dbg(component->dev, "%s: event %d DMIC%d dmic_gpio_cnt %d\n",
  329. __func__, event, dmic_idx, *dmic_gpio_cnt);
  330. switch (event) {
  331. case SND_SOC_DAPM_PRE_PMU:
  332. (*dmic_gpio_cnt)++;
  333. if (*dmic_gpio_cnt == 1) {
  334. ret = msm_cdc_pinctrl_select_active_state(
  335. dmic_gpio);
  336. if (ret < 0) {
  337. pr_err_ratelimited("%s: gpio set cannot be activated %sd",
  338. __func__, "dmic_gpio");
  339. return ret;
  340. }
  341. }
  342. break;
  343. case SND_SOC_DAPM_POST_PMD:
  344. (*dmic_gpio_cnt)--;
  345. if (*dmic_gpio_cnt == 0) {
  346. ret = msm_cdc_pinctrl_select_sleep_state(
  347. dmic_gpio);
  348. if (ret < 0) {
  349. pr_err_ratelimited("%s: gpio set cannot be de-activated %sd",
  350. __func__, "dmic_gpio");
  351. return ret;
  352. }
  353. }
  354. break;
  355. default:
  356. pr_err_ratelimited("%s: invalid DAPM event %d\n", __func__, event);
  357. return -EINVAL;
  358. }
  359. return 0;
  360. }
  361. static const struct snd_soc_dapm_widget msm_int_dapm_widgets[] = {
  362. SND_SOC_DAPM_MIC("Analog Mic1", NULL),
  363. SND_SOC_DAPM_MIC("Analog Mic2", NULL),
  364. SND_SOC_DAPM_MIC("Analog Mic3", NULL),
  365. SND_SOC_DAPM_MIC("Analog Mic4", NULL),
  366. SND_SOC_DAPM_MIC("Analog Mic5", NULL),
  367. SND_SOC_DAPM_MIC("Digital Mic0", msm_dmic_event),
  368. SND_SOC_DAPM_MIC("Digital Mic1", msm_dmic_event),
  369. SND_SOC_DAPM_MIC("Digital Mic2", msm_dmic_event),
  370. SND_SOC_DAPM_MIC("Digital Mic3", msm_dmic_event),
  371. SND_SOC_DAPM_MIC("Digital Mic4", msm_dmic_event),
  372. SND_SOC_DAPM_MIC("Digital Mic5", msm_dmic_event),
  373. SND_SOC_DAPM_MIC("Digital Mic6", NULL),
  374. SND_SOC_DAPM_MIC("Digital Mic7", NULL),
  375. };
  376. #ifndef CONFIG_AUDIO_BTFM_PROXY
  377. static int msm_wcn_init(struct snd_soc_pcm_runtime *rtd)
  378. {
  379. unsigned int rx_ch[WCN_CDC_SLIM_RX_CH_MAX] = {157, 158};
  380. unsigned int tx_ch[WCN_CDC_SLIM_TX_CH_MAX] = {159, 160};
  381. struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
  382. int ret = 0;
  383. ret = snd_soc_dai_set_channel_map(codec_dai, ARRAY_SIZE(tx_ch),
  384. tx_ch, ARRAY_SIZE(rx_ch), rx_ch);
  385. if (ret)
  386. return ret;
  387. msm_common_dai_link_init(rtd);
  388. return ret;
  389. }
  390. #endif
  391. static struct snd_info_entry *msm_snd_info_create_subdir(struct module *mod,
  392. const char *name,
  393. struct snd_info_entry *parent)
  394. {
  395. struct snd_info_entry *entry;
  396. entry = snd_info_create_module_entry(mod, name, parent);
  397. if (!entry)
  398. return NULL;
  399. entry->mode = S_IFDIR | 0555;
  400. if (snd_info_register(entry) < 0) {
  401. snd_info_free_entry(entry);
  402. return NULL;
  403. }
  404. return entry;
  405. }
  406. static void *def_wcd_mbhc_cal(void)
  407. {
  408. void *wcd_mbhc_cal;
  409. struct wcd_mbhc_btn_detect_cfg *btn_cfg;
  410. u16 *btn_high;
  411. wcd_mbhc_cal = kzalloc(WCD_MBHC_CAL_SIZE(WCD_MBHC_DEF_BUTTONS,
  412. WCD9XXX_MBHC_DEF_RLOADS), GFP_KERNEL);
  413. if (!wcd_mbhc_cal)
  414. return NULL;
  415. WCD_MBHC_CAL_PLUG_TYPE_PTR(wcd_mbhc_cal)->v_hs_max = WCD_MBHC_HS_V_MAX;
  416. WCD_MBHC_CAL_BTN_DET_PTR(wcd_mbhc_cal)->num_btn = WCD_MBHC_DEF_BUTTONS;
  417. btn_cfg = WCD_MBHC_CAL_BTN_DET_PTR(wcd_mbhc_cal);
  418. btn_high = ((void *)&btn_cfg->_v_btn_low) +
  419. (sizeof(btn_cfg->_v_btn_low[0]) * btn_cfg->num_btn);
  420. btn_high[0] = 75;
  421. btn_high[1] = 150;
  422. btn_high[2] = 237;
  423. btn_high[3] = 500;
  424. btn_high[4] = 500;
  425. btn_high[5] = 500;
  426. btn_high[6] = 500;
  427. btn_high[7] = 500;
  428. return wcd_mbhc_cal;
  429. }
  430. /* Digital audio interface glue - connects codec <---> CPU */
  431. static struct snd_soc_dai_link msm_common_be_dai_links[] = {
  432. /* Proxy Tx BACK END DAI Link */
  433. {
  434. .name = LPASS_BE_RT_PROXY_PCM_TX,
  435. .stream_name = LPASS_BE_RT_PROXY_PCM_TX,
  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(proxy_tx),
  442. },
  443. {
  444. .name = LPASS_BE_RT_PROXY_PCM_TX_2,
  445. .stream_name = LPASS_BE_RT_PROXY_PCM_TX_2,
  446. .capture_only = 1,
  447. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  448. SND_SOC_DPCM_TRIGGER_POST},
  449. .ignore_suspend = 1,
  450. .ops = &msm_common_be_ops,
  451. SND_SOC_DAILINK_REG(proxy_tx2),
  452. },
  453. /* Proxy Rx BACK END DAI Link */
  454. {
  455. .name = LPASS_BE_RT_PROXY_PCM_RX,
  456. .stream_name = LPASS_BE_RT_PROXY_PCM_RX,
  457. .playback_only = 1,
  458. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  459. SND_SOC_DPCM_TRIGGER_POST},
  460. .ignore_pmdown_time = 1,
  461. .ignore_suspend = 1,
  462. .ops = &msm_common_be_ops,
  463. SND_SOC_DAILINK_REG(proxy_rx),
  464. },
  465. {
  466. .name = LPASS_BE_RT_PROXY_PCM_RX_2,
  467. .stream_name = LPASS_BE_RT_PROXY_PCM_RX_2,
  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. .ops = &msm_common_be_ops,
  474. SND_SOC_DAILINK_REG(proxy_rx2),
  475. },
  476. {
  477. .name = LPASS_BE_USB_AUDIO_RX,
  478. .stream_name = LPASS_BE_USB_AUDIO_RX,
  479. .playback_only = 1,
  480. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  481. SND_SOC_DPCM_TRIGGER_POST},
  482. .ignore_pmdown_time = 1,
  483. .ignore_suspend = 1,
  484. .ops = &msm_common_be_ops,
  485. SND_SOC_DAILINK_REG(usb_audio_rx),
  486. },
  487. {
  488. .name = LPASS_BE_USB_AUDIO_TX,
  489. .stream_name = LPASS_BE_USB_AUDIO_TX,
  490. .capture_only = 1,
  491. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  492. SND_SOC_DPCM_TRIGGER_POST},
  493. .ignore_suspend = 1,
  494. .ops = &msm_common_be_ops,
  495. SND_SOC_DAILINK_REG(usb_audio_tx),
  496. },
  497. {
  498. .name = LPASS_BE_PCM_DUMMY_TX_0,
  499. .stream_name = LPASS_BE_PCM_DUMMY_TX_0,
  500. .capture_only = 1,
  501. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  502. SND_SOC_DPCM_TRIGGER_POST},
  503. .ignore_suspend = 1,
  504. .ops = &msm_common_be_ops,
  505. SND_SOC_DAILINK_REG(pcm_dummy_tx0),
  506. },
  507. /* Dummy Dev Rx BACK END DAI Link */
  508. {
  509. .name = LPASS_BE_PCM_DUMMY_RX_0,
  510. .stream_name = LPASS_BE_PCM_DUMMY_RX_0,
  511. .playback_only = 1,
  512. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  513. SND_SOC_DPCM_TRIGGER_POST},
  514. .ignore_pmdown_time = 1,
  515. .ignore_suspend = 1,
  516. .ops = &msm_common_be_ops,
  517. SND_SOC_DAILINK_REG(pcm_dummy_rx0),
  518. },
  519. /* Dummy Dev Tx BACK END DAI Link */
  520. {
  521. .name = LPASS_BE_PCM_DUMMY_TX_1,
  522. .stream_name = LPASS_BE_PCM_DUMMY_TX_1,
  523. .capture_only = 1,
  524. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  525. SND_SOC_DPCM_TRIGGER_POST},
  526. .ignore_suspend = 1,
  527. .ops = &msm_common_be_ops,
  528. SND_SOC_DAILINK_REG(pcm_dummy_tx1),
  529. },
  530. };
  531. #ifndef CONFIG_AUDIO_BTFM_PROXY
  532. static struct snd_soc_dai_link msm_wcn_be_dai_links[] = {
  533. {
  534. .name = LPASS_BE_SLIMBUS_7_RX,
  535. .stream_name = LPASS_BE_SLIMBUS_7_RX,
  536. .playback_only = 1,
  537. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  538. SND_SOC_DPCM_TRIGGER_POST},
  539. .init = &msm_wcn_init,
  540. .ops = &msm_common_be_ops,
  541. /* dai link has playback support */
  542. .ignore_pmdown_time = 1,
  543. .ignore_suspend = 1,
  544. SND_SOC_DAILINK_REG(slimbus_7_rx),
  545. },
  546. {
  547. .name = LPASS_BE_SLIMBUS_7_TX,
  548. .stream_name = LPASS_BE_SLIMBUS_7_TX,
  549. .capture_only = 1,
  550. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  551. SND_SOC_DPCM_TRIGGER_POST},
  552. .ops = &msm_common_be_ops,
  553. .ignore_suspend = 1,
  554. SND_SOC_DAILINK_REG(slimbus_7_tx),
  555. },
  556. };
  557. static struct snd_soc_dai_link msm_wcn_btfm_be_dai_links[] = {
  558. {
  559. .name = LPASS_BE_SLIMBUS_7_RX,
  560. .stream_name = LPASS_BE_SLIMBUS_7_RX,
  561. .playback_only = 1,
  562. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  563. SND_SOC_DPCM_TRIGGER_POST},
  564. .init = &msm_wcn_init,
  565. .ops = &msm_common_be_ops,
  566. /* dai link has playback support */
  567. .ignore_pmdown_time = 1,
  568. .ignore_suspend = 1,
  569. SND_SOC_DAILINK_REG(slimbus_7_rx),
  570. },
  571. {
  572. .name = LPASS_BE_SLIMBUS_7_TX,
  573. .stream_name = LPASS_BE_SLIMBUS_7_TX,
  574. .capture_only = 1,
  575. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  576. SND_SOC_DPCM_TRIGGER_POST},
  577. .ops = &msm_common_be_ops,
  578. .ignore_suspend = 1,
  579. SND_SOC_DAILINK_REG(slimbus_7_tx),
  580. },
  581. {
  582. .name = LPASS_BE_SLIMBUS_8_TX,
  583. .stream_name = LPASS_BE_SLIMBUS_8_TX,
  584. .capture_only = 1,
  585. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  586. SND_SOC_DPCM_TRIGGER_POST},
  587. .ops = &msm_common_be_ops,
  588. .ignore_suspend = 1,
  589. SND_SOC_DAILINK_REG(slimbus_8_tx),
  590. },
  591. };
  592. #else
  593. static struct snd_soc_dai_link msm_wcn_be_dai_links[] = {
  594. {
  595. .name = LPASS_BE_BTFM_PROXY_RX_0,
  596. .stream_name = LPASS_BE_BTFM_PROXY_RX_0,
  597. .playback_only = 1,
  598. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  599. SND_SOC_DPCM_TRIGGER_POST},
  600. .ops = &msm_common_be_ops,
  601. /* dai link has playback support */
  602. .ignore_pmdown_time = 1,
  603. .ignore_suspend = 1,
  604. SND_SOC_DAILINK_REG(btfm_0_rx),
  605. },
  606. {
  607. .name = LPASS_BE_BTFM_PROXY_TX_0,
  608. .stream_name = LPASS_BE_BTFM_PROXY_TX_0,
  609. .capture_only = 1,
  610. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  611. SND_SOC_DPCM_TRIGGER_POST},
  612. .ops = &msm_common_be_ops,
  613. .ignore_suspend = 1,
  614. SND_SOC_DAILINK_REG(btfm_0_tx),
  615. },
  616. };
  617. #endif
  618. static struct snd_soc_dai_link ext_disp_be_dai_link[] = {
  619. /* DISP PORT BACK END DAI Link */
  620. {
  621. .name = LPASS_BE_DISPLAY_PORT_RX,
  622. .stream_name = LPASS_BE_DISPLAY_PORT_RX,
  623. .playback_only = 1,
  624. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  625. SND_SOC_DPCM_TRIGGER_POST},
  626. .ignore_pmdown_time = 1,
  627. .ignore_suspend = 1,
  628. SND_SOC_DAILINK_REG(display_port),
  629. },
  630. };
  631. static struct snd_soc_dai_link msm_wsa_cdc_dma_be_dai_links[] = {
  632. /* WSA CDC DMA Backend DAI Links */
  633. {
  634. .name = LPASS_BE_WSA_CDC_DMA_RX_0,
  635. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_0,
  636. .playback_only = 1,
  637. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  638. SND_SOC_DPCM_TRIGGER_POST},
  639. .ignore_pmdown_time = 1,
  640. .ignore_suspend = 1,
  641. .ops = &msm_common_be_ops,
  642. SND_SOC_DAILINK_REG(wsa_dma_rx0),
  643. .init = &msm_int_wsa_init,
  644. },
  645. {
  646. .name = LPASS_BE_WSA_CDC_DMA_RX_1,
  647. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_1,
  648. .playback_only = 1,
  649. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  650. SND_SOC_DPCM_TRIGGER_POST},
  651. .ignore_pmdown_time = 1,
  652. .ignore_suspend = 1,
  653. .ops = &msm_common_be_ops,
  654. SND_SOC_DAILINK_REG(wsa_dma_rx1),
  655. },
  656. {
  657. .name = LPASS_BE_WSA_CDC_DMA_TX_1,
  658. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_1,
  659. .capture_only = 1,
  660. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  661. SND_SOC_DPCM_TRIGGER_POST},
  662. .ignore_suspend = 1,
  663. .ops = &msm_common_be_ops,
  664. SND_SOC_DAILINK_REG(wsa_dma_tx1),
  665. },
  666. {
  667. .name = LPASS_BE_WSA_CDC_DMA_TX_0,
  668. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_0,
  669. .capture_only = 1,
  670. .ignore_suspend = 1,
  671. .ops = &msm_common_be_ops,
  672. /* .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, */
  673. SND_SOC_DAILINK_REG(vi_feedback),
  674. },
  675. {
  676. .name = LPASS_BE_WSA_CDC_DMA_TX_2,
  677. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_2,
  678. .capture_only = 1,
  679. .ignore_suspend = 1,
  680. .ops = &msm_common_be_ops,
  681. /* .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, */
  682. SND_SOC_DAILINK_REG(cps_feedback),
  683. },
  684. {
  685. .name = LPASS_BE_WSA_CDC_DMA_RX_0_VIRT,
  686. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_0_VIRT,
  687. .playback_only = 1,
  688. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  689. SND_SOC_DPCM_TRIGGER_POST},
  690. .ignore_pmdown_time = 1,
  691. .ignore_suspend = 1,
  692. .ops = &msm_common_be_ops,
  693. SND_SOC_DAILINK_REG(wsa_dma_rx0),
  694. .init = &msm_int_wsa_init,
  695. },
  696. };
  697. static struct snd_soc_dai_link msm_wsa2_cdc_dma_be_dai_links[] = {
  698. /* WSA2 CDC DMA Backend DAI Links */
  699. {
  700. .name = LPASS_BE_WSA2_CDC_DMA_RX_0,
  701. .stream_name = LPASS_BE_WSA2_CDC_DMA_RX_0,
  702. .playback_only = 1,
  703. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  704. SND_SOC_DPCM_TRIGGER_POST},
  705. .ignore_pmdown_time = 1,
  706. .ignore_suspend = 1,
  707. .ops = &msm_common_be_ops,
  708. SND_SOC_DAILINK_REG(wsa2_dma_rx0),
  709. .init = &msm_int_wsa2_init,
  710. },
  711. {
  712. .name = LPASS_BE_WSA2_CDC_DMA_RX_1,
  713. .stream_name = LPASS_BE_WSA2_CDC_DMA_RX_1,
  714. .playback_only = 1,
  715. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  716. SND_SOC_DPCM_TRIGGER_POST},
  717. .ignore_pmdown_time = 1,
  718. .ignore_suspend = 1,
  719. .ops = &msm_common_be_ops,
  720. SND_SOC_DAILINK_REG(wsa2_dma_rx1),
  721. },
  722. {
  723. .name = LPASS_BE_WSA2_CDC_DMA_TX_1,
  724. .stream_name = LPASS_BE_WSA2_CDC_DMA_TX_1,
  725. .capture_only = 1,
  726. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  727. SND_SOC_DPCM_TRIGGER_POST},
  728. .ignore_suspend = 1,
  729. .ops = &msm_common_be_ops,
  730. SND_SOC_DAILINK_REG(wsa2_dma_tx1),
  731. },
  732. {
  733. .name = LPASS_BE_WSA2_CDC_DMA_TX_0,
  734. .stream_name = LPASS_BE_WSA2_CDC_DMA_TX_0,
  735. .capture_only = 1,
  736. .ignore_suspend = 1,
  737. .ops = &msm_common_be_ops,
  738. /* .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, */
  739. SND_SOC_DAILINK_REG(wsa2_vi_feedback),
  740. },
  741. {
  742. .name = LPASS_BE_WSA2_CDC_DMA_TX_2,
  743. .stream_name = LPASS_BE_WSA2_CDC_DMA_TX_2,
  744. .capture_only = 1,
  745. .ignore_suspend = 1,
  746. .ops = &msm_common_be_ops,
  747. /* .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, */
  748. SND_SOC_DAILINK_REG(wsa2_cps_feedback),
  749. },
  750. };
  751. static struct snd_soc_dai_link msm_wsa_wsa2_cdc_dma_be_dai_links[] = {
  752. /* WSA CDC DMA Backend DAI Links */
  753. {
  754. .name = LPASS_BE_WSA_CDC_DMA_RX_0,
  755. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_0,
  756. .playback_only = 1,
  757. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  758. SND_SOC_DPCM_TRIGGER_POST},
  759. .ignore_pmdown_time = 1,
  760. .ignore_suspend = 1,
  761. .ops = &msm_common_be_ops,
  762. SND_SOC_DAILINK_REG(wsa_wsa2_dma_rx0),
  763. .init = &msm_int_wsa_init,
  764. },
  765. {
  766. .name = LPASS_BE_WSA_CDC_DMA_RX_1,
  767. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_1,
  768. .playback_only = 1,
  769. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  770. SND_SOC_DPCM_TRIGGER_POST},
  771. .ignore_pmdown_time = 1,
  772. .ignore_suspend = 1,
  773. .ops = &msm_common_be_ops,
  774. SND_SOC_DAILINK_REG(wsa_wsa2_dma_rx1),
  775. },
  776. {
  777. .name = LPASS_BE_WSA_CDC_DMA_TX_1,
  778. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_1,
  779. .capture_only = 1,
  780. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  781. SND_SOC_DPCM_TRIGGER_POST},
  782. .ignore_suspend = 1,
  783. .ops = &msm_common_be_ops,
  784. SND_SOC_DAILINK_REG(wsa_wsa2_dma_tx1),
  785. },
  786. {
  787. .name = LPASS_BE_WSA_CDC_DMA_TX_0,
  788. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_0,
  789. .capture_only = 1,
  790. .ignore_suspend = 1,
  791. .ops = &msm_common_be_ops,
  792. /* .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, */
  793. SND_SOC_DAILINK_REG(wsa_wsa2_vi_feedback),
  794. },
  795. {
  796. .name = LPASS_BE_WSA_CDC_DMA_TX_2,
  797. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_2,
  798. .capture_only = 1,
  799. .ignore_suspend = 1,
  800. .ops = &msm_common_be_ops,
  801. /* .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, */
  802. SND_SOC_DAILINK_REG(wsa_wsa2_cps_feedback),
  803. },
  804. };
  805. static struct snd_soc_dai_link msm_rx_tx_cdc_dma_be_dai_links[] = {
  806. /* RX CDC DMA Backend DAI Links */
  807. {
  808. .name = LPASS_BE_RX_CDC_DMA_RX_0,
  809. .stream_name = LPASS_BE_RX_CDC_DMA_RX_0,
  810. .playback_only = 1,
  811. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  812. SND_SOC_DPCM_TRIGGER_POST},
  813. .ignore_pmdown_time = 1,
  814. .ignore_suspend = 1,
  815. .ops = &msm_common_be_ops,
  816. SND_SOC_DAILINK_REG(rx_dma_rx0),
  817. .init = &msm_rx_tx_codec_init,
  818. },
  819. {
  820. .name = LPASS_BE_RX_CDC_DMA_RX_1,
  821. .stream_name = LPASS_BE_RX_CDC_DMA_RX_1,
  822. .playback_only = 1,
  823. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  824. SND_SOC_DPCM_TRIGGER_POST},
  825. .ignore_pmdown_time = 1,
  826. .ignore_suspend = 1,
  827. .ops = &msm_common_be_ops,
  828. SND_SOC_DAILINK_REG(rx_dma_rx1),
  829. },
  830. {
  831. .name = LPASS_BE_RX_CDC_DMA_RX_2,
  832. .stream_name = LPASS_BE_RX_CDC_DMA_RX_2,
  833. .playback_only = 1,
  834. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  835. SND_SOC_DPCM_TRIGGER_POST},
  836. .ignore_pmdown_time = 1,
  837. .ignore_suspend = 1,
  838. .ops = &msm_common_be_ops,
  839. SND_SOC_DAILINK_REG(rx_dma_rx2),
  840. },
  841. {
  842. .name = LPASS_BE_RX_CDC_DMA_RX_3,
  843. .stream_name = LPASS_BE_RX_CDC_DMA_RX_3,
  844. .playback_only = 1,
  845. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  846. SND_SOC_DPCM_TRIGGER_POST},
  847. .ignore_pmdown_time = 1,
  848. .ignore_suspend = 1,
  849. .ops = &msm_common_be_ops,
  850. SND_SOC_DAILINK_REG(rx_dma_rx3),
  851. },
  852. {
  853. .name = LPASS_BE_RX_CDC_DMA_RX_5,
  854. .stream_name = LPASS_BE_RX_CDC_DMA_RX_5,
  855. .playback_only = 1,
  856. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  857. SND_SOC_DPCM_TRIGGER_POST},
  858. .ignore_pmdown_time = 1,
  859. .ignore_suspend = 1,
  860. .ops = &msm_common_be_ops,
  861. SND_SOC_DAILINK_REG(rx_dma_rx5),
  862. },
  863. {
  864. .name = LPASS_BE_RX_CDC_DMA_RX_6,
  865. .stream_name = LPASS_BE_RX_CDC_DMA_RX_6,
  866. .playback_only = 1,
  867. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  868. SND_SOC_DPCM_TRIGGER_POST},
  869. .ignore_pmdown_time = 1,
  870. .ignore_suspend = 1,
  871. .ops = &msm_common_be_ops,
  872. SND_SOC_DAILINK_REG(rx_dma_rx6),
  873. },
  874. /* TX CDC DMA Backend DAI Links */
  875. {
  876. .name = LPASS_BE_TX_CDC_DMA_TX_3,
  877. .stream_name = LPASS_BE_TX_CDC_DMA_TX_3,
  878. .capture_only = 1,
  879. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  880. SND_SOC_DPCM_TRIGGER_POST},
  881. .ignore_suspend = 1,
  882. .ops = &msm_common_be_ops,
  883. SND_SOC_DAILINK_REG(tx_dma_tx3),
  884. },
  885. {
  886. .name = LPASS_BE_TX_CDC_DMA_TX_4,
  887. .stream_name = LPASS_BE_TX_CDC_DMA_TX_4,
  888. .capture_only = 1,
  889. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  890. SND_SOC_DPCM_TRIGGER_POST},
  891. .ignore_suspend = 1,
  892. .ops = &msm_common_be_ops,
  893. SND_SOC_DAILINK_REG(tx_dma_tx4),
  894. },
  895. };
  896. static struct snd_soc_dai_link msm_va_cdc_dma_be_dai_links[] = {
  897. {
  898. .name = LPASS_BE_VA_CDC_DMA_TX_0,
  899. .stream_name = LPASS_BE_VA_CDC_DMA_TX_0,
  900. .capture_only = 1,
  901. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  902. SND_SOC_DPCM_TRIGGER_POST},
  903. .ignore_suspend = 1,
  904. .ops = &msm_common_be_ops,
  905. SND_SOC_DAILINK_REG(va_dma_tx0),
  906. },
  907. {
  908. .name = LPASS_BE_VA_CDC_DMA_TX_1,
  909. .stream_name = LPASS_BE_VA_CDC_DMA_TX_1,
  910. .capture_only = 1,
  911. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  912. SND_SOC_DPCM_TRIGGER_POST},
  913. .ignore_suspend = 1,
  914. .ops = &msm_common_be_ops,
  915. SND_SOC_DAILINK_REG(va_dma_tx1),
  916. },
  917. {
  918. .name = LPASS_BE_VA_CDC_DMA_TX_2,
  919. .stream_name = LPASS_BE_VA_CDC_DMA_TX_2,
  920. .capture_only = 1,
  921. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  922. SND_SOC_DPCM_TRIGGER_POST},
  923. .ignore_suspend = 1,
  924. .ops = &msm_common_be_ops,
  925. SND_SOC_DAILINK_REG(va_dma_tx2),
  926. },
  927. };
  928. /*
  929. * I2S interface pinctrl mapping
  930. * ------------------------------------
  931. * Primary - pri_mi2s
  932. * Secondary - lpi_i2s3
  933. * Tertiary - tert_mi2s
  934. * Quaternary - quat_mi2s (lpi_i2s0)
  935. * Quinary - lpi_i2s1
  936. * Senary - lpi_i2s2
  937. * ------------------------------------
  938. */
  939. static struct snd_soc_dai_link msm_mi2s_dai_links[] = {
  940. {
  941. .name = LPASS_BE_PRI_MI2S_RX,
  942. .stream_name = LPASS_BE_PRI_MI2S_RX,
  943. .playback_only = 1,
  944. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  945. SND_SOC_DPCM_TRIGGER_POST},
  946. .ops = &msm_common_be_ops,
  947. .ignore_suspend = 1,
  948. .ignore_pmdown_time = 1,
  949. SND_SOC_DAILINK_REG(pri_mi2s_rx),
  950. },
  951. {
  952. .name = LPASS_BE_PRI_MI2S_TX,
  953. .stream_name = LPASS_BE_PRI_MI2S_TX,
  954. .capture_only = 1,
  955. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  956. SND_SOC_DPCM_TRIGGER_POST},
  957. .ops = &msm_common_be_ops,
  958. .ignore_suspend = 1,
  959. SND_SOC_DAILINK_REG(pri_mi2s_tx),
  960. },
  961. {
  962. .name = LPASS_BE_SEC_MI2S_RX,
  963. .stream_name = LPASS_BE_SEC_MI2S_RX,
  964. .playback_only = 1,
  965. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  966. SND_SOC_DPCM_TRIGGER_POST},
  967. .ops = &msm_common_be_ops,
  968. .ignore_suspend = 1,
  969. .ignore_pmdown_time = 1,
  970. SND_SOC_DAILINK_REG(sec_mi2s_rx),
  971. },
  972. {
  973. .name = LPASS_BE_SEC_MI2S_TX,
  974. .stream_name = LPASS_BE_SEC_MI2S_TX,
  975. .capture_only = 1,
  976. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  977. SND_SOC_DPCM_TRIGGER_POST},
  978. .ops = &msm_common_be_ops,
  979. .ignore_suspend = 1,
  980. SND_SOC_DAILINK_REG(sec_mi2s_tx),
  981. },
  982. {
  983. .name = LPASS_BE_TERT_MI2S_RX,
  984. .stream_name = LPASS_BE_TERT_MI2S_RX,
  985. .playback_only = 1,
  986. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  987. SND_SOC_DPCM_TRIGGER_POST},
  988. .ops = &msm_common_be_ops,
  989. .ignore_suspend = 1,
  990. .ignore_pmdown_time = 1,
  991. SND_SOC_DAILINK_REG(tert_mi2s_rx),
  992. },
  993. {
  994. .name = LPASS_BE_TERT_MI2S_TX,
  995. .stream_name = LPASS_BE_TERT_MI2S_TX,
  996. .capture_only = 1,
  997. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  998. SND_SOC_DPCM_TRIGGER_POST},
  999. .ops = &msm_common_be_ops,
  1000. .ignore_suspend = 1,
  1001. SND_SOC_DAILINK_REG(tert_mi2s_tx),
  1002. },
  1003. {
  1004. .name = LPASS_BE_QUAT_MI2S_RX,
  1005. .stream_name = LPASS_BE_QUAT_MI2S_RX,
  1006. .playback_only = 1,
  1007. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1008. SND_SOC_DPCM_TRIGGER_POST},
  1009. .ops = &msm_common_be_ops,
  1010. .ignore_suspend = 1,
  1011. .ignore_pmdown_time = 1,
  1012. SND_SOC_DAILINK_REG(quat_mi2s_rx),
  1013. },
  1014. {
  1015. .name = LPASS_BE_QUAT_MI2S_TX,
  1016. .stream_name = LPASS_BE_QUAT_MI2S_TX,
  1017. .capture_only = 1,
  1018. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1019. SND_SOC_DPCM_TRIGGER_POST},
  1020. .ops = &msm_common_be_ops,
  1021. .ignore_suspend = 1,
  1022. SND_SOC_DAILINK_REG(quat_mi2s_tx),
  1023. },
  1024. {
  1025. .name = LPASS_BE_QUIN_MI2S_RX,
  1026. .stream_name = LPASS_BE_QUIN_MI2S_RX,
  1027. .playback_only = 1,
  1028. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1029. SND_SOC_DPCM_TRIGGER_POST},
  1030. .ops = &msm_common_be_ops,
  1031. .ignore_suspend = 1,
  1032. .ignore_pmdown_time = 1,
  1033. SND_SOC_DAILINK_REG(quin_mi2s_rx),
  1034. },
  1035. {
  1036. .name = LPASS_BE_QUIN_MI2S_TX,
  1037. .stream_name = LPASS_BE_QUIN_MI2S_TX,
  1038. .capture_only = 1,
  1039. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1040. SND_SOC_DPCM_TRIGGER_POST},
  1041. .ops = &msm_common_be_ops,
  1042. .ignore_suspend = 1,
  1043. SND_SOC_DAILINK_REG(quin_mi2s_tx),
  1044. },
  1045. {
  1046. .name = LPASS_BE_SEN_MI2S_RX,
  1047. .stream_name = LPASS_BE_SEN_MI2S_RX,
  1048. .playback_only = 1,
  1049. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1050. SND_SOC_DPCM_TRIGGER_POST},
  1051. .ops = &msm_common_be_ops,
  1052. .ignore_suspend = 1,
  1053. .ignore_pmdown_time = 1,
  1054. SND_SOC_DAILINK_REG(sen_mi2s_rx),
  1055. },
  1056. {
  1057. .name = LPASS_BE_SEN_MI2S_TX,
  1058. .stream_name = LPASS_BE_SEN_MI2S_TX,
  1059. .capture_only = 1,
  1060. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1061. SND_SOC_DPCM_TRIGGER_POST},
  1062. .ops = &msm_common_be_ops,
  1063. .ignore_suspend = 1,
  1064. SND_SOC_DAILINK_REG(sen_mi2s_tx),
  1065. },
  1066. {
  1067. .name = LPASS_BE_SEP_MI2S_RX,
  1068. .stream_name = LPASS_BE_SEP_MI2S_RX,
  1069. .playback_only = 1,
  1070. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1071. SND_SOC_DPCM_TRIGGER_POST},
  1072. .ops = &msm_common_be_ops,
  1073. .ignore_suspend = 1,
  1074. .ignore_pmdown_time = 1,
  1075. SND_SOC_DAILINK_REG(sep_mi2s_rx),
  1076. },
  1077. {
  1078. .name = LPASS_BE_SEP_MI2S_TX,
  1079. .stream_name = LPASS_BE_SEP_MI2S_TX,
  1080. .capture_only = 1,
  1081. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1082. SND_SOC_DPCM_TRIGGER_POST},
  1083. .ops = &msm_common_be_ops,
  1084. .ignore_suspend = 1,
  1085. SND_SOC_DAILINK_REG(sep_mi2s_tx),
  1086. },
  1087. };
  1088. static struct snd_soc_dai_link msm_tdm_dai_links[] = {
  1089. {
  1090. .name = LPASS_BE_PRI_TDM_RX_0,
  1091. .stream_name = LPASS_BE_PRI_TDM_RX_0,
  1092. .playback_only = 1,
  1093. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1094. SND_SOC_DPCM_TRIGGER_POST},
  1095. .ops = &msm_common_be_ops,
  1096. .ignore_suspend = 1,
  1097. .ignore_pmdown_time = 1,
  1098. SND_SOC_DAILINK_REG(pri_tdm_rx_0),
  1099. },
  1100. {
  1101. .name = LPASS_BE_PRI_TDM_TX_0,
  1102. .stream_name = LPASS_BE_PRI_TDM_TX_0,
  1103. .capture_only = 1,
  1104. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1105. SND_SOC_DPCM_TRIGGER_POST},
  1106. .ops = &msm_common_be_ops,
  1107. .ignore_suspend = 1,
  1108. SND_SOC_DAILINK_REG(pri_tdm_tx_0),
  1109. },
  1110. {
  1111. .name = LPASS_BE_SEC_TDM_RX_0,
  1112. .stream_name = LPASS_BE_SEC_TDM_RX_0,
  1113. .playback_only = 1,
  1114. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1115. SND_SOC_DPCM_TRIGGER_POST},
  1116. .ops = &msm_common_be_ops,
  1117. .ignore_suspend = 1,
  1118. .ignore_pmdown_time = 1,
  1119. SND_SOC_DAILINK_REG(sec_tdm_rx_0),
  1120. },
  1121. {
  1122. .name = LPASS_BE_SEC_TDM_TX_0,
  1123. .stream_name = LPASS_BE_SEC_TDM_TX_0,
  1124. .capture_only = 1,
  1125. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1126. SND_SOC_DPCM_TRIGGER_POST},
  1127. .ops = &msm_common_be_ops,
  1128. .ignore_suspend = 1,
  1129. SND_SOC_DAILINK_REG(sec_tdm_tx_0),
  1130. },
  1131. {
  1132. .name = LPASS_BE_TERT_TDM_RX_0,
  1133. .stream_name = LPASS_BE_TERT_TDM_RX_0,
  1134. .playback_only = 1,
  1135. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1136. SND_SOC_DPCM_TRIGGER_POST},
  1137. .ops = &msm_common_be_ops,
  1138. .ignore_suspend = 1,
  1139. .ignore_pmdown_time = 1,
  1140. SND_SOC_DAILINK_REG(tert_tdm_rx_0),
  1141. },
  1142. {
  1143. .name = LPASS_BE_TERT_TDM_TX_0,
  1144. .stream_name = LPASS_BE_TERT_TDM_TX_0,
  1145. .capture_only = 1,
  1146. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1147. SND_SOC_DPCM_TRIGGER_POST},
  1148. .ops = &msm_common_be_ops,
  1149. .ignore_suspend = 1,
  1150. SND_SOC_DAILINK_REG(tert_tdm_tx_0),
  1151. },
  1152. {
  1153. .name = LPASS_BE_QUAT_TDM_RX_0,
  1154. .stream_name = LPASS_BE_QUAT_TDM_RX_0,
  1155. .playback_only = 1,
  1156. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1157. SND_SOC_DPCM_TRIGGER_POST},
  1158. .ops = &msm_common_be_ops,
  1159. .ignore_suspend = 1,
  1160. .ignore_pmdown_time = 1,
  1161. SND_SOC_DAILINK_REG(quat_tdm_rx_0),
  1162. },
  1163. {
  1164. .name = LPASS_BE_QUAT_TDM_TX_0,
  1165. .stream_name = LPASS_BE_QUAT_TDM_TX_0,
  1166. .capture_only = 1,
  1167. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1168. SND_SOC_DPCM_TRIGGER_POST},
  1169. .ops = &msm_common_be_ops,
  1170. .ignore_suspend = 1,
  1171. SND_SOC_DAILINK_REG(quat_tdm_tx_0),
  1172. },
  1173. {
  1174. .name = LPASS_BE_QUIN_TDM_RX_0,
  1175. .stream_name = LPASS_BE_QUIN_TDM_RX_0,
  1176. .playback_only = 1,
  1177. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1178. SND_SOC_DPCM_TRIGGER_POST},
  1179. .ops = &msm_common_be_ops,
  1180. .ignore_suspend = 1,
  1181. .ignore_pmdown_time = 1,
  1182. SND_SOC_DAILINK_REG(quin_tdm_rx_0),
  1183. },
  1184. {
  1185. .name = LPASS_BE_QUIN_TDM_TX_0,
  1186. .stream_name = LPASS_BE_QUIN_TDM_TX_0,
  1187. .capture_only = 1,
  1188. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1189. SND_SOC_DPCM_TRIGGER_POST},
  1190. .ops = &msm_common_be_ops,
  1191. .ignore_suspend = 1,
  1192. SND_SOC_DAILINK_REG(quin_tdm_tx_0),
  1193. },
  1194. {
  1195. .name = LPASS_BE_SEN_TDM_RX_0,
  1196. .stream_name = LPASS_BE_SEN_TDM_RX_0,
  1197. .playback_only = 1,
  1198. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1199. SND_SOC_DPCM_TRIGGER_POST},
  1200. .ops = &msm_common_be_ops,
  1201. .ignore_suspend = 1,
  1202. .ignore_pmdown_time = 1,
  1203. SND_SOC_DAILINK_REG(sen_tdm_rx_0),
  1204. },
  1205. {
  1206. .name = LPASS_BE_SEN_TDM_TX_0,
  1207. .stream_name = LPASS_BE_SEN_TDM_TX_0,
  1208. .capture_only = 1,
  1209. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1210. SND_SOC_DPCM_TRIGGER_POST},
  1211. .ops = &msm_common_be_ops,
  1212. .ignore_suspend = 1,
  1213. SND_SOC_DAILINK_REG(sen_tdm_tx_0),
  1214. },
  1215. {
  1216. .name = LPASS_BE_SEP_TDM_RX_0,
  1217. .stream_name = LPASS_BE_SEP_TDM_RX_0,
  1218. .playback_only = 1,
  1219. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1220. SND_SOC_DPCM_TRIGGER_POST},
  1221. .ops = &msm_common_be_ops,
  1222. .ignore_suspend = 1,
  1223. .ignore_pmdown_time = 1,
  1224. SND_SOC_DAILINK_REG(sep_tdm_rx_0),
  1225. },
  1226. {
  1227. .name = LPASS_BE_SEP_TDM_TX_0,
  1228. .stream_name = LPASS_BE_SEP_TDM_TX_0,
  1229. .capture_only = 1,
  1230. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1231. SND_SOC_DPCM_TRIGGER_POST},
  1232. .ops = &msm_common_be_ops,
  1233. .ignore_suspend = 1,
  1234. SND_SOC_DAILINK_REG(sep_tdm_tx_0),
  1235. },
  1236. };
  1237. static struct snd_soc_dai_link msm_pineapple_dai_links[
  1238. ARRAY_SIZE(msm_wsa_cdc_dma_be_dai_links) +
  1239. ARRAY_SIZE(msm_wsa2_cdc_dma_be_dai_links) +
  1240. ARRAY_SIZE(msm_wsa_wsa2_cdc_dma_be_dai_links) +
  1241. ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links) +
  1242. ARRAY_SIZE(msm_va_cdc_dma_be_dai_links) +
  1243. ARRAY_SIZE(ext_disp_be_dai_link) +
  1244. ARRAY_SIZE(msm_common_be_dai_links) +
  1245. ARRAY_SIZE(msm_wcn_btfm_be_dai_links) +
  1246. ARRAY_SIZE(msm_mi2s_dai_links) +
  1247. ARRAY_SIZE(msm_tdm_dai_links)];
  1248. static int msm_populate_dai_link_component_of_node(
  1249. struct snd_soc_card *card)
  1250. {
  1251. int i, j, index, ret = 0;
  1252. struct device *cdev = card->dev;
  1253. struct snd_soc_dai_link *dai_link = card->dai_link;
  1254. struct device_node *np = NULL;
  1255. int codecs_enabled = 0;
  1256. struct snd_soc_dai_link_component *codecs_comp = NULL;
  1257. if (!cdev) {
  1258. dev_err_ratelimited(cdev, "%s: Sound card device memory NULL\n", __func__);
  1259. return -ENODEV;
  1260. }
  1261. for (i = 0; i < card->num_links; i++) {
  1262. if (dai_link[i].init == NULL)
  1263. dai_link[i].init = &msm_common_dai_link_init;
  1264. /* populate codec_of_node for snd card dai links */
  1265. if (dai_link[i].num_codecs > 0) {
  1266. for (j = 0; j < dai_link[i].num_codecs; j++) {
  1267. if (dai_link[i].codecs[j].of_node ||
  1268. !dai_link[i].codecs[j].name)
  1269. continue;
  1270. index = of_property_match_string(cdev->of_node,
  1271. "asoc-codec-names",
  1272. dai_link[i].codecs[j].name);
  1273. if (index < 0)
  1274. continue;
  1275. np = of_parse_phandle(cdev->of_node,
  1276. "asoc-codec",
  1277. index);
  1278. if (!np) {
  1279. dev_err_ratelimited(cdev,
  1280. "%s: retrieving phandle for codec %s failed\n",
  1281. __func__,
  1282. dai_link[i].codecs[j].name);
  1283. ret = -ENODEV;
  1284. goto err;
  1285. }
  1286. dai_link[i].codecs[j].of_node = np;
  1287. dai_link[i].codecs[j].name = NULL;
  1288. }
  1289. }
  1290. }
  1291. /* In multi-codec scenario, check if codecs are enabled for this platform */
  1292. for (i = 0; i < card->num_links; i++) {
  1293. codecs_enabled = 0;
  1294. if (dai_link[i].num_codecs > 1) {
  1295. for (j = 0; j < dai_link[i].num_codecs; j++) {
  1296. if (!dai_link[i].codecs[j].of_node)
  1297. continue;
  1298. np = dai_link[i].codecs[j].of_node;
  1299. if (!of_device_is_available(np)) {
  1300. dev_err_ratelimited(cdev, "%s: codec is disabled: %s\n",
  1301. __func__,
  1302. np->full_name);
  1303. dai_link[i].codecs[j].of_node = NULL;
  1304. continue;
  1305. }
  1306. codecs_enabled++;
  1307. }
  1308. if (codecs_enabled > 0 &&
  1309. codecs_enabled < dai_link[i].num_codecs) {
  1310. codecs_comp = devm_kzalloc(cdev,
  1311. sizeof(struct snd_soc_dai_link_component)
  1312. * codecs_enabled, GFP_KERNEL);
  1313. if (!codecs_comp) {
  1314. dev_err_ratelimited(cdev,
  1315. "%s: %s dailink codec component alloc failed\n",
  1316. __func__, dai_link[i].name);
  1317. ret = -ENOMEM;
  1318. goto err;
  1319. }
  1320. index = 0;
  1321. for (j = 0; j < dai_link[i].num_codecs; j++) {
  1322. if(dai_link[i].codecs[j].of_node) {
  1323. codecs_comp[index].of_node =
  1324. dai_link[i].codecs[j].of_node;
  1325. codecs_comp[index].dai_name =
  1326. dai_link[i].codecs[j].dai_name;
  1327. codecs_comp[index].name = NULL;
  1328. index++;
  1329. }
  1330. }
  1331. dai_link[i].codecs = codecs_comp;
  1332. dai_link[i].num_codecs = codecs_enabled;
  1333. }
  1334. }
  1335. }
  1336. err:
  1337. return ret;
  1338. }
  1339. static int msm_audrx_stub_init(struct snd_soc_pcm_runtime *rtd)
  1340. {
  1341. return 0;
  1342. }
  1343. static int msm_snd_stub_hw_params(struct snd_pcm_substream *substream,
  1344. struct snd_pcm_hw_params *params)
  1345. {
  1346. return 0;
  1347. }
  1348. static struct snd_soc_ops msm_stub_be_ops = {
  1349. .hw_params = msm_snd_stub_hw_params,
  1350. };
  1351. struct snd_soc_card snd_soc_card_stub_msm = {
  1352. .name = "pineapple-stub-snd-card",
  1353. };
  1354. static struct snd_soc_dai_link msm_stub_be_dai_links[] = {
  1355. /* Backend DAI Links */
  1356. {
  1357. .name = LPASS_BE_PRI_AUXPCM_RX,
  1358. .stream_name = LPASS_BE_PRI_AUXPCM_RX,
  1359. .playback_only = 1,
  1360. .init = &msm_audrx_stub_init,
  1361. .ignore_pmdown_time = 1,
  1362. .ignore_suspend = 1,
  1363. .ops = &msm_stub_be_ops,
  1364. SND_SOC_DAILINK_REG(auxpcm_rx),
  1365. },
  1366. {
  1367. .name = LPASS_BE_PRI_AUXPCM_TX,
  1368. .stream_name = LPASS_BE_PRI_AUXPCM_TX,
  1369. .capture_only = 1,
  1370. .ignore_suspend = 1,
  1371. .ops = &msm_stub_be_ops,
  1372. SND_SOC_DAILINK_REG(auxpcm_tx),
  1373. },
  1374. };
  1375. static struct snd_soc_dai_link msm_stub_dai_links[
  1376. ARRAY_SIZE(msm_stub_be_dai_links)];
  1377. static const struct of_device_id pineapple_asoc_machine_of_match[] = {
  1378. { .compatible = "qcom,pineapple-asoc-snd",
  1379. .data = "codec"},
  1380. { .compatible = "qcom,pineapple-asoc-snd-stub",
  1381. .data = "stub_codec"},
  1382. {},
  1383. };
  1384. static int msm_snd_card_late_probe(struct snd_soc_card *card)
  1385. {
  1386. struct snd_soc_component *component = NULL;
  1387. struct snd_soc_pcm_runtime *rtd;
  1388. struct msm_asoc_mach_data *pdata;
  1389. int ret = 0;
  1390. void *mbhc_calibration;
  1391. char wcd_name[20];
  1392. pdata = snd_soc_card_get_drvdata(card);
  1393. if (!pdata)
  1394. return -EINVAL;
  1395. if (pdata->wcd_disabled)
  1396. return 0;
  1397. rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
  1398. if (!rtd) {
  1399. dev_err(card->dev,
  1400. "%s: snd_soc_get_pcm_runtime for %s failed!\n",
  1401. __func__, card->dai_link[0]);
  1402. return -EINVAL;
  1403. }
  1404. if (pdata->wcd_used == WCD937X_DEV_INDEX)
  1405. strscpy(wcd_name, WCD937X_DRV_NAME, sizeof(WCD937X_DRV_NAME));
  1406. else
  1407. strscpy(wcd_name, WCD939X_DRV_NAME, sizeof(WCD939X_DRV_NAME));
  1408. component = snd_soc_rtdcom_lookup(rtd, wcd_name);
  1409. if (!component) {
  1410. pr_err("%s component is NULL\n", __func__);
  1411. return -EINVAL;
  1412. }
  1413. mbhc_calibration = def_wcd_mbhc_cal();
  1414. if (!mbhc_calibration)
  1415. return -ENOMEM;
  1416. wcd_mbhc_cfg.calibration = mbhc_calibration;
  1417. #if IS_ENABLED(CONFIG_QCOM_WCD_USBSS_I2C)
  1418. if (of_find_property(card->dev->of_node,
  1419. "qcom,usbss-hsj-connect-enabled", NULL))
  1420. wcd_mbhc_cfg.usbss_hsj_connect_enable = true;
  1421. #endif
  1422. switch (pdata->wcd_used) {
  1423. case WCD937X_DEV_INDEX:
  1424. ret = wcd937x_mbhc_hs_detect(component, &wcd_mbhc_cfg);
  1425. break;
  1426. case WCD939X_DEV_INDEX:
  1427. ret = wcd939x_mbhc_hs_detect(component, &wcd_mbhc_cfg);
  1428. break;
  1429. default:
  1430. return -EINVAL;
  1431. }
  1432. if (ret) {
  1433. dev_err(component->dev, "%s: mbhc hs detect failed, err:%d\n",
  1434. __func__, ret);
  1435. goto err_hs_detect;
  1436. }
  1437. return 0;
  1438. err_hs_detect:
  1439. kfree(mbhc_calibration);
  1440. return ret;
  1441. }
  1442. static struct snd_soc_card *populate_snd_card_dailinks(struct device *dev, int wsa_max_devs)
  1443. {
  1444. struct snd_soc_card *card = NULL;
  1445. struct snd_soc_dai_link *dailink = NULL;
  1446. int total_links = 0;
  1447. int rc = 0;
  1448. u32 val = 0;
  1449. const struct of_device_id *match;
  1450. match = of_match_node(pineapple_asoc_machine_of_match, dev->of_node);
  1451. if (!match) {
  1452. dev_err_ratelimited(dev, "%s: No DT match found for sound card\n",
  1453. __func__);
  1454. return NULL;
  1455. }
  1456. if (!strcmp(match->data, "codec")) {
  1457. card = &snd_soc_card_pineapple_msm;
  1458. /* late probe uses dai link at index '0' to get wcd component */
  1459. memcpy(msm_pineapple_dai_links + total_links,
  1460. msm_rx_tx_cdc_dma_be_dai_links,
  1461. sizeof(msm_rx_tx_cdc_dma_be_dai_links));
  1462. total_links +=
  1463. ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links);
  1464. switch (wsa_max_devs) {
  1465. case MONO_SPEAKER:
  1466. case STEREO_SPEAKER:
  1467. memcpy(msm_pineapple_dai_links + total_links,
  1468. msm_wsa_cdc_dma_be_dai_links,
  1469. sizeof(msm_wsa_cdc_dma_be_dai_links));
  1470. total_links += ARRAY_SIZE(msm_wsa_cdc_dma_be_dai_links);
  1471. break;
  1472. case QUAD_SPEAKER:
  1473. if (of_find_property(dev->of_node,
  1474. "qcom,dedicated-wsa2", NULL)) {
  1475. memcpy(msm_pineapple_dai_links + total_links,
  1476. msm_wsa_cdc_dma_be_dai_links,
  1477. sizeof(msm_wsa_cdc_dma_be_dai_links));
  1478. total_links += ARRAY_SIZE(msm_wsa_cdc_dma_be_dai_links);
  1479. memcpy(msm_pineapple_dai_links + total_links,
  1480. msm_wsa2_cdc_dma_be_dai_links,
  1481. sizeof(msm_wsa2_cdc_dma_be_dai_links));
  1482. total_links += ARRAY_SIZE(msm_wsa2_cdc_dma_be_dai_links);
  1483. } else {
  1484. memcpy(msm_pineapple_dai_links + total_links,
  1485. msm_wsa2_cdc_dma_be_dai_links,
  1486. sizeof(msm_wsa2_cdc_dma_be_dai_links));
  1487. total_links += ARRAY_SIZE(msm_wsa2_cdc_dma_be_dai_links);
  1488. memcpy(msm_pineapple_dai_links + total_links,
  1489. msm_wsa_wsa2_cdc_dma_be_dai_links,
  1490. sizeof(msm_wsa_wsa2_cdc_dma_be_dai_links));
  1491. total_links += ARRAY_SIZE(msm_wsa_wsa2_cdc_dma_be_dai_links);
  1492. }
  1493. break;
  1494. default:
  1495. dev_dbg(dev,
  1496. "%s: Unexpected number of WSAs, wsa_max_devs: %d\n",
  1497. __func__, wsa_max_devs);
  1498. break;
  1499. }
  1500. memcpy(msm_pineapple_dai_links + total_links,
  1501. msm_va_cdc_dma_be_dai_links,
  1502. sizeof(msm_va_cdc_dma_be_dai_links));
  1503. total_links += ARRAY_SIZE(msm_va_cdc_dma_be_dai_links);
  1504. memcpy(msm_pineapple_dai_links + total_links,
  1505. msm_common_be_dai_links,
  1506. sizeof(msm_common_be_dai_links));
  1507. total_links += ARRAY_SIZE(msm_common_be_dai_links);
  1508. rc = of_property_read_u32(dev->of_node,
  1509. "qcom,mi2s-audio-intf", &val);
  1510. if (!rc && val) {
  1511. memcpy(msm_pineapple_dai_links + total_links,
  1512. msm_mi2s_dai_links,
  1513. sizeof(msm_mi2s_dai_links));
  1514. total_links += ARRAY_SIZE(msm_mi2s_dai_links);
  1515. }
  1516. rc = of_property_read_u32(dev->of_node,
  1517. "qcom,tdm-audio-intf", &val);
  1518. if (!rc && val) {
  1519. memcpy(msm_pineapple_dai_links + total_links,
  1520. msm_tdm_dai_links,
  1521. sizeof(msm_tdm_dai_links));
  1522. total_links += ARRAY_SIZE(msm_tdm_dai_links);
  1523. }
  1524. rc = of_property_read_u32(dev->of_node,
  1525. "qcom,ext-disp-audio-rx", &val);
  1526. if (!rc && val) {
  1527. if (!socinfo_get_part_info(PART_DISPLAY)) {
  1528. dev_dbg(dev, "%s(): ext disp audio support present\n",
  1529. __func__);
  1530. memcpy(msm_pineapple_dai_links + total_links,
  1531. ext_disp_be_dai_link,
  1532. sizeof(ext_disp_be_dai_link));
  1533. total_links += ARRAY_SIZE(ext_disp_be_dai_link);
  1534. }
  1535. }
  1536. rc = of_property_read_u32(dev->of_node, "qcom,wcn-bt", &val);
  1537. if (!rc && val) {
  1538. dev_dbg(dev, "%s(): WCN BT support present\n",
  1539. __func__);
  1540. memcpy(msm_pineapple_dai_links + total_links,
  1541. msm_wcn_be_dai_links,
  1542. sizeof(msm_wcn_be_dai_links));
  1543. total_links += ARRAY_SIZE(msm_wcn_be_dai_links);
  1544. } else {
  1545. rc = of_property_read_u32(dev->of_node, "qcom,wcn-btfm", &val);
  1546. if (!rc && val) {
  1547. dev_dbg(dev, "%s(): WCN BT FM support present\n",
  1548. __func__);
  1549. memcpy(msm_pineapple_dai_links + total_links,
  1550. msm_wcn_btfm_be_dai_links,
  1551. sizeof(msm_wcn_btfm_be_dai_links));
  1552. total_links += ARRAY_SIZE(msm_wcn_btfm_be_dai_links);
  1553. }
  1554. }
  1555. dailink = msm_pineapple_dai_links;
  1556. } else if(!strcmp(match->data, "stub_codec")) {
  1557. card = &snd_soc_card_stub_msm;
  1558. memcpy(msm_stub_dai_links,
  1559. msm_stub_be_dai_links,
  1560. sizeof(msm_stub_be_dai_links));
  1561. dailink = msm_stub_dai_links;
  1562. total_links = ARRAY_SIZE(msm_stub_be_dai_links);
  1563. }
  1564. if (card) {
  1565. card->dai_link = dailink;
  1566. card->num_links = total_links;
  1567. if (!strcmp(match->data, "codec"))
  1568. card->late_probe = msm_snd_card_late_probe;
  1569. }
  1570. return card;
  1571. }
  1572. static int msm_int_wsa883x_init(struct snd_soc_pcm_runtime *rtd)
  1573. {
  1574. u8 spkleft_ports[WSA883X_MAX_SWR_PORTS] = {0, 1, 2, 3};
  1575. u8 spkright_ports[WSA883X_MAX_SWR_PORTS] = {0, 1, 2, 3};
  1576. u8 spkleft_port_types[WSA883X_MAX_SWR_PORTS] = {SPKR_L, SPKR_L_COMP,
  1577. SPKR_L_BOOST, SPKR_L_VI};
  1578. u8 spkright_port_types[WSA883X_MAX_SWR_PORTS] = {SPKR_R, SPKR_R_COMP,
  1579. SPKR_R_BOOST, SPKR_R_VI};
  1580. unsigned int ch_rate[WSA883X_MAX_SWR_PORTS] = {SWR_CLK_RATE_2P4MHZ, SWR_CLK_RATE_0P6MHZ,
  1581. SWR_CLK_RATE_0P3MHZ, SWR_CLK_RATE_1P2MHZ};
  1582. unsigned int ch_mask[WSA883X_MAX_SWR_PORTS] = {0x1, 0xF, 0x3, 0x3};
  1583. struct snd_soc_component *component = NULL;
  1584. struct msm_asoc_mach_data *pdata =
  1585. snd_soc_card_get_drvdata(rtd->card);
  1586. if (pdata->wsa_max_devs > 0) {
  1587. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.1");
  1588. if (!component) {
  1589. pr_err("%s: wsa-codec.1 component is NULL\n", __func__);
  1590. return -EINVAL;
  1591. }
  1592. wsa883x_set_channel_map(component, &spkleft_ports[0],
  1593. WSA883X_MAX_SWR_PORTS, &ch_mask[0],
  1594. &ch_rate[0], &spkleft_port_types[0]);
  1595. wsa883x_codec_info_create_codec_entry(pdata->codec_root,
  1596. component);
  1597. }
  1598. /* If current platform has more than one WSA */
  1599. if (pdata->wsa_max_devs > 1) {
  1600. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.2");
  1601. if (!component) {
  1602. pr_err("%s: wsa-codec.2 component is NULL\n", __func__);
  1603. return -EINVAL;
  1604. }
  1605. wsa883x_set_channel_map(component, &spkright_ports[0],
  1606. WSA883X_MAX_SWR_PORTS, &ch_mask[0],
  1607. &ch_rate[0], &spkright_port_types[0]);
  1608. wsa883x_codec_info_create_codec_entry(pdata->codec_root,
  1609. component);
  1610. }
  1611. if (!pdata->dedicated_wsa2) {
  1612. if (pdata->wsa_max_devs > 2) {
  1613. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.3");
  1614. if (!component) {
  1615. pr_err("%s: wsa-codec.3 component is NULL\n", __func__);
  1616. return -EINVAL;
  1617. }
  1618. wsa883x_set_channel_map(component, &spkleft_ports[0],
  1619. WSA883X_MAX_SWR_PORTS, &ch_mask[0],
  1620. &ch_rate[0], &spkleft_port_types[0]);
  1621. wsa883x_codec_info_create_codec_entry(pdata->codec_root,
  1622. component);
  1623. }
  1624. if (pdata->wsa_max_devs > 3) {
  1625. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.4");
  1626. if (!component) {
  1627. pr_err("%s: wsa-codec.4 component is NULL\n", __func__);
  1628. return -EINVAL;
  1629. }
  1630. wsa883x_set_channel_map(component, &spkright_ports[0],
  1631. WSA883X_MAX_SWR_PORTS, &ch_mask[0],
  1632. &ch_rate[0], &spkright_port_types[0]);
  1633. wsa883x_codec_info_create_codec_entry(pdata->codec_root,
  1634. component);
  1635. }
  1636. }
  1637. msm_common_dai_link_init(rtd);
  1638. return 0;
  1639. }
  1640. static int msm_int_wsa884x_init(struct snd_soc_pcm_runtime *rtd)
  1641. {
  1642. u8 spkleft_ports[WSA884X_MAX_SWR_PORTS] = {0, 1, 2, 3, 4, 5};
  1643. u8 spkright_ports[WSA884X_MAX_SWR_PORTS] = {0, 1, 2, 3, 4, 5};
  1644. u8 spkleft_port_types[WSA884X_MAX_SWR_PORTS] = {SPKR_L, SPKR_L_COMP,
  1645. SPKR_L_BOOST, PBR, SPKR_L_VI, CPS};
  1646. u8 spkright_port_types[WSA884X_MAX_SWR_PORTS] = {SPKR_R, SPKR_R_COMP,
  1647. SPKR_R_BOOST, PBR, SPKR_R_VI, CPS};
  1648. unsigned int ch_rate[WSA884X_MAX_SWR_PORTS] = {SWR_CLK_RATE_2P4MHZ, SWR_CLK_RATE_0P6MHZ,
  1649. SWR_CLK_RATE_0P3MHZ, SWR_CLK_RATE_48KHZ,
  1650. SWR_CLK_RATE_1P2MHZ, SWR_CLK_RATE_24KHZ};
  1651. unsigned int ch_mask[WSA884X_MAX_SWR_PORTS] = {0x1, 0xF, 0x3, 0x1, 0x3, 0x3};
  1652. struct snd_soc_component *component = NULL;
  1653. struct msm_asoc_mach_data *pdata =
  1654. snd_soc_card_get_drvdata(rtd->card);
  1655. if (pdata->wsa_max_devs > 0) {
  1656. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.1");
  1657. if (!component) {
  1658. pr_err("%s: wsa-codec.1 component is NULL\n", __func__);
  1659. return -EINVAL;
  1660. }
  1661. wsa884x_set_channel_map(component, &spkleft_ports[0],
  1662. WSA884X_MAX_SWR_PORTS, &ch_mask[0],
  1663. &ch_rate[0], &spkleft_port_types[0]);
  1664. wsa884x_codec_info_create_codec_entry(pdata->codec_root,
  1665. component);
  1666. }
  1667. /* If current platform has more than one WSA */
  1668. if (pdata->wsa_max_devs > 1) {
  1669. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.2");
  1670. if (!component) {
  1671. pr_err("%s: wsa-codec.2 component is NULL\n", __func__);
  1672. return -EINVAL;
  1673. }
  1674. wsa884x_set_channel_map(component, &spkright_ports[0],
  1675. WSA884X_MAX_SWR_PORTS, &ch_mask[0],
  1676. &ch_rate[0], &spkright_port_types[0]);
  1677. wsa884x_codec_info_create_codec_entry(pdata->codec_root,
  1678. component);
  1679. }
  1680. if (!pdata->dedicated_wsa2) {
  1681. if (pdata->wsa_max_devs > 2) {
  1682. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.3");
  1683. if (!component) {
  1684. pr_err("%s: wsa-codec.3 component is NULL\n", __func__);
  1685. return -EINVAL;
  1686. }
  1687. wsa884x_set_channel_map(component, &spkleft_ports[0],
  1688. WSA884X_MAX_SWR_PORTS, &ch_mask[0],
  1689. &ch_rate[0], &spkleft_port_types[0]);
  1690. wsa884x_codec_info_create_codec_entry(pdata->codec_root,
  1691. component);
  1692. }
  1693. if (pdata->wsa_max_devs > 3) {
  1694. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.4");
  1695. if (!component) {
  1696. pr_err("%s: wsa-codec.4 component is NULL\n", __func__);
  1697. return -EINVAL;
  1698. }
  1699. wsa884x_set_channel_map(component, &spkright_ports[0],
  1700. WSA884X_MAX_SWR_PORTS, &ch_mask[0],
  1701. &ch_rate[0], &spkright_port_types[0]);
  1702. wsa884x_codec_info_create_codec_entry(pdata->codec_root,
  1703. component);
  1704. }
  1705. }
  1706. msm_common_dai_link_init(rtd);
  1707. return 0;
  1708. }
  1709. static int msm_int_wsa_init(struct snd_soc_pcm_runtime *rtd)
  1710. {
  1711. if (strstr(rtd->card->name, "wsa883x"))
  1712. return msm_int_wsa883x_init(rtd);
  1713. return msm_int_wsa884x_init(rtd);
  1714. }
  1715. static int msm_int_wsa883x_2_init(struct snd_soc_pcm_runtime *rtd)
  1716. {
  1717. u8 spkleft_ports[WSA883X_MAX_SWR_PORTS] = {0, 1, 2, 3};
  1718. u8 spkright_ports[WSA883X_MAX_SWR_PORTS] = {0, 1, 2, 3};
  1719. u8 spkleft_port_types[WSA883X_MAX_SWR_PORTS] = {SPKR_L, SPKR_L_COMP,
  1720. SPKR_L_BOOST, SPKR_L_VI};
  1721. u8 spkright_port_types[WSA883X_MAX_SWR_PORTS] = {SPKR_R, SPKR_R_COMP,
  1722. SPKR_R_BOOST, SPKR_R_VI};
  1723. unsigned int ch_rate[WSA883X_MAX_SWR_PORTS] = {SWR_CLK_RATE_2P4MHZ, SWR_CLK_RATE_0P6MHZ,
  1724. SWR_CLK_RATE_0P3MHZ, SWR_CLK_RATE_1P2MHZ};
  1725. unsigned int ch_mask[WSA883X_MAX_SWR_PORTS] = {0x1, 0xF, 0x3, 0x3};
  1726. struct snd_soc_component *component = NULL;
  1727. struct msm_asoc_mach_data *pdata =
  1728. snd_soc_card_get_drvdata(rtd->card);
  1729. if (pdata->dedicated_wsa2) {
  1730. if (pdata->wsa_max_devs > 2) {
  1731. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.3");
  1732. if (!component) {
  1733. pr_err("%s: wsa-codec.3 component is NULL\n", __func__);
  1734. return -EINVAL;
  1735. }
  1736. wsa883x_set_channel_map(component, &spkleft_ports[0],
  1737. WSA883X_MAX_SWR_PORTS, &ch_mask[0],
  1738. &ch_rate[0], &spkleft_port_types[0]);
  1739. wsa883x_codec_info_create_codec_entry(pdata->codec_root,
  1740. component);
  1741. }
  1742. if (pdata->wsa_max_devs > 3) {
  1743. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.4");
  1744. if (!component) {
  1745. pr_err("%s: wsa-codec.4 component is NULL\n", __func__);
  1746. return -EINVAL;
  1747. }
  1748. wsa883x_set_channel_map(component, &spkright_ports[0],
  1749. WSA883X_MAX_SWR_PORTS, &ch_mask[0],
  1750. &ch_rate[0], &spkright_port_types[0]);
  1751. wsa883x_codec_info_create_codec_entry(pdata->codec_root,
  1752. component);
  1753. }
  1754. msm_common_dai_link_init(rtd);
  1755. }
  1756. return 0;
  1757. }
  1758. static int msm_int_wsa884x_2_init(struct snd_soc_pcm_runtime *rtd)
  1759. {
  1760. u8 spkleft_ports[WSA884X_MAX_SWR_PORTS] = {0, 1, 2, 3, 4, 5};
  1761. u8 spkright_ports[WSA884X_MAX_SWR_PORTS] = {0, 1, 2, 3, 4, 5};
  1762. u8 spkleft_port_types[WSA884X_MAX_SWR_PORTS] = {SPKR_L, SPKR_L_COMP,
  1763. SPKR_L_BOOST, PBR, SPKR_L_VI, CPS};
  1764. u8 spkright_port_types[WSA884X_MAX_SWR_PORTS] = {SPKR_R, SPKR_R_COMP,
  1765. SPKR_R_BOOST, PBR, SPKR_R_VI, CPS};
  1766. unsigned int ch_rate[WSA884X_MAX_SWR_PORTS] = {SWR_CLK_RATE_2P4MHZ, SWR_CLK_RATE_0P6MHZ,
  1767. SWR_CLK_RATE_0P3MHZ, SWR_CLK_RATE_48KHZ,
  1768. SWR_CLK_RATE_1P2MHZ, SWR_CLK_RATE_24KHZ};
  1769. unsigned int ch_mask[WSA884X_MAX_SWR_PORTS] = {0x1, 0xF, 0x3, 0x1, 0x3, 0x3};
  1770. struct snd_soc_component *component = NULL;
  1771. struct msm_asoc_mach_data *pdata =
  1772. snd_soc_card_get_drvdata(rtd->card);
  1773. if (pdata->dedicated_wsa2) {
  1774. if (pdata->wsa_max_devs > 2) {
  1775. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.3");
  1776. if (!component) {
  1777. pr_err("%s: wsa-codec.3 component is NULL\n", __func__);
  1778. return -EINVAL;
  1779. }
  1780. wsa884x_set_channel_map(component, &spkleft_ports[0],
  1781. WSA884X_MAX_SWR_PORTS, &ch_mask[0],
  1782. &ch_rate[0], &spkleft_port_types[0]);
  1783. wsa884x_codec_info_create_codec_entry(pdata->codec_root,
  1784. component);
  1785. }
  1786. if (pdata->wsa_max_devs > 3) {
  1787. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.4");
  1788. if (!component) {
  1789. pr_err("%s: wsa-codec.4 component is NULL\n", __func__);
  1790. return -EINVAL;
  1791. }
  1792. wsa884x_set_channel_map(component, &spkright_ports[0],
  1793. WSA884X_MAX_SWR_PORTS, &ch_mask[0],
  1794. &ch_rate[0], &spkright_port_types[0]);
  1795. wsa884x_codec_info_create_codec_entry(pdata->codec_root,
  1796. component);
  1797. }
  1798. msm_common_dai_link_init(rtd);
  1799. }
  1800. return 0;
  1801. }
  1802. static int msm_int_wsa2_init(struct snd_soc_pcm_runtime *rtd)
  1803. {
  1804. if (strstr(rtd->card->name, "wsa883x"))
  1805. return msm_int_wsa883x_2_init(rtd);
  1806. return msm_int_wsa884x_2_init(rtd);
  1807. }
  1808. static int msm_rx_tx_codec_init(struct snd_soc_pcm_runtime *rtd)
  1809. {
  1810. int codec_variant = -1;
  1811. struct snd_soc_component *component = NULL;
  1812. struct snd_soc_component *lpass_cdc_component = NULL;
  1813. struct snd_soc_dapm_context *dapm = NULL;
  1814. struct snd_info_entry *entry = NULL;
  1815. struct snd_card *card = NULL;
  1816. struct msm_asoc_mach_data *pdata =
  1817. snd_soc_card_get_drvdata(rtd->card);
  1818. int ret = 0;
  1819. lpass_cdc_component = snd_soc_rtdcom_lookup(rtd, "lpass-cdc");
  1820. if (!lpass_cdc_component) {
  1821. pr_err("%s: could not find component for lpass-cdc\n",
  1822. __func__);
  1823. return ret;
  1824. }
  1825. dapm = snd_soc_component_get_dapm(lpass_cdc_component);
  1826. snd_soc_dapm_new_controls(dapm, msm_int_dapm_widgets,
  1827. ARRAY_SIZE(msm_int_dapm_widgets));
  1828. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic0");
  1829. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic1");
  1830. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic2");
  1831. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic3");
  1832. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic4");
  1833. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic5");
  1834. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic6");
  1835. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic7");
  1836. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic1");
  1837. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic2");
  1838. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic3");
  1839. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic4");
  1840. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic5");
  1841. lpass_cdc_set_port_map(lpass_cdc_component, ARRAY_SIZE(sm_port_map), sm_port_map);
  1842. card = rtd->card->snd_card;
  1843. if (!pdata->codec_root) {
  1844. entry = msm_snd_info_create_subdir(card->module, "codecs",
  1845. card->proc_root);
  1846. if (!entry) {
  1847. pr_debug("%s: Cannot create codecs module entry\n",
  1848. __func__);
  1849. return ret;
  1850. }
  1851. pdata->codec_root = entry;
  1852. }
  1853. lpass_cdc_info_create_codec_entry(pdata->codec_root, lpass_cdc_component);
  1854. lpass_cdc_register_wake_irq(lpass_cdc_component, false);
  1855. if (pdata->wcd_disabled)
  1856. goto done;
  1857. component = snd_soc_rtdcom_lookup(rtd, WCD939X_DRV_NAME);
  1858. if (!component) {
  1859. component = snd_soc_rtdcom_lookup(rtd, WCD937X_DRV_NAME);
  1860. if (!component) {
  1861. pr_err("%s component is NULL\n", __func__);
  1862. ret = -EINVAL;
  1863. goto exit;
  1864. }
  1865. pdata->wcd_used = WCD937X_DEV_INDEX;
  1866. } else {
  1867. pdata->wcd_used = WCD939X_DEV_INDEX;
  1868. }
  1869. dapm = snd_soc_component_get_dapm(component);
  1870. card = component->card->snd_card;
  1871. snd_soc_dapm_ignore_suspend(dapm, "EAR");
  1872. if (pdata->wcd_used != WCD939X_DEV_INDEX)
  1873. snd_soc_dapm_ignore_suspend(dapm, "AUX");
  1874. snd_soc_dapm_ignore_suspend(dapm, "HPHL");
  1875. snd_soc_dapm_ignore_suspend(dapm, "HPHR");
  1876. snd_soc_dapm_ignore_suspend(dapm, "AMIC1");
  1877. snd_soc_dapm_ignore_suspend(dapm, "AMIC2");
  1878. snd_soc_dapm_ignore_suspend(dapm, "AMIC3");
  1879. snd_soc_dapm_ignore_suspend(dapm, "AMIC4");
  1880. snd_soc_dapm_sync(dapm);
  1881. pdata = snd_soc_card_get_drvdata(component->card);
  1882. if (!pdata->codec_root) {
  1883. entry = msm_snd_info_create_subdir(card->module, "codecs",
  1884. card->proc_root);
  1885. if (!entry) {
  1886. dev_dbg(component->dev, "%s: Cannot create codecs module entry\n",
  1887. __func__);
  1888. return 0;
  1889. }
  1890. pdata->codec_root = entry;
  1891. }
  1892. if (pdata->wcd_used == WCD937X_DEV_INDEX) {
  1893. wcd937x_info_create_codec_entry(pdata->codec_root, component);
  1894. codec_variant = wcd937x_get_codec_variant(component);
  1895. dev_dbg(component->dev, "%s: variant %d\n", __func__, codec_variant);
  1896. } else {
  1897. wcd939x_info_create_codec_entry(pdata->codec_root, component);
  1898. codec_variant = wcd939x_get_codec_variant(component);
  1899. dev_dbg(component->dev, "%s: variant %d\n", __func__, codec_variant);
  1900. if (codec_variant == WCD9395)
  1901. ret = lpass_cdc_rx_set_fir_capability(lpass_cdc_component, true);
  1902. else
  1903. ret = lpass_cdc_rx_set_fir_capability(lpass_cdc_component, false);
  1904. }
  1905. if (ret < 0) {
  1906. dev_err_ratelimited(component->dev, "%s: set fir capability failed: %d\n",
  1907. __func__, ret);
  1908. return ret;
  1909. }
  1910. done:
  1911. codec_reg_done = true;
  1912. msm_common_dai_link_init(rtd);
  1913. exit:
  1914. return ret;
  1915. }
  1916. static int pineapple_ssr_enable(struct device *dev, void *data)
  1917. {
  1918. struct platform_device *pdev = to_platform_device(dev);
  1919. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1920. struct snd_soc_pcm_runtime *rtd = NULL, *rtd_wcd = NULL, *rtd_wsa = NULL;
  1921. struct msm_asoc_mach_data *pdata = NULL;
  1922. int ret = 0;
  1923. if (!card) {
  1924. dev_err_ratelimited(dev, "%s: card is NULL\n", __func__);
  1925. ret = -EINVAL;
  1926. goto err;
  1927. }
  1928. if (!strcmp(card->name, "pineapple-stub-snd-card")) {
  1929. /* TODO */
  1930. dev_dbg(dev, "%s: TODO \n", __func__);
  1931. }
  1932. snd_card_notify_user(SND_CARD_STATUS_ONLINE);
  1933. dev_dbg(dev, "%s: setting snd_card to ONLINE\n", __func__);
  1934. pdata = snd_soc_card_get_drvdata(card);
  1935. if (!pdata) {
  1936. dev_dbg(dev, "%s: pdata is NULL \n", __func__);
  1937. goto err;
  1938. }
  1939. rtd_wcd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
  1940. if (!rtd_wcd) {
  1941. dev_dbg(dev,
  1942. "%s: snd_soc_get_pcm_runtime for %s failed!\n",
  1943. __func__, card->dai_link[0]);
  1944. }
  1945. if (pdata->wsa_max_devs > 0) {
  1946. rtd_wsa = snd_soc_get_pcm_runtime(card,
  1947. &card->dai_link[ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links)]);
  1948. if (!rtd_wsa) {
  1949. dev_dbg(dev,
  1950. "%s: snd_soc_get_pcm_runtime for %s failed!\n",
  1951. __func__, card->dai_link[ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links)]);
  1952. }
  1953. }
  1954. /* set UPD configuration */
  1955. if(!pdata->upd_config.backend_used) {
  1956. dev_dbg(dev,
  1957. "%s: upd- backend_used is NULL\n", __func__);
  1958. goto err;
  1959. }
  1960. if (!strcmp(pdata->upd_config.backend_used, "wsa")) {
  1961. if (!rtd_wsa)
  1962. goto err;
  1963. else
  1964. rtd = rtd_wsa;
  1965. } else if(!strcmp(pdata->upd_config.backend_used, "wcd")) {
  1966. if (!rtd_wcd &&!pdata->wcd_disabled)
  1967. goto err;
  1968. else
  1969. rtd = rtd_wcd;
  1970. } else {
  1971. dev_err_ratelimited(card->dev, "%s: Invalid backend to set UPD config\n",
  1972. __func__);
  1973. goto err;
  1974. }
  1975. msm_set_upd_config(rtd);
  1976. err:
  1977. return ret;
  1978. }
  1979. static void pineapple_ssr_disable(struct device *dev, void *data)
  1980. {
  1981. struct platform_device *pdev = to_platform_device(dev);
  1982. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1983. if (!card) {
  1984. dev_err_ratelimited(dev, "%s: card is NULL\n", __func__);
  1985. return;
  1986. }
  1987. dev_dbg(dev, "%s: setting snd_card to OFFLINE\n", __func__);
  1988. snd_card_notify_user(SND_CARD_STATUS_OFFLINE);
  1989. if (!strcmp(card->name, "pineapple-stub-snd-card")) {
  1990. /* TODO */
  1991. dev_dbg(dev, "%s: TODO \n", __func__);
  1992. }
  1993. }
  1994. static const struct snd_event_ops pineapple_ssr_ops = {
  1995. .enable = pineapple_ssr_enable,
  1996. .disable = pineapple_ssr_disable,
  1997. };
  1998. static int msm_audio_ssr_compare(struct device *dev, void *data)
  1999. {
  2000. struct device_node *node = data;
  2001. dev_dbg(dev, "%s: dev->of_node = 0x%p, node = 0x%p\n",
  2002. __func__, dev->of_node, node);
  2003. return (dev->of_node && dev->of_node == node);
  2004. }
  2005. static int msm_audio_ssr_register(struct device *dev)
  2006. {
  2007. struct device_node *np = dev->of_node;
  2008. struct snd_event_clients *ssr_clients = NULL;
  2009. struct device_node *node = NULL;
  2010. int ret = 0;
  2011. int i = 0;
  2012. for (i = 0; ; i++) {
  2013. node = of_parse_phandle(np, "qcom,msm_audio_ssr_devs", i);
  2014. if (!node)
  2015. break;
  2016. snd_event_mstr_add_client(&ssr_clients,
  2017. msm_audio_ssr_compare, node);
  2018. }
  2019. ret = snd_event_master_register(dev, &pineapple_ssr_ops,
  2020. ssr_clients, NULL);
  2021. if (!ret)
  2022. snd_event_notify(dev, SND_EVENT_UP);
  2023. return ret;
  2024. }
  2025. struct msm_common_pdata *msm_common_get_pdata(struct snd_soc_card *card)
  2026. {
  2027. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  2028. if (!pdata)
  2029. return NULL;
  2030. return pdata->common_pdata;
  2031. }
  2032. void msm_common_set_pdata(struct snd_soc_card *card,
  2033. struct msm_common_pdata *common_pdata)
  2034. {
  2035. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  2036. if (!pdata)
  2037. return;
  2038. pdata->common_pdata = common_pdata;
  2039. }
  2040. static int msm_asoc_machine_probe(struct platform_device *pdev)
  2041. {
  2042. struct snd_soc_card *card = NULL;
  2043. struct msm_asoc_mach_data *pdata = NULL;
  2044. int ret = 0;
  2045. struct clk *lpass_audio_hw_vote = NULL;
  2046. const struct of_device_id *match;
  2047. if (!pdev->dev.of_node) {
  2048. dev_err(&pdev->dev, "%s: No platform supplied from device tree\n", __func__);
  2049. return -EINVAL;
  2050. }
  2051. pdata = devm_kzalloc(&pdev->dev,
  2052. sizeof(struct msm_asoc_mach_data), GFP_KERNEL);
  2053. if (!pdata)
  2054. return -ENOMEM;
  2055. of_property_read_u32(pdev->dev.of_node,
  2056. "qcom,wcd-disabled",
  2057. &pdata->wcd_disabled);
  2058. /* Get maximum WSA device count for this platform */
  2059. ret = of_property_read_u32(pdev->dev.of_node,
  2060. "qcom,wsa-max-devs", &pdata->wsa_max_devs);
  2061. if (ret) {
  2062. dev_info(&pdev->dev,
  2063. "%s: wsa-max-devs property missing in DT %s, ret = %d\n",
  2064. __func__, pdev->dev.of_node->full_name, ret);
  2065. pdata->wsa_max_devs = 0;
  2066. }
  2067. /* Check if WSA2 Backends were used for dedicated usecase */
  2068. pdata->dedicated_wsa2 = of_find_property(pdev->dev.of_node,
  2069. "qcom,dedicated-wsa2", NULL);
  2070. card = populate_snd_card_dailinks(&pdev->dev, pdata->wsa_max_devs);
  2071. if (!card) {
  2072. dev_err(&pdev->dev, "%s: Card uninitialized\n", __func__);
  2073. ret = -EINVAL;
  2074. goto err;
  2075. }
  2076. match = of_match_node(pineapple_asoc_machine_of_match, pdev->dev.of_node);
  2077. if (!match) {
  2078. dev_err(&pdev->dev, "%s: No DT match found for sound card\n",
  2079. __func__);
  2080. ret = -EINVAL;
  2081. goto err;
  2082. }
  2083. card->dev = &pdev->dev;
  2084. platform_set_drvdata(pdev, card);
  2085. snd_soc_card_set_drvdata(card, pdata);
  2086. ret = snd_soc_of_parse_card_name(card, "qcom,model");
  2087. if (ret) {
  2088. dev_err(&pdev->dev, "%s: parse card name failed, err:%d\n",
  2089. __func__, ret);
  2090. goto err;
  2091. }
  2092. if(!strcmp(match->data, "codec")) {
  2093. ret = snd_soc_of_parse_audio_routing(card, "qcom,audio-routing");
  2094. if (ret) {
  2095. dev_err(&pdev->dev, "%s: parse audio routing failed, err:%d\n",
  2096. __func__, ret);
  2097. goto err;
  2098. }
  2099. }
  2100. ret = msm_populate_dai_link_component_of_node(card);
  2101. if (ret) {
  2102. ret = -EPROBE_DEFER;
  2103. goto err;
  2104. }
  2105. /* parse upd configuration */
  2106. msm_parse_upd_configuration(pdev, pdata);
  2107. ret = devm_snd_soc_register_card(&pdev->dev, card);
  2108. if (ret == -EPROBE_DEFER) {
  2109. if (codec_reg_done)
  2110. ret = -EINVAL;
  2111. goto err;
  2112. } else if (ret) {
  2113. dev_err(&pdev->dev, "%s: snd_soc_register_card failed (%d)\n",
  2114. __func__, ret);
  2115. goto err;
  2116. }
  2117. dev_info(&pdev->dev, "%s: Sound card %s registered\n",
  2118. __func__, card->name);
  2119. if (wcd_mbhc_cfg.enable_usbc_analog)
  2120. wcd_mbhc_cfg.swap_gnd_mic = msm_usbc_swap_gnd_mic;
  2121. pdata->wcd_usbss_handle = of_parse_phandle(pdev->dev.of_node,
  2122. "wcd939x-i2c-handle", 0);
  2123. if (!pdata->wcd_usbss_handle)
  2124. dev_dbg(&pdev->dev, "property %s not detected in node %s\n",
  2125. "wcd939x-i2c-handle", pdev->dev.of_node->full_name);
  2126. pdata->dmic01_gpio_p = of_parse_phandle(pdev->dev.of_node,
  2127. "qcom,cdc-dmic01-gpios",
  2128. 0);
  2129. pdata->dmic23_gpio_p = of_parse_phandle(pdev->dev.of_node,
  2130. "qcom,cdc-dmic23-gpios",
  2131. 0);
  2132. pdata->dmic45_gpio_p = of_parse_phandle(pdev->dev.of_node,
  2133. "qcom,cdc-dmic45-gpios",
  2134. 0);
  2135. pdata->dmic67_gpio_p = of_parse_phandle(pdev->dev.of_node,
  2136. "qcom,cdc-dmic67-gpios",
  2137. 0);
  2138. if (pdata->dmic01_gpio_p)
  2139. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic01_gpio_p, false);
  2140. if (pdata->dmic23_gpio_p)
  2141. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic23_gpio_p, false);
  2142. if (pdata->dmic45_gpio_p)
  2143. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic45_gpio_p, false);
  2144. if (pdata->dmic67_gpio_p)
  2145. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic67_gpio_p, false);
  2146. msm_common_snd_init(pdev, card);
  2147. /* Register LPASS audio hw vote */
  2148. lpass_audio_hw_vote = devm_clk_get(&pdev->dev, "lpass_audio_hw_vote");
  2149. if (IS_ERR(lpass_audio_hw_vote)) {
  2150. ret = PTR_ERR(lpass_audio_hw_vote);
  2151. dev_dbg(&pdev->dev, "%s: clk get %s failed %d\n",
  2152. __func__, "lpass_audio_hw_vote", ret);
  2153. lpass_audio_hw_vote = NULL;
  2154. ret = 0;
  2155. }
  2156. pdata->lpass_audio_hw_vote = lpass_audio_hw_vote;
  2157. pdata->core_audio_vote_count = 0;
  2158. ret = msm_audio_ssr_register(&pdev->dev);
  2159. if (ret)
  2160. pr_err("%s: Registration with SND event FWK failed ret = %d\n",
  2161. __func__, ret);
  2162. is_initial_boot = true;
  2163. /* change card status to ONLINE */
  2164. dev_dbg(&pdev->dev, "%s: setting snd_card to ONLINE\n", __func__);
  2165. snd_card_set_card_status(SND_CARD_STATUS_ONLINE);
  2166. return 0;
  2167. err:
  2168. devm_kfree(&pdev->dev, pdata);
  2169. return ret;
  2170. }
  2171. static int msm_asoc_machine_remove(struct platform_device *pdev)
  2172. {
  2173. struct snd_soc_card *card = platform_get_drvdata(pdev);
  2174. struct msm_asoc_mach_data *pdata = NULL;
  2175. struct msm_common_pdata *common_pdata = NULL;
  2176. if (card)
  2177. pdata = snd_soc_card_get_drvdata(card);
  2178. if (pdata)
  2179. common_pdata = pdata->common_pdata;
  2180. msm_common_snd_deinit(common_pdata);
  2181. snd_event_master_deregister(&pdev->dev);
  2182. snd_soc_unregister_card(card);
  2183. return 0;
  2184. }
  2185. static struct platform_driver pineapple_asoc_machine_driver = {
  2186. .driver = {
  2187. .name = DRV_NAME,
  2188. .owner = THIS_MODULE,
  2189. .pm = &snd_soc_pm_ops,
  2190. .of_match_table = pineapple_asoc_machine_of_match,
  2191. .suppress_bind_attrs = true,
  2192. },
  2193. .probe = msm_asoc_machine_probe,
  2194. .remove = msm_asoc_machine_remove,
  2195. };
  2196. static int __init msm_asoc_machine_init(void)
  2197. {
  2198. snd_card_sysfs_init();
  2199. return platform_driver_register(&pineapple_asoc_machine_driver);
  2200. }
  2201. module_init(msm_asoc_machine_init);
  2202. static void __exit msm_asoc_machine_exit(void)
  2203. {
  2204. platform_driver_unregister(&pineapple_asoc_machine_driver);
  2205. }
  2206. module_exit(msm_asoc_machine_exit);
  2207. #ifndef CONFIG_AUDIO_BTFM_PROXY
  2208. MODULE_SOFTDEP("pre: bt_fm_slim");
  2209. #else
  2210. MODULE_SOFTDEP("pre: btfmcodec");
  2211. #endif
  2212. MODULE_DESCRIPTION("ALSA SoC msm");
  2213. MODULE_LICENSE("GPL v2");
  2214. MODULE_ALIAS("platform:" DRV_NAME);
  2215. MODULE_DEVICE_TABLE(of, pineapple_asoc_machine_of_match);