pineapple.c 67 KB

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