rx-macro.c 128 KB

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