wcd938x.c 124 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/module.h>
  6. #include <linux/slab.h>
  7. #include <linux/platform_device.h>
  8. #include <linux/device.h>
  9. #include <linux/delay.h>
  10. #include <linux/kernel.h>
  11. #include <linux/component.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/wcdcal-hwdep.h>
  19. #include <asoc/msm-cdc-pinctrl.h>
  20. #include <asoc/msm-cdc-supply.h>
  21. #include <dt-bindings/sound/audio-codec-port-types.h>
  22. #include "wcd938x-registers.h"
  23. #include "wcd938x.h"
  24. #include "internal.h"
  25. #define NUM_SWRS_DT_PARAMS 5
  26. #define WCD938X_VARIANT_ENTRY_SIZE 32
  27. #define WCD938X_VERSION_1_0 1
  28. #define WCD938X_VERSION_ENTRY_SIZE 32
  29. #define EAR_RX_PATH_AUX 1
  30. #define ADC_MODE_VAL_HIFI 0x01
  31. #define ADC_MODE_VAL_LO_HIF 0x02
  32. #define ADC_MODE_VAL_NORMAL 0x03
  33. #define ADC_MODE_VAL_LP 0x05
  34. #define ADC_MODE_VAL_ULP1 0x09
  35. #define ADC_MODE_VAL_ULP2 0x0B
  36. #define NUM_ATTEMPTS 5
  37. #define DAPM_MICBIAS1_STANDALONE "MIC BIAS1 Standalone"
  38. #define DAPM_MICBIAS2_STANDALONE "MIC BIAS2 Standalone"
  39. #define DAPM_MICBIAS3_STANDALONE "MIC BIAS3 Standalone"
  40. #define DAPM_MICBIAS4_STANDALONE "MIC BIAS4 Standalone"
  41. #define WCD938X_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
  42. SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
  43. SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000 |\
  44. SNDRV_PCM_RATE_384000)
  45. /* Fractional Rates */
  46. #define WCD938X_FRAC_RATES (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_88200 |\
  47. SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_352800)
  48. #define WCD938X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
  49. SNDRV_PCM_FMTBIT_S24_LE |\
  50. SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
  51. enum {
  52. CODEC_TX = 0,
  53. CODEC_RX,
  54. };
  55. enum {
  56. WCD_ADC1 = 0,
  57. WCD_ADC2,
  58. WCD_ADC3,
  59. WCD_ADC4,
  60. ALLOW_BUCK_DISABLE,
  61. HPH_COMP_DELAY,
  62. HPH_PA_DELAY,
  63. AMIC2_BCS_ENABLE,
  64. WCD_SUPPLIES_LPM_MODE,
  65. };
  66. enum {
  67. ADC_MODE_INVALID = 0,
  68. ADC_MODE_HIFI,
  69. ADC_MODE_LO_HIF,
  70. ADC_MODE_NORMAL,
  71. ADC_MODE_LP,
  72. ADC_MODE_ULP1,
  73. ADC_MODE_ULP2,
  74. };
  75. static u8 tx_mode_bit[] = {
  76. [ADC_MODE_INVALID] = 0x00,
  77. [ADC_MODE_HIFI] = 0x01,
  78. [ADC_MODE_LO_HIF] = 0x02,
  79. [ADC_MODE_NORMAL] = 0x04,
  80. [ADC_MODE_LP] = 0x08,
  81. [ADC_MODE_ULP1] = 0x10,
  82. [ADC_MODE_ULP2] = 0x20,
  83. };
  84. static const DECLARE_TLV_DB_SCALE(line_gain, 0, 7, 1);
  85. static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1);
  86. static int wcd938x_handle_post_irq(void *data);
  87. static int wcd938x_reset(struct device *dev);
  88. static int wcd938x_reset_low(struct device *dev);
  89. static const struct regmap_irq wcd938x_irqs[WCD938X_NUM_IRQS] = {
  90. REGMAP_IRQ_REG(WCD938X_IRQ_MBHC_BUTTON_PRESS_DET, 0, 0x01),
  91. REGMAP_IRQ_REG(WCD938X_IRQ_MBHC_BUTTON_RELEASE_DET, 0, 0x02),
  92. REGMAP_IRQ_REG(WCD938X_IRQ_MBHC_ELECT_INS_REM_DET, 0, 0x04),
  93. REGMAP_IRQ_REG(WCD938X_IRQ_MBHC_ELECT_INS_REM_LEG_DET, 0, 0x08),
  94. REGMAP_IRQ_REG(WCD938X_IRQ_MBHC_SW_DET, 0, 0x10),
  95. REGMAP_IRQ_REG(WCD938X_IRQ_HPHR_OCP_INT, 0, 0x20),
  96. REGMAP_IRQ_REG(WCD938X_IRQ_HPHR_CNP_INT, 0, 0x40),
  97. REGMAP_IRQ_REG(WCD938X_IRQ_HPHL_OCP_INT, 0, 0x80),
  98. REGMAP_IRQ_REG(WCD938X_IRQ_HPHL_CNP_INT, 1, 0x01),
  99. REGMAP_IRQ_REG(WCD938X_IRQ_EAR_CNP_INT, 1, 0x02),
  100. REGMAP_IRQ_REG(WCD938X_IRQ_EAR_SCD_INT, 1, 0x04),
  101. REGMAP_IRQ_REG(WCD938X_IRQ_AUX_CNP_INT, 1, 0x08),
  102. REGMAP_IRQ_REG(WCD938X_IRQ_AUX_SCD_INT, 1, 0x10),
  103. REGMAP_IRQ_REG(WCD938X_IRQ_HPHL_PDM_WD_INT, 1, 0x20),
  104. REGMAP_IRQ_REG(WCD938X_IRQ_HPHR_PDM_WD_INT, 1, 0x40),
  105. REGMAP_IRQ_REG(WCD938X_IRQ_AUX_PDM_WD_INT, 1, 0x80),
  106. REGMAP_IRQ_REG(WCD938X_IRQ_LDORT_SCD_INT, 2, 0x01),
  107. REGMAP_IRQ_REG(WCD938X_IRQ_MBHC_MOISTURE_INT, 2, 0x02),
  108. REGMAP_IRQ_REG(WCD938X_IRQ_HPHL_SURGE_DET_INT, 2, 0x04),
  109. REGMAP_IRQ_REG(WCD938X_IRQ_HPHR_SURGE_DET_INT, 2, 0x08),
  110. };
  111. static struct regmap_irq_chip wcd938x_regmap_irq_chip = {
  112. .name = "wcd938x",
  113. .irqs = wcd938x_irqs,
  114. .num_irqs = ARRAY_SIZE(wcd938x_irqs),
  115. .num_regs = 3,
  116. .status_base = WCD938X_DIGITAL_INTR_STATUS_0,
  117. .mask_base = WCD938X_DIGITAL_INTR_MASK_0,
  118. .type_base = WCD938X_DIGITAL_INTR_LEVEL_0,
  119. .ack_base = WCD938X_DIGITAL_INTR_CLEAR_0,
  120. .use_ack = 1,
  121. .runtime_pm = false,
  122. .handle_post_irq = wcd938x_handle_post_irq,
  123. .irq_drv_data = NULL,
  124. };
  125. static int wcd938x_handle_post_irq(void *data)
  126. {
  127. struct wcd938x_priv *wcd938x = data;
  128. u32 sts1 = 0, sts2 = 0, sts3 = 0;
  129. regmap_read(wcd938x->regmap, WCD938X_DIGITAL_INTR_STATUS_0, &sts1);
  130. regmap_read(wcd938x->regmap, WCD938X_DIGITAL_INTR_STATUS_1, &sts2);
  131. regmap_read(wcd938x->regmap, WCD938X_DIGITAL_INTR_STATUS_2, &sts3);
  132. wcd938x->tx_swr_dev->slave_irq_pending =
  133. ((sts1 || sts2 || sts3) ? true : false);
  134. return IRQ_HANDLED;
  135. }
  136. static int wcd938x_swr_slv_get_current_bank(struct swr_device *dev, u8 devnum)
  137. {
  138. int ret = 0;
  139. int bank = 0;
  140. ret = swr_read(dev, devnum, SWR_SCP_CONTROL, &bank, 1);
  141. if (ret)
  142. return -EINVAL;
  143. return ((bank & 0x40) ? 1: 0);
  144. }
  145. static int wcd938x_get_clk_rate(int mode)
  146. {
  147. int rate;
  148. switch (mode) {
  149. case ADC_MODE_ULP2:
  150. rate = SWR_CLK_RATE_0P6MHZ;
  151. break;
  152. case ADC_MODE_ULP1:
  153. rate = SWR_CLK_RATE_1P2MHZ;
  154. break;
  155. case ADC_MODE_LP:
  156. rate = SWR_CLK_RATE_4P8MHZ;
  157. break;
  158. case ADC_MODE_NORMAL:
  159. case ADC_MODE_LO_HIF:
  160. case ADC_MODE_HIFI:
  161. case ADC_MODE_INVALID:
  162. default:
  163. rate = SWR_CLK_RATE_9P6MHZ;
  164. break;
  165. }
  166. return rate;
  167. }
  168. static int wcd938x_set_swr_clk_rate(struct snd_soc_component *component,
  169. int rate, int bank)
  170. {
  171. u8 mask = (bank ? 0xF0 : 0x0F);
  172. u8 val = 0;
  173. switch (rate) {
  174. case SWR_CLK_RATE_0P6MHZ:
  175. val = (bank ? 0x60 : 0x06);
  176. break;
  177. case SWR_CLK_RATE_1P2MHZ:
  178. val = (bank ? 0x50 : 0x05);
  179. break;
  180. case SWR_CLK_RATE_2P4MHZ:
  181. val = (bank ? 0x30 : 0x03);
  182. break;
  183. case SWR_CLK_RATE_4P8MHZ:
  184. val = (bank ? 0x10 : 0x01);
  185. break;
  186. case SWR_CLK_RATE_9P6MHZ:
  187. default:
  188. val = 0x00;
  189. break;
  190. }
  191. snd_soc_component_update_bits(component,
  192. WCD938X_DIGITAL_SWR_TX_CLK_RATE,
  193. mask, val);
  194. return 0;
  195. }
  196. static int wcd938x_init_reg(struct snd_soc_component *component)
  197. {
  198. snd_soc_component_update_bits(component, WCD938X_SLEEP_CTL, 0x0E, 0x0E);
  199. snd_soc_component_update_bits(component, WCD938X_SLEEP_CTL, 0x80, 0x80);
  200. /* 1 msec delay as per HW requirement */
  201. usleep_range(1000, 1010);
  202. snd_soc_component_update_bits(component, WCD938X_SLEEP_CTL, 0x40, 0x40);
  203. /* 1 msec delay as per HW requirement */
  204. usleep_range(1000, 1010);
  205. snd_soc_component_update_bits(component, WCD938X_LDORXTX_CONFIG,
  206. 0x10, 0x00);
  207. snd_soc_component_update_bits(component, WCD938X_BIAS_VBG_FINE_ADJ,
  208. 0xF0, 0x80);
  209. snd_soc_component_update_bits(component, WCD938X_ANA_BIAS, 0x80, 0x80);
  210. snd_soc_component_update_bits(component, WCD938X_ANA_BIAS, 0x40, 0x40);
  211. /* 10 msec delay as per HW requirement */
  212. usleep_range(10000, 10010);
  213. snd_soc_component_update_bits(component, WCD938X_ANA_BIAS, 0x40, 0x00);
  214. snd_soc_component_update_bits(component,
  215. WCD938X_HPH_NEW_INT_RDAC_GAIN_CTL,
  216. 0xF0, 0x00);
  217. snd_soc_component_update_bits(component,
  218. WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_L_NEW,
  219. 0x1F, 0x15);
  220. snd_soc_component_update_bits(component,
  221. WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_R_NEW,
  222. 0x1F, 0x15);
  223. snd_soc_component_update_bits(component, WCD938X_HPH_REFBUFF_UHQA_CTL,
  224. 0xC0, 0x80);
  225. snd_soc_component_update_bits(component, WCD938X_DIGITAL_CDC_DMIC_CTL,
  226. 0x02, 0x02);
  227. snd_soc_component_update_bits(component,
  228. WCD938X_TX_COM_NEW_INT_TXFE_ICTRL_STG2CASC_ULP,
  229. 0xFF, 0x14);
  230. snd_soc_component_update_bits(component,
  231. WCD938X_TX_COM_NEW_INT_TXFE_ICTRL_STG2MAIN_ULP,
  232. 0x1F, 0x08);
  233. snd_soc_component_update_bits(component,
  234. WCD938X_DIGITAL_TX_REQ_FB_CTL_0, 0xFF, 0x55);
  235. snd_soc_component_update_bits(component,
  236. WCD938X_DIGITAL_TX_REQ_FB_CTL_1, 0xFF, 0x44);
  237. snd_soc_component_update_bits(component,
  238. WCD938X_DIGITAL_TX_REQ_FB_CTL_2, 0xFF, 0x11);
  239. snd_soc_component_update_bits(component,
  240. WCD938X_DIGITAL_TX_REQ_FB_CTL_3, 0xFF, 0x00);
  241. snd_soc_component_update_bits(component,
  242. WCD938X_DIGITAL_TX_REQ_FB_CTL_4, 0xFF, 0x00);
  243. snd_soc_component_update_bits(component,
  244. WCD938X_MICB1_TEST_CTL_1, 0xE0, 0xE0);
  245. snd_soc_component_update_bits(component,
  246. WCD938X_MICB2_TEST_CTL_1, 0xE0, 0xE0);
  247. snd_soc_component_update_bits(component,
  248. WCD938X_MICB3_TEST_CTL_1, 0xE0, 0xE0);
  249. snd_soc_component_update_bits(component,
  250. WCD938X_MICB4_TEST_CTL_1, 0xE0, 0xE0);
  251. snd_soc_component_update_bits(component,
  252. WCD938X_TX_3_4_TEST_BLK_EN2, 0x01, 0x00);
  253. snd_soc_component_update_bits(component, WCD938X_SLEEP_CTL, 0x0E,
  254. ((snd_soc_component_read32(component,
  255. WCD938X_DIGITAL_EFUSE_REG_30) & 0x07) << 1));
  256. snd_soc_component_update_bits(component,
  257. WCD938X_HPH_SURGE_HPHLR_SURGE_EN, 0xC0, 0xC0);
  258. return 0;
  259. }
  260. static int wcd938x_set_port_params(struct snd_soc_component *component,
  261. u8 slv_prt_type, u8 *port_id, u8 *num_ch,
  262. u8 *ch_mask, u32 *ch_rate,
  263. u8 *port_type, u8 path)
  264. {
  265. int i, j;
  266. u8 num_ports = 0;
  267. struct codec_port_info (*map)[MAX_PORT][MAX_CH_PER_PORT];
  268. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  269. switch (path) {
  270. case CODEC_RX:
  271. map = &wcd938x->rx_port_mapping;
  272. num_ports = wcd938x->num_rx_ports;
  273. break;
  274. case CODEC_TX:
  275. map = &wcd938x->tx_port_mapping;
  276. num_ports = wcd938x->num_tx_ports;
  277. break;
  278. default:
  279. dev_err(component->dev, "%s Invalid path selected %u\n",
  280. __func__, path);
  281. return -EINVAL;
  282. }
  283. for (i = 0; i <= num_ports; i++) {
  284. for (j = 0; j < MAX_CH_PER_PORT; j++) {
  285. if ((*map)[i][j].slave_port_type == slv_prt_type)
  286. goto found;
  287. }
  288. }
  289. found:
  290. if (i > num_ports || j == MAX_CH_PER_PORT) {
  291. dev_err(component->dev, "%s Failed to find slave port for type %u\n",
  292. __func__, slv_prt_type);
  293. return -EINVAL;
  294. }
  295. *port_id = i;
  296. *num_ch = (*map)[i][j].num_ch;
  297. *ch_mask = (*map)[i][j].ch_mask;
  298. *ch_rate = (*map)[i][j].ch_rate;
  299. *port_type = (*map)[i][j].master_port_type;
  300. return 0;
  301. }
  302. static int wcd938x_parse_port_mapping(struct device *dev,
  303. char *prop, u8 path)
  304. {
  305. u32 *dt_array, map_size, map_length;
  306. u32 port_num = 0, ch_mask, ch_rate, old_port_num = 0;
  307. u32 slave_port_type, master_port_type;
  308. u32 i, ch_iter = 0;
  309. int ret = 0;
  310. u8 *num_ports = NULL;
  311. struct codec_port_info (*map)[MAX_PORT][MAX_CH_PER_PORT];
  312. struct wcd938x_priv *wcd938x = dev_get_drvdata(dev);
  313. switch (path) {
  314. case CODEC_RX:
  315. map = &wcd938x->rx_port_mapping;
  316. num_ports = &wcd938x->num_rx_ports;
  317. break;
  318. case CODEC_TX:
  319. map = &wcd938x->tx_port_mapping;
  320. num_ports = &wcd938x->num_tx_ports;
  321. break;
  322. default:
  323. dev_err(dev, "%s Invalid path selected %u\n",
  324. __func__, path);
  325. return -EINVAL;
  326. }
  327. if (!of_find_property(dev->of_node, prop,
  328. &map_size)) {
  329. dev_err(dev, "missing port mapping prop %s\n", prop);
  330. ret = -EINVAL;
  331. goto err_port_map;
  332. }
  333. map_length = map_size / (NUM_SWRS_DT_PARAMS * sizeof(u32));
  334. dt_array = kzalloc(map_size, GFP_KERNEL);
  335. if (!dt_array) {
  336. ret = -ENOMEM;
  337. goto err_alloc;
  338. }
  339. ret = of_property_read_u32_array(dev->of_node, prop, dt_array,
  340. NUM_SWRS_DT_PARAMS * map_length);
  341. if (ret) {
  342. dev_err(dev, "%s: Failed to read port mapping from prop %s\n",
  343. __func__, prop);
  344. goto err_pdata_fail;
  345. }
  346. for (i = 0; i < map_length; i++) {
  347. port_num = dt_array[NUM_SWRS_DT_PARAMS * i];
  348. slave_port_type = dt_array[NUM_SWRS_DT_PARAMS * i + 1];
  349. ch_mask = dt_array[NUM_SWRS_DT_PARAMS * i + 2];
  350. ch_rate = dt_array[NUM_SWRS_DT_PARAMS * i + 3];
  351. master_port_type = dt_array[NUM_SWRS_DT_PARAMS * i + 4];
  352. if (port_num != old_port_num)
  353. ch_iter = 0;
  354. (*map)[port_num][ch_iter].slave_port_type = slave_port_type;
  355. (*map)[port_num][ch_iter].ch_mask = ch_mask;
  356. (*map)[port_num][ch_iter].master_port_type = master_port_type;
  357. (*map)[port_num][ch_iter].num_ch = __sw_hweight8(ch_mask);
  358. (*map)[port_num][ch_iter++].ch_rate = ch_rate;
  359. old_port_num = port_num;
  360. }
  361. *num_ports = port_num;
  362. kfree(dt_array);
  363. return 0;
  364. err_pdata_fail:
  365. kfree(dt_array);
  366. err_alloc:
  367. err_port_map:
  368. return ret;
  369. }
  370. static int wcd938x_tx_connect_port(struct snd_soc_component *component,
  371. u8 slv_port_type, int clk_rate,
  372. u8 enable)
  373. {
  374. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  375. u8 port_id, num_ch, ch_mask;
  376. u8 ch_type = 0;
  377. u32 ch_rate;
  378. int slave_ch_idx;
  379. u8 num_port = 1;
  380. int ret = 0;
  381. ret = wcd938x_set_port_params(component, slv_port_type, &port_id,
  382. &num_ch, &ch_mask, &ch_rate,
  383. &ch_type, CODEC_TX);
  384. if (ret)
  385. return ret;
  386. if (clk_rate)
  387. ch_rate = clk_rate;
  388. slave_ch_idx = wcd938x_slave_get_slave_ch_val(slv_port_type);
  389. if (slave_ch_idx != -EINVAL)
  390. ch_type = wcd938x->tx_master_ch_map[slave_ch_idx];
  391. dev_dbg(component->dev, "%s slv_ch_idx: %d, mstr_ch_type: %d\n",
  392. __func__, slave_ch_idx, ch_type);
  393. if (enable)
  394. ret = swr_connect_port(wcd938x->tx_swr_dev, &port_id,
  395. num_port, &ch_mask, &ch_rate,
  396. &num_ch, &ch_type);
  397. else
  398. ret = swr_disconnect_port(wcd938x->tx_swr_dev, &port_id,
  399. num_port, &ch_mask, &ch_type);
  400. return ret;
  401. }
  402. static int wcd938x_rx_connect_port(struct snd_soc_component *component,
  403. u8 slv_port_type, u8 enable)
  404. {
  405. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  406. u8 port_id, num_ch, ch_mask, port_type;
  407. u32 ch_rate;
  408. u8 num_port = 1;
  409. int ret = 0;
  410. ret = wcd938x_set_port_params(component, slv_port_type, &port_id,
  411. &num_ch, &ch_mask, &ch_rate,
  412. &port_type, CODEC_RX);
  413. if (ret)
  414. return ret;
  415. if (enable)
  416. ret = swr_connect_port(wcd938x->rx_swr_dev, &port_id,
  417. num_port, &ch_mask, &ch_rate,
  418. &num_ch, &port_type);
  419. else
  420. ret = swr_disconnect_port(wcd938x->rx_swr_dev, &port_id,
  421. num_port, &ch_mask, &port_type);
  422. return ret;
  423. }
  424. static int wcd938x_rx_clk_enable(struct snd_soc_component *component)
  425. {
  426. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  427. if (wcd938x->rx_clk_cnt == 0) {
  428. snd_soc_component_update_bits(component,
  429. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x01, 0x01);
  430. snd_soc_component_update_bits(component,
  431. WCD938X_ANA_RX_SUPPLIES, 0x01, 0x01);
  432. snd_soc_component_update_bits(component,
  433. WCD938X_DIGITAL_CDC_RX0_CTL, 0x40, 0x00);
  434. snd_soc_component_update_bits(component,
  435. WCD938X_DIGITAL_CDC_RX1_CTL, 0x40, 0x00);
  436. snd_soc_component_update_bits(component,
  437. WCD938X_DIGITAL_CDC_RX2_CTL, 0x40, 0x00);
  438. snd_soc_component_update_bits(component,
  439. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x02, 0x02);
  440. snd_soc_component_update_bits(component,
  441. WCD938X_AUX_AUXPA, 0x10, 0x10);
  442. }
  443. wcd938x->rx_clk_cnt++;
  444. return 0;
  445. }
  446. static int wcd938x_rx_clk_disable(struct snd_soc_component *component)
  447. {
  448. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  449. wcd938x->rx_clk_cnt--;
  450. if (wcd938x->rx_clk_cnt == 0) {
  451. snd_soc_component_update_bits(component,
  452. WCD938X_ANA_RX_SUPPLIES, 0x40, 0x00);
  453. snd_soc_component_update_bits(component,
  454. WCD938X_ANA_RX_SUPPLIES, 0x80, 0x00);
  455. snd_soc_component_update_bits(component,
  456. WCD938X_ANA_RX_SUPPLIES, 0x01, 0x00);
  457. snd_soc_component_update_bits(component,
  458. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x02, 0x00);
  459. snd_soc_component_update_bits(component,
  460. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x01, 0x00);
  461. }
  462. return 0;
  463. }
  464. /*
  465. * wcd938x_soc_get_mbhc: get wcd938x_mbhc handle of corresponding component
  466. * @component: handle to snd_soc_component *
  467. *
  468. * return wcd938x_mbhc handle or error code in case of failure
  469. */
  470. struct wcd938x_mbhc *wcd938x_soc_get_mbhc(struct snd_soc_component *component)
  471. {
  472. struct wcd938x_priv *wcd938x;
  473. if (!component) {
  474. pr_err("%s: Invalid params, NULL component\n", __func__);
  475. return NULL;
  476. }
  477. wcd938x = snd_soc_component_get_drvdata(component);
  478. if (!wcd938x) {
  479. pr_err("%s: wcd938x is NULL\n", __func__);
  480. return NULL;
  481. }
  482. return wcd938x->mbhc;
  483. }
  484. EXPORT_SYMBOL(wcd938x_soc_get_mbhc);
  485. static int wcd938x_codec_hphl_dac_event(struct snd_soc_dapm_widget *w,
  486. struct snd_kcontrol *kcontrol,
  487. int event)
  488. {
  489. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  490. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  491. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  492. w->name, event);
  493. switch (event) {
  494. case SND_SOC_DAPM_PRE_PMU:
  495. wcd938x_rx_clk_enable(component);
  496. snd_soc_component_update_bits(component,
  497. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x01, 0x01);
  498. snd_soc_component_update_bits(component,
  499. WCD938X_DIGITAL_CDC_HPH_GAIN_CTL, 0x04, 0x04);
  500. snd_soc_component_update_bits(component,
  501. WCD938X_HPH_RDAC_CLK_CTL1, 0x80, 0x00);
  502. break;
  503. case SND_SOC_DAPM_POST_PMU:
  504. snd_soc_component_update_bits(component,
  505. WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_L, 0x0F, 0x02);
  506. if (wcd938x->comp1_enable) {
  507. snd_soc_component_update_bits(component,
  508. WCD938X_DIGITAL_CDC_COMP_CTL_0, 0x02, 0x02);
  509. /* 5msec compander delay as per HW requirement */
  510. if (!wcd938x->comp2_enable ||
  511. (snd_soc_component_read32(component,
  512. WCD938X_DIGITAL_CDC_COMP_CTL_0) & 0x01))
  513. usleep_range(5000, 5010);
  514. snd_soc_component_update_bits(component,
  515. WCD938X_HPH_NEW_INT_HPH_TIMER1, 0x02, 0x00);
  516. } else {
  517. snd_soc_component_update_bits(component,
  518. WCD938X_DIGITAL_CDC_COMP_CTL_0,
  519. 0x02, 0x00);
  520. snd_soc_component_update_bits(component,
  521. WCD938X_HPH_L_EN, 0x20, 0x20);
  522. }
  523. break;
  524. case SND_SOC_DAPM_POST_PMD:
  525. snd_soc_component_update_bits(component,
  526. WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_R,
  527. 0x0F, 0x01);
  528. break;
  529. }
  530. return 0;
  531. }
  532. static int wcd938x_codec_hphr_dac_event(struct snd_soc_dapm_widget *w,
  533. struct snd_kcontrol *kcontrol,
  534. int event)
  535. {
  536. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  537. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  538. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  539. w->name, event);
  540. switch (event) {
  541. case SND_SOC_DAPM_PRE_PMU:
  542. wcd938x_rx_clk_enable(component);
  543. snd_soc_component_update_bits(component,
  544. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x02, 0x02);
  545. snd_soc_component_update_bits(component,
  546. WCD938X_DIGITAL_CDC_HPH_GAIN_CTL, 0x08, 0x08);
  547. snd_soc_component_update_bits(component,
  548. WCD938X_HPH_RDAC_CLK_CTL1, 0x80, 0x00);
  549. break;
  550. case SND_SOC_DAPM_POST_PMU:
  551. snd_soc_component_update_bits(component,
  552. WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_R, 0x0F, 0x02);
  553. if (wcd938x->comp2_enable) {
  554. snd_soc_component_update_bits(component,
  555. WCD938X_DIGITAL_CDC_COMP_CTL_0, 0x01, 0x01);
  556. /* 5msec compander delay as per HW requirement */
  557. if (!wcd938x->comp1_enable ||
  558. (snd_soc_component_read32(component,
  559. WCD938X_DIGITAL_CDC_COMP_CTL_0) & 0x02))
  560. usleep_range(5000, 5010);
  561. snd_soc_component_update_bits(component,
  562. WCD938X_HPH_NEW_INT_HPH_TIMER1, 0x02, 0x00);
  563. } else {
  564. snd_soc_component_update_bits(component,
  565. WCD938X_DIGITAL_CDC_COMP_CTL_0,
  566. 0x01, 0x00);
  567. snd_soc_component_update_bits(component,
  568. WCD938X_HPH_R_EN, 0x20, 0x20);
  569. }
  570. break;
  571. case SND_SOC_DAPM_POST_PMD:
  572. snd_soc_component_update_bits(component,
  573. WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_R,
  574. 0x0F, 0x01);
  575. break;
  576. }
  577. return 0;
  578. }
  579. static int wcd938x_codec_ear_dac_event(struct snd_soc_dapm_widget *w,
  580. struct snd_kcontrol *kcontrol,
  581. int event)
  582. {
  583. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  584. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  585. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  586. w->name, event);
  587. switch (event) {
  588. case SND_SOC_DAPM_PRE_PMU:
  589. wcd938x_rx_clk_enable(component);
  590. wcd938x->ear_rx_path =
  591. snd_soc_component_read32(
  592. component, WCD938X_DIGITAL_CDC_EAR_PATH_CTL);
  593. if (wcd938x->ear_rx_path & EAR_RX_PATH_AUX) {
  594. snd_soc_component_update_bits(component,
  595. WCD938X_EAR_EAR_DAC_CON, 0x80, 0x00);
  596. snd_soc_component_update_bits(component,
  597. WCD938X_DIGITAL_CDC_AUX_GAIN_CTL, 0x01, 0x01);
  598. snd_soc_component_update_bits(component,
  599. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x04, 0x04);
  600. snd_soc_component_update_bits(component,
  601. WCD938X_ANA_EAR_COMPANDER_CTL, 0x80, 0x80);
  602. } else {
  603. snd_soc_component_update_bits(component,
  604. WCD938X_DIGITAL_CDC_HPH_GAIN_CTL, 0x04, 0x04);
  605. snd_soc_component_update_bits(component,
  606. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x01, 0x01);
  607. if (wcd938x->comp1_enable)
  608. snd_soc_component_update_bits(component,
  609. WCD938X_DIGITAL_CDC_COMP_CTL_0,
  610. 0x02, 0x02);
  611. }
  612. /* 5 msec delay as per HW requirement */
  613. usleep_range(5000, 5010);
  614. if (wcd938x->flyback_cur_det_disable == 0)
  615. snd_soc_component_update_bits(component,
  616. WCD938X_FLYBACK_EN,
  617. 0x04, 0x00);
  618. wcd938x->flyback_cur_det_disable++;
  619. wcd_cls_h_fsm(component, &wcd938x->clsh_info,
  620. WCD_CLSH_EVENT_PRE_DAC,
  621. WCD_CLSH_STATE_EAR,
  622. wcd938x->hph_mode);
  623. break;
  624. case SND_SOC_DAPM_POST_PMD:
  625. if (wcd938x->ear_rx_path & EAR_RX_PATH_AUX) {
  626. snd_soc_component_update_bits(component,
  627. WCD938X_DIGITAL_CDC_AUX_GAIN_CTL, 0x01, 0x00);
  628. snd_soc_component_update_bits(component,
  629. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x04, 0x00);
  630. } else {
  631. snd_soc_component_update_bits(component,
  632. WCD938X_DIGITAL_CDC_HPH_GAIN_CTL, 0x04, 0x00);
  633. snd_soc_component_update_bits(component,
  634. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x01, 0x00);
  635. if (wcd938x->comp1_enable)
  636. snd_soc_component_update_bits(component,
  637. WCD938X_DIGITAL_CDC_COMP_CTL_0,
  638. 0x02, 0x00);
  639. }
  640. snd_soc_component_update_bits(component,
  641. WCD938X_ANA_EAR_COMPANDER_CTL, 0x80, 0x00);
  642. snd_soc_component_update_bits(component,
  643. WCD938X_EAR_EAR_DAC_CON, 0x80, 0x80);
  644. break;
  645. };
  646. return 0;
  647. }
  648. static int wcd938x_codec_aux_dac_event(struct snd_soc_dapm_widget *w,
  649. struct snd_kcontrol *kcontrol,
  650. int event)
  651. {
  652. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  653. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  654. int ret = 0;
  655. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  656. w->name, event);
  657. switch (event) {
  658. case SND_SOC_DAPM_PRE_PMU:
  659. wcd938x_rx_clk_enable(component);
  660. snd_soc_component_update_bits(component,
  661. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x04, 0x04);
  662. snd_soc_component_update_bits(component,
  663. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x04, 0x04);
  664. snd_soc_component_update_bits(component,
  665. WCD938X_DIGITAL_CDC_AUX_GAIN_CTL, 0x01, 0x01);
  666. if (wcd938x->flyback_cur_det_disable == 0)
  667. snd_soc_component_update_bits(component,
  668. WCD938X_FLYBACK_EN,
  669. 0x04, 0x00);
  670. wcd938x->flyback_cur_det_disable++;
  671. wcd_cls_h_fsm(component, &wcd938x->clsh_info,
  672. WCD_CLSH_EVENT_PRE_DAC,
  673. WCD_CLSH_STATE_AUX,
  674. wcd938x->hph_mode);
  675. break;
  676. case SND_SOC_DAPM_POST_PMD:
  677. snd_soc_component_update_bits(component,
  678. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x04, 0x00);
  679. break;
  680. };
  681. return ret;
  682. }
  683. static int wcd938x_codec_enable_hphr_pa(struct snd_soc_dapm_widget *w,
  684. struct snd_kcontrol *kcontrol,
  685. int event)
  686. {
  687. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  688. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  689. int ret = 0;
  690. int hph_mode = wcd938x->hph_mode;
  691. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  692. w->name, event);
  693. switch (event) {
  694. case SND_SOC_DAPM_PRE_PMU:
  695. if (wcd938x->ldoh)
  696. snd_soc_component_update_bits(component,
  697. WCD938X_LDOH_MODE,
  698. 0x80, 0x80);
  699. if (wcd938x->update_wcd_event)
  700. wcd938x->update_wcd_event(wcd938x->handle,
  701. WCD_BOLERO_EVT_RX_MUTE,
  702. (WCD_RX2 << 0x10 | 0x1));
  703. ret = swr_slvdev_datapath_control(wcd938x->rx_swr_dev,
  704. wcd938x->rx_swr_dev->dev_num,
  705. true);
  706. wcd_cls_h_fsm(component, &wcd938x->clsh_info,
  707. WCD_CLSH_EVENT_PRE_DAC,
  708. WCD_CLSH_STATE_HPHR,
  709. hph_mode);
  710. wcd_clsh_set_hph_mode(component, CLS_H_HIFI);
  711. if (hph_mode == CLS_H_LP || hph_mode == CLS_H_LOHIFI ||
  712. hph_mode == CLS_H_ULP) {
  713. snd_soc_component_update_bits(component,
  714. WCD938X_HPH_REFBUFF_LP_CTL, 0x01, 0x01);
  715. }
  716. snd_soc_component_update_bits(component, WCD938X_ANA_HPH,
  717. 0x10, 0x10);
  718. wcd_clsh_set_hph_mode(component, hph_mode);
  719. /* 100 usec delay as per HW requirement */
  720. usleep_range(100, 110);
  721. set_bit(HPH_PA_DELAY, &wcd938x->status_mask);
  722. snd_soc_component_update_bits(component,
  723. WCD938X_DIGITAL_PDM_WD_CTL1, 0x07, 0x03);
  724. break;
  725. case SND_SOC_DAPM_POST_PMU:
  726. /*
  727. * 7ms sleep is required if compander is enabled as per
  728. * HW requirement. If compander is disabled, then
  729. * 20ms delay is required.
  730. */
  731. if (test_bit(HPH_PA_DELAY, &wcd938x->status_mask)) {
  732. if (!wcd938x->comp2_enable)
  733. usleep_range(20000, 20100);
  734. else
  735. usleep_range(7000, 7100);
  736. if (hph_mode == CLS_H_LP ||
  737. hph_mode == CLS_H_LOHIFI ||
  738. hph_mode == CLS_H_ULP)
  739. snd_soc_component_update_bits(component,
  740. WCD938X_HPH_REFBUFF_LP_CTL, 0x01,
  741. 0x00);
  742. clear_bit(HPH_PA_DELAY, &wcd938x->status_mask);
  743. }
  744. snd_soc_component_update_bits(component,
  745. WCD938X_HPH_NEW_INT_HPH_TIMER1, 0x02, 0x02);
  746. if (hph_mode == CLS_AB || hph_mode == CLS_AB_HIFI ||
  747. hph_mode == CLS_AB_LP || hph_mode == CLS_AB_LOHIFI)
  748. snd_soc_component_update_bits(component,
  749. WCD938X_ANA_RX_SUPPLIES, 0x02, 0x02);
  750. if (wcd938x->update_wcd_event)
  751. wcd938x->update_wcd_event(wcd938x->handle,
  752. WCD_BOLERO_EVT_RX_MUTE,
  753. (WCD_RX2 << 0x10));
  754. wcd_enable_irq(&wcd938x->irq_info,
  755. WCD938X_IRQ_HPHR_PDM_WD_INT);
  756. break;
  757. case SND_SOC_DAPM_PRE_PMD:
  758. if (wcd938x->update_wcd_event)
  759. wcd938x->update_wcd_event(wcd938x->handle,
  760. WCD_BOLERO_EVT_RX_MUTE,
  761. (WCD_RX2 << 0x10 | 0x1));
  762. wcd_disable_irq(&wcd938x->irq_info,
  763. WCD938X_IRQ_HPHR_PDM_WD_INT);
  764. if (wcd938x->update_wcd_event && wcd938x->comp2_enable)
  765. wcd938x->update_wcd_event(wcd938x->handle,
  766. WCD_BOLERO_EVT_RX_COMPANDER_SOFT_RST,
  767. (WCD_RX2 << 0x10));
  768. /*
  769. * 7ms sleep is required if compander is enabled as per
  770. * HW requirement. If compander is disabled, then
  771. * 20ms delay is required.
  772. */
  773. if (!wcd938x->comp2_enable)
  774. usleep_range(20000, 20100);
  775. else
  776. usleep_range(7000, 7100);
  777. snd_soc_component_update_bits(component, WCD938X_ANA_HPH,
  778. 0x40, 0x00);
  779. blocking_notifier_call_chain(&wcd938x->mbhc->notifier,
  780. WCD_EVENT_PRE_HPHR_PA_OFF,
  781. &wcd938x->mbhc->wcd_mbhc);
  782. set_bit(HPH_PA_DELAY, &wcd938x->status_mask);
  783. break;
  784. case SND_SOC_DAPM_POST_PMD:
  785. /*
  786. * 7ms sleep is required if compander is enabled as per
  787. * HW requirement. If compander is disabled, then
  788. * 20ms delay is required.
  789. */
  790. if (test_bit(HPH_PA_DELAY, &wcd938x->status_mask)) {
  791. if (!wcd938x->comp2_enable)
  792. usleep_range(20000, 20100);
  793. else
  794. usleep_range(7000, 7100);
  795. clear_bit(HPH_PA_DELAY, &wcd938x->status_mask);
  796. }
  797. blocking_notifier_call_chain(&wcd938x->mbhc->notifier,
  798. WCD_EVENT_POST_HPHR_PA_OFF,
  799. &wcd938x->mbhc->wcd_mbhc);
  800. snd_soc_component_update_bits(component, WCD938X_ANA_HPH,
  801. 0x10, 0x00);
  802. snd_soc_component_update_bits(component,
  803. WCD938X_DIGITAL_PDM_WD_CTL1, 0x07, 0x00);
  804. wcd_cls_h_fsm(component, &wcd938x->clsh_info,
  805. WCD_CLSH_EVENT_POST_PA,
  806. WCD_CLSH_STATE_HPHR,
  807. hph_mode);
  808. if (wcd938x->ldoh)
  809. snd_soc_component_update_bits(component,
  810. WCD938X_LDOH_MODE,
  811. 0x80, 0x00);
  812. break;
  813. };
  814. return ret;
  815. }
  816. static int wcd938x_codec_enable_hphl_pa(struct snd_soc_dapm_widget *w,
  817. struct snd_kcontrol *kcontrol,
  818. int event)
  819. {
  820. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  821. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  822. int ret = 0;
  823. int hph_mode = wcd938x->hph_mode;
  824. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  825. w->name, event);
  826. switch (event) {
  827. case SND_SOC_DAPM_PRE_PMU:
  828. if (wcd938x->ldoh)
  829. snd_soc_component_update_bits(component,
  830. WCD938X_LDOH_MODE,
  831. 0x80, 0x80);
  832. if (wcd938x->update_wcd_event)
  833. wcd938x->update_wcd_event(wcd938x->handle,
  834. WCD_BOLERO_EVT_RX_MUTE,
  835. (WCD_RX1 << 0x10 | 0x01));
  836. ret = swr_slvdev_datapath_control(wcd938x->rx_swr_dev,
  837. wcd938x->rx_swr_dev->dev_num,
  838. true);
  839. wcd_cls_h_fsm(component, &wcd938x->clsh_info,
  840. WCD_CLSH_EVENT_PRE_DAC,
  841. WCD_CLSH_STATE_HPHL,
  842. hph_mode);
  843. wcd_clsh_set_hph_mode(component, CLS_H_HIFI);
  844. if (hph_mode == CLS_H_LP || hph_mode == CLS_H_LOHIFI ||
  845. hph_mode == CLS_H_ULP) {
  846. snd_soc_component_update_bits(component,
  847. WCD938X_HPH_REFBUFF_LP_CTL, 0x01, 0x01);
  848. }
  849. snd_soc_component_update_bits(component, WCD938X_ANA_HPH,
  850. 0x20, 0x20);
  851. wcd_clsh_set_hph_mode(component, hph_mode);
  852. /* 100 usec delay as per HW requirement */
  853. usleep_range(100, 110);
  854. set_bit(HPH_PA_DELAY, &wcd938x->status_mask);
  855. snd_soc_component_update_bits(component,
  856. WCD938X_DIGITAL_PDM_WD_CTL0, 0x07, 0x03);
  857. break;
  858. case SND_SOC_DAPM_POST_PMU:
  859. /*
  860. * 7ms sleep is required if compander is enabled as per
  861. * HW requirement. If compander is disabled, then
  862. * 20ms delay is required.
  863. */
  864. if (test_bit(HPH_PA_DELAY, &wcd938x->status_mask)) {
  865. if (!wcd938x->comp1_enable)
  866. usleep_range(20000, 20100);
  867. else
  868. usleep_range(7000, 7100);
  869. if (hph_mode == CLS_H_LP ||
  870. hph_mode == CLS_H_LOHIFI ||
  871. hph_mode == CLS_H_ULP)
  872. snd_soc_component_update_bits(component,
  873. WCD938X_HPH_REFBUFF_LP_CTL,
  874. 0x01, 0x00);
  875. clear_bit(HPH_PA_DELAY, &wcd938x->status_mask);
  876. }
  877. snd_soc_component_update_bits(component,
  878. WCD938X_HPH_NEW_INT_HPH_TIMER1, 0x02, 0x02);
  879. if (hph_mode == CLS_AB || hph_mode == CLS_AB_HIFI ||
  880. hph_mode == CLS_AB_LP || hph_mode == CLS_AB_LOHIFI)
  881. snd_soc_component_update_bits(component,
  882. WCD938X_ANA_RX_SUPPLIES, 0x02, 0x02);
  883. if (wcd938x->update_wcd_event)
  884. wcd938x->update_wcd_event(wcd938x->handle,
  885. WCD_BOLERO_EVT_RX_MUTE,
  886. (WCD_RX1 << 0x10));
  887. wcd_enable_irq(&wcd938x->irq_info,
  888. WCD938X_IRQ_HPHL_PDM_WD_INT);
  889. break;
  890. case SND_SOC_DAPM_PRE_PMD:
  891. if (wcd938x->update_wcd_event)
  892. wcd938x->update_wcd_event(wcd938x->handle,
  893. WCD_BOLERO_EVT_RX_MUTE,
  894. (WCD_RX1 << 0x10 | 0x1));
  895. wcd_disable_irq(&wcd938x->irq_info,
  896. WCD938X_IRQ_HPHL_PDM_WD_INT);
  897. if (wcd938x->update_wcd_event && wcd938x->comp1_enable)
  898. wcd938x->update_wcd_event(wcd938x->handle,
  899. WCD_BOLERO_EVT_RX_COMPANDER_SOFT_RST,
  900. (WCD_RX1 << 0x10));
  901. /*
  902. * 7ms sleep is required if compander is enabled as per
  903. * HW requirement. If compander is disabled, then
  904. * 20ms delay is required.
  905. */
  906. if (!wcd938x->comp1_enable)
  907. usleep_range(20000, 20100);
  908. else
  909. usleep_range(7000, 7100);
  910. snd_soc_component_update_bits(component, WCD938X_ANA_HPH,
  911. 0x80, 0x00);
  912. blocking_notifier_call_chain(&wcd938x->mbhc->notifier,
  913. WCD_EVENT_PRE_HPHL_PA_OFF,
  914. &wcd938x->mbhc->wcd_mbhc);
  915. set_bit(HPH_PA_DELAY, &wcd938x->status_mask);
  916. break;
  917. case SND_SOC_DAPM_POST_PMD:
  918. /*
  919. * 7ms sleep is required if compander is enabled as per
  920. * HW requirement. If compander is disabled, then
  921. * 20ms delay is required.
  922. */
  923. if (test_bit(HPH_PA_DELAY, &wcd938x->status_mask)) {
  924. if (!wcd938x->comp1_enable)
  925. usleep_range(21000, 21100);
  926. else
  927. usleep_range(7000, 7100);
  928. clear_bit(HPH_PA_DELAY, &wcd938x->status_mask);
  929. }
  930. blocking_notifier_call_chain(&wcd938x->mbhc->notifier,
  931. WCD_EVENT_POST_HPHL_PA_OFF,
  932. &wcd938x->mbhc->wcd_mbhc);
  933. snd_soc_component_update_bits(component, WCD938X_ANA_HPH,
  934. 0x20, 0x00);
  935. snd_soc_component_update_bits(component,
  936. WCD938X_DIGITAL_PDM_WD_CTL0, 0x07, 0x00);
  937. wcd_cls_h_fsm(component, &wcd938x->clsh_info,
  938. WCD_CLSH_EVENT_POST_PA,
  939. WCD_CLSH_STATE_HPHL,
  940. hph_mode);
  941. if (wcd938x->ldoh)
  942. snd_soc_component_update_bits(component,
  943. WCD938X_LDOH_MODE,
  944. 0x80, 0x00);
  945. break;
  946. };
  947. return ret;
  948. }
  949. static int wcd938x_codec_enable_aux_pa(struct snd_soc_dapm_widget *w,
  950. struct snd_kcontrol *kcontrol,
  951. int event)
  952. {
  953. struct snd_soc_component *component =
  954. snd_soc_dapm_to_component(w->dapm);
  955. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  956. int hph_mode = wcd938x->hph_mode;
  957. int ret = 0;
  958. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  959. w->name, event);
  960. switch (event) {
  961. case SND_SOC_DAPM_PRE_PMU:
  962. ret = swr_slvdev_datapath_control(wcd938x->rx_swr_dev,
  963. wcd938x->rx_swr_dev->dev_num,
  964. true);
  965. snd_soc_component_update_bits(component,
  966. WCD938X_DIGITAL_PDM_WD_CTL2, 0x01, 0x01);
  967. break;
  968. case SND_SOC_DAPM_POST_PMU:
  969. /* 1 msec delay as per HW requirement */
  970. usleep_range(1000, 1010);
  971. if (hph_mode == CLS_AB || hph_mode == CLS_AB_HIFI ||
  972. hph_mode == CLS_AB_LP || hph_mode == CLS_AB_LOHIFI)
  973. snd_soc_component_update_bits(component,
  974. WCD938X_ANA_RX_SUPPLIES,
  975. 0x02, 0x02);
  976. if (wcd938x->update_wcd_event)
  977. wcd938x->update_wcd_event(wcd938x->handle,
  978. WCD_BOLERO_EVT_RX_MUTE,
  979. (WCD_RX3 << 0x10));
  980. wcd_enable_irq(&wcd938x->irq_info, WCD938X_IRQ_AUX_PDM_WD_INT);
  981. break;
  982. case SND_SOC_DAPM_PRE_PMD:
  983. wcd_disable_irq(&wcd938x->irq_info,
  984. WCD938X_IRQ_AUX_PDM_WD_INT);
  985. if (wcd938x->update_wcd_event)
  986. wcd938x->update_wcd_event(wcd938x->handle,
  987. WCD_BOLERO_EVT_RX_MUTE,
  988. (WCD_RX3 << 0x10 | 0x1));
  989. break;
  990. case SND_SOC_DAPM_POST_PMD:
  991. /* 1 msec delay as per HW requirement */
  992. usleep_range(1000, 1010);
  993. snd_soc_component_update_bits(component,
  994. WCD938X_DIGITAL_PDM_WD_CTL2, 0x01, 0x00);
  995. wcd_cls_h_fsm(component, &wcd938x->clsh_info,
  996. WCD_CLSH_EVENT_POST_PA,
  997. WCD_CLSH_STATE_AUX,
  998. hph_mode);
  999. wcd938x->flyback_cur_det_disable--;
  1000. if (wcd938x->flyback_cur_det_disable == 0)
  1001. snd_soc_component_update_bits(component,
  1002. WCD938X_FLYBACK_EN,
  1003. 0x04, 0x04);
  1004. break;
  1005. };
  1006. return ret;
  1007. }
  1008. static int wcd938x_codec_enable_ear_pa(struct snd_soc_dapm_widget *w,
  1009. struct snd_kcontrol *kcontrol,
  1010. int event)
  1011. {
  1012. struct snd_soc_component *component =
  1013. snd_soc_dapm_to_component(w->dapm);
  1014. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1015. int hph_mode = wcd938x->hph_mode;
  1016. int ret = 0;
  1017. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1018. w->name, event);
  1019. switch (event) {
  1020. case SND_SOC_DAPM_PRE_PMU:
  1021. ret = swr_slvdev_datapath_control(wcd938x->rx_swr_dev,
  1022. wcd938x->rx_swr_dev->dev_num,
  1023. true);
  1024. /*
  1025. * Enable watchdog interrupt for HPHL or AUX
  1026. * depending on mux value
  1027. */
  1028. wcd938x->ear_rx_path =
  1029. snd_soc_component_read32(
  1030. component, WCD938X_DIGITAL_CDC_EAR_PATH_CTL);
  1031. if (wcd938x->ear_rx_path & EAR_RX_PATH_AUX)
  1032. snd_soc_component_update_bits(component,
  1033. WCD938X_DIGITAL_PDM_WD_CTL2,
  1034. 0x01, 0x01);
  1035. else
  1036. snd_soc_component_update_bits(component,
  1037. WCD938X_DIGITAL_PDM_WD_CTL0,
  1038. 0x07, 0x03);
  1039. if (!wcd938x->comp1_enable)
  1040. snd_soc_component_update_bits(component,
  1041. WCD938X_ANA_EAR_COMPANDER_CTL, 0x80, 0x80);
  1042. break;
  1043. case SND_SOC_DAPM_POST_PMU:
  1044. /* 6 msec delay as per HW requirement */
  1045. usleep_range(6000, 6010);
  1046. if (hph_mode == CLS_AB || hph_mode == CLS_AB_HIFI ||
  1047. hph_mode == CLS_AB_LP || hph_mode == CLS_AB_LOHIFI)
  1048. snd_soc_component_update_bits(component,
  1049. WCD938X_ANA_RX_SUPPLIES,
  1050. 0x02, 0x02);
  1051. if (wcd938x->ear_rx_path & EAR_RX_PATH_AUX) {
  1052. if (wcd938x->update_wcd_event)
  1053. wcd938x->update_wcd_event(wcd938x->handle,
  1054. WCD_BOLERO_EVT_RX_MUTE,
  1055. (WCD_RX3 << 0x10));
  1056. wcd_enable_irq(&wcd938x->irq_info,
  1057. WCD938X_IRQ_AUX_PDM_WD_INT);
  1058. } else {
  1059. if (wcd938x->update_wcd_event)
  1060. wcd938x->update_wcd_event(wcd938x->handle,
  1061. WCD_BOLERO_EVT_RX_MUTE,
  1062. (WCD_RX1 << 0x10));
  1063. wcd_enable_irq(&wcd938x->irq_info,
  1064. WCD938X_IRQ_HPHL_PDM_WD_INT);
  1065. }
  1066. break;
  1067. case SND_SOC_DAPM_PRE_PMD:
  1068. if (wcd938x->ear_rx_path & EAR_RX_PATH_AUX) {
  1069. wcd_disable_irq(&wcd938x->irq_info,
  1070. WCD938X_IRQ_AUX_PDM_WD_INT);
  1071. if (wcd938x->update_wcd_event)
  1072. wcd938x->update_wcd_event(wcd938x->handle,
  1073. WCD_BOLERO_EVT_RX_MUTE,
  1074. (WCD_RX3 << 0x10 | 0x1));
  1075. } else {
  1076. wcd_disable_irq(&wcd938x->irq_info,
  1077. WCD938X_IRQ_HPHL_PDM_WD_INT);
  1078. if (wcd938x->update_wcd_event)
  1079. wcd938x->update_wcd_event(wcd938x->handle,
  1080. WCD_BOLERO_EVT_RX_MUTE,
  1081. (WCD_RX1 << 0x10 | 0x1));
  1082. }
  1083. break;
  1084. case SND_SOC_DAPM_POST_PMD:
  1085. if (!wcd938x->comp1_enable)
  1086. snd_soc_component_update_bits(component,
  1087. WCD938X_ANA_EAR_COMPANDER_CTL, 0x80, 0x00);
  1088. /* 7 msec delay as per HW requirement */
  1089. usleep_range(7000, 7010);
  1090. if (wcd938x->ear_rx_path & EAR_RX_PATH_AUX)
  1091. snd_soc_component_update_bits(component,
  1092. WCD938X_DIGITAL_PDM_WD_CTL2,
  1093. 0x01, 0x00);
  1094. else
  1095. snd_soc_component_update_bits(component,
  1096. WCD938X_DIGITAL_PDM_WD_CTL0,
  1097. 0x07, 0x00);
  1098. wcd_cls_h_fsm(component, &wcd938x->clsh_info,
  1099. WCD_CLSH_EVENT_POST_PA,
  1100. WCD_CLSH_STATE_EAR,
  1101. hph_mode);
  1102. wcd938x->flyback_cur_det_disable--;
  1103. if (wcd938x->flyback_cur_det_disable == 0)
  1104. snd_soc_component_update_bits(component,
  1105. WCD938X_FLYBACK_EN,
  1106. 0x04, 0x04);
  1107. break;
  1108. };
  1109. return ret;
  1110. }
  1111. static int wcd938x_enable_clsh(struct snd_soc_dapm_widget *w,
  1112. struct snd_kcontrol *kcontrol,
  1113. int event)
  1114. {
  1115. struct snd_soc_component *component =
  1116. snd_soc_dapm_to_component(w->dapm);
  1117. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1118. int mode = wcd938x->hph_mode;
  1119. int ret = 0;
  1120. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1121. w->name, event);
  1122. if (mode == CLS_H_LOHIFI || mode == CLS_H_ULP ||
  1123. mode == CLS_H_HIFI || mode == CLS_H_LP) {
  1124. wcd938x_rx_connect_port(component, CLSH,
  1125. SND_SOC_DAPM_EVENT_ON(event));
  1126. }
  1127. if (SND_SOC_DAPM_EVENT_OFF(event))
  1128. ret = swr_slvdev_datapath_control(
  1129. wcd938x->rx_swr_dev,
  1130. wcd938x->rx_swr_dev->dev_num,
  1131. false);
  1132. return ret;
  1133. }
  1134. static int wcd938x_enable_rx1(struct snd_soc_dapm_widget *w,
  1135. struct snd_kcontrol *kcontrol,
  1136. int event)
  1137. {
  1138. struct snd_soc_component *component =
  1139. snd_soc_dapm_to_component(w->dapm);
  1140. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1141. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1142. w->name, event);
  1143. switch (event) {
  1144. case SND_SOC_DAPM_PRE_PMU:
  1145. wcd938x_rx_connect_port(component, HPH_L, true);
  1146. if (wcd938x->comp1_enable)
  1147. wcd938x_rx_connect_port(component, COMP_L, true);
  1148. break;
  1149. case SND_SOC_DAPM_POST_PMD:
  1150. wcd938x_rx_connect_port(component, HPH_L, false);
  1151. if (wcd938x->comp1_enable)
  1152. wcd938x_rx_connect_port(component, COMP_L, false);
  1153. wcd938x_rx_clk_disable(component);
  1154. snd_soc_component_update_bits(component,
  1155. WCD938X_DIGITAL_CDC_DIG_CLK_CTL,
  1156. 0x01, 0x00);
  1157. break;
  1158. };
  1159. return 0;
  1160. }
  1161. static int wcd938x_enable_rx2(struct snd_soc_dapm_widget *w,
  1162. struct snd_kcontrol *kcontrol, int event)
  1163. {
  1164. struct snd_soc_component *component =
  1165. snd_soc_dapm_to_component(w->dapm);
  1166. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1167. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1168. w->name, event);
  1169. switch (event) {
  1170. case SND_SOC_DAPM_PRE_PMU:
  1171. wcd938x_rx_connect_port(component, HPH_R, true);
  1172. if (wcd938x->comp2_enable)
  1173. wcd938x_rx_connect_port(component, COMP_R, true);
  1174. break;
  1175. case SND_SOC_DAPM_POST_PMD:
  1176. wcd938x_rx_connect_port(component, HPH_R, false);
  1177. if (wcd938x->comp2_enable)
  1178. wcd938x_rx_connect_port(component, COMP_R, false);
  1179. wcd938x_rx_clk_disable(component);
  1180. snd_soc_component_update_bits(component,
  1181. WCD938X_DIGITAL_CDC_DIG_CLK_CTL,
  1182. 0x02, 0x00);
  1183. break;
  1184. };
  1185. return 0;
  1186. }
  1187. static int wcd938x_enable_rx3(struct snd_soc_dapm_widget *w,
  1188. struct snd_kcontrol *kcontrol,
  1189. int event)
  1190. {
  1191. struct snd_soc_component *component =
  1192. snd_soc_dapm_to_component(w->dapm);
  1193. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1194. w->name, event);
  1195. switch (event) {
  1196. case SND_SOC_DAPM_PRE_PMU:
  1197. wcd938x_rx_connect_port(component, LO, true);
  1198. break;
  1199. case SND_SOC_DAPM_POST_PMD:
  1200. wcd938x_rx_connect_port(component, LO, false);
  1201. /* 6 msec delay as per HW requirement */
  1202. usleep_range(6000, 6010);
  1203. wcd938x_rx_clk_disable(component);
  1204. snd_soc_component_update_bits(component,
  1205. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x04, 0x00);
  1206. break;
  1207. }
  1208. return 0;
  1209. }
  1210. static int wcd938x_codec_enable_dmic(struct snd_soc_dapm_widget *w,
  1211. struct snd_kcontrol *kcontrol,
  1212. int event)
  1213. {
  1214. struct snd_soc_component *component =
  1215. snd_soc_dapm_to_component(w->dapm);
  1216. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1217. u16 dmic_clk_reg, dmic_clk_en_reg;
  1218. s32 *dmic_clk_cnt;
  1219. u8 dmic_ctl_shift = 0;
  1220. u8 dmic_clk_shift = 0;
  1221. u8 dmic_clk_mask = 0;
  1222. u16 dmic2_left_en = 0;
  1223. int ret = 0;
  1224. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1225. w->name, event);
  1226. switch (w->shift) {
  1227. case 0:
  1228. case 1:
  1229. dmic_clk_cnt = &(wcd938x->dmic_0_1_clk_cnt);
  1230. dmic_clk_reg = WCD938X_DIGITAL_CDC_DMIC_RATE_1_2;
  1231. dmic_clk_en_reg = WCD938X_DIGITAL_CDC_DMIC1_CTL;
  1232. dmic_clk_mask = 0x0F;
  1233. dmic_clk_shift = 0x00;
  1234. dmic_ctl_shift = 0x00;
  1235. break;
  1236. case 2:
  1237. dmic2_left_en = WCD938X_DIGITAL_CDC_DMIC2_CTL;
  1238. case 3:
  1239. dmic_clk_cnt = &(wcd938x->dmic_2_3_clk_cnt);
  1240. dmic_clk_reg = WCD938X_DIGITAL_CDC_DMIC_RATE_1_2;
  1241. dmic_clk_en_reg = WCD938X_DIGITAL_CDC_DMIC2_CTL;
  1242. dmic_clk_mask = 0xF0;
  1243. dmic_clk_shift = 0x04;
  1244. dmic_ctl_shift = 0x01;
  1245. break;
  1246. case 4:
  1247. case 5:
  1248. dmic_clk_cnt = &(wcd938x->dmic_4_5_clk_cnt);
  1249. dmic_clk_reg = WCD938X_DIGITAL_CDC_DMIC_RATE_3_4;
  1250. dmic_clk_en_reg = WCD938X_DIGITAL_CDC_DMIC3_CTL;
  1251. dmic_clk_mask = 0x0F;
  1252. dmic_clk_shift = 0x00;
  1253. dmic_ctl_shift = 0x02;
  1254. break;
  1255. case 6:
  1256. case 7:
  1257. dmic_clk_cnt = &(wcd938x->dmic_6_7_clk_cnt);
  1258. dmic_clk_reg = WCD938X_DIGITAL_CDC_DMIC_RATE_3_4;
  1259. dmic_clk_en_reg = WCD938X_DIGITAL_CDC_DMIC4_CTL;
  1260. dmic_clk_mask = 0xF0;
  1261. dmic_clk_shift = 0x04;
  1262. dmic_ctl_shift = 0x03;
  1263. break;
  1264. default:
  1265. dev_err(component->dev, "%s: Invalid DMIC Selection\n",
  1266. __func__);
  1267. return -EINVAL;
  1268. };
  1269. dev_dbg(component->dev, "%s: event %d DMIC%d dmic_clk_cnt %d\n",
  1270. __func__, event, (w->shift +1), *dmic_clk_cnt);
  1271. switch (event) {
  1272. case SND_SOC_DAPM_PRE_PMU:
  1273. snd_soc_component_update_bits(component,
  1274. WCD938X_DIGITAL_CDC_AMIC_CTL,
  1275. (0x01 << dmic_ctl_shift), 0x00);
  1276. /* 250us sleep as per HW requirement */
  1277. usleep_range(250, 260);
  1278. if (dmic2_left_en)
  1279. snd_soc_component_update_bits(component,
  1280. dmic2_left_en, 0x80, 0x80);
  1281. /* Setting DMIC clock rate to 2.4MHz */
  1282. snd_soc_component_update_bits(component,
  1283. dmic_clk_reg, dmic_clk_mask,
  1284. (0x03 << dmic_clk_shift));
  1285. snd_soc_component_update_bits(component,
  1286. dmic_clk_en_reg, 0x08, 0x08);
  1287. /* enable clock scaling */
  1288. snd_soc_component_update_bits(component,
  1289. WCD938X_DIGITAL_CDC_DMIC_CTL, 0x06, 0x06);
  1290. ret = swr_slvdev_datapath_control(wcd938x->tx_swr_dev,
  1291. wcd938x->tx_swr_dev->dev_num,
  1292. true);
  1293. break;
  1294. case SND_SOC_DAPM_POST_PMD:
  1295. ret = swr_slvdev_datapath_control(wcd938x->tx_swr_dev,
  1296. wcd938x->tx_swr_dev->dev_num,
  1297. false);
  1298. snd_soc_component_update_bits(component,
  1299. WCD938X_DIGITAL_CDC_AMIC_CTL,
  1300. (0x01 << dmic_ctl_shift),
  1301. (0x01 << dmic_ctl_shift));
  1302. if (dmic2_left_en)
  1303. snd_soc_component_update_bits(component,
  1304. dmic2_left_en, 0x80, 0x00);
  1305. snd_soc_component_update_bits(component,
  1306. dmic_clk_en_reg, 0x08, 0x00);
  1307. break;
  1308. };
  1309. return ret;
  1310. }
  1311. /*
  1312. * wcd938x_get_micb_vout_ctl_val: converts micbias from volts to register value
  1313. * @micb_mv: micbias in mv
  1314. *
  1315. * return register value converted
  1316. */
  1317. int wcd938x_get_micb_vout_ctl_val(u32 micb_mv)
  1318. {
  1319. /* min micbias voltage is 1V and maximum is 2.85V */
  1320. if (micb_mv < 1000 || micb_mv > 2850) {
  1321. pr_err("%s: unsupported micbias voltage\n", __func__);
  1322. return -EINVAL;
  1323. }
  1324. return (micb_mv - 1000) / 50;
  1325. }
  1326. EXPORT_SYMBOL(wcd938x_get_micb_vout_ctl_val);
  1327. /*
  1328. * wcd938x_mbhc_micb_adjust_voltage: adjust specific micbias voltage
  1329. * @component: handle to snd_soc_component *
  1330. * @req_volt: micbias voltage to be set
  1331. * @micb_num: micbias to be set, e.g. micbias1 or micbias2
  1332. *
  1333. * return 0 if adjustment is success or error code in case of failure
  1334. */
  1335. int wcd938x_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
  1336. int req_volt, int micb_num)
  1337. {
  1338. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1339. int cur_vout_ctl, req_vout_ctl;
  1340. int micb_reg, micb_val, micb_en;
  1341. int ret = 0;
  1342. switch (micb_num) {
  1343. case MIC_BIAS_1:
  1344. micb_reg = WCD938X_ANA_MICB1;
  1345. break;
  1346. case MIC_BIAS_2:
  1347. micb_reg = WCD938X_ANA_MICB2;
  1348. break;
  1349. case MIC_BIAS_3:
  1350. micb_reg = WCD938X_ANA_MICB3;
  1351. break;
  1352. case MIC_BIAS_4:
  1353. micb_reg = WCD938X_ANA_MICB4;
  1354. break;
  1355. default:
  1356. return -EINVAL;
  1357. }
  1358. mutex_lock(&wcd938x->micb_lock);
  1359. /*
  1360. * If requested micbias voltage is same as current micbias
  1361. * voltage, then just return. Otherwise, adjust voltage as
  1362. * per requested value. If micbias is already enabled, then
  1363. * to avoid slow micbias ramp-up or down enable pull-up
  1364. * momentarily, change the micbias value and then re-enable
  1365. * micbias.
  1366. */
  1367. micb_val = snd_soc_component_read32(component, micb_reg);
  1368. micb_en = (micb_val & 0xC0) >> 6;
  1369. cur_vout_ctl = micb_val & 0x3F;
  1370. req_vout_ctl = wcd938x_get_micb_vout_ctl_val(req_volt);
  1371. if (req_vout_ctl < 0) {
  1372. ret = -EINVAL;
  1373. goto exit;
  1374. }
  1375. if (cur_vout_ctl == req_vout_ctl) {
  1376. ret = 0;
  1377. goto exit;
  1378. }
  1379. dev_dbg(component->dev, "%s: micb_num: %d, cur_mv: %d, req_mv: %d, micb_en: %d\n",
  1380. __func__, micb_num, WCD_VOUT_CTL_TO_MICB(cur_vout_ctl),
  1381. req_volt, micb_en);
  1382. if (micb_en == 0x1)
  1383. snd_soc_component_update_bits(component, micb_reg, 0xC0, 0x80);
  1384. snd_soc_component_update_bits(component, micb_reg, 0x3F, req_vout_ctl);
  1385. if (micb_en == 0x1) {
  1386. snd_soc_component_update_bits(component, micb_reg, 0xC0, 0x40);
  1387. /*
  1388. * Add 2ms delay as per HW requirement after enabling
  1389. * micbias
  1390. */
  1391. usleep_range(2000, 2100);
  1392. }
  1393. exit:
  1394. mutex_unlock(&wcd938x->micb_lock);
  1395. return ret;
  1396. }
  1397. EXPORT_SYMBOL(wcd938x_mbhc_micb_adjust_voltage);
  1398. static int wcd938x_tx_swr_ctrl(struct snd_soc_dapm_widget *w,
  1399. struct snd_kcontrol *kcontrol,
  1400. int event)
  1401. {
  1402. struct snd_soc_component *component =
  1403. snd_soc_dapm_to_component(w->dapm);
  1404. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1405. int ret = 0;
  1406. int bank = 0;
  1407. u8 mode = 0;
  1408. int i = 0;
  1409. int rate = 0;
  1410. bank = (wcd938x_swr_slv_get_current_bank(wcd938x->tx_swr_dev,
  1411. wcd938x->tx_swr_dev->dev_num) ? 0 : 1);
  1412. switch (event) {
  1413. case SND_SOC_DAPM_PRE_PMU:
  1414. if (strnstr(w->name, "ADC", sizeof("ADC"))) {
  1415. if (test_bit(WCD_ADC1, &wcd938x->status_mask))
  1416. mode |= tx_mode_bit[wcd938x->tx_mode[WCD_ADC1]];
  1417. if (test_bit(WCD_ADC2, &wcd938x->status_mask))
  1418. mode |= tx_mode_bit[wcd938x->tx_mode[WCD_ADC2]];
  1419. if (test_bit(WCD_ADC3, &wcd938x->status_mask))
  1420. mode |= tx_mode_bit[wcd938x->tx_mode[WCD_ADC3]];
  1421. if (test_bit(WCD_ADC4, &wcd938x->status_mask))
  1422. mode |= tx_mode_bit[wcd938x->tx_mode[WCD_ADC4]];
  1423. if (mode != 0) {
  1424. for (i = 0; i < ADC_MODE_ULP2; i++) {
  1425. if (mode & (1 << i)) {
  1426. i++;
  1427. break;
  1428. }
  1429. }
  1430. }
  1431. rate = wcd938x_get_clk_rate(i);
  1432. wcd938x_set_swr_clk_rate(component, rate, bank);
  1433. }
  1434. if (w->shift == ADC2 && !(snd_soc_component_read32(component,
  1435. WCD938X_TX_NEW_AMIC_MUX_CFG) & 0x80)) {
  1436. if (!wcd938x->bcs_dis)
  1437. wcd938x_tx_connect_port(component, MBHC,
  1438. SWR_CLK_RATE_4P8MHZ, true);
  1439. set_bit(AMIC2_BCS_ENABLE, &wcd938x->status_mask);
  1440. }
  1441. if (strnstr(w->name, "ADC", sizeof("ADC"))) {
  1442. wcd938x_tx_connect_port(component, w->shift, rate,
  1443. true);
  1444. /* Copy clk settings to active bank */
  1445. wcd938x_set_swr_clk_rate(component, rate, !bank);
  1446. } else {
  1447. wcd938x_tx_connect_port(component, w->shift,
  1448. SWR_CLK_RATE_2P4MHZ, true);
  1449. }
  1450. break;
  1451. case SND_SOC_DAPM_POST_PMD:
  1452. if (strnstr(w->name, "ADC", sizeof("ADC"))) {
  1453. rate = wcd938x_get_clk_rate(ADC_MODE_INVALID);
  1454. wcd938x_set_swr_clk_rate(component, rate, !bank);
  1455. }
  1456. wcd938x_tx_connect_port(component, w->shift, 0, false);
  1457. if (w->shift == ADC2 &&
  1458. test_bit(AMIC2_BCS_ENABLE, &wcd938x->status_mask)) {
  1459. if (!wcd938x->bcs_dis)
  1460. wcd938x_tx_connect_port(component, MBHC, 0,
  1461. false);
  1462. clear_bit(AMIC2_BCS_ENABLE, &wcd938x->status_mask);
  1463. }
  1464. if (strnstr(w->name, "ADC", sizeof("ADC")))
  1465. wcd938x_set_swr_clk_rate(component, rate, bank);
  1466. break;
  1467. };
  1468. return ret;
  1469. }
  1470. static int wcd938x_get_adc_mode(int val)
  1471. {
  1472. int ret = 0;
  1473. switch (val) {
  1474. case ADC_MODE_INVALID:
  1475. ret = ADC_MODE_VAL_NORMAL;
  1476. break;
  1477. case ADC_MODE_HIFI:
  1478. ret = ADC_MODE_VAL_HIFI;
  1479. break;
  1480. case ADC_MODE_LO_HIF:
  1481. ret = ADC_MODE_VAL_LO_HIF;
  1482. break;
  1483. case ADC_MODE_NORMAL:
  1484. ret = ADC_MODE_VAL_NORMAL;
  1485. break;
  1486. case ADC_MODE_LP:
  1487. ret = ADC_MODE_VAL_LP;
  1488. break;
  1489. case ADC_MODE_ULP1:
  1490. ret = ADC_MODE_VAL_ULP1;
  1491. break;
  1492. case ADC_MODE_ULP2:
  1493. ret = ADC_MODE_VAL_ULP2;
  1494. break;
  1495. default:
  1496. ret = -EINVAL;
  1497. pr_err("%s: invalid ADC mode value %d\n", __func__, val);
  1498. break;
  1499. }
  1500. return ret;
  1501. }
  1502. static int wcd938x_codec_enable_adc(struct snd_soc_dapm_widget *w,
  1503. struct snd_kcontrol *kcontrol,
  1504. int event){
  1505. struct snd_soc_component *component =
  1506. snd_soc_dapm_to_component(w->dapm);
  1507. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1508. int clk_rate = 0, ret = 0;
  1509. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1510. w->name, event);
  1511. switch (event) {
  1512. case SND_SOC_DAPM_PRE_PMU:
  1513. snd_soc_component_update_bits(component,
  1514. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x08, 0x08);
  1515. snd_soc_component_update_bits(component,
  1516. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x10, 0x10);
  1517. set_bit(w->shift, &wcd938x->status_mask);
  1518. clk_rate = wcd938x_get_clk_rate(wcd938x->tx_mode[w->shift]);
  1519. ret = swr_slvdev_datapath_control(wcd938x->tx_swr_dev,
  1520. wcd938x->tx_swr_dev->dev_num,
  1521. true);
  1522. break;
  1523. case SND_SOC_DAPM_POST_PMD:
  1524. ret = swr_slvdev_datapath_control(wcd938x->tx_swr_dev,
  1525. wcd938x->tx_swr_dev->dev_num,
  1526. false);
  1527. snd_soc_component_update_bits(component,
  1528. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x08, 0x00);
  1529. clear_bit(w->shift, &wcd938x->status_mask);
  1530. break;
  1531. };
  1532. return ret;
  1533. }
  1534. void wcd938x_disable_bcs_before_slow_insert(struct snd_soc_component *component,
  1535. bool bcs_disable)
  1536. {
  1537. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1538. if (wcd938x->update_wcd_event) {
  1539. if (bcs_disable)
  1540. wcd938x->update_wcd_event(wcd938x->handle,
  1541. WCD_BOLERO_EVT_BCS_CLK_OFF, 0);
  1542. else
  1543. wcd938x->update_wcd_event(wcd938x->handle,
  1544. WCD_BOLERO_EVT_BCS_CLK_OFF, 1);
  1545. }
  1546. }
  1547. int wcd938x_tx_channel_config(struct snd_soc_component *component,
  1548. int channel, int mode)
  1549. {
  1550. int reg = WCD938X_ANA_TX_CH2, mask = 0, val = 0;
  1551. int ret = 0;
  1552. switch (channel) {
  1553. case 0:
  1554. reg = WCD938X_ANA_TX_CH2;
  1555. mask = 0x40;
  1556. break;
  1557. case 1:
  1558. reg = WCD938X_ANA_TX_CH2;
  1559. mask = 0x20;
  1560. break;
  1561. case 2:
  1562. reg = WCD938X_ANA_TX_CH4;
  1563. mask = 0x40;
  1564. break;
  1565. case 3:
  1566. reg = WCD938X_ANA_TX_CH4;
  1567. mask = 0x20;
  1568. break;
  1569. default:
  1570. pr_err("%s: Invalid channel num %d\n", __func__, channel);
  1571. ret = -EINVAL;
  1572. break;
  1573. }
  1574. if (!mode)
  1575. val = 0x00;
  1576. else
  1577. val = mask;
  1578. if (!ret)
  1579. snd_soc_component_update_bits(component, reg, mask, val);
  1580. return ret;
  1581. }
  1582. static int wcd938x_enable_req(struct snd_soc_dapm_widget *w,
  1583. struct snd_kcontrol *kcontrol, int event)
  1584. {
  1585. struct snd_soc_component *component =
  1586. snd_soc_dapm_to_component(w->dapm);
  1587. int mode;
  1588. int ret = 0;
  1589. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1590. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1591. w->name, event);
  1592. switch (event) {
  1593. case SND_SOC_DAPM_PRE_PMU:
  1594. snd_soc_component_update_bits(component,
  1595. WCD938X_DIGITAL_CDC_REQ_CTL, 0x02, 0x02);
  1596. snd_soc_component_update_bits(component,
  1597. WCD938X_DIGITAL_CDC_REQ_CTL, 0x01, 0x00);
  1598. ret = wcd938x_tx_channel_config(component, w->shift, 1);
  1599. mode = wcd938x_get_adc_mode(wcd938x->tx_mode[w->shift]);
  1600. if (mode < 0) {
  1601. dev_info(component->dev,
  1602. "%s: invalid mode, setting to normal mode\n",
  1603. __func__);
  1604. mode = ADC_MODE_VAL_NORMAL;
  1605. }
  1606. switch (w->shift) {
  1607. case 0:
  1608. snd_soc_component_update_bits(component,
  1609. WCD938X_DIGITAL_CDC_TX_ANA_MODE_0_1, 0x0F,
  1610. mode);
  1611. snd_soc_component_update_bits(component,
  1612. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x10, 0x10);
  1613. break;
  1614. case 1:
  1615. snd_soc_component_update_bits(component,
  1616. WCD938X_DIGITAL_CDC_TX_ANA_MODE_0_1, 0xF0,
  1617. mode << 4);
  1618. snd_soc_component_update_bits(component,
  1619. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x20, 0x20);
  1620. break;
  1621. case 2:
  1622. snd_soc_component_update_bits(component,
  1623. WCD938X_DIGITAL_CDC_TX_ANA_MODE_2_3, 0x0F,
  1624. mode);
  1625. snd_soc_component_update_bits(component,
  1626. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x40, 0x40);
  1627. break;
  1628. case 3:
  1629. snd_soc_component_update_bits(component,
  1630. WCD938X_DIGITAL_CDC_TX_ANA_MODE_2_3, 0xF0,
  1631. mode << 4);
  1632. snd_soc_component_update_bits(component,
  1633. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x80, 0x80);
  1634. break;
  1635. default:
  1636. break;
  1637. }
  1638. ret |= wcd938x_tx_channel_config(component, w->shift, 0);
  1639. break;
  1640. case SND_SOC_DAPM_POST_PMD:
  1641. switch (w->shift) {
  1642. case 0:
  1643. snd_soc_component_update_bits(component,
  1644. WCD938X_DIGITAL_CDC_TX_ANA_MODE_0_1, 0x0F,
  1645. 0x00);
  1646. snd_soc_component_update_bits(component,
  1647. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x10, 0x00);
  1648. break;
  1649. case 1:
  1650. snd_soc_component_update_bits(component,
  1651. WCD938X_DIGITAL_CDC_TX_ANA_MODE_0_1, 0xF0,
  1652. 0x00);
  1653. snd_soc_component_update_bits(component,
  1654. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x20, 0x00);
  1655. break;
  1656. case 2:
  1657. snd_soc_component_update_bits(component,
  1658. WCD938X_DIGITAL_CDC_TX_ANA_MODE_2_3, 0x0F,
  1659. 0x00);
  1660. snd_soc_component_update_bits(component,
  1661. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x40, 0x00);
  1662. break;
  1663. case 3:
  1664. snd_soc_component_update_bits(component,
  1665. WCD938X_DIGITAL_CDC_TX_ANA_MODE_2_3, 0xF0,
  1666. 0x00);
  1667. snd_soc_component_update_bits(component,
  1668. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x80, 0x00);
  1669. break;
  1670. default:
  1671. break;
  1672. }
  1673. snd_soc_component_update_bits(component,
  1674. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x10, 0x00);
  1675. break;
  1676. };
  1677. return ret;
  1678. }
  1679. int wcd938x_micbias_control(struct snd_soc_component *component,
  1680. int micb_num, int req, bool is_dapm)
  1681. {
  1682. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1683. int micb_index = micb_num - 1;
  1684. u16 micb_reg;
  1685. int pre_off_event = 0, post_off_event = 0;
  1686. int post_on_event = 0, post_dapm_off = 0;
  1687. int post_dapm_on = 0;
  1688. int ret = 0;
  1689. if ((micb_index < 0) || (micb_index > WCD938X_MAX_MICBIAS - 1)) {
  1690. dev_err(component->dev,
  1691. "%s: Invalid micbias index, micb_ind:%d\n",
  1692. __func__, micb_index);
  1693. return -EINVAL;
  1694. }
  1695. if (NULL == wcd938x) {
  1696. dev_err(component->dev,
  1697. "%s: wcd938x private data is NULL\n", __func__);
  1698. return -EINVAL;
  1699. }
  1700. switch (micb_num) {
  1701. case MIC_BIAS_1:
  1702. micb_reg = WCD938X_ANA_MICB1;
  1703. break;
  1704. case MIC_BIAS_2:
  1705. micb_reg = WCD938X_ANA_MICB2;
  1706. pre_off_event = WCD_EVENT_PRE_MICBIAS_2_OFF;
  1707. post_off_event = WCD_EVENT_POST_MICBIAS_2_OFF;
  1708. post_on_event = WCD_EVENT_POST_MICBIAS_2_ON;
  1709. post_dapm_on = WCD_EVENT_POST_DAPM_MICBIAS_2_ON;
  1710. post_dapm_off = WCD_EVENT_POST_DAPM_MICBIAS_2_OFF;
  1711. break;
  1712. case MIC_BIAS_3:
  1713. micb_reg = WCD938X_ANA_MICB3;
  1714. break;
  1715. case MIC_BIAS_4:
  1716. micb_reg = WCD938X_ANA_MICB4;
  1717. break;
  1718. default:
  1719. dev_err(component->dev, "%s: Invalid micbias number: %d\n",
  1720. __func__, micb_num);
  1721. return -EINVAL;
  1722. };
  1723. mutex_lock(&wcd938x->micb_lock);
  1724. switch (req) {
  1725. case MICB_PULLUP_ENABLE:
  1726. if (!wcd938x->dev_up) {
  1727. dev_dbg(component->dev, "%s: enable req %d wcd device down\n",
  1728. __func__, req);
  1729. ret = -ENODEV;
  1730. goto done;
  1731. }
  1732. wcd938x->pullup_ref[micb_index]++;
  1733. if ((wcd938x->pullup_ref[micb_index] == 1) &&
  1734. (wcd938x->micb_ref[micb_index] == 0))
  1735. snd_soc_component_update_bits(component, micb_reg,
  1736. 0xC0, 0x80);
  1737. break;
  1738. case MICB_PULLUP_DISABLE:
  1739. if (wcd938x->pullup_ref[micb_index] > 0)
  1740. wcd938x->pullup_ref[micb_index]--;
  1741. if (!wcd938x->dev_up) {
  1742. dev_dbg(component->dev, "%s: enable req %d wcd device down\n",
  1743. __func__, req);
  1744. ret = -ENODEV;
  1745. goto done;
  1746. }
  1747. if ((wcd938x->pullup_ref[micb_index] == 0) &&
  1748. (wcd938x->micb_ref[micb_index] == 0))
  1749. snd_soc_component_update_bits(component, micb_reg,
  1750. 0xC0, 0x00);
  1751. break;
  1752. case MICB_ENABLE:
  1753. if (!wcd938x->dev_up) {
  1754. dev_dbg(component->dev, "%s: enable req %d wcd device down\n",
  1755. __func__, req);
  1756. ret = -ENODEV;
  1757. goto done;
  1758. }
  1759. wcd938x->micb_ref[micb_index]++;
  1760. if (wcd938x->micb_ref[micb_index] == 1) {
  1761. snd_soc_component_update_bits(component,
  1762. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0xF0, 0xF0);
  1763. snd_soc_component_update_bits(component,
  1764. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x10, 0x10);
  1765. snd_soc_component_update_bits(component,
  1766. WCD938X_DIGITAL_CDC_ANA_TX_CLK_CTL, 0x01, 0x01);
  1767. snd_soc_component_update_bits(component,
  1768. WCD938X_MICB1_TEST_CTL_2, 0x01, 0x01);
  1769. snd_soc_component_update_bits(component,
  1770. WCD938X_MICB2_TEST_CTL_2, 0x01, 0x01);
  1771. snd_soc_component_update_bits(component,
  1772. WCD938X_MICB3_TEST_CTL_2, 0x01, 0x01);
  1773. snd_soc_component_update_bits(component,
  1774. WCD938X_MICB4_TEST_CTL_2, 0x01, 0x01);
  1775. snd_soc_component_update_bits(component,
  1776. micb_reg, 0xC0, 0x40);
  1777. if (post_on_event)
  1778. blocking_notifier_call_chain(
  1779. &wcd938x->mbhc->notifier,
  1780. post_on_event,
  1781. &wcd938x->mbhc->wcd_mbhc);
  1782. }
  1783. if (is_dapm && post_dapm_on && wcd938x->mbhc)
  1784. blocking_notifier_call_chain(&wcd938x->mbhc->notifier,
  1785. post_dapm_on,
  1786. &wcd938x->mbhc->wcd_mbhc);
  1787. break;
  1788. case MICB_DISABLE:
  1789. if (wcd938x->micb_ref[micb_index] > 0)
  1790. wcd938x->micb_ref[micb_index]--;
  1791. if (!wcd938x->dev_up) {
  1792. dev_dbg(component->dev, "%s: enable req %d wcd device down\n",
  1793. __func__, req);
  1794. ret = -ENODEV;
  1795. goto done;
  1796. }
  1797. if ((wcd938x->micb_ref[micb_index] == 0) &&
  1798. (wcd938x->pullup_ref[micb_index] > 0))
  1799. snd_soc_component_update_bits(component, micb_reg,
  1800. 0xC0, 0x80);
  1801. else if ((wcd938x->micb_ref[micb_index] == 0) &&
  1802. (wcd938x->pullup_ref[micb_index] == 0)) {
  1803. if (pre_off_event && wcd938x->mbhc)
  1804. blocking_notifier_call_chain(
  1805. &wcd938x->mbhc->notifier,
  1806. pre_off_event,
  1807. &wcd938x->mbhc->wcd_mbhc);
  1808. snd_soc_component_update_bits(component, micb_reg,
  1809. 0xC0, 0x00);
  1810. if (post_off_event && wcd938x->mbhc)
  1811. blocking_notifier_call_chain(
  1812. &wcd938x->mbhc->notifier,
  1813. post_off_event,
  1814. &wcd938x->mbhc->wcd_mbhc);
  1815. }
  1816. if (is_dapm && post_dapm_off && wcd938x->mbhc)
  1817. blocking_notifier_call_chain(&wcd938x->mbhc->notifier,
  1818. post_dapm_off,
  1819. &wcd938x->mbhc->wcd_mbhc);
  1820. break;
  1821. };
  1822. dev_dbg(component->dev,
  1823. "%s: micb_num:%d, micb_ref: %d, pullup_ref: %d\n",
  1824. __func__, micb_num, wcd938x->micb_ref[micb_index],
  1825. wcd938x->pullup_ref[micb_index]);
  1826. done:
  1827. mutex_unlock(&wcd938x->micb_lock);
  1828. return ret;
  1829. }
  1830. EXPORT_SYMBOL(wcd938x_micbias_control);
  1831. static int wcd938x_get_logical_addr(struct swr_device *swr_dev)
  1832. {
  1833. int ret = 0;
  1834. uint8_t devnum = 0;
  1835. int num_retry = NUM_ATTEMPTS;
  1836. do {
  1837. /* retry after 1ms */
  1838. usleep_range(1000, 1010);
  1839. ret = swr_get_logical_dev_num(swr_dev, swr_dev->addr, &devnum);
  1840. } while (ret && --num_retry);
  1841. if (ret)
  1842. dev_err(&swr_dev->dev,
  1843. "%s get devnum %d for dev addr %llx failed\n",
  1844. __func__, devnum, swr_dev->addr);
  1845. swr_dev->dev_num = devnum;
  1846. return 0;
  1847. }
  1848. static bool get_usbc_hs_status(struct snd_soc_component *component,
  1849. struct wcd_mbhc_config *mbhc_cfg)
  1850. {
  1851. if (mbhc_cfg->enable_usbc_analog) {
  1852. if (!(snd_soc_component_read32(component, WCD938X_ANA_MBHC_MECH)
  1853. & 0x20))
  1854. return true;
  1855. }
  1856. return false;
  1857. }
  1858. static int wcd938x_event_notify(struct notifier_block *block,
  1859. unsigned long val,
  1860. void *data)
  1861. {
  1862. u16 event = (val & 0xffff);
  1863. int ret = 0;
  1864. struct wcd938x_priv *wcd938x = dev_get_drvdata((struct device *)data);
  1865. struct snd_soc_component *component = wcd938x->component;
  1866. struct wcd_mbhc *mbhc;
  1867. switch (event) {
  1868. case BOLERO_WCD_EVT_TX_CH_HOLD_CLEAR:
  1869. if (test_bit(WCD_ADC1, &wcd938x->status_mask)) {
  1870. snd_soc_component_update_bits(component,
  1871. WCD938X_ANA_TX_CH2, 0x40, 0x00);
  1872. clear_bit(WCD_ADC1, &wcd938x->status_mask);
  1873. }
  1874. if (test_bit(WCD_ADC2, &wcd938x->status_mask)) {
  1875. snd_soc_component_update_bits(component,
  1876. WCD938X_ANA_TX_CH2, 0x20, 0x00);
  1877. clear_bit(WCD_ADC2, &wcd938x->status_mask);
  1878. }
  1879. if (test_bit(WCD_ADC3, &wcd938x->status_mask)) {
  1880. snd_soc_component_update_bits(component,
  1881. WCD938X_ANA_TX_CH4, 0x40, 0x00);
  1882. clear_bit(WCD_ADC3, &wcd938x->status_mask);
  1883. }
  1884. if (test_bit(WCD_ADC4, &wcd938x->status_mask)) {
  1885. snd_soc_component_update_bits(component,
  1886. WCD938X_ANA_TX_CH4, 0x20, 0x00);
  1887. clear_bit(WCD_ADC4, &wcd938x->status_mask);
  1888. }
  1889. break;
  1890. case BOLERO_WCD_EVT_PA_OFF_PRE_SSR:
  1891. snd_soc_component_update_bits(component, WCD938X_ANA_HPH,
  1892. 0xC0, 0x00);
  1893. snd_soc_component_update_bits(component, WCD938X_ANA_EAR,
  1894. 0x80, 0x00);
  1895. snd_soc_component_update_bits(component, WCD938X_AUX_AUXPA,
  1896. 0x80, 0x00);
  1897. break;
  1898. case BOLERO_WCD_EVT_SSR_DOWN:
  1899. wcd938x->dev_up = false;
  1900. wcd938x->mbhc->wcd_mbhc.deinit_in_progress = true;
  1901. mbhc = &wcd938x->mbhc->wcd_mbhc;
  1902. wcd938x->usbc_hs_status = get_usbc_hs_status(component,
  1903. mbhc->mbhc_cfg);
  1904. wcd938x_mbhc_ssr_down(wcd938x->mbhc, component);
  1905. wcd938x_reset_low(wcd938x->dev);
  1906. break;
  1907. case BOLERO_WCD_EVT_SSR_UP:
  1908. wcd938x_reset(wcd938x->dev);
  1909. /* allow reset to take effect */
  1910. usleep_range(10000, 10010);
  1911. wcd938x_get_logical_addr(wcd938x->tx_swr_dev);
  1912. wcd938x_get_logical_addr(wcd938x->rx_swr_dev);
  1913. wcd938x_init_reg(component);
  1914. regcache_mark_dirty(wcd938x->regmap);
  1915. regcache_sync(wcd938x->regmap);
  1916. /* Initialize MBHC module */
  1917. mbhc = &wcd938x->mbhc->wcd_mbhc;
  1918. ret = wcd938x_mbhc_post_ssr_init(wcd938x->mbhc, component);
  1919. if (ret) {
  1920. dev_err(component->dev, "%s: mbhc initialization failed\n",
  1921. __func__);
  1922. } else {
  1923. wcd938x_mbhc_hs_detect(component, mbhc->mbhc_cfg);
  1924. if (wcd938x->usbc_hs_status)
  1925. mdelay(500);
  1926. }
  1927. wcd938x->mbhc->wcd_mbhc.deinit_in_progress = false;
  1928. wcd938x->dev_up = true;
  1929. break;
  1930. case BOLERO_WCD_EVT_CLK_NOTIFY:
  1931. snd_soc_component_update_bits(component,
  1932. WCD938X_DIGITAL_TOP_CLK_CFG, 0x06,
  1933. ((val >> 0x10) << 0x01));
  1934. break;
  1935. default:
  1936. dev_dbg(component->dev, "%s: invalid event %d\n", __func__, event);
  1937. break;
  1938. }
  1939. return 0;
  1940. }
  1941. static int __wcd938x_codec_enable_micbias(struct snd_soc_dapm_widget *w,
  1942. int event)
  1943. {
  1944. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  1945. int micb_num;
  1946. dev_dbg(component->dev, "%s: wname: %s, event: %d\n",
  1947. __func__, w->name, event);
  1948. if (strnstr(w->name, "MIC BIAS1", sizeof("MIC BIAS1")))
  1949. micb_num = MIC_BIAS_1;
  1950. else if (strnstr(w->name, "MIC BIAS2", sizeof("MIC BIAS2")))
  1951. micb_num = MIC_BIAS_2;
  1952. else if (strnstr(w->name, "MIC BIAS3", sizeof("MIC BIAS3")))
  1953. micb_num = MIC_BIAS_3;
  1954. else if (strnstr(w->name, "MIC BIAS4", sizeof("MIC BIAS4")))
  1955. micb_num = MIC_BIAS_4;
  1956. else
  1957. return -EINVAL;
  1958. switch (event) {
  1959. case SND_SOC_DAPM_PRE_PMU:
  1960. wcd938x_micbias_control(component, micb_num,
  1961. MICB_ENABLE, true);
  1962. break;
  1963. case SND_SOC_DAPM_POST_PMU:
  1964. /* 1 msec delay as per HW requirement */
  1965. usleep_range(1000, 1100);
  1966. break;
  1967. case SND_SOC_DAPM_POST_PMD:
  1968. wcd938x_micbias_control(component, micb_num,
  1969. MICB_DISABLE, true);
  1970. break;
  1971. };
  1972. return 0;
  1973. }
  1974. static int wcd938x_codec_enable_micbias(struct snd_soc_dapm_widget *w,
  1975. struct snd_kcontrol *kcontrol,
  1976. int event)
  1977. {
  1978. return __wcd938x_codec_enable_micbias(w, event);
  1979. }
  1980. static int __wcd938x_codec_enable_micbias_pullup(struct snd_soc_dapm_widget *w,
  1981. int event)
  1982. {
  1983. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  1984. int micb_num;
  1985. dev_dbg(component->dev, "%s: wname: %s, event: %d\n",
  1986. __func__, w->name, event);
  1987. if (strnstr(w->name, "VA MIC BIAS1", sizeof("VA MIC BIAS1")))
  1988. micb_num = MIC_BIAS_1;
  1989. else if (strnstr(w->name, "VA MIC BIAS2", sizeof("VA MIC BIAS2")))
  1990. micb_num = MIC_BIAS_2;
  1991. else if (strnstr(w->name, "VA MIC BIAS3", sizeof("VA MIC BIAS3")))
  1992. micb_num = MIC_BIAS_3;
  1993. else if (strnstr(w->name, "VA MIC BIAS4", sizeof("VA MIC BIAS4")))
  1994. micb_num = MIC_BIAS_4;
  1995. else
  1996. return -EINVAL;
  1997. switch (event) {
  1998. case SND_SOC_DAPM_PRE_PMU:
  1999. wcd938x_micbias_control(component, micb_num,
  2000. MICB_PULLUP_ENABLE, true);
  2001. break;
  2002. case SND_SOC_DAPM_POST_PMU:
  2003. /* 1 msec delay as per HW requirement */
  2004. usleep_range(1000, 1100);
  2005. break;
  2006. case SND_SOC_DAPM_POST_PMD:
  2007. wcd938x_micbias_control(component, micb_num,
  2008. MICB_PULLUP_DISABLE, true);
  2009. break;
  2010. };
  2011. return 0;
  2012. }
  2013. static int wcd938x_codec_enable_micbias_pullup(struct snd_soc_dapm_widget *w,
  2014. struct snd_kcontrol *kcontrol,
  2015. int event)
  2016. {
  2017. return __wcd938x_codec_enable_micbias_pullup(w, event);
  2018. }
  2019. static int wcd938x_wakeup(void *handle, bool enable)
  2020. {
  2021. struct wcd938x_priv *priv;
  2022. int ret = 0;
  2023. if (!handle) {
  2024. pr_err("%s: NULL handle\n", __func__);
  2025. return -EINVAL;
  2026. }
  2027. priv = (struct wcd938x_priv *)handle;
  2028. if (!priv->tx_swr_dev) {
  2029. pr_err("%s: tx swr dev is NULL\n", __func__);
  2030. return -EINVAL;
  2031. }
  2032. mutex_lock(&priv->wakeup_lock);
  2033. if (enable)
  2034. ret = swr_device_wakeup_vote(priv->tx_swr_dev);
  2035. else
  2036. ret = swr_device_wakeup_unvote(priv->tx_swr_dev);
  2037. mutex_unlock(&priv->wakeup_lock);
  2038. return ret;
  2039. }
  2040. static int wcd938x_codec_force_enable_micbias(struct snd_soc_dapm_widget *w,
  2041. struct snd_kcontrol *kcontrol,
  2042. int event)
  2043. {
  2044. int ret = 0;
  2045. struct snd_soc_component *component =
  2046. snd_soc_dapm_to_component(w->dapm);
  2047. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  2048. switch (event) {
  2049. case SND_SOC_DAPM_PRE_PMU:
  2050. wcd938x_wakeup(wcd938x, true);
  2051. ret = __wcd938x_codec_enable_micbias(w, SND_SOC_DAPM_PRE_PMU);
  2052. wcd938x_wakeup(wcd938x, false);
  2053. break;
  2054. case SND_SOC_DAPM_POST_PMD:
  2055. wcd938x_wakeup(wcd938x, true);
  2056. ret = __wcd938x_codec_enable_micbias(w, SND_SOC_DAPM_POST_PMD);
  2057. wcd938x_wakeup(wcd938x, false);
  2058. break;
  2059. }
  2060. return ret;
  2061. }
  2062. static int wcd938x_enable_micbias(struct wcd938x_priv *wcd938x,
  2063. int micb_num, int req)
  2064. {
  2065. int micb_index = micb_num - 1;
  2066. u16 micb_reg;
  2067. if (NULL == wcd938x) {
  2068. pr_err("%s: wcd938x private data is NULL\n", __func__);
  2069. return -EINVAL;
  2070. }
  2071. switch (micb_num) {
  2072. case MIC_BIAS_1:
  2073. micb_reg = WCD938X_ANA_MICB1;
  2074. break;
  2075. case MIC_BIAS_2:
  2076. micb_reg = WCD938X_ANA_MICB2;
  2077. break;
  2078. case MIC_BIAS_3:
  2079. micb_reg = WCD938X_ANA_MICB3;
  2080. break;
  2081. case MIC_BIAS_4:
  2082. micb_reg = WCD938X_ANA_MICB4;
  2083. break;
  2084. default:
  2085. pr_err("%s: Invalid micbias number: %d\n", __func__, micb_num);
  2086. return -EINVAL;
  2087. };
  2088. mutex_lock(&wcd938x->micb_lock);
  2089. switch (req) {
  2090. case MICB_ENABLE:
  2091. wcd938x->micb_ref[micb_index]++;
  2092. if (wcd938x->micb_ref[micb_index] == 1) {
  2093. regmap_update_bits(wcd938x->regmap,
  2094. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0xE0, 0xE0);
  2095. regmap_update_bits(wcd938x->regmap,
  2096. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x10, 0x10);
  2097. regmap_update_bits(wcd938x->regmap,
  2098. WCD938X_DIGITAL_CDC_ANA_TX_CLK_CTL, 0x01, 0x01);
  2099. regmap_update_bits(wcd938x->regmap,
  2100. WCD938X_MICB1_TEST_CTL_2, 0x01, 0x01);
  2101. regmap_update_bits(wcd938x->regmap,
  2102. WCD938X_MICB2_TEST_CTL_2, 0x01, 0x01);
  2103. regmap_update_bits(wcd938x->regmap,
  2104. WCD938X_MICB3_TEST_CTL_2, 0x01, 0x01);
  2105. regmap_update_bits(wcd938x->regmap,
  2106. WCD938X_MICB4_TEST_CTL_2, 0x01, 0x01);
  2107. regmap_update_bits(wcd938x->regmap,
  2108. micb_reg, 0xC0, 0x40);
  2109. regmap_update_bits(wcd938x->regmap, micb_reg, 0x3F, 0x10);
  2110. }
  2111. break;
  2112. case MICB_PULLUP_ENABLE:
  2113. wcd938x->pullup_ref[micb_index]++;
  2114. if ((wcd938x->pullup_ref[micb_index] == 1) &&
  2115. (wcd938x->micb_ref[micb_index] == 0))
  2116. regmap_update_bits(wcd938x->regmap, micb_reg,
  2117. 0xC0, 0x80);
  2118. break;
  2119. case MICB_PULLUP_DISABLE:
  2120. if (wcd938x->pullup_ref[micb_index] > 0)
  2121. wcd938x->pullup_ref[micb_index]--;
  2122. if ((wcd938x->pullup_ref[micb_index] == 0) &&
  2123. (wcd938x->micb_ref[micb_index] == 0))
  2124. regmap_update_bits(wcd938x->regmap, micb_reg,
  2125. 0xC0, 0x00);
  2126. break;
  2127. case MICB_DISABLE:
  2128. if (wcd938x->micb_ref[micb_index] > 0)
  2129. wcd938x->micb_ref[micb_index]--;
  2130. if ((wcd938x->micb_ref[micb_index] == 0) &&
  2131. (wcd938x->pullup_ref[micb_index] > 0))
  2132. regmap_update_bits(wcd938x->regmap, micb_reg,
  2133. 0xC0, 0x80);
  2134. else if ((wcd938x->micb_ref[micb_index] == 0) &&
  2135. (wcd938x->pullup_ref[micb_index] == 0))
  2136. regmap_update_bits(wcd938x->regmap, micb_reg,
  2137. 0xC0, 0x00);
  2138. break;
  2139. };
  2140. mutex_unlock(&wcd938x->micb_lock);
  2141. return 0;
  2142. }
  2143. int wcd938x_codec_force_enable_micbias_v2(struct snd_soc_component *component,
  2144. int event, int micb_num)
  2145. {
  2146. struct wcd938x_priv *wcd938x_priv = NULL;
  2147. if(NULL == component) {
  2148. pr_err("%s: wcd938x component is NULL\n", __func__);
  2149. return -EINVAL;
  2150. }
  2151. if(event != SND_SOC_DAPM_PRE_PMU && event != SND_SOC_DAPM_POST_PMD) {
  2152. pr_err("%s: invalid event: %d\n", __func__, event);
  2153. return -EINVAL;
  2154. }
  2155. if(micb_num < MIC_BIAS_1 || micb_num > MIC_BIAS_4) {
  2156. pr_err("%s: invalid mic bias num: %d\n", __func__, micb_num);
  2157. return -EINVAL;
  2158. }
  2159. wcd938x_priv = snd_soc_component_get_drvdata(component);
  2160. switch (event) {
  2161. case SND_SOC_DAPM_PRE_PMU:
  2162. wcd938x_wakeup(wcd938x_priv, true);
  2163. wcd938x_enable_micbias(wcd938x_priv, micb_num, MICB_PULLUP_ENABLE);
  2164. wcd938x_wakeup(wcd938x_priv, false);
  2165. break;
  2166. case SND_SOC_DAPM_POST_PMD:
  2167. wcd938x_wakeup(wcd938x_priv, true);
  2168. wcd938x_enable_micbias(wcd938x_priv, micb_num, MICB_PULLUP_DISABLE);
  2169. wcd938x_wakeup(wcd938x_priv, false);
  2170. break;
  2171. }
  2172. return 0;
  2173. }
  2174. EXPORT_SYMBOL(wcd938x_codec_force_enable_micbias_v2);
  2175. static inline int wcd938x_tx_path_get(const char *wname,
  2176. unsigned int *path_num)
  2177. {
  2178. int ret = 0;
  2179. char *widget_name = NULL;
  2180. char *w_name = NULL;
  2181. char *path_num_char = NULL;
  2182. char *path_name = NULL;
  2183. widget_name = kstrndup(wname, 9, GFP_KERNEL);
  2184. if (!widget_name)
  2185. return -EINVAL;
  2186. w_name = widget_name;
  2187. path_name = strsep(&widget_name, " ");
  2188. if (!path_name) {
  2189. pr_err("%s: Invalid widget name = %s\n",
  2190. __func__, widget_name);
  2191. ret = -EINVAL;
  2192. goto err;
  2193. }
  2194. path_num_char = strpbrk(path_name, "0123");
  2195. if (!path_num_char) {
  2196. pr_err("%s: tx path index not found\n",
  2197. __func__);
  2198. ret = -EINVAL;
  2199. goto err;
  2200. }
  2201. ret = kstrtouint(path_num_char, 10, path_num);
  2202. if (ret < 0)
  2203. pr_err("%s: Invalid tx path = %s\n",
  2204. __func__, w_name);
  2205. err:
  2206. kfree(w_name);
  2207. return ret;
  2208. }
  2209. static int wcd938x_tx_mode_get(struct snd_kcontrol *kcontrol,
  2210. struct snd_ctl_elem_value *ucontrol)
  2211. {
  2212. struct snd_soc_component *component =
  2213. snd_soc_kcontrol_component(kcontrol);
  2214. struct wcd938x_priv *wcd938x = NULL;
  2215. int ret = 0;
  2216. unsigned int path = 0;
  2217. if (!component)
  2218. return -EINVAL;
  2219. wcd938x = snd_soc_component_get_drvdata(component);
  2220. if (!wcd938x)
  2221. return -EINVAL;
  2222. ret = wcd938x_tx_path_get(kcontrol->id.name, &path);
  2223. if (ret < 0)
  2224. return ret;
  2225. ucontrol->value.integer.value[0] = wcd938x->tx_mode[path];
  2226. return 0;
  2227. }
  2228. static int wcd938x_tx_mode_put(struct snd_kcontrol *kcontrol,
  2229. struct snd_ctl_elem_value *ucontrol)
  2230. {
  2231. struct snd_soc_component *component =
  2232. snd_soc_kcontrol_component(kcontrol);
  2233. struct wcd938x_priv *wcd938x = NULL;
  2234. u32 mode_val;
  2235. unsigned int path = 0;
  2236. int ret = 0;
  2237. if (!component)
  2238. return -EINVAL;
  2239. wcd938x = snd_soc_component_get_drvdata(component);
  2240. if (!wcd938x)
  2241. return -EINVAL;
  2242. ret = wcd938x_tx_path_get(kcontrol->id.name, &path);
  2243. if (ret)
  2244. return ret;
  2245. mode_val = ucontrol->value.enumerated.item[0];
  2246. dev_dbg(component->dev, "%s: mode: %d\n", __func__, mode_val);
  2247. wcd938x->tx_mode[path] = mode_val;
  2248. return 0;
  2249. }
  2250. static int wcd938x_rx_hph_mode_get(struct snd_kcontrol *kcontrol,
  2251. struct snd_ctl_elem_value *ucontrol)
  2252. {
  2253. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  2254. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  2255. ucontrol->value.integer.value[0] = wcd938x->hph_mode;
  2256. return 0;
  2257. }
  2258. static int wcd938x_rx_hph_mode_put(struct snd_kcontrol *kcontrol,
  2259. struct snd_ctl_elem_value *ucontrol)
  2260. {
  2261. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  2262. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  2263. u32 mode_val;
  2264. mode_val = ucontrol->value.enumerated.item[0];
  2265. dev_dbg(component->dev, "%s: mode: %d\n", __func__, mode_val);
  2266. if (wcd938x->variant == WCD9380) {
  2267. if (mode_val == CLS_H_HIFI || mode_val == CLS_AB_HIFI) {
  2268. dev_info(component->dev,
  2269. "%s:Invalid HPH Mode, default to CLS_H_ULP\n",
  2270. __func__);
  2271. mode_val = CLS_H_ULP;
  2272. }
  2273. }
  2274. if (mode_val == CLS_H_NORMAL) {
  2275. dev_info(component->dev,
  2276. "%s:Invalid HPH Mode, default to class_AB\n",
  2277. __func__);
  2278. mode_val = CLS_H_ULP;
  2279. }
  2280. wcd938x->hph_mode = mode_val;
  2281. return 0;
  2282. }
  2283. static int wcd938x_ear_pa_gain_get(struct snd_kcontrol *kcontrol,
  2284. struct snd_ctl_elem_value *ucontrol)
  2285. {
  2286. u8 ear_pa_gain = 0;
  2287. struct snd_soc_component *component =
  2288. snd_soc_kcontrol_component(kcontrol);
  2289. ear_pa_gain = snd_soc_component_read32(component,
  2290. WCD938X_ANA_EAR_COMPANDER_CTL);
  2291. ear_pa_gain = (ear_pa_gain & 0x7C) >> 2;
  2292. ucontrol->value.integer.value[0] = ear_pa_gain;
  2293. dev_dbg(component->dev, "%s: ear_pa_gain = 0x%x\n", __func__,
  2294. ear_pa_gain);
  2295. return 0;
  2296. }
  2297. static int wcd938x_ear_pa_gain_put(struct snd_kcontrol *kcontrol,
  2298. struct snd_ctl_elem_value *ucontrol)
  2299. {
  2300. u8 ear_pa_gain = 0;
  2301. struct snd_soc_component *component =
  2302. snd_soc_kcontrol_component(kcontrol);
  2303. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  2304. dev_dbg(component->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  2305. __func__, ucontrol->value.integer.value[0]);
  2306. ear_pa_gain = ucontrol->value.integer.value[0] << 2;
  2307. if (!wcd938x->comp1_enable) {
  2308. snd_soc_component_update_bits(component,
  2309. WCD938X_ANA_EAR_COMPANDER_CTL,
  2310. 0x7C, ear_pa_gain);
  2311. }
  2312. return 0;
  2313. }
  2314. static int wcd938x_get_compander(struct snd_kcontrol *kcontrol,
  2315. struct snd_ctl_elem_value *ucontrol)
  2316. {
  2317. struct snd_soc_component *component =
  2318. snd_soc_kcontrol_component(kcontrol);
  2319. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  2320. bool hphr;
  2321. struct soc_multi_mixer_control *mc;
  2322. mc = (struct soc_multi_mixer_control *)(kcontrol->private_value);
  2323. hphr = mc->shift;
  2324. ucontrol->value.integer.value[0] = hphr ? wcd938x->comp2_enable :
  2325. wcd938x->comp1_enable;
  2326. return 0;
  2327. }
  2328. static int wcd938x_set_compander(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. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  2334. int value = ucontrol->value.integer.value[0];
  2335. bool hphr;
  2336. struct soc_multi_mixer_control *mc;
  2337. mc = (struct soc_multi_mixer_control *)(kcontrol->private_value);
  2338. hphr = mc->shift;
  2339. if (hphr)
  2340. wcd938x->comp2_enable = value;
  2341. else
  2342. wcd938x->comp1_enable = value;
  2343. return 0;
  2344. }
  2345. static int wcd938x_codec_enable_vdd_buck(struct snd_soc_dapm_widget *w,
  2346. struct snd_kcontrol *kcontrol,
  2347. int event)
  2348. {
  2349. struct snd_soc_component *component =
  2350. snd_soc_dapm_to_component(w->dapm);
  2351. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  2352. struct wcd938x_pdata *pdata = NULL;
  2353. int ret = 0;
  2354. pdata = dev_get_platdata(wcd938x->dev);
  2355. if (!pdata) {
  2356. dev_err(component->dev, "%s: pdata is NULL\n", __func__);
  2357. return -EINVAL;
  2358. }
  2359. if (!msm_cdc_is_ondemand_supply(wcd938x->dev,
  2360. wcd938x->supplies,
  2361. pdata->regulator,
  2362. pdata->num_supplies,
  2363. "cdc-vdd-buck"))
  2364. return 0;
  2365. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  2366. w->name, event);
  2367. switch (event) {
  2368. case SND_SOC_DAPM_PRE_PMU:
  2369. if (test_bit(ALLOW_BUCK_DISABLE, &wcd938x->status_mask)) {
  2370. dev_dbg(component->dev,
  2371. "%s: buck already in enabled state\n",
  2372. __func__);
  2373. clear_bit(ALLOW_BUCK_DISABLE, &wcd938x->status_mask);
  2374. return 0;
  2375. }
  2376. ret = msm_cdc_enable_ondemand_supply(wcd938x->dev,
  2377. wcd938x->supplies,
  2378. pdata->regulator,
  2379. pdata->num_supplies,
  2380. "cdc-vdd-buck");
  2381. if (ret == -EINVAL) {
  2382. dev_err(component->dev, "%s: vdd buck is not enabled\n",
  2383. __func__);
  2384. return ret;
  2385. }
  2386. clear_bit(ALLOW_BUCK_DISABLE, &wcd938x->status_mask);
  2387. /*
  2388. * 200us sleep is required after LDO is enabled as per
  2389. * HW requirement
  2390. */
  2391. usleep_range(200, 250);
  2392. break;
  2393. case SND_SOC_DAPM_POST_PMD:
  2394. set_bit(ALLOW_BUCK_DISABLE, &wcd938x->status_mask);
  2395. break;
  2396. }
  2397. return 0;
  2398. }
  2399. static int wcd938x_ldoh_get(struct snd_kcontrol *kcontrol,
  2400. struct snd_ctl_elem_value *ucontrol)
  2401. {
  2402. struct snd_soc_component *component =
  2403. snd_soc_kcontrol_component(kcontrol);
  2404. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  2405. ucontrol->value.integer.value[0] = wcd938x->ldoh;
  2406. return 0;
  2407. }
  2408. static int wcd938x_ldoh_put(struct snd_kcontrol *kcontrol,
  2409. struct snd_ctl_elem_value *ucontrol)
  2410. {
  2411. struct snd_soc_component *component =
  2412. snd_soc_kcontrol_component(kcontrol);
  2413. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  2414. wcd938x->ldoh = ucontrol->value.integer.value[0];
  2415. return 0;
  2416. }
  2417. const char * const tx_master_ch_text[] = {
  2418. "ZERO", "SWRM_TX1_CH1", "SWRM_TX1_CH2", "SWRM_TX1_CH3", "SWRM_TX1_CH4",
  2419. "SWRM_TX2_CH1", "SWRM_TX2_CH2", "SWRM_TX2_CH3", "SWRM_TX2_CH4",
  2420. "SWRM_TX3_CH1", "SWRM_TX3_CH2", "SWRM_TX3_CH3", "SWRM_TX3_CH4",
  2421. "SWRM_PCM_IN",
  2422. };
  2423. const struct soc_enum tx_master_ch_enum =
  2424. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(tx_master_ch_text),
  2425. tx_master_ch_text);
  2426. static void wcd938x_tx_get_slave_ch_type_idx(const char *wname, int *ch_idx)
  2427. {
  2428. u8 ch_type = 0;
  2429. if (strnstr(wname, "ADC1", sizeof("ADC1")))
  2430. ch_type = ADC1;
  2431. else if (strnstr(wname, "ADC2", sizeof("ADC2")))
  2432. ch_type = ADC2;
  2433. else if (strnstr(wname, "ADC3", sizeof("ADC3")))
  2434. ch_type = ADC3;
  2435. else if (strnstr(wname, "ADC4", sizeof("ADC4")))
  2436. ch_type = ADC4;
  2437. else if (strnstr(wname, "DMIC0", sizeof("DMIC0")))
  2438. ch_type = DMIC0;
  2439. else if (strnstr(wname, "DMIC1", sizeof("DMIC1")))
  2440. ch_type = DMIC1;
  2441. else if (strnstr(wname, "MBHC", sizeof("MBHC")))
  2442. ch_type = MBHC;
  2443. else if (strnstr(wname, "DMIC2", sizeof("DMIC2")))
  2444. ch_type = DMIC2;
  2445. else if (strnstr(wname, "DMIC3", sizeof("DMIC3")))
  2446. ch_type = DMIC3;
  2447. else if (strnstr(wname, "DMIC4", sizeof("DMIC4")))
  2448. ch_type = DMIC4;
  2449. else if (strnstr(wname, "DMIC5", sizeof("DMIC5")))
  2450. ch_type = DMIC5;
  2451. else if (strnstr(wname, "DMIC6", sizeof("DMIC6")))
  2452. ch_type = DMIC6;
  2453. else if (strnstr(wname, "DMIC7", sizeof("DMIC7")))
  2454. ch_type = DMIC7;
  2455. else
  2456. pr_err("%s: port name: %s is not listed\n", __func__, wname);
  2457. if (ch_type)
  2458. *ch_idx = wcd938x_slave_get_slave_ch_val(ch_type);
  2459. else
  2460. *ch_idx = -EINVAL;
  2461. }
  2462. static int wcd938x_tx_master_ch_get(struct snd_kcontrol *kcontrol,
  2463. struct snd_ctl_elem_value *ucontrol)
  2464. {
  2465. struct snd_soc_component *component =
  2466. snd_soc_kcontrol_component(kcontrol);
  2467. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  2468. int slave_ch_idx;
  2469. wcd938x_tx_get_slave_ch_type_idx(kcontrol->id.name, &slave_ch_idx);
  2470. if (slave_ch_idx != -EINVAL)
  2471. ucontrol->value.integer.value[0] =
  2472. wcd938x_slave_get_master_ch_val(
  2473. wcd938x->tx_master_ch_map[slave_ch_idx]);
  2474. return 0;
  2475. }
  2476. static int wcd938x_tx_master_ch_put(struct snd_kcontrol *kcontrol,
  2477. struct snd_ctl_elem_value *ucontrol)
  2478. {
  2479. struct snd_soc_component *component =
  2480. snd_soc_kcontrol_component(kcontrol);
  2481. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  2482. int slave_ch_idx;
  2483. wcd938x_tx_get_slave_ch_type_idx(kcontrol->id.name, &slave_ch_idx);
  2484. dev_dbg(component->dev, "%s: slave_ch_idx: %d", __func__, slave_ch_idx);
  2485. dev_dbg(component->dev, "%s: ucontrol->value.enumerated.item[0] = %ld\n",
  2486. __func__, ucontrol->value.enumerated.item[0]);
  2487. if (slave_ch_idx != -EINVAL)
  2488. wcd938x->tx_master_ch_map[slave_ch_idx] =
  2489. wcd938x_slave_get_master_ch(
  2490. ucontrol->value.enumerated.item[0]);
  2491. return 0;
  2492. }
  2493. static int wcd938x_bcs_get(struct snd_kcontrol *kcontrol,
  2494. struct snd_ctl_elem_value *ucontrol)
  2495. {
  2496. struct snd_soc_component *component =
  2497. snd_soc_kcontrol_component(kcontrol);
  2498. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  2499. ucontrol->value.integer.value[0] = wcd938x->bcs_dis;
  2500. return 0;
  2501. }
  2502. static int wcd938x_bcs_put(struct snd_kcontrol *kcontrol,
  2503. struct snd_ctl_elem_value *ucontrol)
  2504. {
  2505. struct snd_soc_component *component =
  2506. snd_soc_kcontrol_component(kcontrol);
  2507. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  2508. wcd938x->bcs_dis = ucontrol->value.integer.value[0];
  2509. return 0;
  2510. }
  2511. static const char * const tx_mode_mux_text_wcd9380[] = {
  2512. "ADC_INVALID", "ADC_HIFI", "ADC_LO_HIF", "ADC_NORMAL", "ADC_LP",
  2513. };
  2514. static const struct soc_enum tx_mode_mux_enum_wcd9380 =
  2515. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(tx_mode_mux_text_wcd9380),
  2516. tx_mode_mux_text_wcd9380);
  2517. static const char * const tx_mode_mux_text[] = {
  2518. "ADC_INVALID", "ADC_HIFI", "ADC_LO_HIF", "ADC_NORMAL", "ADC_LP",
  2519. "ADC_ULP1", "ADC_ULP2",
  2520. };
  2521. static const struct soc_enum tx_mode_mux_enum =
  2522. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(tx_mode_mux_text),
  2523. tx_mode_mux_text);
  2524. static const char * const rx_hph_mode_mux_text_wcd9380[] = {
  2525. "CLS_H_INVALID", "CLS_H_INVALID_1", "CLS_H_LP", "CLS_AB",
  2526. "CLS_H_LOHIFI", "CLS_H_ULP", "CLS_H_INVALID_2", "CLS_AB_LP",
  2527. "CLS_AB_LOHIFI",
  2528. };
  2529. static const char * const wcd938x_ear_pa_gain_text[] = {
  2530. "G_6_DB", "G_4P5_DB", "G_3_DB", "G_1P5_DB", "G_0_DB",
  2531. "G_M1P5_DB", "G_M3_DB", "G_M4P5_DB",
  2532. "G_M6_DB", "G_7P5_DB", "G_M9_DB",
  2533. "G_M10P5_DB", "G_M12_DB", "G_M13P5_DB",
  2534. "G_M15_DB", "G_M16P5_DB", "G_M18_DB",
  2535. };
  2536. static const struct soc_enum rx_hph_mode_mux_enum_wcd9380 =
  2537. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(rx_hph_mode_mux_text_wcd9380),
  2538. rx_hph_mode_mux_text_wcd9380);
  2539. static SOC_ENUM_SINGLE_EXT_DECL(wcd938x_ear_pa_gain_enum,
  2540. wcd938x_ear_pa_gain_text);
  2541. static const char * const rx_hph_mode_mux_text[] = {
  2542. "CLS_H_INVALID", "CLS_H_HIFI", "CLS_H_LP", "CLS_AB", "CLS_H_LOHIFI",
  2543. "CLS_H_ULP", "CLS_AB_HIFI", "CLS_AB_LP", "CLS_AB_LOHIFI",
  2544. };
  2545. static const struct soc_enum rx_hph_mode_mux_enum =
  2546. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(rx_hph_mode_mux_text),
  2547. rx_hph_mode_mux_text);
  2548. static const struct snd_kcontrol_new wcd9380_snd_controls[] = {
  2549. SOC_ENUM_EXT("EAR PA GAIN", wcd938x_ear_pa_gain_enum,
  2550. wcd938x_ear_pa_gain_get, wcd938x_ear_pa_gain_put),
  2551. SOC_ENUM_EXT("RX HPH Mode", rx_hph_mode_mux_enum_wcd9380,
  2552. wcd938x_rx_hph_mode_get, wcd938x_rx_hph_mode_put),
  2553. SOC_ENUM_EXT("TX0 MODE", tx_mode_mux_enum_wcd9380,
  2554. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  2555. SOC_ENUM_EXT("TX1 MODE", tx_mode_mux_enum_wcd9380,
  2556. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  2557. SOC_ENUM_EXT("TX2 MODE", tx_mode_mux_enum_wcd9380,
  2558. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  2559. SOC_ENUM_EXT("TX3 MODE", tx_mode_mux_enum_wcd9380,
  2560. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  2561. };
  2562. static const struct snd_kcontrol_new wcd9385_snd_controls[] = {
  2563. SOC_ENUM_EXT("RX HPH Mode", rx_hph_mode_mux_enum,
  2564. wcd938x_rx_hph_mode_get, wcd938x_rx_hph_mode_put),
  2565. SOC_ENUM_EXT("TX0 MODE", tx_mode_mux_enum,
  2566. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  2567. SOC_ENUM_EXT("TX1 MODE", tx_mode_mux_enum,
  2568. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  2569. SOC_ENUM_EXT("TX2 MODE", tx_mode_mux_enum,
  2570. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  2571. SOC_ENUM_EXT("TX3 MODE", tx_mode_mux_enum,
  2572. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  2573. };
  2574. static const struct snd_kcontrol_new wcd938x_snd_controls[] = {
  2575. SOC_SINGLE_EXT("HPHL_COMP Switch", SND_SOC_NOPM, 0, 1, 0,
  2576. wcd938x_get_compander, wcd938x_set_compander),
  2577. SOC_SINGLE_EXT("HPHR_COMP Switch", SND_SOC_NOPM, 1, 1, 0,
  2578. wcd938x_get_compander, wcd938x_set_compander),
  2579. SOC_SINGLE_EXT("LDOH Enable", SND_SOC_NOPM, 0, 1, 0,
  2580. wcd938x_ldoh_get, wcd938x_ldoh_put),
  2581. SOC_SINGLE_EXT("ADC2_BCS Disable", SND_SOC_NOPM, 0, 1, 0,
  2582. wcd938x_bcs_get, wcd938x_bcs_put),
  2583. SOC_SINGLE_TLV("HPHL Volume", WCD938X_HPH_L_EN, 0, 20, 1, line_gain),
  2584. SOC_SINGLE_TLV("HPHR Volume", WCD938X_HPH_R_EN, 0, 20, 1, line_gain),
  2585. SOC_SINGLE_TLV("ADC1 Volume", WCD938X_ANA_TX_CH1, 0, 20, 0,
  2586. analog_gain),
  2587. SOC_SINGLE_TLV("ADC2 Volume", WCD938X_ANA_TX_CH2, 0, 20, 0,
  2588. analog_gain),
  2589. SOC_SINGLE_TLV("ADC3 Volume", WCD938X_ANA_TX_CH3, 0, 20, 0,
  2590. analog_gain),
  2591. SOC_SINGLE_TLV("ADC4 Volume", WCD938X_ANA_TX_CH4, 0, 20, 0,
  2592. analog_gain),
  2593. SOC_ENUM_EXT("ADC1 ChMap", tx_master_ch_enum,
  2594. wcd938x_tx_master_ch_get, wcd938x_tx_master_ch_put),
  2595. SOC_ENUM_EXT("ADC2 ChMap", tx_master_ch_enum,
  2596. wcd938x_tx_master_ch_get, wcd938x_tx_master_ch_put),
  2597. SOC_ENUM_EXT("ADC3 ChMap", tx_master_ch_enum,
  2598. wcd938x_tx_master_ch_get, wcd938x_tx_master_ch_put),
  2599. SOC_ENUM_EXT("ADC4 ChMap", tx_master_ch_enum,
  2600. wcd938x_tx_master_ch_get, wcd938x_tx_master_ch_put),
  2601. SOC_ENUM_EXT("DMIC0 ChMap", tx_master_ch_enum,
  2602. wcd938x_tx_master_ch_get, wcd938x_tx_master_ch_put),
  2603. SOC_ENUM_EXT("DMIC1 ChMap", tx_master_ch_enum,
  2604. wcd938x_tx_master_ch_get, wcd938x_tx_master_ch_put),
  2605. SOC_ENUM_EXT("MBHC ChMap", tx_master_ch_enum,
  2606. wcd938x_tx_master_ch_get, wcd938x_tx_master_ch_put),
  2607. SOC_ENUM_EXT("DMIC2 ChMap", tx_master_ch_enum,
  2608. wcd938x_tx_master_ch_get, wcd938x_tx_master_ch_put),
  2609. SOC_ENUM_EXT("DMIC3 ChMap", tx_master_ch_enum,
  2610. wcd938x_tx_master_ch_get, wcd938x_tx_master_ch_put),
  2611. SOC_ENUM_EXT("DMIC4 ChMap", tx_master_ch_enum,
  2612. wcd938x_tx_master_ch_get, wcd938x_tx_master_ch_put),
  2613. SOC_ENUM_EXT("DMIC5 ChMap", tx_master_ch_enum,
  2614. wcd938x_tx_master_ch_get, wcd938x_tx_master_ch_put),
  2615. SOC_ENUM_EXT("DMIC6 ChMap", tx_master_ch_enum,
  2616. wcd938x_tx_master_ch_get, wcd938x_tx_master_ch_put),
  2617. SOC_ENUM_EXT("DMIC7 ChMap", tx_master_ch_enum,
  2618. wcd938x_tx_master_ch_get, wcd938x_tx_master_ch_put),
  2619. };
  2620. static const struct snd_kcontrol_new adc1_switch[] = {
  2621. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2622. };
  2623. static const struct snd_kcontrol_new adc2_switch[] = {
  2624. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2625. };
  2626. static const struct snd_kcontrol_new adc3_switch[] = {
  2627. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2628. };
  2629. static const struct snd_kcontrol_new adc4_switch[] = {
  2630. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2631. };
  2632. static const struct snd_kcontrol_new dmic1_switch[] = {
  2633. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2634. };
  2635. static const struct snd_kcontrol_new dmic2_switch[] = {
  2636. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2637. };
  2638. static const struct snd_kcontrol_new dmic3_switch[] = {
  2639. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2640. };
  2641. static const struct snd_kcontrol_new dmic4_switch[] = {
  2642. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2643. };
  2644. static const struct snd_kcontrol_new dmic5_switch[] = {
  2645. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2646. };
  2647. static const struct snd_kcontrol_new dmic6_switch[] = {
  2648. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2649. };
  2650. static const struct snd_kcontrol_new dmic7_switch[] = {
  2651. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2652. };
  2653. static const struct snd_kcontrol_new dmic8_switch[] = {
  2654. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2655. };
  2656. static const struct snd_kcontrol_new ear_rdac_switch[] = {
  2657. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2658. };
  2659. static const struct snd_kcontrol_new aux_rdac_switch[] = {
  2660. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2661. };
  2662. static const struct snd_kcontrol_new hphl_rdac_switch[] = {
  2663. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2664. };
  2665. static const struct snd_kcontrol_new hphr_rdac_switch[] = {
  2666. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2667. };
  2668. static const char * const adc2_mux_text[] = {
  2669. "INP2", "INP3"
  2670. };
  2671. static const struct soc_enum adc2_enum =
  2672. SOC_ENUM_SINGLE(WCD938X_TX_NEW_AMIC_MUX_CFG, 7,
  2673. ARRAY_SIZE(adc2_mux_text), adc2_mux_text);
  2674. static const struct snd_kcontrol_new tx_adc2_mux =
  2675. SOC_DAPM_ENUM("ADC2 MUX Mux", adc2_enum);
  2676. static const char * const adc3_mux_text[] = {
  2677. "INP4", "INP6"
  2678. };
  2679. static const struct soc_enum adc3_enum =
  2680. SOC_ENUM_SINGLE(WCD938X_TX_NEW_AMIC_MUX_CFG, 6,
  2681. ARRAY_SIZE(adc3_mux_text), adc3_mux_text);
  2682. static const struct snd_kcontrol_new tx_adc3_mux =
  2683. SOC_DAPM_ENUM("ADC3 MUX Mux", adc3_enum);
  2684. static const char * const adc4_mux_text[] = {
  2685. "INP5", "INP7"
  2686. };
  2687. static const struct soc_enum adc4_enum =
  2688. SOC_ENUM_SINGLE(WCD938X_TX_NEW_AMIC_MUX_CFG, 5,
  2689. ARRAY_SIZE(adc4_mux_text), adc4_mux_text);
  2690. static const struct snd_kcontrol_new tx_adc4_mux =
  2691. SOC_DAPM_ENUM("ADC4 MUX Mux", adc4_enum);
  2692. static const char * const rdac3_mux_text[] = {
  2693. "RX1", "RX3"
  2694. };
  2695. static const char * const hdr12_mux_text[] = {
  2696. "NO_HDR12", "HDR12"
  2697. };
  2698. static const struct soc_enum hdr12_enum =
  2699. SOC_ENUM_SINGLE(WCD938X_TX_NEW_AMIC_MUX_CFG, 4,
  2700. ARRAY_SIZE(hdr12_mux_text), hdr12_mux_text);
  2701. static const struct snd_kcontrol_new tx_hdr12_mux =
  2702. SOC_DAPM_ENUM("HDR12 MUX Mux", hdr12_enum);
  2703. static const char * const hdr34_mux_text[] = {
  2704. "NO_HDR34", "HDR34"
  2705. };
  2706. static const struct soc_enum hdr34_enum =
  2707. SOC_ENUM_SINGLE(WCD938X_TX_NEW_AMIC_MUX_CFG, 3,
  2708. ARRAY_SIZE(hdr34_mux_text), hdr34_mux_text);
  2709. static const struct snd_kcontrol_new tx_hdr34_mux =
  2710. SOC_DAPM_ENUM("HDR34 MUX Mux", hdr34_enum);
  2711. static const struct soc_enum rdac3_enum =
  2712. SOC_ENUM_SINGLE(WCD938X_DIGITAL_CDC_EAR_PATH_CTL, 0,
  2713. ARRAY_SIZE(rdac3_mux_text), rdac3_mux_text);
  2714. static const struct snd_kcontrol_new rx_rdac3_mux =
  2715. SOC_DAPM_ENUM("RDAC3_MUX Mux", rdac3_enum);
  2716. static const struct snd_soc_dapm_widget wcd938x_dapm_widgets[] = {
  2717. /*input widgets*/
  2718. SND_SOC_DAPM_INPUT("AMIC1"),
  2719. SND_SOC_DAPM_INPUT("AMIC2"),
  2720. SND_SOC_DAPM_INPUT("AMIC3"),
  2721. SND_SOC_DAPM_INPUT("AMIC4"),
  2722. SND_SOC_DAPM_INPUT("AMIC5"),
  2723. SND_SOC_DAPM_INPUT("AMIC6"),
  2724. SND_SOC_DAPM_INPUT("AMIC7"),
  2725. SND_SOC_DAPM_INPUT("IN1_HPHL"),
  2726. SND_SOC_DAPM_INPUT("IN2_HPHR"),
  2727. SND_SOC_DAPM_INPUT("IN3_AUX"),
  2728. /*
  2729. * These dummy widgets are null connected to WCD938x dapm input and
  2730. * output widgets which are not actual path endpoints. This ensures
  2731. * dapm doesnt set these dapm input and output widgets as endpoints.
  2732. */
  2733. SND_SOC_DAPM_INPUT("WCD_TX_DUMMY"),
  2734. SND_SOC_DAPM_OUTPUT("WCD_RX_DUMMY"),
  2735. /*tx widgets*/
  2736. SND_SOC_DAPM_ADC_E("ADC1", NULL, SND_SOC_NOPM, 0, 0,
  2737. wcd938x_codec_enable_adc,
  2738. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2739. SND_SOC_DAPM_ADC_E("ADC2", NULL, SND_SOC_NOPM, 1, 0,
  2740. wcd938x_codec_enable_adc,
  2741. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2742. SND_SOC_DAPM_ADC_E("ADC3", NULL, SND_SOC_NOPM, 2, 0,
  2743. wcd938x_codec_enable_adc,
  2744. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2745. SND_SOC_DAPM_ADC_E("ADC4", NULL, SND_SOC_NOPM, 3, 0,
  2746. wcd938x_codec_enable_adc,
  2747. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2748. SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0,
  2749. wcd938x_codec_enable_dmic,
  2750. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2751. SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 1, 0,
  2752. wcd938x_codec_enable_dmic,
  2753. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2754. SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 2, 0,
  2755. wcd938x_codec_enable_dmic,
  2756. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2757. SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 3, 0,
  2758. wcd938x_codec_enable_dmic,
  2759. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2760. SND_SOC_DAPM_ADC_E("DMIC5", NULL, SND_SOC_NOPM, 4, 0,
  2761. wcd938x_codec_enable_dmic,
  2762. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2763. SND_SOC_DAPM_ADC_E("DMIC6", NULL, SND_SOC_NOPM, 5, 0,
  2764. wcd938x_codec_enable_dmic,
  2765. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2766. SND_SOC_DAPM_ADC_E("DMIC7", NULL, SND_SOC_NOPM, 6, 0,
  2767. wcd938x_codec_enable_dmic,
  2768. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2769. SND_SOC_DAPM_ADC_E("DMIC8", NULL, SND_SOC_NOPM, 7, 0,
  2770. wcd938x_codec_enable_dmic,
  2771. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2772. SND_SOC_DAPM_MIXER_E("ADC1 REQ", SND_SOC_NOPM, 0, 0,
  2773. NULL, 0, wcd938x_enable_req,
  2774. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2775. SND_SOC_DAPM_MIXER_E("ADC2 REQ", SND_SOC_NOPM, 1, 0,
  2776. NULL, 0, wcd938x_enable_req,
  2777. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2778. SND_SOC_DAPM_MIXER_E("ADC3 REQ", SND_SOC_NOPM, 2, 0,
  2779. NULL, 0, wcd938x_enable_req,
  2780. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2781. SND_SOC_DAPM_MIXER_E("ADC4 REQ", SND_SOC_NOPM, 3, 0,
  2782. NULL, 0, wcd938x_enable_req,
  2783. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2784. SND_SOC_DAPM_MUX("ADC2 MUX", SND_SOC_NOPM, 0, 0,
  2785. &tx_adc2_mux),
  2786. SND_SOC_DAPM_MUX("ADC3 MUX", SND_SOC_NOPM, 0, 0,
  2787. &tx_adc3_mux),
  2788. SND_SOC_DAPM_MUX("ADC4 MUX", SND_SOC_NOPM, 0, 0,
  2789. &tx_adc4_mux),
  2790. SND_SOC_DAPM_MUX("HDR12 MUX", SND_SOC_NOPM, 0, 0,
  2791. &tx_hdr12_mux),
  2792. SND_SOC_DAPM_MUX("HDR34 MUX", SND_SOC_NOPM, 0, 0,
  2793. &tx_hdr34_mux),
  2794. /*tx mixers*/
  2795. SND_SOC_DAPM_MIXER_E("ADC1_MIXER", SND_SOC_NOPM, ADC1, 0,
  2796. adc1_switch, ARRAY_SIZE(adc1_switch),
  2797. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  2798. SND_SOC_DAPM_POST_PMD),
  2799. SND_SOC_DAPM_MIXER_E("ADC2_MIXER", SND_SOC_NOPM, ADC2, 0,
  2800. adc2_switch, ARRAY_SIZE(adc2_switch),
  2801. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  2802. SND_SOC_DAPM_POST_PMD),
  2803. SND_SOC_DAPM_MIXER_E("ADC3_MIXER", SND_SOC_NOPM, ADC3, 0, adc3_switch,
  2804. ARRAY_SIZE(adc3_switch), wcd938x_tx_swr_ctrl,
  2805. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2806. SND_SOC_DAPM_MIXER_E("ADC4_MIXER", SND_SOC_NOPM, ADC4, 0, adc4_switch,
  2807. ARRAY_SIZE(adc4_switch), wcd938x_tx_swr_ctrl,
  2808. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2809. SND_SOC_DAPM_MIXER_E("DMIC1_MIXER", SND_SOC_NOPM, DMIC1,
  2810. 0, dmic1_switch, ARRAY_SIZE(dmic1_switch),
  2811. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  2812. SND_SOC_DAPM_POST_PMD),
  2813. SND_SOC_DAPM_MIXER_E("DMIC2_MIXER", SND_SOC_NOPM, DMIC2,
  2814. 0, dmic2_switch, ARRAY_SIZE(dmic2_switch),
  2815. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  2816. SND_SOC_DAPM_POST_PMD),
  2817. SND_SOC_DAPM_MIXER_E("DMIC3_MIXER", SND_SOC_NOPM, DMIC3,
  2818. 0, dmic3_switch, ARRAY_SIZE(dmic3_switch),
  2819. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  2820. SND_SOC_DAPM_POST_PMD),
  2821. SND_SOC_DAPM_MIXER_E("DMIC4_MIXER", SND_SOC_NOPM, DMIC4,
  2822. 0, dmic4_switch, ARRAY_SIZE(dmic4_switch),
  2823. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  2824. SND_SOC_DAPM_POST_PMD),
  2825. SND_SOC_DAPM_MIXER_E("DMIC5_MIXER", SND_SOC_NOPM, DMIC5,
  2826. 0, dmic5_switch, ARRAY_SIZE(dmic5_switch),
  2827. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  2828. SND_SOC_DAPM_POST_PMD),
  2829. SND_SOC_DAPM_MIXER_E("DMIC6_MIXER", SND_SOC_NOPM, DMIC6,
  2830. 0, dmic6_switch, ARRAY_SIZE(dmic6_switch),
  2831. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  2832. SND_SOC_DAPM_POST_PMD),
  2833. SND_SOC_DAPM_MIXER_E("DMIC7_MIXER", SND_SOC_NOPM, DMIC7,
  2834. 0, dmic7_switch, ARRAY_SIZE(dmic7_switch),
  2835. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  2836. SND_SOC_DAPM_POST_PMD),
  2837. SND_SOC_DAPM_MIXER_E("DMIC8_MIXER", SND_SOC_NOPM, DMIC8,
  2838. 0, dmic8_switch, ARRAY_SIZE(dmic8_switch),
  2839. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  2840. SND_SOC_DAPM_POST_PMD),
  2841. /* micbias widgets*/
  2842. SND_SOC_DAPM_SUPPLY("MIC BIAS1", SND_SOC_NOPM, 0, 0,
  2843. wcd938x_codec_enable_micbias,
  2844. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2845. SND_SOC_DAPM_POST_PMD),
  2846. SND_SOC_DAPM_SUPPLY("MIC BIAS2", SND_SOC_NOPM, 0, 0,
  2847. wcd938x_codec_enable_micbias,
  2848. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2849. SND_SOC_DAPM_POST_PMD),
  2850. SND_SOC_DAPM_SUPPLY("MIC BIAS3", SND_SOC_NOPM, 0, 0,
  2851. wcd938x_codec_enable_micbias,
  2852. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2853. SND_SOC_DAPM_POST_PMD),
  2854. SND_SOC_DAPM_SUPPLY("MIC BIAS4", SND_SOC_NOPM, 0, 0,
  2855. wcd938x_codec_enable_micbias,
  2856. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2857. SND_SOC_DAPM_POST_PMD),
  2858. SND_SOC_DAPM_SUPPLY(DAPM_MICBIAS1_STANDALONE, SND_SOC_NOPM, 0, 0,
  2859. wcd938x_codec_force_enable_micbias,
  2860. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2861. SND_SOC_DAPM_SUPPLY(DAPM_MICBIAS2_STANDALONE, SND_SOC_NOPM, 0, 0,
  2862. wcd938x_codec_force_enable_micbias,
  2863. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2864. SND_SOC_DAPM_SUPPLY(DAPM_MICBIAS3_STANDALONE, SND_SOC_NOPM, 0, 0,
  2865. wcd938x_codec_force_enable_micbias,
  2866. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2867. SND_SOC_DAPM_SUPPLY(DAPM_MICBIAS4_STANDALONE, SND_SOC_NOPM, 0, 0,
  2868. wcd938x_codec_force_enable_micbias,
  2869. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2870. SND_SOC_DAPM_SUPPLY("VDD_BUCK", SND_SOC_NOPM, 0, 0,
  2871. wcd938x_codec_enable_vdd_buck,
  2872. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2873. SND_SOC_DAPM_SUPPLY_S("CLS_H_PORT", 1, SND_SOC_NOPM, 0, 0,
  2874. wcd938x_enable_clsh,
  2875. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2876. /*rx widgets*/
  2877. SND_SOC_DAPM_PGA_E("EAR PGA", WCD938X_ANA_EAR, 7, 0, NULL, 0,
  2878. wcd938x_codec_enable_ear_pa,
  2879. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2880. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2881. SND_SOC_DAPM_PGA_E("AUX PGA", WCD938X_AUX_AUXPA, 7, 0, NULL, 0,
  2882. wcd938x_codec_enable_aux_pa,
  2883. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2884. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2885. SND_SOC_DAPM_PGA_E("HPHL PGA", WCD938X_ANA_HPH, 7, 0, NULL, 0,
  2886. wcd938x_codec_enable_hphl_pa,
  2887. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2888. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2889. SND_SOC_DAPM_PGA_E("HPHR PGA", WCD938X_ANA_HPH, 6, 0, NULL, 0,
  2890. wcd938x_codec_enable_hphr_pa,
  2891. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2892. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2893. SND_SOC_DAPM_DAC_E("RDAC1", NULL, SND_SOC_NOPM, 0, 0,
  2894. wcd938x_codec_hphl_dac_event,
  2895. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2896. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2897. SND_SOC_DAPM_DAC_E("RDAC2", NULL, SND_SOC_NOPM, 0, 0,
  2898. wcd938x_codec_hphr_dac_event,
  2899. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2900. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2901. SND_SOC_DAPM_DAC_E("RDAC3", NULL, SND_SOC_NOPM, 0, 0,
  2902. wcd938x_codec_ear_dac_event,
  2903. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2904. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2905. SND_SOC_DAPM_DAC_E("RDAC4", NULL, SND_SOC_NOPM, 0, 0,
  2906. wcd938x_codec_aux_dac_event,
  2907. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2908. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2909. SND_SOC_DAPM_MUX("RDAC3_MUX", SND_SOC_NOPM, 0, 0, &rx_rdac3_mux),
  2910. SND_SOC_DAPM_MIXER_E("RX1", SND_SOC_NOPM, 0, 0, NULL, 0,
  2911. wcd938x_enable_rx1, SND_SOC_DAPM_PRE_PMU |
  2912. SND_SOC_DAPM_POST_PMD),
  2913. SND_SOC_DAPM_MIXER_E("RX2", SND_SOC_NOPM, 0, 0, NULL, 0,
  2914. wcd938x_enable_rx2, SND_SOC_DAPM_PRE_PMU |
  2915. SND_SOC_DAPM_POST_PMD),
  2916. SND_SOC_DAPM_MIXER_E("RX3", SND_SOC_NOPM, 0, 0, NULL, 0,
  2917. wcd938x_enable_rx3, SND_SOC_DAPM_PRE_PMU |
  2918. SND_SOC_DAPM_POST_PMD),
  2919. /* rx mixer widgets*/
  2920. SND_SOC_DAPM_MIXER("EAR_RDAC", SND_SOC_NOPM, 0, 0,
  2921. ear_rdac_switch, ARRAY_SIZE(ear_rdac_switch)),
  2922. SND_SOC_DAPM_MIXER("AUX_RDAC", SND_SOC_NOPM, 0, 0,
  2923. aux_rdac_switch, ARRAY_SIZE(aux_rdac_switch)),
  2924. SND_SOC_DAPM_MIXER("HPHL_RDAC", SND_SOC_NOPM, 0, 0,
  2925. hphl_rdac_switch, ARRAY_SIZE(hphl_rdac_switch)),
  2926. SND_SOC_DAPM_MIXER("HPHR_RDAC", SND_SOC_NOPM, 0, 0,
  2927. hphr_rdac_switch, ARRAY_SIZE(hphr_rdac_switch)),
  2928. /*output widgets tx*/
  2929. SND_SOC_DAPM_OUTPUT("WCD_TX_OUTPUT"),
  2930. /*output widgets rx*/
  2931. SND_SOC_DAPM_OUTPUT("EAR"),
  2932. SND_SOC_DAPM_OUTPUT("AUX"),
  2933. SND_SOC_DAPM_OUTPUT("HPHL"),
  2934. SND_SOC_DAPM_OUTPUT("HPHR"),
  2935. /* micbias pull up widgets*/
  2936. SND_SOC_DAPM_SUPPLY("VA MIC BIAS1", SND_SOC_NOPM, 0, 0,
  2937. wcd938x_codec_enable_micbias_pullup,
  2938. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2939. SND_SOC_DAPM_POST_PMD),
  2940. SND_SOC_DAPM_SUPPLY("VA MIC BIAS2", SND_SOC_NOPM, 0, 0,
  2941. wcd938x_codec_enable_micbias_pullup,
  2942. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2943. SND_SOC_DAPM_POST_PMD),
  2944. SND_SOC_DAPM_SUPPLY("VA MIC BIAS3", SND_SOC_NOPM, 0, 0,
  2945. wcd938x_codec_enable_micbias_pullup,
  2946. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2947. SND_SOC_DAPM_POST_PMD),
  2948. SND_SOC_DAPM_SUPPLY("VA MIC BIAS4", SND_SOC_NOPM, 0, 0,
  2949. wcd938x_codec_enable_micbias_pullup,
  2950. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2951. SND_SOC_DAPM_POST_PMD),
  2952. };
  2953. static const struct snd_soc_dapm_route wcd938x_audio_map[] = {
  2954. {"WCD_TX_DUMMY", NULL, "WCD_TX_OUTPUT"},
  2955. {"WCD_TX_OUTPUT", NULL, "ADC1_MIXER"},
  2956. {"ADC1_MIXER", "Switch", "ADC1 REQ"},
  2957. {"ADC1 REQ", NULL, "ADC1"},
  2958. {"ADC1", NULL, "AMIC1"},
  2959. {"WCD_TX_OUTPUT", NULL, "ADC2_MIXER"},
  2960. {"ADC2_MIXER", "Switch", "ADC2 REQ"},
  2961. {"ADC2 REQ", NULL, "ADC2"},
  2962. {"ADC2", NULL, "HDR12 MUX"},
  2963. {"HDR12 MUX", "NO_HDR12", "ADC2 MUX"},
  2964. {"HDR12 MUX", "HDR12", "AMIC1"},
  2965. {"ADC2 MUX", "INP3", "AMIC3"},
  2966. {"ADC2 MUX", "INP2", "AMIC2"},
  2967. {"WCD_TX_OUTPUT", NULL, "ADC3_MIXER"},
  2968. {"ADC3_MIXER", "Switch", "ADC3 REQ"},
  2969. {"ADC3 REQ", NULL, "ADC3"},
  2970. {"ADC3", NULL, "HDR34 MUX"},
  2971. {"HDR34 MUX", "NO_HDR34", "ADC3 MUX"},
  2972. {"HDR34 MUX", "HDR34", "AMIC5"},
  2973. {"ADC3 MUX", "INP4", "AMIC4"},
  2974. {"ADC3 MUX", "INP6", "AMIC6"},
  2975. {"WCD_TX_OUTPUT", NULL, "ADC4_MIXER"},
  2976. {"ADC4_MIXER", "Switch", "ADC4 REQ"},
  2977. {"ADC4 REQ", NULL, "ADC4"},
  2978. {"ADC4", NULL, "ADC4 MUX"},
  2979. {"ADC4 MUX", "INP5", "AMIC5"},
  2980. {"ADC4 MUX", "INP7", "AMIC7"},
  2981. {"WCD_TX_OUTPUT", NULL, "DMIC1_MIXER"},
  2982. {"DMIC1_MIXER", "Switch", "DMIC1"},
  2983. {"WCD_TX_OUTPUT", NULL, "DMIC2_MIXER"},
  2984. {"DMIC2_MIXER", "Switch", "DMIC2"},
  2985. {"WCD_TX_OUTPUT", NULL, "DMIC3_MIXER"},
  2986. {"DMIC3_MIXER", "Switch", "DMIC3"},
  2987. {"WCD_TX_OUTPUT", NULL, "DMIC4_MIXER"},
  2988. {"DMIC4_MIXER", "Switch", "DMIC4"},
  2989. {"WCD_TX_OUTPUT", NULL, "DMIC5_MIXER"},
  2990. {"DMIC5_MIXER", "Switch", "DMIC5"},
  2991. {"WCD_TX_OUTPUT", NULL, "DMIC6_MIXER"},
  2992. {"DMIC6_MIXER", "Switch", "DMIC6"},
  2993. {"WCD_TX_OUTPUT", NULL, "DMIC7_MIXER"},
  2994. {"DMIC7_MIXER", "Switch", "DMIC7"},
  2995. {"WCD_TX_OUTPUT", NULL, "DMIC8_MIXER"},
  2996. {"DMIC8_MIXER", "Switch", "DMIC8"},
  2997. {"IN1_HPHL", NULL, "WCD_RX_DUMMY"},
  2998. {"IN1_HPHL", NULL, "VDD_BUCK"},
  2999. {"IN1_HPHL", NULL, "CLS_H_PORT"},
  3000. {"RX1", NULL, "IN1_HPHL"},
  3001. {"RDAC1", NULL, "RX1"},
  3002. {"HPHL_RDAC", "Switch", "RDAC1"},
  3003. {"HPHL PGA", NULL, "HPHL_RDAC"},
  3004. {"HPHL", NULL, "HPHL PGA"},
  3005. {"IN2_HPHR", NULL, "WCD_RX_DUMMY"},
  3006. {"IN2_HPHR", NULL, "VDD_BUCK"},
  3007. {"IN2_HPHR", NULL, "CLS_H_PORT"},
  3008. {"RX2", NULL, "IN2_HPHR"},
  3009. {"RDAC2", NULL, "RX2"},
  3010. {"HPHR_RDAC", "Switch", "RDAC2"},
  3011. {"HPHR PGA", NULL, "HPHR_RDAC"},
  3012. {"HPHR", NULL, "HPHR PGA"},
  3013. {"IN3_AUX", NULL, "WCD_RX_DUMMY"},
  3014. {"IN3_AUX", NULL, "VDD_BUCK"},
  3015. {"IN3_AUX", NULL, "CLS_H_PORT"},
  3016. {"RX3", NULL, "IN3_AUX"},
  3017. {"RDAC4", NULL, "RX3"},
  3018. {"AUX_RDAC", "Switch", "RDAC4"},
  3019. {"AUX PGA", NULL, "AUX_RDAC"},
  3020. {"AUX", NULL, "AUX PGA"},
  3021. {"RDAC3_MUX", "RX3", "RX3"},
  3022. {"RDAC3_MUX", "RX1", "RX1"},
  3023. {"RDAC3", NULL, "RDAC3_MUX"},
  3024. {"EAR_RDAC", "Switch", "RDAC3"},
  3025. {"EAR PGA", NULL, "EAR_RDAC"},
  3026. {"EAR", NULL, "EAR PGA"},
  3027. };
  3028. static ssize_t wcd938x_version_read(struct snd_info_entry *entry,
  3029. void *file_private_data,
  3030. struct file *file,
  3031. char __user *buf, size_t count,
  3032. loff_t pos)
  3033. {
  3034. struct wcd938x_priv *priv;
  3035. char buffer[WCD938X_VERSION_ENTRY_SIZE];
  3036. int len = 0;
  3037. priv = (struct wcd938x_priv *) entry->private_data;
  3038. if (!priv) {
  3039. pr_err("%s: wcd938x priv is null\n", __func__);
  3040. return -EINVAL;
  3041. }
  3042. switch (priv->version) {
  3043. case WCD938X_VERSION_1_0:
  3044. len = snprintf(buffer, sizeof(buffer), "WCD938X_1_0\n");
  3045. break;
  3046. default:
  3047. len = snprintf(buffer, sizeof(buffer), "VER_UNDEFINED\n");
  3048. }
  3049. return simple_read_from_buffer(buf, count, &pos, buffer, len);
  3050. }
  3051. static struct snd_info_entry_ops wcd938x_info_ops = {
  3052. .read = wcd938x_version_read,
  3053. };
  3054. static ssize_t wcd938x_variant_read(struct snd_info_entry *entry,
  3055. void *file_private_data,
  3056. struct file *file,
  3057. char __user *buf, size_t count,
  3058. loff_t pos)
  3059. {
  3060. struct wcd938x_priv *priv;
  3061. char buffer[WCD938X_VARIANT_ENTRY_SIZE];
  3062. int len = 0;
  3063. priv = (struct wcd938x_priv *) entry->private_data;
  3064. if (!priv) {
  3065. pr_err("%s: wcd938x priv is null\n", __func__);
  3066. return -EINVAL;
  3067. }
  3068. switch (priv->variant) {
  3069. case WCD9380:
  3070. len = snprintf(buffer, sizeof(buffer), "WCD9380\n");
  3071. break;
  3072. case WCD9385:
  3073. len = snprintf(buffer, sizeof(buffer), "WCD9385\n");
  3074. break;
  3075. default:
  3076. len = snprintf(buffer, sizeof(buffer), "VER_UNDEFINED\n");
  3077. }
  3078. return simple_read_from_buffer(buf, count, &pos, buffer, len);
  3079. }
  3080. static struct snd_info_entry_ops wcd938x_variant_ops = {
  3081. .read = wcd938x_variant_read,
  3082. };
  3083. /*
  3084. * wcd938x_get_codec_variant
  3085. * @component: component instance
  3086. *
  3087. * Return: codec variant or -EINVAL in error.
  3088. */
  3089. int wcd938x_get_codec_variant(struct snd_soc_component *component)
  3090. {
  3091. struct wcd938x_priv *priv = NULL;
  3092. if (!component)
  3093. return -EINVAL;
  3094. priv = snd_soc_component_get_drvdata(component);
  3095. if (!priv) {
  3096. dev_err(component->dev,
  3097. "%s:wcd938x not probed\n", __func__);
  3098. return 0;
  3099. }
  3100. return priv->variant;
  3101. }
  3102. EXPORT_SYMBOL(wcd938x_get_codec_variant);
  3103. /*
  3104. * wcd938x_info_create_codec_entry - creates wcd938x module
  3105. * @codec_root: The parent directory
  3106. * @component: component instance
  3107. *
  3108. * Creates wcd938x module, variant and version entry under the given
  3109. * parent directory.
  3110. *
  3111. * Return: 0 on success or negative error code on failure.
  3112. */
  3113. int wcd938x_info_create_codec_entry(struct snd_info_entry *codec_root,
  3114. struct snd_soc_component *component)
  3115. {
  3116. struct snd_info_entry *version_entry;
  3117. struct snd_info_entry *variant_entry;
  3118. struct wcd938x_priv *priv;
  3119. struct snd_soc_card *card;
  3120. if (!codec_root || !component)
  3121. return -EINVAL;
  3122. priv = snd_soc_component_get_drvdata(component);
  3123. if (priv->entry) {
  3124. dev_dbg(priv->dev,
  3125. "%s:wcd938x module already created\n", __func__);
  3126. return 0;
  3127. }
  3128. card = component->card;
  3129. priv->entry = snd_info_create_module_entry(codec_root->module,
  3130. "wcd938x", codec_root);
  3131. if (!priv->entry) {
  3132. dev_dbg(component->dev, "%s: failed to create wcd938x entry\n",
  3133. __func__);
  3134. return -ENOMEM;
  3135. }
  3136. priv->entry->mode = S_IFDIR | 0555;
  3137. if (snd_info_register(priv->entry) < 0) {
  3138. snd_info_free_entry(priv->entry);
  3139. return -ENOMEM;
  3140. }
  3141. version_entry = snd_info_create_card_entry(card->snd_card,
  3142. "version",
  3143. priv->entry);
  3144. if (!version_entry) {
  3145. dev_dbg(component->dev, "%s: failed to create wcd938x version entry\n",
  3146. __func__);
  3147. snd_info_free_entry(priv->entry);
  3148. return -ENOMEM;
  3149. }
  3150. version_entry->private_data = priv;
  3151. version_entry->size = WCD938X_VERSION_ENTRY_SIZE;
  3152. version_entry->content = SNDRV_INFO_CONTENT_DATA;
  3153. version_entry->c.ops = &wcd938x_info_ops;
  3154. if (snd_info_register(version_entry) < 0) {
  3155. snd_info_free_entry(version_entry);
  3156. snd_info_free_entry(priv->entry);
  3157. return -ENOMEM;
  3158. }
  3159. priv->version_entry = version_entry;
  3160. variant_entry = snd_info_create_card_entry(card->snd_card,
  3161. "variant",
  3162. priv->entry);
  3163. if (!variant_entry) {
  3164. dev_dbg(component->dev, "%s: failed to create wcd938x variant entry\n",
  3165. __func__);
  3166. snd_info_free_entry(version_entry);
  3167. snd_info_free_entry(priv->entry);
  3168. return -ENOMEM;
  3169. }
  3170. variant_entry->private_data = priv;
  3171. variant_entry->size = WCD938X_VARIANT_ENTRY_SIZE;
  3172. variant_entry->content = SNDRV_INFO_CONTENT_DATA;
  3173. variant_entry->c.ops = &wcd938x_variant_ops;
  3174. if (snd_info_register(variant_entry) < 0) {
  3175. snd_info_free_entry(variant_entry);
  3176. snd_info_free_entry(version_entry);
  3177. snd_info_free_entry(priv->entry);
  3178. return -ENOMEM;
  3179. }
  3180. priv->variant_entry = variant_entry;
  3181. return 0;
  3182. }
  3183. EXPORT_SYMBOL(wcd938x_info_create_codec_entry);
  3184. static int wcd938x_set_micbias_data(struct wcd938x_priv *wcd938x,
  3185. struct wcd938x_pdata *pdata)
  3186. {
  3187. int vout_ctl_1 = 0, vout_ctl_2 = 0, vout_ctl_3 = 0, vout_ctl_4 = 0;
  3188. int rc = 0;
  3189. if (!pdata) {
  3190. dev_err(wcd938x->dev, "%s: NULL pdata\n", __func__);
  3191. return -ENODEV;
  3192. }
  3193. /* set micbias voltage */
  3194. vout_ctl_1 = wcd938x_get_micb_vout_ctl_val(pdata->micbias.micb1_mv);
  3195. vout_ctl_2 = wcd938x_get_micb_vout_ctl_val(pdata->micbias.micb2_mv);
  3196. vout_ctl_3 = wcd938x_get_micb_vout_ctl_val(pdata->micbias.micb3_mv);
  3197. vout_ctl_4 = wcd938x_get_micb_vout_ctl_val(pdata->micbias.micb4_mv);
  3198. if (vout_ctl_1 < 0 || vout_ctl_2 < 0 || vout_ctl_3 < 0 ||
  3199. vout_ctl_4 < 0) {
  3200. rc = -EINVAL;
  3201. goto done;
  3202. }
  3203. regmap_update_bits(wcd938x->regmap, WCD938X_ANA_MICB1, 0x3F,
  3204. vout_ctl_1);
  3205. regmap_update_bits(wcd938x->regmap, WCD938X_ANA_MICB2, 0x3F,
  3206. vout_ctl_2);
  3207. regmap_update_bits(wcd938x->regmap, WCD938X_ANA_MICB3, 0x3F,
  3208. vout_ctl_3);
  3209. regmap_update_bits(wcd938x->regmap, WCD938X_ANA_MICB4, 0x3F,
  3210. vout_ctl_4);
  3211. done:
  3212. return rc;
  3213. }
  3214. static int wcd938x_soc_codec_probe(struct snd_soc_component *component)
  3215. {
  3216. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  3217. struct snd_soc_dapm_context *dapm =
  3218. snd_soc_component_get_dapm(component);
  3219. int variant;
  3220. int ret = -EINVAL;
  3221. dev_info(component->dev, "%s()\n", __func__);
  3222. wcd938x = snd_soc_component_get_drvdata(component);
  3223. if (!wcd938x)
  3224. return -EINVAL;
  3225. wcd938x->component = component;
  3226. snd_soc_component_init_regmap(component, wcd938x->regmap);
  3227. variant = (snd_soc_component_read32(component,
  3228. WCD938X_DIGITAL_EFUSE_REG_0) & 0x1E) >> 1;
  3229. wcd938x->variant = variant;
  3230. wcd938x->fw_data = devm_kzalloc(component->dev,
  3231. sizeof(*(wcd938x->fw_data)),
  3232. GFP_KERNEL);
  3233. if (!wcd938x->fw_data) {
  3234. dev_err(component->dev, "Failed to allocate fw_data\n");
  3235. ret = -ENOMEM;
  3236. goto err;
  3237. }
  3238. set_bit(WCD9XXX_MBHC_CAL, wcd938x->fw_data->cal_bit);
  3239. ret = wcd_cal_create_hwdep(wcd938x->fw_data,
  3240. WCD9XXX_CODEC_HWDEP_NODE, component);
  3241. if (ret < 0) {
  3242. dev_err(component->dev, "%s hwdep failed %d\n", __func__, ret);
  3243. goto err_hwdep;
  3244. }
  3245. ret = wcd938x_mbhc_init(&wcd938x->mbhc, component, wcd938x->fw_data);
  3246. if (ret) {
  3247. pr_err("%s: mbhc initialization failed\n", __func__);
  3248. goto err_hwdep;
  3249. }
  3250. snd_soc_dapm_ignore_suspend(dapm, "WCD938X_AIF Playback");
  3251. snd_soc_dapm_ignore_suspend(dapm, "WCD938X_AIF Capture");
  3252. snd_soc_dapm_ignore_suspend(dapm, "AMIC1");
  3253. snd_soc_dapm_ignore_suspend(dapm, "AMIC2");
  3254. snd_soc_dapm_ignore_suspend(dapm, "AMIC3");
  3255. snd_soc_dapm_ignore_suspend(dapm, "AMIC4");
  3256. snd_soc_dapm_ignore_suspend(dapm, "AMIC5");
  3257. snd_soc_dapm_ignore_suspend(dapm, "AMIC6");
  3258. snd_soc_dapm_ignore_suspend(dapm, "AMIC7");
  3259. snd_soc_dapm_ignore_suspend(dapm, "WCD_TX_OUTPUT");
  3260. snd_soc_dapm_ignore_suspend(dapm, "IN1_HPHL");
  3261. snd_soc_dapm_ignore_suspend(dapm, "IN2_HPHR");
  3262. snd_soc_dapm_ignore_suspend(dapm, "IN3_AUX");
  3263. snd_soc_dapm_ignore_suspend(dapm, "EAR");
  3264. snd_soc_dapm_ignore_suspend(dapm, "AUX");
  3265. snd_soc_dapm_ignore_suspend(dapm, "HPHL");
  3266. snd_soc_dapm_ignore_suspend(dapm, "HPHR");
  3267. snd_soc_dapm_ignore_suspend(dapm, "WCD_TX_DUMMY");
  3268. snd_soc_dapm_ignore_suspend(dapm, "WCD_RX_DUMMY");
  3269. snd_soc_dapm_sync(dapm);
  3270. wcd_cls_h_init(&wcd938x->clsh_info);
  3271. wcd938x_init_reg(component);
  3272. if (wcd938x->variant == WCD9380) {
  3273. ret = snd_soc_add_component_controls(component, wcd9380_snd_controls,
  3274. ARRAY_SIZE(wcd9380_snd_controls));
  3275. if (ret < 0) {
  3276. dev_err(component->dev,
  3277. "%s: Failed to add snd ctrls for variant: %d\n",
  3278. __func__, wcd938x->variant);
  3279. goto err_hwdep;
  3280. }
  3281. }
  3282. if (wcd938x->variant == WCD9385) {
  3283. ret = snd_soc_add_component_controls(component, wcd9385_snd_controls,
  3284. ARRAY_SIZE(wcd9385_snd_controls));
  3285. if (ret < 0) {
  3286. dev_err(component->dev,
  3287. "%s: Failed to add snd ctrls for variant: %d\n",
  3288. __func__, wcd938x->variant);
  3289. goto err_hwdep;
  3290. }
  3291. }
  3292. wcd938x->version = WCD938X_VERSION_1_0;
  3293. /* Register event notifier */
  3294. wcd938x->nblock.notifier_call = wcd938x_event_notify;
  3295. if (wcd938x->register_notifier) {
  3296. ret = wcd938x->register_notifier(wcd938x->handle,
  3297. &wcd938x->nblock,
  3298. true);
  3299. if (ret) {
  3300. dev_err(component->dev,
  3301. "%s: Failed to register notifier %d\n",
  3302. __func__, ret);
  3303. return ret;
  3304. }
  3305. }
  3306. wcd938x->dev_up = true;
  3307. return ret;
  3308. err_hwdep:
  3309. wcd938x->fw_data = NULL;
  3310. err:
  3311. return ret;
  3312. }
  3313. static void wcd938x_soc_codec_remove(struct snd_soc_component *component)
  3314. {
  3315. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  3316. if (!wcd938x) {
  3317. dev_err(component->dev, "%s: wcd938x is already NULL\n",
  3318. __func__);
  3319. return;
  3320. }
  3321. if (wcd938x->register_notifier)
  3322. wcd938x->register_notifier(wcd938x->handle,
  3323. &wcd938x->nblock,
  3324. false);
  3325. }
  3326. static int wcd938x_soc_codec_suspend(struct snd_soc_component *component)
  3327. {
  3328. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  3329. if (!wcd938x)
  3330. return 0;
  3331. wcd938x->dapm_bias_off = true;
  3332. return 0;
  3333. }
  3334. static int wcd938x_soc_codec_resume(struct snd_soc_component *component)
  3335. {
  3336. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  3337. if (!wcd938x)
  3338. return 0;
  3339. wcd938x->dapm_bias_off = false;
  3340. return 0;
  3341. }
  3342. static struct snd_soc_component_driver soc_codec_dev_wcd938x = {
  3343. .name = WCD938X_DRV_NAME,
  3344. .probe = wcd938x_soc_codec_probe,
  3345. .remove = wcd938x_soc_codec_remove,
  3346. .controls = wcd938x_snd_controls,
  3347. .num_controls = ARRAY_SIZE(wcd938x_snd_controls),
  3348. .dapm_widgets = wcd938x_dapm_widgets,
  3349. .num_dapm_widgets = ARRAY_SIZE(wcd938x_dapm_widgets),
  3350. .dapm_routes = wcd938x_audio_map,
  3351. .num_dapm_routes = ARRAY_SIZE(wcd938x_audio_map),
  3352. .suspend = wcd938x_soc_codec_suspend,
  3353. .resume = wcd938x_soc_codec_resume,
  3354. };
  3355. static int wcd938x_reset(struct device *dev)
  3356. {
  3357. struct wcd938x_priv *wcd938x = NULL;
  3358. int rc = 0;
  3359. int value = 0;
  3360. if (!dev)
  3361. return -ENODEV;
  3362. wcd938x = dev_get_drvdata(dev);
  3363. if (!wcd938x)
  3364. return -EINVAL;
  3365. if (!wcd938x->rst_np) {
  3366. dev_err(dev, "%s: reset gpio device node not specified\n",
  3367. __func__);
  3368. return -EINVAL;
  3369. }
  3370. value = msm_cdc_pinctrl_get_state(wcd938x->rst_np);
  3371. if (value > 0)
  3372. return 0;
  3373. rc = msm_cdc_pinctrl_select_sleep_state(wcd938x->rst_np);
  3374. if (rc) {
  3375. dev_err(dev, "%s: wcd sleep state request fail!\n",
  3376. __func__);
  3377. return rc;
  3378. }
  3379. /* 20us sleep required after pulling the reset gpio to LOW */
  3380. usleep_range(20, 30);
  3381. rc = msm_cdc_pinctrl_select_active_state(wcd938x->rst_np);
  3382. if (rc) {
  3383. dev_err(dev, "%s: wcd active state request fail!\n",
  3384. __func__);
  3385. return rc;
  3386. }
  3387. /* 20us sleep required after pulling the reset gpio to HIGH */
  3388. usleep_range(20, 30);
  3389. return rc;
  3390. }
  3391. static int wcd938x_read_of_property_u32(struct device *dev, const char *name,
  3392. u32 *val)
  3393. {
  3394. int rc = 0;
  3395. rc = of_property_read_u32(dev->of_node, name, val);
  3396. if (rc)
  3397. dev_err(dev, "%s: Looking up %s property in node %s failed\n",
  3398. __func__, name, dev->of_node->full_name);
  3399. return rc;
  3400. }
  3401. static void wcd938x_dt_parse_micbias_info(struct device *dev,
  3402. struct wcd938x_micbias_setting *mb)
  3403. {
  3404. u32 prop_val = 0;
  3405. int rc = 0;
  3406. /* MB1 */
  3407. if (of_find_property(dev->of_node, "qcom,cdc-micbias1-mv",
  3408. NULL)) {
  3409. rc = wcd938x_read_of_property_u32(dev,
  3410. "qcom,cdc-micbias1-mv",
  3411. &prop_val);
  3412. if (!rc)
  3413. mb->micb1_mv = prop_val;
  3414. } else {
  3415. dev_info(dev, "%s: Micbias1 DT property not found\n",
  3416. __func__);
  3417. }
  3418. /* MB2 */
  3419. if (of_find_property(dev->of_node, "qcom,cdc-micbias2-mv",
  3420. NULL)) {
  3421. rc = wcd938x_read_of_property_u32(dev,
  3422. "qcom,cdc-micbias2-mv",
  3423. &prop_val);
  3424. if (!rc)
  3425. mb->micb2_mv = prop_val;
  3426. } else {
  3427. dev_info(dev, "%s: Micbias2 DT property not found\n",
  3428. __func__);
  3429. }
  3430. /* MB3 */
  3431. if (of_find_property(dev->of_node, "qcom,cdc-micbias3-mv",
  3432. NULL)) {
  3433. rc = wcd938x_read_of_property_u32(dev,
  3434. "qcom,cdc-micbias3-mv",
  3435. &prop_val);
  3436. if (!rc)
  3437. mb->micb3_mv = prop_val;
  3438. } else {
  3439. dev_info(dev, "%s: Micbias3 DT property not found\n",
  3440. __func__);
  3441. }
  3442. /* MB4 */
  3443. if (of_find_property(dev->of_node, "qcom,cdc-micbias4-mv",
  3444. NULL)) {
  3445. rc = wcd938x_read_of_property_u32(dev,
  3446. "qcom,cdc-micbias4-mv",
  3447. &prop_val);
  3448. if (!rc)
  3449. mb->micb4_mv = prop_val;
  3450. } else {
  3451. dev_info(dev, "%s: Micbias4 DT property not found\n",
  3452. __func__);
  3453. }
  3454. }
  3455. static int wcd938x_reset_low(struct device *dev)
  3456. {
  3457. struct wcd938x_priv *wcd938x = NULL;
  3458. int rc = 0;
  3459. if (!dev)
  3460. return -ENODEV;
  3461. wcd938x = dev_get_drvdata(dev);
  3462. if (!wcd938x)
  3463. return -EINVAL;
  3464. if (!wcd938x->rst_np) {
  3465. dev_err(dev, "%s: reset gpio device node not specified\n",
  3466. __func__);
  3467. return -EINVAL;
  3468. }
  3469. rc = msm_cdc_pinctrl_select_sleep_state(wcd938x->rst_np);
  3470. if (rc) {
  3471. dev_err(dev, "%s: wcd sleep state request fail!\n",
  3472. __func__);
  3473. return rc;
  3474. }
  3475. /* 20us sleep required after pulling the reset gpio to LOW */
  3476. usleep_range(20, 30);
  3477. return rc;
  3478. }
  3479. struct wcd938x_pdata *wcd938x_populate_dt_data(struct device *dev)
  3480. {
  3481. struct wcd938x_pdata *pdata = NULL;
  3482. pdata = devm_kzalloc(dev, sizeof(struct wcd938x_pdata),
  3483. GFP_KERNEL);
  3484. if (!pdata)
  3485. return NULL;
  3486. pdata->rst_np = of_parse_phandle(dev->of_node,
  3487. "qcom,wcd-rst-gpio-node", 0);
  3488. if (!pdata->rst_np) {
  3489. dev_err(dev, "%s: Looking up %s property in node %s failed\n",
  3490. __func__, "qcom,wcd-rst-gpio-node",
  3491. dev->of_node->full_name);
  3492. return NULL;
  3493. }
  3494. /* Parse power supplies */
  3495. msm_cdc_get_power_supplies(dev, &pdata->regulator,
  3496. &pdata->num_supplies);
  3497. if (!pdata->regulator || (pdata->num_supplies <= 0)) {
  3498. dev_err(dev, "%s: no power supplies defined for codec\n",
  3499. __func__);
  3500. return NULL;
  3501. }
  3502. pdata->rx_slave = of_parse_phandle(dev->of_node, "qcom,rx-slave", 0);
  3503. pdata->tx_slave = of_parse_phandle(dev->of_node, "qcom,tx-slave", 0);
  3504. wcd938x_dt_parse_micbias_info(dev, &pdata->micbias);
  3505. return pdata;
  3506. }
  3507. static irqreturn_t wcd938x_wd_handle_irq(int irq, void *data)
  3508. {
  3509. pr_err_ratelimited("%s: Watchdog interrupt for irq =%d triggered\n",
  3510. __func__, irq);
  3511. return IRQ_HANDLED;
  3512. }
  3513. static struct snd_soc_dai_driver wcd938x_dai[] = {
  3514. {
  3515. .name = "wcd938x_cdc",
  3516. .playback = {
  3517. .stream_name = "WCD938X_AIF Playback",
  3518. .rates = WCD938X_RATES | WCD938X_FRAC_RATES,
  3519. .formats = WCD938X_FORMATS,
  3520. .rate_max = 192000,
  3521. .rate_min = 8000,
  3522. .channels_min = 1,
  3523. .channels_max = 4,
  3524. },
  3525. .capture = {
  3526. .stream_name = "WCD938X_AIF Capture",
  3527. .rates = WCD938X_RATES | WCD938X_FRAC_RATES,
  3528. .formats = WCD938X_FORMATS,
  3529. .rate_max = 192000,
  3530. .rate_min = 8000,
  3531. .channels_min = 1,
  3532. .channels_max = 4,
  3533. },
  3534. },
  3535. };
  3536. static int wcd938x_bind(struct device *dev)
  3537. {
  3538. int ret = 0, i = 0;
  3539. struct wcd938x_pdata *pdata = dev_get_platdata(dev);
  3540. struct wcd938x_priv *wcd938x = dev_get_drvdata(dev);
  3541. /*
  3542. * Add 5msec delay to provide sufficient time for
  3543. * soundwire auto enumeration of slave devices as
  3544. * as per HW requirement.
  3545. */
  3546. usleep_range(5000, 5010);
  3547. ret = component_bind_all(dev, wcd938x);
  3548. if (ret) {
  3549. dev_err(dev, "%s: Slave bind failed, ret = %d\n",
  3550. __func__, ret);
  3551. return ret;
  3552. }
  3553. wcd938x->rx_swr_dev = get_matching_swr_slave_device(pdata->rx_slave);
  3554. if (!wcd938x->rx_swr_dev) {
  3555. dev_err(dev, "%s: Could not find RX swr slave device\n",
  3556. __func__);
  3557. ret = -ENODEV;
  3558. goto err;
  3559. }
  3560. wcd938x->tx_swr_dev = get_matching_swr_slave_device(pdata->tx_slave);
  3561. if (!wcd938x->tx_swr_dev) {
  3562. dev_err(dev, "%s: Could not find TX swr slave device\n",
  3563. __func__);
  3564. ret = -ENODEV;
  3565. goto err;
  3566. }
  3567. wcd938x->regmap = devm_regmap_init_swr(wcd938x->tx_swr_dev,
  3568. &wcd938x_regmap_config);
  3569. if (!wcd938x->regmap) {
  3570. dev_err(dev, "%s: Regmap init failed\n",
  3571. __func__);
  3572. goto err;
  3573. }
  3574. /* Set all interupts as edge triggered */
  3575. for (i = 0; i < wcd938x_regmap_irq_chip.num_regs; i++)
  3576. regmap_write(wcd938x->regmap,
  3577. (WCD938X_DIGITAL_INTR_LEVEL_0 + i), 0);
  3578. wcd938x_regmap_irq_chip.irq_drv_data = wcd938x;
  3579. wcd938x->irq_info.wcd_regmap_irq_chip = &wcd938x_regmap_irq_chip;
  3580. wcd938x->irq_info.codec_name = "WCD938X";
  3581. wcd938x->irq_info.regmap = wcd938x->regmap;
  3582. wcd938x->irq_info.dev = dev;
  3583. ret = wcd_irq_init(&wcd938x->irq_info, &wcd938x->virq);
  3584. if (ret) {
  3585. dev_err(wcd938x->dev, "%s: IRQ init failed: %d\n",
  3586. __func__, ret);
  3587. goto err;
  3588. }
  3589. wcd938x->tx_swr_dev->slave_irq = wcd938x->virq;
  3590. ret = wcd938x_set_micbias_data(wcd938x, pdata);
  3591. if (ret < 0) {
  3592. dev_err(dev, "%s: bad micbias pdata\n", __func__);
  3593. goto err_irq;
  3594. }
  3595. /* Request for watchdog interrupt */
  3596. wcd_request_irq(&wcd938x->irq_info, WCD938X_IRQ_HPHR_PDM_WD_INT,
  3597. "HPHR PDM WD INT", wcd938x_wd_handle_irq, NULL);
  3598. wcd_request_irq(&wcd938x->irq_info, WCD938X_IRQ_HPHL_PDM_WD_INT,
  3599. "HPHL PDM WD INT", wcd938x_wd_handle_irq, NULL);
  3600. wcd_request_irq(&wcd938x->irq_info, WCD938X_IRQ_AUX_PDM_WD_INT,
  3601. "AUX PDM WD INT", wcd938x_wd_handle_irq, NULL);
  3602. /* Disable watchdog interrupt for HPH and AUX */
  3603. wcd_disable_irq(&wcd938x->irq_info, WCD938X_IRQ_HPHR_PDM_WD_INT);
  3604. wcd_disable_irq(&wcd938x->irq_info, WCD938X_IRQ_HPHL_PDM_WD_INT);
  3605. wcd_disable_irq(&wcd938x->irq_info, WCD938X_IRQ_AUX_PDM_WD_INT);
  3606. ret = snd_soc_register_component(dev, &soc_codec_dev_wcd938x,
  3607. wcd938x_dai, ARRAY_SIZE(wcd938x_dai));
  3608. if (ret) {
  3609. dev_err(dev, "%s: Codec registration failed\n",
  3610. __func__);
  3611. goto err_irq;
  3612. }
  3613. return ret;
  3614. err_irq:
  3615. wcd_irq_exit(&wcd938x->irq_info, wcd938x->virq);
  3616. err:
  3617. component_unbind_all(dev, wcd938x);
  3618. return ret;
  3619. }
  3620. static void wcd938x_unbind(struct device *dev)
  3621. {
  3622. struct wcd938x_priv *wcd938x = dev_get_drvdata(dev);
  3623. wcd_free_irq(&wcd938x->irq_info, WCD938X_IRQ_HPHR_PDM_WD_INT, NULL);
  3624. wcd_free_irq(&wcd938x->irq_info, WCD938X_IRQ_HPHL_PDM_WD_INT, NULL);
  3625. wcd_free_irq(&wcd938x->irq_info, WCD938X_IRQ_AUX_PDM_WD_INT, NULL);
  3626. wcd_irq_exit(&wcd938x->irq_info, wcd938x->virq);
  3627. snd_soc_unregister_component(dev);
  3628. component_unbind_all(dev, wcd938x);
  3629. }
  3630. static const struct of_device_id wcd938x_dt_match[] = {
  3631. { .compatible = "qcom,wcd938x-codec", .data = "wcd938x"},
  3632. {}
  3633. };
  3634. static const struct component_master_ops wcd938x_comp_ops = {
  3635. .bind = wcd938x_bind,
  3636. .unbind = wcd938x_unbind,
  3637. };
  3638. static int wcd938x_compare_of(struct device *dev, void *data)
  3639. {
  3640. return dev->of_node == data;
  3641. }
  3642. static void wcd938x_release_of(struct device *dev, void *data)
  3643. {
  3644. of_node_put(data);
  3645. }
  3646. static int wcd938x_add_slave_components(struct device *dev,
  3647. struct component_match **matchptr)
  3648. {
  3649. struct device_node *np, *rx_node, *tx_node;
  3650. np = dev->of_node;
  3651. rx_node = of_parse_phandle(np, "qcom,rx-slave", 0);
  3652. if (!rx_node) {
  3653. dev_err(dev, "%s: Rx-slave node not defined\n", __func__);
  3654. return -ENODEV;
  3655. }
  3656. of_node_get(rx_node);
  3657. component_match_add_release(dev, matchptr,
  3658. wcd938x_release_of,
  3659. wcd938x_compare_of,
  3660. rx_node);
  3661. tx_node = of_parse_phandle(np, "qcom,tx-slave", 0);
  3662. if (!tx_node) {
  3663. dev_err(dev, "%s: Tx-slave node not defined\n", __func__);
  3664. return -ENODEV;
  3665. }
  3666. of_node_get(tx_node);
  3667. component_match_add_release(dev, matchptr,
  3668. wcd938x_release_of,
  3669. wcd938x_compare_of,
  3670. tx_node);
  3671. return 0;
  3672. }
  3673. static int wcd938x_probe(struct platform_device *pdev)
  3674. {
  3675. struct component_match *match = NULL;
  3676. struct wcd938x_priv *wcd938x = NULL;
  3677. struct wcd938x_pdata *pdata = NULL;
  3678. struct wcd_ctrl_platform_data *plat_data = NULL;
  3679. struct device *dev = &pdev->dev;
  3680. int ret;
  3681. wcd938x = devm_kzalloc(dev, sizeof(struct wcd938x_priv),
  3682. GFP_KERNEL);
  3683. if (!wcd938x)
  3684. return -ENOMEM;
  3685. dev_set_drvdata(dev, wcd938x);
  3686. wcd938x->dev = dev;
  3687. pdata = wcd938x_populate_dt_data(dev);
  3688. if (!pdata) {
  3689. dev_err(dev, "%s: Fail to obtain platform data\n", __func__);
  3690. return -EINVAL;
  3691. }
  3692. dev->platform_data = pdata;
  3693. wcd938x->rst_np = pdata->rst_np;
  3694. ret = msm_cdc_init_supplies(dev, &wcd938x->supplies,
  3695. pdata->regulator, pdata->num_supplies);
  3696. if (!wcd938x->supplies) {
  3697. dev_err(dev, "%s: Cannot init wcd supplies\n",
  3698. __func__);
  3699. return ret;
  3700. }
  3701. plat_data = dev_get_platdata(dev->parent);
  3702. if (!plat_data) {
  3703. dev_err(dev, "%s: platform data from parent is NULL\n",
  3704. __func__);
  3705. return -EINVAL;
  3706. }
  3707. wcd938x->handle = (void *)plat_data->handle;
  3708. if (!wcd938x->handle) {
  3709. dev_err(dev, "%s: handle is NULL\n", __func__);
  3710. return -EINVAL;
  3711. }
  3712. wcd938x->update_wcd_event = plat_data->update_wcd_event;
  3713. if (!wcd938x->update_wcd_event) {
  3714. dev_err(dev, "%s: update_wcd_event api is null!\n",
  3715. __func__);
  3716. return -EINVAL;
  3717. }
  3718. wcd938x->register_notifier = plat_data->register_notifier;
  3719. if (!wcd938x->register_notifier) {
  3720. dev_err(dev, "%s: register_notifier api is null!\n",
  3721. __func__);
  3722. return -EINVAL;
  3723. }
  3724. ret = msm_cdc_enable_static_supplies(&pdev->dev, wcd938x->supplies,
  3725. pdata->regulator,
  3726. pdata->num_supplies);
  3727. if (ret) {
  3728. dev_err(dev, "%s: wcd static supply enable failed!\n",
  3729. __func__);
  3730. return ret;
  3731. }
  3732. ret = wcd938x_parse_port_mapping(dev, "qcom,rx_swr_ch_map",
  3733. CODEC_RX);
  3734. ret |= wcd938x_parse_port_mapping(dev, "qcom,tx_swr_ch_map",
  3735. CODEC_TX);
  3736. if (ret) {
  3737. dev_err(dev, "Failed to read port mapping\n");
  3738. goto err;
  3739. }
  3740. mutex_init(&wcd938x->wakeup_lock);
  3741. mutex_init(&wcd938x->micb_lock);
  3742. ret = wcd938x_add_slave_components(dev, &match);
  3743. if (ret)
  3744. goto err_lock_init;
  3745. wcd938x_reset(dev);
  3746. wcd938x->wakeup = wcd938x_wakeup;
  3747. return component_master_add_with_match(dev,
  3748. &wcd938x_comp_ops, match);
  3749. err_lock_init:
  3750. mutex_destroy(&wcd938x->micb_lock);
  3751. mutex_destroy(&wcd938x->wakeup_lock);
  3752. err:
  3753. return ret;
  3754. }
  3755. static int wcd938x_remove(struct platform_device *pdev)
  3756. {
  3757. struct wcd938x_priv *wcd938x = NULL;
  3758. wcd938x = platform_get_drvdata(pdev);
  3759. component_master_del(&pdev->dev, &wcd938x_comp_ops);
  3760. mutex_destroy(&wcd938x->micb_lock);
  3761. mutex_destroy(&wcd938x->wakeup_lock);
  3762. dev_set_drvdata(&pdev->dev, NULL);
  3763. return 0;
  3764. }
  3765. #ifdef CONFIG_PM_SLEEP
  3766. static int wcd938x_suspend(struct device *dev)
  3767. {
  3768. struct wcd938x_priv *wcd938x = NULL;
  3769. int ret = 0;
  3770. struct wcd938x_pdata *pdata = NULL;
  3771. if (!dev)
  3772. return -ENODEV;
  3773. wcd938x = dev_get_drvdata(dev);
  3774. if (!wcd938x)
  3775. return -EINVAL;
  3776. pdata = dev_get_platdata(wcd938x->dev);
  3777. if (!pdata) {
  3778. dev_err(dev, "%s: pdata is NULL\n", __func__);
  3779. return -EINVAL;
  3780. }
  3781. if (test_bit(ALLOW_BUCK_DISABLE, &wcd938x->status_mask)) {
  3782. ret = msm_cdc_disable_ondemand_supply(wcd938x->dev,
  3783. wcd938x->supplies,
  3784. pdata->regulator,
  3785. pdata->num_supplies,
  3786. "cdc-vdd-buck");
  3787. if (ret == -EINVAL) {
  3788. dev_err(dev, "%s: vdd buck is not disabled\n",
  3789. __func__);
  3790. return 0;
  3791. }
  3792. clear_bit(ALLOW_BUCK_DISABLE, &wcd938x->status_mask);
  3793. }
  3794. if (wcd938x->dapm_bias_off) {
  3795. msm_cdc_set_supplies_lpm_mode(wcd938x->dev,
  3796. wcd938x->supplies,
  3797. pdata->regulator,
  3798. pdata->num_supplies,
  3799. true);
  3800. set_bit(WCD_SUPPLIES_LPM_MODE, &wcd938x->status_mask);
  3801. }
  3802. return 0;
  3803. }
  3804. static int wcd938x_resume(struct device *dev)
  3805. {
  3806. struct wcd938x_priv *wcd938x = NULL;
  3807. struct wcd938x_pdata *pdata = NULL;
  3808. if (!dev)
  3809. return -ENODEV;
  3810. wcd938x = dev_get_drvdata(dev);
  3811. if (!wcd938x)
  3812. return -EINVAL;
  3813. pdata = dev_get_platdata(wcd938x->dev);
  3814. if (!pdata) {
  3815. dev_err(dev, "%s: pdata is NULL\n", __func__);
  3816. return -EINVAL;
  3817. }
  3818. if (test_bit(WCD_SUPPLIES_LPM_MODE, &wcd938x->status_mask)) {
  3819. msm_cdc_set_supplies_lpm_mode(wcd938x->dev,
  3820. wcd938x->supplies,
  3821. pdata->regulator,
  3822. pdata->num_supplies,
  3823. false);
  3824. clear_bit(WCD_SUPPLIES_LPM_MODE, &wcd938x->status_mask);
  3825. }
  3826. return 0;
  3827. }
  3828. static const struct dev_pm_ops wcd938x_dev_pm_ops = {
  3829. .suspend_late = wcd938x_suspend,
  3830. .resume_early = wcd938x_resume,
  3831. };
  3832. #endif
  3833. static struct platform_driver wcd938x_codec_driver = {
  3834. .probe = wcd938x_probe,
  3835. .remove = wcd938x_remove,
  3836. .driver = {
  3837. .name = "wcd938x_codec",
  3838. .owner = THIS_MODULE,
  3839. .of_match_table = of_match_ptr(wcd938x_dt_match),
  3840. #ifdef CONFIG_PM_SLEEP
  3841. .pm = &wcd938x_dev_pm_ops,
  3842. #endif
  3843. .suppress_bind_attrs = true,
  3844. },
  3845. };
  3846. module_platform_driver(wcd938x_codec_driver);
  3847. MODULE_DESCRIPTION("WCD938X Codec driver");
  3848. MODULE_LICENSE("GPL v2");