rx-macro.c 103 KB

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