pineapple.c 66 KB

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