wcd938x.c 124 KB

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