wcd939x.c 146 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2018-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022-2023, Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #include <linux/module.h>
  7. #include <linux/slab.h>
  8. #include <linux/platform_device.h>
  9. #include <linux/device.h>
  10. #include <linux/delay.h>
  11. #include <linux/kernel.h>
  12. #include <linux/component.h>
  13. #include <sound/soc.h>
  14. #include <sound/tlv.h>
  15. #include <soc/soundwire.h>
  16. #include <linux/regmap.h>
  17. #include <sound/soc.h>
  18. #include <sound/soc-dapm.h>
  19. #include <asoc/wcdcal-hwdep.h>
  20. #include <asoc/msm-cdc-pinctrl.h>
  21. #include <asoc/msm-cdc-supply.h>
  22. #include <bindings/audio-codec-port-types.h>
  23. #include <linux/qti-regmap-debugfs.h>
  24. #include "wcd939x-registers.h"
  25. #include "wcd939x.h"
  26. #include "internal.h"
  27. #include "asoc/bolero-slave-internal.h"
  28. #include "wcd939x-reg-masks.h"
  29. #include "wcd939x-reg-shifts.h"
  30. #define NUM_SWRS_DT_PARAMS 5
  31. #define WCD939X_VARIANT_ENTRY_SIZE 32
  32. #define WCD939X_VERSION_1_0 1
  33. #define WCD939X_VERSION_ENTRY_SIZE 32
  34. #define ADC_MODE_VAL_HIFI 0x01
  35. #define ADC_MODE_VAL_LO_HIF 0x02
  36. #define ADC_MODE_VAL_NORMAL 0x03
  37. #define ADC_MODE_VAL_LP 0x05
  38. #define ADC_MODE_VAL_ULP1 0x09
  39. #define ADC_MODE_VAL_ULP2 0x0B
  40. #define NUM_ATTEMPTS 5
  41. #define COMP_MAX_COEFF 25
  42. #define DAPM_MICBIAS1_STANDALONE "MIC BIAS1 Standalone"
  43. #define DAPM_MICBIAS2_STANDALONE "MIC BIAS2 Standalone"
  44. #define DAPM_MICBIAS3_STANDALONE "MIC BIAS3 Standalone"
  45. #define DAPM_MICBIAS4_STANDALONE "MIC BIAS4 Standalone"
  46. #define WCD939X_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
  47. SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
  48. SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000 |\
  49. SNDRV_PCM_RATE_384000)
  50. /* Fractional Rates */
  51. #define WCD939X_FRAC_RATES (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_88200 |\
  52. SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_352800)
  53. #define WCD939X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
  54. SNDRV_PCM_FMTBIT_S24_LE |\
  55. SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
  56. #define REG_FIELD_VALUE(register_name, field_name, value) \
  57. WCD939X_##register_name, FIELD_MASK(register_name, field_name), \
  58. value << FIELD_SHIFT(register_name, field_name)
  59. #define WCD939X_COMP_OFFSET \
  60. (WCD939X_R_BASE - WCD939X_COMPANDER_HPHL_BASE)
  61. #define WCD939X_XTALK_OFFSET \
  62. (WCD939X_HPHR_RX_PATH_SEC0 - WCD939X_HPHL_RX_PATH_SEC0)
  63. enum {
  64. HPH_ULP,
  65. HPH_HIFI,
  66. HPH_LOHIFI,
  67. HPH_LP,
  68. HPH_MODE_MAX,
  69. };
  70. static struct comp_coeff_val
  71. comp_coeff_table [HPH_MODE_MAX][COMP_MAX_COEFF] = {
  72. {
  73. {0x40, 0x00},
  74. {0x4C, 0x00},
  75. {0x5A, 0x00},
  76. {0x6B, 0x00},
  77. {0x7F, 0x00},
  78. {0x97, 0x00},
  79. {0xB3, 0x00},
  80. {0xD5, 0x00},
  81. {0xFD, 0x00},
  82. {0x2D, 0x01},
  83. {0x66, 0x01},
  84. {0xA7, 0x01},
  85. {0xF8, 0x01},
  86. {0x57, 0x02},
  87. {0xC7, 0x02},
  88. {0x4B, 0x03},
  89. {0xE9, 0x03},
  90. {0xA3, 0x04},
  91. {0x7D, 0x05},
  92. {0x90, 0x06},
  93. {0xD1, 0x07},
  94. {0x49, 0x09},
  95. {0x00, 0x0B},
  96. {0x01, 0x0D},
  97. {0x59, 0x0F},
  98. },
  99. {
  100. /*HPH_HIFI, HPH_LOHIFI, HPH_LP*/
  101. {0x40, 0x00},
  102. {0x4C, 0x00},
  103. {0x5A, 0x00},
  104. {0x6B, 0x00},
  105. {0x80, 0x00},
  106. {0x98, 0x00},
  107. {0xB4, 0x00},
  108. {0xD5, 0x00},
  109. {0xFE, 0x00},
  110. {0x2E, 0x01},
  111. {0x66, 0x01},
  112. {0xA9, 0x01},
  113. {0xF8, 0x01},
  114. {0x56, 0x02},
  115. {0xC4, 0x02},
  116. {0x4F, 0x03},
  117. {0xF0, 0x03},
  118. {0xAE, 0x04},
  119. {0x8B, 0x05},
  120. {0x8E, 0x06},
  121. {0xBC, 0x07},
  122. {0x56, 0x09},
  123. {0x0F, 0x0B},
  124. {0x13, 0x0D},
  125. {0x6F, 0x0F},
  126. },
  127. };
  128. enum {
  129. CODEC_TX = 0,
  130. CODEC_RX,
  131. };
  132. enum {
  133. WCD_ADC1 = 0,
  134. WCD_ADC2,
  135. WCD_ADC3,
  136. WCD_ADC4,
  137. ALLOW_BUCK_DISABLE,
  138. HPH_COMP_DELAY,
  139. HPH_PA_DELAY,
  140. AMIC2_BCS_ENABLE,
  141. WCD_SUPPLIES_LPM_MODE,
  142. WCD_ADC1_MODE,
  143. WCD_ADC2_MODE,
  144. WCD_ADC3_MODE,
  145. WCD_ADC4_MODE,
  146. };
  147. enum {
  148. ADC_MODE_INVALID = 0,
  149. ADC_MODE_HIFI,
  150. ADC_MODE_LO_HIF,
  151. ADC_MODE_NORMAL,
  152. ADC_MODE_LP,
  153. ADC_MODE_ULP1,
  154. ADC_MODE_ULP2,
  155. };
  156. static u8 tx_mode_bit[] = {
  157. [ADC_MODE_INVALID] = 0x00,
  158. [ADC_MODE_HIFI] = 0x01,
  159. [ADC_MODE_LO_HIF] = 0x02,
  160. [ADC_MODE_NORMAL] = 0x04,
  161. [ADC_MODE_LP] = 0x08,
  162. [ADC_MODE_ULP1] = 0x10,
  163. [ADC_MODE_ULP2] = 0x20,
  164. };
  165. static const DECLARE_TLV_DB_SCALE(line_gain, 0, 7, 1);
  166. static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1);
  167. static int wcd939x_handle_post_irq(void *data);
  168. static int wcd939x_reset(struct device *dev);
  169. static int wcd939x_reset_low(struct device *dev);
  170. static int wcd939x_get_adc_mode(int val);
  171. static const struct regmap_irq wcd939x_irqs[WCD939X_NUM_IRQS] = {
  172. REGMAP_IRQ_REG(WCD939X_IRQ_MBHC_BUTTON_PRESS_DET, 0, 0x01),
  173. REGMAP_IRQ_REG(WCD939X_IRQ_MBHC_BUTTON_RELEASE_DET, 0, 0x02),
  174. REGMAP_IRQ_REG(WCD939X_IRQ_MBHC_ELECT_INS_REM_DET, 0, 0x04),
  175. REGMAP_IRQ_REG(WCD939X_IRQ_MBHC_ELECT_INS_REM_LEG_DET, 0, 0x08),
  176. REGMAP_IRQ_REG(WCD939X_IRQ_MBHC_SW_DET, 0, 0x10),
  177. REGMAP_IRQ_REG(WCD939X_IRQ_HPHR_OCP_INT, 0, 0x20),
  178. REGMAP_IRQ_REG(WCD939X_IRQ_HPHR_CNP_INT, 0, 0x40),
  179. REGMAP_IRQ_REG(WCD939X_IRQ_HPHL_OCP_INT, 0, 0x80),
  180. REGMAP_IRQ_REG(WCD939X_IRQ_HPHL_CNP_INT, 1, 0x01),
  181. REGMAP_IRQ_REG(WCD939X_IRQ_EAR_CNP_INT, 1, 0x02),
  182. REGMAP_IRQ_REG(WCD939X_IRQ_EAR_SCD_INT, 1, 0x04),
  183. REGMAP_IRQ_REG(WCD939X_IRQ_HPHL_PDM_WD_INT, 1, 0x20),
  184. REGMAP_IRQ_REG(WCD939X_IRQ_HPHR_PDM_WD_INT, 1, 0x40),
  185. REGMAP_IRQ_REG(WCD939X_IRQ_EAR_PDM_WD_INT, 1, 0x80),
  186. REGMAP_IRQ_REG(WCD939X_IRQ_LDORT_SCD_INT, 2, 0x01),
  187. REGMAP_IRQ_REG(WCD939X_IRQ_MBHC_MOISTURE_INT, 2, 0x02),
  188. REGMAP_IRQ_REG(WCD939X_IRQ_HPHL_SURGE_DET_INT, 2, 0x04),
  189. REGMAP_IRQ_REG(WCD939X_IRQ_HPHR_SURGE_DET_INT, 2, 0x08),
  190. };
  191. static struct regmap_irq_chip wcd939x_regmap_irq_chip = {
  192. .name = "wcd939x",
  193. .irqs = wcd939x_irqs,
  194. .num_irqs = ARRAY_SIZE(wcd939x_irqs),
  195. .num_regs = 3,
  196. .status_base = WCD939X_INTR_STATUS_0,
  197. .mask_base = WCD939X_INTR_MASK_0,
  198. .type_base = WCD939X_INTR_LEVEL_0,
  199. .ack_base = WCD939X_INTR_CLEAR_0,
  200. .use_ack = 1,
  201. .runtime_pm = false,
  202. .handle_post_irq = wcd939x_handle_post_irq,
  203. .irq_drv_data = NULL,
  204. };
  205. static int wcd939x_handle_post_irq(void *data)
  206. {
  207. struct wcd939x_priv *wcd939x = data;
  208. u32 sts1 = 0, sts2 = 0, sts3 = 0;
  209. regmap_read(wcd939x->regmap, WCD939X_INTR_STATUS_0, &sts1);
  210. regmap_read(wcd939x->regmap, WCD939X_INTR_STATUS_1, &sts2);
  211. regmap_read(wcd939x->regmap, WCD939X_INTR_STATUS_2, &sts3);
  212. wcd939x->tx_swr_dev->slave_irq_pending =
  213. ((sts1 || sts2 || sts3) ? true : false);
  214. return IRQ_HANDLED;
  215. }
  216. int wcd939x_load_compander_coeff(struct snd_soc_component *component,
  217. u16 lsb_reg, u16 msb_reg,
  218. struct comp_coeff_val *comp_coeff_table,
  219. u16 arr_size)
  220. {
  221. int i = 0;
  222. /* Load Compander Coeff */
  223. for (i = 0; i < arr_size; i++) {
  224. snd_soc_component_write(component, lsb_reg,
  225. comp_coeff_table[i].lsb);
  226. snd_soc_component_write(component, msb_reg,
  227. comp_coeff_table[i].msb);
  228. }
  229. return 0;
  230. }
  231. EXPORT_SYMBOL(wcd939x_load_compander_coeff);
  232. static int wcd939x_hph_compander_get(struct snd_kcontrol *kcontrol,
  233. struct snd_ctl_elem_value *ucontrol)
  234. {
  235. struct snd_soc_component *component =
  236. snd_soc_kcontrol_component(kcontrol);
  237. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  238. int compander = ((struct soc_multi_mixer_control *)
  239. kcontrol->private_value)->shift;
  240. ucontrol->value.integer.value[0] = wcd939x->compander_enabled[compander];
  241. return 0;
  242. }
  243. static int wcd939x_hph_compander_put(struct snd_kcontrol *kcontrol,
  244. struct snd_ctl_elem_value *ucontrol)
  245. {
  246. struct snd_soc_component *component =
  247. snd_soc_kcontrol_component(kcontrol);
  248. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  249. int compander = ((struct soc_multi_mixer_control *)
  250. kcontrol->private_value)->shift;
  251. int value = ucontrol->value.integer.value[0];
  252. if (value < WCD939X_HPH_MAX && value >= 0)
  253. wcd939x->compander_enabled[compander] = value;
  254. else {
  255. dev_err(component->dev, "%s: Invalid comp value = %d\n", __func__, value);
  256. return -EINVAL;
  257. }
  258. dev_dbg(component->dev, "%s: Compander %d value %d\n",
  259. __func__, wcd939x->compander_enabled[compander], value);
  260. return 0;
  261. }
  262. static int wcd939x_hph_xtalk_put(struct snd_kcontrol *kcontrol,
  263. struct snd_ctl_elem_value *ucontrol)
  264. {
  265. struct snd_soc_component *component =
  266. snd_soc_kcontrol_component(kcontrol);
  267. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  268. int xtalk = ((struct soc_multi_mixer_control *)
  269. kcontrol->private_value)->shift;
  270. int value = ucontrol->value.integer.value[0];
  271. if (value < WCD939X_HPH_MAX && value >= 0)
  272. wcd939x->xtalk_enabled[xtalk] = value;
  273. else {
  274. dev_err(component->dev, "%s: Invalid xtalk value = %d\n", __func__, value);
  275. return -EINVAL;
  276. }
  277. dev_dbg(component->dev, "%s: xtalk %d value %d\n",
  278. __func__, wcd939x->xtalk_enabled[xtalk], value);
  279. return 0;
  280. }
  281. static int wcd939x_hph_xtalk_get(struct snd_kcontrol *kcontrol,
  282. struct snd_ctl_elem_value *ucontrol)
  283. {
  284. struct snd_soc_component *component =
  285. snd_soc_kcontrol_component(kcontrol);
  286. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  287. int xtalk = ((struct soc_multi_mixer_control *)
  288. kcontrol->private_value)->shift;
  289. ucontrol->value.integer.value[0] = wcd939x->xtalk_enabled[xtalk];
  290. return 0;
  291. }
  292. static int wcd939x_hph_pcm_enable_put(struct snd_kcontrol *kcontrol,
  293. struct snd_ctl_elem_value *ucontrol)
  294. {
  295. struct snd_soc_component *component =
  296. snd_soc_kcontrol_component(kcontrol);
  297. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  298. int pcm_index = ((struct soc_multi_mixer_control *)
  299. kcontrol->private_value)->shift;
  300. int value = ucontrol->value.integer.value[0];
  301. dev_dbg(component->dev, "%s: pcm_index %d value %d\n",
  302. __func__, wcd939x->hph_pcm_enabled[pcm_index], value);
  303. wcd939x->hph_pcm_enabled[pcm_index] = value;
  304. return 0;
  305. }
  306. static int wcd939x_hph_pcm_enable_get(struct snd_kcontrol *kcontrol,
  307. struct snd_ctl_elem_value *ucontrol)
  308. {
  309. struct snd_soc_component *component =
  310. snd_soc_kcontrol_component(kcontrol);
  311. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  312. int pcm_index = ((struct soc_multi_mixer_control *)
  313. kcontrol->private_value)->shift;
  314. ucontrol->value.integer.value[0] = wcd939x->hph_pcm_enabled[pcm_index];
  315. return 0;
  316. }
  317. static int wcd939x_swr_slv_get_current_bank(struct swr_device *dev, u8 devnum)
  318. {
  319. int ret = 0;
  320. int bank = 0;
  321. ret = swr_read(dev, devnum, SWR_SCP_CONTROL, &bank, 1);
  322. if (ret)
  323. return -EINVAL;
  324. return ((bank & 0x40) ? 1: 0);
  325. }
  326. static int wcd939x_get_clk_rate(int mode)
  327. {
  328. int rate;
  329. switch (mode) {
  330. case ADC_MODE_ULP2:
  331. rate = SWR_CLK_RATE_0P6MHZ;
  332. break;
  333. case ADC_MODE_ULP1:
  334. rate = SWR_CLK_RATE_1P2MHZ;
  335. break;
  336. case ADC_MODE_LP:
  337. rate = SWR_CLK_RATE_4P8MHZ;
  338. break;
  339. case ADC_MODE_NORMAL:
  340. case ADC_MODE_LO_HIF:
  341. case ADC_MODE_HIFI:
  342. case ADC_MODE_INVALID:
  343. default:
  344. rate = SWR_CLK_RATE_9P6MHZ;
  345. break;
  346. }
  347. return rate;
  348. }
  349. static int wcd939x_set_swr_clk_rate(struct snd_soc_component *component,
  350. int rate, int bank)
  351. {
  352. u8 mask = (bank ? 0xF0 : 0x0F);
  353. u8 val = 0;
  354. switch (rate) {
  355. case SWR_CLK_RATE_0P6MHZ:
  356. val = (bank ? 0x60 : 0x06);
  357. break;
  358. case SWR_CLK_RATE_1P2MHZ:
  359. val = (bank ? 0x50 : 0x05);
  360. break;
  361. case SWR_CLK_RATE_2P4MHZ:
  362. val = (bank ? 0x30 : 0x03);
  363. break;
  364. case SWR_CLK_RATE_4P8MHZ:
  365. val = (bank ? 0x10 : 0x01);
  366. break;
  367. case SWR_CLK_RATE_9P6MHZ:
  368. default:
  369. val = 0x00;
  370. break;
  371. }
  372. snd_soc_component_update_bits(component,
  373. WCD939X_SWR_TX_CLK_RATE,
  374. mask, val);
  375. return 0;
  376. }
  377. static int wcd939x_init_reg(struct snd_soc_component *component)
  378. {
  379. snd_soc_component_update_bits(component,
  380. REG_FIELD_VALUE(VBG_FINE_ADJ, VBG_FINE_ADJ, 0x04));
  381. snd_soc_component_update_bits(component,
  382. REG_FIELD_VALUE(BIAS, ANALOG_BIAS_EN, 0x01));
  383. snd_soc_component_update_bits(component,
  384. REG_FIELD_VALUE(BIAS, PRECHRG_EN, 0x01));
  385. /* 10 msec delay as per HW requirement */
  386. usleep_range(10000, 10010);
  387. snd_soc_component_update_bits(component,
  388. REG_FIELD_VALUE(BIAS, PRECHRG_EN, 0x00));
  389. snd_soc_component_update_bits(component,
  390. REG_FIELD_VALUE(RDAC_HD2_CTL_L, HD2_RES_DIV_CTL_L, 0x15));
  391. snd_soc_component_update_bits(component,
  392. REG_FIELD_VALUE(RDAC_HD2_CTL_R, HD2_RES_DIV_CTL_R, 0x15));
  393. snd_soc_component_update_bits(component,
  394. REG_FIELD_VALUE(REFBUFF_UHQA_CTL, SPARE_BITS, 0x02));
  395. snd_soc_component_update_bits(component,
  396. REG_FIELD_VALUE(CDC_DMIC_CTL, CLK_SCALE_EN, 0x01));
  397. snd_soc_component_update_bits(component,
  398. REG_FIELD_VALUE(TXFE_ICTRL_STG2CASC_ULP, ICTRL_SCBIAS_ULP0P6M, 0x1));
  399. snd_soc_component_update_bits(component,
  400. REG_FIELD_VALUE(TXFE_ICTRL_STG2CASC_ULP, ICTRL_STG2CASC_ULP, 0x4));
  401. snd_soc_component_update_bits(component,
  402. REG_FIELD_VALUE(TXFE_ICTRL_STG2MAIN_ULP, ICTRL_STG2MAIN_ULP, 0x08));
  403. snd_soc_component_update_bits(component,
  404. REG_FIELD_VALUE(TEST_CTL_1, NOISE_FILT_RES_VAL, 0x07));
  405. snd_soc_component_update_bits(component,
  406. REG_FIELD_VALUE(MICB2_TEST_CTL_1, NOISE_FILT_RES_VAL, 0x07));
  407. snd_soc_component_update_bits(component,
  408. REG_FIELD_VALUE(MICB3_TEST_CTL_1, NOISE_FILT_RES_VAL, 0x07));
  409. snd_soc_component_update_bits(component,
  410. REG_FIELD_VALUE(MICB4_TEST_CTL_1, NOISE_FILT_RES_VAL, 0x07));
  411. snd_soc_component_update_bits(component,
  412. REG_FIELD_VALUE(TEST_BLK_EN2, TXFE2_MBHC_CLKRST_EN, 0x00));
  413. snd_soc_component_update_bits(component,
  414. REG_FIELD_VALUE(HPHLR_SURGE_EN, EN_SURGE_PROTECTION_HPHL, 0x01));
  415. snd_soc_component_update_bits(component,
  416. REG_FIELD_VALUE(HPHLR_SURGE_EN, EN_SURGE_PROTECTION_HPHR, 0x01));
  417. return 0;
  418. }
  419. static int wcd939x_set_port_params(struct snd_soc_component *component,
  420. u8 slv_prt_type, u8 *port_id, u8 *num_ch,
  421. u8 *ch_mask, u32 *ch_rate,
  422. u8 *port_type, u8 path)
  423. {
  424. int i, j;
  425. u8 num_ports = 0;
  426. struct codec_port_info (*map)[MAX_PORT][MAX_CH_PER_PORT];
  427. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  428. switch (path) {
  429. case CODEC_RX:
  430. map = &wcd939x->rx_port_mapping;
  431. num_ports = wcd939x->num_rx_ports;
  432. break;
  433. case CODEC_TX:
  434. map = &wcd939x->tx_port_mapping;
  435. num_ports = wcd939x->num_tx_ports;
  436. break;
  437. default:
  438. dev_err_ratelimited(component->dev, "%s Invalid path selected %u\n",
  439. __func__, path);
  440. return -EINVAL;
  441. }
  442. for (i = 0; i <= num_ports; i++) {
  443. for (j = 0; j < MAX_CH_PER_PORT; j++) {
  444. if ((*map)[i][j].slave_port_type == slv_prt_type)
  445. goto found;
  446. }
  447. }
  448. found:
  449. if (i > num_ports || j == MAX_CH_PER_PORT) {
  450. dev_err_ratelimited(component->dev, "%s Failed to find slave port for type %u\n",
  451. __func__, slv_prt_type);
  452. return -EINVAL;
  453. }
  454. *port_id = i;
  455. *num_ch = (*map)[i][j].num_ch;
  456. *ch_mask = (*map)[i][j].ch_mask;
  457. *ch_rate = (*map)[i][j].ch_rate;
  458. *port_type = (*map)[i][j].master_port_type;
  459. return 0;
  460. }
  461. /* qcom,swr-tx-port-params = <OFFSET1_VAL0 LANE1>, <OFFSET1_VAL5 LANE0>, <OFFSET1_VAL1 LANE0>, <OFFSET1_VAL1 LANE0>,*UC0*
  462. <OFFSET1_VAL0 LANE1>, <OFFSET1_VAL2 LANE0>, <OFFSET1_VAL1 LANE0>, <OFFSET1_VAL1 LANE0>, *UC1*
  463. <OFFSET1_VAL1 LANE0>, <OFFSET1_VAL1 LANE0>, <OFFSET1_VAL1 LANE0>, <OFFSET1_VAL1 LANE0>; *UC2*
  464. <OFFSET1_VAL1 LANE0>, <OFFSET1_VAL1 LANE0>, <OFFSET1_VAL1 LANE0>, <OFFSET1_VAL1 LANE0>; *UC3 */
  465. static int wcd939x_parse_port_params(struct device *dev,
  466. char *prop, u8 path)
  467. {
  468. u32 *dt_array, map_size, max_uc;
  469. int ret = 0;
  470. u32 cnt = 0;
  471. u32 i, j;
  472. struct swr_port_params (*map)[SWR_UC_MAX][SWR_NUM_PORTS];
  473. struct swr_dev_frame_config (*map_uc)[SWR_UC_MAX];
  474. struct wcd939x_priv *wcd939x = dev_get_drvdata(dev);
  475. switch (path) {
  476. case CODEC_TX:
  477. map = &wcd939x->tx_port_params;
  478. map_uc = &wcd939x->swr_tx_port_params;
  479. break;
  480. default:
  481. ret = -EINVAL;
  482. goto err_port_map;
  483. }
  484. if (!of_find_property(dev->of_node, prop,
  485. &map_size)) {
  486. dev_err(dev, "missing port mapping prop %s\n", prop);
  487. ret = -EINVAL;
  488. goto err_port_map;
  489. }
  490. max_uc = map_size / (SWR_NUM_PORTS * SWR_PORT_PARAMS * sizeof(u32));
  491. if (max_uc != SWR_UC_MAX) {
  492. dev_err(dev, "%s: port params not provided for all usecases\n",
  493. __func__);
  494. ret = -EINVAL;
  495. goto err_port_map;
  496. }
  497. dt_array = kzalloc(map_size, GFP_KERNEL);
  498. if (!dt_array) {
  499. ret = -ENOMEM;
  500. goto err_alloc;
  501. }
  502. ret = of_property_read_u32_array(dev->of_node, prop, dt_array,
  503. SWR_NUM_PORTS * SWR_PORT_PARAMS * max_uc);
  504. if (ret) {
  505. dev_err(dev, "%s: Failed to read port mapping from prop %s\n",
  506. __func__, prop);
  507. goto err_pdata_fail;
  508. }
  509. for (i = 0; i < max_uc; i++) {
  510. for (j = 0; j < SWR_NUM_PORTS; j++) {
  511. cnt = (i * SWR_NUM_PORTS + j) * SWR_PORT_PARAMS;
  512. (*map)[i][j].offset1 = dt_array[cnt];
  513. (*map)[i][j].lane_ctrl = dt_array[cnt + 1];
  514. }
  515. (*map_uc)[i].pp = &(*map)[i][0];
  516. }
  517. kfree(dt_array);
  518. return 0;
  519. err_pdata_fail:
  520. kfree(dt_array);
  521. err_alloc:
  522. err_port_map:
  523. return ret;
  524. }
  525. static int wcd939x_parse_port_mapping(struct device *dev,
  526. char *prop, u8 path)
  527. {
  528. u32 *dt_array, map_size, map_length;
  529. u32 port_num = 0, ch_mask, ch_rate, old_port_num = 0;
  530. u32 slave_port_type, master_port_type;
  531. u32 i, ch_iter = 0;
  532. int ret = 0;
  533. u8 *num_ports = NULL;
  534. struct codec_port_info (*map)[MAX_PORT][MAX_CH_PER_PORT];
  535. struct wcd939x_priv *wcd939x = dev_get_drvdata(dev);
  536. switch (path) {
  537. case CODEC_RX:
  538. map = &wcd939x->rx_port_mapping;
  539. num_ports = &wcd939x->num_rx_ports;
  540. break;
  541. case CODEC_TX:
  542. map = &wcd939x->tx_port_mapping;
  543. num_ports = &wcd939x->num_tx_ports;
  544. break;
  545. default:
  546. dev_err(dev, "%s Invalid path selected %u\n",
  547. __func__, path);
  548. return -EINVAL;
  549. }
  550. if (!of_find_property(dev->of_node, prop,
  551. &map_size)) {
  552. dev_err(dev, "missing port mapping prop %s\n", prop);
  553. ret = -EINVAL;
  554. goto err_port_map;
  555. }
  556. map_length = map_size / (NUM_SWRS_DT_PARAMS * sizeof(u32));
  557. dt_array = kzalloc(map_size, GFP_KERNEL);
  558. if (!dt_array) {
  559. ret = -ENOMEM;
  560. goto err_alloc;
  561. }
  562. ret = of_property_read_u32_array(dev->of_node, prop, dt_array,
  563. NUM_SWRS_DT_PARAMS * map_length);
  564. if (ret) {
  565. dev_err(dev, "%s: Failed to read port mapping from prop %s\n",
  566. __func__, prop);
  567. goto err_pdata_fail;
  568. }
  569. for (i = 0; i < map_length; i++) {
  570. port_num = dt_array[NUM_SWRS_DT_PARAMS * i];
  571. slave_port_type = dt_array[NUM_SWRS_DT_PARAMS * i + 1];
  572. ch_mask = dt_array[NUM_SWRS_DT_PARAMS * i + 2];
  573. ch_rate = dt_array[NUM_SWRS_DT_PARAMS * i + 3];
  574. master_port_type = dt_array[NUM_SWRS_DT_PARAMS * i + 4];
  575. if (port_num != old_port_num)
  576. ch_iter = 0;
  577. (*map)[port_num][ch_iter].slave_port_type = slave_port_type;
  578. (*map)[port_num][ch_iter].ch_mask = ch_mask;
  579. (*map)[port_num][ch_iter].master_port_type = master_port_type;
  580. (*map)[port_num][ch_iter].num_ch = __sw_hweight8(ch_mask);
  581. (*map)[port_num][ch_iter++].ch_rate = ch_rate;
  582. old_port_num = port_num;
  583. }
  584. *num_ports = port_num;
  585. kfree(dt_array);
  586. return 0;
  587. err_pdata_fail:
  588. kfree(dt_array);
  589. err_alloc:
  590. err_port_map:
  591. return ret;
  592. }
  593. static int wcd939x_tx_connect_port(struct snd_soc_component *component,
  594. u8 slv_port_type, int clk_rate,
  595. u8 enable)
  596. {
  597. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  598. u8 port_id, num_ch, ch_mask;
  599. u8 ch_type = 0;
  600. u32 ch_rate;
  601. int slave_ch_idx;
  602. u8 num_port = 1;
  603. int ret = 0;
  604. ret = wcd939x_set_port_params(component, slv_port_type, &port_id,
  605. &num_ch, &ch_mask, &ch_rate,
  606. &ch_type, CODEC_TX);
  607. if (ret)
  608. return ret;
  609. if (clk_rate)
  610. ch_rate = clk_rate;
  611. slave_ch_idx = wcd939x_slave_get_slave_ch_val(slv_port_type);
  612. if (slave_ch_idx != -EINVAL)
  613. ch_type = wcd939x->tx_master_ch_map[slave_ch_idx];
  614. dev_dbg(component->dev, "%s slv_ch_idx: %d, mstr_ch_type: %d\n",
  615. __func__, slave_ch_idx, ch_type);
  616. if (enable)
  617. ret = swr_connect_port(wcd939x->tx_swr_dev, &port_id,
  618. num_port, &ch_mask, &ch_rate,
  619. &num_ch, &ch_type);
  620. else
  621. ret = swr_disconnect_port(wcd939x->tx_swr_dev, &port_id,
  622. num_port, &ch_mask, &ch_type);
  623. return ret;
  624. }
  625. static int wcd939x_rx_connect_port(struct snd_soc_component *component,
  626. u8 slv_port_type, u8 enable)
  627. {
  628. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  629. u8 port_id, num_ch, ch_mask, port_type;
  630. u32 ch_rate;
  631. u8 num_port = 1;
  632. int ret = 0;
  633. ret = wcd939x_set_port_params(component, slv_port_type, &port_id,
  634. &num_ch, &ch_mask, &ch_rate,
  635. &port_type, CODEC_RX);
  636. if (ret)
  637. return ret;
  638. if (enable)
  639. ret = swr_connect_port(wcd939x->rx_swr_dev, &port_id,
  640. num_port, &ch_mask, &ch_rate,
  641. &num_ch, &port_type);
  642. else
  643. ret = swr_disconnect_port(wcd939x->rx_swr_dev, &port_id,
  644. num_port, &ch_mask, &port_type);
  645. return ret;
  646. }
  647. static int wcd939x_rx_clk_enable(struct snd_soc_component *component)
  648. {
  649. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  650. if (wcd939x->rx_clk_cnt == 0) {
  651. snd_soc_component_update_bits(component,
  652. REG_FIELD_VALUE(RX_SUPPLIES, RX_BIAS_ENABLE, 0x01));
  653. /*Analog path clock controls*/
  654. snd_soc_component_update_bits(component,
  655. REG_FIELD_VALUE(CDC_ANA_CLK_CTL, ANA_RX_CLK_EN, 0x01));
  656. snd_soc_component_update_bits(component,
  657. REG_FIELD_VALUE(CDC_ANA_CLK_CTL, ANA_RX_DIV2_CLK_EN, 0x01));
  658. snd_soc_component_update_bits(component,
  659. REG_FIELD_VALUE(CDC_ANA_CLK_CTL, ANA_RX_DIV4_CLK_EN, 0x01));
  660. /*Digital path clock controls*/
  661. snd_soc_component_update_bits(component,
  662. REG_FIELD_VALUE(CDC_DIG_CLK_CTL, RXD0_CLK_EN, 0x01));
  663. snd_soc_component_update_bits(component,
  664. REG_FIELD_VALUE(CDC_DIG_CLK_CTL, RXD1_CLK_EN, 0x01));
  665. snd_soc_component_update_bits(component,
  666. REG_FIELD_VALUE(CDC_DIG_CLK_CTL, RXD2_CLK_EN, 0x01));
  667. }
  668. wcd939x->rx_clk_cnt++;
  669. return 0;
  670. }
  671. static int wcd939x_rx_clk_disable(struct snd_soc_component *component)
  672. {
  673. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  674. wcd939x->rx_clk_cnt--;
  675. if (wcd939x->rx_clk_cnt == 0) {
  676. snd_soc_component_update_bits(component,
  677. REG_FIELD_VALUE(RX_SUPPLIES, VNEG_EN, 0x00));
  678. snd_soc_component_update_bits(component,
  679. REG_FIELD_VALUE(RX_SUPPLIES, VPOS_EN, 0x00));
  680. snd_soc_component_update_bits(component,
  681. REG_FIELD_VALUE(CDC_DIG_CLK_CTL, RXD2_CLK_EN, 0x00));
  682. snd_soc_component_update_bits(component,
  683. REG_FIELD_VALUE(CDC_DIG_CLK_CTL, RXD1_CLK_EN, 0x00));
  684. snd_soc_component_update_bits(component,
  685. REG_FIELD_VALUE(CDC_DIG_CLK_CTL, RXD0_CLK_EN, 0x00));
  686. snd_soc_component_update_bits(component,
  687. REG_FIELD_VALUE(CDC_ANA_CLK_CTL, ANA_RX_DIV4_CLK_EN, 0x00));
  688. snd_soc_component_update_bits(component,
  689. REG_FIELD_VALUE(CDC_ANA_CLK_CTL, ANA_RX_DIV2_CLK_EN, 0x00));
  690. snd_soc_component_update_bits(component,
  691. REG_FIELD_VALUE(CDC_ANA_CLK_CTL, ANA_RX_CLK_EN, 0x00));
  692. snd_soc_component_update_bits(component,
  693. REG_FIELD_VALUE(RX_SUPPLIES, RX_BIAS_ENABLE, 0x00));
  694. }
  695. return 0;
  696. }
  697. /*
  698. * wcd939x_soc_get_mbhc: get wcd939x_mbhc handle of corresponding component
  699. * @component: handle to snd_soc_component *
  700. *
  701. * return wcd939x_mbhc handle or error code in case of failure
  702. */
  703. struct wcd939x_mbhc *wcd939x_soc_get_mbhc(struct snd_soc_component *component)
  704. {
  705. struct wcd939x_priv *wcd939x;
  706. if (!component) {
  707. pr_err_ratelimited("%s: Invalid params, NULL component\n", __func__);
  708. return NULL;
  709. }
  710. wcd939x = snd_soc_component_get_drvdata(component);
  711. if (!wcd939x) {
  712. pr_err_ratelimited("%s: wcd939x is NULL\n", __func__);
  713. return NULL;
  714. }
  715. return wcd939x->mbhc;
  716. }
  717. EXPORT_SYMBOL(wcd939x_soc_get_mbhc);
  718. static int wcd939x_config_power_mode(struct snd_soc_component *component,
  719. int event, int index, int mode)
  720. {
  721. switch (event) {
  722. case SND_SOC_DAPM_POST_PMU:
  723. if (mode == CLS_H_ULP) {
  724. if (index == WCD939X_HPHL) {
  725. snd_soc_component_update_bits(component,
  726. REG_FIELD_VALUE(CTL12, ZONE3_RMS, 0x21));
  727. snd_soc_component_update_bits(component,
  728. REG_FIELD_VALUE(CTL13, ZONE4_RMS, 0x30));
  729. snd_soc_component_update_bits(component,
  730. REG_FIELD_VALUE(CTL14, ZONE5_RMS, 0x3F));
  731. snd_soc_component_update_bits(component,
  732. REG_FIELD_VALUE(CTL15, ZONE6_RMS, 0x48));
  733. snd_soc_component_update_bits(component,
  734. REG_FIELD_VALUE(CTL17, PATH_GAIN, 0x0C));
  735. } else if (index == WCD939X_HPHR) {
  736. snd_soc_component_update_bits(component,
  737. REG_FIELD_VALUE(R_CTL12, ZONE3_RMS, 0x21));
  738. snd_soc_component_update_bits(component,
  739. REG_FIELD_VALUE(R_CTL13, ZONE4_RMS, 0x30));
  740. snd_soc_component_update_bits(component,
  741. REG_FIELD_VALUE(R_CTL14, ZONE5_RMS, 0x3F));
  742. snd_soc_component_update_bits(component,
  743. REG_FIELD_VALUE(R_CTL15, ZONE6_RMS, 0x48));
  744. snd_soc_component_update_bits(component,
  745. REG_FIELD_VALUE(R_CTL17, PATH_GAIN, 0x0C));
  746. }
  747. } else {
  748. if (index == WCD939X_HPHL) {
  749. snd_soc_component_update_bits(component,
  750. REG_FIELD_VALUE(CTL12, ZONE3_RMS, 0x1E));
  751. snd_soc_component_update_bits(component,
  752. REG_FIELD_VALUE(CTL13, ZONE4_RMS, 0x2A));
  753. snd_soc_component_update_bits(component,
  754. REG_FIELD_VALUE(CTL14, ZONE5_RMS, 0x36));
  755. snd_soc_component_update_bits(component,
  756. REG_FIELD_VALUE(CTL15, ZONE6_RMS, 0x3C));
  757. snd_soc_component_update_bits(component,
  758. REG_FIELD_VALUE(CTL17, PATH_GAIN, 0x00));
  759. } else if (index == WCD939X_HPHR) {
  760. snd_soc_component_update_bits(component,
  761. REG_FIELD_VALUE(R_CTL12, ZONE3_RMS, 0x1E));
  762. snd_soc_component_update_bits(component,
  763. REG_FIELD_VALUE(R_CTL13, ZONE4_RMS, 0x2A));
  764. snd_soc_component_update_bits(component,
  765. REG_FIELD_VALUE(R_CTL14, ZONE5_RMS, 0x36));
  766. snd_soc_component_update_bits(component,
  767. REG_FIELD_VALUE(R_CTL15, ZONE6_RMS, 0x2C));
  768. snd_soc_component_update_bits(component,
  769. REG_FIELD_VALUE(R_CTL17, PATH_GAIN, 0x00));
  770. }
  771. }
  772. }
  773. return 0;
  774. }
  775. static int wcd939x_enable_hph_pcm_index(struct snd_soc_component *component,
  776. int event, int hph)
  777. {
  778. struct wcd939x_priv *wcd939x = NULL;
  779. if (!component) {
  780. pr_err_ratelimited("%s: Invalid params, NULL component\n", __func__);
  781. return -EINVAL;
  782. }
  783. wcd939x = snd_soc_component_get_drvdata(component);
  784. if (!wcd939x->hph_pcm_enabled[hph])
  785. return 0;
  786. switch (event) {
  787. case SND_SOC_DAPM_POST_PMU:
  788. if (hph == WCD939X_HPHL) {
  789. snd_soc_component_update_bits(component,
  790. REG_FIELD_VALUE(HPHL_RX_PATH_CFG1,
  791. RX_DC_DROOP_COEFF_SEL, 0x3));
  792. snd_soc_component_update_bits(component,
  793. REG_FIELD_VALUE(HPHL_RX_PATH_CFG0,
  794. DLY_ZN_EN, 0x1));
  795. snd_soc_component_update_bits(component,
  796. REG_FIELD_VALUE(HPHL_RX_PATH_CFG0,
  797. INT_EN, 0x3));
  798. } else if (hph == WCD939X_HPHR) {
  799. snd_soc_component_update_bits(component,
  800. REG_FIELD_VALUE(HPHR_RX_PATH_CFG1,
  801. RX_DC_DROOP_COEFF_SEL, 0x3));
  802. snd_soc_component_update_bits(component,
  803. REG_FIELD_VALUE(HPHR_RX_PATH_CFG0,
  804. DLY_ZN_EN, 0x1));
  805. snd_soc_component_update_bits(component,
  806. REG_FIELD_VALUE(HPHR_RX_PATH_CFG0,
  807. INT_EN, 0x3));
  808. }
  809. break;
  810. case SND_SOC_DAPM_POST_PMD:
  811. break;
  812. }
  813. return 0;
  814. }
  815. static int wcd939x_config_compander(struct snd_soc_component *component,
  816. int event, int compander_indx)
  817. {
  818. u16 comp_coeff_lsb_reg = 0, comp_coeff_msb_reg = 0;
  819. u16 comp_ctl7_reg = 0, comp_ctl0_reg = 0;
  820. u16 comp_en_mask_val = 0;
  821. struct wcd939x_priv *wcd939x;
  822. int hph_mode;
  823. if (compander_indx >= WCD939X_HPH_MAX || compander_indx < 0) {
  824. pr_err_ratelimited("%s: Invalid compander value: %d\n",
  825. __func__, compander_indx);
  826. return -EINVAL;
  827. }
  828. if (!component) {
  829. pr_err_ratelimited("%s: Invalid params, NULL component\n", __func__);
  830. return -EINVAL;
  831. }
  832. wcd939x = snd_soc_component_get_drvdata(component);
  833. if (!wcd939x->compander_enabled[compander_indx])
  834. return 0;
  835. hph_mode = wcd939x->hph_mode;
  836. dev_dbg(component->dev, "%s compander_index = %d hph mode = %d\n",
  837. __func__, compander_indx, wcd939x->hph_mode);
  838. if (compander_indx == WCD939X_HPHL) {
  839. comp_coeff_lsb_reg = WCD939X_HPHL_COMP_WR_LSB;
  840. comp_coeff_msb_reg = WCD939X_HPHL_COMP_WR_MSB;
  841. comp_en_mask_val = 1 << 1;
  842. } else if (compander_indx == WCD939X_HPHR) {
  843. comp_coeff_lsb_reg = WCD939X_HPHR_COMP_WR_LSB;
  844. comp_coeff_msb_reg = WCD939X_HPHR_COMP_WR_MSB;
  845. comp_en_mask_val = 1 << 0;
  846. } else {
  847. return 0;
  848. }
  849. comp_ctl0_reg = WCD939X_CTL0 + (compander_indx * WCD939X_COMP_OFFSET);
  850. comp_ctl7_reg = WCD939X_CTL7 + (compander_indx * WCD939X_COMP_OFFSET);
  851. if (SND_SOC_DAPM_EVENT_ON(event)){
  852. snd_soc_component_update_bits(component,
  853. comp_ctl7_reg, 0x1E, 0x00);
  854. /* Enable compander clock*/
  855. snd_soc_component_update_bits(component,
  856. comp_ctl0_reg , 0x01, 0x01);
  857. /* 250us sleep required as per HW Sequence */
  858. usleep_range(250, 260);
  859. snd_soc_component_update_bits(component,
  860. comp_ctl0_reg , 0x02, 0x01);
  861. snd_soc_component_update_bits(component,
  862. comp_ctl0_reg , 0x02, 0x00);
  863. /* Compander coeff values are same for below modes */
  864. if (wcd939x->hph_mode == HPH_HIFI || wcd939x->hph_mode == HPH_LOHIFI
  865. || wcd939x->hph_mode == HPH_LP)
  866. hph_mode = 1;
  867. wcd939x_load_compander_coeff(component, comp_coeff_lsb_reg,
  868. comp_coeff_msb_reg, comp_coeff_table[hph_mode],
  869. COMP_MAX_COEFF);
  870. /* Enable compander*/
  871. snd_soc_component_update_bits(component,
  872. WCD939X_CDC_COMP_CTL_0, comp_en_mask_val, comp_en_mask_val);
  873. } if (SND_SOC_DAPM_EVENT_OFF(event)) {
  874. snd_soc_component_update_bits(component,
  875. WCD939X_CDC_COMP_CTL_0, comp_en_mask_val, 0x00);
  876. snd_soc_component_update_bits(component,
  877. comp_ctl0_reg , 0x01, 0x00);
  878. }
  879. return 0;
  880. }
  881. static int wcd939x_config_xtalk(struct snd_soc_component *component,
  882. int event, int xtalk_indx)
  883. {
  884. u16 xtalk_sec0 = 0, xtalk_sec1 = 0, xtalk_sec2 = 0, xtalk_sec3 = 0;
  885. struct wcd939x_priv *wcd939x = NULL;
  886. if (!component) {
  887. pr_err_ratelimited("%s: Invalid params, NULL component\n", __func__);
  888. return -EINVAL;
  889. }
  890. wcd939x = snd_soc_component_get_drvdata(component);
  891. if (!wcd939x->xtalk_enabled[xtalk_indx])
  892. return 0;
  893. dev_dbg(component->dev, "%s xtalk_indx = %d event = %d\n",
  894. __func__, xtalk_indx, event);
  895. switch(event) {
  896. case SND_SOC_DAPM_PRE_PMU:
  897. xtalk_sec0 = WCD939X_HPHL_RX_PATH_SEC0 + (xtalk_indx * WCD939X_XTALK_OFFSET);
  898. xtalk_sec1 = WCD939X_HPHL_RX_PATH_SEC1 + (xtalk_indx * WCD939X_XTALK_OFFSET);
  899. xtalk_sec2 = WCD939X_HPHL_RX_PATH_SEC2 + (xtalk_indx * WCD939X_XTALK_OFFSET);
  900. xtalk_sec3 = WCD939X_HPHL_RX_PATH_SEC3 + (xtalk_indx * WCD939X_XTALK_OFFSET);
  901. snd_soc_component_update_bits(component, xtalk_sec1, 0xFF, 0xFE);
  902. snd_soc_component_update_bits(component, xtalk_sec0, 0x1F, 0x06);
  903. snd_soc_component_update_bits(component, xtalk_sec3, 0xFF, 0x4F);
  904. snd_soc_component_update_bits(component, xtalk_sec2, 0x1F, 0x11);
  905. break;
  906. case SND_SOC_DAPM_POST_PMU:
  907. /* enable xtalk for L and R channels*/
  908. snd_soc_component_update_bits(component, WCD939X_RX_PATH_CFG2,
  909. 0x0F, 0x0F);
  910. break;
  911. case SND_SOC_DAPM_POST_PMD:
  912. /* Disable Xtalk for L and R channels*/
  913. snd_soc_component_update_bits(component, WCD939X_RX_PATH_CFG2,
  914. 0x00, 0x00);
  915. break;
  916. }
  917. return 0;
  918. }
  919. static int wcd939x_rx_mux(struct snd_soc_dapm_widget *w,
  920. struct snd_kcontrol *kcontrol,
  921. int event)
  922. {
  923. int hph_mode = 0;
  924. struct wcd939x_priv *wcd939x = NULL;
  925. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  926. wcd939x = snd_soc_component_get_drvdata(component);
  927. hph_mode = wcd939x->hph_mode;
  928. dev_dbg(component->dev, "%s event: %d wshift: %d wname: %s\n",
  929. __func__, event, w->shift, w->name);
  930. switch (event) {
  931. case SND_SOC_DAPM_PRE_PMU:
  932. wcd939x_rx_clk_enable(component);
  933. if (wcd939x->hph_pcm_enabled[w->shift])
  934. wcd939x_config_power_mode(component, event, w->shift, hph_mode);
  935. wcd939x_config_compander(component, event, w->shift);
  936. wcd939x_config_xtalk(component, event, w->shift);
  937. break;
  938. case SND_SOC_DAPM_POST_PMU:
  939. wcd939x_config_xtalk(component, event, w->shift);
  940. /*TBD: need to revisit , for both L & R we are updating, but in QCRG only once*/
  941. if (wcd939x->hph_pcm_enabled[w->shift])
  942. snd_soc_component_update_bits(component,
  943. REG_FIELD_VALUE(TOP_CFG0, HPH_DAC_RATE_SEL, 0x1));
  944. wcd939x_enable_hph_pcm_index(component, event, w->shift);
  945. break;
  946. case SND_SOC_DAPM_POST_PMD:
  947. wcd939x_config_xtalk(component, event, w->shift);
  948. wcd939x_config_compander(component, event, w->shift);
  949. wcd939x_rx_clk_disable(component);
  950. break;
  951. }
  952. return 0;
  953. }
  954. static int wcd939x_codec_hphl_dac_event(struct snd_soc_dapm_widget *w,
  955. struct snd_kcontrol *kcontrol,
  956. int event)
  957. {
  958. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  959. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  960. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  961. w->name, event);
  962. switch (event) {
  963. case SND_SOC_DAPM_PRE_PMU:
  964. snd_soc_component_update_bits(component,
  965. REG_FIELD_VALUE(RDAC_CLK_CTL1, OPAMP_CHOP_CLK_EN, 0x00));
  966. snd_soc_component_update_bits(component,
  967. REG_FIELD_VALUE(CDC_HPH_GAIN_CTL, HPHL_RX_EN, 0x01));
  968. break;
  969. case SND_SOC_DAPM_POST_PMU:
  970. if (!wcd939x->hph_pcm_enabled[WCD939X_HPHL]) {
  971. snd_soc_component_update_bits(component,
  972. REG_FIELD_VALUE(RDAC_HD2_CTL_L, HD2_RES_DIV_CTL_L, 0x0f));
  973. if (wcd939x->comp1_enable) {
  974. snd_soc_component_update_bits(component,
  975. REG_FIELD_VALUE(CDC_COMP_CTL_0, HPHL_COMP_EN, 0x01));
  976. /* 5msec compander delay as per HW requirement */
  977. if (!wcd939x->comp2_enable ||
  978. (snd_soc_component_read(component,
  979. WCD939X_CDC_COMP_CTL_0) & 0x01))
  980. usleep_range(5000, 5010);
  981. snd_soc_component_update_bits(component,
  982. REG_FIELD_VALUE(HPH_TIMER1, AUTOCHOP_TIMER_CTL_EN, 0x00));
  983. } else {
  984. snd_soc_component_update_bits(component,
  985. REG_FIELD_VALUE(CDC_COMP_CTL_0, HPHL_COMP_EN, 0x00));
  986. snd_soc_component_update_bits(component,
  987. REG_FIELD_VALUE(L_EN, GAIN_SOURCE_SEL, 0x01));
  988. }
  989. }
  990. break;
  991. case SND_SOC_DAPM_POST_PMD:
  992. if (!wcd939x->hph_pcm_enabled[WCD939X_HPHL])
  993. snd_soc_component_update_bits(component,
  994. REG_FIELD_VALUE(RDAC_HD2_CTL_L, HD2_RES_DIV_CTL_L, 0x01));
  995. snd_soc_component_update_bits(component,
  996. REG_FIELD_VALUE(CDC_HPH_GAIN_CTL, HPHL_RX_EN, 0x00));
  997. break;
  998. }
  999. return 0;
  1000. }
  1001. static int wcd939x_codec_hphr_dac_event(struct snd_soc_dapm_widget *w,
  1002. struct snd_kcontrol *kcontrol,
  1003. int event)
  1004. {
  1005. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  1006. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  1007. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1008. w->name, event);
  1009. switch (event) {
  1010. case SND_SOC_DAPM_PRE_PMU:
  1011. snd_soc_component_update_bits(component,
  1012. REG_FIELD_VALUE(RDAC_CLK_CTL1, OPAMP_CHOP_CLK_EN, 0x00));
  1013. snd_soc_component_update_bits(component,
  1014. REG_FIELD_VALUE(CDC_HPH_GAIN_CTL, HPHR_RX_EN, 0x01));
  1015. break;
  1016. case SND_SOC_DAPM_POST_PMU:
  1017. if (!wcd939x->hph_pcm_enabled[WCD939X_HPHR]) {
  1018. snd_soc_component_update_bits(component,
  1019. REG_FIELD_VALUE(RDAC_HD2_CTL_R, HD2_RES_DIV_CTL_R, 0x02));
  1020. if (wcd939x->comp1_enable) {
  1021. snd_soc_component_update_bits(component,
  1022. REG_FIELD_VALUE(CDC_COMP_CTL_0, HPHR_COMP_EN, 0x01));
  1023. /* 5msec compander delay as per HW requirement */
  1024. if (!wcd939x->comp2_enable ||
  1025. (snd_soc_component_read(component,
  1026. WCD939X_CDC_COMP_CTL_0) & 0x02))
  1027. usleep_range(5000, 5010);
  1028. snd_soc_component_update_bits(component,
  1029. REG_FIELD_VALUE(HPH_TIMER1, AUTOCHOP_TIMER_CTL_EN, 0x00));
  1030. } else {
  1031. snd_soc_component_update_bits(component,
  1032. REG_FIELD_VALUE(CDC_COMP_CTL_0, HPHR_COMP_EN, 0x00));
  1033. snd_soc_component_update_bits(component,
  1034. REG_FIELD_VALUE(R_EN, GAIN_SOURCE_SEL, 0x01));
  1035. }
  1036. }
  1037. break;
  1038. case SND_SOC_DAPM_POST_PMD:
  1039. if (!wcd939x->hph_pcm_enabled[WCD939X_HPHR])
  1040. snd_soc_component_update_bits(component,
  1041. REG_FIELD_VALUE(RDAC_HD2_CTL_R, HD2_RES_DIV_CTL_R, 0x01));
  1042. snd_soc_component_update_bits(component,
  1043. REG_FIELD_VALUE(CDC_HPH_GAIN_CTL, HPHR_RX_EN, 0x00));
  1044. break;
  1045. }
  1046. return 0;
  1047. }
  1048. static int wcd939x_codec_ear_dac_event(struct snd_soc_dapm_widget *w,
  1049. struct snd_kcontrol *kcontrol,
  1050. int event)
  1051. {
  1052. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  1053. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  1054. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1055. w->name, event);
  1056. switch (event) {
  1057. case SND_SOC_DAPM_PRE_PMU:
  1058. snd_soc_component_update_bits(component,
  1059. REG_FIELD_VALUE(CDC_EAR_GAIN_CTL, EAR_EN, 0x01));
  1060. snd_soc_component_update_bits(component,
  1061. REG_FIELD_VALUE(CDC_DIG_CLK_CTL, RXD0_CLK_EN, 0x01));
  1062. if (wcd939x->comp1_enable)
  1063. snd_soc_component_update_bits(component,
  1064. REG_FIELD_VALUE(CDC_COMP_CTL_0, HPHL_COMP_EN, 0x01));
  1065. /* 5 msec delay as per HW requirement */
  1066. usleep_range(5000, 5010);
  1067. if (wcd939x->flyback_cur_det_disable == 0)
  1068. snd_soc_component_update_bits(component,
  1069. REG_FIELD_VALUE(EN, EN_CUR_DET, 0x00));
  1070. wcd939x->flyback_cur_det_disable++;
  1071. wcd_cls_h_fsm(component, &wcd939x->clsh_info,
  1072. WCD_CLSH_EVENT_PRE_DAC,
  1073. WCD_CLSH_STATE_EAR,
  1074. wcd939x->hph_mode);
  1075. break;
  1076. case SND_SOC_DAPM_POST_PMD:
  1077. snd_soc_component_update_bits(component,
  1078. REG_FIELD_VALUE(CDC_COMP_CTL_0, HPHL_COMP_EN, 0x01));
  1079. snd_soc_component_update_bits(component,
  1080. REG_FIELD_VALUE(CDC_DIG_CLK_CTL, RXD0_CLK_EN, 0x00));
  1081. if (wcd939x->comp1_enable)
  1082. snd_soc_component_update_bits(component,
  1083. REG_FIELD_VALUE(CDC_COMP_CTL_0, HPHL_COMP_EN, 0x00));
  1084. snd_soc_component_update_bits(component,
  1085. REG_FIELD_VALUE(EAR_COMPANDER_CTL, GAIN_OVRD_REG, 0x00));
  1086. snd_soc_component_update_bits(component,
  1087. REG_FIELD_VALUE(EAR_DAC_CON, DAC_SAMPLE_EDGE_SEL, 0x01));
  1088. break;
  1089. };
  1090. return 0;
  1091. }
  1092. static int wcd939x_codec_enable_hphr_pa(struct snd_soc_dapm_widget *w,
  1093. struct snd_kcontrol *kcontrol,
  1094. int event)
  1095. {
  1096. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  1097. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  1098. int ret = 0;
  1099. int hph_mode = wcd939x->hph_mode;
  1100. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1101. w->name, event);
  1102. switch (event) {
  1103. case SND_SOC_DAPM_PRE_PMU:
  1104. if (wcd939x->ldoh)
  1105. snd_soc_component_update_bits(component,
  1106. REG_FIELD_VALUE(MODE, LDOH_EN, 0x01));
  1107. if (wcd939x->update_wcd_event)
  1108. wcd939x->update_wcd_event(wcd939x->handle,
  1109. SLV_BOLERO_EVT_RX_MUTE,
  1110. (WCD_RX2 << 0x10 | 0x1));
  1111. ret = swr_slvdev_datapath_control(wcd939x->rx_swr_dev,
  1112. wcd939x->rx_swr_dev->dev_num,
  1113. true);
  1114. wcd_cls_h_fsm(component, &wcd939x->clsh_info,
  1115. WCD_CLSH_EVENT_PRE_DAC,
  1116. WCD_CLSH_STATE_HPHR,
  1117. hph_mode);
  1118. wcd_clsh_set_hph_mode(component, CLS_H_HIFI);
  1119. if (hph_mode == CLS_H_LP || hph_mode == CLS_H_LOHIFI ||
  1120. hph_mode == CLS_H_ULP) {
  1121. snd_soc_component_update_bits(component,
  1122. REG_FIELD_VALUE(REFBUFF_LP_CTL, PREREF_FILT_BYPASS, 0x01));
  1123. }
  1124. snd_soc_component_update_bits(component,
  1125. REG_FIELD_VALUE(HPH, HPHR_REF_ENABLE, 0x01));
  1126. wcd_clsh_set_hph_mode(component, hph_mode);
  1127. /* 100 usec delay as per HW requirement */
  1128. usleep_range(100, 110);
  1129. set_bit(HPH_PA_DELAY, &wcd939x->status_mask);
  1130. snd_soc_component_update_bits(component,
  1131. REG_FIELD_VALUE(PDM_WD_CTL1, PDM_WD_EN, 0x03));
  1132. break;
  1133. case SND_SOC_DAPM_POST_PMU:
  1134. /*
  1135. * 7ms sleep is required if compander is enabled as per
  1136. * HW requirement. If compander is disabled, then
  1137. * 20ms delay is required.
  1138. */
  1139. if (test_bit(HPH_PA_DELAY, &wcd939x->status_mask)) {
  1140. if (!wcd939x->comp2_enable)
  1141. usleep_range(20000, 20100);
  1142. else
  1143. usleep_range(7000, 7100);
  1144. if (hph_mode == CLS_H_LP ||
  1145. hph_mode == CLS_H_LOHIFI ||
  1146. hph_mode == CLS_H_ULP)
  1147. snd_soc_component_update_bits(component,
  1148. REG_FIELD_VALUE(REFBUFF_LP_CTL, PREREF_FILT_BYPASS, 0x00));
  1149. clear_bit(HPH_PA_DELAY, &wcd939x->status_mask);
  1150. }
  1151. snd_soc_component_update_bits(component,
  1152. REG_FIELD_VALUE(HPH_TIMER1, AUTOCHOP_TIMER_CTL_EN, 0x01));
  1153. if (hph_mode == CLS_AB || hph_mode == CLS_AB_HIFI ||
  1154. hph_mode == CLS_AB_LP || hph_mode == CLS_AB_LOHIFI)
  1155. snd_soc_component_update_bits(component,
  1156. REG_FIELD_VALUE(RX_SUPPLIES, REGULATOR_MODE, 0x01));
  1157. if (wcd939x->update_wcd_event)
  1158. wcd939x->update_wcd_event(wcd939x->handle,
  1159. SLV_BOLERO_EVT_RX_MUTE,
  1160. (WCD_RX2 << 0x10));
  1161. wcd_enable_irq(&wcd939x->irq_info,
  1162. WCD939X_IRQ_HPHR_PDM_WD_INT);
  1163. break;
  1164. case SND_SOC_DAPM_PRE_PMD:
  1165. if (wcd939x->update_wcd_event)
  1166. wcd939x->update_wcd_event(wcd939x->handle,
  1167. SLV_BOLERO_EVT_RX_MUTE,
  1168. (WCD_RX2 << 0x10 | 0x1));
  1169. wcd_disable_irq(&wcd939x->irq_info,
  1170. WCD939X_IRQ_HPHR_PDM_WD_INT);
  1171. if (wcd939x->update_wcd_event && wcd939x->comp2_enable)
  1172. wcd939x->update_wcd_event(wcd939x->handle,
  1173. SLV_BOLERO_EVT_RX_COMPANDER_SOFT_RST,
  1174. (WCD_RX2 << 0x10));
  1175. /*
  1176. * 7ms sleep is required if compander is enabled as per
  1177. * HW requirement. If compander is disabled, then
  1178. * 20ms delay is required.
  1179. */
  1180. if (!wcd939x->comp2_enable)
  1181. usleep_range(20000, 20100);
  1182. else
  1183. usleep_range(7000, 7100);
  1184. snd_soc_component_update_bits(component,
  1185. REG_FIELD_VALUE(HPH, HPHR_ENABLE, 0x00));
  1186. blocking_notifier_call_chain(&wcd939x->mbhc->notifier,
  1187. WCD_EVENT_PRE_HPHR_PA_OFF,
  1188. &wcd939x->mbhc->wcd_mbhc);
  1189. set_bit(HPH_PA_DELAY, &wcd939x->status_mask);
  1190. break;
  1191. case SND_SOC_DAPM_POST_PMD:
  1192. /*
  1193. * 7ms sleep is required if compander is enabled as per
  1194. * HW requirement. If compander is disabled, then
  1195. * 20ms delay is required.
  1196. */
  1197. if (test_bit(HPH_PA_DELAY, &wcd939x->status_mask)) {
  1198. if (!wcd939x->comp2_enable)
  1199. usleep_range(20000, 20100);
  1200. else
  1201. usleep_range(7000, 7100);
  1202. clear_bit(HPH_PA_DELAY, &wcd939x->status_mask);
  1203. }
  1204. blocking_notifier_call_chain(&wcd939x->mbhc->notifier,
  1205. WCD_EVENT_POST_HPHR_PA_OFF,
  1206. &wcd939x->mbhc->wcd_mbhc);
  1207. snd_soc_component_update_bits(component,
  1208. REG_FIELD_VALUE(HPH, HPHR_REF_ENABLE, 0x00));
  1209. snd_soc_component_update_bits(component,
  1210. REG_FIELD_VALUE(PDM_WD_CTL1, PDM_WD_EN, 0x00));
  1211. wcd_cls_h_fsm(component, &wcd939x->clsh_info,
  1212. WCD_CLSH_EVENT_POST_PA,
  1213. WCD_CLSH_STATE_HPHR,
  1214. hph_mode);
  1215. if (wcd939x->ldoh)
  1216. snd_soc_component_update_bits(component,
  1217. REG_FIELD_VALUE(MODE, LDOH_EN, 0x00));
  1218. break;
  1219. };
  1220. return ret;
  1221. }
  1222. static int wcd939x_codec_enable_hphl_pa(struct snd_soc_dapm_widget *w,
  1223. struct snd_kcontrol *kcontrol,
  1224. int event)
  1225. {
  1226. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  1227. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  1228. int ret = 0;
  1229. int hph_mode = wcd939x->hph_mode;
  1230. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1231. w->name, event);
  1232. switch (event) {
  1233. case SND_SOC_DAPM_PRE_PMU:
  1234. if (wcd939x->ldoh)
  1235. snd_soc_component_update_bits(component,
  1236. REG_FIELD_VALUE(MODE, LDOH_EN, 0x01));
  1237. if (wcd939x->update_wcd_event)
  1238. wcd939x->update_wcd_event(wcd939x->handle,
  1239. SLV_BOLERO_EVT_RX_MUTE,
  1240. (WCD_RX1 << 0x10 | 0x01));
  1241. ret = swr_slvdev_datapath_control(wcd939x->rx_swr_dev,
  1242. wcd939x->rx_swr_dev->dev_num,
  1243. true);
  1244. wcd_cls_h_fsm(component, &wcd939x->clsh_info,
  1245. WCD_CLSH_EVENT_PRE_DAC,
  1246. WCD_CLSH_STATE_HPHL,
  1247. hph_mode);
  1248. wcd_clsh_set_hph_mode(component, CLS_H_HIFI);
  1249. if (hph_mode == CLS_H_LP || hph_mode == CLS_H_LOHIFI ||
  1250. hph_mode == CLS_H_ULP) {
  1251. snd_soc_component_update_bits(component,
  1252. REG_FIELD_VALUE(REFBUFF_LP_CTL, PREREF_FILT_BYPASS, 0x01));
  1253. }
  1254. snd_soc_component_update_bits(component,
  1255. REG_FIELD_VALUE(HPH, HPHL_REF_ENABLE, 0x01));
  1256. wcd_clsh_set_hph_mode(component, hph_mode);
  1257. /* 100 usec delay as per HW requirement */
  1258. usleep_range(100, 110);
  1259. set_bit(HPH_PA_DELAY, &wcd939x->status_mask);
  1260. snd_soc_component_update_bits(component,
  1261. REG_FIELD_VALUE(PDM_WD_CTL0, PDM_WD_EN, 0x03));
  1262. break;
  1263. case SND_SOC_DAPM_POST_PMU:
  1264. /*
  1265. * 7ms sleep is required if compander is enabled as per
  1266. * HW requirement. If compander is disabled, then
  1267. * 20ms delay is required.
  1268. */
  1269. if (test_bit(HPH_PA_DELAY, &wcd939x->status_mask)) {
  1270. if (!wcd939x->comp1_enable)
  1271. usleep_range(20000, 20100);
  1272. else
  1273. usleep_range(7000, 7100);
  1274. if (hph_mode == CLS_H_LP ||
  1275. hph_mode == CLS_H_LOHIFI ||
  1276. hph_mode == CLS_H_ULP)
  1277. snd_soc_component_update_bits(component,
  1278. REG_FIELD_VALUE(REFBUFF_LP_CTL, PREREF_FILT_BYPASS, 0x00));
  1279. clear_bit(HPH_PA_DELAY, &wcd939x->status_mask);
  1280. }
  1281. snd_soc_component_update_bits(component,
  1282. REG_FIELD_VALUE(HPH_TIMER1, AUTOCHOP_TIMER_CTL_EN, 0x01));
  1283. if (hph_mode == CLS_AB || hph_mode == CLS_AB_HIFI ||
  1284. hph_mode == CLS_AB_LP || hph_mode == CLS_AB_LOHIFI)
  1285. snd_soc_component_update_bits(component,
  1286. REG_FIELD_VALUE(RX_SUPPLIES, REGULATOR_MODE, 0x01));
  1287. if (wcd939x->update_wcd_event)
  1288. wcd939x->update_wcd_event(wcd939x->handle,
  1289. SLV_BOLERO_EVT_RX_MUTE,
  1290. (WCD_RX1 << 0x10));
  1291. wcd_enable_irq(&wcd939x->irq_info,
  1292. WCD939X_IRQ_HPHL_PDM_WD_INT);
  1293. break;
  1294. case SND_SOC_DAPM_PRE_PMD:
  1295. if (wcd939x->update_wcd_event)
  1296. wcd939x->update_wcd_event(wcd939x->handle,
  1297. SLV_BOLERO_EVT_RX_MUTE,
  1298. (WCD_RX1 << 0x10 | 0x1));
  1299. wcd_disable_irq(&wcd939x->irq_info,
  1300. WCD939X_IRQ_HPHL_PDM_WD_INT);
  1301. if (wcd939x->update_wcd_event && wcd939x->comp1_enable)
  1302. wcd939x->update_wcd_event(wcd939x->handle,
  1303. SLV_BOLERO_EVT_RX_COMPANDER_SOFT_RST,
  1304. (WCD_RX1 << 0x10));
  1305. /*
  1306. * 7ms sleep is required if compander is enabled as per
  1307. * HW requirement. If compander is disabled, then
  1308. * 20ms delay is required.
  1309. */
  1310. if (!wcd939x->comp1_enable)
  1311. usleep_range(20000, 20100);
  1312. else
  1313. usleep_range(7000, 7100);
  1314. snd_soc_component_update_bits(component,
  1315. REG_FIELD_VALUE(HPH, HPHL_ENABLE, 0x00));
  1316. blocking_notifier_call_chain(&wcd939x->mbhc->notifier,
  1317. WCD_EVENT_PRE_HPHL_PA_OFF,
  1318. &wcd939x->mbhc->wcd_mbhc);
  1319. set_bit(HPH_PA_DELAY, &wcd939x->status_mask);
  1320. break;
  1321. case SND_SOC_DAPM_POST_PMD:
  1322. /*
  1323. * 7ms sleep is required if compander is enabled as per
  1324. * HW requirement. If compander is disabled, then
  1325. * 20ms delay is required.
  1326. */
  1327. if (test_bit(HPH_PA_DELAY, &wcd939x->status_mask)) {
  1328. if (!wcd939x->comp1_enable)
  1329. usleep_range(21000, 21100);
  1330. else
  1331. usleep_range(7000, 7100);
  1332. clear_bit(HPH_PA_DELAY, &wcd939x->status_mask);
  1333. }
  1334. blocking_notifier_call_chain(&wcd939x->mbhc->notifier,
  1335. WCD_EVENT_POST_HPHL_PA_OFF,
  1336. &wcd939x->mbhc->wcd_mbhc);
  1337. snd_soc_component_update_bits(component,
  1338. REG_FIELD_VALUE(HPH, HPHL_REF_ENABLE, 0x00));
  1339. snd_soc_component_update_bits(component,
  1340. REG_FIELD_VALUE(PDM_WD_CTL0, PDM_WD_EN, 0x00));
  1341. wcd_cls_h_fsm(component, &wcd939x->clsh_info,
  1342. WCD_CLSH_EVENT_POST_PA,
  1343. WCD_CLSH_STATE_HPHL,
  1344. hph_mode);
  1345. if (wcd939x->ldoh)
  1346. snd_soc_component_update_bits(component,
  1347. REG_FIELD_VALUE(MODE, LDOH_EN, 0x00));
  1348. break;
  1349. };
  1350. return ret;
  1351. }
  1352. static int wcd939x_codec_enable_ear_pa(struct snd_soc_dapm_widget *w,
  1353. struct snd_kcontrol *kcontrol,
  1354. int event)
  1355. {
  1356. struct snd_soc_component *component =
  1357. snd_soc_dapm_to_component(w->dapm);
  1358. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  1359. int hph_mode = wcd939x->hph_mode;
  1360. int ret = 0;
  1361. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1362. w->name, event);
  1363. switch (event) {
  1364. case SND_SOC_DAPM_PRE_PMU:
  1365. ret = swr_slvdev_datapath_control(wcd939x->rx_swr_dev,
  1366. wcd939x->rx_swr_dev->dev_num,
  1367. true);
  1368. /*
  1369. * Enable watchdog interrupt for HPHL
  1370. */
  1371. snd_soc_component_update_bits(component,
  1372. REG_FIELD_VALUE(PDM_WD_CTL0, PDM_WD_EN, 0x03));
  1373. if (!wcd939x->comp1_enable)
  1374. snd_soc_component_update_bits(component,
  1375. REG_FIELD_VALUE(EAR_COMPANDER_CTL, GAIN_OVRD_REG, 0x01));
  1376. break;
  1377. case SND_SOC_DAPM_POST_PMU:
  1378. /* 6 msec delay as per HW requirement */
  1379. usleep_range(6000, 6010);
  1380. if (hph_mode == CLS_AB || hph_mode == CLS_AB_HIFI ||
  1381. hph_mode == CLS_AB_LP || hph_mode == CLS_AB_LOHIFI)
  1382. snd_soc_component_update_bits(component,
  1383. REG_FIELD_VALUE(RX_SUPPLIES, REGULATOR_MODE, 0x01));
  1384. if (wcd939x->update_wcd_event)
  1385. wcd939x->update_wcd_event(wcd939x->handle,
  1386. SLV_BOLERO_EVT_RX_MUTE,
  1387. (WCD_RX1 << 0x10));
  1388. wcd_enable_irq(&wcd939x->irq_info,
  1389. WCD939X_IRQ_EAR_PDM_WD_INT);
  1390. break;
  1391. case SND_SOC_DAPM_PRE_PMD:
  1392. wcd_disable_irq(&wcd939x->irq_info,
  1393. WCD939X_IRQ_EAR_PDM_WD_INT);
  1394. if (wcd939x->update_wcd_event)
  1395. wcd939x->update_wcd_event(wcd939x->handle,
  1396. SLV_BOLERO_EVT_RX_MUTE,
  1397. (WCD_RX1 << 0x10 | 0x1));
  1398. break;
  1399. case SND_SOC_DAPM_POST_PMD:
  1400. if (!wcd939x->comp1_enable)
  1401. snd_soc_component_update_bits(component,
  1402. REG_FIELD_VALUE(EAR_COMPANDER_CTL, GAIN_OVRD_REG, 0x00));
  1403. /* 7 msec delay as per HW requirement */
  1404. usleep_range(7000, 7010);
  1405. snd_soc_component_update_bits(component,
  1406. REG_FIELD_VALUE(PDM_WD_CTL0, PDM_WD_EN, 0x00));
  1407. wcd_cls_h_fsm(component, &wcd939x->clsh_info,
  1408. WCD_CLSH_EVENT_POST_PA,
  1409. WCD_CLSH_STATE_EAR,
  1410. hph_mode);
  1411. wcd939x->flyback_cur_det_disable--;
  1412. if (wcd939x->flyback_cur_det_disable == 0)
  1413. snd_soc_component_update_bits(component,
  1414. REG_FIELD_VALUE(EN, EN_CUR_DET, 0x01));
  1415. break;
  1416. };
  1417. return ret;
  1418. }
  1419. static int wcd939x_enable_clsh(struct snd_soc_dapm_widget *w,
  1420. struct snd_kcontrol *kcontrol,
  1421. int event)
  1422. {
  1423. struct snd_soc_component *component =
  1424. snd_soc_dapm_to_component(w->dapm);
  1425. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  1426. int mode = wcd939x->hph_mode;
  1427. int ret = 0;
  1428. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1429. w->name, event);
  1430. if (mode == CLS_H_LOHIFI || mode == CLS_H_ULP ||
  1431. mode == CLS_H_HIFI || mode == CLS_H_LP) {
  1432. wcd939x_rx_connect_port(component, CLSH,
  1433. SND_SOC_DAPM_EVENT_ON(event));
  1434. }
  1435. if (SND_SOC_DAPM_EVENT_OFF(event))
  1436. ret = swr_slvdev_datapath_control(
  1437. wcd939x->rx_swr_dev,
  1438. wcd939x->rx_swr_dev->dev_num,
  1439. false);
  1440. return ret;
  1441. }
  1442. static int wcd939x_enable_rx1(struct snd_soc_dapm_widget *w,
  1443. struct snd_kcontrol *kcontrol,
  1444. int event)
  1445. {
  1446. struct snd_soc_component *component =
  1447. snd_soc_dapm_to_component(w->dapm);
  1448. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  1449. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1450. w->name, event);
  1451. switch (event) {
  1452. case SND_SOC_DAPM_PRE_PMU:
  1453. if (wcd939x->hph_pcm_enabled[WCD939X_HPHL])
  1454. wcd939x_rx_connect_port(component, HIFI_PCM_L, true);
  1455. else {
  1456. wcd939x_rx_connect_port(component, HPH_L, true);
  1457. if (wcd939x->comp1_enable)
  1458. wcd939x_rx_connect_port(component, COMP_L, true);
  1459. }
  1460. break;
  1461. case SND_SOC_DAPM_POST_PMD:
  1462. if (wcd939x->hph_pcm_enabled[WCD939X_HPHL])
  1463. wcd939x_rx_connect_port(component, HIFI_PCM_L, false);
  1464. else {
  1465. wcd939x_rx_connect_port(component, HPH_L, false);
  1466. if (wcd939x->comp1_enable)
  1467. wcd939x_rx_connect_port(component, COMP_L, false);
  1468. }
  1469. break;
  1470. };
  1471. return 0;
  1472. }
  1473. static int wcd939x_enable_rx2(struct snd_soc_dapm_widget *w,
  1474. struct snd_kcontrol *kcontrol, int event)
  1475. {
  1476. struct snd_soc_component *component =
  1477. snd_soc_dapm_to_component(w->dapm);
  1478. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  1479. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1480. w->name, event);
  1481. switch (event) {
  1482. case SND_SOC_DAPM_PRE_PMU:
  1483. if (wcd939x->hph_pcm_enabled[WCD939X_HPHR])
  1484. wcd939x_rx_connect_port(component, HIFI_PCM_R, true);
  1485. else {
  1486. wcd939x_rx_connect_port(component, HPH_R, true);
  1487. if (wcd939x->comp2_enable)
  1488. wcd939x_rx_connect_port(component, COMP_R, true);
  1489. }
  1490. break;
  1491. case SND_SOC_DAPM_POST_PMD:
  1492. if (wcd939x->hph_pcm_enabled[WCD939X_HPHR])
  1493. wcd939x_rx_connect_port(component, HIFI_PCM_R, false);
  1494. else {
  1495. wcd939x_rx_connect_port(component, HPH_R, false);
  1496. if (wcd939x->comp2_enable)
  1497. wcd939x_rx_connect_port(component, COMP_R, false);
  1498. }
  1499. break;
  1500. };
  1501. return 0;
  1502. }
  1503. static int wcd939x_enable_rx3(struct snd_soc_dapm_widget *w,
  1504. struct snd_kcontrol *kcontrol,
  1505. int event)
  1506. {
  1507. struct snd_soc_component *component =
  1508. snd_soc_dapm_to_component(w->dapm);
  1509. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1510. w->name, event);
  1511. switch (event) {
  1512. case SND_SOC_DAPM_PRE_PMU:
  1513. wcd939x_rx_connect_port(component, LO, true);
  1514. break;
  1515. case SND_SOC_DAPM_POST_PMD:
  1516. wcd939x_rx_connect_port(component, LO, false);
  1517. /* 6 msec delay as per HW requirement */
  1518. usleep_range(6000, 6010);
  1519. break;
  1520. }
  1521. return 0;
  1522. }
  1523. static int wcd939x_codec_enable_dmic(struct snd_soc_dapm_widget *w,
  1524. struct snd_kcontrol *kcontrol,
  1525. int event)
  1526. {
  1527. struct snd_soc_component *component =
  1528. snd_soc_dapm_to_component(w->dapm);
  1529. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  1530. u16 dmic_clk_reg, dmic_clk_en_reg;
  1531. s32 *dmic_clk_cnt;
  1532. u8 dmic_ctl_shift = 0;
  1533. u8 dmic_clk_shift = 0;
  1534. u8 dmic_clk_mask = 0;
  1535. u16 dmic2_left_en = 0;
  1536. int ret = 0;
  1537. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1538. w->name, event);
  1539. switch (w->shift) {
  1540. case 0:
  1541. case 1:
  1542. dmic_clk_cnt = &(wcd939x->dmic_0_1_clk_cnt);
  1543. dmic_clk_reg = WCD939X_CDC_DMIC_RATE_1_2;
  1544. dmic_clk_en_reg = WCD939X_CDC_DMIC1_CTL;
  1545. dmic_clk_mask = 0x0F;
  1546. dmic_clk_shift = 0x00;
  1547. dmic_ctl_shift = 0x00;
  1548. break;
  1549. case 2:
  1550. dmic2_left_en = WCD939X_CDC_DMIC2_CTL;
  1551. fallthrough;
  1552. case 3:
  1553. dmic_clk_cnt = &(wcd939x->dmic_2_3_clk_cnt);
  1554. dmic_clk_reg = WCD939X_CDC_DMIC_RATE_1_2;
  1555. dmic_clk_en_reg = WCD939X_CDC_DMIC2_CTL;
  1556. dmic_clk_mask = 0xF0;
  1557. dmic_clk_shift = 0x04;
  1558. dmic_ctl_shift = 0x01;
  1559. break;
  1560. case 4:
  1561. case 5:
  1562. dmic_clk_cnt = &(wcd939x->dmic_4_5_clk_cnt);
  1563. dmic_clk_reg = WCD939X_CDC_DMIC_RATE_3_4;
  1564. dmic_clk_en_reg = WCD939X_CDC_DMIC3_CTL;
  1565. dmic_clk_mask = 0x0F;
  1566. dmic_clk_shift = 0x00;
  1567. dmic_ctl_shift = 0x02;
  1568. break;
  1569. case 6:
  1570. case 7:
  1571. dmic_clk_cnt = &(wcd939x->dmic_6_7_clk_cnt);
  1572. dmic_clk_reg = WCD939X_CDC_DMIC_RATE_3_4;
  1573. dmic_clk_en_reg = WCD939X_CDC_DMIC4_CTL;
  1574. dmic_clk_mask = 0xF0;
  1575. dmic_clk_shift = 0x04;
  1576. dmic_ctl_shift = 0x03;
  1577. break;
  1578. default:
  1579. dev_err_ratelimited(component->dev, "%s: Invalid DMIC Selection\n",
  1580. __func__);
  1581. return -EINVAL;
  1582. };
  1583. dev_dbg(component->dev, "%s: event %d DMIC%d dmic_clk_cnt %d\n",
  1584. __func__, event, (w->shift +1), *dmic_clk_cnt);
  1585. switch (event) {
  1586. case SND_SOC_DAPM_PRE_PMU:
  1587. snd_soc_component_update_bits(component,
  1588. WCD939X_CDC_AMIC_CTL,
  1589. (0x01 << dmic_ctl_shift), 0x00);
  1590. /* 250us sleep as per HW requirement */
  1591. usleep_range(250, 260);
  1592. if (dmic2_left_en)
  1593. snd_soc_component_update_bits(component,
  1594. dmic2_left_en, 0x80, 0x80);
  1595. /* Setting DMIC clock rate to 2.4MHz */
  1596. snd_soc_component_update_bits(component,
  1597. dmic_clk_reg, dmic_clk_mask,
  1598. (0x03 << dmic_clk_shift));
  1599. snd_soc_component_update_bits(component,
  1600. dmic_clk_en_reg, 0x08, 0x08);
  1601. /* enable clock scaling */
  1602. snd_soc_component_update_bits(component,
  1603. REG_FIELD_VALUE(CDC_DMIC_CTL, CLK_SCALE_EN, 0x01));
  1604. snd_soc_component_update_bits(component,
  1605. REG_FIELD_VALUE(CDC_DMIC_CTL, DMIC_DIV_BAK_EN, 0x01));
  1606. ret = swr_slvdev_datapath_control(wcd939x->tx_swr_dev,
  1607. wcd939x->tx_swr_dev->dev_num,
  1608. true);
  1609. break;
  1610. case SND_SOC_DAPM_POST_PMD:
  1611. wcd939x_tx_connect_port(component, DMIC0 + (w->shift), 0,
  1612. false);
  1613. snd_soc_component_update_bits(component,
  1614. WCD939X_CDC_AMIC_CTL,
  1615. (0x01 << dmic_ctl_shift),
  1616. (0x01 << dmic_ctl_shift));
  1617. if (dmic2_left_en)
  1618. snd_soc_component_update_bits(component,
  1619. dmic2_left_en, 0x80, 0x00);
  1620. snd_soc_component_update_bits(component,
  1621. dmic_clk_en_reg, 0x08, 0x00);
  1622. break;
  1623. };
  1624. return ret;
  1625. }
  1626. /*
  1627. * wcd939x_get_micb_vout_ctl_val: converts micbias from volts to register value
  1628. * @micb_mv: micbias in mv
  1629. *
  1630. * return register value converted
  1631. */
  1632. int wcd939x_get_micb_vout_ctl_val(u32 micb_mv)
  1633. {
  1634. /* min micbias voltage is 1V and maximum is 2.85V */
  1635. if (micb_mv < 1000 || micb_mv > 2850) {
  1636. pr_err_ratelimited("%s: unsupported micbias voltage\n", __func__);
  1637. return -EINVAL;
  1638. }
  1639. return (micb_mv - 1000) / 50;
  1640. }
  1641. EXPORT_SYMBOL(wcd939x_get_micb_vout_ctl_val);
  1642. /*
  1643. * wcd939x_mbhc_micb_adjust_voltage: adjust specific micbias voltage
  1644. * @component: handle to snd_soc_component *
  1645. * @req_volt: micbias voltage to be set
  1646. * @micb_num: micbias to be set, e.g. micbias1 or micbias2
  1647. *
  1648. * return 0 if adjustment is success or error code in case of failure
  1649. */
  1650. int wcd939x_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
  1651. int req_volt, int micb_num)
  1652. {
  1653. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  1654. int cur_vout_ctl, req_vout_ctl;
  1655. int micb_reg, micb_val, micb_en;
  1656. int ret = 0;
  1657. switch (micb_num) {
  1658. case MIC_BIAS_1:
  1659. micb_reg = WCD939X_MICB1;
  1660. break;
  1661. case MIC_BIAS_2:
  1662. micb_reg = WCD939X_MICB2;
  1663. break;
  1664. case MIC_BIAS_3:
  1665. micb_reg = WCD939X_MICB3;
  1666. break;
  1667. case MIC_BIAS_4:
  1668. micb_reg = WCD939X_MICB4;
  1669. break;
  1670. default:
  1671. return -EINVAL;
  1672. }
  1673. mutex_lock(&wcd939x->micb_lock);
  1674. /*
  1675. * If requested micbias voltage is same as current micbias
  1676. * voltage, then just return. Otherwise, adjust voltage as
  1677. * per requested value. If micbias is already enabled, then
  1678. * to avoid slow micbias ramp-up or down enable pull-up
  1679. * momentarily, change the micbias value and then re-enable
  1680. * micbias.
  1681. */
  1682. micb_val = snd_soc_component_read(component, micb_reg);
  1683. micb_en = (micb_val & 0xC0) >> 6;
  1684. cur_vout_ctl = micb_val & 0x3F;
  1685. req_vout_ctl = wcd939x_get_micb_vout_ctl_val(req_volt);
  1686. if (req_vout_ctl < 0) {
  1687. ret = -EINVAL;
  1688. goto exit;
  1689. }
  1690. if (cur_vout_ctl == req_vout_ctl) {
  1691. ret = 0;
  1692. goto exit;
  1693. }
  1694. dev_dbg(component->dev, "%s: micb_num: %d, cur_mv: %d, req_mv: %d, micb_en: %d\n",
  1695. __func__, micb_num, WCD_VOUT_CTL_TO_MICB(cur_vout_ctl),
  1696. req_volt, micb_en);
  1697. if (micb_en == 0x1)
  1698. snd_soc_component_update_bits(component, micb_reg, 0xC0, 0x80);
  1699. snd_soc_component_update_bits(component, micb_reg, 0x3F, req_vout_ctl);
  1700. if (micb_en == 0x1) {
  1701. snd_soc_component_update_bits(component, micb_reg, 0xC0, 0x40);
  1702. /*
  1703. * Add 2ms delay as per HW requirement after enabling
  1704. * micbias
  1705. */
  1706. usleep_range(2000, 2100);
  1707. }
  1708. exit:
  1709. mutex_unlock(&wcd939x->micb_lock);
  1710. return ret;
  1711. }
  1712. EXPORT_SYMBOL(wcd939x_mbhc_micb_adjust_voltage);
  1713. static int wcd939x_tx_swr_ctrl(struct snd_soc_dapm_widget *w,
  1714. struct snd_kcontrol *kcontrol,
  1715. int event)
  1716. {
  1717. struct snd_soc_component *component =
  1718. snd_soc_dapm_to_component(w->dapm);
  1719. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  1720. int ret = 0;
  1721. int bank = 0;
  1722. u8 mode = 0;
  1723. int i = 0;
  1724. int rate = 0;
  1725. bank = (wcd939x_swr_slv_get_current_bank(wcd939x->tx_swr_dev,
  1726. wcd939x->tx_swr_dev->dev_num) ? 0 : 1);
  1727. /* power mode is applicable only to analog mics */
  1728. if (strnstr(w->name, "ADC", sizeof("ADC"))) {
  1729. /* Get channel rate */
  1730. rate = wcd939x_get_clk_rate(wcd939x->tx_mode[w->shift - ADC1]);
  1731. }
  1732. switch (event) {
  1733. case SND_SOC_DAPM_PRE_PMU:
  1734. /* Check AMIC2 is connected to ADC2 to take an action on BCS */
  1735. if (w->shift == ADC2 &&
  1736. (((snd_soc_component_read(component, WCD939X_TX_CH12_MUX) &
  1737. 0x38) >> 3) == 0x2)) {
  1738. if (!wcd939x->bcs_dis) {
  1739. wcd939x_tx_connect_port(component, MBHC,
  1740. SWR_CLK_RATE_4P8MHZ, true);
  1741. set_bit(AMIC2_BCS_ENABLE, &wcd939x->status_mask);
  1742. }
  1743. }
  1744. if (strnstr(w->name, "ADC", sizeof("ADC"))) {
  1745. set_bit(w->shift - ADC1, &wcd939x->status_mask);
  1746. wcd939x_tx_connect_port(component, w->shift, rate,
  1747. true);
  1748. } else {
  1749. wcd939x_tx_connect_port(component, w->shift,
  1750. SWR_CLK_RATE_2P4MHZ, true);
  1751. }
  1752. break;
  1753. case SND_SOC_DAPM_POST_PMD:
  1754. if (strnstr(w->name, "ADC", sizeof("ADC"))) {
  1755. if (strnstr(w->name, "ADC1", sizeof("ADC1"))) {
  1756. clear_bit(WCD_ADC1, &wcd939x->status_mask);
  1757. clear_bit(WCD_ADC1_MODE, &wcd939x->status_mask);
  1758. } else if (strnstr(w->name, "ADC2", sizeof("ADC2"))) {
  1759. clear_bit(WCD_ADC2, &wcd939x->status_mask);
  1760. clear_bit(WCD_ADC2_MODE, &wcd939x->status_mask);
  1761. } else if (strnstr(w->name, "ADC3", sizeof("ADC3"))) {
  1762. clear_bit(WCD_ADC3, &wcd939x->status_mask);
  1763. clear_bit(WCD_ADC3_MODE, &wcd939x->status_mask);
  1764. } else if (strnstr(w->name, "ADC4", sizeof("ADC4"))) {
  1765. clear_bit(WCD_ADC4, &wcd939x->status_mask);
  1766. clear_bit(WCD_ADC4_MODE, &wcd939x->status_mask);
  1767. }
  1768. }
  1769. if (strnstr(w->name, "ADC", sizeof("ADC"))) {
  1770. if (test_bit(WCD_ADC1, &wcd939x->status_mask) ||
  1771. test_bit(WCD_ADC1_MODE, &wcd939x->status_mask))
  1772. mode |= tx_mode_bit[wcd939x->tx_mode[WCD_ADC1]];
  1773. if (test_bit(WCD_ADC2, &wcd939x->status_mask) ||
  1774. test_bit(WCD_ADC2_MODE, &wcd939x->status_mask))
  1775. mode |= tx_mode_bit[wcd939x->tx_mode[WCD_ADC2]];
  1776. if (test_bit(WCD_ADC3, &wcd939x->status_mask) ||
  1777. test_bit(WCD_ADC3_MODE, &wcd939x->status_mask))
  1778. mode |= tx_mode_bit[wcd939x->tx_mode[WCD_ADC3]];
  1779. if (test_bit(WCD_ADC4, &wcd939x->status_mask) ||
  1780. test_bit(WCD_ADC4_MODE, &wcd939x->status_mask))
  1781. mode |= tx_mode_bit[wcd939x->tx_mode[WCD_ADC4]];
  1782. if (mode != 0) {
  1783. for (i = 0; i < ADC_MODE_ULP2; i++) {
  1784. if (mode & (1 << i)) {
  1785. i++;
  1786. break;
  1787. }
  1788. }
  1789. }
  1790. rate = wcd939x_get_clk_rate(i);
  1791. if (wcd939x->adc_count) {
  1792. rate = (wcd939x->adc_count * rate);
  1793. if (rate > SWR_CLK_RATE_9P6MHZ)
  1794. rate = SWR_CLK_RATE_9P6MHZ;
  1795. }
  1796. wcd939x_set_swr_clk_rate(component, rate, bank);
  1797. }
  1798. ret = swr_slvdev_datapath_control(wcd939x->tx_swr_dev,
  1799. wcd939x->tx_swr_dev->dev_num,
  1800. false);
  1801. if (strnstr(w->name, "ADC", sizeof("ADC")))
  1802. wcd939x_set_swr_clk_rate(component, rate, !bank);
  1803. break;
  1804. };
  1805. return ret;
  1806. }
  1807. static int wcd939x_get_adc_mode(int val)
  1808. {
  1809. int ret = 0;
  1810. switch (val) {
  1811. case ADC_MODE_INVALID:
  1812. ret = ADC_MODE_VAL_NORMAL;
  1813. break;
  1814. case ADC_MODE_HIFI:
  1815. ret = ADC_MODE_VAL_HIFI;
  1816. break;
  1817. case ADC_MODE_LO_HIF:
  1818. ret = ADC_MODE_VAL_LO_HIF;
  1819. break;
  1820. case ADC_MODE_NORMAL:
  1821. ret = ADC_MODE_VAL_NORMAL;
  1822. break;
  1823. case ADC_MODE_LP:
  1824. ret = ADC_MODE_VAL_LP;
  1825. break;
  1826. case ADC_MODE_ULP1:
  1827. ret = ADC_MODE_VAL_ULP1;
  1828. break;
  1829. case ADC_MODE_ULP2:
  1830. ret = ADC_MODE_VAL_ULP2;
  1831. break;
  1832. default:
  1833. ret = -EINVAL;
  1834. pr_err_ratelimited("%s: invalid ADC mode value %d\n", __func__, val);
  1835. break;
  1836. }
  1837. return ret;
  1838. }
  1839. int wcd939x_tx_channel_config(struct snd_soc_component *component,
  1840. int channel, int mode)
  1841. {
  1842. int reg = WCD939X_TX_CH2, mask = 0, val = 0;
  1843. int ret = 0;
  1844. switch (channel) {
  1845. case 0:
  1846. reg = WCD939X_TX_CH2;
  1847. mask = 0x40;
  1848. break;
  1849. case 1:
  1850. reg = WCD939X_TX_CH2;
  1851. mask = 0x20;
  1852. break;
  1853. case 2:
  1854. reg = WCD939X_TX_CH4;
  1855. mask = 0x40;
  1856. break;
  1857. case 3:
  1858. reg = WCD939X_TX_CH4;
  1859. mask = 0x20;
  1860. break;
  1861. default:
  1862. pr_err_ratelimited("%s: Invalid channel num %d\n", __func__, channel);
  1863. ret = -EINVAL;
  1864. break;
  1865. }
  1866. if (!mode)
  1867. val = 0x00;
  1868. else
  1869. val = mask;
  1870. if (!ret)
  1871. snd_soc_component_update_bits(component, reg, mask, val);
  1872. return ret;
  1873. }
  1874. static int wcd939x_codec_enable_adc(struct snd_soc_dapm_widget *w,
  1875. struct snd_kcontrol *kcontrol,
  1876. int event){
  1877. struct snd_soc_component *component =
  1878. snd_soc_dapm_to_component(w->dapm);
  1879. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  1880. int clk_rate = 0, ret = 0;
  1881. int mode = 0, i = 0, bank = 0;
  1882. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1883. w->name, event);
  1884. bank = (wcd939x_swr_slv_get_current_bank(wcd939x->tx_swr_dev,
  1885. wcd939x->tx_swr_dev->dev_num) ? 0 : 1);
  1886. switch (event) {
  1887. case SND_SOC_DAPM_PRE_PMU:
  1888. wcd939x->adc_count++;
  1889. if (test_bit(WCD_ADC1, &wcd939x->status_mask) ||
  1890. test_bit(WCD_ADC1_MODE, &wcd939x->status_mask))
  1891. mode |= tx_mode_bit[wcd939x->tx_mode[WCD_ADC1]];
  1892. if (test_bit(WCD_ADC2, &wcd939x->status_mask) ||
  1893. test_bit(WCD_ADC2_MODE, &wcd939x->status_mask))
  1894. mode |= tx_mode_bit[wcd939x->tx_mode[WCD_ADC2]];
  1895. if (test_bit(WCD_ADC3, &wcd939x->status_mask) ||
  1896. test_bit(WCD_ADC3_MODE, &wcd939x->status_mask))
  1897. mode |= tx_mode_bit[wcd939x->tx_mode[WCD_ADC3]];
  1898. if (test_bit(WCD_ADC4, &wcd939x->status_mask) ||
  1899. test_bit(WCD_ADC4_MODE, &wcd939x->status_mask))
  1900. mode |= tx_mode_bit[wcd939x->tx_mode[WCD_ADC4]];
  1901. if (mode != 0) {
  1902. for (i = 0; i < ADC_MODE_ULP2; i++) {
  1903. if (mode & (1 << i)) {
  1904. i++;
  1905. break;
  1906. }
  1907. }
  1908. }
  1909. clk_rate = wcd939x_get_clk_rate(i);
  1910. /* clk_rate depends on number of paths getting enabled */
  1911. clk_rate = (wcd939x->adc_count * clk_rate);
  1912. if (clk_rate > SWR_CLK_RATE_9P6MHZ)
  1913. clk_rate = SWR_CLK_RATE_9P6MHZ;
  1914. wcd939x_set_swr_clk_rate(component, clk_rate, bank);
  1915. ret = swr_slvdev_datapath_control(wcd939x->tx_swr_dev,
  1916. wcd939x->tx_swr_dev->dev_num,
  1917. true);
  1918. wcd939x_set_swr_clk_rate(component, clk_rate, !bank);
  1919. break;
  1920. case SND_SOC_DAPM_POST_PMD:
  1921. wcd939x->adc_count--;
  1922. if (wcd939x->adc_count < 0)
  1923. wcd939x->adc_count = 0;
  1924. wcd939x_tx_connect_port(component, ADC1 + w->shift, 0, false);
  1925. if (w->shift + ADC1 == ADC2 &&
  1926. test_bit(AMIC2_BCS_ENABLE, &wcd939x->status_mask)) {
  1927. wcd939x_tx_connect_port(component, MBHC, 0,
  1928. false);
  1929. clear_bit(AMIC2_BCS_ENABLE, &wcd939x->status_mask);
  1930. }
  1931. break;
  1932. };
  1933. return ret;
  1934. }
  1935. void wcd939x_disable_bcs_before_slow_insert(struct snd_soc_component *component,
  1936. bool bcs_disable)
  1937. {
  1938. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  1939. if (wcd939x->update_wcd_event) {
  1940. if (bcs_disable)
  1941. wcd939x->update_wcd_event(wcd939x->handle,
  1942. SLV_BOLERO_EVT_BCS_CLK_OFF, 0);
  1943. else
  1944. wcd939x->update_wcd_event(wcd939x->handle,
  1945. SLV_BOLERO_EVT_BCS_CLK_OFF, 1);
  1946. }
  1947. }
  1948. static int wcd939x_enable_req(struct snd_soc_dapm_widget *w,
  1949. struct snd_kcontrol *kcontrol, int event)
  1950. {
  1951. struct snd_soc_component *component =
  1952. snd_soc_dapm_to_component(w->dapm);
  1953. struct wcd939x_priv *wcd939x =
  1954. snd_soc_component_get_drvdata(component);
  1955. int ret = 0;
  1956. u8 mode = 0;
  1957. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1958. w->name, event);
  1959. switch (event) {
  1960. case SND_SOC_DAPM_PRE_PMU:
  1961. snd_soc_component_update_bits(component,
  1962. REG_FIELD_VALUE(CDC_ANA_CLK_CTL, ANA_TX_CLK_EN, 0x01));
  1963. snd_soc_component_update_bits(component,
  1964. REG_FIELD_VALUE(CDC_ANA_CLK_CTL, ANA_TX_DIV2_CLK_EN, 0x01));
  1965. snd_soc_component_update_bits(component,
  1966. REG_FIELD_VALUE(CDC_REQ_CTL, FS_RATE_4P8, 0x01));
  1967. snd_soc_component_update_bits(component,
  1968. REG_FIELD_VALUE(CDC_REQ_CTL, NO_NOTCH, 0x00));
  1969. ret = wcd939x_tx_channel_config(component, w->shift, 1);
  1970. mode = wcd939x_get_adc_mode(wcd939x->tx_mode[w->shift]);
  1971. if (mode < 0) {
  1972. dev_info_ratelimited(component->dev,
  1973. "%s: invalid mode, setting to normal mode\n",
  1974. __func__);
  1975. mode = ADC_MODE_VAL_NORMAL;
  1976. }
  1977. switch (w->shift) {
  1978. case 0:
  1979. snd_soc_component_update_bits(component,
  1980. WCD939X_CDC_TX_ANA_MODE_0_1, 0x0F,
  1981. mode);
  1982. snd_soc_component_update_bits(component,
  1983. REG_FIELD_VALUE(CDC_DIG_CLK_CTL, TXD0_CLK_EN, 0x01));
  1984. break;
  1985. case 1:
  1986. snd_soc_component_update_bits(component,
  1987. WCD939X_CDC_TX_ANA_MODE_0_1, 0xF0,
  1988. mode << 4);
  1989. snd_soc_component_update_bits(component,
  1990. REG_FIELD_VALUE(CDC_DIG_CLK_CTL, TXD1_CLK_EN, 0x01));
  1991. break;
  1992. case 2:
  1993. snd_soc_component_update_bits(component,
  1994. WCD939X_CDC_TX_ANA_MODE_2_3, 0x0F,
  1995. mode);
  1996. snd_soc_component_update_bits(component,
  1997. REG_FIELD_VALUE(CDC_DIG_CLK_CTL, TXD2_CLK_EN, 0x01));
  1998. break;
  1999. case 3:
  2000. snd_soc_component_update_bits(component,
  2001. WCD939X_CDC_TX_ANA_MODE_2_3, 0xF0,
  2002. mode << 4);
  2003. snd_soc_component_update_bits(component,
  2004. REG_FIELD_VALUE(CDC_DIG_CLK_CTL, TXD3_CLK_EN, 0x01));
  2005. break;
  2006. default:
  2007. break;
  2008. }
  2009. ret |= wcd939x_tx_channel_config(component, w->shift, 0);
  2010. break;
  2011. case SND_SOC_DAPM_POST_PMD:
  2012. switch (w->shift) {
  2013. case 0:
  2014. snd_soc_component_update_bits(component,
  2015. REG_FIELD_VALUE(CDC_TX_ANA_MODE_0_1, TXD0_MODE, 0x00));
  2016. snd_soc_component_update_bits(component,
  2017. REG_FIELD_VALUE(CDC_DIG_CLK_CTL, TXD0_CLK_EN, 0x00));
  2018. break;
  2019. case 1:
  2020. snd_soc_component_update_bits(component,
  2021. REG_FIELD_VALUE(CDC_TX_ANA_MODE_0_1, TXD1_MODE, 0x00));
  2022. snd_soc_component_update_bits(component,
  2023. REG_FIELD_VALUE(CDC_DIG_CLK_CTL, TXD1_CLK_EN, 0x00));
  2024. break;
  2025. case 2:
  2026. snd_soc_component_update_bits(component,
  2027. REG_FIELD_VALUE(CDC_TX_ANA_MODE_2_3, TXD2_MODE, 0x00));
  2028. snd_soc_component_update_bits(component,
  2029. REG_FIELD_VALUE(CDC_DIG_CLK_CTL, TXD2_CLK_EN, 0x00));
  2030. break;
  2031. case 3:
  2032. snd_soc_component_update_bits(component,
  2033. REG_FIELD_VALUE(CDC_TX_ANA_MODE_2_3, TXD3_MODE, 0x00));
  2034. snd_soc_component_update_bits(component,
  2035. REG_FIELD_VALUE(CDC_DIG_CLK_CTL, TXD3_CLK_EN, 0x00));
  2036. break;
  2037. default:
  2038. break;
  2039. }
  2040. if (wcd939x->adc_count == 0) {
  2041. snd_soc_component_update_bits(component,
  2042. REG_FIELD_VALUE(CDC_ANA_CLK_CTL, ANA_TX_DIV2_CLK_EN, 0x00));
  2043. snd_soc_component_update_bits(component,
  2044. REG_FIELD_VALUE(CDC_ANA_CLK_CTL, ANA_TX_CLK_EN, 0x00));
  2045. }
  2046. break;
  2047. };
  2048. return ret;
  2049. }
  2050. int wcd939x_micbias_control(struct snd_soc_component *component,
  2051. int micb_num, int req, bool is_dapm)
  2052. {
  2053. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  2054. int micb_index = micb_num - 1;
  2055. u16 micb_reg;
  2056. int pre_off_event = 0, post_off_event = 0;
  2057. int post_on_event = 0, post_dapm_off = 0;
  2058. int post_dapm_on = 0;
  2059. int ret = 0;
  2060. if ((micb_index < 0) || (micb_index > WCD939X_MAX_MICBIAS - 1)) {
  2061. dev_err_ratelimited(component->dev,
  2062. "%s: Invalid micbias index, micb_ind:%d\n",
  2063. __func__, micb_index);
  2064. return -EINVAL;
  2065. }
  2066. if (NULL == wcd939x) {
  2067. dev_err_ratelimited(component->dev,
  2068. "%s: wcd939x private data is NULL\n", __func__);
  2069. return -EINVAL;
  2070. }
  2071. switch (micb_num) {
  2072. case MIC_BIAS_1:
  2073. micb_reg = WCD939X_MICB1;
  2074. break;
  2075. case MIC_BIAS_2:
  2076. micb_reg = WCD939X_MICB2;
  2077. pre_off_event = WCD_EVENT_PRE_MICBIAS_2_OFF;
  2078. post_off_event = WCD_EVENT_POST_MICBIAS_2_OFF;
  2079. post_on_event = WCD_EVENT_POST_MICBIAS_2_ON;
  2080. post_dapm_on = WCD_EVENT_POST_DAPM_MICBIAS_2_ON;
  2081. post_dapm_off = WCD_EVENT_POST_DAPM_MICBIAS_2_OFF;
  2082. break;
  2083. case MIC_BIAS_3:
  2084. micb_reg = WCD939X_MICB3;
  2085. break;
  2086. case MIC_BIAS_4:
  2087. micb_reg = WCD939X_MICB4;
  2088. break;
  2089. default:
  2090. dev_err_ratelimited(component->dev, "%s: Invalid micbias number: %d\n",
  2091. __func__, micb_num);
  2092. return -EINVAL;
  2093. };
  2094. mutex_lock(&wcd939x->micb_lock);
  2095. switch (req) {
  2096. case MICB_PULLUP_ENABLE:
  2097. if (!wcd939x->dev_up) {
  2098. dev_dbg(component->dev, "%s: enable req %d wcd device down\n",
  2099. __func__, req);
  2100. ret = -ENODEV;
  2101. goto done;
  2102. }
  2103. wcd939x->pullup_ref[micb_index]++;
  2104. if ((wcd939x->pullup_ref[micb_index] == 1) &&
  2105. (wcd939x->micb_ref[micb_index] == 0))
  2106. snd_soc_component_update_bits(component, micb_reg,
  2107. 0xC0, 0x80);
  2108. break;
  2109. case MICB_PULLUP_DISABLE:
  2110. if (wcd939x->pullup_ref[micb_index] > 0)
  2111. wcd939x->pullup_ref[micb_index]--;
  2112. if (!wcd939x->dev_up) {
  2113. dev_dbg(component->dev, "%s: enable req %d wcd device down\n",
  2114. __func__, req);
  2115. ret = -ENODEV;
  2116. goto done;
  2117. }
  2118. if ((wcd939x->pullup_ref[micb_index] == 0) &&
  2119. (wcd939x->micb_ref[micb_index] == 0))
  2120. snd_soc_component_update_bits(component, micb_reg,
  2121. 0xC0, 0x00);
  2122. break;
  2123. case MICB_ENABLE:
  2124. if (!wcd939x->dev_up) {
  2125. dev_dbg(component->dev, "%s: enable req %d wcd device down\n",
  2126. __func__, req);
  2127. ret = -ENODEV;
  2128. goto done;
  2129. }
  2130. wcd939x->micb_ref[micb_index]++;
  2131. if (wcd939x->micb_ref[micb_index] == 1) {
  2132. snd_soc_component_update_bits(component,
  2133. REG_FIELD_VALUE(CDC_DIG_CLK_CTL,TXD3_CLK_EN, 0x01));
  2134. snd_soc_component_update_bits(component,
  2135. REG_FIELD_VALUE(CDC_DIG_CLK_CTL,TXD2_CLK_EN, 0x01));
  2136. snd_soc_component_update_bits(component,
  2137. REG_FIELD_VALUE(CDC_DIG_CLK_CTL,TXD1_CLK_EN, 0x01));
  2138. snd_soc_component_update_bits(component,
  2139. REG_FIELD_VALUE(CDC_DIG_CLK_CTL,TXD0_CLK_EN, 0x01));
  2140. snd_soc_component_update_bits(component,
  2141. REG_FIELD_VALUE(CDC_ANA_CLK_CTL, ANA_TX_DIV2_CLK_EN, 0x01));
  2142. snd_soc_component_update_bits(component,
  2143. REG_FIELD_VALUE(CDC_ANA_TX_CLK_CTL, ANA_TXSCBIAS_CLK_EN, 0x01));
  2144. snd_soc_component_update_bits(component,
  2145. REG_FIELD_VALUE(TEST_CTL_2, IBIAS_LDO_DRIVER, 0x01));
  2146. snd_soc_component_update_bits(component,
  2147. REG_FIELD_VALUE(MICB2_TEST_CTL_2, IBIAS_LDO_DRIVER, 0x01));
  2148. snd_soc_component_update_bits(component,
  2149. REG_FIELD_VALUE(MICB3_TEST_CTL_2, IBIAS_LDO_DRIVER, 0x01));
  2150. snd_soc_component_update_bits(component,
  2151. REG_FIELD_VALUE(MICB4_TEST_CTL_2, IBIAS_LDO_DRIVER, 0x01));
  2152. snd_soc_component_update_bits(component,
  2153. micb_reg, 0xC0, 0x40);
  2154. if (post_on_event)
  2155. blocking_notifier_call_chain(
  2156. &wcd939x->mbhc->notifier,
  2157. post_on_event,
  2158. &wcd939x->mbhc->wcd_mbhc);
  2159. }
  2160. if (is_dapm && post_dapm_on && wcd939x->mbhc)
  2161. blocking_notifier_call_chain(&wcd939x->mbhc->notifier,
  2162. post_dapm_on,
  2163. &wcd939x->mbhc->wcd_mbhc);
  2164. break;
  2165. case MICB_DISABLE:
  2166. if (wcd939x->micb_ref[micb_index] > 0)
  2167. wcd939x->micb_ref[micb_index]--;
  2168. if (!wcd939x->dev_up) {
  2169. dev_dbg(component->dev, "%s: enable req %d wcd device down\n",
  2170. __func__, req);
  2171. ret = -ENODEV;
  2172. goto done;
  2173. }
  2174. if ((wcd939x->micb_ref[micb_index] == 0) &&
  2175. (wcd939x->pullup_ref[micb_index] > 0))
  2176. snd_soc_component_update_bits(component, micb_reg,
  2177. 0xC0, 0x80);
  2178. else if ((wcd939x->micb_ref[micb_index] == 0) &&
  2179. (wcd939x->pullup_ref[micb_index] == 0)) {
  2180. if (pre_off_event && wcd939x->mbhc)
  2181. blocking_notifier_call_chain(
  2182. &wcd939x->mbhc->notifier,
  2183. pre_off_event,
  2184. &wcd939x->mbhc->wcd_mbhc);
  2185. snd_soc_component_update_bits(component, micb_reg,
  2186. 0xC0, 0x00);
  2187. if (post_off_event && wcd939x->mbhc)
  2188. blocking_notifier_call_chain(
  2189. &wcd939x->mbhc->notifier,
  2190. post_off_event,
  2191. &wcd939x->mbhc->wcd_mbhc);
  2192. }
  2193. if (is_dapm && post_dapm_off && wcd939x->mbhc)
  2194. blocking_notifier_call_chain(&wcd939x->mbhc->notifier,
  2195. post_dapm_off,
  2196. &wcd939x->mbhc->wcd_mbhc);
  2197. break;
  2198. };
  2199. dev_dbg(component->dev,
  2200. "%s: micb_num:%d, micb_ref: %d, pullup_ref: %d\n",
  2201. __func__, micb_num, wcd939x->micb_ref[micb_index],
  2202. wcd939x->pullup_ref[micb_index]);
  2203. done:
  2204. mutex_unlock(&wcd939x->micb_lock);
  2205. return ret;
  2206. }
  2207. EXPORT_SYMBOL(wcd939x_micbias_control);
  2208. static int wcd939x_get_logical_addr(struct swr_device *swr_dev)
  2209. {
  2210. int ret = 0;
  2211. uint8_t devnum = 0;
  2212. int num_retry = NUM_ATTEMPTS;
  2213. do {
  2214. /* retry after 1ms */
  2215. usleep_range(1000, 1010);
  2216. ret = swr_get_logical_dev_num(swr_dev, swr_dev->addr, &devnum);
  2217. } while (ret && --num_retry);
  2218. if (ret)
  2219. dev_err_ratelimited(&swr_dev->dev,
  2220. "%s get devnum %d for dev addr %llx failed\n",
  2221. __func__, devnum, swr_dev->addr);
  2222. swr_dev->dev_num = devnum;
  2223. return 0;
  2224. }
  2225. static bool get_usbc_hs_status(struct snd_soc_component *component,
  2226. struct wcd_mbhc_config *mbhc_cfg)
  2227. {
  2228. if (mbhc_cfg->enable_usbc_analog) {
  2229. if (!(snd_soc_component_read(component, WCD939X_MBHC_MECH)
  2230. & 0x20))
  2231. return true;
  2232. }
  2233. return false;
  2234. }
  2235. int wcd939x_swr_dmic_register_notifier(struct snd_soc_component *component,
  2236. struct notifier_block *nblock,
  2237. bool enable)
  2238. {
  2239. struct wcd939x_priv *wcd939x_priv;
  2240. if(NULL == component) {
  2241. pr_err_ratelimited("%s: wcd939x component is NULL\n", __func__);
  2242. return -EINVAL;
  2243. }
  2244. wcd939x_priv = snd_soc_component_get_drvdata(component);
  2245. wcd939x_priv->notify_swr_dmic = enable;
  2246. if (enable)
  2247. return blocking_notifier_chain_register(&wcd939x_priv->notifier,
  2248. nblock);
  2249. else
  2250. return blocking_notifier_chain_unregister(
  2251. &wcd939x_priv->notifier, nblock);
  2252. }
  2253. EXPORT_SYMBOL(wcd939x_swr_dmic_register_notifier);
  2254. static int wcd939x_event_notify(struct notifier_block *block,
  2255. unsigned long val,
  2256. void *data)
  2257. {
  2258. u16 event = (val & 0xffff);
  2259. int ret = 0;
  2260. struct wcd939x_priv *wcd939x = dev_get_drvdata((struct device *)data);
  2261. struct snd_soc_component *component = wcd939x->component;
  2262. struct wcd_mbhc *mbhc;
  2263. switch (event) {
  2264. case BOLERO_SLV_EVT_TX_CH_HOLD_CLEAR:
  2265. if (test_bit(WCD_ADC1, &wcd939x->status_mask)) {
  2266. snd_soc_component_update_bits(component,
  2267. REG_FIELD_VALUE(TX_CH2, HPF1_INIT, 0x00));
  2268. set_bit(WCD_ADC1_MODE, &wcd939x->status_mask);
  2269. clear_bit(WCD_ADC1, &wcd939x->status_mask);
  2270. }
  2271. if (test_bit(WCD_ADC2, &wcd939x->status_mask)) {
  2272. snd_soc_component_update_bits(component,
  2273. REG_FIELD_VALUE(TX_CH2, HPF2_INIT, 0x00));
  2274. set_bit(WCD_ADC2_MODE, &wcd939x->status_mask);
  2275. clear_bit(WCD_ADC2, &wcd939x->status_mask);
  2276. }
  2277. if (test_bit(WCD_ADC3, &wcd939x->status_mask)) {
  2278. snd_soc_component_update_bits(component,
  2279. REG_FIELD_VALUE(TX_CH4, HPF3_INIT, 0x00));
  2280. set_bit(WCD_ADC3_MODE, &wcd939x->status_mask);
  2281. clear_bit(WCD_ADC3, &wcd939x->status_mask);
  2282. }
  2283. if (test_bit(WCD_ADC4, &wcd939x->status_mask)) {
  2284. snd_soc_component_update_bits(component,
  2285. REG_FIELD_VALUE(TX_CH4, HPF4_INIT, 0x00));
  2286. set_bit(WCD_ADC4_MODE, &wcd939x->status_mask);
  2287. clear_bit(WCD_ADC4, &wcd939x->status_mask);
  2288. }
  2289. break;
  2290. case BOLERO_SLV_EVT_PA_OFF_PRE_SSR:
  2291. snd_soc_component_update_bits(component,
  2292. REG_FIELD_VALUE(HPH, HPHL_ENABLE, 0x00));
  2293. snd_soc_component_update_bits(component,
  2294. REG_FIELD_VALUE(HPH, HPHR_ENABLE , 0x00));
  2295. snd_soc_component_update_bits(component,
  2296. REG_FIELD_VALUE(EAR, ENABLE, 0x00));
  2297. break;
  2298. case BOLERO_SLV_EVT_SSR_DOWN:
  2299. wcd939x->dev_up = false;
  2300. if(wcd939x->notify_swr_dmic)
  2301. blocking_notifier_call_chain(&wcd939x->notifier,
  2302. WCD939X_EVT_SSR_DOWN,
  2303. NULL);
  2304. wcd939x->mbhc->wcd_mbhc.deinit_in_progress = true;
  2305. mbhc = &wcd939x->mbhc->wcd_mbhc;
  2306. wcd939x->usbc_hs_status = get_usbc_hs_status(component,
  2307. mbhc->mbhc_cfg);
  2308. wcd939x_mbhc_ssr_down(wcd939x->mbhc, component);
  2309. wcd939x_reset_low(wcd939x->dev);
  2310. break;
  2311. case BOLERO_SLV_EVT_SSR_UP:
  2312. wcd939x_reset(wcd939x->dev);
  2313. /* allow reset to take effect */
  2314. usleep_range(10000, 10010);
  2315. wcd939x_get_logical_addr(wcd939x->tx_swr_dev);
  2316. wcd939x_get_logical_addr(wcd939x->rx_swr_dev);
  2317. wcd939x_init_reg(component);
  2318. regcache_mark_dirty(wcd939x->regmap);
  2319. regcache_sync(wcd939x->regmap);
  2320. /* Initialize MBHC module */
  2321. mbhc = &wcd939x->mbhc->wcd_mbhc;
  2322. ret = wcd939x_mbhc_post_ssr_init(wcd939x->mbhc, component);
  2323. if (ret) {
  2324. dev_err_ratelimited(component->dev, "%s: mbhc initialization failed\n",
  2325. __func__);
  2326. } else {
  2327. wcd939x_mbhc_hs_detect(component, mbhc->mbhc_cfg);
  2328. }
  2329. wcd939x->mbhc->wcd_mbhc.deinit_in_progress = false;
  2330. wcd939x->dev_up = true;
  2331. if(wcd939x->notify_swr_dmic)
  2332. blocking_notifier_call_chain(&wcd939x->notifier,
  2333. WCD939X_EVT_SSR_UP,
  2334. NULL);
  2335. if (wcd939x->usbc_hs_status)
  2336. mdelay(500);
  2337. break;
  2338. case BOLERO_SLV_EVT_CLK_NOTIFY:
  2339. snd_soc_component_update_bits(component,
  2340. WCD939X_TOP_CLK_CFG, 0x06,
  2341. ((val >> 0x10) << 0x01));
  2342. break;
  2343. default:
  2344. dev_dbg(component->dev, "%s: invalid event %d\n", __func__, event);
  2345. break;
  2346. }
  2347. return 0;
  2348. }
  2349. static int __wcd939x_codec_enable_micbias(struct snd_soc_dapm_widget *w,
  2350. int event)
  2351. {
  2352. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  2353. int micb_num;
  2354. dev_dbg(component->dev, "%s: wname: %s, event: %d\n",
  2355. __func__, w->name, event);
  2356. if (strnstr(w->name, "MIC BIAS1", sizeof("MIC BIAS1")))
  2357. micb_num = MIC_BIAS_1;
  2358. else if (strnstr(w->name, "MIC BIAS2", sizeof("MIC BIAS2")))
  2359. micb_num = MIC_BIAS_2;
  2360. else if (strnstr(w->name, "MIC BIAS3", sizeof("MIC BIAS3")))
  2361. micb_num = MIC_BIAS_3;
  2362. else if (strnstr(w->name, "MIC BIAS4", sizeof("MIC BIAS4")))
  2363. micb_num = MIC_BIAS_4;
  2364. else
  2365. return -EINVAL;
  2366. switch (event) {
  2367. case SND_SOC_DAPM_PRE_PMU:
  2368. wcd939x_micbias_control(component, micb_num,
  2369. MICB_ENABLE, true);
  2370. break;
  2371. case SND_SOC_DAPM_POST_PMU:
  2372. /* 1 msec delay as per HW requirement */
  2373. usleep_range(1000, 1100);
  2374. break;
  2375. case SND_SOC_DAPM_POST_PMD:
  2376. wcd939x_micbias_control(component, micb_num,
  2377. MICB_DISABLE, true);
  2378. break;
  2379. };
  2380. return 0;
  2381. }
  2382. static int wcd939x_codec_enable_micbias(struct snd_soc_dapm_widget *w,
  2383. struct snd_kcontrol *kcontrol,
  2384. int event)
  2385. {
  2386. return __wcd939x_codec_enable_micbias(w, event);
  2387. }
  2388. static int __wcd939x_codec_enable_micbias_pullup(struct snd_soc_dapm_widget *w,
  2389. int event)
  2390. {
  2391. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  2392. int micb_num;
  2393. dev_dbg(component->dev, "%s: wname: %s, event: %d\n",
  2394. __func__, w->name, event);
  2395. if (strnstr(w->name, "VA MIC BIAS1", sizeof("VA MIC BIAS1")))
  2396. micb_num = MIC_BIAS_1;
  2397. else if (strnstr(w->name, "VA MIC BIAS2", sizeof("VA MIC BIAS2")))
  2398. micb_num = MIC_BIAS_2;
  2399. else if (strnstr(w->name, "VA MIC BIAS3", sizeof("VA MIC BIAS3")))
  2400. micb_num = MIC_BIAS_3;
  2401. else if (strnstr(w->name, "VA MIC BIAS4", sizeof("VA MIC BIAS4")))
  2402. micb_num = MIC_BIAS_4;
  2403. else
  2404. return -EINVAL;
  2405. switch (event) {
  2406. case SND_SOC_DAPM_PRE_PMU:
  2407. wcd939x_micbias_control(component, micb_num,
  2408. MICB_PULLUP_ENABLE, true);
  2409. break;
  2410. case SND_SOC_DAPM_POST_PMU:
  2411. /* 1 msec delay as per HW requirement */
  2412. usleep_range(1000, 1100);
  2413. break;
  2414. case SND_SOC_DAPM_POST_PMD:
  2415. wcd939x_micbias_control(component, micb_num,
  2416. MICB_PULLUP_DISABLE, true);
  2417. break;
  2418. };
  2419. return 0;
  2420. }
  2421. static int wcd939x_codec_enable_micbias_pullup(struct snd_soc_dapm_widget *w,
  2422. struct snd_kcontrol *kcontrol,
  2423. int event)
  2424. {
  2425. return __wcd939x_codec_enable_micbias_pullup(w, event);
  2426. }
  2427. static int wcd939x_wakeup(void *handle, bool enable)
  2428. {
  2429. struct wcd939x_priv *priv;
  2430. int ret = 0;
  2431. if (!handle) {
  2432. pr_err_ratelimited("%s: NULL handle\n", __func__);
  2433. return -EINVAL;
  2434. }
  2435. priv = (struct wcd939x_priv *)handle;
  2436. if (!priv->tx_swr_dev) {
  2437. pr_err_ratelimited("%s: tx swr dev is NULL\n", __func__);
  2438. return -EINVAL;
  2439. }
  2440. mutex_lock(&priv->wakeup_lock);
  2441. if (enable)
  2442. ret = swr_device_wakeup_vote(priv->tx_swr_dev);
  2443. else
  2444. ret = swr_device_wakeup_unvote(priv->tx_swr_dev);
  2445. mutex_unlock(&priv->wakeup_lock);
  2446. return ret;
  2447. }
  2448. static int wcd939x_codec_force_enable_micbias(struct snd_soc_dapm_widget *w,
  2449. struct snd_kcontrol *kcontrol,
  2450. int event)
  2451. {
  2452. int ret = 0;
  2453. struct snd_soc_component *component =
  2454. snd_soc_dapm_to_component(w->dapm);
  2455. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  2456. switch (event) {
  2457. case SND_SOC_DAPM_PRE_PMU:
  2458. wcd939x_wakeup(wcd939x, true);
  2459. ret = __wcd939x_codec_enable_micbias(w, SND_SOC_DAPM_PRE_PMU);
  2460. wcd939x_wakeup(wcd939x, false);
  2461. break;
  2462. case SND_SOC_DAPM_POST_PMD:
  2463. wcd939x_wakeup(wcd939x, true);
  2464. ret = __wcd939x_codec_enable_micbias(w, SND_SOC_DAPM_POST_PMD);
  2465. wcd939x_wakeup(wcd939x, false);
  2466. break;
  2467. }
  2468. return ret;
  2469. }
  2470. static int wcd939x_enable_micbias(struct wcd939x_priv *wcd939x,
  2471. int micb_num, int req)
  2472. {
  2473. int micb_index = micb_num - 1;
  2474. u16 micb_reg;
  2475. if (NULL == wcd939x) {
  2476. pr_err_ratelimited("%s: wcd939x private data is NULL\n", __func__);
  2477. return -EINVAL;
  2478. }
  2479. switch (micb_num) {
  2480. case MIC_BIAS_1:
  2481. micb_reg = WCD939X_MICB1;
  2482. break;
  2483. case MIC_BIAS_2:
  2484. micb_reg = WCD939X_MICB2;
  2485. break;
  2486. case MIC_BIAS_3:
  2487. micb_reg = WCD939X_MICB3;
  2488. break;
  2489. case MIC_BIAS_4:
  2490. micb_reg = WCD939X_MICB4;
  2491. break;
  2492. default:
  2493. pr_err_ratelimited("%s: Invalid micbias number: %d\n", __func__, micb_num);
  2494. return -EINVAL;
  2495. };
  2496. pr_debug("%s: req: %d micb_num: %d micb_ref: %d pullup_ref: %d\n",
  2497. __func__, req, micb_num, wcd939x->micb_ref[micb_index],
  2498. wcd939x->pullup_ref[micb_index]);
  2499. mutex_lock(&wcd939x->micb_lock);
  2500. switch (req) {
  2501. case MICB_ENABLE:
  2502. wcd939x->micb_ref[micb_index]++;
  2503. if (wcd939x->micb_ref[micb_index] == 1) {
  2504. regmap_update_bits(wcd939x->regmap,
  2505. WCD939X_CDC_DIG_CLK_CTL, 0xE0, 0xE0);
  2506. regmap_update_bits(wcd939x->regmap,
  2507. WCD939X_CDC_ANA_CLK_CTL, 0x10, 0x10);
  2508. regmap_update_bits(wcd939x->regmap,
  2509. WCD939X_CDC_ANA_TX_CLK_CTL, 0x01, 0x01);
  2510. regmap_update_bits(wcd939x->regmap,
  2511. WCD939X_TEST_CTL_2, 0x01, 0x01);
  2512. regmap_update_bits(wcd939x->regmap,
  2513. WCD939X_MICB2_TEST_CTL_2, 0x01, 0x01);
  2514. regmap_update_bits(wcd939x->regmap,
  2515. WCD939X_MICB3_TEST_CTL_2, 0x01, 0x01);
  2516. regmap_update_bits(wcd939x->regmap,
  2517. WCD939X_MICB4_TEST_CTL_2, 0x01, 0x01);
  2518. regmap_update_bits(wcd939x->regmap,
  2519. micb_reg, 0xC0, 0x40);
  2520. regmap_update_bits(wcd939x->regmap, micb_reg, 0x3F, 0x10);
  2521. }
  2522. break;
  2523. case MICB_PULLUP_ENABLE:
  2524. wcd939x->pullup_ref[micb_index]++;
  2525. if ((wcd939x->pullup_ref[micb_index] == 1) &&
  2526. (wcd939x->micb_ref[micb_index] == 0))
  2527. regmap_update_bits(wcd939x->regmap, micb_reg,
  2528. 0xC0, 0x80);
  2529. break;
  2530. case MICB_PULLUP_DISABLE:
  2531. if (wcd939x->pullup_ref[micb_index] > 0)
  2532. wcd939x->pullup_ref[micb_index]--;
  2533. if ((wcd939x->pullup_ref[micb_index] == 0) &&
  2534. (wcd939x->micb_ref[micb_index] == 0))
  2535. regmap_update_bits(wcd939x->regmap, micb_reg,
  2536. 0xC0, 0x00);
  2537. break;
  2538. case MICB_DISABLE:
  2539. if (wcd939x->micb_ref[micb_index] > 0)
  2540. wcd939x->micb_ref[micb_index]--;
  2541. if ((wcd939x->micb_ref[micb_index] == 0) &&
  2542. (wcd939x->pullup_ref[micb_index] > 0))
  2543. regmap_update_bits(wcd939x->regmap, micb_reg,
  2544. 0xC0, 0x80);
  2545. else if ((wcd939x->micb_ref[micb_index] == 0) &&
  2546. (wcd939x->pullup_ref[micb_index] == 0))
  2547. regmap_update_bits(wcd939x->regmap, micb_reg,
  2548. 0xC0, 0x00);
  2549. break;
  2550. };
  2551. mutex_unlock(&wcd939x->micb_lock);
  2552. return 0;
  2553. }
  2554. int wcd939x_codec_force_enable_micbias_v2(struct snd_soc_component *component,
  2555. int event, int micb_num)
  2556. {
  2557. struct wcd939x_priv *wcd939x_priv = NULL;
  2558. int ret = 0;
  2559. int micb_index = micb_num - 1;
  2560. if(NULL == component) {
  2561. pr_err_ratelimited("%s: wcd939x component is NULL\n", __func__);
  2562. return -EINVAL;
  2563. }
  2564. if(event != SND_SOC_DAPM_PRE_PMU && event != SND_SOC_DAPM_POST_PMD) {
  2565. pr_err_ratelimited("%s: invalid event: %d\n", __func__, event);
  2566. return -EINVAL;
  2567. }
  2568. if(micb_num < MIC_BIAS_1 || micb_num > MIC_BIAS_4) {
  2569. pr_err_ratelimited("%s: invalid mic bias num: %d\n", __func__, micb_num);
  2570. return -EINVAL;
  2571. }
  2572. wcd939x_priv = snd_soc_component_get_drvdata(component);
  2573. if (!wcd939x_priv->dev_up) {
  2574. if ((wcd939x_priv->pullup_ref[micb_index] > 0) &&
  2575. (event == SND_SOC_DAPM_POST_PMD)) {
  2576. wcd939x_priv->pullup_ref[micb_index]--;
  2577. ret = -ENODEV;
  2578. goto done;
  2579. }
  2580. }
  2581. switch (event) {
  2582. case SND_SOC_DAPM_PRE_PMU:
  2583. wcd939x_wakeup(wcd939x_priv, true);
  2584. wcd939x_enable_micbias(wcd939x_priv, micb_num, MICB_PULLUP_ENABLE);
  2585. wcd939x_wakeup(wcd939x_priv, false);
  2586. break;
  2587. case SND_SOC_DAPM_POST_PMD:
  2588. wcd939x_wakeup(wcd939x_priv, true);
  2589. wcd939x_enable_micbias(wcd939x_priv, micb_num, MICB_PULLUP_DISABLE);
  2590. wcd939x_wakeup(wcd939x_priv, false);
  2591. break;
  2592. }
  2593. done:
  2594. return ret;
  2595. }
  2596. EXPORT_SYMBOL(wcd939x_codec_force_enable_micbias_v2);
  2597. static inline int wcd939x_tx_path_get(const char *wname,
  2598. unsigned int *path_num)
  2599. {
  2600. int ret = 0;
  2601. char *widget_name = NULL;
  2602. char *w_name = NULL;
  2603. char *path_num_char = NULL;
  2604. char *path_name = NULL;
  2605. widget_name = kstrndup(wname, 9, GFP_KERNEL);
  2606. if (!widget_name)
  2607. return -EINVAL;
  2608. w_name = widget_name;
  2609. path_name = strsep(&widget_name, " ");
  2610. if (!path_name) {
  2611. pr_err_ratelimited("%s: Invalid widget name = %s\n",
  2612. __func__, widget_name);
  2613. ret = -EINVAL;
  2614. goto err;
  2615. }
  2616. path_num_char = strpbrk(path_name, "0123");
  2617. if (!path_num_char) {
  2618. pr_err_ratelimited("%s: tx path index not found\n",
  2619. __func__);
  2620. ret = -EINVAL;
  2621. goto err;
  2622. }
  2623. ret = kstrtouint(path_num_char, 10, path_num);
  2624. if (ret < 0)
  2625. pr_err_ratelimited("%s: Invalid tx path = %s\n",
  2626. __func__, w_name);
  2627. err:
  2628. kfree(w_name);
  2629. return ret;
  2630. }
  2631. static int wcd939x_tx_mode_get(struct snd_kcontrol *kcontrol,
  2632. struct snd_ctl_elem_value *ucontrol)
  2633. {
  2634. struct snd_soc_component *component =
  2635. snd_soc_kcontrol_component(kcontrol);
  2636. struct wcd939x_priv *wcd939x = NULL;
  2637. int ret = 0;
  2638. unsigned int path = 0;
  2639. if (!component)
  2640. return -EINVAL;
  2641. wcd939x = snd_soc_component_get_drvdata(component);
  2642. if (!wcd939x)
  2643. return -EINVAL;
  2644. ret = wcd939x_tx_path_get(kcontrol->id.name, &path);
  2645. if (ret < 0)
  2646. return ret;
  2647. ucontrol->value.integer.value[0] = wcd939x->tx_mode[path];
  2648. return 0;
  2649. }
  2650. static int wcd939x_tx_mode_put(struct snd_kcontrol *kcontrol,
  2651. struct snd_ctl_elem_value *ucontrol)
  2652. {
  2653. struct snd_soc_component *component =
  2654. snd_soc_kcontrol_component(kcontrol);
  2655. struct wcd939x_priv *wcd939x = NULL;
  2656. u32 mode_val;
  2657. unsigned int path = 0;
  2658. int ret = 0;
  2659. if (!component)
  2660. return -EINVAL;
  2661. wcd939x = snd_soc_component_get_drvdata(component);
  2662. if (!wcd939x)
  2663. return -EINVAL;
  2664. ret = wcd939x_tx_path_get(kcontrol->id.name, &path);
  2665. if (ret)
  2666. return ret;
  2667. mode_val = ucontrol->value.enumerated.item[0];
  2668. dev_dbg(component->dev, "%s: mode: %d\n", __func__, mode_val);
  2669. wcd939x->tx_mode[path] = mode_val;
  2670. return 0;
  2671. }
  2672. static int wcd939x_rx_hph_mode_get(struct snd_kcontrol *kcontrol,
  2673. struct snd_ctl_elem_value *ucontrol)
  2674. {
  2675. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  2676. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  2677. ucontrol->value.integer.value[0] = wcd939x->hph_mode;
  2678. return 0;
  2679. }
  2680. static int wcd939x_rx_hph_mode_put(struct snd_kcontrol *kcontrol,
  2681. struct snd_ctl_elem_value *ucontrol)
  2682. {
  2683. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  2684. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  2685. u32 mode_val;
  2686. mode_val = ucontrol->value.enumerated.item[0];
  2687. dev_dbg(component->dev, "%s: mode: %d\n", __func__, mode_val);
  2688. if (wcd939x->variant == WCD9390) {
  2689. if (mode_val == CLS_H_HIFI || mode_val == CLS_AB_HIFI) {
  2690. dev_info_ratelimited(component->dev,
  2691. "%s:Invalid HPH Mode, default to CLS_H_ULP\n",
  2692. __func__);
  2693. mode_val = CLS_H_ULP;
  2694. }
  2695. }
  2696. if (mode_val == CLS_H_NORMAL) {
  2697. dev_info_ratelimited(component->dev,
  2698. "%s:Invalid HPH Mode, default to class_AB\n",
  2699. __func__);
  2700. mode_val = CLS_H_ULP;
  2701. }
  2702. wcd939x->hph_mode = mode_val;
  2703. return 0;
  2704. }
  2705. static int wcd939x_ear_pa_gain_get(struct snd_kcontrol *kcontrol,
  2706. struct snd_ctl_elem_value *ucontrol)
  2707. {
  2708. u8 ear_pa_gain = 0;
  2709. struct snd_soc_component *component =
  2710. snd_soc_kcontrol_component(kcontrol);
  2711. ear_pa_gain = snd_soc_component_read(component,
  2712. WCD939X_EAR_COMPANDER_CTL);
  2713. ear_pa_gain = (ear_pa_gain & 0x7C) >> 2;
  2714. ucontrol->value.integer.value[0] = ear_pa_gain;
  2715. dev_dbg(component->dev, "%s: ear_pa_gain = 0x%x\n", __func__,
  2716. ear_pa_gain);
  2717. return 0;
  2718. }
  2719. static int wcd939x_ear_pa_gain_put(struct snd_kcontrol *kcontrol,
  2720. struct snd_ctl_elem_value *ucontrol)
  2721. {
  2722. u8 ear_pa_gain = 0;
  2723. struct snd_soc_component *component =
  2724. snd_soc_kcontrol_component(kcontrol);
  2725. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  2726. dev_dbg(component->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  2727. __func__, ucontrol->value.integer.value[0]);
  2728. ear_pa_gain = ucontrol->value.integer.value[0] << 2;
  2729. if (!wcd939x->comp1_enable) {
  2730. snd_soc_component_update_bits(component,
  2731. WCD939X_EAR_COMPANDER_CTL,
  2732. 0x7C, ear_pa_gain);
  2733. }
  2734. return 0;
  2735. }
  2736. /* wcd939x_codec_get_dev_num - returns swr device number
  2737. * @component: Codec instance
  2738. *
  2739. * Return: swr device number on success or negative error
  2740. * code on failure.
  2741. */
  2742. int wcd939x_codec_get_dev_num(struct snd_soc_component *component)
  2743. {
  2744. struct wcd939x_priv *wcd939x;
  2745. if (!component)
  2746. return -EINVAL;
  2747. wcd939x = snd_soc_component_get_drvdata(component);
  2748. if (!wcd939x || !wcd939x->rx_swr_dev) {
  2749. pr_err_ratelimited("%s: wcd939x component is NULL\n", __func__);
  2750. return -EINVAL;
  2751. }
  2752. return wcd939x->rx_swr_dev->dev_num;
  2753. }
  2754. EXPORT_SYMBOL(wcd939x_codec_get_dev_num);
  2755. static int wcd939x_get_compander(struct snd_kcontrol *kcontrol,
  2756. struct snd_ctl_elem_value *ucontrol)
  2757. {
  2758. struct snd_soc_component *component =
  2759. snd_soc_kcontrol_component(kcontrol);
  2760. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  2761. bool hphr;
  2762. struct soc_multi_mixer_control *mc;
  2763. mc = (struct soc_multi_mixer_control *)(kcontrol->private_value);
  2764. hphr = mc->shift;
  2765. ucontrol->value.integer.value[0] = hphr ? wcd939x->comp2_enable :
  2766. wcd939x->comp1_enable;
  2767. return 0;
  2768. }
  2769. static int wcd939x_set_compander(struct snd_kcontrol *kcontrol,
  2770. struct snd_ctl_elem_value *ucontrol)
  2771. {
  2772. struct snd_soc_component *component =
  2773. snd_soc_kcontrol_component(kcontrol);
  2774. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  2775. int value = ucontrol->value.integer.value[0];
  2776. bool hphr;
  2777. struct soc_multi_mixer_control *mc;
  2778. mc = (struct soc_multi_mixer_control *)(kcontrol->private_value);
  2779. hphr = mc->shift;
  2780. if (hphr)
  2781. wcd939x->comp2_enable = value;
  2782. else
  2783. wcd939x->comp1_enable = value;
  2784. return 0;
  2785. }
  2786. static int wcd939x_codec_enable_vdd_buck(struct snd_soc_dapm_widget *w,
  2787. struct snd_kcontrol *kcontrol,
  2788. int event)
  2789. {
  2790. struct snd_soc_component *component =
  2791. snd_soc_dapm_to_component(w->dapm);
  2792. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  2793. struct wcd939x_pdata *pdata = NULL;
  2794. int ret = 0;
  2795. pdata = dev_get_platdata(wcd939x->dev);
  2796. if (!pdata) {
  2797. dev_err_ratelimited(component->dev, "%s: pdata is NULL\n", __func__);
  2798. return -EINVAL;
  2799. }
  2800. if (!msm_cdc_is_ondemand_supply(wcd939x->dev,
  2801. wcd939x->supplies,
  2802. pdata->regulator,
  2803. pdata->num_supplies,
  2804. "cdc-vdd-buck"))
  2805. return 0;
  2806. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  2807. w->name, event);
  2808. switch (event) {
  2809. case SND_SOC_DAPM_PRE_PMU:
  2810. if (test_bit(ALLOW_BUCK_DISABLE, &wcd939x->status_mask)) {
  2811. dev_dbg(component->dev,
  2812. "%s: buck already in enabled state\n",
  2813. __func__);
  2814. clear_bit(ALLOW_BUCK_DISABLE, &wcd939x->status_mask);
  2815. return 0;
  2816. }
  2817. ret = msm_cdc_enable_ondemand_supply(wcd939x->dev,
  2818. wcd939x->supplies,
  2819. pdata->regulator,
  2820. pdata->num_supplies,
  2821. "cdc-vdd-buck");
  2822. if (ret == -EINVAL) {
  2823. dev_err_ratelimited(component->dev, "%s: vdd buck is not enabled\n",
  2824. __func__);
  2825. return ret;
  2826. }
  2827. clear_bit(ALLOW_BUCK_DISABLE, &wcd939x->status_mask);
  2828. /*
  2829. * 200us sleep is required after LDO is enabled as per
  2830. * HW requirement
  2831. */
  2832. usleep_range(200, 250);
  2833. break;
  2834. case SND_SOC_DAPM_POST_PMD:
  2835. set_bit(ALLOW_BUCK_DISABLE, &wcd939x->status_mask);
  2836. break;
  2837. }
  2838. return 0;
  2839. }
  2840. static int wcd939x_ldoh_get(struct snd_kcontrol *kcontrol,
  2841. struct snd_ctl_elem_value *ucontrol)
  2842. {
  2843. struct snd_soc_component *component =
  2844. snd_soc_kcontrol_component(kcontrol);
  2845. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  2846. ucontrol->value.integer.value[0] = wcd939x->ldoh;
  2847. return 0;
  2848. }
  2849. static int wcd939x_ldoh_put(struct snd_kcontrol *kcontrol,
  2850. struct snd_ctl_elem_value *ucontrol)
  2851. {
  2852. struct snd_soc_component *component =
  2853. snd_soc_kcontrol_component(kcontrol);
  2854. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  2855. wcd939x->ldoh = ucontrol->value.integer.value[0];
  2856. return 0;
  2857. }
  2858. const char * const tx_master_ch_text[] = {
  2859. "ZERO", "SWRM_PCM_OUT", "SWRM_TX1_CH1", "SWRM_TX1_CH2", "SWRM_TX1_CH3",
  2860. "SWRM_TX1_CH4", "SWRM_TX2_CH1", "SWRM_TX2_CH2", "SWRM_TX2_CH3",
  2861. "SWRM_TX2_CH4", "SWRM_TX3_CH1", "SWRM_TX3_CH2", "SWRM_TX3_CH3",
  2862. "SWRM_TX3_CH4", "SWRM_PCM_IN",
  2863. };
  2864. const struct soc_enum tx_master_ch_enum =
  2865. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(tx_master_ch_text),
  2866. tx_master_ch_text);
  2867. static void wcd939x_tx_get_slave_ch_type_idx(const char *wname, int *ch_idx)
  2868. {
  2869. u8 ch_type = 0;
  2870. if (strnstr(wname, "ADC1", sizeof("ADC1")))
  2871. ch_type = ADC1;
  2872. else if (strnstr(wname, "ADC2", sizeof("ADC2")))
  2873. ch_type = ADC2;
  2874. else if (strnstr(wname, "ADC3", sizeof("ADC3")))
  2875. ch_type = ADC3;
  2876. else if (strnstr(wname, "ADC4", sizeof("ADC4")))
  2877. ch_type = ADC4;
  2878. else if (strnstr(wname, "DMIC0", sizeof("DMIC0")))
  2879. ch_type = DMIC0;
  2880. else if (strnstr(wname, "DMIC1", sizeof("DMIC1")))
  2881. ch_type = DMIC1;
  2882. else if (strnstr(wname, "MBHC", sizeof("MBHC")))
  2883. ch_type = MBHC;
  2884. else if (strnstr(wname, "DMIC2", sizeof("DMIC2")))
  2885. ch_type = DMIC2;
  2886. else if (strnstr(wname, "DMIC3", sizeof("DMIC3")))
  2887. ch_type = DMIC3;
  2888. else if (strnstr(wname, "DMIC4", sizeof("DMIC4")))
  2889. ch_type = DMIC4;
  2890. else if (strnstr(wname, "DMIC5", sizeof("DMIC5")))
  2891. ch_type = DMIC5;
  2892. else if (strnstr(wname, "DMIC6", sizeof("DMIC6")))
  2893. ch_type = DMIC6;
  2894. else if (strnstr(wname, "DMIC7", sizeof("DMIC7")))
  2895. ch_type = DMIC7;
  2896. else
  2897. pr_err_ratelimited("%s: port name: %s is not listed\n", __func__, wname);
  2898. if (ch_type)
  2899. *ch_idx = wcd939x_slave_get_slave_ch_val(ch_type);
  2900. else
  2901. *ch_idx = -EINVAL;
  2902. }
  2903. static int wcd939x_tx_master_ch_get(struct snd_kcontrol *kcontrol,
  2904. struct snd_ctl_elem_value *ucontrol)
  2905. {
  2906. struct snd_soc_component *component =
  2907. snd_soc_kcontrol_component(kcontrol);
  2908. struct wcd939x_priv *wcd939x = NULL;
  2909. int slave_ch_idx = -EINVAL;
  2910. if (component == NULL)
  2911. return -EINVAL;
  2912. wcd939x = snd_soc_component_get_drvdata(component);
  2913. if (wcd939x == NULL)
  2914. return -EINVAL;
  2915. wcd939x_tx_get_slave_ch_type_idx(kcontrol->id.name, &slave_ch_idx);
  2916. if (slave_ch_idx < 0 || slave_ch_idx >= WCD939X_MAX_SLAVE_CH_TYPES)
  2917. return -EINVAL;
  2918. ucontrol->value.integer.value[0] = wcd939x_slave_get_master_ch_val(
  2919. wcd939x->tx_master_ch_map[slave_ch_idx]);
  2920. return 0;
  2921. }
  2922. static int wcd939x_tx_master_ch_put(struct snd_kcontrol *kcontrol,
  2923. struct snd_ctl_elem_value *ucontrol)
  2924. {
  2925. struct snd_soc_component *component =
  2926. snd_soc_kcontrol_component(kcontrol);
  2927. struct wcd939x_priv *wcd939x = NULL;
  2928. int slave_ch_idx = -EINVAL, idx = 0;
  2929. if (component == NULL)
  2930. return -EINVAL;
  2931. wcd939x = snd_soc_component_get_drvdata(component);
  2932. if (wcd939x == NULL)
  2933. return -EINVAL;
  2934. wcd939x_tx_get_slave_ch_type_idx(kcontrol->id.name, &slave_ch_idx);
  2935. if (slave_ch_idx < 0 || slave_ch_idx >= WCD939X_MAX_SLAVE_CH_TYPES)
  2936. return -EINVAL;
  2937. dev_dbg(component->dev, "%s: slave_ch_idx: %d", __func__, slave_ch_idx);
  2938. dev_dbg(component->dev, "%s: ucontrol->value.enumerated.item[0] = %ld\n",
  2939. __func__, ucontrol->value.enumerated.item[0]);
  2940. idx = ucontrol->value.enumerated.item[0];
  2941. if (idx < 0 || idx >= ARRAY_SIZE(swr_master_ch_map))
  2942. return -EINVAL;
  2943. wcd939x->tx_master_ch_map[slave_ch_idx] = wcd939x_slave_get_master_ch(idx);
  2944. return 0;
  2945. }
  2946. static int wcd939x_bcs_get(struct snd_kcontrol *kcontrol,
  2947. struct snd_ctl_elem_value *ucontrol)
  2948. {
  2949. struct snd_soc_component *component =
  2950. snd_soc_kcontrol_component(kcontrol);
  2951. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  2952. ucontrol->value.integer.value[0] = wcd939x->bcs_dis;
  2953. return 0;
  2954. }
  2955. static int wcd939x_bcs_put(struct snd_kcontrol *kcontrol,
  2956. struct snd_ctl_elem_value *ucontrol)
  2957. {
  2958. struct snd_soc_component *component =
  2959. snd_soc_kcontrol_component(kcontrol);
  2960. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  2961. wcd939x->bcs_dis = ucontrol->value.integer.value[0];
  2962. return 0;
  2963. }
  2964. static const char * const tx_mode_mux_text_wcd9390[] = {
  2965. "ADC_INVALID", "ADC_HIFI", "ADC_LO_HIF", "ADC_NORMAL", "ADC_LP",
  2966. };
  2967. static const struct soc_enum tx_mode_mux_enum_wcd9390 =
  2968. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(tx_mode_mux_text_wcd9390),
  2969. tx_mode_mux_text_wcd9390);
  2970. static const char * const tx_mode_mux_text[] = {
  2971. "ADC_INVALID", "ADC_HIFI", "ADC_LO_HIF", "ADC_NORMAL", "ADC_LP",
  2972. "ADC_ULP1", "ADC_ULP2",
  2973. };
  2974. static const struct soc_enum tx_mode_mux_enum =
  2975. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(tx_mode_mux_text),
  2976. tx_mode_mux_text);
  2977. static const char * const rx_hph_mode_mux_text_wcd9390[] = {
  2978. "CLS_H_INVALID", "CLS_H_INVALID_1", "CLS_H_LP", "CLS_AB",
  2979. "CLS_H_LOHIFI", "CLS_H_ULP", "CLS_H_INVALID_2", "CLS_AB_LP",
  2980. "CLS_AB_LOHIFI",
  2981. };
  2982. static const char * const wcd939x_ear_pa_gain_text[] = {
  2983. "G_6_DB", "G_4P5_DB", "G_3_DB", "G_1P5_DB", "G_0_DB",
  2984. "G_M1P5_DB", "G_M3_DB", "G_M4P5_DB",
  2985. "G_M6_DB", "G_7P5_DB", "G_M9_DB",
  2986. "G_M10P5_DB", "G_M12_DB", "G_M13P5_DB",
  2987. "G_M15_DB", "G_M16P5_DB", "G_M18_DB",
  2988. };
  2989. static const struct soc_enum rx_hph_mode_mux_enum_wcd9390 =
  2990. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(rx_hph_mode_mux_text_wcd9390),
  2991. rx_hph_mode_mux_text_wcd9390);
  2992. static SOC_ENUM_SINGLE_EXT_DECL(wcd939x_ear_pa_gain_enum,
  2993. wcd939x_ear_pa_gain_text);
  2994. static const char * const rx_hph_mode_mux_text[] = {
  2995. "CLS_H_INVALID", "CLS_H_HIFI", "CLS_H_LP", "CLS_AB", "CLS_H_LOHIFI",
  2996. "CLS_H_ULP", "CLS_AB_HIFI", "CLS_AB_LP", "CLS_AB_LOHIFI",
  2997. };
  2998. static const struct soc_enum rx_hph_mode_mux_enum =
  2999. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(rx_hph_mode_mux_text),
  3000. rx_hph_mode_mux_text);
  3001. static const struct snd_kcontrol_new wcd9390_snd_controls[] = {
  3002. SOC_ENUM_EXT("EAR PA GAIN", wcd939x_ear_pa_gain_enum,
  3003. wcd939x_ear_pa_gain_get, wcd939x_ear_pa_gain_put),
  3004. SOC_ENUM_EXT("RX HPH Mode", rx_hph_mode_mux_enum_wcd9390,
  3005. wcd939x_rx_hph_mode_get, wcd939x_rx_hph_mode_put),
  3006. SOC_ENUM_EXT("TX0 MODE", tx_mode_mux_enum_wcd9390,
  3007. wcd939x_tx_mode_get, wcd939x_tx_mode_put),
  3008. SOC_ENUM_EXT("TX1 MODE", tx_mode_mux_enum_wcd9390,
  3009. wcd939x_tx_mode_get, wcd939x_tx_mode_put),
  3010. SOC_ENUM_EXT("TX2 MODE", tx_mode_mux_enum_wcd9390,
  3011. wcd939x_tx_mode_get, wcd939x_tx_mode_put),
  3012. SOC_ENUM_EXT("TX3 MODE", tx_mode_mux_enum_wcd9390,
  3013. wcd939x_tx_mode_get, wcd939x_tx_mode_put),
  3014. };
  3015. static const struct snd_kcontrol_new wcd9395_snd_controls[] = {
  3016. SOC_ENUM_EXT("RX HPH Mode", rx_hph_mode_mux_enum,
  3017. wcd939x_rx_hph_mode_get, wcd939x_rx_hph_mode_put),
  3018. SOC_ENUM_EXT("TX0 MODE", tx_mode_mux_enum,
  3019. wcd939x_tx_mode_get, wcd939x_tx_mode_put),
  3020. SOC_ENUM_EXT("TX1 MODE", tx_mode_mux_enum,
  3021. wcd939x_tx_mode_get, wcd939x_tx_mode_put),
  3022. SOC_ENUM_EXT("TX2 MODE", tx_mode_mux_enum,
  3023. wcd939x_tx_mode_get, wcd939x_tx_mode_put),
  3024. SOC_ENUM_EXT("TX3 MODE", tx_mode_mux_enum,
  3025. wcd939x_tx_mode_get, wcd939x_tx_mode_put),
  3026. };
  3027. static const struct snd_kcontrol_new wcd939x_snd_controls[] = {
  3028. SOC_SINGLE_EXT("HPHL_COMP Switch", SND_SOC_NOPM, 0, 1, 0,
  3029. wcd939x_get_compander, wcd939x_set_compander),
  3030. SOC_SINGLE_EXT("HPHR_COMP Switch", SND_SOC_NOPM, 1, 1, 0,
  3031. wcd939x_get_compander, wcd939x_set_compander),
  3032. SOC_SINGLE_EXT("LDOH Enable", SND_SOC_NOPM, 0, 1, 0,
  3033. wcd939x_ldoh_get, wcd939x_ldoh_put),
  3034. SOC_SINGLE_EXT("ADC2_BCS Disable", SND_SOC_NOPM, 0, 1, 0,
  3035. wcd939x_bcs_get, wcd939x_bcs_put),
  3036. SOC_SINGLE_TLV("HPHL Volume", WCD939X_L_EN, 0, 20, 1, line_gain),
  3037. SOC_SINGLE_TLV("HPHR Volume", WCD939X_R_EN, 0, 20, 1, line_gain),
  3038. SOC_SINGLE_TLV("ADC1 Volume", WCD939X_TX_CH1, 0, 20, 0,
  3039. analog_gain),
  3040. SOC_SINGLE_TLV("ADC2 Volume", WCD939X_TX_CH2, 0, 20, 0,
  3041. analog_gain),
  3042. SOC_SINGLE_TLV("ADC3 Volume", WCD939X_TX_CH3, 0, 20, 0,
  3043. analog_gain),
  3044. SOC_SINGLE_TLV("ADC4 Volume", WCD939X_TX_CH4, 0, 20, 0,
  3045. analog_gain),
  3046. SOC_SINGLE_EXT("HPHL Compander", SND_SOC_NOPM, WCD939X_HPHL, 1, 0,
  3047. wcd939x_hph_compander_get, wcd939x_hph_compander_put),
  3048. SOC_SINGLE_EXT("HPHR Compander", SND_SOC_NOPM, WCD939X_HPHR, 1, 0,
  3049. wcd939x_hph_compander_get, wcd939x_hph_compander_put),
  3050. SOC_SINGLE_EXT("HPHL XTALK", SND_SOC_NOPM, WCD939X_HPHL, 1, 0,
  3051. wcd939x_hph_xtalk_get, wcd939x_hph_xtalk_put),
  3052. SOC_SINGLE_EXT("HPHR XTALK", SND_SOC_NOPM, WCD939X_HPHR, 1, 0,
  3053. wcd939x_hph_xtalk_get, wcd939x_hph_xtalk_put),
  3054. SOC_SINGLE_EXT("HPHL PCM Enable", SND_SOC_NOPM, WCD939X_HPHL, 1, 0,
  3055. wcd939x_hph_pcm_enable_get, wcd939x_hph_pcm_enable_put),
  3056. SOC_SINGLE_EXT("HPHR PCM Enable", SND_SOC_NOPM, WCD939X_HPHR, 1, 0,
  3057. wcd939x_hph_pcm_enable_get, wcd939x_hph_pcm_enable_put),
  3058. SOC_ENUM_EXT("ADC1 ChMap", tx_master_ch_enum,
  3059. wcd939x_tx_master_ch_get, wcd939x_tx_master_ch_put),
  3060. SOC_ENUM_EXT("ADC2 ChMap", tx_master_ch_enum,
  3061. wcd939x_tx_master_ch_get, wcd939x_tx_master_ch_put),
  3062. SOC_ENUM_EXT("ADC3 ChMap", tx_master_ch_enum,
  3063. wcd939x_tx_master_ch_get, wcd939x_tx_master_ch_put),
  3064. SOC_ENUM_EXT("ADC4 ChMap", tx_master_ch_enum,
  3065. wcd939x_tx_master_ch_get, wcd939x_tx_master_ch_put),
  3066. SOC_ENUM_EXT("DMIC0 ChMap", tx_master_ch_enum,
  3067. wcd939x_tx_master_ch_get, wcd939x_tx_master_ch_put),
  3068. SOC_ENUM_EXT("DMIC1 ChMap", tx_master_ch_enum,
  3069. wcd939x_tx_master_ch_get, wcd939x_tx_master_ch_put),
  3070. SOC_ENUM_EXT("MBHC ChMap", tx_master_ch_enum,
  3071. wcd939x_tx_master_ch_get, wcd939x_tx_master_ch_put),
  3072. SOC_ENUM_EXT("DMIC2 ChMap", tx_master_ch_enum,
  3073. wcd939x_tx_master_ch_get, wcd939x_tx_master_ch_put),
  3074. SOC_ENUM_EXT("DMIC3 ChMap", tx_master_ch_enum,
  3075. wcd939x_tx_master_ch_get, wcd939x_tx_master_ch_put),
  3076. SOC_ENUM_EXT("DMIC4 ChMap", tx_master_ch_enum,
  3077. wcd939x_tx_master_ch_get, wcd939x_tx_master_ch_put),
  3078. SOC_ENUM_EXT("DMIC5 ChMap", tx_master_ch_enum,
  3079. wcd939x_tx_master_ch_get, wcd939x_tx_master_ch_put),
  3080. SOC_ENUM_EXT("DMIC6 ChMap", tx_master_ch_enum,
  3081. wcd939x_tx_master_ch_get, wcd939x_tx_master_ch_put),
  3082. SOC_ENUM_EXT("DMIC7 ChMap", tx_master_ch_enum,
  3083. wcd939x_tx_master_ch_get, wcd939x_tx_master_ch_put),
  3084. };
  3085. static const struct snd_kcontrol_new adc1_switch[] = {
  3086. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  3087. };
  3088. static const struct snd_kcontrol_new adc2_switch[] = {
  3089. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  3090. };
  3091. static const struct snd_kcontrol_new adc3_switch[] = {
  3092. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  3093. };
  3094. static const struct snd_kcontrol_new adc4_switch[] = {
  3095. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  3096. };
  3097. static const struct snd_kcontrol_new amic1_switch[] = {
  3098. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  3099. };
  3100. static const struct snd_kcontrol_new amic2_switch[] = {
  3101. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  3102. };
  3103. static const struct snd_kcontrol_new amic3_switch[] = {
  3104. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  3105. };
  3106. static const struct snd_kcontrol_new amic4_switch[] = {
  3107. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  3108. };
  3109. static const struct snd_kcontrol_new amic5_switch[] = {
  3110. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  3111. };
  3112. static const struct snd_kcontrol_new va_amic1_switch[] = {
  3113. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  3114. };
  3115. static const struct snd_kcontrol_new va_amic2_switch[] = {
  3116. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  3117. };
  3118. static const struct snd_kcontrol_new va_amic3_switch[] = {
  3119. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  3120. };
  3121. static const struct snd_kcontrol_new va_amic4_switch[] = {
  3122. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  3123. };
  3124. static const struct snd_kcontrol_new va_amic5_switch[] = {
  3125. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  3126. };
  3127. static const struct snd_kcontrol_new dmic1_switch[] = {
  3128. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  3129. };
  3130. static const struct snd_kcontrol_new dmic2_switch[] = {
  3131. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  3132. };
  3133. static const struct snd_kcontrol_new dmic3_switch[] = {
  3134. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  3135. };
  3136. static const struct snd_kcontrol_new dmic4_switch[] = {
  3137. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  3138. };
  3139. static const struct snd_kcontrol_new dmic5_switch[] = {
  3140. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  3141. };
  3142. static const struct snd_kcontrol_new dmic6_switch[] = {
  3143. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  3144. };
  3145. static const struct snd_kcontrol_new dmic7_switch[] = {
  3146. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  3147. };
  3148. static const struct snd_kcontrol_new dmic8_switch[] = {
  3149. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  3150. };
  3151. static const struct snd_kcontrol_new ear_rdac_switch[] = {
  3152. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  3153. };
  3154. static const struct snd_kcontrol_new hphl_rdac_switch[] = {
  3155. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  3156. };
  3157. static const struct snd_kcontrol_new hphr_rdac_switch[] = {
  3158. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  3159. };
  3160. static const char * const adc1_mux_text[] = {
  3161. "CH1_AMIC_DISABLE", "CH1_AMIC1", "CH1_AMIC2", "CH1_AMIC3", "CH1_AMIC4", "CH1_AMIC5"
  3162. };
  3163. static const struct soc_enum adc1_enum =
  3164. SOC_ENUM_SINGLE(WCD939X_TX_CH12_MUX, WCD939X_TX_CH12_MUX_CH1_SEL_SHIFT,
  3165. ARRAY_SIZE(adc1_mux_text), adc1_mux_text);
  3166. static const struct snd_kcontrol_new tx_adc1_mux =
  3167. SOC_DAPM_ENUM("ADC1 MUX Mux", adc1_enum);
  3168. static const char * const adc2_mux_text[] = {
  3169. "CH2_AMIC_DISABLE", "CH2_AMIC1", "CH2_AMIC2", "CH2_AMIC3", "CH2_AMIC4", "CH2_AMIC5"
  3170. };
  3171. static const struct soc_enum adc2_enum =
  3172. SOC_ENUM_SINGLE(WCD939X_TX_CH12_MUX, WCD939X_TX_CH12_MUX_CH2_SEL_SHIFT,
  3173. ARRAY_SIZE(adc2_mux_text), adc2_mux_text);
  3174. static const struct snd_kcontrol_new tx_adc2_mux =
  3175. SOC_DAPM_ENUM("ADC2 MUX Mux", adc2_enum);
  3176. static const char * const adc3_mux_text[] = {
  3177. "CH3_AMIC_DISABLE", "CH3_AMIC1", "CH3_AMIC3", "CH3_AMIC4", "CH3_AMIC5"
  3178. };
  3179. static const struct soc_enum adc3_enum =
  3180. SOC_ENUM_SINGLE(WCD939X_TX_CH34_MUX, WCD939X_TX_CH34_MUX_CH3_SEL_SHIFT,
  3181. ARRAY_SIZE(adc3_mux_text), adc3_mux_text);
  3182. static const struct snd_kcontrol_new tx_adc3_mux =
  3183. SOC_DAPM_ENUM("ADC3 MUX Mux", adc3_enum);
  3184. static const char * const adc4_mux_text[] = {
  3185. "CH4_AMIC_DISABLE", "CH4_AMIC1", "CH4_AMIC3", "CH4_AMIC4", "CH4_AMIC5"
  3186. };
  3187. static const struct soc_enum adc4_enum =
  3188. SOC_ENUM_SINGLE(WCD939X_TX_CH34_MUX, WCD939X_TX_CH34_MUX_CH4_SEL_SHIFT,
  3189. ARRAY_SIZE(adc4_mux_text), adc4_mux_text);
  3190. static const struct snd_kcontrol_new tx_adc4_mux =
  3191. SOC_DAPM_ENUM("ADC4 MUX Mux", adc4_enum);
  3192. static const char * const rdac3_mux_text[] = {
  3193. "RX1", "RX3"
  3194. };
  3195. static const struct soc_enum rdac3_enum =
  3196. SOC_ENUM_SINGLE(WCD939X_CDC_EAR_PATH_CTL, 0,
  3197. ARRAY_SIZE(rdac3_mux_text), rdac3_mux_text);
  3198. static const struct snd_kcontrol_new rx_rdac3_mux =
  3199. SOC_DAPM_ENUM("RDAC3_MUX Mux", rdac3_enum);
  3200. static const char * const rx1_mux_text[] = {
  3201. "ZERO", "RX1 MUX"
  3202. };
  3203. static const struct soc_enum rx1_enum =
  3204. SOC_ENUM_SINGLE(SND_SOC_NOPM, 0, 0, rx1_mux_text);
  3205. static const struct snd_kcontrol_new rx1_mux =
  3206. SOC_DAPM_ENUM("RX1 MUX Mux", rx1_enum);
  3207. static const char * const rx2_mux_text[] = {
  3208. "ZERO", "RX2 MUX"
  3209. };
  3210. static const struct soc_enum rx2_enum =
  3211. SOC_ENUM_SINGLE(SND_SOC_NOPM, 0, 0, rx2_mux_text);
  3212. static const struct snd_kcontrol_new rx2_mux =
  3213. SOC_DAPM_ENUM("RX2 MUX Mux", rx2_enum);
  3214. static const struct snd_soc_dapm_widget wcd939x_dapm_widgets[] = {
  3215. /*input widgets*/
  3216. SND_SOC_DAPM_INPUT("AMIC1"),
  3217. SND_SOC_DAPM_INPUT("AMIC2"),
  3218. SND_SOC_DAPM_INPUT("AMIC3"),
  3219. SND_SOC_DAPM_INPUT("AMIC4"),
  3220. SND_SOC_DAPM_INPUT("AMIC5"),
  3221. SND_SOC_DAPM_INPUT("VA AMIC1"),
  3222. SND_SOC_DAPM_INPUT("VA AMIC2"),
  3223. SND_SOC_DAPM_INPUT("VA AMIC3"),
  3224. SND_SOC_DAPM_INPUT("VA AMIC4"),
  3225. SND_SOC_DAPM_INPUT("VA AMIC5"),
  3226. SND_SOC_DAPM_INPUT("IN1_HPHL"),
  3227. SND_SOC_DAPM_INPUT("IN2_HPHR"),
  3228. SND_SOC_DAPM_INPUT("IN3_EAR"),
  3229. /*
  3230. * These dummy widgets are null connected to WCD939x dapm input and
  3231. * output widgets which are not actual path endpoints. This ensures
  3232. * dapm doesnt set these dapm input and output widgets as endpoints.
  3233. */
  3234. SND_SOC_DAPM_INPUT("WCD_TX_DUMMY"),
  3235. SND_SOC_DAPM_OUTPUT("WCD_RX_DUMMY"),
  3236. /*tx widgets*/
  3237. SND_SOC_DAPM_ADC_E("ADC1", NULL, SND_SOC_NOPM, 0, 0,
  3238. wcd939x_codec_enable_adc,
  3239. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3240. SND_SOC_DAPM_ADC_E("ADC2", NULL, SND_SOC_NOPM, 1, 0,
  3241. wcd939x_codec_enable_adc,
  3242. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3243. SND_SOC_DAPM_ADC_E("ADC3", NULL, SND_SOC_NOPM, 2, 0,
  3244. wcd939x_codec_enable_adc,
  3245. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3246. SND_SOC_DAPM_ADC_E("ADC4", NULL, SND_SOC_NOPM, 3, 0,
  3247. wcd939x_codec_enable_adc,
  3248. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3249. SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0,
  3250. wcd939x_codec_enable_dmic,
  3251. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3252. SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 1, 0,
  3253. wcd939x_codec_enable_dmic,
  3254. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3255. SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 2, 0,
  3256. wcd939x_codec_enable_dmic,
  3257. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3258. SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 3, 0,
  3259. wcd939x_codec_enable_dmic,
  3260. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3261. SND_SOC_DAPM_ADC_E("DMIC5", NULL, SND_SOC_NOPM, 4, 0,
  3262. wcd939x_codec_enable_dmic,
  3263. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3264. SND_SOC_DAPM_ADC_E("DMIC6", NULL, SND_SOC_NOPM, 5, 0,
  3265. wcd939x_codec_enable_dmic,
  3266. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3267. SND_SOC_DAPM_ADC_E("DMIC7", NULL, SND_SOC_NOPM, 6, 0,
  3268. wcd939x_codec_enable_dmic,
  3269. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3270. SND_SOC_DAPM_ADC_E("DMIC8", NULL, SND_SOC_NOPM, 7, 0,
  3271. wcd939x_codec_enable_dmic,
  3272. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3273. SND_SOC_DAPM_MIXER_E("ADC1 REQ", SND_SOC_NOPM, 0, 0,
  3274. NULL, 0, wcd939x_enable_req,
  3275. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3276. SND_SOC_DAPM_MIXER_E("ADC2 REQ", SND_SOC_NOPM, 1, 0,
  3277. NULL, 0, wcd939x_enable_req,
  3278. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3279. SND_SOC_DAPM_MIXER_E("ADC3 REQ", SND_SOC_NOPM, 2, 0,
  3280. NULL, 0, wcd939x_enable_req,
  3281. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3282. SND_SOC_DAPM_MIXER_E("ADC4 REQ", SND_SOC_NOPM, 3, 0,
  3283. NULL, 0, wcd939x_enable_req,
  3284. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3285. SND_SOC_DAPM_MIXER_E("AMIC1_MIXER", SND_SOC_NOPM, 0, 0,
  3286. amic1_switch, ARRAY_SIZE(amic1_switch), NULL,
  3287. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3288. SND_SOC_DAPM_MIXER_E("AMIC2_MIXER", SND_SOC_NOPM, 0, 0,
  3289. amic2_switch, ARRAY_SIZE(amic2_switch), NULL,
  3290. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3291. SND_SOC_DAPM_MIXER_E("AMIC3_MIXER", SND_SOC_NOPM, 0, 0,
  3292. amic3_switch, ARRAY_SIZE(amic3_switch), NULL,
  3293. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3294. SND_SOC_DAPM_MIXER_E("AMIC4_MIXER", SND_SOC_NOPM, 0, 0,
  3295. amic4_switch, ARRAY_SIZE(amic4_switch), NULL,
  3296. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3297. SND_SOC_DAPM_MIXER_E("AMIC5_MIXER", SND_SOC_NOPM, 0, 0,
  3298. amic5_switch, ARRAY_SIZE(amic5_switch), NULL,
  3299. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3300. SND_SOC_DAPM_MIXER_E("VA_AMIC1_MIXER", SND_SOC_NOPM, 0, 0,
  3301. va_amic1_switch, ARRAY_SIZE(va_amic1_switch), NULL,
  3302. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3303. SND_SOC_DAPM_MIXER_E("VA_AMIC2_MIXER", SND_SOC_NOPM, 0, 0,
  3304. va_amic2_switch, ARRAY_SIZE(va_amic2_switch), NULL,
  3305. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3306. SND_SOC_DAPM_MIXER_E("VA_AMIC3_MIXER", SND_SOC_NOPM, 0, 0,
  3307. va_amic3_switch, ARRAY_SIZE(va_amic3_switch), NULL,
  3308. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3309. SND_SOC_DAPM_MIXER_E("VA_AMIC4_MIXER", SND_SOC_NOPM, 0, 0,
  3310. va_amic4_switch, ARRAY_SIZE(va_amic4_switch), NULL,
  3311. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3312. SND_SOC_DAPM_MIXER_E("VA_AMIC5_MIXER", SND_SOC_NOPM, 0, 0,
  3313. va_amic5_switch, ARRAY_SIZE(va_amic5_switch), NULL,
  3314. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3315. SND_SOC_DAPM_MUX("ADC1 MUX", SND_SOC_NOPM, 0, 0,
  3316. &tx_adc1_mux),
  3317. SND_SOC_DAPM_MUX("ADC2 MUX", SND_SOC_NOPM, 0, 0,
  3318. &tx_adc2_mux),
  3319. SND_SOC_DAPM_MUX("ADC3 MUX", SND_SOC_NOPM, 0, 0,
  3320. &tx_adc3_mux),
  3321. SND_SOC_DAPM_MUX("ADC4 MUX", SND_SOC_NOPM, 0, 0,
  3322. &tx_adc4_mux),
  3323. /*tx mixers*/
  3324. SND_SOC_DAPM_MIXER_E("ADC1_MIXER", SND_SOC_NOPM, ADC1, 0,
  3325. adc1_switch, ARRAY_SIZE(adc1_switch),
  3326. wcd939x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  3327. SND_SOC_DAPM_POST_PMD),
  3328. SND_SOC_DAPM_MIXER_E("ADC2_MIXER", SND_SOC_NOPM, ADC2, 0,
  3329. adc2_switch, ARRAY_SIZE(adc2_switch),
  3330. wcd939x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  3331. SND_SOC_DAPM_POST_PMD),
  3332. SND_SOC_DAPM_MIXER_E("ADC3_MIXER", SND_SOC_NOPM, ADC3, 0, adc3_switch,
  3333. ARRAY_SIZE(adc3_switch), wcd939x_tx_swr_ctrl,
  3334. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3335. SND_SOC_DAPM_MIXER_E("ADC4_MIXER", SND_SOC_NOPM, ADC4, 0, adc4_switch,
  3336. ARRAY_SIZE(adc4_switch), wcd939x_tx_swr_ctrl,
  3337. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3338. SND_SOC_DAPM_MIXER_E("DMIC1_MIXER", SND_SOC_NOPM, DMIC1,
  3339. 0, dmic1_switch, ARRAY_SIZE(dmic1_switch),
  3340. wcd939x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  3341. SND_SOC_DAPM_POST_PMD),
  3342. SND_SOC_DAPM_MIXER_E("DMIC2_MIXER", SND_SOC_NOPM, DMIC2,
  3343. 0, dmic2_switch, ARRAY_SIZE(dmic2_switch),
  3344. wcd939x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  3345. SND_SOC_DAPM_POST_PMD),
  3346. SND_SOC_DAPM_MIXER_E("DMIC3_MIXER", SND_SOC_NOPM, DMIC3,
  3347. 0, dmic3_switch, ARRAY_SIZE(dmic3_switch),
  3348. wcd939x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  3349. SND_SOC_DAPM_POST_PMD),
  3350. SND_SOC_DAPM_MIXER_E("DMIC4_MIXER", SND_SOC_NOPM, DMIC4,
  3351. 0, dmic4_switch, ARRAY_SIZE(dmic4_switch),
  3352. wcd939x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  3353. SND_SOC_DAPM_POST_PMD),
  3354. SND_SOC_DAPM_MIXER_E("DMIC5_MIXER", SND_SOC_NOPM, DMIC5,
  3355. 0, dmic5_switch, ARRAY_SIZE(dmic5_switch),
  3356. wcd939x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  3357. SND_SOC_DAPM_POST_PMD),
  3358. SND_SOC_DAPM_MIXER_E("DMIC6_MIXER", SND_SOC_NOPM, DMIC6,
  3359. 0, dmic6_switch, ARRAY_SIZE(dmic6_switch),
  3360. wcd939x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  3361. SND_SOC_DAPM_POST_PMD),
  3362. SND_SOC_DAPM_MIXER_E("DMIC7_MIXER", SND_SOC_NOPM, DMIC7,
  3363. 0, dmic7_switch, ARRAY_SIZE(dmic7_switch),
  3364. wcd939x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  3365. SND_SOC_DAPM_POST_PMD),
  3366. SND_SOC_DAPM_MIXER_E("DMIC8_MIXER", SND_SOC_NOPM, DMIC8,
  3367. 0, dmic8_switch, ARRAY_SIZE(dmic8_switch),
  3368. wcd939x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  3369. SND_SOC_DAPM_POST_PMD),
  3370. /* micbias widgets*/
  3371. SND_SOC_DAPM_SUPPLY("MIC BIAS1", SND_SOC_NOPM, 0, 0,
  3372. wcd939x_codec_enable_micbias,
  3373. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  3374. SND_SOC_DAPM_POST_PMD),
  3375. SND_SOC_DAPM_SUPPLY("MIC BIAS2", SND_SOC_NOPM, 0, 0,
  3376. wcd939x_codec_enable_micbias,
  3377. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  3378. SND_SOC_DAPM_POST_PMD),
  3379. SND_SOC_DAPM_SUPPLY("MIC BIAS3", SND_SOC_NOPM, 0, 0,
  3380. wcd939x_codec_enable_micbias,
  3381. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  3382. SND_SOC_DAPM_POST_PMD),
  3383. SND_SOC_DAPM_SUPPLY("MIC BIAS4", SND_SOC_NOPM, 0, 0,
  3384. wcd939x_codec_enable_micbias,
  3385. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  3386. SND_SOC_DAPM_POST_PMD),
  3387. SND_SOC_DAPM_SUPPLY(DAPM_MICBIAS1_STANDALONE, SND_SOC_NOPM, 0, 0,
  3388. wcd939x_codec_force_enable_micbias,
  3389. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3390. SND_SOC_DAPM_SUPPLY(DAPM_MICBIAS2_STANDALONE, SND_SOC_NOPM, 0, 0,
  3391. wcd939x_codec_force_enable_micbias,
  3392. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3393. SND_SOC_DAPM_SUPPLY(DAPM_MICBIAS3_STANDALONE, SND_SOC_NOPM, 0, 0,
  3394. wcd939x_codec_force_enable_micbias,
  3395. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3396. SND_SOC_DAPM_SUPPLY(DAPM_MICBIAS4_STANDALONE, SND_SOC_NOPM, 0, 0,
  3397. wcd939x_codec_force_enable_micbias,
  3398. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3399. SND_SOC_DAPM_SUPPLY("VDD_BUCK", SND_SOC_NOPM, 0, 0,
  3400. wcd939x_codec_enable_vdd_buck,
  3401. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3402. SND_SOC_DAPM_SUPPLY_S("CLS_H_PORT", 1, SND_SOC_NOPM, 0, 0,
  3403. wcd939x_enable_clsh,
  3404. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3405. /*rx widgets*/
  3406. SND_SOC_DAPM_PGA_E("EAR PGA", WCD939X_EAR, 7, 0, NULL, 0,
  3407. wcd939x_codec_enable_ear_pa,
  3408. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  3409. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  3410. SND_SOC_DAPM_PGA_E("HPHL PGA", WCD939X_HPH, 7, 0, NULL, 0,
  3411. wcd939x_codec_enable_hphl_pa,
  3412. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  3413. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  3414. SND_SOC_DAPM_PGA_E("HPHR PGA", WCD939X_HPH, 6, 0, NULL, 0,
  3415. wcd939x_codec_enable_hphr_pa,
  3416. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  3417. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  3418. SND_SOC_DAPM_DAC_E("RDAC1", NULL, SND_SOC_NOPM, 0, 0,
  3419. wcd939x_codec_hphl_dac_event,
  3420. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  3421. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  3422. SND_SOC_DAPM_DAC_E("RDAC2", NULL, SND_SOC_NOPM, 0, 0,
  3423. wcd939x_codec_hphr_dac_event,
  3424. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  3425. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  3426. SND_SOC_DAPM_DAC_E("RDAC3", NULL, SND_SOC_NOPM, 0, 0,
  3427. wcd939x_codec_ear_dac_event,
  3428. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  3429. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  3430. SND_SOC_DAPM_MUX("RDAC3_MUX", SND_SOC_NOPM, 0, 0, &rx_rdac3_mux),
  3431. SND_SOC_DAPM_MUX_E("RX1 MUX", SND_SOC_NOPM, WCD_RX1, 0, &rx1_mux,
  3432. wcd939x_rx_mux, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU
  3433. | SND_SOC_DAPM_POST_PMD),
  3434. SND_SOC_DAPM_MUX_E("RX2 MUX", SND_SOC_NOPM, WCD_RX2, 0, &rx2_mux,
  3435. wcd939x_rx_mux, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU
  3436. | SND_SOC_DAPM_POST_PMD),
  3437. SND_SOC_DAPM_MIXER_E("RX1", SND_SOC_NOPM, 0, 0, NULL, 0,
  3438. wcd939x_enable_rx1, SND_SOC_DAPM_PRE_PMU |
  3439. SND_SOC_DAPM_POST_PMD),
  3440. SND_SOC_DAPM_MIXER_E("RX2", SND_SOC_NOPM, 0, 0, NULL, 0,
  3441. wcd939x_enable_rx2, SND_SOC_DAPM_PRE_PMU |
  3442. SND_SOC_DAPM_POST_PMD),
  3443. SND_SOC_DAPM_MIXER_E("RX3", SND_SOC_NOPM, 0, 0, NULL, 0,
  3444. wcd939x_enable_rx3, SND_SOC_DAPM_PRE_PMU |
  3445. SND_SOC_DAPM_POST_PMD),
  3446. /* rx mixer widgets*/
  3447. SND_SOC_DAPM_MIXER("EAR_RDAC", SND_SOC_NOPM, 0, 0,
  3448. ear_rdac_switch, ARRAY_SIZE(ear_rdac_switch)),
  3449. SND_SOC_DAPM_MIXER("HPHL_RDAC", SND_SOC_NOPM, 0, 0,
  3450. hphl_rdac_switch, ARRAY_SIZE(hphl_rdac_switch)),
  3451. SND_SOC_DAPM_MIXER("HPHR_RDAC", SND_SOC_NOPM, 0, 0,
  3452. hphr_rdac_switch, ARRAY_SIZE(hphr_rdac_switch)),
  3453. /*output widgets tx*/
  3454. SND_SOC_DAPM_OUTPUT("WCD_TX_OUTPUT"),
  3455. /*output widgets rx*/
  3456. SND_SOC_DAPM_OUTPUT("EAR"),
  3457. SND_SOC_DAPM_OUTPUT("HPHL"),
  3458. SND_SOC_DAPM_OUTPUT("HPHR"),
  3459. /* micbias pull up widgets*/
  3460. SND_SOC_DAPM_SUPPLY("VA MIC BIAS1", SND_SOC_NOPM, 0, 0,
  3461. wcd939x_codec_enable_micbias_pullup,
  3462. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  3463. SND_SOC_DAPM_POST_PMD),
  3464. SND_SOC_DAPM_SUPPLY("VA MIC BIAS2", SND_SOC_NOPM, 0, 0,
  3465. wcd939x_codec_enable_micbias_pullup,
  3466. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  3467. SND_SOC_DAPM_POST_PMD),
  3468. SND_SOC_DAPM_SUPPLY("VA MIC BIAS3", SND_SOC_NOPM, 0, 0,
  3469. wcd939x_codec_enable_micbias_pullup,
  3470. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  3471. SND_SOC_DAPM_POST_PMD),
  3472. SND_SOC_DAPM_SUPPLY("VA MIC BIAS4", SND_SOC_NOPM, 0, 0,
  3473. wcd939x_codec_enable_micbias_pullup,
  3474. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  3475. SND_SOC_DAPM_POST_PMD),
  3476. };
  3477. static const struct snd_soc_dapm_route wcd939x_audio_map[] = {
  3478. /*ADC-1 (channel-1)*/
  3479. {"WCD_TX_DUMMY", NULL, "WCD_TX_OUTPUT"},
  3480. {"WCD_TX_OUTPUT", NULL, "ADC1_MIXER"},
  3481. {"ADC1_MIXER", "Switch", "ADC1 REQ"},
  3482. {"ADC1 REQ", NULL, "ADC1"},
  3483. {"ADC1", NULL, "ADC1 MUX"},
  3484. {"ADC1 MUX", "CH1_AMIC1", "AMIC1_MIXER"},
  3485. {"ADC1 MUX", "CH1_AMIC2", "AMIC2_MIXER"},
  3486. {"ADC1 MUX", "CH1_AMIC3", "AMIC3_MIXER"},
  3487. {"ADC1 MUX", "CH1_AMIC4", "AMIC4_MIXER"},
  3488. {"ADC1 MUX", "CH1_AMIC5", "AMIC5_MIXER"},
  3489. {"AMIC1_MIXER", "Switch", "AMIC1"},
  3490. {"AMIC1_MIXER", NULL, "VA_AMIC1_MIXER"},
  3491. {"VA_AMIC1_MIXER", "Switch", "VA AMIC1"},
  3492. {"AMIC2_MIXER", "Switch", "AMIC2"},
  3493. {"AMIC2_MIXER", NULL, "VA_AMIC2_MIXER"},
  3494. {"VA_AMIC2_MIXER", "Switch", "VA AMIC2"},
  3495. {"AMIC3_MIXER", "Switch", "AMIC3"},
  3496. {"AMIC3_MIXER", NULL, "VA_AMIC3_MIXER"},
  3497. {"VA_AMIC3_MIXER", "Switch", "VA AMIC3"},
  3498. {"AMIC4_MIXER", "Switch", "AMIC4"},
  3499. {"AMIC4_MIXER", NULL, "VA_AMIC4_MIXER"},
  3500. {"VA_AMIC4_MIXER", "Switch", "VA AMIC4"},
  3501. {"AMIC5_MIXER", "Switch", "AMIC5"},
  3502. {"AMIC5_MIXER", NULL, "VA_AMIC5_MIXER"},
  3503. {"VA_AMIC5_MIXER", "Switch", "VA AMIC5"},
  3504. /*ADC-2 (channel-2)*/
  3505. {"WCD_TX_DUMMY", NULL, "WCD_TX_OUTPUT"},
  3506. {"WCD_TX_OUTPUT", NULL, "ADC2_MIXER"},
  3507. {"ADC2_MIXER", "Switch", "ADC2 REQ"},
  3508. {"ADC2 REQ", NULL, "ADC2"},
  3509. {"ADC2", NULL, "ADC2 MUX"},
  3510. {"ADC2 MUX", "CH2_AMIC1", "AMIC1_MIXER"},
  3511. {"ADC2 MUX", "CH2_AMIC2", "AMIC2_MIXER"},
  3512. {"ADC2 MUX", "CH2_AMIC3", "AMIC3_MIXER"},
  3513. {"ADC2 MUX", "CH2_AMIC4", "AMIC4_MIXER"},
  3514. {"ADC2 MUX", "CH2_AMIC5", "AMIC5_MIXER"},
  3515. /*ADC-3 (channel-3)*/
  3516. {"WCD_TX_DUMMY", NULL, "WCD_TX_OUTPUT"},
  3517. {"WCD_TX_OUTPUT", NULL, "ADC3_MIXER"},
  3518. {"ADC3_MIXER", "Switch", "ADC3 REQ"},
  3519. {"ADC3 REQ", NULL, "ADC3"},
  3520. {"ADC3", NULL, "ADC3 MUX"},
  3521. {"ADC3 MUX", "CH3_AMIC1", "AMIC1_MIXER"},
  3522. {"ADC3 MUX", "CH3_AMIC3", "AMIC3_MIXER"},
  3523. {"ADC3 MUX", "CH3_AMIC4", "AMIC4_MIXER"},
  3524. {"ADC3 MUX", "CH3_AMIC5", "AMIC5_MIXER"},
  3525. /*ADC-4 (channel-4)*/
  3526. {"WCD_TX_DUMMY", NULL, "WCD_TX_OUTPUT"},
  3527. {"WCD_TX_OUTPUT", NULL, "ADC4_MIXER"},
  3528. {"ADC4_MIXER", "Switch", "ADC4 REQ"},
  3529. {"ADC4 REQ", NULL, "ADC4"},
  3530. {"ADC4", NULL, "ADC4 MUX"},
  3531. {"ADC4 MUX", "CH4_AMIC1", "AMIC1_MIXER"},
  3532. {"ADC4 MUX", "CH4_AMIC3", "AMIC3_MIXER"},
  3533. {"ADC4 MUX", "CH4_AMIC4", "AMIC4_MIXER"},
  3534. {"ADC4 MUX", "CH4_AMIC5", "AMIC5_MIXER"},
  3535. {"WCD_TX_OUTPUT", NULL, "DMIC1_MIXER"},
  3536. {"DMIC1_MIXER", "Switch", "DMIC1"},
  3537. {"WCD_TX_OUTPUT", NULL, "DMIC2_MIXER"},
  3538. {"DMIC2_MIXER", "Switch", "DMIC2"},
  3539. {"WCD_TX_OUTPUT", NULL, "DMIC3_MIXER"},
  3540. {"DMIC3_MIXER", "Switch", "DMIC3"},
  3541. {"WCD_TX_OUTPUT", NULL, "DMIC4_MIXER"},
  3542. {"DMIC4_MIXER", "Switch", "DMIC4"},
  3543. {"WCD_TX_OUTPUT", NULL, "DMIC5_MIXER"},
  3544. {"DMIC5_MIXER", "Switch", "DMIC5"},
  3545. {"WCD_TX_OUTPUT", NULL, "DMIC6_MIXER"},
  3546. {"DMIC6_MIXER", "Switch", "DMIC6"},
  3547. {"WCD_TX_OUTPUT", NULL, "DMIC7_MIXER"},
  3548. {"DMIC7_MIXER", "Switch", "DMIC7"},
  3549. {"WCD_TX_OUTPUT", NULL, "DMIC8_MIXER"},
  3550. {"DMIC8_MIXER", "Switch", "DMIC8"},
  3551. {"IN1_HPHL", NULL, "WCD_RX_DUMMY"},
  3552. {"IN1_HPHL", NULL, "VDD_BUCK"},
  3553. {"IN1_HPHL", NULL, "CLS_H_PORT"},
  3554. {"RX1 MUX", NULL, "IN1_HPHL"},
  3555. {"RX1", NULL, "RX1 MUX"},
  3556. {"RDAC1", NULL, "RX1"},
  3557. {"HPHL_RDAC", "Switch", "RDAC1"},
  3558. {"HPHL PGA", NULL, "HPHL_RDAC"},
  3559. {"HPHL", NULL, "HPHL PGA"},
  3560. {"IN2_HPHR", NULL, "WCD_RX_DUMMY"},
  3561. {"IN2_HPHR", NULL, "VDD_BUCK"},
  3562. {"IN2_HPHR", NULL, "CLS_H_PORT"},
  3563. {"RX2 MUX", NULL, "IN2_HPHR"},
  3564. {"RX2", NULL, "RX2 MUX"},
  3565. {"RDAC2", NULL, "RX2"},
  3566. {"HPHR_RDAC", "Switch", "RDAC2"},
  3567. {"HPHR PGA", NULL, "HPHR_RDAC"},
  3568. {"HPHR", NULL, "HPHR PGA"},
  3569. {"IN3_EAR", NULL, "WCD_RX_DUMMY"},
  3570. {"IN3_EAR", NULL, "VDD_BUCK"},
  3571. {"IN3_EAR", NULL, "CLS_H_PORT"},
  3572. {"RX3", NULL, "IN3_EAR"},
  3573. {"RDAC3_MUX", "RX3", "RX3"},
  3574. {"RDAC3_MUX", "RX1", "RX1"},
  3575. {"RDAC3", NULL, "RDAC3_MUX"},
  3576. {"EAR_RDAC", "Switch", "RDAC3"},
  3577. {"EAR PGA", NULL, "EAR_RDAC"},
  3578. {"EAR", NULL, "EAR PGA"},
  3579. };
  3580. static ssize_t wcd939x_version_read(struct snd_info_entry *entry,
  3581. void *file_private_data,
  3582. struct file *file,
  3583. char __user *buf, size_t count,
  3584. loff_t pos)
  3585. {
  3586. struct wcd939x_priv *priv;
  3587. char buffer[WCD939X_VERSION_ENTRY_SIZE];
  3588. int len = 0;
  3589. priv = (struct wcd939x_priv *) entry->private_data;
  3590. if (!priv) {
  3591. pr_err_ratelimited("%s: wcd939x priv is null\n", __func__);
  3592. return -EINVAL;
  3593. }
  3594. switch (priv->version) {
  3595. case WCD939X_VERSION_1_0:
  3596. len = snprintf(buffer, sizeof(buffer), "WCD939X_1_0\n");
  3597. break;
  3598. default:
  3599. len = snprintf(buffer, sizeof(buffer), "VER_UNDEFINED\n");
  3600. }
  3601. return simple_read_from_buffer(buf, count, &pos, buffer, len);
  3602. }
  3603. static struct snd_info_entry_ops wcd939x_info_ops = {
  3604. .read = wcd939x_version_read,
  3605. };
  3606. static ssize_t wcd939x_variant_read(struct snd_info_entry *entry,
  3607. void *file_private_data,
  3608. struct file *file,
  3609. char __user *buf, size_t count,
  3610. loff_t pos)
  3611. {
  3612. struct wcd939x_priv *priv;
  3613. char buffer[WCD939X_VARIANT_ENTRY_SIZE];
  3614. int len = 0;
  3615. priv = (struct wcd939x_priv *) entry->private_data;
  3616. if (!priv) {
  3617. pr_err_ratelimited("%s: wcd939x priv is null\n", __func__);
  3618. return -EINVAL;
  3619. }
  3620. switch (priv->variant) {
  3621. case WCD9390:
  3622. len = snprintf(buffer, sizeof(buffer), "WCD9390\n");
  3623. break;
  3624. case WCD9395:
  3625. len = snprintf(buffer, sizeof(buffer), "WCD9395\n");
  3626. break;
  3627. default:
  3628. len = snprintf(buffer, sizeof(buffer), "VER_UNDEFINED\n");
  3629. }
  3630. return simple_read_from_buffer(buf, count, &pos, buffer, len);
  3631. }
  3632. static struct snd_info_entry_ops wcd939x_variant_ops = {
  3633. .read = wcd939x_variant_read,
  3634. };
  3635. /*
  3636. * wcd939x_get_codec_variant
  3637. * @component: component instance
  3638. *
  3639. * Return: codec variant or -EINVAL in error.
  3640. */
  3641. int wcd939x_get_codec_variant(struct snd_soc_component *component)
  3642. {
  3643. struct wcd939x_priv *priv = NULL;
  3644. if (!component)
  3645. return -EINVAL;
  3646. priv = snd_soc_component_get_drvdata(component);
  3647. if (!priv) {
  3648. dev_err(component->dev,
  3649. "%s:wcd939x not probed\n", __func__);
  3650. return 0;
  3651. }
  3652. return priv->variant;
  3653. }
  3654. EXPORT_SYMBOL(wcd939x_get_codec_variant);
  3655. /*
  3656. * wcd939x_info_create_codec_entry - creates wcd939x module
  3657. * @codec_root: The parent directory
  3658. * @component: component instance
  3659. *
  3660. * Creates wcd939x module, variant and version entry under the given
  3661. * parent directory.
  3662. *
  3663. * Return: 0 on success or negative error code on failure.
  3664. */
  3665. int wcd939x_info_create_codec_entry(struct snd_info_entry *codec_root,
  3666. struct snd_soc_component *component)
  3667. {
  3668. struct snd_info_entry *version_entry;
  3669. struct snd_info_entry *variant_entry;
  3670. struct wcd939x_priv *priv;
  3671. struct snd_soc_card *card;
  3672. if (!codec_root || !component)
  3673. return -EINVAL;
  3674. priv = snd_soc_component_get_drvdata(component);
  3675. if (priv->entry) {
  3676. dev_dbg(priv->dev,
  3677. "%s:wcd939x module already created\n", __func__);
  3678. return 0;
  3679. }
  3680. card = component->card;
  3681. priv->entry = snd_info_create_module_entry(codec_root->module,
  3682. "wcd939x", codec_root);
  3683. if (!priv->entry) {
  3684. dev_dbg(component->dev, "%s: failed to create wcd939x entry\n",
  3685. __func__);
  3686. return -ENOMEM;
  3687. }
  3688. priv->entry->mode = S_IFDIR | 0555;
  3689. if (snd_info_register(priv->entry) < 0) {
  3690. snd_info_free_entry(priv->entry);
  3691. return -ENOMEM;
  3692. }
  3693. version_entry = snd_info_create_card_entry(card->snd_card,
  3694. "version",
  3695. priv->entry);
  3696. if (!version_entry) {
  3697. dev_dbg(component->dev, "%s: failed to create wcd939x version entry\n",
  3698. __func__);
  3699. snd_info_free_entry(priv->entry);
  3700. return -ENOMEM;
  3701. }
  3702. version_entry->private_data = priv;
  3703. version_entry->size = WCD939X_VERSION_ENTRY_SIZE;
  3704. version_entry->content = SNDRV_INFO_CONTENT_DATA;
  3705. version_entry->c.ops = &wcd939x_info_ops;
  3706. if (snd_info_register(version_entry) < 0) {
  3707. snd_info_free_entry(version_entry);
  3708. snd_info_free_entry(priv->entry);
  3709. return -ENOMEM;
  3710. }
  3711. priv->version_entry = version_entry;
  3712. variant_entry = snd_info_create_card_entry(card->snd_card,
  3713. "variant",
  3714. priv->entry);
  3715. if (!variant_entry) {
  3716. dev_dbg(component->dev, "%s: failed to create wcd939x variant entry\n",
  3717. __func__);
  3718. snd_info_free_entry(version_entry);
  3719. snd_info_free_entry(priv->entry);
  3720. return -ENOMEM;
  3721. }
  3722. variant_entry->private_data = priv;
  3723. variant_entry->size = WCD939X_VARIANT_ENTRY_SIZE;
  3724. variant_entry->content = SNDRV_INFO_CONTENT_DATA;
  3725. variant_entry->c.ops = &wcd939x_variant_ops;
  3726. if (snd_info_register(variant_entry) < 0) {
  3727. snd_info_free_entry(variant_entry);
  3728. snd_info_free_entry(version_entry);
  3729. snd_info_free_entry(priv->entry);
  3730. return -ENOMEM;
  3731. }
  3732. priv->variant_entry = variant_entry;
  3733. return 0;
  3734. }
  3735. EXPORT_SYMBOL(wcd939x_info_create_codec_entry);
  3736. static int wcd939x_set_micbias_data(struct wcd939x_priv *wcd939x,
  3737. struct wcd939x_pdata *pdata)
  3738. {
  3739. int vout_ctl_1 = 0, vout_ctl_2 = 0, vout_ctl_3 = 0, vout_ctl_4 = 0;
  3740. int rc = 0;
  3741. if (!pdata) {
  3742. dev_err(wcd939x->dev, "%s: NULL pdata\n", __func__);
  3743. return -ENODEV;
  3744. }
  3745. /* set micbias voltage */
  3746. vout_ctl_1 = wcd939x_get_micb_vout_ctl_val(pdata->micbias.micb1_mv);
  3747. vout_ctl_2 = wcd939x_get_micb_vout_ctl_val(pdata->micbias.micb2_mv);
  3748. vout_ctl_3 = wcd939x_get_micb_vout_ctl_val(pdata->micbias.micb3_mv);
  3749. vout_ctl_4 = wcd939x_get_micb_vout_ctl_val(pdata->micbias.micb4_mv);
  3750. if (vout_ctl_1 < 0 || vout_ctl_2 < 0 || vout_ctl_3 < 0 ||
  3751. vout_ctl_4 < 0) {
  3752. rc = -EINVAL;
  3753. goto done;
  3754. }
  3755. regmap_update_bits(wcd939x->regmap, WCD939X_MICB1, 0x3F,
  3756. vout_ctl_1);
  3757. regmap_update_bits(wcd939x->regmap, WCD939X_MICB2, 0x3F,
  3758. vout_ctl_2);
  3759. regmap_update_bits(wcd939x->regmap, WCD939X_MICB3, 0x3F,
  3760. vout_ctl_3);
  3761. regmap_update_bits(wcd939x->regmap, WCD939X_MICB4, 0x3F,
  3762. vout_ctl_4);
  3763. done:
  3764. return rc;
  3765. }
  3766. static int wcd939x_soc_codec_probe(struct snd_soc_component *component)
  3767. {
  3768. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  3769. struct snd_soc_dapm_context *dapm =
  3770. snd_soc_component_get_dapm(component);
  3771. int ret = -EINVAL;
  3772. dev_info(component->dev, "%s()\n", __func__);
  3773. wcd939x = snd_soc_component_get_drvdata(component);
  3774. if (!wcd939x)
  3775. return -EINVAL;
  3776. wcd939x->component = component;
  3777. snd_soc_component_init_regmap(component, wcd939x->regmap);
  3778. devm_regmap_qti_debugfs_register(&wcd939x->tx_swr_dev->dev, wcd939x->regmap);
  3779. /*Harmonium contains only one variant i.e wcd9395*/
  3780. wcd939x->variant = WCD9395;
  3781. wcd939x->fw_data = devm_kzalloc(component->dev,
  3782. sizeof(*(wcd939x->fw_data)),
  3783. GFP_KERNEL);
  3784. if (!wcd939x->fw_data) {
  3785. dev_err(component->dev, "Failed to allocate fw_data\n");
  3786. ret = -ENOMEM;
  3787. goto err;
  3788. }
  3789. set_bit(WCD9XXX_MBHC_CAL, wcd939x->fw_data->cal_bit);
  3790. ret = wcd_cal_create_hwdep(wcd939x->fw_data,
  3791. WCD9XXX_CODEC_HWDEP_NODE, component);
  3792. if (ret < 0) {
  3793. dev_err(component->dev, "%s hwdep failed %d\n", __func__, ret);
  3794. goto err_hwdep;
  3795. }
  3796. ret = wcd939x_mbhc_init(&wcd939x->mbhc, component, wcd939x->fw_data);
  3797. if (ret) {
  3798. pr_err("%s: mbhc initialization failed\n", __func__);
  3799. goto err_hwdep;
  3800. }
  3801. snd_soc_dapm_ignore_suspend(dapm, "WCD939X_AIF Playback");
  3802. snd_soc_dapm_ignore_suspend(dapm, "WCD939X_AIF Capture");
  3803. snd_soc_dapm_ignore_suspend(dapm, "AMIC1");
  3804. snd_soc_dapm_ignore_suspend(dapm, "AMIC2");
  3805. snd_soc_dapm_ignore_suspend(dapm, "AMIC3");
  3806. snd_soc_dapm_ignore_suspend(dapm, "AMIC4");
  3807. snd_soc_dapm_ignore_suspend(dapm, "AMIC5");
  3808. snd_soc_dapm_ignore_suspend(dapm, "VA AMIC1");
  3809. snd_soc_dapm_ignore_suspend(dapm, "VA AMIC2");
  3810. snd_soc_dapm_ignore_suspend(dapm, "VA AMIC3");
  3811. snd_soc_dapm_ignore_suspend(dapm, "VA AMIC4");
  3812. snd_soc_dapm_ignore_suspend(dapm, "VA AMIC5");
  3813. snd_soc_dapm_ignore_suspend(dapm, "WCD_TX_OUTPUT");
  3814. snd_soc_dapm_ignore_suspend(dapm, "IN1_HPHL");
  3815. snd_soc_dapm_ignore_suspend(dapm, "IN2_HPHR");
  3816. snd_soc_dapm_ignore_suspend(dapm, "IN3_EAR");
  3817. snd_soc_dapm_ignore_suspend(dapm, "EAR");
  3818. snd_soc_dapm_ignore_suspend(dapm, "HPHL");
  3819. snd_soc_dapm_ignore_suspend(dapm, "HPHR");
  3820. snd_soc_dapm_ignore_suspend(dapm, "WCD_TX_DUMMY");
  3821. snd_soc_dapm_ignore_suspend(dapm, "WCD_RX_DUMMY");
  3822. snd_soc_dapm_sync(dapm);
  3823. wcd_cls_h_init(&wcd939x->clsh_info);
  3824. wcd939x_init_reg(component);
  3825. if (wcd939x->variant == WCD9390) {
  3826. ret = snd_soc_add_component_controls(component, wcd9390_snd_controls,
  3827. ARRAY_SIZE(wcd9390_snd_controls));
  3828. if (ret < 0) {
  3829. dev_err(component->dev,
  3830. "%s: Failed to add snd ctrls for variant: %d\n",
  3831. __func__, wcd939x->variant);
  3832. goto err_hwdep;
  3833. }
  3834. }
  3835. if (wcd939x->variant == WCD9395) {
  3836. ret = snd_soc_add_component_controls(component, wcd9395_snd_controls,
  3837. ARRAY_SIZE(wcd9395_snd_controls));
  3838. if (ret < 0) {
  3839. dev_err(component->dev,
  3840. "%s: Failed to add snd ctrls for variant: %d\n",
  3841. __func__, wcd939x->variant);
  3842. goto err_hwdep;
  3843. }
  3844. }
  3845. wcd939x->version = WCD939X_VERSION_1_0;
  3846. /* Register event notifier */
  3847. wcd939x->nblock.notifier_call = wcd939x_event_notify;
  3848. if (wcd939x->register_notifier) {
  3849. ret = wcd939x->register_notifier(wcd939x->handle,
  3850. &wcd939x->nblock,
  3851. true);
  3852. if (ret) {
  3853. dev_err(component->dev,
  3854. "%s: Failed to register notifier %d\n",
  3855. __func__, ret);
  3856. return ret;
  3857. }
  3858. }
  3859. return ret;
  3860. err_hwdep:
  3861. wcd939x->fw_data = NULL;
  3862. err:
  3863. return ret;
  3864. }
  3865. static void wcd939x_soc_codec_remove(struct snd_soc_component *component)
  3866. {
  3867. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  3868. if (!wcd939x) {
  3869. dev_err(component->dev, "%s: wcd939x is already NULL\n",
  3870. __func__);
  3871. return;
  3872. }
  3873. if (wcd939x->register_notifier)
  3874. wcd939x->register_notifier(wcd939x->handle,
  3875. &wcd939x->nblock,
  3876. false);
  3877. }
  3878. static int wcd939x_soc_codec_suspend(struct snd_soc_component *component)
  3879. {
  3880. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  3881. if (!wcd939x)
  3882. return 0;
  3883. wcd939x->dapm_bias_off = true;
  3884. return 0;
  3885. }
  3886. static int wcd939x_soc_codec_resume(struct snd_soc_component *component)
  3887. {
  3888. struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
  3889. if (!wcd939x)
  3890. return 0;
  3891. wcd939x->dapm_bias_off = false;
  3892. return 0;
  3893. }
  3894. static struct snd_soc_component_driver soc_codec_dev_wcd939x = {
  3895. .name = WCD939X_DRV_NAME,
  3896. .probe = wcd939x_soc_codec_probe,
  3897. .remove = wcd939x_soc_codec_remove,
  3898. .controls = wcd939x_snd_controls,
  3899. .num_controls = ARRAY_SIZE(wcd939x_snd_controls),
  3900. .dapm_widgets = wcd939x_dapm_widgets,
  3901. .num_dapm_widgets = ARRAY_SIZE(wcd939x_dapm_widgets),
  3902. .dapm_routes = wcd939x_audio_map,
  3903. .num_dapm_routes = ARRAY_SIZE(wcd939x_audio_map),
  3904. .suspend = wcd939x_soc_codec_suspend,
  3905. .resume = wcd939x_soc_codec_resume,
  3906. };
  3907. static int wcd939x_reset(struct device *dev)
  3908. {
  3909. struct wcd939x_priv *wcd939x = NULL;
  3910. int rc = 0;
  3911. int value = 0;
  3912. if (!dev)
  3913. return -ENODEV;
  3914. wcd939x = dev_get_drvdata(dev);
  3915. if (!wcd939x)
  3916. return -EINVAL;
  3917. if (!wcd939x->rst_np) {
  3918. dev_err_ratelimited(dev, "%s: reset gpio device node not specified\n",
  3919. __func__);
  3920. return -EINVAL;
  3921. }
  3922. value = msm_cdc_pinctrl_get_state(wcd939x->rst_np);
  3923. if (value > 0)
  3924. return 0;
  3925. rc = msm_cdc_pinctrl_select_sleep_state(wcd939x->rst_np);
  3926. if (rc) {
  3927. dev_err_ratelimited(dev, "%s: wcd sleep state request fail!\n",
  3928. __func__);
  3929. return rc;
  3930. }
  3931. /* 20us sleep required after pulling the reset gpio to LOW */
  3932. usleep_range(20, 30);
  3933. rc = msm_cdc_pinctrl_select_active_state(wcd939x->rst_np);
  3934. if (rc) {
  3935. dev_err_ratelimited(dev, "%s: wcd active state request fail!\n",
  3936. __func__);
  3937. return rc;
  3938. }
  3939. /* 20us sleep required after pulling the reset gpio to HIGH */
  3940. usleep_range(20, 30);
  3941. return rc;
  3942. }
  3943. static int wcd939x_read_of_property_u32(struct device *dev, const char *name,
  3944. u32 *val)
  3945. {
  3946. int rc = 0;
  3947. rc = of_property_read_u32(dev->of_node, name, val);
  3948. if (rc)
  3949. dev_err(dev, "%s: Looking up %s property in node %s failed\n",
  3950. __func__, name, dev->of_node->full_name);
  3951. return rc;
  3952. }
  3953. static void wcd939x_dt_parse_micbias_info(struct device *dev,
  3954. struct wcd939x_micbias_setting *mb)
  3955. {
  3956. u32 prop_val = 0;
  3957. int rc = 0;
  3958. /* MB1 */
  3959. if (of_find_property(dev->of_node, "qcom,cdc-micbias1-mv",
  3960. NULL)) {
  3961. rc = wcd939x_read_of_property_u32(dev,
  3962. "qcom,cdc-micbias1-mv",
  3963. &prop_val);
  3964. if (!rc)
  3965. mb->micb1_mv = prop_val;
  3966. } else {
  3967. dev_info(dev, "%s: Micbias1 DT property not found\n",
  3968. __func__);
  3969. }
  3970. /* MB2 */
  3971. if (of_find_property(dev->of_node, "qcom,cdc-micbias2-mv",
  3972. NULL)) {
  3973. rc = wcd939x_read_of_property_u32(dev,
  3974. "qcom,cdc-micbias2-mv",
  3975. &prop_val);
  3976. if (!rc)
  3977. mb->micb2_mv = prop_val;
  3978. } else {
  3979. dev_info(dev, "%s: Micbias2 DT property not found\n",
  3980. __func__);
  3981. }
  3982. /* MB3 */
  3983. if (of_find_property(dev->of_node, "qcom,cdc-micbias3-mv",
  3984. NULL)) {
  3985. rc = wcd939x_read_of_property_u32(dev,
  3986. "qcom,cdc-micbias3-mv",
  3987. &prop_val);
  3988. if (!rc)
  3989. mb->micb3_mv = prop_val;
  3990. } else {
  3991. dev_info(dev, "%s: Micbias3 DT property not found\n",
  3992. __func__);
  3993. }
  3994. /* MB4 */
  3995. if (of_find_property(dev->of_node, "qcom,cdc-micbias4-mv",
  3996. NULL)) {
  3997. rc = wcd939x_read_of_property_u32(dev,
  3998. "qcom,cdc-micbias4-mv",
  3999. &prop_val);
  4000. if (!rc)
  4001. mb->micb4_mv = prop_val;
  4002. } else {
  4003. dev_info(dev, "%s: Micbias4 DT property not found\n",
  4004. __func__);
  4005. }
  4006. }
  4007. static int wcd939x_reset_low(struct device *dev)
  4008. {
  4009. struct wcd939x_priv *wcd939x = NULL;
  4010. int rc = 0;
  4011. if (!dev)
  4012. return -ENODEV;
  4013. wcd939x = dev_get_drvdata(dev);
  4014. if (!wcd939x)
  4015. return -EINVAL;
  4016. if (!wcd939x->rst_np) {
  4017. dev_err_ratelimited(dev, "%s: reset gpio device node not specified\n",
  4018. __func__);
  4019. return -EINVAL;
  4020. }
  4021. rc = msm_cdc_pinctrl_select_sleep_state(wcd939x->rst_np);
  4022. if (rc) {
  4023. dev_err_ratelimited(dev, "%s: wcd sleep state request fail!\n",
  4024. __func__);
  4025. return rc;
  4026. }
  4027. /* 20us sleep required after pulling the reset gpio to LOW */
  4028. usleep_range(20, 30);
  4029. return rc;
  4030. }
  4031. struct wcd939x_pdata *wcd939x_populate_dt_data(struct device *dev)
  4032. {
  4033. struct wcd939x_pdata *pdata = NULL;
  4034. pdata = devm_kzalloc(dev, sizeof(struct wcd939x_pdata),
  4035. GFP_KERNEL);
  4036. if (!pdata)
  4037. return NULL;
  4038. pdata->rst_np = of_parse_phandle(dev->of_node,
  4039. "qcom,wcd-rst-gpio-node", 0);
  4040. if (!pdata->rst_np) {
  4041. dev_err_ratelimited(dev, "%s: Looking up %s property in node %s failed\n",
  4042. __func__, "qcom,wcd-rst-gpio-node",
  4043. dev->of_node->full_name);
  4044. return NULL;
  4045. }
  4046. /* Parse power supplies */
  4047. msm_cdc_get_power_supplies(dev, &pdata->regulator,
  4048. &pdata->num_supplies);
  4049. if (!pdata->regulator || (pdata->num_supplies <= 0)) {
  4050. dev_err_ratelimited(dev, "%s: no power supplies defined for codec\n",
  4051. __func__);
  4052. return NULL;
  4053. }
  4054. pdata->rx_slave = of_parse_phandle(dev->of_node, "qcom,rx-slave", 0);
  4055. pdata->tx_slave = of_parse_phandle(dev->of_node, "qcom,tx-slave", 0);
  4056. wcd939x_dt_parse_micbias_info(dev, &pdata->micbias);
  4057. return pdata;
  4058. }
  4059. static irqreturn_t wcd939x_wd_handle_irq(int irq, void *data)
  4060. {
  4061. pr_err_ratelimited("%s: Watchdog interrupt for irq =%d triggered\n",
  4062. __func__, irq);
  4063. return IRQ_HANDLED;
  4064. }
  4065. static struct snd_soc_dai_driver wcd939x_dai[] = {
  4066. {
  4067. .name = "wcd939x_cdc",
  4068. .playback = {
  4069. .stream_name = "WCD939X_AIF Playback",
  4070. .rates = WCD939X_RATES | WCD939X_FRAC_RATES,
  4071. .formats = WCD939X_FORMATS,
  4072. .rate_max = 384000,
  4073. .rate_min = 8000,
  4074. .channels_min = 1,
  4075. .channels_max = 4,
  4076. },
  4077. .capture = {
  4078. .stream_name = "WCD939X_AIF Capture",
  4079. .rates = WCD939X_RATES | WCD939X_FRAC_RATES,
  4080. .formats = WCD939X_FORMATS,
  4081. .rate_max = 384000,
  4082. .rate_min = 8000,
  4083. .channels_min = 1,
  4084. .channels_max = 4,
  4085. },
  4086. },
  4087. };
  4088. static int wcd939x_bind(struct device *dev)
  4089. {
  4090. int ret = 0, i = 0;
  4091. struct wcd939x_pdata *pdata = dev_get_platdata(dev);
  4092. struct wcd939x_priv *wcd939x = dev_get_drvdata(dev);
  4093. /*
  4094. * Add 5msec delay to provide sufficient time for
  4095. * soundwire auto enumeration of slave devices as
  4096. * as per HW requirement.
  4097. */
  4098. usleep_range(5000, 5010);
  4099. ret = component_bind_all(dev, wcd939x);
  4100. if (ret) {
  4101. dev_err_ratelimited(dev, "%s: Slave bind failed, ret = %d\n",
  4102. __func__, ret);
  4103. return ret;
  4104. }
  4105. wcd939x->rx_swr_dev = get_matching_swr_slave_device(pdata->rx_slave);
  4106. if (!wcd939x->rx_swr_dev) {
  4107. dev_err_ratelimited(dev, "%s: Could not find RX swr slave device\n",
  4108. __func__);
  4109. ret = -ENODEV;
  4110. goto err;
  4111. }
  4112. wcd939x->tx_swr_dev = get_matching_swr_slave_device(pdata->tx_slave);
  4113. if (!wcd939x->tx_swr_dev) {
  4114. dev_err_ratelimited(dev, "%s: Could not find TX swr slave device\n",
  4115. __func__);
  4116. ret = -ENODEV;
  4117. goto err;
  4118. }
  4119. swr_init_port_params(wcd939x->tx_swr_dev, SWR_NUM_PORTS,
  4120. wcd939x->swr_tx_port_params);
  4121. wcd939x->regmap = devm_regmap_init_swr(wcd939x->tx_swr_dev,
  4122. &wcd939x_regmap_config);
  4123. if (!wcd939x->regmap) {
  4124. dev_err_ratelimited(dev, "%s: Regmap init failed\n",
  4125. __func__);
  4126. goto err;
  4127. }
  4128. /* Set all interupts as edge triggered */
  4129. for (i = 0; i < wcd939x_regmap_irq_chip.num_regs; i++)
  4130. regmap_write(wcd939x->regmap,
  4131. (WCD939X_INTR_LEVEL_0 + i), 0);
  4132. wcd939x_regmap_irq_chip.irq_drv_data = wcd939x;
  4133. wcd939x->irq_info.wcd_regmap_irq_chip = &wcd939x_regmap_irq_chip;
  4134. wcd939x->irq_info.codec_name = "WCD939X";
  4135. wcd939x->irq_info.regmap = wcd939x->regmap;
  4136. wcd939x->irq_info.dev = dev;
  4137. ret = wcd_irq_init(&wcd939x->irq_info, &wcd939x->virq);
  4138. if (ret) {
  4139. dev_err_ratelimited(wcd939x->dev, "%s: IRQ init failed: %d\n",
  4140. __func__, ret);
  4141. goto err;
  4142. }
  4143. wcd939x->tx_swr_dev->slave_irq = wcd939x->virq;
  4144. ret = wcd939x_set_micbias_data(wcd939x, pdata);
  4145. if (ret < 0) {
  4146. dev_err_ratelimited(dev, "%s: bad micbias pdata\n", __func__);
  4147. goto err_irq;
  4148. }
  4149. /* Request for watchdog interrupt */
  4150. wcd_request_irq(&wcd939x->irq_info, WCD939X_IRQ_HPHR_PDM_WD_INT,
  4151. "HPHR PDM WD INT", wcd939x_wd_handle_irq, NULL);
  4152. wcd_request_irq(&wcd939x->irq_info, WCD939X_IRQ_HPHL_PDM_WD_INT,
  4153. "HPHL PDM WD INT", wcd939x_wd_handle_irq, NULL);
  4154. wcd_request_irq(&wcd939x->irq_info, WCD939X_IRQ_EAR_PDM_WD_INT,
  4155. "EAR PDM WD INT", wcd939x_wd_handle_irq, NULL);
  4156. /* Disable watchdog interrupt for HPH and EAR */
  4157. wcd_disable_irq(&wcd939x->irq_info, WCD939X_IRQ_HPHR_PDM_WD_INT);
  4158. wcd_disable_irq(&wcd939x->irq_info, WCD939X_IRQ_HPHL_PDM_WD_INT);
  4159. wcd_disable_irq(&wcd939x->irq_info, WCD939X_IRQ_EAR_PDM_WD_INT);
  4160. ret = snd_soc_register_component(dev, &soc_codec_dev_wcd939x,
  4161. wcd939x_dai, ARRAY_SIZE(wcd939x_dai));
  4162. if (ret) {
  4163. dev_err_ratelimited(dev, "%s: Codec registration failed\n",
  4164. __func__);
  4165. goto err_irq;
  4166. }
  4167. wcd939x->dev_up = true;
  4168. return ret;
  4169. err_irq:
  4170. wcd_irq_exit(&wcd939x->irq_info, wcd939x->virq);
  4171. err:
  4172. component_unbind_all(dev, wcd939x);
  4173. return ret;
  4174. }
  4175. static void wcd939x_unbind(struct device *dev)
  4176. {
  4177. struct wcd939x_priv *wcd939x = dev_get_drvdata(dev);
  4178. wcd_free_irq(&wcd939x->irq_info, WCD939X_IRQ_HPHR_PDM_WD_INT, NULL);
  4179. wcd_free_irq(&wcd939x->irq_info, WCD939X_IRQ_HPHL_PDM_WD_INT, NULL);
  4180. wcd_free_irq(&wcd939x->irq_info, WCD939X_IRQ_EAR_PDM_WD_INT, NULL);
  4181. wcd_irq_exit(&wcd939x->irq_info, wcd939x->virq);
  4182. snd_soc_unregister_component(dev);
  4183. component_unbind_all(dev, wcd939x);
  4184. }
  4185. static const struct of_device_id wcd939x_dt_match[] = {
  4186. { .compatible = "qcom,wcd939x-codec", .data = "wcd939x"},
  4187. {}
  4188. };
  4189. static const struct component_master_ops wcd939x_comp_ops = {
  4190. .bind = wcd939x_bind,
  4191. .unbind = wcd939x_unbind,
  4192. };
  4193. static int wcd939x_compare_of(struct device *dev, void *data)
  4194. {
  4195. return dev->of_node == data;
  4196. }
  4197. static void wcd939x_release_of(struct device *dev, void *data)
  4198. {
  4199. of_node_put(data);
  4200. }
  4201. static int wcd939x_add_slave_components(struct device *dev,
  4202. struct component_match **matchptr)
  4203. {
  4204. struct device_node *np, *rx_node, *tx_node;
  4205. np = dev->of_node;
  4206. rx_node = of_parse_phandle(np, "qcom,rx-slave", 0);
  4207. if (!rx_node) {
  4208. dev_err_ratelimited(dev, "%s: Rx-slave node not defined\n", __func__);
  4209. return -ENODEV;
  4210. }
  4211. of_node_get(rx_node);
  4212. component_match_add_release(dev, matchptr,
  4213. wcd939x_release_of,
  4214. wcd939x_compare_of,
  4215. rx_node);
  4216. tx_node = of_parse_phandle(np, "qcom,tx-slave", 0);
  4217. if (!tx_node) {
  4218. dev_err_ratelimited(dev, "%s: Tx-slave node not defined\n", __func__);
  4219. return -ENODEV;
  4220. }
  4221. of_node_get(tx_node);
  4222. component_match_add_release(dev, matchptr,
  4223. wcd939x_release_of,
  4224. wcd939x_compare_of,
  4225. tx_node);
  4226. return 0;
  4227. }
  4228. static int wcd939x_probe(struct platform_device *pdev)
  4229. {
  4230. struct component_match *match = NULL;
  4231. struct wcd939x_priv *wcd939x = NULL;
  4232. struct wcd939x_pdata *pdata = NULL;
  4233. struct wcd_ctrl_platform_data *plat_data = NULL;
  4234. struct device *dev = &pdev->dev;
  4235. int ret;
  4236. wcd939x = devm_kzalloc(dev, sizeof(struct wcd939x_priv),
  4237. GFP_KERNEL);
  4238. if (!wcd939x)
  4239. return -ENOMEM;
  4240. dev_set_drvdata(dev, wcd939x);
  4241. wcd939x->dev = dev;
  4242. pdata = wcd939x_populate_dt_data(dev);
  4243. if (!pdata) {
  4244. dev_err(dev, "%s: Fail to obtain platform data\n", __func__);
  4245. return -EINVAL;
  4246. }
  4247. dev->platform_data = pdata;
  4248. wcd939x->rst_np = pdata->rst_np;
  4249. ret = msm_cdc_init_supplies(dev, &wcd939x->supplies,
  4250. pdata->regulator, pdata->num_supplies);
  4251. if (!wcd939x->supplies) {
  4252. dev_err(dev, "%s: Cannot init wcd supplies\n",
  4253. __func__);
  4254. return ret;
  4255. }
  4256. plat_data = dev_get_platdata(dev->parent);
  4257. if (!plat_data) {
  4258. dev_err(dev, "%s: platform data from parent is NULL\n",
  4259. __func__);
  4260. return -EINVAL;
  4261. }
  4262. wcd939x->handle = (void *)plat_data->handle;
  4263. if (!wcd939x->handle) {
  4264. dev_err(dev, "%s: handle is NULL\n", __func__);
  4265. return -EINVAL;
  4266. }
  4267. wcd939x->update_wcd_event = plat_data->update_wcd_event;
  4268. if (!wcd939x->update_wcd_event) {
  4269. dev_err(dev, "%s: update_wcd_event api is null!\n",
  4270. __func__);
  4271. return -EINVAL;
  4272. }
  4273. wcd939x->register_notifier = plat_data->register_notifier;
  4274. if (!wcd939x->register_notifier) {
  4275. dev_err(dev, "%s: register_notifier api is null!\n",
  4276. __func__);
  4277. return -EINVAL;
  4278. }
  4279. ret = msm_cdc_enable_static_supplies(&pdev->dev, wcd939x->supplies,
  4280. pdata->regulator,
  4281. pdata->num_supplies);
  4282. if (ret) {
  4283. dev_err(dev, "%s: wcd static supply enable failed!\n",
  4284. __func__);
  4285. return ret;
  4286. }
  4287. ret = wcd939x_parse_port_mapping(dev, "qcom,rx_swr_ch_map",
  4288. CODEC_RX);
  4289. ret |= wcd939x_parse_port_mapping(dev, "qcom,tx_swr_ch_map",
  4290. CODEC_TX);
  4291. if (ret) {
  4292. dev_err(dev, "Failed to read port mapping\n");
  4293. goto err;
  4294. }
  4295. ret = wcd939x_parse_port_params(dev, "qcom,swr-tx-port-params",
  4296. CODEC_TX);
  4297. if (ret) {
  4298. dev_err(dev, "Failed to read port params\n");
  4299. goto err;
  4300. }
  4301. mutex_init(&wcd939x->wakeup_lock);
  4302. mutex_init(&wcd939x->micb_lock);
  4303. ret = wcd939x_add_slave_components(dev, &match);
  4304. if (ret)
  4305. goto err_lock_init;
  4306. wcd939x_reset(dev);
  4307. wcd939x->wakeup = wcd939x_wakeup;
  4308. return component_master_add_with_match(dev,
  4309. &wcd939x_comp_ops, match);
  4310. err_lock_init:
  4311. mutex_destroy(&wcd939x->micb_lock);
  4312. mutex_destroy(&wcd939x->wakeup_lock);
  4313. err:
  4314. return ret;
  4315. }
  4316. static int wcd939x_remove(struct platform_device *pdev)
  4317. {
  4318. struct wcd939x_priv *wcd939x = NULL;
  4319. wcd939x = platform_get_drvdata(pdev);
  4320. component_master_del(&pdev->dev, &wcd939x_comp_ops);
  4321. mutex_destroy(&wcd939x->micb_lock);
  4322. mutex_destroy(&wcd939x->wakeup_lock);
  4323. dev_set_drvdata(&pdev->dev, NULL);
  4324. return 0;
  4325. }
  4326. #ifdef CONFIG_PM_SLEEP
  4327. static int wcd939x_suspend(struct device *dev)
  4328. {
  4329. struct wcd939x_priv *wcd939x = NULL;
  4330. int ret = 0;
  4331. struct wcd939x_pdata *pdata = NULL;
  4332. if (!dev)
  4333. return -ENODEV;
  4334. wcd939x = dev_get_drvdata(dev);
  4335. if (!wcd939x)
  4336. return -EINVAL;
  4337. pdata = dev_get_platdata(wcd939x->dev);
  4338. if (!pdata) {
  4339. dev_err_ratelimited(dev, "%s: pdata is NULL\n", __func__);
  4340. return -EINVAL;
  4341. }
  4342. if (test_bit(ALLOW_BUCK_DISABLE, &wcd939x->status_mask)) {
  4343. ret = msm_cdc_disable_ondemand_supply(wcd939x->dev,
  4344. wcd939x->supplies,
  4345. pdata->regulator,
  4346. pdata->num_supplies,
  4347. "cdc-vdd-buck");
  4348. if (ret == -EINVAL) {
  4349. dev_err_ratelimited(dev, "%s: vdd buck is not disabled\n",
  4350. __func__);
  4351. return 0;
  4352. }
  4353. clear_bit(ALLOW_BUCK_DISABLE, &wcd939x->status_mask);
  4354. }
  4355. if (wcd939x->dapm_bias_off ||
  4356. (wcd939x->component &&
  4357. (snd_soc_component_get_bias_level(wcd939x->component) ==
  4358. SND_SOC_BIAS_OFF))) {
  4359. msm_cdc_set_supplies_lpm_mode(wcd939x->dev,
  4360. wcd939x->supplies,
  4361. pdata->regulator,
  4362. pdata->num_supplies,
  4363. true);
  4364. set_bit(WCD_SUPPLIES_LPM_MODE, &wcd939x->status_mask);
  4365. }
  4366. return 0;
  4367. }
  4368. static int wcd939x_resume(struct device *dev)
  4369. {
  4370. struct wcd939x_priv *wcd939x = NULL;
  4371. struct wcd939x_pdata *pdata = NULL;
  4372. if (!dev)
  4373. return -ENODEV;
  4374. wcd939x = dev_get_drvdata(dev);
  4375. if (!wcd939x)
  4376. return -EINVAL;
  4377. pdata = dev_get_platdata(wcd939x->dev);
  4378. if (!pdata) {
  4379. dev_err_ratelimited(dev, "%s: pdata is NULL\n", __func__);
  4380. return -EINVAL;
  4381. }
  4382. if (test_bit(WCD_SUPPLIES_LPM_MODE, &wcd939x->status_mask)) {
  4383. msm_cdc_set_supplies_lpm_mode(wcd939x->dev,
  4384. wcd939x->supplies,
  4385. pdata->regulator,
  4386. pdata->num_supplies,
  4387. false);
  4388. clear_bit(WCD_SUPPLIES_LPM_MODE, &wcd939x->status_mask);
  4389. }
  4390. return 0;
  4391. }
  4392. static const struct dev_pm_ops wcd939x_dev_pm_ops = {
  4393. .suspend_late = wcd939x_suspend,
  4394. .resume_early = wcd939x_resume,
  4395. };
  4396. #endif
  4397. static struct platform_driver wcd939x_codec_driver = {
  4398. .probe = wcd939x_probe,
  4399. .remove = wcd939x_remove,
  4400. .driver = {
  4401. .name = "wcd939x_codec",
  4402. .owner = THIS_MODULE,
  4403. .of_match_table = of_match_ptr(wcd939x_dt_match),
  4404. #ifdef CONFIG_PM_SLEEP
  4405. .pm = &wcd939x_dev_pm_ops,
  4406. #endif
  4407. .suppress_bind_attrs = true,
  4408. },
  4409. };
  4410. module_platform_driver(wcd939x_codec_driver);
  4411. MODULE_DESCRIPTION("WCD939X Codec driver");
  4412. MODULE_LICENSE("GPL v2");