rx-macro.c 116 KB

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