pineapple.c 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188
  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. /* Dummy Dev Rx BACK END DAI Link */
  464. {
  465. .name = LPASS_BE_PCM_DUMMY_RX_0,
  466. .stream_name = LPASS_BE_PCM_DUMMY_RX_0,
  467. .playback_only = 1,
  468. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  469. SND_SOC_DPCM_TRIGGER_POST},
  470. .ignore_pmdown_time = 1,
  471. .ignore_suspend = 1,
  472. .ops = &msm_common_be_ops,
  473. SND_SOC_DAILINK_REG(pcm_dummy_rx0),
  474. },
  475. /* Dummy Dev Tx BACK END DAI Link */
  476. {
  477. .name = LPASS_BE_PCM_DUMMY_TX_1,
  478. .stream_name = LPASS_BE_PCM_DUMMY_TX_1,
  479. .capture_only = 1,
  480. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  481. SND_SOC_DPCM_TRIGGER_POST},
  482. .ignore_suspend = 1,
  483. .ops = &msm_common_be_ops,
  484. SND_SOC_DAILINK_REG(pcm_dummy_tx1),
  485. },
  486. };
  487. #ifndef CONFIG_AUDIO_BTFM_PROXY
  488. static struct snd_soc_dai_link msm_wcn_be_dai_links[] = {
  489. {
  490. .name = LPASS_BE_SLIMBUS_7_RX,
  491. .stream_name = LPASS_BE_SLIMBUS_7_RX,
  492. .playback_only = 1,
  493. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  494. SND_SOC_DPCM_TRIGGER_POST},
  495. .init = &msm_wcn_init,
  496. .ops = &msm_common_be_ops,
  497. /* dai link has playback support */
  498. .ignore_pmdown_time = 1,
  499. .ignore_suspend = 1,
  500. SND_SOC_DAILINK_REG(slimbus_7_rx),
  501. },
  502. {
  503. .name = LPASS_BE_SLIMBUS_7_TX,
  504. .stream_name = LPASS_BE_SLIMBUS_7_TX,
  505. .capture_only = 1,
  506. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  507. SND_SOC_DPCM_TRIGGER_POST},
  508. .ops = &msm_common_be_ops,
  509. .ignore_suspend = 1,
  510. SND_SOC_DAILINK_REG(slimbus_7_tx),
  511. },
  512. };
  513. #else
  514. static struct snd_soc_dai_link msm_wcn_be_dai_links[] = {
  515. {
  516. .name = LPASS_BE_BTFM_PROXY_RX_0,
  517. .stream_name = LPASS_BE_BTFM_PROXY_RX_0,
  518. .playback_only = 1,
  519. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  520. SND_SOC_DPCM_TRIGGER_POST},
  521. .ops = &msm_common_be_ops,
  522. /* dai link has playback support */
  523. .ignore_pmdown_time = 1,
  524. .ignore_suspend = 1,
  525. SND_SOC_DAILINK_REG(btfm_0_rx),
  526. },
  527. {
  528. .name = LPASS_BE_BTFM_PROXY_TX_0,
  529. .stream_name = LPASS_BE_BTFM_PROXY_TX_0,
  530. .capture_only = 1,
  531. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  532. SND_SOC_DPCM_TRIGGER_POST},
  533. .ops = &msm_common_be_ops,
  534. .ignore_suspend = 1,
  535. SND_SOC_DAILINK_REG(btfm_0_tx),
  536. },
  537. };
  538. #endif
  539. static struct snd_soc_dai_link ext_disp_be_dai_link[] = {
  540. /* DISP PORT BACK END DAI Link */
  541. {
  542. .name = LPASS_BE_DISPLAY_PORT_RX,
  543. .stream_name = LPASS_BE_DISPLAY_PORT_RX,
  544. .playback_only = 1,
  545. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  546. SND_SOC_DPCM_TRIGGER_POST},
  547. .ignore_pmdown_time = 1,
  548. .ignore_suspend = 1,
  549. SND_SOC_DAILINK_REG(display_port),
  550. },
  551. };
  552. static struct snd_soc_dai_link msm_wsa_cdc_dma_be_dai_links[] = {
  553. /* WSA CDC DMA Backend DAI Links */
  554. {
  555. .name = LPASS_BE_WSA_CDC_DMA_RX_0,
  556. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_0,
  557. .playback_only = 1,
  558. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  559. SND_SOC_DPCM_TRIGGER_POST},
  560. .ignore_pmdown_time = 1,
  561. .ignore_suspend = 1,
  562. .ops = &msm_common_be_ops,
  563. SND_SOC_DAILINK_REG(wsa_dma_rx0),
  564. .init = &msm_int_wsa_init,
  565. },
  566. {
  567. .name = LPASS_BE_WSA_CDC_DMA_RX_1,
  568. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_1,
  569. .playback_only = 1,
  570. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  571. SND_SOC_DPCM_TRIGGER_POST},
  572. .ignore_pmdown_time = 1,
  573. .ignore_suspend = 1,
  574. .ops = &msm_common_be_ops,
  575. SND_SOC_DAILINK_REG(wsa_dma_rx1),
  576. },
  577. {
  578. .name = LPASS_BE_WSA_CDC_DMA_TX_1,
  579. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_1,
  580. .capture_only = 1,
  581. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  582. SND_SOC_DPCM_TRIGGER_POST},
  583. .ignore_suspend = 1,
  584. .ops = &msm_common_be_ops,
  585. SND_SOC_DAILINK_REG(wsa_dma_tx1),
  586. },
  587. {
  588. .name = LPASS_BE_WSA_CDC_DMA_TX_0,
  589. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_0,
  590. .capture_only = 1,
  591. .ignore_suspend = 1,
  592. .ops = &msm_common_be_ops,
  593. /* .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, */
  594. SND_SOC_DAILINK_REG(vi_feedback),
  595. },
  596. {
  597. .name = LPASS_BE_WSA_CDC_DMA_TX_2,
  598. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_2,
  599. .capture_only = 1,
  600. .ignore_suspend = 1,
  601. .ops = &msm_common_be_ops,
  602. /* .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, */
  603. SND_SOC_DAILINK_REG(cps_feedback),
  604. },
  605. {
  606. .name = LPASS_BE_WSA_CDC_DMA_RX_0_VIRT,
  607. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_0_VIRT,
  608. .playback_only = 1,
  609. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  610. SND_SOC_DPCM_TRIGGER_POST},
  611. .ignore_pmdown_time = 1,
  612. .ignore_suspend = 1,
  613. .ops = &msm_common_be_ops,
  614. SND_SOC_DAILINK_REG(wsa_dma_rx0),
  615. .init = &msm_int_wsa_init,
  616. },
  617. };
  618. static struct snd_soc_dai_link msm_wsa2_cdc_dma_be_dai_links[] = {
  619. /* WSA2 CDC DMA Backend DAI Links */
  620. {
  621. .name = LPASS_BE_WSA2_CDC_DMA_RX_0,
  622. .stream_name = LPASS_BE_WSA2_CDC_DMA_RX_0,
  623. .playback_only = 1,
  624. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  625. SND_SOC_DPCM_TRIGGER_POST},
  626. .ignore_pmdown_time = 1,
  627. .ignore_suspend = 1,
  628. .ops = &msm_common_be_ops,
  629. SND_SOC_DAILINK_REG(wsa2_dma_rx0),
  630. },
  631. {
  632. .name = LPASS_BE_WSA2_CDC_DMA_RX_1,
  633. .stream_name = LPASS_BE_WSA2_CDC_DMA_RX_1,
  634. .playback_only = 1,
  635. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  636. SND_SOC_DPCM_TRIGGER_POST},
  637. .ignore_pmdown_time = 1,
  638. .ignore_suspend = 1,
  639. .ops = &msm_common_be_ops,
  640. SND_SOC_DAILINK_REG(wsa2_dma_rx1),
  641. },
  642. {
  643. .name = LPASS_BE_WSA2_CDC_DMA_TX_1,
  644. .stream_name = LPASS_BE_WSA2_CDC_DMA_TX_1,
  645. .capture_only = 1,
  646. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  647. SND_SOC_DPCM_TRIGGER_POST},
  648. .ignore_suspend = 1,
  649. .ops = &msm_common_be_ops,
  650. SND_SOC_DAILINK_REG(wsa2_dma_tx1),
  651. },
  652. {
  653. .name = LPASS_BE_WSA2_CDC_DMA_TX_0,
  654. .stream_name = LPASS_BE_WSA2_CDC_DMA_TX_0,
  655. .capture_only = 1,
  656. .ignore_suspend = 1,
  657. .ops = &msm_common_be_ops,
  658. /* .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, */
  659. SND_SOC_DAILINK_REG(wsa2_vi_feedback),
  660. },
  661. {
  662. .name = LPASS_BE_WSA2_CDC_DMA_TX_2,
  663. .stream_name = LPASS_BE_WSA2_CDC_DMA_TX_2,
  664. .capture_only = 1,
  665. .ignore_suspend = 1,
  666. .ops = &msm_common_be_ops,
  667. /* .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, */
  668. SND_SOC_DAILINK_REG(wsa2_cps_feedback),
  669. },
  670. };
  671. static struct snd_soc_dai_link msm_wsa_wsa2_cdc_dma_be_dai_links[] = {
  672. /* WSA CDC DMA Backend DAI Links */
  673. {
  674. .name = LPASS_BE_WSA_CDC_DMA_RX_0,
  675. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_0,
  676. .playback_only = 1,
  677. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  678. SND_SOC_DPCM_TRIGGER_POST},
  679. .ignore_pmdown_time = 1,
  680. .ignore_suspend = 1,
  681. .ops = &msm_common_be_ops,
  682. SND_SOC_DAILINK_REG(wsa_wsa2_dma_rx0),
  683. .init = &msm_int_wsa_init,
  684. },
  685. {
  686. .name = LPASS_BE_WSA_CDC_DMA_RX_1,
  687. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_1,
  688. .playback_only = 1,
  689. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  690. SND_SOC_DPCM_TRIGGER_POST},
  691. .ignore_pmdown_time = 1,
  692. .ignore_suspend = 1,
  693. .ops = &msm_common_be_ops,
  694. SND_SOC_DAILINK_REG(wsa_wsa2_dma_rx1),
  695. },
  696. {
  697. .name = LPASS_BE_WSA_CDC_DMA_TX_1,
  698. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_1,
  699. .capture_only = 1,
  700. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  701. SND_SOC_DPCM_TRIGGER_POST},
  702. .ignore_suspend = 1,
  703. .ops = &msm_common_be_ops,
  704. SND_SOC_DAILINK_REG(wsa_wsa2_dma_tx1),
  705. },
  706. {
  707. .name = LPASS_BE_WSA_CDC_DMA_TX_0,
  708. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_0,
  709. .capture_only = 1,
  710. .ignore_suspend = 1,
  711. .ops = &msm_common_be_ops,
  712. /* .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, */
  713. SND_SOC_DAILINK_REG(wsa_wsa2_vi_feedback),
  714. },
  715. {
  716. .name = LPASS_BE_WSA_CDC_DMA_TX_2,
  717. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_2,
  718. .capture_only = 1,
  719. .ignore_suspend = 1,
  720. .ops = &msm_common_be_ops,
  721. /* .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, */
  722. SND_SOC_DAILINK_REG(wsa_wsa2_cps_feedback),
  723. },
  724. };
  725. static struct snd_soc_dai_link msm_rx_tx_cdc_dma_be_dai_links[] = {
  726. /* RX CDC DMA Backend DAI Links */
  727. {
  728. .name = LPASS_BE_RX_CDC_DMA_RX_0,
  729. .stream_name = LPASS_BE_RX_CDC_DMA_RX_0,
  730. .playback_only = 1,
  731. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  732. SND_SOC_DPCM_TRIGGER_POST},
  733. .ignore_pmdown_time = 1,
  734. .ignore_suspend = 1,
  735. .ops = &msm_common_be_ops,
  736. SND_SOC_DAILINK_REG(rx_dma_rx0),
  737. .init = &msm_rx_tx_codec_init,
  738. },
  739. {
  740. .name = LPASS_BE_RX_CDC_DMA_RX_1,
  741. .stream_name = LPASS_BE_RX_CDC_DMA_RX_1,
  742. .playback_only = 1,
  743. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  744. SND_SOC_DPCM_TRIGGER_POST},
  745. .ignore_pmdown_time = 1,
  746. .ignore_suspend = 1,
  747. .ops = &msm_common_be_ops,
  748. SND_SOC_DAILINK_REG(rx_dma_rx1),
  749. },
  750. {
  751. .name = LPASS_BE_RX_CDC_DMA_RX_2,
  752. .stream_name = LPASS_BE_RX_CDC_DMA_RX_2,
  753. .playback_only = 1,
  754. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  755. SND_SOC_DPCM_TRIGGER_POST},
  756. .ignore_pmdown_time = 1,
  757. .ignore_suspend = 1,
  758. .ops = &msm_common_be_ops,
  759. SND_SOC_DAILINK_REG(rx_dma_rx2),
  760. },
  761. {
  762. .name = LPASS_BE_RX_CDC_DMA_RX_3,
  763. .stream_name = LPASS_BE_RX_CDC_DMA_RX_3,
  764. .playback_only = 1,
  765. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  766. SND_SOC_DPCM_TRIGGER_POST},
  767. .ignore_pmdown_time = 1,
  768. .ignore_suspend = 1,
  769. .ops = &msm_common_be_ops,
  770. SND_SOC_DAILINK_REG(rx_dma_rx3),
  771. },
  772. {
  773. .name = LPASS_BE_RX_CDC_DMA_RX_5,
  774. .stream_name = LPASS_BE_RX_CDC_DMA_RX_5,
  775. .playback_only = 1,
  776. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  777. SND_SOC_DPCM_TRIGGER_POST},
  778. .ignore_pmdown_time = 1,
  779. .ignore_suspend = 1,
  780. .ops = &msm_common_be_ops,
  781. SND_SOC_DAILINK_REG(rx_dma_rx5),
  782. },
  783. {
  784. .name = LPASS_BE_RX_CDC_DMA_RX_6,
  785. .stream_name = LPASS_BE_RX_CDC_DMA_RX_6,
  786. .playback_only = 1,
  787. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  788. SND_SOC_DPCM_TRIGGER_POST},
  789. .ignore_pmdown_time = 1,
  790. .ignore_suspend = 1,
  791. .ops = &msm_common_be_ops,
  792. SND_SOC_DAILINK_REG(rx_dma_rx6),
  793. },
  794. /* TX CDC DMA Backend DAI Links */
  795. {
  796. .name = LPASS_BE_TX_CDC_DMA_TX_3,
  797. .stream_name = LPASS_BE_TX_CDC_DMA_TX_3,
  798. .capture_only = 1,
  799. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  800. SND_SOC_DPCM_TRIGGER_POST},
  801. .ignore_suspend = 1,
  802. .ops = &msm_common_be_ops,
  803. SND_SOC_DAILINK_REG(tx_dma_tx3),
  804. },
  805. {
  806. .name = LPASS_BE_TX_CDC_DMA_TX_4,
  807. .stream_name = LPASS_BE_TX_CDC_DMA_TX_4,
  808. .capture_only = 1,
  809. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  810. SND_SOC_DPCM_TRIGGER_POST},
  811. .ignore_suspend = 1,
  812. .ops = &msm_common_be_ops,
  813. SND_SOC_DAILINK_REG(tx_dma_tx4),
  814. },
  815. };
  816. static struct snd_soc_dai_link msm_va_cdc_dma_be_dai_links[] = {
  817. {
  818. .name = LPASS_BE_VA_CDC_DMA_TX_0,
  819. .stream_name = LPASS_BE_VA_CDC_DMA_TX_0,
  820. .capture_only = 1,
  821. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  822. SND_SOC_DPCM_TRIGGER_POST},
  823. .ignore_suspend = 1,
  824. .ops = &msm_common_be_ops,
  825. SND_SOC_DAILINK_REG(va_dma_tx0),
  826. },
  827. {
  828. .name = LPASS_BE_VA_CDC_DMA_TX_1,
  829. .stream_name = LPASS_BE_VA_CDC_DMA_TX_1,
  830. .capture_only = 1,
  831. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  832. SND_SOC_DPCM_TRIGGER_POST},
  833. .ignore_suspend = 1,
  834. .ops = &msm_common_be_ops,
  835. SND_SOC_DAILINK_REG(va_dma_tx1),
  836. },
  837. {
  838. .name = LPASS_BE_VA_CDC_DMA_TX_2,
  839. .stream_name = LPASS_BE_VA_CDC_DMA_TX_2,
  840. .capture_only = 1,
  841. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  842. SND_SOC_DPCM_TRIGGER_POST},
  843. .ignore_suspend = 1,
  844. .ops = &msm_common_be_ops,
  845. SND_SOC_DAILINK_REG(va_dma_tx2),
  846. },
  847. };
  848. /*
  849. * I2S interface pinctrl mapping
  850. * ------------------------------------
  851. * Primary - pri_mi2s
  852. * Secondary - lpi_i2s3
  853. * Tertiary - tert_mi2s
  854. * Quaternary - quat_mi2s (lpi_i2s0)
  855. * Quinary - lpi_i2s1
  856. * Senary - lpi_i2s2
  857. * ------------------------------------
  858. */
  859. static struct snd_soc_dai_link msm_mi2s_dai_links[] = {
  860. {
  861. .name = LPASS_BE_PRI_MI2S_RX,
  862. .stream_name = LPASS_BE_PRI_MI2S_RX,
  863. .playback_only = 1,
  864. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  865. SND_SOC_DPCM_TRIGGER_POST},
  866. .ops = &msm_common_be_ops,
  867. .ignore_suspend = 1,
  868. .ignore_pmdown_time = 1,
  869. SND_SOC_DAILINK_REG(pri_mi2s_rx),
  870. },
  871. {
  872. .name = LPASS_BE_PRI_MI2S_TX,
  873. .stream_name = LPASS_BE_PRI_MI2S_TX,
  874. .capture_only = 1,
  875. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  876. SND_SOC_DPCM_TRIGGER_POST},
  877. .ops = &msm_common_be_ops,
  878. .ignore_suspend = 1,
  879. SND_SOC_DAILINK_REG(pri_mi2s_tx),
  880. },
  881. {
  882. .name = LPASS_BE_SEC_MI2S_RX,
  883. .stream_name = LPASS_BE_SEC_MI2S_RX,
  884. .playback_only = 1,
  885. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  886. SND_SOC_DPCM_TRIGGER_POST},
  887. .ops = &msm_common_be_ops,
  888. .ignore_suspend = 1,
  889. .ignore_pmdown_time = 1,
  890. SND_SOC_DAILINK_REG(sec_mi2s_rx),
  891. },
  892. {
  893. .name = LPASS_BE_SEC_MI2S_TX,
  894. .stream_name = LPASS_BE_SEC_MI2S_TX,
  895. .capture_only = 1,
  896. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  897. SND_SOC_DPCM_TRIGGER_POST},
  898. .ops = &msm_common_be_ops,
  899. .ignore_suspend = 1,
  900. SND_SOC_DAILINK_REG(sec_mi2s_tx),
  901. },
  902. {
  903. .name = LPASS_BE_TERT_MI2S_RX,
  904. .stream_name = LPASS_BE_TERT_MI2S_RX,
  905. .playback_only = 1,
  906. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  907. SND_SOC_DPCM_TRIGGER_POST},
  908. .ops = &msm_common_be_ops,
  909. .ignore_suspend = 1,
  910. .ignore_pmdown_time = 1,
  911. SND_SOC_DAILINK_REG(tert_mi2s_rx),
  912. },
  913. {
  914. .name = LPASS_BE_TERT_MI2S_TX,
  915. .stream_name = LPASS_BE_TERT_MI2S_TX,
  916. .capture_only = 1,
  917. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  918. SND_SOC_DPCM_TRIGGER_POST},
  919. .ops = &msm_common_be_ops,
  920. .ignore_suspend = 1,
  921. SND_SOC_DAILINK_REG(tert_mi2s_tx),
  922. },
  923. {
  924. .name = LPASS_BE_QUAT_MI2S_RX,
  925. .stream_name = LPASS_BE_QUAT_MI2S_RX,
  926. .playback_only = 1,
  927. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  928. SND_SOC_DPCM_TRIGGER_POST},
  929. .ops = &msm_common_be_ops,
  930. .ignore_suspend = 1,
  931. .ignore_pmdown_time = 1,
  932. SND_SOC_DAILINK_REG(quat_mi2s_rx),
  933. },
  934. {
  935. .name = LPASS_BE_QUAT_MI2S_TX,
  936. .stream_name = LPASS_BE_QUAT_MI2S_TX,
  937. .capture_only = 1,
  938. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  939. SND_SOC_DPCM_TRIGGER_POST},
  940. .ops = &msm_common_be_ops,
  941. .ignore_suspend = 1,
  942. SND_SOC_DAILINK_REG(quat_mi2s_tx),
  943. },
  944. {
  945. .name = LPASS_BE_QUIN_MI2S_RX,
  946. .stream_name = LPASS_BE_QUIN_MI2S_RX,
  947. .playback_only = 1,
  948. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  949. SND_SOC_DPCM_TRIGGER_POST},
  950. .ops = &msm_common_be_ops,
  951. .ignore_suspend = 1,
  952. .ignore_pmdown_time = 1,
  953. SND_SOC_DAILINK_REG(quin_mi2s_rx),
  954. },
  955. {
  956. .name = LPASS_BE_QUIN_MI2S_TX,
  957. .stream_name = LPASS_BE_QUIN_MI2S_TX,
  958. .capture_only = 1,
  959. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  960. SND_SOC_DPCM_TRIGGER_POST},
  961. .ops = &msm_common_be_ops,
  962. .ignore_suspend = 1,
  963. SND_SOC_DAILINK_REG(quin_mi2s_tx),
  964. },
  965. {
  966. .name = LPASS_BE_SEN_MI2S_RX,
  967. .stream_name = LPASS_BE_SEN_MI2S_RX,
  968. .playback_only = 1,
  969. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  970. SND_SOC_DPCM_TRIGGER_POST},
  971. .ops = &msm_common_be_ops,
  972. .ignore_suspend = 1,
  973. .ignore_pmdown_time = 1,
  974. SND_SOC_DAILINK_REG(sen_mi2s_rx),
  975. },
  976. {
  977. .name = LPASS_BE_SEN_MI2S_TX,
  978. .stream_name = LPASS_BE_SEN_MI2S_TX,
  979. .capture_only = 1,
  980. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  981. SND_SOC_DPCM_TRIGGER_POST},
  982. .ops = &msm_common_be_ops,
  983. .ignore_suspend = 1,
  984. SND_SOC_DAILINK_REG(sen_mi2s_tx),
  985. },
  986. {
  987. .name = LPASS_BE_SEP_MI2S_RX,
  988. .stream_name = LPASS_BE_SEP_MI2S_RX,
  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(sep_mi2s_rx),
  996. },
  997. {
  998. .name = LPASS_BE_SEP_MI2S_TX,
  999. .stream_name = LPASS_BE_SEP_MI2S_TX,
  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(sep_mi2s_tx),
  1006. },
  1007. };
  1008. static struct snd_soc_dai_link msm_tdm_dai_links[] = {
  1009. {
  1010. .name = LPASS_BE_PRI_TDM_RX_0,
  1011. .stream_name = LPASS_BE_PRI_TDM_RX_0,
  1012. .playback_only = 1,
  1013. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1014. SND_SOC_DPCM_TRIGGER_POST},
  1015. .ops = &msm_common_be_ops,
  1016. .ignore_suspend = 1,
  1017. .ignore_pmdown_time = 1,
  1018. SND_SOC_DAILINK_REG(pri_tdm_rx_0),
  1019. },
  1020. {
  1021. .name = LPASS_BE_PRI_TDM_TX_0,
  1022. .stream_name = LPASS_BE_PRI_TDM_TX_0,
  1023. .capture_only = 1,
  1024. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1025. SND_SOC_DPCM_TRIGGER_POST},
  1026. .ops = &msm_common_be_ops,
  1027. .ignore_suspend = 1,
  1028. SND_SOC_DAILINK_REG(pri_tdm_tx_0),
  1029. },
  1030. {
  1031. .name = LPASS_BE_SEC_TDM_RX_0,
  1032. .stream_name = LPASS_BE_SEC_TDM_RX_0,
  1033. .playback_only = 1,
  1034. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1035. SND_SOC_DPCM_TRIGGER_POST},
  1036. .ops = &msm_common_be_ops,
  1037. .ignore_suspend = 1,
  1038. .ignore_pmdown_time = 1,
  1039. SND_SOC_DAILINK_REG(sec_tdm_rx_0),
  1040. },
  1041. {
  1042. .name = LPASS_BE_SEC_TDM_TX_0,
  1043. .stream_name = LPASS_BE_SEC_TDM_TX_0,
  1044. .capture_only = 1,
  1045. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1046. SND_SOC_DPCM_TRIGGER_POST},
  1047. .ops = &msm_common_be_ops,
  1048. .ignore_suspend = 1,
  1049. SND_SOC_DAILINK_REG(sec_tdm_tx_0),
  1050. },
  1051. {
  1052. .name = LPASS_BE_TERT_TDM_RX_0,
  1053. .stream_name = LPASS_BE_TERT_TDM_RX_0,
  1054. .playback_only = 1,
  1055. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1056. SND_SOC_DPCM_TRIGGER_POST},
  1057. .ops = &msm_common_be_ops,
  1058. .ignore_suspend = 1,
  1059. .ignore_pmdown_time = 1,
  1060. SND_SOC_DAILINK_REG(tert_tdm_rx_0),
  1061. },
  1062. {
  1063. .name = LPASS_BE_TERT_TDM_TX_0,
  1064. .stream_name = LPASS_BE_TERT_TDM_TX_0,
  1065. .capture_only = 1,
  1066. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1067. SND_SOC_DPCM_TRIGGER_POST},
  1068. .ops = &msm_common_be_ops,
  1069. .ignore_suspend = 1,
  1070. SND_SOC_DAILINK_REG(tert_tdm_tx_0),
  1071. },
  1072. {
  1073. .name = LPASS_BE_QUAT_TDM_RX_0,
  1074. .stream_name = LPASS_BE_QUAT_TDM_RX_0,
  1075. .playback_only = 1,
  1076. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1077. SND_SOC_DPCM_TRIGGER_POST},
  1078. .ops = &msm_common_be_ops,
  1079. .ignore_suspend = 1,
  1080. .ignore_pmdown_time = 1,
  1081. SND_SOC_DAILINK_REG(quat_tdm_rx_0),
  1082. },
  1083. {
  1084. .name = LPASS_BE_QUAT_TDM_TX_0,
  1085. .stream_name = LPASS_BE_QUAT_TDM_TX_0,
  1086. .capture_only = 1,
  1087. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1088. SND_SOC_DPCM_TRIGGER_POST},
  1089. .ops = &msm_common_be_ops,
  1090. .ignore_suspend = 1,
  1091. SND_SOC_DAILINK_REG(quat_tdm_tx_0),
  1092. },
  1093. {
  1094. .name = LPASS_BE_QUIN_TDM_RX_0,
  1095. .stream_name = LPASS_BE_QUIN_TDM_RX_0,
  1096. .playback_only = 1,
  1097. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1098. SND_SOC_DPCM_TRIGGER_POST},
  1099. .ops = &msm_common_be_ops,
  1100. .ignore_suspend = 1,
  1101. .ignore_pmdown_time = 1,
  1102. SND_SOC_DAILINK_REG(quin_tdm_rx_0),
  1103. },
  1104. {
  1105. .name = LPASS_BE_QUIN_TDM_TX_0,
  1106. .stream_name = LPASS_BE_QUIN_TDM_TX_0,
  1107. .capture_only = 1,
  1108. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1109. SND_SOC_DPCM_TRIGGER_POST},
  1110. .ops = &msm_common_be_ops,
  1111. .ignore_suspend = 1,
  1112. SND_SOC_DAILINK_REG(quin_tdm_tx_0),
  1113. },
  1114. {
  1115. .name = LPASS_BE_SEN_TDM_RX_0,
  1116. .stream_name = LPASS_BE_SEN_TDM_RX_0,
  1117. .playback_only = 1,
  1118. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1119. SND_SOC_DPCM_TRIGGER_POST},
  1120. .ops = &msm_common_be_ops,
  1121. .ignore_suspend = 1,
  1122. .ignore_pmdown_time = 1,
  1123. SND_SOC_DAILINK_REG(sen_tdm_rx_0),
  1124. },
  1125. {
  1126. .name = LPASS_BE_SEN_TDM_TX_0,
  1127. .stream_name = LPASS_BE_SEN_TDM_TX_0,
  1128. .capture_only = 1,
  1129. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1130. SND_SOC_DPCM_TRIGGER_POST},
  1131. .ops = &msm_common_be_ops,
  1132. .ignore_suspend = 1,
  1133. SND_SOC_DAILINK_REG(sen_tdm_tx_0),
  1134. },
  1135. {
  1136. .name = LPASS_BE_SEP_TDM_RX_0,
  1137. .stream_name = LPASS_BE_SEP_TDM_RX_0,
  1138. .playback_only = 1,
  1139. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1140. SND_SOC_DPCM_TRIGGER_POST},
  1141. .ops = &msm_common_be_ops,
  1142. .ignore_suspend = 1,
  1143. .ignore_pmdown_time = 1,
  1144. SND_SOC_DAILINK_REG(sep_tdm_rx_0),
  1145. },
  1146. {
  1147. .name = LPASS_BE_SEP_TDM_TX_0,
  1148. .stream_name = LPASS_BE_SEP_TDM_TX_0,
  1149. .capture_only = 1,
  1150. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1151. SND_SOC_DPCM_TRIGGER_POST},
  1152. .ops = &msm_common_be_ops,
  1153. .ignore_suspend = 1,
  1154. SND_SOC_DAILINK_REG(sep_tdm_tx_0),
  1155. },
  1156. };
  1157. static struct snd_soc_dai_link msm_pineapple_dai_links[
  1158. ARRAY_SIZE(msm_wsa_cdc_dma_be_dai_links) +
  1159. ARRAY_SIZE(msm_wsa2_cdc_dma_be_dai_links) +
  1160. ARRAY_SIZE(msm_wsa_wsa2_cdc_dma_be_dai_links) +
  1161. ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links) +
  1162. ARRAY_SIZE(msm_va_cdc_dma_be_dai_links) +
  1163. ARRAY_SIZE(ext_disp_be_dai_link) +
  1164. ARRAY_SIZE(msm_common_be_dai_links) +
  1165. ARRAY_SIZE(msm_wcn_be_dai_links) +
  1166. ARRAY_SIZE(msm_mi2s_dai_links) +
  1167. ARRAY_SIZE(msm_tdm_dai_links)];
  1168. static int msm_populate_dai_link_component_of_node(
  1169. struct snd_soc_card *card)
  1170. {
  1171. int i, j, index, ret = 0;
  1172. struct device *cdev = card->dev;
  1173. struct snd_soc_dai_link *dai_link = card->dai_link;
  1174. struct device_node *np = NULL;
  1175. int codecs_enabled = 0;
  1176. struct snd_soc_dai_link_component *codecs_comp = NULL;
  1177. if (!cdev) {
  1178. dev_err_ratelimited(cdev, "%s: Sound card device memory NULL\n", __func__);
  1179. return -ENODEV;
  1180. }
  1181. for (i = 0; i < card->num_links; i++) {
  1182. if (dai_link[i].init == NULL)
  1183. dai_link[i].init = &msm_common_dai_link_init;
  1184. /* populate codec_of_node for snd card dai links */
  1185. if (dai_link[i].num_codecs > 0) {
  1186. for (j = 0; j < dai_link[i].num_codecs; j++) {
  1187. if (dai_link[i].codecs[j].of_node ||
  1188. !dai_link[i].codecs[j].name)
  1189. continue;
  1190. index = of_property_match_string(cdev->of_node,
  1191. "asoc-codec-names",
  1192. dai_link[i].codecs[j].name);
  1193. if (index < 0)
  1194. continue;
  1195. np = of_parse_phandle(cdev->of_node,
  1196. "asoc-codec",
  1197. index);
  1198. if (!np) {
  1199. dev_err_ratelimited(cdev,
  1200. "%s: retrieving phandle for codec %s failed\n",
  1201. __func__,
  1202. dai_link[i].codecs[j].name);
  1203. ret = -ENODEV;
  1204. goto err;
  1205. }
  1206. dai_link[i].codecs[j].of_node = np;
  1207. dai_link[i].codecs[j].name = NULL;
  1208. }
  1209. }
  1210. }
  1211. /* In multi-codec scenario, check if codecs are enabled for this platform */
  1212. for (i = 0; i < card->num_links; i++) {
  1213. codecs_enabled = 0;
  1214. if (dai_link[i].num_codecs > 1) {
  1215. for (j = 0; j < dai_link[i].num_codecs; j++) {
  1216. if (!dai_link[i].codecs[j].of_node)
  1217. continue;
  1218. np = dai_link[i].codecs[j].of_node;
  1219. if (!of_device_is_available(np)) {
  1220. dev_err_ratelimited(cdev, "%s: codec is disabled: %s\n",
  1221. __func__,
  1222. np->full_name);
  1223. dai_link[i].codecs[j].of_node = NULL;
  1224. continue;
  1225. }
  1226. codecs_enabled++;
  1227. }
  1228. if (codecs_enabled > 0 &&
  1229. codecs_enabled < dai_link[i].num_codecs) {
  1230. codecs_comp = devm_kzalloc(cdev,
  1231. sizeof(struct snd_soc_dai_link_component)
  1232. * codecs_enabled, GFP_KERNEL);
  1233. if (!codecs_comp) {
  1234. dev_err_ratelimited(cdev,
  1235. "%s: %s dailink codec component alloc failed\n",
  1236. __func__, dai_link[i].name);
  1237. ret = -ENOMEM;
  1238. goto err;
  1239. }
  1240. index = 0;
  1241. for (j = 0; j < dai_link[i].num_codecs; j++) {
  1242. if(dai_link[i].codecs[j].of_node) {
  1243. codecs_comp[index].of_node =
  1244. dai_link[i].codecs[j].of_node;
  1245. codecs_comp[index].dai_name =
  1246. dai_link[i].codecs[j].dai_name;
  1247. codecs_comp[index].name = NULL;
  1248. index++;
  1249. }
  1250. }
  1251. dai_link[i].codecs = codecs_comp;
  1252. dai_link[i].num_codecs = codecs_enabled;
  1253. }
  1254. }
  1255. }
  1256. err:
  1257. return ret;
  1258. }
  1259. static int msm_audrx_stub_init(struct snd_soc_pcm_runtime *rtd)
  1260. {
  1261. return 0;
  1262. }
  1263. static int msm_snd_stub_hw_params(struct snd_pcm_substream *substream,
  1264. struct snd_pcm_hw_params *params)
  1265. {
  1266. return 0;
  1267. }
  1268. static struct snd_soc_ops msm_stub_be_ops = {
  1269. .hw_params = msm_snd_stub_hw_params,
  1270. };
  1271. struct snd_soc_card snd_soc_card_stub_msm = {
  1272. .name = "pineapple-stub-snd-card",
  1273. };
  1274. static struct snd_soc_dai_link msm_stub_be_dai_links[] = {
  1275. /* Backend DAI Links */
  1276. {
  1277. .name = LPASS_BE_PRI_AUXPCM_RX,
  1278. .stream_name = LPASS_BE_PRI_AUXPCM_RX,
  1279. .playback_only = 1,
  1280. .init = &msm_audrx_stub_init,
  1281. .ignore_pmdown_time = 1,
  1282. .ignore_suspend = 1,
  1283. .ops = &msm_stub_be_ops,
  1284. SND_SOC_DAILINK_REG(auxpcm_rx),
  1285. },
  1286. {
  1287. .name = LPASS_BE_PRI_AUXPCM_TX,
  1288. .stream_name = LPASS_BE_PRI_AUXPCM_TX,
  1289. .capture_only = 1,
  1290. .ignore_suspend = 1,
  1291. .ops = &msm_stub_be_ops,
  1292. SND_SOC_DAILINK_REG(auxpcm_tx),
  1293. },
  1294. };
  1295. static struct snd_soc_dai_link msm_stub_dai_links[
  1296. ARRAY_SIZE(msm_stub_be_dai_links)];
  1297. static const struct of_device_id pineapple_asoc_machine_of_match[] = {
  1298. { .compatible = "qcom,pineapple-asoc-snd",
  1299. .data = "codec"},
  1300. { .compatible = "qcom,pineapple-asoc-snd-stub",
  1301. .data = "stub_codec"},
  1302. {},
  1303. };
  1304. static int msm_snd_card_late_probe(struct snd_soc_card *card)
  1305. {
  1306. struct snd_soc_component *component = NULL;
  1307. struct snd_soc_pcm_runtime *rtd;
  1308. struct msm_asoc_mach_data *pdata;
  1309. int ret = 0;
  1310. void *mbhc_calibration;
  1311. pdata = snd_soc_card_get_drvdata(card);
  1312. if (!pdata)
  1313. return -EINVAL;
  1314. if (pdata->wcd_disabled)
  1315. return 0;
  1316. rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
  1317. if (!rtd) {
  1318. dev_err(card->dev,
  1319. "%s: snd_soc_get_pcm_runtime for %s failed!\n",
  1320. __func__, card->dai_link[0]);
  1321. return -EINVAL;
  1322. }
  1323. component = snd_soc_rtdcom_lookup(rtd, WCD939X_DRV_NAME);
  1324. if (!component) {
  1325. pr_err("%s component is NULL\n", __func__);
  1326. return -EINVAL;
  1327. }
  1328. mbhc_calibration = def_wcd_mbhc_cal();
  1329. if (!mbhc_calibration)
  1330. return -ENOMEM;
  1331. wcd_mbhc_cfg.calibration = mbhc_calibration;
  1332. ret = wcd939x_mbhc_hs_detect(component, &wcd_mbhc_cfg);
  1333. if (ret) {
  1334. dev_err(component->dev, "%s: mbhc hs detect failed, err:%d\n",
  1335. __func__, ret);
  1336. goto err_hs_detect;
  1337. }
  1338. return 0;
  1339. err_hs_detect:
  1340. kfree(mbhc_calibration);
  1341. return ret;
  1342. }
  1343. static struct snd_soc_card *populate_snd_card_dailinks(struct device *dev, int wsa_max_devs)
  1344. {
  1345. struct snd_soc_card *card = NULL;
  1346. struct snd_soc_dai_link *dailink = NULL;
  1347. int total_links = 0;
  1348. int rc = 0;
  1349. u32 val = 0;
  1350. const struct of_device_id *match;
  1351. match = of_match_node(pineapple_asoc_machine_of_match, dev->of_node);
  1352. if (!match) {
  1353. dev_err_ratelimited(dev, "%s: No DT match found for sound card\n",
  1354. __func__);
  1355. return NULL;
  1356. }
  1357. if (!strcmp(match->data, "codec")) {
  1358. card = &snd_soc_card_pineapple_msm;
  1359. /* late probe uses dai link at index '0' to get wcd component */
  1360. memcpy(msm_pineapple_dai_links + total_links,
  1361. msm_rx_tx_cdc_dma_be_dai_links,
  1362. sizeof(msm_rx_tx_cdc_dma_be_dai_links));
  1363. total_links +=
  1364. ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links);
  1365. switch (wsa_max_devs) {
  1366. case MONO_SPEAKER:
  1367. case STEREO_SPEAKER:
  1368. memcpy(msm_pineapple_dai_links + total_links,
  1369. msm_wsa_cdc_dma_be_dai_links,
  1370. sizeof(msm_wsa_cdc_dma_be_dai_links));
  1371. total_links += ARRAY_SIZE(msm_wsa_cdc_dma_be_dai_links);
  1372. break;
  1373. case QUAD_SPEAKER:
  1374. memcpy(msm_pineapple_dai_links + total_links,
  1375. msm_wsa2_cdc_dma_be_dai_links,
  1376. sizeof(msm_wsa2_cdc_dma_be_dai_links));
  1377. total_links += ARRAY_SIZE(msm_wsa2_cdc_dma_be_dai_links);
  1378. memcpy(msm_pineapple_dai_links + total_links,
  1379. msm_wsa_wsa2_cdc_dma_be_dai_links,
  1380. sizeof(msm_wsa_wsa2_cdc_dma_be_dai_links));
  1381. total_links += ARRAY_SIZE(msm_wsa_wsa2_cdc_dma_be_dai_links);
  1382. break;
  1383. default:
  1384. dev_dbg(dev,
  1385. "%s: Unexpected number of WSAs, wsa_max_devs: %d\n",
  1386. __func__, wsa_max_devs);
  1387. break;
  1388. }
  1389. memcpy(msm_pineapple_dai_links + total_links,
  1390. msm_va_cdc_dma_be_dai_links,
  1391. sizeof(msm_va_cdc_dma_be_dai_links));
  1392. total_links += ARRAY_SIZE(msm_va_cdc_dma_be_dai_links);
  1393. memcpy(msm_pineapple_dai_links + total_links,
  1394. msm_common_be_dai_links,
  1395. sizeof(msm_common_be_dai_links));
  1396. total_links += ARRAY_SIZE(msm_common_be_dai_links);
  1397. rc = of_property_read_u32(dev->of_node,
  1398. "qcom,mi2s-audio-intf", &val);
  1399. if (!rc && val) {
  1400. memcpy(msm_pineapple_dai_links + total_links,
  1401. msm_mi2s_dai_links,
  1402. sizeof(msm_mi2s_dai_links));
  1403. total_links += ARRAY_SIZE(msm_mi2s_dai_links);
  1404. }
  1405. rc = of_property_read_u32(dev->of_node,
  1406. "qcom,tdm-audio-intf", &val);
  1407. if (!rc && val) {
  1408. memcpy(msm_pineapple_dai_links + total_links,
  1409. msm_tdm_dai_links,
  1410. sizeof(msm_tdm_dai_links));
  1411. total_links += ARRAY_SIZE(msm_tdm_dai_links);
  1412. }
  1413. rc = of_property_read_u32(dev->of_node,
  1414. "qcom,ext-disp-audio-rx", &val);
  1415. if (!rc && val) {
  1416. dev_dbg(dev, "%s(): ext disp audio support present\n",
  1417. __func__);
  1418. memcpy(msm_pineapple_dai_links + total_links,
  1419. ext_disp_be_dai_link,
  1420. sizeof(ext_disp_be_dai_link));
  1421. total_links += ARRAY_SIZE(ext_disp_be_dai_link);
  1422. }
  1423. rc = of_property_read_u32(dev->of_node, "qcom,wcn-bt", &val);
  1424. if (!rc && val) {
  1425. dev_dbg(dev, "%s(): WCN BT support present\n",
  1426. __func__);
  1427. memcpy(msm_pineapple_dai_links + total_links,
  1428. msm_wcn_be_dai_links,
  1429. sizeof(msm_wcn_be_dai_links));
  1430. total_links += ARRAY_SIZE(msm_wcn_be_dai_links);
  1431. }
  1432. dailink = msm_pineapple_dai_links;
  1433. } else if(!strcmp(match->data, "stub_codec")) {
  1434. card = &snd_soc_card_stub_msm;
  1435. memcpy(msm_stub_dai_links,
  1436. msm_stub_be_dai_links,
  1437. sizeof(msm_stub_be_dai_links));
  1438. dailink = msm_stub_dai_links;
  1439. total_links = ARRAY_SIZE(msm_stub_be_dai_links);
  1440. }
  1441. if (card) {
  1442. card->dai_link = dailink;
  1443. card->num_links = total_links;
  1444. if (!strcmp(match->data, "codec"))
  1445. card->late_probe = msm_snd_card_late_probe;
  1446. }
  1447. return card;
  1448. }
  1449. static int msm_int_wsa883x_init(struct snd_soc_pcm_runtime *rtd)
  1450. {
  1451. u8 spkleft_ports[WSA883X_MAX_SWR_PORTS] = {0, 1, 2, 3};
  1452. u8 spkright_ports[WSA883X_MAX_SWR_PORTS] = {0, 1, 2, 3};
  1453. u8 spkleft_port_types[WSA883X_MAX_SWR_PORTS] = {SPKR_L, SPKR_L_COMP,
  1454. SPKR_L_BOOST, SPKR_L_VI};
  1455. u8 spkright_port_types[WSA883X_MAX_SWR_PORTS] = {SPKR_R, SPKR_R_COMP,
  1456. SPKR_R_BOOST, SPKR_R_VI};
  1457. unsigned int ch_rate[WSA883X_MAX_SWR_PORTS] = {SWR_CLK_RATE_2P4MHZ, SWR_CLK_RATE_0P6MHZ,
  1458. SWR_CLK_RATE_0P3MHZ, SWR_CLK_RATE_1P2MHZ};
  1459. unsigned int ch_mask[WSA883X_MAX_SWR_PORTS] = {0x1, 0xF, 0x3, 0x3};
  1460. struct snd_soc_component *component = NULL;
  1461. struct msm_asoc_mach_data *pdata =
  1462. snd_soc_card_get_drvdata(rtd->card);
  1463. if (pdata->wsa_max_devs > 0) {
  1464. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.1");
  1465. if (!component) {
  1466. pr_err("%s: wsa-codec.1 component is NULL\n", __func__);
  1467. return -EINVAL;
  1468. }
  1469. wsa883x_set_channel_map(component, &spkleft_ports[0],
  1470. WSA883X_MAX_SWR_PORTS, &ch_mask[0],
  1471. &ch_rate[0], &spkleft_port_types[0]);
  1472. wsa883x_codec_info_create_codec_entry(pdata->codec_root,
  1473. component);
  1474. }
  1475. /* If current platform has more than one WSA */
  1476. if (pdata->wsa_max_devs > 1) {
  1477. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.2");
  1478. if (!component) {
  1479. pr_err("%s: wsa-codec.2 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. if (pdata->wsa_max_devs > 2) {
  1489. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.3");
  1490. if (!component) {
  1491. pr_err("%s: wsa-codec.3 component is NULL\n", __func__);
  1492. return -EINVAL;
  1493. }
  1494. wsa883x_set_channel_map(component, &spkleft_ports[0],
  1495. WSA883X_MAX_SWR_PORTS, &ch_mask[0],
  1496. &ch_rate[0], &spkleft_port_types[0]);
  1497. wsa883x_codec_info_create_codec_entry(pdata->codec_root,
  1498. component);
  1499. }
  1500. if (pdata->wsa_max_devs > 3) {
  1501. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.4");
  1502. if (!component) {
  1503. pr_err("%s: wsa-codec.4 component is NULL\n", __func__);
  1504. return -EINVAL;
  1505. }
  1506. wsa883x_set_channel_map(component, &spkright_ports[0],
  1507. WSA883X_MAX_SWR_PORTS, &ch_mask[0],
  1508. &ch_rate[0], &spkright_port_types[0]);
  1509. wsa883x_codec_info_create_codec_entry(pdata->codec_root,
  1510. component);
  1511. }
  1512. msm_common_dai_link_init(rtd);
  1513. return 0;
  1514. }
  1515. static int msm_int_wsa884x_init(struct snd_soc_pcm_runtime *rtd)
  1516. {
  1517. u8 spkleft_ports[WSA884X_MAX_SWR_PORTS] = {0, 1, 2, 3, 4, 5};
  1518. u8 spkright_ports[WSA884X_MAX_SWR_PORTS] = {0, 1, 2, 3, 4, 5};
  1519. u8 spkleft_port_types[WSA884X_MAX_SWR_PORTS] = {SPKR_L, SPKR_L_COMP,
  1520. SPKR_L_BOOST, PBR, SPKR_L_VI, CPS};
  1521. u8 spkright_port_types[WSA884X_MAX_SWR_PORTS] = {SPKR_R, SPKR_R_COMP,
  1522. SPKR_R_BOOST, PBR, SPKR_R_VI, CPS};
  1523. unsigned int ch_rate[WSA884X_MAX_SWR_PORTS] = {SWR_CLK_RATE_2P4MHZ, SWR_CLK_RATE_0P6MHZ,
  1524. SWR_CLK_RATE_0P3MHZ, SWR_CLK_RATE_48KHZ,
  1525. SWR_CLK_RATE_1P2MHZ, SWR_CLK_RATE_24KHZ};
  1526. unsigned int ch_mask[WSA884X_MAX_SWR_PORTS] = {0x1, 0xF, 0x3, 0x1, 0x3, 0x3};
  1527. struct snd_soc_component *component = NULL;
  1528. struct msm_asoc_mach_data *pdata =
  1529. snd_soc_card_get_drvdata(rtd->card);
  1530. if (pdata->wsa_max_devs > 0) {
  1531. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.1");
  1532. if (!component) {
  1533. pr_err("%s: wsa-codec.1 component is NULL\n", __func__);
  1534. return -EINVAL;
  1535. }
  1536. wsa884x_set_channel_map(component, &spkleft_ports[0],
  1537. WSA884X_MAX_SWR_PORTS, &ch_mask[0],
  1538. &ch_rate[0], &spkleft_port_types[0]);
  1539. wsa884x_codec_info_create_codec_entry(pdata->codec_root,
  1540. component);
  1541. }
  1542. /* If current platform has more than one WSA */
  1543. if (pdata->wsa_max_devs > 1) {
  1544. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.2");
  1545. if (!component) {
  1546. pr_err("%s: wsa-codec.2 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. if (pdata->wsa_max_devs > 2) {
  1556. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.3");
  1557. if (!component) {
  1558. pr_err("%s: wsa-codec.3 component is NULL\n", __func__);
  1559. return -EINVAL;
  1560. }
  1561. wsa884x_set_channel_map(component, &spkleft_ports[0],
  1562. WSA884X_MAX_SWR_PORTS, &ch_mask[0],
  1563. &ch_rate[0], &spkleft_port_types[0]);
  1564. wsa884x_codec_info_create_codec_entry(pdata->codec_root,
  1565. component);
  1566. }
  1567. if (pdata->wsa_max_devs > 3) {
  1568. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.4");
  1569. if (!component) {
  1570. pr_err("%s: wsa-codec.4 component is NULL\n", __func__);
  1571. return -EINVAL;
  1572. }
  1573. wsa884x_set_channel_map(component, &spkright_ports[0],
  1574. WSA884X_MAX_SWR_PORTS, &ch_mask[0],
  1575. &ch_rate[0], &spkright_port_types[0]);
  1576. wsa884x_codec_info_create_codec_entry(pdata->codec_root,
  1577. component);
  1578. }
  1579. msm_common_dai_link_init(rtd);
  1580. return 0;
  1581. }
  1582. static int msm_int_wsa_init(struct snd_soc_pcm_runtime *rtd)
  1583. {
  1584. if (strstr(rtd->card->name, "wsa883x"))
  1585. return msm_int_wsa883x_init(rtd);
  1586. return msm_int_wsa884x_init(rtd);
  1587. }
  1588. static int msm_rx_tx_codec_init(struct snd_soc_pcm_runtime *rtd)
  1589. {
  1590. int codec_variant = -1;
  1591. struct snd_soc_component *component = NULL;
  1592. struct snd_soc_component *lpass_cdc_component = NULL;
  1593. struct snd_soc_dapm_context *dapm = NULL;
  1594. struct snd_info_entry *entry = NULL;
  1595. struct snd_card *card = NULL;
  1596. struct msm_asoc_mach_data *pdata =
  1597. snd_soc_card_get_drvdata(rtd->card);
  1598. int ret = 0;
  1599. lpass_cdc_component = snd_soc_rtdcom_lookup(rtd, "lpass-cdc");
  1600. if (!lpass_cdc_component) {
  1601. pr_err("%s: could not find component for lpass-cdc\n",
  1602. __func__);
  1603. return ret;
  1604. }
  1605. dapm = snd_soc_component_get_dapm(lpass_cdc_component);
  1606. snd_soc_dapm_new_controls(dapm, msm_int_dapm_widgets,
  1607. ARRAY_SIZE(msm_int_dapm_widgets));
  1608. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic0");
  1609. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic1");
  1610. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic2");
  1611. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic3");
  1612. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic4");
  1613. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic5");
  1614. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic6");
  1615. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic7");
  1616. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic1");
  1617. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic2");
  1618. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic3");
  1619. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic4");
  1620. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic5");
  1621. lpass_cdc_set_port_map(lpass_cdc_component, ARRAY_SIZE(sm_port_map), sm_port_map);
  1622. card = rtd->card->snd_card;
  1623. if (!pdata->codec_root) {
  1624. entry = msm_snd_info_create_subdir(card->module, "codecs",
  1625. card->proc_root);
  1626. if (!entry) {
  1627. pr_debug("%s: Cannot create codecs module entry\n",
  1628. __func__);
  1629. return ret;
  1630. }
  1631. pdata->codec_root = entry;
  1632. }
  1633. lpass_cdc_info_create_codec_entry(pdata->codec_root, lpass_cdc_component);
  1634. lpass_cdc_register_wake_irq(lpass_cdc_component, false);
  1635. if (pdata->wcd_disabled)
  1636. goto done;
  1637. component = snd_soc_rtdcom_lookup(rtd, WCD939X_DRV_NAME);
  1638. if (!component) {
  1639. pr_err("%s could not find component for %s\n",
  1640. __func__, WCD939X_DRV_NAME);
  1641. return -EINVAL;
  1642. }
  1643. dapm = snd_soc_component_get_dapm(component);
  1644. card = component->card->snd_card;
  1645. snd_soc_dapm_ignore_suspend(dapm, "EAR");
  1646. snd_soc_dapm_ignore_suspend(dapm, "HPHL");
  1647. snd_soc_dapm_ignore_suspend(dapm, "HPHR");
  1648. snd_soc_dapm_ignore_suspend(dapm, "AMIC1");
  1649. snd_soc_dapm_ignore_suspend(dapm, "AMIC2");
  1650. snd_soc_dapm_ignore_suspend(dapm, "AMIC3");
  1651. snd_soc_dapm_ignore_suspend(dapm, "AMIC4");
  1652. snd_soc_dapm_sync(dapm);
  1653. pdata = snd_soc_card_get_drvdata(component->card);
  1654. if (!pdata->codec_root) {
  1655. entry = msm_snd_info_create_subdir(card->module, "codecs",
  1656. card->proc_root);
  1657. if (!entry) {
  1658. dev_dbg(component->dev, "%s: Cannot create codecs module entry\n",
  1659. __func__);
  1660. return 0;
  1661. }
  1662. pdata->codec_root = entry;
  1663. }
  1664. wcd939x_info_create_codec_entry(pdata->codec_root, component);
  1665. codec_variant = wcd939x_get_codec_variant(component);
  1666. dev_dbg(component->dev, "%s: variant %d\n", __func__, codec_variant);
  1667. if (codec_variant == WCD9395)
  1668. ret = lpass_cdc_rx_set_fir_capability(lpass_cdc_component, true);
  1669. else
  1670. ret = lpass_cdc_rx_set_fir_capability(lpass_cdc_component, false);
  1671. if (ret < 0) {
  1672. dev_err_ratelimited(component->dev, "%s: set fir capability failed: %d\n",
  1673. __func__, ret);
  1674. return ret;
  1675. }
  1676. done:
  1677. codec_reg_done = true;
  1678. msm_common_dai_link_init(rtd);
  1679. return ret;
  1680. }
  1681. static int pineapple_ssr_enable(struct device *dev, void *data)
  1682. {
  1683. struct platform_device *pdev = to_platform_device(dev);
  1684. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1685. struct snd_soc_pcm_runtime *rtd = NULL, *rtd_wcd = NULL, *rtd_wsa = NULL;
  1686. struct msm_asoc_mach_data *pdata = NULL;
  1687. int ret = 0;
  1688. if (!card) {
  1689. dev_err_ratelimited(dev, "%s: card is NULL\n", __func__);
  1690. ret = -EINVAL;
  1691. goto err;
  1692. }
  1693. if (!strcmp(card->name, "pineapple-stub-snd-card")) {
  1694. /* TODO */
  1695. dev_dbg(dev, "%s: TODO \n", __func__);
  1696. }
  1697. snd_card_notify_user(SND_CARD_STATUS_ONLINE);
  1698. dev_dbg(dev, "%s: setting snd_card to ONLINE\n", __func__);
  1699. pdata = snd_soc_card_get_drvdata(card);
  1700. if (!pdata) {
  1701. dev_dbg(dev, "%s: pdata is NULL \n", __func__);
  1702. goto err;
  1703. }
  1704. rtd_wcd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
  1705. if (!rtd_wcd) {
  1706. dev_dbg(dev,
  1707. "%s: snd_soc_get_pcm_runtime for %s failed!\n",
  1708. __func__, card->dai_link[0]);
  1709. }
  1710. if (pdata->wsa_max_devs > 0) {
  1711. rtd_wsa = snd_soc_get_pcm_runtime(card,
  1712. &card->dai_link[ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links)]);
  1713. if (!rtd_wsa) {
  1714. dev_dbg(dev,
  1715. "%s: snd_soc_get_pcm_runtime for %s failed!\n",
  1716. __func__, card->dai_link[ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links)]);
  1717. }
  1718. }
  1719. /* set UPD configuration */
  1720. if(!pdata->upd_config.backend_used) {
  1721. dev_dbg(dev,
  1722. "%s: upd- backend_used is NULL\n", __func__);
  1723. goto err;
  1724. }
  1725. if (!strcmp(pdata->upd_config.backend_used, "wsa")) {
  1726. if (!rtd_wsa)
  1727. goto err;
  1728. else
  1729. rtd = rtd_wsa;
  1730. } else if(!strcmp(pdata->upd_config.backend_used, "wcd")) {
  1731. if (!rtd_wcd &&!pdata->wcd_disabled)
  1732. goto err;
  1733. else
  1734. rtd = rtd_wcd;
  1735. } else {
  1736. dev_err_ratelimited(card->dev, "%s: Invalid backend to set UPD config\n",
  1737. __func__);
  1738. goto err;
  1739. }
  1740. msm_set_upd_config(rtd);
  1741. err:
  1742. return ret;
  1743. }
  1744. static void pineapple_ssr_disable(struct device *dev, void *data)
  1745. {
  1746. struct platform_device *pdev = to_platform_device(dev);
  1747. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1748. if (!card) {
  1749. dev_err_ratelimited(dev, "%s: card is NULL\n", __func__);
  1750. return;
  1751. }
  1752. dev_dbg(dev, "%s: setting snd_card to OFFLINE\n", __func__);
  1753. snd_card_notify_user(SND_CARD_STATUS_OFFLINE);
  1754. if (!strcmp(card->name, "pineapple-stub-snd-card")) {
  1755. /* TODO */
  1756. dev_dbg(dev, "%s: TODO \n", __func__);
  1757. }
  1758. }
  1759. static const struct snd_event_ops pineapple_ssr_ops = {
  1760. .enable = pineapple_ssr_enable,
  1761. .disable = pineapple_ssr_disable,
  1762. };
  1763. static int msm_audio_ssr_compare(struct device *dev, void *data)
  1764. {
  1765. struct device_node *node = data;
  1766. dev_dbg(dev, "%s: dev->of_node = 0x%p, node = 0x%p\n",
  1767. __func__, dev->of_node, node);
  1768. return (dev->of_node && dev->of_node == node);
  1769. }
  1770. static int msm_audio_ssr_register(struct device *dev)
  1771. {
  1772. struct device_node *np = dev->of_node;
  1773. struct snd_event_clients *ssr_clients = NULL;
  1774. struct device_node *node = NULL;
  1775. int ret = 0;
  1776. int i = 0;
  1777. for (i = 0; ; i++) {
  1778. node = of_parse_phandle(np, "qcom,msm_audio_ssr_devs", i);
  1779. if (!node)
  1780. break;
  1781. snd_event_mstr_add_client(&ssr_clients,
  1782. msm_audio_ssr_compare, node);
  1783. }
  1784. ret = snd_event_master_register(dev, &pineapple_ssr_ops,
  1785. ssr_clients, NULL);
  1786. if (!ret)
  1787. snd_event_notify(dev, SND_EVENT_UP);
  1788. return ret;
  1789. }
  1790. struct msm_common_pdata *msm_common_get_pdata(struct snd_soc_card *card)
  1791. {
  1792. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  1793. if (!pdata)
  1794. return NULL;
  1795. return pdata->common_pdata;
  1796. }
  1797. void msm_common_set_pdata(struct snd_soc_card *card,
  1798. struct msm_common_pdata *common_pdata)
  1799. {
  1800. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  1801. if (!pdata)
  1802. return;
  1803. pdata->common_pdata = common_pdata;
  1804. }
  1805. static int msm_asoc_machine_probe(struct platform_device *pdev)
  1806. {
  1807. struct snd_soc_card *card = NULL;
  1808. struct msm_asoc_mach_data *pdata = NULL;
  1809. int ret = 0;
  1810. struct clk *lpass_audio_hw_vote = NULL;
  1811. const struct of_device_id *match;
  1812. if (!pdev->dev.of_node) {
  1813. dev_err(&pdev->dev, "%s: No platform supplied from device tree\n", __func__);
  1814. return -EINVAL;
  1815. }
  1816. pdata = devm_kzalloc(&pdev->dev,
  1817. sizeof(struct msm_asoc_mach_data), GFP_KERNEL);
  1818. if (!pdata)
  1819. return -ENOMEM;
  1820. of_property_read_u32(pdev->dev.of_node,
  1821. "qcom,wcd-disabled",
  1822. &pdata->wcd_disabled);
  1823. /* Get maximum WSA device count for this platform */
  1824. ret = of_property_read_u32(pdev->dev.of_node,
  1825. "qcom,wsa-max-devs", &pdata->wsa_max_devs);
  1826. if (ret) {
  1827. dev_info(&pdev->dev,
  1828. "%s: wsa-max-devs property missing in DT %s, ret = %d\n",
  1829. __func__, pdev->dev.of_node->full_name, ret);
  1830. pdata->wsa_max_devs = 0;
  1831. }
  1832. card = populate_snd_card_dailinks(&pdev->dev, pdata->wsa_max_devs);
  1833. if (!card) {
  1834. dev_err(&pdev->dev, "%s: Card uninitialized\n", __func__);
  1835. ret = -EINVAL;
  1836. goto err;
  1837. }
  1838. match = of_match_node(pineapple_asoc_machine_of_match, pdev->dev.of_node);
  1839. if (!match) {
  1840. dev_err(&pdev->dev, "%s: No DT match found for sound card\n",
  1841. __func__);
  1842. ret = -EINVAL;
  1843. goto err;
  1844. }
  1845. card->dev = &pdev->dev;
  1846. platform_set_drvdata(pdev, card);
  1847. snd_soc_card_set_drvdata(card, pdata);
  1848. ret = snd_soc_of_parse_card_name(card, "qcom,model");
  1849. if (ret) {
  1850. dev_err(&pdev->dev, "%s: parse card name failed, err:%d\n",
  1851. __func__, ret);
  1852. goto err;
  1853. }
  1854. if(!strcmp(match->data, "codec")) {
  1855. ret = snd_soc_of_parse_audio_routing(card, "qcom,audio-routing");
  1856. if (ret) {
  1857. dev_err(&pdev->dev, "%s: parse audio routing failed, err:%d\n",
  1858. __func__, ret);
  1859. goto err;
  1860. }
  1861. }
  1862. ret = msm_populate_dai_link_component_of_node(card);
  1863. if (ret) {
  1864. ret = -EPROBE_DEFER;
  1865. goto err;
  1866. }
  1867. /* parse upd configuration */
  1868. msm_parse_upd_configuration(pdev, pdata);
  1869. ret = devm_snd_soc_register_card(&pdev->dev, card);
  1870. if (ret == -EPROBE_DEFER) {
  1871. if (codec_reg_done)
  1872. ret = -EINVAL;
  1873. goto err;
  1874. } else if (ret) {
  1875. dev_err(&pdev->dev, "%s: snd_soc_register_card failed (%d)\n",
  1876. __func__, ret);
  1877. goto err;
  1878. }
  1879. dev_info(&pdev->dev, "%s: Sound card %s registered\n",
  1880. __func__, card->name);
  1881. if (wcd_mbhc_cfg.enable_usbc_analog)
  1882. wcd_mbhc_cfg.swap_gnd_mic = msm_usbc_swap_gnd_mic;
  1883. pdata->wcd_usbss_handle = of_parse_phandle(pdev->dev.of_node,
  1884. "wcd939x-i2c-handle", 0);
  1885. if (!pdata->wcd_usbss_handle)
  1886. dev_dbg(&pdev->dev, "property %s not detected in node %s\n",
  1887. "wcd939x-i2c-handle", pdev->dev.of_node->full_name);
  1888. pdata->dmic01_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1889. "qcom,cdc-dmic01-gpios",
  1890. 0);
  1891. pdata->dmic23_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1892. "qcom,cdc-dmic23-gpios",
  1893. 0);
  1894. pdata->dmic45_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1895. "qcom,cdc-dmic45-gpios",
  1896. 0);
  1897. pdata->dmic67_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1898. "qcom,cdc-dmic67-gpios",
  1899. 0);
  1900. if (pdata->dmic01_gpio_p)
  1901. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic01_gpio_p, false);
  1902. if (pdata->dmic23_gpio_p)
  1903. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic23_gpio_p, false);
  1904. if (pdata->dmic45_gpio_p)
  1905. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic45_gpio_p, false);
  1906. if (pdata->dmic67_gpio_p)
  1907. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic67_gpio_p, false);
  1908. msm_common_snd_init(pdev, card);
  1909. /* Register LPASS audio hw vote */
  1910. lpass_audio_hw_vote = devm_clk_get(&pdev->dev, "lpass_audio_hw_vote");
  1911. if (IS_ERR(lpass_audio_hw_vote)) {
  1912. ret = PTR_ERR(lpass_audio_hw_vote);
  1913. dev_dbg(&pdev->dev, "%s: clk get %s failed %d\n",
  1914. __func__, "lpass_audio_hw_vote", ret);
  1915. lpass_audio_hw_vote = NULL;
  1916. ret = 0;
  1917. }
  1918. pdata->lpass_audio_hw_vote = lpass_audio_hw_vote;
  1919. pdata->core_audio_vote_count = 0;
  1920. ret = msm_audio_ssr_register(&pdev->dev);
  1921. if (ret)
  1922. pr_err("%s: Registration with SND event FWK failed ret = %d\n",
  1923. __func__, ret);
  1924. is_initial_boot = true;
  1925. /* change card status to ONLINE */
  1926. dev_dbg(&pdev->dev, "%s: setting snd_card to ONLINE\n", __func__);
  1927. snd_card_set_card_status(SND_CARD_STATUS_ONLINE);
  1928. return 0;
  1929. err:
  1930. devm_kfree(&pdev->dev, pdata);
  1931. return ret;
  1932. }
  1933. static int msm_asoc_machine_remove(struct platform_device *pdev)
  1934. {
  1935. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1936. struct msm_asoc_mach_data *pdata = NULL;
  1937. struct msm_common_pdata *common_pdata = NULL;
  1938. if (card)
  1939. pdata = snd_soc_card_get_drvdata(card);
  1940. if (pdata)
  1941. common_pdata = pdata->common_pdata;
  1942. msm_common_snd_deinit(common_pdata);
  1943. snd_event_master_deregister(&pdev->dev);
  1944. snd_soc_unregister_card(card);
  1945. return 0;
  1946. }
  1947. static struct platform_driver pineapple_asoc_machine_driver = {
  1948. .driver = {
  1949. .name = DRV_NAME,
  1950. .owner = THIS_MODULE,
  1951. .pm = &snd_soc_pm_ops,
  1952. .of_match_table = pineapple_asoc_machine_of_match,
  1953. .suppress_bind_attrs = true,
  1954. },
  1955. .probe = msm_asoc_machine_probe,
  1956. .remove = msm_asoc_machine_remove,
  1957. };
  1958. static int __init msm_asoc_machine_init(void)
  1959. {
  1960. snd_card_sysfs_init();
  1961. return platform_driver_register(&pineapple_asoc_machine_driver);
  1962. }
  1963. module_init(msm_asoc_machine_init);
  1964. static void __exit msm_asoc_machine_exit(void)
  1965. {
  1966. platform_driver_unregister(&pineapple_asoc_machine_driver);
  1967. }
  1968. module_exit(msm_asoc_machine_exit);
  1969. #ifndef CONFIG_AUDIO_BTFM_PROXY
  1970. MODULE_SOFTDEP("pre: bt_fm_slim");
  1971. #else
  1972. MODULE_SOFTDEP("pre: btfmcodec");
  1973. #endif
  1974. MODULE_DESCRIPTION("ALSA SoC msm");
  1975. MODULE_LICENSE("GPL v2");
  1976. MODULE_ALIAS("platform:" DRV_NAME);
  1977. MODULE_DEVICE_TABLE(of, pineapple_asoc_machine_of_match);