pineapple.c 66 KB

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