rx-macro.c 111 KB

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