wm8994.c 119 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301
  1. /*
  2. * wm8994.c -- WM8994 ALSA SoC Audio driver
  3. *
  4. * Copyright 2009 Wolfson Microelectronics plc
  5. *
  6. * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
  7. *
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/moduleparam.h>
  15. #include <linux/init.h>
  16. #include <linux/delay.h>
  17. #include <linux/pm.h>
  18. #include <linux/i2c.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/pm_runtime.h>
  21. #include <linux/regulator/consumer.h>
  22. #include <linux/slab.h>
  23. #include <sound/core.h>
  24. #include <sound/jack.h>
  25. #include <sound/pcm.h>
  26. #include <sound/pcm_params.h>
  27. #include <sound/soc.h>
  28. #include <sound/initval.h>
  29. #include <sound/tlv.h>
  30. #include <trace/events/asoc.h>
  31. #include <linux/mfd/wm8994/core.h>
  32. #include <linux/mfd/wm8994/registers.h>
  33. #include <linux/mfd/wm8994/pdata.h>
  34. #include <linux/mfd/wm8994/gpio.h>
  35. #include "wm8994.h"
  36. #include "wm_hubs.h"
  37. #define WM1811_JACKDET_MODE_NONE 0x0000
  38. #define WM1811_JACKDET_MODE_JACK 0x0100
  39. #define WM1811_JACKDET_MODE_MIC 0x0080
  40. #define WM1811_JACKDET_MODE_AUDIO 0x0180
  41. #define WM8994_NUM_DRC 3
  42. #define WM8994_NUM_EQ 3
  43. static struct {
  44. unsigned int reg;
  45. unsigned int mask;
  46. } wm8994_vu_bits[] = {
  47. { WM8994_LEFT_LINE_INPUT_1_2_VOLUME, WM8994_IN1_VU },
  48. { WM8994_RIGHT_LINE_INPUT_1_2_VOLUME, WM8994_IN1_VU },
  49. { WM8994_LEFT_LINE_INPUT_3_4_VOLUME, WM8994_IN2_VU },
  50. { WM8994_RIGHT_LINE_INPUT_3_4_VOLUME, WM8994_IN2_VU },
  51. { WM8994_SPEAKER_VOLUME_LEFT, WM8994_SPKOUT_VU },
  52. { WM8994_SPEAKER_VOLUME_RIGHT, WM8994_SPKOUT_VU },
  53. { WM8994_LEFT_OUTPUT_VOLUME, WM8994_HPOUT1_VU },
  54. { WM8994_RIGHT_OUTPUT_VOLUME, WM8994_HPOUT1_VU },
  55. { WM8994_LEFT_OPGA_VOLUME, WM8994_MIXOUT_VU },
  56. { WM8994_RIGHT_OPGA_VOLUME, WM8994_MIXOUT_VU },
  57. { WM8994_AIF1_DAC1_LEFT_VOLUME, WM8994_AIF1DAC1_VU },
  58. { WM8994_AIF1_DAC1_RIGHT_VOLUME, WM8994_AIF1DAC1_VU },
  59. { WM8994_AIF1_DAC2_LEFT_VOLUME, WM8994_AIF1DAC2_VU },
  60. { WM8994_AIF1_DAC2_RIGHT_VOLUME, WM8994_AIF1DAC2_VU },
  61. { WM8994_AIF2_DAC_LEFT_VOLUME, WM8994_AIF2DAC_VU },
  62. { WM8994_AIF2_DAC_RIGHT_VOLUME, WM8994_AIF2DAC_VU },
  63. { WM8994_AIF1_ADC1_LEFT_VOLUME, WM8994_AIF1ADC1_VU },
  64. { WM8994_AIF1_ADC1_RIGHT_VOLUME, WM8994_AIF1ADC1_VU },
  65. { WM8994_AIF1_ADC2_LEFT_VOLUME, WM8994_AIF1ADC2_VU },
  66. { WM8994_AIF1_ADC2_RIGHT_VOLUME, WM8994_AIF1ADC2_VU },
  67. { WM8994_AIF2_ADC_LEFT_VOLUME, WM8994_AIF2ADC_VU },
  68. { WM8994_AIF2_ADC_RIGHT_VOLUME, WM8994_AIF1ADC2_VU },
  69. { WM8994_DAC1_LEFT_VOLUME, WM8994_DAC1_VU },
  70. { WM8994_DAC1_RIGHT_VOLUME, WM8994_DAC1_VU },
  71. { WM8994_DAC2_LEFT_VOLUME, WM8994_DAC2_VU },
  72. { WM8994_DAC2_RIGHT_VOLUME, WM8994_DAC2_VU },
  73. };
  74. static int wm8994_drc_base[] = {
  75. WM8994_AIF1_DRC1_1,
  76. WM8994_AIF1_DRC2_1,
  77. WM8994_AIF2_DRC_1,
  78. };
  79. static int wm8994_retune_mobile_base[] = {
  80. WM8994_AIF1_DAC1_EQ_GAINS_1,
  81. WM8994_AIF1_DAC2_EQ_GAINS_1,
  82. WM8994_AIF2_EQ_GAINS_1,
  83. };
  84. static void wm8958_default_micdet(u16 status, void *data);
  85. static const struct wm8958_micd_rate micdet_rates[] = {
  86. { 32768, true, 1, 4 },
  87. { 32768, false, 1, 1 },
  88. { 44100 * 256, true, 7, 10 },
  89. { 44100 * 256, false, 7, 10 },
  90. };
  91. static const struct wm8958_micd_rate jackdet_rates[] = {
  92. { 32768, true, 0, 1 },
  93. { 32768, false, 0, 1 },
  94. { 44100 * 256, true, 7, 10 },
  95. { 44100 * 256, false, 7, 10 },
  96. };
  97. static void wm8958_micd_set_rate(struct snd_soc_codec *codec)
  98. {
  99. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  100. int best, i, sysclk, val;
  101. bool idle;
  102. const struct wm8958_micd_rate *rates;
  103. int num_rates;
  104. if (wm8994->jack_cb != wm8958_default_micdet)
  105. return;
  106. idle = !wm8994->jack_mic;
  107. sysclk = snd_soc_read(codec, WM8994_CLOCKING_1);
  108. if (sysclk & WM8994_SYSCLK_SRC)
  109. sysclk = wm8994->aifclk[1];
  110. else
  111. sysclk = wm8994->aifclk[0];
  112. if (wm8994->pdata && wm8994->pdata->micd_rates) {
  113. rates = wm8994->pdata->micd_rates;
  114. num_rates = wm8994->pdata->num_micd_rates;
  115. } else if (wm8994->jackdet) {
  116. rates = jackdet_rates;
  117. num_rates = ARRAY_SIZE(jackdet_rates);
  118. } else {
  119. rates = micdet_rates;
  120. num_rates = ARRAY_SIZE(micdet_rates);
  121. }
  122. best = 0;
  123. for (i = 0; i < num_rates; i++) {
  124. if (rates[i].idle != idle)
  125. continue;
  126. if (abs(rates[i].sysclk - sysclk) <
  127. abs(rates[best].sysclk - sysclk))
  128. best = i;
  129. else if (rates[best].idle != idle)
  130. best = i;
  131. }
  132. val = rates[best].start << WM8958_MICD_BIAS_STARTTIME_SHIFT
  133. | rates[best].rate << WM8958_MICD_RATE_SHIFT;
  134. snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
  135. WM8958_MICD_BIAS_STARTTIME_MASK |
  136. WM8958_MICD_RATE_MASK, val);
  137. }
  138. static int configure_aif_clock(struct snd_soc_codec *codec, int aif)
  139. {
  140. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  141. int rate;
  142. int reg1 = 0;
  143. int offset;
  144. if (aif)
  145. offset = 4;
  146. else
  147. offset = 0;
  148. switch (wm8994->sysclk[aif]) {
  149. case WM8994_SYSCLK_MCLK1:
  150. rate = wm8994->mclk[0];
  151. break;
  152. case WM8994_SYSCLK_MCLK2:
  153. reg1 |= 0x8;
  154. rate = wm8994->mclk[1];
  155. break;
  156. case WM8994_SYSCLK_FLL1:
  157. reg1 |= 0x10;
  158. rate = wm8994->fll[0].out;
  159. break;
  160. case WM8994_SYSCLK_FLL2:
  161. reg1 |= 0x18;
  162. rate = wm8994->fll[1].out;
  163. break;
  164. default:
  165. return -EINVAL;
  166. }
  167. if (rate >= 13500000) {
  168. rate /= 2;
  169. reg1 |= WM8994_AIF1CLK_DIV;
  170. dev_dbg(codec->dev, "Dividing AIF%d clock to %dHz\n",
  171. aif + 1, rate);
  172. }
  173. wm8994->aifclk[aif] = rate;
  174. snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1 + offset,
  175. WM8994_AIF1CLK_SRC_MASK | WM8994_AIF1CLK_DIV,
  176. reg1);
  177. return 0;
  178. }
  179. static int configure_clock(struct snd_soc_codec *codec)
  180. {
  181. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  182. int change, new;
  183. /* Bring up the AIF clocks first */
  184. configure_aif_clock(codec, 0);
  185. configure_aif_clock(codec, 1);
  186. /* Then switch CLK_SYS over to the higher of them; a change
  187. * can only happen as a result of a clocking change which can
  188. * only be made outside of DAPM so we can safely redo the
  189. * clocking.
  190. */
  191. /* If they're equal it doesn't matter which is used */
  192. if (wm8994->aifclk[0] == wm8994->aifclk[1]) {
  193. wm8958_micd_set_rate(codec);
  194. return 0;
  195. }
  196. if (wm8994->aifclk[0] < wm8994->aifclk[1])
  197. new = WM8994_SYSCLK_SRC;
  198. else
  199. new = 0;
  200. change = snd_soc_update_bits(codec, WM8994_CLOCKING_1,
  201. WM8994_SYSCLK_SRC, new);
  202. if (change)
  203. snd_soc_dapm_sync(&codec->dapm);
  204. wm8958_micd_set_rate(codec);
  205. return 0;
  206. }
  207. static int check_clk_sys(struct snd_soc_dapm_widget *source,
  208. struct snd_soc_dapm_widget *sink)
  209. {
  210. int reg = snd_soc_read(source->codec, WM8994_CLOCKING_1);
  211. const char *clk;
  212. /* Check what we're currently using for CLK_SYS */
  213. if (reg & WM8994_SYSCLK_SRC)
  214. clk = "AIF2CLK";
  215. else
  216. clk = "AIF1CLK";
  217. return strcmp(source->name, clk) == 0;
  218. }
  219. static const char *sidetone_hpf_text[] = {
  220. "2.7kHz", "1.35kHz", "675Hz", "370Hz", "180Hz", "90Hz", "45Hz"
  221. };
  222. static const struct soc_enum sidetone_hpf =
  223. SOC_ENUM_SINGLE(WM8994_SIDETONE, 7, 7, sidetone_hpf_text);
  224. static const char *adc_hpf_text[] = {
  225. "HiFi", "Voice 1", "Voice 2", "Voice 3"
  226. };
  227. static const struct soc_enum aif1adc1_hpf =
  228. SOC_ENUM_SINGLE(WM8994_AIF1_ADC1_FILTERS, 13, 4, adc_hpf_text);
  229. static const struct soc_enum aif1adc2_hpf =
  230. SOC_ENUM_SINGLE(WM8994_AIF1_ADC2_FILTERS, 13, 4, adc_hpf_text);
  231. static const struct soc_enum aif2adc_hpf =
  232. SOC_ENUM_SINGLE(WM8994_AIF2_ADC_FILTERS, 13, 4, adc_hpf_text);
  233. static const DECLARE_TLV_DB_SCALE(aif_tlv, 0, 600, 0);
  234. static const DECLARE_TLV_DB_SCALE(digital_tlv, -7200, 75, 1);
  235. static const DECLARE_TLV_DB_SCALE(st_tlv, -3600, 300, 0);
  236. static const DECLARE_TLV_DB_SCALE(wm8994_3d_tlv, -1600, 183, 0);
  237. static const DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0);
  238. static const DECLARE_TLV_DB_SCALE(ng_tlv, -10200, 600, 0);
  239. static const DECLARE_TLV_DB_SCALE(mixin_boost_tlv, 0, 900, 0);
  240. #define WM8994_DRC_SWITCH(xname, reg, shift) \
  241. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  242. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
  243. .put = wm8994_put_drc_sw, \
  244. .private_value = SOC_SINGLE_VALUE(reg, shift, 1, 0) }
  245. static int wm8994_put_drc_sw(struct snd_kcontrol *kcontrol,
  246. struct snd_ctl_elem_value *ucontrol)
  247. {
  248. struct soc_mixer_control *mc =
  249. (struct soc_mixer_control *)kcontrol->private_value;
  250. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  251. int mask, ret;
  252. /* Can't enable both ADC and DAC paths simultaneously */
  253. if (mc->shift == WM8994_AIF1DAC1_DRC_ENA_SHIFT)
  254. mask = WM8994_AIF1ADC1L_DRC_ENA_MASK |
  255. WM8994_AIF1ADC1R_DRC_ENA_MASK;
  256. else
  257. mask = WM8994_AIF1DAC1_DRC_ENA_MASK;
  258. ret = snd_soc_read(codec, mc->reg);
  259. if (ret < 0)
  260. return ret;
  261. if (ret & mask)
  262. return -EINVAL;
  263. return snd_soc_put_volsw(kcontrol, ucontrol);
  264. }
  265. static void wm8994_set_drc(struct snd_soc_codec *codec, int drc)
  266. {
  267. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  268. struct wm8994_pdata *pdata = wm8994->pdata;
  269. int base = wm8994_drc_base[drc];
  270. int cfg = wm8994->drc_cfg[drc];
  271. int save, i;
  272. /* Save any enables; the configuration should clear them. */
  273. save = snd_soc_read(codec, base);
  274. save &= WM8994_AIF1DAC1_DRC_ENA | WM8994_AIF1ADC1L_DRC_ENA |
  275. WM8994_AIF1ADC1R_DRC_ENA;
  276. for (i = 0; i < WM8994_DRC_REGS; i++)
  277. snd_soc_update_bits(codec, base + i, 0xffff,
  278. pdata->drc_cfgs[cfg].regs[i]);
  279. snd_soc_update_bits(codec, base, WM8994_AIF1DAC1_DRC_ENA |
  280. WM8994_AIF1ADC1L_DRC_ENA |
  281. WM8994_AIF1ADC1R_DRC_ENA, save);
  282. }
  283. /* Icky as hell but saves code duplication */
  284. static int wm8994_get_drc(const char *name)
  285. {
  286. if (strcmp(name, "AIF1DRC1 Mode") == 0)
  287. return 0;
  288. if (strcmp(name, "AIF1DRC2 Mode") == 0)
  289. return 1;
  290. if (strcmp(name, "AIF2DRC Mode") == 0)
  291. return 2;
  292. return -EINVAL;
  293. }
  294. static int wm8994_put_drc_enum(struct snd_kcontrol *kcontrol,
  295. struct snd_ctl_elem_value *ucontrol)
  296. {
  297. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  298. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  299. struct wm8994_pdata *pdata = wm8994->pdata;
  300. int drc = wm8994_get_drc(kcontrol->id.name);
  301. int value = ucontrol->value.integer.value[0];
  302. if (drc < 0)
  303. return drc;
  304. if (value >= pdata->num_drc_cfgs)
  305. return -EINVAL;
  306. wm8994->drc_cfg[drc] = value;
  307. wm8994_set_drc(codec, drc);
  308. return 0;
  309. }
  310. static int wm8994_get_drc_enum(struct snd_kcontrol *kcontrol,
  311. struct snd_ctl_elem_value *ucontrol)
  312. {
  313. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  314. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  315. int drc = wm8994_get_drc(kcontrol->id.name);
  316. ucontrol->value.enumerated.item[0] = wm8994->drc_cfg[drc];
  317. return 0;
  318. }
  319. static void wm8994_set_retune_mobile(struct snd_soc_codec *codec, int block)
  320. {
  321. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  322. struct wm8994_pdata *pdata = wm8994->pdata;
  323. int base = wm8994_retune_mobile_base[block];
  324. int iface, best, best_val, save, i, cfg;
  325. if (!pdata || !wm8994->num_retune_mobile_texts)
  326. return;
  327. switch (block) {
  328. case 0:
  329. case 1:
  330. iface = 0;
  331. break;
  332. case 2:
  333. iface = 1;
  334. break;
  335. default:
  336. return;
  337. }
  338. /* Find the version of the currently selected configuration
  339. * with the nearest sample rate. */
  340. cfg = wm8994->retune_mobile_cfg[block];
  341. best = 0;
  342. best_val = INT_MAX;
  343. for (i = 0; i < pdata->num_retune_mobile_cfgs; i++) {
  344. if (strcmp(pdata->retune_mobile_cfgs[i].name,
  345. wm8994->retune_mobile_texts[cfg]) == 0 &&
  346. abs(pdata->retune_mobile_cfgs[i].rate
  347. - wm8994->dac_rates[iface]) < best_val) {
  348. best = i;
  349. best_val = abs(pdata->retune_mobile_cfgs[i].rate
  350. - wm8994->dac_rates[iface]);
  351. }
  352. }
  353. dev_dbg(codec->dev, "ReTune Mobile %d %s/%dHz for %dHz sample rate\n",
  354. block,
  355. pdata->retune_mobile_cfgs[best].name,
  356. pdata->retune_mobile_cfgs[best].rate,
  357. wm8994->dac_rates[iface]);
  358. /* The EQ will be disabled while reconfiguring it, remember the
  359. * current configuration.
  360. */
  361. save = snd_soc_read(codec, base);
  362. save &= WM8994_AIF1DAC1_EQ_ENA;
  363. for (i = 0; i < WM8994_EQ_REGS; i++)
  364. snd_soc_update_bits(codec, base + i, 0xffff,
  365. pdata->retune_mobile_cfgs[best].regs[i]);
  366. snd_soc_update_bits(codec, base, WM8994_AIF1DAC1_EQ_ENA, save);
  367. }
  368. /* Icky as hell but saves code duplication */
  369. static int wm8994_get_retune_mobile_block(const char *name)
  370. {
  371. if (strcmp(name, "AIF1.1 EQ Mode") == 0)
  372. return 0;
  373. if (strcmp(name, "AIF1.2 EQ Mode") == 0)
  374. return 1;
  375. if (strcmp(name, "AIF2 EQ Mode") == 0)
  376. return 2;
  377. return -EINVAL;
  378. }
  379. static int wm8994_put_retune_mobile_enum(struct snd_kcontrol *kcontrol,
  380. struct snd_ctl_elem_value *ucontrol)
  381. {
  382. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  383. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  384. struct wm8994_pdata *pdata = wm8994->pdata;
  385. int block = wm8994_get_retune_mobile_block(kcontrol->id.name);
  386. int value = ucontrol->value.integer.value[0];
  387. if (block < 0)
  388. return block;
  389. if (value >= pdata->num_retune_mobile_cfgs)
  390. return -EINVAL;
  391. wm8994->retune_mobile_cfg[block] = value;
  392. wm8994_set_retune_mobile(codec, block);
  393. return 0;
  394. }
  395. static int wm8994_get_retune_mobile_enum(struct snd_kcontrol *kcontrol,
  396. struct snd_ctl_elem_value *ucontrol)
  397. {
  398. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  399. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  400. int block = wm8994_get_retune_mobile_block(kcontrol->id.name);
  401. ucontrol->value.enumerated.item[0] = wm8994->retune_mobile_cfg[block];
  402. return 0;
  403. }
  404. static const char *aif_chan_src_text[] = {
  405. "Left", "Right"
  406. };
  407. static const struct soc_enum aif1adcl_src =
  408. SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_1, 15, 2, aif_chan_src_text);
  409. static const struct soc_enum aif1adcr_src =
  410. SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_1, 14, 2, aif_chan_src_text);
  411. static const struct soc_enum aif2adcl_src =
  412. SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_1, 15, 2, aif_chan_src_text);
  413. static const struct soc_enum aif2adcr_src =
  414. SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_1, 14, 2, aif_chan_src_text);
  415. static const struct soc_enum aif1dacl_src =
  416. SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_2, 15, 2, aif_chan_src_text);
  417. static const struct soc_enum aif1dacr_src =
  418. SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_2, 14, 2, aif_chan_src_text);
  419. static const struct soc_enum aif2dacl_src =
  420. SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_2, 15, 2, aif_chan_src_text);
  421. static const struct soc_enum aif2dacr_src =
  422. SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_2, 14, 2, aif_chan_src_text);
  423. static const char *osr_text[] = {
  424. "Low Power", "High Performance",
  425. };
  426. static const struct soc_enum dac_osr =
  427. SOC_ENUM_SINGLE(WM8994_OVERSAMPLING, 0, 2, osr_text);
  428. static const struct soc_enum adc_osr =
  429. SOC_ENUM_SINGLE(WM8994_OVERSAMPLING, 1, 2, osr_text);
  430. static const struct snd_kcontrol_new wm8994_snd_controls[] = {
  431. SOC_DOUBLE_R_TLV("AIF1ADC1 Volume", WM8994_AIF1_ADC1_LEFT_VOLUME,
  432. WM8994_AIF1_ADC1_RIGHT_VOLUME,
  433. 1, 119, 0, digital_tlv),
  434. SOC_DOUBLE_R_TLV("AIF1ADC2 Volume", WM8994_AIF1_ADC2_LEFT_VOLUME,
  435. WM8994_AIF1_ADC2_RIGHT_VOLUME,
  436. 1, 119, 0, digital_tlv),
  437. SOC_DOUBLE_R_TLV("AIF2ADC Volume", WM8994_AIF2_ADC_LEFT_VOLUME,
  438. WM8994_AIF2_ADC_RIGHT_VOLUME,
  439. 1, 119, 0, digital_tlv),
  440. SOC_ENUM("AIF1ADCL Source", aif1adcl_src),
  441. SOC_ENUM("AIF1ADCR Source", aif1adcr_src),
  442. SOC_ENUM("AIF2ADCL Source", aif2adcl_src),
  443. SOC_ENUM("AIF2ADCR Source", aif2adcr_src),
  444. SOC_ENUM("AIF1DACL Source", aif1dacl_src),
  445. SOC_ENUM("AIF1DACR Source", aif1dacr_src),
  446. SOC_ENUM("AIF2DACL Source", aif2dacl_src),
  447. SOC_ENUM("AIF2DACR Source", aif2dacr_src),
  448. SOC_DOUBLE_R_TLV("AIF1DAC1 Volume", WM8994_AIF1_DAC1_LEFT_VOLUME,
  449. WM8994_AIF1_DAC1_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
  450. SOC_DOUBLE_R_TLV("AIF1DAC2 Volume", WM8994_AIF1_DAC2_LEFT_VOLUME,
  451. WM8994_AIF1_DAC2_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
  452. SOC_DOUBLE_R_TLV("AIF2DAC Volume", WM8994_AIF2_DAC_LEFT_VOLUME,
  453. WM8994_AIF2_DAC_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
  454. SOC_SINGLE_TLV("AIF1 Boost Volume", WM8994_AIF1_CONTROL_2, 10, 3, 0, aif_tlv),
  455. SOC_SINGLE_TLV("AIF2 Boost Volume", WM8994_AIF2_CONTROL_2, 10, 3, 0, aif_tlv),
  456. SOC_SINGLE("AIF1DAC1 EQ Switch", WM8994_AIF1_DAC1_EQ_GAINS_1, 0, 1, 0),
  457. SOC_SINGLE("AIF1DAC2 EQ Switch", WM8994_AIF1_DAC2_EQ_GAINS_1, 0, 1, 0),
  458. SOC_SINGLE("AIF2 EQ Switch", WM8994_AIF2_EQ_GAINS_1, 0, 1, 0),
  459. WM8994_DRC_SWITCH("AIF1DAC1 DRC Switch", WM8994_AIF1_DRC1_1, 2),
  460. WM8994_DRC_SWITCH("AIF1ADC1L DRC Switch", WM8994_AIF1_DRC1_1, 1),
  461. WM8994_DRC_SWITCH("AIF1ADC1R DRC Switch", WM8994_AIF1_DRC1_1, 0),
  462. WM8994_DRC_SWITCH("AIF1DAC2 DRC Switch", WM8994_AIF1_DRC2_1, 2),
  463. WM8994_DRC_SWITCH("AIF1ADC2L DRC Switch", WM8994_AIF1_DRC2_1, 1),
  464. WM8994_DRC_SWITCH("AIF1ADC2R DRC Switch", WM8994_AIF1_DRC2_1, 0),
  465. WM8994_DRC_SWITCH("AIF2DAC DRC Switch", WM8994_AIF2_DRC_1, 2),
  466. WM8994_DRC_SWITCH("AIF2ADCL DRC Switch", WM8994_AIF2_DRC_1, 1),
  467. WM8994_DRC_SWITCH("AIF2ADCR DRC Switch", WM8994_AIF2_DRC_1, 0),
  468. SOC_SINGLE_TLV("DAC1 Right Sidetone Volume", WM8994_DAC1_MIXER_VOLUMES,
  469. 5, 12, 0, st_tlv),
  470. SOC_SINGLE_TLV("DAC1 Left Sidetone Volume", WM8994_DAC1_MIXER_VOLUMES,
  471. 0, 12, 0, st_tlv),
  472. SOC_SINGLE_TLV("DAC2 Right Sidetone Volume", WM8994_DAC2_MIXER_VOLUMES,
  473. 5, 12, 0, st_tlv),
  474. SOC_SINGLE_TLV("DAC2 Left Sidetone Volume", WM8994_DAC2_MIXER_VOLUMES,
  475. 0, 12, 0, st_tlv),
  476. SOC_ENUM("Sidetone HPF Mux", sidetone_hpf),
  477. SOC_SINGLE("Sidetone HPF Switch", WM8994_SIDETONE, 6, 1, 0),
  478. SOC_ENUM("AIF1ADC1 HPF Mode", aif1adc1_hpf),
  479. SOC_DOUBLE("AIF1ADC1 HPF Switch", WM8994_AIF1_ADC1_FILTERS, 12, 11, 1, 0),
  480. SOC_ENUM("AIF1ADC2 HPF Mode", aif1adc2_hpf),
  481. SOC_DOUBLE("AIF1ADC2 HPF Switch", WM8994_AIF1_ADC2_FILTERS, 12, 11, 1, 0),
  482. SOC_ENUM("AIF2ADC HPF Mode", aif2adc_hpf),
  483. SOC_DOUBLE("AIF2ADC HPF Switch", WM8994_AIF2_ADC_FILTERS, 12, 11, 1, 0),
  484. SOC_ENUM("ADC OSR", adc_osr),
  485. SOC_ENUM("DAC OSR", dac_osr),
  486. SOC_DOUBLE_R_TLV("DAC1 Volume", WM8994_DAC1_LEFT_VOLUME,
  487. WM8994_DAC1_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
  488. SOC_DOUBLE_R("DAC1 Switch", WM8994_DAC1_LEFT_VOLUME,
  489. WM8994_DAC1_RIGHT_VOLUME, 9, 1, 1),
  490. SOC_DOUBLE_R_TLV("DAC2 Volume", WM8994_DAC2_LEFT_VOLUME,
  491. WM8994_DAC2_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
  492. SOC_DOUBLE_R("DAC2 Switch", WM8994_DAC2_LEFT_VOLUME,
  493. WM8994_DAC2_RIGHT_VOLUME, 9, 1, 1),
  494. SOC_SINGLE_TLV("SPKL DAC2 Volume", WM8994_SPKMIXL_ATTENUATION,
  495. 6, 1, 1, wm_hubs_spkmix_tlv),
  496. SOC_SINGLE_TLV("SPKL DAC1 Volume", WM8994_SPKMIXL_ATTENUATION,
  497. 2, 1, 1, wm_hubs_spkmix_tlv),
  498. SOC_SINGLE_TLV("SPKR DAC2 Volume", WM8994_SPKMIXR_ATTENUATION,
  499. 6, 1, 1, wm_hubs_spkmix_tlv),
  500. SOC_SINGLE_TLV("SPKR DAC1 Volume", WM8994_SPKMIXR_ATTENUATION,
  501. 2, 1, 1, wm_hubs_spkmix_tlv),
  502. SOC_SINGLE_TLV("AIF1DAC1 3D Stereo Volume", WM8994_AIF1_DAC1_FILTERS_2,
  503. 10, 15, 0, wm8994_3d_tlv),
  504. SOC_SINGLE("AIF1DAC1 3D Stereo Switch", WM8994_AIF1_DAC1_FILTERS_2,
  505. 8, 1, 0),
  506. SOC_SINGLE_TLV("AIF1DAC2 3D Stereo Volume", WM8994_AIF1_DAC2_FILTERS_2,
  507. 10, 15, 0, wm8994_3d_tlv),
  508. SOC_SINGLE("AIF1DAC2 3D Stereo Switch", WM8994_AIF1_DAC2_FILTERS_2,
  509. 8, 1, 0),
  510. SOC_SINGLE_TLV("AIF2DAC 3D Stereo Volume", WM8994_AIF2_DAC_FILTERS_2,
  511. 10, 15, 0, wm8994_3d_tlv),
  512. SOC_SINGLE("AIF2DAC 3D Stereo Switch", WM8994_AIF2_DAC_FILTERS_2,
  513. 8, 1, 0),
  514. };
  515. static const struct snd_kcontrol_new wm8994_eq_controls[] = {
  516. SOC_SINGLE_TLV("AIF1DAC1 EQ1 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 11, 31, 0,
  517. eq_tlv),
  518. SOC_SINGLE_TLV("AIF1DAC1 EQ2 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 6, 31, 0,
  519. eq_tlv),
  520. SOC_SINGLE_TLV("AIF1DAC1 EQ3 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 1, 31, 0,
  521. eq_tlv),
  522. SOC_SINGLE_TLV("AIF1DAC1 EQ4 Volume", WM8994_AIF1_DAC1_EQ_GAINS_2, 11, 31, 0,
  523. eq_tlv),
  524. SOC_SINGLE_TLV("AIF1DAC1 EQ5 Volume", WM8994_AIF1_DAC1_EQ_GAINS_2, 6, 31, 0,
  525. eq_tlv),
  526. SOC_SINGLE_TLV("AIF1DAC2 EQ1 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 11, 31, 0,
  527. eq_tlv),
  528. SOC_SINGLE_TLV("AIF1DAC2 EQ2 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 6, 31, 0,
  529. eq_tlv),
  530. SOC_SINGLE_TLV("AIF1DAC2 EQ3 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 1, 31, 0,
  531. eq_tlv),
  532. SOC_SINGLE_TLV("AIF1DAC2 EQ4 Volume", WM8994_AIF1_DAC2_EQ_GAINS_2, 11, 31, 0,
  533. eq_tlv),
  534. SOC_SINGLE_TLV("AIF1DAC2 EQ5 Volume", WM8994_AIF1_DAC2_EQ_GAINS_2, 6, 31, 0,
  535. eq_tlv),
  536. SOC_SINGLE_TLV("AIF2 EQ1 Volume", WM8994_AIF2_EQ_GAINS_1, 11, 31, 0,
  537. eq_tlv),
  538. SOC_SINGLE_TLV("AIF2 EQ2 Volume", WM8994_AIF2_EQ_GAINS_1, 6, 31, 0,
  539. eq_tlv),
  540. SOC_SINGLE_TLV("AIF2 EQ3 Volume", WM8994_AIF2_EQ_GAINS_1, 1, 31, 0,
  541. eq_tlv),
  542. SOC_SINGLE_TLV("AIF2 EQ4 Volume", WM8994_AIF2_EQ_GAINS_2, 11, 31, 0,
  543. eq_tlv),
  544. SOC_SINGLE_TLV("AIF2 EQ5 Volume", WM8994_AIF2_EQ_GAINS_2, 6, 31, 0,
  545. eq_tlv),
  546. };
  547. static const char *wm8958_ng_text[] = {
  548. "30ms", "125ms", "250ms", "500ms",
  549. };
  550. static const struct soc_enum wm8958_aif1dac1_ng_hold =
  551. SOC_ENUM_SINGLE(WM8958_AIF1_DAC1_NOISE_GATE,
  552. WM8958_AIF1DAC1_NG_THR_SHIFT, 4, wm8958_ng_text);
  553. static const struct soc_enum wm8958_aif1dac2_ng_hold =
  554. SOC_ENUM_SINGLE(WM8958_AIF1_DAC2_NOISE_GATE,
  555. WM8958_AIF1DAC2_NG_THR_SHIFT, 4, wm8958_ng_text);
  556. static const struct soc_enum wm8958_aif2dac_ng_hold =
  557. SOC_ENUM_SINGLE(WM8958_AIF2_DAC_NOISE_GATE,
  558. WM8958_AIF2DAC_NG_THR_SHIFT, 4, wm8958_ng_text);
  559. static const struct snd_kcontrol_new wm8958_snd_controls[] = {
  560. SOC_SINGLE_TLV("AIF3 Boost Volume", WM8958_AIF3_CONTROL_2, 10, 3, 0, aif_tlv),
  561. SOC_SINGLE("AIF1DAC1 Noise Gate Switch", WM8958_AIF1_DAC1_NOISE_GATE,
  562. WM8958_AIF1DAC1_NG_ENA_SHIFT, 1, 0),
  563. SOC_ENUM("AIF1DAC1 Noise Gate Hold Time", wm8958_aif1dac1_ng_hold),
  564. SOC_SINGLE_TLV("AIF1DAC1 Noise Gate Threshold Volume",
  565. WM8958_AIF1_DAC1_NOISE_GATE, WM8958_AIF1DAC1_NG_THR_SHIFT,
  566. 7, 1, ng_tlv),
  567. SOC_SINGLE("AIF1DAC2 Noise Gate Switch", WM8958_AIF1_DAC2_NOISE_GATE,
  568. WM8958_AIF1DAC2_NG_ENA_SHIFT, 1, 0),
  569. SOC_ENUM("AIF1DAC2 Noise Gate Hold Time", wm8958_aif1dac2_ng_hold),
  570. SOC_SINGLE_TLV("AIF1DAC2 Noise Gate Threshold Volume",
  571. WM8958_AIF1_DAC2_NOISE_GATE, WM8958_AIF1DAC2_NG_THR_SHIFT,
  572. 7, 1, ng_tlv),
  573. SOC_SINGLE("AIF2DAC Noise Gate Switch", WM8958_AIF2_DAC_NOISE_GATE,
  574. WM8958_AIF2DAC_NG_ENA_SHIFT, 1, 0),
  575. SOC_ENUM("AIF2DAC Noise Gate Hold Time", wm8958_aif2dac_ng_hold),
  576. SOC_SINGLE_TLV("AIF2DAC Noise Gate Threshold Volume",
  577. WM8958_AIF2_DAC_NOISE_GATE, WM8958_AIF2DAC_NG_THR_SHIFT,
  578. 7, 1, ng_tlv),
  579. };
  580. static const struct snd_kcontrol_new wm1811_snd_controls[] = {
  581. SOC_SINGLE_TLV("MIXINL IN1LP Boost Volume", WM8994_INPUT_MIXER_1, 7, 1, 0,
  582. mixin_boost_tlv),
  583. SOC_SINGLE_TLV("MIXINL IN1RP Boost Volume", WM8994_INPUT_MIXER_1, 8, 1, 0,
  584. mixin_boost_tlv),
  585. };
  586. /* We run all mode setting through a function to enforce audio mode */
  587. static void wm1811_jackdet_set_mode(struct snd_soc_codec *codec, u16 mode)
  588. {
  589. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  590. if (!wm8994->jackdet || !wm8994->jack_cb)
  591. return;
  592. if (wm8994->active_refcount)
  593. mode = WM1811_JACKDET_MODE_AUDIO;
  594. if (mode == wm8994->jackdet_mode)
  595. return;
  596. wm8994->jackdet_mode = mode;
  597. /* Always use audio mode to detect while the system is active */
  598. if (mode != WM1811_JACKDET_MODE_NONE)
  599. mode = WM1811_JACKDET_MODE_AUDIO;
  600. snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
  601. WM1811_JACKDET_MODE_MASK, mode);
  602. }
  603. static void active_reference(struct snd_soc_codec *codec)
  604. {
  605. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  606. mutex_lock(&wm8994->accdet_lock);
  607. wm8994->active_refcount++;
  608. dev_dbg(codec->dev, "Active refcount incremented, now %d\n",
  609. wm8994->active_refcount);
  610. /* If we're using jack detection go into audio mode */
  611. wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_AUDIO);
  612. mutex_unlock(&wm8994->accdet_lock);
  613. }
  614. static void active_dereference(struct snd_soc_codec *codec)
  615. {
  616. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  617. u16 mode;
  618. mutex_lock(&wm8994->accdet_lock);
  619. wm8994->active_refcount--;
  620. dev_dbg(codec->dev, "Active refcount decremented, now %d\n",
  621. wm8994->active_refcount);
  622. if (wm8994->active_refcount == 0) {
  623. /* Go into appropriate detection only mode */
  624. if (wm8994->jack_mic || wm8994->mic_detecting)
  625. mode = WM1811_JACKDET_MODE_MIC;
  626. else
  627. mode = WM1811_JACKDET_MODE_JACK;
  628. wm1811_jackdet_set_mode(codec, mode);
  629. }
  630. mutex_unlock(&wm8994->accdet_lock);
  631. }
  632. static int clk_sys_event(struct snd_soc_dapm_widget *w,
  633. struct snd_kcontrol *kcontrol, int event)
  634. {
  635. struct snd_soc_codec *codec = w->codec;
  636. switch (event) {
  637. case SND_SOC_DAPM_PRE_PMU:
  638. return configure_clock(codec);
  639. case SND_SOC_DAPM_POST_PMD:
  640. configure_clock(codec);
  641. break;
  642. }
  643. return 0;
  644. }
  645. static void vmid_reference(struct snd_soc_codec *codec)
  646. {
  647. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  648. pm_runtime_get_sync(codec->dev);
  649. wm8994->vmid_refcount++;
  650. dev_dbg(codec->dev, "Referencing VMID, refcount is now %d\n",
  651. wm8994->vmid_refcount);
  652. if (wm8994->vmid_refcount == 1) {
  653. snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
  654. WM8994_LINEOUT1_DISCH |
  655. WM8994_LINEOUT2_DISCH, 0);
  656. wm_hubs_vmid_ena(codec);
  657. switch (wm8994->vmid_mode) {
  658. default:
  659. WARN_ON(0 == "Invalid VMID mode");
  660. case WM8994_VMID_NORMAL:
  661. /* Startup bias, VMID ramp & buffer */
  662. snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
  663. WM8994_BIAS_SRC |
  664. WM8994_VMID_DISCH |
  665. WM8994_STARTUP_BIAS_ENA |
  666. WM8994_VMID_BUF_ENA |
  667. WM8994_VMID_RAMP_MASK,
  668. WM8994_BIAS_SRC |
  669. WM8994_STARTUP_BIAS_ENA |
  670. WM8994_VMID_BUF_ENA |
  671. (0x3 << WM8994_VMID_RAMP_SHIFT));
  672. /* Main bias enable, VMID=2x40k */
  673. snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
  674. WM8994_BIAS_ENA |
  675. WM8994_VMID_SEL_MASK,
  676. WM8994_BIAS_ENA | 0x2);
  677. msleep(50);
  678. snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
  679. WM8994_VMID_RAMP_MASK |
  680. WM8994_BIAS_SRC,
  681. 0);
  682. break;
  683. case WM8994_VMID_FORCE:
  684. /* Startup bias, slow VMID ramp & buffer */
  685. snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
  686. WM8994_BIAS_SRC |
  687. WM8994_VMID_DISCH |
  688. WM8994_STARTUP_BIAS_ENA |
  689. WM8994_VMID_BUF_ENA |
  690. WM8994_VMID_RAMP_MASK,
  691. WM8994_BIAS_SRC |
  692. WM8994_STARTUP_BIAS_ENA |
  693. WM8994_VMID_BUF_ENA |
  694. (0x2 << WM8994_VMID_RAMP_SHIFT));
  695. /* Main bias enable, VMID=2x40k */
  696. snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
  697. WM8994_BIAS_ENA |
  698. WM8994_VMID_SEL_MASK,
  699. WM8994_BIAS_ENA | 0x2);
  700. msleep(400);
  701. snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
  702. WM8994_VMID_RAMP_MASK |
  703. WM8994_BIAS_SRC,
  704. 0);
  705. break;
  706. }
  707. }
  708. }
  709. static void vmid_dereference(struct snd_soc_codec *codec)
  710. {
  711. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  712. wm8994->vmid_refcount--;
  713. dev_dbg(codec->dev, "Dereferencing VMID, refcount is now %d\n",
  714. wm8994->vmid_refcount);
  715. if (wm8994->vmid_refcount == 0) {
  716. if (wm8994->hubs.lineout1_se)
  717. snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_3,
  718. WM8994_LINEOUT1N_ENA |
  719. WM8994_LINEOUT1P_ENA,
  720. WM8994_LINEOUT1N_ENA |
  721. WM8994_LINEOUT1P_ENA);
  722. if (wm8994->hubs.lineout2_se)
  723. snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_3,
  724. WM8994_LINEOUT2N_ENA |
  725. WM8994_LINEOUT2P_ENA,
  726. WM8994_LINEOUT2N_ENA |
  727. WM8994_LINEOUT2P_ENA);
  728. /* Start discharging VMID */
  729. snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
  730. WM8994_BIAS_SRC |
  731. WM8994_VMID_DISCH,
  732. WM8994_BIAS_SRC |
  733. WM8994_VMID_DISCH);
  734. switch (wm8994->vmid_mode) {
  735. case WM8994_VMID_FORCE:
  736. msleep(350);
  737. break;
  738. default:
  739. break;
  740. }
  741. snd_soc_update_bits(codec, WM8994_ADDITIONAL_CONTROL,
  742. WM8994_VROI, WM8994_VROI);
  743. /* Active discharge */
  744. snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
  745. WM8994_LINEOUT1_DISCH |
  746. WM8994_LINEOUT2_DISCH,
  747. WM8994_LINEOUT1_DISCH |
  748. WM8994_LINEOUT2_DISCH);
  749. msleep(150);
  750. snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_3,
  751. WM8994_LINEOUT1N_ENA |
  752. WM8994_LINEOUT1P_ENA |
  753. WM8994_LINEOUT2N_ENA |
  754. WM8994_LINEOUT2P_ENA, 0);
  755. snd_soc_update_bits(codec, WM8994_ADDITIONAL_CONTROL,
  756. WM8994_VROI, 0);
  757. /* Switch off startup biases */
  758. snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
  759. WM8994_BIAS_SRC |
  760. WM8994_STARTUP_BIAS_ENA |
  761. WM8994_VMID_BUF_ENA |
  762. WM8994_VMID_RAMP_MASK, 0);
  763. snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
  764. WM8994_BIAS_ENA | WM8994_VMID_SEL_MASK, 0);
  765. snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
  766. WM8994_VMID_RAMP_MASK, 0);
  767. }
  768. pm_runtime_put(codec->dev);
  769. }
  770. static int vmid_event(struct snd_soc_dapm_widget *w,
  771. struct snd_kcontrol *kcontrol, int event)
  772. {
  773. struct snd_soc_codec *codec = w->codec;
  774. switch (event) {
  775. case SND_SOC_DAPM_PRE_PMU:
  776. vmid_reference(codec);
  777. break;
  778. case SND_SOC_DAPM_POST_PMD:
  779. vmid_dereference(codec);
  780. break;
  781. }
  782. return 0;
  783. }
  784. static void wm8994_update_class_w(struct snd_soc_codec *codec)
  785. {
  786. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  787. int enable = 1;
  788. int source = 0; /* GCC flow analysis can't track enable */
  789. int reg, reg_r;
  790. /* Only support direct DAC->headphone paths */
  791. reg = snd_soc_read(codec, WM8994_OUTPUT_MIXER_1);
  792. if (!(reg & WM8994_DAC1L_TO_HPOUT1L)) {
  793. dev_vdbg(codec->dev, "HPL connected to output mixer\n");
  794. enable = 0;
  795. }
  796. reg = snd_soc_read(codec, WM8994_OUTPUT_MIXER_2);
  797. if (!(reg & WM8994_DAC1R_TO_HPOUT1R)) {
  798. dev_vdbg(codec->dev, "HPR connected to output mixer\n");
  799. enable = 0;
  800. }
  801. /* We also need the same setting for L/R and only one path */
  802. reg = snd_soc_read(codec, WM8994_DAC1_LEFT_MIXER_ROUTING);
  803. switch (reg) {
  804. case WM8994_AIF2DACL_TO_DAC1L:
  805. dev_vdbg(codec->dev, "Class W source AIF2DAC\n");
  806. source = 2 << WM8994_CP_DYN_SRC_SEL_SHIFT;
  807. break;
  808. case WM8994_AIF1DAC2L_TO_DAC1L:
  809. dev_vdbg(codec->dev, "Class W source AIF1DAC2\n");
  810. source = 1 << WM8994_CP_DYN_SRC_SEL_SHIFT;
  811. break;
  812. case WM8994_AIF1DAC1L_TO_DAC1L:
  813. dev_vdbg(codec->dev, "Class W source AIF1DAC1\n");
  814. source = 0 << WM8994_CP_DYN_SRC_SEL_SHIFT;
  815. break;
  816. default:
  817. dev_vdbg(codec->dev, "DAC mixer setting: %x\n", reg);
  818. enable = 0;
  819. break;
  820. }
  821. reg_r = snd_soc_read(codec, WM8994_DAC1_RIGHT_MIXER_ROUTING);
  822. if (reg_r != reg) {
  823. dev_vdbg(codec->dev, "Left and right DAC mixers different\n");
  824. enable = 0;
  825. }
  826. if (enable) {
  827. dev_dbg(codec->dev, "Class W enabled\n");
  828. snd_soc_update_bits(codec, WM8994_CLASS_W_1,
  829. WM8994_CP_DYN_PWR |
  830. WM8994_CP_DYN_SRC_SEL_MASK,
  831. source | WM8994_CP_DYN_PWR);
  832. wm8994->hubs.class_w = true;
  833. } else {
  834. dev_dbg(codec->dev, "Class W disabled\n");
  835. snd_soc_update_bits(codec, WM8994_CLASS_W_1,
  836. WM8994_CP_DYN_PWR, 0);
  837. wm8994->hubs.class_w = false;
  838. }
  839. }
  840. static int aif1clk_ev(struct snd_soc_dapm_widget *w,
  841. struct snd_kcontrol *kcontrol, int event)
  842. {
  843. struct snd_soc_codec *codec = w->codec;
  844. struct wm8994 *control = codec->control_data;
  845. int mask = WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC1R_ENA;
  846. int i;
  847. int dac;
  848. int adc;
  849. int val;
  850. switch (control->type) {
  851. case WM8994:
  852. case WM8958:
  853. mask |= WM8994_AIF1DAC2L_ENA | WM8994_AIF1DAC2R_ENA;
  854. break;
  855. default:
  856. break;
  857. }
  858. switch (event) {
  859. case SND_SOC_DAPM_PRE_PMU:
  860. val = snd_soc_read(codec, WM8994_AIF1_CONTROL_1);
  861. if ((val & WM8994_AIF1ADCL_SRC) &&
  862. (val & WM8994_AIF1ADCR_SRC))
  863. adc = WM8994_AIF1ADC1R_ENA | WM8994_AIF1ADC2R_ENA;
  864. else if (!(val & WM8994_AIF1ADCL_SRC) &&
  865. !(val & WM8994_AIF1ADCR_SRC))
  866. adc = WM8994_AIF1ADC1L_ENA | WM8994_AIF1ADC2L_ENA;
  867. else
  868. adc = WM8994_AIF1ADC1R_ENA | WM8994_AIF1ADC2R_ENA |
  869. WM8994_AIF1ADC1L_ENA | WM8994_AIF1ADC2L_ENA;
  870. val = snd_soc_read(codec, WM8994_AIF1_CONTROL_2);
  871. if ((val & WM8994_AIF1DACL_SRC) &&
  872. (val & WM8994_AIF1DACR_SRC))
  873. dac = WM8994_AIF1DAC1R_ENA | WM8994_AIF1DAC2R_ENA;
  874. else if (!(val & WM8994_AIF1DACL_SRC) &&
  875. !(val & WM8994_AIF1DACR_SRC))
  876. dac = WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC2L_ENA;
  877. else
  878. dac = WM8994_AIF1DAC1R_ENA | WM8994_AIF1DAC2R_ENA |
  879. WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC2L_ENA;
  880. snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4,
  881. mask, adc);
  882. snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
  883. mask, dac);
  884. snd_soc_update_bits(codec, WM8994_CLOCKING_1,
  885. WM8994_AIF1DSPCLK_ENA |
  886. WM8994_SYSDSPCLK_ENA,
  887. WM8994_AIF1DSPCLK_ENA |
  888. WM8994_SYSDSPCLK_ENA);
  889. snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4, mask,
  890. WM8994_AIF1ADC1R_ENA |
  891. WM8994_AIF1ADC1L_ENA |
  892. WM8994_AIF1ADC2R_ENA |
  893. WM8994_AIF1ADC2L_ENA);
  894. snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5, mask,
  895. WM8994_AIF1DAC1R_ENA |
  896. WM8994_AIF1DAC1L_ENA |
  897. WM8994_AIF1DAC2R_ENA |
  898. WM8994_AIF1DAC2L_ENA);
  899. break;
  900. case SND_SOC_DAPM_POST_PMU:
  901. for (i = 0; i < ARRAY_SIZE(wm8994_vu_bits); i++)
  902. snd_soc_write(codec, wm8994_vu_bits[i].reg,
  903. snd_soc_read(codec,
  904. wm8994_vu_bits[i].reg));
  905. break;
  906. case SND_SOC_DAPM_PRE_PMD:
  907. case SND_SOC_DAPM_POST_PMD:
  908. snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
  909. mask, 0);
  910. snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4,
  911. mask, 0);
  912. val = snd_soc_read(codec, WM8994_CLOCKING_1);
  913. if (val & WM8994_AIF2DSPCLK_ENA)
  914. val = WM8994_SYSDSPCLK_ENA;
  915. else
  916. val = 0;
  917. snd_soc_update_bits(codec, WM8994_CLOCKING_1,
  918. WM8994_SYSDSPCLK_ENA |
  919. WM8994_AIF1DSPCLK_ENA, val);
  920. break;
  921. }
  922. return 0;
  923. }
  924. static int aif2clk_ev(struct snd_soc_dapm_widget *w,
  925. struct snd_kcontrol *kcontrol, int event)
  926. {
  927. struct snd_soc_codec *codec = w->codec;
  928. int i;
  929. int dac;
  930. int adc;
  931. int val;
  932. switch (event) {
  933. case SND_SOC_DAPM_PRE_PMU:
  934. val = snd_soc_read(codec, WM8994_AIF2_CONTROL_1);
  935. if ((val & WM8994_AIF2ADCL_SRC) &&
  936. (val & WM8994_AIF2ADCR_SRC))
  937. adc = WM8994_AIF2ADCR_ENA;
  938. else if (!(val & WM8994_AIF2ADCL_SRC) &&
  939. !(val & WM8994_AIF2ADCR_SRC))
  940. adc = WM8994_AIF2ADCL_ENA;
  941. else
  942. adc = WM8994_AIF2ADCL_ENA | WM8994_AIF2ADCR_ENA;
  943. val = snd_soc_read(codec, WM8994_AIF2_CONTROL_2);
  944. if ((val & WM8994_AIF2DACL_SRC) &&
  945. (val & WM8994_AIF2DACR_SRC))
  946. dac = WM8994_AIF2DACR_ENA;
  947. else if (!(val & WM8994_AIF2DACL_SRC) &&
  948. !(val & WM8994_AIF2DACR_SRC))
  949. dac = WM8994_AIF2DACL_ENA;
  950. else
  951. dac = WM8994_AIF2DACL_ENA | WM8994_AIF2DACR_ENA;
  952. snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4,
  953. WM8994_AIF2ADCL_ENA |
  954. WM8994_AIF2ADCR_ENA, adc);
  955. snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
  956. WM8994_AIF2DACL_ENA |
  957. WM8994_AIF2DACR_ENA, dac);
  958. snd_soc_update_bits(codec, WM8994_CLOCKING_1,
  959. WM8994_AIF2DSPCLK_ENA |
  960. WM8994_SYSDSPCLK_ENA,
  961. WM8994_AIF2DSPCLK_ENA |
  962. WM8994_SYSDSPCLK_ENA);
  963. snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4,
  964. WM8994_AIF2ADCL_ENA |
  965. WM8994_AIF2ADCR_ENA,
  966. WM8994_AIF2ADCL_ENA |
  967. WM8994_AIF2ADCR_ENA);
  968. snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
  969. WM8994_AIF2DACL_ENA |
  970. WM8994_AIF2DACR_ENA,
  971. WM8994_AIF2DACL_ENA |
  972. WM8994_AIF2DACR_ENA);
  973. break;
  974. case SND_SOC_DAPM_POST_PMU:
  975. for (i = 0; i < ARRAY_SIZE(wm8994_vu_bits); i++)
  976. snd_soc_write(codec, wm8994_vu_bits[i].reg,
  977. snd_soc_read(codec,
  978. wm8994_vu_bits[i].reg));
  979. break;
  980. case SND_SOC_DAPM_PRE_PMD:
  981. case SND_SOC_DAPM_POST_PMD:
  982. snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
  983. WM8994_AIF2DACL_ENA |
  984. WM8994_AIF2DACR_ENA, 0);
  985. snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4,
  986. WM8994_AIF2ADCL_ENA |
  987. WM8994_AIF2ADCR_ENA, 0);
  988. val = snd_soc_read(codec, WM8994_CLOCKING_1);
  989. if (val & WM8994_AIF1DSPCLK_ENA)
  990. val = WM8994_SYSDSPCLK_ENA;
  991. else
  992. val = 0;
  993. snd_soc_update_bits(codec, WM8994_CLOCKING_1,
  994. WM8994_SYSDSPCLK_ENA |
  995. WM8994_AIF2DSPCLK_ENA, val);
  996. break;
  997. }
  998. return 0;
  999. }
  1000. static int aif1clk_late_ev(struct snd_soc_dapm_widget *w,
  1001. struct snd_kcontrol *kcontrol, int event)
  1002. {
  1003. struct snd_soc_codec *codec = w->codec;
  1004. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  1005. switch (event) {
  1006. case SND_SOC_DAPM_PRE_PMU:
  1007. wm8994->aif1clk_enable = 1;
  1008. break;
  1009. case SND_SOC_DAPM_POST_PMD:
  1010. wm8994->aif1clk_disable = 1;
  1011. break;
  1012. }
  1013. return 0;
  1014. }
  1015. static int aif2clk_late_ev(struct snd_soc_dapm_widget *w,
  1016. struct snd_kcontrol *kcontrol, int event)
  1017. {
  1018. struct snd_soc_codec *codec = w->codec;
  1019. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  1020. switch (event) {
  1021. case SND_SOC_DAPM_PRE_PMU:
  1022. wm8994->aif2clk_enable = 1;
  1023. break;
  1024. case SND_SOC_DAPM_POST_PMD:
  1025. wm8994->aif2clk_disable = 1;
  1026. break;
  1027. }
  1028. return 0;
  1029. }
  1030. static int late_enable_ev(struct snd_soc_dapm_widget *w,
  1031. struct snd_kcontrol *kcontrol, int event)
  1032. {
  1033. struct snd_soc_codec *codec = w->codec;
  1034. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  1035. switch (event) {
  1036. case SND_SOC_DAPM_PRE_PMU:
  1037. if (wm8994->aif1clk_enable) {
  1038. aif1clk_ev(w, kcontrol, SND_SOC_DAPM_PRE_PMU);
  1039. snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
  1040. WM8994_AIF1CLK_ENA_MASK,
  1041. WM8994_AIF1CLK_ENA);
  1042. aif1clk_ev(w, kcontrol, SND_SOC_DAPM_POST_PMU);
  1043. wm8994->aif1clk_enable = 0;
  1044. }
  1045. if (wm8994->aif2clk_enable) {
  1046. aif2clk_ev(w, kcontrol, SND_SOC_DAPM_PRE_PMU);
  1047. snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
  1048. WM8994_AIF2CLK_ENA_MASK,
  1049. WM8994_AIF2CLK_ENA);
  1050. aif2clk_ev(w, kcontrol, SND_SOC_DAPM_POST_PMU);
  1051. wm8994->aif2clk_enable = 0;
  1052. }
  1053. break;
  1054. }
  1055. /* We may also have postponed startup of DSP, handle that. */
  1056. wm8958_aif_ev(w, kcontrol, event);
  1057. return 0;
  1058. }
  1059. static int late_disable_ev(struct snd_soc_dapm_widget *w,
  1060. struct snd_kcontrol *kcontrol, int event)
  1061. {
  1062. struct snd_soc_codec *codec = w->codec;
  1063. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  1064. switch (event) {
  1065. case SND_SOC_DAPM_POST_PMD:
  1066. if (wm8994->aif1clk_disable) {
  1067. aif1clk_ev(w, kcontrol, SND_SOC_DAPM_PRE_PMD);
  1068. snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
  1069. WM8994_AIF1CLK_ENA_MASK, 0);
  1070. aif1clk_ev(w, kcontrol, SND_SOC_DAPM_POST_PMD);
  1071. wm8994->aif1clk_disable = 0;
  1072. }
  1073. if (wm8994->aif2clk_disable) {
  1074. aif2clk_ev(w, kcontrol, SND_SOC_DAPM_PRE_PMD);
  1075. snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
  1076. WM8994_AIF2CLK_ENA_MASK, 0);
  1077. aif2clk_ev(w, kcontrol, SND_SOC_DAPM_POST_PMD);
  1078. wm8994->aif2clk_disable = 0;
  1079. }
  1080. break;
  1081. }
  1082. return 0;
  1083. }
  1084. static int adc_mux_ev(struct snd_soc_dapm_widget *w,
  1085. struct snd_kcontrol *kcontrol, int event)
  1086. {
  1087. late_enable_ev(w, kcontrol, event);
  1088. return 0;
  1089. }
  1090. static int micbias_ev(struct snd_soc_dapm_widget *w,
  1091. struct snd_kcontrol *kcontrol, int event)
  1092. {
  1093. late_enable_ev(w, kcontrol, event);
  1094. return 0;
  1095. }
  1096. static int dac_ev(struct snd_soc_dapm_widget *w,
  1097. struct snd_kcontrol *kcontrol, int event)
  1098. {
  1099. struct snd_soc_codec *codec = w->codec;
  1100. unsigned int mask = 1 << w->shift;
  1101. snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
  1102. mask, mask);
  1103. return 0;
  1104. }
  1105. static const char *hp_mux_text[] = {
  1106. "Mixer",
  1107. "DAC",
  1108. };
  1109. #define WM8994_HP_ENUM(xname, xenum) \
  1110. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  1111. .info = snd_soc_info_enum_double, \
  1112. .get = snd_soc_dapm_get_enum_double, \
  1113. .put = wm8994_put_hp_enum, \
  1114. .private_value = (unsigned long)&xenum }
  1115. static int wm8994_put_hp_enum(struct snd_kcontrol *kcontrol,
  1116. struct snd_ctl_elem_value *ucontrol)
  1117. {
  1118. struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
  1119. struct snd_soc_dapm_widget *w = wlist->widgets[0];
  1120. struct snd_soc_codec *codec = w->codec;
  1121. int ret;
  1122. ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
  1123. wm8994_update_class_w(codec);
  1124. return ret;
  1125. }
  1126. static const struct soc_enum hpl_enum =
  1127. SOC_ENUM_SINGLE(WM8994_OUTPUT_MIXER_1, 8, 2, hp_mux_text);
  1128. static const struct snd_kcontrol_new hpl_mux =
  1129. WM8994_HP_ENUM("Left Headphone Mux", hpl_enum);
  1130. static const struct soc_enum hpr_enum =
  1131. SOC_ENUM_SINGLE(WM8994_OUTPUT_MIXER_2, 8, 2, hp_mux_text);
  1132. static const struct snd_kcontrol_new hpr_mux =
  1133. WM8994_HP_ENUM("Right Headphone Mux", hpr_enum);
  1134. static const char *adc_mux_text[] = {
  1135. "ADC",
  1136. "DMIC",
  1137. };
  1138. static const struct soc_enum adc_enum =
  1139. SOC_ENUM_SINGLE(0, 0, 2, adc_mux_text);
  1140. static const struct snd_kcontrol_new adcl_mux =
  1141. SOC_DAPM_ENUM_VIRT("ADCL Mux", adc_enum);
  1142. static const struct snd_kcontrol_new adcr_mux =
  1143. SOC_DAPM_ENUM_VIRT("ADCR Mux", adc_enum);
  1144. static const struct snd_kcontrol_new left_speaker_mixer[] = {
  1145. SOC_DAPM_SINGLE("DAC2 Switch", WM8994_SPEAKER_MIXER, 9, 1, 0),
  1146. SOC_DAPM_SINGLE("Input Switch", WM8994_SPEAKER_MIXER, 7, 1, 0),
  1147. SOC_DAPM_SINGLE("IN1LP Switch", WM8994_SPEAKER_MIXER, 5, 1, 0),
  1148. SOC_DAPM_SINGLE("Output Switch", WM8994_SPEAKER_MIXER, 3, 1, 0),
  1149. SOC_DAPM_SINGLE("DAC1 Switch", WM8994_SPEAKER_MIXER, 1, 1, 0),
  1150. };
  1151. static const struct snd_kcontrol_new right_speaker_mixer[] = {
  1152. SOC_DAPM_SINGLE("DAC2 Switch", WM8994_SPEAKER_MIXER, 8, 1, 0),
  1153. SOC_DAPM_SINGLE("Input Switch", WM8994_SPEAKER_MIXER, 6, 1, 0),
  1154. SOC_DAPM_SINGLE("IN1RP Switch", WM8994_SPEAKER_MIXER, 4, 1, 0),
  1155. SOC_DAPM_SINGLE("Output Switch", WM8994_SPEAKER_MIXER, 2, 1, 0),
  1156. SOC_DAPM_SINGLE("DAC1 Switch", WM8994_SPEAKER_MIXER, 0, 1, 0),
  1157. };
  1158. /* Debugging; dump chip status after DAPM transitions */
  1159. static int post_ev(struct snd_soc_dapm_widget *w,
  1160. struct snd_kcontrol *kcontrol, int event)
  1161. {
  1162. struct snd_soc_codec *codec = w->codec;
  1163. dev_dbg(codec->dev, "SRC status: %x\n",
  1164. snd_soc_read(codec,
  1165. WM8994_RATE_STATUS));
  1166. return 0;
  1167. }
  1168. static const struct snd_kcontrol_new aif1adc1l_mix[] = {
  1169. SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8994_AIF1_ADC1_LEFT_MIXER_ROUTING,
  1170. 1, 1, 0),
  1171. SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC1_LEFT_MIXER_ROUTING,
  1172. 0, 1, 0),
  1173. };
  1174. static const struct snd_kcontrol_new aif1adc1r_mix[] = {
  1175. SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8994_AIF1_ADC1_RIGHT_MIXER_ROUTING,
  1176. 1, 1, 0),
  1177. SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC1_RIGHT_MIXER_ROUTING,
  1178. 0, 1, 0),
  1179. };
  1180. static const struct snd_kcontrol_new aif1adc2l_mix[] = {
  1181. SOC_DAPM_SINGLE("DMIC Switch", WM8994_AIF1_ADC2_LEFT_MIXER_ROUTING,
  1182. 1, 1, 0),
  1183. SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC2_LEFT_MIXER_ROUTING,
  1184. 0, 1, 0),
  1185. };
  1186. static const struct snd_kcontrol_new aif1adc2r_mix[] = {
  1187. SOC_DAPM_SINGLE("DMIC Switch", WM8994_AIF1_ADC2_RIGHT_MIXER_ROUTING,
  1188. 1, 1, 0),
  1189. SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC2_RIGHT_MIXER_ROUTING,
  1190. 0, 1, 0),
  1191. };
  1192. static const struct snd_kcontrol_new aif2dac2l_mix[] = {
  1193. SOC_DAPM_SINGLE("Right Sidetone Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
  1194. 5, 1, 0),
  1195. SOC_DAPM_SINGLE("Left Sidetone Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
  1196. 4, 1, 0),
  1197. SOC_DAPM_SINGLE("AIF2 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
  1198. 2, 1, 0),
  1199. SOC_DAPM_SINGLE("AIF1.2 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
  1200. 1, 1, 0),
  1201. SOC_DAPM_SINGLE("AIF1.1 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
  1202. 0, 1, 0),
  1203. };
  1204. static const struct snd_kcontrol_new aif2dac2r_mix[] = {
  1205. SOC_DAPM_SINGLE("Right Sidetone Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
  1206. 5, 1, 0),
  1207. SOC_DAPM_SINGLE("Left Sidetone Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
  1208. 4, 1, 0),
  1209. SOC_DAPM_SINGLE("AIF2 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
  1210. 2, 1, 0),
  1211. SOC_DAPM_SINGLE("AIF1.2 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
  1212. 1, 1, 0),
  1213. SOC_DAPM_SINGLE("AIF1.1 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
  1214. 0, 1, 0),
  1215. };
  1216. #define WM8994_CLASS_W_SWITCH(xname, reg, shift, max, invert) \
  1217. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  1218. .info = snd_soc_info_volsw, \
  1219. .get = snd_soc_dapm_get_volsw, .put = wm8994_put_class_w, \
  1220. .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
  1221. static int wm8994_put_class_w(struct snd_kcontrol *kcontrol,
  1222. struct snd_ctl_elem_value *ucontrol)
  1223. {
  1224. struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
  1225. struct snd_soc_dapm_widget *w = wlist->widgets[0];
  1226. struct snd_soc_codec *codec = w->codec;
  1227. int ret;
  1228. ret = snd_soc_dapm_put_volsw(kcontrol, ucontrol);
  1229. wm8994_update_class_w(codec);
  1230. return ret;
  1231. }
  1232. static const struct snd_kcontrol_new dac1l_mix[] = {
  1233. WM8994_CLASS_W_SWITCH("Right Sidetone Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
  1234. 5, 1, 0),
  1235. WM8994_CLASS_W_SWITCH("Left Sidetone Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
  1236. 4, 1, 0),
  1237. WM8994_CLASS_W_SWITCH("AIF2 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
  1238. 2, 1, 0),
  1239. WM8994_CLASS_W_SWITCH("AIF1.2 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
  1240. 1, 1, 0),
  1241. WM8994_CLASS_W_SWITCH("AIF1.1 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
  1242. 0, 1, 0),
  1243. };
  1244. static const struct snd_kcontrol_new dac1r_mix[] = {
  1245. WM8994_CLASS_W_SWITCH("Right Sidetone Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
  1246. 5, 1, 0),
  1247. WM8994_CLASS_W_SWITCH("Left Sidetone Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
  1248. 4, 1, 0),
  1249. WM8994_CLASS_W_SWITCH("AIF2 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
  1250. 2, 1, 0),
  1251. WM8994_CLASS_W_SWITCH("AIF1.2 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
  1252. 1, 1, 0),
  1253. WM8994_CLASS_W_SWITCH("AIF1.1 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
  1254. 0, 1, 0),
  1255. };
  1256. static const char *sidetone_text[] = {
  1257. "ADC/DMIC1", "DMIC2",
  1258. };
  1259. static const struct soc_enum sidetone1_enum =
  1260. SOC_ENUM_SINGLE(WM8994_SIDETONE, 0, 2, sidetone_text);
  1261. static const struct snd_kcontrol_new sidetone1_mux =
  1262. SOC_DAPM_ENUM("Left Sidetone Mux", sidetone1_enum);
  1263. static const struct soc_enum sidetone2_enum =
  1264. SOC_ENUM_SINGLE(WM8994_SIDETONE, 1, 2, sidetone_text);
  1265. static const struct snd_kcontrol_new sidetone2_mux =
  1266. SOC_DAPM_ENUM("Right Sidetone Mux", sidetone2_enum);
  1267. static const char *aif1dac_text[] = {
  1268. "AIF1DACDAT", "AIF3DACDAT",
  1269. };
  1270. static const struct soc_enum aif1dac_enum =
  1271. SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 0, 2, aif1dac_text);
  1272. static const struct snd_kcontrol_new aif1dac_mux =
  1273. SOC_DAPM_ENUM("AIF1DAC Mux", aif1dac_enum);
  1274. static const char *aif2dac_text[] = {
  1275. "AIF2DACDAT", "AIF3DACDAT",
  1276. };
  1277. static const struct soc_enum aif2dac_enum =
  1278. SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 1, 2, aif2dac_text);
  1279. static const struct snd_kcontrol_new aif2dac_mux =
  1280. SOC_DAPM_ENUM("AIF2DAC Mux", aif2dac_enum);
  1281. static const char *aif2adc_text[] = {
  1282. "AIF2ADCDAT", "AIF3DACDAT",
  1283. };
  1284. static const struct soc_enum aif2adc_enum =
  1285. SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 2, 2, aif2adc_text);
  1286. static const struct snd_kcontrol_new aif2adc_mux =
  1287. SOC_DAPM_ENUM("AIF2ADC Mux", aif2adc_enum);
  1288. static const char *aif3adc_text[] = {
  1289. "AIF1ADCDAT", "AIF2ADCDAT", "AIF2DACDAT", "Mono PCM",
  1290. };
  1291. static const struct soc_enum wm8994_aif3adc_enum =
  1292. SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 3, 3, aif3adc_text);
  1293. static const struct snd_kcontrol_new wm8994_aif3adc_mux =
  1294. SOC_DAPM_ENUM("AIF3ADC Mux", wm8994_aif3adc_enum);
  1295. static const struct soc_enum wm8958_aif3adc_enum =
  1296. SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 3, 4, aif3adc_text);
  1297. static const struct snd_kcontrol_new wm8958_aif3adc_mux =
  1298. SOC_DAPM_ENUM("AIF3ADC Mux", wm8958_aif3adc_enum);
  1299. static const char *mono_pcm_out_text[] = {
  1300. "None", "AIF2ADCL", "AIF2ADCR",
  1301. };
  1302. static const struct soc_enum mono_pcm_out_enum =
  1303. SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 9, 3, mono_pcm_out_text);
  1304. static const struct snd_kcontrol_new mono_pcm_out_mux =
  1305. SOC_DAPM_ENUM("Mono PCM Out Mux", mono_pcm_out_enum);
  1306. static const char *aif2dac_src_text[] = {
  1307. "AIF2", "AIF3",
  1308. };
  1309. /* Note that these two control shouldn't be simultaneously switched to AIF3 */
  1310. static const struct soc_enum aif2dacl_src_enum =
  1311. SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 7, 2, aif2dac_src_text);
  1312. static const struct snd_kcontrol_new aif2dacl_src_mux =
  1313. SOC_DAPM_ENUM("AIF2DACL Mux", aif2dacl_src_enum);
  1314. static const struct soc_enum aif2dacr_src_enum =
  1315. SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 8, 2, aif2dac_src_text);
  1316. static const struct snd_kcontrol_new aif2dacr_src_mux =
  1317. SOC_DAPM_ENUM("AIF2DACR Mux", aif2dacr_src_enum);
  1318. static const struct snd_soc_dapm_widget wm8994_lateclk_revd_widgets[] = {
  1319. SND_SOC_DAPM_SUPPLY("AIF1CLK", SND_SOC_NOPM, 0, 0, aif1clk_late_ev,
  1320. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1321. SND_SOC_DAPM_SUPPLY("AIF2CLK", SND_SOC_NOPM, 0, 0, aif2clk_late_ev,
  1322. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1323. SND_SOC_DAPM_PGA_E("Late DAC1L Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
  1324. late_enable_ev, SND_SOC_DAPM_PRE_PMU),
  1325. SND_SOC_DAPM_PGA_E("Late DAC1R Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
  1326. late_enable_ev, SND_SOC_DAPM_PRE_PMU),
  1327. SND_SOC_DAPM_PGA_E("Late DAC2L Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
  1328. late_enable_ev, SND_SOC_DAPM_PRE_PMU),
  1329. SND_SOC_DAPM_PGA_E("Late DAC2R Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
  1330. late_enable_ev, SND_SOC_DAPM_PRE_PMU),
  1331. SND_SOC_DAPM_PGA_E("Direct Voice", SND_SOC_NOPM, 0, 0, NULL, 0,
  1332. late_enable_ev, SND_SOC_DAPM_PRE_PMU),
  1333. SND_SOC_DAPM_MIXER_E("SPKL", WM8994_POWER_MANAGEMENT_3, 8, 0,
  1334. left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer),
  1335. late_enable_ev, SND_SOC_DAPM_PRE_PMU),
  1336. SND_SOC_DAPM_MIXER_E("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0,
  1337. right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer),
  1338. late_enable_ev, SND_SOC_DAPM_PRE_PMU),
  1339. SND_SOC_DAPM_MUX_E("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &hpl_mux,
  1340. late_enable_ev, SND_SOC_DAPM_PRE_PMU),
  1341. SND_SOC_DAPM_MUX_E("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &hpr_mux,
  1342. late_enable_ev, SND_SOC_DAPM_PRE_PMU),
  1343. SND_SOC_DAPM_POST("Late Disable PGA", late_disable_ev)
  1344. };
  1345. static const struct snd_soc_dapm_widget wm8994_lateclk_widgets[] = {
  1346. SND_SOC_DAPM_SUPPLY("AIF1CLK", WM8994_AIF1_CLOCKING_1, 0, 0, aif1clk_ev,
  1347. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1348. SND_SOC_DAPM_PRE_PMD),
  1349. SND_SOC_DAPM_SUPPLY("AIF2CLK", WM8994_AIF2_CLOCKING_1, 0, 0, aif2clk_ev,
  1350. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1351. SND_SOC_DAPM_PRE_PMD),
  1352. SND_SOC_DAPM_PGA("Direct Voice", SND_SOC_NOPM, 0, 0, NULL, 0),
  1353. SND_SOC_DAPM_MIXER("SPKL", WM8994_POWER_MANAGEMENT_3, 8, 0,
  1354. left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer)),
  1355. SND_SOC_DAPM_MIXER("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0,
  1356. right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer)),
  1357. SND_SOC_DAPM_MUX("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &hpl_mux),
  1358. SND_SOC_DAPM_MUX("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &hpr_mux),
  1359. };
  1360. static const struct snd_soc_dapm_widget wm8994_dac_revd_widgets[] = {
  1361. SND_SOC_DAPM_DAC_E("DAC2L", NULL, SND_SOC_NOPM, 3, 0,
  1362. dac_ev, SND_SOC_DAPM_PRE_PMU),
  1363. SND_SOC_DAPM_DAC_E("DAC2R", NULL, SND_SOC_NOPM, 2, 0,
  1364. dac_ev, SND_SOC_DAPM_PRE_PMU),
  1365. SND_SOC_DAPM_DAC_E("DAC1L", NULL, SND_SOC_NOPM, 1, 0,
  1366. dac_ev, SND_SOC_DAPM_PRE_PMU),
  1367. SND_SOC_DAPM_DAC_E("DAC1R", NULL, SND_SOC_NOPM, 0, 0,
  1368. dac_ev, SND_SOC_DAPM_PRE_PMU),
  1369. };
  1370. static const struct snd_soc_dapm_widget wm8994_dac_widgets[] = {
  1371. SND_SOC_DAPM_DAC("DAC2L", NULL, WM8994_POWER_MANAGEMENT_5, 3, 0),
  1372. SND_SOC_DAPM_DAC("DAC2R", NULL, WM8994_POWER_MANAGEMENT_5, 2, 0),
  1373. SND_SOC_DAPM_DAC("DAC1L", NULL, WM8994_POWER_MANAGEMENT_5, 1, 0),
  1374. SND_SOC_DAPM_DAC("DAC1R", NULL, WM8994_POWER_MANAGEMENT_5, 0, 0),
  1375. };
  1376. static const struct snd_soc_dapm_widget wm8994_adc_revd_widgets[] = {
  1377. SND_SOC_DAPM_VIRT_MUX_E("ADCL Mux", WM8994_POWER_MANAGEMENT_4, 1, 0, &adcl_mux,
  1378. adc_mux_ev, SND_SOC_DAPM_PRE_PMU),
  1379. SND_SOC_DAPM_VIRT_MUX_E("ADCR Mux", WM8994_POWER_MANAGEMENT_4, 0, 0, &adcr_mux,
  1380. adc_mux_ev, SND_SOC_DAPM_PRE_PMU),
  1381. };
  1382. static const struct snd_soc_dapm_widget wm8994_adc_widgets[] = {
  1383. SND_SOC_DAPM_VIRT_MUX("ADCL Mux", WM8994_POWER_MANAGEMENT_4, 1, 0, &adcl_mux),
  1384. SND_SOC_DAPM_VIRT_MUX("ADCR Mux", WM8994_POWER_MANAGEMENT_4, 0, 0, &adcr_mux),
  1385. };
  1386. static const struct snd_soc_dapm_widget wm8994_dapm_widgets[] = {
  1387. SND_SOC_DAPM_INPUT("DMIC1DAT"),
  1388. SND_SOC_DAPM_INPUT("DMIC2DAT"),
  1389. SND_SOC_DAPM_INPUT("Clock"),
  1390. SND_SOC_DAPM_SUPPLY_S("MICBIAS Supply", 1, SND_SOC_NOPM, 0, 0, micbias_ev,
  1391. SND_SOC_DAPM_PRE_PMU),
  1392. SND_SOC_DAPM_SUPPLY("VMID", SND_SOC_NOPM, 0, 0, vmid_event,
  1393. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1394. SND_SOC_DAPM_SUPPLY("CLK_SYS", SND_SOC_NOPM, 0, 0, clk_sys_event,
  1395. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  1396. SND_SOC_DAPM_SUPPLY("DSP1CLK", SND_SOC_NOPM, 3, 0, NULL, 0),
  1397. SND_SOC_DAPM_SUPPLY("DSP2CLK", SND_SOC_NOPM, 2, 0, NULL, 0),
  1398. SND_SOC_DAPM_SUPPLY("DSPINTCLK", SND_SOC_NOPM, 1, 0, NULL, 0),
  1399. SND_SOC_DAPM_AIF_OUT("AIF1ADC1L", NULL,
  1400. 0, SND_SOC_NOPM, 9, 0),
  1401. SND_SOC_DAPM_AIF_OUT("AIF1ADC1R", NULL,
  1402. 0, SND_SOC_NOPM, 8, 0),
  1403. SND_SOC_DAPM_AIF_IN_E("AIF1DAC1L", NULL, 0,
  1404. SND_SOC_NOPM, 9, 0, wm8958_aif_ev,
  1405. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  1406. SND_SOC_DAPM_AIF_IN_E("AIF1DAC1R", NULL, 0,
  1407. SND_SOC_NOPM, 8, 0, wm8958_aif_ev,
  1408. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  1409. SND_SOC_DAPM_AIF_OUT("AIF1ADC2L", NULL,
  1410. 0, SND_SOC_NOPM, 11, 0),
  1411. SND_SOC_DAPM_AIF_OUT("AIF1ADC2R", NULL,
  1412. 0, SND_SOC_NOPM, 10, 0),
  1413. SND_SOC_DAPM_AIF_IN_E("AIF1DAC2L", NULL, 0,
  1414. SND_SOC_NOPM, 11, 0, wm8958_aif_ev,
  1415. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  1416. SND_SOC_DAPM_AIF_IN_E("AIF1DAC2R", NULL, 0,
  1417. SND_SOC_NOPM, 10, 0, wm8958_aif_ev,
  1418. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  1419. SND_SOC_DAPM_MIXER("AIF1ADC1L Mixer", SND_SOC_NOPM, 0, 0,
  1420. aif1adc1l_mix, ARRAY_SIZE(aif1adc1l_mix)),
  1421. SND_SOC_DAPM_MIXER("AIF1ADC1R Mixer", SND_SOC_NOPM, 0, 0,
  1422. aif1adc1r_mix, ARRAY_SIZE(aif1adc1r_mix)),
  1423. SND_SOC_DAPM_MIXER("AIF1ADC2L Mixer", SND_SOC_NOPM, 0, 0,
  1424. aif1adc2l_mix, ARRAY_SIZE(aif1adc2l_mix)),
  1425. SND_SOC_DAPM_MIXER("AIF1ADC2R Mixer", SND_SOC_NOPM, 0, 0,
  1426. aif1adc2r_mix, ARRAY_SIZE(aif1adc2r_mix)),
  1427. SND_SOC_DAPM_MIXER("AIF2DAC2L Mixer", SND_SOC_NOPM, 0, 0,
  1428. aif2dac2l_mix, ARRAY_SIZE(aif2dac2l_mix)),
  1429. SND_SOC_DAPM_MIXER("AIF2DAC2R Mixer", SND_SOC_NOPM, 0, 0,
  1430. aif2dac2r_mix, ARRAY_SIZE(aif2dac2r_mix)),
  1431. SND_SOC_DAPM_MUX("Left Sidetone", SND_SOC_NOPM, 0, 0, &sidetone1_mux),
  1432. SND_SOC_DAPM_MUX("Right Sidetone", SND_SOC_NOPM, 0, 0, &sidetone2_mux),
  1433. SND_SOC_DAPM_MIXER("DAC1L Mixer", SND_SOC_NOPM, 0, 0,
  1434. dac1l_mix, ARRAY_SIZE(dac1l_mix)),
  1435. SND_SOC_DAPM_MIXER("DAC1R Mixer", SND_SOC_NOPM, 0, 0,
  1436. dac1r_mix, ARRAY_SIZE(dac1r_mix)),
  1437. SND_SOC_DAPM_AIF_OUT("AIF2ADCL", NULL, 0,
  1438. SND_SOC_NOPM, 13, 0),
  1439. SND_SOC_DAPM_AIF_OUT("AIF2ADCR", NULL, 0,
  1440. SND_SOC_NOPM, 12, 0),
  1441. SND_SOC_DAPM_AIF_IN_E("AIF2DACL", NULL, 0,
  1442. SND_SOC_NOPM, 13, 0, wm8958_aif_ev,
  1443. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  1444. SND_SOC_DAPM_AIF_IN_E("AIF2DACR", NULL, 0,
  1445. SND_SOC_NOPM, 12, 0, wm8958_aif_ev,
  1446. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  1447. SND_SOC_DAPM_AIF_IN("AIF1DACDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
  1448. SND_SOC_DAPM_AIF_IN("AIF2DACDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
  1449. SND_SOC_DAPM_AIF_OUT("AIF1ADCDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
  1450. SND_SOC_DAPM_AIF_OUT("AIF2ADCDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
  1451. SND_SOC_DAPM_MUX("AIF1DAC Mux", SND_SOC_NOPM, 0, 0, &aif1dac_mux),
  1452. SND_SOC_DAPM_MUX("AIF2DAC Mux", SND_SOC_NOPM, 0, 0, &aif2dac_mux),
  1453. SND_SOC_DAPM_MUX("AIF2ADC Mux", SND_SOC_NOPM, 0, 0, &aif2adc_mux),
  1454. SND_SOC_DAPM_AIF_IN("AIF3DACDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
  1455. SND_SOC_DAPM_AIF_OUT("AIF3ADCDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
  1456. SND_SOC_DAPM_SUPPLY("TOCLK", WM8994_CLOCKING_1, 4, 0, NULL, 0),
  1457. SND_SOC_DAPM_ADC("DMIC2L", NULL, WM8994_POWER_MANAGEMENT_4, 5, 0),
  1458. SND_SOC_DAPM_ADC("DMIC2R", NULL, WM8994_POWER_MANAGEMENT_4, 4, 0),
  1459. SND_SOC_DAPM_ADC("DMIC1L", NULL, WM8994_POWER_MANAGEMENT_4, 3, 0),
  1460. SND_SOC_DAPM_ADC("DMIC1R", NULL, WM8994_POWER_MANAGEMENT_4, 2, 0),
  1461. /* Power is done with the muxes since the ADC power also controls the
  1462. * downsampling chain, the chip will automatically manage the analogue
  1463. * specific portions.
  1464. */
  1465. SND_SOC_DAPM_ADC("ADCL", NULL, SND_SOC_NOPM, 1, 0),
  1466. SND_SOC_DAPM_ADC("ADCR", NULL, SND_SOC_NOPM, 0, 0),
  1467. SND_SOC_DAPM_POST("Debug log", post_ev),
  1468. };
  1469. static const struct snd_soc_dapm_widget wm8994_specific_dapm_widgets[] = {
  1470. SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &wm8994_aif3adc_mux),
  1471. };
  1472. static const struct snd_soc_dapm_widget wm8958_dapm_widgets[] = {
  1473. SND_SOC_DAPM_MUX("Mono PCM Out Mux", SND_SOC_NOPM, 0, 0, &mono_pcm_out_mux),
  1474. SND_SOC_DAPM_MUX("AIF2DACL Mux", SND_SOC_NOPM, 0, 0, &aif2dacl_src_mux),
  1475. SND_SOC_DAPM_MUX("AIF2DACR Mux", SND_SOC_NOPM, 0, 0, &aif2dacr_src_mux),
  1476. SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &wm8958_aif3adc_mux),
  1477. };
  1478. static const struct snd_soc_dapm_route intercon[] = {
  1479. { "CLK_SYS", NULL, "AIF1CLK", check_clk_sys },
  1480. { "CLK_SYS", NULL, "AIF2CLK", check_clk_sys },
  1481. { "DSP1CLK", NULL, "CLK_SYS" },
  1482. { "DSP2CLK", NULL, "CLK_SYS" },
  1483. { "DSPINTCLK", NULL, "CLK_SYS" },
  1484. { "AIF1ADC1L", NULL, "AIF1CLK" },
  1485. { "AIF1ADC1L", NULL, "DSP1CLK" },
  1486. { "AIF1ADC1R", NULL, "AIF1CLK" },
  1487. { "AIF1ADC1R", NULL, "DSP1CLK" },
  1488. { "AIF1ADC1R", NULL, "DSPINTCLK" },
  1489. { "AIF1DAC1L", NULL, "AIF1CLK" },
  1490. { "AIF1DAC1L", NULL, "DSP1CLK" },
  1491. { "AIF1DAC1R", NULL, "AIF1CLK" },
  1492. { "AIF1DAC1R", NULL, "DSP1CLK" },
  1493. { "AIF1DAC1R", NULL, "DSPINTCLK" },
  1494. { "AIF1ADC2L", NULL, "AIF1CLK" },
  1495. { "AIF1ADC2L", NULL, "DSP1CLK" },
  1496. { "AIF1ADC2R", NULL, "AIF1CLK" },
  1497. { "AIF1ADC2R", NULL, "DSP1CLK" },
  1498. { "AIF1ADC2R", NULL, "DSPINTCLK" },
  1499. { "AIF1DAC2L", NULL, "AIF1CLK" },
  1500. { "AIF1DAC2L", NULL, "DSP1CLK" },
  1501. { "AIF1DAC2R", NULL, "AIF1CLK" },
  1502. { "AIF1DAC2R", NULL, "DSP1CLK" },
  1503. { "AIF1DAC2R", NULL, "DSPINTCLK" },
  1504. { "AIF2ADCL", NULL, "AIF2CLK" },
  1505. { "AIF2ADCL", NULL, "DSP2CLK" },
  1506. { "AIF2ADCR", NULL, "AIF2CLK" },
  1507. { "AIF2ADCR", NULL, "DSP2CLK" },
  1508. { "AIF2ADCR", NULL, "DSPINTCLK" },
  1509. { "AIF2DACL", NULL, "AIF2CLK" },
  1510. { "AIF2DACL", NULL, "DSP2CLK" },
  1511. { "AIF2DACR", NULL, "AIF2CLK" },
  1512. { "AIF2DACR", NULL, "DSP2CLK" },
  1513. { "AIF2DACR", NULL, "DSPINTCLK" },
  1514. { "DMIC1L", NULL, "DMIC1DAT" },
  1515. { "DMIC1L", NULL, "CLK_SYS" },
  1516. { "DMIC1R", NULL, "DMIC1DAT" },
  1517. { "DMIC1R", NULL, "CLK_SYS" },
  1518. { "DMIC2L", NULL, "DMIC2DAT" },
  1519. { "DMIC2L", NULL, "CLK_SYS" },
  1520. { "DMIC2R", NULL, "DMIC2DAT" },
  1521. { "DMIC2R", NULL, "CLK_SYS" },
  1522. { "ADCL", NULL, "AIF1CLK" },
  1523. { "ADCL", NULL, "DSP1CLK" },
  1524. { "ADCL", NULL, "DSPINTCLK" },
  1525. { "ADCR", NULL, "AIF1CLK" },
  1526. { "ADCR", NULL, "DSP1CLK" },
  1527. { "ADCR", NULL, "DSPINTCLK" },
  1528. { "ADCL Mux", "ADC", "ADCL" },
  1529. { "ADCL Mux", "DMIC", "DMIC1L" },
  1530. { "ADCR Mux", "ADC", "ADCR" },
  1531. { "ADCR Mux", "DMIC", "DMIC1R" },
  1532. { "DAC1L", NULL, "AIF1CLK" },
  1533. { "DAC1L", NULL, "DSP1CLK" },
  1534. { "DAC1L", NULL, "DSPINTCLK" },
  1535. { "DAC1R", NULL, "AIF1CLK" },
  1536. { "DAC1R", NULL, "DSP1CLK" },
  1537. { "DAC1R", NULL, "DSPINTCLK" },
  1538. { "DAC2L", NULL, "AIF2CLK" },
  1539. { "DAC2L", NULL, "DSP2CLK" },
  1540. { "DAC2L", NULL, "DSPINTCLK" },
  1541. { "DAC2R", NULL, "AIF2DACR" },
  1542. { "DAC2R", NULL, "AIF2CLK" },
  1543. { "DAC2R", NULL, "DSP2CLK" },
  1544. { "DAC2R", NULL, "DSPINTCLK" },
  1545. { "TOCLK", NULL, "CLK_SYS" },
  1546. { "AIF1DACDAT", NULL, "AIF1 Playback" },
  1547. { "AIF2DACDAT", NULL, "AIF2 Playback" },
  1548. { "AIF3DACDAT", NULL, "AIF3 Playback" },
  1549. { "AIF1 Capture", NULL, "AIF1ADCDAT" },
  1550. { "AIF2 Capture", NULL, "AIF2ADCDAT" },
  1551. { "AIF3 Capture", NULL, "AIF3ADCDAT" },
  1552. /* AIF1 outputs */
  1553. { "AIF1ADC1L", NULL, "AIF1ADC1L Mixer" },
  1554. { "AIF1ADC1L Mixer", "ADC/DMIC Switch", "ADCL Mux" },
  1555. { "AIF1ADC1L Mixer", "AIF2 Switch", "AIF2DACL" },
  1556. { "AIF1ADC1R", NULL, "AIF1ADC1R Mixer" },
  1557. { "AIF1ADC1R Mixer", "ADC/DMIC Switch", "ADCR Mux" },
  1558. { "AIF1ADC1R Mixer", "AIF2 Switch", "AIF2DACR" },
  1559. { "AIF1ADC2L", NULL, "AIF1ADC2L Mixer" },
  1560. { "AIF1ADC2L Mixer", "DMIC Switch", "DMIC2L" },
  1561. { "AIF1ADC2L Mixer", "AIF2 Switch", "AIF2DACL" },
  1562. { "AIF1ADC2R", NULL, "AIF1ADC2R Mixer" },
  1563. { "AIF1ADC2R Mixer", "DMIC Switch", "DMIC2R" },
  1564. { "AIF1ADC2R Mixer", "AIF2 Switch", "AIF2DACR" },
  1565. /* Pin level routing for AIF3 */
  1566. { "AIF1DAC1L", NULL, "AIF1DAC Mux" },
  1567. { "AIF1DAC1R", NULL, "AIF1DAC Mux" },
  1568. { "AIF1DAC2L", NULL, "AIF1DAC Mux" },
  1569. { "AIF1DAC2R", NULL, "AIF1DAC Mux" },
  1570. { "AIF1DAC Mux", "AIF1DACDAT", "AIF1DACDAT" },
  1571. { "AIF1DAC Mux", "AIF3DACDAT", "AIF3DACDAT" },
  1572. { "AIF2DAC Mux", "AIF2DACDAT", "AIF2DACDAT" },
  1573. { "AIF2DAC Mux", "AIF3DACDAT", "AIF3DACDAT" },
  1574. { "AIF2ADC Mux", "AIF2ADCDAT", "AIF2ADCL" },
  1575. { "AIF2ADC Mux", "AIF2ADCDAT", "AIF2ADCR" },
  1576. { "AIF2ADC Mux", "AIF3DACDAT", "AIF3ADCDAT" },
  1577. /* DAC1 inputs */
  1578. { "DAC1L Mixer", "AIF2 Switch", "AIF2DACL" },
  1579. { "DAC1L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
  1580. { "DAC1L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
  1581. { "DAC1L Mixer", "Left Sidetone Switch", "Left Sidetone" },
  1582. { "DAC1L Mixer", "Right Sidetone Switch", "Right Sidetone" },
  1583. { "DAC1R Mixer", "AIF2 Switch", "AIF2DACR" },
  1584. { "DAC1R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
  1585. { "DAC1R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
  1586. { "DAC1R Mixer", "Left Sidetone Switch", "Left Sidetone" },
  1587. { "DAC1R Mixer", "Right Sidetone Switch", "Right Sidetone" },
  1588. /* DAC2/AIF2 outputs */
  1589. { "AIF2ADCL", NULL, "AIF2DAC2L Mixer" },
  1590. { "AIF2DAC2L Mixer", "AIF2 Switch", "AIF2DACL" },
  1591. { "AIF2DAC2L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
  1592. { "AIF2DAC2L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
  1593. { "AIF2DAC2L Mixer", "Left Sidetone Switch", "Left Sidetone" },
  1594. { "AIF2DAC2L Mixer", "Right Sidetone Switch", "Right Sidetone" },
  1595. { "AIF2ADCR", NULL, "AIF2DAC2R Mixer" },
  1596. { "AIF2DAC2R Mixer", "AIF2 Switch", "AIF2DACR" },
  1597. { "AIF2DAC2R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
  1598. { "AIF2DAC2R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
  1599. { "AIF2DAC2R Mixer", "Left Sidetone Switch", "Left Sidetone" },
  1600. { "AIF2DAC2R Mixer", "Right Sidetone Switch", "Right Sidetone" },
  1601. { "AIF1ADCDAT", NULL, "AIF1ADC1L" },
  1602. { "AIF1ADCDAT", NULL, "AIF1ADC1R" },
  1603. { "AIF1ADCDAT", NULL, "AIF1ADC2L" },
  1604. { "AIF1ADCDAT", NULL, "AIF1ADC2R" },
  1605. { "AIF2ADCDAT", NULL, "AIF2ADC Mux" },
  1606. /* AIF3 output */
  1607. { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC1L" },
  1608. { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC1R" },
  1609. { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC2L" },
  1610. { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC2R" },
  1611. { "AIF3ADCDAT", "AIF2ADCDAT", "AIF2ADCL" },
  1612. { "AIF3ADCDAT", "AIF2ADCDAT", "AIF2ADCR" },
  1613. { "AIF3ADCDAT", "AIF2DACDAT", "AIF2DACL" },
  1614. { "AIF3ADCDAT", "AIF2DACDAT", "AIF2DACR" },
  1615. /* Sidetone */
  1616. { "Left Sidetone", "ADC/DMIC1", "ADCL Mux" },
  1617. { "Left Sidetone", "DMIC2", "DMIC2L" },
  1618. { "Right Sidetone", "ADC/DMIC1", "ADCR Mux" },
  1619. { "Right Sidetone", "DMIC2", "DMIC2R" },
  1620. /* Output stages */
  1621. { "Left Output Mixer", "DAC Switch", "DAC1L" },
  1622. { "Right Output Mixer", "DAC Switch", "DAC1R" },
  1623. { "SPKL", "DAC1 Switch", "DAC1L" },
  1624. { "SPKL", "DAC2 Switch", "DAC2L" },
  1625. { "SPKR", "DAC1 Switch", "DAC1R" },
  1626. { "SPKR", "DAC2 Switch", "DAC2R" },
  1627. { "Left Headphone Mux", "DAC", "DAC1L" },
  1628. { "Right Headphone Mux", "DAC", "DAC1R" },
  1629. };
  1630. static const struct snd_soc_dapm_route wm8994_lateclk_revd_intercon[] = {
  1631. { "DAC1L", NULL, "Late DAC1L Enable PGA" },
  1632. { "Late DAC1L Enable PGA", NULL, "DAC1L Mixer" },
  1633. { "DAC1R", NULL, "Late DAC1R Enable PGA" },
  1634. { "Late DAC1R Enable PGA", NULL, "DAC1R Mixer" },
  1635. { "DAC2L", NULL, "Late DAC2L Enable PGA" },
  1636. { "Late DAC2L Enable PGA", NULL, "AIF2DAC2L Mixer" },
  1637. { "DAC2R", NULL, "Late DAC2R Enable PGA" },
  1638. { "Late DAC2R Enable PGA", NULL, "AIF2DAC2R Mixer" }
  1639. };
  1640. static const struct snd_soc_dapm_route wm8994_lateclk_intercon[] = {
  1641. { "DAC1L", NULL, "DAC1L Mixer" },
  1642. { "DAC1R", NULL, "DAC1R Mixer" },
  1643. { "DAC2L", NULL, "AIF2DAC2L Mixer" },
  1644. { "DAC2R", NULL, "AIF2DAC2R Mixer" },
  1645. };
  1646. static const struct snd_soc_dapm_route wm8994_revd_intercon[] = {
  1647. { "AIF1DACDAT", NULL, "AIF2DACDAT" },
  1648. { "AIF2DACDAT", NULL, "AIF1DACDAT" },
  1649. { "AIF1ADCDAT", NULL, "AIF2ADCDAT" },
  1650. { "AIF2ADCDAT", NULL, "AIF1ADCDAT" },
  1651. { "MICBIAS1", NULL, "CLK_SYS" },
  1652. { "MICBIAS1", NULL, "MICBIAS Supply" },
  1653. { "MICBIAS2", NULL, "CLK_SYS" },
  1654. { "MICBIAS2", NULL, "MICBIAS Supply" },
  1655. };
  1656. static const struct snd_soc_dapm_route wm8994_intercon[] = {
  1657. { "AIF2DACL", NULL, "AIF2DAC Mux" },
  1658. { "AIF2DACR", NULL, "AIF2DAC Mux" },
  1659. { "MICBIAS1", NULL, "VMID" },
  1660. { "MICBIAS2", NULL, "VMID" },
  1661. };
  1662. static const struct snd_soc_dapm_route wm8958_intercon[] = {
  1663. { "AIF2DACL", NULL, "AIF2DACL Mux" },
  1664. { "AIF2DACR", NULL, "AIF2DACR Mux" },
  1665. { "AIF2DACL Mux", "AIF2", "AIF2DAC Mux" },
  1666. { "AIF2DACL Mux", "AIF3", "AIF3DACDAT" },
  1667. { "AIF2DACR Mux", "AIF2", "AIF2DAC Mux" },
  1668. { "AIF2DACR Mux", "AIF3", "AIF3DACDAT" },
  1669. { "Mono PCM Out Mux", "AIF2ADCL", "AIF2ADCL" },
  1670. { "Mono PCM Out Mux", "AIF2ADCR", "AIF2ADCR" },
  1671. { "AIF3ADC Mux", "Mono PCM", "Mono PCM Out Mux" },
  1672. };
  1673. /* The size in bits of the FLL divide multiplied by 10
  1674. * to allow rounding later */
  1675. #define FIXED_FLL_SIZE ((1 << 16) * 10)
  1676. struct fll_div {
  1677. u16 outdiv;
  1678. u16 n;
  1679. u16 k;
  1680. u16 clk_ref_div;
  1681. u16 fll_fratio;
  1682. };
  1683. static int wm8994_get_fll_config(struct fll_div *fll,
  1684. int freq_in, int freq_out)
  1685. {
  1686. u64 Kpart;
  1687. unsigned int K, Ndiv, Nmod;
  1688. pr_debug("FLL input=%dHz, output=%dHz\n", freq_in, freq_out);
  1689. /* Scale the input frequency down to <= 13.5MHz */
  1690. fll->clk_ref_div = 0;
  1691. while (freq_in > 13500000) {
  1692. fll->clk_ref_div++;
  1693. freq_in /= 2;
  1694. if (fll->clk_ref_div > 3)
  1695. return -EINVAL;
  1696. }
  1697. pr_debug("CLK_REF_DIV=%d, Fref=%dHz\n", fll->clk_ref_div, freq_in);
  1698. /* Scale the output to give 90MHz<=Fvco<=100MHz */
  1699. fll->outdiv = 3;
  1700. while (freq_out * (fll->outdiv + 1) < 90000000) {
  1701. fll->outdiv++;
  1702. if (fll->outdiv > 63)
  1703. return -EINVAL;
  1704. }
  1705. freq_out *= fll->outdiv + 1;
  1706. pr_debug("OUTDIV=%d, Fvco=%dHz\n", fll->outdiv, freq_out);
  1707. if (freq_in > 1000000) {
  1708. fll->fll_fratio = 0;
  1709. } else if (freq_in > 256000) {
  1710. fll->fll_fratio = 1;
  1711. freq_in *= 2;
  1712. } else if (freq_in > 128000) {
  1713. fll->fll_fratio = 2;
  1714. freq_in *= 4;
  1715. } else if (freq_in > 64000) {
  1716. fll->fll_fratio = 3;
  1717. freq_in *= 8;
  1718. } else {
  1719. fll->fll_fratio = 4;
  1720. freq_in *= 16;
  1721. }
  1722. pr_debug("FLL_FRATIO=%d, Fref=%dHz\n", fll->fll_fratio, freq_in);
  1723. /* Now, calculate N.K */
  1724. Ndiv = freq_out / freq_in;
  1725. fll->n = Ndiv;
  1726. Nmod = freq_out % freq_in;
  1727. pr_debug("Nmod=%d\n", Nmod);
  1728. /* Calculate fractional part - scale up so we can round. */
  1729. Kpart = FIXED_FLL_SIZE * (long long)Nmod;
  1730. do_div(Kpart, freq_in);
  1731. K = Kpart & 0xFFFFFFFF;
  1732. if ((K % 10) >= 5)
  1733. K += 5;
  1734. /* Move down to proper range now rounding is done */
  1735. fll->k = K / 10;
  1736. pr_debug("N=%x K=%x\n", fll->n, fll->k);
  1737. return 0;
  1738. }
  1739. static int _wm8994_set_fll(struct snd_soc_codec *codec, int id, int src,
  1740. unsigned int freq_in, unsigned int freq_out)
  1741. {
  1742. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  1743. struct wm8994 *control = wm8994->wm8994;
  1744. int reg_offset, ret;
  1745. struct fll_div fll;
  1746. u16 reg, aif1, aif2;
  1747. unsigned long timeout;
  1748. bool was_enabled;
  1749. aif1 = snd_soc_read(codec, WM8994_AIF1_CLOCKING_1)
  1750. & WM8994_AIF1CLK_ENA;
  1751. aif2 = snd_soc_read(codec, WM8994_AIF2_CLOCKING_1)
  1752. & WM8994_AIF2CLK_ENA;
  1753. switch (id) {
  1754. case WM8994_FLL1:
  1755. reg_offset = 0;
  1756. id = 0;
  1757. break;
  1758. case WM8994_FLL2:
  1759. reg_offset = 0x20;
  1760. id = 1;
  1761. break;
  1762. default:
  1763. return -EINVAL;
  1764. }
  1765. reg = snd_soc_read(codec, WM8994_FLL1_CONTROL_1 + reg_offset);
  1766. was_enabled = reg & WM8994_FLL1_ENA;
  1767. switch (src) {
  1768. case 0:
  1769. /* Allow no source specification when stopping */
  1770. if (freq_out)
  1771. return -EINVAL;
  1772. src = wm8994->fll[id].src;
  1773. break;
  1774. case WM8994_FLL_SRC_MCLK1:
  1775. case WM8994_FLL_SRC_MCLK2:
  1776. case WM8994_FLL_SRC_LRCLK:
  1777. case WM8994_FLL_SRC_BCLK:
  1778. break;
  1779. default:
  1780. return -EINVAL;
  1781. }
  1782. /* Are we changing anything? */
  1783. if (wm8994->fll[id].src == src &&
  1784. wm8994->fll[id].in == freq_in && wm8994->fll[id].out == freq_out)
  1785. return 0;
  1786. /* If we're stopping the FLL redo the old config - no
  1787. * registers will actually be written but we avoid GCC flow
  1788. * analysis bugs spewing warnings.
  1789. */
  1790. if (freq_out)
  1791. ret = wm8994_get_fll_config(&fll, freq_in, freq_out);
  1792. else
  1793. ret = wm8994_get_fll_config(&fll, wm8994->fll[id].in,
  1794. wm8994->fll[id].out);
  1795. if (ret < 0)
  1796. return ret;
  1797. /* Gate the AIF clocks while we reclock */
  1798. snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
  1799. WM8994_AIF1CLK_ENA, 0);
  1800. snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
  1801. WM8994_AIF2CLK_ENA, 0);
  1802. /* We always need to disable the FLL while reconfiguring */
  1803. snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_1 + reg_offset,
  1804. WM8994_FLL1_ENA, 0);
  1805. reg = (fll.outdiv << WM8994_FLL1_OUTDIV_SHIFT) |
  1806. (fll.fll_fratio << WM8994_FLL1_FRATIO_SHIFT);
  1807. snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_2 + reg_offset,
  1808. WM8994_FLL1_OUTDIV_MASK |
  1809. WM8994_FLL1_FRATIO_MASK, reg);
  1810. snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_3 + reg_offset,
  1811. WM8994_FLL1_K_MASK, fll.k);
  1812. snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_4 + reg_offset,
  1813. WM8994_FLL1_N_MASK,
  1814. fll.n << WM8994_FLL1_N_SHIFT);
  1815. snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_5 + reg_offset,
  1816. WM8994_FLL1_REFCLK_DIV_MASK |
  1817. WM8994_FLL1_REFCLK_SRC_MASK,
  1818. (fll.clk_ref_div << WM8994_FLL1_REFCLK_DIV_SHIFT) |
  1819. (src - 1));
  1820. /* Clear any pending completion from a previous failure */
  1821. try_wait_for_completion(&wm8994->fll_locked[id]);
  1822. /* Enable (with fractional mode if required) */
  1823. if (freq_out) {
  1824. /* Enable VMID if we need it */
  1825. if (!was_enabled) {
  1826. active_reference(codec);
  1827. switch (control->type) {
  1828. case WM8994:
  1829. vmid_reference(codec);
  1830. break;
  1831. case WM8958:
  1832. if (wm8994->revision < 1)
  1833. vmid_reference(codec);
  1834. break;
  1835. default:
  1836. break;
  1837. }
  1838. }
  1839. if (fll.k)
  1840. reg = WM8994_FLL1_ENA | WM8994_FLL1_FRAC;
  1841. else
  1842. reg = WM8994_FLL1_ENA;
  1843. snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_1 + reg_offset,
  1844. WM8994_FLL1_ENA | WM8994_FLL1_FRAC,
  1845. reg);
  1846. if (wm8994->fll_locked_irq) {
  1847. timeout = wait_for_completion_timeout(&wm8994->fll_locked[id],
  1848. msecs_to_jiffies(10));
  1849. if (timeout == 0)
  1850. dev_warn(codec->dev,
  1851. "Timed out waiting for FLL lock\n");
  1852. } else {
  1853. msleep(5);
  1854. }
  1855. } else {
  1856. if (was_enabled) {
  1857. switch (control->type) {
  1858. case WM8994:
  1859. vmid_dereference(codec);
  1860. break;
  1861. case WM8958:
  1862. if (wm8994->revision < 1)
  1863. vmid_dereference(codec);
  1864. break;
  1865. default:
  1866. break;
  1867. }
  1868. active_dereference(codec);
  1869. }
  1870. }
  1871. wm8994->fll[id].in = freq_in;
  1872. wm8994->fll[id].out = freq_out;
  1873. wm8994->fll[id].src = src;
  1874. /* Enable any gated AIF clocks */
  1875. snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
  1876. WM8994_AIF1CLK_ENA, aif1);
  1877. snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
  1878. WM8994_AIF2CLK_ENA, aif2);
  1879. configure_clock(codec);
  1880. return 0;
  1881. }
  1882. static irqreturn_t wm8994_fll_locked_irq(int irq, void *data)
  1883. {
  1884. struct completion *completion = data;
  1885. complete(completion);
  1886. return IRQ_HANDLED;
  1887. }
  1888. static int opclk_divs[] = { 10, 20, 30, 40, 55, 60, 80, 120, 160 };
  1889. static int wm8994_set_fll(struct snd_soc_dai *dai, int id, int src,
  1890. unsigned int freq_in, unsigned int freq_out)
  1891. {
  1892. return _wm8994_set_fll(dai->codec, id, src, freq_in, freq_out);
  1893. }
  1894. static int wm8994_set_dai_sysclk(struct snd_soc_dai *dai,
  1895. int clk_id, unsigned int freq, int dir)
  1896. {
  1897. struct snd_soc_codec *codec = dai->codec;
  1898. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  1899. int i;
  1900. switch (dai->id) {
  1901. case 1:
  1902. case 2:
  1903. break;
  1904. default:
  1905. /* AIF3 shares clocking with AIF1/2 */
  1906. return -EINVAL;
  1907. }
  1908. switch (clk_id) {
  1909. case WM8994_SYSCLK_MCLK1:
  1910. wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_MCLK1;
  1911. wm8994->mclk[0] = freq;
  1912. dev_dbg(dai->dev, "AIF%d using MCLK1 at %uHz\n",
  1913. dai->id, freq);
  1914. break;
  1915. case WM8994_SYSCLK_MCLK2:
  1916. /* TODO: Set GPIO AF */
  1917. wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_MCLK2;
  1918. wm8994->mclk[1] = freq;
  1919. dev_dbg(dai->dev, "AIF%d using MCLK2 at %uHz\n",
  1920. dai->id, freq);
  1921. break;
  1922. case WM8994_SYSCLK_FLL1:
  1923. wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_FLL1;
  1924. dev_dbg(dai->dev, "AIF%d using FLL1\n", dai->id);
  1925. break;
  1926. case WM8994_SYSCLK_FLL2:
  1927. wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_FLL2;
  1928. dev_dbg(dai->dev, "AIF%d using FLL2\n", dai->id);
  1929. break;
  1930. case WM8994_SYSCLK_OPCLK:
  1931. /* Special case - a division (times 10) is given and
  1932. * no effect on main clocking.
  1933. */
  1934. if (freq) {
  1935. for (i = 0; i < ARRAY_SIZE(opclk_divs); i++)
  1936. if (opclk_divs[i] == freq)
  1937. break;
  1938. if (i == ARRAY_SIZE(opclk_divs))
  1939. return -EINVAL;
  1940. snd_soc_update_bits(codec, WM8994_CLOCKING_2,
  1941. WM8994_OPCLK_DIV_MASK, i);
  1942. snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_2,
  1943. WM8994_OPCLK_ENA, WM8994_OPCLK_ENA);
  1944. } else {
  1945. snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_2,
  1946. WM8994_OPCLK_ENA, 0);
  1947. }
  1948. default:
  1949. return -EINVAL;
  1950. }
  1951. configure_clock(codec);
  1952. return 0;
  1953. }
  1954. static int wm8994_set_bias_level(struct snd_soc_codec *codec,
  1955. enum snd_soc_bias_level level)
  1956. {
  1957. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  1958. struct wm8994 *control = wm8994->wm8994;
  1959. wm_hubs_set_bias_level(codec, level);
  1960. switch (level) {
  1961. case SND_SOC_BIAS_ON:
  1962. break;
  1963. case SND_SOC_BIAS_PREPARE:
  1964. /* MICBIAS into regulating mode */
  1965. switch (control->type) {
  1966. case WM8958:
  1967. case WM1811:
  1968. snd_soc_update_bits(codec, WM8958_MICBIAS1,
  1969. WM8958_MICB1_MODE, 0);
  1970. snd_soc_update_bits(codec, WM8958_MICBIAS2,
  1971. WM8958_MICB2_MODE, 0);
  1972. break;
  1973. default:
  1974. break;
  1975. }
  1976. if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY)
  1977. active_reference(codec);
  1978. break;
  1979. case SND_SOC_BIAS_STANDBY:
  1980. if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
  1981. switch (control->type) {
  1982. case WM8958:
  1983. if (wm8994->revision == 0) {
  1984. /* Optimise performance for rev A */
  1985. snd_soc_update_bits(codec,
  1986. WM8958_CHARGE_PUMP_2,
  1987. WM8958_CP_DISCH,
  1988. WM8958_CP_DISCH);
  1989. }
  1990. break;
  1991. default:
  1992. break;
  1993. }
  1994. /* Discharge LINEOUT1 & 2 */
  1995. snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
  1996. WM8994_LINEOUT1_DISCH |
  1997. WM8994_LINEOUT2_DISCH,
  1998. WM8994_LINEOUT1_DISCH |
  1999. WM8994_LINEOUT2_DISCH);
  2000. }
  2001. if (codec->dapm.bias_level == SND_SOC_BIAS_PREPARE)
  2002. active_dereference(codec);
  2003. /* MICBIAS into bypass mode on newer devices */
  2004. switch (control->type) {
  2005. case WM8958:
  2006. case WM1811:
  2007. snd_soc_update_bits(codec, WM8958_MICBIAS1,
  2008. WM8958_MICB1_MODE,
  2009. WM8958_MICB1_MODE);
  2010. snd_soc_update_bits(codec, WM8958_MICBIAS2,
  2011. WM8958_MICB2_MODE,
  2012. WM8958_MICB2_MODE);
  2013. break;
  2014. default:
  2015. break;
  2016. }
  2017. break;
  2018. case SND_SOC_BIAS_OFF:
  2019. if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY)
  2020. wm8994->cur_fw = NULL;
  2021. break;
  2022. }
  2023. codec->dapm.bias_level = level;
  2024. return 0;
  2025. }
  2026. int wm8994_vmid_mode(struct snd_soc_codec *codec, enum wm8994_vmid_mode mode)
  2027. {
  2028. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  2029. switch (mode) {
  2030. case WM8994_VMID_NORMAL:
  2031. if (wm8994->hubs.lineout1_se) {
  2032. snd_soc_dapm_disable_pin(&codec->dapm,
  2033. "LINEOUT1N Driver");
  2034. snd_soc_dapm_disable_pin(&codec->dapm,
  2035. "LINEOUT1P Driver");
  2036. }
  2037. if (wm8994->hubs.lineout2_se) {
  2038. snd_soc_dapm_disable_pin(&codec->dapm,
  2039. "LINEOUT2N Driver");
  2040. snd_soc_dapm_disable_pin(&codec->dapm,
  2041. "LINEOUT2P Driver");
  2042. }
  2043. /* Do the sync with the old mode to allow it to clean up */
  2044. snd_soc_dapm_sync(&codec->dapm);
  2045. wm8994->vmid_mode = mode;
  2046. break;
  2047. case WM8994_VMID_FORCE:
  2048. if (wm8994->hubs.lineout1_se) {
  2049. snd_soc_dapm_force_enable_pin(&codec->dapm,
  2050. "LINEOUT1N Driver");
  2051. snd_soc_dapm_force_enable_pin(&codec->dapm,
  2052. "LINEOUT1P Driver");
  2053. }
  2054. if (wm8994->hubs.lineout2_se) {
  2055. snd_soc_dapm_force_enable_pin(&codec->dapm,
  2056. "LINEOUT2N Driver");
  2057. snd_soc_dapm_force_enable_pin(&codec->dapm,
  2058. "LINEOUT2P Driver");
  2059. }
  2060. wm8994->vmid_mode = mode;
  2061. snd_soc_dapm_sync(&codec->dapm);
  2062. break;
  2063. default:
  2064. return -EINVAL;
  2065. }
  2066. return 0;
  2067. }
  2068. static int wm8994_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  2069. {
  2070. struct snd_soc_codec *codec = dai->codec;
  2071. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  2072. struct wm8994 *control = wm8994->wm8994;
  2073. int ms_reg;
  2074. int aif1_reg;
  2075. int ms = 0;
  2076. int aif1 = 0;
  2077. switch (dai->id) {
  2078. case 1:
  2079. ms_reg = WM8994_AIF1_MASTER_SLAVE;
  2080. aif1_reg = WM8994_AIF1_CONTROL_1;
  2081. break;
  2082. case 2:
  2083. ms_reg = WM8994_AIF2_MASTER_SLAVE;
  2084. aif1_reg = WM8994_AIF2_CONTROL_1;
  2085. break;
  2086. default:
  2087. return -EINVAL;
  2088. }
  2089. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  2090. case SND_SOC_DAIFMT_CBS_CFS:
  2091. break;
  2092. case SND_SOC_DAIFMT_CBM_CFM:
  2093. ms = WM8994_AIF1_MSTR;
  2094. break;
  2095. default:
  2096. return -EINVAL;
  2097. }
  2098. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  2099. case SND_SOC_DAIFMT_DSP_B:
  2100. aif1 |= WM8994_AIF1_LRCLK_INV;
  2101. case SND_SOC_DAIFMT_DSP_A:
  2102. aif1 |= 0x18;
  2103. break;
  2104. case SND_SOC_DAIFMT_I2S:
  2105. aif1 |= 0x10;
  2106. break;
  2107. case SND_SOC_DAIFMT_RIGHT_J:
  2108. break;
  2109. case SND_SOC_DAIFMT_LEFT_J:
  2110. aif1 |= 0x8;
  2111. break;
  2112. default:
  2113. return -EINVAL;
  2114. }
  2115. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  2116. case SND_SOC_DAIFMT_DSP_A:
  2117. case SND_SOC_DAIFMT_DSP_B:
  2118. /* frame inversion not valid for DSP modes */
  2119. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  2120. case SND_SOC_DAIFMT_NB_NF:
  2121. break;
  2122. case SND_SOC_DAIFMT_IB_NF:
  2123. aif1 |= WM8994_AIF1_BCLK_INV;
  2124. break;
  2125. default:
  2126. return -EINVAL;
  2127. }
  2128. break;
  2129. case SND_SOC_DAIFMT_I2S:
  2130. case SND_SOC_DAIFMT_RIGHT_J:
  2131. case SND_SOC_DAIFMT_LEFT_J:
  2132. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  2133. case SND_SOC_DAIFMT_NB_NF:
  2134. break;
  2135. case SND_SOC_DAIFMT_IB_IF:
  2136. aif1 |= WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV;
  2137. break;
  2138. case SND_SOC_DAIFMT_IB_NF:
  2139. aif1 |= WM8994_AIF1_BCLK_INV;
  2140. break;
  2141. case SND_SOC_DAIFMT_NB_IF:
  2142. aif1 |= WM8994_AIF1_LRCLK_INV;
  2143. break;
  2144. default:
  2145. return -EINVAL;
  2146. }
  2147. break;
  2148. default:
  2149. return -EINVAL;
  2150. }
  2151. /* The AIF2 format configuration needs to be mirrored to AIF3
  2152. * on WM8958 if it's in use so just do it all the time. */
  2153. switch (control->type) {
  2154. case WM1811:
  2155. case WM8958:
  2156. if (dai->id == 2)
  2157. snd_soc_update_bits(codec, WM8958_AIF3_CONTROL_1,
  2158. WM8994_AIF1_LRCLK_INV |
  2159. WM8958_AIF3_FMT_MASK, aif1);
  2160. break;
  2161. default:
  2162. break;
  2163. }
  2164. snd_soc_update_bits(codec, aif1_reg,
  2165. WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV |
  2166. WM8994_AIF1_FMT_MASK,
  2167. aif1);
  2168. snd_soc_update_bits(codec, ms_reg, WM8994_AIF1_MSTR,
  2169. ms);
  2170. return 0;
  2171. }
  2172. static struct {
  2173. int val, rate;
  2174. } srs[] = {
  2175. { 0, 8000 },
  2176. { 1, 11025 },
  2177. { 2, 12000 },
  2178. { 3, 16000 },
  2179. { 4, 22050 },
  2180. { 5, 24000 },
  2181. { 6, 32000 },
  2182. { 7, 44100 },
  2183. { 8, 48000 },
  2184. { 9, 88200 },
  2185. { 10, 96000 },
  2186. };
  2187. static int fs_ratios[] = {
  2188. 64, 128, 192, 256, 384, 512, 768, 1024, 1408, 1536
  2189. };
  2190. static int bclk_divs[] = {
  2191. 10, 15, 20, 30, 40, 50, 60, 80, 110, 120, 160, 220, 240, 320, 440, 480,
  2192. 640, 880, 960, 1280, 1760, 1920
  2193. };
  2194. static int wm8994_hw_params(struct snd_pcm_substream *substream,
  2195. struct snd_pcm_hw_params *params,
  2196. struct snd_soc_dai *dai)
  2197. {
  2198. struct snd_soc_codec *codec = dai->codec;
  2199. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  2200. int aif1_reg;
  2201. int aif2_reg;
  2202. int bclk_reg;
  2203. int lrclk_reg;
  2204. int rate_reg;
  2205. int aif1 = 0;
  2206. int aif2 = 0;
  2207. int bclk = 0;
  2208. int lrclk = 0;
  2209. int rate_val = 0;
  2210. int id = dai->id - 1;
  2211. int i, cur_val, best_val, bclk_rate, best;
  2212. switch (dai->id) {
  2213. case 1:
  2214. aif1_reg = WM8994_AIF1_CONTROL_1;
  2215. aif2_reg = WM8994_AIF1_CONTROL_2;
  2216. bclk_reg = WM8994_AIF1_BCLK;
  2217. rate_reg = WM8994_AIF1_RATE;
  2218. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
  2219. wm8994->lrclk_shared[0]) {
  2220. lrclk_reg = WM8994_AIF1DAC_LRCLK;
  2221. } else {
  2222. lrclk_reg = WM8994_AIF1ADC_LRCLK;
  2223. dev_dbg(codec->dev, "AIF1 using split LRCLK\n");
  2224. }
  2225. break;
  2226. case 2:
  2227. aif1_reg = WM8994_AIF2_CONTROL_1;
  2228. aif2_reg = WM8994_AIF2_CONTROL_2;
  2229. bclk_reg = WM8994_AIF2_BCLK;
  2230. rate_reg = WM8994_AIF2_RATE;
  2231. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
  2232. wm8994->lrclk_shared[1]) {
  2233. lrclk_reg = WM8994_AIF2DAC_LRCLK;
  2234. } else {
  2235. lrclk_reg = WM8994_AIF2ADC_LRCLK;
  2236. dev_dbg(codec->dev, "AIF2 using split LRCLK\n");
  2237. }
  2238. break;
  2239. default:
  2240. return -EINVAL;
  2241. }
  2242. bclk_rate = params_rate(params) * 4;
  2243. switch (params_format(params)) {
  2244. case SNDRV_PCM_FORMAT_S16_LE:
  2245. bclk_rate *= 16;
  2246. break;
  2247. case SNDRV_PCM_FORMAT_S20_3LE:
  2248. bclk_rate *= 20;
  2249. aif1 |= 0x20;
  2250. break;
  2251. case SNDRV_PCM_FORMAT_S24_LE:
  2252. bclk_rate *= 24;
  2253. aif1 |= 0x40;
  2254. break;
  2255. case SNDRV_PCM_FORMAT_S32_LE:
  2256. bclk_rate *= 32;
  2257. aif1 |= 0x60;
  2258. break;
  2259. default:
  2260. return -EINVAL;
  2261. }
  2262. /* Try to find an appropriate sample rate; look for an exact match. */
  2263. for (i = 0; i < ARRAY_SIZE(srs); i++)
  2264. if (srs[i].rate == params_rate(params))
  2265. break;
  2266. if (i == ARRAY_SIZE(srs))
  2267. return -EINVAL;
  2268. rate_val |= srs[i].val << WM8994_AIF1_SR_SHIFT;
  2269. dev_dbg(dai->dev, "Sample rate is %dHz\n", srs[i].rate);
  2270. dev_dbg(dai->dev, "AIF%dCLK is %dHz, target BCLK %dHz\n",
  2271. dai->id, wm8994->aifclk[id], bclk_rate);
  2272. if (params_channels(params) == 1 &&
  2273. (snd_soc_read(codec, aif1_reg) & 0x18) == 0x18)
  2274. aif2 |= WM8994_AIF1_MONO;
  2275. if (wm8994->aifclk[id] == 0) {
  2276. dev_err(dai->dev, "AIF%dCLK not configured\n", dai->id);
  2277. return -EINVAL;
  2278. }
  2279. /* AIFCLK/fs ratio; look for a close match in either direction */
  2280. best = 0;
  2281. best_val = abs((fs_ratios[0] * params_rate(params))
  2282. - wm8994->aifclk[id]);
  2283. for (i = 1; i < ARRAY_SIZE(fs_ratios); i++) {
  2284. cur_val = abs((fs_ratios[i] * params_rate(params))
  2285. - wm8994->aifclk[id]);
  2286. if (cur_val >= best_val)
  2287. continue;
  2288. best = i;
  2289. best_val = cur_val;
  2290. }
  2291. dev_dbg(dai->dev, "Selected AIF%dCLK/fs = %d\n",
  2292. dai->id, fs_ratios[best]);
  2293. rate_val |= best;
  2294. /* We may not get quite the right frequency if using
  2295. * approximate clocks so look for the closest match that is
  2296. * higher than the target (we need to ensure that there enough
  2297. * BCLKs to clock out the samples).
  2298. */
  2299. best = 0;
  2300. for (i = 0; i < ARRAY_SIZE(bclk_divs); i++) {
  2301. cur_val = (wm8994->aifclk[id] * 10 / bclk_divs[i]) - bclk_rate;
  2302. if (cur_val < 0) /* BCLK table is sorted */
  2303. break;
  2304. best = i;
  2305. }
  2306. bclk_rate = wm8994->aifclk[id] * 10 / bclk_divs[best];
  2307. dev_dbg(dai->dev, "Using BCLK_DIV %d for actual BCLK %dHz\n",
  2308. bclk_divs[best], bclk_rate);
  2309. bclk |= best << WM8994_AIF1_BCLK_DIV_SHIFT;
  2310. lrclk = bclk_rate / params_rate(params);
  2311. if (!lrclk) {
  2312. dev_err(dai->dev, "Unable to generate LRCLK from %dHz BCLK\n",
  2313. bclk_rate);
  2314. return -EINVAL;
  2315. }
  2316. dev_dbg(dai->dev, "Using LRCLK rate %d for actual LRCLK %dHz\n",
  2317. lrclk, bclk_rate / lrclk);
  2318. snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
  2319. snd_soc_update_bits(codec, aif2_reg, WM8994_AIF1_MONO, aif2);
  2320. snd_soc_update_bits(codec, bclk_reg, WM8994_AIF1_BCLK_DIV_MASK, bclk);
  2321. snd_soc_update_bits(codec, lrclk_reg, WM8994_AIF1DAC_RATE_MASK,
  2322. lrclk);
  2323. snd_soc_update_bits(codec, rate_reg, WM8994_AIF1_SR_MASK |
  2324. WM8994_AIF1CLK_RATE_MASK, rate_val);
  2325. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  2326. switch (dai->id) {
  2327. case 1:
  2328. wm8994->dac_rates[0] = params_rate(params);
  2329. wm8994_set_retune_mobile(codec, 0);
  2330. wm8994_set_retune_mobile(codec, 1);
  2331. break;
  2332. case 2:
  2333. wm8994->dac_rates[1] = params_rate(params);
  2334. wm8994_set_retune_mobile(codec, 2);
  2335. break;
  2336. }
  2337. }
  2338. return 0;
  2339. }
  2340. static int wm8994_aif3_hw_params(struct snd_pcm_substream *substream,
  2341. struct snd_pcm_hw_params *params,
  2342. struct snd_soc_dai *dai)
  2343. {
  2344. struct snd_soc_codec *codec = dai->codec;
  2345. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  2346. struct wm8994 *control = wm8994->wm8994;
  2347. int aif1_reg;
  2348. int aif1 = 0;
  2349. switch (dai->id) {
  2350. case 3:
  2351. switch (control->type) {
  2352. case WM1811:
  2353. case WM8958:
  2354. aif1_reg = WM8958_AIF3_CONTROL_1;
  2355. break;
  2356. default:
  2357. return 0;
  2358. }
  2359. break;
  2360. default:
  2361. return 0;
  2362. }
  2363. switch (params_format(params)) {
  2364. case SNDRV_PCM_FORMAT_S16_LE:
  2365. break;
  2366. case SNDRV_PCM_FORMAT_S20_3LE:
  2367. aif1 |= 0x20;
  2368. break;
  2369. case SNDRV_PCM_FORMAT_S24_LE:
  2370. aif1 |= 0x40;
  2371. break;
  2372. case SNDRV_PCM_FORMAT_S32_LE:
  2373. aif1 |= 0x60;
  2374. break;
  2375. default:
  2376. return -EINVAL;
  2377. }
  2378. return snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
  2379. }
  2380. static void wm8994_aif_shutdown(struct snd_pcm_substream *substream,
  2381. struct snd_soc_dai *dai)
  2382. {
  2383. struct snd_soc_codec *codec = dai->codec;
  2384. int rate_reg = 0;
  2385. switch (dai->id) {
  2386. case 1:
  2387. rate_reg = WM8994_AIF1_RATE;
  2388. break;
  2389. case 2:
  2390. rate_reg = WM8994_AIF2_RATE;
  2391. break;
  2392. default:
  2393. break;
  2394. }
  2395. /* If the DAI is idle then configure the divider tree for the
  2396. * lowest output rate to save a little power if the clock is
  2397. * still active (eg, because it is system clock).
  2398. */
  2399. if (rate_reg && !dai->playback_active && !dai->capture_active)
  2400. snd_soc_update_bits(codec, rate_reg,
  2401. WM8994_AIF1_SR_MASK |
  2402. WM8994_AIF1CLK_RATE_MASK, 0x9);
  2403. }
  2404. static int wm8994_aif_mute(struct snd_soc_dai *codec_dai, int mute)
  2405. {
  2406. struct snd_soc_codec *codec = codec_dai->codec;
  2407. int mute_reg;
  2408. int reg;
  2409. switch (codec_dai->id) {
  2410. case 1:
  2411. mute_reg = WM8994_AIF1_DAC1_FILTERS_1;
  2412. break;
  2413. case 2:
  2414. mute_reg = WM8994_AIF2_DAC_FILTERS_1;
  2415. break;
  2416. default:
  2417. return -EINVAL;
  2418. }
  2419. if (mute)
  2420. reg = WM8994_AIF1DAC1_MUTE;
  2421. else
  2422. reg = 0;
  2423. snd_soc_update_bits(codec, mute_reg, WM8994_AIF1DAC1_MUTE, reg);
  2424. return 0;
  2425. }
  2426. static int wm8994_set_tristate(struct snd_soc_dai *codec_dai, int tristate)
  2427. {
  2428. struct snd_soc_codec *codec = codec_dai->codec;
  2429. int reg, val, mask;
  2430. switch (codec_dai->id) {
  2431. case 1:
  2432. reg = WM8994_AIF1_MASTER_SLAVE;
  2433. mask = WM8994_AIF1_TRI;
  2434. break;
  2435. case 2:
  2436. reg = WM8994_AIF2_MASTER_SLAVE;
  2437. mask = WM8994_AIF2_TRI;
  2438. break;
  2439. case 3:
  2440. reg = WM8994_POWER_MANAGEMENT_6;
  2441. mask = WM8994_AIF3_TRI;
  2442. break;
  2443. default:
  2444. return -EINVAL;
  2445. }
  2446. if (tristate)
  2447. val = mask;
  2448. else
  2449. val = 0;
  2450. return snd_soc_update_bits(codec, reg, mask, val);
  2451. }
  2452. static int wm8994_aif2_probe(struct snd_soc_dai *dai)
  2453. {
  2454. struct snd_soc_codec *codec = dai->codec;
  2455. /* Disable the pulls on the AIF if we're using it to save power. */
  2456. snd_soc_update_bits(codec, WM8994_GPIO_3,
  2457. WM8994_GPN_PU | WM8994_GPN_PD, 0);
  2458. snd_soc_update_bits(codec, WM8994_GPIO_4,
  2459. WM8994_GPN_PU | WM8994_GPN_PD, 0);
  2460. snd_soc_update_bits(codec, WM8994_GPIO_5,
  2461. WM8994_GPN_PU | WM8994_GPN_PD, 0);
  2462. return 0;
  2463. }
  2464. #define WM8994_RATES SNDRV_PCM_RATE_8000_96000
  2465. #define WM8994_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
  2466. SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
  2467. static const struct snd_soc_dai_ops wm8994_aif1_dai_ops = {
  2468. .set_sysclk = wm8994_set_dai_sysclk,
  2469. .set_fmt = wm8994_set_dai_fmt,
  2470. .hw_params = wm8994_hw_params,
  2471. .shutdown = wm8994_aif_shutdown,
  2472. .digital_mute = wm8994_aif_mute,
  2473. .set_pll = wm8994_set_fll,
  2474. .set_tristate = wm8994_set_tristate,
  2475. };
  2476. static const struct snd_soc_dai_ops wm8994_aif2_dai_ops = {
  2477. .set_sysclk = wm8994_set_dai_sysclk,
  2478. .set_fmt = wm8994_set_dai_fmt,
  2479. .hw_params = wm8994_hw_params,
  2480. .shutdown = wm8994_aif_shutdown,
  2481. .digital_mute = wm8994_aif_mute,
  2482. .set_pll = wm8994_set_fll,
  2483. .set_tristate = wm8994_set_tristate,
  2484. };
  2485. static const struct snd_soc_dai_ops wm8994_aif3_dai_ops = {
  2486. .hw_params = wm8994_aif3_hw_params,
  2487. .set_tristate = wm8994_set_tristate,
  2488. };
  2489. static struct snd_soc_dai_driver wm8994_dai[] = {
  2490. {
  2491. .name = "wm8994-aif1",
  2492. .id = 1,
  2493. .playback = {
  2494. .stream_name = "AIF1 Playback",
  2495. .channels_min = 1,
  2496. .channels_max = 2,
  2497. .rates = WM8994_RATES,
  2498. .formats = WM8994_FORMATS,
  2499. .sig_bits = 24,
  2500. },
  2501. .capture = {
  2502. .stream_name = "AIF1 Capture",
  2503. .channels_min = 1,
  2504. .channels_max = 2,
  2505. .rates = WM8994_RATES,
  2506. .formats = WM8994_FORMATS,
  2507. .sig_bits = 24,
  2508. },
  2509. .ops = &wm8994_aif1_dai_ops,
  2510. },
  2511. {
  2512. .name = "wm8994-aif2",
  2513. .id = 2,
  2514. .playback = {
  2515. .stream_name = "AIF2 Playback",
  2516. .channels_min = 1,
  2517. .channels_max = 2,
  2518. .rates = WM8994_RATES,
  2519. .formats = WM8994_FORMATS,
  2520. .sig_bits = 24,
  2521. },
  2522. .capture = {
  2523. .stream_name = "AIF2 Capture",
  2524. .channels_min = 1,
  2525. .channels_max = 2,
  2526. .rates = WM8994_RATES,
  2527. .formats = WM8994_FORMATS,
  2528. .sig_bits = 24,
  2529. },
  2530. .probe = wm8994_aif2_probe,
  2531. .ops = &wm8994_aif2_dai_ops,
  2532. },
  2533. {
  2534. .name = "wm8994-aif3",
  2535. .id = 3,
  2536. .playback = {
  2537. .stream_name = "AIF3 Playback",
  2538. .channels_min = 1,
  2539. .channels_max = 2,
  2540. .rates = WM8994_RATES,
  2541. .formats = WM8994_FORMATS,
  2542. .sig_bits = 24,
  2543. },
  2544. .capture = {
  2545. .stream_name = "AIF3 Capture",
  2546. .channels_min = 1,
  2547. .channels_max = 2,
  2548. .rates = WM8994_RATES,
  2549. .formats = WM8994_FORMATS,
  2550. .sig_bits = 24,
  2551. },
  2552. .ops = &wm8994_aif3_dai_ops,
  2553. }
  2554. };
  2555. #ifdef CONFIG_PM
  2556. static int wm8994_codec_suspend(struct snd_soc_codec *codec)
  2557. {
  2558. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  2559. struct wm8994 *control = wm8994->wm8994;
  2560. int i, ret;
  2561. switch (control->type) {
  2562. case WM8994:
  2563. snd_soc_update_bits(codec, WM8994_MICBIAS, WM8994_MICD_ENA, 0);
  2564. break;
  2565. case WM1811:
  2566. snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
  2567. WM1811_JACKDET_MODE_MASK, 0);
  2568. /* Fall through */
  2569. case WM8958:
  2570. snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
  2571. WM8958_MICD_ENA, 0);
  2572. break;
  2573. }
  2574. for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) {
  2575. memcpy(&wm8994->fll_suspend[i], &wm8994->fll[i],
  2576. sizeof(struct wm8994_fll_config));
  2577. ret = _wm8994_set_fll(codec, i + 1, 0, 0, 0);
  2578. if (ret < 0)
  2579. dev_warn(codec->dev, "Failed to stop FLL%d: %d\n",
  2580. i + 1, ret);
  2581. }
  2582. wm8994_set_bias_level(codec, SND_SOC_BIAS_OFF);
  2583. return 0;
  2584. }
  2585. static int wm8994_codec_resume(struct snd_soc_codec *codec)
  2586. {
  2587. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  2588. struct wm8994 *control = wm8994->wm8994;
  2589. int i, ret;
  2590. unsigned int val, mask;
  2591. if (wm8994->revision < 4) {
  2592. /* force a HW read */
  2593. ret = regmap_read(control->regmap,
  2594. WM8994_POWER_MANAGEMENT_5, &val);
  2595. /* modify the cache only */
  2596. codec->cache_only = 1;
  2597. mask = WM8994_DAC1R_ENA | WM8994_DAC1L_ENA |
  2598. WM8994_DAC2R_ENA | WM8994_DAC2L_ENA;
  2599. val &= mask;
  2600. snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
  2601. mask, val);
  2602. codec->cache_only = 0;
  2603. }
  2604. for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) {
  2605. if (!wm8994->fll_suspend[i].out)
  2606. continue;
  2607. ret = _wm8994_set_fll(codec, i + 1,
  2608. wm8994->fll_suspend[i].src,
  2609. wm8994->fll_suspend[i].in,
  2610. wm8994->fll_suspend[i].out);
  2611. if (ret < 0)
  2612. dev_warn(codec->dev, "Failed to restore FLL%d: %d\n",
  2613. i + 1, ret);
  2614. }
  2615. switch (control->type) {
  2616. case WM8994:
  2617. if (wm8994->micdet[0].jack || wm8994->micdet[1].jack)
  2618. snd_soc_update_bits(codec, WM8994_MICBIAS,
  2619. WM8994_MICD_ENA, WM8994_MICD_ENA);
  2620. break;
  2621. case WM1811:
  2622. if (wm8994->jackdet && wm8994->jack_cb) {
  2623. /* Restart from idle */
  2624. snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
  2625. WM1811_JACKDET_MODE_MASK,
  2626. WM1811_JACKDET_MODE_JACK);
  2627. break;
  2628. }
  2629. break;
  2630. case WM8958:
  2631. if (wm8994->jack_cb)
  2632. snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
  2633. WM8958_MICD_ENA, WM8958_MICD_ENA);
  2634. break;
  2635. }
  2636. return 0;
  2637. }
  2638. #else
  2639. #define wm8994_codec_suspend NULL
  2640. #define wm8994_codec_resume NULL
  2641. #endif
  2642. static void wm8994_handle_retune_mobile_pdata(struct wm8994_priv *wm8994)
  2643. {
  2644. struct snd_soc_codec *codec = wm8994->codec;
  2645. struct wm8994_pdata *pdata = wm8994->pdata;
  2646. struct snd_kcontrol_new controls[] = {
  2647. SOC_ENUM_EXT("AIF1.1 EQ Mode",
  2648. wm8994->retune_mobile_enum,
  2649. wm8994_get_retune_mobile_enum,
  2650. wm8994_put_retune_mobile_enum),
  2651. SOC_ENUM_EXT("AIF1.2 EQ Mode",
  2652. wm8994->retune_mobile_enum,
  2653. wm8994_get_retune_mobile_enum,
  2654. wm8994_put_retune_mobile_enum),
  2655. SOC_ENUM_EXT("AIF2 EQ Mode",
  2656. wm8994->retune_mobile_enum,
  2657. wm8994_get_retune_mobile_enum,
  2658. wm8994_put_retune_mobile_enum),
  2659. };
  2660. int ret, i, j;
  2661. const char **t;
  2662. /* We need an array of texts for the enum API but the number
  2663. * of texts is likely to be less than the number of
  2664. * configurations due to the sample rate dependency of the
  2665. * configurations. */
  2666. wm8994->num_retune_mobile_texts = 0;
  2667. wm8994->retune_mobile_texts = NULL;
  2668. for (i = 0; i < pdata->num_retune_mobile_cfgs; i++) {
  2669. for (j = 0; j < wm8994->num_retune_mobile_texts; j++) {
  2670. if (strcmp(pdata->retune_mobile_cfgs[i].name,
  2671. wm8994->retune_mobile_texts[j]) == 0)
  2672. break;
  2673. }
  2674. if (j != wm8994->num_retune_mobile_texts)
  2675. continue;
  2676. /* Expand the array... */
  2677. t = krealloc(wm8994->retune_mobile_texts,
  2678. sizeof(char *) *
  2679. (wm8994->num_retune_mobile_texts + 1),
  2680. GFP_KERNEL);
  2681. if (t == NULL)
  2682. continue;
  2683. /* ...store the new entry... */
  2684. t[wm8994->num_retune_mobile_texts] =
  2685. pdata->retune_mobile_cfgs[i].name;
  2686. /* ...and remember the new version. */
  2687. wm8994->num_retune_mobile_texts++;
  2688. wm8994->retune_mobile_texts = t;
  2689. }
  2690. dev_dbg(codec->dev, "Allocated %d unique ReTune Mobile names\n",
  2691. wm8994->num_retune_mobile_texts);
  2692. wm8994->retune_mobile_enum.max = wm8994->num_retune_mobile_texts;
  2693. wm8994->retune_mobile_enum.texts = wm8994->retune_mobile_texts;
  2694. ret = snd_soc_add_codec_controls(wm8994->codec, controls,
  2695. ARRAY_SIZE(controls));
  2696. if (ret != 0)
  2697. dev_err(wm8994->codec->dev,
  2698. "Failed to add ReTune Mobile controls: %d\n", ret);
  2699. }
  2700. static void wm8994_handle_pdata(struct wm8994_priv *wm8994)
  2701. {
  2702. struct snd_soc_codec *codec = wm8994->codec;
  2703. struct wm8994_pdata *pdata = wm8994->pdata;
  2704. int ret, i;
  2705. if (!pdata)
  2706. return;
  2707. wm_hubs_handle_analogue_pdata(codec, pdata->lineout1_diff,
  2708. pdata->lineout2_diff,
  2709. pdata->lineout1fb,
  2710. pdata->lineout2fb,
  2711. pdata->jd_scthr,
  2712. pdata->jd_thr,
  2713. pdata->micbias1_lvl,
  2714. pdata->micbias2_lvl);
  2715. dev_dbg(codec->dev, "%d DRC configurations\n", pdata->num_drc_cfgs);
  2716. if (pdata->num_drc_cfgs) {
  2717. struct snd_kcontrol_new controls[] = {
  2718. SOC_ENUM_EXT("AIF1DRC1 Mode", wm8994->drc_enum,
  2719. wm8994_get_drc_enum, wm8994_put_drc_enum),
  2720. SOC_ENUM_EXT("AIF1DRC2 Mode", wm8994->drc_enum,
  2721. wm8994_get_drc_enum, wm8994_put_drc_enum),
  2722. SOC_ENUM_EXT("AIF2DRC Mode", wm8994->drc_enum,
  2723. wm8994_get_drc_enum, wm8994_put_drc_enum),
  2724. };
  2725. /* We need an array of texts for the enum API */
  2726. wm8994->drc_texts = devm_kzalloc(wm8994->codec->dev,
  2727. sizeof(char *) * pdata->num_drc_cfgs, GFP_KERNEL);
  2728. if (!wm8994->drc_texts) {
  2729. dev_err(wm8994->codec->dev,
  2730. "Failed to allocate %d DRC config texts\n",
  2731. pdata->num_drc_cfgs);
  2732. return;
  2733. }
  2734. for (i = 0; i < pdata->num_drc_cfgs; i++)
  2735. wm8994->drc_texts[i] = pdata->drc_cfgs[i].name;
  2736. wm8994->drc_enum.max = pdata->num_drc_cfgs;
  2737. wm8994->drc_enum.texts = wm8994->drc_texts;
  2738. ret = snd_soc_add_codec_controls(wm8994->codec, controls,
  2739. ARRAY_SIZE(controls));
  2740. if (ret != 0)
  2741. dev_err(wm8994->codec->dev,
  2742. "Failed to add DRC mode controls: %d\n", ret);
  2743. for (i = 0; i < WM8994_NUM_DRC; i++)
  2744. wm8994_set_drc(codec, i);
  2745. }
  2746. dev_dbg(codec->dev, "%d ReTune Mobile configurations\n",
  2747. pdata->num_retune_mobile_cfgs);
  2748. if (pdata->num_retune_mobile_cfgs)
  2749. wm8994_handle_retune_mobile_pdata(wm8994);
  2750. else
  2751. snd_soc_add_codec_controls(wm8994->codec, wm8994_eq_controls,
  2752. ARRAY_SIZE(wm8994_eq_controls));
  2753. for (i = 0; i < ARRAY_SIZE(pdata->micbias); i++) {
  2754. if (pdata->micbias[i]) {
  2755. snd_soc_write(codec, WM8958_MICBIAS1 + i,
  2756. pdata->micbias[i] & 0xffff);
  2757. }
  2758. }
  2759. }
  2760. /**
  2761. * wm8994_mic_detect - Enable microphone detection via the WM8994 IRQ
  2762. *
  2763. * @codec: WM8994 codec
  2764. * @jack: jack to report detection events on
  2765. * @micbias: microphone bias to detect on
  2766. *
  2767. * Enable microphone detection via IRQ on the WM8994. If GPIOs are
  2768. * being used to bring out signals to the processor then only platform
  2769. * data configuration is needed for WM8994 and processor GPIOs should
  2770. * be configured using snd_soc_jack_add_gpios() instead.
  2771. *
  2772. * Configuration of detection levels is available via the micbias1_lvl
  2773. * and micbias2_lvl platform data members.
  2774. */
  2775. int wm8994_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
  2776. int micbias)
  2777. {
  2778. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  2779. struct wm8994_micdet *micdet;
  2780. struct wm8994 *control = wm8994->wm8994;
  2781. int reg, ret;
  2782. if (control->type != WM8994) {
  2783. dev_warn(codec->dev, "Not a WM8994\n");
  2784. return -EINVAL;
  2785. }
  2786. switch (micbias) {
  2787. case 1:
  2788. micdet = &wm8994->micdet[0];
  2789. if (jack)
  2790. ret = snd_soc_dapm_force_enable_pin(&codec->dapm,
  2791. "MICBIAS1");
  2792. else
  2793. ret = snd_soc_dapm_disable_pin(&codec->dapm,
  2794. "MICBIAS1");
  2795. break;
  2796. case 2:
  2797. micdet = &wm8994->micdet[1];
  2798. if (jack)
  2799. ret = snd_soc_dapm_force_enable_pin(&codec->dapm,
  2800. "MICBIAS1");
  2801. else
  2802. ret = snd_soc_dapm_disable_pin(&codec->dapm,
  2803. "MICBIAS1");
  2804. break;
  2805. default:
  2806. dev_warn(codec->dev, "Invalid MICBIAS %d\n", micbias);
  2807. return -EINVAL;
  2808. }
  2809. if (ret != 0)
  2810. dev_warn(codec->dev, "Failed to configure MICBIAS%d: %d\n",
  2811. micbias, ret);
  2812. dev_dbg(codec->dev, "Configuring microphone detection on %d %p\n",
  2813. micbias, jack);
  2814. /* Store the configuration */
  2815. micdet->jack = jack;
  2816. micdet->detecting = true;
  2817. /* If either of the jacks is set up then enable detection */
  2818. if (wm8994->micdet[0].jack || wm8994->micdet[1].jack)
  2819. reg = WM8994_MICD_ENA;
  2820. else
  2821. reg = 0;
  2822. snd_soc_update_bits(codec, WM8994_MICBIAS, WM8994_MICD_ENA, reg);
  2823. snd_soc_dapm_sync(&codec->dapm);
  2824. return 0;
  2825. }
  2826. EXPORT_SYMBOL_GPL(wm8994_mic_detect);
  2827. static irqreturn_t wm8994_mic_irq(int irq, void *data)
  2828. {
  2829. struct wm8994_priv *priv = data;
  2830. struct snd_soc_codec *codec = priv->codec;
  2831. int reg;
  2832. int report;
  2833. #ifndef CONFIG_SND_SOC_WM8994_MODULE
  2834. trace_snd_soc_jack_irq(dev_name(codec->dev));
  2835. #endif
  2836. reg = snd_soc_read(codec, WM8994_INTERRUPT_RAW_STATUS_2);
  2837. if (reg < 0) {
  2838. dev_err(codec->dev, "Failed to read microphone status: %d\n",
  2839. reg);
  2840. return IRQ_HANDLED;
  2841. }
  2842. dev_dbg(codec->dev, "Microphone status: %x\n", reg);
  2843. report = 0;
  2844. if (reg & WM8994_MIC1_DET_STS) {
  2845. if (priv->micdet[0].detecting)
  2846. report = SND_JACK_HEADSET;
  2847. }
  2848. if (reg & WM8994_MIC1_SHRT_STS) {
  2849. if (priv->micdet[0].detecting)
  2850. report = SND_JACK_HEADPHONE;
  2851. else
  2852. report |= SND_JACK_BTN_0;
  2853. }
  2854. if (report)
  2855. priv->micdet[0].detecting = false;
  2856. else
  2857. priv->micdet[0].detecting = true;
  2858. snd_soc_jack_report(priv->micdet[0].jack, report,
  2859. SND_JACK_HEADSET | SND_JACK_BTN_0);
  2860. report = 0;
  2861. if (reg & WM8994_MIC2_DET_STS) {
  2862. if (priv->micdet[1].detecting)
  2863. report = SND_JACK_HEADSET;
  2864. }
  2865. if (reg & WM8994_MIC2_SHRT_STS) {
  2866. if (priv->micdet[1].detecting)
  2867. report = SND_JACK_HEADPHONE;
  2868. else
  2869. report |= SND_JACK_BTN_0;
  2870. }
  2871. if (report)
  2872. priv->micdet[1].detecting = false;
  2873. else
  2874. priv->micdet[1].detecting = true;
  2875. snd_soc_jack_report(priv->micdet[1].jack, report,
  2876. SND_JACK_HEADSET | SND_JACK_BTN_0);
  2877. return IRQ_HANDLED;
  2878. }
  2879. /* Default microphone detection handler for WM8958 - the user can
  2880. * override this if they wish.
  2881. */
  2882. static void wm8958_default_micdet(u16 status, void *data)
  2883. {
  2884. struct snd_soc_codec *codec = data;
  2885. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  2886. int report;
  2887. dev_dbg(codec->dev, "MICDET %x\n", status);
  2888. /* Either nothing present or just starting detection */
  2889. if (!(status & WM8958_MICD_STS)) {
  2890. if (!wm8994->jackdet) {
  2891. /* If nothing present then clear our statuses */
  2892. dev_dbg(codec->dev, "Detected open circuit\n");
  2893. wm8994->jack_mic = false;
  2894. wm8994->mic_detecting = true;
  2895. wm8958_micd_set_rate(codec);
  2896. snd_soc_jack_report(wm8994->micdet[0].jack, 0,
  2897. wm8994->btn_mask |
  2898. SND_JACK_HEADSET);
  2899. }
  2900. return;
  2901. }
  2902. /* If the measurement is showing a high impedence we've got a
  2903. * microphone.
  2904. */
  2905. if (wm8994->mic_detecting && (status & 0x600)) {
  2906. dev_dbg(codec->dev, "Detected microphone\n");
  2907. wm8994->mic_detecting = false;
  2908. wm8994->jack_mic = true;
  2909. wm8958_micd_set_rate(codec);
  2910. snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADSET,
  2911. SND_JACK_HEADSET);
  2912. }
  2913. if (wm8994->mic_detecting && status & 0xfc) {
  2914. dev_dbg(codec->dev, "Detected headphone\n");
  2915. wm8994->mic_detecting = false;
  2916. wm8958_micd_set_rate(codec);
  2917. snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADPHONE,
  2918. SND_JACK_HEADSET);
  2919. /* If we have jackdet that will detect removal */
  2920. if (wm8994->jackdet) {
  2921. mutex_lock(&wm8994->accdet_lock);
  2922. snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
  2923. WM8958_MICD_ENA, 0);
  2924. wm1811_jackdet_set_mode(codec,
  2925. WM1811_JACKDET_MODE_JACK);
  2926. mutex_unlock(&wm8994->accdet_lock);
  2927. if (wm8994->pdata->jd_ext_cap) {
  2928. mutex_lock(&codec->mutex);
  2929. snd_soc_dapm_disable_pin(&codec->dapm,
  2930. "MICBIAS2");
  2931. snd_soc_dapm_sync(&codec->dapm);
  2932. mutex_unlock(&codec->mutex);
  2933. }
  2934. }
  2935. }
  2936. /* Report short circuit as a button */
  2937. if (wm8994->jack_mic) {
  2938. report = 0;
  2939. if (status & 0x4)
  2940. report |= SND_JACK_BTN_0;
  2941. if (status & 0x8)
  2942. report |= SND_JACK_BTN_1;
  2943. if (status & 0x10)
  2944. report |= SND_JACK_BTN_2;
  2945. if (status & 0x20)
  2946. report |= SND_JACK_BTN_3;
  2947. if (status & 0x40)
  2948. report |= SND_JACK_BTN_4;
  2949. if (status & 0x80)
  2950. report |= SND_JACK_BTN_5;
  2951. snd_soc_jack_report(wm8994->micdet[0].jack, report,
  2952. wm8994->btn_mask);
  2953. }
  2954. }
  2955. static irqreturn_t wm1811_jackdet_irq(int irq, void *data)
  2956. {
  2957. struct wm8994_priv *wm8994 = data;
  2958. struct snd_soc_codec *codec = wm8994->codec;
  2959. int reg;
  2960. bool present;
  2961. mutex_lock(&wm8994->accdet_lock);
  2962. reg = snd_soc_read(codec, WM1811_JACKDET_CTRL);
  2963. if (reg < 0) {
  2964. dev_err(codec->dev, "Failed to read jack status: %d\n", reg);
  2965. mutex_unlock(&wm8994->accdet_lock);
  2966. return IRQ_NONE;
  2967. }
  2968. dev_dbg(codec->dev, "JACKDET %x\n", reg);
  2969. present = reg & WM1811_JACKDET_LVL;
  2970. if (present) {
  2971. dev_dbg(codec->dev, "Jack detected\n");
  2972. snd_soc_update_bits(codec, WM8958_MICBIAS2,
  2973. WM8958_MICB2_DISCH, 0);
  2974. /* Disable debounce while inserted */
  2975. snd_soc_update_bits(codec, WM1811_JACKDET_CTRL,
  2976. WM1811_JACKDET_DB, 0);
  2977. /*
  2978. * Start off measument of microphone impedence to find
  2979. * out what's actually there.
  2980. */
  2981. wm8994->mic_detecting = true;
  2982. wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_MIC);
  2983. snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
  2984. WM8958_MICD_ENA, WM8958_MICD_ENA);
  2985. } else {
  2986. dev_dbg(codec->dev, "Jack not detected\n");
  2987. snd_soc_update_bits(codec, WM8958_MICBIAS2,
  2988. WM8958_MICB2_DISCH, WM8958_MICB2_DISCH);
  2989. /* Enable debounce while removed */
  2990. snd_soc_update_bits(codec, WM1811_JACKDET_CTRL,
  2991. WM1811_JACKDET_DB, WM1811_JACKDET_DB);
  2992. wm8994->mic_detecting = false;
  2993. wm8994->jack_mic = false;
  2994. snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
  2995. WM8958_MICD_ENA, 0);
  2996. wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_JACK);
  2997. }
  2998. mutex_unlock(&wm8994->accdet_lock);
  2999. /* If required for an external cap force MICBIAS on */
  3000. if (wm8994->pdata->jd_ext_cap) {
  3001. mutex_lock(&codec->mutex);
  3002. if (present)
  3003. snd_soc_dapm_force_enable_pin(&codec->dapm,
  3004. "MICBIAS2");
  3005. else
  3006. snd_soc_dapm_disable_pin(&codec->dapm, "MICBIAS2");
  3007. snd_soc_dapm_sync(&codec->dapm);
  3008. mutex_unlock(&codec->mutex);
  3009. }
  3010. if (present)
  3011. snd_soc_jack_report(wm8994->micdet[0].jack,
  3012. SND_JACK_MECHANICAL, SND_JACK_MECHANICAL);
  3013. else
  3014. snd_soc_jack_report(wm8994->micdet[0].jack, 0,
  3015. SND_JACK_MECHANICAL | SND_JACK_HEADSET |
  3016. wm8994->btn_mask);
  3017. return IRQ_HANDLED;
  3018. }
  3019. /**
  3020. * wm8958_mic_detect - Enable microphone detection via the WM8958 IRQ
  3021. *
  3022. * @codec: WM8958 codec
  3023. * @jack: jack to report detection events on
  3024. *
  3025. * Enable microphone detection functionality for the WM8958. By
  3026. * default simple detection which supports the detection of up to 6
  3027. * buttons plus video and microphone functionality is supported.
  3028. *
  3029. * The WM8958 has an advanced jack detection facility which is able to
  3030. * support complex accessory detection, especially when used in
  3031. * conjunction with external circuitry. In order to provide maximum
  3032. * flexiblity a callback is provided which allows a completely custom
  3033. * detection algorithm.
  3034. */
  3035. int wm8958_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
  3036. wm8958_micdet_cb cb, void *cb_data)
  3037. {
  3038. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  3039. struct wm8994 *control = wm8994->wm8994;
  3040. u16 micd_lvl_sel;
  3041. switch (control->type) {
  3042. case WM1811:
  3043. case WM8958:
  3044. break;
  3045. default:
  3046. return -EINVAL;
  3047. }
  3048. if (jack) {
  3049. if (!cb) {
  3050. dev_dbg(codec->dev, "Using default micdet callback\n");
  3051. cb = wm8958_default_micdet;
  3052. cb_data = codec;
  3053. }
  3054. snd_soc_dapm_force_enable_pin(&codec->dapm, "CLK_SYS");
  3055. snd_soc_dapm_sync(&codec->dapm);
  3056. wm8994->micdet[0].jack = jack;
  3057. wm8994->jack_cb = cb;
  3058. wm8994->jack_cb_data = cb_data;
  3059. wm8994->mic_detecting = true;
  3060. wm8994->jack_mic = false;
  3061. wm8958_micd_set_rate(codec);
  3062. /* Detect microphones and short circuits by default */
  3063. if (wm8994->pdata->micd_lvl_sel)
  3064. micd_lvl_sel = wm8994->pdata->micd_lvl_sel;
  3065. else
  3066. micd_lvl_sel = 0x41;
  3067. wm8994->btn_mask = SND_JACK_BTN_0 | SND_JACK_BTN_1 |
  3068. SND_JACK_BTN_2 | SND_JACK_BTN_3 |
  3069. SND_JACK_BTN_4 | SND_JACK_BTN_5;
  3070. snd_soc_update_bits(codec, WM8958_MIC_DETECT_2,
  3071. WM8958_MICD_LVL_SEL_MASK, micd_lvl_sel);
  3072. WARN_ON(codec->dapm.bias_level > SND_SOC_BIAS_STANDBY);
  3073. /*
  3074. * If we can use jack detection start off with that,
  3075. * otherwise jump straight to microphone detection.
  3076. */
  3077. if (wm8994->jackdet) {
  3078. snd_soc_update_bits(codec, WM8958_MICBIAS2,
  3079. WM8958_MICB2_DISCH,
  3080. WM8958_MICB2_DISCH);
  3081. snd_soc_update_bits(codec, WM8994_LDO_1,
  3082. WM8994_LDO1_DISCH, 0);
  3083. wm1811_jackdet_set_mode(codec,
  3084. WM1811_JACKDET_MODE_JACK);
  3085. } else {
  3086. snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
  3087. WM8958_MICD_ENA, WM8958_MICD_ENA);
  3088. }
  3089. } else {
  3090. snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
  3091. WM8958_MICD_ENA, 0);
  3092. wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_NONE);
  3093. snd_soc_dapm_disable_pin(&codec->dapm, "CLK_SYS");
  3094. snd_soc_dapm_sync(&codec->dapm);
  3095. }
  3096. return 0;
  3097. }
  3098. EXPORT_SYMBOL_GPL(wm8958_mic_detect);
  3099. static irqreturn_t wm8958_mic_irq(int irq, void *data)
  3100. {
  3101. struct wm8994_priv *wm8994 = data;
  3102. struct snd_soc_codec *codec = wm8994->codec;
  3103. int reg, count;
  3104. /*
  3105. * Jack detection may have detected a removal simulataneously
  3106. * with an update of the MICDET status; if so it will have
  3107. * stopped detection and we can ignore this interrupt.
  3108. */
  3109. if (!(snd_soc_read(codec, WM8958_MIC_DETECT_1) & WM8958_MICD_ENA))
  3110. return IRQ_HANDLED;
  3111. /* We may occasionally read a detection without an impedence
  3112. * range being provided - if that happens loop again.
  3113. */
  3114. count = 10;
  3115. do {
  3116. reg = snd_soc_read(codec, WM8958_MIC_DETECT_3);
  3117. if (reg < 0) {
  3118. dev_err(codec->dev,
  3119. "Failed to read mic detect status: %d\n",
  3120. reg);
  3121. return IRQ_NONE;
  3122. }
  3123. if (!(reg & WM8958_MICD_VALID)) {
  3124. dev_dbg(codec->dev, "Mic detect data not valid\n");
  3125. goto out;
  3126. }
  3127. if (!(reg & WM8958_MICD_STS) || (reg & WM8958_MICD_LVL_MASK))
  3128. break;
  3129. msleep(1);
  3130. } while (count--);
  3131. if (count == 0)
  3132. dev_warn(codec->dev, "No impedence range reported for jack\n");
  3133. #ifndef CONFIG_SND_SOC_WM8994_MODULE
  3134. trace_snd_soc_jack_irq(dev_name(codec->dev));
  3135. #endif
  3136. if (wm8994->jack_cb)
  3137. wm8994->jack_cb(reg, wm8994->jack_cb_data);
  3138. else
  3139. dev_warn(codec->dev, "Accessory detection with no callback\n");
  3140. out:
  3141. return IRQ_HANDLED;
  3142. }
  3143. static irqreturn_t wm8994_fifo_error(int irq, void *data)
  3144. {
  3145. struct snd_soc_codec *codec = data;
  3146. dev_err(codec->dev, "FIFO error\n");
  3147. return IRQ_HANDLED;
  3148. }
  3149. static irqreturn_t wm8994_temp_warn(int irq, void *data)
  3150. {
  3151. struct snd_soc_codec *codec = data;
  3152. dev_err(codec->dev, "Thermal warning\n");
  3153. return IRQ_HANDLED;
  3154. }
  3155. static irqreturn_t wm8994_temp_shut(int irq, void *data)
  3156. {
  3157. struct snd_soc_codec *codec = data;
  3158. dev_crit(codec->dev, "Thermal shutdown\n");
  3159. return IRQ_HANDLED;
  3160. }
  3161. static int wm8994_codec_probe(struct snd_soc_codec *codec)
  3162. {
  3163. struct wm8994 *control = dev_get_drvdata(codec->dev->parent);
  3164. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  3165. struct snd_soc_dapm_context *dapm = &codec->dapm;
  3166. unsigned int reg;
  3167. int ret, i;
  3168. wm8994->codec = codec;
  3169. codec->control_data = control->regmap;
  3170. snd_soc_codec_set_cache_io(codec, 16, 16, SND_SOC_REGMAP);
  3171. wm8994->codec = codec;
  3172. mutex_init(&wm8994->accdet_lock);
  3173. for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
  3174. init_completion(&wm8994->fll_locked[i]);
  3175. if (wm8994->pdata && wm8994->pdata->micdet_irq)
  3176. wm8994->micdet_irq = wm8994->pdata->micdet_irq;
  3177. else if (wm8994->pdata && wm8994->pdata->irq_base)
  3178. wm8994->micdet_irq = wm8994->pdata->irq_base +
  3179. WM8994_IRQ_MIC1_DET;
  3180. pm_runtime_enable(codec->dev);
  3181. pm_runtime_idle(codec->dev);
  3182. /* By default use idle_bias_off, will override for WM8994 */
  3183. codec->dapm.idle_bias_off = 1;
  3184. /* Set revision-specific configuration */
  3185. wm8994->revision = snd_soc_read(codec, WM8994_CHIP_REVISION);
  3186. switch (control->type) {
  3187. case WM8994:
  3188. /* Single ended line outputs should have VMID on. */
  3189. if (!wm8994->pdata->lineout1_diff ||
  3190. !wm8994->pdata->lineout2_diff)
  3191. codec->dapm.idle_bias_off = 0;
  3192. switch (wm8994->revision) {
  3193. case 2:
  3194. case 3:
  3195. wm8994->hubs.dcs_codes_l = -5;
  3196. wm8994->hubs.dcs_codes_r = -5;
  3197. wm8994->hubs.hp_startup_mode = 1;
  3198. wm8994->hubs.dcs_readback_mode = 1;
  3199. wm8994->hubs.series_startup = 1;
  3200. break;
  3201. default:
  3202. wm8994->hubs.dcs_readback_mode = 2;
  3203. break;
  3204. }
  3205. break;
  3206. case WM8958:
  3207. wm8994->hubs.dcs_readback_mode = 1;
  3208. wm8994->hubs.hp_startup_mode = 1;
  3209. break;
  3210. case WM1811:
  3211. wm8994->hubs.dcs_readback_mode = 2;
  3212. wm8994->hubs.no_series_update = 1;
  3213. wm8994->hubs.hp_startup_mode = 1;
  3214. wm8994->hubs.no_cache_class_w = true;
  3215. switch (wm8994->revision) {
  3216. case 0:
  3217. case 1:
  3218. case 2:
  3219. case 3:
  3220. wm8994->hubs.dcs_codes_l = -9;
  3221. wm8994->hubs.dcs_codes_r = -7;
  3222. break;
  3223. default:
  3224. break;
  3225. }
  3226. snd_soc_update_bits(codec, WM8994_ANALOGUE_HP_1,
  3227. WM1811_HPOUT1_ATTN, WM1811_HPOUT1_ATTN);
  3228. break;
  3229. default:
  3230. break;
  3231. }
  3232. wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_FIFOS_ERR,
  3233. wm8994_fifo_error, "FIFO error", codec);
  3234. wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_TEMP_WARN,
  3235. wm8994_temp_warn, "Thermal warning", codec);
  3236. wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_TEMP_SHUT,
  3237. wm8994_temp_shut, "Thermal shutdown", codec);
  3238. ret = wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_DCS_DONE,
  3239. wm_hubs_dcs_done, "DC servo done",
  3240. &wm8994->hubs);
  3241. if (ret == 0)
  3242. wm8994->hubs.dcs_done_irq = true;
  3243. switch (control->type) {
  3244. case WM8994:
  3245. if (wm8994->micdet_irq) {
  3246. ret = request_threaded_irq(wm8994->micdet_irq, NULL,
  3247. wm8994_mic_irq,
  3248. IRQF_TRIGGER_RISING,
  3249. "Mic1 detect",
  3250. wm8994);
  3251. if (ret != 0)
  3252. dev_warn(codec->dev,
  3253. "Failed to request Mic1 detect IRQ: %d\n",
  3254. ret);
  3255. }
  3256. ret = wm8994_request_irq(wm8994->wm8994,
  3257. WM8994_IRQ_MIC1_SHRT,
  3258. wm8994_mic_irq, "Mic 1 short",
  3259. wm8994);
  3260. if (ret != 0)
  3261. dev_warn(codec->dev,
  3262. "Failed to request Mic1 short IRQ: %d\n",
  3263. ret);
  3264. ret = wm8994_request_irq(wm8994->wm8994,
  3265. WM8994_IRQ_MIC2_DET,
  3266. wm8994_mic_irq, "Mic 2 detect",
  3267. wm8994);
  3268. if (ret != 0)
  3269. dev_warn(codec->dev,
  3270. "Failed to request Mic2 detect IRQ: %d\n",
  3271. ret);
  3272. ret = wm8994_request_irq(wm8994->wm8994,
  3273. WM8994_IRQ_MIC2_SHRT,
  3274. wm8994_mic_irq, "Mic 2 short",
  3275. wm8994);
  3276. if (ret != 0)
  3277. dev_warn(codec->dev,
  3278. "Failed to request Mic2 short IRQ: %d\n",
  3279. ret);
  3280. break;
  3281. case WM8958:
  3282. case WM1811:
  3283. if (wm8994->micdet_irq) {
  3284. ret = request_threaded_irq(wm8994->micdet_irq, NULL,
  3285. wm8958_mic_irq,
  3286. IRQF_TRIGGER_RISING,
  3287. "Mic detect",
  3288. wm8994);
  3289. if (ret != 0)
  3290. dev_warn(codec->dev,
  3291. "Failed to request Mic detect IRQ: %d\n",
  3292. ret);
  3293. }
  3294. }
  3295. switch (control->type) {
  3296. case WM1811:
  3297. if (wm8994->revision > 1) {
  3298. ret = wm8994_request_irq(wm8994->wm8994,
  3299. WM8994_IRQ_GPIO(6),
  3300. wm1811_jackdet_irq, "JACKDET",
  3301. wm8994);
  3302. if (ret == 0)
  3303. wm8994->jackdet = true;
  3304. }
  3305. break;
  3306. default:
  3307. break;
  3308. }
  3309. wm8994->fll_locked_irq = true;
  3310. for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++) {
  3311. ret = wm8994_request_irq(wm8994->wm8994,
  3312. WM8994_IRQ_FLL1_LOCK + i,
  3313. wm8994_fll_locked_irq, "FLL lock",
  3314. &wm8994->fll_locked[i]);
  3315. if (ret != 0)
  3316. wm8994->fll_locked_irq = false;
  3317. }
  3318. /* Make sure we can read from the GPIOs if they're inputs */
  3319. pm_runtime_get_sync(codec->dev);
  3320. /* Remember if AIFnLRCLK is configured as a GPIO. This should be
  3321. * configured on init - if a system wants to do this dynamically
  3322. * at runtime we can deal with that then.
  3323. */
  3324. ret = regmap_read(control->regmap, WM8994_GPIO_1, &reg);
  3325. if (ret < 0) {
  3326. dev_err(codec->dev, "Failed to read GPIO1 state: %d\n", ret);
  3327. goto err_irq;
  3328. }
  3329. if ((reg & WM8994_GPN_FN_MASK) != WM8994_GP_FN_PIN_SPECIFIC) {
  3330. wm8994->lrclk_shared[0] = 1;
  3331. wm8994_dai[0].symmetric_rates = 1;
  3332. } else {
  3333. wm8994->lrclk_shared[0] = 0;
  3334. }
  3335. ret = regmap_read(control->regmap, WM8994_GPIO_6, &reg);
  3336. if (ret < 0) {
  3337. dev_err(codec->dev, "Failed to read GPIO6 state: %d\n", ret);
  3338. goto err_irq;
  3339. }
  3340. if ((reg & WM8994_GPN_FN_MASK) != WM8994_GP_FN_PIN_SPECIFIC) {
  3341. wm8994->lrclk_shared[1] = 1;
  3342. wm8994_dai[1].symmetric_rates = 1;
  3343. } else {
  3344. wm8994->lrclk_shared[1] = 0;
  3345. }
  3346. pm_runtime_put(codec->dev);
  3347. /* Latch volume update bits */
  3348. for (i = 0; i < ARRAY_SIZE(wm8994_vu_bits); i++)
  3349. snd_soc_update_bits(codec, wm8994_vu_bits[i].reg,
  3350. wm8994_vu_bits[i].mask,
  3351. wm8994_vu_bits[i].mask);
  3352. /* Set the low bit of the 3D stereo depth so TLV matches */
  3353. snd_soc_update_bits(codec, WM8994_AIF1_DAC1_FILTERS_2,
  3354. 1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT,
  3355. 1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT);
  3356. snd_soc_update_bits(codec, WM8994_AIF1_DAC2_FILTERS_2,
  3357. 1 << WM8994_AIF1DAC2_3D_GAIN_SHIFT,
  3358. 1 << WM8994_AIF1DAC2_3D_GAIN_SHIFT);
  3359. snd_soc_update_bits(codec, WM8994_AIF2_DAC_FILTERS_2,
  3360. 1 << WM8994_AIF2DAC_3D_GAIN_SHIFT,
  3361. 1 << WM8994_AIF2DAC_3D_GAIN_SHIFT);
  3362. /* Unconditionally enable AIF1 ADC TDM mode on chips which can
  3363. * use this; it only affects behaviour on idle TDM clock
  3364. * cycles. */
  3365. switch (control->type) {
  3366. case WM8994:
  3367. case WM8958:
  3368. snd_soc_update_bits(codec, WM8994_AIF1_CONTROL_1,
  3369. WM8994_AIF1ADC_TDM, WM8994_AIF1ADC_TDM);
  3370. break;
  3371. default:
  3372. break;
  3373. }
  3374. /* Put MICBIAS into bypass mode by default on newer devices */
  3375. switch (control->type) {
  3376. case WM8958:
  3377. case WM1811:
  3378. snd_soc_update_bits(codec, WM8958_MICBIAS1,
  3379. WM8958_MICB1_MODE, WM8958_MICB1_MODE);
  3380. snd_soc_update_bits(codec, WM8958_MICBIAS2,
  3381. WM8958_MICB2_MODE, WM8958_MICB2_MODE);
  3382. break;
  3383. default:
  3384. break;
  3385. }
  3386. wm8994_update_class_w(codec);
  3387. wm8994_handle_pdata(wm8994);
  3388. wm_hubs_add_analogue_controls(codec);
  3389. snd_soc_add_codec_controls(codec, wm8994_snd_controls,
  3390. ARRAY_SIZE(wm8994_snd_controls));
  3391. snd_soc_dapm_new_controls(dapm, wm8994_dapm_widgets,
  3392. ARRAY_SIZE(wm8994_dapm_widgets));
  3393. switch (control->type) {
  3394. case WM8994:
  3395. snd_soc_dapm_new_controls(dapm, wm8994_specific_dapm_widgets,
  3396. ARRAY_SIZE(wm8994_specific_dapm_widgets));
  3397. if (wm8994->revision < 4) {
  3398. snd_soc_dapm_new_controls(dapm, wm8994_lateclk_revd_widgets,
  3399. ARRAY_SIZE(wm8994_lateclk_revd_widgets));
  3400. snd_soc_dapm_new_controls(dapm, wm8994_adc_revd_widgets,
  3401. ARRAY_SIZE(wm8994_adc_revd_widgets));
  3402. snd_soc_dapm_new_controls(dapm, wm8994_dac_revd_widgets,
  3403. ARRAY_SIZE(wm8994_dac_revd_widgets));
  3404. } else {
  3405. snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
  3406. ARRAY_SIZE(wm8994_lateclk_widgets));
  3407. snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
  3408. ARRAY_SIZE(wm8994_adc_widgets));
  3409. snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
  3410. ARRAY_SIZE(wm8994_dac_widgets));
  3411. }
  3412. break;
  3413. case WM8958:
  3414. snd_soc_add_codec_controls(codec, wm8958_snd_controls,
  3415. ARRAY_SIZE(wm8958_snd_controls));
  3416. snd_soc_dapm_new_controls(dapm, wm8958_dapm_widgets,
  3417. ARRAY_SIZE(wm8958_dapm_widgets));
  3418. if (wm8994->revision < 1) {
  3419. snd_soc_dapm_new_controls(dapm, wm8994_lateclk_revd_widgets,
  3420. ARRAY_SIZE(wm8994_lateclk_revd_widgets));
  3421. snd_soc_dapm_new_controls(dapm, wm8994_adc_revd_widgets,
  3422. ARRAY_SIZE(wm8994_adc_revd_widgets));
  3423. snd_soc_dapm_new_controls(dapm, wm8994_dac_revd_widgets,
  3424. ARRAY_SIZE(wm8994_dac_revd_widgets));
  3425. } else {
  3426. snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
  3427. ARRAY_SIZE(wm8994_lateclk_widgets));
  3428. snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
  3429. ARRAY_SIZE(wm8994_adc_widgets));
  3430. snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
  3431. ARRAY_SIZE(wm8994_dac_widgets));
  3432. }
  3433. break;
  3434. case WM1811:
  3435. snd_soc_add_codec_controls(codec, wm8958_snd_controls,
  3436. ARRAY_SIZE(wm8958_snd_controls));
  3437. snd_soc_dapm_new_controls(dapm, wm8958_dapm_widgets,
  3438. ARRAY_SIZE(wm8958_dapm_widgets));
  3439. snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets,
  3440. ARRAY_SIZE(wm8994_lateclk_widgets));
  3441. snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets,
  3442. ARRAY_SIZE(wm8994_adc_widgets));
  3443. snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets,
  3444. ARRAY_SIZE(wm8994_dac_widgets));
  3445. break;
  3446. }
  3447. wm_hubs_add_analogue_routes(codec, 0, 0);
  3448. snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
  3449. switch (control->type) {
  3450. case WM8994:
  3451. snd_soc_dapm_add_routes(dapm, wm8994_intercon,
  3452. ARRAY_SIZE(wm8994_intercon));
  3453. if (wm8994->revision < 4) {
  3454. snd_soc_dapm_add_routes(dapm, wm8994_revd_intercon,
  3455. ARRAY_SIZE(wm8994_revd_intercon));
  3456. snd_soc_dapm_add_routes(dapm, wm8994_lateclk_revd_intercon,
  3457. ARRAY_SIZE(wm8994_lateclk_revd_intercon));
  3458. } else {
  3459. snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
  3460. ARRAY_SIZE(wm8994_lateclk_intercon));
  3461. }
  3462. break;
  3463. case WM8958:
  3464. if (wm8994->revision < 1) {
  3465. snd_soc_dapm_add_routes(dapm, wm8994_revd_intercon,
  3466. ARRAY_SIZE(wm8994_revd_intercon));
  3467. snd_soc_dapm_add_routes(dapm, wm8994_lateclk_revd_intercon,
  3468. ARRAY_SIZE(wm8994_lateclk_revd_intercon));
  3469. } else {
  3470. snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
  3471. ARRAY_SIZE(wm8994_lateclk_intercon));
  3472. snd_soc_dapm_add_routes(dapm, wm8958_intercon,
  3473. ARRAY_SIZE(wm8958_intercon));
  3474. }
  3475. wm8958_dsp2_init(codec);
  3476. break;
  3477. case WM1811:
  3478. snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon,
  3479. ARRAY_SIZE(wm8994_lateclk_intercon));
  3480. snd_soc_dapm_add_routes(dapm, wm8958_intercon,
  3481. ARRAY_SIZE(wm8958_intercon));
  3482. break;
  3483. }
  3484. return 0;
  3485. err_irq:
  3486. if (wm8994->jackdet)
  3487. wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_GPIO(6), wm8994);
  3488. wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_SHRT, wm8994);
  3489. wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_DET, wm8994);
  3490. wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_SHRT, wm8994);
  3491. if (wm8994->micdet_irq)
  3492. free_irq(wm8994->micdet_irq, wm8994);
  3493. for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
  3494. wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FLL1_LOCK + i,
  3495. &wm8994->fll_locked[i]);
  3496. wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_DCS_DONE,
  3497. &wm8994->hubs);
  3498. wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FIFOS_ERR, codec);
  3499. wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_SHUT, codec);
  3500. wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_WARN, codec);
  3501. return ret;
  3502. }
  3503. static int wm8994_codec_remove(struct snd_soc_codec *codec)
  3504. {
  3505. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  3506. struct wm8994 *control = wm8994->wm8994;
  3507. int i;
  3508. wm8994_set_bias_level(codec, SND_SOC_BIAS_OFF);
  3509. pm_runtime_disable(codec->dev);
  3510. for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
  3511. wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FLL1_LOCK + i,
  3512. &wm8994->fll_locked[i]);
  3513. wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_DCS_DONE,
  3514. &wm8994->hubs);
  3515. wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FIFOS_ERR, codec);
  3516. wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_SHUT, codec);
  3517. wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_TEMP_WARN, codec);
  3518. if (wm8994->jackdet)
  3519. wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_GPIO(6), wm8994);
  3520. switch (control->type) {
  3521. case WM8994:
  3522. if (wm8994->micdet_irq)
  3523. free_irq(wm8994->micdet_irq, wm8994);
  3524. wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_DET,
  3525. wm8994);
  3526. wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_SHRT,
  3527. wm8994);
  3528. wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_DET,
  3529. wm8994);
  3530. break;
  3531. case WM1811:
  3532. case WM8958:
  3533. if (wm8994->micdet_irq)
  3534. free_irq(wm8994->micdet_irq, wm8994);
  3535. break;
  3536. }
  3537. if (wm8994->mbc)
  3538. release_firmware(wm8994->mbc);
  3539. if (wm8994->mbc_vss)
  3540. release_firmware(wm8994->mbc_vss);
  3541. if (wm8994->enh_eq)
  3542. release_firmware(wm8994->enh_eq);
  3543. kfree(wm8994->retune_mobile_texts);
  3544. return 0;
  3545. }
  3546. static struct snd_soc_codec_driver soc_codec_dev_wm8994 = {
  3547. .probe = wm8994_codec_probe,
  3548. .remove = wm8994_codec_remove,
  3549. .suspend = wm8994_codec_suspend,
  3550. .resume = wm8994_codec_resume,
  3551. .set_bias_level = wm8994_set_bias_level,
  3552. };
  3553. static int __devinit wm8994_probe(struct platform_device *pdev)
  3554. {
  3555. struct wm8994_priv *wm8994;
  3556. wm8994 = devm_kzalloc(&pdev->dev, sizeof(struct wm8994_priv),
  3557. GFP_KERNEL);
  3558. if (wm8994 == NULL)
  3559. return -ENOMEM;
  3560. platform_set_drvdata(pdev, wm8994);
  3561. wm8994->wm8994 = dev_get_drvdata(pdev->dev.parent);
  3562. wm8994->pdata = dev_get_platdata(pdev->dev.parent);
  3563. return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_wm8994,
  3564. wm8994_dai, ARRAY_SIZE(wm8994_dai));
  3565. }
  3566. static int __devexit wm8994_remove(struct platform_device *pdev)
  3567. {
  3568. snd_soc_unregister_codec(&pdev->dev);
  3569. return 0;
  3570. }
  3571. #ifdef CONFIG_PM_SLEEP
  3572. static int wm8994_suspend(struct device *dev)
  3573. {
  3574. struct wm8994_priv *wm8994 = dev_get_drvdata(dev);
  3575. /* Drop down to power saving mode when system is suspended */
  3576. if (wm8994->jackdet && !wm8994->active_refcount)
  3577. regmap_update_bits(wm8994->wm8994->regmap, WM8994_ANTIPOP_2,
  3578. WM1811_JACKDET_MODE_MASK,
  3579. wm8994->jackdet_mode);
  3580. return 0;
  3581. }
  3582. static int wm8994_resume(struct device *dev)
  3583. {
  3584. struct wm8994_priv *wm8994 = dev_get_drvdata(dev);
  3585. if (wm8994->jackdet && wm8994->jack_cb)
  3586. regmap_update_bits(wm8994->wm8994->regmap, WM8994_ANTIPOP_2,
  3587. WM1811_JACKDET_MODE_MASK,
  3588. WM1811_JACKDET_MODE_AUDIO);
  3589. return 0;
  3590. }
  3591. #endif
  3592. static const struct dev_pm_ops wm8994_pm_ops = {
  3593. SET_SYSTEM_SLEEP_PM_OPS(wm8994_suspend, wm8994_resume)
  3594. };
  3595. static struct platform_driver wm8994_codec_driver = {
  3596. .driver = {
  3597. .name = "wm8994-codec",
  3598. .owner = THIS_MODULE,
  3599. .pm = &wm8994_pm_ops,
  3600. },
  3601. .probe = wm8994_probe,
  3602. .remove = __devexit_p(wm8994_remove),
  3603. };
  3604. module_platform_driver(wm8994_codec_driver);
  3605. MODULE_DESCRIPTION("ASoC WM8994 driver");
  3606. MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
  3607. MODULE_LICENSE("GPL");
  3608. MODULE_ALIAS("platform:wm8994-codec");