pineapple.c 66 KB

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