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