pineapple.c 58 KB

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