pineapple.c 66 KB

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