pineapple.c 71 KB

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