pineapple.c 68 KB

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