wcd9378.c 132 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2018-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022-2024 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 <sound/soc.h>
  13. #include <sound/tlv.h>
  14. #include <soc/soundwire.h>
  15. #include <linux/regmap.h>
  16. #include <sound/soc.h>
  17. #include <sound/soc-dapm.h>
  18. #include <asoc/msm-cdc-pinctrl.h>
  19. #include <asoc/msm-cdc-supply.h>
  20. #include <bindings/audio-codec-port-types.h>
  21. #include <linux/qti-regmap-debugfs.h>
  22. #include "wcd9378-reg-masks.h"
  23. #include "wcd9378.h"
  24. #include "internal.h"
  25. #include "asoc/bolero-slave-internal.h"
  26. #define NUM_SWRS_DT_PARAMS 5
  27. #define WCD9378_MOBILE_MODE 0x01
  28. #define WCD9378_VERSION_1_0 1
  29. #define WCD9378_VERSION_ENTRY_SIZE 32
  30. #define SWR_BASECLK_19P2MHZ (0x01)
  31. #define SWR_BASECLK_24P576MHZ (0x03)
  32. #define SWR_BASECLK_22P5792MHZ (0x04)
  33. #define SWR_CLKSCALE_DIV2 (0x02)
  34. #define ADC_MODE_VAL_HIFI 0x01
  35. #define ADC_MODE_VAL_NORMAL 0x03
  36. #define ADC_MODE_VAL_LP 0x05
  37. #define PWR_LEVEL_LOHIFI_VAL 0x00
  38. #define PWR_LEVEL_LP_VAL 0x01
  39. #define PWR_LEVEL_HIFI_VAL 0x02
  40. #define PWR_LEVEL_ULP_VAL 0x03
  41. #define WCD9378_MBQ_ENABLE_MASK 0x2000
  42. #define MICB_USAGE_VAL_DISABLE 0x00
  43. #define MICB_USAGE_VAL_PULL_DOWN 0x01
  44. #define MICB_USAGE_VAL_1P2V 0x02
  45. #define MICB_USAGE_VAL_1P8VORPULLUP 0x03
  46. #define MICB_USAGE_VAL_2P5V 0x04
  47. #define MICB_USAGE_VAL_2P75V 0x05
  48. #define MICB_USAGE_VAL_2P2V 0xF0
  49. #define MICB_USAGE_VAL_2P7V 0xF1
  50. #define MICB_USAGE_VAL_2P8V 0xF2
  51. #define MICB_USAGE_VAL_MICB1_TABLE_VAL 0xF3
  52. #define MICB_USAGE_VAL_MICB2_TABLE_VAL 0xF4
  53. #define MICB_USAGE_VAL_MICB3_TABLE_VAL 0xF5
  54. #define MICB_NUM_MAX 3
  55. #define NUM_ATTEMPTS 20
  56. #define WCD9378_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
  57. SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
  58. SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000 |\
  59. SNDRV_PCM_RATE_384000)
  60. /* Fractional Rates */
  61. #define WCD9378_FRAC_RATES (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_88200 |\
  62. SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_352800)
  63. #define WCD9378_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
  64. SNDRV_PCM_FMTBIT_S24_LE |\
  65. SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
  66. #define WCD9378_EAR_PA_GAIN_TLV(xname, reg, shift, max, invert, tlv_array) \
  67. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  68. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  69. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  70. .tlv.p = (tlv_array), \
  71. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
  72. .put = wcd9378_ear_pa_put_gain, \
  73. .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert, 0) }
  74. #define WCD9378_AUX_PA_GAIN_TLV(xname, reg, shift, max, invert, tlv_array) \
  75. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  76. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  77. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  78. .tlv.p = (tlv_array), \
  79. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
  80. .put = wcd9378_aux_pa_put_gain, \
  81. .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert, 0) }
  82. enum {
  83. CODEC_TX = 0,
  84. CODEC_RX,
  85. };
  86. enum {
  87. RX2_HP_MODE,
  88. RX2_NORMAL_MODE,
  89. };
  90. enum {
  91. CLASS_AB_EN = 0,
  92. TX1_FOR_JACK,
  93. TX2_AMIC4_EN,
  94. TX2_AMIC1_EN,
  95. TX1_AMIC3_EN,
  96. TX1_AMIC2_EN,
  97. TX0_AMIC2_EN,
  98. TX0_AMIC1_EN,
  99. RX2_EAR_EN,
  100. RX2_AUX_EN,
  101. RX1_AUX_EN,
  102. RX0_EAR_EN,
  103. RX0_RX1_HPH_EN,
  104. };
  105. enum {
  106. WCD_ADC1 = 0,
  107. WCD_ADC2,
  108. WCD_ADC3,
  109. WCD_ADC4,
  110. ALLOW_BUCK_DISABLE,
  111. HPH_COMP_DELAY,
  112. HPH_PA_DELAY,
  113. AMIC2_BCS_ENABLE,
  114. WCD_SUPPLIES_LPM_MODE,
  115. WCD_ADC1_MODE,
  116. WCD_ADC2_MODE,
  117. WCD_ADC3_MODE,
  118. WCD_ADC4_MODE,
  119. WCD_AUX_EN,
  120. WCD_EAR_EN,
  121. };
  122. enum {
  123. SYS_USAGE_0,
  124. SYS_USAGE_1,
  125. SYS_USAGE_2,
  126. SYS_USAGE_3,
  127. SYS_USAGE_4,
  128. SYS_USAGE_5,
  129. SYS_USAGE_6,
  130. SYS_USAGE_7,
  131. SYS_USAGE_8,
  132. SYS_USAGE_9,
  133. SYS_USAGE_10,
  134. SYS_USAGE_11,
  135. SYS_USAGE_12,
  136. SYS_USAGE_NUM,
  137. };
  138. enum {
  139. NO_MICB_USED,
  140. MICB1,
  141. MICB2,
  142. MICB3,
  143. MICB_NUM,
  144. };
  145. enum {
  146. ADC_MODE_INVALID = 0,
  147. ADC_MODE_HIFI,
  148. ADC_MODE_NORMAL,
  149. ADC_MODE_LP,
  150. };
  151. static const SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(analog_gain, 0, 3000);
  152. static int wcd9378_reset(struct device *dev);
  153. static int wcd9378_reset_low(struct device *dev);
  154. static int wcd9378_swr_slave_clk_set(struct device *dev, int bank, int path, bool enable);
  155. static void wcd9378_class_load(struct snd_soc_component *component);
  156. /* sys_usage:
  157. * rx0_rx1_hph_en,
  158. * rx0_ear_en, rx1_aux_en, rx2_aux_en, rx2_ear_en,
  159. * tx0_amic1_en, tx0_amic2_en, tx1_amic2_en, tx1_amic3_en,
  160. * tx2_amic1_en, tx2_amic4_en, tx1_for_jack, class_ab_en;
  161. */
  162. static const int sys_usage[SYS_USAGE_NUM] = {
  163. [SYS_USAGE_0] = 0x0c95, /*0b0 1100 1001 0101*/
  164. [SYS_USAGE_1] = 0x12a7, /*0b1 0010 1010 0111*/
  165. [SYS_USAGE_2] = 0x0c99, /*0b0 1100 1001 1001*/
  166. [SYS_USAGE_3] = 0x1aab, /*0b1 1010 1010 1011*/
  167. [SYS_USAGE_4] = 0x0894, /*0b0 1000 1001 0100*/
  168. [SYS_USAGE_5] = 0x11a6, /*0b1 0001 1010 0110*/
  169. [SYS_USAGE_6] = 0x0898, /*0b0 1000 1001 1000*/
  170. [SYS_USAGE_7] = 0x11ab, /*0b1 0001 1010 1011*/
  171. [SYS_USAGE_8] = 0x126a, /*0b1 0010 0110 1010*/
  172. [SYS_USAGE_9] = 0x116b, /*0b1 0001 0110 1011*/
  173. [SYS_USAGE_10] = 0x1ca7, /*0b1 1100 1010 0111*/
  174. [SYS_USAGE_11] = 0x1195, /*0b1 0001 1001 0101*/
  175. [SYS_USAGE_12] = 0x1296, /*0b1 0010 1001 0101*/
  176. };
  177. static const struct regmap_irq wcd9378_regmap_irqs[WCD9378_NUM_IRQS] = {
  178. REGMAP_IRQ_REG(WCD9378_IRQ_MBHC_BUTTON_PRESS_DET, 0, 0x01),
  179. REGMAP_IRQ_REG(WCD9378_IRQ_MBHC_BUTTON_RELEASE_DET, 0, 0x02),
  180. REGMAP_IRQ_REG(WCD9378_IRQ_MBHC_ELECT_INS_REM_DET, 0, 0x04),
  181. REGMAP_IRQ_REG(WCD9378_IRQ_MBHC_ELECT_INS_REM_LEG_DET, 0, 0x08),
  182. REGMAP_IRQ_REG(WCD9378_IRQ_MBHC_SW_DET, 0, 0x10),
  183. REGMAP_IRQ_REG(WCD9378_IRQ_HPHR_OCP_INT, 0, 0x20),
  184. REGMAP_IRQ_REG(WCD9378_IRQ_HPHR_CNP_INT, 0, 0x40),
  185. REGMAP_IRQ_REG(WCD9378_IRQ_HPHL_OCP_INT, 0, 0x80),
  186. REGMAP_IRQ_REG(WCD9378_IRQ_HPHL_CNP_INT, 1, 0x01),
  187. REGMAP_IRQ_REG(WCD9378_IRQ_EAR_CNP_INT, 1, 0x02),
  188. REGMAP_IRQ_REG(WCD9378_IRQ_EAR_SCD_INT, 1, 0x04),
  189. REGMAP_IRQ_REG(WCD9378_IRQ_AUX_CNP_INT, 1, 0x08),
  190. REGMAP_IRQ_REG(WCD9378_IRQ_AUX_SCD_INT, 1, 0x10),
  191. REGMAP_IRQ_REG(WCD9378_IRQ_HPHL_PDM_WD_INT, 1, 0x20),
  192. REGMAP_IRQ_REG(WCD9378_IRQ_HPHR_PDM_WD_INT, 1, 0x40),
  193. REGMAP_IRQ_REG(WCD9378_IRQ_AUX_PDM_WD_INT, 1, 0x80),
  194. REGMAP_IRQ_REG(WCD9378_IRQ_LDORT_SCD_INT, 2, 0x01),
  195. REGMAP_IRQ_REG(WCD9378_IRQ_MBHC_MOISTURE_INT, 2, 0x02),
  196. REGMAP_IRQ_REG(WCD9378_IRQ_HPHL_SURGE_DET_INT, 2, 0x04),
  197. REGMAP_IRQ_REG(WCD9378_IRQ_HPHR_SURGE_DET_INT, 2, 0x08),
  198. REGMAP_IRQ_REG(WCD9378_IRQ_SAPU_PROT_MODE_CHG, 2, 0x40),
  199. };
  200. static int wcd9378_handle_post_irq(void *data)
  201. {
  202. struct wcd9378_priv *wcd9378 = data;
  203. u32 sts1 = 0, sts2 = 0, sts3 = 0;
  204. regmap_read(wcd9378->regmap, SWRS_SCP_SDCA_INTSTAT_1, &sts1);
  205. regmap_read(wcd9378->regmap, SWRS_SCP_SDCA_INTSTAT_2, &sts2);
  206. regmap_read(wcd9378->regmap, SWRS_SCP_SDCA_INTSTAT_3, &sts3);
  207. wcd9378->tx_swr_dev->slave_irq_pending =
  208. ((sts1 || sts2 || !sts3) ? true : false);
  209. return IRQ_HANDLED;
  210. }
  211. static struct regmap_irq_chip wcd9378_regmap_irq_chip = {
  212. .name = "wcd9378",
  213. .irqs = wcd9378_regmap_irqs,
  214. .num_irqs = ARRAY_SIZE(wcd9378_regmap_irqs),
  215. .num_regs = 3,
  216. .status_base = SWRS_SCP_SDCA_INTSTAT_1,
  217. .unmask_base = SWRS_SCP_SDCA_INTMASK_1,
  218. .type_base = SWRS_SCP_SDCA_INTRTYPE_1,
  219. .ack_base = SWRS_SCP_SDCA_INTSTAT_1,
  220. .use_ack = 1,
  221. .runtime_pm = false,
  222. .handle_post_irq = wcd9378_handle_post_irq,
  223. .irq_drv_data = NULL,
  224. };
  225. static int wcd9378_swr_slv_get_current_bank(struct swr_device *dev, u8 devnum)
  226. {
  227. int ret = 0;
  228. int bank = 0;
  229. ret = swr_read(dev, devnum, SWR_SCP_CONTROL, &bank, 1);
  230. if (ret)
  231. return -EINVAL;
  232. return ((bank & 0x40) ? 1 : 0);
  233. }
  234. static int wcd9378_init_reg(struct snd_soc_component *component)
  235. {
  236. struct wcd9378_priv *wcd9378 =
  237. snd_soc_component_get_drvdata(component);
  238. u32 val = 0;
  239. val = snd_soc_component_read(component, WCD9378_EFUSE_REG_16);
  240. if (!val)
  241. snd_soc_component_update_bits(component, WCD9378_MBHC_CTL_SPARE_1,
  242. WCD9378_MBHC_CTL_SPARE_1_BIASGEN_RES_CTRL_MASK,
  243. 0x03);
  244. else
  245. snd_soc_component_update_bits(component, WCD9378_MBHC_CTL_SPARE_1,
  246. WCD9378_MBHC_CTL_SPARE_1_BIASGEN_RES_CTRL_MASK,
  247. 0x01);
  248. /*0.9 Volts*/
  249. snd_soc_component_update_bits(component, WCD9378_SLEEP_CTL,
  250. WCD9378_SLEEP_CTL_BG_CTL_MASK, 0x0E);
  251. /*BG_EN ENABLE*/
  252. snd_soc_component_update_bits(component, WCD9378_SLEEP_CTL,
  253. WCD9378_SLEEP_CTL_BG_EN_MASK, 0x80);
  254. usleep_range(1000, 1010);
  255. /*LDOL_BG_SEL SLEEP_BG*/
  256. snd_soc_component_update_bits(component, WCD9378_SLEEP_CTL,
  257. WCD9378_SLEEP_CTL_LDOL_BG_SEL_MASK, 0x40);
  258. usleep_range(1000, 1010);
  259. /*Start up analog master bias. Sequence cannot change*/
  260. /*VBG_FINE_ADJ 0.005 Volts*/
  261. snd_soc_component_update_bits(component, WCD9378_BIAS_VBG_FINE_ADJ,
  262. WCD9378_BIAS_VBG_FINE_ADJ_VBG_FINE_ADJ_MASK, 0xB0);
  263. /*ANALOG_BIAS_EN ENABLE*/
  264. snd_soc_component_update_bits(component, WCD9378_ANA_BIAS,
  265. WCD9378_ANA_BIAS_ANALOG_BIAS_EN_MASK, 0x80);
  266. /*PRECHRG_EN ENABLE*/
  267. snd_soc_component_update_bits(component, WCD9378_ANA_BIAS,
  268. WCD9378_ANA_BIAS_PRECHRG_EN_MASK, 0x40);
  269. usleep_range(10000, 10010);
  270. /*PRECHRG_EN DISABLE*/
  271. snd_soc_component_update_bits(component, WCD9378_ANA_BIAS,
  272. WCD9378_ANA_BIAS_PRECHRG_EN_MASK, 0x00);
  273. /*End Analog Master Bias enable*/
  274. /*SEQ_BYPASS ENABLE*/
  275. snd_soc_component_update_bits(component, WCD9378_TX_COM_TXFE_DIV_CTL,
  276. WCD9378_TX_COM_TXFE_DIV_CTL_SEQ_BYPASS_MASK, 0x80);
  277. /*TIME_OUT_SEL_PCM 160_CYCLES*/
  278. snd_soc_component_update_bits(component, WCD9378_PDM_WD_CTL0,
  279. WCD9378_PDM_WD_CTL0_TIME_OUT_SEL_PCM_MASK, 0x10);
  280. /*TIME_OUT_SEL_PCM 160_CYCLES*/
  281. snd_soc_component_update_bits(component, WCD9378_PDM_WD_CTL1,
  282. WCD9378_PDM_WD_CTL1_TIME_OUT_SEL_PCM_MASK, 0x10);
  283. /*IBIAS_LDO_DRIVER 5e-06*/
  284. snd_soc_component_update_bits(component, WCD9378_MICB1_TEST_CTL_2,
  285. WCD9378_MICB1_TEST_CTL_2_IBIAS_LDO_DRIVER_MASK, 0x01);
  286. /*IBIAS_LDO_DRIVER 5e-06*/
  287. snd_soc_component_update_bits(component, WCD9378_MICB3_TEST_CTL_2,
  288. WCD9378_MICB3_TEST_CTL_2_IBIAS_LDO_DRIVER_MASK, 0x01);
  289. /*HD2_RES_DIV_CTL_L 82.77*/
  290. snd_soc_component_update_bits(component, WCD9378_HPH_NEW_INT_RDAC_HD2_CTL_L,
  291. WCD9378_HPH_NEW_INT_RDAC_HD2_CTL_L_HD2_RES_DIV_CTL_L_MASK, 0x04);
  292. /*HD2_RES_DIV_CTL_R 82.77*/
  293. snd_soc_component_update_bits(component, WCD9378_HPH_NEW_INT_RDAC_HD2_CTL_R,
  294. WCD9378_HPH_NEW_INT_RDAC_HD2_CTL_R_HD2_RES_DIV_CTL_R_MASK, 0x04);
  295. /*RDAC_GAINCTL 0.55*/
  296. snd_soc_component_update_bits(component, WCD9378_HPH_NEW_INT_RDAC_GAIN_CTL,
  297. WCD9378_HPH_NEW_INT_RDAC_GAIN_CTL_RDAC_GAINCTL_MASK, 0x50);
  298. /*HPH_UP_T0: 0.002*/
  299. snd_soc_component_update_bits(component, WCD9378_HPH_UP_T0,
  300. WCD9378_HPH_UP_T0_HPH_UP_T0_MASK, 0x05);
  301. /*HPH_UP_T9: 0.002*/
  302. snd_soc_component_update_bits(component, WCD9378_HPH_UP_T9,
  303. WCD9378_HPH_UP_T9_HPH_UP_T9_MASK, 0x05);
  304. /*HPH_DN_T0: 0.007*/
  305. snd_soc_component_update_bits(component, WCD9378_HPH_DN_T0,
  306. WCD9378_HPH_DN_T0_HPH_DN_T0_MASK, 0x06);
  307. /*SM0 MB SEL:MB1*/
  308. snd_soc_component_update_bits(component, WCD9378_SM0_MB_SEL,
  309. WCD9378_SM0_MB_SEL_SM0_MB_SEL_MASK, 0x01);
  310. /*SM1 MB SEL:MB2*/
  311. snd_soc_component_update_bits(component, WCD9378_SM1_MB_SEL,
  312. WCD9378_SM1_MB_SEL_SM1_MB_SEL_MASK, 0x02);
  313. /*SM2 MB SEL:MB3*/
  314. snd_soc_component_update_bits(component, WCD9378_SM2_MB_SEL,
  315. WCD9378_SM2_MB_SEL_SM2_MB_SEL_MASK, 0x03);
  316. /*INIT SYS_USAGE*/
  317. snd_soc_component_update_bits(component,
  318. WCD9378_SYS_USAGE_CTRL,
  319. WCD9378_SYS_USAGE_CTRL_SYS_USAGE_CTRL_MASK,
  320. 0);
  321. wcd9378->sys_usage = 0;
  322. wcd9378_class_load(component);
  323. return 0;
  324. }
  325. static int wcd9378_set_port_params(struct snd_soc_component *component,
  326. u8 slv_prt_type, u8 *port_id, u8 *num_ch,
  327. u8 *ch_mask, u32 *ch_rate,
  328. u8 *port_type, u8 path)
  329. {
  330. int i, j;
  331. u8 num_ports = 0;
  332. struct codec_port_info (*map)[MAX_PORT][MAX_CH_PER_PORT];
  333. struct wcd9378_priv *wcd9378 = snd_soc_component_get_drvdata(component);
  334. switch (path) {
  335. case CODEC_RX:
  336. map = &wcd9378->rx_port_mapping;
  337. num_ports = wcd9378->num_rx_ports;
  338. break;
  339. case CODEC_TX:
  340. map = &wcd9378->tx_port_mapping;
  341. num_ports = wcd9378->num_tx_ports;
  342. break;
  343. default:
  344. dev_err(component->dev, "%s Invalid path selected %u\n",
  345. __func__, path);
  346. return -EINVAL;
  347. }
  348. for (i = 0; i <= num_ports; i++) {
  349. for (j = 0; j < MAX_CH_PER_PORT; j++) {
  350. if ((*map)[i][j].slave_port_type == slv_prt_type)
  351. goto found;
  352. }
  353. }
  354. found:
  355. if (i > num_ports || j == MAX_CH_PER_PORT) {
  356. dev_err(component->dev, "%s Failed to find slave port for type %u\n",
  357. __func__, slv_prt_type);
  358. return -EINVAL;
  359. }
  360. *port_id = i;
  361. *num_ch = (*map)[i][j].num_ch;
  362. *ch_mask = (*map)[i][j].ch_mask;
  363. *ch_rate = (*map)[i][j].ch_rate;
  364. *port_type = (*map)[i][j].master_port_type;
  365. return 0;
  366. }
  367. static int wcd9378_parse_port_params(struct device *dev,
  368. char *prop, u8 path)
  369. {
  370. u32 *dt_array, map_size, max_uc;
  371. int ret = 0;
  372. u32 cnt = 0;
  373. u32 i, j;
  374. struct swr_port_params (*map)[SWR_UC_MAX][SWR_NUM_PORTS];
  375. struct swr_dev_frame_config (*map_uc)[SWR_UC_MAX];
  376. struct wcd9378_priv *wcd9378 = dev_get_drvdata(dev);
  377. switch (path) {
  378. case CODEC_TX:
  379. map = &wcd9378->tx_port_params;
  380. map_uc = &wcd9378->swr_tx_port_params;
  381. break;
  382. default:
  383. ret = -EINVAL;
  384. goto err_port_map;
  385. }
  386. if (!of_find_property(dev->of_node, prop,
  387. &map_size)) {
  388. dev_err(dev, "missing port mapping prop %s\n", prop);
  389. ret = -EINVAL;
  390. goto err_port_map;
  391. }
  392. max_uc = map_size / (SWR_NUM_PORTS * SWR_PORT_PARAMS * sizeof(u32));
  393. if (max_uc != SWR_UC_MAX) {
  394. dev_err(dev, "%s: port params not provided for all usecases\n",
  395. __func__);
  396. ret = -EINVAL;
  397. goto err_port_map;
  398. }
  399. dt_array = kzalloc(map_size, GFP_KERNEL);
  400. if (!dt_array) {
  401. ret = -ENOMEM;
  402. goto err_alloc;
  403. }
  404. ret = of_property_read_u32_array(dev->of_node, prop, dt_array,
  405. SWR_NUM_PORTS * SWR_PORT_PARAMS * max_uc);
  406. if (ret) {
  407. dev_err(dev, "%s: Failed to read port mapping from prop %s\n",
  408. __func__, prop);
  409. goto err_pdata_fail;
  410. }
  411. for (i = 0; i < max_uc; i++) {
  412. for (j = 0; j < SWR_NUM_PORTS; j++) {
  413. cnt = (i * SWR_NUM_PORTS + j) * SWR_PORT_PARAMS;
  414. (*map)[i][j].offset1 = dt_array[cnt];
  415. (*map)[i][j].lane_ctrl = dt_array[cnt + 1];
  416. }
  417. (*map_uc)[i].pp = &(*map)[i][0];
  418. }
  419. kfree(dt_array);
  420. return 0;
  421. err_pdata_fail:
  422. kfree(dt_array);
  423. err_alloc:
  424. err_port_map:
  425. return ret;
  426. }
  427. static int wcd9378_parse_port_mapping(struct device *dev,
  428. char *prop, u8 path)
  429. {
  430. u32 *dt_array, map_size, map_length;
  431. u32 port_num = 0, ch_mask, ch_rate, old_port_num = 0;
  432. u32 slave_port_type, master_port_type;
  433. u32 i, ch_iter = 0;
  434. int ret = 0;
  435. u8 *num_ports = NULL;
  436. struct codec_port_info (*map)[MAX_PORT][MAX_CH_PER_PORT];
  437. struct wcd9378_priv *wcd9378 = dev_get_drvdata(dev);
  438. switch (path) {
  439. case CODEC_RX:
  440. map = &wcd9378->rx_port_mapping;
  441. num_ports = &wcd9378->num_rx_ports;
  442. break;
  443. case CODEC_TX:
  444. map = &wcd9378->tx_port_mapping;
  445. num_ports = &wcd9378->num_tx_ports;
  446. break;
  447. default:
  448. dev_err(dev, "%s Invalid path selected %u\n",
  449. __func__, path);
  450. return -EINVAL;
  451. }
  452. if (!of_find_property(dev->of_node, prop,
  453. &map_size)) {
  454. dev_err(dev, "missing port mapping prop %s\n", prop);
  455. ret = -EINVAL;
  456. goto err_port_map;
  457. }
  458. map_length = map_size / (NUM_SWRS_DT_PARAMS * sizeof(u32));
  459. dt_array = kzalloc(map_size, GFP_KERNEL);
  460. if (!dt_array) {
  461. ret = -ENOMEM;
  462. goto err_alloc;
  463. }
  464. ret = of_property_read_u32_array(dev->of_node, prop, dt_array,
  465. NUM_SWRS_DT_PARAMS * map_length);
  466. if (ret) {
  467. dev_err(dev, "%s: Failed to read port mapping from prop %s\n",
  468. __func__, prop);
  469. goto err_pdata_fail;
  470. }
  471. for (i = 0; i < map_length; i++) {
  472. port_num = dt_array[NUM_SWRS_DT_PARAMS * i];
  473. slave_port_type = dt_array[NUM_SWRS_DT_PARAMS * i + 1];
  474. ch_mask = dt_array[NUM_SWRS_DT_PARAMS * i + 2];
  475. ch_rate = dt_array[NUM_SWRS_DT_PARAMS * i + 3];
  476. master_port_type = dt_array[NUM_SWRS_DT_PARAMS * i + 4];
  477. if (port_num != old_port_num)
  478. ch_iter = 0;
  479. (*map)[port_num][ch_iter].slave_port_type = slave_port_type;
  480. (*map)[port_num][ch_iter].ch_mask = ch_mask;
  481. (*map)[port_num][ch_iter].master_port_type = master_port_type;
  482. (*map)[port_num][ch_iter].num_ch = __sw_hweight8(ch_mask);
  483. (*map)[port_num][ch_iter++].ch_rate = ch_rate;
  484. old_port_num = port_num;
  485. }
  486. *num_ports = port_num;
  487. kfree(dt_array);
  488. return 0;
  489. err_pdata_fail:
  490. kfree(dt_array);
  491. err_alloc:
  492. err_port_map:
  493. return ret;
  494. }
  495. static int wcd9378_tx_connect_port(struct snd_soc_component *component,
  496. u8 slv_port_type, int clk_rate,
  497. u8 enable)
  498. {
  499. struct wcd9378_priv *wcd9378 = snd_soc_component_get_drvdata(component);
  500. u8 port_id, num_ch, ch_mask;
  501. u8 ch_type = 0;
  502. u32 ch_rate;
  503. int slave_ch_idx;
  504. u8 num_port = 1;
  505. int ret = 0;
  506. ret = wcd9378_set_port_params(component, slv_port_type, &port_id,
  507. &num_ch, &ch_mask, &ch_rate,
  508. &ch_type, CODEC_TX);
  509. if (ret)
  510. return ret;
  511. if (clk_rate)
  512. ch_rate = clk_rate;
  513. slave_ch_idx = wcd9378_slave_get_slave_ch_val(slv_port_type);
  514. if (slave_ch_idx != -EINVAL)
  515. ch_type = wcd9378->tx_master_ch_map[slave_ch_idx];
  516. dev_dbg(component->dev, "%s slv_ch_idx: %d, mstr_ch_type: %d\n",
  517. __func__, slave_ch_idx, ch_type);
  518. if (enable)
  519. ret = swr_connect_port(wcd9378->tx_swr_dev, &port_id,
  520. num_port, &ch_mask, &ch_rate,
  521. &num_ch, &ch_type);
  522. else
  523. ret = swr_disconnect_port(wcd9378->tx_swr_dev, &port_id,
  524. num_port, &ch_mask, &ch_type);
  525. return ret;
  526. }
  527. static int wcd9378_rx_connect_port(struct snd_soc_component *component,
  528. u8 slv_port_type, u8 enable)
  529. {
  530. struct wcd9378_priv *wcd9378 = snd_soc_component_get_drvdata(component);
  531. u8 port_id, num_ch, ch_mask, port_type;
  532. u32 ch_rate;
  533. u8 num_port = 1;
  534. int ret = 0;
  535. ret = wcd9378_set_port_params(component, slv_port_type, &port_id,
  536. &num_ch, &ch_mask, &ch_rate,
  537. &port_type, CODEC_RX);
  538. if (ret)
  539. return ret;
  540. if (enable)
  541. ret = swr_connect_port(wcd9378->rx_swr_dev, &port_id,
  542. num_port, &ch_mask, &ch_rate,
  543. &num_ch, &port_type);
  544. else
  545. ret = swr_disconnect_port(wcd9378->rx_swr_dev, &port_id,
  546. num_port, &ch_mask, &port_type);
  547. return ret;
  548. }
  549. static int wcd9378_enable_clsh(struct snd_soc_dapm_widget *w,
  550. struct snd_kcontrol *kcontrol,
  551. int event)
  552. {
  553. struct snd_soc_component *component =
  554. snd_soc_dapm_to_component(w->dapm);
  555. struct wcd9378_priv *wcd9378 = snd_soc_component_get_drvdata(component);
  556. int mode = wcd9378->hph_mode;
  557. int ret = 0;
  558. int bank = 0;
  559. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  560. w->name, event);
  561. if (mode == CLS_H_LOHIFI || mode == CLS_H_ULP ||
  562. mode == CLS_H_HIFI || mode == CLS_H_LP) {
  563. wcd9378_rx_connect_port(component, CLSH,
  564. SND_SOC_DAPM_EVENT_ON(event));
  565. }
  566. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  567. bank = (wcd9378_swr_slv_get_current_bank(wcd9378->rx_swr_dev,
  568. wcd9378->rx_swr_dev->dev_num) ? 0 : 1);
  569. wcd9378_swr_slave_clk_set(wcd9378->dev, bank, RX_PATH, false);
  570. ret = swr_slvdev_datapath_control(
  571. wcd9378->rx_swr_dev,
  572. wcd9378->rx_swr_dev->dev_num,
  573. false);
  574. wcd9378_swr_slave_clk_set(wcd9378->dev, !bank, RX_PATH, false);
  575. }
  576. return ret;
  577. }
  578. static int wcd9378_codec_enable_dmic(struct snd_soc_dapm_widget *w,
  579. struct snd_kcontrol *kcontrol,
  580. int event)
  581. {
  582. struct snd_soc_component *component =
  583. snd_soc_dapm_to_component(w->dapm);
  584. struct wcd9378_priv *wcd9378 = snd_soc_component_get_drvdata(component);
  585. u32 dmic_clk_reg, dmic_clk_en_reg;
  586. s32 *dmic_clk_cnt;
  587. u8 dmic_ctl_shift = 0;
  588. u8 dmic_clk_shift = 0;
  589. u8 dmic_clk_mask = 0;
  590. u32 dmic2_left_en = 0;
  591. int ret = 0;
  592. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  593. w->name, event);
  594. switch (w->shift) {
  595. case 0:
  596. case 1:
  597. dmic_clk_cnt = &(wcd9378->dmic_0_1_clk_cnt);
  598. dmic_clk_reg = WCD9378_CDC_DMIC_RATE_1_2;
  599. dmic_clk_en_reg = WCD9378_CDC_DMIC1_CTL;
  600. dmic_clk_mask = 0x0F;
  601. dmic_clk_shift = 0x00;
  602. dmic_ctl_shift = 0x00;
  603. break;
  604. case 2:
  605. dmic2_left_en = WCD9378_CDC_DMIC2_CTL;
  606. fallthrough;
  607. case 3:
  608. dmic_clk_cnt = &(wcd9378->dmic_2_3_clk_cnt);
  609. dmic_clk_reg = WCD9378_CDC_DMIC_RATE_1_2;
  610. dmic_clk_en_reg = WCD9378_CDC_DMIC2_CTL;
  611. dmic_clk_mask = 0xF0;
  612. dmic_clk_shift = 0x04;
  613. dmic_ctl_shift = 0x01;
  614. break;
  615. case 4:
  616. case 5:
  617. dmic_clk_cnt = &(wcd9378->dmic_4_5_clk_cnt);
  618. dmic_clk_reg = WCD9378_CDC_DMIC_RATE_3_4;
  619. dmic_clk_en_reg = WCD9378_CDC_DMIC3_CTL;
  620. dmic_clk_mask = 0x0F;
  621. dmic_clk_shift = 0x00;
  622. dmic_ctl_shift = 0x02;
  623. break;
  624. default:
  625. dev_err_ratelimited(component->dev, "%s: Invalid DMIC Selection\n",
  626. __func__);
  627. return -EINVAL;
  628. };
  629. dev_dbg(component->dev, "%s: event %d DMIC%d dmic_clk_cnt %d\n",
  630. __func__, event, (w->shift + 1), *dmic_clk_cnt);
  631. switch (event) {
  632. case SND_SOC_DAPM_PRE_PMU:
  633. snd_soc_component_update_bits(component,
  634. WCD9378_CDC_AMIC_CTL,
  635. (0x01 << dmic_ctl_shift), 0x00);
  636. /* 250us sleep as per HW requirement */
  637. usleep_range(250, 260);
  638. if (dmic2_left_en)
  639. snd_soc_component_update_bits(component,
  640. dmic2_left_en, 0x80, 0x80);
  641. /* Setting DMIC clock rate to 2.4MHz */
  642. snd_soc_component_update_bits(component,
  643. dmic_clk_reg, dmic_clk_mask,
  644. (0x03 << dmic_clk_shift));
  645. snd_soc_component_update_bits(component,
  646. dmic_clk_en_reg, 0x08, 0x08);
  647. /* enable clock scaling */
  648. snd_soc_component_update_bits(component,
  649. WCD9378_CDC_DMIC_CTL, 0x06, 0x06);
  650. ret = swr_slvdev_datapath_control(wcd9378->tx_swr_dev,
  651. wcd9378->tx_swr_dev->dev_num,
  652. true);
  653. break;
  654. case SND_SOC_DAPM_POST_PMD:
  655. wcd9378_tx_connect_port(component, DMIC0 + (w->shift), 0,
  656. false);
  657. snd_soc_component_update_bits(component,
  658. WCD9378_CDC_AMIC_CTL,
  659. (0x01 << dmic_ctl_shift),
  660. (0x01 << dmic_ctl_shift));
  661. if (dmic2_left_en)
  662. snd_soc_component_update_bits(component,
  663. dmic2_left_en, 0x80, 0x00);
  664. snd_soc_component_update_bits(component,
  665. dmic_clk_en_reg, 0x08, 0x00);
  666. break;
  667. };
  668. return ret;
  669. }
  670. /*
  671. * wcd9378_get_micb_vout_ctl_val: converts micbias from volts to register value
  672. * @micb_mv: micbias in mv
  673. *
  674. * return register value converted
  675. */
  676. int wcd9378_get_micb_vout_ctl_val(u32 micb_mv)
  677. {
  678. /* min micbias voltage is 1V and maximum is 2.85V */
  679. if (micb_mv < 1000 || micb_mv > 2850) {
  680. pr_err("%s: unsupported micbias voltage\n", __func__);
  681. return -EINVAL;
  682. }
  683. return (micb_mv - 1000) / 50;
  684. }
  685. EXPORT_SYMBOL_GPL(wcd9378_get_micb_vout_ctl_val);
  686. /*
  687. * wcd9378_mbhc_micb_adjust_voltage: adjust specific micbias voltage
  688. * @component: handle to snd_soc_component *
  689. * @req_volt: micbias voltage to be set
  690. * @micb_num: micbias to be set, e.g. micbias1 or micbias2
  691. *
  692. * return 0 if adjustment is success or error code in case of failure
  693. */
  694. static int wcd9378_micb_table_value_set(struct snd_soc_component *component,
  695. u32 micb_mv, int micb_num)
  696. {
  697. int vcout_ctl;
  698. switch (micb_mv) {
  699. case 2200:
  700. return MICB_USAGE_VAL_2P2V;
  701. case 2700:
  702. return MICB_USAGE_VAL_2P7V;
  703. case 2800:
  704. return MICB_USAGE_VAL_2P8V;
  705. default:
  706. vcout_ctl = wcd9378_get_micb_vout_ctl_val(micb_mv);
  707. if (micb_num == MIC_BIAS_1) {
  708. snd_soc_component_update_bits(component,
  709. WCD9378_MICB_REMAP_TABLE_VAL_3,
  710. WCD9378_MICB_REMAP_TABLE_VAL_3_MICB_REMAP_TABLE_VAL_3_MASK,
  711. vcout_ctl);
  712. return MICB_USAGE_VAL_MICB1_TABLE_VAL;
  713. } else if (micb_num == MIC_BIAS_2) {
  714. snd_soc_component_update_bits(component,
  715. WCD9378_MICB_REMAP_TABLE_VAL_4,
  716. WCD9378_MICB_REMAP_TABLE_VAL_4_MICB_REMAP_TABLE_VAL_4_MASK,
  717. vcout_ctl);
  718. return MICB_USAGE_VAL_MICB2_TABLE_VAL;
  719. } else if (micb_num == MIC_BIAS_3) {
  720. snd_soc_component_update_bits(component,
  721. WCD9378_MICB_REMAP_TABLE_VAL_5,
  722. WCD9378_MICB_REMAP_TABLE_VAL_5_MICB_REMAP_TABLE_VAL_5_MASK,
  723. vcout_ctl);
  724. return MICB_USAGE_VAL_MICB3_TABLE_VAL;
  725. }
  726. }
  727. return 0;
  728. }
  729. static int wcd9378_micb_usage_value_convert(struct snd_soc_component *component,
  730. u32 micb_mv, int micb_num)
  731. {
  732. switch (micb_mv) {
  733. case 0:
  734. return MICB_USAGE_VAL_PULL_DOWN;
  735. case 1200:
  736. return MICB_USAGE_VAL_1P2V;
  737. case 1800:
  738. return MICB_USAGE_VAL_1P8VORPULLUP;
  739. case 2500:
  740. return MICB_USAGE_VAL_2P5V;
  741. case 2750:
  742. return MICB_USAGE_VAL_2P75V;
  743. default:
  744. return wcd9378_micb_table_value_set(component, micb_mv, micb_num);
  745. }
  746. return MICB_USAGE_VAL_DISABLE;
  747. }
  748. int wcd9378_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
  749. int req_volt, int micb_num)
  750. {
  751. struct wcd9378_priv *wcd9378 =
  752. snd_soc_component_get_drvdata(component);
  753. int micb_usage = 0, micb_mask = 0, req_vout_ctl = 0;
  754. if (wcd9378 == NULL) {
  755. dev_err(component->dev,
  756. "%s: wcd9378 private data is NULL\n", __func__);
  757. return -EINVAL;
  758. }
  759. switch (micb_num) {
  760. case MIC_BIAS_1:
  761. micb_usage = WCD9378_IT11_USAGE;
  762. micb_mask = WCD9378_IT11_MICB_IT11_MICB_MASK;
  763. break;
  764. case MIC_BIAS_2:
  765. micb_usage = WCD9378_SMP_MIC_CTRL1_IT11_MICB;
  766. micb_mask = WCD9378_SMP_MIC_CTRL1_IT11_MICB_IT11_MICB_MASK;
  767. break;
  768. case MIC_BIAS_3:
  769. micb_usage = WCD9378_SMP_MIC_CTRL2_IT11_MICB;
  770. micb_mask = WCD9378_SMP_MIC_CTRL2_IT11_MICB_IT11_MICB_MASK;
  771. break;
  772. default:
  773. dev_err(component->dev,
  774. "%s: wcd9378 private data is NULL\n", __func__);
  775. break;
  776. }
  777. mutex_lock(&wcd9378->micb_lock);
  778. req_vout_ctl =
  779. wcd9378_micb_usage_value_convert(component, req_volt, micb_num);
  780. snd_soc_component_update_bits(component,
  781. micb_usage, micb_mask, req_vout_ctl);
  782. if (micb_num == MIC_BIAS_2) {
  783. dev_err(component->dev,
  784. "%s: sj micbias set\n", __func__);
  785. snd_soc_component_update_bits(component,
  786. WCD9378_IT31_MICB,
  787. WCD9378_IT31_MICB_IT31_MICB_MASK,
  788. req_vout_ctl);
  789. wcd9378->curr_micbias2 = req_volt;
  790. }
  791. mutex_unlock(&wcd9378->micb_lock);
  792. return 0;
  793. }
  794. EXPORT_SYMBOL_GPL(wcd9378_mbhc_micb_adjust_voltage);
  795. void wcd9378_disable_bcs_before_slow_insert(struct snd_soc_component *component,
  796. bool bcs_disable)
  797. {
  798. struct wcd9378_priv *wcd9378 = snd_soc_component_get_drvdata(component);
  799. if (wcd9378->update_wcd_event) {
  800. if (bcs_disable)
  801. wcd9378->update_wcd_event(wcd9378->handle,
  802. SLV_BOLERO_EVT_BCS_CLK_OFF, 0);
  803. else
  804. wcd9378->update_wcd_event(wcd9378->handle,
  805. SLV_BOLERO_EVT_BCS_CLK_OFF, 1);
  806. }
  807. }
  808. static int wcd9378_get_clk_rate(int mode)
  809. {
  810. int rate;
  811. switch (mode) {
  812. case ADC_MODE_LP:
  813. rate = SWR_CLK_RATE_4P8MHZ;
  814. break;
  815. case ADC_MODE_INVALID:
  816. case ADC_MODE_NORMAL:
  817. case ADC_MODE_HIFI:
  818. default:
  819. rate = SWR_CLK_RATE_9P6MHZ;
  820. break;
  821. }
  822. pr_debug("%s: mode: %d, rate: %d\n", __func__, mode, rate);
  823. return rate;
  824. }
  825. static int wcd9378_get_adc_mode_val(int mode)
  826. {
  827. int ret = 0;
  828. switch (mode) {
  829. case ADC_MODE_INVALID:
  830. case ADC_MODE_NORMAL:
  831. ret = ADC_MODE_VAL_NORMAL;
  832. break;
  833. case ADC_MODE_HIFI:
  834. ret = ADC_MODE_VAL_HIFI;
  835. break;
  836. case ADC_MODE_LP:
  837. ret = ADC_MODE_VAL_LP;
  838. break;
  839. default:
  840. ret = -EINVAL;
  841. pr_err("%s: invalid ADC mode value %d\n", __func__, mode);
  842. break;
  843. }
  844. return ret;
  845. }
  846. static int wcd9378_sys_usage_auto_udpate(struct snd_soc_component *component,
  847. int sys_usage_bit, bool set_enable)
  848. {
  849. struct wcd9378_priv *wcd9378 =
  850. snd_soc_component_get_drvdata(component);
  851. int i = 0;
  852. dev_dbg(component->dev,
  853. "%s: enter, current sys_usage: %d, sys_usage_status: 0x%x, sys_usage_bit: %d, set_enable: %d\n",
  854. __func__, wcd9378->sys_usage,
  855. wcd9378->sys_usage_status,
  856. sys_usage_bit, set_enable);
  857. mutex_lock(&wcd9378->sys_usage_lock);
  858. if (set_enable) {
  859. set_bit(sys_usage_bit, &wcd9378->sys_usage_status);
  860. if ((sys_usage[wcd9378->sys_usage] &
  861. wcd9378->sys_usage_status) == wcd9378->sys_usage_status)
  862. goto exit;
  863. for (i = 0; i < SYS_USAGE_NUM; i++) {
  864. if ((sys_usage[i] & wcd9378->sys_usage_status)
  865. == wcd9378->sys_usage_status) {
  866. snd_soc_component_update_bits(component,
  867. WCD9378_SYS_USAGE_CTRL,
  868. WCD9378_SYS_USAGE_CTRL_SYS_USAGE_CTRL_MASK,
  869. i);
  870. wcd9378->sys_usage = i;
  871. dev_dbg(component->dev, "%s: update sys_usage: %d\n",
  872. __func__, wcd9378->sys_usage);
  873. goto exit;
  874. }
  875. }
  876. dev_dbg(component->dev, "%s: cannot find sys_usage\n",
  877. __func__);
  878. } else {
  879. clear_bit(sys_usage_bit, &wcd9378->sys_usage_status);
  880. }
  881. exit:
  882. mutex_unlock(&wcd9378->sys_usage_lock);
  883. return 0;
  884. }
  885. static int wcd9378_sys_usage_bit_get(
  886. struct snd_soc_component *component, u32 w_shift,
  887. int *sys_usage_bit, int event)
  888. {
  889. struct wcd9378_priv *wcd9378 =
  890. snd_soc_component_get_drvdata(component);
  891. dev_dbg(component->dev, "%s: wshift: %d event: %d\n", __func__,
  892. w_shift, event);
  893. switch (event) {
  894. case SND_SOC_DAPM_PRE_PMU:
  895. switch (w_shift) {
  896. case ADC1:
  897. if ((snd_soc_component_read(component,
  898. WCD9378_TX_NEW_TX_CH12_MUX) &
  899. WCD9378_TX_NEW_TX_CH12_MUX_CH1_SEL_MASK) == 0x01) {
  900. *sys_usage_bit = TX0_AMIC1_EN;
  901. } else if ((snd_soc_component_read(component,
  902. WCD9378_TX_NEW_TX_CH12_MUX) &
  903. WCD9378_TX_NEW_TX_CH12_MUX_CH1_SEL_MASK) == 0x02) {
  904. *sys_usage_bit = TX0_AMIC2_EN;
  905. } else {
  906. dev_err(component->dev, "%s: unsupport usecase, pls check\n",
  907. __func__);
  908. return -EINVAL;
  909. }
  910. break;
  911. case ADC2:
  912. if ((snd_soc_component_read(component,
  913. WCD9378_TX_NEW_TX_CH12_MUX) &
  914. WCD9378_TX_NEW_TX_CH12_MUX_CH2_SEL_MASK) == 0x10) {
  915. *sys_usage_bit = TX1_AMIC2_EN;
  916. } else if ((snd_soc_component_read(component,
  917. WCD9378_TX_NEW_TX_CH12_MUX) &
  918. WCD9378_TX_NEW_TX_CH12_MUX_CH2_SEL_MASK) == 0x18) {
  919. *sys_usage_bit = TX1_AMIC3_EN;
  920. } else {
  921. dev_err(component->dev, "%s: unsupport usecase, pls check\n",
  922. __func__);
  923. return -EINVAL;
  924. }
  925. break;
  926. case ADC3:
  927. if ((snd_soc_component_read(component,
  928. WCD9378_TX_NEW_TX_CH34_MUX) &
  929. WCD9378_TX_NEW_TX_CH34_MUX_CH3_SEL_SHIFT) == 0x01) {
  930. *sys_usage_bit = TX2_AMIC1_EN;
  931. } else if ((snd_soc_component_read(component,
  932. WCD9378_TX_NEW_TX_CH34_MUX) &
  933. WCD9378_TX_NEW_TX_CH34_MUX_CH3_SEL_SHIFT) == 0x03) {
  934. *sys_usage_bit = TX2_AMIC4_EN;
  935. } else {
  936. dev_err(component->dev, "%s: unsupport usecase, pls check\n",
  937. __func__);
  938. return -EINVAL;
  939. }
  940. break;
  941. default:
  942. break;
  943. }
  944. break;
  945. case SND_SOC_DAPM_POST_PMD:
  946. switch (w_shift) {
  947. case ADC1:
  948. if (test_bit(TX0_AMIC1_EN, &wcd9378->sys_usage_status))
  949. *sys_usage_bit = TX0_AMIC1_EN;
  950. if (test_bit(TX0_AMIC2_EN, &wcd9378->sys_usage_status))
  951. *sys_usage_bit = TX0_AMIC2_EN;
  952. break;
  953. case ADC2:
  954. if (test_bit(TX1_AMIC2_EN, &wcd9378->sys_usage_status))
  955. *sys_usage_bit = TX1_AMIC2_EN;
  956. if (test_bit(TX1_AMIC3_EN, &wcd9378->sys_usage_status))
  957. *sys_usage_bit = TX1_AMIC3_EN;
  958. break;
  959. case ADC3:
  960. if (test_bit(TX2_AMIC1_EN, &wcd9378->sys_usage_status))
  961. *sys_usage_bit = TX2_AMIC1_EN;
  962. if (test_bit(TX2_AMIC4_EN, &wcd9378->sys_usage_status))
  963. *sys_usage_bit = TX2_AMIC4_EN;
  964. break;
  965. default:
  966. break;
  967. }
  968. break;
  969. default:
  970. break;
  971. }
  972. dev_dbg(component->dev, "%s: done, event: %d, sys_usage_bit: %d\n",
  973. __func__, event, *sys_usage_bit);
  974. return 0;
  975. }
  976. static int wcd9378_tx_sequencer_enable(struct snd_soc_dapm_widget *w,
  977. struct snd_kcontrol *kcontrol, int event)
  978. {
  979. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  980. struct wcd9378_priv *wcd9378 =
  981. snd_soc_component_get_drvdata(component);
  982. int mode_val = 0, bank = 0, ret = 0, rate = 0;
  983. int act_ps = 0, sys_usage_bit = 0;
  984. bank = (wcd9378_swr_slv_get_current_bank(wcd9378->tx_swr_dev,
  985. wcd9378->tx_swr_dev->dev_num) ? 0 : 1);
  986. dev_dbg(component->dev, "%s wname: %s wshift: %d event: %d\n", __func__,
  987. w->name, w->shift, event);
  988. ret = wcd9378_sys_usage_bit_get(component, w->shift, &sys_usage_bit, event);
  989. if (ret < 0)
  990. return ret;
  991. switch (event) {
  992. case SND_SOC_DAPM_PRE_PMU:
  993. /*Update sys_usage*/
  994. wcd9378_sys_usage_auto_udpate(component, sys_usage_bit, true);
  995. mode_val = wcd9378_get_adc_mode_val(wcd9378->tx_mode[w->shift - ADC1]);
  996. if (mode_val < 0) {
  997. dev_dbg(component->dev,
  998. "%s: invalid mode, setting to normal mode\n",
  999. __func__);
  1000. mode_val = ADC_MODE_VAL_NORMAL;
  1001. }
  1002. rate = wcd9378_get_clk_rate(wcd9378->tx_mode[w->shift - ADC1]);
  1003. if (w->shift == ADC2 && !((snd_soc_component_read(component,
  1004. WCD9378_TX_NEW_TX_CH12_MUX) &
  1005. WCD9378_TX_NEW_TX_CH12_MUX_CH2_SEL_MASK) == 0x10)) {
  1006. if (!wcd9378->bcs_dis) {
  1007. wcd9378_tx_connect_port(component, MBHC,
  1008. SWR_CLK_RATE_4P8MHZ, true);
  1009. set_bit(AMIC2_BCS_ENABLE, &wcd9378->status_mask);
  1010. }
  1011. }
  1012. set_bit(w->shift - ADC1, &wcd9378->status_mask);
  1013. wcd9378_tx_connect_port(component, w->shift, rate,
  1014. true);
  1015. switch (w->shift) {
  1016. case ADC1:
  1017. /*SMP MIC0 IT11 USAGE SET*/
  1018. snd_soc_component_update_bits(component, WCD9378_IT11_USAGE,
  1019. WCD9378_IT11_USAGE_IT11_USAGE_MASK, mode_val);
  1020. /*Hold TXFE in Initialization During Startup*/
  1021. snd_soc_component_update_bits(component, WCD9378_ANA_TX_CH2,
  1022. WCD9378_ANA_TX_CH2_HPF1_INIT_MASK, 0x40);
  1023. /*Power up TX0 sequencer*/
  1024. snd_soc_component_update_bits(component, WCD9378_PDE11_REQ_PS,
  1025. WCD9378_PDE11_REQ_PS_PDE11_REQ_PS_MASK, 0x00);
  1026. break;
  1027. case ADC2:
  1028. /*Check if amic2 is connected to ADC2 MUX*/
  1029. if ((snd_soc_component_read(component,
  1030. WCD9378_TX_NEW_TX_CH12_MUX) &
  1031. WCD9378_TX_NEW_TX_CH12_MUX_CH2_SEL_MASK) == 0x10) {
  1032. /*SMP JACK IT31 USAGE SET*/
  1033. snd_soc_component_update_bits(component,
  1034. WCD9378_IT31_USAGE,
  1035. WCD9378_IT31_USAGE_IT31_USAGE_MASK, mode_val);
  1036. /*Power up TX1 sequencer*/
  1037. snd_soc_component_update_bits(component,
  1038. WCD9378_PDE34_REQ_PS,
  1039. WCD9378_PDE34_REQ_PS_PDE34_REQ_PS_MASK, 0x00);
  1040. } else {
  1041. snd_soc_component_update_bits(component,
  1042. WCD9378_SMP_MIC_CTRL1_IT11_USAGE,
  1043. WCD9378_SMP_MIC_CTRL1_IT11_USAGE_IT11_USAGE_MASK,
  1044. mode_val);
  1045. /*Hold TXFE in Initialization During Startup*/
  1046. snd_soc_component_update_bits(component, WCD9378_ANA_TX_CH2,
  1047. WCD9378_ANA_TX_CH2_HPF2_INIT_MASK, 0x20);
  1048. /*Power up TX1 sequencer*/
  1049. snd_soc_component_update_bits(component,
  1050. WCD9378_SMP_MIC_CTRL1_PDE11_REQ_PS,
  1051. WCD9378_SMP_MIC_CTRL1_PDE11_REQ_PS_PDE11_REQ_PS_MASK,
  1052. 0x00);
  1053. }
  1054. break;
  1055. case ADC3:
  1056. /*SMP MIC2 IT11 USAGE SET*/
  1057. snd_soc_component_update_bits(component,
  1058. WCD9378_SMP_MIC_CTRL2_IT11_USAGE,
  1059. WCD9378_SMP_MIC_CTRL2_IT11_USAGE_IT11_USAGE_MASK,
  1060. mode_val);
  1061. /*Hold TXFE in Initialization During Startup*/
  1062. snd_soc_component_update_bits(component, WCD9378_ANA_TX_CH3_HPF,
  1063. WCD9378_ANA_TX_CH3_HPF_HPF3_INIT_MASK, 0x40);
  1064. /*Power up TX2 sequencer*/
  1065. snd_soc_component_update_bits(component, WCD9378_SMP_MIC_CTRL2_PDE11_REQ_PS,
  1066. WCD9378_SMP_MIC_CTRL2_PDE11_REQ_PS_PDE11_REQ_PS_MASK, 0x00);
  1067. break;
  1068. default:
  1069. break;
  1070. }
  1071. /*default delay 800us*/
  1072. usleep_range(800, 810);
  1073. wcd9378_swr_slave_clk_set(wcd9378->dev, bank, TX_PATH, true);
  1074. ret = swr_slvdev_datapath_control(wcd9378->tx_swr_dev,
  1075. wcd9378->tx_swr_dev->dev_num,
  1076. true);
  1077. wcd9378_swr_slave_clk_set(wcd9378->dev, !bank, TX_PATH, true);
  1078. switch (w->shift) {
  1079. case ADC1:
  1080. snd_soc_component_update_bits(component, WCD9378_ANA_TX_CH2,
  1081. WCD9378_ANA_TX_CH2_HPF1_INIT_MASK, 0x00);
  1082. act_ps = snd_soc_component_read(component, WCD9378_PDE11_ACT_PS);
  1083. if (act_ps)
  1084. dev_dbg(component->dev, "%s: tx0 sequencer didnot power on, act_ps: 0x%0x\n",
  1085. __func__, act_ps);
  1086. else
  1087. dev_dbg(component->dev, "%s: tx0 sequencer power on successful, act_ps: 0x%0x\n",
  1088. __func__, act_ps);
  1089. break;
  1090. case ADC2:
  1091. snd_soc_component_update_bits(component, WCD9378_ANA_TX_CH2,
  1092. WCD9378_ANA_TX_CH2_HPF2_INIT_MASK, 0x00);
  1093. if (test_bit(TX1_AMIC2_EN, &wcd9378->sys_usage_status))
  1094. act_ps = snd_soc_component_read(component,
  1095. WCD9378_PDE34_ACT_PS);
  1096. else
  1097. act_ps = snd_soc_component_read(component,
  1098. WCD9378_SMP_MIC_CTRL1_PDE11_ACT_PS);
  1099. if (act_ps)
  1100. dev_dbg(component->dev, "%s: tx1 sequencer didnot power on, act_ps: 0x%0x\n",
  1101. __func__, act_ps);
  1102. else
  1103. dev_dbg(component->dev, "%s: tx1 sequencer power on successful, act_ps: 0x%0x\n",
  1104. __func__, act_ps);
  1105. break;
  1106. case ADC3:
  1107. snd_soc_component_update_bits(component, WCD9378_ANA_TX_CH3_HPF,
  1108. WCD9378_ANA_TX_CH3_HPF_HPF3_INIT_MASK, 0x00);
  1109. act_ps = snd_soc_component_read(component,
  1110. WCD9378_SMP_MIC_CTRL2_PDE11_ACT_PS);
  1111. if (act_ps)
  1112. dev_dbg(component->dev, "%s: tx2 sequencer didnot power on, act_ps: 0x%0x\n",
  1113. __func__, act_ps);
  1114. else
  1115. dev_dbg(component->dev, "%s: tx2 sequencer power on successful, act_ps: 0x%0x\n",
  1116. __func__, act_ps);
  1117. break;
  1118. };
  1119. break;
  1120. case SND_SOC_DAPM_POST_PMD:
  1121. wcd9378_tx_connect_port(component, w->shift, 0, false);
  1122. if (w->shift == ADC2 &&
  1123. test_bit(AMIC2_BCS_ENABLE, &wcd9378->status_mask)) {
  1124. wcd9378_tx_connect_port(component, MBHC, 0,
  1125. false);
  1126. clear_bit(AMIC2_BCS_ENABLE, &wcd9378->status_mask);
  1127. }
  1128. switch (w->shift) {
  1129. case ADC1:
  1130. /*Normal TXFE Startup*/
  1131. snd_soc_component_update_bits(component, WCD9378_ANA_TX_CH2,
  1132. WCD9378_ANA_TX_CH2_HPF1_INIT_MASK, 0x00);
  1133. /*tear down TX0 sequencer*/
  1134. snd_soc_component_update_bits(component, WCD9378_PDE11_REQ_PS,
  1135. WCD9378_PDE11_REQ_PS_PDE11_REQ_PS_MASK, 0x03);
  1136. break;
  1137. case ADC2:
  1138. if (test_bit(TX1_AMIC2_EN, &wcd9378->sys_usage_status))
  1139. /*tear down TX1 sequencer*/
  1140. snd_soc_component_update_bits(component, WCD9378_PDE34_REQ_PS,
  1141. WCD9378_PDE34_REQ_PS_PDE34_REQ_PS_MASK, 0x03);
  1142. if (test_bit(TX1_AMIC3_EN, &wcd9378->sys_usage_status)) {
  1143. /*Normal TXFE Startup*/
  1144. snd_soc_component_update_bits(component, WCD9378_ANA_TX_CH2,
  1145. WCD9378_ANA_TX_CH2_HPF1_INIT_MASK, 0x00);
  1146. /*tear down TX1 sequencer*/
  1147. snd_soc_component_update_bits(component,
  1148. WCD9378_SMP_MIC_CTRL1_PDE11_REQ_PS,
  1149. WCD9378_SMP_MIC_CTRL1_PDE11_REQ_PS_PDE11_REQ_PS_MASK,
  1150. 0x03);
  1151. }
  1152. break;
  1153. case ADC3:
  1154. /*Normal TXFE Startup*/
  1155. snd_soc_component_update_bits(component, WCD9378_ANA_TX_CH3_HPF,
  1156. WCD9378_ANA_TX_CH3_HPF_HPF3_INIT_MASK, 0x00);
  1157. /*tear down TX2 sequencer*/
  1158. snd_soc_component_update_bits(component, WCD9378_SMP_MIC_CTRL2_PDE11_REQ_PS,
  1159. WCD9378_SMP_MIC_CTRL2_PDE11_REQ_PS_PDE11_REQ_PS_MASK, 0x03);
  1160. break;
  1161. default:
  1162. break;
  1163. }
  1164. /*default delay 800us*/
  1165. usleep_range(800, 810);
  1166. wcd9378_swr_slave_clk_set(wcd9378->dev, !bank, TX_PATH, false);
  1167. ret = swr_slvdev_datapath_control(wcd9378->tx_swr_dev,
  1168. wcd9378->tx_swr_dev->dev_num,
  1169. false);
  1170. wcd9378_swr_slave_clk_set(wcd9378->dev, bank, TX_PATH, false);
  1171. /*Disable sys_usage_status*/
  1172. wcd9378_sys_usage_auto_udpate(component, sys_usage_bit, false);
  1173. break;
  1174. default:
  1175. break;
  1176. }
  1177. return ret;
  1178. }
  1179. static int wcd9378_tx_swr_ctrl(struct snd_soc_dapm_widget *w,
  1180. struct snd_kcontrol *kcontrol,
  1181. int event)
  1182. {
  1183. struct snd_soc_component *component =
  1184. snd_soc_dapm_to_component(w->dapm);
  1185. struct wcd9378_priv *wcd9378 = snd_soc_component_get_drvdata(component);
  1186. int ret = 0;
  1187. switch (event) {
  1188. case SND_SOC_DAPM_PRE_PMU:
  1189. wcd9378_tx_connect_port(component, w->shift,
  1190. SWR_CLK_RATE_2P4MHZ, true);
  1191. break;
  1192. case SND_SOC_DAPM_POST_PMD:
  1193. ret = swr_slvdev_datapath_control(wcd9378->tx_swr_dev,
  1194. wcd9378->tx_swr_dev->dev_num,
  1195. false);
  1196. break;
  1197. };
  1198. return ret;
  1199. }
  1200. static int wcd9378_codec_enable_micbias(struct snd_soc_dapm_widget *w,
  1201. struct snd_kcontrol *kcontrol,
  1202. int event)
  1203. {
  1204. struct snd_soc_component *component =
  1205. snd_soc_dapm_to_component(w->dapm);
  1206. int micb_num = 0;
  1207. dev_dbg(component->dev, "%s: wname: %s, event: %d\n",
  1208. __func__, w->name, event);
  1209. if (strnstr(w->name, "MIC BIAS1", sizeof("MIC BIAS1")))
  1210. micb_num = MIC_BIAS_1;
  1211. else if (strnstr(w->name, "MIC BIAS2", sizeof("MIC BIAS2")))
  1212. micb_num = MIC_BIAS_2;
  1213. else if (strnstr(w->name, "MIC BIAS3", sizeof("MIC BIAS3")))
  1214. micb_num = MIC_BIAS_3;
  1215. else
  1216. return -EINVAL;
  1217. switch (event) {
  1218. case SND_SOC_DAPM_PRE_PMU:
  1219. wcd9378_micbias_control(component, micb_num,
  1220. MICB_ENABLE, true);
  1221. break;
  1222. case SND_SOC_DAPM_POST_PMU:
  1223. usleep_range(1000, 1100);
  1224. break;
  1225. case SND_SOC_DAPM_POST_PMD:
  1226. wcd9378_micbias_control(component, micb_num,
  1227. MICB_DISABLE, true);
  1228. break;
  1229. };
  1230. return 0;
  1231. }
  1232. static int wcd9378_codec_enable_micbias_pullup(struct snd_soc_dapm_widget *w,
  1233. struct snd_kcontrol *kcontrol,
  1234. int event)
  1235. {
  1236. struct snd_soc_component *component =
  1237. snd_soc_dapm_to_component(w->dapm);
  1238. int micb_num = 0;
  1239. dev_dbg(component->dev, "%s: wname: %s, event: %d\n",
  1240. __func__, w->name, event);
  1241. if (strnstr(w->name, "VA MIC BIAS1", sizeof("VA MIC BIAS1")))
  1242. micb_num = MIC_BIAS_1;
  1243. else if (strnstr(w->name, "VA MIC BIAS2", sizeof("VA MIC BIAS2")))
  1244. micb_num = MIC_BIAS_2;
  1245. else if (strnstr(w->name, "VA MIC BIAS3", sizeof("VA MIC BIAS3")))
  1246. micb_num = MIC_BIAS_3;
  1247. else
  1248. return -EINVAL;
  1249. switch (event) {
  1250. case SND_SOC_DAPM_PRE_PMU:
  1251. wcd9378_micbias_control(component, micb_num,
  1252. MICB_PULLUP_ENABLE, true);
  1253. break;
  1254. case SND_SOC_DAPM_POST_PMU:
  1255. usleep_range(1000, 1100);
  1256. break;
  1257. case SND_SOC_DAPM_POST_PMD:
  1258. wcd9378_micbias_control(component, micb_num,
  1259. MICB_PULLUP_DISABLE, true);
  1260. break;
  1261. };
  1262. return 0;
  1263. }
  1264. /*
  1265. * wcd9378_soc_get_mbhc: get wcd9378_mbhc handle of corresponding component
  1266. * @component: handle to snd_soc_component *
  1267. *
  1268. * return wcd9378_mbhc handle or error code in case of failure
  1269. */
  1270. struct wcd9378_mbhc *wcd9378_soc_get_mbhc(struct snd_soc_component *component)
  1271. {
  1272. struct wcd9378_priv *wcd9378;
  1273. if (!component) {
  1274. pr_err_ratelimited("%s: Invalid params, NULL component\n", __func__);
  1275. return NULL;
  1276. }
  1277. wcd9378 = snd_soc_component_get_drvdata(component);
  1278. if (!wcd9378) {
  1279. pr_err_ratelimited("%s: wcd9378 is NULL\n", __func__);
  1280. return NULL;
  1281. }
  1282. return wcd9378->mbhc;
  1283. }
  1284. EXPORT_SYMBOL_GPL(wcd9378_soc_get_mbhc);
  1285. static int wcd9378_codec_hphl_dac_event(struct snd_soc_dapm_widget *w,
  1286. struct snd_kcontrol *kcontrol,
  1287. int event)
  1288. {
  1289. struct snd_soc_component *component =
  1290. snd_soc_dapm_to_component(w->dapm);
  1291. struct wcd9378_priv *wcd9378 = snd_soc_component_get_drvdata(component);
  1292. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1293. w->name, event);
  1294. switch (event) {
  1295. case SND_SOC_DAPM_PRE_PMU:
  1296. /*OCP FSM EN*/
  1297. snd_soc_component_update_bits(component, WCD9378_HPH_OCP_CTL,
  1298. WCD9378_HPH_OCP_CTL_OCP_FSM_EN_MASK, 0x10);
  1299. /*SCD OP EN*/
  1300. snd_soc_component_update_bits(component, WCD9378_HPH_OCP_CTL,
  1301. WCD9378_HPH_OCP_CTL_SCD_OP_EN_MASK, 0x02);
  1302. /*HPHL ENABLE*/
  1303. snd_soc_component_update_bits(component, WCD9378_CDC_HPH_GAIN_CTL,
  1304. WCD9378_CDC_HPH_GAIN_CTL_HPHL_RX_EN_MASK, 0x04);
  1305. /*OPAMP_CHOP_CLK DISABLE*/
  1306. snd_soc_component_update_bits(component, WCD9378_HPH_RDAC_CLK_CTL1,
  1307. WCD9378_HPH_RDAC_CLK_CTL1_OPAMP_CHOP_CLK_EN_MASK, 0x00);
  1308. wcd9378_rx_connect_port(component, HPH_L, true);
  1309. if (wcd9378->comp1_enable) {
  1310. snd_soc_component_update_bits(component, WCD9378_CDC_COMP_CTL_0,
  1311. WCD9378_CDC_COMP_CTL_0_HPHL_COMP_EN_MASK, 0x02);
  1312. wcd9378_rx_connect_port(component, COMP_L, true);
  1313. }
  1314. if (wcd9378->update_wcd_event)
  1315. wcd9378->update_wcd_event(wcd9378->handle,
  1316. SLV_BOLERO_EVT_RX_MUTE,
  1317. (WCD_RX1 << 0x10));
  1318. break;
  1319. case SND_SOC_DAPM_POST_PMD:
  1320. /*OCP FSM DISABLE*/
  1321. snd_soc_component_update_bits(component, WCD9378_HPH_OCP_CTL,
  1322. WCD9378_HPH_OCP_CTL_OCP_FSM_EN_MASK, 0x00);
  1323. /*SCD OP DISABLE*/
  1324. snd_soc_component_update_bits(component, WCD9378_HPH_OCP_CTL,
  1325. WCD9378_HPH_OCP_CTL_SCD_OP_EN_MASK, 0x00);
  1326. /*HPHL DISABLE*/
  1327. snd_soc_component_update_bits(component, WCD9378_CDC_HPH_GAIN_CTL,
  1328. WCD9378_CDC_HPH_GAIN_CTL_HPHL_RX_EN_MASK, 0x00);
  1329. wcd9378_rx_connect_port(component, HPH_L, false);
  1330. if (wcd9378->comp1_enable) {
  1331. snd_soc_component_update_bits(component, WCD9378_CDC_COMP_CTL_0,
  1332. WCD9378_CDC_COMP_CTL_0_HPHL_COMP_EN_MASK, 0x00);
  1333. wcd9378_rx_connect_port(component, COMP_R, false);
  1334. }
  1335. break;
  1336. default:
  1337. break;
  1338. };
  1339. return 0;
  1340. }
  1341. static int wcd9378_codec_hphr_dac_event(struct snd_soc_dapm_widget *w,
  1342. struct snd_kcontrol *kcontrol,
  1343. int event)
  1344. {
  1345. struct snd_soc_component *component =
  1346. snd_soc_dapm_to_component(w->dapm);
  1347. struct wcd9378_priv *wcd9378 = snd_soc_component_get_drvdata(component);
  1348. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1349. w->name, event);
  1350. switch (event) {
  1351. case SND_SOC_DAPM_PRE_PMU:
  1352. /*OCP FSM EN*/
  1353. snd_soc_component_update_bits(component, WCD9378_HPH_OCP_CTL,
  1354. WCD9378_HPH_OCP_CTL_OCP_FSM_EN_MASK, 0x10);
  1355. /*SCD OP EN*/
  1356. snd_soc_component_update_bits(component, WCD9378_HPH_OCP_CTL,
  1357. WCD9378_HPH_OCP_CTL_SCD_OP_EN_MASK, 0x02);
  1358. /*HPHR ENABLE*/
  1359. snd_soc_component_update_bits(component, WCD9378_CDC_HPH_GAIN_CTL,
  1360. WCD9378_CDC_HPH_GAIN_CTL_HPHR_RX_EN_MASK, 0x08);
  1361. /*OPAMP_CHOP_CLK DISABLE*/
  1362. snd_soc_component_update_bits(component, WCD9378_HPH_RDAC_CLK_CTL1,
  1363. WCD9378_HPH_RDAC_CLK_CTL1_OPAMP_CHOP_CLK_EN_MASK, 0x00);
  1364. wcd9378_rx_connect_port(component, HPH_R, true);
  1365. if (wcd9378->comp2_enable) {
  1366. snd_soc_component_update_bits(component, WCD9378_CDC_COMP_CTL_0,
  1367. WCD9378_CDC_COMP_CTL_0_HPHR_COMP_EN_MASK, 0x01);
  1368. wcd9378_rx_connect_port(component, COMP_R, true);
  1369. }
  1370. break;
  1371. case SND_SOC_DAPM_POST_PMD:
  1372. /*OCP FSM DISABLE*/
  1373. snd_soc_component_update_bits(component, WCD9378_HPH_OCP_CTL,
  1374. WCD9378_HPH_OCP_CTL_OCP_FSM_EN_MASK, 0x00);
  1375. /*SCD OP DISABLE*/
  1376. snd_soc_component_update_bits(component, WCD9378_HPH_OCP_CTL,
  1377. WCD9378_HPH_OCP_CTL_SCD_OP_EN_MASK, 0x00);
  1378. /*HPHR DISABLE*/
  1379. snd_soc_component_update_bits(component, WCD9378_CDC_HPH_GAIN_CTL,
  1380. WCD9378_CDC_HPH_GAIN_CTL_HPHR_RX_EN_MASK, 0x00);
  1381. wcd9378_rx_connect_port(component, HPH_R, false);
  1382. if (wcd9378->comp2_enable) {
  1383. snd_soc_component_update_bits(component, WCD9378_CDC_COMP_CTL_0,
  1384. WCD9378_CDC_COMP_CTL_0_HPHR_COMP_EN_MASK, 0x00);
  1385. wcd9378_rx_connect_port(component, COMP_R, false);
  1386. }
  1387. break;
  1388. default:
  1389. break;
  1390. };
  1391. return 0;
  1392. }
  1393. static int wcd9378_codec_enable_hphl_pa(struct snd_soc_dapm_widget *w,
  1394. struct snd_kcontrol *kcontrol,
  1395. int event)
  1396. {
  1397. struct snd_soc_component *component =
  1398. snd_soc_dapm_to_component(w->dapm);
  1399. struct wcd9378_priv *wcd9378 = snd_soc_component_get_drvdata(component);
  1400. int bank = 0;
  1401. int act_ps = 0;
  1402. bank = (wcd9378_swr_slv_get_current_bank(wcd9378->rx_swr_dev,
  1403. wcd9378->rx_swr_dev->dev_num) ? 0 : 1);
  1404. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1405. w->name, event);
  1406. switch (event) {
  1407. case SND_SOC_DAPM_PRE_PMU:
  1408. if (wcd9378->update_wcd_event)
  1409. wcd9378->update_wcd_event(wcd9378->handle,
  1410. SLV_BOLERO_EVT_RX_MUTE,
  1411. (WCD_RX1 << 0x10 | 0x01));
  1412. if (wcd9378->update_wcd_event)
  1413. wcd9378->update_wcd_event(wcd9378->handle,
  1414. SLV_BOLERO_EVT_RX_MUTE,
  1415. (WCD_RX1 << 0x10));
  1416. act_ps = snd_soc_component_read(component, WCD9378_PDE47_ACT_PS);
  1417. if (act_ps)
  1418. dev_dbg(component->dev, "%s: hph sequencer didnot power on, act_ps: 0x%0x\n",
  1419. __func__, act_ps);
  1420. else
  1421. dev_dbg(component->dev, "%s: hph sequencer power on successful, act_ps: 0x%0x\n",
  1422. __func__, act_ps);
  1423. break;
  1424. case SND_SOC_DAPM_POST_PMD:
  1425. if (wcd9378->update_wcd_event)
  1426. wcd9378->update_wcd_event(wcd9378->handle,
  1427. SLV_BOLERO_EVT_RX_MUTE,
  1428. (WCD_RX1 << 0x10 | 0x1));
  1429. if (wcd9378->update_wcd_event && wcd9378->comp1_enable)
  1430. wcd9378->update_wcd_event(wcd9378->handle,
  1431. SLV_BOLERO_EVT_RX_COMPANDER_SOFT_RST,
  1432. (WCD_RX1 << 0x10));
  1433. blocking_notifier_call_chain(&wcd9378->mbhc->notifier,
  1434. WCD_EVENT_POST_HPHL_PA_OFF,
  1435. &wcd9378->mbhc->wcd_mbhc);
  1436. break;
  1437. default:
  1438. break;
  1439. };
  1440. return 0;
  1441. }
  1442. static int wcd9378_codec_enable_hphr_pa(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 wcd9378_priv *wcd9378 = snd_soc_component_get_drvdata(component);
  1449. int act_ps = 0;
  1450. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1451. w->name, event);
  1452. switch (event) {
  1453. case SND_SOC_DAPM_PRE_PMU:
  1454. if (wcd9378->update_wcd_event)
  1455. wcd9378->update_wcd_event(wcd9378->handle,
  1456. SLV_BOLERO_EVT_RX_MUTE,
  1457. (WCD_RX2 << 0x10 | 0x1));
  1458. if (wcd9378->update_wcd_event)
  1459. wcd9378->update_wcd_event(wcd9378->handle,
  1460. SLV_BOLERO_EVT_RX_MUTE,
  1461. (WCD_RX2 << 0x10));
  1462. act_ps = snd_soc_component_read(component, WCD9378_PDE47_ACT_PS);
  1463. if (act_ps)
  1464. dev_dbg(component->dev, "%s: hph sequencer didnot power on, act_ps: 0x%0x\n",
  1465. __func__, act_ps);
  1466. else
  1467. dev_dbg(component->dev, "%s: hph sequencer power on successful, act_ps: 0x%0x\n",
  1468. __func__, act_ps);
  1469. break;
  1470. case SND_SOC_DAPM_POST_PMD:
  1471. if (wcd9378->update_wcd_event)
  1472. wcd9378->update_wcd_event(wcd9378->handle,
  1473. SLV_BOLERO_EVT_RX_MUTE,
  1474. (WCD_RX2 << 0x10 | 0x1));
  1475. if (wcd9378->update_wcd_event && wcd9378->comp2_enable)
  1476. wcd9378->update_wcd_event(wcd9378->handle,
  1477. SLV_BOLERO_EVT_RX_COMPANDER_SOFT_RST,
  1478. (WCD_RX2 << 0x10));
  1479. blocking_notifier_call_chain(&wcd9378->mbhc->notifier,
  1480. WCD_EVENT_POST_HPHR_PA_OFF,
  1481. &wcd9378->mbhc->wcd_mbhc);
  1482. break;
  1483. default:
  1484. break;
  1485. };
  1486. return 0;
  1487. }
  1488. static int wcd9378_codec_enable_aux_pa(struct snd_soc_dapm_widget *w,
  1489. struct snd_kcontrol *kcontrol,
  1490. int event)
  1491. {
  1492. struct snd_soc_component *component =
  1493. snd_soc_dapm_to_component(w->dapm);
  1494. struct wcd9378_priv *wcd9378 = snd_soc_component_get_drvdata(component);
  1495. int ret = 0;
  1496. int bank = 0;
  1497. int act_ps = 0;
  1498. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1499. w->name, event);
  1500. bank = (wcd9378_swr_slv_get_current_bank(wcd9378->rx_swr_dev,
  1501. wcd9378->rx_swr_dev->dev_num) ? 0 : 1);
  1502. switch (event) {
  1503. case SND_SOC_DAPM_PRE_PMU:
  1504. wcd9378_swr_slave_clk_set(wcd9378->dev, bank, RX_PATH, true);
  1505. ret = swr_slvdev_datapath_control(wcd9378->rx_swr_dev,
  1506. wcd9378->rx_swr_dev->dev_num,
  1507. true);
  1508. wcd9378_swr_slave_clk_set(wcd9378->dev, !bank, RX_PATH, true);
  1509. if (test_bit(RX1_AUX_EN, &wcd9378->sys_usage_status)) {
  1510. if (wcd9378->update_wcd_event)
  1511. wcd9378->update_wcd_event(wcd9378->handle,
  1512. SLV_BOLERO_EVT_RX_MUTE,
  1513. (WCD_RX2 << 0x10));
  1514. } else {
  1515. if (wcd9378->update_wcd_event)
  1516. wcd9378->update_wcd_event(wcd9378->handle,
  1517. SLV_BOLERO_EVT_RX_MUTE,
  1518. (WCD_RX3 << 0x10));
  1519. }
  1520. act_ps = snd_soc_component_read(component, WCD9378_PDE23_ACT_PS);
  1521. if (act_ps)
  1522. dev_dbg(component->dev, "%s: sa sequencer didnot power on, act_ps: 0x%0x\n",
  1523. __func__, act_ps);
  1524. else
  1525. dev_dbg(component->dev, "%s: sa sequencer power on successful, act_ps: 0x%0x\n",
  1526. __func__, act_ps);
  1527. break;
  1528. case SND_SOC_DAPM_POST_PMD:
  1529. if (test_bit(RX1_AUX_EN, &wcd9378->sys_usage_status)) {
  1530. if (wcd9378->update_wcd_event)
  1531. wcd9378->update_wcd_event(wcd9378->handle,
  1532. SLV_BOLERO_EVT_RX_MUTE,
  1533. (WCD_RX2 << 0x10 | 0x1));
  1534. } else {
  1535. if (wcd9378->update_wcd_event)
  1536. wcd9378->update_wcd_event(wcd9378->handle,
  1537. SLV_BOLERO_EVT_RX_MUTE,
  1538. (WCD_RX3 << 0x10 | 0x1));
  1539. }
  1540. break;
  1541. };
  1542. return ret;
  1543. }
  1544. static int wcd9378_codec_enable_ear_pa(struct snd_soc_dapm_widget *w,
  1545. struct snd_kcontrol *kcontrol,
  1546. int event)
  1547. {
  1548. struct snd_soc_component *component =
  1549. snd_soc_dapm_to_component(w->dapm);
  1550. struct wcd9378_priv *wcd9378 = snd_soc_component_get_drvdata(component);
  1551. int ret = 0, bank = 0;
  1552. int act_ps = 0;
  1553. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1554. w->name, event);
  1555. bank = (wcd9378_swr_slv_get_current_bank(wcd9378->rx_swr_dev,
  1556. wcd9378->rx_swr_dev->dev_num) ? 0 : 1);
  1557. switch (event) {
  1558. case SND_SOC_DAPM_PRE_PMU:
  1559. wcd9378_swr_slave_clk_set(wcd9378->dev, bank, RX_PATH, true);
  1560. ret = swr_slvdev_datapath_control(wcd9378->rx_swr_dev,
  1561. wcd9378->rx_swr_dev->dev_num,
  1562. true);
  1563. wcd9378_swr_slave_clk_set(wcd9378->dev, !bank, RX_PATH, true);
  1564. if (test_bit(RX0_EAR_EN, &wcd9378->sys_usage_status)) {
  1565. if (wcd9378->update_wcd_event)
  1566. wcd9378->update_wcd_event(wcd9378->handle,
  1567. SLV_BOLERO_EVT_RX_MUTE,
  1568. (WCD_RX1 << 0x10));
  1569. } else {
  1570. if (wcd9378->update_wcd_event)
  1571. wcd9378->update_wcd_event(wcd9378->handle,
  1572. SLV_BOLERO_EVT_RX_MUTE,
  1573. (WCD_RX3 << 0x10));
  1574. }
  1575. act_ps = snd_soc_component_read(component, WCD9378_PDE23_ACT_PS);
  1576. if (act_ps)
  1577. dev_dbg(component->dev, "%s: sa sequencer didnot power on, act_ps: 0x%0x\n",
  1578. __func__, act_ps);
  1579. else
  1580. dev_dbg(component->dev, "%s: sa sequencer power on successful, act_ps: 0x%0x\n",
  1581. __func__, act_ps);
  1582. break;
  1583. case SND_SOC_DAPM_POST_PMD:
  1584. if (test_bit(RX0_EAR_EN, &wcd9378->sys_usage_status)) {
  1585. if (wcd9378->update_wcd_event)
  1586. wcd9378->update_wcd_event(wcd9378->handle,
  1587. SLV_BOLERO_EVT_RX_MUTE,
  1588. (WCD_RX1 << 0x10 | 0x1));
  1589. } else {
  1590. if (wcd9378->update_wcd_event)
  1591. wcd9378->update_wcd_event(wcd9378->handle,
  1592. SLV_BOLERO_EVT_RX_MUTE,
  1593. (WCD_RX3 << 0x10 | 0x1));
  1594. }
  1595. break;
  1596. };
  1597. return ret;
  1598. }
  1599. static int wcd9378_get_hph_pwr_level(int hph_mode)
  1600. {
  1601. switch (hph_mode) {
  1602. case CLS_H_LOHIFI:
  1603. case CLS_AB_LOHIFI:
  1604. return PWR_LEVEL_LOHIFI_VAL;
  1605. case CLS_H_LP:
  1606. case CLS_AB_LP:
  1607. return PWR_LEVEL_LP_VAL;
  1608. case CLS_H_HIFI:
  1609. case CLS_AB_HIFI:
  1610. return PWR_LEVEL_HIFI_VAL;
  1611. case CLS_H_ULP:
  1612. case CLS_AB:
  1613. case CLS_H_NORMAL:
  1614. default:
  1615. return PWR_LEVEL_ULP_VAL;
  1616. }
  1617. return PWR_LEVEL_ULP_VAL;
  1618. }
  1619. static void wcd9378_hph_set_channel_volume(struct snd_soc_component *component)
  1620. {
  1621. struct wcd9378_priv *wcd9378 =
  1622. snd_soc_component_get_drvdata(component);
  1623. if ((!wcd9378->comp1_enable) &&
  1624. (!wcd9378->comp2_enable)) {
  1625. dev_err(component->dev, "%s hph gainis 0x%0xd\n", __func__, wcd9378->hph_gain);
  1626. snd_soc_component_update_bits(component,
  1627. (WCD9378_FU42_CH_VOL_CH1 | WCD9378_MBQ_ENABLE_MASK),
  1628. WCD9378_FU42_CH_VOL_CH1_FU42_CH_VOL_CH1_MASK,
  1629. wcd9378->hph_gain >> 8);
  1630. snd_soc_component_update_bits(component,
  1631. WCD9378_FU42_CH_VOL_CH1,
  1632. WCD9378_FU42_CH_VOL_CH1_FU42_CH_VOL_CH1_MASK,
  1633. wcd9378->hph_gain & 0x00ff);
  1634. snd_soc_component_update_bits(component,
  1635. (WCD9378_FU42_CH_VOL_CH2 | WCD9378_MBQ_ENABLE_MASK),
  1636. WCD9378_FU42_CH_VOL_CH2_FU42_CH_VOL_CH2_MASK,
  1637. wcd9378->hph_gain >> 8);
  1638. snd_soc_component_update_bits(component,
  1639. WCD9378_FU42_CH_VOL_CH2,
  1640. WCD9378_FU42_CH_VOL_CH2_FU42_CH_VOL_CH2_MASK,
  1641. wcd9378->hph_gain & 0x00ff);
  1642. }
  1643. }
  1644. static int wcd9378_swr_slave_clk_set(struct device *dev, int bank, int path, bool enable)
  1645. {
  1646. u16 clk_scale_reg = 0;
  1647. u8 clk_rst = 0x00, scale_rst = 0x00;
  1648. u8 swr_base_clk = 0, swr_clk_scale = 0;
  1649. struct wcd9378_priv *wcd9378 = NULL;
  1650. struct swr_device *swr_dev = NULL;
  1651. wcd9378 = dev_get_drvdata(dev);
  1652. if (!wcd9378)
  1653. return -EINVAL;
  1654. if (path == RX_PATH) {
  1655. swr_dev = wcd9378->rx_swr_dev;
  1656. swr_base_clk = wcd9378->swr_base_clk;
  1657. swr_clk_scale = wcd9378->swr_clk_scale;
  1658. } else {
  1659. swr_dev = wcd9378->tx_swr_dev;
  1660. swr_base_clk = SWR_BASECLK_19P2MHZ;
  1661. swr_clk_scale = SWR_CLKSCALE_DIV2;
  1662. }
  1663. clk_scale_reg = (bank ? SWRS_SCP_BUSCLOCK_SCALE_BANK1 :
  1664. SWRS_SCP_BUSCLOCK_SCALE_BANK0);
  1665. if (enable) {
  1666. swr_write(swr_dev, swr_dev->dev_num,
  1667. SWRS_SCP_BASE_CLK_BASE, &swr_base_clk);
  1668. swr_write(swr_dev, swr_dev->dev_num,
  1669. clk_scale_reg, &swr_clk_scale);
  1670. } else {
  1671. swr_write(swr_dev, swr_dev->dev_num,
  1672. SWRS_SCP_BASE_CLK_BASE, &clk_rst);
  1673. swr_write(swr_dev, swr_dev->dev_num,
  1674. clk_scale_reg, &scale_rst);
  1675. }
  1676. return 0;
  1677. }
  1678. static int wcd9378_hph_sequencer_enable(struct snd_soc_dapm_widget *w,
  1679. struct snd_kcontrol *kcontrol, int event)
  1680. {
  1681. struct snd_soc_component *component =
  1682. snd_soc_dapm_to_component(w->dapm);
  1683. struct wcd9378_priv *wcd9378 =
  1684. snd_soc_component_get_drvdata(component);
  1685. int power_level, bank = 0;
  1686. int ret = 0;
  1687. struct swr_device *swr_dev = wcd9378->tx_swr_dev;
  1688. u8 scp_commit_val = 0x2;
  1689. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1690. w->name, event);
  1691. switch (event) {
  1692. case SND_SOC_DAPM_PRE_PMU:
  1693. wcd9378_sys_usage_auto_udpate(component, RX0_RX1_HPH_EN, true);
  1694. if ((!wcd9378->comp1_enable) || (!wcd9378->comp2_enable)) {
  1695. snd_soc_component_update_bits(component, WCD9378_HPH_UP_T7,
  1696. WCD9378_HPH_UP_T7_HPH_UP_T7_MASK, 0x07);
  1697. snd_soc_component_update_bits(component, WCD9378_HPH_DN_T1,
  1698. WCD9378_HPH_DN_T1_HPH_DN_T1_MASK, 0x07);
  1699. }
  1700. if ((wcd9378->hph_mode == CLS_AB) ||
  1701. (wcd9378->hph_mode == CLS_AB_HIFI) ||
  1702. (wcd9378->hph_mode == CLS_AB_LP) ||
  1703. (wcd9378->hph_mode == CLS_AB_LOHIFI))
  1704. snd_soc_component_update_bits(component, WCD9378_CP_CP_DTOP_CTRL_14,
  1705. WCD9378_CP_CP_DTOP_CTRL_14_OVERRIDE_VREF_MASK, 0x80);
  1706. /*GET HPH_MODE*/
  1707. power_level = wcd9378_get_hph_pwr_level(wcd9378->hph_mode);
  1708. /*SET HPH_MODE*/
  1709. snd_soc_component_update_bits(component, WCD9378_IT41_USAGE,
  1710. WCD9378_IT41_USAGE_IT41_USAGE_MASK, power_level);
  1711. /*TURN ON HPH SEQUENCER*/
  1712. snd_soc_component_update_bits(component, WCD9378_PDE47_REQ_PS,
  1713. WCD9378_PDE47_REQ_PS_PDE47_REQ_PS_MASK, 0x00);
  1714. /*TBD: SET SDCA GAIN, NEED CHECK THE LOGIC*/
  1715. wcd9378_hph_set_channel_volume(component);
  1716. if ((!wcd9378->comp1_enable) || (!wcd9378->comp2_enable))
  1717. /*PA delay is 22400us*/
  1718. usleep_range(22500, 22510);
  1719. else
  1720. /*COMP delay is 9400us*/
  1721. usleep_range(9500, 9510);
  1722. /*RX0 unmute*/
  1723. snd_soc_component_update_bits(component, WCD9378_FU42_MUTE_CH1,
  1724. WCD9378_FU42_MUTE_CH1_FU42_MUTE_CH1_MASK, 0x00);
  1725. /*RX1 unmute*/
  1726. snd_soc_component_update_bits(component, WCD9378_FU42_MUTE_CH2,
  1727. WCD9378_FU42_MUTE_CH2_FU42_MUTE_CH2_MASK, 0x00);
  1728. if (wcd9378->sys_usage == SYS_USAGE_10)
  1729. /*FU23 UNMUTE*/
  1730. snd_soc_component_update_bits(component, WCD9378_FU23_MUTE,
  1731. WCD9378_FU23_MUTE_FU23_MUTE_MASK, 0x00);
  1732. swr_write(swr_dev, swr_dev->dev_num, 0x004c, &scp_commit_val);
  1733. wcd9378_swr_slave_clk_set(wcd9378->dev, bank, RX_PATH, true);
  1734. ret = swr_slvdev_datapath_control(wcd9378->rx_swr_dev,
  1735. wcd9378->rx_swr_dev->dev_num,
  1736. true);
  1737. wcd9378_swr_slave_clk_set(wcd9378->dev, !bank, RX_PATH, true);
  1738. break;
  1739. case SND_SOC_DAPM_POST_PMD:
  1740. /*RX0 mute*/
  1741. snd_soc_component_update_bits(component, WCD9378_FU42_MUTE_CH1,
  1742. WCD9378_FU42_MUTE_CH1_FU42_MUTE_CH1_MASK, 0x01);
  1743. /*RX1 mute*/
  1744. snd_soc_component_update_bits(component, WCD9378_FU42_MUTE_CH2,
  1745. WCD9378_FU42_MUTE_CH2_FU42_MUTE_CH2_MASK, 0x01);
  1746. /*TEAR DOWN HPH SEQUENCER*/
  1747. snd_soc_component_update_bits(component, WCD9378_PDE47_REQ_PS,
  1748. WCD9378_PDE47_REQ_PS_PDE47_REQ_PS_MASK, 0x03);
  1749. if (!wcd9378->comp1_enable || !wcd9378->comp2_enable)
  1750. /*PA delay is 24250us*/
  1751. usleep_range(24300, 24310);
  1752. else
  1753. /*COMP delay is 11250us*/
  1754. usleep_range(11300, 11310);
  1755. wcd9378_sys_usage_auto_udpate(component, RX0_RX1_HPH_EN, false);
  1756. break;
  1757. default:
  1758. break;
  1759. };
  1760. return ret;
  1761. }
  1762. static int wcd9378_codec_ear_dac_event(struct snd_soc_dapm_widget *w,
  1763. struct snd_kcontrol *kcontrol,
  1764. int event)
  1765. {
  1766. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  1767. struct wcd9378_priv *wcd9378 = snd_soc_component_get_drvdata(component);
  1768. int ear_rx2 = 0;
  1769. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1770. w->name, event);
  1771. ear_rx2 = snd_soc_component_read(component, WCD9378_CDC_AUX_GAIN_CTL) &
  1772. WCD9378_CDC_AUX_GAIN_CTL_AUX_EN_MASK;
  1773. switch (event) {
  1774. case SND_SOC_DAPM_PRE_PMU:
  1775. /*SHORT_PROT_EN ENABLE*/
  1776. snd_soc_component_update_bits(component, WCD9378_ANA_EAR,
  1777. WCD9378_ANA_EAR_SHORT_PROT_EN_MASK, 0x40);
  1778. if (!ear_rx2) {
  1779. /*RX0 ENABLE*/
  1780. snd_soc_component_update_bits(component, WCD9378_CDC_HPH_GAIN_CTL,
  1781. WCD9378_CDC_HPH_GAIN_CTL_HPHL_RX_EN_MASK, 0x04);
  1782. wcd9378_sys_usage_auto_udpate(component, RX0_EAR_EN, true);
  1783. if (wcd9378->comp1_enable) {
  1784. snd_soc_component_update_bits(component, WCD9378_CDC_COMP_CTL_0,
  1785. WCD9378_CDC_COMP_CTL_0_EAR_COMP_EN_MASK, 0x04);
  1786. wcd9378_rx_connect_port(component, COMP_L, true);
  1787. }
  1788. wcd9378_rx_connect_port(component, HPH_L, true);
  1789. } else {
  1790. wcd9378_sys_usage_auto_udpate(component, RX2_EAR_EN, true);
  1791. /*FORCE CLASS_AB EN*/
  1792. snd_soc_component_update_bits(component, WCD9378_SEQ_OVRRIDE_CTL0,
  1793. WCD9378_SEQ_OVRRIDE_CTL0_CLASSAB_EN_OVR_MASK, 0x20);
  1794. snd_soc_component_update_bits(component, WCD9378_CP_CP_DTOP_CTRL_14,
  1795. WCD9378_CP_CP_DTOP_CTRL_14_OVERRIDE_VREF_MASK, 0x80);
  1796. if (wcd9378->rx2_clk_mode)
  1797. snd_soc_component_update_bits(component, WCD9378_CDC_PATH_MODE,
  1798. WCD9378_CDC_PATH_MODE_RX2_CLK_RATE_MASK, 0x40);
  1799. wcd9378_rx_connect_port(component, LO, true);
  1800. }
  1801. break;
  1802. case SND_SOC_DAPM_POST_PMD:
  1803. /*SHORT_PROT_EN DISABLE*/
  1804. snd_soc_component_update_bits(component, WCD9378_ANA_EAR,
  1805. WCD9378_ANA_EAR_SHORT_PROT_EN_MASK, 0x00);
  1806. if (test_bit(RX0_EAR_EN, &wcd9378->sys_usage_status)) {
  1807. /*RX0 DISABLE*/
  1808. snd_soc_component_update_bits(component, WCD9378_CDC_HPH_GAIN_CTL,
  1809. WCD9378_CDC_HPH_GAIN_CTL_HPHL_RX_EN_MASK, 0x00);
  1810. wcd9378_rx_connect_port(component, HPH_L, false);
  1811. if (wcd9378->comp1_enable) {
  1812. snd_soc_component_update_bits(component, WCD9378_CDC_COMP_CTL_0,
  1813. WCD9378_CDC_COMP_CTL_0_EAR_COMP_EN_MASK, 0x00);
  1814. wcd9378_rx_connect_port(component, COMP_L, false);
  1815. }
  1816. wcd9378_sys_usage_auto_udpate(component, RX0_EAR_EN, false);
  1817. } else {
  1818. wcd9378_rx_connect_port(component, LO, false);
  1819. wcd9378_sys_usage_auto_udpate(component, RX2_EAR_EN, false);
  1820. }
  1821. break;
  1822. };
  1823. return 0;
  1824. }
  1825. static int wcd9378_codec_aux_dac_event(struct snd_soc_dapm_widget *w,
  1826. struct snd_kcontrol *kcontrol,
  1827. int event)
  1828. {
  1829. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  1830. struct wcd9378_priv *wcd9378 = snd_soc_component_get_drvdata(component);
  1831. int aux_rx2 = 0;
  1832. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1833. w->name, event);
  1834. aux_rx2 = snd_soc_component_read(component, WCD9378_CDC_AUX_GAIN_CTL) &
  1835. WCD9378_CDC_AUX_GAIN_CTL_AUX_EN_MASK;
  1836. switch (event) {
  1837. case SND_SOC_DAPM_PRE_PMU:
  1838. /*AUXPA SHORT PROT ENABLE*/
  1839. snd_soc_component_update_bits(component, WCD9378_AUX_AUXPA,
  1840. WCD9378_AUX_AUXPA_AUX_PA_SHORT_PROT_EN_MASK, 0x40);
  1841. if (!aux_rx2) {
  1842. /*RX1 ENABLE*/
  1843. snd_soc_component_update_bits(component, WCD9378_CDC_HPH_GAIN_CTL,
  1844. WCD9378_CDC_HPH_GAIN_CTL_HPHR_RX_EN_MASK, 0x08);
  1845. wcd9378_sys_usage_auto_udpate(component, RX1_AUX_EN, true);
  1846. wcd9378_rx_connect_port(component, HPH_R, true);
  1847. } else {
  1848. wcd9378_sys_usage_auto_udpate(component, RX2_AUX_EN, true);
  1849. if (wcd9378->rx2_clk_mode)
  1850. snd_soc_component_update_bits(component, WCD9378_CDC_PATH_MODE,
  1851. WCD9378_CDC_PATH_MODE_RX2_CLK_RATE_MASK, 0x40);
  1852. wcd9378_rx_connect_port(component, LO, true);
  1853. }
  1854. break;
  1855. case SND_SOC_DAPM_POST_PMD:
  1856. /*AUXPA SHORT PROT DISABLE*/
  1857. snd_soc_component_update_bits(component, WCD9378_AUX_AUXPA,
  1858. WCD9378_AUX_AUXPA_AUX_PA_SHORT_PROT_EN_MASK, 0x00);
  1859. if (test_bit(RX1_AUX_EN, &wcd9378->sys_usage_status)) {
  1860. wcd9378_rx_connect_port(component, HPH_R, false);
  1861. wcd9378_sys_usage_auto_udpate(component, RX1_AUX_EN, false);
  1862. } else {
  1863. wcd9378_rx_connect_port(component, LO, false);
  1864. wcd9378_sys_usage_auto_udpate(component, RX2_AUX_EN, false);
  1865. }
  1866. break;
  1867. };
  1868. return 0;
  1869. }
  1870. static int wcd9378_sa_sequencer_enable(struct snd_soc_dapm_widget *w,
  1871. struct snd_kcontrol *kcontrol, int event)
  1872. {
  1873. struct snd_soc_component *component =
  1874. snd_soc_dapm_to_component(w->dapm);
  1875. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1876. w->name, event);
  1877. switch (event) {
  1878. case SND_SOC_DAPM_PRE_PMU:
  1879. /*TURN ON AMP SEQUENCER*/
  1880. snd_soc_component_update_bits(component, WCD9378_PDE23_REQ_PS,
  1881. WCD9378_PDE23_REQ_PS_PDE23_REQ_PS_MASK, 0x00);
  1882. /*default delay 8550us*/
  1883. usleep_range(8600, 8610);
  1884. /*FU23 UNMUTE*/
  1885. snd_soc_component_update_bits(component, WCD9378_FU23_MUTE,
  1886. WCD9378_FU23_MUTE_FU23_MUTE_MASK, 0x00);
  1887. break;
  1888. case SND_SOC_DAPM_POST_PMD:
  1889. /*FU23 MUTE*/
  1890. snd_soc_component_update_bits(component, WCD9378_FU23_MUTE,
  1891. WCD9378_FU23_MUTE_FU23_MUTE_MASK, 0x01);
  1892. /*TEAR DOWN AMP SEQUENCER*/
  1893. snd_soc_component_update_bits(component, WCD9378_PDE23_REQ_PS,
  1894. WCD9378_PDE23_REQ_PS_PDE23_REQ_PS_MASK, 0x03);
  1895. /*default delay 1530us*/
  1896. usleep_range(15400, 15410);
  1897. break;
  1898. default:
  1899. break;
  1900. };
  1901. return 0;
  1902. }
  1903. int wcd9378_micbias_control(struct snd_soc_component *component,
  1904. int micb_num, int req, bool is_dapm)
  1905. {
  1906. struct wcd9378_priv *wcd9378 =
  1907. snd_soc_component_get_drvdata(component);
  1908. struct wcd9378_pdata *pdata =
  1909. dev_get_platdata(wcd9378->dev);
  1910. struct wcd9378_micbias_setting *mb = &pdata->micbias;
  1911. int micb_usage = 0, micb_mask = 0, micb_usage_val = 0;
  1912. int pre_off_event = 0, post_off_event = 0;
  1913. int post_on_event = 0, post_dapm_off = 0;
  1914. int post_dapm_on = 0;
  1915. int pull_up_mask = 0, pull_up_en = 0;
  1916. int micb_index = 0, ret = 0;
  1917. switch (micb_num) {
  1918. case MIC_BIAS_1:
  1919. pull_up_mask = WCD9378_MB_PULLUP_EN_MB1_1P8V_OR_PULLUP_SEL_MASK;
  1920. pull_up_en = 0x01;
  1921. micb_usage = WCD9378_IT11_MICB;
  1922. micb_mask = WCD9378_IT11_MICB_IT11_MICB_MASK;
  1923. micb_usage_val = mb->micb1_usage_val;
  1924. break;
  1925. case MIC_BIAS_2:
  1926. pull_up_mask = WCD9378_MB_PULLUP_EN_MB2_1P8V_OR_PULLUP_SEL_MASK;
  1927. pull_up_en = 0x02;
  1928. micb_usage = WCD9378_SMP_MIC_CTRL1_IT11_MICB;
  1929. micb_mask = WCD9378_SMP_MIC_CTRL1_IT11_MICB_IT11_MICB_MASK;
  1930. micb_usage_val = mb->micb2_usage_val;
  1931. pre_off_event = WCD_EVENT_PRE_MICBIAS_2_OFF;
  1932. post_off_event = WCD_EVENT_POST_MICBIAS_2_OFF;
  1933. post_on_event = WCD_EVENT_POST_MICBIAS_2_ON;
  1934. post_dapm_on = WCD_EVENT_POST_DAPM_MICBIAS_2_ON;
  1935. post_dapm_off = WCD_EVENT_POST_DAPM_MICBIAS_2_OFF;
  1936. break;
  1937. case MIC_BIAS_3:
  1938. micb_usage = WCD9378_SMP_MIC_CTRL2_IT11_MICB;
  1939. micb_mask = WCD9378_SMP_MIC_CTRL2_IT11_MICB_IT11_MICB_MASK;
  1940. pull_up_mask = WCD9378_MB_PULLUP_EN_MB3_1P8V_OR_PULLUP_SEL_MASK;
  1941. pull_up_en = 0x04;
  1942. micb_usage_val = mb->micb3_usage_val;
  1943. break;
  1944. default:
  1945. dev_err(component->dev, "%s: Invalid micbias number: %d\n",
  1946. __func__, micb_num);
  1947. return -EINVAL;
  1948. }
  1949. mutex_lock(&wcd9378->micb_lock);
  1950. micb_index = micb_num - 1;
  1951. switch (req) {
  1952. case MICB_PULLUP_ENABLE:
  1953. wcd9378->pullup_ref[micb_index]++;
  1954. if ((wcd9378->pullup_ref[micb_index] == 1) &&
  1955. (wcd9378->micb_ref[micb_index] == 0)) {
  1956. snd_soc_component_update_bits(component, WCD9378_MB_PULLUP_EN,
  1957. pull_up_mask, pull_up_en);
  1958. snd_soc_component_update_bits(component,
  1959. micb_usage, micb_mask, 0x03);
  1960. if (micb_num == MIC_BIAS_2) {
  1961. dev_dbg(component->dev, "%s: pull up sj micbias\n",
  1962. __func__);
  1963. snd_soc_component_update_bits(component,
  1964. WCD9378_IT31_MICB,
  1965. WCD9378_IT31_MICB_IT31_MICB_MASK,
  1966. 0x03);
  1967. wcd9378->curr_micbias2 = 1800;
  1968. }
  1969. }
  1970. break;
  1971. case MICB_PULLUP_DISABLE:
  1972. if (wcd9378->pullup_ref[micb_index] > 0)
  1973. wcd9378->pullup_ref[micb_index]--;
  1974. if ((wcd9378->pullup_ref[micb_index] == 0) &&
  1975. (wcd9378->micb_ref[micb_index] == 0)) {
  1976. snd_soc_component_update_bits(component, micb_usage, micb_mask, 0x01);
  1977. if (micb_num == MIC_BIAS_2) {
  1978. dev_dbg(component->dev, "%s: pull down sj micbias\n",
  1979. __func__);
  1980. snd_soc_component_update_bits(component,
  1981. WCD9378_IT31_MICB,
  1982. WCD9378_IT31_MICB_IT31_MICB_MASK,
  1983. 0x01);
  1984. wcd9378->curr_micbias2 = 0;
  1985. }
  1986. }
  1987. break;
  1988. case MICB_ENABLE:
  1989. dev_dbg(component->dev, "%s: micbias enable enter\n",
  1990. __func__);
  1991. if (!wcd9378->dev_up) {
  1992. dev_dbg(component->dev, "%s: enable req %d wcd device down\n",
  1993. __func__, req);
  1994. ret = -ENODEV;
  1995. goto done;
  1996. }
  1997. wcd9378->micb_ref[micb_index]++;
  1998. if (wcd9378->micb_ref[micb_index] == 1) {
  1999. dev_dbg(component->dev, "%s: enable micbias, micb_usage:0x%0x, val:0x%0x\n",
  2000. __func__, micb_usage, micb_usage_val);
  2001. snd_soc_component_update_bits(component,
  2002. micb_usage, micb_mask, micb_usage_val);
  2003. if (micb_num == MIC_BIAS_2) {
  2004. dev_dbg(component->dev, "%s: enable sj micbias\n",
  2005. __func__);
  2006. snd_soc_component_update_bits(component,
  2007. WCD9378_IT31_MICB,
  2008. WCD9378_IT31_MICB_IT31_MICB_MASK,
  2009. micb_usage_val);
  2010. wcd9378->curr_micbias2 = 1800;
  2011. }
  2012. if (post_on_event)
  2013. blocking_notifier_call_chain(
  2014. &wcd9378->mbhc->notifier,
  2015. post_on_event,
  2016. &wcd9378->mbhc->wcd_mbhc);
  2017. }
  2018. if (is_dapm && post_dapm_on && wcd9378->mbhc)
  2019. blocking_notifier_call_chain(&wcd9378->mbhc->notifier,
  2020. post_dapm_on,
  2021. &wcd9378->mbhc->wcd_mbhc);
  2022. break;
  2023. case MICB_DISABLE:
  2024. dev_dbg(component->dev, "%s: micbias disable enter\n",
  2025. __func__);
  2026. if (wcd9378->micb_ref[micb_index] > 0)
  2027. wcd9378->micb_ref[micb_index]--;
  2028. if ((wcd9378->micb_ref[micb_index] == 0) &&
  2029. (wcd9378->pullup_ref[micb_index] > 0)) {
  2030. snd_soc_component_update_bits(component, WCD9378_MB_PULLUP_EN,
  2031. pull_up_mask, pull_up_en);
  2032. if (micb_num == MIC_BIAS_2)
  2033. wcd9378->curr_micbias2 = 1800;
  2034. } else if ((wcd9378->micb_ref[micb_index] == 0) &&
  2035. (wcd9378->pullup_ref[micb_index] == 0)) {
  2036. if (pre_off_event && wcd9378->mbhc)
  2037. blocking_notifier_call_chain(
  2038. &wcd9378->mbhc->notifier,
  2039. pre_off_event,
  2040. &wcd9378->mbhc->wcd_mbhc);
  2041. snd_soc_component_update_bits(component, micb_usage,
  2042. micb_mask, 0x00);
  2043. if (micb_num == MIC_BIAS_2) {
  2044. snd_soc_component_update_bits(component,
  2045. WCD9378_IT31_MICB,
  2046. WCD9378_IT31_MICB_IT31_MICB_MASK,
  2047. 0x00);
  2048. wcd9378->curr_micbias2 = 0;
  2049. }
  2050. if (post_off_event && wcd9378->mbhc)
  2051. blocking_notifier_call_chain(
  2052. &wcd9378->mbhc->notifier,
  2053. post_off_event,
  2054. &wcd9378->mbhc->wcd_mbhc);
  2055. }
  2056. if (is_dapm && post_dapm_off && wcd9378->mbhc)
  2057. blocking_notifier_call_chain(&wcd9378->mbhc->notifier,
  2058. post_dapm_off,
  2059. &wcd9378->mbhc->wcd_mbhc);
  2060. break;
  2061. default:
  2062. dev_err(component->dev, "%s: Invalid req event: %d\n",
  2063. __func__, req);
  2064. return -EINVAL;
  2065. }
  2066. dev_dbg(component->dev,
  2067. "%s: micb_num:%d, micb_ref: %d, pullup_ref: %d\n",
  2068. __func__, micb_num, wcd9378->micb_ref[micb_index],
  2069. wcd9378->pullup_ref[micb_index]);
  2070. done:
  2071. mutex_unlock(&wcd9378->micb_lock);
  2072. return ret;
  2073. }
  2074. EXPORT_SYMBOL_GPL(wcd9378_micbias_control);
  2075. static int wcd9378_get_logical_addr(struct swr_device *swr_dev)
  2076. {
  2077. int ret = 0;
  2078. uint8_t devnum = 0;
  2079. int num_retry = NUM_ATTEMPTS;
  2080. do {
  2081. /* retry after 4ms */
  2082. usleep_range(4000, 4010);
  2083. ret = swr_get_logical_dev_num(swr_dev, swr_dev->addr, &devnum);
  2084. } while (ret && --num_retry);
  2085. if (ret)
  2086. dev_err(&swr_dev->dev,
  2087. "%s get devnum %d for dev addr %llx failed\n",
  2088. __func__, devnum, swr_dev->addr);
  2089. swr_dev->dev_num = devnum;
  2090. return 0;
  2091. }
  2092. static bool get_usbc_hs_status(struct snd_soc_component *component,
  2093. struct wcd_mbhc_config *mbhc_cfg)
  2094. {
  2095. if (mbhc_cfg->enable_usbc_analog) {
  2096. if (!(snd_soc_component_read(component, WCD9378_ANA_MBHC_MECH)
  2097. & 0x20))
  2098. return true;
  2099. }
  2100. return false;
  2101. }
  2102. int wcd9378_swr_dmic_register_notifier(struct snd_soc_component *component,
  2103. struct notifier_block *nblock,
  2104. bool enable)
  2105. {
  2106. struct wcd9378_priv *wcd9378_priv = NULL;
  2107. if (component == NULL) {
  2108. pr_err_ratelimited("%s: wcd9378 component is NULL\n", __func__);
  2109. return -EINVAL;
  2110. }
  2111. wcd9378_priv = snd_soc_component_get_drvdata(component);
  2112. wcd9378_priv->notify_swr_dmic = enable;
  2113. if (enable)
  2114. return blocking_notifier_chain_register(&wcd9378_priv->notifier,
  2115. nblock);
  2116. else
  2117. return blocking_notifier_chain_unregister(
  2118. &wcd9378_priv->notifier, nblock);
  2119. }
  2120. EXPORT_SYMBOL_GPL(wcd9378_swr_dmic_register_notifier);
  2121. static int wcd9378_event_notify(struct notifier_block *block,
  2122. unsigned long val,
  2123. void *data)
  2124. {
  2125. u16 event = (val & 0xffff);
  2126. int ret = 0;
  2127. struct wcd9378_priv *wcd9378 = dev_get_drvdata((struct device *)data);
  2128. struct snd_soc_component *component = wcd9378->component;
  2129. struct wcd_mbhc *mbhc;
  2130. int rx_clk_type;
  2131. switch (event) {
  2132. case BOLERO_SLV_EVT_TX_CH_HOLD_CLEAR:
  2133. if (test_bit(WCD_ADC1, &wcd9378->status_mask)) {
  2134. snd_soc_component_update_bits(component,
  2135. WCD9378_ANA_TX_CH2, 0x40, 0x00);
  2136. set_bit(WCD_ADC1_MODE, &wcd9378->status_mask);
  2137. clear_bit(WCD_ADC1, &wcd9378->status_mask);
  2138. }
  2139. if (test_bit(WCD_ADC2, &wcd9378->status_mask)) {
  2140. snd_soc_component_update_bits(component,
  2141. WCD9378_ANA_TX_CH2, 0x20, 0x00);
  2142. set_bit(WCD_ADC2_MODE, &wcd9378->status_mask);
  2143. clear_bit(WCD_ADC2, &wcd9378->status_mask);
  2144. }
  2145. if (test_bit(WCD_ADC3, &wcd9378->status_mask)) {
  2146. snd_soc_component_update_bits(component,
  2147. WCD9378_ANA_TX_CH3_HPF, 0x40, 0x00);
  2148. set_bit(WCD_ADC3_MODE, &wcd9378->status_mask);
  2149. clear_bit(WCD_ADC3, &wcd9378->status_mask);
  2150. }
  2151. break;
  2152. case BOLERO_SLV_EVT_PA_OFF_PRE_SSR:
  2153. snd_soc_component_update_bits(component, WCD9378_ANA_HPH,
  2154. 0xC0, 0x00);
  2155. snd_soc_component_update_bits(component, WCD9378_ANA_EAR,
  2156. 0x80, 0x00);
  2157. snd_soc_component_update_bits(component, WCD9378_AUX_AUXPA,
  2158. 0x80, 0x00);
  2159. break;
  2160. case BOLERO_SLV_EVT_SSR_DOWN:
  2161. wcd9378->dev_up = false;
  2162. if (wcd9378->notify_swr_dmic)
  2163. blocking_notifier_call_chain(&wcd9378->notifier,
  2164. WCD9378_EVT_SSR_DOWN,
  2165. NULL);
  2166. wcd9378->mbhc->wcd_mbhc.deinit_in_progress = true;
  2167. mbhc = &wcd9378->mbhc->wcd_mbhc;
  2168. wcd9378->usbc_hs_status = get_usbc_hs_status(component,
  2169. mbhc->mbhc_cfg);
  2170. wcd9378_mbhc_ssr_down(wcd9378->mbhc, component);
  2171. wcd9378_reset_low(wcd9378->dev);
  2172. break;
  2173. case BOLERO_SLV_EVT_SSR_UP:
  2174. wcd9378_reset(wcd9378->dev);
  2175. /* allow reset to take effect */
  2176. usleep_range(10000, 10010);
  2177. wcd9378_get_logical_addr(wcd9378->tx_swr_dev);
  2178. wcd9378_get_logical_addr(wcd9378->rx_swr_dev);
  2179. wcd9378->tx_swr_dev->scp1_val = 0;
  2180. wcd9378->tx_swr_dev->scp2_val = 0;
  2181. wcd9378->rx_swr_dev->scp1_val = 0;
  2182. wcd9378->rx_swr_dev->scp2_val = 0;
  2183. wcd9378_init_reg(component);
  2184. regcache_mark_dirty(wcd9378->regmap);
  2185. regcache_sync(wcd9378->regmap);
  2186. /* Initialize MBHC module */
  2187. mbhc = &wcd9378->mbhc->wcd_mbhc;
  2188. ret = wcd9378_mbhc_post_ssr_init(wcd9378->mbhc, component);
  2189. if (ret) {
  2190. dev_err(component->dev, "%s: mbhc initialization failed\n",
  2191. __func__);
  2192. } else {
  2193. wcd9378_mbhc_hs_detect(component, mbhc->mbhc_cfg);
  2194. }
  2195. wcd9378->mbhc->wcd_mbhc.deinit_in_progress = false;
  2196. wcd9378->dev_up = true;
  2197. if (wcd9378->notify_swr_dmic)
  2198. blocking_notifier_call_chain(&wcd9378->notifier,
  2199. WCD9378_EVT_SSR_UP,
  2200. NULL);
  2201. if (wcd9378->usbc_hs_status)
  2202. mdelay(500);
  2203. break;
  2204. case BOLERO_SLV_EVT_CLK_NOTIFY:
  2205. snd_soc_component_update_bits(component,
  2206. WCD9378_TOP_CLK_CFG, 0x06,
  2207. ((val >> 0x10) << 0x01));
  2208. rx_clk_type = (val >> 0x10);
  2209. switch (rx_clk_type) {
  2210. case RX_CLK_12P288MHZ:
  2211. wcd9378->swr_base_clk = SWR_BASECLK_24P576MHZ;
  2212. wcd9378->swr_clk_scale = SWR_CLKSCALE_DIV2;
  2213. break;
  2214. case RX_CLK_11P2896MHZ:
  2215. wcd9378->swr_base_clk = SWR_BASECLK_22P5792MHZ;
  2216. wcd9378->swr_clk_scale = SWR_CLKSCALE_DIV2;
  2217. break;
  2218. default:
  2219. wcd9378->swr_base_clk = SWR_BASECLK_19P2MHZ;
  2220. wcd9378->swr_clk_scale = SWR_CLKSCALE_DIV2;
  2221. break;
  2222. }
  2223. dev_dbg(component->dev, "%s: base_clk:0x%0x, clk_scale:0x%x\n",
  2224. __func__, wcd9378->swr_base_clk, wcd9378->swr_clk_scale);
  2225. break;
  2226. default:
  2227. dev_dbg(component->dev, "%s: invalid event %d\n", __func__, event);
  2228. break;
  2229. }
  2230. return 0;
  2231. }
  2232. static int wcd9378_wakeup(void *handle, bool enable)
  2233. {
  2234. struct wcd9378_priv *priv;
  2235. int ret = 0;
  2236. if (!handle) {
  2237. pr_err("%s: NULL handle\n", __func__);
  2238. return -EINVAL;
  2239. }
  2240. priv = (struct wcd9378_priv *)handle;
  2241. if (!priv->tx_swr_dev) {
  2242. pr_err("%s: tx swr dev is NULL\n", __func__);
  2243. return -EINVAL;
  2244. }
  2245. mutex_lock(&priv->wakeup_lock);
  2246. if (enable)
  2247. ret = swr_device_wakeup_vote(priv->tx_swr_dev);
  2248. else
  2249. ret = swr_device_wakeup_unvote(priv->tx_swr_dev);
  2250. mutex_unlock(&priv->wakeup_lock);
  2251. return ret;
  2252. }
  2253. static inline int wcd9378_tx_path_get(const char *wname,
  2254. unsigned int *path_num)
  2255. {
  2256. int ret = 0;
  2257. char *widget_name = NULL;
  2258. char *w_name = NULL;
  2259. char *path_num_char = NULL;
  2260. char *path_name = NULL;
  2261. widget_name = kstrndup(wname, 9, GFP_KERNEL);
  2262. if (!widget_name)
  2263. return -EINVAL;
  2264. w_name = widget_name;
  2265. path_name = strsep(&widget_name, " ");
  2266. if (!path_name) {
  2267. pr_err("%s: Invalid widget name = %s\n",
  2268. __func__, widget_name);
  2269. ret = -EINVAL;
  2270. goto err;
  2271. }
  2272. path_num_char = strpbrk(path_name, "0123");
  2273. if (!path_num_char) {
  2274. pr_err("%s: tx path index not found\n",
  2275. __func__);
  2276. ret = -EINVAL;
  2277. goto err;
  2278. }
  2279. ret = kstrtouint(path_num_char, 10, path_num);
  2280. if (ret < 0)
  2281. pr_err("%s: Invalid tx path = %s\n",
  2282. __func__, w_name);
  2283. err:
  2284. kfree(w_name);
  2285. return ret;
  2286. }
  2287. static int wcd9378_tx_mode_get(struct snd_kcontrol *kcontrol,
  2288. struct snd_ctl_elem_value *ucontrol)
  2289. {
  2290. struct snd_soc_component *component =
  2291. snd_soc_kcontrol_component(kcontrol);
  2292. struct wcd9378_priv *wcd9378 = NULL;
  2293. int ret = 0;
  2294. unsigned int path = 0;
  2295. if (!component)
  2296. return -EINVAL;
  2297. wcd9378 = snd_soc_component_get_drvdata(component);
  2298. if (!wcd9378)
  2299. return -EINVAL;
  2300. ret = wcd9378_tx_path_get(kcontrol->id.name, &path);
  2301. if (ret < 0)
  2302. return ret;
  2303. ucontrol->value.integer.value[0] = wcd9378->tx_mode[path];
  2304. return 0;
  2305. }
  2306. static int wcd9378_tx_mode_put(struct snd_kcontrol *kcontrol,
  2307. struct snd_ctl_elem_value *ucontrol)
  2308. {
  2309. struct snd_soc_component *component =
  2310. snd_soc_kcontrol_component(kcontrol);
  2311. struct wcd9378_priv *wcd9378 = NULL;
  2312. u32 mode_val;
  2313. unsigned int path = 0;
  2314. int ret = 0;
  2315. if (!component)
  2316. return -EINVAL;
  2317. wcd9378 = snd_soc_component_get_drvdata(component);
  2318. if (!wcd9378)
  2319. return -EINVAL;
  2320. ret = wcd9378_tx_path_get(kcontrol->id.name, &path);
  2321. if (ret)
  2322. return ret;
  2323. mode_val = ucontrol->value.enumerated.item[0];
  2324. dev_dbg(component->dev, "%s: mode: %d\n", __func__, mode_val);
  2325. wcd9378->tx_mode[path] = mode_val;
  2326. return 0;
  2327. }
  2328. static int wcd9378_loopback_mode_get(struct snd_kcontrol *kcontrol,
  2329. struct snd_ctl_elem_value *ucontrol)
  2330. {
  2331. struct snd_soc_component *component =
  2332. snd_soc_kcontrol_component(kcontrol);
  2333. u32 loopback_mode = 0;
  2334. if (!component)
  2335. return -EINVAL;
  2336. loopback_mode = (snd_soc_component_read(component, WCD9378_LOOP_BACK_MODE) &
  2337. WCD9378_LOOP_BACK_MODE_LOOPBACK_MODE_MASK);
  2338. ucontrol->value.integer.value[0] = loopback_mode;
  2339. return 0;
  2340. }
  2341. static int wcd9378_loopback_mode_put(struct snd_kcontrol *kcontrol,
  2342. struct snd_ctl_elem_value *ucontrol)
  2343. {
  2344. struct snd_soc_component *component =
  2345. snd_soc_kcontrol_component(kcontrol);
  2346. u32 loopback_mode = 0;
  2347. if (!component)
  2348. return -EINVAL;
  2349. loopback_mode = ucontrol->value.enumerated.item[0];
  2350. snd_soc_component_update_bits(component,
  2351. WCD9378_LOOP_BACK_MODE,
  2352. WCD9378_LOOP_BACK_MODE_LOOPBACK_MODE_MASK,
  2353. loopback_mode);
  2354. dev_dbg(component->dev, "%s: loopback_mode: %d\n",
  2355. __func__, loopback_mode);
  2356. return 0;
  2357. }
  2358. static int wcd9378_aux_dsm_get(struct snd_kcontrol *kcontrol,
  2359. struct snd_ctl_elem_value *ucontrol)
  2360. {
  2361. struct snd_soc_component *component =
  2362. snd_soc_kcontrol_component(kcontrol);
  2363. u32 aux_dsm_in = 0;
  2364. if (!component)
  2365. return -EINVAL;
  2366. aux_dsm_in = (snd_soc_component_read(component, WCD9378_LB_IN_SEL_CTL) &
  2367. WCD9378_LB_IN_SEL_CTL_AUX_LB_IN_SEL_MASK);
  2368. ucontrol->value.integer.value[0] = aux_dsm_in;
  2369. return 0;
  2370. }
  2371. static int wcd9378_aux_dsm_put(struct snd_kcontrol *kcontrol,
  2372. struct snd_ctl_elem_value *ucontrol)
  2373. {
  2374. struct snd_soc_component *component =
  2375. snd_soc_kcontrol_component(kcontrol);
  2376. u32 aux_dsm_in = 0;
  2377. if (!component)
  2378. return -EINVAL;
  2379. aux_dsm_in = ucontrol->value.enumerated.item[0];
  2380. snd_soc_component_update_bits(component,
  2381. WCD9378_LB_IN_SEL_CTL,
  2382. WCD9378_LB_IN_SEL_CTL_AUX_LB_IN_SEL_MASK,
  2383. aux_dsm_in);
  2384. dev_dbg(component->dev, "%s: aux_dsm input: %d\n",
  2385. __func__, aux_dsm_in);
  2386. return 0;
  2387. }
  2388. static int wcd9378_hph_dsm_get(struct snd_kcontrol *kcontrol,
  2389. struct snd_ctl_elem_value *ucontrol)
  2390. {
  2391. struct snd_soc_component *component =
  2392. snd_soc_kcontrol_component(kcontrol);
  2393. u32 hph_dsm_in = 0;
  2394. if (!component)
  2395. return -EINVAL;
  2396. hph_dsm_in = (snd_soc_component_read(component, WCD9378_LB_IN_SEL_CTL) &
  2397. WCD9378_LB_IN_SEL_CTL_HPH_LB_IN_SEL_MASK);
  2398. ucontrol->value.integer.value[0] = hph_dsm_in;
  2399. return 0;
  2400. }
  2401. static int wcd9378_hph_dsm_put(struct snd_kcontrol *kcontrol,
  2402. struct snd_ctl_elem_value *ucontrol)
  2403. {
  2404. struct snd_soc_component *component =
  2405. snd_soc_kcontrol_component(kcontrol);
  2406. u32 hph_dsm_in = 0;
  2407. if (!component)
  2408. return -EINVAL;
  2409. hph_dsm_in = ucontrol->value.enumerated.item[0];
  2410. snd_soc_component_update_bits(component,
  2411. WCD9378_LB_IN_SEL_CTL,
  2412. WCD9378_LB_IN_SEL_CTL_HPH_LB_IN_SEL_MASK,
  2413. hph_dsm_in);
  2414. dev_dbg(component->dev, "%s: hph_dsm input: %d\n",
  2415. __func__, hph_dsm_in);
  2416. return 0;
  2417. }
  2418. static int wcd9378_hph_put_gain(struct snd_kcontrol *kcontrol,
  2419. struct snd_ctl_elem_value *ucontrol)
  2420. {
  2421. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  2422. struct wcd9378_priv *wcd9378 = snd_soc_component_get_drvdata(component);
  2423. u16 offset = ucontrol->value.enumerated.item[0];
  2424. u32 temp = 0;
  2425. temp = 0x00 - offset * 0x180;
  2426. wcd9378->hph_gain = (u16)(temp & 0xffff);
  2427. dev_dbg(component->dev, "%s: hph gain is 0x%0x\n", __func__, wcd9378->hph_gain);
  2428. return 0;
  2429. }
  2430. static int wcd9378_hph_get_gain(struct snd_kcontrol *kcontrol,
  2431. struct snd_ctl_elem_value *ucontrol)
  2432. {
  2433. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  2434. struct wcd9378_priv *wcd9378 = snd_soc_component_get_drvdata(component);
  2435. u32 temp = 0;
  2436. u16 offset = 0;
  2437. temp = 0 - wcd9378->hph_gain;
  2438. offset = (u16)(temp & 0xffff);
  2439. offset /= 0x180;
  2440. ucontrol->value.enumerated.item[0] = offset;
  2441. dev_dbg(component->dev, "%s: offset is 0x%0x\n", __func__, offset);
  2442. return 0;
  2443. }
  2444. static int wcd9378_ear_pa_gain_get(struct snd_kcontrol *kcontrol,
  2445. struct snd_ctl_elem_value *ucontrol)
  2446. {
  2447. struct snd_soc_component *component =
  2448. snd_soc_kcontrol_component(kcontrol);
  2449. int ear_gain = 0;
  2450. if (component == NULL)
  2451. return -EINVAL;
  2452. ear_gain =
  2453. snd_soc_component_read(component, WCD9378_ANA_EAR_COMPANDER_CTL) &
  2454. WCD9378_ANA_EAR_COMPANDER_CTL_EAR_GAIN_MASK;
  2455. ucontrol->value.enumerated.item[0] = ear_gain;
  2456. dev_dbg(component->dev, "%s: get ear_gain val: 0x%x\n",
  2457. __func__, ear_gain);
  2458. return 0;
  2459. }
  2460. static int wcd9378_ear_pa_gain_put(struct snd_kcontrol *kcontrol,
  2461. struct snd_ctl_elem_value *ucontrol)
  2462. {
  2463. struct snd_soc_component *component =
  2464. snd_soc_kcontrol_component(kcontrol);
  2465. int ear_gain = 0;
  2466. if (component == NULL)
  2467. return -EINVAL;
  2468. if (ucontrol->value.integer.value[0] < 0 ||
  2469. ucontrol->value.integer.value[0] > 0x10) {
  2470. dev_err(component->dev, "%s: Unsupported gain val %ld\n",
  2471. __func__, ucontrol->value.integer.value[0]);
  2472. return -EINVAL;
  2473. }
  2474. ear_gain = ucontrol->value.integer.value[0];
  2475. snd_soc_component_update_bits(component, WCD9378_ANA_EAR_COMPANDER_CTL,
  2476. WCD9378_ANA_EAR_COMPANDER_CTL_EAR_GAIN_MASK,
  2477. ear_gain);
  2478. dev_dbg(component->dev, "%s: set ear_gain val: 0x%x\n",
  2479. __func__, ear_gain);
  2480. return 0;
  2481. }
  2482. static int wcd9378_aux_pa_gain_get(struct snd_kcontrol *kcontrol,
  2483. struct snd_ctl_elem_value *ucontrol)
  2484. {
  2485. struct snd_soc_component *component =
  2486. snd_soc_kcontrol_component(kcontrol);
  2487. int aux_gain = 0;
  2488. if (component == NULL)
  2489. return -EINVAL;
  2490. aux_gain = snd_soc_component_read(component, WCD9378_AUX_INT_MISC) &
  2491. WCD9378_AUX_INT_MISC_PA_GAIN_MASK;
  2492. ucontrol->value.enumerated.item[0] = aux_gain;
  2493. dev_dbg(component->dev, "%s: get aux_gain val: 0x%x\n",
  2494. __func__, aux_gain);
  2495. return 0;
  2496. }
  2497. static int wcd9378_aux_pa_gain_put(struct snd_kcontrol *kcontrol,
  2498. struct snd_ctl_elem_value *ucontrol)
  2499. {
  2500. struct snd_soc_component *component =
  2501. snd_soc_kcontrol_component(kcontrol);
  2502. int aux_gain = 0;
  2503. if (component == NULL)
  2504. return -EINVAL;
  2505. if (ucontrol->value.integer.value[0] < 0 ||
  2506. ucontrol->value.integer.value[0] > 0x8) {
  2507. dev_err(component->dev, "%s: Unsupported gain val %ld\n",
  2508. __func__, ucontrol->value.integer.value[0]);
  2509. return -EINVAL;
  2510. }
  2511. aux_gain = ucontrol->value.integer.value[0];
  2512. snd_soc_component_update_bits(component, WCD9378_AUX_INT_MISC,
  2513. WCD9378_AUX_INT_MISC_PA_GAIN_MASK,
  2514. aux_gain);
  2515. dev_dbg(component->dev, "%s: set aux_gain val: 0x%x\n",
  2516. __func__, aux_gain);
  2517. return 0;
  2518. }
  2519. static int wcd9378_rx2_mode_put(struct snd_kcontrol *kcontrol,
  2520. struct snd_ctl_elem_value *ucontrol)
  2521. {
  2522. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  2523. struct wcd9378_priv *wcd9378 =
  2524. snd_soc_component_get_drvdata(component);
  2525. if (ucontrol->value.enumerated.item[0])
  2526. wcd9378->rx2_clk_mode = RX2_NORMAL_MODE;
  2527. else
  2528. wcd9378->rx2_clk_mode = RX2_HP_MODE;
  2529. return 1;
  2530. }
  2531. static int wcd9378_rx_hph_mode_get(struct snd_kcontrol *kcontrol,
  2532. struct snd_ctl_elem_value *ucontrol)
  2533. {
  2534. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  2535. struct wcd9378_priv *wcd9378 = snd_soc_component_get_drvdata(component);
  2536. ucontrol->value.enumerated.item[0] = wcd9378->hph_mode;
  2537. return 0;
  2538. }
  2539. static int wcd9378_rx_hph_mode_put(struct snd_kcontrol *kcontrol,
  2540. struct snd_ctl_elem_value *ucontrol)
  2541. {
  2542. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  2543. struct wcd9378_priv *wcd9378 = snd_soc_component_get_drvdata(component);
  2544. if (wcd9378->hph_mode == ucontrol->value.enumerated.item[0])
  2545. return 0;
  2546. wcd9378->hph_mode = ucontrol->value.enumerated.item[0];
  2547. return 1;
  2548. }
  2549. /* wcd9378_codec_get_dev_num - returns swr device number
  2550. * @component: Codec instance
  2551. *
  2552. * Return: swr device number on success or negative error
  2553. * code on failure.
  2554. */
  2555. int wcd9378_codec_get_dev_num(struct snd_soc_component *component)
  2556. {
  2557. struct wcd9378_priv *wcd9378;
  2558. if (!component)
  2559. return -EINVAL;
  2560. wcd9378 = snd_soc_component_get_drvdata(component);
  2561. if (!wcd9378 || !wcd9378->rx_swr_dev) {
  2562. pr_err("%s: wcd9378 component is NULL\n", __func__);
  2563. return -EINVAL;
  2564. }
  2565. return wcd9378->rx_swr_dev->dev_num;
  2566. }
  2567. EXPORT_SYMBOL_GPL(wcd9378_codec_get_dev_num);
  2568. static int wcd9378_get_compander(struct snd_kcontrol *kcontrol,
  2569. struct snd_ctl_elem_value *ucontrol)
  2570. {
  2571. struct snd_soc_component *component =
  2572. snd_soc_kcontrol_component(kcontrol);
  2573. struct wcd9378_priv *wcd9378 = snd_soc_component_get_drvdata(component);
  2574. bool hphr;
  2575. struct soc_multi_mixer_control *mc;
  2576. mc = (struct soc_multi_mixer_control *)(kcontrol->private_value);
  2577. hphr = mc->shift;
  2578. ucontrol->value.integer.value[0] = hphr ? wcd9378->comp2_enable :
  2579. wcd9378->comp1_enable;
  2580. return 0;
  2581. }
  2582. static int wcd9378_set_compander(struct snd_kcontrol *kcontrol,
  2583. struct snd_ctl_elem_value *ucontrol)
  2584. {
  2585. struct snd_soc_component *component =
  2586. snd_soc_kcontrol_component(kcontrol);
  2587. struct wcd9378_priv *wcd9378 =
  2588. snd_soc_component_get_drvdata(component);
  2589. int value = ucontrol->value.integer.value[0];
  2590. bool hphr;
  2591. struct soc_multi_mixer_control *mc;
  2592. mc = (struct soc_multi_mixer_control *)(kcontrol->private_value);
  2593. hphr = mc->shift;
  2594. if (hphr)
  2595. wcd9378->comp2_enable = value;
  2596. else
  2597. wcd9378->comp1_enable = value;
  2598. dev_dbg(component->dev, "%s: set compander: %d\n", __func__, value);
  2599. return 0;
  2600. }
  2601. static int wcd9378_codec_enable_vdd_buck(struct snd_soc_dapm_widget *w,
  2602. struct snd_kcontrol *kcontrol,
  2603. int event)
  2604. {
  2605. struct snd_soc_component *component =
  2606. snd_soc_dapm_to_component(w->dapm);
  2607. struct wcd9378_priv *wcd9378 = snd_soc_component_get_drvdata(component);
  2608. struct wcd9378_pdata *pdata = NULL;
  2609. int ret = 0;
  2610. pdata = dev_get_platdata(wcd9378->dev);
  2611. if (!pdata) {
  2612. dev_err(component->dev, "%s: pdata is NULL\n", __func__);
  2613. return -EINVAL;
  2614. }
  2615. if (!msm_cdc_is_ondemand_supply(wcd9378->dev,
  2616. wcd9378->supplies,
  2617. pdata->regulator,
  2618. pdata->num_supplies,
  2619. "cdc-vdd-buck"))
  2620. return 0;
  2621. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  2622. w->name, event);
  2623. switch (event) {
  2624. case SND_SOC_DAPM_PRE_PMU:
  2625. if (test_bit(ALLOW_BUCK_DISABLE, &wcd9378->status_mask)) {
  2626. dev_dbg(component->dev,
  2627. "%s: buck already in enabled state\n",
  2628. __func__);
  2629. clear_bit(ALLOW_BUCK_DISABLE, &wcd9378->status_mask);
  2630. return 0;
  2631. }
  2632. ret = msm_cdc_enable_ondemand_supply(wcd9378->dev,
  2633. wcd9378->supplies,
  2634. pdata->regulator,
  2635. pdata->num_supplies,
  2636. "cdc-vdd-buck");
  2637. if (ret == -EINVAL) {
  2638. dev_err(component->dev, "%s: vdd buck is not enabled\n",
  2639. __func__);
  2640. return ret;
  2641. }
  2642. clear_bit(ALLOW_BUCK_DISABLE, &wcd9378->status_mask);
  2643. /*
  2644. * 200us sleep is required after LDO is enabled as per
  2645. * HW requirement
  2646. */
  2647. usleep_range(200, 250);
  2648. break;
  2649. case SND_SOC_DAPM_POST_PMD:
  2650. set_bit(ALLOW_BUCK_DISABLE, &wcd9378->status_mask);
  2651. break;
  2652. }
  2653. return 0;
  2654. }
  2655. static void wcd9378_tx_get_slave_ch_type_idx(const char *wname, int *ch_idx)
  2656. {
  2657. u8 ch_type = 0;
  2658. if (strnstr(wname, "ADC1", sizeof("ADC1")))
  2659. ch_type = ADC1;
  2660. else if (strnstr(wname, "ADC2", sizeof("ADC2")))
  2661. ch_type = ADC2;
  2662. else if (strnstr(wname, "ADC3", sizeof("ADC3")))
  2663. ch_type = ADC3;
  2664. else if (strnstr(wname, "ADC4", sizeof("ADC4")))
  2665. ch_type = ADC4;
  2666. else if (strnstr(wname, "DMIC0", sizeof("DMIC0")))
  2667. ch_type = DMIC0;
  2668. else if (strnstr(wname, "DMIC1", sizeof("DMIC1")))
  2669. ch_type = DMIC1;
  2670. else if (strnstr(wname, "MBHC", sizeof("MBHC")))
  2671. ch_type = MBHC;
  2672. else if (strnstr(wname, "DMIC2", sizeof("DMIC2")))
  2673. ch_type = DMIC2;
  2674. else if (strnstr(wname, "DMIC3", sizeof("DMIC3")))
  2675. ch_type = DMIC3;
  2676. else if (strnstr(wname, "DMIC4", sizeof("DMIC4")))
  2677. ch_type = DMIC4;
  2678. else if (strnstr(wname, "DMIC5", sizeof("DMIC5")))
  2679. ch_type = DMIC5;
  2680. else
  2681. pr_err("%s: port name: %s is not listed\n", __func__, wname);
  2682. if (ch_type)
  2683. *ch_idx = wcd9378_slave_get_slave_ch_val(ch_type);
  2684. else
  2685. *ch_idx = -EINVAL;
  2686. }
  2687. static int wcd9378_tx_master_ch_get(struct snd_kcontrol *kcontrol,
  2688. struct snd_ctl_elem_value *ucontrol)
  2689. {
  2690. struct snd_soc_component *component =
  2691. snd_soc_kcontrol_component(kcontrol);
  2692. struct wcd9378_priv *wcd9378 = NULL;
  2693. int slave_ch_idx = -EINVAL;
  2694. if (component == NULL)
  2695. return -EINVAL;
  2696. wcd9378 = snd_soc_component_get_drvdata(component);
  2697. if (wcd9378 == NULL)
  2698. return -EINVAL;
  2699. wcd9378_tx_get_slave_ch_type_idx(kcontrol->id.name, &slave_ch_idx);
  2700. if (slave_ch_idx < 0 || slave_ch_idx >= WCD9378_MAX_SLAVE_CH_TYPES)
  2701. return -EINVAL;
  2702. ucontrol->value.integer.value[0] = wcd9378_slave_get_master_ch_val(
  2703. wcd9378->tx_master_ch_map[slave_ch_idx]);
  2704. return 0;
  2705. }
  2706. static int wcd9378_tx_master_ch_put(struct snd_kcontrol *kcontrol,
  2707. struct snd_ctl_elem_value *ucontrol)
  2708. {
  2709. struct snd_soc_component *component =
  2710. snd_soc_kcontrol_component(kcontrol);
  2711. struct wcd9378_priv *wcd9378 = NULL;
  2712. int slave_ch_idx = -EINVAL, idx = 0;
  2713. if (component == NULL)
  2714. return -EINVAL;
  2715. wcd9378 = snd_soc_component_get_drvdata(component);
  2716. if (wcd9378 == NULL)
  2717. return -EINVAL;
  2718. wcd9378_tx_get_slave_ch_type_idx(kcontrol->id.name, &slave_ch_idx);
  2719. if (slave_ch_idx < 0 || slave_ch_idx >= WCD9378_MAX_SLAVE_CH_TYPES)
  2720. return -EINVAL;
  2721. dev_dbg(component->dev, "%s: slave_ch_idx: %d", __func__, slave_ch_idx);
  2722. dev_dbg(component->dev, "%s: ucontrol->value.enumerated.item[0] = %ld\n",
  2723. __func__, ucontrol->value.enumerated.item[0]);
  2724. idx = ucontrol->value.enumerated.item[0];
  2725. if (idx < 0 || idx >= ARRAY_SIZE(wcd9378_swr_master_ch_map))
  2726. return -EINVAL;
  2727. wcd9378->tx_master_ch_map[slave_ch_idx] = wcd9378_slave_get_master_ch(idx);
  2728. return 0;
  2729. }
  2730. static int wcd9378_bcs_get(struct snd_kcontrol *kcontrol,
  2731. struct snd_ctl_elem_value *ucontrol)
  2732. {
  2733. struct snd_soc_component *component =
  2734. snd_soc_kcontrol_component(kcontrol);
  2735. struct wcd9378_priv *wcd9378 = snd_soc_component_get_drvdata(component);
  2736. ucontrol->value.integer.value[0] = wcd9378->bcs_dis;
  2737. return 0;
  2738. }
  2739. static int wcd9378_bcs_put(struct snd_kcontrol *kcontrol,
  2740. struct snd_ctl_elem_value *ucontrol)
  2741. {
  2742. struct snd_soc_component *component =
  2743. snd_soc_kcontrol_component(kcontrol);
  2744. struct wcd9378_priv *wcd9378 = snd_soc_component_get_drvdata(component);
  2745. wcd9378->bcs_dis = ucontrol->value.integer.value[0];
  2746. return 0;
  2747. }
  2748. static const char * const loopback_mode_text[] = {
  2749. "NO_LP", "SWR_LP1", "SWR_LP2", "SWR_LP3",
  2750. };
  2751. static const struct soc_enum loopback_mode_enum =
  2752. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(loopback_mode_text),
  2753. loopback_mode_text);
  2754. static const char * const aux_dsm_text[] = {
  2755. "TX2->AUX", "TX3->AUX", "TX0->AUX", "TX1->AUX",
  2756. };
  2757. static const struct soc_enum aux_dsm_enum =
  2758. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(aux_dsm_text),
  2759. aux_dsm_text);
  2760. static const char * const hph_dsm_text[] = {
  2761. "HPH_DSM_IN0", "HPH_DSM_IN1", "HPH_DSM_IN2", "HPH_DSM_IN3",
  2762. };
  2763. static const struct soc_enum hph_dsm_enum =
  2764. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(hph_dsm_text),
  2765. hph_dsm_text);
  2766. static const char * const tx_mode_mux_text[] = {
  2767. "ADC_INVALID", "ADC_HIFI", "ADC_NORMAL", "ADC_LP",
  2768. };
  2769. static const struct soc_enum tx_mode_mux_enum =
  2770. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(tx_mode_mux_text),
  2771. tx_mode_mux_text);
  2772. static const char * const rx2_mode_text[] = {
  2773. "HP", "NORMAL",
  2774. };
  2775. static const struct soc_enum rx2_mode_enum =
  2776. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(rx2_mode_text),
  2777. rx2_mode_text);
  2778. static const char * const rx_hph_mode_mux_text[] = {
  2779. "CLS_H_INVALID", "CLS_H_HIFI", "CLS_H_LP", "CLS_AB", "CLS_H_LOHIFI",
  2780. "CLS_H_ULP", "CLS_AB_HIFI", "CLS_AB_LP", "CLS_AB_LOHIFI",
  2781. };
  2782. static const struct soc_enum rx_hph_mode_mux_enum =
  2783. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(rx_hph_mode_mux_text),
  2784. rx_hph_mode_mux_text);
  2785. static const char * const ear_pa_gain_text[] = {
  2786. "GAIN_6DB", "GAIN_4P5DB", "GAIN_3DB", "GAIN_1P5DB", "GAIN_0DB",
  2787. "GAIN_M1P5DB", "GAIN_M3DB", "GAIN_M4P5DB", "GAIN_M6DB",
  2788. "GAIN_M7P5DB", "GAIN_M9DB", "GAIN_M10P5DB", "GAIN_M12DB",
  2789. "GAIN_M13P5DB", "GAIN_M15DB", "GAIN_M16P5DB", "GAIN_M18DB",
  2790. };
  2791. static const struct soc_enum ear_pa_gain_enum =
  2792. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(ear_pa_gain_text),
  2793. ear_pa_gain_text);
  2794. static const char * const aux_pa_gain_text[] = {
  2795. "GAIN_6DB", "GAIN_4P5DB", "GAIN_3DB", "GAIN_1P5DB", "GAIN_0DB",
  2796. "GAIN_M1P5DB", "GAIN_M3DB", "GAIN_M4P5DB", "GAIN_M6DB",
  2797. };
  2798. static const struct soc_enum aux_pa_gain_enum =
  2799. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(aux_pa_gain_text),
  2800. aux_pa_gain_text);
  2801. const char * const tx_master_ch_text[] = {
  2802. "ZERO", "SWRM_TX1_CH1", "SWRM_TX1_CH2", "SWRM_TX1_CH3", "SWRM_TX1_CH4",
  2803. "SWRM_TX2_CH1", "SWRM_TX2_CH2", "SWRM_TX2_CH3", "SWRM_TX2_CH4",
  2804. "SWRM_TX3_CH1", "SWRM_TX3_CH2", "SWRM_TX3_CH3", "SWRM_TX3_CH4",
  2805. "SWRM_PCM_IN",
  2806. };
  2807. const struct soc_enum tx_master_ch_enum =
  2808. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(tx_master_ch_text),
  2809. tx_master_ch_text);
  2810. static const struct snd_kcontrol_new wcd9378_snd_controls[] = {
  2811. SOC_SINGLE_EXT("HPHL_COMP Switch", SND_SOC_NOPM, 0, 1, 0,
  2812. wcd9378_get_compander, wcd9378_set_compander),
  2813. SOC_SINGLE_EXT("HPHR_COMP Switch", SND_SOC_NOPM, 1, 1, 0,
  2814. wcd9378_get_compander, wcd9378_set_compander),
  2815. SOC_SINGLE_EXT("ADC2_BCS Disable", SND_SOC_NOPM, 0, 1, 0,
  2816. wcd9378_bcs_get, wcd9378_bcs_put),
  2817. SOC_ENUM_EXT("LOOPBACK Mode", loopback_mode_enum,
  2818. wcd9378_loopback_mode_get, wcd9378_loopback_mode_put),
  2819. SOC_ENUM_EXT("AUX_LB_IN SEL", aux_dsm_enum,
  2820. wcd9378_aux_dsm_get, wcd9378_aux_dsm_put),
  2821. SOC_ENUM_EXT("HPH_LB_IN SEL", hph_dsm_enum,
  2822. wcd9378_hph_dsm_get, wcd9378_hph_dsm_put),
  2823. SOC_ENUM_EXT("TX0 MODE", tx_mode_mux_enum,
  2824. wcd9378_tx_mode_get, wcd9378_tx_mode_put),
  2825. SOC_ENUM_EXT("TX1 MODE", tx_mode_mux_enum,
  2826. wcd9378_tx_mode_get, wcd9378_tx_mode_put),
  2827. SOC_ENUM_EXT("TX2 MODE", tx_mode_mux_enum,
  2828. wcd9378_tx_mode_get, wcd9378_tx_mode_put),
  2829. SOC_ENUM_EXT("RX2 Mode", rx2_mode_enum,
  2830. NULL, wcd9378_rx2_mode_put),
  2831. SOC_ENUM_EXT("RX HPH Mode", rx_hph_mode_mux_enum,
  2832. wcd9378_rx_hph_mode_get, wcd9378_rx_hph_mode_put),
  2833. SOC_SINGLE_EXT("HPH Volume", SND_SOC_NOPM, 0, 0x14, 0,
  2834. wcd9378_hph_get_gain, wcd9378_hph_put_gain),
  2835. SOC_ENUM_EXT("EAR_PA Gain", ear_pa_gain_enum,
  2836. wcd9378_ear_pa_gain_get, wcd9378_ear_pa_gain_put),
  2837. SOC_ENUM_EXT("AUX_PA Gain", aux_pa_gain_enum,
  2838. wcd9378_aux_pa_gain_get, wcd9378_aux_pa_gain_put),
  2839. SOC_SINGLE_TLV("ADC1 Volume", WCD9378_ANA_TX_CH1, 0, 20, 0,
  2840. analog_gain),
  2841. SOC_SINGLE_TLV("ADC2 Volume", WCD9378_ANA_TX_CH2, 0, 20, 0,
  2842. analog_gain),
  2843. SOC_SINGLE_TLV("ADC3 Volume", WCD9378_ANA_TX_CH3, 0, 20, 0,
  2844. analog_gain),
  2845. SOC_ENUM_EXT("ADC1 ChMap", tx_master_ch_enum,
  2846. wcd9378_tx_master_ch_get, wcd9378_tx_master_ch_put),
  2847. SOC_ENUM_EXT("ADC2 ChMap", tx_master_ch_enum,
  2848. wcd9378_tx_master_ch_get, wcd9378_tx_master_ch_put),
  2849. SOC_ENUM_EXT("ADC3 ChMap", tx_master_ch_enum,
  2850. wcd9378_tx_master_ch_get, wcd9378_tx_master_ch_put),
  2851. SOC_ENUM_EXT("DMIC0 ChMap", tx_master_ch_enum,
  2852. wcd9378_tx_master_ch_get, wcd9378_tx_master_ch_put),
  2853. SOC_ENUM_EXT("DMIC1 ChMap", tx_master_ch_enum,
  2854. wcd9378_tx_master_ch_get, wcd9378_tx_master_ch_put),
  2855. SOC_ENUM_EXT("MBHC ChMap", tx_master_ch_enum,
  2856. wcd9378_tx_master_ch_get, wcd9378_tx_master_ch_put),
  2857. SOC_ENUM_EXT("DMIC2 ChMap", tx_master_ch_enum,
  2858. wcd9378_tx_master_ch_get, wcd9378_tx_master_ch_put),
  2859. SOC_ENUM_EXT("DMIC3 ChMap", tx_master_ch_enum,
  2860. wcd9378_tx_master_ch_get, wcd9378_tx_master_ch_put),
  2861. SOC_ENUM_EXT("DMIC4 ChMap", tx_master_ch_enum,
  2862. wcd9378_tx_master_ch_get, wcd9378_tx_master_ch_put),
  2863. SOC_ENUM_EXT("DMIC5 ChMap", tx_master_ch_enum,
  2864. wcd9378_tx_master_ch_get, wcd9378_tx_master_ch_put),
  2865. };
  2866. static const struct snd_kcontrol_new amic1_switch[] = {
  2867. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2868. };
  2869. static const struct snd_kcontrol_new amic2_switch[] = {
  2870. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2871. };
  2872. static const struct snd_kcontrol_new amic3_switch[] = {
  2873. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2874. };
  2875. static const struct snd_kcontrol_new amic4_switch[] = {
  2876. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2877. };
  2878. static const struct snd_kcontrol_new va_amic1_switch[] = {
  2879. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2880. };
  2881. static const struct snd_kcontrol_new va_amic2_switch[] = {
  2882. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2883. };
  2884. static const struct snd_kcontrol_new va_amic3_switch[] = {
  2885. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2886. };
  2887. static const struct snd_kcontrol_new va_amic4_switch[] = {
  2888. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2889. };
  2890. static const struct snd_kcontrol_new dmic1_switch[] = {
  2891. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2892. };
  2893. static const struct snd_kcontrol_new dmic2_switch[] = {
  2894. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2895. };
  2896. static const struct snd_kcontrol_new dmic3_switch[] = {
  2897. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2898. };
  2899. static const struct snd_kcontrol_new dmic4_switch[] = {
  2900. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2901. };
  2902. static const struct snd_kcontrol_new dmic5_switch[] = {
  2903. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2904. };
  2905. static const struct snd_kcontrol_new dmic6_switch[] = {
  2906. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2907. };
  2908. static const char * const adc1_mux_text[] = {
  2909. "CH1_AMIC_DISABLE", "CH1_AMIC1", "CH1_AMIC2", "CH1_AMIC3", "CH1_AMIC4"
  2910. };
  2911. static const char * const adc2_mux_text[] = {
  2912. "CH2_AMIC_DISABLE", "CH2_AMIC1", "CH2_AMIC2", "CH2_AMIC3", "CH2_AMIC4"
  2913. };
  2914. static const char * const adc3_mux_text[] = {
  2915. "CH3_AMIC_DISABLE", "CH3_AMIC1", "CH3_AMIC3", "CH3_AMIC4"
  2916. };
  2917. static const char * const ear_mux_text[] = {
  2918. "RX0", "RX2"
  2919. };
  2920. static const char * const aux_mux_text[] = {
  2921. "RX1", "RX2"
  2922. };
  2923. static const struct soc_enum adc1_enum =
  2924. SOC_ENUM_SINGLE(WCD9378_TX_NEW_TX_CH12_MUX,
  2925. WCD9378_TX_NEW_TX_CH12_MUX_CH1_SEL_SHIFT,
  2926. ARRAY_SIZE(adc1_mux_text), adc1_mux_text);
  2927. static const struct soc_enum adc2_enum =
  2928. SOC_ENUM_SINGLE(WCD9378_TX_NEW_TX_CH12_MUX,
  2929. WCD9378_TX_NEW_TX_CH12_MUX_CH2_SEL_SHIFT,
  2930. ARRAY_SIZE(adc2_mux_text), adc2_mux_text);
  2931. static const struct soc_enum adc3_enum =
  2932. SOC_ENUM_SINGLE(WCD9378_TX_NEW_TX_CH34_MUX,
  2933. WCD9378_TX_NEW_TX_CH34_MUX_CH3_SEL_SHIFT,
  2934. ARRAY_SIZE(adc3_mux_text), adc3_mux_text);
  2935. static const struct soc_enum ear_enum =
  2936. SOC_ENUM_SINGLE(WCD9378_CDC_AUX_GAIN_CTL,
  2937. WCD9378_CDC_AUX_GAIN_CTL_AUX_EN_SHIFT,
  2938. ARRAY_SIZE(ear_mux_text), ear_mux_text);
  2939. static const struct soc_enum aux_enum =
  2940. SOC_ENUM_SINGLE(WCD9378_CDC_AUX_GAIN_CTL,
  2941. WCD9378_CDC_AUX_GAIN_CTL_AUX_EN_SHIFT,
  2942. ARRAY_SIZE(aux_mux_text), aux_mux_text);
  2943. static const struct snd_kcontrol_new tx_adc1_mux =
  2944. SOC_DAPM_ENUM("ADC1 MUX Mux", adc1_enum);
  2945. static const struct snd_kcontrol_new tx_adc2_mux =
  2946. SOC_DAPM_ENUM("ADC2 MUX Mux", adc2_enum);
  2947. static const struct snd_kcontrol_new tx_adc3_mux =
  2948. SOC_DAPM_ENUM("ADC3 MUX Mux", adc3_enum);
  2949. static const struct snd_kcontrol_new ear_mux =
  2950. SOC_DAPM_ENUM("EAR Mux", ear_enum);
  2951. static const struct snd_kcontrol_new aux_mux =
  2952. SOC_DAPM_ENUM("AUX Mux", aux_enum);
  2953. static const struct snd_kcontrol_new dac1_switch[] = {
  2954. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2955. };
  2956. static const struct snd_kcontrol_new dac2_switch[] = {
  2957. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2958. };
  2959. static const struct snd_kcontrol_new ear_mixer_switch[] = {
  2960. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2961. };
  2962. static const struct snd_kcontrol_new aux_mixer_switch[] = {
  2963. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2964. };
  2965. static const struct snd_kcontrol_new hphl_rdac_switch[] = {
  2966. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2967. };
  2968. static const struct snd_kcontrol_new hphr_rdac_switch[] = {
  2969. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2970. };
  2971. static const struct snd_kcontrol_new rx0_switch[] = {
  2972. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2973. };
  2974. static const struct snd_kcontrol_new rx1_switch[] = {
  2975. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2976. };
  2977. static const struct snd_soc_dapm_widget wcd9378_dapm_widgets[] = {
  2978. /*input widgets*/
  2979. SND_SOC_DAPM_INPUT("AMIC1"),
  2980. SND_SOC_DAPM_INPUT("AMIC2"),
  2981. SND_SOC_DAPM_INPUT("AMIC3"),
  2982. SND_SOC_DAPM_INPUT("AMIC4"),
  2983. SND_SOC_DAPM_INPUT("VA AMIC1"),
  2984. SND_SOC_DAPM_INPUT("VA AMIC2"),
  2985. SND_SOC_DAPM_INPUT("VA AMIC3"),
  2986. SND_SOC_DAPM_INPUT("VA AMIC4"),
  2987. SND_SOC_DAPM_INPUT("IN1_HPHL"),
  2988. SND_SOC_DAPM_INPUT("IN2_HPHR"),
  2989. SND_SOC_DAPM_INPUT("IN3_AUX"),
  2990. /*tx widgets*/
  2991. SND_SOC_DAPM_MIXER_E("TX0 SEQUENCER", SND_SOC_NOPM, ADC1, 0,
  2992. NULL, 0, wcd9378_tx_sequencer_enable,
  2993. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2994. SND_SOC_DAPM_MIXER_E("TX1 SEQUENCER", SND_SOC_NOPM, ADC2, 0,
  2995. NULL, 0, wcd9378_tx_sequencer_enable,
  2996. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2997. SND_SOC_DAPM_MIXER_E("TX2 SEQUENCER", SND_SOC_NOPM, ADC3, 0,
  2998. NULL, 0, wcd9378_tx_sequencer_enable,
  2999. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3000. SND_SOC_DAPM_MUX("ADC1 MUX", SND_SOC_NOPM, 0, 0,
  3001. &tx_adc1_mux),
  3002. SND_SOC_DAPM_MUX("ADC2 MUX", SND_SOC_NOPM, 0, 0,
  3003. &tx_adc2_mux),
  3004. SND_SOC_DAPM_MUX("ADC3 MUX", SND_SOC_NOPM, 0, 0,
  3005. &tx_adc3_mux),
  3006. SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0,
  3007. wcd9378_codec_enable_dmic,
  3008. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3009. SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 1, 0,
  3010. wcd9378_codec_enable_dmic,
  3011. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3012. SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 2, 0,
  3013. wcd9378_codec_enable_dmic,
  3014. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3015. SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 3, 0,
  3016. wcd9378_codec_enable_dmic,
  3017. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3018. SND_SOC_DAPM_ADC_E("DMIC5", NULL, SND_SOC_NOPM, 4, 0,
  3019. wcd9378_codec_enable_dmic,
  3020. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3021. SND_SOC_DAPM_ADC_E("DMIC6", NULL, SND_SOC_NOPM, 5, 0,
  3022. wcd9378_codec_enable_dmic,
  3023. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3024. /*rx widgets*/
  3025. SND_SOC_DAPM_DAC_E("RDAC1", NULL, SND_SOC_NOPM, 0, 0,
  3026. wcd9378_codec_hphl_dac_event,
  3027. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3028. SND_SOC_DAPM_DAC_E("RDAC2", NULL, SND_SOC_NOPM, 0, 0,
  3029. wcd9378_codec_hphr_dac_event,
  3030. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3031. SND_SOC_DAPM_MIXER_E("HPH SEQUENCER", SND_SOC_NOPM, 0, 0, NULL, 0,
  3032. wcd9378_hph_sequencer_enable,
  3033. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3034. SND_SOC_DAPM_PGA_E("HPHL PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
  3035. wcd9378_codec_enable_hphl_pa,
  3036. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3037. SND_SOC_DAPM_PGA_E("HPHR PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
  3038. wcd9378_codec_enable_hphr_pa,
  3039. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3040. SND_SOC_DAPM_MIXER_E("SA SEQUENCER", SND_SOC_NOPM, 0, 0,
  3041. NULL, 0, wcd9378_sa_sequencer_enable,
  3042. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3043. SND_SOC_DAPM_DAC_E("EAR_RDAC", NULL, SND_SOC_NOPM, 0, 0,
  3044. wcd9378_codec_ear_dac_event,
  3045. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3046. SND_SOC_DAPM_DAC_E("AUX_RDAC", NULL, SND_SOC_NOPM, 0, 0,
  3047. wcd9378_codec_aux_dac_event,
  3048. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3049. SND_SOC_DAPM_PGA_E("EAR PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
  3050. wcd9378_codec_enable_ear_pa,
  3051. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3052. SND_SOC_DAPM_PGA_E("AUX PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
  3053. wcd9378_codec_enable_aux_pa,
  3054. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3055. SND_SOC_DAPM_SUPPLY("VDD_BUCK", SND_SOC_NOPM, 0, 0,
  3056. wcd9378_codec_enable_vdd_buck,
  3057. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3058. SND_SOC_DAPM_SUPPLY_S("CLS_H_PORT", 1, SND_SOC_NOPM, 0, 0,
  3059. wcd9378_enable_clsh,
  3060. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3061. SND_SOC_DAPM_MIXER_E("AMIC1_MIXER", SND_SOC_NOPM, 0, 0,
  3062. amic1_switch, ARRAY_SIZE(amic1_switch), NULL,
  3063. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3064. SND_SOC_DAPM_MIXER_E("AMIC2_MIXER", SND_SOC_NOPM, 0, 0,
  3065. amic2_switch, ARRAY_SIZE(amic2_switch), NULL,
  3066. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3067. SND_SOC_DAPM_MIXER_E("AMIC3_MIXER", SND_SOC_NOPM, 0, 0,
  3068. amic3_switch, ARRAY_SIZE(amic3_switch), NULL,
  3069. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3070. SND_SOC_DAPM_MIXER_E("AMIC4_MIXER", SND_SOC_NOPM, 0, 0,
  3071. amic4_switch, ARRAY_SIZE(amic4_switch), NULL,
  3072. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3073. SND_SOC_DAPM_MIXER_E("VA_AMIC1_MIXER", SND_SOC_NOPM, 0, 0,
  3074. va_amic1_switch, ARRAY_SIZE(va_amic1_switch), NULL,
  3075. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3076. SND_SOC_DAPM_MIXER_E("VA_AMIC2_MIXER", SND_SOC_NOPM, 0, 0,
  3077. va_amic2_switch, ARRAY_SIZE(va_amic2_switch), NULL,
  3078. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3079. SND_SOC_DAPM_MIXER_E("VA_AMIC3_MIXER", SND_SOC_NOPM, 0, 0,
  3080. va_amic3_switch, ARRAY_SIZE(va_amic3_switch), NULL,
  3081. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3082. SND_SOC_DAPM_MIXER_E("VA_AMIC4_MIXER", SND_SOC_NOPM, 0, 0,
  3083. va_amic4_switch, ARRAY_SIZE(va_amic4_switch), NULL,
  3084. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  3085. SND_SOC_DAPM_MIXER_E("DMIC1_MIXER", SND_SOC_NOPM, DMIC1,
  3086. 0, dmic1_switch, ARRAY_SIZE(dmic1_switch),
  3087. wcd9378_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  3088. SND_SOC_DAPM_POST_PMD),
  3089. SND_SOC_DAPM_MIXER_E("DMIC2_MIXER", SND_SOC_NOPM, DMIC2,
  3090. 0, dmic2_switch, ARRAY_SIZE(dmic2_switch),
  3091. wcd9378_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  3092. SND_SOC_DAPM_POST_PMD),
  3093. SND_SOC_DAPM_MIXER_E("DMIC3_MIXER", SND_SOC_NOPM, DMIC3,
  3094. 0, dmic3_switch, ARRAY_SIZE(dmic3_switch),
  3095. wcd9378_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  3096. SND_SOC_DAPM_POST_PMD),
  3097. SND_SOC_DAPM_MIXER_E("DMIC4_MIXER", SND_SOC_NOPM, DMIC4,
  3098. 0, dmic4_switch, ARRAY_SIZE(dmic4_switch),
  3099. wcd9378_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  3100. SND_SOC_DAPM_POST_PMD),
  3101. SND_SOC_DAPM_MIXER_E("DMIC5_MIXER", SND_SOC_NOPM, DMIC5,
  3102. 0, dmic5_switch, ARRAY_SIZE(dmic5_switch),
  3103. wcd9378_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  3104. SND_SOC_DAPM_POST_PMD),
  3105. SND_SOC_DAPM_MIXER_E("DMIC6_MIXER", SND_SOC_NOPM, DMIC6,
  3106. 0, dmic6_switch, ARRAY_SIZE(dmic6_switch),
  3107. wcd9378_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  3108. SND_SOC_DAPM_POST_PMD),
  3109. /* micbias widgets*/
  3110. SND_SOC_DAPM_SUPPLY("MIC BIAS1", SND_SOC_NOPM, 0, 0,
  3111. wcd9378_codec_enable_micbias,
  3112. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  3113. SND_SOC_DAPM_POST_PMD),
  3114. SND_SOC_DAPM_SUPPLY("MIC BIAS2", SND_SOC_NOPM, 0, 0,
  3115. wcd9378_codec_enable_micbias,
  3116. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  3117. SND_SOC_DAPM_POST_PMD),
  3118. SND_SOC_DAPM_SUPPLY("MIC BIAS3", SND_SOC_NOPM, 0, 0,
  3119. wcd9378_codec_enable_micbias,
  3120. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  3121. SND_SOC_DAPM_POST_PMD),
  3122. /* micbias pull up widgets*/
  3123. SND_SOC_DAPM_SUPPLY("VA MIC BIAS1", SND_SOC_NOPM, 0, 0,
  3124. wcd9378_codec_enable_micbias_pullup,
  3125. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  3126. SND_SOC_DAPM_POST_PMD),
  3127. SND_SOC_DAPM_SUPPLY("VA MIC BIAS2", SND_SOC_NOPM, 0, 0,
  3128. wcd9378_codec_enable_micbias_pullup,
  3129. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  3130. SND_SOC_DAPM_POST_PMD),
  3131. SND_SOC_DAPM_SUPPLY("VA MIC BIAS3", SND_SOC_NOPM, 0, 0,
  3132. wcd9378_codec_enable_micbias_pullup,
  3133. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  3134. SND_SOC_DAPM_POST_PMD),
  3135. /* rx mixer widgets*/
  3136. SND_SOC_DAPM_MUX("EAR_MUX", SND_SOC_NOPM, 0, 0, &ear_mux),
  3137. SND_SOC_DAPM_MUX("AUX_MUX", SND_SOC_NOPM, 0, 0, &aux_mux),
  3138. SND_SOC_DAPM_MIXER("EAR_MIXER", SND_SOC_NOPM, 0, 0,
  3139. ear_mixer_switch, ARRAY_SIZE(ear_mixer_switch)),
  3140. SND_SOC_DAPM_MIXER("AUX_MIXER", SND_SOC_NOPM, 0, 0,
  3141. aux_mixer_switch, ARRAY_SIZE(aux_mixer_switch)),
  3142. SND_SOC_DAPM_MIXER("DAC1", SND_SOC_NOPM, 0, 0,
  3143. dac1_switch, ARRAY_SIZE(dac1_switch)),
  3144. SND_SOC_DAPM_MIXER("DAC2", SND_SOC_NOPM, 0, 0,
  3145. dac2_switch, ARRAY_SIZE(dac2_switch)),
  3146. SND_SOC_DAPM_MIXER("HPHL_RDAC", SND_SOC_NOPM, 0, 0,
  3147. hphl_rdac_switch, ARRAY_SIZE(hphl_rdac_switch)),
  3148. SND_SOC_DAPM_MIXER("HPHR_RDAC", SND_SOC_NOPM, 0, 0,
  3149. hphr_rdac_switch, ARRAY_SIZE(hphr_rdac_switch)),
  3150. /*output widgets tx*/
  3151. SND_SOC_DAPM_OUTPUT("ADC1_OUTPUT"),
  3152. SND_SOC_DAPM_OUTPUT("ADC2_OUTPUT"),
  3153. SND_SOC_DAPM_OUTPUT("ADC3_OUTPUT"),
  3154. SND_SOC_DAPM_OUTPUT("DMIC1_OUTPUT"),
  3155. SND_SOC_DAPM_OUTPUT("DMIC2_OUTPUT"),
  3156. SND_SOC_DAPM_OUTPUT("DMIC3_OUTPUT"),
  3157. SND_SOC_DAPM_OUTPUT("DMIC4_OUTPUT"),
  3158. SND_SOC_DAPM_OUTPUT("DMIC5_OUTPUT"),
  3159. SND_SOC_DAPM_OUTPUT("DMIC6_OUTPUT"),
  3160. /*output widgets rx*/
  3161. SND_SOC_DAPM_OUTPUT("EAR"),
  3162. SND_SOC_DAPM_OUTPUT("AUX"),
  3163. SND_SOC_DAPM_OUTPUT("HPHL"),
  3164. SND_SOC_DAPM_OUTPUT("HPHR"),
  3165. };
  3166. static const struct snd_soc_dapm_route wcd9378_audio_map[] = {
  3167. /*ADC-1 (channel-1)*/
  3168. {"ADC1_OUTPUT", NULL, "TX0 SEQUENCER"},
  3169. {"TX0 SEQUENCER", NULL, "ADC1 MUX"},
  3170. {"ADC1 MUX", "CH1_AMIC1", "AMIC1_MIXER"},
  3171. {"ADC1 MUX", "CH1_AMIC2", "AMIC2_MIXER"},
  3172. {"ADC1 MUX", "CH1_AMIC3", "AMIC3_MIXER"},
  3173. {"ADC1 MUX", "CH1_AMIC4", "AMIC4_MIXER"},
  3174. /*ADC-2 (channel-2)*/
  3175. {"ADC2_OUTPUT", NULL, "TX1 SEQUENCER"},
  3176. {"TX1 SEQUENCER", NULL, "ADC2 MUX"},
  3177. {"ADC2 MUX", "CH2_AMIC1", "AMIC1_MIXER"},
  3178. {"ADC2 MUX", "CH2_AMIC2", "AMIC2_MIXER"},
  3179. {"ADC2 MUX", "CH2_AMIC3", "AMIC3_MIXER"},
  3180. {"ADC2 MUX", "CH2_AMIC4", "AMIC4_MIXER"},
  3181. /*ADC-3 (channel-3)*/
  3182. {"ADC3_OUTPUT", NULL, "TX2 SEQUENCER"},
  3183. {"TX2 SEQUENCER", NULL, "ADC3 MUX"},
  3184. {"ADC3 MUX", "CH3_AMIC1", "AMIC1_MIXER"},
  3185. {"ADC3 MUX", "CH3_AMIC3", "AMIC3_MIXER"},
  3186. {"ADC3 MUX", "CH3_AMIC4", "AMIC4_MIXER"},
  3187. {"AMIC1_MIXER", "Switch", "AMIC1"},
  3188. {"AMIC1_MIXER", NULL, "VA_AMIC1_MIXER"},
  3189. {"VA_AMIC1_MIXER", "Switch", "VA AMIC1"},
  3190. {"AMIC2_MIXER", "Switch", "AMIC2"},
  3191. {"AMIC2_MIXER", NULL, "VA_AMIC2_MIXER"},
  3192. {"VA_AMIC2_MIXER", "Switch", "VA AMIC2"},
  3193. {"AMIC3_MIXER", "Switch", "AMIC3"},
  3194. {"AMIC3_MIXER", NULL, "VA_AMIC3_MIXER"},
  3195. {"VA_AMIC3_MIXER", "Switch", "VA AMIC3"},
  3196. {"AMIC4_MIXER", "Switch", "AMIC4"},
  3197. {"AMIC4_MIXER", NULL, "VA_AMIC4_MIXER"},
  3198. {"VA_AMIC4_MIXER", "Switch", "VA AMIC4"},
  3199. {"DMIC1_OUTPUT", NULL, "DMIC1_MIXER"},
  3200. {"DMIC1_MIXER", "Switch", "DMIC1"},
  3201. {"DMIC2_OUTPUT", NULL, "DMIC2_MIXER"},
  3202. {"DMIC2_MIXER", "Switch", "DMIC2"},
  3203. {"DMIC3_OUTPUT", NULL, "DMIC3_MIXER"},
  3204. {"DMIC3_MIXER", "Switch", "DMIC3"},
  3205. {"DMIC4_OUTPUT", NULL, "DMIC4_MIXER"},
  3206. {"DMIC4_MIXER", "Switch", "DMIC4"},
  3207. {"DMIC5_OUTPUT", NULL, "DMIC5_MIXER"},
  3208. {"DMIC5_MIXER", "Switch", "DMIC5"},
  3209. {"DMIC6_OUTPUT", NULL, "DMIC6_MIXER"},
  3210. {"DMIC6_MIXER", "Switch", "DMIC6"},
  3211. /*Headphone playback*/
  3212. {"IN1_HPHL", NULL, "VDD_BUCK"},
  3213. {"IN1_HPHL", NULL, "CLS_H_PORT"},
  3214. {"HPH SEQUENCER", NULL, "IN1_HPHL"},
  3215. {"RDAC1", NULL, "HPH SEQUENCER"},
  3216. {"HPHL_RDAC", "Switch", "RDAC1"},
  3217. {"HPHL PGA", NULL, "HPHL_RDAC"},
  3218. {"HPHL", NULL, "HPHL PGA"},
  3219. {"IN2_HPHR", NULL, "VDD_BUCK"},
  3220. {"IN2_HPHR", NULL, "CLS_H_PORT"},
  3221. {"HPH SEQUENCER", NULL, "IN2_HPHR"},
  3222. {"RDAC2", NULL, "HPH SEQUENCER"},
  3223. {"HPHR_RDAC", "Switch", "RDAC2"},
  3224. {"HPHR PGA", NULL, "HPHR_RDAC"},
  3225. {"HPHR", NULL, "HPHR PGA"},
  3226. /*Amplier playback*/
  3227. {"IN3_AUX", NULL, "VDD_BUCK"},
  3228. {"IN3_AUX", NULL, "CLS_H_PORT"},
  3229. {"EAR_MUX", "RX0", "IN1_HPHL"},
  3230. {"EAR_MUX", "RX2", "IN3_AUX"},
  3231. {"DAC1", "Switch", "EAR_MUX"},
  3232. {"EAR_RDAC", NULL, "DAC1"},
  3233. {"SA SEQUENCER", NULL, "EAR_RDAC"},
  3234. {"EAR_MIXER", "Switch", "SA SEQUENCER"},
  3235. {"EAR PGA", NULL, "EAR_MIXER"},
  3236. {"EAR", NULL, "EAR PGA"},
  3237. {"AUX_MUX", "RX1", "IN2_HPHR"},
  3238. {"AUX_MUX", "RX2", "IN3_AUX"},
  3239. {"DAC2", "Switch", "AUX_MUX"},
  3240. {"AUX_RDAC", NULL, "DAC2"},
  3241. {"SA SEQUENCER", NULL, "AUX_RDAC"},
  3242. {"AUX_MIXER", "Switch", "SA SEQUENCER",},
  3243. {"AUX PGA", NULL, "AUX_MIXER"},
  3244. {"AUX", NULL, "AUX PGA"},
  3245. };
  3246. static ssize_t wcd9378_version_read(struct snd_info_entry *entry,
  3247. void *file_private_data,
  3248. struct file *file,
  3249. char __user *buf, size_t count,
  3250. loff_t pos)
  3251. {
  3252. struct wcd9378_priv *priv;
  3253. char buffer[WCD9378_VERSION_ENTRY_SIZE];
  3254. int len = 0;
  3255. priv = (struct wcd9378_priv *) entry->private_data;
  3256. if (!priv) {
  3257. pr_err("%s: wcd9378 priv is null\n", __func__);
  3258. return -EINVAL;
  3259. }
  3260. switch (priv->version) {
  3261. case WCD9378_VERSION_1_0:
  3262. len = scnprintf(buffer, sizeof(buffer), "WCD9378_1_0\n");
  3263. break;
  3264. default:
  3265. len = scnprintf(buffer, sizeof(buffer), "VER_UNDEFINED\n");
  3266. }
  3267. return simple_read_from_buffer(buf, count, &pos, buffer, len);
  3268. }
  3269. static struct snd_info_entry_ops wcd9378_info_ops = {
  3270. .read = wcd9378_version_read,
  3271. };
  3272. /*
  3273. * wcd9378_info_create_codec_entry - creates wcd9378 module
  3274. * @codec_root: The parent directory
  3275. * @component: component instance
  3276. *
  3277. * Creates wcd9378 module, version entry under the given
  3278. * parent directory.
  3279. *
  3280. * Return: 0 on success or negative error code on failure.
  3281. */
  3282. int wcd9378_info_create_codec_entry(struct snd_info_entry *codec_root,
  3283. struct snd_soc_component *component)
  3284. {
  3285. struct snd_info_entry *version_entry;
  3286. struct wcd9378_priv *priv;
  3287. struct snd_soc_card *card;
  3288. if (!codec_root || !component)
  3289. return -EINVAL;
  3290. priv = snd_soc_component_get_drvdata(component);
  3291. if (priv->entry) {
  3292. dev_dbg(priv->dev,
  3293. "%s:wcd9378 module already created\n", __func__);
  3294. return 0;
  3295. }
  3296. card = component->card;
  3297. priv->entry = snd_info_create_module_entry(codec_root->module,
  3298. "wcd9378", codec_root);
  3299. if (!priv->entry) {
  3300. dev_dbg(component->dev, "%s: failed to create wcd9378 entry\n",
  3301. __func__);
  3302. return -ENOMEM;
  3303. }
  3304. priv->entry->mode = S_IFDIR | 0555;
  3305. if (snd_info_register(priv->entry) < 0) {
  3306. snd_info_free_entry(priv->entry);
  3307. return -ENOMEM;
  3308. }
  3309. version_entry = snd_info_create_card_entry(card->snd_card,
  3310. "version",
  3311. priv->entry);
  3312. if (!version_entry) {
  3313. dev_dbg(component->dev, "%s: failed to create wcd9378 version entry\n",
  3314. __func__);
  3315. snd_info_free_entry(priv->entry);
  3316. return -ENOMEM;
  3317. }
  3318. version_entry->private_data = priv;
  3319. version_entry->size = WCD9378_VERSION_ENTRY_SIZE;
  3320. version_entry->content = SNDRV_INFO_CONTENT_DATA;
  3321. version_entry->c.ops = &wcd9378_info_ops;
  3322. if (snd_info_register(version_entry) < 0) {
  3323. snd_info_free_entry(version_entry);
  3324. snd_info_free_entry(priv->entry);
  3325. return -ENOMEM;
  3326. }
  3327. priv->version_entry = version_entry;
  3328. return 0;
  3329. }
  3330. EXPORT_SYMBOL_GPL(wcd9378_info_create_codec_entry);
  3331. static void wcd9378_class_load(struct snd_soc_component *component)
  3332. {
  3333. /*SMP AMP CLASS LOADING*/
  3334. snd_soc_component_update_bits(component, WCD9378_FUNC_ACT,
  3335. WCD9378_FUNC_ACT_FUNC_ACT_MASK, 0x01);
  3336. usleep_range(20000, 20010);
  3337. snd_soc_component_update_bits(component, WCD9378_SMP_AMP_FUNC_STAT,
  3338. WCD9378_SMP_AMP_FUNC_STAT_FUNC_STAT_MASK, 0xFF);
  3339. /*SMP JACK CLASS LOADING*/
  3340. snd_soc_component_update_bits(component, WCD9378_SMP_JACK_FUNC_ACT,
  3341. WCD9378_SMP_JACK_FUNC_ACT_FUNC_ACT_MASK, 0x01);
  3342. usleep_range(30000, 30010);
  3343. snd_soc_component_update_bits(component, WCD9378_CMT_GRP_MASK,
  3344. WCD9378_CMT_GRP_MASK_CMT_GRP_MASK_MASK, 0x02);
  3345. snd_soc_component_update_bits(component, WCD9378_SMP_JACK_FUNC_STAT,
  3346. WCD9378_SMP_JACK_FUNC_STAT_FUNC_STAT_MASK, 0xFF);
  3347. /*SMP MIC0 CLASS LOADING*/
  3348. snd_soc_component_update_bits(component, WCD9378_SMP_MIC_CTRL0_FUNC_ACT,
  3349. WCD9378_SMP_MIC_CTRL0_FUNC_ACT_FUNC_ACT_MASK, 0x01);
  3350. usleep_range(5000, 5010);
  3351. snd_soc_component_update_bits(component, WCD9378_SMP_MIC_CTRL0_FUNC_STAT,
  3352. WCD9378_SMP_MIC_CTRL0_FUNC_STAT_FUNC_STAT_MASK, 0xFF);
  3353. /*SMP MIC1 CLASS LOADING*/
  3354. snd_soc_component_update_bits(component, WCD9378_SMP_MIC_CTRL1_FUNC_ACT,
  3355. WCD9378_SMP_MIC_CTRL1_FUNC_ACT_FUNC_ACT_MASK, 0x01);
  3356. usleep_range(5000, 5010);
  3357. snd_soc_component_update_bits(component, WCD9378_SMP_MIC_CTRL1_FUNC_STAT,
  3358. WCD9378_SMP_MIC_CTRL1_FUNC_STAT_FUNC_STAT_MASK, 0xFF);
  3359. /*SMP MIC2 CLASS LOADING*/
  3360. snd_soc_component_update_bits(component, WCD9378_SMP_MIC_CTRL2_FUNC_ACT,
  3361. WCD9378_SMP_MIC_CTRL2_FUNC_ACT_FUNC_ACT_MASK, 0x01);
  3362. usleep_range(5000, 5010);
  3363. snd_soc_component_update_bits(component, WCD9378_SMP_MIC_CTRL2_FUNC_STAT,
  3364. WCD9378_SMP_MIC_CTRL2_FUNC_STAT_FUNC_STAT_MASK, 0xFF);
  3365. }
  3366. static void wcd9378_micb_value_convert(struct snd_soc_component *component)
  3367. {
  3368. struct wcd9378_priv *wcd9378 =
  3369. snd_soc_component_get_drvdata(component);
  3370. struct wcd9378_pdata *pdata =
  3371. dev_get_platdata(wcd9378->dev);
  3372. struct wcd9378_micbias_setting *mb = &pdata->micbias;
  3373. mb->micb1_usage_val = wcd9378_micb_usage_value_convert(component,
  3374. mb->micb1_mv, MIC_BIAS_1);
  3375. mb->micb2_usage_val = wcd9378_micb_usage_value_convert(component,
  3376. mb->micb2_mv, MIC_BIAS_2);
  3377. mb->micb3_usage_val = wcd9378_micb_usage_value_convert(component,
  3378. mb->micb3_mv, MIC_BIAS_3);
  3379. pr_debug("%s: micb1_usage: 0x%x, micb2_usage: 0x%x, micb3_usage: 0x%x\n", __func__,
  3380. mb->micb1_usage_val, mb->micb2_usage_val, mb->micb3_usage_val);
  3381. }
  3382. static int wcd9378_wcd_mode_check(struct snd_soc_component *component)
  3383. {
  3384. struct wcd9378_priv *wcd9378 =
  3385. snd_soc_component_get_drvdata(component);
  3386. if (snd_soc_component_read(component,
  3387. WCD9378_EFUSE_REG_29)
  3388. & WCD9378_EFUSE_REG_29_PLATFORM_BLOWN_MASK) {
  3389. if (((snd_soc_component_read(component,
  3390. WCD9378_EFUSE_REG_29) &
  3391. WCD9378_EFUSE_REG_29_PLATFORM_MASK) >> 1) == wcd9378->wcd_mode)
  3392. return true;
  3393. else
  3394. return false;
  3395. } else {
  3396. if ((snd_soc_component_read(component, WCD9378_PLATFORM_CTL)
  3397. & WCD9378_PLATFORM_CTL_MODE_MASK) == wcd9378->wcd_mode)
  3398. return true;
  3399. else
  3400. return false;
  3401. }
  3402. return 0;
  3403. }
  3404. static int wcd9378_soc_codec_probe(struct snd_soc_component *component)
  3405. {
  3406. struct wcd9378_priv *wcd9378 = snd_soc_component_get_drvdata(component);
  3407. struct snd_soc_dapm_context *dapm =
  3408. snd_soc_component_get_dapm(component);
  3409. int ret = -EINVAL;
  3410. wcd9378 = snd_soc_component_get_drvdata(component);
  3411. if (!wcd9378)
  3412. return -EINVAL;
  3413. wcd9378->component = component;
  3414. snd_soc_component_init_regmap(component, wcd9378->regmap);
  3415. devm_regmap_qti_debugfs_register(&wcd9378->tx_swr_dev->dev, wcd9378->regmap);
  3416. ret = wcd9378_wcd_mode_check(component);
  3417. if (!ret) {
  3418. dev_err(component->dev, "wcd mode check failed\n");
  3419. ret = -EINVAL;
  3420. goto exit;
  3421. }
  3422. ret = wcd9378_mbhc_init(&wcd9378->mbhc, component);
  3423. if (ret) {
  3424. pr_err("%s: mbhc initialization failed\n", __func__);
  3425. ret = -EINVAL;
  3426. goto exit;
  3427. }
  3428. snd_soc_dapm_ignore_suspend(dapm, "AMIC1");
  3429. snd_soc_dapm_ignore_suspend(dapm, "AMIC2");
  3430. snd_soc_dapm_ignore_suspend(dapm, "AMIC3");
  3431. snd_soc_dapm_ignore_suspend(dapm, "AMIC4");
  3432. snd_soc_dapm_ignore_suspend(dapm, "VA AMIC1");
  3433. snd_soc_dapm_ignore_suspend(dapm, "VA AMIC2");
  3434. snd_soc_dapm_ignore_suspend(dapm, "VA AMIC3");
  3435. snd_soc_dapm_ignore_suspend(dapm, "VA AMIC4");
  3436. snd_soc_dapm_ignore_suspend(dapm, "IN1_HPHL");
  3437. snd_soc_dapm_ignore_suspend(dapm, "IN2_HPHR");
  3438. snd_soc_dapm_ignore_suspend(dapm, "IN3_AUX");
  3439. snd_soc_dapm_ignore_suspend(dapm, "ADC1_OUTPUT");
  3440. snd_soc_dapm_ignore_suspend(dapm, "ADC2_OUTPUT");
  3441. snd_soc_dapm_ignore_suspend(dapm, "ADC3_OUTPUT");
  3442. snd_soc_dapm_ignore_suspend(dapm, "EAR");
  3443. snd_soc_dapm_ignore_suspend(dapm, "AUX");
  3444. snd_soc_dapm_ignore_suspend(dapm, "HPHL");
  3445. snd_soc_dapm_ignore_suspend(dapm, "HPHR");
  3446. snd_soc_dapm_sync(dapm);
  3447. wcd_cls_h_init(&wcd9378->clsh_info);
  3448. wcd9378_init_reg(component);
  3449. wcd9378_micb_value_convert(component);
  3450. wcd9378->version = WCD9378_VERSION_1_0;
  3451. /* Register event notifier */
  3452. wcd9378->nblock.notifier_call = wcd9378_event_notify;
  3453. if (wcd9378->register_notifier) {
  3454. ret = wcd9378->register_notifier(wcd9378->handle,
  3455. &wcd9378->nblock,
  3456. true);
  3457. if (ret) {
  3458. dev_err(component->dev,
  3459. "%s: Failed to register notifier %d\n",
  3460. __func__, ret);
  3461. return ret;
  3462. }
  3463. }
  3464. exit:
  3465. return ret;
  3466. }
  3467. static void wcd9378_soc_codec_remove(struct snd_soc_component *component)
  3468. {
  3469. struct wcd9378_priv *wcd9378 = snd_soc_component_get_drvdata(component);
  3470. if (!wcd9378) {
  3471. dev_err(component->dev, "%s: wcd9378 is already NULL\n",
  3472. __func__);
  3473. return;
  3474. }
  3475. if (wcd9378->register_notifier)
  3476. wcd9378->register_notifier(wcd9378->handle,
  3477. &wcd9378->nblock,
  3478. false);
  3479. }
  3480. static int wcd9378_soc_codec_suspend(struct snd_soc_component *component)
  3481. {
  3482. struct wcd9378_priv *wcd9378 = snd_soc_component_get_drvdata(component);
  3483. if (!wcd9378)
  3484. return 0;
  3485. wcd9378->dapm_bias_off = true;
  3486. return 0;
  3487. }
  3488. static int wcd9378_soc_codec_resume(struct snd_soc_component *component)
  3489. {
  3490. struct wcd9378_priv *wcd9378 = snd_soc_component_get_drvdata(component);
  3491. if (!wcd9378)
  3492. return 0;
  3493. wcd9378->dapm_bias_off = false;
  3494. return 0;
  3495. }
  3496. static const struct snd_soc_component_driver soc_codec_dev_wcd9378 = {
  3497. .name = WCD9378_DRV_NAME,
  3498. .probe = wcd9378_soc_codec_probe,
  3499. .remove = wcd9378_soc_codec_remove,
  3500. .controls = wcd9378_snd_controls,
  3501. .num_controls = ARRAY_SIZE(wcd9378_snd_controls),
  3502. .dapm_widgets = wcd9378_dapm_widgets,
  3503. .num_dapm_widgets = ARRAY_SIZE(wcd9378_dapm_widgets),
  3504. .dapm_routes = wcd9378_audio_map,
  3505. .num_dapm_routes = ARRAY_SIZE(wcd9378_audio_map),
  3506. .suspend = wcd9378_soc_codec_suspend,
  3507. .resume = wcd9378_soc_codec_resume,
  3508. };
  3509. static int wcd9378_reset(struct device *dev)
  3510. {
  3511. struct wcd9378_priv *wcd9378 = NULL;
  3512. int rc = 0;
  3513. int value = 0;
  3514. if (!dev)
  3515. return -ENODEV;
  3516. wcd9378 = dev_get_drvdata(dev);
  3517. if (!wcd9378)
  3518. return -EINVAL;
  3519. if (!wcd9378->rst_np) {
  3520. dev_err(dev, "%s: reset gpio device node not specified\n",
  3521. __func__);
  3522. return -EINVAL;
  3523. }
  3524. value = msm_cdc_pinctrl_get_state(wcd9378->rst_np);
  3525. if (value > 0)
  3526. return 0;
  3527. rc = msm_cdc_pinctrl_select_sleep_state(wcd9378->rst_np);
  3528. if (rc) {
  3529. dev_err(dev, "%s: wcd sleep state request fail!\n",
  3530. __func__);
  3531. return -EPROBE_DEFER;
  3532. }
  3533. /* 20us sleep required after pulling the reset gpio to LOW */
  3534. usleep_range(20, 30);
  3535. rc = msm_cdc_pinctrl_select_active_state(wcd9378->rst_np);
  3536. if (rc) {
  3537. dev_err(dev, "%s: wcd active state request fail!\n",
  3538. __func__);
  3539. return -EPROBE_DEFER;
  3540. }
  3541. /* 20us sleep required after pulling the reset gpio to HIGH */
  3542. usleep_range(20, 30);
  3543. return rc;
  3544. }
  3545. static int wcd9378_read_of_property_u32(struct device *dev, const char *name,
  3546. u32 *val)
  3547. {
  3548. int rc = 0;
  3549. rc = of_property_read_u32(dev->of_node, name, val);
  3550. if (rc)
  3551. dev_err(dev, "%s: Looking up %s property in node %s failed\n",
  3552. __func__, name, dev->of_node->full_name);
  3553. return rc;
  3554. }
  3555. static void wcd9378_dt_parse_micbias_info(struct device *dev,
  3556. struct wcd9378_micbias_setting *mb)
  3557. {
  3558. u32 prop_val = 0;
  3559. int rc = 0;
  3560. /* MB1 */
  3561. if (of_find_property(dev->of_node, "qcom,cdc-micbias1-mv",
  3562. NULL)) {
  3563. rc = wcd9378_read_of_property_u32(dev,
  3564. "qcom,cdc-micbias1-mv",
  3565. &prop_val);
  3566. if (!rc)
  3567. mb->micb1_mv = prop_val;
  3568. } else {
  3569. dev_info(dev, "%s: Micbias1 DT property not found\n",
  3570. __func__);
  3571. }
  3572. /* MB2 */
  3573. if (of_find_property(dev->of_node, "qcom,cdc-micbias2-mv",
  3574. NULL)) {
  3575. rc = wcd9378_read_of_property_u32(dev,
  3576. "qcom,cdc-micbias2-mv",
  3577. &prop_val);
  3578. if (!rc)
  3579. mb->micb2_mv = prop_val;
  3580. } else {
  3581. dev_info(dev, "%s: Micbias2 DT property not found\n",
  3582. __func__);
  3583. }
  3584. /* MB3 */
  3585. if (of_find_property(dev->of_node, "qcom,cdc-micbias3-mv",
  3586. NULL)) {
  3587. rc = wcd9378_read_of_property_u32(dev,
  3588. "qcom,cdc-micbias3-mv",
  3589. &prop_val);
  3590. if (!rc)
  3591. mb->micb3_mv = prop_val;
  3592. } else {
  3593. dev_info(dev, "%s: Micbias3 DT property not found\n",
  3594. __func__);
  3595. }
  3596. }
  3597. static int wcd9378_reset_low(struct device *dev)
  3598. {
  3599. struct wcd9378_priv *wcd9378 = NULL;
  3600. int rc = 0;
  3601. if (!dev)
  3602. return -ENODEV;
  3603. wcd9378 = dev_get_drvdata(dev);
  3604. if (!wcd9378)
  3605. return -EINVAL;
  3606. if (!wcd9378->rst_np) {
  3607. dev_err(dev, "%s: reset gpio device node not specified\n",
  3608. __func__);
  3609. return -EINVAL;
  3610. }
  3611. rc = msm_cdc_pinctrl_select_sleep_state(wcd9378->rst_np);
  3612. if (rc) {
  3613. dev_err(dev, "%s: wcd sleep state request fail!\n",
  3614. __func__);
  3615. return rc;
  3616. }
  3617. /* 20us sleep required after pulling the reset gpio to LOW */
  3618. usleep_range(20, 30);
  3619. return rc;
  3620. }
  3621. struct wcd9378_pdata *wcd9378_populate_dt_data(struct device *dev)
  3622. {
  3623. struct wcd9378_pdata *pdata = NULL;
  3624. pdata = devm_kzalloc(dev, sizeof(struct wcd9378_pdata),
  3625. GFP_KERNEL);
  3626. if (!pdata)
  3627. return NULL;
  3628. pdata->rst_np = of_parse_phandle(dev->of_node,
  3629. "qcom,wcd-rst-gpio-node", 0);
  3630. if (!pdata->rst_np) {
  3631. dev_err(dev, "%s: Looking up %s property in node %s failed\n",
  3632. __func__, "qcom,wcd-rst-gpio-node",
  3633. dev->of_node->full_name);
  3634. return NULL;
  3635. }
  3636. /* Parse power supplies */
  3637. msm_cdc_get_power_supplies(dev, &pdata->regulator,
  3638. &pdata->num_supplies);
  3639. if (!pdata->regulator || (pdata->num_supplies <= 0)) {
  3640. dev_err(dev, "%s: no power supplies defined for codec\n",
  3641. __func__);
  3642. return NULL;
  3643. }
  3644. pdata->rx_slave = of_parse_phandle(dev->of_node, "qcom,rx-slave", 0);
  3645. pdata->tx_slave = of_parse_phandle(dev->of_node, "qcom,tx-slave", 0);
  3646. wcd9378_dt_parse_micbias_info(dev, &pdata->micbias);
  3647. return pdata;
  3648. }
  3649. static struct snd_soc_dai_driver wcd9378_dai[] = {
  3650. {
  3651. .name = "wcd9378_cdc",
  3652. .playback = {
  3653. .stream_name = "WCD9378_AIF Playback",
  3654. .rates = WCD9378_RATES | WCD9378_FRAC_RATES,
  3655. .formats = WCD9378_FORMATS,
  3656. .rate_max = 384000,
  3657. .rate_min = 8000,
  3658. .channels_min = 1,
  3659. .channels_max = 4,
  3660. },
  3661. .capture = {
  3662. .stream_name = "WCD9378_AIF Capture",
  3663. .rates = WCD9378_RATES | WCD9378_FRAC_RATES,
  3664. .formats = WCD9378_FORMATS,
  3665. .rate_max = 384000,
  3666. .rate_min = 8000,
  3667. .channels_min = 1,
  3668. .channels_max = 4,
  3669. },
  3670. },
  3671. };
  3672. static int wcd9378_bind(struct device *dev)
  3673. {
  3674. int ret = 0;
  3675. struct wcd9378_pdata *pdata = dev_get_platdata(dev);
  3676. struct wcd9378_priv *wcd9378 = dev_get_drvdata(dev);
  3677. /*
  3678. * Add 5msec delay to provide sufficient time for
  3679. * soundwire auto enumeration of slave devices as
  3680. * per HW requirement.
  3681. */
  3682. usleep_range(5000, 5010);
  3683. ret = component_bind_all(dev, wcd9378);
  3684. if (ret) {
  3685. dev_err(dev, "%s: Slave bind failed, ret = %d\n",
  3686. __func__, ret);
  3687. return ret;
  3688. }
  3689. wcd9378->rx_swr_dev = get_matching_swr_slave_device(pdata->rx_slave);
  3690. if (!wcd9378->rx_swr_dev) {
  3691. dev_err(dev, "%s: Could not find RX swr slave device\n",
  3692. __func__);
  3693. ret = -ENODEV;
  3694. goto err;
  3695. }
  3696. wcd9378->rx_swr_dev->paging_support = true;
  3697. wcd9378->tx_swr_dev = get_matching_swr_slave_device(pdata->tx_slave);
  3698. if (!wcd9378->tx_swr_dev) {
  3699. dev_err(dev, "%s: Could not find TX swr slave device\n",
  3700. __func__);
  3701. ret = -ENODEV;
  3702. goto err;
  3703. }
  3704. wcd9378->tx_swr_dev->paging_support = true;
  3705. swr_init_port_params(wcd9378->tx_swr_dev, SWR_NUM_PORTS,
  3706. wcd9378->swr_tx_port_params);
  3707. wcd9378->regmap = devm_regmap_init_swr(wcd9378->tx_swr_dev,
  3708. &wcd9378_regmap_config);
  3709. if (!wcd9378->regmap) {
  3710. dev_err(dev, "%s: Regmap init failed\n",
  3711. __func__);
  3712. goto err;
  3713. }
  3714. regmap_write(wcd9378->regmap, SWRS_SCP_SDCA_INTRTYPE_1, 0xff);
  3715. regmap_write(wcd9378->regmap, SWRS_SCP_SDCA_INTRTYPE_2, 0x0b);
  3716. regmap_write(wcd9378->regmap, SWRS_SCP_SDCA_INTRTYPE_3, 0xff);
  3717. wcd9378_regmap_irq_chip.irq_drv_data = wcd9378;
  3718. wcd9378->irq_info.wcd_regmap_irq_chip = &wcd9378_regmap_irq_chip;
  3719. wcd9378->irq_info.codec_name = "WCD9378";
  3720. wcd9378->irq_info.regmap = wcd9378->regmap;
  3721. wcd9378->irq_info.dev = dev;
  3722. ret = wcd_irq_init(&wcd9378->irq_info, &wcd9378->virq);
  3723. if (ret) {
  3724. dev_err(wcd9378->dev, "%s: IRQ init failed: %d\n",
  3725. __func__, ret);
  3726. goto err;
  3727. }
  3728. dev_err(wcd9378->dev, "%s: wcd irq init done\n",
  3729. __func__);
  3730. wcd9378->tx_swr_dev->slave_irq = wcd9378->virq;
  3731. ret = snd_soc_register_component(dev, &soc_codec_dev_wcd9378,
  3732. wcd9378_dai, ARRAY_SIZE(wcd9378_dai));
  3733. if (ret) {
  3734. dev_err(dev, "%s: Codec registration failed\n",
  3735. __func__);
  3736. goto err_irq;
  3737. }
  3738. wcd9378->dev_up = true;
  3739. return ret;
  3740. err_irq:
  3741. wcd_irq_exit(&wcd9378->irq_info, wcd9378->virq);
  3742. err:
  3743. component_unbind_all(dev, wcd9378);
  3744. return ret;
  3745. }
  3746. static void wcd9378_unbind(struct device *dev)
  3747. {
  3748. struct wcd9378_priv *wcd9378 = dev_get_drvdata(dev);
  3749. wcd_irq_exit(&wcd9378->irq_info, wcd9378->virq);
  3750. snd_soc_unregister_component(dev);
  3751. component_unbind_all(dev, wcd9378);
  3752. }
  3753. static const struct of_device_id wcd9378_dt_match[] = {
  3754. { .compatible = "qcom,wcd9378-codec", .data = "wcd9378"},
  3755. {}
  3756. };
  3757. static const struct component_master_ops wcd9378_comp_ops = {
  3758. .bind = wcd9378_bind,
  3759. .unbind = wcd9378_unbind,
  3760. };
  3761. static int wcd9378_compare_of(struct device *dev, void *data)
  3762. {
  3763. return dev->of_node == data;
  3764. }
  3765. static void wcd9378_release_of(struct device *dev, void *data)
  3766. {
  3767. of_node_put(data);
  3768. }
  3769. static int wcd9378_add_slave_components(struct device *dev,
  3770. struct component_match **matchptr)
  3771. {
  3772. struct device_node *np, *rx_node, *tx_node;
  3773. np = dev->of_node;
  3774. rx_node = of_parse_phandle(np, "qcom,rx-slave", 0);
  3775. if (!rx_node) {
  3776. dev_err(dev, "%s: Rx-slave node not defined\n", __func__);
  3777. return -ENODEV;
  3778. }
  3779. of_node_get(rx_node);
  3780. component_match_add_release(dev, matchptr,
  3781. wcd9378_release_of,
  3782. wcd9378_compare_of,
  3783. rx_node);
  3784. tx_node = of_parse_phandle(np, "qcom,tx-slave", 0);
  3785. if (!tx_node) {
  3786. dev_err(dev, "%s: Tx-slave node not defined\n", __func__);
  3787. return -ENODEV;
  3788. }
  3789. of_node_get(tx_node);
  3790. component_match_add_release(dev, matchptr,
  3791. wcd9378_release_of,
  3792. wcd9378_compare_of,
  3793. tx_node);
  3794. return 0;
  3795. }
  3796. static int wcd9378_probe(struct platform_device *pdev)
  3797. {
  3798. struct component_match *match = NULL;
  3799. struct wcd9378_priv *wcd9378 = NULL;
  3800. struct wcd9378_pdata *pdata = NULL;
  3801. struct wcd_ctrl_platform_data *plat_data = NULL;
  3802. struct device *dev = &pdev->dev;
  3803. int ret;
  3804. wcd9378 = devm_kzalloc(dev, sizeof(struct wcd9378_priv),
  3805. GFP_KERNEL);
  3806. if (!wcd9378)
  3807. return -ENOMEM;
  3808. dev_set_drvdata(dev, wcd9378);
  3809. wcd9378->dev = dev;
  3810. pdata = wcd9378_populate_dt_data(dev);
  3811. if (!pdata) {
  3812. dev_err(dev, "%s: Fail to obtain platform data\n", __func__);
  3813. return -EINVAL;
  3814. }
  3815. dev->platform_data = pdata;
  3816. wcd9378->rst_np = pdata->rst_np;
  3817. ret = msm_cdc_init_supplies(dev, &wcd9378->supplies,
  3818. pdata->regulator, pdata->num_supplies);
  3819. if (!wcd9378->supplies) {
  3820. dev_err(dev, "%s: Cannot init wcd supplies\n",
  3821. __func__);
  3822. return ret;
  3823. }
  3824. plat_data = dev_get_platdata(dev->parent);
  3825. if (!plat_data) {
  3826. dev_err(dev, "%s: platform data from parent is NULL\n",
  3827. __func__);
  3828. return -EINVAL;
  3829. }
  3830. wcd9378->handle = (void *)plat_data->handle;
  3831. if (!wcd9378->handle) {
  3832. dev_err(dev, "%s: handle is NULL\n", __func__);
  3833. return -EINVAL;
  3834. }
  3835. wcd9378->update_wcd_event = plat_data->update_wcd_event;
  3836. if (!wcd9378->update_wcd_event) {
  3837. dev_err(dev, "%s: update_wcd_event api is null!\n",
  3838. __func__);
  3839. return -EINVAL;
  3840. }
  3841. wcd9378->register_notifier = plat_data->register_notifier;
  3842. if (!wcd9378->register_notifier) {
  3843. dev_err(dev, "%s: register_notifier api is null!\n",
  3844. __func__);
  3845. return -EINVAL;
  3846. }
  3847. ret = of_property_read_u32(dev->of_node, "qcom,wcd-mode",
  3848. &wcd9378->wcd_mode);
  3849. if (ret) {
  3850. dev_dbg(dev, "%s: wcd-mode read failed, use mobile mode\n",
  3851. __func__);
  3852. wcd9378->wcd_mode = WCD9378_MOBILE_MODE;
  3853. }
  3854. ret = msm_cdc_enable_static_supplies(&pdev->dev, wcd9378->supplies,
  3855. pdata->regulator,
  3856. pdata->num_supplies);
  3857. if (ret) {
  3858. dev_err(dev, "%s: wcd static supply enable failed!\n",
  3859. __func__);
  3860. return ret;
  3861. }
  3862. ret = wcd9378_parse_port_mapping(dev, "qcom,rx_swr_ch_map",
  3863. CODEC_RX);
  3864. ret |= wcd9378_parse_port_mapping(dev, "qcom,tx_swr_ch_map",
  3865. CODEC_TX);
  3866. if (ret) {
  3867. dev_err(dev, "Failed to read port mapping\n");
  3868. goto err;
  3869. }
  3870. ret = wcd9378_parse_port_params(dev, "qcom,swr-tx-port-params",
  3871. CODEC_TX);
  3872. if (ret) {
  3873. dev_err(dev, "Failed to read port params\n");
  3874. goto err;
  3875. }
  3876. mutex_init(&wcd9378->wakeup_lock);
  3877. mutex_init(&wcd9378->micb_lock);
  3878. mutex_init(&wcd9378->sys_usage_lock);
  3879. ret = wcd9378_add_slave_components(dev, &match);
  3880. if (ret)
  3881. goto err_lock_init;
  3882. ret = wcd9378_reset(dev);
  3883. if (ret == -EPROBE_DEFER) {
  3884. dev_err(dev, "%s: wcd reset failed!\n", __func__);
  3885. goto err_lock_init;
  3886. }
  3887. wcd9378->wakeup = wcd9378_wakeup;
  3888. return component_master_add_with_match(dev,
  3889. &wcd9378_comp_ops, match);
  3890. err_lock_init:
  3891. mutex_destroy(&wcd9378->micb_lock);
  3892. mutex_destroy(&wcd9378->wakeup_lock);
  3893. mutex_destroy(&wcd9378->sys_usage_lock);
  3894. err:
  3895. return ret;
  3896. }
  3897. static int wcd9378_remove(struct platform_device *pdev)
  3898. {
  3899. struct wcd9378_priv *wcd9378 = NULL;
  3900. wcd9378 = platform_get_drvdata(pdev);
  3901. component_master_del(&pdev->dev, &wcd9378_comp_ops);
  3902. mutex_destroy(&wcd9378->micb_lock);
  3903. mutex_destroy(&wcd9378->wakeup_lock);
  3904. mutex_destroy(&wcd9378->sys_usage_lock);
  3905. dev_set_drvdata(&pdev->dev, NULL);
  3906. return 0;
  3907. }
  3908. #ifdef CONFIG_PM_SLEEP
  3909. static int wcd9378_suspend(struct device *dev)
  3910. {
  3911. struct wcd9378_priv *wcd9378 = NULL;
  3912. int ret = 0;
  3913. struct wcd9378_pdata *pdata = NULL;
  3914. if (!dev)
  3915. return -ENODEV;
  3916. wcd9378 = dev_get_drvdata(dev);
  3917. if (!wcd9378)
  3918. return -EINVAL;
  3919. pdata = dev_get_platdata(wcd9378->dev);
  3920. if (!pdata) {
  3921. dev_err(dev, "%s: pdata is NULL\n", __func__);
  3922. return -EINVAL;
  3923. }
  3924. if (test_bit(ALLOW_BUCK_DISABLE, &wcd9378->status_mask)) {
  3925. ret = msm_cdc_disable_ondemand_supply(wcd9378->dev,
  3926. wcd9378->supplies,
  3927. pdata->regulator,
  3928. pdata->num_supplies,
  3929. "cdc-vdd-buck");
  3930. if (ret == -EINVAL) {
  3931. dev_err(dev, "%s: vdd buck is not disabled\n",
  3932. __func__);
  3933. return 0;
  3934. }
  3935. clear_bit(ALLOW_BUCK_DISABLE, &wcd9378->status_mask);
  3936. }
  3937. if (wcd9378->dapm_bias_off) {
  3938. msm_cdc_set_supplies_lpm_mode(wcd9378->dev,
  3939. wcd9378->supplies,
  3940. pdata->regulator,
  3941. pdata->num_supplies,
  3942. true);
  3943. set_bit(WCD_SUPPLIES_LPM_MODE, &wcd9378->status_mask);
  3944. }
  3945. return 0;
  3946. }
  3947. static int wcd9378_resume(struct device *dev)
  3948. {
  3949. struct wcd9378_priv *wcd9378 = NULL;
  3950. struct wcd9378_pdata *pdata = NULL;
  3951. if (!dev)
  3952. return -ENODEV;
  3953. wcd9378 = dev_get_drvdata(dev);
  3954. if (!wcd9378)
  3955. return -EINVAL;
  3956. pdata = dev_get_platdata(wcd9378->dev);
  3957. if (!pdata) {
  3958. dev_err(dev, "%s: pdata is NULL\n", __func__);
  3959. return -EINVAL;
  3960. }
  3961. if (test_bit(WCD_SUPPLIES_LPM_MODE, &wcd9378->status_mask)) {
  3962. msm_cdc_set_supplies_lpm_mode(wcd9378->dev,
  3963. wcd9378->supplies,
  3964. pdata->regulator,
  3965. pdata->num_supplies,
  3966. false);
  3967. clear_bit(WCD_SUPPLIES_LPM_MODE, &wcd9378->status_mask);
  3968. }
  3969. return 0;
  3970. }
  3971. static const struct dev_pm_ops wcd9378_dev_pm_ops = {
  3972. .suspend_late = wcd9378_suspend,
  3973. .resume_early = wcd9378_resume,
  3974. };
  3975. #endif
  3976. static struct platform_driver wcd9378_codec_driver = {
  3977. .probe = wcd9378_probe,
  3978. .remove = wcd9378_remove,
  3979. .driver = {
  3980. .name = "wcd9378_codec",
  3981. .of_match_table = of_match_ptr(wcd9378_dt_match),
  3982. #ifdef CONFIG_PM_SLEEP
  3983. .pm = &wcd9378_dev_pm_ops,
  3984. #endif
  3985. .suppress_bind_attrs = true,
  3986. },
  3987. };
  3988. module_platform_driver(wcd9378_codec_driver);
  3989. MODULE_DESCRIPTION("WCD9378 Codec driver");
  3990. MODULE_LICENSE("GPL");