rx-macro.c 100 KB

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