rx-macro.c 106 KB

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