pineapple.c 93 KB

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