rx-macro.c 125 KB

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