pineapple.c 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360
  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. {
  428. .name = LPASS_BE_RT_PROXY_PCM_TX_2,
  429. .stream_name = LPASS_BE_RT_PROXY_PCM_TX_2,
  430. .capture_only = 1,
  431. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  432. SND_SOC_DPCM_TRIGGER_POST},
  433. .ignore_suspend = 1,
  434. .ops = &msm_common_be_ops,
  435. SND_SOC_DAILINK_REG(proxy_tx2),
  436. },
  437. /* Proxy Rx BACK END DAI Link */
  438. {
  439. .name = LPASS_BE_RT_PROXY_PCM_RX,
  440. .stream_name = LPASS_BE_RT_PROXY_PCM_RX,
  441. .playback_only = 1,
  442. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  443. SND_SOC_DPCM_TRIGGER_POST},
  444. .ignore_pmdown_time = 1,
  445. .ignore_suspend = 1,
  446. .ops = &msm_common_be_ops,
  447. SND_SOC_DAILINK_REG(proxy_rx),
  448. },
  449. {
  450. .name = LPASS_BE_RT_PROXY_PCM_RX_2,
  451. .stream_name = LPASS_BE_RT_PROXY_PCM_RX_2,
  452. .playback_only = 1,
  453. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  454. SND_SOC_DPCM_TRIGGER_POST},
  455. .ignore_pmdown_time = 1,
  456. .ignore_suspend = 1,
  457. .ops = &msm_common_be_ops,
  458. SND_SOC_DAILINK_REG(proxy_rx2),
  459. },
  460. {
  461. .name = LPASS_BE_USB_AUDIO_RX,
  462. .stream_name = LPASS_BE_USB_AUDIO_RX,
  463. .playback_only = 1,
  464. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  465. SND_SOC_DPCM_TRIGGER_POST},
  466. .ignore_pmdown_time = 1,
  467. .ignore_suspend = 1,
  468. .ops = &msm_common_be_ops,
  469. SND_SOC_DAILINK_REG(usb_audio_rx),
  470. },
  471. {
  472. .name = LPASS_BE_USB_AUDIO_TX,
  473. .stream_name = LPASS_BE_USB_AUDIO_TX,
  474. .capture_only = 1,
  475. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  476. SND_SOC_DPCM_TRIGGER_POST},
  477. .ignore_suspend = 1,
  478. .ops = &msm_common_be_ops,
  479. SND_SOC_DAILINK_REG(usb_audio_tx),
  480. },
  481. {
  482. .name = LPASS_BE_PCM_DUMMY_TX_0,
  483. .stream_name = LPASS_BE_PCM_DUMMY_TX_0,
  484. .capture_only = 1,
  485. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  486. SND_SOC_DPCM_TRIGGER_POST},
  487. .ignore_suspend = 1,
  488. .ops = &msm_common_be_ops,
  489. SND_SOC_DAILINK_REG(pcm_dummy_tx0),
  490. },
  491. /* Dummy Dev Rx BACK END DAI Link */
  492. {
  493. .name = LPASS_BE_PCM_DUMMY_RX_0,
  494. .stream_name = LPASS_BE_PCM_DUMMY_RX_0,
  495. .playback_only = 1,
  496. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  497. SND_SOC_DPCM_TRIGGER_POST},
  498. .ignore_pmdown_time = 1,
  499. .ignore_suspend = 1,
  500. .ops = &msm_common_be_ops,
  501. SND_SOC_DAILINK_REG(pcm_dummy_rx0),
  502. },
  503. /* Dummy Dev Tx BACK END DAI Link */
  504. {
  505. .name = LPASS_BE_PCM_DUMMY_TX_1,
  506. .stream_name = LPASS_BE_PCM_DUMMY_TX_1,
  507. .capture_only = 1,
  508. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  509. SND_SOC_DPCM_TRIGGER_POST},
  510. .ignore_suspend = 1,
  511. .ops = &msm_common_be_ops,
  512. SND_SOC_DAILINK_REG(pcm_dummy_tx1),
  513. },
  514. };
  515. #ifndef CONFIG_AUDIO_BTFM_PROXY
  516. static struct snd_soc_dai_link msm_wcn_be_dai_links[] = {
  517. {
  518. .name = LPASS_BE_SLIMBUS_7_RX,
  519. .stream_name = LPASS_BE_SLIMBUS_7_RX,
  520. .playback_only = 1,
  521. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  522. SND_SOC_DPCM_TRIGGER_POST},
  523. .init = &msm_wcn_init,
  524. .ops = &msm_common_be_ops,
  525. /* dai link has playback support */
  526. .ignore_pmdown_time = 1,
  527. .ignore_suspend = 1,
  528. SND_SOC_DAILINK_REG(slimbus_7_rx),
  529. },
  530. {
  531. .name = LPASS_BE_SLIMBUS_7_TX,
  532. .stream_name = LPASS_BE_SLIMBUS_7_TX,
  533. .capture_only = 1,
  534. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  535. SND_SOC_DPCM_TRIGGER_POST},
  536. .ops = &msm_common_be_ops,
  537. .ignore_suspend = 1,
  538. SND_SOC_DAILINK_REG(slimbus_7_tx),
  539. },
  540. };
  541. #else
  542. static struct snd_soc_dai_link msm_wcn_be_dai_links[] = {
  543. {
  544. .name = LPASS_BE_BTFM_PROXY_RX_0,
  545. .stream_name = LPASS_BE_BTFM_PROXY_RX_0,
  546. .playback_only = 1,
  547. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  548. SND_SOC_DPCM_TRIGGER_POST},
  549. .ops = &msm_common_be_ops,
  550. /* dai link has playback support */
  551. .ignore_pmdown_time = 1,
  552. .ignore_suspend = 1,
  553. SND_SOC_DAILINK_REG(btfm_0_rx),
  554. },
  555. {
  556. .name = LPASS_BE_BTFM_PROXY_TX_0,
  557. .stream_name = LPASS_BE_BTFM_PROXY_TX_0,
  558. .capture_only = 1,
  559. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  560. SND_SOC_DPCM_TRIGGER_POST},
  561. .ops = &msm_common_be_ops,
  562. .ignore_suspend = 1,
  563. SND_SOC_DAILINK_REG(btfm_0_tx),
  564. },
  565. };
  566. #endif
  567. static struct snd_soc_dai_link ext_disp_be_dai_link[] = {
  568. /* DISP PORT BACK END DAI Link */
  569. {
  570. .name = LPASS_BE_DISPLAY_PORT_RX,
  571. .stream_name = LPASS_BE_DISPLAY_PORT_RX,
  572. .playback_only = 1,
  573. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  574. SND_SOC_DPCM_TRIGGER_POST},
  575. .ignore_pmdown_time = 1,
  576. .ignore_suspend = 1,
  577. SND_SOC_DAILINK_REG(display_port),
  578. },
  579. };
  580. static struct snd_soc_dai_link msm_wsa_cdc_dma_be_dai_links[] = {
  581. /* WSA CDC DMA Backend DAI Links */
  582. {
  583. .name = LPASS_BE_WSA_CDC_DMA_RX_0,
  584. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_0,
  585. .playback_only = 1,
  586. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  587. SND_SOC_DPCM_TRIGGER_POST},
  588. .ignore_pmdown_time = 1,
  589. .ignore_suspend = 1,
  590. .ops = &msm_common_be_ops,
  591. SND_SOC_DAILINK_REG(wsa_dma_rx0),
  592. .init = &msm_int_wsa_init,
  593. },
  594. {
  595. .name = LPASS_BE_WSA_CDC_DMA_RX_1,
  596. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_1,
  597. .playback_only = 1,
  598. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  599. SND_SOC_DPCM_TRIGGER_POST},
  600. .ignore_pmdown_time = 1,
  601. .ignore_suspend = 1,
  602. .ops = &msm_common_be_ops,
  603. SND_SOC_DAILINK_REG(wsa_dma_rx1),
  604. },
  605. {
  606. .name = LPASS_BE_WSA_CDC_DMA_TX_1,
  607. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_1,
  608. .capture_only = 1,
  609. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  610. SND_SOC_DPCM_TRIGGER_POST},
  611. .ignore_suspend = 1,
  612. .ops = &msm_common_be_ops,
  613. SND_SOC_DAILINK_REG(wsa_dma_tx1),
  614. },
  615. {
  616. .name = LPASS_BE_WSA_CDC_DMA_TX_0,
  617. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_0,
  618. .capture_only = 1,
  619. .ignore_suspend = 1,
  620. .ops = &msm_common_be_ops,
  621. /* .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, */
  622. SND_SOC_DAILINK_REG(vi_feedback),
  623. },
  624. {
  625. .name = LPASS_BE_WSA_CDC_DMA_TX_2,
  626. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_2,
  627. .capture_only = 1,
  628. .ignore_suspend = 1,
  629. .ops = &msm_common_be_ops,
  630. /* .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, */
  631. SND_SOC_DAILINK_REG(cps_feedback),
  632. },
  633. {
  634. .name = LPASS_BE_WSA_CDC_DMA_RX_0_VIRT,
  635. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_0_VIRT,
  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. static struct snd_soc_dai_link msm_wsa2_cdc_dma_be_dai_links[] = {
  647. /* WSA2 CDC DMA Backend DAI Links */
  648. {
  649. .name = LPASS_BE_WSA2_CDC_DMA_RX_0,
  650. .stream_name = LPASS_BE_WSA2_CDC_DMA_RX_0,
  651. .playback_only = 1,
  652. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  653. SND_SOC_DPCM_TRIGGER_POST},
  654. .ignore_pmdown_time = 1,
  655. .ignore_suspend = 1,
  656. .ops = &msm_common_be_ops,
  657. SND_SOC_DAILINK_REG(wsa2_dma_rx0),
  658. .init = &msm_int_wsa2_init,
  659. },
  660. {
  661. .name = LPASS_BE_WSA2_CDC_DMA_RX_1,
  662. .stream_name = LPASS_BE_WSA2_CDC_DMA_RX_1,
  663. .playback_only = 1,
  664. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  665. SND_SOC_DPCM_TRIGGER_POST},
  666. .ignore_pmdown_time = 1,
  667. .ignore_suspend = 1,
  668. .ops = &msm_common_be_ops,
  669. SND_SOC_DAILINK_REG(wsa2_dma_rx1),
  670. },
  671. {
  672. .name = LPASS_BE_WSA2_CDC_DMA_TX_1,
  673. .stream_name = LPASS_BE_WSA2_CDC_DMA_TX_1,
  674. .capture_only = 1,
  675. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  676. SND_SOC_DPCM_TRIGGER_POST},
  677. .ignore_suspend = 1,
  678. .ops = &msm_common_be_ops,
  679. SND_SOC_DAILINK_REG(wsa2_dma_tx1),
  680. },
  681. {
  682. .name = LPASS_BE_WSA2_CDC_DMA_TX_0,
  683. .stream_name = LPASS_BE_WSA2_CDC_DMA_TX_0,
  684. .capture_only = 1,
  685. .ignore_suspend = 1,
  686. .ops = &msm_common_be_ops,
  687. /* .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, */
  688. SND_SOC_DAILINK_REG(wsa2_vi_feedback),
  689. },
  690. {
  691. .name = LPASS_BE_WSA2_CDC_DMA_TX_2,
  692. .stream_name = LPASS_BE_WSA2_CDC_DMA_TX_2,
  693. .capture_only = 1,
  694. .ignore_suspend = 1,
  695. .ops = &msm_common_be_ops,
  696. /* .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, */
  697. SND_SOC_DAILINK_REG(wsa2_cps_feedback),
  698. },
  699. };
  700. static struct snd_soc_dai_link msm_wsa_wsa2_cdc_dma_be_dai_links[] = {
  701. /* WSA CDC DMA Backend DAI Links */
  702. {
  703. .name = LPASS_BE_WSA_CDC_DMA_RX_0,
  704. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_0,
  705. .playback_only = 1,
  706. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  707. SND_SOC_DPCM_TRIGGER_POST},
  708. .ignore_pmdown_time = 1,
  709. .ignore_suspend = 1,
  710. .ops = &msm_common_be_ops,
  711. SND_SOC_DAILINK_REG(wsa_wsa2_dma_rx0),
  712. .init = &msm_int_wsa_init,
  713. },
  714. {
  715. .name = LPASS_BE_WSA_CDC_DMA_RX_1,
  716. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_1,
  717. .playback_only = 1,
  718. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  719. SND_SOC_DPCM_TRIGGER_POST},
  720. .ignore_pmdown_time = 1,
  721. .ignore_suspend = 1,
  722. .ops = &msm_common_be_ops,
  723. SND_SOC_DAILINK_REG(wsa_wsa2_dma_rx1),
  724. },
  725. {
  726. .name = LPASS_BE_WSA_CDC_DMA_TX_1,
  727. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_1,
  728. .capture_only = 1,
  729. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  730. SND_SOC_DPCM_TRIGGER_POST},
  731. .ignore_suspend = 1,
  732. .ops = &msm_common_be_ops,
  733. SND_SOC_DAILINK_REG(wsa_wsa2_dma_tx1),
  734. },
  735. {
  736. .name = LPASS_BE_WSA_CDC_DMA_TX_0,
  737. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_0,
  738. .capture_only = 1,
  739. .ignore_suspend = 1,
  740. .ops = &msm_common_be_ops,
  741. /* .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, */
  742. SND_SOC_DAILINK_REG(wsa_wsa2_vi_feedback),
  743. },
  744. {
  745. .name = LPASS_BE_WSA_CDC_DMA_TX_2,
  746. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_2,
  747. .capture_only = 1,
  748. .ignore_suspend = 1,
  749. .ops = &msm_common_be_ops,
  750. /* .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, */
  751. SND_SOC_DAILINK_REG(wsa_wsa2_cps_feedback),
  752. },
  753. };
  754. static struct snd_soc_dai_link msm_rx_tx_cdc_dma_be_dai_links[] = {
  755. /* RX CDC DMA Backend DAI Links */
  756. {
  757. .name = LPASS_BE_RX_CDC_DMA_RX_0,
  758. .stream_name = LPASS_BE_RX_CDC_DMA_RX_0,
  759. .playback_only = 1,
  760. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  761. SND_SOC_DPCM_TRIGGER_POST},
  762. .ignore_pmdown_time = 1,
  763. .ignore_suspend = 1,
  764. .ops = &msm_common_be_ops,
  765. SND_SOC_DAILINK_REG(rx_dma_rx0),
  766. .init = &msm_rx_tx_codec_init,
  767. },
  768. {
  769. .name = LPASS_BE_RX_CDC_DMA_RX_1,
  770. .stream_name = LPASS_BE_RX_CDC_DMA_RX_1,
  771. .playback_only = 1,
  772. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  773. SND_SOC_DPCM_TRIGGER_POST},
  774. .ignore_pmdown_time = 1,
  775. .ignore_suspend = 1,
  776. .ops = &msm_common_be_ops,
  777. SND_SOC_DAILINK_REG(rx_dma_rx1),
  778. },
  779. {
  780. .name = LPASS_BE_RX_CDC_DMA_RX_2,
  781. .stream_name = LPASS_BE_RX_CDC_DMA_RX_2,
  782. .playback_only = 1,
  783. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  784. SND_SOC_DPCM_TRIGGER_POST},
  785. .ignore_pmdown_time = 1,
  786. .ignore_suspend = 1,
  787. .ops = &msm_common_be_ops,
  788. SND_SOC_DAILINK_REG(rx_dma_rx2),
  789. },
  790. {
  791. .name = LPASS_BE_RX_CDC_DMA_RX_3,
  792. .stream_name = LPASS_BE_RX_CDC_DMA_RX_3,
  793. .playback_only = 1,
  794. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  795. SND_SOC_DPCM_TRIGGER_POST},
  796. .ignore_pmdown_time = 1,
  797. .ignore_suspend = 1,
  798. .ops = &msm_common_be_ops,
  799. SND_SOC_DAILINK_REG(rx_dma_rx3),
  800. },
  801. {
  802. .name = LPASS_BE_RX_CDC_DMA_RX_5,
  803. .stream_name = LPASS_BE_RX_CDC_DMA_RX_5,
  804. .playback_only = 1,
  805. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  806. SND_SOC_DPCM_TRIGGER_POST},
  807. .ignore_pmdown_time = 1,
  808. .ignore_suspend = 1,
  809. .ops = &msm_common_be_ops,
  810. SND_SOC_DAILINK_REG(rx_dma_rx5),
  811. },
  812. {
  813. .name = LPASS_BE_RX_CDC_DMA_RX_6,
  814. .stream_name = LPASS_BE_RX_CDC_DMA_RX_6,
  815. .playback_only = 1,
  816. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  817. SND_SOC_DPCM_TRIGGER_POST},
  818. .ignore_pmdown_time = 1,
  819. .ignore_suspend = 1,
  820. .ops = &msm_common_be_ops,
  821. SND_SOC_DAILINK_REG(rx_dma_rx6),
  822. },
  823. /* TX CDC DMA Backend DAI Links */
  824. {
  825. .name = LPASS_BE_TX_CDC_DMA_TX_3,
  826. .stream_name = LPASS_BE_TX_CDC_DMA_TX_3,
  827. .capture_only = 1,
  828. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  829. SND_SOC_DPCM_TRIGGER_POST},
  830. .ignore_suspend = 1,
  831. .ops = &msm_common_be_ops,
  832. SND_SOC_DAILINK_REG(tx_dma_tx3),
  833. },
  834. {
  835. .name = LPASS_BE_TX_CDC_DMA_TX_4,
  836. .stream_name = LPASS_BE_TX_CDC_DMA_TX_4,
  837. .capture_only = 1,
  838. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  839. SND_SOC_DPCM_TRIGGER_POST},
  840. .ignore_suspend = 1,
  841. .ops = &msm_common_be_ops,
  842. SND_SOC_DAILINK_REG(tx_dma_tx4),
  843. },
  844. };
  845. static struct snd_soc_dai_link msm_va_cdc_dma_be_dai_links[] = {
  846. {
  847. .name = LPASS_BE_VA_CDC_DMA_TX_0,
  848. .stream_name = LPASS_BE_VA_CDC_DMA_TX_0,
  849. .capture_only = 1,
  850. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  851. SND_SOC_DPCM_TRIGGER_POST},
  852. .ignore_suspend = 1,
  853. .ops = &msm_common_be_ops,
  854. SND_SOC_DAILINK_REG(va_dma_tx0),
  855. },
  856. {
  857. .name = LPASS_BE_VA_CDC_DMA_TX_1,
  858. .stream_name = LPASS_BE_VA_CDC_DMA_TX_1,
  859. .capture_only = 1,
  860. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  861. SND_SOC_DPCM_TRIGGER_POST},
  862. .ignore_suspend = 1,
  863. .ops = &msm_common_be_ops,
  864. SND_SOC_DAILINK_REG(va_dma_tx1),
  865. },
  866. {
  867. .name = LPASS_BE_VA_CDC_DMA_TX_2,
  868. .stream_name = LPASS_BE_VA_CDC_DMA_TX_2,
  869. .capture_only = 1,
  870. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  871. SND_SOC_DPCM_TRIGGER_POST},
  872. .ignore_suspend = 1,
  873. .ops = &msm_common_be_ops,
  874. SND_SOC_DAILINK_REG(va_dma_tx2),
  875. },
  876. };
  877. /*
  878. * I2S interface pinctrl mapping
  879. * ------------------------------------
  880. * Primary - pri_mi2s
  881. * Secondary - lpi_i2s3
  882. * Tertiary - tert_mi2s
  883. * Quaternary - quat_mi2s (lpi_i2s0)
  884. * Quinary - lpi_i2s1
  885. * Senary - lpi_i2s2
  886. * ------------------------------------
  887. */
  888. static struct snd_soc_dai_link msm_mi2s_dai_links[] = {
  889. {
  890. .name = LPASS_BE_PRI_MI2S_RX,
  891. .stream_name = LPASS_BE_PRI_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(pri_mi2s_rx),
  899. },
  900. {
  901. .name = LPASS_BE_PRI_MI2S_TX,
  902. .stream_name = LPASS_BE_PRI_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(pri_mi2s_tx),
  909. },
  910. {
  911. .name = LPASS_BE_SEC_MI2S_RX,
  912. .stream_name = LPASS_BE_SEC_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(sec_mi2s_rx),
  920. },
  921. {
  922. .name = LPASS_BE_SEC_MI2S_TX,
  923. .stream_name = LPASS_BE_SEC_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(sec_mi2s_tx),
  930. },
  931. {
  932. .name = LPASS_BE_TERT_MI2S_RX,
  933. .stream_name = LPASS_BE_TERT_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(tert_mi2s_rx),
  941. },
  942. {
  943. .name = LPASS_BE_TERT_MI2S_TX,
  944. .stream_name = LPASS_BE_TERT_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(tert_mi2s_tx),
  951. },
  952. {
  953. .name = LPASS_BE_QUAT_MI2S_RX,
  954. .stream_name = LPASS_BE_QUAT_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(quat_mi2s_rx),
  962. },
  963. {
  964. .name = LPASS_BE_QUAT_MI2S_TX,
  965. .stream_name = LPASS_BE_QUAT_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(quat_mi2s_tx),
  972. },
  973. {
  974. .name = LPASS_BE_QUIN_MI2S_RX,
  975. .stream_name = LPASS_BE_QUIN_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(quin_mi2s_rx),
  983. },
  984. {
  985. .name = LPASS_BE_QUIN_MI2S_TX,
  986. .stream_name = LPASS_BE_QUIN_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(quin_mi2s_tx),
  993. },
  994. {
  995. .name = LPASS_BE_SEN_MI2S_RX,
  996. .stream_name = LPASS_BE_SEN_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(sen_mi2s_rx),
  1004. },
  1005. {
  1006. .name = LPASS_BE_SEN_MI2S_TX,
  1007. .stream_name = LPASS_BE_SEN_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(sen_mi2s_tx),
  1014. },
  1015. {
  1016. .name = LPASS_BE_SEP_MI2S_RX,
  1017. .stream_name = LPASS_BE_SEP_MI2S_RX,
  1018. .playback_only = 1,
  1019. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1020. SND_SOC_DPCM_TRIGGER_POST},
  1021. .ops = &msm_common_be_ops,
  1022. .ignore_suspend = 1,
  1023. .ignore_pmdown_time = 1,
  1024. SND_SOC_DAILINK_REG(sep_mi2s_rx),
  1025. },
  1026. {
  1027. .name = LPASS_BE_SEP_MI2S_TX,
  1028. .stream_name = LPASS_BE_SEP_MI2S_TX,
  1029. .capture_only = 1,
  1030. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1031. SND_SOC_DPCM_TRIGGER_POST},
  1032. .ops = &msm_common_be_ops,
  1033. .ignore_suspend = 1,
  1034. SND_SOC_DAILINK_REG(sep_mi2s_tx),
  1035. },
  1036. };
  1037. static struct snd_soc_dai_link msm_tdm_dai_links[] = {
  1038. {
  1039. .name = LPASS_BE_PRI_TDM_RX_0,
  1040. .stream_name = LPASS_BE_PRI_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(pri_tdm_rx_0),
  1048. },
  1049. {
  1050. .name = LPASS_BE_PRI_TDM_TX_0,
  1051. .stream_name = LPASS_BE_PRI_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(pri_tdm_tx_0),
  1058. },
  1059. {
  1060. .name = LPASS_BE_SEC_TDM_RX_0,
  1061. .stream_name = LPASS_BE_SEC_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(sec_tdm_rx_0),
  1069. },
  1070. {
  1071. .name = LPASS_BE_SEC_TDM_TX_0,
  1072. .stream_name = LPASS_BE_SEC_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(sec_tdm_tx_0),
  1079. },
  1080. {
  1081. .name = LPASS_BE_TERT_TDM_RX_0,
  1082. .stream_name = LPASS_BE_TERT_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(tert_tdm_rx_0),
  1090. },
  1091. {
  1092. .name = LPASS_BE_TERT_TDM_TX_0,
  1093. .stream_name = LPASS_BE_TERT_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(tert_tdm_tx_0),
  1100. },
  1101. {
  1102. .name = LPASS_BE_QUAT_TDM_RX_0,
  1103. .stream_name = LPASS_BE_QUAT_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(quat_tdm_rx_0),
  1111. },
  1112. {
  1113. .name = LPASS_BE_QUAT_TDM_TX_0,
  1114. .stream_name = LPASS_BE_QUAT_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(quat_tdm_tx_0),
  1121. },
  1122. {
  1123. .name = LPASS_BE_QUIN_TDM_RX_0,
  1124. .stream_name = LPASS_BE_QUIN_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(quin_tdm_rx_0),
  1132. },
  1133. {
  1134. .name = LPASS_BE_QUIN_TDM_TX_0,
  1135. .stream_name = LPASS_BE_QUIN_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(quin_tdm_tx_0),
  1142. },
  1143. {
  1144. .name = LPASS_BE_SEN_TDM_RX_0,
  1145. .stream_name = LPASS_BE_SEN_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(sen_tdm_rx_0),
  1153. },
  1154. {
  1155. .name = LPASS_BE_SEN_TDM_TX_0,
  1156. .stream_name = LPASS_BE_SEN_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(sen_tdm_tx_0),
  1163. },
  1164. {
  1165. .name = LPASS_BE_SEP_TDM_RX_0,
  1166. .stream_name = LPASS_BE_SEP_TDM_RX_0,
  1167. .playback_only = 1,
  1168. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1169. SND_SOC_DPCM_TRIGGER_POST},
  1170. .ops = &msm_common_be_ops,
  1171. .ignore_suspend = 1,
  1172. .ignore_pmdown_time = 1,
  1173. SND_SOC_DAILINK_REG(sep_tdm_rx_0),
  1174. },
  1175. {
  1176. .name = LPASS_BE_SEP_TDM_TX_0,
  1177. .stream_name = LPASS_BE_SEP_TDM_TX_0,
  1178. .capture_only = 1,
  1179. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1180. SND_SOC_DPCM_TRIGGER_POST},
  1181. .ops = &msm_common_be_ops,
  1182. .ignore_suspend = 1,
  1183. SND_SOC_DAILINK_REG(sep_tdm_tx_0),
  1184. },
  1185. };
  1186. static struct snd_soc_dai_link msm_pineapple_dai_links[
  1187. ARRAY_SIZE(msm_wsa_cdc_dma_be_dai_links) +
  1188. ARRAY_SIZE(msm_wsa2_cdc_dma_be_dai_links) +
  1189. ARRAY_SIZE(msm_wsa_wsa2_cdc_dma_be_dai_links) +
  1190. ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links) +
  1191. ARRAY_SIZE(msm_va_cdc_dma_be_dai_links) +
  1192. ARRAY_SIZE(ext_disp_be_dai_link) +
  1193. ARRAY_SIZE(msm_common_be_dai_links) +
  1194. ARRAY_SIZE(msm_wcn_be_dai_links) +
  1195. ARRAY_SIZE(msm_mi2s_dai_links) +
  1196. ARRAY_SIZE(msm_tdm_dai_links)];
  1197. static int msm_populate_dai_link_component_of_node(
  1198. struct snd_soc_card *card)
  1199. {
  1200. int i, j, index, ret = 0;
  1201. struct device *cdev = card->dev;
  1202. struct snd_soc_dai_link *dai_link = card->dai_link;
  1203. struct device_node *np = NULL;
  1204. int codecs_enabled = 0;
  1205. struct snd_soc_dai_link_component *codecs_comp = NULL;
  1206. if (!cdev) {
  1207. dev_err_ratelimited(cdev, "%s: Sound card device memory NULL\n", __func__);
  1208. return -ENODEV;
  1209. }
  1210. for (i = 0; i < card->num_links; i++) {
  1211. if (dai_link[i].init == NULL)
  1212. dai_link[i].init = &msm_common_dai_link_init;
  1213. /* populate codec_of_node for snd card dai links */
  1214. if (dai_link[i].num_codecs > 0) {
  1215. for (j = 0; j < dai_link[i].num_codecs; j++) {
  1216. if (dai_link[i].codecs[j].of_node ||
  1217. !dai_link[i].codecs[j].name)
  1218. continue;
  1219. index = of_property_match_string(cdev->of_node,
  1220. "asoc-codec-names",
  1221. dai_link[i].codecs[j].name);
  1222. if (index < 0)
  1223. continue;
  1224. np = of_parse_phandle(cdev->of_node,
  1225. "asoc-codec",
  1226. index);
  1227. if (!np) {
  1228. dev_err_ratelimited(cdev,
  1229. "%s: retrieving phandle for codec %s failed\n",
  1230. __func__,
  1231. dai_link[i].codecs[j].name);
  1232. ret = -ENODEV;
  1233. goto err;
  1234. }
  1235. dai_link[i].codecs[j].of_node = np;
  1236. dai_link[i].codecs[j].name = NULL;
  1237. }
  1238. }
  1239. }
  1240. /* In multi-codec scenario, check if codecs are enabled for this platform */
  1241. for (i = 0; i < card->num_links; i++) {
  1242. codecs_enabled = 0;
  1243. if (dai_link[i].num_codecs > 1) {
  1244. for (j = 0; j < dai_link[i].num_codecs; j++) {
  1245. if (!dai_link[i].codecs[j].of_node)
  1246. continue;
  1247. np = dai_link[i].codecs[j].of_node;
  1248. if (!of_device_is_available(np)) {
  1249. dev_err_ratelimited(cdev, "%s: codec is disabled: %s\n",
  1250. __func__,
  1251. np->full_name);
  1252. dai_link[i].codecs[j].of_node = NULL;
  1253. continue;
  1254. }
  1255. codecs_enabled++;
  1256. }
  1257. if (codecs_enabled > 0 &&
  1258. codecs_enabled < dai_link[i].num_codecs) {
  1259. codecs_comp = devm_kzalloc(cdev,
  1260. sizeof(struct snd_soc_dai_link_component)
  1261. * codecs_enabled, GFP_KERNEL);
  1262. if (!codecs_comp) {
  1263. dev_err_ratelimited(cdev,
  1264. "%s: %s dailink codec component alloc failed\n",
  1265. __func__, dai_link[i].name);
  1266. ret = -ENOMEM;
  1267. goto err;
  1268. }
  1269. index = 0;
  1270. for (j = 0; j < dai_link[i].num_codecs; j++) {
  1271. if(dai_link[i].codecs[j].of_node) {
  1272. codecs_comp[index].of_node =
  1273. dai_link[i].codecs[j].of_node;
  1274. codecs_comp[index].dai_name =
  1275. dai_link[i].codecs[j].dai_name;
  1276. codecs_comp[index].name = NULL;
  1277. index++;
  1278. }
  1279. }
  1280. dai_link[i].codecs = codecs_comp;
  1281. dai_link[i].num_codecs = codecs_enabled;
  1282. }
  1283. }
  1284. }
  1285. err:
  1286. return ret;
  1287. }
  1288. static int msm_audrx_stub_init(struct snd_soc_pcm_runtime *rtd)
  1289. {
  1290. return 0;
  1291. }
  1292. static int msm_snd_stub_hw_params(struct snd_pcm_substream *substream,
  1293. struct snd_pcm_hw_params *params)
  1294. {
  1295. return 0;
  1296. }
  1297. static struct snd_soc_ops msm_stub_be_ops = {
  1298. .hw_params = msm_snd_stub_hw_params,
  1299. };
  1300. struct snd_soc_card snd_soc_card_stub_msm = {
  1301. .name = "pineapple-stub-snd-card",
  1302. };
  1303. static struct snd_soc_dai_link msm_stub_be_dai_links[] = {
  1304. /* Backend DAI Links */
  1305. {
  1306. .name = LPASS_BE_PRI_AUXPCM_RX,
  1307. .stream_name = LPASS_BE_PRI_AUXPCM_RX,
  1308. .playback_only = 1,
  1309. .init = &msm_audrx_stub_init,
  1310. .ignore_pmdown_time = 1,
  1311. .ignore_suspend = 1,
  1312. .ops = &msm_stub_be_ops,
  1313. SND_SOC_DAILINK_REG(auxpcm_rx),
  1314. },
  1315. {
  1316. .name = LPASS_BE_PRI_AUXPCM_TX,
  1317. .stream_name = LPASS_BE_PRI_AUXPCM_TX,
  1318. .capture_only = 1,
  1319. .ignore_suspend = 1,
  1320. .ops = &msm_stub_be_ops,
  1321. SND_SOC_DAILINK_REG(auxpcm_tx),
  1322. },
  1323. };
  1324. static struct snd_soc_dai_link msm_stub_dai_links[
  1325. ARRAY_SIZE(msm_stub_be_dai_links)];
  1326. static const struct of_device_id pineapple_asoc_machine_of_match[] = {
  1327. { .compatible = "qcom,pineapple-asoc-snd",
  1328. .data = "codec"},
  1329. { .compatible = "qcom,pineapple-asoc-snd-stub",
  1330. .data = "stub_codec"},
  1331. {},
  1332. };
  1333. static int msm_snd_card_late_probe(struct snd_soc_card *card)
  1334. {
  1335. struct snd_soc_component *component = NULL;
  1336. struct snd_soc_pcm_runtime *rtd;
  1337. struct msm_asoc_mach_data *pdata;
  1338. int ret = 0;
  1339. void *mbhc_calibration;
  1340. pdata = snd_soc_card_get_drvdata(card);
  1341. if (!pdata)
  1342. return -EINVAL;
  1343. if (pdata->wcd_disabled)
  1344. return 0;
  1345. rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
  1346. if (!rtd) {
  1347. dev_err(card->dev,
  1348. "%s: snd_soc_get_pcm_runtime for %s failed!\n",
  1349. __func__, card->dai_link[0]);
  1350. return -EINVAL;
  1351. }
  1352. component = snd_soc_rtdcom_lookup(rtd, WCD939X_DRV_NAME);
  1353. if (!component) {
  1354. pr_err("%s component is NULL\n", __func__);
  1355. return -EINVAL;
  1356. }
  1357. mbhc_calibration = def_wcd_mbhc_cal();
  1358. if (!mbhc_calibration)
  1359. return -ENOMEM;
  1360. wcd_mbhc_cfg.calibration = mbhc_calibration;
  1361. #if IS_ENABLED(CONFIG_QCOM_WCD_USBSS_I2C)
  1362. if (of_find_property(card->dev->of_node,
  1363. "qcom,usbss-hsj-connect-enabled", NULL))
  1364. wcd_mbhc_cfg.usbss_hsj_connect_enable = true;
  1365. #endif
  1366. ret = wcd939x_mbhc_hs_detect(component, &wcd_mbhc_cfg);
  1367. if (ret) {
  1368. dev_err(component->dev, "%s: mbhc hs detect failed, err:%d\n",
  1369. __func__, ret);
  1370. goto err_hs_detect;
  1371. }
  1372. return 0;
  1373. err_hs_detect:
  1374. kfree(mbhc_calibration);
  1375. return ret;
  1376. }
  1377. static struct snd_soc_card *populate_snd_card_dailinks(struct device *dev, int wsa_max_devs)
  1378. {
  1379. struct snd_soc_card *card = NULL;
  1380. struct snd_soc_dai_link *dailink = NULL;
  1381. int total_links = 0;
  1382. int rc = 0;
  1383. u32 val = 0;
  1384. const struct of_device_id *match;
  1385. match = of_match_node(pineapple_asoc_machine_of_match, dev->of_node);
  1386. if (!match) {
  1387. dev_err_ratelimited(dev, "%s: No DT match found for sound card\n",
  1388. __func__);
  1389. return NULL;
  1390. }
  1391. if (!strcmp(match->data, "codec")) {
  1392. card = &snd_soc_card_pineapple_msm;
  1393. /* late probe uses dai link at index '0' to get wcd component */
  1394. memcpy(msm_pineapple_dai_links + total_links,
  1395. msm_rx_tx_cdc_dma_be_dai_links,
  1396. sizeof(msm_rx_tx_cdc_dma_be_dai_links));
  1397. total_links +=
  1398. ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links);
  1399. switch (wsa_max_devs) {
  1400. case MONO_SPEAKER:
  1401. case STEREO_SPEAKER:
  1402. memcpy(msm_pineapple_dai_links + total_links,
  1403. msm_wsa_cdc_dma_be_dai_links,
  1404. sizeof(msm_wsa_cdc_dma_be_dai_links));
  1405. total_links += ARRAY_SIZE(msm_wsa_cdc_dma_be_dai_links);
  1406. break;
  1407. case QUAD_SPEAKER:
  1408. if (of_find_property(dev->of_node,
  1409. "qcom,dedicated-wsa2", NULL)) {
  1410. memcpy(msm_pineapple_dai_links + total_links,
  1411. msm_wsa_cdc_dma_be_dai_links,
  1412. sizeof(msm_wsa_cdc_dma_be_dai_links));
  1413. total_links += ARRAY_SIZE(msm_wsa_cdc_dma_be_dai_links);
  1414. memcpy(msm_pineapple_dai_links + total_links,
  1415. msm_wsa2_cdc_dma_be_dai_links,
  1416. sizeof(msm_wsa2_cdc_dma_be_dai_links));
  1417. total_links += ARRAY_SIZE(msm_wsa2_cdc_dma_be_dai_links);
  1418. } else {
  1419. memcpy(msm_pineapple_dai_links + total_links,
  1420. msm_wsa2_cdc_dma_be_dai_links,
  1421. sizeof(msm_wsa2_cdc_dma_be_dai_links));
  1422. total_links += ARRAY_SIZE(msm_wsa2_cdc_dma_be_dai_links);
  1423. memcpy(msm_pineapple_dai_links + total_links,
  1424. msm_wsa_wsa2_cdc_dma_be_dai_links,
  1425. sizeof(msm_wsa_wsa2_cdc_dma_be_dai_links));
  1426. total_links += ARRAY_SIZE(msm_wsa_wsa2_cdc_dma_be_dai_links);
  1427. }
  1428. break;
  1429. default:
  1430. dev_dbg(dev,
  1431. "%s: Unexpected number of WSAs, wsa_max_devs: %d\n",
  1432. __func__, wsa_max_devs);
  1433. break;
  1434. }
  1435. memcpy(msm_pineapple_dai_links + total_links,
  1436. msm_va_cdc_dma_be_dai_links,
  1437. sizeof(msm_va_cdc_dma_be_dai_links));
  1438. total_links += ARRAY_SIZE(msm_va_cdc_dma_be_dai_links);
  1439. memcpy(msm_pineapple_dai_links + total_links,
  1440. msm_common_be_dai_links,
  1441. sizeof(msm_common_be_dai_links));
  1442. total_links += ARRAY_SIZE(msm_common_be_dai_links);
  1443. rc = of_property_read_u32(dev->of_node,
  1444. "qcom,mi2s-audio-intf", &val);
  1445. if (!rc && val) {
  1446. memcpy(msm_pineapple_dai_links + total_links,
  1447. msm_mi2s_dai_links,
  1448. sizeof(msm_mi2s_dai_links));
  1449. total_links += ARRAY_SIZE(msm_mi2s_dai_links);
  1450. }
  1451. rc = of_property_read_u32(dev->of_node,
  1452. "qcom,tdm-audio-intf", &val);
  1453. if (!rc && val) {
  1454. memcpy(msm_pineapple_dai_links + total_links,
  1455. msm_tdm_dai_links,
  1456. sizeof(msm_tdm_dai_links));
  1457. total_links += ARRAY_SIZE(msm_tdm_dai_links);
  1458. }
  1459. rc = of_property_read_u32(dev->of_node,
  1460. "qcom,ext-disp-audio-rx", &val);
  1461. if (!rc && val) {
  1462. if (!socinfo_get_part_info(PART_DISPLAY)) {
  1463. dev_dbg(dev, "%s(): ext disp audio support present\n",
  1464. __func__);
  1465. memcpy(msm_pineapple_dai_links + total_links,
  1466. ext_disp_be_dai_link,
  1467. sizeof(ext_disp_be_dai_link));
  1468. total_links += ARRAY_SIZE(ext_disp_be_dai_link);
  1469. }
  1470. }
  1471. rc = of_property_read_u32(dev->of_node, "qcom,wcn-bt", &val);
  1472. if (!rc && val) {
  1473. dev_dbg(dev, "%s(): WCN BT support present\n",
  1474. __func__);
  1475. memcpy(msm_pineapple_dai_links + total_links,
  1476. msm_wcn_be_dai_links,
  1477. sizeof(msm_wcn_be_dai_links));
  1478. total_links += ARRAY_SIZE(msm_wcn_be_dai_links);
  1479. }
  1480. dailink = msm_pineapple_dai_links;
  1481. } else if(!strcmp(match->data, "stub_codec")) {
  1482. card = &snd_soc_card_stub_msm;
  1483. memcpy(msm_stub_dai_links,
  1484. msm_stub_be_dai_links,
  1485. sizeof(msm_stub_be_dai_links));
  1486. dailink = msm_stub_dai_links;
  1487. total_links = ARRAY_SIZE(msm_stub_be_dai_links);
  1488. }
  1489. if (card) {
  1490. card->dai_link = dailink;
  1491. card->num_links = total_links;
  1492. if (!strcmp(match->data, "codec"))
  1493. card->late_probe = msm_snd_card_late_probe;
  1494. }
  1495. return card;
  1496. }
  1497. static int msm_int_wsa883x_init(struct snd_soc_pcm_runtime *rtd)
  1498. {
  1499. u8 spkleft_ports[WSA883X_MAX_SWR_PORTS] = {0, 1, 2, 3};
  1500. u8 spkright_ports[WSA883X_MAX_SWR_PORTS] = {0, 1, 2, 3};
  1501. u8 spkleft_port_types[WSA883X_MAX_SWR_PORTS] = {SPKR_L, SPKR_L_COMP,
  1502. SPKR_L_BOOST, SPKR_L_VI};
  1503. u8 spkright_port_types[WSA883X_MAX_SWR_PORTS] = {SPKR_R, SPKR_R_COMP,
  1504. SPKR_R_BOOST, SPKR_R_VI};
  1505. unsigned int ch_rate[WSA883X_MAX_SWR_PORTS] = {SWR_CLK_RATE_2P4MHZ, SWR_CLK_RATE_0P6MHZ,
  1506. SWR_CLK_RATE_0P3MHZ, SWR_CLK_RATE_1P2MHZ};
  1507. unsigned int ch_mask[WSA883X_MAX_SWR_PORTS] = {0x1, 0xF, 0x3, 0x3};
  1508. struct snd_soc_component *component = NULL;
  1509. struct msm_asoc_mach_data *pdata =
  1510. snd_soc_card_get_drvdata(rtd->card);
  1511. if (pdata->wsa_max_devs > 0) {
  1512. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.1");
  1513. if (!component) {
  1514. pr_err("%s: wsa-codec.1 component is NULL\n", __func__);
  1515. return -EINVAL;
  1516. }
  1517. wsa883x_set_channel_map(component, &spkleft_ports[0],
  1518. WSA883X_MAX_SWR_PORTS, &ch_mask[0],
  1519. &ch_rate[0], &spkleft_port_types[0]);
  1520. wsa883x_codec_info_create_codec_entry(pdata->codec_root,
  1521. component);
  1522. }
  1523. /* If current platform has more than one WSA */
  1524. if (pdata->wsa_max_devs > 1) {
  1525. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.2");
  1526. if (!component) {
  1527. pr_err("%s: wsa-codec.2 component is NULL\n", __func__);
  1528. return -EINVAL;
  1529. }
  1530. wsa883x_set_channel_map(component, &spkright_ports[0],
  1531. WSA883X_MAX_SWR_PORTS, &ch_mask[0],
  1532. &ch_rate[0], &spkright_port_types[0]);
  1533. wsa883x_codec_info_create_codec_entry(pdata->codec_root,
  1534. component);
  1535. }
  1536. if (!pdata->dedicated_wsa2) {
  1537. if (pdata->wsa_max_devs > 2) {
  1538. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.3");
  1539. if (!component) {
  1540. pr_err("%s: wsa-codec.3 component is NULL\n", __func__);
  1541. return -EINVAL;
  1542. }
  1543. wsa883x_set_channel_map(component, &spkleft_ports[0],
  1544. WSA883X_MAX_SWR_PORTS, &ch_mask[0],
  1545. &ch_rate[0], &spkleft_port_types[0]);
  1546. wsa883x_codec_info_create_codec_entry(pdata->codec_root,
  1547. component);
  1548. }
  1549. if (pdata->wsa_max_devs > 3) {
  1550. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.4");
  1551. if (!component) {
  1552. pr_err("%s: wsa-codec.4 component is NULL\n", __func__);
  1553. return -EINVAL;
  1554. }
  1555. wsa883x_set_channel_map(component, &spkright_ports[0],
  1556. WSA883X_MAX_SWR_PORTS, &ch_mask[0],
  1557. &ch_rate[0], &spkright_port_types[0]);
  1558. wsa883x_codec_info_create_codec_entry(pdata->codec_root,
  1559. component);
  1560. }
  1561. }
  1562. msm_common_dai_link_init(rtd);
  1563. return 0;
  1564. }
  1565. static int msm_int_wsa884x_init(struct snd_soc_pcm_runtime *rtd)
  1566. {
  1567. u8 spkleft_ports[WSA884X_MAX_SWR_PORTS] = {0, 1, 2, 3, 4, 5};
  1568. u8 spkright_ports[WSA884X_MAX_SWR_PORTS] = {0, 1, 2, 3, 4, 5};
  1569. u8 spkleft_port_types[WSA884X_MAX_SWR_PORTS] = {SPKR_L, SPKR_L_COMP,
  1570. SPKR_L_BOOST, PBR, SPKR_L_VI, CPS};
  1571. u8 spkright_port_types[WSA884X_MAX_SWR_PORTS] = {SPKR_R, SPKR_R_COMP,
  1572. SPKR_R_BOOST, PBR, SPKR_R_VI, CPS};
  1573. unsigned int ch_rate[WSA884X_MAX_SWR_PORTS] = {SWR_CLK_RATE_2P4MHZ, SWR_CLK_RATE_0P6MHZ,
  1574. SWR_CLK_RATE_0P3MHZ, SWR_CLK_RATE_48KHZ,
  1575. SWR_CLK_RATE_1P2MHZ, SWR_CLK_RATE_24KHZ};
  1576. unsigned int ch_mask[WSA884X_MAX_SWR_PORTS] = {0x1, 0xF, 0x3, 0x1, 0x3, 0x3};
  1577. struct snd_soc_component *component = NULL;
  1578. struct msm_asoc_mach_data *pdata =
  1579. snd_soc_card_get_drvdata(rtd->card);
  1580. if (pdata->wsa_max_devs > 0) {
  1581. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.1");
  1582. if (!component) {
  1583. pr_err("%s: wsa-codec.1 component is NULL\n", __func__);
  1584. return -EINVAL;
  1585. }
  1586. wsa884x_set_channel_map(component, &spkleft_ports[0],
  1587. WSA884X_MAX_SWR_PORTS, &ch_mask[0],
  1588. &ch_rate[0], &spkleft_port_types[0]);
  1589. wsa884x_codec_info_create_codec_entry(pdata->codec_root,
  1590. component);
  1591. }
  1592. /* If current platform has more than one WSA */
  1593. if (pdata->wsa_max_devs > 1) {
  1594. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.2");
  1595. if (!component) {
  1596. pr_err("%s: wsa-codec.2 component is NULL\n", __func__);
  1597. return -EINVAL;
  1598. }
  1599. wsa884x_set_channel_map(component, &spkright_ports[0],
  1600. WSA884X_MAX_SWR_PORTS, &ch_mask[0],
  1601. &ch_rate[0], &spkright_port_types[0]);
  1602. wsa884x_codec_info_create_codec_entry(pdata->codec_root,
  1603. component);
  1604. }
  1605. if (!pdata->dedicated_wsa2) {
  1606. if (pdata->wsa_max_devs > 2) {
  1607. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.3");
  1608. if (!component) {
  1609. pr_err("%s: wsa-codec.3 component is NULL\n", __func__);
  1610. return -EINVAL;
  1611. }
  1612. wsa884x_set_channel_map(component, &spkleft_ports[0],
  1613. WSA884X_MAX_SWR_PORTS, &ch_mask[0],
  1614. &ch_rate[0], &spkleft_port_types[0]);
  1615. wsa884x_codec_info_create_codec_entry(pdata->codec_root,
  1616. component);
  1617. }
  1618. if (pdata->wsa_max_devs > 3) {
  1619. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.4");
  1620. if (!component) {
  1621. pr_err("%s: wsa-codec.4 component is NULL\n", __func__);
  1622. return -EINVAL;
  1623. }
  1624. wsa884x_set_channel_map(component, &spkright_ports[0],
  1625. WSA884X_MAX_SWR_PORTS, &ch_mask[0],
  1626. &ch_rate[0], &spkright_port_types[0]);
  1627. wsa884x_codec_info_create_codec_entry(pdata->codec_root,
  1628. component);
  1629. }
  1630. }
  1631. msm_common_dai_link_init(rtd);
  1632. return 0;
  1633. }
  1634. static int msm_int_wsa_init(struct snd_soc_pcm_runtime *rtd)
  1635. {
  1636. if (strstr(rtd->card->name, "wsa883x"))
  1637. return msm_int_wsa883x_init(rtd);
  1638. return msm_int_wsa884x_init(rtd);
  1639. }
  1640. static int msm_int_wsa883x_2_init(struct snd_soc_pcm_runtime *rtd)
  1641. {
  1642. u8 spkleft_ports[WSA883X_MAX_SWR_PORTS] = {0, 1, 2, 3};
  1643. u8 spkright_ports[WSA883X_MAX_SWR_PORTS] = {0, 1, 2, 3};
  1644. u8 spkleft_port_types[WSA883X_MAX_SWR_PORTS] = {SPKR_L, SPKR_L_COMP,
  1645. SPKR_L_BOOST, SPKR_L_VI};
  1646. u8 spkright_port_types[WSA883X_MAX_SWR_PORTS] = {SPKR_R, SPKR_R_COMP,
  1647. SPKR_R_BOOST, SPKR_R_VI};
  1648. unsigned int ch_rate[WSA883X_MAX_SWR_PORTS] = {SWR_CLK_RATE_2P4MHZ, SWR_CLK_RATE_0P6MHZ,
  1649. SWR_CLK_RATE_0P3MHZ, SWR_CLK_RATE_1P2MHZ};
  1650. unsigned int ch_mask[WSA883X_MAX_SWR_PORTS] = {0x1, 0xF, 0x3, 0x3};
  1651. struct snd_soc_component *component = NULL;
  1652. struct msm_asoc_mach_data *pdata =
  1653. snd_soc_card_get_drvdata(rtd->card);
  1654. if (pdata->dedicated_wsa2) {
  1655. if (pdata->wsa_max_devs > 2) {
  1656. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.3");
  1657. if (!component) {
  1658. pr_err("%s: wsa-codec.3 component is NULL\n", __func__);
  1659. return -EINVAL;
  1660. }
  1661. wsa883x_set_channel_map(component, &spkleft_ports[0],
  1662. WSA883X_MAX_SWR_PORTS, &ch_mask[0],
  1663. &ch_rate[0], &spkleft_port_types[0]);
  1664. wsa883x_codec_info_create_codec_entry(pdata->codec_root,
  1665. component);
  1666. }
  1667. if (pdata->wsa_max_devs > 3) {
  1668. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.4");
  1669. if (!component) {
  1670. pr_err("%s: wsa-codec.4 component is NULL\n", __func__);
  1671. return -EINVAL;
  1672. }
  1673. wsa883x_set_channel_map(component, &spkright_ports[0],
  1674. WSA883X_MAX_SWR_PORTS, &ch_mask[0],
  1675. &ch_rate[0], &spkright_port_types[0]);
  1676. wsa883x_codec_info_create_codec_entry(pdata->codec_root,
  1677. component);
  1678. }
  1679. msm_common_dai_link_init(rtd);
  1680. }
  1681. return 0;
  1682. }
  1683. static int msm_int_wsa884x_2_init(struct snd_soc_pcm_runtime *rtd)
  1684. {
  1685. u8 spkleft_ports[WSA884X_MAX_SWR_PORTS] = {0, 1, 2, 3, 4, 5};
  1686. u8 spkright_ports[WSA884X_MAX_SWR_PORTS] = {0, 1, 2, 3, 4, 5};
  1687. u8 spkleft_port_types[WSA884X_MAX_SWR_PORTS] = {SPKR_L, SPKR_L_COMP,
  1688. SPKR_L_BOOST, PBR, SPKR_L_VI, CPS};
  1689. u8 spkright_port_types[WSA884X_MAX_SWR_PORTS] = {SPKR_R, SPKR_R_COMP,
  1690. SPKR_R_BOOST, PBR, SPKR_R_VI, CPS};
  1691. unsigned int ch_rate[WSA884X_MAX_SWR_PORTS] = {SWR_CLK_RATE_2P4MHZ, SWR_CLK_RATE_0P6MHZ,
  1692. SWR_CLK_RATE_0P3MHZ, SWR_CLK_RATE_48KHZ,
  1693. SWR_CLK_RATE_1P2MHZ, SWR_CLK_RATE_24KHZ};
  1694. unsigned int ch_mask[WSA884X_MAX_SWR_PORTS] = {0x1, 0xF, 0x3, 0x1, 0x3, 0x3};
  1695. struct snd_soc_component *component = NULL;
  1696. struct msm_asoc_mach_data *pdata =
  1697. snd_soc_card_get_drvdata(rtd->card);
  1698. if (pdata->dedicated_wsa2) {
  1699. if (pdata->wsa_max_devs > 2) {
  1700. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.3");
  1701. if (!component) {
  1702. pr_err("%s: wsa-codec.3 component is NULL\n", __func__);
  1703. return -EINVAL;
  1704. }
  1705. wsa884x_set_channel_map(component, &spkleft_ports[0],
  1706. WSA884X_MAX_SWR_PORTS, &ch_mask[0],
  1707. &ch_rate[0], &spkleft_port_types[0]);
  1708. wsa884x_codec_info_create_codec_entry(pdata->codec_root,
  1709. component);
  1710. }
  1711. if (pdata->wsa_max_devs > 3) {
  1712. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.4");
  1713. if (!component) {
  1714. pr_err("%s: wsa-codec.4 component is NULL\n", __func__);
  1715. return -EINVAL;
  1716. }
  1717. wsa884x_set_channel_map(component, &spkright_ports[0],
  1718. WSA884X_MAX_SWR_PORTS, &ch_mask[0],
  1719. &ch_rate[0], &spkright_port_types[0]);
  1720. wsa884x_codec_info_create_codec_entry(pdata->codec_root,
  1721. component);
  1722. }
  1723. msm_common_dai_link_init(rtd);
  1724. }
  1725. return 0;
  1726. }
  1727. static int msm_int_wsa2_init(struct snd_soc_pcm_runtime *rtd)
  1728. {
  1729. if (strstr(rtd->card->name, "wsa883x"))
  1730. return msm_int_wsa883x_2_init(rtd);
  1731. return msm_int_wsa884x_2_init(rtd);
  1732. }
  1733. static int msm_rx_tx_codec_init(struct snd_soc_pcm_runtime *rtd)
  1734. {
  1735. int codec_variant = -1;
  1736. struct snd_soc_component *component = NULL;
  1737. struct snd_soc_component *lpass_cdc_component = NULL;
  1738. struct snd_soc_dapm_context *dapm = NULL;
  1739. struct snd_info_entry *entry = NULL;
  1740. struct snd_card *card = NULL;
  1741. struct msm_asoc_mach_data *pdata =
  1742. snd_soc_card_get_drvdata(rtd->card);
  1743. int ret = 0;
  1744. lpass_cdc_component = snd_soc_rtdcom_lookup(rtd, "lpass-cdc");
  1745. if (!lpass_cdc_component) {
  1746. pr_err("%s: could not find component for lpass-cdc\n",
  1747. __func__);
  1748. return ret;
  1749. }
  1750. dapm = snd_soc_component_get_dapm(lpass_cdc_component);
  1751. snd_soc_dapm_new_controls(dapm, msm_int_dapm_widgets,
  1752. ARRAY_SIZE(msm_int_dapm_widgets));
  1753. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic0");
  1754. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic1");
  1755. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic2");
  1756. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic3");
  1757. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic4");
  1758. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic5");
  1759. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic6");
  1760. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic7");
  1761. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic1");
  1762. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic2");
  1763. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic3");
  1764. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic4");
  1765. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic5");
  1766. lpass_cdc_set_port_map(lpass_cdc_component, ARRAY_SIZE(sm_port_map), sm_port_map);
  1767. card = rtd->card->snd_card;
  1768. if (!pdata->codec_root) {
  1769. entry = msm_snd_info_create_subdir(card->module, "codecs",
  1770. card->proc_root);
  1771. if (!entry) {
  1772. pr_debug("%s: Cannot create codecs module entry\n",
  1773. __func__);
  1774. return ret;
  1775. }
  1776. pdata->codec_root = entry;
  1777. }
  1778. lpass_cdc_info_create_codec_entry(pdata->codec_root, lpass_cdc_component);
  1779. lpass_cdc_register_wake_irq(lpass_cdc_component, false);
  1780. if (pdata->wcd_disabled)
  1781. goto done;
  1782. component = snd_soc_rtdcom_lookup(rtd, WCD939X_DRV_NAME);
  1783. if (!component) {
  1784. pr_err("%s could not find component for %s\n",
  1785. __func__, WCD939X_DRV_NAME);
  1786. return -EINVAL;
  1787. }
  1788. dapm = snd_soc_component_get_dapm(component);
  1789. card = component->card->snd_card;
  1790. snd_soc_dapm_ignore_suspend(dapm, "EAR");
  1791. snd_soc_dapm_ignore_suspend(dapm, "HPHL");
  1792. snd_soc_dapm_ignore_suspend(dapm, "HPHR");
  1793. snd_soc_dapm_ignore_suspend(dapm, "AMIC1");
  1794. snd_soc_dapm_ignore_suspend(dapm, "AMIC2");
  1795. snd_soc_dapm_ignore_suspend(dapm, "AMIC3");
  1796. snd_soc_dapm_ignore_suspend(dapm, "AMIC4");
  1797. snd_soc_dapm_sync(dapm);
  1798. pdata = snd_soc_card_get_drvdata(component->card);
  1799. if (!pdata->codec_root) {
  1800. entry = msm_snd_info_create_subdir(card->module, "codecs",
  1801. card->proc_root);
  1802. if (!entry) {
  1803. dev_dbg(component->dev, "%s: Cannot create codecs module entry\n",
  1804. __func__);
  1805. return 0;
  1806. }
  1807. pdata->codec_root = entry;
  1808. }
  1809. wcd939x_info_create_codec_entry(pdata->codec_root, component);
  1810. codec_variant = wcd939x_get_codec_variant(component);
  1811. dev_dbg(component->dev, "%s: variant %d\n", __func__, codec_variant);
  1812. if (codec_variant == WCD9395)
  1813. ret = lpass_cdc_rx_set_fir_capability(lpass_cdc_component, true);
  1814. else
  1815. ret = lpass_cdc_rx_set_fir_capability(lpass_cdc_component, false);
  1816. if (ret < 0) {
  1817. dev_err_ratelimited(component->dev, "%s: set fir capability failed: %d\n",
  1818. __func__, ret);
  1819. return ret;
  1820. }
  1821. done:
  1822. codec_reg_done = true;
  1823. msm_common_dai_link_init(rtd);
  1824. return ret;
  1825. }
  1826. static int pineapple_ssr_enable(struct device *dev, void *data)
  1827. {
  1828. struct platform_device *pdev = to_platform_device(dev);
  1829. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1830. struct snd_soc_pcm_runtime *rtd = NULL, *rtd_wcd = NULL, *rtd_wsa = NULL;
  1831. struct msm_asoc_mach_data *pdata = NULL;
  1832. int ret = 0;
  1833. if (!card) {
  1834. dev_err_ratelimited(dev, "%s: card is NULL\n", __func__);
  1835. ret = -EINVAL;
  1836. goto err;
  1837. }
  1838. if (!strcmp(card->name, "pineapple-stub-snd-card")) {
  1839. /* TODO */
  1840. dev_dbg(dev, "%s: TODO \n", __func__);
  1841. }
  1842. snd_card_notify_user(SND_CARD_STATUS_ONLINE);
  1843. dev_dbg(dev, "%s: setting snd_card to ONLINE\n", __func__);
  1844. pdata = snd_soc_card_get_drvdata(card);
  1845. if (!pdata) {
  1846. dev_dbg(dev, "%s: pdata is NULL \n", __func__);
  1847. goto err;
  1848. }
  1849. rtd_wcd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
  1850. if (!rtd_wcd) {
  1851. dev_dbg(dev,
  1852. "%s: snd_soc_get_pcm_runtime for %s failed!\n",
  1853. __func__, card->dai_link[0]);
  1854. }
  1855. if (pdata->wsa_max_devs > 0) {
  1856. rtd_wsa = snd_soc_get_pcm_runtime(card,
  1857. &card->dai_link[ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links)]);
  1858. if (!rtd_wsa) {
  1859. dev_dbg(dev,
  1860. "%s: snd_soc_get_pcm_runtime for %s failed!\n",
  1861. __func__, card->dai_link[ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links)]);
  1862. }
  1863. }
  1864. /* set UPD configuration */
  1865. if(!pdata->upd_config.backend_used) {
  1866. dev_dbg(dev,
  1867. "%s: upd- backend_used is NULL\n", __func__);
  1868. goto err;
  1869. }
  1870. if (!strcmp(pdata->upd_config.backend_used, "wsa")) {
  1871. if (!rtd_wsa)
  1872. goto err;
  1873. else
  1874. rtd = rtd_wsa;
  1875. } else if(!strcmp(pdata->upd_config.backend_used, "wcd")) {
  1876. if (!rtd_wcd &&!pdata->wcd_disabled)
  1877. goto err;
  1878. else
  1879. rtd = rtd_wcd;
  1880. } else {
  1881. dev_err_ratelimited(card->dev, "%s: Invalid backend to set UPD config\n",
  1882. __func__);
  1883. goto err;
  1884. }
  1885. msm_set_upd_config(rtd);
  1886. err:
  1887. return ret;
  1888. }
  1889. static void pineapple_ssr_disable(struct device *dev, void *data)
  1890. {
  1891. struct platform_device *pdev = to_platform_device(dev);
  1892. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1893. if (!card) {
  1894. dev_err_ratelimited(dev, "%s: card is NULL\n", __func__);
  1895. return;
  1896. }
  1897. dev_dbg(dev, "%s: setting snd_card to OFFLINE\n", __func__);
  1898. snd_card_notify_user(SND_CARD_STATUS_OFFLINE);
  1899. if (!strcmp(card->name, "pineapple-stub-snd-card")) {
  1900. /* TODO */
  1901. dev_dbg(dev, "%s: TODO \n", __func__);
  1902. }
  1903. }
  1904. static const struct snd_event_ops pineapple_ssr_ops = {
  1905. .enable = pineapple_ssr_enable,
  1906. .disable = pineapple_ssr_disable,
  1907. };
  1908. static int msm_audio_ssr_compare(struct device *dev, void *data)
  1909. {
  1910. struct device_node *node = data;
  1911. dev_dbg(dev, "%s: dev->of_node = 0x%p, node = 0x%p\n",
  1912. __func__, dev->of_node, node);
  1913. return (dev->of_node && dev->of_node == node);
  1914. }
  1915. static int msm_audio_ssr_register(struct device *dev)
  1916. {
  1917. struct device_node *np = dev->of_node;
  1918. struct snd_event_clients *ssr_clients = NULL;
  1919. struct device_node *node = NULL;
  1920. int ret = 0;
  1921. int i = 0;
  1922. for (i = 0; ; i++) {
  1923. node = of_parse_phandle(np, "qcom,msm_audio_ssr_devs", i);
  1924. if (!node)
  1925. break;
  1926. snd_event_mstr_add_client(&ssr_clients,
  1927. msm_audio_ssr_compare, node);
  1928. }
  1929. ret = snd_event_master_register(dev, &pineapple_ssr_ops,
  1930. ssr_clients, NULL);
  1931. if (!ret)
  1932. snd_event_notify(dev, SND_EVENT_UP);
  1933. return ret;
  1934. }
  1935. struct msm_common_pdata *msm_common_get_pdata(struct snd_soc_card *card)
  1936. {
  1937. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  1938. if (!pdata)
  1939. return NULL;
  1940. return pdata->common_pdata;
  1941. }
  1942. void msm_common_set_pdata(struct snd_soc_card *card,
  1943. struct msm_common_pdata *common_pdata)
  1944. {
  1945. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  1946. if (!pdata)
  1947. return;
  1948. pdata->common_pdata = common_pdata;
  1949. }
  1950. static int msm_asoc_machine_probe(struct platform_device *pdev)
  1951. {
  1952. struct snd_soc_card *card = NULL;
  1953. struct msm_asoc_mach_data *pdata = NULL;
  1954. int ret = 0;
  1955. struct clk *lpass_audio_hw_vote = NULL;
  1956. const struct of_device_id *match;
  1957. if (!pdev->dev.of_node) {
  1958. dev_err(&pdev->dev, "%s: No platform supplied from device tree\n", __func__);
  1959. return -EINVAL;
  1960. }
  1961. pdata = devm_kzalloc(&pdev->dev,
  1962. sizeof(struct msm_asoc_mach_data), GFP_KERNEL);
  1963. if (!pdata)
  1964. return -ENOMEM;
  1965. of_property_read_u32(pdev->dev.of_node,
  1966. "qcom,wcd-disabled",
  1967. &pdata->wcd_disabled);
  1968. /* Get maximum WSA device count for this platform */
  1969. ret = of_property_read_u32(pdev->dev.of_node,
  1970. "qcom,wsa-max-devs", &pdata->wsa_max_devs);
  1971. if (ret) {
  1972. dev_info(&pdev->dev,
  1973. "%s: wsa-max-devs property missing in DT %s, ret = %d\n",
  1974. __func__, pdev->dev.of_node->full_name, ret);
  1975. pdata->wsa_max_devs = 0;
  1976. }
  1977. /* Check if WSA2 Backends were used for dedicated usecase */
  1978. pdata->dedicated_wsa2 = of_find_property(pdev->dev.of_node,
  1979. "qcom,dedicated-wsa2", NULL);
  1980. card = populate_snd_card_dailinks(&pdev->dev, pdata->wsa_max_devs);
  1981. if (!card) {
  1982. dev_err(&pdev->dev, "%s: Card uninitialized\n", __func__);
  1983. ret = -EINVAL;
  1984. goto err;
  1985. }
  1986. match = of_match_node(pineapple_asoc_machine_of_match, pdev->dev.of_node);
  1987. if (!match) {
  1988. dev_err(&pdev->dev, "%s: No DT match found for sound card\n",
  1989. __func__);
  1990. ret = -EINVAL;
  1991. goto err;
  1992. }
  1993. card->dev = &pdev->dev;
  1994. platform_set_drvdata(pdev, card);
  1995. snd_soc_card_set_drvdata(card, pdata);
  1996. ret = snd_soc_of_parse_card_name(card, "qcom,model");
  1997. if (ret) {
  1998. dev_err(&pdev->dev, "%s: parse card name failed, err:%d\n",
  1999. __func__, ret);
  2000. goto err;
  2001. }
  2002. if(!strcmp(match->data, "codec")) {
  2003. ret = snd_soc_of_parse_audio_routing(card, "qcom,audio-routing");
  2004. if (ret) {
  2005. dev_err(&pdev->dev, "%s: parse audio routing failed, err:%d\n",
  2006. __func__, ret);
  2007. goto err;
  2008. }
  2009. }
  2010. ret = msm_populate_dai_link_component_of_node(card);
  2011. if (ret) {
  2012. ret = -EPROBE_DEFER;
  2013. goto err;
  2014. }
  2015. /* parse upd configuration */
  2016. msm_parse_upd_configuration(pdev, pdata);
  2017. ret = devm_snd_soc_register_card(&pdev->dev, card);
  2018. if (ret == -EPROBE_DEFER) {
  2019. if (codec_reg_done)
  2020. ret = -EINVAL;
  2021. goto err;
  2022. } else if (ret) {
  2023. dev_err(&pdev->dev, "%s: snd_soc_register_card failed (%d)\n",
  2024. __func__, ret);
  2025. goto err;
  2026. }
  2027. dev_info(&pdev->dev, "%s: Sound card %s registered\n",
  2028. __func__, card->name);
  2029. if (wcd_mbhc_cfg.enable_usbc_analog)
  2030. wcd_mbhc_cfg.swap_gnd_mic = msm_usbc_swap_gnd_mic;
  2031. pdata->wcd_usbss_handle = of_parse_phandle(pdev->dev.of_node,
  2032. "wcd939x-i2c-handle", 0);
  2033. if (!pdata->wcd_usbss_handle)
  2034. dev_dbg(&pdev->dev, "property %s not detected in node %s\n",
  2035. "wcd939x-i2c-handle", pdev->dev.of_node->full_name);
  2036. pdata->dmic01_gpio_p = of_parse_phandle(pdev->dev.of_node,
  2037. "qcom,cdc-dmic01-gpios",
  2038. 0);
  2039. pdata->dmic23_gpio_p = of_parse_phandle(pdev->dev.of_node,
  2040. "qcom,cdc-dmic23-gpios",
  2041. 0);
  2042. pdata->dmic45_gpio_p = of_parse_phandle(pdev->dev.of_node,
  2043. "qcom,cdc-dmic45-gpios",
  2044. 0);
  2045. pdata->dmic67_gpio_p = of_parse_phandle(pdev->dev.of_node,
  2046. "qcom,cdc-dmic67-gpios",
  2047. 0);
  2048. if (pdata->dmic01_gpio_p)
  2049. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic01_gpio_p, false);
  2050. if (pdata->dmic23_gpio_p)
  2051. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic23_gpio_p, false);
  2052. if (pdata->dmic45_gpio_p)
  2053. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic45_gpio_p, false);
  2054. if (pdata->dmic67_gpio_p)
  2055. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic67_gpio_p, false);
  2056. msm_common_snd_init(pdev, card);
  2057. /* Register LPASS audio hw vote */
  2058. lpass_audio_hw_vote = devm_clk_get(&pdev->dev, "lpass_audio_hw_vote");
  2059. if (IS_ERR(lpass_audio_hw_vote)) {
  2060. ret = PTR_ERR(lpass_audio_hw_vote);
  2061. dev_dbg(&pdev->dev, "%s: clk get %s failed %d\n",
  2062. __func__, "lpass_audio_hw_vote", ret);
  2063. lpass_audio_hw_vote = NULL;
  2064. ret = 0;
  2065. }
  2066. pdata->lpass_audio_hw_vote = lpass_audio_hw_vote;
  2067. pdata->core_audio_vote_count = 0;
  2068. ret = msm_audio_ssr_register(&pdev->dev);
  2069. if (ret)
  2070. pr_err("%s: Registration with SND event FWK failed ret = %d\n",
  2071. __func__, ret);
  2072. is_initial_boot = true;
  2073. /* change card status to ONLINE */
  2074. dev_dbg(&pdev->dev, "%s: setting snd_card to ONLINE\n", __func__);
  2075. snd_card_set_card_status(SND_CARD_STATUS_ONLINE);
  2076. return 0;
  2077. err:
  2078. devm_kfree(&pdev->dev, pdata);
  2079. return ret;
  2080. }
  2081. static int msm_asoc_machine_remove(struct platform_device *pdev)
  2082. {
  2083. struct snd_soc_card *card = platform_get_drvdata(pdev);
  2084. struct msm_asoc_mach_data *pdata = NULL;
  2085. struct msm_common_pdata *common_pdata = NULL;
  2086. if (card)
  2087. pdata = snd_soc_card_get_drvdata(card);
  2088. if (pdata)
  2089. common_pdata = pdata->common_pdata;
  2090. msm_common_snd_deinit(common_pdata);
  2091. snd_event_master_deregister(&pdev->dev);
  2092. snd_soc_unregister_card(card);
  2093. return 0;
  2094. }
  2095. static struct platform_driver pineapple_asoc_machine_driver = {
  2096. .driver = {
  2097. .name = DRV_NAME,
  2098. .owner = THIS_MODULE,
  2099. .pm = &snd_soc_pm_ops,
  2100. .of_match_table = pineapple_asoc_machine_of_match,
  2101. .suppress_bind_attrs = true,
  2102. },
  2103. .probe = msm_asoc_machine_probe,
  2104. .remove = msm_asoc_machine_remove,
  2105. };
  2106. static int __init msm_asoc_machine_init(void)
  2107. {
  2108. snd_card_sysfs_init();
  2109. return platform_driver_register(&pineapple_asoc_machine_driver);
  2110. }
  2111. module_init(msm_asoc_machine_init);
  2112. static void __exit msm_asoc_machine_exit(void)
  2113. {
  2114. platform_driver_unregister(&pineapple_asoc_machine_driver);
  2115. }
  2116. module_exit(msm_asoc_machine_exit);
  2117. #ifndef CONFIG_AUDIO_BTFM_PROXY
  2118. MODULE_SOFTDEP("pre: bt_fm_slim");
  2119. #else
  2120. MODULE_SOFTDEP("pre: btfmcodec");
  2121. #endif
  2122. MODULE_DESCRIPTION("ALSA SoC msm");
  2123. MODULE_LICENSE("GPL v2");
  2124. MODULE_ALIAS("platform:" DRV_NAME);
  2125. MODULE_DEVICE_TABLE(of, pineapple_asoc_machine_of_match);