rx-macro.c 126 KB

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