pineapple.c 64 KB

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