pineapple.c 58 KB

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