rx-macro.c 112 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.
  3. */
  4. #include <linux/module.h>
  5. #include <linux/init.h>
  6. #include <linux/io.h>
  7. #include <linux/platform_device.h>
  8. #include <linux/clk.h>
  9. #include <linux/pm_runtime.h>
  10. #include <sound/soc.h>
  11. #include <sound/pcm.h>
  12. #include <sound/pcm_params.h>
  13. #include <sound/soc-dapm.h>
  14. #include <sound/tlv.h>
  15. #include <soc/swr-common.h>
  16. #include <soc/swr-wcd.h>
  17. #include <asoc/msm-cdc-pinctrl.h>
  18. #include "bolero-cdc.h"
  19. #include "bolero-cdc-registers.h"
  20. #include "bolero-clk-rsc.h"
  21. #define AUTO_SUSPEND_DELAY 50 /* delay in msec */
  22. #define RX_MACRO_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
  23. SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
  24. SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000 |\
  25. SNDRV_PCM_RATE_384000)
  26. /* Fractional Rates */
  27. #define RX_MACRO_FRAC_RATES (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_88200 |\
  28. SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_352800)
  29. #define RX_MACRO_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
  30. SNDRV_PCM_FMTBIT_S24_LE |\
  31. SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
  32. #define RX_MACRO_ECHO_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
  33. SNDRV_PCM_RATE_48000)
  34. #define RX_MACRO_ECHO_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
  35. SNDRV_PCM_FMTBIT_S24_LE |\
  36. SNDRV_PCM_FMTBIT_S24_3LE)
  37. #define SAMPLING_RATE_44P1KHZ 44100
  38. #define SAMPLING_RATE_88P2KHZ 88200
  39. #define SAMPLING_RATE_176P4KHZ 176400
  40. #define SAMPLING_RATE_352P8KHZ 352800
  41. #define RX_MACRO_MAX_OFFSET 0x1000
  42. #define RX_MACRO_MAX_DMA_CH_PER_PORT 2
  43. #define RX_SWR_STRING_LEN 80
  44. #define RX_MACRO_CHILD_DEVICES_MAX 3
  45. #define RX_MACRO_INTERP_MUX_NUM_INPUTS 3
  46. #define RX_MACRO_SIDETONE_IIR_COEFF_MAX 5
  47. #define STRING(name) #name
  48. #define RX_MACRO_DAPM_ENUM(name, reg, offset, text) \
  49. static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
  50. static const struct snd_kcontrol_new name##_mux = \
  51. SOC_DAPM_ENUM(STRING(name), name##_enum)
  52. #define RX_MACRO_DAPM_ENUM_EXT(name, reg, offset, text, getname, putname) \
  53. static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
  54. static const struct snd_kcontrol_new name##_mux = \
  55. SOC_DAPM_ENUM_EXT(STRING(name), name##_enum, getname, putname)
  56. #define RX_MACRO_DAPM_MUX(name, shift, kctl) \
  57. SND_SOC_DAPM_MUX(name, SND_SOC_NOPM, shift, 0, &kctl##_mux)
  58. #define RX_MACRO_RX_PATH_OFFSET 0x80
  59. #define RX_MACRO_COMP_OFFSET 0x40
  60. #define MAX_IMPED_PARAMS 6
  61. #define RX_MACRO_EC_MIX_TX0_MASK 0xf0
  62. #define RX_MACRO_EC_MIX_TX1_MASK 0x0f
  63. #define RX_MACRO_EC_MIX_TX2_MASK 0x0f
  64. struct wcd_imped_val {
  65. u32 imped_val;
  66. u8 index;
  67. };
  68. static const struct wcd_imped_val imped_index[] = {
  69. {4, 0},
  70. {5, 1},
  71. {6, 2},
  72. {7, 3},
  73. {8, 4},
  74. {9, 5},
  75. {10, 6},
  76. {11, 7},
  77. {12, 8},
  78. {13, 9},
  79. };
  80. struct rx_macro_reg_mask_val {
  81. u16 reg;
  82. u8 mask;
  83. u8 val;
  84. };
  85. static const struct rx_macro_reg_mask_val imped_table[][MAX_IMPED_PARAMS] = {
  86. {
  87. {BOLERO_CDC_RX_RX0_RX_VOL_CTL, 0xff, 0xf2},
  88. {BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL, 0xff, 0xf2},
  89. {BOLERO_CDC_RX_RX0_RX_PATH_SEC1, 0x01, 0x00},
  90. {BOLERO_CDC_RX_RX1_RX_VOL_CTL, 0xff, 0xf2},
  91. {BOLERO_CDC_RX_RX1_RX_VOL_MIX_CTL, 0xff, 0xf2},
  92. {BOLERO_CDC_RX_RX1_RX_PATH_SEC1, 0x01, 0x00},
  93. },
  94. {
  95. {BOLERO_CDC_RX_RX0_RX_VOL_CTL, 0xff, 0xf4},
  96. {BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL, 0xff, 0xf4},
  97. {BOLERO_CDC_RX_RX0_RX_PATH_SEC1, 0x01, 0x00},
  98. {BOLERO_CDC_RX_RX1_RX_VOL_CTL, 0xff, 0xf4},
  99. {BOLERO_CDC_RX_RX1_RX_VOL_MIX_CTL, 0xff, 0xf4},
  100. {BOLERO_CDC_RX_RX1_RX_PATH_SEC1, 0x01, 0x00},
  101. },
  102. {
  103. {BOLERO_CDC_RX_RX0_RX_VOL_CTL, 0xff, 0xf7},
  104. {BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL, 0xff, 0xf7},
  105. {BOLERO_CDC_RX_RX0_RX_PATH_SEC1, 0x01, 0x01},
  106. {BOLERO_CDC_RX_RX1_RX_VOL_CTL, 0xff, 0xf7},
  107. {BOLERO_CDC_RX_RX1_RX_VOL_MIX_CTL, 0xff, 0xf7},
  108. {BOLERO_CDC_RX_RX1_RX_PATH_SEC1, 0x01, 0x01},
  109. },
  110. {
  111. {BOLERO_CDC_RX_RX0_RX_VOL_CTL, 0xff, 0xf9},
  112. {BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL, 0xff, 0xf9},
  113. {BOLERO_CDC_RX_RX0_RX_PATH_SEC1, 0x01, 0x00},
  114. {BOLERO_CDC_RX_RX1_RX_VOL_CTL, 0xff, 0xf9},
  115. {BOLERO_CDC_RX_RX1_RX_VOL_MIX_CTL, 0xff, 0xf9},
  116. {BOLERO_CDC_RX_RX1_RX_PATH_SEC1, 0x01, 0x00},
  117. },
  118. {
  119. {BOLERO_CDC_RX_RX0_RX_VOL_CTL, 0xff, 0xfa},
  120. {BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL, 0xff, 0xfa},
  121. {BOLERO_CDC_RX_RX0_RX_PATH_SEC1, 0x01, 0x00},
  122. {BOLERO_CDC_RX_RX1_RX_VOL_CTL, 0xff, 0xfa},
  123. {BOLERO_CDC_RX_RX1_RX_VOL_MIX_CTL, 0xff, 0xfa},
  124. {BOLERO_CDC_RX_RX1_RX_PATH_SEC1, 0x01, 0x00},
  125. },
  126. {
  127. {BOLERO_CDC_RX_RX0_RX_VOL_CTL, 0xff, 0xfb},
  128. {BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL, 0xff, 0xfb},
  129. {BOLERO_CDC_RX_RX0_RX_PATH_SEC1, 0x01, 0x00},
  130. {BOLERO_CDC_RX_RX1_RX_VOL_CTL, 0xff, 0xfb},
  131. {BOLERO_CDC_RX_RX1_RX_VOL_MIX_CTL, 0xff, 0xfb},
  132. {BOLERO_CDC_RX_RX1_RX_PATH_SEC1, 0x01, 0x00},
  133. },
  134. {
  135. {BOLERO_CDC_RX_RX0_RX_VOL_CTL, 0xff, 0xfc},
  136. {BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL, 0xff, 0xfc},
  137. {BOLERO_CDC_RX_RX0_RX_PATH_SEC1, 0x01, 0x00},
  138. {BOLERO_CDC_RX_RX1_RX_VOL_CTL, 0xff, 0xfc},
  139. {BOLERO_CDC_RX_RX1_RX_VOL_MIX_CTL, 0xff, 0xfc},
  140. {BOLERO_CDC_RX_RX1_RX_PATH_SEC1, 0x01, 0x00},
  141. },
  142. {
  143. {BOLERO_CDC_RX_RX0_RX_VOL_CTL, 0xff, 0xfd},
  144. {BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL, 0xff, 0xfd},
  145. {BOLERO_CDC_RX_RX0_RX_PATH_SEC1, 0x01, 0x00},
  146. {BOLERO_CDC_RX_RX1_RX_VOL_CTL, 0xff, 0xfd},
  147. {BOLERO_CDC_RX_RX1_RX_VOL_MIX_CTL, 0xff, 0xfd},
  148. {BOLERO_CDC_RX_RX1_RX_PATH_SEC1, 0x01, 0x00},
  149. },
  150. {
  151. {BOLERO_CDC_RX_RX0_RX_VOL_CTL, 0xff, 0xfd},
  152. {BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL, 0xff, 0xfd},
  153. {BOLERO_CDC_RX_RX0_RX_PATH_SEC1, 0x01, 0x01},
  154. {BOLERO_CDC_RX_RX1_RX_VOL_CTL, 0xff, 0xfd},
  155. {BOLERO_CDC_RX_RX1_RX_VOL_MIX_CTL, 0xff, 0xfd},
  156. {BOLERO_CDC_RX_RX1_RX_PATH_SEC1, 0x01, 0x01},
  157. },
  158. };
  159. enum {
  160. INTERP_HPHL,
  161. INTERP_HPHR,
  162. INTERP_AUX,
  163. INTERP_MAX
  164. };
  165. enum {
  166. RX_MACRO_RX0,
  167. RX_MACRO_RX1,
  168. RX_MACRO_RX2,
  169. RX_MACRO_RX3,
  170. RX_MACRO_RX4,
  171. RX_MACRO_RX5,
  172. RX_MACRO_PORTS_MAX
  173. };
  174. enum {
  175. RX_MACRO_COMP1, /* HPH_L */
  176. RX_MACRO_COMP2, /* HPH_R */
  177. RX_MACRO_COMP_MAX
  178. };
  179. enum {
  180. RX_MACRO_EC0_MUX = 0,
  181. RX_MACRO_EC1_MUX,
  182. RX_MACRO_EC2_MUX,
  183. RX_MACRO_EC_MUX_MAX,
  184. };
  185. enum {
  186. INTn_1_INP_SEL_ZERO = 0,
  187. INTn_1_INP_SEL_DEC0,
  188. INTn_1_INP_SEL_DEC1,
  189. INTn_1_INP_SEL_IIR0,
  190. INTn_1_INP_SEL_IIR1,
  191. INTn_1_INP_SEL_RX0,
  192. INTn_1_INP_SEL_RX1,
  193. INTn_1_INP_SEL_RX2,
  194. INTn_1_INP_SEL_RX3,
  195. INTn_1_INP_SEL_RX4,
  196. INTn_1_INP_SEL_RX5,
  197. };
  198. enum {
  199. INTn_2_INP_SEL_ZERO = 0,
  200. INTn_2_INP_SEL_RX0,
  201. INTn_2_INP_SEL_RX1,
  202. INTn_2_INP_SEL_RX2,
  203. INTn_2_INP_SEL_RX3,
  204. INTn_2_INP_SEL_RX4,
  205. INTn_2_INP_SEL_RX5,
  206. };
  207. enum {
  208. INTERP_MAIN_PATH,
  209. INTERP_MIX_PATH,
  210. };
  211. /* Codec supports 2 IIR filters */
  212. enum {
  213. IIR0 = 0,
  214. IIR1,
  215. IIR_MAX,
  216. };
  217. /* Each IIR has 5 Filter Stages */
  218. enum {
  219. BAND1 = 0,
  220. BAND2,
  221. BAND3,
  222. BAND4,
  223. BAND5,
  224. BAND_MAX,
  225. };
  226. struct rx_macro_idle_detect_config {
  227. u8 hph_idle_thr;
  228. u8 hph_idle_detect_en;
  229. };
  230. struct interp_sample_rate {
  231. int sample_rate;
  232. int rate_val;
  233. };
  234. static struct interp_sample_rate sr_val_tbl[] = {
  235. {8000, 0x0}, {16000, 0x1}, {32000, 0x3}, {48000, 0x4}, {96000, 0x5},
  236. {192000, 0x6}, {384000, 0x7}, {44100, 0x9}, {88200, 0xA},
  237. {176400, 0xB}, {352800, 0xC},
  238. };
  239. struct rx_macro_bcl_pmic_params {
  240. u8 id;
  241. u8 sid;
  242. u8 ppid;
  243. };
  244. static int rx_macro_hw_params(struct snd_pcm_substream *substream,
  245. struct snd_pcm_hw_params *params,
  246. struct snd_soc_dai *dai);
  247. static int rx_macro_get_channel_map(struct snd_soc_dai *dai,
  248. unsigned int *tx_num, unsigned int *tx_slot,
  249. unsigned int *rx_num, unsigned int *rx_slot);
  250. static int rx_macro_int_dem_inp_mux_put(struct snd_kcontrol *kcontrol,
  251. struct snd_ctl_elem_value *ucontrol);
  252. static int rx_macro_mux_get(struct snd_kcontrol *kcontrol,
  253. struct snd_ctl_elem_value *ucontrol);
  254. static int rx_macro_mux_put(struct snd_kcontrol *kcontrol,
  255. struct snd_ctl_elem_value *ucontrol);
  256. static int rx_macro_enable_interp_clk(struct snd_soc_component *component,
  257. int event, int interp_idx);
  258. /* Hold instance to soundwire platform device */
  259. struct rx_swr_ctrl_data {
  260. struct platform_device *rx_swr_pdev;
  261. };
  262. struct rx_swr_ctrl_platform_data {
  263. void *handle; /* holds codec private data */
  264. int (*read)(void *handle, int reg);
  265. int (*write)(void *handle, int reg, int val);
  266. int (*bulk_write)(void *handle, u32 *reg, u32 *val, size_t len);
  267. int (*clk)(void *handle, bool enable);
  268. int (*handle_irq)(void *handle,
  269. irqreturn_t (*swrm_irq_handler)(int irq,
  270. void *data),
  271. void *swrm_handle,
  272. int action);
  273. };
  274. enum {
  275. RX_MACRO_AIF_INVALID = 0,
  276. RX_MACRO_AIF1_PB,
  277. RX_MACRO_AIF2_PB,
  278. RX_MACRO_AIF3_PB,
  279. RX_MACRO_AIF4_PB,
  280. RX_MACRO_AIF_ECHO,
  281. RX_MACRO_MAX_DAIS,
  282. };
  283. enum {
  284. RX_MACRO_AIF1_CAP = 0,
  285. RX_MACRO_AIF2_CAP,
  286. RX_MACRO_AIF3_CAP,
  287. RX_MACRO_MAX_AIF_CAP_DAIS
  288. };
  289. /*
  290. * @dev: rx macro device pointer
  291. * @comp_enabled: compander enable mixer value set
  292. * @prim_int_users: Users of interpolator
  293. * @rx_mclk_users: RX MCLK users count
  294. * @vi_feed_value: VI sense mask
  295. * @swr_clk_lock: to lock swr master clock operations
  296. * @swr_ctrl_data: SoundWire data structure
  297. * @swr_plat_data: Soundwire platform data
  298. * @rx_macro_add_child_devices_work: work for adding child devices
  299. * @rx_swr_gpio_p: used by pinctrl API
  300. * @component: codec handle
  301. */
  302. struct rx_macro_priv {
  303. struct device *dev;
  304. int comp_enabled[RX_MACRO_COMP_MAX];
  305. /* Main path clock users count */
  306. int main_clk_users[INTERP_MAX];
  307. int rx_port_value[RX_MACRO_PORTS_MAX];
  308. u16 prim_int_users[INTERP_MAX];
  309. int rx_mclk_users;
  310. int swr_clk_users;
  311. bool dapm_mclk_enable;
  312. bool reset_swr;
  313. int clsh_users;
  314. int rx_mclk_cnt;
  315. bool is_native_on;
  316. bool is_ear_mode_on;
  317. bool dev_up;
  318. bool hph_pwr_mode;
  319. bool hph_hd2_mode;
  320. struct mutex mclk_lock;
  321. struct mutex swr_clk_lock;
  322. struct rx_swr_ctrl_data *swr_ctrl_data;
  323. struct rx_swr_ctrl_platform_data swr_plat_data;
  324. struct work_struct rx_macro_add_child_devices_work;
  325. struct device_node *rx_swr_gpio_p;
  326. struct snd_soc_component *component;
  327. unsigned long active_ch_mask[RX_MACRO_MAX_DAIS];
  328. unsigned long active_ch_cnt[RX_MACRO_MAX_DAIS];
  329. u16 bit_width[RX_MACRO_MAX_DAIS];
  330. char __iomem *rx_io_base;
  331. char __iomem *rx_mclk_mode_muxsel;
  332. struct rx_macro_idle_detect_config idle_det_cfg;
  333. u8 sidetone_coeff_array[IIR_MAX][BAND_MAX]
  334. [RX_MACRO_SIDETONE_IIR_COEFF_MAX * 4];
  335. struct platform_device *pdev_child_devices
  336. [RX_MACRO_CHILD_DEVICES_MAX];
  337. int child_count;
  338. int is_softclip_on;
  339. int softclip_clk_users;
  340. struct rx_macro_bcl_pmic_params bcl_pmic_params;
  341. u16 clk_id;
  342. u16 default_clk_id;
  343. };
  344. static struct snd_soc_dai_driver rx_macro_dai[];
  345. static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
  346. static const char * const rx_int_mix_mux_text[] = {
  347. "ZERO", "RX0", "RX1", "RX2", "RX3", "RX4", "RX5"
  348. };
  349. static const char * const rx_prim_mix_text[] = {
  350. "ZERO", "DEC0", "DEC1", "IIR0", "IIR1", "RX0", "RX1", "RX2",
  351. "RX3", "RX4", "RX5"
  352. };
  353. static const char * const rx_sidetone_mix_text[] = {
  354. "ZERO", "SRC0", "SRC1", "SRC_SUM"
  355. };
  356. static const char * const iir_inp_mux_text[] = {
  357. "ZERO", "DEC0", "DEC1", "DEC2", "DEC3",
  358. "RX0", "RX1", "RX2", "RX3", "RX4", "RX5"
  359. };
  360. static const char * const rx_int_dem_inp_mux_text[] = {
  361. "NORMAL_DSM_OUT", "CLSH_DSM_OUT",
  362. };
  363. static const char * const rx_int0_1_interp_mux_text[] = {
  364. "ZERO", "RX INT0_1 MIX1",
  365. };
  366. static const char * const rx_int1_1_interp_mux_text[] = {
  367. "ZERO", "RX INT1_1 MIX1",
  368. };
  369. static const char * const rx_int2_1_interp_mux_text[] = {
  370. "ZERO", "RX INT2_1 MIX1",
  371. };
  372. static const char * const rx_int0_2_interp_mux_text[] = {
  373. "ZERO", "RX INT0_2 MUX",
  374. };
  375. static const char * const rx_int1_2_interp_mux_text[] = {
  376. "ZERO", "RX INT1_2 MUX",
  377. };
  378. static const char * const rx_int2_2_interp_mux_text[] = {
  379. "ZERO", "RX INT2_2 MUX",
  380. };
  381. static const char *const rx_macro_mux_text[] = {
  382. "ZERO", "AIF1_PB", "AIF2_PB", "AIF3_PB", "AIF4_PB"
  383. };
  384. static const char *const rx_macro_ear_mode_text[] = {"OFF", "ON"};
  385. static const struct soc_enum rx_macro_ear_mode_enum =
  386. SOC_ENUM_SINGLE_EXT(2, rx_macro_ear_mode_text);
  387. static const char *const rx_macro_hph_hd2_mode_text[] = {"OFF", "ON"};
  388. static const struct soc_enum rx_macro_hph_hd2_mode_enum =
  389. SOC_ENUM_SINGLE_EXT(2, rx_macro_hph_hd2_mode_text);
  390. static const char *const rx_macro_hph_pwr_mode_text[] = {"ULP", "LOHIFI"};
  391. static const struct soc_enum rx_macro_hph_pwr_mode_enum =
  392. SOC_ENUM_SINGLE_EXT(2, rx_macro_hph_pwr_mode_text);
  393. static const char * const rx_macro_vbat_bcl_gsm_mode_text[] = {"OFF", "ON"};
  394. static const struct soc_enum rx_macro_vbat_bcl_gsm_mode_enum =
  395. SOC_ENUM_SINGLE_EXT(2, rx_macro_vbat_bcl_gsm_mode_text);
  396. static const struct snd_kcontrol_new rx_int2_1_vbat_mix_switch[] = {
  397. SOC_DAPM_SINGLE("RX AUX VBAT Enable", SND_SOC_NOPM, 0, 1, 0)
  398. };
  399. static const char * const hph_idle_detect_text[] = {"OFF", "ON"};
  400. static SOC_ENUM_SINGLE_EXT_DECL(hph_idle_detect_enum, hph_idle_detect_text);
  401. RX_MACRO_DAPM_ENUM(rx_int0_2, BOLERO_CDC_RX_INP_MUX_RX_INT0_CFG1, 0,
  402. rx_int_mix_mux_text);
  403. RX_MACRO_DAPM_ENUM(rx_int1_2, BOLERO_CDC_RX_INP_MUX_RX_INT1_CFG1, 0,
  404. rx_int_mix_mux_text);
  405. RX_MACRO_DAPM_ENUM(rx_int2_2, BOLERO_CDC_RX_INP_MUX_RX_INT2_CFG1, 0,
  406. rx_int_mix_mux_text);
  407. RX_MACRO_DAPM_ENUM(rx_int0_1_mix_inp0, BOLERO_CDC_RX_INP_MUX_RX_INT0_CFG0, 0,
  408. rx_prim_mix_text);
  409. RX_MACRO_DAPM_ENUM(rx_int0_1_mix_inp1, BOLERO_CDC_RX_INP_MUX_RX_INT0_CFG0, 4,
  410. rx_prim_mix_text);
  411. RX_MACRO_DAPM_ENUM(rx_int0_1_mix_inp2, BOLERO_CDC_RX_INP_MUX_RX_INT0_CFG1, 4,
  412. rx_prim_mix_text);
  413. RX_MACRO_DAPM_ENUM(rx_int1_1_mix_inp0, BOLERO_CDC_RX_INP_MUX_RX_INT1_CFG0, 0,
  414. rx_prim_mix_text);
  415. RX_MACRO_DAPM_ENUM(rx_int1_1_mix_inp1, BOLERO_CDC_RX_INP_MUX_RX_INT1_CFG0, 4,
  416. rx_prim_mix_text);
  417. RX_MACRO_DAPM_ENUM(rx_int1_1_mix_inp2, BOLERO_CDC_RX_INP_MUX_RX_INT1_CFG1, 4,
  418. rx_prim_mix_text);
  419. RX_MACRO_DAPM_ENUM(rx_int2_1_mix_inp0, BOLERO_CDC_RX_INP_MUX_RX_INT2_CFG0, 0,
  420. rx_prim_mix_text);
  421. RX_MACRO_DAPM_ENUM(rx_int2_1_mix_inp1, BOLERO_CDC_RX_INP_MUX_RX_INT2_CFG0, 4,
  422. rx_prim_mix_text);
  423. RX_MACRO_DAPM_ENUM(rx_int2_1_mix_inp2, BOLERO_CDC_RX_INP_MUX_RX_INT2_CFG1, 4,
  424. rx_prim_mix_text);
  425. RX_MACRO_DAPM_ENUM(rx_int0_mix2_inp, BOLERO_CDC_RX_INP_MUX_SIDETONE_SRC_CFG0, 2,
  426. rx_sidetone_mix_text);
  427. RX_MACRO_DAPM_ENUM(rx_int1_mix2_inp, BOLERO_CDC_RX_INP_MUX_SIDETONE_SRC_CFG0, 4,
  428. rx_sidetone_mix_text);
  429. RX_MACRO_DAPM_ENUM(rx_int2_mix2_inp, BOLERO_CDC_RX_INP_MUX_SIDETONE_SRC_CFG0, 6,
  430. rx_sidetone_mix_text);
  431. RX_MACRO_DAPM_ENUM(iir0_inp0, BOLERO_CDC_RX_IIR_INP_MUX_IIR0_MIX_CFG0, 0,
  432. iir_inp_mux_text);
  433. RX_MACRO_DAPM_ENUM(iir0_inp1, BOLERO_CDC_RX_IIR_INP_MUX_IIR0_MIX_CFG1, 0,
  434. iir_inp_mux_text);
  435. RX_MACRO_DAPM_ENUM(iir0_inp2, BOLERO_CDC_RX_IIR_INP_MUX_IIR0_MIX_CFG2, 0,
  436. iir_inp_mux_text);
  437. RX_MACRO_DAPM_ENUM(iir0_inp3, BOLERO_CDC_RX_IIR_INP_MUX_IIR0_MIX_CFG3, 0,
  438. iir_inp_mux_text);
  439. RX_MACRO_DAPM_ENUM(iir1_inp0, BOLERO_CDC_RX_IIR_INP_MUX_IIR1_MIX_CFG0, 0,
  440. iir_inp_mux_text);
  441. RX_MACRO_DAPM_ENUM(iir1_inp1, BOLERO_CDC_RX_IIR_INP_MUX_IIR1_MIX_CFG1, 0,
  442. iir_inp_mux_text);
  443. RX_MACRO_DAPM_ENUM(iir1_inp2, BOLERO_CDC_RX_IIR_INP_MUX_IIR1_MIX_CFG2, 0,
  444. iir_inp_mux_text);
  445. RX_MACRO_DAPM_ENUM(iir1_inp3, BOLERO_CDC_RX_IIR_INP_MUX_IIR1_MIX_CFG3, 0,
  446. iir_inp_mux_text);
  447. RX_MACRO_DAPM_ENUM(rx_int0_1_interp, SND_SOC_NOPM, 0,
  448. rx_int0_1_interp_mux_text);
  449. RX_MACRO_DAPM_ENUM(rx_int1_1_interp, SND_SOC_NOPM, 0,
  450. rx_int1_1_interp_mux_text);
  451. RX_MACRO_DAPM_ENUM(rx_int2_1_interp, SND_SOC_NOPM, 0,
  452. rx_int2_1_interp_mux_text);
  453. RX_MACRO_DAPM_ENUM(rx_int0_2_interp, SND_SOC_NOPM, 0,
  454. rx_int0_2_interp_mux_text);
  455. RX_MACRO_DAPM_ENUM(rx_int1_2_interp, SND_SOC_NOPM, 0,
  456. rx_int1_2_interp_mux_text);
  457. RX_MACRO_DAPM_ENUM(rx_int2_2_interp, SND_SOC_NOPM, 0,
  458. rx_int2_2_interp_mux_text);
  459. RX_MACRO_DAPM_ENUM_EXT(rx_int0_dem_inp, BOLERO_CDC_RX_RX0_RX_PATH_CFG1, 0,
  460. rx_int_dem_inp_mux_text, snd_soc_dapm_get_enum_double,
  461. rx_macro_int_dem_inp_mux_put);
  462. RX_MACRO_DAPM_ENUM_EXT(rx_int1_dem_inp, BOLERO_CDC_RX_RX1_RX_PATH_CFG1, 0,
  463. rx_int_dem_inp_mux_text, snd_soc_dapm_get_enum_double,
  464. rx_macro_int_dem_inp_mux_put);
  465. RX_MACRO_DAPM_ENUM_EXT(rx_macro_rx0, SND_SOC_NOPM, 0, rx_macro_mux_text,
  466. rx_macro_mux_get, rx_macro_mux_put);
  467. RX_MACRO_DAPM_ENUM_EXT(rx_macro_rx1, SND_SOC_NOPM, 0, rx_macro_mux_text,
  468. rx_macro_mux_get, rx_macro_mux_put);
  469. RX_MACRO_DAPM_ENUM_EXT(rx_macro_rx2, SND_SOC_NOPM, 0, rx_macro_mux_text,
  470. rx_macro_mux_get, rx_macro_mux_put);
  471. RX_MACRO_DAPM_ENUM_EXT(rx_macro_rx3, SND_SOC_NOPM, 0, rx_macro_mux_text,
  472. rx_macro_mux_get, rx_macro_mux_put);
  473. RX_MACRO_DAPM_ENUM_EXT(rx_macro_rx4, SND_SOC_NOPM, 0, rx_macro_mux_text,
  474. rx_macro_mux_get, rx_macro_mux_put);
  475. RX_MACRO_DAPM_ENUM_EXT(rx_macro_rx5, SND_SOC_NOPM, 0, rx_macro_mux_text,
  476. rx_macro_mux_get, rx_macro_mux_put);
  477. static const char * const rx_echo_mux_text[] = {
  478. "ZERO", "RX_MIX0", "RX_MIX1", "RX_MIX2"
  479. };
  480. static const struct soc_enum rx_mix_tx2_mux_enum =
  481. SOC_ENUM_SINGLE(BOLERO_CDC_RX_INP_MUX_RX_MIX_CFG5, 0, 4,
  482. rx_echo_mux_text);
  483. static const struct snd_kcontrol_new rx_mix_tx2_mux =
  484. SOC_DAPM_ENUM("RX MIX TX2_MUX Mux", rx_mix_tx2_mux_enum);
  485. static const struct soc_enum rx_mix_tx1_mux_enum =
  486. SOC_ENUM_SINGLE(BOLERO_CDC_RX_INP_MUX_RX_MIX_CFG4, 0, 4,
  487. rx_echo_mux_text);
  488. static const struct snd_kcontrol_new rx_mix_tx1_mux =
  489. SOC_DAPM_ENUM("RX MIX TX1_MUX Mux", rx_mix_tx1_mux_enum);
  490. static const struct soc_enum rx_mix_tx0_mux_enum =
  491. SOC_ENUM_SINGLE(BOLERO_CDC_RX_INP_MUX_RX_MIX_CFG4, 4, 4,
  492. rx_echo_mux_text);
  493. static const struct snd_kcontrol_new rx_mix_tx0_mux =
  494. SOC_DAPM_ENUM("RX MIX TX0_MUX Mux", rx_mix_tx0_mux_enum);
  495. static struct snd_soc_dai_ops rx_macro_dai_ops = {
  496. .hw_params = rx_macro_hw_params,
  497. .get_channel_map = rx_macro_get_channel_map,
  498. };
  499. static struct snd_soc_dai_driver rx_macro_dai[] = {
  500. {
  501. .name = "rx_macro_rx1",
  502. .id = RX_MACRO_AIF1_PB,
  503. .playback = {
  504. .stream_name = "RX_MACRO_AIF1 Playback",
  505. .rates = RX_MACRO_RATES | RX_MACRO_FRAC_RATES,
  506. .formats = RX_MACRO_FORMATS,
  507. .rate_max = 384000,
  508. .rate_min = 8000,
  509. .channels_min = 1,
  510. .channels_max = 2,
  511. },
  512. .ops = &rx_macro_dai_ops,
  513. },
  514. {
  515. .name = "rx_macro_rx2",
  516. .id = RX_MACRO_AIF2_PB,
  517. .playback = {
  518. .stream_name = "RX_MACRO_AIF2 Playback",
  519. .rates = RX_MACRO_RATES | RX_MACRO_FRAC_RATES,
  520. .formats = RX_MACRO_FORMATS,
  521. .rate_max = 384000,
  522. .rate_min = 8000,
  523. .channels_min = 1,
  524. .channels_max = 2,
  525. },
  526. .ops = &rx_macro_dai_ops,
  527. },
  528. {
  529. .name = "rx_macro_rx3",
  530. .id = RX_MACRO_AIF3_PB,
  531. .playback = {
  532. .stream_name = "RX_MACRO_AIF3 Playback",
  533. .rates = RX_MACRO_RATES | RX_MACRO_FRAC_RATES,
  534. .formats = RX_MACRO_FORMATS,
  535. .rate_max = 384000,
  536. .rate_min = 8000,
  537. .channels_min = 1,
  538. .channels_max = 2,
  539. },
  540. .ops = &rx_macro_dai_ops,
  541. },
  542. {
  543. .name = "rx_macro_rx4",
  544. .id = RX_MACRO_AIF4_PB,
  545. .playback = {
  546. .stream_name = "RX_MACRO_AIF4 Playback",
  547. .rates = RX_MACRO_RATES | RX_MACRO_FRAC_RATES,
  548. .formats = RX_MACRO_FORMATS,
  549. .rate_max = 384000,
  550. .rate_min = 8000,
  551. .channels_min = 1,
  552. .channels_max = 2,
  553. },
  554. .ops = &rx_macro_dai_ops,
  555. },
  556. {
  557. .name = "rx_macro_echo",
  558. .id = RX_MACRO_AIF_ECHO,
  559. .capture = {
  560. .stream_name = "RX_AIF_ECHO Capture",
  561. .rates = RX_MACRO_ECHO_RATES,
  562. .formats = RX_MACRO_ECHO_FORMATS,
  563. .rate_max = 48000,
  564. .rate_min = 8000,
  565. .channels_min = 1,
  566. .channels_max = 3,
  567. },
  568. .ops = &rx_macro_dai_ops,
  569. },
  570. };
  571. static int get_impedance_index(int imped)
  572. {
  573. int i = 0;
  574. if (imped < imped_index[i].imped_val) {
  575. pr_debug("%s, detected impedance is less than %d Ohm\n",
  576. __func__, imped_index[i].imped_val);
  577. i = 0;
  578. goto ret;
  579. }
  580. if (imped >= imped_index[ARRAY_SIZE(imped_index) - 1].imped_val) {
  581. pr_debug("%s, detected impedance is greater than %d Ohm\n",
  582. __func__,
  583. imped_index[ARRAY_SIZE(imped_index) - 1].imped_val);
  584. i = ARRAY_SIZE(imped_index) - 1;
  585. goto ret;
  586. }
  587. for (i = 0; i < ARRAY_SIZE(imped_index) - 1; i++) {
  588. if (imped >= imped_index[i].imped_val &&
  589. imped < imped_index[i + 1].imped_val)
  590. break;
  591. }
  592. ret:
  593. pr_debug("%s: selected impedance index = %d\n",
  594. __func__, imped_index[i].index);
  595. return imped_index[i].index;
  596. }
  597. /*
  598. * rx_macro_wcd_clsh_imped_config -
  599. * This function updates HPHL and HPHR gain settings
  600. * according to the impedance value.
  601. *
  602. * @component: codec pointer handle
  603. * @imped: impedance value of HPHL/R
  604. * @reset: bool variable to reset registers when teardown
  605. */
  606. static void rx_macro_wcd_clsh_imped_config(struct snd_soc_component *component,
  607. int imped, bool reset)
  608. {
  609. int i;
  610. int index = 0;
  611. int table_size;
  612. static const struct rx_macro_reg_mask_val
  613. (*imped_table_ptr)[MAX_IMPED_PARAMS];
  614. table_size = ARRAY_SIZE(imped_table);
  615. imped_table_ptr = imped_table;
  616. /* reset = 1, which means request is to reset the register values */
  617. if (reset) {
  618. for (i = 0; i < MAX_IMPED_PARAMS; i++)
  619. snd_soc_component_update_bits(component,
  620. imped_table_ptr[index][i].reg,
  621. imped_table_ptr[index][i].mask, 0);
  622. return;
  623. }
  624. index = get_impedance_index(imped);
  625. if (index >= (ARRAY_SIZE(imped_index) - 1)) {
  626. pr_debug("%s, impedance not in range = %d\n", __func__, imped);
  627. return;
  628. }
  629. if (index >= table_size) {
  630. pr_debug("%s, impedance index not in range = %d\n", __func__,
  631. index);
  632. return;
  633. }
  634. for (i = 0; i < MAX_IMPED_PARAMS; i++)
  635. snd_soc_component_update_bits(component,
  636. imped_table_ptr[index][i].reg,
  637. imped_table_ptr[index][i].mask,
  638. imped_table_ptr[index][i].val);
  639. }
  640. static bool rx_macro_get_data(struct snd_soc_component *component,
  641. struct device **rx_dev,
  642. struct rx_macro_priv **rx_priv,
  643. const char *func_name)
  644. {
  645. *rx_dev = bolero_get_device_ptr(component->dev, RX_MACRO);
  646. if (!(*rx_dev)) {
  647. dev_err(component->dev,
  648. "%s: null device for macro!\n", func_name);
  649. return false;
  650. }
  651. *rx_priv = dev_get_drvdata((*rx_dev));
  652. if (!(*rx_priv)) {
  653. dev_err(component->dev,
  654. "%s: priv is null for macro!\n", func_name);
  655. return false;
  656. }
  657. if (!(*rx_priv)->component) {
  658. dev_err(component->dev,
  659. "%s: rx_priv component is not initialized!\n", func_name);
  660. return false;
  661. }
  662. return true;
  663. }
  664. static int rx_macro_set_port_map(struct snd_soc_component *component,
  665. u32 usecase, u32 size, void *data)
  666. {
  667. struct device *rx_dev = NULL;
  668. struct rx_macro_priv *rx_priv = NULL;
  669. struct swrm_port_config port_cfg;
  670. int ret = 0;
  671. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  672. return -EINVAL;
  673. memset(&port_cfg, 0, sizeof(port_cfg));
  674. port_cfg.uc = usecase;
  675. port_cfg.size = size;
  676. port_cfg.params = data;
  677. ret = swrm_wcd_notify(
  678. rx_priv->swr_ctrl_data[0].rx_swr_pdev,
  679. SWR_SET_PORT_MAP, &port_cfg);
  680. return ret;
  681. }
  682. static int rx_macro_int_dem_inp_mux_put(struct snd_kcontrol *kcontrol,
  683. struct snd_ctl_elem_value *ucontrol)
  684. {
  685. struct snd_soc_dapm_widget *widget =
  686. snd_soc_dapm_kcontrol_widget(kcontrol);
  687. struct snd_soc_component *component =
  688. snd_soc_dapm_to_component(widget->dapm);
  689. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  690. unsigned int val = 0;
  691. unsigned short look_ahead_dly_reg =
  692. BOLERO_CDC_RX_RX0_RX_PATH_CFG0;
  693. val = ucontrol->value.enumerated.item[0];
  694. if (val >= e->items)
  695. return -EINVAL;
  696. dev_dbg(component->dev, "%s: wname: %s, val: 0x%x\n", __func__,
  697. widget->name, val);
  698. if (e->reg == BOLERO_CDC_RX_RX0_RX_PATH_CFG1)
  699. look_ahead_dly_reg = BOLERO_CDC_RX_RX0_RX_PATH_CFG0;
  700. else if (e->reg == BOLERO_CDC_RX_RX1_RX_PATH_CFG1)
  701. look_ahead_dly_reg = BOLERO_CDC_RX_RX1_RX_PATH_CFG0;
  702. /* Set Look Ahead Delay */
  703. snd_soc_component_update_bits(component, look_ahead_dly_reg,
  704. 0x08, (val ? 0x08 : 0x00));
  705. /* Set DEM INP Select */
  706. return snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
  707. }
  708. static int rx_macro_set_prim_interpolator_rate(struct snd_soc_dai *dai,
  709. u8 rate_reg_val,
  710. u32 sample_rate)
  711. {
  712. u8 int_1_mix1_inp = 0;
  713. u32 j = 0, port = 0;
  714. u16 int_mux_cfg0 = 0, int_mux_cfg1 = 0;
  715. u16 int_fs_reg = 0;
  716. u8 int_mux_cfg0_val = 0, int_mux_cfg1_val = 0;
  717. u8 inp0_sel = 0, inp1_sel = 0, inp2_sel = 0;
  718. struct snd_soc_component *component = dai->component;
  719. struct device *rx_dev = NULL;
  720. struct rx_macro_priv *rx_priv = NULL;
  721. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  722. return -EINVAL;
  723. for_each_set_bit(port, &rx_priv->active_ch_mask[dai->id],
  724. RX_MACRO_PORTS_MAX) {
  725. int_1_mix1_inp = port;
  726. if ((int_1_mix1_inp < RX_MACRO_RX0) ||
  727. (int_1_mix1_inp > RX_MACRO_PORTS_MAX)) {
  728. pr_err("%s: Invalid RX port, Dai ID is %d\n",
  729. __func__, dai->id);
  730. return -EINVAL;
  731. }
  732. int_mux_cfg0 = BOLERO_CDC_RX_INP_MUX_RX_INT0_CFG0;
  733. /*
  734. * Loop through all interpolator MUX inputs and find out
  735. * to which interpolator input, the rx port
  736. * is connected
  737. */
  738. for (j = 0; j < INTERP_MAX; j++) {
  739. int_mux_cfg1 = int_mux_cfg0 + 4;
  740. int_mux_cfg0_val = snd_soc_component_read32(
  741. component, int_mux_cfg0);
  742. int_mux_cfg1_val = snd_soc_component_read32(
  743. component, int_mux_cfg1);
  744. inp0_sel = int_mux_cfg0_val & 0x07;
  745. inp1_sel = (int_mux_cfg0_val >> 4) & 0x038;
  746. inp2_sel = (int_mux_cfg1_val >> 4) & 0x038;
  747. if ((inp0_sel == int_1_mix1_inp) ||
  748. (inp1_sel == int_1_mix1_inp) ||
  749. (inp2_sel == int_1_mix1_inp)) {
  750. int_fs_reg = BOLERO_CDC_RX_RX0_RX_PATH_CTL +
  751. 0x80 * j;
  752. pr_debug("%s: AIF_PB DAI(%d) connected to INT%u_1\n",
  753. __func__, dai->id, j);
  754. pr_debug("%s: set INT%u_1 sample rate to %u\n",
  755. __func__, j, sample_rate);
  756. /* sample_rate is in Hz */
  757. snd_soc_component_update_bits(component,
  758. int_fs_reg,
  759. 0x0F, rate_reg_val);
  760. }
  761. int_mux_cfg0 += 8;
  762. }
  763. }
  764. return 0;
  765. }
  766. static int rx_macro_set_mix_interpolator_rate(struct snd_soc_dai *dai,
  767. u8 rate_reg_val,
  768. u32 sample_rate)
  769. {
  770. u8 int_2_inp = 0;
  771. u32 j = 0, port = 0;
  772. u16 int_mux_cfg1 = 0, int_fs_reg = 0;
  773. u8 int_mux_cfg1_val = 0;
  774. struct snd_soc_component *component = dai->component;
  775. struct device *rx_dev = NULL;
  776. struct rx_macro_priv *rx_priv = NULL;
  777. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  778. return -EINVAL;
  779. for_each_set_bit(port, &rx_priv->active_ch_mask[dai->id],
  780. RX_MACRO_PORTS_MAX) {
  781. int_2_inp = port;
  782. if ((int_2_inp < RX_MACRO_RX0) ||
  783. (int_2_inp > RX_MACRO_PORTS_MAX)) {
  784. pr_err("%s: Invalid RX port, Dai ID is %d\n",
  785. __func__, dai->id);
  786. return -EINVAL;
  787. }
  788. int_mux_cfg1 = BOLERO_CDC_RX_INP_MUX_RX_INT0_CFG1;
  789. for (j = 0; j < INTERP_MAX; j++) {
  790. int_mux_cfg1_val = snd_soc_component_read32(
  791. component, int_mux_cfg1) &
  792. 0x07;
  793. if (int_mux_cfg1_val == int_2_inp) {
  794. int_fs_reg = BOLERO_CDC_RX_RX0_RX_PATH_MIX_CTL +
  795. 0x80 * j;
  796. pr_debug("%s: AIF_PB DAI(%d) connected to INT%u_2\n",
  797. __func__, dai->id, j);
  798. pr_debug("%s: set INT%u_2 sample rate to %u\n",
  799. __func__, j, sample_rate);
  800. snd_soc_component_update_bits(
  801. component, int_fs_reg,
  802. 0x0F, rate_reg_val);
  803. }
  804. int_mux_cfg1 += 8;
  805. }
  806. }
  807. return 0;
  808. }
  809. static bool rx_macro_is_fractional_sample_rate(u32 sample_rate)
  810. {
  811. switch (sample_rate) {
  812. case SAMPLING_RATE_44P1KHZ:
  813. case SAMPLING_RATE_88P2KHZ:
  814. case SAMPLING_RATE_176P4KHZ:
  815. case SAMPLING_RATE_352P8KHZ:
  816. return true;
  817. default:
  818. return false;
  819. }
  820. return false;
  821. }
  822. static int rx_macro_set_interpolator_rate(struct snd_soc_dai *dai,
  823. u32 sample_rate)
  824. {
  825. struct snd_soc_component *component = dai->component;
  826. int rate_val = 0;
  827. int i = 0, ret = 0;
  828. struct device *rx_dev = NULL;
  829. struct rx_macro_priv *rx_priv = NULL;
  830. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  831. return -EINVAL;
  832. for (i = 0; i < ARRAY_SIZE(sr_val_tbl); i++) {
  833. if (sample_rate == sr_val_tbl[i].sample_rate) {
  834. rate_val = sr_val_tbl[i].rate_val;
  835. if (rx_macro_is_fractional_sample_rate(sample_rate))
  836. rx_priv->is_native_on = true;
  837. else
  838. rx_priv->is_native_on = false;
  839. break;
  840. }
  841. }
  842. if ((i == ARRAY_SIZE(sr_val_tbl)) || (rate_val < 0)) {
  843. dev_err(component->dev, "%s: Unsupported sample rate: %d\n",
  844. __func__, sample_rate);
  845. return -EINVAL;
  846. }
  847. ret = rx_macro_set_prim_interpolator_rate(dai, (u8)rate_val, sample_rate);
  848. if (ret)
  849. return ret;
  850. ret = rx_macro_set_mix_interpolator_rate(dai, (u8)rate_val, sample_rate);
  851. if (ret)
  852. return ret;
  853. return ret;
  854. }
  855. static int rx_macro_hw_params(struct snd_pcm_substream *substream,
  856. struct snd_pcm_hw_params *params,
  857. struct snd_soc_dai *dai)
  858. {
  859. struct snd_soc_component *component = dai->component;
  860. int ret = 0;
  861. struct device *rx_dev = NULL;
  862. struct rx_macro_priv *rx_priv = NULL;
  863. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  864. return -EINVAL;
  865. dev_dbg(component->dev,
  866. "%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n", __func__,
  867. dai->name, dai->id, params_rate(params),
  868. params_channels(params));
  869. switch (substream->stream) {
  870. case SNDRV_PCM_STREAM_PLAYBACK:
  871. ret = rx_macro_set_interpolator_rate(dai, params_rate(params));
  872. if (ret) {
  873. pr_err("%s: cannot set sample rate: %u\n",
  874. __func__, params_rate(params));
  875. return ret;
  876. }
  877. rx_priv->bit_width[dai->id] = params_width(params);
  878. break;
  879. case SNDRV_PCM_STREAM_CAPTURE:
  880. default:
  881. break;
  882. }
  883. return 0;
  884. }
  885. static int rx_macro_get_channel_map(struct snd_soc_dai *dai,
  886. unsigned int *tx_num, unsigned int *tx_slot,
  887. unsigned int *rx_num, unsigned int *rx_slot)
  888. {
  889. struct snd_soc_component *component = dai->component;
  890. struct device *rx_dev = NULL;
  891. struct rx_macro_priv *rx_priv = NULL;
  892. unsigned int temp = 0, ch_mask = 0;
  893. u16 val = 0, mask = 0, cnt = 0, i = 0;
  894. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  895. return -EINVAL;
  896. switch (dai->id) {
  897. case RX_MACRO_AIF1_PB:
  898. case RX_MACRO_AIF2_PB:
  899. case RX_MACRO_AIF3_PB:
  900. case RX_MACRO_AIF4_PB:
  901. for_each_set_bit(temp, &rx_priv->active_ch_mask[dai->id],
  902. RX_MACRO_PORTS_MAX) {
  903. ch_mask |= (1 << temp);
  904. if (++i == RX_MACRO_MAX_DMA_CH_PER_PORT)
  905. break;
  906. }
  907. *rx_slot = ch_mask;
  908. *rx_num = rx_priv->active_ch_cnt[dai->id];
  909. break;
  910. case RX_MACRO_AIF_ECHO:
  911. val = snd_soc_component_read32(component,
  912. BOLERO_CDC_RX_INP_MUX_RX_MIX_CFG4);
  913. if (val & RX_MACRO_EC_MIX_TX0_MASK) {
  914. mask |= 0x1;
  915. cnt++;
  916. }
  917. if (val & RX_MACRO_EC_MIX_TX1_MASK) {
  918. mask |= 0x2;
  919. cnt++;
  920. }
  921. val = snd_soc_component_read32(component,
  922. BOLERO_CDC_RX_INP_MUX_RX_MIX_CFG5);
  923. if (val & RX_MACRO_EC_MIX_TX2_MASK) {
  924. mask |= 0x4;
  925. cnt++;
  926. }
  927. *tx_slot = mask;
  928. *tx_num = cnt;
  929. break;
  930. default:
  931. dev_err(rx_dev, "%s: Invalid AIF\n", __func__);
  932. break;
  933. }
  934. return 0;
  935. }
  936. static int rx_macro_mclk_enable(struct rx_macro_priv *rx_priv,
  937. bool mclk_enable, bool dapm)
  938. {
  939. struct regmap *regmap = dev_get_regmap(rx_priv->dev->parent, NULL);
  940. int ret = 0;
  941. if (regmap == NULL) {
  942. dev_err(rx_priv->dev, "%s: regmap is NULL\n", __func__);
  943. return -EINVAL;
  944. }
  945. dev_dbg(rx_priv->dev, "%s: mclk_enable = %u, dapm = %d clk_users= %d\n",
  946. __func__, mclk_enable, dapm, rx_priv->rx_mclk_users);
  947. mutex_lock(&rx_priv->mclk_lock);
  948. if (mclk_enable) {
  949. if (rx_priv->rx_mclk_users == 0) {
  950. if (rx_priv->is_native_on)
  951. rx_priv->clk_id = RX_CORE_CLK;
  952. ret = bolero_clk_rsc_request_clock(rx_priv->dev,
  953. rx_priv->default_clk_id,
  954. rx_priv->clk_id,
  955. true);
  956. if (ret < 0) {
  957. dev_err(rx_priv->dev,
  958. "%s: rx request clock enable failed\n",
  959. __func__);
  960. goto exit;
  961. }
  962. bolero_clk_rsc_fs_gen_request(rx_priv->dev,
  963. true);
  964. regcache_mark_dirty(regmap);
  965. regcache_sync_region(regmap,
  966. RX_START_OFFSET,
  967. RX_MAX_OFFSET);
  968. regmap_update_bits(regmap,
  969. BOLERO_CDC_RX_CLK_RST_CTRL_MCLK_CONTROL,
  970. 0x01, 0x01);
  971. regmap_update_bits(regmap,
  972. BOLERO_CDC_RX_CLK_RST_CTRL_MCLK_CONTROL,
  973. 0x02, 0x02);
  974. regmap_update_bits(regmap,
  975. BOLERO_CDC_RX_CLK_RST_CTRL_FS_CNT_CONTROL,
  976. 0x01, 0x01);
  977. }
  978. rx_priv->rx_mclk_users++;
  979. } else {
  980. if (rx_priv->rx_mclk_users <= 0) {
  981. dev_err(rx_priv->dev, "%s: clock already disabled\n",
  982. __func__);
  983. rx_priv->rx_mclk_users = 0;
  984. goto exit;
  985. }
  986. rx_priv->rx_mclk_users--;
  987. if (rx_priv->rx_mclk_users == 0) {
  988. regmap_update_bits(regmap,
  989. BOLERO_CDC_RX_CLK_RST_CTRL_FS_CNT_CONTROL,
  990. 0x01, 0x00);
  991. regmap_update_bits(regmap,
  992. BOLERO_CDC_RX_CLK_RST_CTRL_MCLK_CONTROL,
  993. 0x01, 0x00);
  994. bolero_clk_rsc_fs_gen_request(rx_priv->dev,
  995. false);
  996. bolero_clk_rsc_request_clock(rx_priv->dev,
  997. rx_priv->default_clk_id,
  998. rx_priv->clk_id,
  999. false);
  1000. rx_priv->clk_id = rx_priv->default_clk_id;
  1001. }
  1002. }
  1003. exit:
  1004. mutex_unlock(&rx_priv->mclk_lock);
  1005. return ret;
  1006. }
  1007. static int rx_macro_mclk_event(struct snd_soc_dapm_widget *w,
  1008. struct snd_kcontrol *kcontrol, int event)
  1009. {
  1010. struct snd_soc_component *component =
  1011. snd_soc_dapm_to_component(w->dapm);
  1012. int ret = 0;
  1013. struct device *rx_dev = NULL;
  1014. struct rx_macro_priv *rx_priv = NULL;
  1015. int mclk_freq = MCLK_FREQ;
  1016. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1017. return -EINVAL;
  1018. dev_dbg(rx_dev, "%s: event = %d\n", __func__, event);
  1019. switch (event) {
  1020. case SND_SOC_DAPM_PRE_PMU:
  1021. /* if swr_clk_users > 0, call device down */
  1022. if (rx_priv->swr_clk_users > 0) {
  1023. if ((rx_priv->clk_id == rx_priv->default_clk_id &&
  1024. rx_priv->is_native_on) ||
  1025. (rx_priv->clk_id == RX_CORE_CLK &&
  1026. !rx_priv->is_native_on)) {
  1027. swrm_wcd_notify(
  1028. rx_priv->swr_ctrl_data[0].rx_swr_pdev,
  1029. SWR_DEVICE_DOWN, NULL);
  1030. }
  1031. }
  1032. if (rx_priv->is_native_on)
  1033. mclk_freq = MCLK_FREQ_NATIVE;
  1034. swrm_wcd_notify(
  1035. rx_priv->swr_ctrl_data[0].rx_swr_pdev,
  1036. SWR_CLK_FREQ, &mclk_freq);
  1037. ret = rx_macro_mclk_enable(rx_priv, 1, true);
  1038. if (ret)
  1039. rx_priv->dapm_mclk_enable = false;
  1040. else
  1041. rx_priv->dapm_mclk_enable = true;
  1042. break;
  1043. case SND_SOC_DAPM_POST_PMD:
  1044. if (rx_priv->dapm_mclk_enable)
  1045. ret = rx_macro_mclk_enable(rx_priv, 0, true);
  1046. break;
  1047. default:
  1048. dev_err(rx_priv->dev,
  1049. "%s: invalid DAPM event %d\n", __func__, event);
  1050. ret = -EINVAL;
  1051. }
  1052. return ret;
  1053. }
  1054. static int rx_macro_event_handler(struct snd_soc_component *component,
  1055. u16 event, u32 data)
  1056. {
  1057. u16 reg = 0, reg_mix = 0, rx_idx = 0, mute = 0x0, val = 0;
  1058. struct device *rx_dev = NULL;
  1059. struct rx_macro_priv *rx_priv = NULL;
  1060. int ret = 0;
  1061. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1062. return -EINVAL;
  1063. switch (event) {
  1064. case BOLERO_MACRO_EVT_RX_MUTE:
  1065. rx_idx = data >> 0x10;
  1066. mute = data & 0xffff;
  1067. val = mute ? 0x10 : 0x00;
  1068. reg = BOLERO_CDC_RX_RX0_RX_PATH_CTL + (rx_idx *
  1069. RX_MACRO_RX_PATH_OFFSET);
  1070. reg_mix = BOLERO_CDC_RX_RX0_RX_PATH_MIX_CTL + (rx_idx *
  1071. RX_MACRO_RX_PATH_OFFSET);
  1072. snd_soc_component_update_bits(component, reg,
  1073. 0x10, val);
  1074. snd_soc_component_update_bits(component, reg_mix,
  1075. 0x10, val);
  1076. break;
  1077. case BOLERO_MACRO_EVT_IMPED_TRUE:
  1078. rx_macro_wcd_clsh_imped_config(component, data, true);
  1079. break;
  1080. case BOLERO_MACRO_EVT_IMPED_FALSE:
  1081. rx_macro_wcd_clsh_imped_config(component, data, false);
  1082. break;
  1083. case BOLERO_MACRO_EVT_SSR_DOWN:
  1084. rx_priv->dev_up = false;
  1085. swrm_wcd_notify(
  1086. rx_priv->swr_ctrl_data[0].rx_swr_pdev,
  1087. SWR_DEVICE_DOWN, NULL);
  1088. swrm_wcd_notify(
  1089. rx_priv->swr_ctrl_data[0].rx_swr_pdev,
  1090. SWR_DEVICE_SSR_DOWN, NULL);
  1091. break;
  1092. case BOLERO_MACRO_EVT_SSR_UP:
  1093. rx_priv->dev_up = true;
  1094. /* reset swr after ssr/pdr */
  1095. rx_priv->reset_swr = true;
  1096. /* enable&disable RX_CORE_CLK to reset GFMUX reg */
  1097. ret = bolero_clk_rsc_request_clock(rx_priv->dev,
  1098. rx_priv->default_clk_id,
  1099. RX_CORE_CLK, true);
  1100. if (ret < 0)
  1101. dev_err_ratelimited(rx_priv->dev,
  1102. "%s, failed to enable clk, ret:%d\n",
  1103. __func__, ret);
  1104. else
  1105. bolero_clk_rsc_request_clock(rx_priv->dev,
  1106. rx_priv->default_clk_id,
  1107. RX_CORE_CLK, false);
  1108. swrm_wcd_notify(
  1109. rx_priv->swr_ctrl_data[0].rx_swr_pdev,
  1110. SWR_DEVICE_SSR_UP, NULL);
  1111. break;
  1112. }
  1113. return ret;
  1114. }
  1115. static int rx_macro_find_playback_dai_id_for_port(int port_id,
  1116. struct rx_macro_priv *rx_priv)
  1117. {
  1118. int i = 0;
  1119. for (i = RX_MACRO_AIF1_PB; i < RX_MACRO_MAX_DAIS; i++) {
  1120. if (test_bit(port_id, &rx_priv->active_ch_mask[i]))
  1121. return i;
  1122. }
  1123. return -EINVAL;
  1124. }
  1125. static int rx_macro_set_idle_detect_thr(struct snd_soc_component *component,
  1126. struct rx_macro_priv *rx_priv,
  1127. int interp, int path_type)
  1128. {
  1129. int port_id[4] = { 0, 0, 0, 0 };
  1130. int *port_ptr = NULL;
  1131. int num_ports = 0;
  1132. int bit_width = 0, i = 0;
  1133. int mux_reg = 0, mux_reg_val = 0;
  1134. int dai_id = 0, idle_thr = 0;
  1135. if ((interp != INTERP_HPHL) && (interp != INTERP_HPHR))
  1136. return 0;
  1137. if (!rx_priv->idle_det_cfg.hph_idle_detect_en)
  1138. return 0;
  1139. port_ptr = &port_id[0];
  1140. num_ports = 0;
  1141. /*
  1142. * Read interpolator MUX input registers and find
  1143. * which cdc_dma port is connected and store the port
  1144. * numbers in port_id array.
  1145. */
  1146. if (path_type == INTERP_MIX_PATH) {
  1147. mux_reg = BOLERO_CDC_RX_INP_MUX_RX_INT0_CFG1 +
  1148. 2 * interp;
  1149. mux_reg_val = snd_soc_component_read32(component, mux_reg) &
  1150. 0x0f;
  1151. if ((mux_reg_val >= INTn_2_INP_SEL_RX0) &&
  1152. (mux_reg_val <= INTn_2_INP_SEL_RX5)) {
  1153. *port_ptr++ = mux_reg_val - 1;
  1154. num_ports++;
  1155. }
  1156. }
  1157. if (path_type == INTERP_MAIN_PATH) {
  1158. mux_reg = BOLERO_CDC_RX_INP_MUX_RX_INT1_CFG0 +
  1159. 2 * (interp - 1);
  1160. mux_reg_val = snd_soc_component_read32(component, mux_reg) &
  1161. 0x0f;
  1162. i = RX_MACRO_INTERP_MUX_NUM_INPUTS;
  1163. while (i) {
  1164. if ((mux_reg_val >= INTn_1_INP_SEL_RX0) &&
  1165. (mux_reg_val <= INTn_1_INP_SEL_RX5)) {
  1166. *port_ptr++ = mux_reg_val -
  1167. INTn_1_INP_SEL_RX0;
  1168. num_ports++;
  1169. }
  1170. mux_reg_val =
  1171. (snd_soc_component_read32(component, mux_reg) &
  1172. 0xf0) >> 4;
  1173. mux_reg += 1;
  1174. i--;
  1175. }
  1176. }
  1177. dev_dbg(component->dev, "%s: num_ports: %d, ports[%d %d %d %d]\n",
  1178. __func__, num_ports, port_id[0], port_id[1],
  1179. port_id[2], port_id[3]);
  1180. i = 0;
  1181. while (num_ports) {
  1182. dai_id = rx_macro_find_playback_dai_id_for_port(port_id[i++],
  1183. rx_priv);
  1184. if ((dai_id >= 0) && (dai_id < RX_MACRO_MAX_DAIS)) {
  1185. dev_dbg(component->dev, "%s: dai_id: %d bit_width: %d\n",
  1186. __func__, dai_id,
  1187. rx_priv->bit_width[dai_id]);
  1188. if (rx_priv->bit_width[dai_id] > bit_width)
  1189. bit_width = rx_priv->bit_width[dai_id];
  1190. }
  1191. num_ports--;
  1192. }
  1193. switch (bit_width) {
  1194. case 16:
  1195. idle_thr = 0xff; /* F16 */
  1196. break;
  1197. case 24:
  1198. case 32:
  1199. idle_thr = 0x03; /* F22 */
  1200. break;
  1201. default:
  1202. idle_thr = 0x00;
  1203. break;
  1204. }
  1205. dev_dbg(component->dev, "%s: (new) idle_thr: %d, (cur) idle_thr: %d\n",
  1206. __func__, idle_thr, rx_priv->idle_det_cfg.hph_idle_thr);
  1207. if ((rx_priv->idle_det_cfg.hph_idle_thr == 0) ||
  1208. (idle_thr < rx_priv->idle_det_cfg.hph_idle_thr)) {
  1209. snd_soc_component_write(component,
  1210. BOLERO_CDC_RX_IDLE_DETECT_CFG3, idle_thr);
  1211. rx_priv->idle_det_cfg.hph_idle_thr = idle_thr;
  1212. }
  1213. return 0;
  1214. }
  1215. static int rx_macro_enable_mix_path(struct snd_soc_dapm_widget *w,
  1216. struct snd_kcontrol *kcontrol, int event)
  1217. {
  1218. struct snd_soc_component *component =
  1219. snd_soc_dapm_to_component(w->dapm);
  1220. u16 gain_reg = 0, mix_reg = 0;
  1221. struct device *rx_dev = NULL;
  1222. struct rx_macro_priv *rx_priv = NULL;
  1223. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1224. return -EINVAL;
  1225. if (w->shift >= INTERP_MAX) {
  1226. dev_err(component->dev, "%s: Invalid Interpolator value %d for name %s\n",
  1227. __func__, w->shift, w->name);
  1228. return -EINVAL;
  1229. }
  1230. gain_reg = BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL +
  1231. (w->shift * RX_MACRO_RX_PATH_OFFSET);
  1232. mix_reg = BOLERO_CDC_RX_RX0_RX_PATH_MIX_CTL +
  1233. (w->shift * RX_MACRO_RX_PATH_OFFSET);
  1234. dev_dbg(component->dev, "%s %d %s\n", __func__, event, w->name);
  1235. switch (event) {
  1236. case SND_SOC_DAPM_PRE_PMU:
  1237. rx_macro_set_idle_detect_thr(component, rx_priv, w->shift,
  1238. INTERP_MIX_PATH);
  1239. rx_macro_enable_interp_clk(component, event, w->shift);
  1240. /* Clk enable */
  1241. snd_soc_component_update_bits(component, mix_reg, 0x20, 0x20);
  1242. break;
  1243. case SND_SOC_DAPM_POST_PMU:
  1244. snd_soc_component_write(component, gain_reg,
  1245. snd_soc_component_read32(component, gain_reg));
  1246. break;
  1247. case SND_SOC_DAPM_POST_PMD:
  1248. /* Clk Disable */
  1249. snd_soc_component_update_bits(component, mix_reg, 0x20, 0x00);
  1250. rx_macro_enable_interp_clk(component, event, w->shift);
  1251. /* Reset enable and disable */
  1252. snd_soc_component_update_bits(component, mix_reg, 0x40, 0x40);
  1253. snd_soc_component_update_bits(component, mix_reg, 0x40, 0x00);
  1254. break;
  1255. }
  1256. return 0;
  1257. }
  1258. static int rx_macro_enable_main_path(struct snd_soc_dapm_widget *w,
  1259. struct snd_kcontrol *kcontrol,
  1260. int event)
  1261. {
  1262. struct snd_soc_component *component =
  1263. snd_soc_dapm_to_component(w->dapm);
  1264. u16 gain_reg = 0;
  1265. u16 reg = 0;
  1266. struct device *rx_dev = NULL;
  1267. struct rx_macro_priv *rx_priv = NULL;
  1268. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1269. return -EINVAL;
  1270. dev_dbg(component->dev, "%s %d %s\n", __func__, event, w->name);
  1271. if (w->shift >= INTERP_MAX) {
  1272. dev_err(component->dev, "%s: Invalid Interpolator value %d for name %s\n",
  1273. __func__, w->shift, w->name);
  1274. return -EINVAL;
  1275. }
  1276. reg = BOLERO_CDC_RX_RX0_RX_PATH_CTL + (w->shift *
  1277. RX_MACRO_RX_PATH_OFFSET);
  1278. gain_reg = BOLERO_CDC_RX_RX0_RX_VOL_CTL + (w->shift *
  1279. RX_MACRO_RX_PATH_OFFSET);
  1280. switch (event) {
  1281. case SND_SOC_DAPM_PRE_PMU:
  1282. rx_macro_set_idle_detect_thr(component, rx_priv, w->shift,
  1283. INTERP_MAIN_PATH);
  1284. rx_macro_enable_interp_clk(component, event, w->shift);
  1285. break;
  1286. case SND_SOC_DAPM_POST_PMU:
  1287. snd_soc_component_write(component, gain_reg,
  1288. snd_soc_component_read32(component, gain_reg));
  1289. break;
  1290. case SND_SOC_DAPM_POST_PMD:
  1291. rx_macro_enable_interp_clk(component, event, w->shift);
  1292. break;
  1293. }
  1294. return 0;
  1295. }
  1296. static int rx_macro_config_compander(struct snd_soc_component *component,
  1297. struct rx_macro_priv *rx_priv,
  1298. int interp_n, int event)
  1299. {
  1300. int comp = 0;
  1301. u16 comp_ctl0_reg = 0, rx_path_cfg0_reg = 0;
  1302. /* AUX does not have compander */
  1303. if (interp_n == INTERP_AUX)
  1304. return 0;
  1305. comp = interp_n;
  1306. dev_dbg(component->dev, "%s: event %d compander %d, enabled %d\n",
  1307. __func__, event, comp + 1, rx_priv->comp_enabled[comp]);
  1308. if (!rx_priv->comp_enabled[comp])
  1309. return 0;
  1310. comp_ctl0_reg = BOLERO_CDC_RX_COMPANDER0_CTL0 +
  1311. (comp * RX_MACRO_COMP_OFFSET);
  1312. rx_path_cfg0_reg = BOLERO_CDC_RX_RX0_RX_PATH_CFG0 +
  1313. (comp * RX_MACRO_RX_PATH_OFFSET);
  1314. if (SND_SOC_DAPM_EVENT_ON(event)) {
  1315. /* Enable Compander Clock */
  1316. snd_soc_component_update_bits(component, comp_ctl0_reg,
  1317. 0x01, 0x01);
  1318. snd_soc_component_update_bits(component, comp_ctl0_reg,
  1319. 0x02, 0x02);
  1320. snd_soc_component_update_bits(component, comp_ctl0_reg,
  1321. 0x02, 0x00);
  1322. snd_soc_component_update_bits(component, rx_path_cfg0_reg,
  1323. 0x02, 0x02);
  1324. }
  1325. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  1326. snd_soc_component_update_bits(component, comp_ctl0_reg,
  1327. 0x04, 0x04);
  1328. snd_soc_component_update_bits(component, rx_path_cfg0_reg,
  1329. 0x02, 0x00);
  1330. snd_soc_component_update_bits(component, comp_ctl0_reg,
  1331. 0x01, 0x00);
  1332. snd_soc_component_update_bits(component, comp_ctl0_reg,
  1333. 0x04, 0x00);
  1334. }
  1335. return 0;
  1336. }
  1337. static void rx_macro_enable_softclip_clk(struct snd_soc_component *component,
  1338. struct rx_macro_priv *rx_priv,
  1339. bool enable)
  1340. {
  1341. if (enable) {
  1342. if (rx_priv->softclip_clk_users == 0)
  1343. snd_soc_component_update_bits(component,
  1344. BOLERO_CDC_RX_SOFTCLIP_CRC,
  1345. 0x01, 0x01);
  1346. rx_priv->softclip_clk_users++;
  1347. } else {
  1348. rx_priv->softclip_clk_users--;
  1349. if (rx_priv->softclip_clk_users == 0)
  1350. snd_soc_component_update_bits(component,
  1351. BOLERO_CDC_RX_SOFTCLIP_CRC,
  1352. 0x01, 0x00);
  1353. }
  1354. }
  1355. static int rx_macro_config_softclip(struct snd_soc_component *component,
  1356. struct rx_macro_priv *rx_priv,
  1357. int event)
  1358. {
  1359. dev_dbg(component->dev, "%s: event %d, enabled %d\n",
  1360. __func__, event, rx_priv->is_softclip_on);
  1361. if (!rx_priv->is_softclip_on)
  1362. return 0;
  1363. if (SND_SOC_DAPM_EVENT_ON(event)) {
  1364. /* Enable Softclip clock */
  1365. rx_macro_enable_softclip_clk(component, rx_priv, true);
  1366. /* Enable Softclip control */
  1367. snd_soc_component_update_bits(component,
  1368. BOLERO_CDC_RX_SOFTCLIP_SOFTCLIP_CTRL, 0x01, 0x01);
  1369. }
  1370. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  1371. snd_soc_component_update_bits(component,
  1372. BOLERO_CDC_RX_SOFTCLIP_SOFTCLIP_CTRL, 0x01, 0x00);
  1373. rx_macro_enable_softclip_clk(component, rx_priv, false);
  1374. }
  1375. return 0;
  1376. }
  1377. static inline void
  1378. rx_macro_enable_clsh_block(struct rx_macro_priv *rx_priv, bool enable)
  1379. {
  1380. if ((enable && ++rx_priv->clsh_users == 1) ||
  1381. (!enable && --rx_priv->clsh_users == 0))
  1382. snd_soc_component_update_bits(rx_priv->component,
  1383. BOLERO_CDC_RX_CLSH_CRC, 0x01,
  1384. (u8) enable);
  1385. if (rx_priv->clsh_users < 0)
  1386. rx_priv->clsh_users = 0;
  1387. dev_dbg(rx_priv->dev, "%s: clsh_users %d, enable %d", __func__,
  1388. rx_priv->clsh_users, enable);
  1389. }
  1390. static int rx_macro_config_classh(struct snd_soc_component *component,
  1391. struct rx_macro_priv *rx_priv,
  1392. int interp_n, int event)
  1393. {
  1394. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  1395. rx_macro_enable_clsh_block(rx_priv, false);
  1396. return 0;
  1397. }
  1398. if (!SND_SOC_DAPM_EVENT_ON(event))
  1399. return 0;
  1400. rx_macro_enable_clsh_block(rx_priv, true);
  1401. if (interp_n == INTERP_HPHL ||
  1402. interp_n == INTERP_HPHR) {
  1403. /*
  1404. * These K1 values depend on the Headphone Impedance
  1405. * For now it is assumed to be 16 ohm
  1406. */
  1407. snd_soc_component_update_bits(component,
  1408. BOLERO_CDC_RX_CLSH_K1_LSB,
  1409. 0xFF, 0xC0);
  1410. snd_soc_component_update_bits(component,
  1411. BOLERO_CDC_RX_CLSH_K1_MSB,
  1412. 0x0F, 0x00);
  1413. }
  1414. switch (interp_n) {
  1415. case INTERP_HPHL:
  1416. if (rx_priv->is_ear_mode_on)
  1417. snd_soc_component_update_bits(component,
  1418. BOLERO_CDC_RX_CLSH_HPH_V_PA,
  1419. 0x3F, 0x39);
  1420. else
  1421. snd_soc_component_update_bits(component,
  1422. BOLERO_CDC_RX_CLSH_HPH_V_PA,
  1423. 0x3F, 0x1C);
  1424. snd_soc_component_update_bits(component,
  1425. BOLERO_CDC_RX_CLSH_DECAY_CTRL,
  1426. 0x07, 0x00);
  1427. snd_soc_component_update_bits(component,
  1428. BOLERO_CDC_RX_RX0_RX_PATH_CFG0,
  1429. 0x40, 0x40);
  1430. break;
  1431. case INTERP_HPHR:
  1432. snd_soc_component_update_bits(component,
  1433. BOLERO_CDC_RX_CLSH_HPH_V_PA,
  1434. 0x3F, 0x1C);
  1435. snd_soc_component_update_bits(component,
  1436. BOLERO_CDC_RX_CLSH_DECAY_CTRL,
  1437. 0x07, 0x00);
  1438. snd_soc_component_update_bits(component,
  1439. BOLERO_CDC_RX_RX1_RX_PATH_CFG0,
  1440. 0x40, 0x40);
  1441. break;
  1442. case INTERP_AUX:
  1443. snd_soc_component_update_bits(component,
  1444. BOLERO_CDC_RX_RX2_RX_PATH_CFG0,
  1445. 0x08, 0x08);
  1446. snd_soc_component_update_bits(component,
  1447. BOLERO_CDC_RX_RX2_RX_PATH_CFG0,
  1448. 0x10, 0x10);
  1449. break;
  1450. }
  1451. return 0;
  1452. }
  1453. static void rx_macro_hd2_control(struct snd_soc_component *component,
  1454. u16 interp_idx, int event)
  1455. {
  1456. u16 hd2_scale_reg = 0;
  1457. u16 hd2_enable_reg = 0;
  1458. switch (interp_idx) {
  1459. case INTERP_HPHL:
  1460. hd2_scale_reg = BOLERO_CDC_RX_RX0_RX_PATH_SEC3;
  1461. hd2_enable_reg = BOLERO_CDC_RX_RX0_RX_PATH_CFG0;
  1462. break;
  1463. case INTERP_HPHR:
  1464. hd2_scale_reg = BOLERO_CDC_RX_RX1_RX_PATH_SEC3;
  1465. hd2_enable_reg = BOLERO_CDC_RX_RX1_RX_PATH_CFG0;
  1466. break;
  1467. }
  1468. if (hd2_enable_reg && SND_SOC_DAPM_EVENT_ON(event)) {
  1469. snd_soc_component_update_bits(component, hd2_scale_reg,
  1470. 0x3C, 0x14);
  1471. snd_soc_component_update_bits(component, hd2_enable_reg,
  1472. 0x04, 0x04);
  1473. }
  1474. if (hd2_enable_reg && SND_SOC_DAPM_EVENT_OFF(event)) {
  1475. snd_soc_component_update_bits(component, hd2_enable_reg,
  1476. 0x04, 0x00);
  1477. snd_soc_component_update_bits(component, hd2_scale_reg,
  1478. 0x3C, 0x00);
  1479. }
  1480. }
  1481. static int rx_macro_hph_idle_detect_get(struct snd_kcontrol *kcontrol,
  1482. struct snd_ctl_elem_value *ucontrol)
  1483. {
  1484. struct snd_soc_component *component =
  1485. snd_soc_kcontrol_component(kcontrol);
  1486. struct rx_macro_priv *rx_priv = NULL;
  1487. struct device *rx_dev = NULL;
  1488. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1489. return -EINVAL;
  1490. ucontrol->value.integer.value[0] =
  1491. rx_priv->idle_det_cfg.hph_idle_detect_en;
  1492. return 0;
  1493. }
  1494. static int rx_macro_hph_idle_detect_put(struct snd_kcontrol *kcontrol,
  1495. struct snd_ctl_elem_value *ucontrol)
  1496. {
  1497. struct snd_soc_component *component =
  1498. snd_soc_kcontrol_component(kcontrol);
  1499. struct rx_macro_priv *rx_priv = NULL;
  1500. struct device *rx_dev = NULL;
  1501. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1502. return -EINVAL;
  1503. rx_priv->idle_det_cfg.hph_idle_detect_en =
  1504. ucontrol->value.integer.value[0];
  1505. return 0;
  1506. }
  1507. static int rx_macro_get_compander(struct snd_kcontrol *kcontrol,
  1508. struct snd_ctl_elem_value *ucontrol)
  1509. {
  1510. struct snd_soc_component *component =
  1511. snd_soc_kcontrol_component(kcontrol);
  1512. int comp = ((struct soc_multi_mixer_control *)
  1513. kcontrol->private_value)->shift;
  1514. struct device *rx_dev = NULL;
  1515. struct rx_macro_priv *rx_priv = NULL;
  1516. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1517. return -EINVAL;
  1518. ucontrol->value.integer.value[0] = rx_priv->comp_enabled[comp];
  1519. return 0;
  1520. }
  1521. static int rx_macro_set_compander(struct snd_kcontrol *kcontrol,
  1522. struct snd_ctl_elem_value *ucontrol)
  1523. {
  1524. struct snd_soc_component *component =
  1525. snd_soc_kcontrol_component(kcontrol);
  1526. int comp = ((struct soc_multi_mixer_control *)
  1527. kcontrol->private_value)->shift;
  1528. int value = ucontrol->value.integer.value[0];
  1529. struct device *rx_dev = NULL;
  1530. struct rx_macro_priv *rx_priv = NULL;
  1531. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1532. return -EINVAL;
  1533. dev_dbg(component->dev, "%s: Compander %d enable current %d, new %d\n",
  1534. __func__, comp + 1, rx_priv->comp_enabled[comp], value);
  1535. rx_priv->comp_enabled[comp] = value;
  1536. return 0;
  1537. }
  1538. static int rx_macro_mux_get(struct snd_kcontrol *kcontrol,
  1539. struct snd_ctl_elem_value *ucontrol)
  1540. {
  1541. struct snd_soc_dapm_widget *widget =
  1542. snd_soc_dapm_kcontrol_widget(kcontrol);
  1543. struct snd_soc_component *component =
  1544. snd_soc_dapm_to_component(widget->dapm);
  1545. struct device *rx_dev = NULL;
  1546. struct rx_macro_priv *rx_priv = NULL;
  1547. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1548. return -EINVAL;
  1549. ucontrol->value.integer.value[0] =
  1550. rx_priv->rx_port_value[widget->shift];
  1551. return 0;
  1552. }
  1553. static int rx_macro_mux_put(struct snd_kcontrol *kcontrol,
  1554. struct snd_ctl_elem_value *ucontrol)
  1555. {
  1556. struct snd_soc_dapm_widget *widget =
  1557. snd_soc_dapm_kcontrol_widget(kcontrol);
  1558. struct snd_soc_component *component =
  1559. snd_soc_dapm_to_component(widget->dapm);
  1560. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1561. struct snd_soc_dapm_update *update = NULL;
  1562. u32 rx_port_value = ucontrol->value.integer.value[0];
  1563. u32 aif_rst = 0;
  1564. struct device *rx_dev = NULL;
  1565. struct rx_macro_priv *rx_priv = NULL;
  1566. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1567. return -EINVAL;
  1568. aif_rst = rx_priv->rx_port_value[widget->shift];
  1569. if (!rx_port_value) {
  1570. if (aif_rst == 0) {
  1571. dev_err(rx_dev, "%s:AIF reset already\n", __func__);
  1572. return 0;
  1573. }
  1574. }
  1575. rx_priv->rx_port_value[widget->shift] = rx_port_value;
  1576. switch (rx_port_value) {
  1577. case 0:
  1578. clear_bit(widget->shift,
  1579. &rx_priv->active_ch_mask[aif_rst]);
  1580. rx_priv->active_ch_cnt[aif_rst]--;
  1581. break;
  1582. case 1:
  1583. case 2:
  1584. case 3:
  1585. case 4:
  1586. set_bit(widget->shift,
  1587. &rx_priv->active_ch_mask[rx_port_value]);
  1588. rx_priv->active_ch_cnt[rx_port_value]++;
  1589. break;
  1590. default:
  1591. dev_err(component->dev,
  1592. "%s:Invalid AIF_ID for RX_MACRO MUX\n", __func__);
  1593. goto err;
  1594. }
  1595. snd_soc_dapm_mux_update_power(widget->dapm, kcontrol,
  1596. rx_port_value, e, update);
  1597. return 0;
  1598. err:
  1599. return -EINVAL;
  1600. }
  1601. static int rx_macro_get_ear_mode(struct snd_kcontrol *kcontrol,
  1602. struct snd_ctl_elem_value *ucontrol)
  1603. {
  1604. struct snd_soc_component *component =
  1605. snd_soc_kcontrol_component(kcontrol);
  1606. struct device *rx_dev = NULL;
  1607. struct rx_macro_priv *rx_priv = NULL;
  1608. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1609. return -EINVAL;
  1610. ucontrol->value.integer.value[0] = rx_priv->is_ear_mode_on;
  1611. return 0;
  1612. }
  1613. static int rx_macro_put_ear_mode(struct snd_kcontrol *kcontrol,
  1614. struct snd_ctl_elem_value *ucontrol)
  1615. {
  1616. struct snd_soc_component *component =
  1617. snd_soc_kcontrol_component(kcontrol);
  1618. struct device *rx_dev = NULL;
  1619. struct rx_macro_priv *rx_priv = NULL;
  1620. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1621. return -EINVAL;
  1622. rx_priv->is_ear_mode_on =
  1623. (!ucontrol->value.integer.value[0] ? false : true);
  1624. return 0;
  1625. }
  1626. static int rx_macro_get_hph_hd2_mode(struct snd_kcontrol *kcontrol,
  1627. struct snd_ctl_elem_value *ucontrol)
  1628. {
  1629. struct snd_soc_component *component =
  1630. snd_soc_kcontrol_component(kcontrol);
  1631. struct device *rx_dev = NULL;
  1632. struct rx_macro_priv *rx_priv = NULL;
  1633. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1634. return -EINVAL;
  1635. ucontrol->value.integer.value[0] = rx_priv->hph_hd2_mode;
  1636. return 0;
  1637. }
  1638. static int rx_macro_put_hph_hd2_mode(struct snd_kcontrol *kcontrol,
  1639. struct snd_ctl_elem_value *ucontrol)
  1640. {
  1641. struct snd_soc_component *component =
  1642. snd_soc_kcontrol_component(kcontrol);
  1643. struct device *rx_dev = NULL;
  1644. struct rx_macro_priv *rx_priv = NULL;
  1645. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1646. return -EINVAL;
  1647. rx_priv->hph_hd2_mode = ucontrol->value.integer.value[0];
  1648. return 0;
  1649. }
  1650. static int rx_macro_get_hph_pwr_mode(struct snd_kcontrol *kcontrol,
  1651. struct snd_ctl_elem_value *ucontrol)
  1652. {
  1653. struct snd_soc_component *component =
  1654. snd_soc_kcontrol_component(kcontrol);
  1655. struct device *rx_dev = NULL;
  1656. struct rx_macro_priv *rx_priv = NULL;
  1657. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1658. return -EINVAL;
  1659. ucontrol->value.integer.value[0] = rx_priv->hph_pwr_mode;
  1660. return 0;
  1661. }
  1662. static int rx_macro_put_hph_pwr_mode(struct snd_kcontrol *kcontrol,
  1663. struct snd_ctl_elem_value *ucontrol)
  1664. {
  1665. struct snd_soc_component *component =
  1666. snd_soc_kcontrol_component(kcontrol);
  1667. struct device *rx_dev = NULL;
  1668. struct rx_macro_priv *rx_priv = NULL;
  1669. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1670. return -EINVAL;
  1671. rx_priv->hph_pwr_mode = ucontrol->value.integer.value[0];
  1672. return 0;
  1673. }
  1674. static int rx_macro_vbat_bcl_gsm_mode_func_get(struct snd_kcontrol *kcontrol,
  1675. struct snd_ctl_elem_value *ucontrol)
  1676. {
  1677. struct snd_soc_component *component =
  1678. snd_soc_kcontrol_component(kcontrol);
  1679. ucontrol->value.integer.value[0] =
  1680. ((snd_soc_component_read32(
  1681. component, BOLERO_CDC_RX_BCL_VBAT_CFG) & 0x04) ?
  1682. 1 : 0);
  1683. dev_dbg(component->dev, "%s: value: %lu\n", __func__,
  1684. ucontrol->value.integer.value[0]);
  1685. return 0;
  1686. }
  1687. static int rx_macro_vbat_bcl_gsm_mode_func_put(struct snd_kcontrol *kcontrol,
  1688. struct snd_ctl_elem_value *ucontrol)
  1689. {
  1690. struct snd_soc_component *component =
  1691. snd_soc_kcontrol_component(kcontrol);
  1692. dev_dbg(component->dev, "%s: value: %lu\n", __func__,
  1693. ucontrol->value.integer.value[0]);
  1694. /* Set Vbat register configuration for GSM mode bit based on value */
  1695. if (ucontrol->value.integer.value[0])
  1696. snd_soc_component_update_bits(component,
  1697. BOLERO_CDC_RX_BCL_VBAT_CFG,
  1698. 0x04, 0x04);
  1699. else
  1700. snd_soc_component_update_bits(component,
  1701. BOLERO_CDC_RX_BCL_VBAT_CFG,
  1702. 0x04, 0x00);
  1703. return 0;
  1704. }
  1705. static int rx_macro_soft_clip_enable_get(struct snd_kcontrol *kcontrol,
  1706. struct snd_ctl_elem_value *ucontrol)
  1707. {
  1708. struct snd_soc_component *component =
  1709. snd_soc_kcontrol_component(kcontrol);
  1710. struct device *rx_dev = NULL;
  1711. struct rx_macro_priv *rx_priv = NULL;
  1712. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1713. return -EINVAL;
  1714. ucontrol->value.integer.value[0] = rx_priv->is_softclip_on;
  1715. dev_dbg(component->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  1716. __func__, ucontrol->value.integer.value[0]);
  1717. return 0;
  1718. }
  1719. static int rx_macro_soft_clip_enable_put(struct snd_kcontrol *kcontrol,
  1720. struct snd_ctl_elem_value *ucontrol)
  1721. {
  1722. struct snd_soc_component *component =
  1723. snd_soc_kcontrol_component(kcontrol);
  1724. struct device *rx_dev = NULL;
  1725. struct rx_macro_priv *rx_priv = NULL;
  1726. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1727. return -EINVAL;
  1728. rx_priv->is_softclip_on = ucontrol->value.integer.value[0];
  1729. dev_dbg(component->dev, "%s: soft clip enable = %d\n", __func__,
  1730. rx_priv->is_softclip_on);
  1731. return 0;
  1732. }
  1733. static int rx_macro_enable_vbat(struct snd_soc_dapm_widget *w,
  1734. struct snd_kcontrol *kcontrol,
  1735. int event)
  1736. {
  1737. struct snd_soc_component *component =
  1738. snd_soc_dapm_to_component(w->dapm);
  1739. struct device *rx_dev = NULL;
  1740. struct rx_macro_priv *rx_priv = NULL;
  1741. dev_dbg(component->dev, "%s %s %d\n", __func__, w->name, event);
  1742. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1743. return -EINVAL;
  1744. switch (event) {
  1745. case SND_SOC_DAPM_PRE_PMU:
  1746. /* Enable clock for VBAT block */
  1747. snd_soc_component_update_bits(component,
  1748. BOLERO_CDC_RX_BCL_VBAT_PATH_CTL, 0x10, 0x10);
  1749. /* Enable VBAT block */
  1750. snd_soc_component_update_bits(component,
  1751. BOLERO_CDC_RX_BCL_VBAT_CFG, 0x01, 0x01);
  1752. /* Update interpolator with 384K path */
  1753. snd_soc_component_update_bits(component,
  1754. BOLERO_CDC_RX_RX2_RX_PATH_CFG1, 0x80, 0x80);
  1755. /* Update DSM FS rate */
  1756. snd_soc_component_update_bits(component,
  1757. BOLERO_CDC_RX_RX2_RX_PATH_SEC7, 0x02, 0x02);
  1758. /* Use attenuation mode */
  1759. snd_soc_component_update_bits(component,
  1760. BOLERO_CDC_RX_BCL_VBAT_CFG, 0x02, 0x00);
  1761. /* BCL block needs softclip clock to be enabled */
  1762. rx_macro_enable_softclip_clk(component, rx_priv, true);
  1763. /* Enable VBAT at channel level */
  1764. snd_soc_component_update_bits(component,
  1765. BOLERO_CDC_RX_RX2_RX_PATH_CFG1, 0x02, 0x02);
  1766. /* Set the ATTK1 gain */
  1767. snd_soc_component_update_bits(component,
  1768. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD1,
  1769. 0xFF, 0xFF);
  1770. snd_soc_component_update_bits(component,
  1771. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD2,
  1772. 0xFF, 0x03);
  1773. snd_soc_component_update_bits(component,
  1774. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD3,
  1775. 0xFF, 0x00);
  1776. /* Set the ATTK2 gain */
  1777. snd_soc_component_update_bits(component,
  1778. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD4,
  1779. 0xFF, 0xFF);
  1780. snd_soc_component_update_bits(component,
  1781. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD5,
  1782. 0xFF, 0x03);
  1783. snd_soc_component_update_bits(component,
  1784. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD6,
  1785. 0xFF, 0x00);
  1786. /* Set the ATTK3 gain */
  1787. snd_soc_component_update_bits(component,
  1788. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD7,
  1789. 0xFF, 0xFF);
  1790. snd_soc_component_update_bits(component,
  1791. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD8,
  1792. 0xFF, 0x03);
  1793. snd_soc_component_update_bits(component,
  1794. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD9,
  1795. 0xFF, 0x00);
  1796. break;
  1797. case SND_SOC_DAPM_POST_PMD:
  1798. snd_soc_component_update_bits(component,
  1799. BOLERO_CDC_RX_RX2_RX_PATH_CFG1,
  1800. 0x80, 0x00);
  1801. snd_soc_component_update_bits(component,
  1802. BOLERO_CDC_RX_RX2_RX_PATH_SEC7,
  1803. 0x02, 0x00);
  1804. snd_soc_component_update_bits(component,
  1805. BOLERO_CDC_RX_BCL_VBAT_CFG,
  1806. 0x02, 0x02);
  1807. snd_soc_component_update_bits(component,
  1808. BOLERO_CDC_RX_RX2_RX_PATH_CFG1,
  1809. 0x02, 0x00);
  1810. snd_soc_component_update_bits(component,
  1811. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD1,
  1812. 0xFF, 0x00);
  1813. snd_soc_component_update_bits(component,
  1814. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD2,
  1815. 0xFF, 0x00);
  1816. snd_soc_component_update_bits(component,
  1817. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD3,
  1818. 0xFF, 0x00);
  1819. snd_soc_component_update_bits(component,
  1820. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD4,
  1821. 0xFF, 0x00);
  1822. snd_soc_component_update_bits(component,
  1823. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD5,
  1824. 0xFF, 0x00);
  1825. snd_soc_component_update_bits(component,
  1826. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD6,
  1827. 0xFF, 0x00);
  1828. snd_soc_component_update_bits(component,
  1829. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD7,
  1830. 0xFF, 0x00);
  1831. snd_soc_component_update_bits(component,
  1832. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD8,
  1833. 0xFF, 0x00);
  1834. snd_soc_component_update_bits(component,
  1835. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD9,
  1836. 0xFF, 0x00);
  1837. rx_macro_enable_softclip_clk(component, rx_priv, false);
  1838. snd_soc_component_update_bits(component,
  1839. BOLERO_CDC_RX_BCL_VBAT_CFG, 0x01, 0x00);
  1840. snd_soc_component_update_bits(component,
  1841. BOLERO_CDC_RX_BCL_VBAT_PATH_CTL, 0x10, 0x00);
  1842. break;
  1843. default:
  1844. dev_err(rx_dev, "%s: Invalid event %d\n", __func__, event);
  1845. break;
  1846. }
  1847. return 0;
  1848. }
  1849. static void rx_macro_idle_detect_control(struct snd_soc_component *component,
  1850. struct rx_macro_priv *rx_priv,
  1851. int interp, int event)
  1852. {
  1853. int reg = 0, mask = 0, val = 0;
  1854. if (!rx_priv->idle_det_cfg.hph_idle_detect_en)
  1855. return;
  1856. if (interp == INTERP_HPHL) {
  1857. reg = BOLERO_CDC_RX_IDLE_DETECT_PATH_CTL;
  1858. mask = 0x01;
  1859. val = 0x01;
  1860. }
  1861. if (interp == INTERP_HPHR) {
  1862. reg = BOLERO_CDC_RX_IDLE_DETECT_PATH_CTL;
  1863. mask = 0x02;
  1864. val = 0x02;
  1865. }
  1866. if (reg && SND_SOC_DAPM_EVENT_ON(event))
  1867. snd_soc_component_update_bits(component, reg, mask, val);
  1868. if (reg && SND_SOC_DAPM_EVENT_OFF(event)) {
  1869. snd_soc_component_update_bits(component, reg, mask, 0x00);
  1870. rx_priv->idle_det_cfg.hph_idle_thr = 0;
  1871. snd_soc_component_write(component,
  1872. BOLERO_CDC_RX_IDLE_DETECT_CFG3, 0x0);
  1873. }
  1874. }
  1875. static void rx_macro_hphdelay_lutbypass(struct snd_soc_component *component,
  1876. struct rx_macro_priv *rx_priv,
  1877. u16 interp_idx, int event)
  1878. {
  1879. u16 hph_lut_bypass_reg = 0;
  1880. u16 hph_comp_ctrl7 = 0;
  1881. switch (interp_idx) {
  1882. case INTERP_HPHL:
  1883. hph_lut_bypass_reg = BOLERO_CDC_RX_TOP_HPHL_COMP_LUT;
  1884. hph_comp_ctrl7 = BOLERO_CDC_RX_COMPANDER0_CTL7;
  1885. break;
  1886. case INTERP_HPHR:
  1887. hph_lut_bypass_reg = BOLERO_CDC_RX_TOP_HPHR_COMP_LUT;
  1888. hph_comp_ctrl7 = BOLERO_CDC_RX_COMPANDER1_CTL7;
  1889. break;
  1890. default:
  1891. break;
  1892. }
  1893. if (hph_lut_bypass_reg && SND_SOC_DAPM_EVENT_ON(event)) {
  1894. if (interp_idx == INTERP_HPHL) {
  1895. if (rx_priv->is_ear_mode_on)
  1896. snd_soc_component_update_bits(component,
  1897. BOLERO_CDC_RX_RX0_RX_PATH_CFG1,
  1898. 0x02, 0x02);
  1899. else
  1900. snd_soc_component_update_bits(component,
  1901. hph_lut_bypass_reg,
  1902. 0x80, 0x80);
  1903. } else {
  1904. snd_soc_component_update_bits(component,
  1905. hph_lut_bypass_reg,
  1906. 0x80, 0x80);
  1907. }
  1908. if (rx_priv->hph_pwr_mode)
  1909. snd_soc_component_update_bits(component,
  1910. hph_comp_ctrl7,
  1911. 0x20, 0x00);
  1912. }
  1913. if (hph_lut_bypass_reg && SND_SOC_DAPM_EVENT_OFF(event)) {
  1914. snd_soc_component_update_bits(component,
  1915. BOLERO_CDC_RX_RX0_RX_PATH_CFG1,
  1916. 0x02, 0x00);
  1917. snd_soc_component_update_bits(component, hph_lut_bypass_reg,
  1918. 0x80, 0x00);
  1919. snd_soc_component_update_bits(component, hph_comp_ctrl7,
  1920. 0x20, 0x0);
  1921. }
  1922. }
  1923. static int rx_macro_enable_interp_clk(struct snd_soc_component *component,
  1924. int event, int interp_idx)
  1925. {
  1926. u16 main_reg = 0, dsm_reg = 0, rx_cfg2_reg = 0;
  1927. struct device *rx_dev = NULL;
  1928. struct rx_macro_priv *rx_priv = NULL;
  1929. if (!component) {
  1930. pr_err("%s: component is NULL\n", __func__);
  1931. return -EINVAL;
  1932. }
  1933. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1934. return -EINVAL;
  1935. main_reg = BOLERO_CDC_RX_RX0_RX_PATH_CTL +
  1936. (interp_idx * RX_MACRO_RX_PATH_OFFSET);
  1937. dsm_reg = BOLERO_CDC_RX_RX0_RX_PATH_DSM_CTL +
  1938. (interp_idx * RX_MACRO_RX_PATH_OFFSET);
  1939. if (interp_idx == INTERP_AUX)
  1940. dsm_reg = BOLERO_CDC_RX_RX2_RX_PATH_DSM_CTL;
  1941. rx_cfg2_reg = BOLERO_CDC_RX_RX0_RX_PATH_CFG2 +
  1942. (interp_idx * RX_MACRO_RX_PATH_OFFSET);
  1943. if (SND_SOC_DAPM_EVENT_ON(event)) {
  1944. if (rx_priv->main_clk_users[interp_idx] == 0) {
  1945. /* Main path PGA mute enable */
  1946. snd_soc_component_update_bits(component, main_reg,
  1947. 0x10, 0x10);
  1948. snd_soc_component_update_bits(component, dsm_reg,
  1949. 0x01, 0x01);
  1950. /* Clk enable */
  1951. snd_soc_component_update_bits(component, main_reg,
  1952. 0x20, 0x20);
  1953. snd_soc_component_update_bits(component, rx_cfg2_reg,
  1954. 0x03, 0x03);
  1955. rx_macro_idle_detect_control(component, rx_priv,
  1956. interp_idx, event);
  1957. if (rx_priv->hph_hd2_mode)
  1958. rx_macro_hd2_control(
  1959. component, interp_idx, event);
  1960. rx_macro_hphdelay_lutbypass(component, rx_priv,
  1961. interp_idx, event);
  1962. rx_macro_config_compander(component, rx_priv,
  1963. interp_idx, event);
  1964. if (interp_idx == INTERP_AUX)
  1965. rx_macro_config_softclip(component, rx_priv,
  1966. event);
  1967. rx_macro_config_classh(component, rx_priv,
  1968. interp_idx, event);
  1969. }
  1970. rx_priv->main_clk_users[interp_idx]++;
  1971. }
  1972. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  1973. rx_priv->main_clk_users[interp_idx]--;
  1974. if (rx_priv->main_clk_users[interp_idx] <= 0) {
  1975. rx_priv->main_clk_users[interp_idx] = 0;
  1976. /* Clk Disable */
  1977. snd_soc_component_update_bits(component, dsm_reg,
  1978. 0x01, 0x00);
  1979. snd_soc_component_update_bits(component, main_reg,
  1980. 0x20, 0x00);
  1981. /* Reset enable and disable */
  1982. snd_soc_component_update_bits(component, main_reg,
  1983. 0x40, 0x40);
  1984. snd_soc_component_update_bits(component, main_reg,
  1985. 0x40, 0x00);
  1986. /* Reset rate to 48K*/
  1987. snd_soc_component_update_bits(component, main_reg,
  1988. 0x0F, 0x04);
  1989. snd_soc_component_update_bits(component, rx_cfg2_reg,
  1990. 0x03, 0x00);
  1991. rx_macro_config_classh(component, rx_priv,
  1992. interp_idx, event);
  1993. rx_macro_config_compander(component, rx_priv,
  1994. interp_idx, event);
  1995. if (interp_idx == INTERP_AUX)
  1996. rx_macro_config_softclip(component, rx_priv,
  1997. event);
  1998. rx_macro_hphdelay_lutbypass(component, rx_priv,
  1999. interp_idx, event);
  2000. if (rx_priv->hph_hd2_mode)
  2001. rx_macro_hd2_control(component, interp_idx,
  2002. event);
  2003. rx_macro_idle_detect_control(component, rx_priv,
  2004. interp_idx, event);
  2005. }
  2006. }
  2007. dev_dbg(component->dev, "%s event %d main_clk_users %d\n",
  2008. __func__, event, rx_priv->main_clk_users[interp_idx]);
  2009. return rx_priv->main_clk_users[interp_idx];
  2010. }
  2011. static int rx_macro_enable_rx_path_clk(struct snd_soc_dapm_widget *w,
  2012. struct snd_kcontrol *kcontrol, int event)
  2013. {
  2014. struct snd_soc_component *component =
  2015. snd_soc_dapm_to_component(w->dapm);
  2016. u16 sidetone_reg = 0;
  2017. dev_dbg(component->dev, "%s %d %d\n", __func__, event, w->shift);
  2018. sidetone_reg = BOLERO_CDC_RX_RX0_RX_PATH_CFG1 +
  2019. RX_MACRO_RX_PATH_OFFSET * (w->shift);
  2020. switch (event) {
  2021. case SND_SOC_DAPM_PRE_PMU:
  2022. rx_macro_enable_interp_clk(component, event, w->shift);
  2023. snd_soc_component_update_bits(component, sidetone_reg,
  2024. 0x10, 0x10);
  2025. break;
  2026. case SND_SOC_DAPM_POST_PMD:
  2027. snd_soc_component_update_bits(component, sidetone_reg,
  2028. 0x10, 0x00);
  2029. rx_macro_enable_interp_clk(component, event, w->shift);
  2030. break;
  2031. default:
  2032. break;
  2033. };
  2034. return 0;
  2035. }
  2036. static void rx_macro_restore_iir_coeff(struct rx_macro_priv *rx_priv, int iir_idx,
  2037. int band_idx)
  2038. {
  2039. u16 reg_add = 0, coeff_idx = 0, idx = 0;
  2040. struct regmap *regmap = dev_get_regmap(rx_priv->dev->parent, NULL);
  2041. if (regmap == NULL) {
  2042. dev_err(rx_priv->dev, "%s: regmap is NULL\n", __func__);
  2043. return;
  2044. }
  2045. regmap_write(regmap,
  2046. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 0x80 * iir_idx),
  2047. (band_idx * BAND_MAX * sizeof(uint32_t)) & 0x7F);
  2048. reg_add = BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx;
  2049. /* 5 coefficients per band and 4 writes per coefficient */
  2050. for (coeff_idx = 0; coeff_idx < RX_MACRO_SIDETONE_IIR_COEFF_MAX;
  2051. coeff_idx++) {
  2052. /* Four 8 bit values(one 32 bit) per coefficient */
  2053. regmap_write(regmap, reg_add,
  2054. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++]);
  2055. regmap_write(regmap, reg_add,
  2056. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++]);
  2057. regmap_write(regmap, reg_add,
  2058. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++]);
  2059. regmap_write(regmap, reg_add,
  2060. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++]);
  2061. }
  2062. }
  2063. static int rx_macro_iir_enable_audio_mixer_get(struct snd_kcontrol *kcontrol,
  2064. struct snd_ctl_elem_value *ucontrol)
  2065. {
  2066. struct snd_soc_component *component =
  2067. snd_soc_kcontrol_component(kcontrol);
  2068. int iir_idx = ((struct soc_multi_mixer_control *)
  2069. kcontrol->private_value)->reg;
  2070. int band_idx = ((struct soc_multi_mixer_control *)
  2071. kcontrol->private_value)->shift;
  2072. /* IIR filter band registers are at integer multiples of 0x80 */
  2073. u16 iir_reg = BOLERO_CDC_RX_SIDETONE_IIR0_IIR_CTL + 0x80 * iir_idx;
  2074. ucontrol->value.integer.value[0] = (
  2075. snd_soc_component_read32(component, iir_reg) &
  2076. (1 << band_idx)) != 0;
  2077. dev_dbg(component->dev, "%s: IIR #%d band #%d enable %d\n", __func__,
  2078. iir_idx, band_idx,
  2079. (uint32_t)ucontrol->value.integer.value[0]);
  2080. return 0;
  2081. }
  2082. static int rx_macro_iir_enable_audio_mixer_put(struct snd_kcontrol *kcontrol,
  2083. struct snd_ctl_elem_value *ucontrol)
  2084. {
  2085. struct snd_soc_component *component =
  2086. snd_soc_kcontrol_component(kcontrol);
  2087. int iir_idx = ((struct soc_multi_mixer_control *)
  2088. kcontrol->private_value)->reg;
  2089. int band_idx = ((struct soc_multi_mixer_control *)
  2090. kcontrol->private_value)->shift;
  2091. bool iir_band_en_status = 0;
  2092. int value = ucontrol->value.integer.value[0];
  2093. u16 iir_reg = BOLERO_CDC_RX_SIDETONE_IIR0_IIR_CTL + 0x80 * iir_idx;
  2094. struct device *rx_dev = NULL;
  2095. struct rx_macro_priv *rx_priv = NULL;
  2096. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  2097. return -EINVAL;
  2098. rx_macro_restore_iir_coeff(rx_priv, iir_idx, band_idx);
  2099. /* Mask first 5 bits, 6-8 are reserved */
  2100. snd_soc_component_update_bits(component, iir_reg, (1 << band_idx),
  2101. (value << band_idx));
  2102. iir_band_en_status = ((snd_soc_component_read32(component, iir_reg) &
  2103. (1 << band_idx)) != 0);
  2104. dev_dbg(component->dev, "%s: IIR #%d band #%d enable %d\n", __func__,
  2105. iir_idx, band_idx, iir_band_en_status);
  2106. return 0;
  2107. }
  2108. static uint32_t get_iir_band_coeff(struct snd_soc_component *component,
  2109. int iir_idx, int band_idx,
  2110. int coeff_idx)
  2111. {
  2112. uint32_t value = 0;
  2113. /* Address does not automatically update if reading */
  2114. snd_soc_component_write(component,
  2115. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 0x80 * iir_idx),
  2116. ((band_idx * BAND_MAX + coeff_idx)
  2117. * sizeof(uint32_t)) & 0x7F);
  2118. value |= snd_soc_component_read32(component,
  2119. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx));
  2120. snd_soc_component_write(component,
  2121. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 0x80 * iir_idx),
  2122. ((band_idx * BAND_MAX + coeff_idx)
  2123. * sizeof(uint32_t) + 1) & 0x7F);
  2124. value |= (snd_soc_component_read32(component,
  2125. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL +
  2126. 0x80 * iir_idx)) << 8);
  2127. snd_soc_component_write(component,
  2128. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 0x80 * iir_idx),
  2129. ((band_idx * BAND_MAX + coeff_idx)
  2130. * sizeof(uint32_t) + 2) & 0x7F);
  2131. value |= (snd_soc_component_read32(component,
  2132. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL +
  2133. 0x80 * iir_idx)) << 16);
  2134. snd_soc_component_write(component,
  2135. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 0x80 * iir_idx),
  2136. ((band_idx * BAND_MAX + coeff_idx)
  2137. * sizeof(uint32_t) + 3) & 0x7F);
  2138. /* Mask bits top 2 bits since they are reserved */
  2139. value |= ((snd_soc_component_read32(component,
  2140. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL +
  2141. 16 * iir_idx)) & 0x3F) << 24);
  2142. return value;
  2143. }
  2144. static int rx_macro_iir_band_audio_mixer_get(struct snd_kcontrol *kcontrol,
  2145. struct snd_ctl_elem_value *ucontrol)
  2146. {
  2147. struct snd_soc_component *component =
  2148. snd_soc_kcontrol_component(kcontrol);
  2149. int iir_idx = ((struct soc_multi_mixer_control *)
  2150. kcontrol->private_value)->reg;
  2151. int band_idx = ((struct soc_multi_mixer_control *)
  2152. kcontrol->private_value)->shift;
  2153. ucontrol->value.integer.value[0] =
  2154. get_iir_band_coeff(component, iir_idx, band_idx, 0);
  2155. ucontrol->value.integer.value[1] =
  2156. get_iir_band_coeff(component, iir_idx, band_idx, 1);
  2157. ucontrol->value.integer.value[2] =
  2158. get_iir_band_coeff(component, iir_idx, band_idx, 2);
  2159. ucontrol->value.integer.value[3] =
  2160. get_iir_band_coeff(component, iir_idx, band_idx, 3);
  2161. ucontrol->value.integer.value[4] =
  2162. get_iir_band_coeff(component, iir_idx, band_idx, 4);
  2163. dev_dbg(component->dev, "%s: IIR #%d band #%d b0 = 0x%x\n"
  2164. "%s: IIR #%d band #%d b1 = 0x%x\n"
  2165. "%s: IIR #%d band #%d b2 = 0x%x\n"
  2166. "%s: IIR #%d band #%d a1 = 0x%x\n"
  2167. "%s: IIR #%d band #%d a2 = 0x%x\n",
  2168. __func__, iir_idx, band_idx,
  2169. (uint32_t)ucontrol->value.integer.value[0],
  2170. __func__, iir_idx, band_idx,
  2171. (uint32_t)ucontrol->value.integer.value[1],
  2172. __func__, iir_idx, band_idx,
  2173. (uint32_t)ucontrol->value.integer.value[2],
  2174. __func__, iir_idx, band_idx,
  2175. (uint32_t)ucontrol->value.integer.value[3],
  2176. __func__, iir_idx, band_idx,
  2177. (uint32_t)ucontrol->value.integer.value[4]);
  2178. return 0;
  2179. }
  2180. static void set_iir_band_coeff(struct snd_soc_component *component,
  2181. int iir_idx, int band_idx,
  2182. uint32_t value)
  2183. {
  2184. snd_soc_component_write(component,
  2185. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx),
  2186. (value & 0xFF));
  2187. snd_soc_component_write(component,
  2188. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx),
  2189. (value >> 8) & 0xFF);
  2190. snd_soc_component_write(component,
  2191. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx),
  2192. (value >> 16) & 0xFF);
  2193. /* Mask top 2 bits, 7-8 are reserved */
  2194. snd_soc_component_write(component,
  2195. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx),
  2196. (value >> 24) & 0x3F);
  2197. }
  2198. static int rx_macro_iir_band_audio_mixer_put(struct snd_kcontrol *kcontrol,
  2199. struct snd_ctl_elem_value *ucontrol)
  2200. {
  2201. struct snd_soc_component *component =
  2202. snd_soc_kcontrol_component(kcontrol);
  2203. int iir_idx = ((struct soc_multi_mixer_control *)
  2204. kcontrol->private_value)->reg;
  2205. int band_idx = ((struct soc_multi_mixer_control *)
  2206. kcontrol->private_value)->shift;
  2207. int coeff_idx, idx = 0;
  2208. struct device *rx_dev = NULL;
  2209. struct rx_macro_priv *rx_priv = NULL;
  2210. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  2211. return -EINVAL;
  2212. /*
  2213. * Mask top bit it is reserved
  2214. * Updates addr automatically for each B2 write
  2215. */
  2216. snd_soc_component_write(component,
  2217. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 16 * iir_idx),
  2218. (band_idx * BAND_MAX * sizeof(uint32_t)) & 0x7F);
  2219. /* Store the coefficients in sidetone coeff array */
  2220. for (coeff_idx = 0; coeff_idx < RX_MACRO_SIDETONE_IIR_COEFF_MAX;
  2221. coeff_idx++) {
  2222. uint32_t value = ucontrol->value.integer.value[coeff_idx];
  2223. set_iir_band_coeff(component, iir_idx, band_idx, value);
  2224. /* Four 8 bit values(one 32 bit) per coefficient */
  2225. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  2226. (value & 0xFF);
  2227. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  2228. (value >> 8) & 0xFF;
  2229. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  2230. (value >> 16) & 0xFF;
  2231. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  2232. (value >> 24) & 0xFF;
  2233. }
  2234. pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n"
  2235. "%s: IIR #%d band #%d b1 = 0x%x\n"
  2236. "%s: IIR #%d band #%d b2 = 0x%x\n"
  2237. "%s: IIR #%d band #%d a1 = 0x%x\n"
  2238. "%s: IIR #%d band #%d a2 = 0x%x\n",
  2239. __func__, iir_idx, band_idx,
  2240. get_iir_band_coeff(component, iir_idx, band_idx, 0),
  2241. __func__, iir_idx, band_idx,
  2242. get_iir_band_coeff(component, iir_idx, band_idx, 1),
  2243. __func__, iir_idx, band_idx,
  2244. get_iir_band_coeff(component, iir_idx, band_idx, 2),
  2245. __func__, iir_idx, band_idx,
  2246. get_iir_band_coeff(component, iir_idx, band_idx, 3),
  2247. __func__, iir_idx, band_idx,
  2248. get_iir_band_coeff(component, iir_idx, band_idx, 4));
  2249. return 0;
  2250. }
  2251. static int rx_macro_set_iir_gain(struct snd_soc_dapm_widget *w,
  2252. struct snd_kcontrol *kcontrol, int event)
  2253. {
  2254. struct snd_soc_component *component =
  2255. snd_soc_dapm_to_component(w->dapm);
  2256. dev_dbg(component->dev, "%s: event = %d\n", __func__, event);
  2257. switch (event) {
  2258. case SND_SOC_DAPM_POST_PMU: /* fall through */
  2259. case SND_SOC_DAPM_PRE_PMD:
  2260. if (strnstr(w->name, "IIR0", sizeof("IIR0"))) {
  2261. snd_soc_component_write(component,
  2262. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B1_CTL,
  2263. snd_soc_component_read32(component,
  2264. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B1_CTL));
  2265. snd_soc_component_write(component,
  2266. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B2_CTL,
  2267. snd_soc_component_read32(component,
  2268. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B2_CTL));
  2269. snd_soc_component_write(component,
  2270. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B3_CTL,
  2271. snd_soc_component_read32(component,
  2272. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B3_CTL));
  2273. snd_soc_component_write(component,
  2274. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B4_CTL,
  2275. snd_soc_component_read32(component,
  2276. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B4_CTL));
  2277. } else {
  2278. snd_soc_component_write(component,
  2279. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B1_CTL,
  2280. snd_soc_component_read32(component,
  2281. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B1_CTL));
  2282. snd_soc_component_write(component,
  2283. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B2_CTL,
  2284. snd_soc_component_read32(component,
  2285. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B2_CTL));
  2286. snd_soc_component_write(component,
  2287. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B3_CTL,
  2288. snd_soc_component_read32(component,
  2289. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B3_CTL));
  2290. snd_soc_component_write(component,
  2291. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B4_CTL,
  2292. snd_soc_component_read32(component,
  2293. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B4_CTL));
  2294. }
  2295. break;
  2296. }
  2297. return 0;
  2298. }
  2299. static const struct snd_kcontrol_new rx_macro_snd_controls[] = {
  2300. SOC_SINGLE_SX_TLV("RX_RX0 Digital Volume",
  2301. BOLERO_CDC_RX_RX0_RX_VOL_CTL,
  2302. 0, -84, 40, digital_gain),
  2303. SOC_SINGLE_SX_TLV("RX_RX1 Digital Volume",
  2304. BOLERO_CDC_RX_RX1_RX_VOL_CTL,
  2305. 0, -84, 40, digital_gain),
  2306. SOC_SINGLE_SX_TLV("RX_RX2 Digital Volume",
  2307. BOLERO_CDC_RX_RX2_RX_VOL_CTL,
  2308. 0, -84, 40, digital_gain),
  2309. SOC_SINGLE_SX_TLV("RX_RX0 Mix Digital Volume",
  2310. BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  2311. SOC_SINGLE_SX_TLV("RX_RX1 Mix Digital Volume",
  2312. BOLERO_CDC_RX_RX1_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  2313. SOC_SINGLE_SX_TLV("RX_RX2 Mix Digital Volume",
  2314. BOLERO_CDC_RX_RX2_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  2315. SOC_SINGLE_EXT("RX_COMP1 Switch", SND_SOC_NOPM, RX_MACRO_COMP1, 1, 0,
  2316. rx_macro_get_compander, rx_macro_set_compander),
  2317. SOC_SINGLE_EXT("RX_COMP2 Switch", SND_SOC_NOPM, RX_MACRO_COMP2, 1, 0,
  2318. rx_macro_get_compander, rx_macro_set_compander),
  2319. SOC_ENUM_EXT("HPH Idle Detect", hph_idle_detect_enum,
  2320. rx_macro_hph_idle_detect_get, rx_macro_hph_idle_detect_put),
  2321. SOC_ENUM_EXT("RX_EAR Mode", rx_macro_ear_mode_enum,
  2322. rx_macro_get_ear_mode, rx_macro_put_ear_mode),
  2323. SOC_ENUM_EXT("RX_HPH HD2 Mode", rx_macro_hph_hd2_mode_enum,
  2324. rx_macro_get_hph_hd2_mode, rx_macro_put_hph_hd2_mode),
  2325. SOC_ENUM_EXT("RX_HPH_PWR_MODE", rx_macro_hph_pwr_mode_enum,
  2326. rx_macro_get_hph_pwr_mode, rx_macro_put_hph_pwr_mode),
  2327. SOC_ENUM_EXT("RX_GSM mode Enable", rx_macro_vbat_bcl_gsm_mode_enum,
  2328. rx_macro_vbat_bcl_gsm_mode_func_get,
  2329. rx_macro_vbat_bcl_gsm_mode_func_put),
  2330. SOC_SINGLE_EXT("RX_Softclip Enable", SND_SOC_NOPM, 0, 1, 0,
  2331. rx_macro_soft_clip_enable_get,
  2332. rx_macro_soft_clip_enable_put),
  2333. SOC_SINGLE_SX_TLV("IIR0 INP0 Volume",
  2334. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B1_CTL, 0, -84, 40,
  2335. digital_gain),
  2336. SOC_SINGLE_SX_TLV("IIR0 INP1 Volume",
  2337. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B2_CTL, 0, -84, 40,
  2338. digital_gain),
  2339. SOC_SINGLE_SX_TLV("IIR0 INP2 Volume",
  2340. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B3_CTL, 0, -84, 40,
  2341. digital_gain),
  2342. SOC_SINGLE_SX_TLV("IIR0 INP3 Volume",
  2343. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B4_CTL, 0, -84, 40,
  2344. digital_gain),
  2345. SOC_SINGLE_SX_TLV("IIR1 INP0 Volume",
  2346. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B1_CTL, 0, -84, 40,
  2347. digital_gain),
  2348. SOC_SINGLE_SX_TLV("IIR1 INP1 Volume",
  2349. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B2_CTL, 0, -84, 40,
  2350. digital_gain),
  2351. SOC_SINGLE_SX_TLV("IIR1 INP2 Volume",
  2352. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B3_CTL, 0, -84, 40,
  2353. digital_gain),
  2354. SOC_SINGLE_SX_TLV("IIR1 INP3 Volume",
  2355. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B4_CTL, 0, -84, 40,
  2356. digital_gain),
  2357. SOC_SINGLE_EXT("IIR0 Enable Band1", IIR0, BAND1, 1, 0,
  2358. rx_macro_iir_enable_audio_mixer_get,
  2359. rx_macro_iir_enable_audio_mixer_put),
  2360. SOC_SINGLE_EXT("IIR0 Enable Band2", IIR0, BAND2, 1, 0,
  2361. rx_macro_iir_enable_audio_mixer_get,
  2362. rx_macro_iir_enable_audio_mixer_put),
  2363. SOC_SINGLE_EXT("IIR0 Enable Band3", IIR0, BAND3, 1, 0,
  2364. rx_macro_iir_enable_audio_mixer_get,
  2365. rx_macro_iir_enable_audio_mixer_put),
  2366. SOC_SINGLE_EXT("IIR0 Enable Band4", IIR0, BAND4, 1, 0,
  2367. rx_macro_iir_enable_audio_mixer_get,
  2368. rx_macro_iir_enable_audio_mixer_put),
  2369. SOC_SINGLE_EXT("IIR0 Enable Band5", IIR0, BAND5, 1, 0,
  2370. rx_macro_iir_enable_audio_mixer_get,
  2371. rx_macro_iir_enable_audio_mixer_put),
  2372. SOC_SINGLE_EXT("IIR1 Enable Band1", IIR1, BAND1, 1, 0,
  2373. rx_macro_iir_enable_audio_mixer_get,
  2374. rx_macro_iir_enable_audio_mixer_put),
  2375. SOC_SINGLE_EXT("IIR1 Enable Band2", IIR1, BAND2, 1, 0,
  2376. rx_macro_iir_enable_audio_mixer_get,
  2377. rx_macro_iir_enable_audio_mixer_put),
  2378. SOC_SINGLE_EXT("IIR1 Enable Band3", IIR1, BAND3, 1, 0,
  2379. rx_macro_iir_enable_audio_mixer_get,
  2380. rx_macro_iir_enable_audio_mixer_put),
  2381. SOC_SINGLE_EXT("IIR1 Enable Band4", IIR1, BAND4, 1, 0,
  2382. rx_macro_iir_enable_audio_mixer_get,
  2383. rx_macro_iir_enable_audio_mixer_put),
  2384. SOC_SINGLE_EXT("IIR1 Enable Band5", IIR1, BAND5, 1, 0,
  2385. rx_macro_iir_enable_audio_mixer_get,
  2386. rx_macro_iir_enable_audio_mixer_put),
  2387. SOC_SINGLE_MULTI_EXT("IIR0 Band1", IIR0, BAND1, 255, 0, 5,
  2388. rx_macro_iir_band_audio_mixer_get,
  2389. rx_macro_iir_band_audio_mixer_put),
  2390. SOC_SINGLE_MULTI_EXT("IIR0 Band2", IIR0, BAND2, 255, 0, 5,
  2391. rx_macro_iir_band_audio_mixer_get,
  2392. rx_macro_iir_band_audio_mixer_put),
  2393. SOC_SINGLE_MULTI_EXT("IIR0 Band3", IIR0, BAND3, 255, 0, 5,
  2394. rx_macro_iir_band_audio_mixer_get,
  2395. rx_macro_iir_band_audio_mixer_put),
  2396. SOC_SINGLE_MULTI_EXT("IIR0 Band4", IIR0, BAND4, 255, 0, 5,
  2397. rx_macro_iir_band_audio_mixer_get,
  2398. rx_macro_iir_band_audio_mixer_put),
  2399. SOC_SINGLE_MULTI_EXT("IIR0 Band5", IIR0, BAND5, 255, 0, 5,
  2400. rx_macro_iir_band_audio_mixer_get,
  2401. rx_macro_iir_band_audio_mixer_put),
  2402. SOC_SINGLE_MULTI_EXT("IIR1 Band1", IIR1, BAND1, 255, 0, 5,
  2403. rx_macro_iir_band_audio_mixer_get,
  2404. rx_macro_iir_band_audio_mixer_put),
  2405. SOC_SINGLE_MULTI_EXT("IIR1 Band2", IIR1, BAND2, 255, 0, 5,
  2406. rx_macro_iir_band_audio_mixer_get,
  2407. rx_macro_iir_band_audio_mixer_put),
  2408. SOC_SINGLE_MULTI_EXT("IIR1 Band3", IIR1, BAND3, 255, 0, 5,
  2409. rx_macro_iir_band_audio_mixer_get,
  2410. rx_macro_iir_band_audio_mixer_put),
  2411. SOC_SINGLE_MULTI_EXT("IIR1 Band4", IIR1, BAND4, 255, 0, 5,
  2412. rx_macro_iir_band_audio_mixer_get,
  2413. rx_macro_iir_band_audio_mixer_put),
  2414. SOC_SINGLE_MULTI_EXT("IIR1 Band5", IIR1, BAND5, 255, 0, 5,
  2415. rx_macro_iir_band_audio_mixer_get,
  2416. rx_macro_iir_band_audio_mixer_put),
  2417. };
  2418. static int rx_macro_enable_echo(struct snd_soc_dapm_widget *w,
  2419. struct snd_kcontrol *kcontrol,
  2420. int event)
  2421. {
  2422. struct snd_soc_component *component =
  2423. snd_soc_dapm_to_component(w->dapm);
  2424. struct device *rx_dev = NULL;
  2425. struct rx_macro_priv *rx_priv = NULL;
  2426. u16 val = 0, ec_hq_reg = 0;
  2427. int ec_tx = 0;
  2428. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  2429. return -EINVAL;
  2430. dev_dbg(rx_dev, "%s %d %s\n", __func__, event, w->name);
  2431. val = snd_soc_component_read32(component,
  2432. BOLERO_CDC_RX_INP_MUX_RX_MIX_CFG4);
  2433. if (!(strcmp(w->name, "RX MIX TX0 MUX")))
  2434. ec_tx = ((val & 0xf0) >> 0x4) - 1;
  2435. else if (!(strcmp(w->name, "RX MIX TX1 MUX")))
  2436. ec_tx = (val & 0x0f) - 1;
  2437. val = snd_soc_component_read32(component,
  2438. BOLERO_CDC_RX_INP_MUX_RX_MIX_CFG5);
  2439. if (!(strcmp(w->name, "RX MIX TX2 MUX")))
  2440. ec_tx = (val & 0x0f) - 1;
  2441. if (ec_tx < 0 || (ec_tx >= RX_MACRO_EC_MUX_MAX)) {
  2442. dev_err(rx_dev, "%s: EC mix control not set correctly\n",
  2443. __func__);
  2444. return -EINVAL;
  2445. }
  2446. ec_hq_reg = BOLERO_CDC_RX_EC_REF_HQ0_EC_REF_HQ_PATH_CTL +
  2447. 0x40 * ec_tx;
  2448. snd_soc_component_update_bits(component, ec_hq_reg, 0x01, 0x01);
  2449. ec_hq_reg = BOLERO_CDC_RX_EC_REF_HQ0_EC_REF_HQ_CFG0 +
  2450. 0x40 * ec_tx;
  2451. /* default set to 48k */
  2452. snd_soc_component_update_bits(component, ec_hq_reg, 0x1E, 0x08);
  2453. return 0;
  2454. }
  2455. static const struct snd_soc_dapm_widget rx_macro_dapm_widgets[] = {
  2456. SND_SOC_DAPM_AIF_IN("RX AIF1 PB", "RX_MACRO_AIF1 Playback", 0,
  2457. SND_SOC_NOPM, 0, 0),
  2458. SND_SOC_DAPM_AIF_IN("RX AIF2 PB", "RX_MACRO_AIF2 Playback", 0,
  2459. SND_SOC_NOPM, 0, 0),
  2460. SND_SOC_DAPM_AIF_IN("RX AIF3 PB", "RX_MACRO_AIF3 Playback", 0,
  2461. SND_SOC_NOPM, 0, 0),
  2462. SND_SOC_DAPM_AIF_IN("RX AIF4 PB", "RX_MACRO_AIF4 Playback", 0,
  2463. SND_SOC_NOPM, 0, 0),
  2464. SND_SOC_DAPM_AIF_OUT("RX AIF_ECHO", "RX_AIF_ECHO Capture", 0,
  2465. SND_SOC_NOPM, 0, 0),
  2466. RX_MACRO_DAPM_MUX("RX_MACRO RX0 MUX", RX_MACRO_RX0, rx_macro_rx0),
  2467. RX_MACRO_DAPM_MUX("RX_MACRO RX1 MUX", RX_MACRO_RX1, rx_macro_rx1),
  2468. RX_MACRO_DAPM_MUX("RX_MACRO RX2 MUX", RX_MACRO_RX2, rx_macro_rx2),
  2469. RX_MACRO_DAPM_MUX("RX_MACRO RX3 MUX", RX_MACRO_RX3, rx_macro_rx3),
  2470. RX_MACRO_DAPM_MUX("RX_MACRO RX4 MUX", RX_MACRO_RX4, rx_macro_rx4),
  2471. RX_MACRO_DAPM_MUX("RX_MACRO RX5 MUX", RX_MACRO_RX5, rx_macro_rx5),
  2472. SND_SOC_DAPM_MIXER("RX_RX0", SND_SOC_NOPM, 0, 0, NULL, 0),
  2473. SND_SOC_DAPM_MIXER("RX_RX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2474. SND_SOC_DAPM_MIXER("RX_RX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  2475. SND_SOC_DAPM_MIXER("RX_RX3", SND_SOC_NOPM, 0, 0, NULL, 0),
  2476. SND_SOC_DAPM_MIXER("RX_RX4", SND_SOC_NOPM, 0, 0, NULL, 0),
  2477. SND_SOC_DAPM_MIXER("RX_RX5", SND_SOC_NOPM, 0, 0, NULL, 0),
  2478. RX_MACRO_DAPM_MUX("IIR0 INP0 MUX", 0, iir0_inp0),
  2479. RX_MACRO_DAPM_MUX("IIR0 INP1 MUX", 0, iir0_inp1),
  2480. RX_MACRO_DAPM_MUX("IIR0 INP2 MUX", 0, iir0_inp2),
  2481. RX_MACRO_DAPM_MUX("IIR0 INP3 MUX", 0, iir0_inp3),
  2482. RX_MACRO_DAPM_MUX("IIR1 INP0 MUX", 0, iir1_inp0),
  2483. RX_MACRO_DAPM_MUX("IIR1 INP1 MUX", 0, iir1_inp1),
  2484. RX_MACRO_DAPM_MUX("IIR1 INP2 MUX", 0, iir1_inp2),
  2485. RX_MACRO_DAPM_MUX("IIR1 INP3 MUX", 0, iir1_inp3),
  2486. SND_SOC_DAPM_MUX_E("RX MIX TX0 MUX", SND_SOC_NOPM,
  2487. RX_MACRO_EC0_MUX, 0,
  2488. &rx_mix_tx0_mux, rx_macro_enable_echo,
  2489. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2490. SND_SOC_DAPM_MUX_E("RX MIX TX1 MUX", SND_SOC_NOPM,
  2491. RX_MACRO_EC1_MUX, 0,
  2492. &rx_mix_tx1_mux, rx_macro_enable_echo,
  2493. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2494. SND_SOC_DAPM_MUX_E("RX MIX TX2 MUX", SND_SOC_NOPM,
  2495. RX_MACRO_EC2_MUX, 0,
  2496. &rx_mix_tx2_mux, rx_macro_enable_echo,
  2497. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2498. SND_SOC_DAPM_MIXER_E("IIR0", BOLERO_CDC_RX_SIDETONE_IIR0_IIR_PATH_CTL,
  2499. 4, 0, NULL, 0, rx_macro_set_iir_gain,
  2500. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  2501. SND_SOC_DAPM_MIXER_E("IIR1", BOLERO_CDC_RX_SIDETONE_IIR1_IIR_PATH_CTL,
  2502. 4, 0, NULL, 0, rx_macro_set_iir_gain,
  2503. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  2504. SND_SOC_DAPM_MIXER("SRC0", BOLERO_CDC_RX_SIDETONE_SRC0_ST_SRC_PATH_CTL,
  2505. 4, 0, NULL, 0),
  2506. SND_SOC_DAPM_MIXER("SRC1", BOLERO_CDC_RX_SIDETONE_SRC1_ST_SRC_PATH_CTL,
  2507. 4, 0, NULL, 0),
  2508. RX_MACRO_DAPM_MUX("RX INT0 DEM MUX", 0, rx_int0_dem_inp),
  2509. RX_MACRO_DAPM_MUX("RX INT1 DEM MUX", 0, rx_int1_dem_inp),
  2510. SND_SOC_DAPM_MUX_E("RX INT0_2 MUX", SND_SOC_NOPM, INTERP_HPHL, 0,
  2511. &rx_int0_2_mux, rx_macro_enable_mix_path,
  2512. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2513. SND_SOC_DAPM_POST_PMD),
  2514. SND_SOC_DAPM_MUX_E("RX INT1_2 MUX", SND_SOC_NOPM, INTERP_HPHR, 0,
  2515. &rx_int1_2_mux, rx_macro_enable_mix_path,
  2516. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2517. SND_SOC_DAPM_POST_PMD),
  2518. SND_SOC_DAPM_MUX_E("RX INT2_2 MUX", SND_SOC_NOPM, INTERP_AUX, 0,
  2519. &rx_int2_2_mux, rx_macro_enable_mix_path,
  2520. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2521. SND_SOC_DAPM_POST_PMD),
  2522. RX_MACRO_DAPM_MUX("RX INT0_1 MIX1 INP0", 0, rx_int0_1_mix_inp0),
  2523. RX_MACRO_DAPM_MUX("RX INT0_1 MIX1 INP1", 0, rx_int0_1_mix_inp1),
  2524. RX_MACRO_DAPM_MUX("RX INT0_1 MIX1 INP2", 0, rx_int0_1_mix_inp2),
  2525. RX_MACRO_DAPM_MUX("RX INT1_1 MIX1 INP0", 0, rx_int1_1_mix_inp0),
  2526. RX_MACRO_DAPM_MUX("RX INT1_1 MIX1 INP1", 0, rx_int1_1_mix_inp1),
  2527. RX_MACRO_DAPM_MUX("RX INT1_1 MIX1 INP2", 0, rx_int1_1_mix_inp2),
  2528. RX_MACRO_DAPM_MUX("RX INT2_1 MIX1 INP0", 0, rx_int2_1_mix_inp0),
  2529. RX_MACRO_DAPM_MUX("RX INT2_1 MIX1 INP1", 0, rx_int2_1_mix_inp1),
  2530. RX_MACRO_DAPM_MUX("RX INT2_1 MIX1 INP2", 0, rx_int2_1_mix_inp2),
  2531. SND_SOC_DAPM_MUX_E("RX INT0_1 INTERP", SND_SOC_NOPM, INTERP_HPHL, 0,
  2532. &rx_int0_1_interp_mux, rx_macro_enable_main_path,
  2533. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2534. SND_SOC_DAPM_POST_PMD),
  2535. SND_SOC_DAPM_MUX_E("RX INT1_1 INTERP", SND_SOC_NOPM, INTERP_HPHR, 0,
  2536. &rx_int1_1_interp_mux, rx_macro_enable_main_path,
  2537. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2538. SND_SOC_DAPM_POST_PMD),
  2539. SND_SOC_DAPM_MUX_E("RX INT2_1 INTERP", SND_SOC_NOPM, INTERP_AUX, 0,
  2540. &rx_int2_1_interp_mux, rx_macro_enable_main_path,
  2541. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2542. SND_SOC_DAPM_POST_PMD),
  2543. RX_MACRO_DAPM_MUX("RX INT0_2 INTERP", 0, rx_int0_2_interp),
  2544. RX_MACRO_DAPM_MUX("RX INT1_2 INTERP", 0, rx_int1_2_interp),
  2545. RX_MACRO_DAPM_MUX("RX INT2_2 INTERP", 0, rx_int2_2_interp),
  2546. SND_SOC_DAPM_MIXER("RX INT0_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2547. SND_SOC_DAPM_MIXER("RX INT0 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  2548. SND_SOC_DAPM_MIXER("RX INT1_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2549. SND_SOC_DAPM_MIXER("RX INT1 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  2550. SND_SOC_DAPM_MIXER("RX INT2_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2551. SND_SOC_DAPM_MIXER("RX INT2 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  2552. SND_SOC_DAPM_MUX_E("RX INT0 MIX2 INP", SND_SOC_NOPM, INTERP_HPHL,
  2553. 0, &rx_int0_mix2_inp_mux, rx_macro_enable_rx_path_clk,
  2554. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2555. SND_SOC_DAPM_MUX_E("RX INT1 MIX2 INP", SND_SOC_NOPM, INTERP_HPHR,
  2556. 0, &rx_int1_mix2_inp_mux, rx_macro_enable_rx_path_clk,
  2557. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2558. SND_SOC_DAPM_MUX_E("RX INT2 MIX2 INP", SND_SOC_NOPM, INTERP_AUX,
  2559. 0, &rx_int2_mix2_inp_mux, rx_macro_enable_rx_path_clk,
  2560. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2561. SND_SOC_DAPM_MIXER_E("RX INT2_1 VBAT", SND_SOC_NOPM,
  2562. 0, 0, rx_int2_1_vbat_mix_switch,
  2563. ARRAY_SIZE(rx_int2_1_vbat_mix_switch),
  2564. rx_macro_enable_vbat,
  2565. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2566. SND_SOC_DAPM_MIXER("RX INT0 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  2567. SND_SOC_DAPM_MIXER("RX INT1 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  2568. SND_SOC_DAPM_MIXER("RX INT2 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  2569. SND_SOC_DAPM_OUTPUT("HPHL_OUT"),
  2570. SND_SOC_DAPM_OUTPUT("HPHR_OUT"),
  2571. SND_SOC_DAPM_OUTPUT("AUX_OUT"),
  2572. SND_SOC_DAPM_INPUT("RX_TX DEC0_INP"),
  2573. SND_SOC_DAPM_INPUT("RX_TX DEC1_INP"),
  2574. SND_SOC_DAPM_INPUT("RX_TX DEC2_INP"),
  2575. SND_SOC_DAPM_INPUT("RX_TX DEC3_INP"),
  2576. SND_SOC_DAPM_SUPPLY_S("RX_MCLK", 0, SND_SOC_NOPM, 0, 0,
  2577. rx_macro_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2578. };
  2579. static const struct snd_soc_dapm_route rx_audio_map[] = {
  2580. {"RX AIF1 PB", NULL, "RX_MCLK"},
  2581. {"RX AIF2 PB", NULL, "RX_MCLK"},
  2582. {"RX AIF3 PB", NULL, "RX_MCLK"},
  2583. {"RX AIF4 PB", NULL, "RX_MCLK"},
  2584. {"RX_MACRO RX0 MUX", "AIF1_PB", "RX AIF1 PB"},
  2585. {"RX_MACRO RX1 MUX", "AIF1_PB", "RX AIF1 PB"},
  2586. {"RX_MACRO RX2 MUX", "AIF1_PB", "RX AIF1 PB"},
  2587. {"RX_MACRO RX3 MUX", "AIF1_PB", "RX AIF1 PB"},
  2588. {"RX_MACRO RX4 MUX", "AIF1_PB", "RX AIF1 PB"},
  2589. {"RX_MACRO RX5 MUX", "AIF1_PB", "RX AIF1 PB"},
  2590. {"RX_MACRO RX0 MUX", "AIF2_PB", "RX AIF2 PB"},
  2591. {"RX_MACRO RX1 MUX", "AIF2_PB", "RX AIF2 PB"},
  2592. {"RX_MACRO RX2 MUX", "AIF2_PB", "RX AIF2 PB"},
  2593. {"RX_MACRO RX3 MUX", "AIF2_PB", "RX AIF2 PB"},
  2594. {"RX_MACRO RX4 MUX", "AIF2_PB", "RX AIF2 PB"},
  2595. {"RX_MACRO RX5 MUX", "AIF2_PB", "RX AIF2 PB"},
  2596. {"RX_MACRO RX0 MUX", "AIF3_PB", "RX AIF3 PB"},
  2597. {"RX_MACRO RX1 MUX", "AIF3_PB", "RX AIF3 PB"},
  2598. {"RX_MACRO RX2 MUX", "AIF3_PB", "RX AIF3 PB"},
  2599. {"RX_MACRO RX3 MUX", "AIF3_PB", "RX AIF3 PB"},
  2600. {"RX_MACRO RX4 MUX", "AIF3_PB", "RX AIF3 PB"},
  2601. {"RX_MACRO RX5 MUX", "AIF3_PB", "RX AIF3 PB"},
  2602. {"RX_MACRO RX0 MUX", "AIF4_PB", "RX AIF4 PB"},
  2603. {"RX_MACRO RX1 MUX", "AIF4_PB", "RX AIF4 PB"},
  2604. {"RX_MACRO RX2 MUX", "AIF4_PB", "RX AIF4 PB"},
  2605. {"RX_MACRO RX3 MUX", "AIF4_PB", "RX AIF4 PB"},
  2606. {"RX_MACRO RX4 MUX", "AIF4_PB", "RX AIF4 PB"},
  2607. {"RX_MACRO RX5 MUX", "AIF4_PB", "RX AIF4 PB"},
  2608. {"RX_RX0", NULL, "RX_MACRO RX0 MUX"},
  2609. {"RX_RX1", NULL, "RX_MACRO RX1 MUX"},
  2610. {"RX_RX2", NULL, "RX_MACRO RX2 MUX"},
  2611. {"RX_RX3", NULL, "RX_MACRO RX3 MUX"},
  2612. {"RX_RX4", NULL, "RX_MACRO RX4 MUX"},
  2613. {"RX_RX5", NULL, "RX_MACRO RX5 MUX"},
  2614. {"RX INT0_1 MIX1 INP0", "RX0", "RX_RX0"},
  2615. {"RX INT0_1 MIX1 INP0", "RX1", "RX_RX1"},
  2616. {"RX INT0_1 MIX1 INP0", "RX2", "RX_RX2"},
  2617. {"RX INT0_1 MIX1 INP0", "RX3", "RX_RX3"},
  2618. {"RX INT0_1 MIX1 INP0", "RX4", "RX_RX4"},
  2619. {"RX INT0_1 MIX1 INP0", "RX5", "RX_RX5"},
  2620. {"RX INT0_1 MIX1 INP0", "IIR0", "IIR0"},
  2621. {"RX INT0_1 MIX1 INP0", "IIR1", "IIR1"},
  2622. {"RX INT0_1 MIX1 INP1", "RX0", "RX_RX0"},
  2623. {"RX INT0_1 MIX1 INP1", "RX1", "RX_RX1"},
  2624. {"RX INT0_1 MIX1 INP1", "RX2", "RX_RX2"},
  2625. {"RX INT0_1 MIX1 INP1", "RX3", "RX_RX3"},
  2626. {"RX INT0_1 MIX1 INP1", "RX4", "RX_RX4"},
  2627. {"RX INT0_1 MIX1 INP1", "RX5", "RX_RX5"},
  2628. {"RX INT0_1 MIX1 INP1", "IIR0", "IIR0"},
  2629. {"RX INT0_1 MIX1 INP1", "IIR1", "IIR1"},
  2630. {"RX INT0_1 MIX1 INP2", "RX0", "RX_RX0"},
  2631. {"RX INT0_1 MIX1 INP2", "RX1", "RX_RX1"},
  2632. {"RX INT0_1 MIX1 INP2", "RX2", "RX_RX2"},
  2633. {"RX INT0_1 MIX1 INP2", "RX3", "RX_RX3"},
  2634. {"RX INT0_1 MIX1 INP2", "RX4", "RX_RX4"},
  2635. {"RX INT0_1 MIX1 INP2", "RX5", "RX_RX5"},
  2636. {"RX INT0_1 MIX1 INP2", "IIR0", "IIR0"},
  2637. {"RX INT0_1 MIX1 INP2", "IIR1", "IIR1"},
  2638. {"RX INT1_1 MIX1 INP0", "RX0", "RX_RX0"},
  2639. {"RX INT1_1 MIX1 INP0", "RX1", "RX_RX1"},
  2640. {"RX INT1_1 MIX1 INP0", "RX2", "RX_RX2"},
  2641. {"RX INT1_1 MIX1 INP0", "RX3", "RX_RX3"},
  2642. {"RX INT1_1 MIX1 INP0", "RX4", "RX_RX4"},
  2643. {"RX INT1_1 MIX1 INP0", "RX5", "RX_RX5"},
  2644. {"RX INT1_1 MIX1 INP0", "IIR0", "IIR0"},
  2645. {"RX INT1_1 MIX1 INP0", "IIR1", "IIR1"},
  2646. {"RX INT1_1 MIX1 INP1", "RX0", "RX_RX0"},
  2647. {"RX INT1_1 MIX1 INP1", "RX1", "RX_RX1"},
  2648. {"RX INT1_1 MIX1 INP1", "RX2", "RX_RX2"},
  2649. {"RX INT1_1 MIX1 INP1", "RX3", "RX_RX3"},
  2650. {"RX INT1_1 MIX1 INP1", "RX4", "RX_RX4"},
  2651. {"RX INT1_1 MIX1 INP1", "RX5", "RX_RX5"},
  2652. {"RX INT1_1 MIX1 INP1", "IIR0", "IIR0"},
  2653. {"RX INT1_1 MIX1 INP1", "IIR1", "IIR1"},
  2654. {"RX INT1_1 MIX1 INP2", "RX0", "RX_RX0"},
  2655. {"RX INT1_1 MIX1 INP2", "RX1", "RX_RX1"},
  2656. {"RX INT1_1 MIX1 INP2", "RX2", "RX_RX2"},
  2657. {"RX INT1_1 MIX1 INP2", "RX3", "RX_RX3"},
  2658. {"RX INT1_1 MIX1 INP2", "RX4", "RX_RX4"},
  2659. {"RX INT1_1 MIX1 INP2", "RX5", "RX_RX5"},
  2660. {"RX INT1_1 MIX1 INP2", "IIR0", "IIR0"},
  2661. {"RX INT1_1 MIX1 INP2", "IIR1", "IIR1"},
  2662. {"RX INT2_1 MIX1 INP0", "RX0", "RX_RX0"},
  2663. {"RX INT2_1 MIX1 INP0", "RX1", "RX_RX1"},
  2664. {"RX INT2_1 MIX1 INP0", "RX2", "RX_RX2"},
  2665. {"RX INT2_1 MIX1 INP0", "RX3", "RX_RX3"},
  2666. {"RX INT2_1 MIX1 INP0", "RX4", "RX_RX4"},
  2667. {"RX INT2_1 MIX1 INP0", "RX5", "RX_RX5"},
  2668. {"RX INT2_1 MIX1 INP0", "IIR0", "IIR0"},
  2669. {"RX INT2_1 MIX1 INP0", "IIR1", "IIR1"},
  2670. {"RX INT2_1 MIX1 INP1", "RX0", "RX_RX0"},
  2671. {"RX INT2_1 MIX1 INP1", "RX1", "RX_RX1"},
  2672. {"RX INT2_1 MIX1 INP1", "RX2", "RX_RX2"},
  2673. {"RX INT2_1 MIX1 INP1", "RX3", "RX_RX3"},
  2674. {"RX INT2_1 MIX1 INP1", "RX4", "RX_RX4"},
  2675. {"RX INT2_1 MIX1 INP1", "RX5", "RX_RX5"},
  2676. {"RX INT2_1 MIX1 INP1", "IIR0", "IIR0"},
  2677. {"RX INT2_1 MIX1 INP1", "IIR1", "IIR1"},
  2678. {"RX INT2_1 MIX1 INP2", "RX0", "RX_RX0"},
  2679. {"RX INT2_1 MIX1 INP2", "RX1", "RX_RX1"},
  2680. {"RX INT2_1 MIX1 INP2", "RX2", "RX_RX2"},
  2681. {"RX INT2_1 MIX1 INP2", "RX3", "RX_RX3"},
  2682. {"RX INT2_1 MIX1 INP2", "RX4", "RX_RX4"},
  2683. {"RX INT2_1 MIX1 INP2", "RX5", "RX_RX5"},
  2684. {"RX INT2_1 MIX1 INP2", "IIR0", "IIR0"},
  2685. {"RX INT2_1 MIX1 INP2", "IIR1", "IIR1"},
  2686. {"RX INT0_1 MIX1", NULL, "RX INT0_1 MIX1 INP0"},
  2687. {"RX INT0_1 MIX1", NULL, "RX INT0_1 MIX1 INP1"},
  2688. {"RX INT0_1 MIX1", NULL, "RX INT0_1 MIX1 INP2"},
  2689. {"RX INT1_1 MIX1", NULL, "RX INT1_1 MIX1 INP0"},
  2690. {"RX INT1_1 MIX1", NULL, "RX INT1_1 MIX1 INP1"},
  2691. {"RX INT1_1 MIX1", NULL, "RX INT1_1 MIX1 INP2"},
  2692. {"RX INT2_1 MIX1", NULL, "RX INT2_1 MIX1 INP0"},
  2693. {"RX INT2_1 MIX1", NULL, "RX INT2_1 MIX1 INP1"},
  2694. {"RX INT2_1 MIX1", NULL, "RX INT2_1 MIX1 INP2"},
  2695. {"RX MIX TX0 MUX", "RX_MIX0", "RX INT0 SEC MIX"},
  2696. {"RX MIX TX0 MUX", "RX_MIX1", "RX INT1 SEC MIX"},
  2697. {"RX MIX TX0 MUX", "RX_MIX2", "RX INT2 SEC MIX"},
  2698. {"RX MIX TX1 MUX", "RX_MIX0", "RX INT0 SEC MIX"},
  2699. {"RX MIX TX1 MUX", "RX_MIX1", "RX INT1 SEC MIX"},
  2700. {"RX MIX TX1 MUX", "RX_MIX2", "RX INT2 SEC MIX"},
  2701. {"RX MIX TX2 MUX", "RX_MIX0", "RX INT0 SEC MIX"},
  2702. {"RX MIX TX2 MUX", "RX_MIX1", "RX INT1 SEC MIX"},
  2703. {"RX MIX TX2 MUX", "RX_MIX2", "RX INT2 SEC MIX"},
  2704. {"RX AIF_ECHO", NULL, "RX MIX TX0 MUX"},
  2705. {"RX AIF_ECHO", NULL, "RX MIX TX1 MUX"},
  2706. {"RX AIF_ECHO", NULL, "RX MIX TX2 MUX"},
  2707. {"RX AIF_ECHO", NULL, "RX_MCLK"},
  2708. /* Mixing path INT0 */
  2709. {"RX INT0_2 MUX", "RX0", "RX_RX0"},
  2710. {"RX INT0_2 MUX", "RX1", "RX_RX1"},
  2711. {"RX INT0_2 MUX", "RX2", "RX_RX2"},
  2712. {"RX INT0_2 MUX", "RX3", "RX_RX3"},
  2713. {"RX INT0_2 MUX", "RX4", "RX_RX4"},
  2714. {"RX INT0_2 MUX", "RX5", "RX_RX5"},
  2715. {"RX INT0_2 INTERP", NULL, "RX INT0_2 MUX"},
  2716. {"RX INT0 SEC MIX", NULL, "RX INT0_2 INTERP"},
  2717. /* Mixing path INT1 */
  2718. {"RX INT1_2 MUX", "RX0", "RX_RX0"},
  2719. {"RX INT1_2 MUX", "RX1", "RX_RX1"},
  2720. {"RX INT1_2 MUX", "RX2", "RX_RX2"},
  2721. {"RX INT1_2 MUX", "RX3", "RX_RX3"},
  2722. {"RX INT1_2 MUX", "RX4", "RX_RX4"},
  2723. {"RX INT1_2 MUX", "RX5", "RX_RX5"},
  2724. {"RX INT1_2 INTERP", NULL, "RX INT1_2 MUX"},
  2725. {"RX INT1 SEC MIX", NULL, "RX INT1_2 INTERP"},
  2726. /* Mixing path INT2 */
  2727. {"RX INT2_2 MUX", "RX0", "RX_RX0"},
  2728. {"RX INT2_2 MUX", "RX1", "RX_RX1"},
  2729. {"RX INT2_2 MUX", "RX2", "RX_RX2"},
  2730. {"RX INT2_2 MUX", "RX3", "RX_RX3"},
  2731. {"RX INT2_2 MUX", "RX4", "RX_RX4"},
  2732. {"RX INT2_2 MUX", "RX5", "RX_RX5"},
  2733. {"RX INT2_2 INTERP", NULL, "RX INT2_2 MUX"},
  2734. {"RX INT2 SEC MIX", NULL, "RX INT2_2 INTERP"},
  2735. {"RX INT0_1 INTERP", NULL, "RX INT0_1 MIX1"},
  2736. {"RX INT0 SEC MIX", NULL, "RX INT0_1 INTERP"},
  2737. {"RX INT0 MIX2", NULL, "RX INT0 SEC MIX"},
  2738. {"RX INT0 MIX2", NULL, "RX INT0 MIX2 INP"},
  2739. {"RX INT0 DEM MUX", "CLSH_DSM_OUT", "RX INT0 MIX2"},
  2740. {"HPHL_OUT", NULL, "RX INT0 DEM MUX"},
  2741. {"HPHL_OUT", NULL, "RX_MCLK"},
  2742. {"RX INT1_1 INTERP", NULL, "RX INT1_1 MIX1"},
  2743. {"RX INT1 SEC MIX", NULL, "RX INT1_1 INTERP"},
  2744. {"RX INT1 MIX2", NULL, "RX INT1 SEC MIX"},
  2745. {"RX INT1 MIX2", NULL, "RX INT1 MIX2 INP"},
  2746. {"RX INT1 DEM MUX", "CLSH_DSM_OUT", "RX INT1 MIX2"},
  2747. {"HPHR_OUT", NULL, "RX INT1 DEM MUX"},
  2748. {"HPHR_OUT", NULL, "RX_MCLK"},
  2749. {"RX INT2_1 INTERP", NULL, "RX INT2_1 MIX1"},
  2750. {"RX INT2_1 VBAT", "RX AUX VBAT Enable", "RX INT2_1 INTERP"},
  2751. {"RX INT2 SEC MIX", NULL, "RX INT2_1 VBAT"},
  2752. {"RX INT2 SEC MIX", NULL, "RX INT2_1 INTERP"},
  2753. {"RX INT2 MIX2", NULL, "RX INT2 SEC MIX"},
  2754. {"RX INT2 MIX2", NULL, "RX INT2 MIX2 INP"},
  2755. {"AUX_OUT", NULL, "RX INT2 MIX2"},
  2756. {"AUX_OUT", NULL, "RX_MCLK"},
  2757. {"IIR0", NULL, "RX_MCLK"},
  2758. {"IIR0", NULL, "IIR0 INP0 MUX"},
  2759. {"IIR0 INP0 MUX", "DEC0", "RX_TX DEC0_INP"},
  2760. {"IIR0 INP0 MUX", "DEC1", "RX_TX DEC1_INP"},
  2761. {"IIR0 INP0 MUX", "DEC2", "RX_TX DEC2_INP"},
  2762. {"IIR0 INP0 MUX", "DEC3", "RX_TX DEC3_INP"},
  2763. {"IIR0 INP0 MUX", "RX0", "RX_RX0"},
  2764. {"IIR0 INP0 MUX", "RX1", "RX_RX1"},
  2765. {"IIR0 INP0 MUX", "RX2", "RX_RX2"},
  2766. {"IIR0 INP0 MUX", "RX3", "RX_RX3"},
  2767. {"IIR0 INP0 MUX", "RX4", "RX_RX4"},
  2768. {"IIR0 INP0 MUX", "RX5", "RX_RX5"},
  2769. {"IIR0", NULL, "IIR0 INP1 MUX"},
  2770. {"IIR0 INP1 MUX", "DEC0", "RX_TX DEC0_INP"},
  2771. {"IIR0 INP1 MUX", "DEC1", "RX_TX DEC1_INP"},
  2772. {"IIR0 INP1 MUX", "DEC2", "RX_TX DEC2_INP"},
  2773. {"IIR0 INP1 MUX", "DEC3", "RX_TX DEC3_INP"},
  2774. {"IIR0 INP1 MUX", "RX0", "RX_RX0"},
  2775. {"IIR0 INP1 MUX", "RX1", "RX_RX1"},
  2776. {"IIR0 INP1 MUX", "RX2", "RX_RX2"},
  2777. {"IIR0 INP1 MUX", "RX3", "RX_RX3"},
  2778. {"IIR0 INP1 MUX", "RX4", "RX_RX4"},
  2779. {"IIR0 INP1 MUX", "RX5", "RX_RX5"},
  2780. {"IIR0", NULL, "IIR0 INP2 MUX"},
  2781. {"IIR0 INP2 MUX", "DEC0", "RX_TX DEC0_INP"},
  2782. {"IIR0 INP2 MUX", "DEC1", "RX_TX DEC1_INP"},
  2783. {"IIR0 INP2 MUX", "DEC2", "RX_TX DEC2_INP"},
  2784. {"IIR0 INP2 MUX", "DEC3", "RX_TX DEC3_INP"},
  2785. {"IIR0 INP2 MUX", "RX0", "RX_RX0"},
  2786. {"IIR0 INP2 MUX", "RX1", "RX_RX1"},
  2787. {"IIR0 INP2 MUX", "RX2", "RX_RX2"},
  2788. {"IIR0 INP2 MUX", "RX3", "RX_RX3"},
  2789. {"IIR0 INP2 MUX", "RX4", "RX_RX4"},
  2790. {"IIR0 INP2 MUX", "RX5", "RX_RX5"},
  2791. {"IIR0", NULL, "IIR0 INP3 MUX"},
  2792. {"IIR0 INP3 MUX", "DEC0", "RX_TX DEC0_INP"},
  2793. {"IIR0 INP3 MUX", "DEC1", "RX_TX DEC1_INP"},
  2794. {"IIR0 INP3 MUX", "DEC2", "RX_TX DEC2_INP"},
  2795. {"IIR0 INP3 MUX", "DEC3", "RX_TX DEC3_INP"},
  2796. {"IIR0 INP3 MUX", "RX0", "RX_RX0"},
  2797. {"IIR0 INP3 MUX", "RX1", "RX_RX1"},
  2798. {"IIR0 INP3 MUX", "RX2", "RX_RX2"},
  2799. {"IIR0 INP3 MUX", "RX3", "RX_RX3"},
  2800. {"IIR0 INP3 MUX", "RX4", "RX_RX4"},
  2801. {"IIR0 INP3 MUX", "RX5", "RX_RX5"},
  2802. {"IIR1", NULL, "RX_MCLK"},
  2803. {"IIR1", NULL, "IIR1 INP0 MUX"},
  2804. {"IIR1 INP0 MUX", "DEC0", "RX_TX DEC0_INP"},
  2805. {"IIR1 INP0 MUX", "DEC1", "RX_TX DEC1_INP"},
  2806. {"IIR1 INP0 MUX", "DEC2", "RX_TX DEC2_INP"},
  2807. {"IIR1 INP0 MUX", "DEC3", "RX_TX DEC3_INP"},
  2808. {"IIR1 INP0 MUX", "RX0", "RX_RX0"},
  2809. {"IIR1 INP0 MUX", "RX1", "RX_RX1"},
  2810. {"IIR1 INP0 MUX", "RX2", "RX_RX2"},
  2811. {"IIR1 INP0 MUX", "RX3", "RX_RX3"},
  2812. {"IIR1 INP0 MUX", "RX4", "RX_RX4"},
  2813. {"IIR1 INP0 MUX", "RX5", "RX_RX5"},
  2814. {"IIR1", NULL, "IIR1 INP1 MUX"},
  2815. {"IIR1 INP1 MUX", "DEC0", "RX_TX DEC0_INP"},
  2816. {"IIR1 INP1 MUX", "DEC1", "RX_TX DEC1_INP"},
  2817. {"IIR1 INP1 MUX", "DEC2", "RX_TX DEC2_INP"},
  2818. {"IIR1 INP1 MUX", "DEC3", "RX_TX DEC3_INP"},
  2819. {"IIR1 INP1 MUX", "RX0", "RX_RX0"},
  2820. {"IIR1 INP1 MUX", "RX1", "RX_RX1"},
  2821. {"IIR1 INP1 MUX", "RX2", "RX_RX2"},
  2822. {"IIR1 INP1 MUX", "RX3", "RX_RX3"},
  2823. {"IIR1 INP1 MUX", "RX4", "RX_RX4"},
  2824. {"IIR1 INP1 MUX", "RX5", "RX_RX5"},
  2825. {"IIR1", NULL, "IIR1 INP2 MUX"},
  2826. {"IIR1 INP2 MUX", "DEC0", "RX_TX DEC0_INP"},
  2827. {"IIR1 INP2 MUX", "DEC1", "RX_TX DEC1_INP"},
  2828. {"IIR1 INP2 MUX", "DEC2", "RX_TX DEC2_INP"},
  2829. {"IIR1 INP2 MUX", "DEC3", "RX_TX DEC3_INP"},
  2830. {"IIR1 INP2 MUX", "RX0", "RX_RX0"},
  2831. {"IIR1 INP2 MUX", "RX1", "RX_RX1"},
  2832. {"IIR1 INP2 MUX", "RX2", "RX_RX2"},
  2833. {"IIR1 INP2 MUX", "RX3", "RX_RX3"},
  2834. {"IIR1 INP2 MUX", "RX4", "RX_RX4"},
  2835. {"IIR1 INP2 MUX", "RX5", "RX_RX5"},
  2836. {"IIR1", NULL, "IIR1 INP3 MUX"},
  2837. {"IIR1 INP3 MUX", "DEC0", "RX_TX DEC0_INP"},
  2838. {"IIR1 INP3 MUX", "DEC1", "RX_TX DEC1_INP"},
  2839. {"IIR1 INP3 MUX", "DEC2", "RX_TX DEC2_INP"},
  2840. {"IIR1 INP3 MUX", "DEC3", "RX_TX DEC3_INP"},
  2841. {"IIR1 INP3 MUX", "RX0", "RX_RX0"},
  2842. {"IIR1 INP3 MUX", "RX1", "RX_RX1"},
  2843. {"IIR1 INP3 MUX", "RX2", "RX_RX2"},
  2844. {"IIR1 INP3 MUX", "RX3", "RX_RX3"},
  2845. {"IIR1 INP3 MUX", "RX4", "RX_RX4"},
  2846. {"IIR1 INP3 MUX", "RX5", "RX_RX5"},
  2847. {"SRC0", NULL, "IIR0"},
  2848. {"SRC1", NULL, "IIR1"},
  2849. {"RX INT0 MIX2 INP", "SRC0", "SRC0"},
  2850. {"RX INT0 MIX2 INP", "SRC1", "SRC1"},
  2851. {"RX INT1 MIX2 INP", "SRC0", "SRC0"},
  2852. {"RX INT1 MIX2 INP", "SRC1", "SRC1"},
  2853. {"RX INT2 MIX2 INP", "SRC0", "SRC0"},
  2854. {"RX INT2 MIX2 INP", "SRC1", "SRC1"},
  2855. };
  2856. static int rx_swrm_clock(void *handle, bool enable)
  2857. {
  2858. struct rx_macro_priv *rx_priv = (struct rx_macro_priv *) handle;
  2859. struct regmap *regmap = dev_get_regmap(rx_priv->dev->parent, NULL);
  2860. int ret = 0;
  2861. if (regmap == NULL) {
  2862. dev_err(rx_priv->dev, "%s: regmap is NULL\n", __func__);
  2863. return -EINVAL;
  2864. }
  2865. mutex_lock(&rx_priv->swr_clk_lock);
  2866. dev_dbg(rx_priv->dev, "%s: swrm clock %s\n",
  2867. __func__, (enable ? "enable" : "disable"));
  2868. if (enable) {
  2869. pm_runtime_get_sync(rx_priv->dev);
  2870. if (rx_priv->swr_clk_users == 0) {
  2871. msm_cdc_pinctrl_select_active_state(
  2872. rx_priv->rx_swr_gpio_p);
  2873. ret = rx_macro_mclk_enable(rx_priv, 1, true);
  2874. if (ret < 0) {
  2875. msm_cdc_pinctrl_select_sleep_state(
  2876. rx_priv->rx_swr_gpio_p);
  2877. dev_err(rx_priv->dev,
  2878. "%s: rx request clock enable failed\n",
  2879. __func__);
  2880. goto exit;
  2881. }
  2882. if (rx_priv->reset_swr)
  2883. regmap_update_bits(regmap,
  2884. BOLERO_CDC_RX_CLK_RST_CTRL_SWR_CONTROL,
  2885. 0x02, 0x02);
  2886. regmap_update_bits(regmap,
  2887. BOLERO_CDC_RX_CLK_RST_CTRL_SWR_CONTROL,
  2888. 0x01, 0x01);
  2889. if (rx_priv->reset_swr)
  2890. regmap_update_bits(regmap,
  2891. BOLERO_CDC_RX_CLK_RST_CTRL_SWR_CONTROL,
  2892. 0x02, 0x00);
  2893. rx_priv->reset_swr = false;
  2894. }
  2895. pm_runtime_mark_last_busy(rx_priv->dev);
  2896. pm_runtime_put_autosuspend(rx_priv->dev);
  2897. rx_priv->swr_clk_users++;
  2898. } else {
  2899. if (rx_priv->swr_clk_users <= 0) {
  2900. dev_err(rx_priv->dev,
  2901. "%s: rx swrm clock users already reset\n",
  2902. __func__);
  2903. rx_priv->swr_clk_users = 0;
  2904. goto exit;
  2905. }
  2906. rx_priv->swr_clk_users--;
  2907. if (rx_priv->swr_clk_users == 0) {
  2908. regmap_update_bits(regmap,
  2909. BOLERO_CDC_RX_CLK_RST_CTRL_SWR_CONTROL,
  2910. 0x01, 0x00);
  2911. rx_macro_mclk_enable(rx_priv, 0, true);
  2912. msm_cdc_pinctrl_select_sleep_state(
  2913. rx_priv->rx_swr_gpio_p);
  2914. }
  2915. }
  2916. dev_dbg(rx_priv->dev, "%s: swrm clock users %d\n",
  2917. __func__, rx_priv->swr_clk_users);
  2918. exit:
  2919. mutex_unlock(&rx_priv->swr_clk_lock);
  2920. return ret;
  2921. }
  2922. static void rx_macro_init_bcl_pmic_reg(struct snd_soc_component *component)
  2923. {
  2924. struct device *rx_dev = NULL;
  2925. struct rx_macro_priv *rx_priv = NULL;
  2926. if (!component) {
  2927. pr_err("%s: NULL component pointer!\n", __func__);
  2928. return;
  2929. }
  2930. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  2931. return;
  2932. switch (rx_priv->bcl_pmic_params.id) {
  2933. case 0:
  2934. /* Enable ID0 to listen to respective PMIC group interrupts */
  2935. snd_soc_component_update_bits(component,
  2936. BOLERO_CDC_RX_BCL_VBAT_DECODE_CTL1, 0x02, 0x02);
  2937. /* Update MC_SID0 */
  2938. snd_soc_component_update_bits(component,
  2939. BOLERO_CDC_RX_BCL_VBAT_DECODE_CFG1, 0x0F,
  2940. rx_priv->bcl_pmic_params.sid);
  2941. /* Update MC_PPID0 */
  2942. snd_soc_component_update_bits(component,
  2943. BOLERO_CDC_RX_BCL_VBAT_DECODE_CFG2, 0xFF,
  2944. rx_priv->bcl_pmic_params.ppid);
  2945. break;
  2946. case 1:
  2947. /* Enable ID1 to listen to respective PMIC group interrupts */
  2948. snd_soc_component_update_bits(component,
  2949. BOLERO_CDC_RX_BCL_VBAT_DECODE_CTL1, 0x01, 0x01);
  2950. /* Update MC_SID1 */
  2951. snd_soc_component_update_bits(component,
  2952. BOLERO_CDC_RX_BCL_VBAT_DECODE_CFG3, 0x0F,
  2953. rx_priv->bcl_pmic_params.sid);
  2954. /* Update MC_PPID1 */
  2955. snd_soc_component_update_bits(component,
  2956. BOLERO_CDC_RX_BCL_VBAT_DECODE_CFG1, 0xFF,
  2957. rx_priv->bcl_pmic_params.ppid);
  2958. break;
  2959. default:
  2960. dev_err(rx_dev, "%s: PMIC ID is invalid %d\n",
  2961. __func__, rx_priv->bcl_pmic_params.id);
  2962. break;
  2963. }
  2964. }
  2965. static int rx_macro_init(struct snd_soc_component *component)
  2966. {
  2967. struct snd_soc_dapm_context *dapm =
  2968. snd_soc_component_get_dapm(component);
  2969. int ret = 0;
  2970. struct device *rx_dev = NULL;
  2971. struct rx_macro_priv *rx_priv = NULL;
  2972. rx_dev = bolero_get_device_ptr(component->dev, RX_MACRO);
  2973. if (!rx_dev) {
  2974. dev_err(component->dev,
  2975. "%s: null device for macro!\n", __func__);
  2976. return -EINVAL;
  2977. }
  2978. rx_priv = dev_get_drvdata(rx_dev);
  2979. if (!rx_priv) {
  2980. dev_err(component->dev,
  2981. "%s: priv is null for macro!\n", __func__);
  2982. return -EINVAL;
  2983. }
  2984. ret = snd_soc_dapm_new_controls(dapm, rx_macro_dapm_widgets,
  2985. ARRAY_SIZE(rx_macro_dapm_widgets));
  2986. if (ret < 0) {
  2987. dev_err(rx_dev, "%s: failed to add controls\n", __func__);
  2988. return ret;
  2989. }
  2990. ret = snd_soc_dapm_add_routes(dapm, rx_audio_map,
  2991. ARRAY_SIZE(rx_audio_map));
  2992. if (ret < 0) {
  2993. dev_err(rx_dev, "%s: failed to add routes\n", __func__);
  2994. return ret;
  2995. }
  2996. ret = snd_soc_dapm_new_widgets(dapm->card);
  2997. if (ret < 0) {
  2998. dev_err(rx_dev, "%s: failed to add widgets\n", __func__);
  2999. return ret;
  3000. }
  3001. ret = snd_soc_add_component_controls(component, rx_macro_snd_controls,
  3002. ARRAY_SIZE(rx_macro_snd_controls));
  3003. if (ret < 0) {
  3004. dev_err(rx_dev, "%s: failed to add snd_ctls\n", __func__);
  3005. return ret;
  3006. }
  3007. rx_priv->dev_up = true;
  3008. snd_soc_dapm_ignore_suspend(dapm, "RX_MACRO_AIF1 Playback");
  3009. snd_soc_dapm_ignore_suspend(dapm, "RX_MACRO_AIF2 Playback");
  3010. snd_soc_dapm_ignore_suspend(dapm, "RX_MACRO_AIF3 Playback");
  3011. snd_soc_dapm_ignore_suspend(dapm, "RX_MACRO_AIF4 Playback");
  3012. snd_soc_dapm_ignore_suspend(dapm, "HPHL_OUT");
  3013. snd_soc_dapm_ignore_suspend(dapm, "HPHR_OUT");
  3014. snd_soc_dapm_ignore_suspend(dapm, "AUX_OUT");
  3015. snd_soc_dapm_ignore_suspend(dapm, "RX_TX DEC0_INP");
  3016. snd_soc_dapm_ignore_suspend(dapm, "RX_TX DEC1_INP");
  3017. snd_soc_dapm_ignore_suspend(dapm, "RX_TX DEC2_INP");
  3018. snd_soc_dapm_ignore_suspend(dapm, "RX_TX DEC3_INP");
  3019. snd_soc_dapm_sync(dapm);
  3020. snd_soc_component_update_bits(component,
  3021. BOLERO_CDC_RX_RX0_RX_PATH_DSM_CTL,
  3022. 0x01, 0x01);
  3023. snd_soc_component_update_bits(component,
  3024. BOLERO_CDC_RX_RX1_RX_PATH_DSM_CTL,
  3025. 0x01, 0x01);
  3026. snd_soc_component_update_bits(component,
  3027. BOLERO_CDC_RX_RX2_RX_PATH_DSM_CTL,
  3028. 0x01, 0x01);
  3029. snd_soc_component_update_bits(component, BOLERO_CDC_RX_RX0_RX_PATH_SEC7,
  3030. 0x07, 0x02);
  3031. snd_soc_component_update_bits(component, BOLERO_CDC_RX_RX1_RX_PATH_SEC7,
  3032. 0x07, 0x02);
  3033. snd_soc_component_update_bits(component, BOLERO_CDC_RX_RX2_RX_PATH_SEC7,
  3034. 0x07, 0x02);
  3035. snd_soc_component_update_bits(component, BOLERO_CDC_RX_RX0_RX_PATH_CFG3,
  3036. 0x03, 0x02);
  3037. snd_soc_component_update_bits(component, BOLERO_CDC_RX_RX1_RX_PATH_CFG3,
  3038. 0x03, 0x02);
  3039. snd_soc_component_update_bits(component, BOLERO_CDC_RX_RX2_RX_PATH_CFG3,
  3040. 0x03, 0x02);
  3041. rx_priv->component = component;
  3042. rx_macro_init_bcl_pmic_reg(component);
  3043. return 0;
  3044. }
  3045. static int rx_macro_deinit(struct snd_soc_component *component)
  3046. {
  3047. struct device *rx_dev = NULL;
  3048. struct rx_macro_priv *rx_priv = NULL;
  3049. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  3050. return -EINVAL;
  3051. rx_priv->component = NULL;
  3052. return 0;
  3053. }
  3054. static void rx_macro_add_child_devices(struct work_struct *work)
  3055. {
  3056. struct rx_macro_priv *rx_priv = NULL;
  3057. struct platform_device *pdev = NULL;
  3058. struct device_node *node = NULL;
  3059. struct rx_swr_ctrl_data *swr_ctrl_data = NULL, *temp = NULL;
  3060. int ret = 0;
  3061. u16 count = 0, ctrl_num = 0;
  3062. struct rx_swr_ctrl_platform_data *platdata = NULL;
  3063. char plat_dev_name[RX_SWR_STRING_LEN] = "";
  3064. bool rx_swr_master_node = false;
  3065. rx_priv = container_of(work, struct rx_macro_priv,
  3066. rx_macro_add_child_devices_work);
  3067. if (!rx_priv) {
  3068. pr_err("%s: Memory for rx_priv does not exist\n",
  3069. __func__);
  3070. return;
  3071. }
  3072. if (!rx_priv->dev) {
  3073. pr_err("%s: RX device does not exist\n", __func__);
  3074. return;
  3075. }
  3076. if(!rx_priv->dev->of_node) {
  3077. dev_err(rx_priv->dev,
  3078. "%s: DT node for RX dev does not exist\n", __func__);
  3079. return;
  3080. }
  3081. platdata = &rx_priv->swr_plat_data;
  3082. rx_priv->child_count = 0;
  3083. for_each_available_child_of_node(rx_priv->dev->of_node, node) {
  3084. rx_swr_master_node = false;
  3085. if (strnstr(node->name, "rx_swr_master",
  3086. strlen("rx_swr_master")) != NULL)
  3087. rx_swr_master_node = true;
  3088. if(rx_swr_master_node)
  3089. strlcpy(plat_dev_name, "rx_swr_ctrl",
  3090. (RX_SWR_STRING_LEN - 1));
  3091. else
  3092. strlcpy(plat_dev_name, node->name,
  3093. (RX_SWR_STRING_LEN - 1));
  3094. pdev = platform_device_alloc(plat_dev_name, -1);
  3095. if (!pdev) {
  3096. dev_err(rx_priv->dev, "%s: pdev memory alloc failed\n",
  3097. __func__);
  3098. ret = -ENOMEM;
  3099. goto err;
  3100. }
  3101. pdev->dev.parent = rx_priv->dev;
  3102. pdev->dev.of_node = node;
  3103. if (rx_swr_master_node) {
  3104. ret = platform_device_add_data(pdev, platdata,
  3105. sizeof(*platdata));
  3106. if (ret) {
  3107. dev_err(&pdev->dev,
  3108. "%s: cannot add plat data ctrl:%d\n",
  3109. __func__, ctrl_num);
  3110. goto fail_pdev_add;
  3111. }
  3112. }
  3113. ret = platform_device_add(pdev);
  3114. if (ret) {
  3115. dev_err(&pdev->dev,
  3116. "%s: Cannot add platform device\n",
  3117. __func__);
  3118. goto fail_pdev_add;
  3119. }
  3120. if (rx_swr_master_node) {
  3121. temp = krealloc(swr_ctrl_data,
  3122. (ctrl_num + 1) * sizeof(
  3123. struct rx_swr_ctrl_data),
  3124. GFP_KERNEL);
  3125. if (!temp) {
  3126. ret = -ENOMEM;
  3127. goto fail_pdev_add;
  3128. }
  3129. swr_ctrl_data = temp;
  3130. swr_ctrl_data[ctrl_num].rx_swr_pdev = pdev;
  3131. ctrl_num++;
  3132. dev_dbg(&pdev->dev,
  3133. "%s: Added soundwire ctrl device(s)\n",
  3134. __func__);
  3135. rx_priv->swr_ctrl_data = swr_ctrl_data;
  3136. }
  3137. if (rx_priv->child_count < RX_MACRO_CHILD_DEVICES_MAX)
  3138. rx_priv->pdev_child_devices[
  3139. rx_priv->child_count++] = pdev;
  3140. else
  3141. goto err;
  3142. }
  3143. return;
  3144. fail_pdev_add:
  3145. for (count = 0; count < rx_priv->child_count; count++)
  3146. platform_device_put(rx_priv->pdev_child_devices[count]);
  3147. err:
  3148. return;
  3149. }
  3150. static void rx_macro_init_ops(struct macro_ops *ops, char __iomem *rx_io_base)
  3151. {
  3152. memset(ops, 0, sizeof(struct macro_ops));
  3153. ops->init = rx_macro_init;
  3154. ops->exit = rx_macro_deinit;
  3155. ops->io_base = rx_io_base;
  3156. ops->dai_ptr = rx_macro_dai;
  3157. ops->num_dais = ARRAY_SIZE(rx_macro_dai);
  3158. ops->event_handler = rx_macro_event_handler;
  3159. ops->set_port_map = rx_macro_set_port_map;
  3160. }
  3161. static int rx_macro_probe(struct platform_device *pdev)
  3162. {
  3163. struct macro_ops ops = {0};
  3164. struct rx_macro_priv *rx_priv = NULL;
  3165. u32 rx_base_addr = 0, muxsel = 0;
  3166. char __iomem *rx_io_base = NULL, *muxsel_io = NULL;
  3167. int ret = 0;
  3168. u8 bcl_pmic_params[3];
  3169. u32 default_clk_id = 0;
  3170. rx_priv = devm_kzalloc(&pdev->dev, sizeof(struct rx_macro_priv),
  3171. GFP_KERNEL);
  3172. if (!rx_priv)
  3173. return -ENOMEM;
  3174. rx_priv->dev = &pdev->dev;
  3175. ret = of_property_read_u32(pdev->dev.of_node, "reg",
  3176. &rx_base_addr);
  3177. if (ret) {
  3178. dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
  3179. __func__, "reg");
  3180. return ret;
  3181. }
  3182. ret = of_property_read_u32(pdev->dev.of_node, "qcom,rx_mclk_mode_muxsel",
  3183. &muxsel);
  3184. if (ret) {
  3185. dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
  3186. __func__, "reg");
  3187. return ret;
  3188. }
  3189. ret = of_property_read_u32(pdev->dev.of_node, "qcom,default-clk-id",
  3190. &default_clk_id);
  3191. if (ret) {
  3192. dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
  3193. __func__, "qcom,default-clk-id");
  3194. default_clk_id = RX_CORE_CLK;
  3195. }
  3196. rx_priv->rx_swr_gpio_p = of_parse_phandle(pdev->dev.of_node,
  3197. "qcom,rx-swr-gpios", 0);
  3198. if (!rx_priv->rx_swr_gpio_p) {
  3199. dev_err(&pdev->dev, "%s: swr_gpios handle not provided!\n",
  3200. __func__);
  3201. return -EINVAL;
  3202. }
  3203. rx_io_base = devm_ioremap(&pdev->dev, rx_base_addr,
  3204. RX_MACRO_MAX_OFFSET);
  3205. if (!rx_io_base) {
  3206. dev_err(&pdev->dev, "%s: ioremap failed\n", __func__);
  3207. return -ENOMEM;
  3208. }
  3209. rx_priv->rx_io_base = rx_io_base;
  3210. muxsel_io = devm_ioremap(&pdev->dev, muxsel, 0x4);
  3211. if (!muxsel_io) {
  3212. dev_err(&pdev->dev, "%s: ioremap failed for muxsel\n",
  3213. __func__);
  3214. return -ENOMEM;
  3215. }
  3216. rx_priv->rx_mclk_mode_muxsel = muxsel_io;
  3217. rx_priv->reset_swr = true;
  3218. INIT_WORK(&rx_priv->rx_macro_add_child_devices_work,
  3219. rx_macro_add_child_devices);
  3220. rx_priv->swr_plat_data.handle = (void *) rx_priv;
  3221. rx_priv->swr_plat_data.read = NULL;
  3222. rx_priv->swr_plat_data.write = NULL;
  3223. rx_priv->swr_plat_data.bulk_write = NULL;
  3224. rx_priv->swr_plat_data.clk = rx_swrm_clock;
  3225. rx_priv->swr_plat_data.handle_irq = NULL;
  3226. ret = of_property_read_u8_array(pdev->dev.of_node,
  3227. "qcom,rx-bcl-pmic-params", bcl_pmic_params,
  3228. sizeof(bcl_pmic_params));
  3229. if (ret) {
  3230. dev_dbg(&pdev->dev, "%s: could not find %s entry in dt\n",
  3231. __func__, "qcom,rx-bcl-pmic-params");
  3232. } else {
  3233. rx_priv->bcl_pmic_params.id = bcl_pmic_params[0];
  3234. rx_priv->bcl_pmic_params.sid = bcl_pmic_params[1];
  3235. rx_priv->bcl_pmic_params.ppid = bcl_pmic_params[2];
  3236. }
  3237. rx_priv->clk_id = default_clk_id;
  3238. rx_priv->default_clk_id = default_clk_id;
  3239. ops.clk_id_req = rx_priv->clk_id;
  3240. ops.default_clk_id = default_clk_id;
  3241. dev_set_drvdata(&pdev->dev, rx_priv);
  3242. mutex_init(&rx_priv->mclk_lock);
  3243. mutex_init(&rx_priv->swr_clk_lock);
  3244. rx_macro_init_ops(&ops, rx_io_base);
  3245. ret = bolero_register_macro(&pdev->dev, RX_MACRO, &ops);
  3246. if (ret) {
  3247. dev_err(&pdev->dev,
  3248. "%s: register macro failed\n", __func__);
  3249. goto err_reg_macro;
  3250. }
  3251. schedule_work(&rx_priv->rx_macro_add_child_devices_work);
  3252. pm_runtime_set_autosuspend_delay(&pdev->dev, AUTO_SUSPEND_DELAY);
  3253. pm_runtime_use_autosuspend(&pdev->dev);
  3254. pm_runtime_set_suspended(&pdev->dev);
  3255. pm_runtime_enable(&pdev->dev);
  3256. return 0;
  3257. err_reg_macro:
  3258. mutex_destroy(&rx_priv->mclk_lock);
  3259. mutex_destroy(&rx_priv->swr_clk_lock);
  3260. return ret;
  3261. }
  3262. static int rx_macro_remove(struct platform_device *pdev)
  3263. {
  3264. struct rx_macro_priv *rx_priv = NULL;
  3265. u16 count = 0;
  3266. rx_priv = dev_get_drvdata(&pdev->dev);
  3267. if (!rx_priv)
  3268. return -EINVAL;
  3269. for (count = 0; count < rx_priv->child_count &&
  3270. count < RX_MACRO_CHILD_DEVICES_MAX; count++)
  3271. platform_device_unregister(rx_priv->pdev_child_devices[count]);
  3272. pm_runtime_disable(&pdev->dev);
  3273. pm_runtime_set_suspended(&pdev->dev);
  3274. bolero_unregister_macro(&pdev->dev, RX_MACRO);
  3275. mutex_destroy(&rx_priv->mclk_lock);
  3276. mutex_destroy(&rx_priv->swr_clk_lock);
  3277. kfree(rx_priv->swr_ctrl_data);
  3278. return 0;
  3279. }
  3280. static const struct of_device_id rx_macro_dt_match[] = {
  3281. {.compatible = "qcom,rx-macro"},
  3282. {}
  3283. };
  3284. static const struct dev_pm_ops bolero_dev_pm_ops = {
  3285. SET_RUNTIME_PM_OPS(
  3286. bolero_runtime_suspend,
  3287. bolero_runtime_resume,
  3288. NULL
  3289. )
  3290. };
  3291. static struct platform_driver rx_macro_driver = {
  3292. .driver = {
  3293. .name = "rx_macro",
  3294. .owner = THIS_MODULE,
  3295. .pm = &bolero_dev_pm_ops,
  3296. .of_match_table = rx_macro_dt_match,
  3297. },
  3298. .probe = rx_macro_probe,
  3299. .remove = rx_macro_remove,
  3300. };
  3301. module_platform_driver(rx_macro_driver);
  3302. MODULE_DESCRIPTION("RX macro driver");
  3303. MODULE_LICENSE("GPL v2");