pineapple.c 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589
  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. #ifdef CONFIG_COMMON_AMP_CIRRUS
  53. #include <sound/cirrus/big_data.h>
  54. #include <sound/samsung/bigdata_cirrus_sysfs_cb.h>
  55. #include <sound/cirrus/core.h>
  56. #endif
  57. #if IS_ENABLED(CONFIG_SND_SOC_SAMSUNG_AUDIO)
  58. #include <sound/samsung/snd_debug_proc.h>
  59. #include <sound/samsung/sec_audio_sysfs.h>
  60. #if defined(CONFIG_SND_SOC_TAS25XX)
  61. #include "codecs/tas25xx/inc/tas25xx-ext.h"
  62. #endif
  63. #endif
  64. #if IS_ENABLED(CONFIG_SEC_ABC)
  65. #include <linux/sti/abc_common.h>
  66. #endif
  67. #define DRV_NAME "pineapple-asoc-snd"
  68. #define __CHIPSET__ "PINEAPPLE "
  69. #define MSM_DAILINK_NAME(name) (__CHIPSET__#name)
  70. #define WCD9XXX_MBHC_DEF_RLOADS 5
  71. #define WCD9XXX_MBHC_DEF_BUTTONS 8
  72. #define CODEC_EXT_CLK_RATE 9600000
  73. #define DEV_NAME_STR_LEN 32
  74. #define WCD_MBHC_HS_V_MAX 1600
  75. #define WCN_CDC_SLIM_RX_CH_MAX 2
  76. #define WCN_CDC_SLIM_TX_CH_MAX 2
  77. #define WCN_CDC_SLIM_TX_CH_MAX_LITO 3
  78. #define WCN_CDC_SLIM_TX_CH_MAX_FM 3
  79. /* Number of WSAs */
  80. #define MONO_SPEAKER 1
  81. #define STEREO_SPEAKER 2
  82. #define QUAD_SPEAKER 4
  83. enum {
  84. WCD937X_DEV_INDEX,
  85. WCD939X_DEV_INDEX,
  86. WCD9378_DEV_INDEX,
  87. };
  88. #if IS_ENABLED(CONFIG_SND_SOC_SAMSUNG_AUDIO)
  89. #define MAX_DEFER_COUNT 10
  90. #define AMP_INIT_SUCCESS 1
  91. #define AMP_INIT_FAIL 0
  92. #define AMP_CHECK_NOT_SUPPORT -1
  93. #endif
  94. struct msm_asoc_mach_data {
  95. struct snd_info_entry *codec_root;
  96. struct msm_common_pdata *common_pdata;
  97. int usbc_en2_gpio; /* used by gpio driver API */
  98. struct device_node *dmic01_gpio_p; /* used by pinctrl API */
  99. struct device_node *dmic23_gpio_p; /* used by pinctrl API */
  100. struct device_node *dmic45_gpio_p; /* used by pinctrl API */
  101. struct device_node *dmic67_gpio_p; /* used by pinctrl API */
  102. struct pinctrl *usbc_en2_gpio_p; /* used by pinctrl API */
  103. bool is_afe_config_done;
  104. struct device_node *fsa_handle;
  105. struct device_node *wcd_usbss_handle;
  106. struct clk *lpass_audio_hw_vote;
  107. int core_audio_vote_count;
  108. u32 wsa_max_devs;
  109. int wcd_disabled;
  110. int (*get_dev_num)(struct snd_soc_component *);
  111. int backend_used;
  112. struct prm_earpa_hw_intf_config upd_config;
  113. bool dedicated_wsa2; /* used to define how wsa2 slave devices are used */
  114. int wcd_used;
  115. };
  116. static bool is_initial_boot;
  117. static bool codec_reg_done;
  118. static struct snd_soc_card snd_soc_card_pineapple_msm;
  119. static int dmic_0_1_gpio_cnt;
  120. static int dmic_2_3_gpio_cnt;
  121. static int dmic_4_5_gpio_cnt;
  122. static int dmic_6_7_gpio_cnt;
  123. static int sub_pcb_conn;
  124. #if IS_ENABLED(CONFIG_SND_SOC_SAMSUNG_AUDIO)
  125. static int defer_count;
  126. static struct snd_soc_dai_link_component dummy_compononet = {
  127. .name = "snd-soc-dummy",
  128. .dai_name = "snd-soc-dummy-dai",
  129. };
  130. #endif
  131. static void *def_wcd_mbhc_cal(void);
  132. static int msm_rx_tx_codec_init(struct snd_soc_pcm_runtime*);
  133. static int msm_int_wsa_init(struct snd_soc_pcm_runtime*);
  134. static int msm_int_wsa881x_init(struct snd_soc_pcm_runtime *);
  135. static int msm_int_wsa884x_init(struct snd_soc_pcm_runtime*);
  136. static int msm_int_wsa883x_init(struct snd_soc_pcm_runtime*);
  137. static int msm_int_wsa2_init(struct snd_soc_pcm_runtime *);
  138. static int msm_int_wsa884x_2_init(struct snd_soc_pcm_runtime *);
  139. static int msm_int_wsa883x_2_init(struct snd_soc_pcm_runtime *);
  140. #ifdef CONFIG_COMMON_AMP_CIRRUS
  141. static const struct snd_soc_dapm_route cirrus_mono_routes[] = {
  142. { "AMP0 SPK", NULL, "Mono SPK" },
  143. };
  144. static const struct snd_soc_dapm_route cirrus_stereo_routes[] = {
  145. { "AMP0 SPK", NULL, "Left AMP SPK" },
  146. { "AMP1 SPK", NULL, "Right AMP SPK" },
  147. };
  148. static const struct snd_soc_dapm_route cirrus_quad_routes[] = {
  149. { "AMP0 SPK", NULL, "FL SPK" },
  150. { "AMP1 SPK", NULL, "FR SPK" },
  151. { "AMP2 SPK", NULL, "RL SPK" },
  152. { "AMP3 SPK", NULL, "RR SPK" },
  153. };
  154. static struct snd_soc_codec_conf cs35l43_mono_conf[] = {
  155. {
  156. .dlc.name = "cs35l43.18-0040",
  157. .name_prefix = "Mono",
  158. }
  159. };
  160. static struct snd_soc_codec_conf cs35l43_stereo_conf[] = {
  161. {
  162. .dlc.name = "cs35l43.18-0040",
  163. .name_prefix = "Right",
  164. },
  165. {
  166. .dlc.name = "cs35l43.18-0041",
  167. .name_prefix = "Left",
  168. }
  169. };
  170. static struct snd_soc_codec_conf cs35l43_quad_conf[] = {
  171. {
  172. .dlc.name = "cs35l43.18-0040",
  173. .name_prefix = "RL",
  174. },
  175. {
  176. .dlc.name = "cs35l43.18-0041",
  177. .name_prefix = "FL",
  178. },
  179. {
  180. .dlc.name = "cs35l43.18-0042",
  181. .name_prefix = "RR",
  182. },
  183. {
  184. .dlc.name = "cs35l43.18-0043",
  185. .name_prefix = "FR",
  186. }
  187. };
  188. static struct snd_soc_codec_conf cs35l45_mono_conf[] = {
  189. {
  190. .dlc.name = "cs35l45.18-0030",
  191. .name_prefix = "Mono",
  192. }
  193. };
  194. static struct snd_soc_codec_conf cs35l45_stereo_conf[] = {
  195. {
  196. .dlc.name = "cs35l45.18-0030",
  197. .name_prefix = "Right",
  198. },
  199. {
  200. .dlc.name = "cs35l45.18-0031",
  201. .name_prefix = "Left",
  202. }
  203. };
  204. static struct snd_soc_codec_conf cs35l45_quad_conf[] = {
  205. {
  206. .dlc.name = "cs35l45.18-0030",
  207. .name_prefix = "RL",
  208. },
  209. {
  210. .dlc.name = "cs35l45.18-0031",
  211. .name_prefix = "FL",
  212. },
  213. {
  214. .dlc.name = "cs35l45.18-0032",
  215. .name_prefix = "RR",
  216. },
  217. {
  218. .dlc.name = "cs35l45.18-0033",
  219. .name_prefix = "FR",
  220. }
  221. };
  222. /*
  223. * We want to configure these at runtime for testing
  224. */
  225. static unsigned int codec_clk_src = CLK_SRC_MCLK;
  226. static const char *const codec_src_clocks[] = {"SCLK", "LRCLK", "PDM",
  227. "MCLK", "SELF", "SWIRE"};
  228. static unsigned int dai_clks = SND_SOC_DAIFMT_CBS_CFS;
  229. static const char *const dai_sub_clocks[] = {"Codec Slave", "Codec Master",
  230. "CODEC BMFS", "CODEC BSFM"
  231. };
  232. static unsigned int dai_bit_fmt = SND_SOC_DAIFMT_NB_NF;
  233. static const char *const dai_bit_config[] = {"NormalBF", "NormalB INVF",
  234. "INVB NormalF", "INVB INVF"
  235. };
  236. static unsigned int dai_mode_fmt = SND_SOC_DAIFMT_I2S;
  237. static const char *const dai_mode_config[] = {"I2S", "Right J",
  238. "Left J", "DSP A", "DSP B",
  239. "PDM"
  240. };
  241. static unsigned int sys_clk_static;
  242. static const char *const static_clk_mode[] = {"Off", "5P6", "6P1", "11P2",
  243. "12", "12P2", "13", "22P5", "24", "24P5", "26"
  244. };
  245. unsigned int dai_force_frame32;
  246. static const char *const dai_force_frame32_config[] = {"Off", "On"};
  247. static u32 cirrus_amp_conf;
  248. static u32 cirrus_amp_count;
  249. #endif
  250. /*
  251. * Need to report LINEIN
  252. * if R/L channel impedance is larger than 5K ohm
  253. */
  254. static struct wcd_mbhc_config wcd_mbhc_cfg = {
  255. .read_fw_bin = false,
  256. .calibration = NULL,
  257. .detect_extn_cable = true,
  258. .mono_stero_detection = false,
  259. .swap_gnd_mic = NULL,
  260. .hs_ext_micbias = true,
  261. .key_code[0] = KEY_MEDIA,
  262. .key_code[1] = KEY_VOICECOMMAND,
  263. .key_code[2] = KEY_VOLUMEUP,
  264. .key_code[3] = KEY_VOLUMEDOWN,
  265. .key_code[4] = 0,
  266. .key_code[5] = 0,
  267. .key_code[6] = 0,
  268. .key_code[7] = 0,
  269. .linein_th = 5000,
  270. .moisture_en = false,
  271. .mbhc_micbias = MIC_BIAS_2,
  272. .anc_micbias = MIC_BIAS_2,
  273. .enable_anc_mic_detect = false,
  274. .moisture_duty_cycle_en = true,
  275. };
  276. #ifdef CONFIG_COMMON_AMP_CIRRUS
  277. static int codec_clk_src_get(struct snd_kcontrol *kcontrol,
  278. struct snd_ctl_elem_value *ucontrol)
  279. {
  280. int codec_clk_src_val = 0;
  281. switch (codec_clk_src) {
  282. case CLK_SRC_SCLK:
  283. codec_clk_src_val = 0;
  284. break;
  285. case CLK_SRC_LRCLK:
  286. codec_clk_src_val = 1;
  287. break;
  288. case CLK_SRC_PDM:
  289. codec_clk_src_val = 2;
  290. break;
  291. case CLK_SRC_MCLK:
  292. codec_clk_src_val = 3;
  293. break;
  294. case CLK_SRC_SELF:
  295. codec_clk_src_val = 4;
  296. break;
  297. case CLK_SRC_SWIRE:
  298. codec_clk_src_val = 5;
  299. break;
  300. }
  301. ucontrol->value.integer.value[0] = codec_clk_src_val;
  302. return 0;
  303. }
  304. static int codec_clk_src_put(struct snd_kcontrol *kcontrol,
  305. struct snd_ctl_elem_value *ucontrol)
  306. {
  307. pr_info("%s: ucontrol value = %ld\n", __func__,
  308. ucontrol->value.integer.value[0]);
  309. switch (ucontrol->value.integer.value[0]) {
  310. case 0:
  311. codec_clk_src = CLK_SRC_SCLK;
  312. break;
  313. case 1:
  314. codec_clk_src = CLK_SRC_LRCLK;
  315. break;
  316. case 2:
  317. codec_clk_src = CLK_SRC_PDM;
  318. break;
  319. case 3:
  320. codec_clk_src = CLK_SRC_MCLK;
  321. break;
  322. case 4:
  323. codec_clk_src = CLK_SRC_SELF;
  324. break;
  325. case 5:
  326. codec_clk_src = CLK_SRC_SWIRE;
  327. break;
  328. }
  329. return 0;
  330. }
  331. static int dai_clks_get(struct snd_kcontrol *kcontrol,
  332. struct snd_ctl_elem_value *ucontrol)
  333. {
  334. int dai_clks_val = 0;
  335. switch (dai_clks) {
  336. case SND_SOC_DAIFMT_CBS_CFS:
  337. dai_clks_val = 0;
  338. break;
  339. case SND_SOC_DAIFMT_CBM_CFM:
  340. dai_clks_val = 1;
  341. break;
  342. case SND_SOC_DAIFMT_CBM_CFS:
  343. dai_clks_val = 2;
  344. break;
  345. case SND_SOC_DAIFMT_CBS_CFM:
  346. dai_clks_val = 3;
  347. break;
  348. }
  349. ucontrol->value.integer.value[0] = dai_clks_val;
  350. return 0;
  351. }
  352. static int dai_clks_put(struct snd_kcontrol *kcontrol,
  353. struct snd_ctl_elem_value *ucontrol)
  354. {
  355. pr_info("%s: ucontrol value = %ld\n", __func__,
  356. ucontrol->value.integer.value[0]);
  357. switch (ucontrol->value.integer.value[0]) {
  358. case 0:
  359. dai_clks = SND_SOC_DAIFMT_CBS_CFS;
  360. break;
  361. case 1:
  362. dai_clks = SND_SOC_DAIFMT_CBM_CFM;
  363. break;
  364. case 2:
  365. dai_clks = SND_SOC_DAIFMT_CBM_CFS;
  366. break;
  367. case 3:
  368. dai_clks = SND_SOC_DAIFMT_CBS_CFM;
  369. break;
  370. }
  371. return 0;
  372. }
  373. static int dai_bitfmt_get(struct snd_kcontrol *kcontrol,
  374. struct snd_ctl_elem_value *ucontrol)
  375. {
  376. int dai_bits_val = 0;
  377. switch (dai_bit_fmt) {
  378. case SND_SOC_DAIFMT_NB_NF:
  379. dai_bits_val = 0;
  380. break;
  381. case SND_SOC_DAIFMT_NB_IF:
  382. dai_bits_val = 1;
  383. break;
  384. case SND_SOC_DAIFMT_IB_NF:
  385. dai_bits_val = 2;
  386. break;
  387. case SND_SOC_DAIFMT_IB_IF:
  388. dai_bits_val = 3;
  389. break;
  390. }
  391. ucontrol->value.integer.value[0] = dai_bits_val;
  392. return 0;
  393. }
  394. static int dai_bitfmt_put(struct snd_kcontrol *kcontrol,
  395. struct snd_ctl_elem_value *ucontrol)
  396. {
  397. pr_info("%s: ucontrol value = %ld\n", __func__,
  398. ucontrol->value.integer.value[0]);
  399. switch (ucontrol->value.integer.value[0]) {
  400. case 0:
  401. dai_bit_fmt = SND_SOC_DAIFMT_NB_NF;
  402. break;
  403. case 1:
  404. dai_bit_fmt = SND_SOC_DAIFMT_NB_IF;
  405. break;
  406. case 2:
  407. dai_bit_fmt = SND_SOC_DAIFMT_IB_NF;
  408. break;
  409. case 3:
  410. dai_bit_fmt = SND_SOC_DAIFMT_IB_IF;
  411. break;
  412. }
  413. return 0;
  414. }
  415. static int dai_mode_get(struct snd_kcontrol *kcontrol,
  416. struct snd_ctl_elem_value *ucontrol)
  417. {
  418. int dai_mode_val = 0;
  419. switch (dai_mode_fmt) {
  420. case SND_SOC_DAIFMT_I2S:
  421. dai_mode_val = 0;
  422. break;
  423. case SND_SOC_DAIFMT_RIGHT_J:
  424. dai_mode_val = 1;
  425. break;
  426. case SND_SOC_DAIFMT_LEFT_J:
  427. dai_mode_val = 2;
  428. break;
  429. case SND_SOC_DAIFMT_DSP_A:
  430. dai_mode_val = 3;
  431. break;
  432. case SND_SOC_DAIFMT_DSP_B:
  433. dai_mode_val = 4;
  434. break;
  435. case SND_SOC_DAIFMT_PDM:
  436. dai_mode_val = 5;
  437. break;
  438. }
  439. ucontrol->value.integer.value[0] = dai_mode_val;
  440. return 0;
  441. }
  442. static int dai_mode_put(struct snd_kcontrol *kcontrol,
  443. struct snd_ctl_elem_value *ucontrol)
  444. {
  445. pr_info("%s: ucontrol value = %ld\n", __func__,
  446. ucontrol->value.integer.value[0]);
  447. switch (ucontrol->value.integer.value[0]) {
  448. case 0:
  449. dai_mode_fmt = SND_SOC_DAIFMT_I2S;
  450. break;
  451. case 1:
  452. dai_mode_fmt = SND_SOC_DAIFMT_RIGHT_J;
  453. break;
  454. case 2:
  455. dai_mode_fmt = SND_SOC_DAIFMT_LEFT_J;
  456. break;
  457. case 3:
  458. dai_mode_fmt = SND_SOC_DAIFMT_DSP_A;
  459. break;
  460. case 4:
  461. dai_mode_fmt = SND_SOC_DAIFMT_DSP_B;
  462. break;
  463. case 5:
  464. dai_mode_fmt = SND_SOC_DAIFMT_PDM;
  465. break;
  466. }
  467. return 0;
  468. }
  469. static int static_clk_mode_get(struct snd_kcontrol *kcontrol,
  470. struct snd_ctl_elem_value *ucontrol)
  471. {
  472. int static_mode_val = 0;
  473. switch (sys_clk_static) {
  474. case 0:
  475. static_mode_val = 0;
  476. break;
  477. case 5644800:
  478. static_mode_val = 1;
  479. break;
  480. case 6144000:
  481. static_mode_val = 2;
  482. break;
  483. case 11289600:
  484. static_mode_val = 3;
  485. break;
  486. case 12000000:
  487. static_mode_val = 4;
  488. break;
  489. case 12288000:
  490. static_mode_val = 5;
  491. break;
  492. case 13000000:
  493. static_mode_val = 6;
  494. break;
  495. case 22579200:
  496. static_mode_val = 7;
  497. break;
  498. case 24000000:
  499. static_mode_val = 8;
  500. break;
  501. case 24576000:
  502. static_mode_val = 9;
  503. break;
  504. case 26000000:
  505. static_mode_val = 10;
  506. break;
  507. }
  508. ucontrol->value.integer.value[0] = static_mode_val;
  509. return 0;
  510. }
  511. static int static_clk_mode_put(struct snd_kcontrol *kcontrol,
  512. struct snd_ctl_elem_value *ucontrol)
  513. {
  514. switch (ucontrol->value.integer.value[0]) {
  515. case 0:
  516. sys_clk_static = 0;
  517. break;
  518. case 1:
  519. sys_clk_static = 5644800;
  520. break;
  521. case 2:
  522. sys_clk_static = 6144000;
  523. break;
  524. case 3:
  525. sys_clk_static = 11289600;
  526. break;
  527. case 4:
  528. sys_clk_static = 12000000;
  529. break;
  530. case 5:
  531. sys_clk_static = 12288000;
  532. break;
  533. case 6:
  534. sys_clk_static = 13000000;
  535. break;
  536. case 7:
  537. sys_clk_static = 22579200;
  538. break;
  539. case 8:
  540. sys_clk_static = 24000000;
  541. break;
  542. case 9:
  543. sys_clk_static = 24576000;
  544. break;
  545. case 10:
  546. sys_clk_static = 26000000;
  547. break;
  548. }
  549. return 0;
  550. }
  551. static int dai_force_frame32_get(struct snd_kcontrol *kcontrol,
  552. struct snd_ctl_elem_value *ucontrol)
  553. {
  554. int dai_force_frame32_val = 0;
  555. switch (dai_force_frame32) {
  556. case 0:
  557. dai_force_frame32_val = 0;
  558. break;
  559. case 1:
  560. dai_force_frame32_val = 1;
  561. break;
  562. }
  563. ucontrol->value.integer.value[0] = dai_force_frame32_val;
  564. return 0;
  565. }
  566. static int dai_force_frame32_put(struct snd_kcontrol *kcontrol,
  567. struct snd_ctl_elem_value *ucontrol)
  568. {
  569. switch (ucontrol->value.integer.value[0]) {
  570. case 0:
  571. dai_force_frame32 = 0;
  572. break;
  573. case 1:
  574. dai_force_frame32 = 1;
  575. break;
  576. }
  577. return 0;
  578. }
  579. static const struct soc_enum cirrus_snd_enum[] = {
  580. SOC_ENUM_SINGLE_EXT(4, dai_sub_clocks),
  581. SOC_ENUM_SINGLE_EXT(4, dai_bit_config),
  582. SOC_ENUM_SINGLE_EXT(6, dai_mode_config),
  583. SOC_ENUM_SINGLE_EXT(11, static_clk_mode),
  584. SOC_ENUM_SINGLE_EXT(5, codec_src_clocks),
  585. SOC_ENUM_SINGLE_EXT(2, dai_force_frame32_config),
  586. };
  587. static const struct snd_kcontrol_new msm_cirrus_snd_controls[] = {
  588. SOC_ENUM_EXT("DAI Clocks", cirrus_snd_enum[0], dai_clks_get,
  589. dai_clks_put),
  590. SOC_ENUM_EXT("DAI Polarity", cirrus_snd_enum[1], dai_bitfmt_get,
  591. dai_bitfmt_put),
  592. SOC_ENUM_EXT("DAI Mode", cirrus_snd_enum[2], dai_mode_get,
  593. dai_mode_put),
  594. SOC_ENUM_EXT("Static MCLK Mode", cirrus_snd_enum[3],
  595. static_clk_mode_get, static_clk_mode_put),
  596. SOC_ENUM_EXT("Codec CLK Source", cirrus_snd_enum[4], codec_clk_src_get,
  597. codec_clk_src_put),
  598. SOC_ENUM_EXT("Force Frame32", cirrus_snd_enum[5], dai_force_frame32_get,
  599. dai_force_frame32_put),
  600. };
  601. static int cirrus_amp_0_speaker(struct snd_soc_dapm_widget *w,
  602. struct snd_kcontrol *kcontrol, int event)
  603. {
  604. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  605. dev_info(component->dev, "%s ev: %d\n", __func__, event);
  606. switch (event) {
  607. case SND_SOC_DAPM_PRE_PMD:
  608. cirrus_bd_store_values("_0");
  609. break;
  610. }
  611. return 0;
  612. }
  613. static int cirrus_amp_1_speaker(struct snd_soc_dapm_widget *w,
  614. struct snd_kcontrol *kcontrol, int event)
  615. {
  616. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  617. dev_info(component->dev, "%s ev: %d\n", __func__, event);
  618. switch (event) {
  619. case SND_SOC_DAPM_PRE_PMD:
  620. cirrus_bd_store_values("_1");
  621. break;
  622. }
  623. return 0;
  624. }
  625. static int cirrus_amp_2_speaker(struct snd_soc_dapm_widget *w,
  626. struct snd_kcontrol *kcontrol, int event)
  627. {
  628. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  629. dev_info(component->dev, "%s ev: %d\n", __func__, event);
  630. switch (event) {
  631. case SND_SOC_DAPM_PRE_PMD:
  632. cirrus_bd_store_values("_2");
  633. break;
  634. }
  635. return 0;
  636. }
  637. static int cirrus_amp_3_speaker(struct snd_soc_dapm_widget *w,
  638. struct snd_kcontrol *kcontrol, int event)
  639. {
  640. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  641. dev_info(component->dev, "%s ev: %d\n", __func__, event);
  642. switch (event) {
  643. case SND_SOC_DAPM_PRE_PMD:
  644. cirrus_bd_store_values("_3");
  645. break;
  646. }
  647. return 0;
  648. }
  649. #endif
  650. static bool msm_usbc_swap_gnd_mic(struct snd_soc_component *component, bool active)
  651. {
  652. int ret = 0;
  653. struct snd_soc_card *card = component->card;
  654. struct msm_asoc_mach_data *pdata =
  655. snd_soc_card_get_drvdata(card);
  656. if (!pdata->fsa_handle && !pdata->wcd_usbss_handle)
  657. return false;
  658. if (pdata->fsa_handle) {
  659. ret = fsa4480_switch_event(pdata->fsa_handle, FSA_MIC_GND_SWAP);
  660. } else {
  661. #if IS_ENABLED(CONFIG_QCOM_WCD_USBSS_I2C)
  662. if (wcd_mbhc_cfg.usbss_hsj_connect_enable)
  663. ret = wcd_usbss_switch_update(WCD_USBSS_GND_MIC_SWAP_HSJ,
  664. WCD_USBSS_CABLE_CONNECT);
  665. else if (wcd_mbhc_cfg.enable_usbc_analog)
  666. ret = wcd_usbss_switch_update(WCD_USBSS_GND_MIC_SWAP_AATC,
  667. WCD_USBSS_CABLE_CONNECT);
  668. #endif
  669. }
  670. if (ret == 0)
  671. return true;
  672. else
  673. return false;
  674. }
  675. static void msm_parse_upd_configuration(struct platform_device *pdev,
  676. struct msm_asoc_mach_data *pdata)
  677. {
  678. int ret = 0;
  679. u32 dt_values[2];
  680. if (!pdev || !pdata)
  681. return;
  682. ret = of_property_read_string(pdev->dev.of_node,
  683. "qcom,upd_backends_used", &pdata->upd_config.backend_used);
  684. if (ret) {
  685. pr_debug("%s:could not find %s entry in dt\n",
  686. __func__, "qcom,upd_backends_used");
  687. return;
  688. }
  689. ret = of_property_read_u32_array(pdev->dev.of_node,
  690. "qcom,upd_lpass_reg_addr", dt_values, MAX_EARPA_REG);
  691. if (ret) {
  692. pr_debug("%s: could not find %s entry in dt\n",
  693. __func__, "qcom,upd_lpass_reg_addr");
  694. return;
  695. } else {
  696. pdata->upd_config.ear_pa_hw_reg_cfg.lpass_cdc_rx0_rx_path_ctl_phy_addr =
  697. dt_values[0];
  698. pdata->upd_config.ear_pa_hw_reg_cfg.lpass_wr_fifo_reg_phy_addr =
  699. dt_values[1];
  700. }
  701. ret = of_property_read_u32(pdev->dev.of_node,
  702. "qcom,upd_ear_pa_reg_addr", &pdata->upd_config.ear_pa_pkd_reg_addr);
  703. if (ret) {
  704. pr_debug("%s: could not find %s entry in dt\n",
  705. __func__, "qcom,upd_ear_pa_reg_addr");
  706. }
  707. }
  708. static void msm_set_upd_config(struct snd_soc_pcm_runtime *rtd)
  709. {
  710. int val1 = 0, val2 = 0, ret = 0;
  711. u8 dev_num = 0;
  712. struct snd_soc_component *component = NULL;
  713. struct msm_asoc_mach_data *pdata = NULL;
  714. char wcd_name[20];
  715. if (!rtd) {
  716. pr_err_ratelimited("%s: rtd is NULL\n", __func__);
  717. return;
  718. }
  719. pdata = snd_soc_card_get_drvdata(rtd->card);
  720. if (!pdata) {
  721. pr_err_ratelimited("%s: pdata is NULL\n", __func__);
  722. return;
  723. }
  724. if (!pdata->upd_config.ear_pa_hw_reg_cfg.lpass_cdc_rx0_rx_path_ctl_phy_addr ||
  725. !pdata->upd_config.ear_pa_hw_reg_cfg.lpass_wr_fifo_reg_phy_addr ||
  726. !pdata->upd_config.ear_pa_pkd_reg_addr) {
  727. pr_err_ratelimited("%s: upd static configuration is not set\n", __func__);
  728. return;
  729. }
  730. if (!strcmp(pdata->upd_config.backend_used, "wsa")) {
  731. if (pdata->wsa_max_devs > 0) {
  732. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.1");
  733. if (!component) {
  734. pr_err("%s: %s component is NULL\n", __func__,
  735. "wsa-codec.1");
  736. return;
  737. }
  738. } else {
  739. pr_err("%s wsa_max_devs are NULL\n", __func__);
  740. return;
  741. }
  742. } else {
  743. if (pdata->wcd_used == WCD937X_DEV_INDEX)
  744. strscpy(wcd_name, WCD937X_DRV_NAME, sizeof(WCD937X_DRV_NAME));
  745. else if (pdata->wcd_used == WCD9378_DEV_INDEX)
  746. strscpy(wcd_name, WCD9378_DRV_NAME, sizeof(WCD9378_DRV_NAME));
  747. else
  748. strscpy(wcd_name, WCD939X_DRV_NAME, sizeof(WCD939X_DRV_NAME));
  749. component = snd_soc_rtdcom_lookup(rtd, wcd_name);
  750. if (!component) {
  751. pr_err("%s component is NULL\n", __func__);
  752. return;
  753. }
  754. }
  755. if (!strcmp(pdata->upd_config.backend_used, "wsa")) {
  756. if (strstr(rtd->card->name, "wsa883x"))
  757. pdata->get_dev_num = wsa883x_codec_get_dev_num;
  758. else
  759. pdata->get_dev_num = wsa884x_codec_get_dev_num;
  760. } else {
  761. if (pdata->wcd_used == WCD937X_DEV_INDEX) {
  762. pdata->get_dev_num = wcd937x_codec_get_dev_num;
  763. } else if (pdata->wcd_used == WCD9378_DEV_INDEX) {
  764. pdata->get_dev_num = wcd9378_codec_get_dev_num;
  765. } else {
  766. pdata->get_dev_num = wcd939x_codec_get_dev_num;
  767. }
  768. }
  769. if (!pdata->get_dev_num) {
  770. pr_err("%s: get_dev_num is NULL\n", __func__);
  771. return;
  772. }
  773. dev_num = pdata->get_dev_num(component);
  774. if (dev_num < 0 || dev_num > 6) {
  775. pr_err_ratelimited("%s: invalid slave dev num : %d\n", __func__,
  776. dev_num);
  777. return;
  778. }
  779. pdata->upd_config.ear_pa_pkd_cfg.ear_pa_enable_pkd_reg_addr =
  780. pdata->upd_config.ear_pa_pkd_reg_addr & 0xFFFF;
  781. pdata->upd_config.ear_pa_pkd_cfg.ear_pa_disable_pkd_reg_addr =
  782. pdata->upd_config.ear_pa_pkd_reg_addr & 0xFFFF;
  783. val1 = val2 = 0;
  784. /* bits 16:19 carry command id */
  785. val1 |= 1 << 16;
  786. /* bits 20:23 carry swr device number */
  787. val1 |= dev_num << 20;
  788. /*
  789. * bits 24:31 carry 8 bit data to disable or enable ear pa
  790. * for wcd 7bit is global enable bit - 1 -enable. 0 - disable
  791. * for wsa 0bit is global enable bit - 1 -enable, 0 - disable
  792. */
  793. val2 = val1;
  794. if (!strcmp(pdata->upd_config.backend_used, "wsa"))
  795. val1 |= 1 << 24;
  796. else
  797. val1 |= 1 << 31;
  798. pdata->upd_config.ear_pa_pkd_cfg.ear_pa_enable_pkd_reg_addr |= val1;
  799. pdata->upd_config.ear_pa_pkd_cfg.ear_pa_disable_pkd_reg_addr |= val2;
  800. ret = audio_prm_set_cdc_earpa_duty_cycling_req(&pdata->upd_config, 1);
  801. if (ret < 0) {
  802. pr_err_ratelimited("%s: upd cdc duty cycling registration failed\n", __func__);
  803. return;
  804. }
  805. pr_debug("%s: upd cdc duty cycling registration done successfully!\n", __func__);
  806. }
  807. static struct snd_soc_ops msm_common_be_ops = {
  808. .hw_params = msm_common_snd_hw_params,
  809. .startup = msm_common_snd_startup,
  810. .shutdown = msm_common_snd_shutdown,
  811. };
  812. static int msm_dmic_event(struct snd_soc_dapm_widget *w,
  813. struct snd_kcontrol *kcontrol, int event)
  814. {
  815. struct msm_asoc_mach_data *pdata = NULL;
  816. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  817. int ret = 0;
  818. u32 dmic_idx;
  819. int *dmic_gpio_cnt;
  820. struct device_node *dmic_gpio;
  821. char *wname;
  822. wname = strpbrk(w->name, "01234567");
  823. if (!wname) {
  824. dev_err_ratelimited(component->dev, "%s: widget not found\n", __func__);
  825. return -EINVAL;
  826. }
  827. ret = kstrtouint(wname, 10, &dmic_idx);
  828. if (ret < 0) {
  829. dev_err_ratelimited(component->dev, "%s: Invalid DMIC line on the codec\n",
  830. __func__);
  831. return -EINVAL;
  832. }
  833. pdata = snd_soc_card_get_drvdata(component->card);
  834. switch (dmic_idx) {
  835. case 0:
  836. case 1:
  837. dmic_gpio_cnt = &dmic_0_1_gpio_cnt;
  838. dmic_gpio = pdata->dmic01_gpio_p;
  839. break;
  840. case 2:
  841. case 3:
  842. dmic_gpio_cnt = &dmic_2_3_gpio_cnt;
  843. dmic_gpio = pdata->dmic23_gpio_p;
  844. break;
  845. case 4:
  846. case 5:
  847. dmic_gpio_cnt = &dmic_4_5_gpio_cnt;
  848. dmic_gpio = pdata->dmic45_gpio_p;
  849. break;
  850. case 6:
  851. case 7:
  852. dmic_gpio_cnt = &dmic_6_7_gpio_cnt;
  853. dmic_gpio = pdata->dmic67_gpio_p;
  854. break;
  855. default:
  856. dev_err_ratelimited(component->dev, "%s: Invalid DMIC Selection\n",
  857. __func__);
  858. return -EINVAL;
  859. }
  860. dev_dbg(component->dev, "%s: event %d DMIC%d dmic_gpio_cnt %d\n",
  861. __func__, event, dmic_idx, *dmic_gpio_cnt);
  862. switch (event) {
  863. case SND_SOC_DAPM_PRE_PMU:
  864. (*dmic_gpio_cnt)++;
  865. if (*dmic_gpio_cnt == 1) {
  866. ret = msm_cdc_pinctrl_select_active_state(
  867. dmic_gpio);
  868. if (ret < 0) {
  869. pr_err_ratelimited("%s: gpio set cannot be activated %sd",
  870. __func__, "dmic_gpio");
  871. return ret;
  872. }
  873. }
  874. break;
  875. case SND_SOC_DAPM_POST_PMD:
  876. (*dmic_gpio_cnt)--;
  877. if (*dmic_gpio_cnt == 0) {
  878. ret = msm_cdc_pinctrl_select_sleep_state(
  879. dmic_gpio);
  880. if (ret < 0) {
  881. pr_err_ratelimited("%s: gpio set cannot be de-activated %sd",
  882. __func__, "dmic_gpio");
  883. return ret;
  884. }
  885. }
  886. break;
  887. default:
  888. pr_err_ratelimited("%s: invalid DAPM event %d\n", __func__, event);
  889. return -EINVAL;
  890. }
  891. return 0;
  892. }
  893. static const struct snd_soc_dapm_widget msm_int_dapm_widgets[] = {
  894. SND_SOC_DAPM_MIC("Analog Mic1", NULL),
  895. SND_SOC_DAPM_MIC("Analog Mic2", NULL),
  896. SND_SOC_DAPM_MIC("Analog Mic3", NULL),
  897. SND_SOC_DAPM_MIC("Analog Mic4", NULL),
  898. SND_SOC_DAPM_MIC("Analog Mic5", NULL),
  899. SND_SOC_DAPM_MIC("Digital Mic0", msm_dmic_event),
  900. SND_SOC_DAPM_MIC("Digital Mic1", msm_dmic_event),
  901. SND_SOC_DAPM_MIC("Digital Mic2", msm_dmic_event),
  902. SND_SOC_DAPM_MIC("Digital Mic3", msm_dmic_event),
  903. SND_SOC_DAPM_MIC("Digital Mic4", msm_dmic_event),
  904. SND_SOC_DAPM_MIC("Digital Mic5", msm_dmic_event),
  905. SND_SOC_DAPM_MIC("Digital Mic6", NULL),
  906. SND_SOC_DAPM_MIC("Digital Mic7", NULL),
  907. #ifdef CONFIG_COMMON_AMP_CIRRUS
  908. SND_SOC_DAPM_SPK("AMP0 SPK", cirrus_amp_0_speaker),
  909. SND_SOC_DAPM_SPK("AMP1 SPK", cirrus_amp_1_speaker),
  910. SND_SOC_DAPM_SPK("AMP2 SPK", cirrus_amp_2_speaker),
  911. SND_SOC_DAPM_SPK("AMP3 SPK", cirrus_amp_3_speaker),
  912. #endif
  913. };
  914. #ifdef CONFIG_COMMON_AMP_CIRRUS
  915. #if IS_ENABLED(CONFIG_SEC_ABC)
  916. void cirrus_i2c_fail_log(const char *suffix)
  917. {
  918. pr_info("%s(%s)\n", __func__, suffix);
  919. #if IS_ENABLED(CONFIG_SEC_FACTORY)
  920. sec_abc_send_event("MODULE=audio@INFO=spk_amp");
  921. #else
  922. sec_abc_send_event("MODULE=audio@WARN=spk_amp");
  923. #endif
  924. }
  925. void cirrus_amp_fail_event(const char *suffix)
  926. {
  927. pr_info("%s(%s)\n", __func__, suffix);
  928. #if IS_ENABLED(CONFIG_SEC_FACTORY)
  929. sec_abc_send_event("MODULE=audio@INFO=spk_amp_short");
  930. #else
  931. sec_abc_send_event("MODULE=audio@WARN=spk_amp_short");
  932. #endif
  933. }
  934. #endif
  935. static int pineapple_tdm_cirrus_init(struct snd_soc_pcm_runtime *rtd)
  936. {
  937. int i;
  938. struct snd_soc_dai *codec_dai_amp;
  939. struct snd_soc_dapm_context *amp_dapm;
  940. if (cirrus_amp_count < 1 || cirrus_amp_count > 4) {
  941. pr_err("%s: out of range\n", __func__);
  942. return 0;
  943. }
  944. for (i = 0 ; i < cirrus_amp_count; i++) {
  945. codec_dai_amp = asoc_rtd_to_codec(rtd, i);
  946. amp_dapm = snd_soc_component_get_dapm(codec_dai_amp->component);
  947. switch (cirrus_amp_conf) {
  948. case CS35L43_MONO:
  949. case CS35L43_STEREO:
  950. case CS35L43_QUAD:
  951. snd_soc_dapm_ignore_suspend(amp_dapm, "AMP Capture");
  952. snd_soc_dapm_ignore_suspend(amp_dapm, "AMP Playback");
  953. snd_soc_dapm_ignore_suspend(amp_dapm, "AMP SPK");
  954. snd_soc_dapm_sync(amp_dapm);
  955. break;
  956. case CS35L45_MONO:
  957. case CS35L45_STEREO:
  958. case CS35L45_QUAD:
  959. snd_soc_dapm_ignore_suspend(amp_dapm, "Capture");
  960. snd_soc_dapm_ignore_suspend(amp_dapm, "Playback");
  961. snd_soc_dapm_ignore_suspend(amp_dapm, "SPK");
  962. snd_soc_dapm_ignore_suspend(amp_dapm, "AP");
  963. snd_soc_dapm_ignore_suspend(amp_dapm, "AMP Enable");
  964. snd_soc_dapm_ignore_suspend(amp_dapm, "Entry");
  965. snd_soc_dapm_ignore_suspend(amp_dapm, "Exit");
  966. snd_soc_dapm_sync(amp_dapm);
  967. break;
  968. default:
  969. pr_err("%s: cirrus amp conf is not defined\n",
  970. __func__);
  971. break;
  972. }
  973. }
  974. #if IS_ENABLED(CONFIG_SEC_ABC)
  975. cirrus_amp_register_i2c_error_callback("", cirrus_i2c_fail_log);
  976. cirrus_amp_register_i2c_error_callback("_r", cirrus_i2c_fail_log);
  977. cirrus_amp_register_error_callback("", cirrus_amp_fail_event);
  978. cirrus_amp_register_error_callback("_r", cirrus_amp_fail_event);
  979. #endif
  980. register_cirrus_bigdata_cb(amp_dapm->component);
  981. pr_info("%s end\n", __func__);
  982. return 0;
  983. }
  984. #endif
  985. #if defined(CONFIG_SND_SOC_TAS25XX)
  986. #if IS_ENABLED(CONFIG_SEC_ABC)
  987. void tas_i2c_fail_log(uint32_t i2caddr)
  988. {
  989. pr_info("%s(%x)\n", __func__, i2caddr);
  990. #if IS_ENABLED(CONFIG_SEC_FACTORY)
  991. sec_abc_send_event("MODULE=audio@INFO=spk_amp");
  992. #else
  993. sec_abc_send_event("MODULE=audio@WARN=spk_amp");
  994. #endif
  995. }
  996. void tas_amp_fail_log(int32_t ch, int32_t err)
  997. {
  998. pr_info("%s(ch : %d , error : %d)\n", __func__, ch, err);
  999. #if IS_ENABLED(CONFIG_SEC_FACTORY)
  1000. sec_abc_send_event("MODULE=audio@INFO=spk_amp_short");
  1001. #else
  1002. sec_abc_send_event("MODULE=audio@WARN=spk_amp_short");
  1003. #endif
  1004. }
  1005. #endif
  1006. static int pineapple_tdm_tas_init(struct snd_soc_pcm_runtime *rtd)
  1007. {
  1008. #if IS_ENABLED(CONFIG_SEC_ABC)
  1009. tas25xx_register_i2c_error_callback(tas_i2c_fail_log);
  1010. tas25xx_register_amp_error_callback(tas_amp_fail_log);
  1011. #endif
  1012. return 0;
  1013. }
  1014. #endif
  1015. #ifndef CONFIG_AUDIO_BTFM_PROXY
  1016. static int msm_wcn_init(struct snd_soc_pcm_runtime *rtd)
  1017. {
  1018. unsigned int rx_ch[WCN_CDC_SLIM_RX_CH_MAX] = {157, 158};
  1019. unsigned int tx_ch[WCN_CDC_SLIM_TX_CH_MAX] = {159, 160};
  1020. struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
  1021. int ret = 0;
  1022. ret = snd_soc_dai_set_channel_map(codec_dai, ARRAY_SIZE(tx_ch),
  1023. tx_ch, ARRAY_SIZE(rx_ch), rx_ch);
  1024. if (ret)
  1025. return ret;
  1026. msm_common_dai_link_init(rtd);
  1027. return ret;
  1028. }
  1029. static int msm_wcn_init_btfm(struct snd_soc_pcm_runtime *rtd)
  1030. {
  1031. unsigned int rx_ch[WCN_CDC_SLIM_RX_CH_MAX] = {157, 158};
  1032. unsigned int tx_ch[WCN_CDC_SLIM_TX_CH_MAX_FM] = {159, 160, 161};
  1033. struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
  1034. int ret = 0;
  1035. ret = snd_soc_dai_set_channel_map(codec_dai, ARRAY_SIZE(tx_ch),
  1036. tx_ch, ARRAY_SIZE(rx_ch), rx_ch);
  1037. if (ret)
  1038. return ret;
  1039. msm_common_dai_link_init(rtd);
  1040. return ret;
  1041. }
  1042. #endif
  1043. static struct snd_info_entry *msm_snd_info_create_subdir(struct module *mod,
  1044. const char *name,
  1045. struct snd_info_entry *parent)
  1046. {
  1047. struct snd_info_entry *entry;
  1048. entry = snd_info_create_module_entry(mod, name, parent);
  1049. if (!entry)
  1050. return NULL;
  1051. entry->mode = S_IFDIR | 0555;
  1052. if (snd_info_register(entry) < 0) {
  1053. snd_info_free_entry(entry);
  1054. return NULL;
  1055. }
  1056. return entry;
  1057. }
  1058. static void *def_wcd_mbhc_cal(void)
  1059. {
  1060. void *wcd_mbhc_cal;
  1061. struct wcd_mbhc_btn_detect_cfg *btn_cfg;
  1062. u16 *btn_high;
  1063. wcd_mbhc_cal = kzalloc(WCD_MBHC_CAL_SIZE(WCD_MBHC_DEF_BUTTONS,
  1064. WCD9XXX_MBHC_DEF_RLOADS), GFP_KERNEL);
  1065. if (!wcd_mbhc_cal)
  1066. return NULL;
  1067. WCD_MBHC_CAL_PLUG_TYPE_PTR(wcd_mbhc_cal)->v_hs_max = WCD_MBHC_HS_V_MAX;
  1068. WCD_MBHC_CAL_BTN_DET_PTR(wcd_mbhc_cal)->num_btn = WCD_MBHC_DEF_BUTTONS;
  1069. btn_cfg = WCD_MBHC_CAL_BTN_DET_PTR(wcd_mbhc_cal);
  1070. btn_high = ((void *)&btn_cfg->_v_btn_low) +
  1071. (sizeof(btn_cfg->_v_btn_low[0]) * btn_cfg->num_btn);
  1072. btn_high[0] = 75;
  1073. btn_high[1] = 150;
  1074. btn_high[2] = 237;
  1075. btn_high[3] = 500;
  1076. btn_high[4] = 500;
  1077. btn_high[5] = 500;
  1078. btn_high[6] = 500;
  1079. btn_high[7] = 500;
  1080. return wcd_mbhc_cal;
  1081. }
  1082. /* Digital audio interface glue - connects codec <---> CPU */
  1083. static struct snd_soc_dai_link msm_common_be_dai_links[] = {
  1084. /* Proxy Tx BACK END DAI Link */
  1085. {
  1086. .name = LPASS_BE_RT_PROXY_PCM_TX,
  1087. .stream_name = LPASS_BE_RT_PROXY_PCM_TX,
  1088. .capture_only = 1,
  1089. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1090. SND_SOC_DPCM_TRIGGER_POST},
  1091. .ignore_suspend = 1,
  1092. .ops = &msm_common_be_ops,
  1093. SND_SOC_DAILINK_REG(proxy_tx),
  1094. },
  1095. {
  1096. .name = LPASS_BE_RT_PROXY_PCM_TX_2,
  1097. .stream_name = LPASS_BE_RT_PROXY_PCM_TX_2,
  1098. .capture_only = 1,
  1099. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1100. SND_SOC_DPCM_TRIGGER_POST},
  1101. .ignore_suspend = 1,
  1102. .ops = &msm_common_be_ops,
  1103. SND_SOC_DAILINK_REG(proxy_tx2),
  1104. },
  1105. /* Proxy Rx BACK END DAI Link */
  1106. {
  1107. .name = LPASS_BE_RT_PROXY_PCM_RX,
  1108. .stream_name = LPASS_BE_RT_PROXY_PCM_RX,
  1109. .playback_only = 1,
  1110. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1111. SND_SOC_DPCM_TRIGGER_POST},
  1112. .ignore_pmdown_time = 1,
  1113. .ignore_suspend = 1,
  1114. .ops = &msm_common_be_ops,
  1115. SND_SOC_DAILINK_REG(proxy_rx),
  1116. },
  1117. {
  1118. .name = LPASS_BE_RT_PROXY_PCM_RX_2,
  1119. .stream_name = LPASS_BE_RT_PROXY_PCM_RX_2,
  1120. .playback_only = 1,
  1121. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1122. SND_SOC_DPCM_TRIGGER_POST},
  1123. .ignore_pmdown_time = 1,
  1124. .ignore_suspend = 1,
  1125. .ops = &msm_common_be_ops,
  1126. SND_SOC_DAILINK_REG(proxy_rx2),
  1127. },
  1128. {
  1129. .name = LPASS_BE_USB_AUDIO_RX,
  1130. .stream_name = LPASS_BE_USB_AUDIO_RX,
  1131. .playback_only = 1,
  1132. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1133. SND_SOC_DPCM_TRIGGER_POST},
  1134. .ignore_pmdown_time = 1,
  1135. .ignore_suspend = 1,
  1136. .ops = &msm_common_be_ops,
  1137. SND_SOC_DAILINK_REG(usb_audio_rx),
  1138. },
  1139. {
  1140. .name = LPASS_BE_USB_AUDIO_TX,
  1141. .stream_name = LPASS_BE_USB_AUDIO_TX,
  1142. .capture_only = 1,
  1143. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1144. SND_SOC_DPCM_TRIGGER_POST},
  1145. .ignore_suspend = 1,
  1146. .ops = &msm_common_be_ops,
  1147. SND_SOC_DAILINK_REG(usb_audio_tx),
  1148. },
  1149. {
  1150. .name = LPASS_BE_PCM_DUMMY_TX_0,
  1151. .stream_name = LPASS_BE_PCM_DUMMY_TX_0,
  1152. .capture_only = 1,
  1153. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1154. SND_SOC_DPCM_TRIGGER_POST},
  1155. .ignore_suspend = 1,
  1156. .ops = &msm_common_be_ops,
  1157. SND_SOC_DAILINK_REG(pcm_dummy_tx0),
  1158. },
  1159. /* Dummy Dev Rx BACK END DAI Link */
  1160. {
  1161. .name = LPASS_BE_PCM_DUMMY_RX_0,
  1162. .stream_name = LPASS_BE_PCM_DUMMY_RX_0,
  1163. .playback_only = 1,
  1164. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1165. SND_SOC_DPCM_TRIGGER_POST},
  1166. .ignore_pmdown_time = 1,
  1167. .ignore_suspend = 1,
  1168. .ops = &msm_common_be_ops,
  1169. SND_SOC_DAILINK_REG(pcm_dummy_rx0),
  1170. },
  1171. /* Dummy Dev Tx BACK END DAI Link */
  1172. {
  1173. .name = LPASS_BE_PCM_DUMMY_TX_1,
  1174. .stream_name = LPASS_BE_PCM_DUMMY_TX_1,
  1175. .capture_only = 1,
  1176. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1177. SND_SOC_DPCM_TRIGGER_POST},
  1178. .ignore_suspend = 1,
  1179. .ops = &msm_common_be_ops,
  1180. SND_SOC_DAILINK_REG(pcm_dummy_tx1),
  1181. },
  1182. };
  1183. #ifndef CONFIG_AUDIO_BTFM_PROXY
  1184. static struct snd_soc_dai_link msm_wcn_be_dai_links[] = {
  1185. {
  1186. .name = LPASS_BE_SLIMBUS_7_RX,
  1187. .stream_name = LPASS_BE_SLIMBUS_7_RX,
  1188. .playback_only = 1,
  1189. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1190. SND_SOC_DPCM_TRIGGER_POST},
  1191. .init = &msm_wcn_init,
  1192. .ops = &msm_common_be_ops,
  1193. /* dai link has playback support */
  1194. .ignore_pmdown_time = 1,
  1195. .ignore_suspend = 1,
  1196. SND_SOC_DAILINK_REG(slimbus_7_rx),
  1197. },
  1198. {
  1199. .name = LPASS_BE_SLIMBUS_7_TX,
  1200. .stream_name = LPASS_BE_SLIMBUS_7_TX,
  1201. .capture_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. SND_SOC_DAILINK_REG(slimbus_7_tx),
  1207. },
  1208. };
  1209. static struct snd_soc_dai_link msm_wcn_btfm_be_dai_links[] = {
  1210. {
  1211. .name = LPASS_BE_SLIMBUS_7_RX,
  1212. .stream_name = LPASS_BE_SLIMBUS_7_RX,
  1213. .playback_only = 1,
  1214. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1215. SND_SOC_DPCM_TRIGGER_POST},
  1216. .init = &msm_wcn_init_btfm,
  1217. .ops = &msm_common_be_ops,
  1218. /* dai link has playback support */
  1219. .ignore_pmdown_time = 1,
  1220. .ignore_suspend = 1,
  1221. SND_SOC_DAILINK_REG(slimbus_7_rx),
  1222. },
  1223. {
  1224. .name = LPASS_BE_SLIMBUS_7_TX,
  1225. .stream_name = LPASS_BE_SLIMBUS_7_TX,
  1226. .capture_only = 1,
  1227. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1228. SND_SOC_DPCM_TRIGGER_POST},
  1229. .ops = &msm_common_be_ops,
  1230. .ignore_suspend = 1,
  1231. SND_SOC_DAILINK_REG(slimbus_7_tx),
  1232. },
  1233. {
  1234. .name = LPASS_BE_SLIMBUS_8_TX,
  1235. .stream_name = LPASS_BE_SLIMBUS_8_TX,
  1236. .capture_only = 1,
  1237. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1238. SND_SOC_DPCM_TRIGGER_POST},
  1239. .init = &msm_wcn_init,
  1240. .ops = &msm_common_be_ops,
  1241. .ignore_suspend = 1,
  1242. SND_SOC_DAILINK_REG(slimbus_8_tx),
  1243. },
  1244. };
  1245. #else
  1246. static struct snd_soc_dai_link msm_wcn_be_dai_links[] = {
  1247. {
  1248. .name = LPASS_BE_BTFM_PROXY_RX_0,
  1249. .stream_name = LPASS_BE_BTFM_PROXY_RX_0,
  1250. .playback_only = 1,
  1251. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1252. SND_SOC_DPCM_TRIGGER_POST},
  1253. .ops = &msm_common_be_ops,
  1254. /* dai link has playback support */
  1255. .ignore_pmdown_time = 1,
  1256. .ignore_suspend = 1,
  1257. SND_SOC_DAILINK_REG(btfm_0_rx),
  1258. },
  1259. {
  1260. .name = LPASS_BE_BTFM_PROXY_TX_0,
  1261. .stream_name = LPASS_BE_BTFM_PROXY_TX_0,
  1262. .capture_only = 1,
  1263. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1264. SND_SOC_DPCM_TRIGGER_POST},
  1265. .ops = &msm_common_be_ops,
  1266. .ignore_suspend = 1,
  1267. SND_SOC_DAILINK_REG(btfm_0_tx),
  1268. },
  1269. };
  1270. #endif
  1271. static struct snd_soc_dai_link ext_disp_be_dai_link[] = {
  1272. /* DISP PORT BACK END DAI Link */
  1273. {
  1274. .name = LPASS_BE_DISPLAY_PORT_RX,
  1275. .stream_name = LPASS_BE_DISPLAY_PORT_RX,
  1276. .playback_only = 1,
  1277. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1278. SND_SOC_DPCM_TRIGGER_POST},
  1279. .ignore_pmdown_time = 1,
  1280. .ignore_suspend = 1,
  1281. SND_SOC_DAILINK_REG(display_port),
  1282. },
  1283. };
  1284. static struct snd_soc_dai_link msm_wsa_cdc_dma_be_dai_links[] = {
  1285. /* WSA CDC DMA Backend DAI Links */
  1286. {
  1287. .name = LPASS_BE_WSA_CDC_DMA_RX_0,
  1288. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_0,
  1289. .playback_only = 1,
  1290. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1291. SND_SOC_DPCM_TRIGGER_POST},
  1292. .ignore_pmdown_time = 1,
  1293. .ignore_suspend = 1,
  1294. .ops = &msm_common_be_ops,
  1295. SND_SOC_DAILINK_REG(wsa_dma_rx0),
  1296. .init = &msm_int_wsa_init,
  1297. },
  1298. {
  1299. .name = LPASS_BE_WSA_CDC_DMA_RX_1,
  1300. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_1,
  1301. .playback_only = 1,
  1302. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1303. SND_SOC_DPCM_TRIGGER_POST},
  1304. .ignore_pmdown_time = 1,
  1305. .ignore_suspend = 1,
  1306. .ops = &msm_common_be_ops,
  1307. SND_SOC_DAILINK_REG(wsa_dma_rx1),
  1308. },
  1309. {
  1310. .name = LPASS_BE_WSA_CDC_DMA_TX_1,
  1311. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_1,
  1312. .capture_only = 1,
  1313. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1314. SND_SOC_DPCM_TRIGGER_POST},
  1315. .ignore_suspend = 1,
  1316. .ops = &msm_common_be_ops,
  1317. SND_SOC_DAILINK_REG(wsa_dma_tx1),
  1318. },
  1319. {
  1320. .name = LPASS_BE_WSA_CDC_DMA_TX_0,
  1321. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_0,
  1322. .capture_only = 1,
  1323. .ignore_suspend = 1,
  1324. .ops = &msm_common_be_ops,
  1325. /* .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, */
  1326. SND_SOC_DAILINK_REG(vi_feedback),
  1327. },
  1328. {
  1329. .name = LPASS_BE_WSA_CDC_DMA_TX_2,
  1330. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_2,
  1331. .capture_only = 1,
  1332. .ignore_suspend = 1,
  1333. .ops = &msm_common_be_ops,
  1334. /* .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, */
  1335. SND_SOC_DAILINK_REG(cps_feedback),
  1336. },
  1337. {
  1338. .name = LPASS_BE_WSA_CDC_DMA_RX_0_VIRT,
  1339. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_0_VIRT,
  1340. .playback_only = 1,
  1341. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1342. SND_SOC_DPCM_TRIGGER_POST},
  1343. .ignore_pmdown_time = 1,
  1344. .ignore_suspend = 1,
  1345. .ops = &msm_common_be_ops,
  1346. SND_SOC_DAILINK_REG(wsa_dma_rx0),
  1347. .init = &msm_int_wsa_init,
  1348. },
  1349. };
  1350. static struct snd_soc_dai_link msm_wsa2_cdc_dma_be_dai_links[] = {
  1351. /* WSA2 CDC DMA Backend DAI Links */
  1352. {
  1353. .name = LPASS_BE_WSA2_CDC_DMA_RX_0,
  1354. .stream_name = LPASS_BE_WSA2_CDC_DMA_RX_0,
  1355. .playback_only = 1,
  1356. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1357. SND_SOC_DPCM_TRIGGER_POST},
  1358. .ignore_pmdown_time = 1,
  1359. .ignore_suspend = 1,
  1360. .ops = &msm_common_be_ops,
  1361. SND_SOC_DAILINK_REG(wsa2_dma_rx0),
  1362. .init = &msm_int_wsa2_init,
  1363. },
  1364. {
  1365. .name = LPASS_BE_WSA2_CDC_DMA_RX_1,
  1366. .stream_name = LPASS_BE_WSA2_CDC_DMA_RX_1,
  1367. .playback_only = 1,
  1368. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1369. SND_SOC_DPCM_TRIGGER_POST},
  1370. .ignore_pmdown_time = 1,
  1371. .ignore_suspend = 1,
  1372. .ops = &msm_common_be_ops,
  1373. SND_SOC_DAILINK_REG(wsa2_dma_rx1),
  1374. },
  1375. {
  1376. .name = LPASS_BE_WSA2_CDC_DMA_TX_1,
  1377. .stream_name = LPASS_BE_WSA2_CDC_DMA_TX_1,
  1378. .capture_only = 1,
  1379. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1380. SND_SOC_DPCM_TRIGGER_POST},
  1381. .ignore_suspend = 1,
  1382. .ops = &msm_common_be_ops,
  1383. SND_SOC_DAILINK_REG(wsa2_dma_tx1),
  1384. },
  1385. {
  1386. .name = LPASS_BE_WSA2_CDC_DMA_TX_0,
  1387. .stream_name = LPASS_BE_WSA2_CDC_DMA_TX_0,
  1388. .capture_only = 1,
  1389. .ignore_suspend = 1,
  1390. .ops = &msm_common_be_ops,
  1391. /* .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, */
  1392. SND_SOC_DAILINK_REG(wsa2_vi_feedback),
  1393. },
  1394. {
  1395. .name = LPASS_BE_WSA2_CDC_DMA_TX_2,
  1396. .stream_name = LPASS_BE_WSA2_CDC_DMA_TX_2,
  1397. .capture_only = 1,
  1398. .ignore_suspend = 1,
  1399. .ops = &msm_common_be_ops,
  1400. /* .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, */
  1401. SND_SOC_DAILINK_REG(wsa2_cps_feedback),
  1402. },
  1403. };
  1404. static struct snd_soc_dai_link msm_wsa_wsa2_cdc_dma_be_dai_links[] = {
  1405. /* WSA CDC DMA Backend DAI Links */
  1406. {
  1407. .name = LPASS_BE_WSA_CDC_DMA_RX_0,
  1408. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_0,
  1409. .playback_only = 1,
  1410. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1411. SND_SOC_DPCM_TRIGGER_POST},
  1412. .ignore_pmdown_time = 1,
  1413. .ignore_suspend = 1,
  1414. .ops = &msm_common_be_ops,
  1415. SND_SOC_DAILINK_REG(wsa_wsa2_dma_rx0),
  1416. .init = &msm_int_wsa_init,
  1417. },
  1418. {
  1419. .name = LPASS_BE_WSA_CDC_DMA_RX_1,
  1420. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_1,
  1421. .playback_only = 1,
  1422. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1423. SND_SOC_DPCM_TRIGGER_POST},
  1424. .ignore_pmdown_time = 1,
  1425. .ignore_suspend = 1,
  1426. .ops = &msm_common_be_ops,
  1427. SND_SOC_DAILINK_REG(wsa_wsa2_dma_rx1),
  1428. },
  1429. {
  1430. .name = LPASS_BE_WSA_CDC_DMA_TX_1,
  1431. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_1,
  1432. .capture_only = 1,
  1433. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1434. SND_SOC_DPCM_TRIGGER_POST},
  1435. .ignore_suspend = 1,
  1436. .ops = &msm_common_be_ops,
  1437. SND_SOC_DAILINK_REG(wsa_wsa2_dma_tx1),
  1438. },
  1439. {
  1440. .name = LPASS_BE_WSA_CDC_DMA_TX_0,
  1441. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_0,
  1442. .capture_only = 1,
  1443. .ignore_suspend = 1,
  1444. .ops = &msm_common_be_ops,
  1445. /* .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, */
  1446. SND_SOC_DAILINK_REG(wsa_wsa2_vi_feedback),
  1447. },
  1448. {
  1449. .name = LPASS_BE_WSA_CDC_DMA_TX_2,
  1450. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_2,
  1451. .capture_only = 1,
  1452. .ignore_suspend = 1,
  1453. .ops = &msm_common_be_ops,
  1454. /* .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, */
  1455. SND_SOC_DAILINK_REG(wsa_wsa2_cps_feedback),
  1456. },
  1457. };
  1458. static struct snd_soc_dai_link msm_rx_tx_cdc_dma_be_dai_links[] = {
  1459. /* RX CDC DMA Backend DAI Links */
  1460. {
  1461. .name = LPASS_BE_RX_CDC_DMA_RX_0,
  1462. .stream_name = LPASS_BE_RX_CDC_DMA_RX_0,
  1463. .playback_only = 1,
  1464. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1465. SND_SOC_DPCM_TRIGGER_POST},
  1466. .ignore_pmdown_time = 1,
  1467. .ignore_suspend = 1,
  1468. .ops = &msm_common_be_ops,
  1469. SND_SOC_DAILINK_REG(rx_dma_rx0),
  1470. .init = &msm_rx_tx_codec_init,
  1471. },
  1472. {
  1473. .name = LPASS_BE_RX_CDC_DMA_RX_1,
  1474. .stream_name = LPASS_BE_RX_CDC_DMA_RX_1,
  1475. .playback_only = 1,
  1476. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1477. SND_SOC_DPCM_TRIGGER_POST},
  1478. .ignore_pmdown_time = 1,
  1479. .ignore_suspend = 1,
  1480. .ops = &msm_common_be_ops,
  1481. SND_SOC_DAILINK_REG(rx_dma_rx1),
  1482. .init = &msm_int_wsa881x_init,
  1483. },
  1484. {
  1485. .name = LPASS_BE_RX_CDC_DMA_RX_2,
  1486. .stream_name = LPASS_BE_RX_CDC_DMA_RX_2,
  1487. .playback_only = 1,
  1488. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1489. SND_SOC_DPCM_TRIGGER_POST},
  1490. .ignore_pmdown_time = 1,
  1491. .ignore_suspend = 1,
  1492. .ops = &msm_common_be_ops,
  1493. SND_SOC_DAILINK_REG(rx_dma_rx2),
  1494. },
  1495. {
  1496. .name = LPASS_BE_RX_CDC_DMA_RX_3,
  1497. .stream_name = LPASS_BE_RX_CDC_DMA_RX_3,
  1498. .playback_only = 1,
  1499. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1500. SND_SOC_DPCM_TRIGGER_POST},
  1501. .ignore_pmdown_time = 1,
  1502. .ignore_suspend = 1,
  1503. .ops = &msm_common_be_ops,
  1504. SND_SOC_DAILINK_REG(rx_dma_rx3),
  1505. },
  1506. {
  1507. .name = LPASS_BE_RX_CDC_DMA_RX_5,
  1508. .stream_name = LPASS_BE_RX_CDC_DMA_RX_5,
  1509. .playback_only = 1,
  1510. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1511. SND_SOC_DPCM_TRIGGER_POST},
  1512. .ignore_pmdown_time = 1,
  1513. .ignore_suspend = 1,
  1514. .ops = &msm_common_be_ops,
  1515. SND_SOC_DAILINK_REG(rx_dma_rx5),
  1516. },
  1517. {
  1518. .name = LPASS_BE_RX_CDC_DMA_RX_6,
  1519. .stream_name = LPASS_BE_RX_CDC_DMA_RX_6,
  1520. .playback_only = 1,
  1521. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1522. SND_SOC_DPCM_TRIGGER_POST},
  1523. .ignore_pmdown_time = 1,
  1524. .ignore_suspend = 1,
  1525. .ops = &msm_common_be_ops,
  1526. SND_SOC_DAILINK_REG(rx_dma_rx6),
  1527. },
  1528. /* TX CDC DMA Backend DAI Links */
  1529. {
  1530. .name = LPASS_BE_TX_CDC_DMA_TX_3,
  1531. .stream_name = LPASS_BE_TX_CDC_DMA_TX_3,
  1532. .capture_only = 1,
  1533. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1534. SND_SOC_DPCM_TRIGGER_POST},
  1535. .ignore_suspend = 1,
  1536. .ops = &msm_common_be_ops,
  1537. SND_SOC_DAILINK_REG(tx_dma_tx3),
  1538. },
  1539. {
  1540. .name = LPASS_BE_TX_CDC_DMA_TX_4,
  1541. .stream_name = LPASS_BE_TX_CDC_DMA_TX_4,
  1542. .capture_only = 1,
  1543. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1544. SND_SOC_DPCM_TRIGGER_POST},
  1545. .ignore_suspend = 1,
  1546. .ops = &msm_common_be_ops,
  1547. SND_SOC_DAILINK_REG(tx_dma_tx4),
  1548. },
  1549. {
  1550. .name = LPASS_BE_RX_CDC_DMA_RX_1_VIRT,
  1551. .stream_name = LPASS_BE_RX_CDC_DMA_RX_1_VIRT,
  1552. .playback_only = 1,
  1553. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1554. SND_SOC_DPCM_TRIGGER_POST},
  1555. .ignore_pmdown_time = 1,
  1556. .ignore_suspend = 1,
  1557. .ops = &msm_common_be_ops,
  1558. SND_SOC_DAILINK_REG(rx_dma_rx1),
  1559. .init = &msm_int_wsa881x_init,
  1560. },
  1561. };
  1562. static struct snd_soc_dai_link msm_va_cdc_dma_be_dai_links[] = {
  1563. {
  1564. .name = LPASS_BE_VA_CDC_DMA_TX_0,
  1565. .stream_name = LPASS_BE_VA_CDC_DMA_TX_0,
  1566. .capture_only = 1,
  1567. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1568. SND_SOC_DPCM_TRIGGER_POST},
  1569. .ignore_suspend = 1,
  1570. .ops = &msm_common_be_ops,
  1571. SND_SOC_DAILINK_REG(va_dma_tx0),
  1572. },
  1573. {
  1574. .name = LPASS_BE_VA_CDC_DMA_TX_1,
  1575. .stream_name = LPASS_BE_VA_CDC_DMA_TX_1,
  1576. .capture_only = 1,
  1577. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1578. SND_SOC_DPCM_TRIGGER_POST},
  1579. .ignore_suspend = 1,
  1580. .ops = &msm_common_be_ops,
  1581. SND_SOC_DAILINK_REG(va_dma_tx1),
  1582. },
  1583. {
  1584. .name = LPASS_BE_VA_CDC_DMA_TX_2,
  1585. .stream_name = LPASS_BE_VA_CDC_DMA_TX_2,
  1586. .capture_only = 1,
  1587. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1588. SND_SOC_DPCM_TRIGGER_POST},
  1589. .ignore_suspend = 1,
  1590. .ops = &msm_common_be_ops,
  1591. SND_SOC_DAILINK_REG(va_dma_tx2),
  1592. },
  1593. };
  1594. /*
  1595. * I2S interface pinctrl mapping
  1596. * ------------------------------------
  1597. * Primary - pri_mi2s
  1598. * Secondary - lpi_i2s3
  1599. * Tertiary - tert_mi2s
  1600. * Quaternary - quat_mi2s (lpi_i2s0)
  1601. * Quinary - lpi_i2s1
  1602. * Senary - lpi_i2s2
  1603. * ------------------------------------
  1604. */
  1605. static struct snd_soc_dai_link msm_mi2s_dai_links[] = {
  1606. {
  1607. .name = LPASS_BE_PRI_MI2S_RX,
  1608. .stream_name = LPASS_BE_PRI_MI2S_RX,
  1609. .playback_only = 1,
  1610. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1611. SND_SOC_DPCM_TRIGGER_POST},
  1612. .ops = &msm_common_be_ops,
  1613. .ignore_suspend = 1,
  1614. .ignore_pmdown_time = 1,
  1615. SND_SOC_DAILINK_REG(pri_mi2s_rx),
  1616. },
  1617. {
  1618. .name = LPASS_BE_PRI_MI2S_TX,
  1619. .stream_name = LPASS_BE_PRI_MI2S_TX,
  1620. .capture_only = 1,
  1621. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1622. SND_SOC_DPCM_TRIGGER_POST},
  1623. .ops = &msm_common_be_ops,
  1624. .ignore_suspend = 1,
  1625. SND_SOC_DAILINK_REG(pri_mi2s_tx),
  1626. },
  1627. {
  1628. .name = LPASS_BE_SEC_MI2S_RX,
  1629. .stream_name = LPASS_BE_SEC_MI2S_RX,
  1630. .playback_only = 1,
  1631. #ifdef CONFIG_USE_CS40L26
  1632. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS
  1633. | SND_SOC_DAIFMT_NB_NF,
  1634. #endif
  1635. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1636. SND_SOC_DPCM_TRIGGER_POST},
  1637. .ops = &msm_common_be_ops,
  1638. .ignore_suspend = 1,
  1639. .ignore_pmdown_time = 1,
  1640. SND_SOC_DAILINK_REG(sec_mi2s_rx),
  1641. },
  1642. {
  1643. .name = LPASS_BE_SEC_MI2S_TX,
  1644. .stream_name = LPASS_BE_SEC_MI2S_TX,
  1645. .capture_only = 1,
  1646. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1647. SND_SOC_DPCM_TRIGGER_POST},
  1648. .ops = &msm_common_be_ops,
  1649. .ignore_suspend = 1,
  1650. SND_SOC_DAILINK_REG(sec_mi2s_tx),
  1651. },
  1652. {
  1653. .name = LPASS_BE_TERT_MI2S_RX,
  1654. .stream_name = LPASS_BE_TERT_MI2S_RX,
  1655. .playback_only = 1,
  1656. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1657. SND_SOC_DPCM_TRIGGER_POST},
  1658. .ops = &msm_common_be_ops,
  1659. .ignore_suspend = 1,
  1660. .ignore_pmdown_time = 1,
  1661. SND_SOC_DAILINK_REG(tert_mi2s_rx),
  1662. },
  1663. {
  1664. .name = LPASS_BE_TERT_MI2S_TX,
  1665. .stream_name = LPASS_BE_TERT_MI2S_TX,
  1666. .capture_only = 1,
  1667. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1668. SND_SOC_DPCM_TRIGGER_POST},
  1669. .ops = &msm_common_be_ops,
  1670. .ignore_suspend = 1,
  1671. SND_SOC_DAILINK_REG(tert_mi2s_tx),
  1672. },
  1673. {
  1674. .name = LPASS_BE_QUAT_MI2S_RX,
  1675. .stream_name = LPASS_BE_QUAT_MI2S_RX,
  1676. .playback_only = 1,
  1677. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1678. SND_SOC_DPCM_TRIGGER_POST},
  1679. .ops = &msm_common_be_ops,
  1680. .ignore_suspend = 1,
  1681. .ignore_pmdown_time = 1,
  1682. SND_SOC_DAILINK_REG(quat_mi2s_rx),
  1683. },
  1684. {
  1685. .name = LPASS_BE_QUAT_MI2S_TX,
  1686. .stream_name = LPASS_BE_QUAT_MI2S_TX,
  1687. .capture_only = 1,
  1688. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1689. SND_SOC_DPCM_TRIGGER_POST},
  1690. .ops = &msm_common_be_ops,
  1691. .ignore_suspend = 1,
  1692. SND_SOC_DAILINK_REG(quat_mi2s_tx),
  1693. },
  1694. {
  1695. .name = LPASS_BE_QUIN_MI2S_RX,
  1696. .stream_name = LPASS_BE_QUIN_MI2S_RX,
  1697. .playback_only = 1,
  1698. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1699. SND_SOC_DPCM_TRIGGER_POST},
  1700. .ops = &msm_common_be_ops,
  1701. .ignore_suspend = 1,
  1702. .ignore_pmdown_time = 1,
  1703. SND_SOC_DAILINK_REG(quin_mi2s_rx),
  1704. },
  1705. {
  1706. .name = LPASS_BE_QUIN_MI2S_TX,
  1707. .stream_name = LPASS_BE_QUIN_MI2S_TX,
  1708. .capture_only = 1,
  1709. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1710. SND_SOC_DPCM_TRIGGER_POST},
  1711. .ops = &msm_common_be_ops,
  1712. .ignore_suspend = 1,
  1713. SND_SOC_DAILINK_REG(quin_mi2s_tx),
  1714. },
  1715. {
  1716. .name = LPASS_BE_SEN_MI2S_RX,
  1717. .stream_name = LPASS_BE_SEN_MI2S_RX,
  1718. .playback_only = 1,
  1719. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1720. SND_SOC_DPCM_TRIGGER_POST},
  1721. .ops = &msm_common_be_ops,
  1722. .ignore_suspend = 1,
  1723. .ignore_pmdown_time = 1,
  1724. SND_SOC_DAILINK_REG(sen_mi2s_rx),
  1725. },
  1726. {
  1727. .name = LPASS_BE_SEN_MI2S_TX,
  1728. .stream_name = LPASS_BE_SEN_MI2S_TX,
  1729. .capture_only = 1,
  1730. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1731. SND_SOC_DPCM_TRIGGER_POST},
  1732. .ops = &msm_common_be_ops,
  1733. .ignore_suspend = 1,
  1734. SND_SOC_DAILINK_REG(sen_mi2s_tx),
  1735. },
  1736. {
  1737. .name = LPASS_BE_SEP_MI2S_RX,
  1738. .stream_name = LPASS_BE_SEP_MI2S_RX,
  1739. .playback_only = 1,
  1740. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1741. SND_SOC_DPCM_TRIGGER_POST},
  1742. .ops = &msm_common_be_ops,
  1743. .ignore_suspend = 1,
  1744. .ignore_pmdown_time = 1,
  1745. SND_SOC_DAILINK_REG(sep_mi2s_rx),
  1746. },
  1747. {
  1748. .name = LPASS_BE_SEP_MI2S_TX,
  1749. .stream_name = LPASS_BE_SEP_MI2S_TX,
  1750. .capture_only = 1,
  1751. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1752. SND_SOC_DPCM_TRIGGER_POST},
  1753. .ops = &msm_common_be_ops,
  1754. .ignore_suspend = 1,
  1755. SND_SOC_DAILINK_REG(sep_mi2s_tx),
  1756. },
  1757. };
  1758. static struct snd_soc_dai_link msm_tdm_dai_links[] = {
  1759. {
  1760. .name = LPASS_BE_PRI_TDM_RX_0,
  1761. .stream_name = LPASS_BE_PRI_TDM_RX_0,
  1762. .playback_only = 1,
  1763. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1764. SND_SOC_DPCM_TRIGGER_POST},
  1765. #ifdef CONFIG_COMMON_AMP_CIRRUS
  1766. .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_CBS_CFS
  1767. | SND_SOC_DAIFMT_IB_NF,
  1768. .init = &pineapple_tdm_cirrus_init,
  1769. .ops = &msm_common_be_ops,
  1770. .ignore_suspend = 1,
  1771. .ignore_pmdown_time = 1,
  1772. SND_SOC_DAILINK_REG(cirrus_pri_tdm_rx_0),
  1773. #elif defined(CONFIG_SND_SOC_TAS25XX)
  1774. .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_CBS_CFS
  1775. | SND_SOC_DAIFMT_IB_NF,
  1776. .init = &pineapple_tdm_tas_init,
  1777. .ops = &msm_common_be_ops,
  1778. .ignore_suspend = 1,
  1779. .ignore_pmdown_time = 1,
  1780. SND_SOC_DAILINK_REG(tas25xx_pri_tdm_rx_0),
  1781. #else
  1782. .ops = &msm_common_be_ops,
  1783. .ignore_suspend = 1,
  1784. .ignore_pmdown_time = 1,
  1785. SND_SOC_DAILINK_REG(pri_tdm_rx_0),
  1786. #endif
  1787. },
  1788. {
  1789. .name = LPASS_BE_PRI_TDM_TX_0,
  1790. .stream_name = LPASS_BE_PRI_TDM_TX_0,
  1791. .capture_only = 1,
  1792. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1793. SND_SOC_DPCM_TRIGGER_POST},
  1794. #ifdef CONFIG_COMMON_AMP_CIRRUS
  1795. .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_CBS_CFS
  1796. | SND_SOC_DAIFMT_IB_NF,
  1797. .ops = &msm_common_be_ops,
  1798. .ignore_suspend = 1,
  1799. SND_SOC_DAILINK_REG(cirrus_pri_tdm_tx_0),
  1800. #elif defined(CONFIG_SND_SOC_TAS25XX)
  1801. .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_CBS_CFS
  1802. | SND_SOC_DAIFMT_IB_NF,
  1803. .ops = &msm_common_be_ops,
  1804. .ignore_suspend = 1,
  1805. SND_SOC_DAILINK_REG(tas25xx_pri_tdm_tx_0),
  1806. #else
  1807. .ops = &msm_common_be_ops,
  1808. .ignore_suspend = 1,
  1809. SND_SOC_DAILINK_REG(pri_tdm_tx_0),
  1810. #endif
  1811. },
  1812. {
  1813. .name = LPASS_BE_SEC_TDM_RX_0,
  1814. .stream_name = LPASS_BE_SEC_TDM_RX_0,
  1815. .playback_only = 1,
  1816. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1817. SND_SOC_DPCM_TRIGGER_POST},
  1818. .ops = &msm_common_be_ops,
  1819. .ignore_suspend = 1,
  1820. .ignore_pmdown_time = 1,
  1821. SND_SOC_DAILINK_REG(sec_tdm_rx_0),
  1822. },
  1823. {
  1824. .name = LPASS_BE_SEC_TDM_TX_0,
  1825. .stream_name = LPASS_BE_SEC_TDM_TX_0,
  1826. .capture_only = 1,
  1827. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1828. SND_SOC_DPCM_TRIGGER_POST},
  1829. .ops = &msm_common_be_ops,
  1830. .ignore_suspend = 1,
  1831. SND_SOC_DAILINK_REG(sec_tdm_tx_0),
  1832. },
  1833. {
  1834. .name = LPASS_BE_TERT_TDM_RX_0,
  1835. .stream_name = LPASS_BE_TERT_TDM_RX_0,
  1836. .playback_only = 1,
  1837. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1838. SND_SOC_DPCM_TRIGGER_POST},
  1839. .ops = &msm_common_be_ops,
  1840. .ignore_suspend = 1,
  1841. .ignore_pmdown_time = 1,
  1842. SND_SOC_DAILINK_REG(tert_tdm_rx_0),
  1843. },
  1844. {
  1845. .name = LPASS_BE_TERT_TDM_TX_0,
  1846. .stream_name = LPASS_BE_TERT_TDM_TX_0,
  1847. .capture_only = 1,
  1848. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1849. SND_SOC_DPCM_TRIGGER_POST},
  1850. .ops = &msm_common_be_ops,
  1851. .ignore_suspend = 1,
  1852. SND_SOC_DAILINK_REG(tert_tdm_tx_0),
  1853. },
  1854. {
  1855. .name = LPASS_BE_QUAT_TDM_RX_0,
  1856. .stream_name = LPASS_BE_QUAT_TDM_RX_0,
  1857. .playback_only = 1,
  1858. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1859. SND_SOC_DPCM_TRIGGER_POST},
  1860. .ops = &msm_common_be_ops,
  1861. .ignore_suspend = 1,
  1862. .ignore_pmdown_time = 1,
  1863. SND_SOC_DAILINK_REG(quat_tdm_rx_0),
  1864. },
  1865. {
  1866. .name = LPASS_BE_QUAT_TDM_TX_0,
  1867. .stream_name = LPASS_BE_QUAT_TDM_TX_0,
  1868. .capture_only = 1,
  1869. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1870. SND_SOC_DPCM_TRIGGER_POST},
  1871. .ops = &msm_common_be_ops,
  1872. .ignore_suspend = 1,
  1873. SND_SOC_DAILINK_REG(quat_tdm_tx_0),
  1874. },
  1875. {
  1876. .name = LPASS_BE_QUIN_TDM_RX_0,
  1877. .stream_name = LPASS_BE_QUIN_TDM_RX_0,
  1878. .playback_only = 1,
  1879. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1880. SND_SOC_DPCM_TRIGGER_POST},
  1881. .ops = &msm_common_be_ops,
  1882. .ignore_suspend = 1,
  1883. .ignore_pmdown_time = 1,
  1884. SND_SOC_DAILINK_REG(quin_tdm_rx_0),
  1885. },
  1886. {
  1887. .name = LPASS_BE_QUIN_TDM_TX_0,
  1888. .stream_name = LPASS_BE_QUIN_TDM_TX_0,
  1889. .capture_only = 1,
  1890. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1891. SND_SOC_DPCM_TRIGGER_POST},
  1892. .ops = &msm_common_be_ops,
  1893. .ignore_suspend = 1,
  1894. SND_SOC_DAILINK_REG(quin_tdm_tx_0),
  1895. },
  1896. {
  1897. .name = LPASS_BE_SEN_TDM_RX_0,
  1898. .stream_name = LPASS_BE_SEN_TDM_RX_0,
  1899. .playback_only = 1,
  1900. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1901. SND_SOC_DPCM_TRIGGER_POST},
  1902. .ops = &msm_common_be_ops,
  1903. .ignore_suspend = 1,
  1904. .ignore_pmdown_time = 1,
  1905. SND_SOC_DAILINK_REG(sen_tdm_rx_0),
  1906. },
  1907. {
  1908. .name = LPASS_BE_SEN_TDM_TX_0,
  1909. .stream_name = LPASS_BE_SEN_TDM_TX_0,
  1910. .capture_only = 1,
  1911. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1912. SND_SOC_DPCM_TRIGGER_POST},
  1913. .ops = &msm_common_be_ops,
  1914. .ignore_suspend = 1,
  1915. SND_SOC_DAILINK_REG(sen_tdm_tx_0),
  1916. },
  1917. {
  1918. .name = LPASS_BE_SEP_TDM_RX_0,
  1919. .stream_name = LPASS_BE_SEP_TDM_RX_0,
  1920. .playback_only = 1,
  1921. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1922. SND_SOC_DPCM_TRIGGER_POST},
  1923. .ops = &msm_common_be_ops,
  1924. .ignore_suspend = 1,
  1925. .ignore_pmdown_time = 1,
  1926. SND_SOC_DAILINK_REG(sep_tdm_rx_0),
  1927. },
  1928. {
  1929. .name = LPASS_BE_SEP_TDM_TX_0,
  1930. .stream_name = LPASS_BE_SEP_TDM_TX_0,
  1931. .capture_only = 1,
  1932. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1933. SND_SOC_DPCM_TRIGGER_POST},
  1934. .ops = &msm_common_be_ops,
  1935. .ignore_suspend = 1,
  1936. SND_SOC_DAILINK_REG(sep_tdm_tx_0),
  1937. },
  1938. };
  1939. static struct snd_soc_dai_link msm_pineapple_dai_links[
  1940. ARRAY_SIZE(msm_wsa_cdc_dma_be_dai_links) +
  1941. ARRAY_SIZE(msm_wsa2_cdc_dma_be_dai_links) +
  1942. ARRAY_SIZE(msm_wsa_wsa2_cdc_dma_be_dai_links) +
  1943. ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links) +
  1944. ARRAY_SIZE(msm_va_cdc_dma_be_dai_links) +
  1945. ARRAY_SIZE(ext_disp_be_dai_link) +
  1946. ARRAY_SIZE(msm_common_be_dai_links) +
  1947. #ifndef CONFIG_AUDIO_BTFM_PROXY
  1948. ARRAY_SIZE(msm_wcn_btfm_be_dai_links) +
  1949. #endif
  1950. ARRAY_SIZE(msm_wcn_be_dai_links) +
  1951. ARRAY_SIZE(msm_mi2s_dai_links) +
  1952. ARRAY_SIZE(msm_tdm_dai_links)];
  1953. static int msm_populate_dai_link_component_of_node(
  1954. struct snd_soc_card *card)
  1955. {
  1956. int i, j, index, ret = 0;
  1957. struct device *cdev = card->dev;
  1958. struct snd_soc_dai_link *dai_link = card->dai_link;
  1959. struct device_node *np = NULL;
  1960. int codecs_enabled = 0;
  1961. struct snd_soc_dai_link_component *codecs_comp = NULL;
  1962. if (!cdev) {
  1963. dev_err_ratelimited(cdev, "%s: Sound card device memory NULL\n", __func__);
  1964. return -ENODEV;
  1965. }
  1966. for (i = 0; i < card->num_links; i++) {
  1967. if (dai_link[i].init == NULL)
  1968. dai_link[i].init = &msm_common_dai_link_init;
  1969. /* populate codec_of_node for snd card dai links */
  1970. if (dai_link[i].num_codecs > 0) {
  1971. for (j = 0; j < dai_link[i].num_codecs; j++) {
  1972. if (dai_link[i].codecs[j].of_node ||
  1973. !dai_link[i].codecs[j].name)
  1974. continue;
  1975. index = of_property_match_string(cdev->of_node,
  1976. "asoc-codec-names",
  1977. dai_link[i].codecs[j].name);
  1978. if (index < 0)
  1979. continue;
  1980. np = of_parse_phandle(cdev->of_node,
  1981. "asoc-codec",
  1982. index);
  1983. if (!np) {
  1984. dev_err_ratelimited(cdev,
  1985. "%s: retrieving phandle for codec %s failed\n",
  1986. __func__,
  1987. dai_link[i].codecs[j].name);
  1988. ret = -ENODEV;
  1989. goto err;
  1990. }
  1991. dai_link[i].codecs[j].of_node = np;
  1992. dai_link[i].codecs[j].name = NULL;
  1993. }
  1994. }
  1995. }
  1996. /* In multi-codec scenario, check if codecs are enabled for this platform */
  1997. for (i = 0; i < card->num_links; i++) {
  1998. codecs_enabled = 0;
  1999. if (dai_link[i].num_codecs > 1) {
  2000. for (j = 0; j < dai_link[i].num_codecs; j++) {
  2001. if (!dai_link[i].codecs[j].of_node)
  2002. continue;
  2003. np = dai_link[i].codecs[j].of_node;
  2004. if (!of_device_is_available(np)) {
  2005. dev_err_ratelimited(cdev, "%s: codec is disabled: %s\n",
  2006. __func__,
  2007. np->full_name);
  2008. dai_link[i].codecs[j].of_node = NULL;
  2009. continue;
  2010. }
  2011. codecs_enabled++;
  2012. }
  2013. if (codecs_enabled > 0 &&
  2014. codecs_enabled < dai_link[i].num_codecs) {
  2015. codecs_comp = devm_kzalloc(cdev,
  2016. sizeof(struct snd_soc_dai_link_component)
  2017. * codecs_enabled, GFP_KERNEL);
  2018. if (!codecs_comp) {
  2019. dev_err_ratelimited(cdev,
  2020. "%s: %s dailink codec component alloc failed\n",
  2021. __func__, dai_link[i].name);
  2022. ret = -ENOMEM;
  2023. goto err;
  2024. }
  2025. index = 0;
  2026. for (j = 0; j < dai_link[i].num_codecs; j++) {
  2027. if(dai_link[i].codecs[j].of_node) {
  2028. codecs_comp[index].of_node =
  2029. dai_link[i].codecs[j].of_node;
  2030. codecs_comp[index].dai_name =
  2031. dai_link[i].codecs[j].dai_name;
  2032. codecs_comp[index].name = NULL;
  2033. index++;
  2034. }
  2035. }
  2036. dai_link[i].codecs = codecs_comp;
  2037. dai_link[i].num_codecs = codecs_enabled;
  2038. }
  2039. }
  2040. }
  2041. err:
  2042. return ret;
  2043. }
  2044. static int msm_audrx_stub_init(struct snd_soc_pcm_runtime *rtd)
  2045. {
  2046. return 0;
  2047. }
  2048. static int msm_snd_stub_hw_params(struct snd_pcm_substream *substream,
  2049. struct snd_pcm_hw_params *params)
  2050. {
  2051. return 0;
  2052. }
  2053. static struct snd_soc_ops msm_stub_be_ops = {
  2054. .hw_params = msm_snd_stub_hw_params,
  2055. };
  2056. struct snd_soc_card snd_soc_card_stub_msm = {
  2057. .name = "pineapple-stub-snd-card",
  2058. };
  2059. static struct snd_soc_dai_link msm_stub_be_dai_links[] = {
  2060. /* Backend DAI Links */
  2061. {
  2062. .name = LPASS_BE_PRI_AUXPCM_RX,
  2063. .stream_name = LPASS_BE_PRI_AUXPCM_RX,
  2064. .playback_only = 1,
  2065. .init = &msm_audrx_stub_init,
  2066. .ignore_pmdown_time = 1,
  2067. .ignore_suspend = 1,
  2068. .ops = &msm_stub_be_ops,
  2069. SND_SOC_DAILINK_REG(auxpcm_rx),
  2070. },
  2071. {
  2072. .name = LPASS_BE_PRI_AUXPCM_TX,
  2073. .stream_name = LPASS_BE_PRI_AUXPCM_TX,
  2074. .capture_only = 1,
  2075. .ignore_suspend = 1,
  2076. .ops = &msm_stub_be_ops,
  2077. SND_SOC_DAILINK_REG(auxpcm_tx),
  2078. },
  2079. };
  2080. static struct snd_soc_dai_link msm_stub_dai_links[
  2081. ARRAY_SIZE(msm_stub_be_dai_links)];
  2082. static const struct of_device_id pineapple_asoc_machine_of_match[] = {
  2083. { .compatible = "qcom,pineapple-asoc-snd",
  2084. .data = "codec"},
  2085. { .compatible = "qcom,pineapple-asoc-snd-stub",
  2086. .data = "stub_codec"},
  2087. {},
  2088. };
  2089. static int msm_snd_card_late_probe(struct snd_soc_card *card)
  2090. {
  2091. struct snd_soc_component *component = NULL;
  2092. struct snd_soc_pcm_runtime *rtd;
  2093. struct msm_asoc_mach_data *pdata;
  2094. int ret = 0;
  2095. void *mbhc_calibration;
  2096. char wcd_name[20];
  2097. pdata = snd_soc_card_get_drvdata(card);
  2098. if (!pdata)
  2099. return -EINVAL;
  2100. if (pdata->wcd_disabled)
  2101. return 0;
  2102. rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
  2103. if (!rtd) {
  2104. dev_err(card->dev,
  2105. "%s: snd_soc_get_pcm_runtime for %s failed!\n",
  2106. __func__, card->dai_link[0]);
  2107. return -EINVAL;
  2108. }
  2109. if (pdata->wcd_used == WCD937X_DEV_INDEX)
  2110. strscpy(wcd_name, WCD937X_DRV_NAME, sizeof(WCD937X_DRV_NAME));
  2111. else if (pdata->wcd_used == WCD9378_DEV_INDEX)
  2112. strscpy(wcd_name, WCD9378_DRV_NAME, sizeof(WCD9378_DRV_NAME));
  2113. else
  2114. strscpy(wcd_name, WCD939X_DRV_NAME, sizeof(WCD939X_DRV_NAME));
  2115. component = snd_soc_rtdcom_lookup(rtd, wcd_name);
  2116. if (!component) {
  2117. pr_err("%s component is NULL\n", __func__);
  2118. return -EINVAL;
  2119. }
  2120. mbhc_calibration = def_wcd_mbhc_cal();
  2121. if (!mbhc_calibration)
  2122. return -ENOMEM;
  2123. wcd_mbhc_cfg.calibration = mbhc_calibration;
  2124. #if IS_ENABLED(CONFIG_QCOM_WCD_USBSS_I2C)
  2125. if (of_find_property(card->dev->of_node,
  2126. "qcom,usbss-hsj-connect-enabled", NULL))
  2127. wcd_mbhc_cfg.usbss_hsj_connect_enable = true;
  2128. #endif
  2129. switch (pdata->wcd_used) {
  2130. case WCD937X_DEV_INDEX:
  2131. ret = wcd937x_mbhc_hs_detect(component, &wcd_mbhc_cfg);
  2132. break;
  2133. case WCD9378_DEV_INDEX:
  2134. ret = wcd9378_mbhc_hs_detect(component, &wcd_mbhc_cfg);
  2135. break;
  2136. case WCD939X_DEV_INDEX:
  2137. ret = wcd939x_mbhc_hs_detect(component, &wcd_mbhc_cfg);
  2138. break;
  2139. default:
  2140. return -EINVAL;
  2141. }
  2142. if (ret) {
  2143. dev_err(component->dev, "%s: mbhc hs detect failed, err:%d\n",
  2144. __func__, ret);
  2145. goto err_hs_detect;
  2146. }
  2147. return 0;
  2148. err_hs_detect:
  2149. kfree(mbhc_calibration);
  2150. return ret;
  2151. }
  2152. #ifdef CONFIG_SEC_FACTORY
  2153. /*
  2154. * check whether subpcb is connected or not.
  2155. * gpio level to low - sub pcb is connected.
  2156. * gpio level to high -sub pcb is disconnected.
  2157. */
  2158. static int check_upper_c2c_det(struct device *dev)
  2159. {
  2160. int upper_c2c_det = -1;
  2161. int gpio_level = 0;
  2162. upper_c2c_det = of_get_named_gpio(dev->of_node,
  2163. "upper-c2c-det-gpio", 0);
  2164. if (gpio_is_valid(upper_c2c_det)) {
  2165. gpio_level = gpio_get_value(upper_c2c_det);
  2166. dev_info(dev, "%s: upper_c2c_det(%d) is %s\n",
  2167. __func__, upper_c2c_det, gpio_level ?
  2168. "disconnected":"connected");
  2169. if (gpio_level)
  2170. sdp_boot_print("%s: upper_c2c_det(%d) is disconnected\n",
  2171. __func__, upper_c2c_det);
  2172. }
  2173. return gpio_level;
  2174. }
  2175. #endif
  2176. static struct snd_soc_card *populate_snd_card_dailinks(struct device *dev, int wsa_max_devs)
  2177. {
  2178. struct snd_soc_card *card = NULL;
  2179. struct snd_soc_dai_link *dailink = NULL;
  2180. int total_links = 0;
  2181. int rc = 0;
  2182. u32 val = 0;
  2183. const struct of_device_id *match;
  2184. match = of_match_node(pineapple_asoc_machine_of_match, dev->of_node);
  2185. if (!match) {
  2186. dev_err_ratelimited(dev, "%s: No DT match found for sound card\n",
  2187. __func__);
  2188. return NULL;
  2189. }
  2190. #ifdef CONFIG_SEC_FACTORY
  2191. sub_pcb_conn = check_upper_c2c_det(dev);
  2192. #endif
  2193. if (!strcmp(match->data, "codec")) {
  2194. card = &snd_soc_card_pineapple_msm;
  2195. /* late probe uses dai link at index '0' to get wcd component */
  2196. memcpy(msm_pineapple_dai_links + total_links,
  2197. msm_rx_tx_cdc_dma_be_dai_links,
  2198. sizeof(msm_rx_tx_cdc_dma_be_dai_links));
  2199. total_links +=
  2200. ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links);
  2201. switch (wsa_max_devs) {
  2202. case MONO_SPEAKER:
  2203. case STEREO_SPEAKER:
  2204. memcpy(msm_pineapple_dai_links + total_links,
  2205. msm_wsa_cdc_dma_be_dai_links,
  2206. sizeof(msm_wsa_cdc_dma_be_dai_links));
  2207. total_links += ARRAY_SIZE(msm_wsa_cdc_dma_be_dai_links);
  2208. break;
  2209. case QUAD_SPEAKER:
  2210. if (of_find_property(dev->of_node,
  2211. "qcom,dedicated-wsa2", NULL)) {
  2212. memcpy(msm_pineapple_dai_links + total_links,
  2213. msm_wsa_cdc_dma_be_dai_links,
  2214. sizeof(msm_wsa_cdc_dma_be_dai_links));
  2215. total_links += ARRAY_SIZE(msm_wsa_cdc_dma_be_dai_links);
  2216. memcpy(msm_pineapple_dai_links + total_links,
  2217. msm_wsa2_cdc_dma_be_dai_links,
  2218. sizeof(msm_wsa2_cdc_dma_be_dai_links));
  2219. total_links += ARRAY_SIZE(msm_wsa2_cdc_dma_be_dai_links);
  2220. } else {
  2221. memcpy(msm_pineapple_dai_links + total_links,
  2222. msm_wsa2_cdc_dma_be_dai_links,
  2223. sizeof(msm_wsa2_cdc_dma_be_dai_links));
  2224. total_links += ARRAY_SIZE(msm_wsa2_cdc_dma_be_dai_links);
  2225. memcpy(msm_pineapple_dai_links + total_links,
  2226. msm_wsa_wsa2_cdc_dma_be_dai_links,
  2227. sizeof(msm_wsa_wsa2_cdc_dma_be_dai_links));
  2228. total_links += ARRAY_SIZE(msm_wsa_wsa2_cdc_dma_be_dai_links);
  2229. }
  2230. break;
  2231. default:
  2232. dev_dbg(dev,
  2233. "%s: Unexpected number of WSAs, wsa_max_devs: %d\n",
  2234. __func__, wsa_max_devs);
  2235. break;
  2236. }
  2237. memcpy(msm_pineapple_dai_links + total_links,
  2238. msm_va_cdc_dma_be_dai_links,
  2239. sizeof(msm_va_cdc_dma_be_dai_links));
  2240. total_links += ARRAY_SIZE(msm_va_cdc_dma_be_dai_links);
  2241. memcpy(msm_pineapple_dai_links + total_links,
  2242. msm_common_be_dai_links,
  2243. sizeof(msm_common_be_dai_links));
  2244. total_links += ARRAY_SIZE(msm_common_be_dai_links);
  2245. rc = of_property_read_u32(dev->of_node,
  2246. "qcom,mi2s-audio-intf", &val);
  2247. if (!rc && val && !sub_pcb_conn) {
  2248. memcpy(msm_pineapple_dai_links + total_links,
  2249. msm_mi2s_dai_links,
  2250. sizeof(msm_mi2s_dai_links));
  2251. total_links += ARRAY_SIZE(msm_mi2s_dai_links);
  2252. }
  2253. rc = of_property_read_u32(dev->of_node,
  2254. "qcom,tdm-audio-intf", &val);
  2255. if (!rc && val && !sub_pcb_conn) {
  2256. memcpy(msm_pineapple_dai_links + total_links,
  2257. msm_tdm_dai_links,
  2258. sizeof(msm_tdm_dai_links));
  2259. total_links += ARRAY_SIZE(msm_tdm_dai_links);
  2260. }
  2261. rc = of_property_read_u32(dev->of_node,
  2262. "qcom,ext-disp-audio-rx", &val);
  2263. if (!rc && val) {
  2264. if (!socinfo_get_part_info(PART_DISPLAY)) {
  2265. dev_dbg(dev, "%s(): ext disp audio support present\n",
  2266. __func__);
  2267. memcpy(msm_pineapple_dai_links + total_links,
  2268. ext_disp_be_dai_link,
  2269. sizeof(ext_disp_be_dai_link));
  2270. total_links += ARRAY_SIZE(ext_disp_be_dai_link);
  2271. }
  2272. }
  2273. rc = of_property_read_u32(dev->of_node, "qcom,wcn-bt", &val);
  2274. if (!rc && val) {
  2275. dev_dbg(dev, "%s(): WCN BT support present\n",
  2276. __func__);
  2277. memcpy(msm_pineapple_dai_links + total_links,
  2278. msm_wcn_be_dai_links,
  2279. sizeof(msm_wcn_be_dai_links));
  2280. total_links += ARRAY_SIZE(msm_wcn_be_dai_links);
  2281. #ifndef CONFIG_AUDIO_BTFM_PROXY
  2282. } else {
  2283. rc = of_property_read_u32(dev->of_node, "qcom,wcn-btfm", &val);
  2284. if (!rc && val) {
  2285. dev_dbg(dev, "%s(): WCN BT FM support present\n",
  2286. __func__);
  2287. memcpy(msm_pineapple_dai_links + total_links,
  2288. msm_wcn_btfm_be_dai_links,
  2289. sizeof(msm_wcn_btfm_be_dai_links));
  2290. total_links += ARRAY_SIZE(msm_wcn_btfm_be_dai_links);
  2291. }
  2292. #endif
  2293. }
  2294. dailink = msm_pineapple_dai_links;
  2295. } else if(!strcmp(match->data, "stub_codec")) {
  2296. card = &snd_soc_card_stub_msm;
  2297. memcpy(msm_stub_dai_links,
  2298. msm_stub_be_dai_links,
  2299. sizeof(msm_stub_be_dai_links));
  2300. dailink = msm_stub_dai_links;
  2301. total_links = ARRAY_SIZE(msm_stub_be_dai_links);
  2302. }
  2303. if (card) {
  2304. card->dai_link = dailink;
  2305. card->num_links = total_links;
  2306. if (!strcmp(match->data, "codec"))
  2307. card->late_probe = msm_snd_card_late_probe;
  2308. }
  2309. return card;
  2310. }
  2311. static int msm_int_wsa883x_init(struct snd_soc_pcm_runtime *rtd)
  2312. {
  2313. u8 spkleft_ports[WSA883X_MAX_SWR_PORTS] = {0, 1, 2, 3};
  2314. u8 spkright_ports[WSA883X_MAX_SWR_PORTS] = {0, 1, 2, 3};
  2315. u8 spkleft_port_types[WSA883X_MAX_SWR_PORTS] = {SPKR_L, SPKR_L_COMP,
  2316. SPKR_L_BOOST, SPKR_L_VI};
  2317. u8 spkright_port_types[WSA883X_MAX_SWR_PORTS] = {SPKR_R, SPKR_R_COMP,
  2318. SPKR_R_BOOST, SPKR_R_VI};
  2319. unsigned int ch_rate[WSA883X_MAX_SWR_PORTS] = {SWR_CLK_RATE_2P4MHZ, SWR_CLK_RATE_0P6MHZ,
  2320. SWR_CLK_RATE_0P3MHZ, SWR_CLK_RATE_1P2MHZ};
  2321. unsigned int ch_mask[WSA883X_MAX_SWR_PORTS] = {0x1, 0xF, 0x3, 0x3};
  2322. struct snd_soc_component *component = NULL;
  2323. struct msm_asoc_mach_data *pdata =
  2324. snd_soc_card_get_drvdata(rtd->card);
  2325. if (pdata->wsa_max_devs > 0) {
  2326. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.1");
  2327. if (!component) {
  2328. pr_err("%s: wsa-codec.1 component is NULL\n", __func__);
  2329. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.2");
  2330. if (!component) {
  2331. pr_err("%s: wsa-codec.2 component is NULL\n", __func__);
  2332. return -EINVAL;
  2333. }
  2334. wsa883x_set_channel_map(component, &spkright_ports[0],
  2335. WSA883X_MAX_SWR_PORTS, &ch_mask[0],
  2336. &ch_rate[0], &spkright_port_types[0]);
  2337. wsa883x_codec_info_create_codec_entry(pdata->codec_root,
  2338. component);
  2339. } else {
  2340. wsa883x_set_channel_map(component, &spkleft_ports[0],
  2341. WSA883X_MAX_SWR_PORTS, &ch_mask[0],
  2342. &ch_rate[0], &spkleft_port_types[0]);
  2343. wsa883x_codec_info_create_codec_entry(pdata->codec_root,
  2344. component);
  2345. }
  2346. }
  2347. /* If current platform has more than one WSA */
  2348. if (pdata->wsa_max_devs > 1) {
  2349. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.2");
  2350. if (!component) {
  2351. pr_err("%s: wsa-codec.2 component is NULL\n", __func__);
  2352. return -EINVAL;
  2353. }
  2354. wsa883x_set_channel_map(component, &spkright_ports[0],
  2355. WSA883X_MAX_SWR_PORTS, &ch_mask[0],
  2356. &ch_rate[0], &spkright_port_types[0]);
  2357. wsa883x_codec_info_create_codec_entry(pdata->codec_root,
  2358. component);
  2359. }
  2360. if (!pdata->dedicated_wsa2) {
  2361. if (pdata->wsa_max_devs > 2) {
  2362. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.3");
  2363. if (!component) {
  2364. pr_err("%s: wsa-codec.3 component is NULL\n", __func__);
  2365. return -EINVAL;
  2366. }
  2367. wsa883x_set_channel_map(component, &spkleft_ports[0],
  2368. WSA883X_MAX_SWR_PORTS, &ch_mask[0],
  2369. &ch_rate[0], &spkleft_port_types[0]);
  2370. wsa883x_codec_info_create_codec_entry(pdata->codec_root,
  2371. component);
  2372. }
  2373. if (pdata->wsa_max_devs > 3) {
  2374. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.4");
  2375. if (!component) {
  2376. pr_err("%s: wsa-codec.4 component is NULL\n", __func__);
  2377. return -EINVAL;
  2378. }
  2379. wsa883x_set_channel_map(component, &spkright_ports[0],
  2380. WSA883X_MAX_SWR_PORTS, &ch_mask[0],
  2381. &ch_rate[0], &spkright_port_types[0]);
  2382. wsa883x_codec_info_create_codec_entry(pdata->codec_root,
  2383. component);
  2384. }
  2385. }
  2386. msm_common_dai_link_init(rtd);
  2387. return 0;
  2388. }
  2389. static int msm_int_wsa884x_init(struct snd_soc_pcm_runtime *rtd)
  2390. {
  2391. u8 spkleft_ports[WSA884X_MAX_SWR_PORTS] = {0, 1, 2, 3, 4, 5};
  2392. u8 spkright_ports[WSA884X_MAX_SWR_PORTS] = {0, 1, 2, 3, 4, 5};
  2393. u8 spkleft_port_types[WSA884X_MAX_SWR_PORTS] = {SPKR_L, SPKR_L_COMP,
  2394. SPKR_L_BOOST, PBR, SPKR_L_VI, CPS};
  2395. u8 spkright_port_types[WSA884X_MAX_SWR_PORTS] = {SPKR_R, SPKR_R_COMP,
  2396. SPKR_R_BOOST, PBR, SPKR_R_VI, CPS};
  2397. unsigned int ch_rate[WSA884X_MAX_SWR_PORTS] = {SWR_CLK_RATE_2P4MHZ, SWR_CLK_RATE_0P6MHZ,
  2398. SWR_CLK_RATE_0P3MHZ, SWR_CLK_RATE_48KHZ,
  2399. SWR_CLK_RATE_1P2MHZ, SWR_CLK_RATE_24KHZ};
  2400. unsigned int ch_mask[WSA884X_MAX_SWR_PORTS] = {0x1, 0xF, 0x3, 0x1, 0x3, 0x3};
  2401. struct snd_soc_component *component = NULL;
  2402. struct msm_asoc_mach_data *pdata =
  2403. snd_soc_card_get_drvdata(rtd->card);
  2404. if (pdata->wsa_max_devs > 0) {
  2405. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.1");
  2406. if (!component) {
  2407. pr_err("%s: wsa-codec.1 component is NULL\n", __func__);
  2408. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.2");
  2409. if (!component) {
  2410. pr_err("%s: wsa-codec.2 component is NULL\n", __func__);
  2411. return -EINVAL;
  2412. }
  2413. wsa884x_set_channel_map(component, &spkright_ports[0],
  2414. WSA884X_MAX_SWR_PORTS, &ch_mask[0],
  2415. &ch_rate[0], &spkright_port_types[0]);
  2416. wsa884x_codec_info_create_codec_entry(pdata->codec_root,
  2417. component);
  2418. } else {
  2419. wsa884x_set_channel_map(component, &spkleft_ports[0],
  2420. WSA884X_MAX_SWR_PORTS, &ch_mask[0],
  2421. &ch_rate[0], &spkleft_port_types[0]);
  2422. wsa884x_codec_info_create_codec_entry(pdata->codec_root,
  2423. component);
  2424. }
  2425. }
  2426. /* If current platform has more than one WSA */
  2427. if (pdata->wsa_max_devs > 1) {
  2428. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.2");
  2429. if (!component) {
  2430. pr_err("%s: wsa-codec.2 component is NULL\n", __func__);
  2431. return -EINVAL;
  2432. }
  2433. wsa884x_set_channel_map(component, &spkright_ports[0],
  2434. WSA884X_MAX_SWR_PORTS, &ch_mask[0],
  2435. &ch_rate[0], &spkright_port_types[0]);
  2436. wsa884x_codec_info_create_codec_entry(pdata->codec_root,
  2437. component);
  2438. }
  2439. if (!pdata->dedicated_wsa2) {
  2440. if (pdata->wsa_max_devs > 2) {
  2441. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.3");
  2442. if (!component) {
  2443. pr_err("%s: wsa-codec.3 component is NULL\n", __func__);
  2444. return -EINVAL;
  2445. }
  2446. wsa884x_set_channel_map(component, &spkleft_ports[0],
  2447. WSA884X_MAX_SWR_PORTS, &ch_mask[0],
  2448. &ch_rate[0], &spkleft_port_types[0]);
  2449. wsa884x_codec_info_create_codec_entry(pdata->codec_root,
  2450. component);
  2451. }
  2452. if (pdata->wsa_max_devs > 3) {
  2453. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.4");
  2454. if (!component) {
  2455. pr_err("%s: wsa-codec.4 component is NULL\n", __func__);
  2456. return -EINVAL;
  2457. }
  2458. wsa884x_set_channel_map(component, &spkright_ports[0],
  2459. WSA884X_MAX_SWR_PORTS, &ch_mask[0],
  2460. &ch_rate[0], &spkright_port_types[0]);
  2461. wsa884x_codec_info_create_codec_entry(pdata->codec_root,
  2462. component);
  2463. }
  2464. }
  2465. msm_common_dai_link_init(rtd);
  2466. return 0;
  2467. }
  2468. static int msm_int_wsa881x_init(struct snd_soc_pcm_runtime *rtd)
  2469. {
  2470. struct msm_asoc_mach_data *pdata =
  2471. snd_soc_card_get_drvdata(rtd->card);
  2472. if (pdata->wsa_max_devs == 0)
  2473. pr_info("%s: WSA is not enabled\n", __func__);
  2474. msm_common_dai_link_init(rtd);
  2475. return 0;
  2476. }
  2477. static int msm_int_wsa_init(struct snd_soc_pcm_runtime *rtd)
  2478. {
  2479. if (strstr(rtd->card->name, "wsa883x"))
  2480. return msm_int_wsa883x_init(rtd);
  2481. return msm_int_wsa884x_init(rtd);
  2482. }
  2483. static int msm_int_wsa883x_2_init(struct snd_soc_pcm_runtime *rtd)
  2484. {
  2485. u8 spkleft_ports[WSA883X_MAX_SWR_PORTS] = {0, 1, 2, 3};
  2486. u8 spkright_ports[WSA883X_MAX_SWR_PORTS] = {0, 1, 2, 3};
  2487. u8 spkleft_port_types[WSA883X_MAX_SWR_PORTS] = {SPKR_L, SPKR_L_COMP,
  2488. SPKR_L_BOOST, SPKR_L_VI};
  2489. u8 spkright_port_types[WSA883X_MAX_SWR_PORTS] = {SPKR_R, SPKR_R_COMP,
  2490. SPKR_R_BOOST, SPKR_R_VI};
  2491. unsigned int ch_rate[WSA883X_MAX_SWR_PORTS] = {SWR_CLK_RATE_2P4MHZ, SWR_CLK_RATE_0P6MHZ,
  2492. SWR_CLK_RATE_0P3MHZ, SWR_CLK_RATE_1P2MHZ};
  2493. unsigned int ch_mask[WSA883X_MAX_SWR_PORTS] = {0x1, 0xF, 0x3, 0x3};
  2494. struct snd_soc_component *component = NULL;
  2495. struct msm_asoc_mach_data *pdata =
  2496. snd_soc_card_get_drvdata(rtd->card);
  2497. if (pdata->dedicated_wsa2) {
  2498. if (pdata->wsa_max_devs > 2) {
  2499. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.3");
  2500. if (!component) {
  2501. pr_err("%s: wsa-codec.3 component is NULL\n", __func__);
  2502. return -EINVAL;
  2503. }
  2504. wsa883x_set_channel_map(component, &spkleft_ports[0],
  2505. WSA883X_MAX_SWR_PORTS, &ch_mask[0],
  2506. &ch_rate[0], &spkleft_port_types[0]);
  2507. wsa883x_codec_info_create_codec_entry(pdata->codec_root,
  2508. component);
  2509. }
  2510. if (pdata->wsa_max_devs > 3) {
  2511. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.4");
  2512. if (!component) {
  2513. pr_err("%s: wsa-codec.4 component is NULL\n", __func__);
  2514. return -EINVAL;
  2515. }
  2516. wsa883x_set_channel_map(component, &spkright_ports[0],
  2517. WSA883X_MAX_SWR_PORTS, &ch_mask[0],
  2518. &ch_rate[0], &spkright_port_types[0]);
  2519. wsa883x_codec_info_create_codec_entry(pdata->codec_root,
  2520. component);
  2521. }
  2522. msm_common_dai_link_init(rtd);
  2523. }
  2524. return 0;
  2525. }
  2526. static int msm_int_wsa884x_2_init(struct snd_soc_pcm_runtime *rtd)
  2527. {
  2528. u8 spkleft_ports[WSA884X_MAX_SWR_PORTS] = {0, 1, 2, 3, 4, 5};
  2529. u8 spkright_ports[WSA884X_MAX_SWR_PORTS] = {0, 1, 2, 3, 4, 5};
  2530. u8 spkleft_port_types[WSA884X_MAX_SWR_PORTS] = {SPKR_L, SPKR_L_COMP,
  2531. SPKR_L_BOOST, PBR, SPKR_L_VI, CPS};
  2532. u8 spkright_port_types[WSA884X_MAX_SWR_PORTS] = {SPKR_R, SPKR_R_COMP,
  2533. SPKR_R_BOOST, PBR, SPKR_R_VI, CPS};
  2534. unsigned int ch_rate[WSA884X_MAX_SWR_PORTS] = {SWR_CLK_RATE_2P4MHZ, SWR_CLK_RATE_0P6MHZ,
  2535. SWR_CLK_RATE_0P3MHZ, SWR_CLK_RATE_48KHZ,
  2536. SWR_CLK_RATE_1P2MHZ, SWR_CLK_RATE_24KHZ};
  2537. unsigned int ch_mask[WSA884X_MAX_SWR_PORTS] = {0x1, 0xF, 0x3, 0x1, 0x3, 0x3};
  2538. struct snd_soc_component *component = NULL;
  2539. struct msm_asoc_mach_data *pdata =
  2540. snd_soc_card_get_drvdata(rtd->card);
  2541. if (pdata->dedicated_wsa2) {
  2542. if (pdata->wsa_max_devs > 2) {
  2543. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.3");
  2544. if (!component) {
  2545. pr_err("%s: wsa-codec.3 component is NULL\n", __func__);
  2546. return -EINVAL;
  2547. }
  2548. wsa884x_set_channel_map(component, &spkleft_ports[0],
  2549. WSA884X_MAX_SWR_PORTS, &ch_mask[0],
  2550. &ch_rate[0], &spkleft_port_types[0]);
  2551. wsa884x_codec_info_create_codec_entry(pdata->codec_root,
  2552. component);
  2553. }
  2554. if (pdata->wsa_max_devs > 3) {
  2555. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.4");
  2556. if (!component) {
  2557. pr_err("%s: wsa-codec.4 component is NULL\n", __func__);
  2558. return -EINVAL;
  2559. }
  2560. wsa884x_set_channel_map(component, &spkright_ports[0],
  2561. WSA884X_MAX_SWR_PORTS, &ch_mask[0],
  2562. &ch_rate[0], &spkright_port_types[0]);
  2563. wsa884x_codec_info_create_codec_entry(pdata->codec_root,
  2564. component);
  2565. }
  2566. msm_common_dai_link_init(rtd);
  2567. }
  2568. return 0;
  2569. }
  2570. static int msm_int_wsa2_init(struct snd_soc_pcm_runtime *rtd)
  2571. {
  2572. if (strstr(rtd->card->name, "wsa883x"))
  2573. return msm_int_wsa883x_2_init(rtd);
  2574. return msm_int_wsa884x_2_init(rtd);
  2575. }
  2576. static int msm_rx_tx_codec_init(struct snd_soc_pcm_runtime *rtd)
  2577. {
  2578. int codec_variant = -1;
  2579. struct snd_soc_component *component = NULL;
  2580. struct snd_soc_component *lpass_cdc_component = NULL;
  2581. struct snd_soc_dapm_context *dapm = NULL;
  2582. struct snd_info_entry *entry = NULL;
  2583. struct snd_card *card = NULL;
  2584. #ifdef CONFIG_COMMON_AMP_CIRRUS
  2585. struct snd_soc_card *rtd_card = rtd->card;
  2586. #endif
  2587. struct msm_asoc_mach_data *pdata =
  2588. snd_soc_card_get_drvdata(rtd->card);
  2589. int ret = 0;
  2590. lpass_cdc_component = snd_soc_rtdcom_lookup(rtd, "lpass-cdc");
  2591. if (!lpass_cdc_component) {
  2592. pr_err("%s: could not find component for lpass-cdc\n",
  2593. __func__);
  2594. return ret;
  2595. }
  2596. dapm = snd_soc_component_get_dapm(lpass_cdc_component);
  2597. #ifdef CONFIG_COMMON_AMP_CIRRUS
  2598. ret = snd_soc_add_component_controls(lpass_cdc_component, msm_cirrus_snd_controls,
  2599. ARRAY_SIZE(msm_cirrus_snd_controls));
  2600. if (ret < 0) {
  2601. pr_err("%s: add_component_controls failed: %d\n",
  2602. __func__, ret);
  2603. return ret;
  2604. }
  2605. #endif
  2606. snd_soc_dapm_new_controls(dapm, msm_int_dapm_widgets,
  2607. ARRAY_SIZE(msm_int_dapm_widgets));
  2608. #ifdef CONFIG_COMMON_AMP_CIRRUS
  2609. if(!sub_pcb_conn) {
  2610. switch (cirrus_amp_conf) {
  2611. case CS35L43_MONO:
  2612. case CS35L45_MONO:
  2613. snd_soc_dapm_add_routes(&rtd_card->dapm, cirrus_mono_routes,
  2614. ARRAY_SIZE(cirrus_mono_routes));
  2615. break;
  2616. case CS35L43_STEREO:
  2617. case CS35L45_STEREO:
  2618. snd_soc_dapm_add_routes(&rtd_card->dapm, cirrus_stereo_routes,
  2619. ARRAY_SIZE(cirrus_stereo_routes));
  2620. break;
  2621. case CS35L43_QUAD:
  2622. case CS35L45_QUAD:
  2623. snd_soc_dapm_add_routes(&rtd_card->dapm, cirrus_quad_routes,
  2624. ARRAY_SIZE(cirrus_quad_routes));
  2625. break;
  2626. default:
  2627. pr_err("%s: cirrus amp conf is not defined\n",
  2628. __func__);
  2629. break;
  2630. }
  2631. }
  2632. #endif
  2633. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic0");
  2634. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic1");
  2635. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic2");
  2636. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic3");
  2637. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic4");
  2638. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic5");
  2639. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic6");
  2640. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic7");
  2641. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic1");
  2642. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic2");
  2643. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic3");
  2644. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic4");
  2645. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic5");
  2646. #ifdef CONFIG_COMMON_AMP_CIRRUS
  2647. snd_soc_dapm_ignore_suspend(dapm, "AMP0 SPK");
  2648. snd_soc_dapm_ignore_suspend(dapm, "AMP1 SPK");
  2649. snd_soc_dapm_ignore_suspend(dapm, "AMP2 SPK");
  2650. snd_soc_dapm_ignore_suspend(dapm, "AMP3 SPK");
  2651. #endif
  2652. lpass_cdc_set_port_map(lpass_cdc_component, ARRAY_SIZE(sm_port_map), sm_port_map);
  2653. card = rtd->card->snd_card;
  2654. if (!pdata->codec_root) {
  2655. entry = msm_snd_info_create_subdir(card->module, "codecs",
  2656. card->proc_root);
  2657. if (!entry) {
  2658. pr_debug("%s: Cannot create codecs module entry\n",
  2659. __func__);
  2660. return ret;
  2661. }
  2662. pdata->codec_root = entry;
  2663. }
  2664. lpass_cdc_info_create_codec_entry(pdata->codec_root, lpass_cdc_component);
  2665. lpass_cdc_register_wake_irq(lpass_cdc_component, false);
  2666. if (pdata->wcd_disabled)
  2667. goto done;
  2668. component = snd_soc_rtdcom_lookup(rtd, WCD939X_DRV_NAME);
  2669. if (!component) {
  2670. component = snd_soc_rtdcom_lookup(rtd, WCD937X_DRV_NAME);
  2671. if (!component) {
  2672. component = snd_soc_rtdcom_lookup(rtd, WCD9378_DRV_NAME);
  2673. if (!component) {
  2674. pr_err("%s component is NULL\n", __func__);
  2675. ret = -EINVAL;
  2676. goto exit;
  2677. } else {
  2678. pdata->wcd_used = WCD9378_DEV_INDEX;
  2679. }
  2680. } else {
  2681. pdata->wcd_used = WCD937X_DEV_INDEX;
  2682. }
  2683. } else {
  2684. pdata->wcd_used = WCD939X_DEV_INDEX;
  2685. }
  2686. dapm = snd_soc_component_get_dapm(component);
  2687. card = component->card->snd_card;
  2688. snd_soc_dapm_ignore_suspend(dapm, "EAR");
  2689. if (pdata->wcd_used != WCD939X_DEV_INDEX)
  2690. snd_soc_dapm_ignore_suspend(dapm, "AUX");
  2691. snd_soc_dapm_ignore_suspend(dapm, "HPHL");
  2692. snd_soc_dapm_ignore_suspend(dapm, "HPHR");
  2693. snd_soc_dapm_ignore_suspend(dapm, "AMIC1");
  2694. snd_soc_dapm_ignore_suspend(dapm, "AMIC2");
  2695. snd_soc_dapm_ignore_suspend(dapm, "AMIC3");
  2696. snd_soc_dapm_ignore_suspend(dapm, "AMIC4");
  2697. snd_soc_dapm_sync(dapm);
  2698. pdata = snd_soc_card_get_drvdata(component->card);
  2699. if (!pdata->codec_root) {
  2700. entry = msm_snd_info_create_subdir(card->module, "codecs",
  2701. card->proc_root);
  2702. if (!entry) {
  2703. dev_dbg(component->dev, "%s: Cannot create codecs module entry\n",
  2704. __func__);
  2705. return 0;
  2706. }
  2707. pdata->codec_root = entry;
  2708. }
  2709. if (pdata->wcd_used == WCD937X_DEV_INDEX) {
  2710. wcd937x_info_create_codec_entry(pdata->codec_root, component);
  2711. codec_variant = wcd937x_get_codec_variant(component);
  2712. dev_dbg(component->dev, "%s: variant %d\n", __func__, codec_variant);
  2713. } else if (pdata->wcd_used == WCD9378_DEV_INDEX) {
  2714. wcd9378_info_create_codec_entry(pdata->codec_root, component);
  2715. } else {
  2716. wcd939x_info_create_codec_entry(pdata->codec_root, component);
  2717. codec_variant = wcd939x_get_codec_variant(component);
  2718. dev_dbg(component->dev, "%s: variant %d\n", __func__, codec_variant);
  2719. #ifdef CONFIG_BOLERO_VER_2P6
  2720. if (codec_variant == WCD9395)
  2721. ret = lpass_cdc_rx_set_fir_capability(lpass_cdc_component, true);
  2722. else
  2723. ret = lpass_cdc_rx_set_fir_capability(lpass_cdc_component, false);
  2724. #endif
  2725. }
  2726. if (ret < 0) {
  2727. dev_err_ratelimited(component->dev, "%s: set fir capability failed: %d\n",
  2728. __func__, ret);
  2729. return ret;
  2730. }
  2731. done:
  2732. codec_reg_done = true;
  2733. msm_common_dai_link_init(rtd);
  2734. exit:
  2735. return ret;
  2736. }
  2737. static int pineapple_ssr_enable(struct device *dev, void *data)
  2738. {
  2739. struct platform_device *pdev = to_platform_device(dev);
  2740. struct snd_soc_card *card = platform_get_drvdata(pdev);
  2741. struct snd_soc_pcm_runtime *rtd = NULL, *rtd_wcd = NULL, *rtd_wsa = NULL;
  2742. struct msm_asoc_mach_data *pdata = NULL;
  2743. int ret = 0;
  2744. if (!card) {
  2745. dev_err_ratelimited(dev, "%s: card is NULL\n", __func__);
  2746. ret = -EINVAL;
  2747. goto err;
  2748. }
  2749. if (!strcmp(card->name, "pineapple-stub-snd-card")) {
  2750. /* TODO */
  2751. dev_dbg(dev, "%s: TODO \n", __func__);
  2752. }
  2753. snd_card_notify_user(SND_CARD_STATUS_ONLINE);
  2754. dev_dbg(dev, "%s: setting snd_card to ONLINE\n", __func__);
  2755. pdata = snd_soc_card_get_drvdata(card);
  2756. if (!pdata) {
  2757. dev_dbg(dev, "%s: pdata is NULL \n", __func__);
  2758. goto err;
  2759. }
  2760. rtd_wcd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
  2761. if (!rtd_wcd) {
  2762. dev_dbg(dev,
  2763. "%s: snd_soc_get_pcm_runtime for %s failed!\n",
  2764. __func__, card->dai_link[0]);
  2765. }
  2766. if (pdata->wsa_max_devs > 0) {
  2767. rtd_wsa = snd_soc_get_pcm_runtime(card,
  2768. &card->dai_link[ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links)]);
  2769. if (!rtd_wsa) {
  2770. dev_dbg(dev,
  2771. "%s: snd_soc_get_pcm_runtime for %s failed!\n",
  2772. __func__, card->dai_link[ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links)]);
  2773. }
  2774. }
  2775. /* set UPD configuration */
  2776. if(!pdata->upd_config.backend_used) {
  2777. dev_dbg(dev,
  2778. "%s: upd- backend_used is NULL\n", __func__);
  2779. goto err;
  2780. }
  2781. if (!strcmp(pdata->upd_config.backend_used, "wsa")) {
  2782. if (!rtd_wsa)
  2783. goto err;
  2784. else
  2785. rtd = rtd_wsa;
  2786. } else if(!strcmp(pdata->upd_config.backend_used, "wcd")) {
  2787. if (!rtd_wcd &&!pdata->wcd_disabled)
  2788. goto err;
  2789. else
  2790. rtd = rtd_wcd;
  2791. } else {
  2792. dev_err_ratelimited(card->dev, "%s: Invalid backend to set UPD config\n",
  2793. __func__);
  2794. goto err;
  2795. }
  2796. msm_set_upd_config(rtd);
  2797. err:
  2798. return ret;
  2799. }
  2800. static void pineapple_ssr_disable(struct device *dev, void *data)
  2801. {
  2802. struct platform_device *pdev = to_platform_device(dev);
  2803. struct snd_soc_card *card = platform_get_drvdata(pdev);
  2804. if (!card) {
  2805. dev_err_ratelimited(dev, "%s: card is NULL\n", __func__);
  2806. return;
  2807. }
  2808. dev_dbg(dev, "%s: setting snd_card to OFFLINE\n", __func__);
  2809. snd_card_notify_user(SND_CARD_STATUS_OFFLINE);
  2810. if (!strcmp(card->name, "pineapple-stub-snd-card")) {
  2811. /* TODO */
  2812. dev_dbg(dev, "%s: TODO \n", __func__);
  2813. }
  2814. }
  2815. static const struct snd_event_ops pineapple_ssr_ops = {
  2816. .enable = pineapple_ssr_enable,
  2817. .disable = pineapple_ssr_disable,
  2818. };
  2819. static int msm_audio_ssr_compare(struct device *dev, void *data)
  2820. {
  2821. struct device_node *node = data;
  2822. dev_dbg(dev, "%s: dev->of_node = 0x%p, node = 0x%p\n",
  2823. __func__, dev->of_node, node);
  2824. return (dev->of_node && dev->of_node == node);
  2825. }
  2826. static int msm_audio_ssr_register(struct device *dev)
  2827. {
  2828. struct device_node *np = dev->of_node;
  2829. struct snd_event_clients *ssr_clients = NULL;
  2830. struct device_node *node = NULL;
  2831. int ret = 0;
  2832. int i = 0;
  2833. for (i = 0; ; i++) {
  2834. node = of_parse_phandle(np, "qcom,msm_audio_ssr_devs", i);
  2835. if (!node)
  2836. break;
  2837. snd_event_mstr_add_client(&ssr_clients,
  2838. msm_audio_ssr_compare, node);
  2839. }
  2840. ret = snd_event_master_register(dev, &pineapple_ssr_ops,
  2841. ssr_clients, NULL);
  2842. if (!ret)
  2843. snd_event_notify(dev, SND_EVENT_UP);
  2844. return ret;
  2845. }
  2846. struct msm_common_pdata *msm_common_get_pdata(struct snd_soc_card *card)
  2847. {
  2848. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  2849. if (!pdata)
  2850. return NULL;
  2851. return pdata->common_pdata;
  2852. }
  2853. void msm_common_set_pdata(struct snd_soc_card *card,
  2854. struct msm_common_pdata *common_pdata)
  2855. {
  2856. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  2857. if (!pdata)
  2858. return;
  2859. pdata->common_pdata = common_pdata;
  2860. }
  2861. #ifdef CONFIG_COMMON_AMP_CIRRUS
  2862. /*
  2863. * update codec name and dai name in runtime
  2864. * to support multiple cirrus amp with one binary.
  2865. */
  2866. static void update_cirrus_dai_link(struct device *dev)
  2867. {
  2868. struct snd_soc_dai_link_component cirrus_dai_link[] = {
  2869. { .name = "snd-soc-dummy", .dai_name = "snd-soc-dummy-dai", },
  2870. { .name = "snd-soc-dummy", .dai_name = "snd-soc-dummy-dai", },
  2871. { .name = "snd-soc-dummy", .dai_name = "snd-soc-dummy-dai", },
  2872. { .name = "snd-soc-dummy", .dai_name = "snd-soc-dummy-dai", },
  2873. };
  2874. struct snd_soc_dai_link *dai_link = msm_tdm_dai_links;
  2875. const char *codec_name = "cirrus-codec-name";
  2876. const char *codec_dai_name = "cirrus-codec-dai-name";
  2877. int i, ret = 0;
  2878. #if IS_ENABLED(CONFIG_SND_SOC_SAMSUNG_AUDIO)
  2879. if (defer_count > MAX_DEFER_COUNT)
  2880. return;
  2881. #endif
  2882. dev_info(dev, "%s:\n", __func__);
  2883. for (i = 0; i < cirrus_amp_count; i++) {
  2884. ret = of_property_read_string_index(dev->of_node,
  2885. codec_name, i, &cirrus_dai_link[i].name);
  2886. if (ret) {
  2887. dev_err(dev, "Property '%s' does not exist(%d).\n",
  2888. codec_name, ret);
  2889. return;
  2890. }
  2891. ret = of_property_read_string_index(dev->of_node,
  2892. codec_dai_name, i, &cirrus_dai_link[i].dai_name);
  2893. if (ret) {
  2894. dev_err(dev, "Property '%s' does not exist(%d).\n",
  2895. codec_dai_name, ret);
  2896. return;
  2897. }
  2898. /* 0 : Rx, 1 : Tx */
  2899. dai_link[0].codecs[i].name = cirrus_dai_link[i].name;
  2900. dai_link[1].codecs[i].name = cirrus_dai_link[i].name;
  2901. dai_link[0].codecs[i].dai_name = cirrus_dai_link[i].dai_name;
  2902. dai_link[1].codecs[i].dai_name = cirrus_dai_link[i].dai_name;
  2903. }
  2904. dai_link[0].num_codecs = dai_link[1].num_codecs = cirrus_amp_count;
  2905. }
  2906. #endif
  2907. #if IS_ENABLED(CONFIG_SND_SOC_SAMSUNG_AUDIO)
  2908. /*
  2909. * change codec component to dummy in dailinks
  2910. * when soundcard does not registered several times.
  2911. */
  2912. static void change_snd_card_dailinks(struct snd_soc_card *card)
  2913. {
  2914. int i, j = 0;
  2915. struct snd_soc_dai *dai = NULL;
  2916. sdp_boot_print("%s\n", __func__);
  2917. for (i = 0; i < card->num_links; i++) {
  2918. for (j = 0; j < card->dai_link[i].num_codecs; j++) {
  2919. dai = snd_soc_find_dai(&card->dai_link[i].codecs[j]);
  2920. if(!dai) {
  2921. sdp_boot_print("%s: CANNOT find dai %s\n",
  2922. __func__, card->dai_link[i].codecs[j].name);
  2923. card->dai_link[i].codecs[j].name =
  2924. dummy_compononet.name;
  2925. card->dai_link[i].codecs[j].dai_name =
  2926. dummy_compononet.dai_name;
  2927. card->dai_link[i].init = NULL;
  2928. pr_info("%s: Change codec_dai of %s to DUMMY\n",
  2929. __func__, card->dai_link[i].name);
  2930. }
  2931. }
  2932. }
  2933. return;
  2934. }
  2935. #endif
  2936. #if IS_ENABLED(CONFIG_SND_SOC_SAMSUNG_AUDIO)
  2937. static int get_audio_amp_ready(enum amp_id id)
  2938. {
  2939. #if defined(CONFIG_SND_SOC_TAS25XX)
  2940. int ret = 0;
  2941. ret = tas25xx_get_state(id);
  2942. if (ret > 0) /* amp first i2c successful or amp fully initialized for playback */
  2943. return AMP_INIT_SUCCESS;
  2944. else
  2945. return AMP_INIT_FAIL;
  2946. #endif
  2947. return AMP_CHECK_NOT_SUPPORT;
  2948. }
  2949. #endif
  2950. static int msm_asoc_parse_soundcard_name(struct platform_device *pdev,
  2951. struct snd_soc_card *card)
  2952. {
  2953. struct nvmem_cell *cell = NULL;
  2954. size_t len = 0;
  2955. u32 *buf = NULL;
  2956. u32 adsp_var_idx = 0;
  2957. int ret = 0;
  2958. /* get adsp variant idx */
  2959. cell = nvmem_cell_get(&pdev->dev, "adsp_variant");
  2960. if (IS_ERR_OR_NULL(cell)) {
  2961. dev_dbg(&pdev->dev, "%s: FAILED to get nvmem cell\n", __func__);
  2962. goto parse;
  2963. }
  2964. buf = nvmem_cell_read(cell, &len);
  2965. nvmem_cell_put(cell);
  2966. if (IS_ERR_OR_NULL(buf)) {
  2967. dev_dbg(&pdev->dev, "%s: FAILED to read nvmem cell\n", __func__);
  2968. goto parse;
  2969. }
  2970. if (len <= 0 || len > sizeof(u32)) {
  2971. dev_dbg(&pdev->dev, "%s: nvmem cell length out of range: %d\n",
  2972. __func__, len);
  2973. kfree(buf);
  2974. goto parse;
  2975. }
  2976. memcpy(&adsp_var_idx, buf, len);
  2977. kfree(buf);
  2978. parse:
  2979. if (adsp_var_idx)
  2980. ret = snd_soc_of_parse_card_name(card, "qcom,sku-model");
  2981. else
  2982. ret = snd_soc_of_parse_card_name(card, "qcom,model");
  2983. if (ret)
  2984. dev_err(&pdev->dev, "%s: parse card name failed, err:%d\n",
  2985. __func__, ret);
  2986. return ret;
  2987. }
  2988. static int msm_asoc_machine_probe(struct platform_device *pdev)
  2989. {
  2990. struct snd_soc_card *card = NULL;
  2991. struct msm_asoc_mach_data *pdata = NULL;
  2992. int ret = 0;
  2993. struct clk *lpass_audio_hw_vote = NULL;
  2994. const struct of_device_id *match;
  2995. pr_info("%s enter\n", __func__);
  2996. if (!pdev->dev.of_node) {
  2997. dev_err(&pdev->dev, "%s: No platform supplied from device tree\n", __func__);
  2998. return -EINVAL;
  2999. }
  3000. pdata = devm_kzalloc(&pdev->dev,
  3001. sizeof(struct msm_asoc_mach_data), GFP_KERNEL);
  3002. if (!pdata)
  3003. return -ENOMEM;
  3004. of_property_read_u32(pdev->dev.of_node,
  3005. "qcom,wcd-disabled",
  3006. &pdata->wcd_disabled);
  3007. /* Get maximum WSA device count for this platform */
  3008. ret = of_property_read_u32(pdev->dev.of_node,
  3009. "qcom,wsa-max-devs", &pdata->wsa_max_devs);
  3010. if (ret) {
  3011. dev_info(&pdev->dev,
  3012. "%s: wsa-max-devs property missing in DT %s, ret = %d\n",
  3013. __func__, pdev->dev.of_node->full_name, ret);
  3014. pdata->wsa_max_devs = 0;
  3015. }
  3016. /* Check if WSA2 Backends were used for dedicated usecase */
  3017. pdata->dedicated_wsa2 = of_find_property(pdev->dev.of_node,
  3018. "qcom,dedicated-wsa2", NULL);
  3019. #ifdef CONFIG_COMMON_AMP_CIRRUS
  3020. ret = of_property_read_u32(pdev->dev.of_node,
  3021. "cirrus-amp-conf", &cirrus_amp_conf);
  3022. if (ret) {
  3023. dev_dbg(&pdev->dev,
  3024. "%s: codec_conf property missing in DT %s, ret = %d\n",
  3025. __func__, pdev->dev.of_node->full_name, ret);
  3026. cirrus_amp_conf = 0x32;
  3027. }
  3028. cirrus_amp_count = cirrus_amp_conf & 0x0F;
  3029. dev_info(&pdev->dev, "%s: cirrus amp conf=0x%x\n",
  3030. __func__, cirrus_amp_conf);
  3031. if (cirrus_amp_count > 0 && cirrus_amp_count < 5)
  3032. update_cirrus_dai_link(&pdev->dev);
  3033. #endif
  3034. card = populate_snd_card_dailinks(&pdev->dev, pdata->wsa_max_devs);
  3035. if (!card) {
  3036. dev_err(&pdev->dev, "%s: Card uninitialized\n", __func__);
  3037. ret = -EINVAL;
  3038. goto err;
  3039. }
  3040. match = of_match_node(pineapple_asoc_machine_of_match, pdev->dev.of_node);
  3041. if (!match) {
  3042. dev_err(&pdev->dev, "%s: No DT match found for sound card\n",
  3043. __func__);
  3044. ret = -EINVAL;
  3045. goto err;
  3046. }
  3047. card->dev = &pdev->dev;
  3048. platform_set_drvdata(pdev, card);
  3049. snd_soc_card_set_drvdata(card, pdata);
  3050. ret = msm_asoc_parse_soundcard_name(pdev, card);
  3051. if (ret) {
  3052. dev_err(&pdev->dev, "%s: parse soundcard name failed, err:%d\n",
  3053. __func__, ret);
  3054. goto err;
  3055. }
  3056. if(!strcmp(match->data, "codec")) {
  3057. ret = snd_soc_of_parse_audio_routing(card, "qcom,audio-routing");
  3058. if (ret) {
  3059. dev_err(&pdev->dev, "%s: parse audio routing failed, err:%d\n",
  3060. __func__, ret);
  3061. goto err;
  3062. }
  3063. }
  3064. ret = msm_populate_dai_link_component_of_node(card);
  3065. if (ret) {
  3066. ret = -EPROBE_DEFER;
  3067. goto err;
  3068. }
  3069. /* parse upd configuration */
  3070. msm_parse_upd_configuration(pdev, pdata);
  3071. #ifdef CONFIG_COMMON_AMP_CIRRUS
  3072. switch (cirrus_amp_conf) {
  3073. case CS35L43_MONO:
  3074. card->codec_conf = cs35l43_mono_conf;
  3075. card->num_configs = ARRAY_SIZE(cs35l43_mono_conf);
  3076. break;
  3077. case CS35L43_STEREO:
  3078. card->codec_conf = cs35l43_stereo_conf;
  3079. card->num_configs = ARRAY_SIZE(cs35l43_stereo_conf);
  3080. break;
  3081. case CS35L43_QUAD:
  3082. card->codec_conf = cs35l43_quad_conf;
  3083. card->num_configs = ARRAY_SIZE(cs35l43_quad_conf);
  3084. break;
  3085. case CS35L45_MONO:
  3086. card->codec_conf = cs35l45_mono_conf;
  3087. card->num_configs = ARRAY_SIZE(cs35l45_mono_conf);
  3088. break;
  3089. case CS35L45_STEREO:
  3090. card->codec_conf = cs35l45_stereo_conf;
  3091. card->num_configs = ARRAY_SIZE(cs35l45_stereo_conf);
  3092. break;
  3093. case CS35L45_QUAD:
  3094. card->codec_conf = cs35l45_quad_conf;
  3095. card->num_configs = ARRAY_SIZE(cs35l45_quad_conf);
  3096. break;
  3097. default:
  3098. dev_err(&pdev->dev, "%s: cirrus amp conf is not defined\n",
  3099. __func__);
  3100. break;
  3101. }
  3102. #endif
  3103. #if IS_ENABLED(CONFIG_SND_SOC_SAMSUNG_AUDIO)
  3104. if (++defer_count > MAX_DEFER_COUNT)
  3105. change_snd_card_dailinks(card);
  3106. #endif
  3107. ret = devm_snd_soc_register_card(&pdev->dev, card);
  3108. if (ret == -EPROBE_DEFER) {
  3109. if (codec_reg_done)
  3110. ret = -EINVAL;
  3111. goto err;
  3112. } else if (ret) {
  3113. dev_err(&pdev->dev, "%s: snd_soc_register_card failed (%d)\n",
  3114. __func__, ret);
  3115. goto err;
  3116. }
  3117. dev_info(&pdev->dev, "%s: Sound card %s registered\n",
  3118. __func__, card->name);
  3119. if (wcd_mbhc_cfg.enable_usbc_analog ||
  3120. wcd_mbhc_cfg.usbss_hsj_connect_enable)
  3121. wcd_mbhc_cfg.swap_gnd_mic = msm_usbc_swap_gnd_mic;
  3122. pdata->fsa_handle = of_parse_phandle(pdev->dev.of_node,
  3123. "fsa4480-i2c-handle", 0);
  3124. if (!pdata->fsa_handle)
  3125. dev_dbg(&pdev->dev, "property %s not detected in node %s\n",
  3126. "fsa4480-i2c-handle", pdev->dev.of_node->full_name);
  3127. pdata->wcd_usbss_handle = of_parse_phandle(pdev->dev.of_node,
  3128. "wcd939x-i2c-handle", 0);
  3129. if (!pdata->wcd_usbss_handle)
  3130. dev_dbg(&pdev->dev, "property %s not detected in node %s\n",
  3131. "wcd939x-i2c-handle", pdev->dev.of_node->full_name);
  3132. pdata->dmic01_gpio_p = of_parse_phandle(pdev->dev.of_node,
  3133. "qcom,cdc-dmic01-gpios",
  3134. 0);
  3135. pdata->dmic23_gpio_p = of_parse_phandle(pdev->dev.of_node,
  3136. "qcom,cdc-dmic23-gpios",
  3137. 0);
  3138. pdata->dmic45_gpio_p = of_parse_phandle(pdev->dev.of_node,
  3139. "qcom,cdc-dmic45-gpios",
  3140. 0);
  3141. pdata->dmic67_gpio_p = of_parse_phandle(pdev->dev.of_node,
  3142. "qcom,cdc-dmic67-gpios",
  3143. 0);
  3144. if (pdata->dmic01_gpio_p)
  3145. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic01_gpio_p, false);
  3146. if (pdata->dmic23_gpio_p)
  3147. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic23_gpio_p, false);
  3148. if (pdata->dmic45_gpio_p)
  3149. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic45_gpio_p, false);
  3150. if (pdata->dmic67_gpio_p)
  3151. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic67_gpio_p, false);
  3152. msm_common_snd_init(pdev, card);
  3153. /* Register LPASS audio hw vote */
  3154. lpass_audio_hw_vote = devm_clk_get(&pdev->dev, "lpass_audio_hw_vote");
  3155. if (IS_ERR(lpass_audio_hw_vote)) {
  3156. ret = PTR_ERR(lpass_audio_hw_vote);
  3157. dev_dbg(&pdev->dev, "%s: clk get %s failed %d\n",
  3158. __func__, "lpass_audio_hw_vote", ret);
  3159. lpass_audio_hw_vote = NULL;
  3160. ret = 0;
  3161. }
  3162. pdata->lpass_audio_hw_vote = lpass_audio_hw_vote;
  3163. pdata->core_audio_vote_count = 0;
  3164. ret = msm_audio_ssr_register(&pdev->dev);
  3165. if (ret)
  3166. pr_err("%s: Registration with SND event FWK failed ret = %d\n",
  3167. __func__, ret);
  3168. is_initial_boot = true;
  3169. #if IS_ENABLED(CONFIG_SND_SOC_SAMSUNG_AUDIO)
  3170. audio_register_ready_cb(get_audio_amp_ready);
  3171. #endif
  3172. /* change card status to ONLINE */
  3173. dev_dbg(&pdev->dev, "%s: setting snd_card to ONLINE\n", __func__);
  3174. snd_card_set_card_status(SND_CARD_STATUS_ONLINE);
  3175. sdp_boot_print("%s: snd_card is ONLINE\n", __func__);
  3176. return 0;
  3177. err:
  3178. devm_kfree(&pdev->dev, pdata);
  3179. return ret;
  3180. }
  3181. static int msm_asoc_machine_remove(struct platform_device *pdev)
  3182. {
  3183. struct snd_soc_card *card = platform_get_drvdata(pdev);
  3184. struct msm_asoc_mach_data *pdata = NULL;
  3185. struct msm_common_pdata *common_pdata = NULL;
  3186. if (card)
  3187. pdata = snd_soc_card_get_drvdata(card);
  3188. if (pdata)
  3189. common_pdata = pdata->common_pdata;
  3190. msm_common_snd_deinit(common_pdata);
  3191. snd_event_master_deregister(&pdev->dev);
  3192. snd_soc_unregister_card(card);
  3193. return 0;
  3194. }
  3195. static struct platform_driver pineapple_asoc_machine_driver = {
  3196. .driver = {
  3197. .name = DRV_NAME,
  3198. .owner = THIS_MODULE,
  3199. .pm = &snd_soc_pm_ops,
  3200. .of_match_table = pineapple_asoc_machine_of_match,
  3201. .suppress_bind_attrs = true,
  3202. },
  3203. .probe = msm_asoc_machine_probe,
  3204. .remove = msm_asoc_machine_remove,
  3205. };
  3206. static int __init msm_asoc_machine_init(void)
  3207. {
  3208. snd_card_sysfs_init();
  3209. return platform_driver_register(&pineapple_asoc_machine_driver);
  3210. }
  3211. module_init(msm_asoc_machine_init);
  3212. static void __exit msm_asoc_machine_exit(void)
  3213. {
  3214. platform_driver_unregister(&pineapple_asoc_machine_driver);
  3215. }
  3216. module_exit(msm_asoc_machine_exit);
  3217. #ifndef CONFIG_AUDIO_BTFM_PROXY
  3218. MODULE_SOFTDEP("pre: bt_fm_slim");
  3219. #else
  3220. MODULE_SOFTDEP("pre: btfmcodec");
  3221. #endif
  3222. MODULE_DESCRIPTION("ALSA SoC msm");
  3223. MODULE_LICENSE("GPL v2");
  3224. MODULE_ALIAS("platform:" DRV_NAME);
  3225. MODULE_DEVICE_TABLE(of, pineapple_asoc_machine_of_match);