pineapple.c 65 KB

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