pineapple.c 64 KB

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