rx-macro.c 102 KB

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