rt5659.c 127 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250
  1. /*
  2. * rt5659.c -- RT5659/RT5658 ALSA SoC audio codec driver
  3. *
  4. * Copyright 2015 Realtek Semiconductor Corp.
  5. * Author: Bard Liao <bardliao@realtek.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/clk.h>
  12. #include <linux/module.h>
  13. #include <linux/moduleparam.h>
  14. #include <linux/init.h>
  15. #include <linux/delay.h>
  16. #include <linux/pm.h>
  17. #include <linux/i2c.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/spi/spi.h>
  20. #include <linux/acpi.h>
  21. #include <linux/gpio.h>
  22. #include <linux/gpio/consumer.h>
  23. #include <sound/core.h>
  24. #include <sound/pcm.h>
  25. #include <sound/pcm_params.h>
  26. #include <sound/jack.h>
  27. #include <sound/soc.h>
  28. #include <sound/soc-dapm.h>
  29. #include <sound/initval.h>
  30. #include <sound/tlv.h>
  31. #include <sound/rt5659.h>
  32. #include "rl6231.h"
  33. #include "rt5659.h"
  34. static const struct reg_default rt5659_reg[] = {
  35. { 0x0000, 0x0000 },
  36. { 0x0001, 0x4848 },
  37. { 0x0002, 0x8080 },
  38. { 0x0003, 0xc8c8 },
  39. { 0x0004, 0xc80a },
  40. { 0x0005, 0x0000 },
  41. { 0x0006, 0x0000 },
  42. { 0x0007, 0x0103 },
  43. { 0x0008, 0x0080 },
  44. { 0x0009, 0x0000 },
  45. { 0x000a, 0x0000 },
  46. { 0x000c, 0x0000 },
  47. { 0x000d, 0x0000 },
  48. { 0x000f, 0x0808 },
  49. { 0x0010, 0x3080 },
  50. { 0x0011, 0x4a00 },
  51. { 0x0012, 0x4e00 },
  52. { 0x0015, 0x42c1 },
  53. { 0x0016, 0x0000 },
  54. { 0x0018, 0x000b },
  55. { 0x0019, 0xafaf },
  56. { 0x001a, 0xafaf },
  57. { 0x001b, 0x0011 },
  58. { 0x001c, 0x2f2f },
  59. { 0x001d, 0x2f2f },
  60. { 0x001e, 0x2f2f },
  61. { 0x001f, 0x0000 },
  62. { 0x0020, 0x0000 },
  63. { 0x0021, 0x0000 },
  64. { 0x0022, 0x5757 },
  65. { 0x0023, 0x0039 },
  66. { 0x0026, 0xc060 },
  67. { 0x0027, 0xd8d8 },
  68. { 0x0029, 0x8080 },
  69. { 0x002a, 0xaaaa },
  70. { 0x002b, 0xaaaa },
  71. { 0x002c, 0x00af },
  72. { 0x002d, 0x0000 },
  73. { 0x002f, 0x1002 },
  74. { 0x0031, 0x5000 },
  75. { 0x0032, 0x0000 },
  76. { 0x0033, 0x0000 },
  77. { 0x0034, 0x0000 },
  78. { 0x0035, 0x0000 },
  79. { 0x0036, 0x0000 },
  80. { 0x003a, 0x0000 },
  81. { 0x003b, 0x0000 },
  82. { 0x003c, 0x007f },
  83. { 0x003d, 0x0000 },
  84. { 0x003e, 0x007f },
  85. { 0x0040, 0x0808 },
  86. { 0x0046, 0x001f },
  87. { 0x0047, 0x001f },
  88. { 0x0048, 0x0003 },
  89. { 0x0049, 0xe061 },
  90. { 0x004a, 0x0000 },
  91. { 0x004b, 0x031f },
  92. { 0x004d, 0x0000 },
  93. { 0x004e, 0x001f },
  94. { 0x004f, 0x0000 },
  95. { 0x0050, 0x001f },
  96. { 0x0052, 0xf000 },
  97. { 0x0053, 0x0111 },
  98. { 0x0054, 0x0064 },
  99. { 0x0055, 0x0080 },
  100. { 0x0056, 0xef0e },
  101. { 0x0057, 0xf0f0 },
  102. { 0x0058, 0xef0e },
  103. { 0x0059, 0xf0f0 },
  104. { 0x005a, 0xef0e },
  105. { 0x005b, 0xf0f0 },
  106. { 0x005c, 0xf000 },
  107. { 0x005d, 0x0000 },
  108. { 0x005e, 0x1f2c },
  109. { 0x005f, 0x1f2c },
  110. { 0x0060, 0x2717 },
  111. { 0x0061, 0x0000 },
  112. { 0x0062, 0x0000 },
  113. { 0x0063, 0x003e },
  114. { 0x0064, 0x0000 },
  115. { 0x0065, 0x0000 },
  116. { 0x0066, 0x0000 },
  117. { 0x0067, 0x0000 },
  118. { 0x006a, 0x0000 },
  119. { 0x006b, 0x0000 },
  120. { 0x006c, 0x0000 },
  121. { 0x006e, 0x0000 },
  122. { 0x006f, 0x0000 },
  123. { 0x0070, 0x8000 },
  124. { 0x0071, 0x8000 },
  125. { 0x0072, 0x8000 },
  126. { 0x0073, 0x1110 },
  127. { 0x0074, 0xfe00 },
  128. { 0x0075, 0x2409 },
  129. { 0x0076, 0x000a },
  130. { 0x0077, 0x00f0 },
  131. { 0x0078, 0x0000 },
  132. { 0x0079, 0x0000 },
  133. { 0x007a, 0x0123 },
  134. { 0x007b, 0x8003 },
  135. { 0x0080, 0x0000 },
  136. { 0x0081, 0x0000 },
  137. { 0x0082, 0x0000 },
  138. { 0x0083, 0x0000 },
  139. { 0x0084, 0x0000 },
  140. { 0x0085, 0x0000 },
  141. { 0x0086, 0x0008 },
  142. { 0x0087, 0x0000 },
  143. { 0x0088, 0x0000 },
  144. { 0x0089, 0x0000 },
  145. { 0x008a, 0x0000 },
  146. { 0x008b, 0x0000 },
  147. { 0x008c, 0x0003 },
  148. { 0x008e, 0x0000 },
  149. { 0x008f, 0x1000 },
  150. { 0x0090, 0x0646 },
  151. { 0x0091, 0x0c16 },
  152. { 0x0092, 0x0073 },
  153. { 0x0093, 0x0000 },
  154. { 0x0094, 0x0080 },
  155. { 0x0097, 0x0000 },
  156. { 0x0098, 0x0000 },
  157. { 0x0099, 0x0000 },
  158. { 0x009a, 0x0000 },
  159. { 0x009b, 0x0000 },
  160. { 0x009c, 0x007f },
  161. { 0x009d, 0x0000 },
  162. { 0x009e, 0x007f },
  163. { 0x009f, 0x0000 },
  164. { 0x00a0, 0x0060 },
  165. { 0x00a1, 0x90a1 },
  166. { 0x00ae, 0x2000 },
  167. { 0x00af, 0x0000 },
  168. { 0x00b0, 0x2000 },
  169. { 0x00b1, 0x0000 },
  170. { 0x00b2, 0x0000 },
  171. { 0x00b6, 0x0000 },
  172. { 0x00b7, 0x0000 },
  173. { 0x00b8, 0x0000 },
  174. { 0x00b9, 0x0000 },
  175. { 0x00ba, 0x0000 },
  176. { 0x00bb, 0x0000 },
  177. { 0x00be, 0x0000 },
  178. { 0x00bf, 0x0000 },
  179. { 0x00c0, 0x0000 },
  180. { 0x00c1, 0x0000 },
  181. { 0x00c2, 0x0000 },
  182. { 0x00c3, 0x0000 },
  183. { 0x00c4, 0x0003 },
  184. { 0x00c5, 0x0000 },
  185. { 0x00cb, 0xa02f },
  186. { 0x00cc, 0x0000 },
  187. { 0x00cd, 0x0e02 },
  188. { 0x00d6, 0x0000 },
  189. { 0x00d7, 0x2244 },
  190. { 0x00d9, 0x0809 },
  191. { 0x00da, 0x0000 },
  192. { 0x00db, 0x0008 },
  193. { 0x00dc, 0x00c0 },
  194. { 0x00dd, 0x6724 },
  195. { 0x00de, 0x3131 },
  196. { 0x00df, 0x0008 },
  197. { 0x00e0, 0x4000 },
  198. { 0x00e1, 0x3131 },
  199. { 0x00e4, 0x400c },
  200. { 0x00e5, 0x8031 },
  201. { 0x00ea, 0xb320 },
  202. { 0x00eb, 0x0000 },
  203. { 0x00ec, 0xb300 },
  204. { 0x00ed, 0x0000 },
  205. { 0x00f0, 0x0000 },
  206. { 0x00f1, 0x0202 },
  207. { 0x00f2, 0x0ddd },
  208. { 0x00f3, 0x0ddd },
  209. { 0x00f4, 0x0ddd },
  210. { 0x00f6, 0x0000 },
  211. { 0x00f7, 0x0000 },
  212. { 0x00f8, 0x0000 },
  213. { 0x00f9, 0x0000 },
  214. { 0x00fa, 0x8000 },
  215. { 0x00fb, 0x0000 },
  216. { 0x00fc, 0x0000 },
  217. { 0x00fd, 0x0001 },
  218. { 0x00fe, 0x10ec },
  219. { 0x00ff, 0x6311 },
  220. { 0x0100, 0xaaaa },
  221. { 0x010a, 0xaaaa },
  222. { 0x010b, 0x00a0 },
  223. { 0x010c, 0xaeae },
  224. { 0x010d, 0xaaaa },
  225. { 0x010e, 0xaaa8 },
  226. { 0x010f, 0xa0aa },
  227. { 0x0110, 0xe02a },
  228. { 0x0111, 0xa702 },
  229. { 0x0112, 0xaaaa },
  230. { 0x0113, 0x2800 },
  231. { 0x0116, 0x0000 },
  232. { 0x0117, 0x0f00 },
  233. { 0x011a, 0x0020 },
  234. { 0x011b, 0x0011 },
  235. { 0x011c, 0x0150 },
  236. { 0x011d, 0x0000 },
  237. { 0x011e, 0x0000 },
  238. { 0x011f, 0x0000 },
  239. { 0x0120, 0x0000 },
  240. { 0x0121, 0x009b },
  241. { 0x0122, 0x5014 },
  242. { 0x0123, 0x0421 },
  243. { 0x0124, 0x7cea },
  244. { 0x0125, 0x0420 },
  245. { 0x0126, 0x5550 },
  246. { 0x0132, 0x0000 },
  247. { 0x0133, 0x0000 },
  248. { 0x0137, 0x5055 },
  249. { 0x0138, 0x3700 },
  250. { 0x0139, 0x79a1 },
  251. { 0x013a, 0x2020 },
  252. { 0x013b, 0x2020 },
  253. { 0x013c, 0x2005 },
  254. { 0x013e, 0x1f00 },
  255. { 0x013f, 0x0000 },
  256. { 0x0145, 0x0002 },
  257. { 0x0146, 0x0000 },
  258. { 0x0147, 0x0000 },
  259. { 0x0148, 0x0000 },
  260. { 0x0150, 0x1813 },
  261. { 0x0151, 0x0690 },
  262. { 0x0152, 0x1c17 },
  263. { 0x0153, 0x6883 },
  264. { 0x0154, 0xd3ce },
  265. { 0x0155, 0x352d },
  266. { 0x0156, 0x00eb },
  267. { 0x0157, 0x3717 },
  268. { 0x0158, 0x4c6a },
  269. { 0x0159, 0xe41b },
  270. { 0x015a, 0x2a13 },
  271. { 0x015b, 0xb600 },
  272. { 0x015c, 0xc730 },
  273. { 0x015d, 0x35d4 },
  274. { 0x015e, 0x00bf },
  275. { 0x0160, 0x0ec0 },
  276. { 0x0161, 0x0020 },
  277. { 0x0162, 0x0080 },
  278. { 0x0163, 0x0800 },
  279. { 0x0164, 0x0000 },
  280. { 0x0165, 0x0000 },
  281. { 0x0166, 0x0000 },
  282. { 0x0167, 0x001f },
  283. { 0x0170, 0x4e80 },
  284. { 0x0171, 0x0020 },
  285. { 0x0172, 0x0080 },
  286. { 0x0173, 0x0800 },
  287. { 0x0174, 0x000c },
  288. { 0x0175, 0x0000 },
  289. { 0x0190, 0x3300 },
  290. { 0x0191, 0x2200 },
  291. { 0x0192, 0x0000 },
  292. { 0x01b0, 0x4b38 },
  293. { 0x01b1, 0x0000 },
  294. { 0x01b2, 0x0000 },
  295. { 0x01b3, 0x0000 },
  296. { 0x01c0, 0x0045 },
  297. { 0x01c1, 0x0540 },
  298. { 0x01c2, 0x0000 },
  299. { 0x01c3, 0x0030 },
  300. { 0x01c7, 0x0000 },
  301. { 0x01c8, 0x5757 },
  302. { 0x01c9, 0x5757 },
  303. { 0x01ca, 0x5757 },
  304. { 0x01cb, 0x5757 },
  305. { 0x01cc, 0x5757 },
  306. { 0x01cd, 0x5757 },
  307. { 0x01ce, 0x006f },
  308. { 0x01da, 0x0000 },
  309. { 0x01db, 0x0000 },
  310. { 0x01de, 0x7d00 },
  311. { 0x01df, 0x10c0 },
  312. { 0x01e0, 0x06a1 },
  313. { 0x01e1, 0x0000 },
  314. { 0x01e2, 0x0000 },
  315. { 0x01e3, 0x0000 },
  316. { 0x01e4, 0x0001 },
  317. { 0x01e6, 0x0000 },
  318. { 0x01e7, 0x0000 },
  319. { 0x01e8, 0x0000 },
  320. { 0x01ea, 0x0000 },
  321. { 0x01eb, 0x0000 },
  322. { 0x01ec, 0x0000 },
  323. { 0x01ed, 0x0000 },
  324. { 0x01ee, 0x0000 },
  325. { 0x01ef, 0x0000 },
  326. { 0x01f0, 0x0000 },
  327. { 0x01f1, 0x0000 },
  328. { 0x01f2, 0x0000 },
  329. { 0x01f6, 0x1e04 },
  330. { 0x01f7, 0x01a1 },
  331. { 0x01f8, 0x0000 },
  332. { 0x01f9, 0x0000 },
  333. { 0x01fa, 0x0002 },
  334. { 0x01fb, 0x0000 },
  335. { 0x01fc, 0x0000 },
  336. { 0x01fd, 0x0000 },
  337. { 0x01fe, 0x0000 },
  338. { 0x0200, 0x066c },
  339. { 0x0201, 0x7fff },
  340. { 0x0202, 0x7fff },
  341. { 0x0203, 0x0000 },
  342. { 0x0204, 0x0000 },
  343. { 0x0205, 0x0000 },
  344. { 0x0206, 0x0000 },
  345. { 0x0207, 0x0000 },
  346. { 0x0208, 0x0000 },
  347. { 0x0256, 0x0000 },
  348. { 0x0257, 0x0000 },
  349. { 0x0258, 0x0000 },
  350. { 0x0259, 0x0000 },
  351. { 0x025a, 0x0000 },
  352. { 0x025b, 0x3333 },
  353. { 0x025c, 0x3333 },
  354. { 0x025d, 0x3333 },
  355. { 0x025e, 0x0000 },
  356. { 0x025f, 0x0000 },
  357. { 0x0260, 0x0000 },
  358. { 0x0261, 0x0022 },
  359. { 0x0262, 0x0300 },
  360. { 0x0265, 0x1e80 },
  361. { 0x0266, 0x0131 },
  362. { 0x0267, 0x0003 },
  363. { 0x0268, 0x0000 },
  364. { 0x0269, 0x0000 },
  365. { 0x026a, 0x0000 },
  366. { 0x026b, 0x0000 },
  367. { 0x026c, 0x0000 },
  368. { 0x026d, 0x0000 },
  369. { 0x026e, 0x0000 },
  370. { 0x026f, 0x0000 },
  371. { 0x0270, 0x0000 },
  372. { 0x0271, 0x0000 },
  373. { 0x0272, 0x0000 },
  374. { 0x0273, 0x0000 },
  375. { 0x0280, 0x0000 },
  376. { 0x0281, 0x0000 },
  377. { 0x0282, 0x0418 },
  378. { 0x0283, 0x7fff },
  379. { 0x0284, 0x7000 },
  380. { 0x0290, 0x01d0 },
  381. { 0x0291, 0x0100 },
  382. { 0x02fa, 0x0000 },
  383. { 0x02fb, 0x0000 },
  384. { 0x02fc, 0x0000 },
  385. { 0x0300, 0x001f },
  386. { 0x0301, 0x032c },
  387. { 0x0302, 0x5f21 },
  388. { 0x0303, 0x4000 },
  389. { 0x0304, 0x4000 },
  390. { 0x0305, 0x0600 },
  391. { 0x0306, 0x8000 },
  392. { 0x0307, 0x0700 },
  393. { 0x0308, 0x001f },
  394. { 0x0309, 0x032c },
  395. { 0x030a, 0x5f21 },
  396. { 0x030b, 0x4000 },
  397. { 0x030c, 0x4000 },
  398. { 0x030d, 0x0600 },
  399. { 0x030e, 0x8000 },
  400. { 0x030f, 0x0700 },
  401. { 0x0310, 0x4560 },
  402. { 0x0311, 0xa4a8 },
  403. { 0x0312, 0x7418 },
  404. { 0x0313, 0x0000 },
  405. { 0x0314, 0x0006 },
  406. { 0x0315, 0x00ff },
  407. { 0x0316, 0xc400 },
  408. { 0x0317, 0x4560 },
  409. { 0x0318, 0xa4a8 },
  410. { 0x0319, 0x7418 },
  411. { 0x031a, 0x0000 },
  412. { 0x031b, 0x0006 },
  413. { 0x031c, 0x00ff },
  414. { 0x031d, 0xc400 },
  415. { 0x0320, 0x0f20 },
  416. { 0x0321, 0x8700 },
  417. { 0x0322, 0x7dc2 },
  418. { 0x0323, 0xa178 },
  419. { 0x0324, 0x5383 },
  420. { 0x0325, 0x7dc2 },
  421. { 0x0326, 0xa178 },
  422. { 0x0327, 0x5383 },
  423. { 0x0328, 0x003e },
  424. { 0x0329, 0x02c1 },
  425. { 0x032a, 0xd37d },
  426. { 0x0330, 0x00a6 },
  427. { 0x0331, 0x04c3 },
  428. { 0x0332, 0x27c8 },
  429. { 0x0333, 0xbf50 },
  430. { 0x0334, 0x0045 },
  431. { 0x0335, 0x2007 },
  432. { 0x0336, 0x7418 },
  433. { 0x0337, 0x0501 },
  434. { 0x0338, 0x0000 },
  435. { 0x0339, 0x0010 },
  436. { 0x033a, 0x1010 },
  437. { 0x0340, 0x0800 },
  438. { 0x0341, 0x0800 },
  439. { 0x0342, 0x0800 },
  440. { 0x0343, 0x0800 },
  441. { 0x0344, 0x0000 },
  442. { 0x0345, 0x0000 },
  443. { 0x0346, 0x0000 },
  444. { 0x0347, 0x0000 },
  445. { 0x0348, 0x0000 },
  446. { 0x0349, 0x0000 },
  447. { 0x034a, 0x0000 },
  448. { 0x034b, 0x0000 },
  449. { 0x034c, 0x0000 },
  450. { 0x034d, 0x0000 },
  451. { 0x034e, 0x0000 },
  452. { 0x034f, 0x0000 },
  453. { 0x0350, 0x0000 },
  454. { 0x0351, 0x0000 },
  455. { 0x0352, 0x0000 },
  456. { 0x0353, 0x0000 },
  457. { 0x0354, 0x0000 },
  458. { 0x0355, 0x0000 },
  459. { 0x0356, 0x0000 },
  460. { 0x0357, 0x0000 },
  461. { 0x0358, 0x0000 },
  462. { 0x0359, 0x0000 },
  463. { 0x035a, 0x0000 },
  464. { 0x035b, 0x0000 },
  465. { 0x035c, 0x0000 },
  466. { 0x035d, 0x0000 },
  467. { 0x035e, 0x2000 },
  468. { 0x035f, 0x0000 },
  469. { 0x0360, 0x2000 },
  470. { 0x0361, 0x2000 },
  471. { 0x0362, 0x0000 },
  472. { 0x0363, 0x2000 },
  473. { 0x0364, 0x0200 },
  474. { 0x0365, 0x0000 },
  475. { 0x0366, 0x0000 },
  476. { 0x0367, 0x0000 },
  477. { 0x0368, 0x0000 },
  478. { 0x0369, 0x0000 },
  479. { 0x036a, 0x0000 },
  480. { 0x036b, 0x0000 },
  481. { 0x036c, 0x0000 },
  482. { 0x036d, 0x0000 },
  483. { 0x036e, 0x0200 },
  484. { 0x036f, 0x0000 },
  485. { 0x0370, 0x0000 },
  486. { 0x0371, 0x0000 },
  487. { 0x0372, 0x0000 },
  488. { 0x0373, 0x0000 },
  489. { 0x0374, 0x0000 },
  490. { 0x0375, 0x0000 },
  491. { 0x0376, 0x0000 },
  492. { 0x0377, 0x0000 },
  493. { 0x03d0, 0x0000 },
  494. { 0x03d1, 0x0000 },
  495. { 0x03d2, 0x0000 },
  496. { 0x03d3, 0x0000 },
  497. { 0x03d4, 0x2000 },
  498. { 0x03d5, 0x2000 },
  499. { 0x03d6, 0x0000 },
  500. { 0x03d7, 0x0000 },
  501. { 0x03d8, 0x2000 },
  502. { 0x03d9, 0x2000 },
  503. { 0x03da, 0x2000 },
  504. { 0x03db, 0x2000 },
  505. { 0x03dc, 0x0000 },
  506. { 0x03dd, 0x0000 },
  507. { 0x03de, 0x0000 },
  508. { 0x03df, 0x2000 },
  509. { 0x03e0, 0x0000 },
  510. { 0x03e1, 0x0000 },
  511. { 0x03e2, 0x0000 },
  512. { 0x03e3, 0x0000 },
  513. { 0x03e4, 0x0000 },
  514. { 0x03e5, 0x0000 },
  515. { 0x03e6, 0x0000 },
  516. { 0x03e7, 0x0000 },
  517. { 0x03e8, 0x0000 },
  518. { 0x03e9, 0x0000 },
  519. { 0x03ea, 0x0000 },
  520. { 0x03eb, 0x0000 },
  521. { 0x03ec, 0x0000 },
  522. { 0x03ed, 0x0000 },
  523. { 0x03ee, 0x0000 },
  524. { 0x03ef, 0x0000 },
  525. { 0x03f0, 0x0800 },
  526. { 0x03f1, 0x0800 },
  527. { 0x03f2, 0x0800 },
  528. { 0x03f3, 0x0800 },
  529. };
  530. static bool rt5659_volatile_register(struct device *dev, unsigned int reg)
  531. {
  532. switch (reg) {
  533. case RT5659_RESET:
  534. case RT5659_EJD_CTRL_2:
  535. case RT5659_SILENCE_CTRL:
  536. case RT5659_DAC2_DIG_VOL:
  537. case RT5659_HP_IMP_GAIN_2:
  538. case RT5659_PDM_OUT_CTRL:
  539. case RT5659_PDM_DATA_CTRL_1:
  540. case RT5659_PDM_DATA_CTRL_4:
  541. case RT5659_HAPTIC_GEN_CTRL_1:
  542. case RT5659_HAPTIC_GEN_CTRL_3:
  543. case RT5659_HAPTIC_LPF_CTRL_3:
  544. case RT5659_CLK_DET:
  545. case RT5659_MICBIAS_1:
  546. case RT5659_ASRC_11:
  547. case RT5659_ADC_EQ_CTRL_1:
  548. case RT5659_DAC_EQ_CTRL_1:
  549. case RT5659_INT_ST_1:
  550. case RT5659_INT_ST_2:
  551. case RT5659_GPIO_STA:
  552. case RT5659_SINE_GEN_CTRL_1:
  553. case RT5659_IL_CMD_1:
  554. case RT5659_4BTN_IL_CMD_1:
  555. case RT5659_PSV_IL_CMD_1:
  556. case RT5659_AJD1_CTRL:
  557. case RT5659_AJD2_AJD3_CTRL:
  558. case RT5659_JD_CTRL_3:
  559. case RT5659_VENDOR_ID:
  560. case RT5659_VENDOR_ID_1:
  561. case RT5659_DEVICE_ID:
  562. case RT5659_MEMORY_TEST:
  563. case RT5659_SOFT_RAMP_DEPOP_DAC_CLK_CTRL:
  564. case RT5659_VOL_TEST:
  565. case RT5659_STO_NG2_CTRL_1:
  566. case RT5659_STO_NG2_CTRL_5:
  567. case RT5659_STO_NG2_CTRL_6:
  568. case RT5659_STO_NG2_CTRL_7:
  569. case RT5659_MONO_NG2_CTRL_1:
  570. case RT5659_MONO_NG2_CTRL_5:
  571. case RT5659_MONO_NG2_CTRL_6:
  572. case RT5659_HP_IMP_SENS_CTRL_1:
  573. case RT5659_HP_IMP_SENS_CTRL_3:
  574. case RT5659_HP_IMP_SENS_CTRL_4:
  575. case RT5659_HP_CALIB_CTRL_1:
  576. case RT5659_HP_CALIB_CTRL_9:
  577. case RT5659_HP_CALIB_STA_1:
  578. case RT5659_HP_CALIB_STA_2:
  579. case RT5659_HP_CALIB_STA_3:
  580. case RT5659_HP_CALIB_STA_4:
  581. case RT5659_HP_CALIB_STA_5:
  582. case RT5659_HP_CALIB_STA_6:
  583. case RT5659_HP_CALIB_STA_7:
  584. case RT5659_HP_CALIB_STA_8:
  585. case RT5659_HP_CALIB_STA_9:
  586. case RT5659_MONO_AMP_CALIB_CTRL_1:
  587. case RT5659_MONO_AMP_CALIB_CTRL_3:
  588. case RT5659_MONO_AMP_CALIB_STA_1:
  589. case RT5659_MONO_AMP_CALIB_STA_2:
  590. case RT5659_MONO_AMP_CALIB_STA_3:
  591. case RT5659_MONO_AMP_CALIB_STA_4:
  592. case RT5659_SPK_PWR_LMT_STA_1:
  593. case RT5659_SPK_PWR_LMT_STA_2:
  594. case RT5659_SPK_PWR_LMT_STA_3:
  595. case RT5659_SPK_PWR_LMT_STA_4:
  596. case RT5659_SPK_PWR_LMT_STA_5:
  597. case RT5659_SPK_PWR_LMT_STA_6:
  598. case RT5659_SPK_DC_CAILB_CTRL_1:
  599. case RT5659_SPK_DC_CAILB_STA_1:
  600. case RT5659_SPK_DC_CAILB_STA_2:
  601. case RT5659_SPK_DC_CAILB_STA_3:
  602. case RT5659_SPK_DC_CAILB_STA_4:
  603. case RT5659_SPK_DC_CAILB_STA_5:
  604. case RT5659_SPK_DC_CAILB_STA_6:
  605. case RT5659_SPK_DC_CAILB_STA_7:
  606. case RT5659_SPK_DC_CAILB_STA_8:
  607. case RT5659_SPK_DC_CAILB_STA_9:
  608. case RT5659_SPK_DC_CAILB_STA_10:
  609. case RT5659_SPK_VDD_STA_1:
  610. case RT5659_SPK_VDD_STA_2:
  611. case RT5659_SPK_DC_DET_CTRL_1:
  612. case RT5659_PURE_DC_DET_CTRL_1:
  613. case RT5659_PURE_DC_DET_CTRL_2:
  614. case RT5659_DRC1_PRIV_1:
  615. case RT5659_DRC1_PRIV_4:
  616. case RT5659_DRC1_PRIV_5:
  617. case RT5659_DRC1_PRIV_6:
  618. case RT5659_DRC1_PRIV_7:
  619. case RT5659_DRC2_PRIV_1:
  620. case RT5659_DRC2_PRIV_4:
  621. case RT5659_DRC2_PRIV_5:
  622. case RT5659_DRC2_PRIV_6:
  623. case RT5659_DRC2_PRIV_7:
  624. case RT5659_ALC_PGA_STA_1:
  625. case RT5659_ALC_PGA_STA_2:
  626. case RT5659_ALC_PGA_STA_3:
  627. return true;
  628. default:
  629. return false;
  630. }
  631. }
  632. static bool rt5659_readable_register(struct device *dev, unsigned int reg)
  633. {
  634. switch (reg) {
  635. case RT5659_RESET:
  636. case RT5659_SPO_VOL:
  637. case RT5659_HP_VOL:
  638. case RT5659_LOUT:
  639. case RT5659_MONO_OUT:
  640. case RT5659_HPL_GAIN:
  641. case RT5659_HPR_GAIN:
  642. case RT5659_MONO_GAIN:
  643. case RT5659_SPDIF_CTRL_1:
  644. case RT5659_SPDIF_CTRL_2:
  645. case RT5659_CAL_BST_CTRL:
  646. case RT5659_IN1_IN2:
  647. case RT5659_IN3_IN4:
  648. case RT5659_INL1_INR1_VOL:
  649. case RT5659_EJD_CTRL_1:
  650. case RT5659_EJD_CTRL_2:
  651. case RT5659_EJD_CTRL_3:
  652. case RT5659_SILENCE_CTRL:
  653. case RT5659_PSV_CTRL:
  654. case RT5659_SIDETONE_CTRL:
  655. case RT5659_DAC1_DIG_VOL:
  656. case RT5659_DAC2_DIG_VOL:
  657. case RT5659_DAC_CTRL:
  658. case RT5659_STO1_ADC_DIG_VOL:
  659. case RT5659_MONO_ADC_DIG_VOL:
  660. case RT5659_STO2_ADC_DIG_VOL:
  661. case RT5659_STO1_BOOST:
  662. case RT5659_MONO_BOOST:
  663. case RT5659_STO2_BOOST:
  664. case RT5659_HP_IMP_GAIN_1:
  665. case RT5659_HP_IMP_GAIN_2:
  666. case RT5659_STO1_ADC_MIXER:
  667. case RT5659_MONO_ADC_MIXER:
  668. case RT5659_AD_DA_MIXER:
  669. case RT5659_STO_DAC_MIXER:
  670. case RT5659_MONO_DAC_MIXER:
  671. case RT5659_DIG_MIXER:
  672. case RT5659_A_DAC_MUX:
  673. case RT5659_DIG_INF23_DATA:
  674. case RT5659_PDM_OUT_CTRL:
  675. case RT5659_PDM_DATA_CTRL_1:
  676. case RT5659_PDM_DATA_CTRL_2:
  677. case RT5659_PDM_DATA_CTRL_3:
  678. case RT5659_PDM_DATA_CTRL_4:
  679. case RT5659_SPDIF_CTRL:
  680. case RT5659_REC1_GAIN:
  681. case RT5659_REC1_L1_MIXER:
  682. case RT5659_REC1_L2_MIXER:
  683. case RT5659_REC1_R1_MIXER:
  684. case RT5659_REC1_R2_MIXER:
  685. case RT5659_CAL_REC:
  686. case RT5659_REC2_L1_MIXER:
  687. case RT5659_REC2_L2_MIXER:
  688. case RT5659_REC2_R1_MIXER:
  689. case RT5659_REC2_R2_MIXER:
  690. case RT5659_SPK_L_MIXER:
  691. case RT5659_SPK_R_MIXER:
  692. case RT5659_SPO_AMP_GAIN:
  693. case RT5659_ALC_BACK_GAIN:
  694. case RT5659_MONOMIX_GAIN:
  695. case RT5659_MONOMIX_IN_GAIN:
  696. case RT5659_OUT_L_GAIN:
  697. case RT5659_OUT_L_MIXER:
  698. case RT5659_OUT_R_GAIN:
  699. case RT5659_OUT_R_MIXER:
  700. case RT5659_LOUT_MIXER:
  701. case RT5659_HAPTIC_GEN_CTRL_1:
  702. case RT5659_HAPTIC_GEN_CTRL_2:
  703. case RT5659_HAPTIC_GEN_CTRL_3:
  704. case RT5659_HAPTIC_GEN_CTRL_4:
  705. case RT5659_HAPTIC_GEN_CTRL_5:
  706. case RT5659_HAPTIC_GEN_CTRL_6:
  707. case RT5659_HAPTIC_GEN_CTRL_7:
  708. case RT5659_HAPTIC_GEN_CTRL_8:
  709. case RT5659_HAPTIC_GEN_CTRL_9:
  710. case RT5659_HAPTIC_GEN_CTRL_10:
  711. case RT5659_HAPTIC_GEN_CTRL_11:
  712. case RT5659_HAPTIC_LPF_CTRL_1:
  713. case RT5659_HAPTIC_LPF_CTRL_2:
  714. case RT5659_HAPTIC_LPF_CTRL_3:
  715. case RT5659_PWR_DIG_1:
  716. case RT5659_PWR_DIG_2:
  717. case RT5659_PWR_ANLG_1:
  718. case RT5659_PWR_ANLG_2:
  719. case RT5659_PWR_ANLG_3:
  720. case RT5659_PWR_MIXER:
  721. case RT5659_PWR_VOL:
  722. case RT5659_PRIV_INDEX:
  723. case RT5659_CLK_DET:
  724. case RT5659_PRIV_DATA:
  725. case RT5659_PRE_DIV_1:
  726. case RT5659_PRE_DIV_2:
  727. case RT5659_I2S1_SDP:
  728. case RT5659_I2S2_SDP:
  729. case RT5659_I2S3_SDP:
  730. case RT5659_ADDA_CLK_1:
  731. case RT5659_ADDA_CLK_2:
  732. case RT5659_DMIC_CTRL_1:
  733. case RT5659_DMIC_CTRL_2:
  734. case RT5659_TDM_CTRL_1:
  735. case RT5659_TDM_CTRL_2:
  736. case RT5659_TDM_CTRL_3:
  737. case RT5659_TDM_CTRL_4:
  738. case RT5659_TDM_CTRL_5:
  739. case RT5659_GLB_CLK:
  740. case RT5659_PLL_CTRL_1:
  741. case RT5659_PLL_CTRL_2:
  742. case RT5659_ASRC_1:
  743. case RT5659_ASRC_2:
  744. case RT5659_ASRC_3:
  745. case RT5659_ASRC_4:
  746. case RT5659_ASRC_5:
  747. case RT5659_ASRC_6:
  748. case RT5659_ASRC_7:
  749. case RT5659_ASRC_8:
  750. case RT5659_ASRC_9:
  751. case RT5659_ASRC_10:
  752. case RT5659_DEPOP_1:
  753. case RT5659_DEPOP_2:
  754. case RT5659_DEPOP_3:
  755. case RT5659_HP_CHARGE_PUMP_1:
  756. case RT5659_HP_CHARGE_PUMP_2:
  757. case RT5659_MICBIAS_1:
  758. case RT5659_MICBIAS_2:
  759. case RT5659_ASRC_11:
  760. case RT5659_ASRC_12:
  761. case RT5659_ASRC_13:
  762. case RT5659_REC_M1_M2_GAIN_CTRL:
  763. case RT5659_RC_CLK_CTRL:
  764. case RT5659_CLASSD_CTRL_1:
  765. case RT5659_CLASSD_CTRL_2:
  766. case RT5659_ADC_EQ_CTRL_1:
  767. case RT5659_ADC_EQ_CTRL_2:
  768. case RT5659_DAC_EQ_CTRL_1:
  769. case RT5659_DAC_EQ_CTRL_2:
  770. case RT5659_DAC_EQ_CTRL_3:
  771. case RT5659_IRQ_CTRL_1:
  772. case RT5659_IRQ_CTRL_2:
  773. case RT5659_IRQ_CTRL_3:
  774. case RT5659_IRQ_CTRL_4:
  775. case RT5659_IRQ_CTRL_5:
  776. case RT5659_IRQ_CTRL_6:
  777. case RT5659_INT_ST_1:
  778. case RT5659_INT_ST_2:
  779. case RT5659_GPIO_CTRL_1:
  780. case RT5659_GPIO_CTRL_2:
  781. case RT5659_GPIO_CTRL_3:
  782. case RT5659_GPIO_CTRL_4:
  783. case RT5659_GPIO_CTRL_5:
  784. case RT5659_GPIO_STA:
  785. case RT5659_SINE_GEN_CTRL_1:
  786. case RT5659_SINE_GEN_CTRL_2:
  787. case RT5659_SINE_GEN_CTRL_3:
  788. case RT5659_HP_AMP_DET_CTRL_1:
  789. case RT5659_HP_AMP_DET_CTRL_2:
  790. case RT5659_SV_ZCD_1:
  791. case RT5659_SV_ZCD_2:
  792. case RT5659_IL_CMD_1:
  793. case RT5659_IL_CMD_2:
  794. case RT5659_IL_CMD_3:
  795. case RT5659_IL_CMD_4:
  796. case RT5659_4BTN_IL_CMD_1:
  797. case RT5659_4BTN_IL_CMD_2:
  798. case RT5659_4BTN_IL_CMD_3:
  799. case RT5659_PSV_IL_CMD_1:
  800. case RT5659_PSV_IL_CMD_2:
  801. case RT5659_ADC_STO1_HP_CTRL_1:
  802. case RT5659_ADC_STO1_HP_CTRL_2:
  803. case RT5659_ADC_MONO_HP_CTRL_1:
  804. case RT5659_ADC_MONO_HP_CTRL_2:
  805. case RT5659_AJD1_CTRL:
  806. case RT5659_AJD2_AJD3_CTRL:
  807. case RT5659_JD1_THD:
  808. case RT5659_JD2_THD:
  809. case RT5659_JD3_THD:
  810. case RT5659_JD_CTRL_1:
  811. case RT5659_JD_CTRL_2:
  812. case RT5659_JD_CTRL_3:
  813. case RT5659_JD_CTRL_4:
  814. case RT5659_DIG_MISC:
  815. case RT5659_DUMMY_2:
  816. case RT5659_DUMMY_3:
  817. case RT5659_VENDOR_ID:
  818. case RT5659_VENDOR_ID_1:
  819. case RT5659_DEVICE_ID:
  820. case RT5659_DAC_ADC_DIG_VOL:
  821. case RT5659_BIAS_CUR_CTRL_1:
  822. case RT5659_BIAS_CUR_CTRL_2:
  823. case RT5659_BIAS_CUR_CTRL_3:
  824. case RT5659_BIAS_CUR_CTRL_4:
  825. case RT5659_BIAS_CUR_CTRL_5:
  826. case RT5659_BIAS_CUR_CTRL_6:
  827. case RT5659_BIAS_CUR_CTRL_7:
  828. case RT5659_BIAS_CUR_CTRL_8:
  829. case RT5659_BIAS_CUR_CTRL_9:
  830. case RT5659_BIAS_CUR_CTRL_10:
  831. case RT5659_MEMORY_TEST:
  832. case RT5659_VREF_REC_OP_FB_CAP_CTRL:
  833. case RT5659_CLASSD_0:
  834. case RT5659_CLASSD_1:
  835. case RT5659_CLASSD_2:
  836. case RT5659_CLASSD_3:
  837. case RT5659_CLASSD_4:
  838. case RT5659_CLASSD_5:
  839. case RT5659_CLASSD_6:
  840. case RT5659_CLASSD_7:
  841. case RT5659_CLASSD_8:
  842. case RT5659_CLASSD_9:
  843. case RT5659_CLASSD_10:
  844. case RT5659_CHARGE_PUMP_1:
  845. case RT5659_CHARGE_PUMP_2:
  846. case RT5659_DIG_IN_CTRL_1:
  847. case RT5659_DIG_IN_CTRL_2:
  848. case RT5659_PAD_DRIVING_CTRL:
  849. case RT5659_SOFT_RAMP_DEPOP:
  850. case RT5659_PLL:
  851. case RT5659_CHOP_DAC:
  852. case RT5659_CHOP_ADC:
  853. case RT5659_CALIB_ADC_CTRL:
  854. case RT5659_SOFT_RAMP_DEPOP_DAC_CLK_CTRL:
  855. case RT5659_VOL_TEST:
  856. case RT5659_TEST_MODE_CTRL_1:
  857. case RT5659_TEST_MODE_CTRL_2:
  858. case RT5659_TEST_MODE_CTRL_3:
  859. case RT5659_TEST_MODE_CTRL_4:
  860. case RT5659_BASSBACK_CTRL:
  861. case RT5659_MP3_PLUS_CTRL_1:
  862. case RT5659_MP3_PLUS_CTRL_2:
  863. case RT5659_MP3_HPF_A1:
  864. case RT5659_MP3_HPF_A2:
  865. case RT5659_MP3_HPF_H0:
  866. case RT5659_MP3_LPF_H0:
  867. case RT5659_3D_SPK_CTRL:
  868. case RT5659_3D_SPK_COEF_1:
  869. case RT5659_3D_SPK_COEF_2:
  870. case RT5659_3D_SPK_COEF_3:
  871. case RT5659_3D_SPK_COEF_4:
  872. case RT5659_3D_SPK_COEF_5:
  873. case RT5659_3D_SPK_COEF_6:
  874. case RT5659_3D_SPK_COEF_7:
  875. case RT5659_STO_NG2_CTRL_1:
  876. case RT5659_STO_NG2_CTRL_2:
  877. case RT5659_STO_NG2_CTRL_3:
  878. case RT5659_STO_NG2_CTRL_4:
  879. case RT5659_STO_NG2_CTRL_5:
  880. case RT5659_STO_NG2_CTRL_6:
  881. case RT5659_STO_NG2_CTRL_7:
  882. case RT5659_STO_NG2_CTRL_8:
  883. case RT5659_MONO_NG2_CTRL_1:
  884. case RT5659_MONO_NG2_CTRL_2:
  885. case RT5659_MONO_NG2_CTRL_3:
  886. case RT5659_MONO_NG2_CTRL_4:
  887. case RT5659_MONO_NG2_CTRL_5:
  888. case RT5659_MONO_NG2_CTRL_6:
  889. case RT5659_MID_HP_AMP_DET:
  890. case RT5659_LOW_HP_AMP_DET:
  891. case RT5659_LDO_CTRL:
  892. case RT5659_HP_DECROSS_CTRL_1:
  893. case RT5659_HP_DECROSS_CTRL_2:
  894. case RT5659_HP_DECROSS_CTRL_3:
  895. case RT5659_HP_DECROSS_CTRL_4:
  896. case RT5659_HP_IMP_SENS_CTRL_1:
  897. case RT5659_HP_IMP_SENS_CTRL_2:
  898. case RT5659_HP_IMP_SENS_CTRL_3:
  899. case RT5659_HP_IMP_SENS_CTRL_4:
  900. case RT5659_HP_IMP_SENS_MAP_1:
  901. case RT5659_HP_IMP_SENS_MAP_2:
  902. case RT5659_HP_IMP_SENS_MAP_3:
  903. case RT5659_HP_IMP_SENS_MAP_4:
  904. case RT5659_HP_IMP_SENS_MAP_5:
  905. case RT5659_HP_IMP_SENS_MAP_6:
  906. case RT5659_HP_IMP_SENS_MAP_7:
  907. case RT5659_HP_IMP_SENS_MAP_8:
  908. case RT5659_HP_LOGIC_CTRL_1:
  909. case RT5659_HP_LOGIC_CTRL_2:
  910. case RT5659_HP_CALIB_CTRL_1:
  911. case RT5659_HP_CALIB_CTRL_2:
  912. case RT5659_HP_CALIB_CTRL_3:
  913. case RT5659_HP_CALIB_CTRL_4:
  914. case RT5659_HP_CALIB_CTRL_5:
  915. case RT5659_HP_CALIB_CTRL_6:
  916. case RT5659_HP_CALIB_CTRL_7:
  917. case RT5659_HP_CALIB_CTRL_9:
  918. case RT5659_HP_CALIB_CTRL_10:
  919. case RT5659_HP_CALIB_CTRL_11:
  920. case RT5659_HP_CALIB_STA_1:
  921. case RT5659_HP_CALIB_STA_2:
  922. case RT5659_HP_CALIB_STA_3:
  923. case RT5659_HP_CALIB_STA_4:
  924. case RT5659_HP_CALIB_STA_5:
  925. case RT5659_HP_CALIB_STA_6:
  926. case RT5659_HP_CALIB_STA_7:
  927. case RT5659_HP_CALIB_STA_8:
  928. case RT5659_HP_CALIB_STA_9:
  929. case RT5659_MONO_AMP_CALIB_CTRL_1:
  930. case RT5659_MONO_AMP_CALIB_CTRL_2:
  931. case RT5659_MONO_AMP_CALIB_CTRL_3:
  932. case RT5659_MONO_AMP_CALIB_CTRL_4:
  933. case RT5659_MONO_AMP_CALIB_CTRL_5:
  934. case RT5659_MONO_AMP_CALIB_STA_1:
  935. case RT5659_MONO_AMP_CALIB_STA_2:
  936. case RT5659_MONO_AMP_CALIB_STA_3:
  937. case RT5659_MONO_AMP_CALIB_STA_4:
  938. case RT5659_SPK_PWR_LMT_CTRL_1:
  939. case RT5659_SPK_PWR_LMT_CTRL_2:
  940. case RT5659_SPK_PWR_LMT_CTRL_3:
  941. case RT5659_SPK_PWR_LMT_STA_1:
  942. case RT5659_SPK_PWR_LMT_STA_2:
  943. case RT5659_SPK_PWR_LMT_STA_3:
  944. case RT5659_SPK_PWR_LMT_STA_4:
  945. case RT5659_SPK_PWR_LMT_STA_5:
  946. case RT5659_SPK_PWR_LMT_STA_6:
  947. case RT5659_FLEX_SPK_BST_CTRL_1:
  948. case RT5659_FLEX_SPK_BST_CTRL_2:
  949. case RT5659_FLEX_SPK_BST_CTRL_3:
  950. case RT5659_FLEX_SPK_BST_CTRL_4:
  951. case RT5659_SPK_EX_LMT_CTRL_1:
  952. case RT5659_SPK_EX_LMT_CTRL_2:
  953. case RT5659_SPK_EX_LMT_CTRL_3:
  954. case RT5659_SPK_EX_LMT_CTRL_4:
  955. case RT5659_SPK_EX_LMT_CTRL_5:
  956. case RT5659_SPK_EX_LMT_CTRL_6:
  957. case RT5659_SPK_EX_LMT_CTRL_7:
  958. case RT5659_ADJ_HPF_CTRL_1:
  959. case RT5659_ADJ_HPF_CTRL_2:
  960. case RT5659_SPK_DC_CAILB_CTRL_1:
  961. case RT5659_SPK_DC_CAILB_CTRL_2:
  962. case RT5659_SPK_DC_CAILB_CTRL_3:
  963. case RT5659_SPK_DC_CAILB_CTRL_4:
  964. case RT5659_SPK_DC_CAILB_CTRL_5:
  965. case RT5659_SPK_DC_CAILB_STA_1:
  966. case RT5659_SPK_DC_CAILB_STA_2:
  967. case RT5659_SPK_DC_CAILB_STA_3:
  968. case RT5659_SPK_DC_CAILB_STA_4:
  969. case RT5659_SPK_DC_CAILB_STA_5:
  970. case RT5659_SPK_DC_CAILB_STA_6:
  971. case RT5659_SPK_DC_CAILB_STA_7:
  972. case RT5659_SPK_DC_CAILB_STA_8:
  973. case RT5659_SPK_DC_CAILB_STA_9:
  974. case RT5659_SPK_DC_CAILB_STA_10:
  975. case RT5659_SPK_VDD_STA_1:
  976. case RT5659_SPK_VDD_STA_2:
  977. case RT5659_SPK_DC_DET_CTRL_1:
  978. case RT5659_SPK_DC_DET_CTRL_2:
  979. case RT5659_SPK_DC_DET_CTRL_3:
  980. case RT5659_PURE_DC_DET_CTRL_1:
  981. case RT5659_PURE_DC_DET_CTRL_2:
  982. case RT5659_DUMMY_4:
  983. case RT5659_DUMMY_5:
  984. case RT5659_DUMMY_6:
  985. case RT5659_DRC1_CTRL_1:
  986. case RT5659_DRC1_CTRL_2:
  987. case RT5659_DRC1_CTRL_3:
  988. case RT5659_DRC1_CTRL_4:
  989. case RT5659_DRC1_CTRL_5:
  990. case RT5659_DRC1_CTRL_6:
  991. case RT5659_DRC1_HARD_LMT_CTRL_1:
  992. case RT5659_DRC1_HARD_LMT_CTRL_2:
  993. case RT5659_DRC2_CTRL_1:
  994. case RT5659_DRC2_CTRL_2:
  995. case RT5659_DRC2_CTRL_3:
  996. case RT5659_DRC2_CTRL_4:
  997. case RT5659_DRC2_CTRL_5:
  998. case RT5659_DRC2_CTRL_6:
  999. case RT5659_DRC2_HARD_LMT_CTRL_1:
  1000. case RT5659_DRC2_HARD_LMT_CTRL_2:
  1001. case RT5659_DRC1_PRIV_1:
  1002. case RT5659_DRC1_PRIV_2:
  1003. case RT5659_DRC1_PRIV_3:
  1004. case RT5659_DRC1_PRIV_4:
  1005. case RT5659_DRC1_PRIV_5:
  1006. case RT5659_DRC1_PRIV_6:
  1007. case RT5659_DRC1_PRIV_7:
  1008. case RT5659_DRC2_PRIV_1:
  1009. case RT5659_DRC2_PRIV_2:
  1010. case RT5659_DRC2_PRIV_3:
  1011. case RT5659_DRC2_PRIV_4:
  1012. case RT5659_DRC2_PRIV_5:
  1013. case RT5659_DRC2_PRIV_6:
  1014. case RT5659_DRC2_PRIV_7:
  1015. case RT5659_MULTI_DRC_CTRL:
  1016. case RT5659_CROSS_OVER_1:
  1017. case RT5659_CROSS_OVER_2:
  1018. case RT5659_CROSS_OVER_3:
  1019. case RT5659_CROSS_OVER_4:
  1020. case RT5659_CROSS_OVER_5:
  1021. case RT5659_CROSS_OVER_6:
  1022. case RT5659_CROSS_OVER_7:
  1023. case RT5659_CROSS_OVER_8:
  1024. case RT5659_CROSS_OVER_9:
  1025. case RT5659_CROSS_OVER_10:
  1026. case RT5659_ALC_PGA_CTRL_1:
  1027. case RT5659_ALC_PGA_CTRL_2:
  1028. case RT5659_ALC_PGA_CTRL_3:
  1029. case RT5659_ALC_PGA_CTRL_4:
  1030. case RT5659_ALC_PGA_CTRL_5:
  1031. case RT5659_ALC_PGA_CTRL_6:
  1032. case RT5659_ALC_PGA_CTRL_7:
  1033. case RT5659_ALC_PGA_CTRL_8:
  1034. case RT5659_ALC_PGA_STA_1:
  1035. case RT5659_ALC_PGA_STA_2:
  1036. case RT5659_ALC_PGA_STA_3:
  1037. case RT5659_DAC_L_EQ_PRE_VOL:
  1038. case RT5659_DAC_R_EQ_PRE_VOL:
  1039. case RT5659_DAC_L_EQ_POST_VOL:
  1040. case RT5659_DAC_R_EQ_POST_VOL:
  1041. case RT5659_DAC_L_EQ_LPF1_A1:
  1042. case RT5659_DAC_L_EQ_LPF1_H0:
  1043. case RT5659_DAC_R_EQ_LPF1_A1:
  1044. case RT5659_DAC_R_EQ_LPF1_H0:
  1045. case RT5659_DAC_L_EQ_BPF2_A1:
  1046. case RT5659_DAC_L_EQ_BPF2_A2:
  1047. case RT5659_DAC_L_EQ_BPF2_H0:
  1048. case RT5659_DAC_R_EQ_BPF2_A1:
  1049. case RT5659_DAC_R_EQ_BPF2_A2:
  1050. case RT5659_DAC_R_EQ_BPF2_H0:
  1051. case RT5659_DAC_L_EQ_BPF3_A1:
  1052. case RT5659_DAC_L_EQ_BPF3_A2:
  1053. case RT5659_DAC_L_EQ_BPF3_H0:
  1054. case RT5659_DAC_R_EQ_BPF3_A1:
  1055. case RT5659_DAC_R_EQ_BPF3_A2:
  1056. case RT5659_DAC_R_EQ_BPF3_H0:
  1057. case RT5659_DAC_L_EQ_BPF4_A1:
  1058. case RT5659_DAC_L_EQ_BPF4_A2:
  1059. case RT5659_DAC_L_EQ_BPF4_H0:
  1060. case RT5659_DAC_R_EQ_BPF4_A1:
  1061. case RT5659_DAC_R_EQ_BPF4_A2:
  1062. case RT5659_DAC_R_EQ_BPF4_H0:
  1063. case RT5659_DAC_L_EQ_HPF1_A1:
  1064. case RT5659_DAC_L_EQ_HPF1_H0:
  1065. case RT5659_DAC_R_EQ_HPF1_A1:
  1066. case RT5659_DAC_R_EQ_HPF1_H0:
  1067. case RT5659_DAC_L_EQ_HPF2_A1:
  1068. case RT5659_DAC_L_EQ_HPF2_A2:
  1069. case RT5659_DAC_L_EQ_HPF2_H0:
  1070. case RT5659_DAC_R_EQ_HPF2_A1:
  1071. case RT5659_DAC_R_EQ_HPF2_A2:
  1072. case RT5659_DAC_R_EQ_HPF2_H0:
  1073. case RT5659_DAC_L_BI_EQ_BPF1_H0_1:
  1074. case RT5659_DAC_L_BI_EQ_BPF1_H0_2:
  1075. case RT5659_DAC_L_BI_EQ_BPF1_B1_1:
  1076. case RT5659_DAC_L_BI_EQ_BPF1_B1_2:
  1077. case RT5659_DAC_L_BI_EQ_BPF1_B2_1:
  1078. case RT5659_DAC_L_BI_EQ_BPF1_B2_2:
  1079. case RT5659_DAC_L_BI_EQ_BPF1_A1_1:
  1080. case RT5659_DAC_L_BI_EQ_BPF1_A1_2:
  1081. case RT5659_DAC_L_BI_EQ_BPF1_A2_1:
  1082. case RT5659_DAC_L_BI_EQ_BPF1_A2_2:
  1083. case RT5659_DAC_R_BI_EQ_BPF1_H0_1:
  1084. case RT5659_DAC_R_BI_EQ_BPF1_H0_2:
  1085. case RT5659_DAC_R_BI_EQ_BPF1_B1_1:
  1086. case RT5659_DAC_R_BI_EQ_BPF1_B1_2:
  1087. case RT5659_DAC_R_BI_EQ_BPF1_B2_1:
  1088. case RT5659_DAC_R_BI_EQ_BPF1_B2_2:
  1089. case RT5659_DAC_R_BI_EQ_BPF1_A1_1:
  1090. case RT5659_DAC_R_BI_EQ_BPF1_A1_2:
  1091. case RT5659_DAC_R_BI_EQ_BPF1_A2_1:
  1092. case RT5659_DAC_R_BI_EQ_BPF1_A2_2:
  1093. case RT5659_ADC_L_EQ_LPF1_A1:
  1094. case RT5659_ADC_R_EQ_LPF1_A1:
  1095. case RT5659_ADC_L_EQ_LPF1_H0:
  1096. case RT5659_ADC_R_EQ_LPF1_H0:
  1097. case RT5659_ADC_L_EQ_BPF1_A1:
  1098. case RT5659_ADC_R_EQ_BPF1_A1:
  1099. case RT5659_ADC_L_EQ_BPF1_A2:
  1100. case RT5659_ADC_R_EQ_BPF1_A2:
  1101. case RT5659_ADC_L_EQ_BPF1_H0:
  1102. case RT5659_ADC_R_EQ_BPF1_H0:
  1103. case RT5659_ADC_L_EQ_BPF2_A1:
  1104. case RT5659_ADC_R_EQ_BPF2_A1:
  1105. case RT5659_ADC_L_EQ_BPF2_A2:
  1106. case RT5659_ADC_R_EQ_BPF2_A2:
  1107. case RT5659_ADC_L_EQ_BPF2_H0:
  1108. case RT5659_ADC_R_EQ_BPF2_H0:
  1109. case RT5659_ADC_L_EQ_BPF3_A1:
  1110. case RT5659_ADC_R_EQ_BPF3_A1:
  1111. case RT5659_ADC_L_EQ_BPF3_A2:
  1112. case RT5659_ADC_R_EQ_BPF3_A2:
  1113. case RT5659_ADC_L_EQ_BPF3_H0:
  1114. case RT5659_ADC_R_EQ_BPF3_H0:
  1115. case RT5659_ADC_L_EQ_BPF4_A1:
  1116. case RT5659_ADC_R_EQ_BPF4_A1:
  1117. case RT5659_ADC_L_EQ_BPF4_A2:
  1118. case RT5659_ADC_R_EQ_BPF4_A2:
  1119. case RT5659_ADC_L_EQ_BPF4_H0:
  1120. case RT5659_ADC_R_EQ_BPF4_H0:
  1121. case RT5659_ADC_L_EQ_HPF1_A1:
  1122. case RT5659_ADC_R_EQ_HPF1_A1:
  1123. case RT5659_ADC_L_EQ_HPF1_H0:
  1124. case RT5659_ADC_R_EQ_HPF1_H0:
  1125. case RT5659_ADC_L_EQ_PRE_VOL:
  1126. case RT5659_ADC_R_EQ_PRE_VOL:
  1127. case RT5659_ADC_L_EQ_POST_VOL:
  1128. case RT5659_ADC_R_EQ_POST_VOL:
  1129. return true;
  1130. default:
  1131. return false;
  1132. }
  1133. }
  1134. static const DECLARE_TLV_DB_SCALE(hp_vol_tlv, -2325, 75, 0);
  1135. static const DECLARE_TLV_DB_SCALE(out_vol_tlv, -4650, 150, 0);
  1136. static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -65625, 375, 0);
  1137. static const DECLARE_TLV_DB_SCALE(in_vol_tlv, -3450, 150, 0);
  1138. static const DECLARE_TLV_DB_SCALE(adc_vol_tlv, -17625, 375, 0);
  1139. static const DECLARE_TLV_DB_SCALE(adc_bst_tlv, 0, 1200, 0);
  1140. static const DECLARE_TLV_DB_SCALE(in_bst_tlv, -1200, 75, 0);
  1141. /* Interface data select */
  1142. static const char * const rt5659_data_select[] = {
  1143. "L/R", "R/L", "L/L", "R/R"
  1144. };
  1145. static SOC_ENUM_SINGLE_DECL(rt5659_if1_01_adc_enum,
  1146. RT5659_TDM_CTRL_2, RT5659_DS_ADC_SLOT01_SFT, rt5659_data_select);
  1147. static SOC_ENUM_SINGLE_DECL(rt5659_if1_23_adc_enum,
  1148. RT5659_TDM_CTRL_2, RT5659_DS_ADC_SLOT23_SFT, rt5659_data_select);
  1149. static SOC_ENUM_SINGLE_DECL(rt5659_if1_45_adc_enum,
  1150. RT5659_TDM_CTRL_2, RT5659_DS_ADC_SLOT45_SFT, rt5659_data_select);
  1151. static SOC_ENUM_SINGLE_DECL(rt5659_if1_67_adc_enum,
  1152. RT5659_TDM_CTRL_2, RT5659_DS_ADC_SLOT67_SFT, rt5659_data_select);
  1153. static SOC_ENUM_SINGLE_DECL(rt5659_if2_dac_enum,
  1154. RT5659_DIG_INF23_DATA, RT5659_IF2_DAC_SEL_SFT, rt5659_data_select);
  1155. static SOC_ENUM_SINGLE_DECL(rt5659_if2_adc_enum,
  1156. RT5659_DIG_INF23_DATA, RT5659_IF2_ADC_SEL_SFT, rt5659_data_select);
  1157. static SOC_ENUM_SINGLE_DECL(rt5659_if3_dac_enum,
  1158. RT5659_DIG_INF23_DATA, RT5659_IF3_DAC_SEL_SFT, rt5659_data_select);
  1159. static SOC_ENUM_SINGLE_DECL(rt5659_if3_adc_enum,
  1160. RT5659_DIG_INF23_DATA, RT5659_IF3_ADC_SEL_SFT, rt5659_data_select);
  1161. static const struct snd_kcontrol_new rt5659_if1_01_adc_swap_mux =
  1162. SOC_DAPM_ENUM("IF1 01 ADC Swap Source", rt5659_if1_01_adc_enum);
  1163. static const struct snd_kcontrol_new rt5659_if1_23_adc_swap_mux =
  1164. SOC_DAPM_ENUM("IF1 23 ADC1 Swap Source", rt5659_if1_23_adc_enum);
  1165. static const struct snd_kcontrol_new rt5659_if1_45_adc_swap_mux =
  1166. SOC_DAPM_ENUM("IF1 45 ADC1 Swap Source", rt5659_if1_45_adc_enum);
  1167. static const struct snd_kcontrol_new rt5659_if1_67_adc_swap_mux =
  1168. SOC_DAPM_ENUM("IF1 67 ADC1 Swap Source", rt5659_if1_67_adc_enum);
  1169. static const struct snd_kcontrol_new rt5659_if2_dac_swap_mux =
  1170. SOC_DAPM_ENUM("IF2 DAC Swap Source", rt5659_if2_dac_enum);
  1171. static const struct snd_kcontrol_new rt5659_if2_adc_swap_mux =
  1172. SOC_DAPM_ENUM("IF2 ADC Swap Source", rt5659_if2_adc_enum);
  1173. static const struct snd_kcontrol_new rt5659_if3_dac_swap_mux =
  1174. SOC_DAPM_ENUM("IF3 DAC Swap Source", rt5659_if3_dac_enum);
  1175. static const struct snd_kcontrol_new rt5659_if3_adc_swap_mux =
  1176. SOC_DAPM_ENUM("IF3 ADC Swap Source", rt5659_if3_adc_enum);
  1177. static const char * const rt5659_asrc_clk_src[] = {
  1178. "clk_sysy_div_out", "clk_i2s1_track", "clk_i2s2_track",
  1179. "clk_i2s3_track", "clk_sys2", "clk_sys3"
  1180. };
  1181. static unsigned int rt5659_asrc_clk_map_values[] = {
  1182. 0, 1, 2, 3, 5, 6,
  1183. };
  1184. static SOC_VALUE_ENUM_SINGLE_DECL(
  1185. rt5659_da_sto_asrc_enum, RT5659_ASRC_2, RT5659_DA_STO_T_SFT, 0x7,
  1186. rt5659_asrc_clk_src, rt5659_asrc_clk_map_values);
  1187. static SOC_VALUE_ENUM_SINGLE_DECL(
  1188. rt5659_da_monol_asrc_enum, RT5659_ASRC_2, RT5659_DA_MONO_L_T_SFT, 0x7,
  1189. rt5659_asrc_clk_src, rt5659_asrc_clk_map_values);
  1190. static SOC_VALUE_ENUM_SINGLE_DECL(
  1191. rt5659_da_monor_asrc_enum, RT5659_ASRC_2, RT5659_DA_MONO_R_T_SFT, 0x7,
  1192. rt5659_asrc_clk_src, rt5659_asrc_clk_map_values);
  1193. static SOC_VALUE_ENUM_SINGLE_DECL(
  1194. rt5659_ad_sto1_asrc_enum, RT5659_ASRC_2, RT5659_AD_STO1_T_SFT, 0x7,
  1195. rt5659_asrc_clk_src, rt5659_asrc_clk_map_values);
  1196. static SOC_VALUE_ENUM_SINGLE_DECL(
  1197. rt5659_ad_sto2_asrc_enum, RT5659_ASRC_3, RT5659_AD_STO2_T_SFT, 0x7,
  1198. rt5659_asrc_clk_src, rt5659_asrc_clk_map_values);
  1199. static SOC_VALUE_ENUM_SINGLE_DECL(
  1200. rt5659_ad_monol_asrc_enum, RT5659_ASRC_3, RT5659_AD_MONO_L_T_SFT, 0x7,
  1201. rt5659_asrc_clk_src, rt5659_asrc_clk_map_values);
  1202. static SOC_VALUE_ENUM_SINGLE_DECL(
  1203. rt5659_ad_monor_asrc_enum, RT5659_ASRC_3, RT5659_AD_MONO_R_T_SFT, 0x7,
  1204. rt5659_asrc_clk_src, rt5659_asrc_clk_map_values);
  1205. static int rt5659_hp_vol_put(struct snd_kcontrol *kcontrol,
  1206. struct snd_ctl_elem_value *ucontrol)
  1207. {
  1208. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1209. int ret = snd_soc_put_volsw(kcontrol, ucontrol);
  1210. if (snd_soc_read(codec, RT5659_STO_NG2_CTRL_1) & RT5659_NG2_EN) {
  1211. snd_soc_update_bits(codec, RT5659_STO_NG2_CTRL_1,
  1212. RT5659_NG2_EN_MASK, RT5659_NG2_DIS);
  1213. snd_soc_update_bits(codec, RT5659_STO_NG2_CTRL_1,
  1214. RT5659_NG2_EN_MASK, RT5659_NG2_EN);
  1215. }
  1216. return ret;
  1217. }
  1218. static void rt5659_enable_push_button_irq(struct snd_soc_codec *codec,
  1219. bool enable)
  1220. {
  1221. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  1222. if (enable) {
  1223. snd_soc_write(codec, RT5659_4BTN_IL_CMD_1, 0x000b);
  1224. /* MICBIAS1 and Mic Det Power for button detect*/
  1225. snd_soc_dapm_force_enable_pin(dapm, "MICBIAS1");
  1226. snd_soc_dapm_force_enable_pin(dapm,
  1227. "Mic Det Power");
  1228. snd_soc_dapm_sync(dapm);
  1229. snd_soc_update_bits(codec, RT5659_PWR_ANLG_2,
  1230. RT5659_PWR_MB1, RT5659_PWR_MB1);
  1231. snd_soc_update_bits(codec, RT5659_PWR_VOL,
  1232. RT5659_PWR_MIC_DET, RT5659_PWR_MIC_DET);
  1233. snd_soc_update_bits(codec, RT5659_IRQ_CTRL_2,
  1234. RT5659_IL_IRQ_MASK, RT5659_IL_IRQ_EN);
  1235. snd_soc_update_bits(codec, RT5659_4BTN_IL_CMD_2,
  1236. RT5659_4BTN_IL_MASK, RT5659_4BTN_IL_EN);
  1237. } else {
  1238. snd_soc_update_bits(codec, RT5659_4BTN_IL_CMD_2,
  1239. RT5659_4BTN_IL_MASK, RT5659_4BTN_IL_DIS);
  1240. snd_soc_update_bits(codec, RT5659_IRQ_CTRL_2,
  1241. RT5659_IL_IRQ_MASK, RT5659_IL_IRQ_DIS);
  1242. /* MICBIAS1 and Mic Det Power for button detect*/
  1243. snd_soc_dapm_disable_pin(dapm, "MICBIAS1");
  1244. snd_soc_dapm_disable_pin(dapm, "Mic Det Power");
  1245. snd_soc_dapm_sync(dapm);
  1246. }
  1247. }
  1248. /**
  1249. * rt5659_headset_detect - Detect headset.
  1250. * @codec: SoC audio codec device.
  1251. * @jack_insert: Jack insert or not.
  1252. *
  1253. * Detect whether is headset or not when jack inserted.
  1254. *
  1255. * Returns detect status.
  1256. */
  1257. static int rt5659_headset_detect(struct snd_soc_codec *codec, int jack_insert)
  1258. {
  1259. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  1260. int val, i = 0, sleep_time[5] = {300, 150, 100, 50, 30};
  1261. int reg_63;
  1262. struct rt5659_priv *rt5659 = snd_soc_codec_get_drvdata(codec);
  1263. if (jack_insert) {
  1264. snd_soc_dapm_force_enable_pin(dapm,
  1265. "Mic Det Power");
  1266. snd_soc_dapm_sync(dapm);
  1267. reg_63 = snd_soc_read(codec, RT5659_PWR_ANLG_1);
  1268. snd_soc_update_bits(codec, RT5659_PWR_ANLG_1,
  1269. RT5659_PWR_VREF2 | RT5659_PWR_MB,
  1270. RT5659_PWR_VREF2 | RT5659_PWR_MB);
  1271. msleep(20);
  1272. snd_soc_update_bits(codec, RT5659_PWR_ANLG_1,
  1273. RT5659_PWR_FV2, RT5659_PWR_FV2);
  1274. snd_soc_write(codec, RT5659_EJD_CTRL_2, 0x4160);
  1275. snd_soc_update_bits(codec, RT5659_EJD_CTRL_1,
  1276. 0x20, 0x0);
  1277. msleep(20);
  1278. snd_soc_update_bits(codec, RT5659_EJD_CTRL_1,
  1279. 0x20, 0x20);
  1280. while (i < 5) {
  1281. msleep(sleep_time[i]);
  1282. val = snd_soc_read(codec, RT5659_EJD_CTRL_2) & 0x0003;
  1283. i++;
  1284. if (val == 0x1 || val == 0x2 || val == 0x3)
  1285. break;
  1286. }
  1287. switch (val) {
  1288. case 1:
  1289. rt5659->jack_type = SND_JACK_HEADSET;
  1290. rt5659_enable_push_button_irq(codec, true);
  1291. break;
  1292. default:
  1293. snd_soc_write(codec, RT5659_PWR_ANLG_1, reg_63);
  1294. rt5659->jack_type = SND_JACK_HEADPHONE;
  1295. snd_soc_dapm_disable_pin(dapm, "Mic Det Power");
  1296. snd_soc_dapm_sync(dapm);
  1297. break;
  1298. }
  1299. } else {
  1300. snd_soc_dapm_disable_pin(dapm, "Mic Det Power");
  1301. snd_soc_dapm_sync(dapm);
  1302. if (rt5659->jack_type == SND_JACK_HEADSET)
  1303. rt5659_enable_push_button_irq(codec, false);
  1304. rt5659->jack_type = 0;
  1305. }
  1306. dev_dbg(codec->dev, "jack_type = %d\n", rt5659->jack_type);
  1307. return rt5659->jack_type;
  1308. }
  1309. static int rt5659_button_detect(struct snd_soc_codec *codec)
  1310. {
  1311. int btn_type, val;
  1312. val = snd_soc_read(codec, RT5659_4BTN_IL_CMD_1);
  1313. btn_type = val & 0xfff0;
  1314. snd_soc_write(codec, RT5659_4BTN_IL_CMD_1, val);
  1315. return btn_type;
  1316. }
  1317. static irqreturn_t rt5659_irq(int irq, void *data)
  1318. {
  1319. struct rt5659_priv *rt5659 = data;
  1320. queue_delayed_work(system_power_efficient_wq,
  1321. &rt5659->jack_detect_work, msecs_to_jiffies(250));
  1322. return IRQ_HANDLED;
  1323. }
  1324. int rt5659_set_jack_detect(struct snd_soc_codec *codec,
  1325. struct snd_soc_jack *hs_jack)
  1326. {
  1327. struct rt5659_priv *rt5659 = snd_soc_codec_get_drvdata(codec);
  1328. rt5659->hs_jack = hs_jack;
  1329. rt5659_irq(0, rt5659);
  1330. return 0;
  1331. }
  1332. EXPORT_SYMBOL_GPL(rt5659_set_jack_detect);
  1333. static void rt5659_jack_detect_work(struct work_struct *work)
  1334. {
  1335. struct rt5659_priv *rt5659 =
  1336. container_of(work, struct rt5659_priv, jack_detect_work.work);
  1337. int val, btn_type, report = 0;
  1338. if (!rt5659->codec)
  1339. return;
  1340. val = snd_soc_read(rt5659->codec, RT5659_INT_ST_1) & 0x0080;
  1341. if (!val) {
  1342. /* jack in */
  1343. if (rt5659->jack_type == 0) {
  1344. /* jack was out, report jack type */
  1345. report = rt5659_headset_detect(rt5659->codec, 1);
  1346. } else {
  1347. /* jack is already in, report button event */
  1348. report = SND_JACK_HEADSET;
  1349. btn_type = rt5659_button_detect(rt5659->codec);
  1350. /**
  1351. * rt5659 can report three kinds of button behavior,
  1352. * one click, double click and hold. However,
  1353. * currently we will report button pressed/released
  1354. * event. So all the three button behaviors are
  1355. * treated as button pressed.
  1356. */
  1357. switch (btn_type) {
  1358. case 0x8000:
  1359. case 0x4000:
  1360. case 0x2000:
  1361. report |= SND_JACK_BTN_0;
  1362. break;
  1363. case 0x1000:
  1364. case 0x0800:
  1365. case 0x0400:
  1366. report |= SND_JACK_BTN_1;
  1367. break;
  1368. case 0x0200:
  1369. case 0x0100:
  1370. case 0x0080:
  1371. report |= SND_JACK_BTN_2;
  1372. break;
  1373. case 0x0040:
  1374. case 0x0020:
  1375. case 0x0010:
  1376. report |= SND_JACK_BTN_3;
  1377. break;
  1378. case 0x0000: /* unpressed */
  1379. break;
  1380. default:
  1381. btn_type = 0;
  1382. dev_err(rt5659->codec->dev,
  1383. "Unexpected button code 0x%04x\n",
  1384. btn_type);
  1385. break;
  1386. }
  1387. /* button release or spurious interrput*/
  1388. if (btn_type == 0)
  1389. report = rt5659->jack_type;
  1390. }
  1391. } else {
  1392. /* jack out */
  1393. report = rt5659_headset_detect(rt5659->codec, 0);
  1394. }
  1395. snd_soc_jack_report(rt5659->hs_jack, report, SND_JACK_HEADSET |
  1396. SND_JACK_BTN_0 | SND_JACK_BTN_1 |
  1397. SND_JACK_BTN_2 | SND_JACK_BTN_3);
  1398. }
  1399. static const struct snd_kcontrol_new rt5659_snd_controls[] = {
  1400. /* Speaker Output Volume */
  1401. SOC_DOUBLE_TLV("Speaker Playback Volume", RT5659_SPO_VOL,
  1402. RT5659_L_VOL_SFT, RT5659_R_VOL_SFT, 39, 1, out_vol_tlv),
  1403. /* Headphone Output Volume */
  1404. SOC_DOUBLE_R_EXT_TLV("Headphone Playback Volume", RT5659_HPL_GAIN,
  1405. RT5659_HPR_GAIN, RT5659_G_HP_SFT, 31, 1, snd_soc_get_volsw,
  1406. rt5659_hp_vol_put, hp_vol_tlv),
  1407. /* Mono Output Volume */
  1408. SOC_SINGLE_TLV("Mono Playback Volume", RT5659_MONO_OUT,
  1409. RT5659_L_VOL_SFT, 39, 1, out_vol_tlv),
  1410. /* Output Volume */
  1411. SOC_DOUBLE_TLV("OUT Playback Volume", RT5659_LOUT,
  1412. RT5659_L_VOL_SFT, RT5659_R_VOL_SFT, 39, 1, out_vol_tlv),
  1413. /* DAC Digital Volume */
  1414. SOC_DOUBLE_TLV("DAC1 Playback Volume", RT5659_DAC1_DIG_VOL,
  1415. RT5659_L_VOL_SFT, RT5659_R_VOL_SFT, 175, 0, dac_vol_tlv),
  1416. SOC_DOUBLE("DAC1 Playback Switch", RT5659_AD_DA_MIXER,
  1417. RT5659_M_DAC1_L_SFT, RT5659_M_DAC1_R_SFT, 1, 1),
  1418. SOC_DOUBLE_TLV("DAC2 Playback Volume", RT5659_DAC2_DIG_VOL,
  1419. RT5659_L_VOL_SFT, RT5659_R_VOL_SFT, 175, 0, dac_vol_tlv),
  1420. SOC_DOUBLE("DAC2 Playback Switch", RT5659_DAC_CTRL,
  1421. RT5659_M_DAC2_L_VOL_SFT, RT5659_M_DAC2_R_VOL_SFT, 1, 1),
  1422. /* IN1/IN2/IN3/IN4 Volume */
  1423. SOC_SINGLE_TLV("IN1 Boost Volume", RT5659_IN1_IN2,
  1424. RT5659_BST1_SFT, 69, 0, in_bst_tlv),
  1425. SOC_SINGLE_TLV("IN2 Boost Volume", RT5659_IN1_IN2,
  1426. RT5659_BST2_SFT, 69, 0, in_bst_tlv),
  1427. SOC_SINGLE_TLV("IN3 Boost Volume", RT5659_IN3_IN4,
  1428. RT5659_BST3_SFT, 69, 0, in_bst_tlv),
  1429. SOC_SINGLE_TLV("IN4 Boost Volume", RT5659_IN3_IN4,
  1430. RT5659_BST4_SFT, 69, 0, in_bst_tlv),
  1431. /* INL/INR Volume Control */
  1432. SOC_DOUBLE_TLV("IN Capture Volume", RT5659_INL1_INR1_VOL,
  1433. RT5659_INL_VOL_SFT, RT5659_INR_VOL_SFT, 31, 1, in_vol_tlv),
  1434. /* ADC Digital Volume Control */
  1435. SOC_DOUBLE("STO1 ADC Capture Switch", RT5659_STO1_ADC_DIG_VOL,
  1436. RT5659_L_MUTE_SFT, RT5659_R_MUTE_SFT, 1, 1),
  1437. SOC_DOUBLE_TLV("STO1 ADC Capture Volume", RT5659_STO1_ADC_DIG_VOL,
  1438. RT5659_L_VOL_SFT, RT5659_R_VOL_SFT, 127, 0, adc_vol_tlv),
  1439. SOC_DOUBLE("Mono ADC Capture Switch", RT5659_MONO_ADC_DIG_VOL,
  1440. RT5659_L_MUTE_SFT, RT5659_R_MUTE_SFT, 1, 1),
  1441. SOC_DOUBLE_TLV("Mono ADC Capture Volume", RT5659_MONO_ADC_DIG_VOL,
  1442. RT5659_L_VOL_SFT, RT5659_R_VOL_SFT, 127, 0, adc_vol_tlv),
  1443. SOC_DOUBLE("STO2 ADC Capture Switch", RT5659_STO2_ADC_DIG_VOL,
  1444. RT5659_L_MUTE_SFT, RT5659_R_MUTE_SFT, 1, 1),
  1445. SOC_DOUBLE_TLV("STO2 ADC Capture Volume", RT5659_STO2_ADC_DIG_VOL,
  1446. RT5659_L_VOL_SFT, RT5659_R_VOL_SFT, 127, 0, adc_vol_tlv),
  1447. /* ADC Boost Volume Control */
  1448. SOC_DOUBLE_TLV("STO1 ADC Boost Gain Volume", RT5659_STO1_BOOST,
  1449. RT5659_STO1_ADC_L_BST_SFT, RT5659_STO1_ADC_R_BST_SFT,
  1450. 3, 0, adc_bst_tlv),
  1451. SOC_DOUBLE_TLV("Mono ADC Boost Gain Volume", RT5659_MONO_BOOST,
  1452. RT5659_MONO_ADC_L_BST_SFT, RT5659_MONO_ADC_R_BST_SFT,
  1453. 3, 0, adc_bst_tlv),
  1454. SOC_DOUBLE_TLV("STO2 ADC Boost Gain Volume", RT5659_STO2_BOOST,
  1455. RT5659_STO2_ADC_L_BST_SFT, RT5659_STO2_ADC_R_BST_SFT,
  1456. 3, 0, adc_bst_tlv),
  1457. SOC_SINGLE("DAC IF1 DAC1 L Data Switch", RT5659_TDM_CTRL_4, 12, 7, 0),
  1458. SOC_SINGLE("DAC IF1 DAC1 R Data Switch", RT5659_TDM_CTRL_4, 8, 7, 0),
  1459. SOC_SINGLE("DAC IF1 DAC2 L Data Switch", RT5659_TDM_CTRL_4, 4, 7, 0),
  1460. SOC_SINGLE("DAC IF1 DAC2 R Data Switch", RT5659_TDM_CTRL_4, 0, 7, 0),
  1461. };
  1462. /**
  1463. * set_dmic_clk - Set parameter of dmic.
  1464. *
  1465. * @w: DAPM widget.
  1466. * @kcontrol: The kcontrol of this widget.
  1467. * @event: Event id.
  1468. *
  1469. * Choose dmic clock between 1MHz and 3MHz.
  1470. * It is better for clock to approximate 3MHz.
  1471. */
  1472. static int set_dmic_clk(struct snd_soc_dapm_widget *w,
  1473. struct snd_kcontrol *kcontrol, int event)
  1474. {
  1475. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1476. struct rt5659_priv *rt5659 = snd_soc_codec_get_drvdata(codec);
  1477. int pd, idx = -EINVAL;
  1478. pd = rl6231_get_pre_div(rt5659->regmap,
  1479. RT5659_ADDA_CLK_1, RT5659_I2S_PD1_SFT);
  1480. idx = rl6231_calc_dmic_clk(rt5659->sysclk / pd);
  1481. if (idx < 0)
  1482. dev_err(codec->dev, "Failed to set DMIC clock\n");
  1483. else {
  1484. snd_soc_update_bits(codec, RT5659_DMIC_CTRL_1,
  1485. RT5659_DMIC_CLK_MASK, idx << RT5659_DMIC_CLK_SFT);
  1486. }
  1487. return idx;
  1488. }
  1489. static int set_adc_clk(struct snd_soc_dapm_widget *w,
  1490. struct snd_kcontrol *kcontrol, int event)
  1491. {
  1492. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1493. switch (event) {
  1494. case SND_SOC_DAPM_POST_PMU:
  1495. snd_soc_update_bits(codec, RT5659_CHOP_ADC,
  1496. RT5659_CKXEN_ADCC_MASK | RT5659_CKGEN_ADCC_MASK,
  1497. RT5659_CKXEN_ADCC_MASK | RT5659_CKGEN_ADCC_MASK);
  1498. break;
  1499. case SND_SOC_DAPM_PRE_PMD:
  1500. snd_soc_update_bits(codec, RT5659_CHOP_ADC,
  1501. RT5659_CKXEN_ADCC_MASK | RT5659_CKGEN_ADCC_MASK, 0);
  1502. break;
  1503. default:
  1504. return 0;
  1505. }
  1506. return 0;
  1507. }
  1508. static int rt5659_charge_pump_event(struct snd_soc_dapm_widget *w,
  1509. struct snd_kcontrol *kcontrol, int event)
  1510. {
  1511. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1512. switch (event) {
  1513. case SND_SOC_DAPM_PRE_PMU:
  1514. /* Depop */
  1515. snd_soc_write(codec, RT5659_DEPOP_1, 0x0009);
  1516. break;
  1517. case SND_SOC_DAPM_POST_PMD:
  1518. snd_soc_write(codec, RT5659_HP_CHARGE_PUMP_1, 0x0c16);
  1519. break;
  1520. default:
  1521. return 0;
  1522. }
  1523. return 0;
  1524. }
  1525. static int is_sys_clk_from_pll(struct snd_soc_dapm_widget *w,
  1526. struct snd_soc_dapm_widget *sink)
  1527. {
  1528. unsigned int val;
  1529. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1530. val = snd_soc_read(codec, RT5659_GLB_CLK);
  1531. val &= RT5659_SCLK_SRC_MASK;
  1532. if (val == RT5659_SCLK_SRC_PLL1)
  1533. return 1;
  1534. else
  1535. return 0;
  1536. }
  1537. static int is_using_asrc(struct snd_soc_dapm_widget *w,
  1538. struct snd_soc_dapm_widget *sink)
  1539. {
  1540. unsigned int reg, shift, val;
  1541. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1542. switch (w->shift) {
  1543. case RT5659_ADC_MONO_R_ASRC_SFT:
  1544. reg = RT5659_ASRC_3;
  1545. shift = RT5659_AD_MONO_R_T_SFT;
  1546. break;
  1547. case RT5659_ADC_MONO_L_ASRC_SFT:
  1548. reg = RT5659_ASRC_3;
  1549. shift = RT5659_AD_MONO_L_T_SFT;
  1550. break;
  1551. case RT5659_ADC_STO1_ASRC_SFT:
  1552. reg = RT5659_ASRC_2;
  1553. shift = RT5659_AD_STO1_T_SFT;
  1554. break;
  1555. case RT5659_DAC_MONO_R_ASRC_SFT:
  1556. reg = RT5659_ASRC_2;
  1557. shift = RT5659_DA_MONO_R_T_SFT;
  1558. break;
  1559. case RT5659_DAC_MONO_L_ASRC_SFT:
  1560. reg = RT5659_ASRC_2;
  1561. shift = RT5659_DA_MONO_L_T_SFT;
  1562. break;
  1563. case RT5659_DAC_STO_ASRC_SFT:
  1564. reg = RT5659_ASRC_2;
  1565. shift = RT5659_DA_STO_T_SFT;
  1566. break;
  1567. default:
  1568. return 0;
  1569. }
  1570. val = (snd_soc_read(codec, reg) >> shift) & 0xf;
  1571. switch (val) {
  1572. case 1:
  1573. case 2:
  1574. case 3:
  1575. /* I2S_Pre_Div1 should be 1 in asrc mode */
  1576. snd_soc_update_bits(codec, RT5659_ADDA_CLK_1,
  1577. RT5659_I2S_PD1_MASK, RT5659_I2S_PD1_2);
  1578. return 1;
  1579. default:
  1580. return 0;
  1581. }
  1582. }
  1583. /* Digital Mixer */
  1584. static const struct snd_kcontrol_new rt5659_sto1_adc_l_mix[] = {
  1585. SOC_DAPM_SINGLE("ADC1 Switch", RT5659_STO1_ADC_MIXER,
  1586. RT5659_M_STO1_ADC_L1_SFT, 1, 1),
  1587. SOC_DAPM_SINGLE("ADC2 Switch", RT5659_STO1_ADC_MIXER,
  1588. RT5659_M_STO1_ADC_L2_SFT, 1, 1),
  1589. };
  1590. static const struct snd_kcontrol_new rt5659_sto1_adc_r_mix[] = {
  1591. SOC_DAPM_SINGLE("ADC1 Switch", RT5659_STO1_ADC_MIXER,
  1592. RT5659_M_STO1_ADC_R1_SFT, 1, 1),
  1593. SOC_DAPM_SINGLE("ADC2 Switch", RT5659_STO1_ADC_MIXER,
  1594. RT5659_M_STO1_ADC_R2_SFT, 1, 1),
  1595. };
  1596. static const struct snd_kcontrol_new rt5659_mono_adc_l_mix[] = {
  1597. SOC_DAPM_SINGLE("ADC1 Switch", RT5659_MONO_ADC_MIXER,
  1598. RT5659_M_MONO_ADC_L1_SFT, 1, 1),
  1599. SOC_DAPM_SINGLE("ADC2 Switch", RT5659_MONO_ADC_MIXER,
  1600. RT5659_M_MONO_ADC_L2_SFT, 1, 1),
  1601. };
  1602. static const struct snd_kcontrol_new rt5659_mono_adc_r_mix[] = {
  1603. SOC_DAPM_SINGLE("ADC1 Switch", RT5659_MONO_ADC_MIXER,
  1604. RT5659_M_MONO_ADC_R1_SFT, 1, 1),
  1605. SOC_DAPM_SINGLE("ADC2 Switch", RT5659_MONO_ADC_MIXER,
  1606. RT5659_M_MONO_ADC_R2_SFT, 1, 1),
  1607. };
  1608. static const struct snd_kcontrol_new rt5659_dac_l_mix[] = {
  1609. SOC_DAPM_SINGLE("Stereo ADC Switch", RT5659_AD_DA_MIXER,
  1610. RT5659_M_ADCMIX_L_SFT, 1, 1),
  1611. SOC_DAPM_SINGLE("DAC1 Switch", RT5659_AD_DA_MIXER,
  1612. RT5659_M_DAC1_L_SFT, 1, 1),
  1613. };
  1614. static const struct snd_kcontrol_new rt5659_dac_r_mix[] = {
  1615. SOC_DAPM_SINGLE("Stereo ADC Switch", RT5659_AD_DA_MIXER,
  1616. RT5659_M_ADCMIX_R_SFT, 1, 1),
  1617. SOC_DAPM_SINGLE("DAC1 Switch", RT5659_AD_DA_MIXER,
  1618. RT5659_M_DAC1_R_SFT, 1, 1),
  1619. };
  1620. static const struct snd_kcontrol_new rt5659_sto_dac_l_mix[] = {
  1621. SOC_DAPM_SINGLE("DAC L1 Switch", RT5659_STO_DAC_MIXER,
  1622. RT5659_M_DAC_L1_STO_L_SFT, 1, 1),
  1623. SOC_DAPM_SINGLE("DAC R1 Switch", RT5659_STO_DAC_MIXER,
  1624. RT5659_M_DAC_R1_STO_L_SFT, 1, 1),
  1625. SOC_DAPM_SINGLE("DAC L2 Switch", RT5659_STO_DAC_MIXER,
  1626. RT5659_M_DAC_L2_STO_L_SFT, 1, 1),
  1627. SOC_DAPM_SINGLE("DAC R2 Switch", RT5659_STO_DAC_MIXER,
  1628. RT5659_M_DAC_R2_STO_L_SFT, 1, 1),
  1629. };
  1630. static const struct snd_kcontrol_new rt5659_sto_dac_r_mix[] = {
  1631. SOC_DAPM_SINGLE("DAC L1 Switch", RT5659_STO_DAC_MIXER,
  1632. RT5659_M_DAC_L1_STO_R_SFT, 1, 1),
  1633. SOC_DAPM_SINGLE("DAC R1 Switch", RT5659_STO_DAC_MIXER,
  1634. RT5659_M_DAC_R1_STO_R_SFT, 1, 1),
  1635. SOC_DAPM_SINGLE("DAC L2 Switch", RT5659_STO_DAC_MIXER,
  1636. RT5659_M_DAC_L2_STO_R_SFT, 1, 1),
  1637. SOC_DAPM_SINGLE("DAC R2 Switch", RT5659_STO_DAC_MIXER,
  1638. RT5659_M_DAC_R2_STO_R_SFT, 1, 1),
  1639. };
  1640. static const struct snd_kcontrol_new rt5659_mono_dac_l_mix[] = {
  1641. SOC_DAPM_SINGLE("DAC L1 Switch", RT5659_MONO_DAC_MIXER,
  1642. RT5659_M_DAC_L1_MONO_L_SFT, 1, 1),
  1643. SOC_DAPM_SINGLE("DAC R1 Switch", RT5659_MONO_DAC_MIXER,
  1644. RT5659_M_DAC_R1_MONO_L_SFT, 1, 1),
  1645. SOC_DAPM_SINGLE("DAC L2 Switch", RT5659_MONO_DAC_MIXER,
  1646. RT5659_M_DAC_L2_MONO_L_SFT, 1, 1),
  1647. SOC_DAPM_SINGLE("DAC R2 Switch", RT5659_MONO_DAC_MIXER,
  1648. RT5659_M_DAC_R2_MONO_L_SFT, 1, 1),
  1649. };
  1650. static const struct snd_kcontrol_new rt5659_mono_dac_r_mix[] = {
  1651. SOC_DAPM_SINGLE("DAC L1 Switch", RT5659_MONO_DAC_MIXER,
  1652. RT5659_M_DAC_L1_MONO_R_SFT, 1, 1),
  1653. SOC_DAPM_SINGLE("DAC R1 Switch", RT5659_MONO_DAC_MIXER,
  1654. RT5659_M_DAC_R1_MONO_R_SFT, 1, 1),
  1655. SOC_DAPM_SINGLE("DAC L2 Switch", RT5659_MONO_DAC_MIXER,
  1656. RT5659_M_DAC_L2_MONO_R_SFT, 1, 1),
  1657. SOC_DAPM_SINGLE("DAC R2 Switch", RT5659_MONO_DAC_MIXER,
  1658. RT5659_M_DAC_R2_MONO_R_SFT, 1, 1),
  1659. };
  1660. /* Analog Input Mixer */
  1661. static const struct snd_kcontrol_new rt5659_rec1_l_mix[] = {
  1662. SOC_DAPM_SINGLE("SPKVOLL Switch", RT5659_REC1_L2_MIXER,
  1663. RT5659_M_SPKVOLL_RM1_L_SFT, 1, 1),
  1664. SOC_DAPM_SINGLE("INL Switch", RT5659_REC1_L2_MIXER,
  1665. RT5659_M_INL_RM1_L_SFT, 1, 1),
  1666. SOC_DAPM_SINGLE("BST4 Switch", RT5659_REC1_L2_MIXER,
  1667. RT5659_M_BST4_RM1_L_SFT, 1, 1),
  1668. SOC_DAPM_SINGLE("BST3 Switch", RT5659_REC1_L2_MIXER,
  1669. RT5659_M_BST3_RM1_L_SFT, 1, 1),
  1670. SOC_DAPM_SINGLE("BST2 Switch", RT5659_REC1_L2_MIXER,
  1671. RT5659_M_BST2_RM1_L_SFT, 1, 1),
  1672. SOC_DAPM_SINGLE("BST1 Switch", RT5659_REC1_L2_MIXER,
  1673. RT5659_M_BST1_RM1_L_SFT, 1, 1),
  1674. };
  1675. static const struct snd_kcontrol_new rt5659_rec1_r_mix[] = {
  1676. SOC_DAPM_SINGLE("HPOVOLR Switch", RT5659_REC1_L2_MIXER,
  1677. RT5659_M_HPOVOLR_RM1_R_SFT, 1, 1),
  1678. SOC_DAPM_SINGLE("INR Switch", RT5659_REC1_R2_MIXER,
  1679. RT5659_M_INR_RM1_R_SFT, 1, 1),
  1680. SOC_DAPM_SINGLE("BST4 Switch", RT5659_REC1_R2_MIXER,
  1681. RT5659_M_BST4_RM1_R_SFT, 1, 1),
  1682. SOC_DAPM_SINGLE("BST3 Switch", RT5659_REC1_R2_MIXER,
  1683. RT5659_M_BST3_RM1_R_SFT, 1, 1),
  1684. SOC_DAPM_SINGLE("BST2 Switch", RT5659_REC1_R2_MIXER,
  1685. RT5659_M_BST2_RM1_R_SFT, 1, 1),
  1686. SOC_DAPM_SINGLE("BST1 Switch", RT5659_REC1_R2_MIXER,
  1687. RT5659_M_BST1_RM1_R_SFT, 1, 1),
  1688. };
  1689. static const struct snd_kcontrol_new rt5659_rec2_l_mix[] = {
  1690. SOC_DAPM_SINGLE("SPKVOLL Switch", RT5659_REC2_L2_MIXER,
  1691. RT5659_M_SPKVOL_RM2_L_SFT, 1, 1),
  1692. SOC_DAPM_SINGLE("OUTVOLL Switch", RT5659_REC2_L2_MIXER,
  1693. RT5659_M_OUTVOLL_RM2_L_SFT, 1, 1),
  1694. SOC_DAPM_SINGLE("BST4 Switch", RT5659_REC2_L2_MIXER,
  1695. RT5659_M_BST4_RM2_L_SFT, 1, 1),
  1696. SOC_DAPM_SINGLE("BST3 Switch", RT5659_REC2_L2_MIXER,
  1697. RT5659_M_BST3_RM2_L_SFT, 1, 1),
  1698. SOC_DAPM_SINGLE("BST2 Switch", RT5659_REC2_L2_MIXER,
  1699. RT5659_M_BST2_RM2_L_SFT, 1, 1),
  1700. SOC_DAPM_SINGLE("BST1 Switch", RT5659_REC2_L2_MIXER,
  1701. RT5659_M_BST1_RM2_L_SFT, 1, 1),
  1702. };
  1703. static const struct snd_kcontrol_new rt5659_rec2_r_mix[] = {
  1704. SOC_DAPM_SINGLE("MONOVOL Switch", RT5659_REC2_R2_MIXER,
  1705. RT5659_M_MONOVOL_RM2_R_SFT, 1, 1),
  1706. SOC_DAPM_SINGLE("OUTVOLR Switch", RT5659_REC2_R2_MIXER,
  1707. RT5659_M_OUTVOLR_RM2_R_SFT, 1, 1),
  1708. SOC_DAPM_SINGLE("BST4 Switch", RT5659_REC2_R2_MIXER,
  1709. RT5659_M_BST4_RM2_R_SFT, 1, 1),
  1710. SOC_DAPM_SINGLE("BST3 Switch", RT5659_REC2_R2_MIXER,
  1711. RT5659_M_BST3_RM2_R_SFT, 1, 1),
  1712. SOC_DAPM_SINGLE("BST2 Switch", RT5659_REC2_R2_MIXER,
  1713. RT5659_M_BST2_RM2_R_SFT, 1, 1),
  1714. SOC_DAPM_SINGLE("BST1 Switch", RT5659_REC2_R2_MIXER,
  1715. RT5659_M_BST1_RM2_R_SFT, 1, 1),
  1716. };
  1717. static const struct snd_kcontrol_new rt5659_spk_l_mix[] = {
  1718. SOC_DAPM_SINGLE("DAC L2 Switch", RT5659_SPK_L_MIXER,
  1719. RT5659_M_DAC_L2_SM_L_SFT, 1, 1),
  1720. SOC_DAPM_SINGLE("BST1 Switch", RT5659_SPK_L_MIXER,
  1721. RT5659_M_BST1_SM_L_SFT, 1, 1),
  1722. SOC_DAPM_SINGLE("INL Switch", RT5659_SPK_L_MIXER,
  1723. RT5659_M_IN_L_SM_L_SFT, 1, 1),
  1724. SOC_DAPM_SINGLE("INR Switch", RT5659_SPK_L_MIXER,
  1725. RT5659_M_IN_R_SM_L_SFT, 1, 1),
  1726. SOC_DAPM_SINGLE("BST3 Switch", RT5659_SPK_L_MIXER,
  1727. RT5659_M_BST3_SM_L_SFT, 1, 1),
  1728. };
  1729. static const struct snd_kcontrol_new rt5659_spk_r_mix[] = {
  1730. SOC_DAPM_SINGLE("DAC R2 Switch", RT5659_SPK_R_MIXER,
  1731. RT5659_M_DAC_R2_SM_R_SFT, 1, 1),
  1732. SOC_DAPM_SINGLE("BST4 Switch", RT5659_SPK_R_MIXER,
  1733. RT5659_M_BST4_SM_R_SFT, 1, 1),
  1734. SOC_DAPM_SINGLE("INL Switch", RT5659_SPK_R_MIXER,
  1735. RT5659_M_IN_L_SM_R_SFT, 1, 1),
  1736. SOC_DAPM_SINGLE("INR Switch", RT5659_SPK_R_MIXER,
  1737. RT5659_M_IN_R_SM_R_SFT, 1, 1),
  1738. SOC_DAPM_SINGLE("BST3 Switch", RT5659_SPK_R_MIXER,
  1739. RT5659_M_BST3_SM_R_SFT, 1, 1),
  1740. };
  1741. static const struct snd_kcontrol_new rt5659_monovol_mix[] = {
  1742. SOC_DAPM_SINGLE("DAC L2 Switch", RT5659_MONOMIX_IN_GAIN,
  1743. RT5659_M_DAC_L2_MM_SFT, 1, 1),
  1744. SOC_DAPM_SINGLE("DAC R2 Switch", RT5659_MONOMIX_IN_GAIN,
  1745. RT5659_M_DAC_R2_MM_SFT, 1, 1),
  1746. SOC_DAPM_SINGLE("BST1 Switch", RT5659_MONOMIX_IN_GAIN,
  1747. RT5659_M_BST1_MM_SFT, 1, 1),
  1748. SOC_DAPM_SINGLE("BST2 Switch", RT5659_MONOMIX_IN_GAIN,
  1749. RT5659_M_BST2_MM_SFT, 1, 1),
  1750. SOC_DAPM_SINGLE("BST3 Switch", RT5659_MONOMIX_IN_GAIN,
  1751. RT5659_M_BST3_MM_SFT, 1, 1),
  1752. };
  1753. static const struct snd_kcontrol_new rt5659_out_l_mix[] = {
  1754. SOC_DAPM_SINGLE("DAC L2 Switch", RT5659_OUT_L_MIXER,
  1755. RT5659_M_DAC_L2_OM_L_SFT, 1, 1),
  1756. SOC_DAPM_SINGLE("INL Switch", RT5659_OUT_L_MIXER,
  1757. RT5659_M_IN_L_OM_L_SFT, 1, 1),
  1758. SOC_DAPM_SINGLE("BST1 Switch", RT5659_OUT_L_MIXER,
  1759. RT5659_M_BST1_OM_L_SFT, 1, 1),
  1760. SOC_DAPM_SINGLE("BST2 Switch", RT5659_OUT_L_MIXER,
  1761. RT5659_M_BST2_OM_L_SFT, 1, 1),
  1762. SOC_DAPM_SINGLE("BST3 Switch", RT5659_OUT_L_MIXER,
  1763. RT5659_M_BST3_OM_L_SFT, 1, 1),
  1764. };
  1765. static const struct snd_kcontrol_new rt5659_out_r_mix[] = {
  1766. SOC_DAPM_SINGLE("DAC R2 Switch", RT5659_OUT_R_MIXER,
  1767. RT5659_M_DAC_R2_OM_R_SFT, 1, 1),
  1768. SOC_DAPM_SINGLE("INR Switch", RT5659_OUT_R_MIXER,
  1769. RT5659_M_IN_R_OM_R_SFT, 1, 1),
  1770. SOC_DAPM_SINGLE("BST2 Switch", RT5659_OUT_R_MIXER,
  1771. RT5659_M_BST2_OM_R_SFT, 1, 1),
  1772. SOC_DAPM_SINGLE("BST3 Switch", RT5659_OUT_R_MIXER,
  1773. RT5659_M_BST3_OM_R_SFT, 1, 1),
  1774. SOC_DAPM_SINGLE("BST4 Switch", RT5659_OUT_R_MIXER,
  1775. RT5659_M_BST4_OM_R_SFT, 1, 1),
  1776. };
  1777. static const struct snd_kcontrol_new rt5659_spo_l_mix[] = {
  1778. SOC_DAPM_SINGLE("DAC L2 Switch", RT5659_SPO_AMP_GAIN,
  1779. RT5659_M_DAC_L2_SPKOMIX_SFT, 1, 0),
  1780. SOC_DAPM_SINGLE("SPKVOL L Switch", RT5659_SPO_AMP_GAIN,
  1781. RT5659_M_SPKVOLL_SPKOMIX_SFT, 1, 0),
  1782. };
  1783. static const struct snd_kcontrol_new rt5659_spo_r_mix[] = {
  1784. SOC_DAPM_SINGLE("DAC R2 Switch", RT5659_SPO_AMP_GAIN,
  1785. RT5659_M_DAC_R2_SPKOMIX_SFT, 1, 0),
  1786. SOC_DAPM_SINGLE("SPKVOL R Switch", RT5659_SPO_AMP_GAIN,
  1787. RT5659_M_SPKVOLR_SPKOMIX_SFT, 1, 0),
  1788. };
  1789. static const struct snd_kcontrol_new rt5659_mono_mix[] = {
  1790. SOC_DAPM_SINGLE("DAC L2 Switch", RT5659_MONOMIX_IN_GAIN,
  1791. RT5659_M_DAC_L2_MA_SFT, 1, 1),
  1792. SOC_DAPM_SINGLE("MONOVOL Switch", RT5659_MONOMIX_IN_GAIN,
  1793. RT5659_M_MONOVOL_MA_SFT, 1, 1),
  1794. };
  1795. static const struct snd_kcontrol_new rt5659_lout_l_mix[] = {
  1796. SOC_DAPM_SINGLE("DAC L2 Switch", RT5659_LOUT_MIXER,
  1797. RT5659_M_DAC_L2_LM_SFT, 1, 1),
  1798. SOC_DAPM_SINGLE("OUTVOL L Switch", RT5659_LOUT_MIXER,
  1799. RT5659_M_OV_L_LM_SFT, 1, 1),
  1800. };
  1801. static const struct snd_kcontrol_new rt5659_lout_r_mix[] = {
  1802. SOC_DAPM_SINGLE("DAC R2 Switch", RT5659_LOUT_MIXER,
  1803. RT5659_M_DAC_R2_LM_SFT, 1, 1),
  1804. SOC_DAPM_SINGLE("OUTVOL R Switch", RT5659_LOUT_MIXER,
  1805. RT5659_M_OV_R_LM_SFT, 1, 1),
  1806. };
  1807. /*DAC L2, DAC R2*/
  1808. /*MX-1B [6:4], MX-1B [2:0]*/
  1809. static const char * const rt5659_dac2_src[] = {
  1810. "IF1 DAC2", "IF2 DAC", "IF3 DAC", "Mono ADC MIX"
  1811. };
  1812. static SOC_ENUM_SINGLE_DECL(
  1813. rt5659_dac_l2_enum, RT5659_DAC_CTRL,
  1814. RT5659_DAC_L2_SEL_SFT, rt5659_dac2_src);
  1815. static const struct snd_kcontrol_new rt5659_dac_l2_mux =
  1816. SOC_DAPM_ENUM("DAC L2 Source", rt5659_dac_l2_enum);
  1817. static SOC_ENUM_SINGLE_DECL(
  1818. rt5659_dac_r2_enum, RT5659_DAC_CTRL,
  1819. RT5659_DAC_R2_SEL_SFT, rt5659_dac2_src);
  1820. static const struct snd_kcontrol_new rt5659_dac_r2_mux =
  1821. SOC_DAPM_ENUM("DAC R2 Source", rt5659_dac_r2_enum);
  1822. /* STO1 ADC1 Source */
  1823. /* MX-26 [13] */
  1824. static const char * const rt5659_sto1_adc1_src[] = {
  1825. "DAC MIX", "ADC"
  1826. };
  1827. static SOC_ENUM_SINGLE_DECL(
  1828. rt5659_sto1_adc1_enum, RT5659_STO1_ADC_MIXER,
  1829. RT5659_STO1_ADC1_SRC_SFT, rt5659_sto1_adc1_src);
  1830. static const struct snd_kcontrol_new rt5659_sto1_adc1_mux =
  1831. SOC_DAPM_ENUM("Stereo1 ADC1 Source", rt5659_sto1_adc1_enum);
  1832. /* STO1 ADC Source */
  1833. /* MX-26 [12] */
  1834. static const char * const rt5659_sto1_adc_src[] = {
  1835. "ADC1", "ADC2"
  1836. };
  1837. static SOC_ENUM_SINGLE_DECL(
  1838. rt5659_sto1_adc_enum, RT5659_STO1_ADC_MIXER,
  1839. RT5659_STO1_ADC_SRC_SFT, rt5659_sto1_adc_src);
  1840. static const struct snd_kcontrol_new rt5659_sto1_adc_mux =
  1841. SOC_DAPM_ENUM("Stereo1 ADC Source", rt5659_sto1_adc_enum);
  1842. /* STO1 ADC2 Source */
  1843. /* MX-26 [11] */
  1844. static const char * const rt5659_sto1_adc2_src[] = {
  1845. "DAC MIX", "DMIC"
  1846. };
  1847. static SOC_ENUM_SINGLE_DECL(
  1848. rt5659_sto1_adc2_enum, RT5659_STO1_ADC_MIXER,
  1849. RT5659_STO1_ADC2_SRC_SFT, rt5659_sto1_adc2_src);
  1850. static const struct snd_kcontrol_new rt5659_sto1_adc2_mux =
  1851. SOC_DAPM_ENUM("Stereo1 ADC2 Source", rt5659_sto1_adc2_enum);
  1852. /* STO1 DMIC Source */
  1853. /* MX-26 [8] */
  1854. static const char * const rt5659_sto1_dmic_src[] = {
  1855. "DMIC1", "DMIC2"
  1856. };
  1857. static SOC_ENUM_SINGLE_DECL(
  1858. rt5659_sto1_dmic_enum, RT5659_STO1_ADC_MIXER,
  1859. RT5659_STO1_DMIC_SRC_SFT, rt5659_sto1_dmic_src);
  1860. static const struct snd_kcontrol_new rt5659_sto1_dmic_mux =
  1861. SOC_DAPM_ENUM("Stereo1 DMIC Source", rt5659_sto1_dmic_enum);
  1862. /* MONO ADC L2 Source */
  1863. /* MX-27 [12] */
  1864. static const char * const rt5659_mono_adc_l2_src[] = {
  1865. "Mono DAC MIXL", "DMIC"
  1866. };
  1867. static SOC_ENUM_SINGLE_DECL(
  1868. rt5659_mono_adc_l2_enum, RT5659_MONO_ADC_MIXER,
  1869. RT5659_MONO_ADC_L2_SRC_SFT, rt5659_mono_adc_l2_src);
  1870. static const struct snd_kcontrol_new rt5659_mono_adc_l2_mux =
  1871. SOC_DAPM_ENUM("Mono ADC L2 Source", rt5659_mono_adc_l2_enum);
  1872. /* MONO ADC L1 Source */
  1873. /* MX-27 [11] */
  1874. static const char * const rt5659_mono_adc_l1_src[] = {
  1875. "Mono DAC MIXL", "ADC"
  1876. };
  1877. static SOC_ENUM_SINGLE_DECL(
  1878. rt5659_mono_adc_l1_enum, RT5659_MONO_ADC_MIXER,
  1879. RT5659_MONO_ADC_L1_SRC_SFT, rt5659_mono_adc_l1_src);
  1880. static const struct snd_kcontrol_new rt5659_mono_adc_l1_mux =
  1881. SOC_DAPM_ENUM("Mono ADC L1 Source", rt5659_mono_adc_l1_enum);
  1882. /* MONO ADC L Source, MONO ADC R Source*/
  1883. /* MX-27 [10:9], MX-27 [2:1] */
  1884. static const char * const rt5659_mono_adc_src[] = {
  1885. "ADC1 L", "ADC1 R", "ADC2 L", "ADC2 R"
  1886. };
  1887. static SOC_ENUM_SINGLE_DECL(
  1888. rt5659_mono_adc_l_enum, RT5659_MONO_ADC_MIXER,
  1889. RT5659_MONO_ADC_L_SRC_SFT, rt5659_mono_adc_src);
  1890. static const struct snd_kcontrol_new rt5659_mono_adc_l_mux =
  1891. SOC_DAPM_ENUM("Mono ADC L Source", rt5659_mono_adc_l_enum);
  1892. static SOC_ENUM_SINGLE_DECL(
  1893. rt5659_mono_adcr_enum, RT5659_MONO_ADC_MIXER,
  1894. RT5659_MONO_ADC_R_SRC_SFT, rt5659_mono_adc_src);
  1895. static const struct snd_kcontrol_new rt5659_mono_adc_r_mux =
  1896. SOC_DAPM_ENUM("Mono ADC R Source", rt5659_mono_adcr_enum);
  1897. /* MONO DMIC L Source */
  1898. /* MX-27 [8] */
  1899. static const char * const rt5659_mono_dmic_l_src[] = {
  1900. "DMIC1 L", "DMIC2 L"
  1901. };
  1902. static SOC_ENUM_SINGLE_DECL(
  1903. rt5659_mono_dmic_l_enum, RT5659_MONO_ADC_MIXER,
  1904. RT5659_MONO_DMIC_L_SRC_SFT, rt5659_mono_dmic_l_src);
  1905. static const struct snd_kcontrol_new rt5659_mono_dmic_l_mux =
  1906. SOC_DAPM_ENUM("Mono DMIC L Source", rt5659_mono_dmic_l_enum);
  1907. /* MONO ADC R2 Source */
  1908. /* MX-27 [4] */
  1909. static const char * const rt5659_mono_adc_r2_src[] = {
  1910. "Mono DAC MIXR", "DMIC"
  1911. };
  1912. static SOC_ENUM_SINGLE_DECL(
  1913. rt5659_mono_adc_r2_enum, RT5659_MONO_ADC_MIXER,
  1914. RT5659_MONO_ADC_R2_SRC_SFT, rt5659_mono_adc_r2_src);
  1915. static const struct snd_kcontrol_new rt5659_mono_adc_r2_mux =
  1916. SOC_DAPM_ENUM("Mono ADC R2 Source", rt5659_mono_adc_r2_enum);
  1917. /* MONO ADC R1 Source */
  1918. /* MX-27 [3] */
  1919. static const char * const rt5659_mono_adc_r1_src[] = {
  1920. "Mono DAC MIXR", "ADC"
  1921. };
  1922. static SOC_ENUM_SINGLE_DECL(
  1923. rt5659_mono_adc_r1_enum, RT5659_MONO_ADC_MIXER,
  1924. RT5659_MONO_ADC_R1_SRC_SFT, rt5659_mono_adc_r1_src);
  1925. static const struct snd_kcontrol_new rt5659_mono_adc_r1_mux =
  1926. SOC_DAPM_ENUM("Mono ADC R1 Source", rt5659_mono_adc_r1_enum);
  1927. /* MONO DMIC R Source */
  1928. /* MX-27 [0] */
  1929. static const char * const rt5659_mono_dmic_r_src[] = {
  1930. "DMIC1 R", "DMIC2 R"
  1931. };
  1932. static SOC_ENUM_SINGLE_DECL(
  1933. rt5659_mono_dmic_r_enum, RT5659_MONO_ADC_MIXER,
  1934. RT5659_MONO_DMIC_R_SRC_SFT, rt5659_mono_dmic_r_src);
  1935. static const struct snd_kcontrol_new rt5659_mono_dmic_r_mux =
  1936. SOC_DAPM_ENUM("Mono DMIC R Source", rt5659_mono_dmic_r_enum);
  1937. /* DAC R1 Source, DAC L1 Source*/
  1938. /* MX-29 [11:10], MX-29 [9:8]*/
  1939. static const char * const rt5659_dac1_src[] = {
  1940. "IF1 DAC1", "IF2 DAC", "IF3 DAC"
  1941. };
  1942. static SOC_ENUM_SINGLE_DECL(
  1943. rt5659_dac_r1_enum, RT5659_AD_DA_MIXER,
  1944. RT5659_DAC1_R_SEL_SFT, rt5659_dac1_src);
  1945. static const struct snd_kcontrol_new rt5659_dac_r1_mux =
  1946. SOC_DAPM_ENUM("DAC R1 Source", rt5659_dac_r1_enum);
  1947. static SOC_ENUM_SINGLE_DECL(
  1948. rt5659_dac_l1_enum, RT5659_AD_DA_MIXER,
  1949. RT5659_DAC1_L_SEL_SFT, rt5659_dac1_src);
  1950. static const struct snd_kcontrol_new rt5659_dac_l1_mux =
  1951. SOC_DAPM_ENUM("DAC L1 Source", rt5659_dac_l1_enum);
  1952. /* DAC Digital Mixer L Source, DAC Digital Mixer R Source*/
  1953. /* MX-2C [6], MX-2C [4]*/
  1954. static const char * const rt5659_dig_dac_mix_src[] = {
  1955. "Stereo DAC Mixer", "Mono DAC Mixer"
  1956. };
  1957. static SOC_ENUM_SINGLE_DECL(
  1958. rt5659_dig_dac_mixl_enum, RT5659_DIG_MIXER,
  1959. RT5659_DAC_MIX_L_SFT, rt5659_dig_dac_mix_src);
  1960. static const struct snd_kcontrol_new rt5659_dig_dac_mixl_mux =
  1961. SOC_DAPM_ENUM("DAC Digital Mixer L Source", rt5659_dig_dac_mixl_enum);
  1962. static SOC_ENUM_SINGLE_DECL(
  1963. rt5659_dig_dac_mixr_enum, RT5659_DIG_MIXER,
  1964. RT5659_DAC_MIX_R_SFT, rt5659_dig_dac_mix_src);
  1965. static const struct snd_kcontrol_new rt5659_dig_dac_mixr_mux =
  1966. SOC_DAPM_ENUM("DAC Digital Mixer R Source", rt5659_dig_dac_mixr_enum);
  1967. /* Analog DAC L1 Source, Analog DAC R1 Source*/
  1968. /* MX-2D [3], MX-2D [2]*/
  1969. static const char * const rt5659_alg_dac1_src[] = {
  1970. "DAC", "Stereo DAC Mixer"
  1971. };
  1972. static SOC_ENUM_SINGLE_DECL(
  1973. rt5659_alg_dac_l1_enum, RT5659_A_DAC_MUX,
  1974. RT5659_A_DACL1_SFT, rt5659_alg_dac1_src);
  1975. static const struct snd_kcontrol_new rt5659_alg_dac_l1_mux =
  1976. SOC_DAPM_ENUM("Analog DACL1 Source", rt5659_alg_dac_l1_enum);
  1977. static SOC_ENUM_SINGLE_DECL(
  1978. rt5659_alg_dac_r1_enum, RT5659_A_DAC_MUX,
  1979. RT5659_A_DACR1_SFT, rt5659_alg_dac1_src);
  1980. static const struct snd_kcontrol_new rt5659_alg_dac_r1_mux =
  1981. SOC_DAPM_ENUM("Analog DACR1 Source", rt5659_alg_dac_r1_enum);
  1982. /* Analog DAC LR Source, Analog DAC R2 Source*/
  1983. /* MX-2D [1], MX-2D [0]*/
  1984. static const char * const rt5659_alg_dac2_src[] = {
  1985. "Stereo DAC Mixer", "Mono DAC Mixer"
  1986. };
  1987. static SOC_ENUM_SINGLE_DECL(
  1988. rt5659_alg_dac_l2_enum, RT5659_A_DAC_MUX,
  1989. RT5659_A_DACL2_SFT, rt5659_alg_dac2_src);
  1990. static const struct snd_kcontrol_new rt5659_alg_dac_l2_mux =
  1991. SOC_DAPM_ENUM("Analog DAC L2 Source", rt5659_alg_dac_l2_enum);
  1992. static SOC_ENUM_SINGLE_DECL(
  1993. rt5659_alg_dac_r2_enum, RT5659_A_DAC_MUX,
  1994. RT5659_A_DACR2_SFT, rt5659_alg_dac2_src);
  1995. static const struct snd_kcontrol_new rt5659_alg_dac_r2_mux =
  1996. SOC_DAPM_ENUM("Analog DAC R2 Source", rt5659_alg_dac_r2_enum);
  1997. /* Interface2 ADC Data Input*/
  1998. /* MX-2F [13:12] */
  1999. static const char * const rt5659_if2_adc_in_src[] = {
  2000. "IF_ADC1", "IF_ADC2", "DAC_REF", "IF_ADC3"
  2001. };
  2002. static SOC_ENUM_SINGLE_DECL(
  2003. rt5659_if2_adc_in_enum, RT5659_DIG_INF23_DATA,
  2004. RT5659_IF2_ADC_IN_SFT, rt5659_if2_adc_in_src);
  2005. static const struct snd_kcontrol_new rt5659_if2_adc_in_mux =
  2006. SOC_DAPM_ENUM("IF2 ADC IN Source", rt5659_if2_adc_in_enum);
  2007. /* Interface3 ADC Data Input*/
  2008. /* MX-2F [1:0] */
  2009. static const char * const rt5659_if3_adc_in_src[] = {
  2010. "IF_ADC1", "IF_ADC2", "DAC_REF", "Stereo2_ADC_L/R"
  2011. };
  2012. static SOC_ENUM_SINGLE_DECL(
  2013. rt5659_if3_adc_in_enum, RT5659_DIG_INF23_DATA,
  2014. RT5659_IF3_ADC_IN_SFT, rt5659_if3_adc_in_src);
  2015. static const struct snd_kcontrol_new rt5659_if3_adc_in_mux =
  2016. SOC_DAPM_ENUM("IF3 ADC IN Source", rt5659_if3_adc_in_enum);
  2017. /* PDM 1 L/R*/
  2018. /* MX-31 [15] [13] */
  2019. static const char * const rt5659_pdm_src[] = {
  2020. "Mono DAC", "Stereo DAC"
  2021. };
  2022. static SOC_ENUM_SINGLE_DECL(
  2023. rt5659_pdm_l_enum, RT5659_PDM_OUT_CTRL,
  2024. RT5659_PDM1_L_SFT, rt5659_pdm_src);
  2025. static const struct snd_kcontrol_new rt5659_pdm_l_mux =
  2026. SOC_DAPM_ENUM("PDM L Source", rt5659_pdm_l_enum);
  2027. static SOC_ENUM_SINGLE_DECL(
  2028. rt5659_pdm_r_enum, RT5659_PDM_OUT_CTRL,
  2029. RT5659_PDM1_R_SFT, rt5659_pdm_src);
  2030. static const struct snd_kcontrol_new rt5659_pdm_r_mux =
  2031. SOC_DAPM_ENUM("PDM R Source", rt5659_pdm_r_enum);
  2032. /* SPDIF Output source*/
  2033. /* MX-36 [1:0] */
  2034. static const char * const rt5659_spdif_src[] = {
  2035. "IF1_DAC1", "IF1_DAC2", "IF2_DAC", "IF3_DAC"
  2036. };
  2037. static SOC_ENUM_SINGLE_DECL(
  2038. rt5659_spdif_enum, RT5659_SPDIF_CTRL,
  2039. RT5659_SPDIF_SEL_SFT, rt5659_spdif_src);
  2040. static const struct snd_kcontrol_new rt5659_spdif_mux =
  2041. SOC_DAPM_ENUM("SPDIF Source", rt5659_spdif_enum);
  2042. /* I2S1 TDM ADCDAT Source */
  2043. /* MX-78[4:0] */
  2044. static const char * const rt5659_rx_adc_data_src[] = {
  2045. "AD1:AD2:DAC:NUL", "AD1:AD2:NUL:DAC", "AD1:DAC:AD2:NUL",
  2046. "AD1:DAC:NUL:AD2", "AD1:NUL:DAC:AD2", "AD1:NUL:AD2:DAC",
  2047. "AD2:AD1:DAC:NUL", "AD2:AD1:NUL:DAC", "AD2:DAC:AD1:NUL",
  2048. "AD2:DAC:NUL:AD1", "AD2:NUL:DAC:AD1", "AD1:NUL:AD1:DAC",
  2049. "DAC:AD1:AD2:NUL", "DAC:AD1:NUL:AD2", "DAC:AD2:AD1:NUL",
  2050. "DAC:AD2:NUL:AD1", "DAC:NUL:DAC:AD2", "DAC:NUL:AD2:DAC",
  2051. "NUL:AD1:AD2:DAC", "NUL:AD1:DAC:AD2", "NUL:AD2:AD1:DAC",
  2052. "NUL:AD2:DAC:AD1", "NUL:DAC:DAC:AD2", "NUL:DAC:AD2:DAC"
  2053. };
  2054. static SOC_ENUM_SINGLE_DECL(
  2055. rt5659_rx_adc_data_enum, RT5659_TDM_CTRL_2,
  2056. RT5659_ADCDAT_SRC_SFT, rt5659_rx_adc_data_src);
  2057. static const struct snd_kcontrol_new rt5659_rx_adc_dac_mux =
  2058. SOC_DAPM_ENUM("TDM ADCDAT Source", rt5659_rx_adc_data_enum);
  2059. /* Out Volume Switch */
  2060. static const struct snd_kcontrol_new spkvol_l_switch =
  2061. SOC_DAPM_SINGLE("Switch", RT5659_SPO_VOL, RT5659_VOL_L_SFT, 1, 1);
  2062. static const struct snd_kcontrol_new spkvol_r_switch =
  2063. SOC_DAPM_SINGLE("Switch", RT5659_SPO_VOL, RT5659_VOL_R_SFT, 1, 1);
  2064. static const struct snd_kcontrol_new monovol_switch =
  2065. SOC_DAPM_SINGLE("Switch", RT5659_MONO_OUT, RT5659_VOL_L_SFT, 1, 1);
  2066. static const struct snd_kcontrol_new outvol_l_switch =
  2067. SOC_DAPM_SINGLE("Switch", RT5659_LOUT, RT5659_VOL_L_SFT, 1, 1);
  2068. static const struct snd_kcontrol_new outvol_r_switch =
  2069. SOC_DAPM_SINGLE("Switch", RT5659_LOUT, RT5659_VOL_R_SFT, 1, 1);
  2070. /* Out Switch */
  2071. static const struct snd_kcontrol_new spo_switch =
  2072. SOC_DAPM_SINGLE("Switch", RT5659_CLASSD_2, RT5659_M_RF_DIG_SFT, 1, 1);
  2073. static const struct snd_kcontrol_new mono_switch =
  2074. SOC_DAPM_SINGLE("Switch", RT5659_MONO_OUT, RT5659_L_MUTE_SFT, 1, 1);
  2075. static const struct snd_kcontrol_new hpo_l_switch =
  2076. SOC_DAPM_SINGLE("Switch", RT5659_HP_VOL, RT5659_L_MUTE_SFT, 1, 1);
  2077. static const struct snd_kcontrol_new hpo_r_switch =
  2078. SOC_DAPM_SINGLE("Switch", RT5659_HP_VOL, RT5659_R_MUTE_SFT, 1, 1);
  2079. static const struct snd_kcontrol_new lout_l_switch =
  2080. SOC_DAPM_SINGLE("Switch", RT5659_LOUT, RT5659_L_MUTE_SFT, 1, 1);
  2081. static const struct snd_kcontrol_new lout_r_switch =
  2082. SOC_DAPM_SINGLE("Switch", RT5659_LOUT, RT5659_R_MUTE_SFT, 1, 1);
  2083. static const struct snd_kcontrol_new pdm_l_switch =
  2084. SOC_DAPM_SINGLE("Switch", RT5659_PDM_OUT_CTRL, RT5659_M_PDM1_L_SFT, 1,
  2085. 1);
  2086. static const struct snd_kcontrol_new pdm_r_switch =
  2087. SOC_DAPM_SINGLE("Switch", RT5659_PDM_OUT_CTRL, RT5659_M_PDM1_R_SFT, 1,
  2088. 1);
  2089. static int rt5659_spk_event(struct snd_soc_dapm_widget *w,
  2090. struct snd_kcontrol *kcontrol, int event)
  2091. {
  2092. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2093. switch (event) {
  2094. case SND_SOC_DAPM_PRE_PMU:
  2095. snd_soc_update_bits(codec, RT5659_CLASSD_CTRL_1,
  2096. RT5659_POW_CLSD_DB_MASK, RT5659_POW_CLSD_DB_EN);
  2097. snd_soc_update_bits(codec, RT5659_CLASSD_2,
  2098. RT5659_M_RI_DIG, RT5659_M_RI_DIG);
  2099. snd_soc_write(codec, RT5659_CLASSD_1, 0x0803);
  2100. snd_soc_write(codec, RT5659_SPK_DC_CAILB_CTRL_3, 0x0000);
  2101. break;
  2102. case SND_SOC_DAPM_POST_PMD:
  2103. snd_soc_write(codec, RT5659_CLASSD_1, 0x0011);
  2104. snd_soc_update_bits(codec, RT5659_CLASSD_2,
  2105. RT5659_M_RI_DIG, 0x0);
  2106. snd_soc_write(codec, RT5659_SPK_DC_CAILB_CTRL_3, 0x0003);
  2107. snd_soc_update_bits(codec, RT5659_CLASSD_CTRL_1,
  2108. RT5659_POW_CLSD_DB_MASK, RT5659_POW_CLSD_DB_DIS);
  2109. break;
  2110. default:
  2111. return 0;
  2112. }
  2113. return 0;
  2114. }
  2115. static int rt5659_mono_event(struct snd_soc_dapm_widget *w,
  2116. struct snd_kcontrol *kcontrol, int event)
  2117. {
  2118. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2119. switch (event) {
  2120. case SND_SOC_DAPM_PRE_PMU:
  2121. snd_soc_write(codec, RT5659_MONO_AMP_CALIB_CTRL_1, 0x1e00);
  2122. break;
  2123. case SND_SOC_DAPM_POST_PMD:
  2124. snd_soc_write(codec, RT5659_MONO_AMP_CALIB_CTRL_1, 0x1e04);
  2125. break;
  2126. default:
  2127. return 0;
  2128. }
  2129. return 0;
  2130. }
  2131. static int rt5659_hp_event(struct snd_soc_dapm_widget *w,
  2132. struct snd_kcontrol *kcontrol, int event)
  2133. {
  2134. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2135. switch (event) {
  2136. case SND_SOC_DAPM_POST_PMU:
  2137. snd_soc_write(codec, RT5659_HP_CHARGE_PUMP_1, 0x0e1e);
  2138. snd_soc_update_bits(codec, RT5659_DEPOP_1, 0x0010, 0x0010);
  2139. break;
  2140. case SND_SOC_DAPM_PRE_PMD:
  2141. snd_soc_write(codec, RT5659_DEPOP_1, 0x0000);
  2142. break;
  2143. default:
  2144. return 0;
  2145. }
  2146. return 0;
  2147. }
  2148. static int set_dmic_power(struct snd_soc_dapm_widget *w,
  2149. struct snd_kcontrol *kcontrol, int event)
  2150. {
  2151. switch (event) {
  2152. case SND_SOC_DAPM_POST_PMU:
  2153. /*Add delay to avoid pop noise*/
  2154. msleep(450);
  2155. break;
  2156. default:
  2157. return 0;
  2158. }
  2159. return 0;
  2160. }
  2161. static const struct snd_soc_dapm_widget rt5659_dapm_widgets[] = {
  2162. SND_SOC_DAPM_SUPPLY("LDO2", RT5659_PWR_ANLG_3, RT5659_PWR_LDO2_BIT, 0,
  2163. NULL, 0),
  2164. SND_SOC_DAPM_SUPPLY("PLL", RT5659_PWR_ANLG_3, RT5659_PWR_PLL_BIT, 0,
  2165. NULL, 0),
  2166. SND_SOC_DAPM_SUPPLY("Mic Det Power", RT5659_PWR_VOL,
  2167. RT5659_PWR_MIC_DET_BIT, 0, NULL, 0),
  2168. SND_SOC_DAPM_SUPPLY("Mono Vref", RT5659_PWR_ANLG_1,
  2169. RT5659_PWR_VREF3_BIT, 0, NULL, 0),
  2170. /* ASRC */
  2171. SND_SOC_DAPM_SUPPLY_S("I2S1 ASRC", 1, RT5659_ASRC_1,
  2172. RT5659_I2S1_ASRC_SFT, 0, NULL, 0),
  2173. SND_SOC_DAPM_SUPPLY_S("I2S2 ASRC", 1, RT5659_ASRC_1,
  2174. RT5659_I2S2_ASRC_SFT, 0, NULL, 0),
  2175. SND_SOC_DAPM_SUPPLY_S("I2S3 ASRC", 1, RT5659_ASRC_1,
  2176. RT5659_I2S3_ASRC_SFT, 0, NULL, 0),
  2177. SND_SOC_DAPM_SUPPLY_S("DAC STO ASRC", 1, RT5659_ASRC_1,
  2178. RT5659_DAC_STO_ASRC_SFT, 0, NULL, 0),
  2179. SND_SOC_DAPM_SUPPLY_S("DAC Mono L ASRC", 1, RT5659_ASRC_1,
  2180. RT5659_DAC_MONO_L_ASRC_SFT, 0, NULL, 0),
  2181. SND_SOC_DAPM_SUPPLY_S("DAC Mono R ASRC", 1, RT5659_ASRC_1,
  2182. RT5659_DAC_MONO_R_ASRC_SFT, 0, NULL, 0),
  2183. SND_SOC_DAPM_SUPPLY_S("ADC STO1 ASRC", 1, RT5659_ASRC_1,
  2184. RT5659_ADC_STO1_ASRC_SFT, 0, NULL, 0),
  2185. SND_SOC_DAPM_SUPPLY_S("ADC Mono L ASRC", 1, RT5659_ASRC_1,
  2186. RT5659_ADC_MONO_L_ASRC_SFT, 0, NULL, 0),
  2187. SND_SOC_DAPM_SUPPLY_S("ADC Mono R ASRC", 1, RT5659_ASRC_1,
  2188. RT5659_ADC_MONO_R_ASRC_SFT, 0, NULL, 0),
  2189. /* Input Side */
  2190. SND_SOC_DAPM_SUPPLY("MICBIAS1", RT5659_PWR_ANLG_2, RT5659_PWR_MB1_BIT,
  2191. 0, NULL, 0),
  2192. SND_SOC_DAPM_SUPPLY("MICBIAS2", RT5659_PWR_ANLG_2, RT5659_PWR_MB2_BIT,
  2193. 0, NULL, 0),
  2194. SND_SOC_DAPM_SUPPLY("MICBIAS3", RT5659_PWR_ANLG_2, RT5659_PWR_MB3_BIT,
  2195. 0, NULL, 0),
  2196. /* Input Lines */
  2197. SND_SOC_DAPM_INPUT("DMIC L1"),
  2198. SND_SOC_DAPM_INPUT("DMIC R1"),
  2199. SND_SOC_DAPM_INPUT("DMIC L2"),
  2200. SND_SOC_DAPM_INPUT("DMIC R2"),
  2201. SND_SOC_DAPM_INPUT("IN1P"),
  2202. SND_SOC_DAPM_INPUT("IN1N"),
  2203. SND_SOC_DAPM_INPUT("IN2P"),
  2204. SND_SOC_DAPM_INPUT("IN2N"),
  2205. SND_SOC_DAPM_INPUT("IN3P"),
  2206. SND_SOC_DAPM_INPUT("IN3N"),
  2207. SND_SOC_DAPM_INPUT("IN4P"),
  2208. SND_SOC_DAPM_INPUT("IN4N"),
  2209. SND_SOC_DAPM_PGA("DMIC1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2210. SND_SOC_DAPM_PGA("DMIC2", SND_SOC_NOPM, 0, 0, NULL, 0),
  2211. SND_SOC_DAPM_SUPPLY("DMIC CLK", SND_SOC_NOPM, 0, 0,
  2212. set_dmic_clk, SND_SOC_DAPM_PRE_PMU),
  2213. SND_SOC_DAPM_SUPPLY("DMIC1 Power", RT5659_DMIC_CTRL_1,
  2214. RT5659_DMIC_1_EN_SFT, 0, set_dmic_power, SND_SOC_DAPM_POST_PMU),
  2215. SND_SOC_DAPM_SUPPLY("DMIC2 Power", RT5659_DMIC_CTRL_1,
  2216. RT5659_DMIC_2_EN_SFT, 0, set_dmic_power, SND_SOC_DAPM_POST_PMU),
  2217. /* Boost */
  2218. SND_SOC_DAPM_PGA("BST1", RT5659_PWR_ANLG_2,
  2219. RT5659_PWR_BST1_P_BIT, 0, NULL, 0),
  2220. SND_SOC_DAPM_PGA("BST2", RT5659_PWR_ANLG_2,
  2221. RT5659_PWR_BST2_P_BIT, 0, NULL, 0),
  2222. SND_SOC_DAPM_PGA("BST3", RT5659_PWR_ANLG_2,
  2223. RT5659_PWR_BST3_P_BIT, 0, NULL, 0),
  2224. SND_SOC_DAPM_PGA("BST4", RT5659_PWR_ANLG_2,
  2225. RT5659_PWR_BST4_P_BIT, 0, NULL, 0),
  2226. SND_SOC_DAPM_SUPPLY("BST1 Power", RT5659_PWR_ANLG_2,
  2227. RT5659_PWR_BST1_BIT, 0, NULL, 0),
  2228. SND_SOC_DAPM_SUPPLY("BST2 Power", RT5659_PWR_ANLG_2,
  2229. RT5659_PWR_BST2_BIT, 0, NULL, 0),
  2230. SND_SOC_DAPM_SUPPLY("BST3 Power", RT5659_PWR_ANLG_2,
  2231. RT5659_PWR_BST3_BIT, 0, NULL, 0),
  2232. SND_SOC_DAPM_SUPPLY("BST4 Power", RT5659_PWR_ANLG_2,
  2233. RT5659_PWR_BST4_BIT, 0, NULL, 0),
  2234. /* Input Volume */
  2235. SND_SOC_DAPM_PGA("INL VOL", RT5659_PWR_VOL, RT5659_PWR_IN_L_BIT,
  2236. 0, NULL, 0),
  2237. SND_SOC_DAPM_PGA("INR VOL", RT5659_PWR_VOL, RT5659_PWR_IN_R_BIT,
  2238. 0, NULL, 0),
  2239. /* REC Mixer */
  2240. SND_SOC_DAPM_MIXER("RECMIX1L", RT5659_PWR_MIXER, RT5659_PWR_RM1_L_BIT,
  2241. 0, rt5659_rec1_l_mix, ARRAY_SIZE(rt5659_rec1_l_mix)),
  2242. SND_SOC_DAPM_MIXER("RECMIX1R", RT5659_PWR_MIXER, RT5659_PWR_RM1_R_BIT,
  2243. 0, rt5659_rec1_r_mix, ARRAY_SIZE(rt5659_rec1_r_mix)),
  2244. SND_SOC_DAPM_MIXER("RECMIX2L", RT5659_PWR_MIXER, RT5659_PWR_RM2_L_BIT,
  2245. 0, rt5659_rec2_l_mix, ARRAY_SIZE(rt5659_rec2_l_mix)),
  2246. SND_SOC_DAPM_MIXER("RECMIX2R", RT5659_PWR_MIXER, RT5659_PWR_RM2_R_BIT,
  2247. 0, rt5659_rec2_r_mix, ARRAY_SIZE(rt5659_rec2_r_mix)),
  2248. /* ADCs */
  2249. SND_SOC_DAPM_ADC("ADC1 L", NULL, SND_SOC_NOPM, 0, 0),
  2250. SND_SOC_DAPM_ADC("ADC1 R", NULL, SND_SOC_NOPM, 0, 0),
  2251. SND_SOC_DAPM_ADC("ADC2 L", NULL, SND_SOC_NOPM, 0, 0),
  2252. SND_SOC_DAPM_ADC("ADC2 R", NULL, SND_SOC_NOPM, 0, 0),
  2253. SND_SOC_DAPM_SUPPLY("ADC1 L Power", RT5659_PWR_DIG_1,
  2254. RT5659_PWR_ADC_L1_BIT, 0, NULL, 0),
  2255. SND_SOC_DAPM_SUPPLY("ADC1 R Power", RT5659_PWR_DIG_1,
  2256. RT5659_PWR_ADC_R1_BIT, 0, NULL, 0),
  2257. SND_SOC_DAPM_SUPPLY("ADC2 L Power", RT5659_PWR_DIG_2,
  2258. RT5659_PWR_ADC_L2_BIT, 0, NULL, 0),
  2259. SND_SOC_DAPM_SUPPLY("ADC2 R Power", RT5659_PWR_DIG_2,
  2260. RT5659_PWR_ADC_R2_BIT, 0, NULL, 0),
  2261. SND_SOC_DAPM_SUPPLY("ADC1 clock", SND_SOC_NOPM, 0, 0, set_adc_clk,
  2262. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  2263. SND_SOC_DAPM_SUPPLY("ADC2 clock", SND_SOC_NOPM, 0, 0, set_adc_clk,
  2264. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  2265. /* ADC Mux */
  2266. SND_SOC_DAPM_MUX("Stereo1 DMIC L Mux", SND_SOC_NOPM, 0, 0,
  2267. &rt5659_sto1_dmic_mux),
  2268. SND_SOC_DAPM_MUX("Stereo1 DMIC R Mux", SND_SOC_NOPM, 0, 0,
  2269. &rt5659_sto1_dmic_mux),
  2270. SND_SOC_DAPM_MUX("Stereo1 ADC L1 Mux", SND_SOC_NOPM, 0, 0,
  2271. &rt5659_sto1_adc1_mux),
  2272. SND_SOC_DAPM_MUX("Stereo1 ADC R1 Mux", SND_SOC_NOPM, 0, 0,
  2273. &rt5659_sto1_adc1_mux),
  2274. SND_SOC_DAPM_MUX("Stereo1 ADC L2 Mux", SND_SOC_NOPM, 0, 0,
  2275. &rt5659_sto1_adc2_mux),
  2276. SND_SOC_DAPM_MUX("Stereo1 ADC R2 Mux", SND_SOC_NOPM, 0, 0,
  2277. &rt5659_sto1_adc2_mux),
  2278. SND_SOC_DAPM_MUX("Stereo1 ADC L Mux", SND_SOC_NOPM, 0, 0,
  2279. &rt5659_sto1_adc_mux),
  2280. SND_SOC_DAPM_MUX("Stereo1 ADC R Mux", SND_SOC_NOPM, 0, 0,
  2281. &rt5659_sto1_adc_mux),
  2282. SND_SOC_DAPM_MUX("Mono ADC L2 Mux", SND_SOC_NOPM, 0, 0,
  2283. &rt5659_mono_adc_l2_mux),
  2284. SND_SOC_DAPM_MUX("Mono ADC R2 Mux", SND_SOC_NOPM, 0, 0,
  2285. &rt5659_mono_adc_r2_mux),
  2286. SND_SOC_DAPM_MUX("Mono ADC L1 Mux", SND_SOC_NOPM, 0, 0,
  2287. &rt5659_mono_adc_l1_mux),
  2288. SND_SOC_DAPM_MUX("Mono ADC R1 Mux", SND_SOC_NOPM, 0, 0,
  2289. &rt5659_mono_adc_r1_mux),
  2290. SND_SOC_DAPM_MUX("Mono DMIC L Mux", SND_SOC_NOPM, 0, 0,
  2291. &rt5659_mono_dmic_l_mux),
  2292. SND_SOC_DAPM_MUX("Mono DMIC R Mux", SND_SOC_NOPM, 0, 0,
  2293. &rt5659_mono_dmic_r_mux),
  2294. SND_SOC_DAPM_MUX("Mono ADC L Mux", SND_SOC_NOPM, 0, 0,
  2295. &rt5659_mono_adc_l_mux),
  2296. SND_SOC_DAPM_MUX("Mono ADC R Mux", SND_SOC_NOPM, 0, 0,
  2297. &rt5659_mono_adc_r_mux),
  2298. /* ADC Mixer */
  2299. SND_SOC_DAPM_SUPPLY("ADC Stereo1 Filter", RT5659_PWR_DIG_2,
  2300. RT5659_PWR_ADC_S1F_BIT, 0, NULL, 0),
  2301. SND_SOC_DAPM_SUPPLY("ADC Stereo2 Filter", RT5659_PWR_DIG_2,
  2302. RT5659_PWR_ADC_S2F_BIT, 0, NULL, 0),
  2303. SND_SOC_DAPM_MIXER("Stereo1 ADC MIXL", SND_SOC_NOPM,
  2304. 0, 0, rt5659_sto1_adc_l_mix,
  2305. ARRAY_SIZE(rt5659_sto1_adc_l_mix)),
  2306. SND_SOC_DAPM_MIXER("Stereo1 ADC MIXR", SND_SOC_NOPM,
  2307. 0, 0, rt5659_sto1_adc_r_mix,
  2308. ARRAY_SIZE(rt5659_sto1_adc_r_mix)),
  2309. SND_SOC_DAPM_SUPPLY("ADC Mono Left Filter", RT5659_PWR_DIG_2,
  2310. RT5659_PWR_ADC_MF_L_BIT, 0, NULL, 0),
  2311. SND_SOC_DAPM_MIXER("Mono ADC MIXL", RT5659_MONO_ADC_DIG_VOL,
  2312. RT5659_L_MUTE_SFT, 1, rt5659_mono_adc_l_mix,
  2313. ARRAY_SIZE(rt5659_mono_adc_l_mix)),
  2314. SND_SOC_DAPM_SUPPLY("ADC Mono Right Filter", RT5659_PWR_DIG_2,
  2315. RT5659_PWR_ADC_MF_R_BIT, 0, NULL, 0),
  2316. SND_SOC_DAPM_MIXER("Mono ADC MIXR", RT5659_MONO_ADC_DIG_VOL,
  2317. RT5659_R_MUTE_SFT, 1, rt5659_mono_adc_r_mix,
  2318. ARRAY_SIZE(rt5659_mono_adc_r_mix)),
  2319. /* ADC PGA */
  2320. SND_SOC_DAPM_PGA("IF_ADC1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2321. SND_SOC_DAPM_PGA("IF_ADC2", SND_SOC_NOPM, 0, 0, NULL, 0),
  2322. SND_SOC_DAPM_PGA("IF_ADC3", SND_SOC_NOPM, 0, 0, NULL, 0),
  2323. SND_SOC_DAPM_PGA("IF1_ADC1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2324. SND_SOC_DAPM_PGA("IF1_ADC2", SND_SOC_NOPM, 0, 0, NULL, 0),
  2325. SND_SOC_DAPM_PGA("IF1_ADC3", SND_SOC_NOPM, 0, 0, NULL, 0),
  2326. SND_SOC_DAPM_PGA("IF1_ADC4", SND_SOC_NOPM, 0, 0, NULL, 0),
  2327. SND_SOC_DAPM_PGA("Stereo2 ADC LR", SND_SOC_NOPM, 0, 0, NULL, 0),
  2328. SND_SOC_DAPM_PGA("Stereo1 ADC Volume L", RT5659_STO1_ADC_DIG_VOL,
  2329. RT5659_L_MUTE_SFT, 1, NULL, 0),
  2330. SND_SOC_DAPM_PGA("Stereo1 ADC Volume R", RT5659_STO1_ADC_DIG_VOL,
  2331. RT5659_R_MUTE_SFT, 1, NULL, 0),
  2332. /* Digital Interface */
  2333. SND_SOC_DAPM_SUPPLY("I2S1", RT5659_PWR_DIG_1, RT5659_PWR_I2S1_BIT,
  2334. 0, NULL, 0),
  2335. SND_SOC_DAPM_PGA("IF1 DAC1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2336. SND_SOC_DAPM_PGA("IF1 DAC2", SND_SOC_NOPM, 0, 0, NULL, 0),
  2337. SND_SOC_DAPM_PGA("IF1 DAC1 L", SND_SOC_NOPM, 0, 0, NULL, 0),
  2338. SND_SOC_DAPM_PGA("IF1 DAC1 R", SND_SOC_NOPM, 0, 0, NULL, 0),
  2339. SND_SOC_DAPM_PGA("IF1 DAC2 L", SND_SOC_NOPM, 0, 0, NULL, 0),
  2340. SND_SOC_DAPM_PGA("IF1 DAC2 R", SND_SOC_NOPM, 0, 0, NULL, 0),
  2341. SND_SOC_DAPM_PGA("IF1 ADC", SND_SOC_NOPM, 0, 0, NULL, 0),
  2342. SND_SOC_DAPM_PGA("IF1 ADC L", SND_SOC_NOPM, 0, 0, NULL, 0),
  2343. SND_SOC_DAPM_PGA("IF1 ADC R", SND_SOC_NOPM, 0, 0, NULL, 0),
  2344. SND_SOC_DAPM_SUPPLY("I2S2", RT5659_PWR_DIG_1, RT5659_PWR_I2S2_BIT, 0,
  2345. NULL, 0),
  2346. SND_SOC_DAPM_PGA("IF2 DAC", SND_SOC_NOPM, 0, 0, NULL, 0),
  2347. SND_SOC_DAPM_PGA("IF2 DAC L", SND_SOC_NOPM, 0, 0, NULL, 0),
  2348. SND_SOC_DAPM_PGA("IF2 DAC R", SND_SOC_NOPM, 0, 0, NULL, 0),
  2349. SND_SOC_DAPM_PGA("IF2 ADC", SND_SOC_NOPM, 0, 0, NULL, 0),
  2350. SND_SOC_DAPM_PGA("IF2 ADC1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2351. SND_SOC_DAPM_PGA("IF2 ADC2", SND_SOC_NOPM, 0, 0, NULL, 0),
  2352. SND_SOC_DAPM_SUPPLY("I2S3", RT5659_PWR_DIG_1, RT5659_PWR_I2S3_BIT, 0,
  2353. NULL, 0),
  2354. SND_SOC_DAPM_PGA("IF3 DAC", SND_SOC_NOPM, 0, 0, NULL, 0),
  2355. SND_SOC_DAPM_PGA("IF3 DAC L", SND_SOC_NOPM, 0, 0, NULL, 0),
  2356. SND_SOC_DAPM_PGA("IF3 DAC R", SND_SOC_NOPM, 0, 0, NULL, 0),
  2357. SND_SOC_DAPM_PGA("IF3 ADC", SND_SOC_NOPM, 0, 0, NULL, 0),
  2358. SND_SOC_DAPM_PGA("IF3 ADC L", SND_SOC_NOPM, 0, 0, NULL, 0),
  2359. SND_SOC_DAPM_PGA("IF3 ADC R", SND_SOC_NOPM, 0, 0, NULL, 0),
  2360. /* Digital Interface Select */
  2361. SND_SOC_DAPM_PGA("TDM AD1:AD2:DAC", SND_SOC_NOPM, 0, 0, NULL, 0),
  2362. SND_SOC_DAPM_PGA("TDM AD2:DAC", SND_SOC_NOPM, 0, 0, NULL, 0),
  2363. SND_SOC_DAPM_MUX("TDM Data Mux", SND_SOC_NOPM, 0, 0,
  2364. &rt5659_rx_adc_dac_mux),
  2365. SND_SOC_DAPM_MUX("IF2 ADC Mux", SND_SOC_NOPM, 0, 0,
  2366. &rt5659_if2_adc_in_mux),
  2367. SND_SOC_DAPM_MUX("IF3 ADC Mux", SND_SOC_NOPM, 0, 0,
  2368. &rt5659_if3_adc_in_mux),
  2369. SND_SOC_DAPM_MUX("IF1 01 ADC Swap Mux", SND_SOC_NOPM, 0, 0,
  2370. &rt5659_if1_01_adc_swap_mux),
  2371. SND_SOC_DAPM_MUX("IF1 23 ADC Swap Mux", SND_SOC_NOPM, 0, 0,
  2372. &rt5659_if1_23_adc_swap_mux),
  2373. SND_SOC_DAPM_MUX("IF1 45 ADC Swap Mux", SND_SOC_NOPM, 0, 0,
  2374. &rt5659_if1_45_adc_swap_mux),
  2375. SND_SOC_DAPM_MUX("IF1 67 ADC Swap Mux", SND_SOC_NOPM, 0, 0,
  2376. &rt5659_if1_67_adc_swap_mux),
  2377. SND_SOC_DAPM_MUX("IF2 DAC Swap Mux", SND_SOC_NOPM, 0, 0,
  2378. &rt5659_if2_dac_swap_mux),
  2379. SND_SOC_DAPM_MUX("IF2 ADC Swap Mux", SND_SOC_NOPM, 0, 0,
  2380. &rt5659_if2_adc_swap_mux),
  2381. SND_SOC_DAPM_MUX("IF3 DAC Swap Mux", SND_SOC_NOPM, 0, 0,
  2382. &rt5659_if3_dac_swap_mux),
  2383. SND_SOC_DAPM_MUX("IF3 ADC Swap Mux", SND_SOC_NOPM, 0, 0,
  2384. &rt5659_if3_adc_swap_mux),
  2385. /* Audio Interface */
  2386. SND_SOC_DAPM_AIF_IN("AIF1RX", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
  2387. SND_SOC_DAPM_AIF_OUT("AIF1TX", "AIF1 Capture", 0, SND_SOC_NOPM, 0, 0),
  2388. SND_SOC_DAPM_AIF_IN("AIF2RX", "AIF2 Playback", 0, SND_SOC_NOPM, 0, 0),
  2389. SND_SOC_DAPM_AIF_OUT("AIF2TX", "AIF2 Capture", 0, SND_SOC_NOPM, 0, 0),
  2390. SND_SOC_DAPM_AIF_IN("AIF3RX", "AIF3 Playback", 0, SND_SOC_NOPM, 0, 0),
  2391. SND_SOC_DAPM_AIF_OUT("AIF3TX", "AIF3 Capture", 0, SND_SOC_NOPM, 0, 0),
  2392. /* Output Side */
  2393. /* DAC mixer before sound effect */
  2394. SND_SOC_DAPM_MIXER("DAC1 MIXL", SND_SOC_NOPM, 0, 0,
  2395. rt5659_dac_l_mix, ARRAY_SIZE(rt5659_dac_l_mix)),
  2396. SND_SOC_DAPM_MIXER("DAC1 MIXR", SND_SOC_NOPM, 0, 0,
  2397. rt5659_dac_r_mix, ARRAY_SIZE(rt5659_dac_r_mix)),
  2398. /* DAC channel Mux */
  2399. SND_SOC_DAPM_MUX("DAC L1 Mux", SND_SOC_NOPM, 0, 0, &rt5659_dac_l1_mux),
  2400. SND_SOC_DAPM_MUX("DAC R1 Mux", SND_SOC_NOPM, 0, 0, &rt5659_dac_r1_mux),
  2401. SND_SOC_DAPM_MUX("DAC L2 Mux", SND_SOC_NOPM, 0, 0, &rt5659_dac_l2_mux),
  2402. SND_SOC_DAPM_MUX("DAC R2 Mux", SND_SOC_NOPM, 0, 0, &rt5659_dac_r2_mux),
  2403. SND_SOC_DAPM_MUX("DAC L1 Source", SND_SOC_NOPM, 0, 0,
  2404. &rt5659_alg_dac_l1_mux),
  2405. SND_SOC_DAPM_MUX("DAC R1 Source", SND_SOC_NOPM, 0, 0,
  2406. &rt5659_alg_dac_r1_mux),
  2407. SND_SOC_DAPM_MUX("DAC L2 Source", SND_SOC_NOPM, 0, 0,
  2408. &rt5659_alg_dac_l2_mux),
  2409. SND_SOC_DAPM_MUX("DAC R2 Source", SND_SOC_NOPM, 0, 0,
  2410. &rt5659_alg_dac_r2_mux),
  2411. /* DAC Mixer */
  2412. SND_SOC_DAPM_SUPPLY("DAC Stereo1 Filter", RT5659_PWR_DIG_2,
  2413. RT5659_PWR_DAC_S1F_BIT, 0, NULL, 0),
  2414. SND_SOC_DAPM_SUPPLY("DAC Mono Left Filter", RT5659_PWR_DIG_2,
  2415. RT5659_PWR_DAC_MF_L_BIT, 0, NULL, 0),
  2416. SND_SOC_DAPM_SUPPLY("DAC Mono Right Filter", RT5659_PWR_DIG_2,
  2417. RT5659_PWR_DAC_MF_R_BIT, 0, NULL, 0),
  2418. SND_SOC_DAPM_MIXER("Stereo DAC MIXL", SND_SOC_NOPM, 0, 0,
  2419. rt5659_sto_dac_l_mix, ARRAY_SIZE(rt5659_sto_dac_l_mix)),
  2420. SND_SOC_DAPM_MIXER("Stereo DAC MIXR", SND_SOC_NOPM, 0, 0,
  2421. rt5659_sto_dac_r_mix, ARRAY_SIZE(rt5659_sto_dac_r_mix)),
  2422. SND_SOC_DAPM_MIXER("Mono DAC MIXL", SND_SOC_NOPM, 0, 0,
  2423. rt5659_mono_dac_l_mix, ARRAY_SIZE(rt5659_mono_dac_l_mix)),
  2424. SND_SOC_DAPM_MIXER("Mono DAC MIXR", SND_SOC_NOPM, 0, 0,
  2425. rt5659_mono_dac_r_mix, ARRAY_SIZE(rt5659_mono_dac_r_mix)),
  2426. SND_SOC_DAPM_MUX("DAC MIXL", SND_SOC_NOPM, 0, 0,
  2427. &rt5659_dig_dac_mixl_mux),
  2428. SND_SOC_DAPM_MUX("DAC MIXR", SND_SOC_NOPM, 0, 0,
  2429. &rt5659_dig_dac_mixr_mux),
  2430. /* DACs */
  2431. SND_SOC_DAPM_SUPPLY_S("DAC L1 Power", 1, RT5659_PWR_DIG_1,
  2432. RT5659_PWR_DAC_L1_BIT, 0, NULL, 0),
  2433. SND_SOC_DAPM_SUPPLY_S("DAC R1 Power", 1, RT5659_PWR_DIG_1,
  2434. RT5659_PWR_DAC_R1_BIT, 0, NULL, 0),
  2435. SND_SOC_DAPM_DAC("DAC L1", NULL, SND_SOC_NOPM, 0, 0),
  2436. SND_SOC_DAPM_DAC("DAC R1", NULL, SND_SOC_NOPM, 0, 0),
  2437. SND_SOC_DAPM_SUPPLY("DAC L2 Power", RT5659_PWR_DIG_1,
  2438. RT5659_PWR_DAC_L2_BIT, 0, NULL, 0),
  2439. SND_SOC_DAPM_SUPPLY("DAC R2 Power", RT5659_PWR_DIG_1,
  2440. RT5659_PWR_DAC_R2_BIT, 0, NULL, 0),
  2441. SND_SOC_DAPM_DAC("DAC L2", NULL, SND_SOC_NOPM, 0, 0),
  2442. SND_SOC_DAPM_DAC("DAC R2", NULL, SND_SOC_NOPM, 0, 0),
  2443. SND_SOC_DAPM_PGA("DAC_REF", SND_SOC_NOPM, 0, 0, NULL, 0),
  2444. /* OUT Mixer */
  2445. SND_SOC_DAPM_MIXER("SPK MIXL", RT5659_PWR_MIXER, RT5659_PWR_SM_L_BIT,
  2446. 0, rt5659_spk_l_mix, ARRAY_SIZE(rt5659_spk_l_mix)),
  2447. SND_SOC_DAPM_MIXER("SPK MIXR", RT5659_PWR_MIXER, RT5659_PWR_SM_R_BIT,
  2448. 0, rt5659_spk_r_mix, ARRAY_SIZE(rt5659_spk_r_mix)),
  2449. SND_SOC_DAPM_MIXER("MONOVOL MIX", RT5659_PWR_MIXER, RT5659_PWR_MM_BIT,
  2450. 0, rt5659_monovol_mix, ARRAY_SIZE(rt5659_monovol_mix)),
  2451. SND_SOC_DAPM_MIXER("OUT MIXL", RT5659_PWR_MIXER, RT5659_PWR_OM_L_BIT,
  2452. 0, rt5659_out_l_mix, ARRAY_SIZE(rt5659_out_l_mix)),
  2453. SND_SOC_DAPM_MIXER("OUT MIXR", RT5659_PWR_MIXER, RT5659_PWR_OM_R_BIT,
  2454. 0, rt5659_out_r_mix, ARRAY_SIZE(rt5659_out_r_mix)),
  2455. /* Output Volume */
  2456. SND_SOC_DAPM_SWITCH("SPKVOL L", RT5659_PWR_VOL, RT5659_PWR_SV_L_BIT, 0,
  2457. &spkvol_l_switch),
  2458. SND_SOC_DAPM_SWITCH("SPKVOL R", RT5659_PWR_VOL, RT5659_PWR_SV_R_BIT, 0,
  2459. &spkvol_r_switch),
  2460. SND_SOC_DAPM_SWITCH("MONOVOL", RT5659_PWR_VOL, RT5659_PWR_MV_BIT, 0,
  2461. &monovol_switch),
  2462. SND_SOC_DAPM_SWITCH("OUTVOL L", RT5659_PWR_VOL, RT5659_PWR_OV_L_BIT, 0,
  2463. &outvol_l_switch),
  2464. SND_SOC_DAPM_SWITCH("OUTVOL R", RT5659_PWR_VOL, RT5659_PWR_OV_R_BIT, 0,
  2465. &outvol_r_switch),
  2466. /* SPO/MONO/HPO/LOUT */
  2467. SND_SOC_DAPM_MIXER("SPO L MIX", SND_SOC_NOPM, 0, 0, rt5659_spo_l_mix,
  2468. ARRAY_SIZE(rt5659_spo_l_mix)),
  2469. SND_SOC_DAPM_MIXER("SPO R MIX", SND_SOC_NOPM, 0, 0, rt5659_spo_r_mix,
  2470. ARRAY_SIZE(rt5659_spo_r_mix)),
  2471. SND_SOC_DAPM_MIXER("Mono MIX", SND_SOC_NOPM, 0, 0, rt5659_mono_mix,
  2472. ARRAY_SIZE(rt5659_mono_mix)),
  2473. SND_SOC_DAPM_MIXER("LOUT L MIX", SND_SOC_NOPM, 0, 0, rt5659_lout_l_mix,
  2474. ARRAY_SIZE(rt5659_lout_l_mix)),
  2475. SND_SOC_DAPM_MIXER("LOUT R MIX", SND_SOC_NOPM, 0, 0, rt5659_lout_r_mix,
  2476. ARRAY_SIZE(rt5659_lout_r_mix)),
  2477. SND_SOC_DAPM_PGA_S("SPK Amp", 1, RT5659_PWR_DIG_1, RT5659_PWR_CLS_D_BIT,
  2478. 0, rt5659_spk_event, SND_SOC_DAPM_POST_PMD |
  2479. SND_SOC_DAPM_PRE_PMU),
  2480. SND_SOC_DAPM_PGA_S("Mono Amp", 1, RT5659_PWR_ANLG_1, RT5659_PWR_MA_BIT,
  2481. 0, rt5659_mono_event, SND_SOC_DAPM_POST_PMD |
  2482. SND_SOC_DAPM_PRE_PMU),
  2483. SND_SOC_DAPM_PGA_S("HP Amp", 1, SND_SOC_NOPM, 0, 0, rt5659_hp_event,
  2484. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU),
  2485. SND_SOC_DAPM_PGA("LOUT Amp", SND_SOC_NOPM, 0, 0, NULL, 0),
  2486. SND_SOC_DAPM_SUPPLY("Charge Pump", SND_SOC_NOPM, 0, 0,
  2487. rt5659_charge_pump_event, SND_SOC_DAPM_PRE_PMU |
  2488. SND_SOC_DAPM_POST_PMD),
  2489. SND_SOC_DAPM_SWITCH("SPO Playback", SND_SOC_NOPM, 0, 0, &spo_switch),
  2490. SND_SOC_DAPM_SWITCH("Mono Playback", SND_SOC_NOPM, 0, 0,
  2491. &mono_switch),
  2492. SND_SOC_DAPM_SWITCH("HPO L Playback", SND_SOC_NOPM, 0, 0,
  2493. &hpo_l_switch),
  2494. SND_SOC_DAPM_SWITCH("HPO R Playback", SND_SOC_NOPM, 0, 0,
  2495. &hpo_r_switch),
  2496. SND_SOC_DAPM_SWITCH("LOUT L Playback", SND_SOC_NOPM, 0, 0,
  2497. &lout_l_switch),
  2498. SND_SOC_DAPM_SWITCH("LOUT R Playback", SND_SOC_NOPM, 0, 0,
  2499. &lout_r_switch),
  2500. SND_SOC_DAPM_SWITCH("PDM L Playback", SND_SOC_NOPM, 0, 0,
  2501. &pdm_l_switch),
  2502. SND_SOC_DAPM_SWITCH("PDM R Playback", SND_SOC_NOPM, 0, 0,
  2503. &pdm_r_switch),
  2504. /* PDM */
  2505. SND_SOC_DAPM_SUPPLY("PDM Power", RT5659_PWR_DIG_2,
  2506. RT5659_PWR_PDM1_BIT, 0, NULL, 0),
  2507. SND_SOC_DAPM_MUX("PDM L Mux", RT5659_PDM_OUT_CTRL,
  2508. RT5659_M_PDM1_L_SFT, 1, &rt5659_pdm_l_mux),
  2509. SND_SOC_DAPM_MUX("PDM R Mux", RT5659_PDM_OUT_CTRL,
  2510. RT5659_M_PDM1_R_SFT, 1, &rt5659_pdm_r_mux),
  2511. /* SPDIF */
  2512. SND_SOC_DAPM_MUX("SPDIF Mux", SND_SOC_NOPM, 0, 0, &rt5659_spdif_mux),
  2513. SND_SOC_DAPM_SUPPLY("SYS CLK DET", RT5659_CLK_DET, 3, 0, NULL, 0),
  2514. SND_SOC_DAPM_SUPPLY("CLKDET", RT5659_CLK_DET, 0, 0, NULL, 0),
  2515. /* Output Lines */
  2516. SND_SOC_DAPM_OUTPUT("HPOL"),
  2517. SND_SOC_DAPM_OUTPUT("HPOR"),
  2518. SND_SOC_DAPM_OUTPUT("SPOL"),
  2519. SND_SOC_DAPM_OUTPUT("SPOR"),
  2520. SND_SOC_DAPM_OUTPUT("LOUTL"),
  2521. SND_SOC_DAPM_OUTPUT("LOUTR"),
  2522. SND_SOC_DAPM_OUTPUT("MONOOUT"),
  2523. SND_SOC_DAPM_OUTPUT("PDML"),
  2524. SND_SOC_DAPM_OUTPUT("PDMR"),
  2525. SND_SOC_DAPM_OUTPUT("SPDIF"),
  2526. };
  2527. static const struct snd_soc_dapm_route rt5659_dapm_routes[] = {
  2528. /*PLL*/
  2529. { "ADC Stereo1 Filter", NULL, "PLL", is_sys_clk_from_pll },
  2530. { "ADC Stereo2 Filter", NULL, "PLL", is_sys_clk_from_pll },
  2531. { "ADC Mono Left Filter", NULL, "PLL", is_sys_clk_from_pll },
  2532. { "ADC Mono Right Filter", NULL, "PLL", is_sys_clk_from_pll },
  2533. { "DAC Stereo1 Filter", NULL, "PLL", is_sys_clk_from_pll },
  2534. { "DAC Mono Left Filter", NULL, "PLL", is_sys_clk_from_pll },
  2535. { "DAC Mono Right Filter", NULL, "PLL", is_sys_clk_from_pll },
  2536. /*ASRC*/
  2537. { "ADC Stereo1 Filter", NULL, "ADC STO1 ASRC", is_using_asrc },
  2538. { "ADC Mono Left Filter", NULL, "ADC Mono L ASRC", is_using_asrc },
  2539. { "ADC Mono Right Filter", NULL, "ADC Mono R ASRC", is_using_asrc },
  2540. { "DAC Mono Left Filter", NULL, "DAC Mono L ASRC", is_using_asrc },
  2541. { "DAC Mono Right Filter", NULL, "DAC Mono R ASRC", is_using_asrc },
  2542. { "DAC Stereo1 Filter", NULL, "DAC STO ASRC", is_using_asrc },
  2543. { "SYS CLK DET", NULL, "CLKDET" },
  2544. { "I2S1", NULL, "I2S1 ASRC" },
  2545. { "I2S2", NULL, "I2S2 ASRC" },
  2546. { "I2S3", NULL, "I2S3 ASRC" },
  2547. { "IN1P", NULL, "LDO2" },
  2548. { "IN2P", NULL, "LDO2" },
  2549. { "IN3P", NULL, "LDO2" },
  2550. { "IN4P", NULL, "LDO2" },
  2551. { "DMIC1", NULL, "DMIC L1" },
  2552. { "DMIC1", NULL, "DMIC R1" },
  2553. { "DMIC2", NULL, "DMIC L2" },
  2554. { "DMIC2", NULL, "DMIC R2" },
  2555. { "BST1", NULL, "IN1P" },
  2556. { "BST1", NULL, "IN1N" },
  2557. { "BST1", NULL, "BST1 Power" },
  2558. { "BST2", NULL, "IN2P" },
  2559. { "BST2", NULL, "IN2N" },
  2560. { "BST2", NULL, "BST2 Power" },
  2561. { "BST3", NULL, "IN3P" },
  2562. { "BST3", NULL, "IN3N" },
  2563. { "BST3", NULL, "BST3 Power" },
  2564. { "BST4", NULL, "IN4P" },
  2565. { "BST4", NULL, "IN4N" },
  2566. { "BST4", NULL, "BST4 Power" },
  2567. { "INL VOL", NULL, "IN2P" },
  2568. { "INR VOL", NULL, "IN2N" },
  2569. { "RECMIX1L", "SPKVOLL Switch", "SPKVOL L" },
  2570. { "RECMIX1L", "INL Switch", "INL VOL" },
  2571. { "RECMIX1L", "BST4 Switch", "BST4" },
  2572. { "RECMIX1L", "BST3 Switch", "BST3" },
  2573. { "RECMIX1L", "BST2 Switch", "BST2" },
  2574. { "RECMIX1L", "BST1 Switch", "BST1" },
  2575. { "RECMIX1R", "HPOVOLR Switch", "HPO R Playback" },
  2576. { "RECMIX1R", "INR Switch", "INR VOL" },
  2577. { "RECMIX1R", "BST4 Switch", "BST4" },
  2578. { "RECMIX1R", "BST3 Switch", "BST3" },
  2579. { "RECMIX1R", "BST2 Switch", "BST2" },
  2580. { "RECMIX1R", "BST1 Switch", "BST1" },
  2581. { "RECMIX2L", "SPKVOLL Switch", "SPKVOL L" },
  2582. { "RECMIX2L", "OUTVOLL Switch", "OUTVOL L" },
  2583. { "RECMIX2L", "BST4 Switch", "BST4" },
  2584. { "RECMIX2L", "BST3 Switch", "BST3" },
  2585. { "RECMIX2L", "BST2 Switch", "BST2" },
  2586. { "RECMIX2L", "BST1 Switch", "BST1" },
  2587. { "RECMIX2R", "MONOVOL Switch", "MONOVOL" },
  2588. { "RECMIX2R", "OUTVOLR Switch", "OUTVOL R" },
  2589. { "RECMIX2R", "BST4 Switch", "BST4" },
  2590. { "RECMIX2R", "BST3 Switch", "BST3" },
  2591. { "RECMIX2R", "BST2 Switch", "BST2" },
  2592. { "RECMIX2R", "BST1 Switch", "BST1" },
  2593. { "ADC1 L", NULL, "RECMIX1L" },
  2594. { "ADC1 L", NULL, "ADC1 L Power" },
  2595. { "ADC1 L", NULL, "ADC1 clock" },
  2596. { "ADC1 R", NULL, "RECMIX1R" },
  2597. { "ADC1 R", NULL, "ADC1 R Power" },
  2598. { "ADC1 R", NULL, "ADC1 clock" },
  2599. { "ADC2 L", NULL, "RECMIX2L" },
  2600. { "ADC2 L", NULL, "ADC2 L Power" },
  2601. { "ADC2 L", NULL, "ADC2 clock" },
  2602. { "ADC2 R", NULL, "RECMIX2R" },
  2603. { "ADC2 R", NULL, "ADC2 R Power" },
  2604. { "ADC2 R", NULL, "ADC2 clock" },
  2605. { "DMIC L1", NULL, "DMIC CLK" },
  2606. { "DMIC L1", NULL, "DMIC1 Power" },
  2607. { "DMIC R1", NULL, "DMIC CLK" },
  2608. { "DMIC R1", NULL, "DMIC1 Power" },
  2609. { "DMIC L2", NULL, "DMIC CLK" },
  2610. { "DMIC L2", NULL, "DMIC2 Power" },
  2611. { "DMIC R2", NULL, "DMIC CLK" },
  2612. { "DMIC R2", NULL, "DMIC2 Power" },
  2613. { "Stereo1 DMIC L Mux", "DMIC1", "DMIC L1" },
  2614. { "Stereo1 DMIC L Mux", "DMIC2", "DMIC L2" },
  2615. { "Stereo1 DMIC R Mux", "DMIC1", "DMIC R1" },
  2616. { "Stereo1 DMIC R Mux", "DMIC2", "DMIC R2" },
  2617. { "Mono DMIC L Mux", "DMIC1 L", "DMIC L1" },
  2618. { "Mono DMIC L Mux", "DMIC2 L", "DMIC L2" },
  2619. { "Mono DMIC R Mux", "DMIC1 R", "DMIC R1" },
  2620. { "Mono DMIC R Mux", "DMIC2 R", "DMIC R2" },
  2621. { "Stereo1 ADC L Mux", "ADC1", "ADC1 L" },
  2622. { "Stereo1 ADC L Mux", "ADC2", "ADC2 L" },
  2623. { "Stereo1 ADC R Mux", "ADC1", "ADC1 R" },
  2624. { "Stereo1 ADC R Mux", "ADC2", "ADC2 R" },
  2625. { "Stereo1 ADC L1 Mux", "ADC", "Stereo1 ADC L Mux" },
  2626. { "Stereo1 ADC L1 Mux", "DAC MIX", "DAC MIXL" },
  2627. { "Stereo1 ADC L2 Mux", "DMIC", "Stereo1 DMIC L Mux" },
  2628. { "Stereo1 ADC L2 Mux", "DAC MIX", "DAC MIXL" },
  2629. { "Stereo1 ADC R1 Mux", "ADC", "Stereo1 ADC R Mux" },
  2630. { "Stereo1 ADC R1 Mux", "DAC MIX", "DAC MIXR" },
  2631. { "Stereo1 ADC R2 Mux", "DMIC", "Stereo1 DMIC R Mux" },
  2632. { "Stereo1 ADC R2 Mux", "DAC MIX", "DAC MIXR" },
  2633. { "Mono ADC L Mux", "ADC1 L", "ADC1 L" },
  2634. { "Mono ADC L Mux", "ADC1 R", "ADC1 R" },
  2635. { "Mono ADC L Mux", "ADC2 L", "ADC2 L" },
  2636. { "Mono ADC L Mux", "ADC2 R", "ADC2 R" },
  2637. { "Mono ADC R Mux", "ADC1 L", "ADC1 L" },
  2638. { "Mono ADC R Mux", "ADC1 R", "ADC1 R" },
  2639. { "Mono ADC R Mux", "ADC2 L", "ADC2 L" },
  2640. { "Mono ADC R Mux", "ADC2 R", "ADC2 R" },
  2641. { "Mono ADC L2 Mux", "DMIC", "Mono DMIC L Mux" },
  2642. { "Mono ADC L2 Mux", "Mono DAC MIXL", "Mono DAC MIXL" },
  2643. { "Mono ADC L1 Mux", "Mono DAC MIXL", "Mono DAC MIXL" },
  2644. { "Mono ADC L1 Mux", "ADC", "Mono ADC L Mux" },
  2645. { "Mono ADC R1 Mux", "Mono DAC MIXR", "Mono DAC MIXR" },
  2646. { "Mono ADC R1 Mux", "ADC", "Mono ADC R Mux" },
  2647. { "Mono ADC R2 Mux", "DMIC", "Mono DMIC R Mux" },
  2648. { "Mono ADC R2 Mux", "Mono DAC MIXR", "Mono DAC MIXR" },
  2649. { "Stereo1 ADC MIXL", "ADC1 Switch", "Stereo1 ADC L1 Mux" },
  2650. { "Stereo1 ADC MIXL", "ADC2 Switch", "Stereo1 ADC L2 Mux" },
  2651. { "Stereo1 ADC MIXL", NULL, "ADC Stereo1 Filter" },
  2652. { "Stereo1 ADC MIXR", "ADC1 Switch", "Stereo1 ADC R1 Mux" },
  2653. { "Stereo1 ADC MIXR", "ADC2 Switch", "Stereo1 ADC R2 Mux" },
  2654. { "Stereo1 ADC MIXR", NULL, "ADC Stereo1 Filter" },
  2655. { "Mono ADC MIXL", "ADC1 Switch", "Mono ADC L1 Mux" },
  2656. { "Mono ADC MIXL", "ADC2 Switch", "Mono ADC L2 Mux" },
  2657. { "Mono ADC MIXL", NULL, "ADC Mono Left Filter" },
  2658. { "Mono ADC MIXR", "ADC1 Switch", "Mono ADC R1 Mux" },
  2659. { "Mono ADC MIXR", "ADC2 Switch", "Mono ADC R2 Mux" },
  2660. { "Mono ADC MIXR", NULL, "ADC Mono Right Filter" },
  2661. { "Stereo1 ADC Volume L", NULL, "Stereo1 ADC MIXL" },
  2662. { "Stereo1 ADC Volume R", NULL, "Stereo1 ADC MIXR" },
  2663. { "IF_ADC1", NULL, "Stereo1 ADC Volume L" },
  2664. { "IF_ADC1", NULL, "Stereo1 ADC Volume R" },
  2665. { "IF_ADC2", NULL, "Mono ADC MIXL" },
  2666. { "IF_ADC2", NULL, "Mono ADC MIXR" },
  2667. { "TDM AD1:AD2:DAC", NULL, "IF_ADC1" },
  2668. { "TDM AD1:AD2:DAC", NULL, "IF_ADC2" },
  2669. { "TDM AD1:AD2:DAC", NULL, "DAC_REF" },
  2670. { "TDM AD2:DAC", NULL, "IF_ADC2" },
  2671. { "TDM AD2:DAC", NULL, "DAC_REF" },
  2672. { "TDM Data Mux", "AD1:AD2:DAC:NUL", "TDM AD1:AD2:DAC" },
  2673. { "TDM Data Mux", "AD1:AD2:NUL:DAC", "TDM AD1:AD2:DAC" },
  2674. { "TDM Data Mux", "AD1:DAC:AD2:NUL", "TDM AD1:AD2:DAC" },
  2675. { "TDM Data Mux", "AD1:DAC:NUL:AD2", "TDM AD1:AD2:DAC" },
  2676. { "TDM Data Mux", "AD1:NUL:DAC:AD2", "TDM AD1:AD2:DAC" },
  2677. { "TDM Data Mux", "AD1:NUL:AD2:DAC", "TDM AD1:AD2:DAC" },
  2678. { "TDM Data Mux", "AD2:AD1:DAC:NUL", "TDM AD1:AD2:DAC" },
  2679. { "TDM Data Mux", "AD2:AD1:NUL:DAC", "TDM AD1:AD2:DAC" },
  2680. { "TDM Data Mux", "AD2:DAC:AD1:NUL", "TDM AD1:AD2:DAC" },
  2681. { "TDM Data Mux", "AD2:DAC:NUL:AD1", "TDM AD1:AD2:DAC" },
  2682. { "TDM Data Mux", "AD2:NUL:DAC:AD1", "TDM AD1:AD2:DAC" },
  2683. { "TDM Data Mux", "AD1:NUL:AD1:DAC", "TDM AD1:AD2:DAC" },
  2684. { "TDM Data Mux", "DAC:AD1:AD2:NUL", "TDM AD1:AD2:DAC" },
  2685. { "TDM Data Mux", "DAC:AD1:NUL:AD2", "TDM AD1:AD2:DAC" },
  2686. { "TDM Data Mux", "DAC:AD2:AD1:NUL", "TDM AD1:AD2:DAC" },
  2687. { "TDM Data Mux", "DAC:AD2:NUL:AD1", "TDM AD1:AD2:DAC" },
  2688. { "TDM Data Mux", "DAC:NUL:DAC:AD2", "TDM AD2:DAC" },
  2689. { "TDM Data Mux", "DAC:NUL:AD2:DAC", "TDM AD2:DAC" },
  2690. { "TDM Data Mux", "NUL:AD1:AD2:DAC", "TDM AD1:AD2:DAC" },
  2691. { "TDM Data Mux", "NUL:AD1:DAC:AD2", "TDM AD1:AD2:DAC" },
  2692. { "TDM Data Mux", "NUL:AD2:AD1:DAC", "TDM AD1:AD2:DAC" },
  2693. { "TDM Data Mux", "NUL:AD2:DAC:AD1", "TDM AD1:AD2:DAC" },
  2694. { "TDM Data Mux", "NUL:DAC:DAC:AD2", "TDM AD2:DAC" },
  2695. { "TDM Data Mux", "NUL:DAC:AD2:DAC", "TDM AD2:DAC" },
  2696. { "IF1 01 ADC Swap Mux", "L/R", "TDM Data Mux" },
  2697. { "IF1 01 ADC Swap Mux", "R/L", "TDM Data Mux" },
  2698. { "IF1 01 ADC Swap Mux", "L/L", "TDM Data Mux" },
  2699. { "IF1 01 ADC Swap Mux", "R/R", "TDM Data Mux" },
  2700. { "IF1 23 ADC Swap Mux", "L/R", "TDM Data Mux" },
  2701. { "IF1 23 ADC Swap Mux", "R/L", "TDM Data Mux" },
  2702. { "IF1 23 ADC Swap Mux", "L/L", "TDM Data Mux" },
  2703. { "IF1 23 ADC Swap Mux", "R/R", "TDM Data Mux" },
  2704. { "IF1 45 ADC Swap Mux", "L/R", "TDM Data Mux" },
  2705. { "IF1 45 ADC Swap Mux", "R/L", "TDM Data Mux" },
  2706. { "IF1 45 ADC Swap Mux", "L/L", "TDM Data Mux" },
  2707. { "IF1 45 ADC Swap Mux", "R/R", "TDM Data Mux" },
  2708. { "IF1 67 ADC Swap Mux", "L/R", "TDM Data Mux" },
  2709. { "IF1 67 ADC Swap Mux", "R/L", "TDM Data Mux" },
  2710. { "IF1 67 ADC Swap Mux", "L/L", "TDM Data Mux" },
  2711. { "IF1 67 ADC Swap Mux", "R/R", "TDM Data Mux" },
  2712. { "IF1 ADC", NULL, "IF1 01 ADC Swap Mux" },
  2713. { "IF1 ADC", NULL, "IF1 23 ADC Swap Mux" },
  2714. { "IF1 ADC", NULL, "IF1 45 ADC Swap Mux" },
  2715. { "IF1 ADC", NULL, "IF1 67 ADC Swap Mux" },
  2716. { "IF1 ADC", NULL, "I2S1" },
  2717. { "IF2 ADC Mux", "IF_ADC1", "IF_ADC1" },
  2718. { "IF2 ADC Mux", "IF_ADC2", "IF_ADC2" },
  2719. { "IF2 ADC Mux", "IF_ADC3", "IF_ADC3" },
  2720. { "IF2 ADC Mux", "DAC_REF", "DAC_REF" },
  2721. { "IF2 ADC", NULL, "IF2 ADC Mux"},
  2722. { "IF2 ADC", NULL, "I2S2" },
  2723. { "IF3 ADC Mux", "IF_ADC1", "IF_ADC1" },
  2724. { "IF3 ADC Mux", "IF_ADC2", "IF_ADC2" },
  2725. { "IF3 ADC Mux", "Stereo2_ADC_L/R", "Stereo2 ADC LR" },
  2726. { "IF3 ADC Mux", "DAC_REF", "DAC_REF" },
  2727. { "IF3 ADC", NULL, "IF3 ADC Mux"},
  2728. { "IF3 ADC", NULL, "I2S3" },
  2729. { "AIF1TX", NULL, "IF1 ADC" },
  2730. { "IF2 ADC Swap Mux", "L/R", "IF2 ADC" },
  2731. { "IF2 ADC Swap Mux", "R/L", "IF2 ADC" },
  2732. { "IF2 ADC Swap Mux", "L/L", "IF2 ADC" },
  2733. { "IF2 ADC Swap Mux", "R/R", "IF2 ADC" },
  2734. { "AIF2TX", NULL, "IF2 ADC Swap Mux" },
  2735. { "IF3 ADC Swap Mux", "L/R", "IF3 ADC" },
  2736. { "IF3 ADC Swap Mux", "R/L", "IF3 ADC" },
  2737. { "IF3 ADC Swap Mux", "L/L", "IF3 ADC" },
  2738. { "IF3 ADC Swap Mux", "R/R", "IF3 ADC" },
  2739. { "AIF3TX", NULL, "IF3 ADC Swap Mux" },
  2740. { "IF1 DAC1", NULL, "AIF1RX" },
  2741. { "IF1 DAC2", NULL, "AIF1RX" },
  2742. { "IF2 DAC Swap Mux", "L/R", "AIF2RX" },
  2743. { "IF2 DAC Swap Mux", "R/L", "AIF2RX" },
  2744. { "IF2 DAC Swap Mux", "L/L", "AIF2RX" },
  2745. { "IF2 DAC Swap Mux", "R/R", "AIF2RX" },
  2746. { "IF2 DAC", NULL, "IF2 DAC Swap Mux" },
  2747. { "IF3 DAC Swap Mux", "L/R", "AIF3RX" },
  2748. { "IF3 DAC Swap Mux", "R/L", "AIF3RX" },
  2749. { "IF3 DAC Swap Mux", "L/L", "AIF3RX" },
  2750. { "IF3 DAC Swap Mux", "R/R", "AIF3RX" },
  2751. { "IF3 DAC", NULL, "IF3 DAC Swap Mux" },
  2752. { "IF1 DAC1", NULL, "I2S1" },
  2753. { "IF1 DAC2", NULL, "I2S1" },
  2754. { "IF2 DAC", NULL, "I2S2" },
  2755. { "IF3 DAC", NULL, "I2S3" },
  2756. { "IF1 DAC2 L", NULL, "IF1 DAC2" },
  2757. { "IF1 DAC2 R", NULL, "IF1 DAC2" },
  2758. { "IF1 DAC1 L", NULL, "IF1 DAC1" },
  2759. { "IF1 DAC1 R", NULL, "IF1 DAC1" },
  2760. { "IF2 DAC L", NULL, "IF2 DAC" },
  2761. { "IF2 DAC R", NULL, "IF2 DAC" },
  2762. { "IF3 DAC L", NULL, "IF3 DAC" },
  2763. { "IF3 DAC R", NULL, "IF3 DAC" },
  2764. { "DAC L1 Mux", "IF1 DAC1", "IF1 DAC1 L" },
  2765. { "DAC L1 Mux", "IF2 DAC", "IF2 DAC L" },
  2766. { "DAC L1 Mux", "IF3 DAC", "IF3 DAC L" },
  2767. { "DAC L1 Mux", NULL, "DAC Stereo1 Filter" },
  2768. { "DAC R1 Mux", "IF1 DAC1", "IF1 DAC1 R" },
  2769. { "DAC R1 Mux", "IF2 DAC", "IF2 DAC R" },
  2770. { "DAC R1 Mux", "IF3 DAC", "IF3 DAC R" },
  2771. { "DAC R1 Mux", NULL, "DAC Stereo1 Filter" },
  2772. { "DAC1 MIXL", "Stereo ADC Switch", "Stereo1 ADC Volume L" },
  2773. { "DAC1 MIXL", "DAC1 Switch", "DAC L1 Mux" },
  2774. { "DAC1 MIXR", "Stereo ADC Switch", "Stereo1 ADC Volume R" },
  2775. { "DAC1 MIXR", "DAC1 Switch", "DAC R1 Mux" },
  2776. { "DAC_REF", NULL, "DAC1 MIXL" },
  2777. { "DAC_REF", NULL, "DAC1 MIXR" },
  2778. { "DAC L2 Mux", "IF1 DAC2", "IF1 DAC2 L" },
  2779. { "DAC L2 Mux", "IF2 DAC", "IF2 DAC L" },
  2780. { "DAC L2 Mux", "IF3 DAC", "IF3 DAC L" },
  2781. { "DAC L2 Mux", "Mono ADC MIX", "Mono ADC MIXL" },
  2782. { "DAC L2 Mux", NULL, "DAC Mono Left Filter" },
  2783. { "DAC R2 Mux", "IF1 DAC2", "IF1 DAC2 R" },
  2784. { "DAC R2 Mux", "IF2 DAC", "IF2 DAC R" },
  2785. { "DAC R2 Mux", "IF3 DAC", "IF3 DAC R" },
  2786. { "DAC R2 Mux", "Mono ADC MIX", "Mono ADC MIXR" },
  2787. { "DAC R2 Mux", NULL, "DAC Mono Right Filter" },
  2788. { "Stereo DAC MIXL", "DAC L1 Switch", "DAC1 MIXL" },
  2789. { "Stereo DAC MIXL", "DAC R1 Switch", "DAC1 MIXR" },
  2790. { "Stereo DAC MIXL", "DAC L2 Switch", "DAC L2 Mux" },
  2791. { "Stereo DAC MIXL", "DAC R2 Switch", "DAC R2 Mux" },
  2792. { "Stereo DAC MIXR", "DAC R1 Switch", "DAC1 MIXR" },
  2793. { "Stereo DAC MIXR", "DAC L1 Switch", "DAC1 MIXL" },
  2794. { "Stereo DAC MIXR", "DAC L2 Switch", "DAC L2 Mux" },
  2795. { "Stereo DAC MIXR", "DAC R2 Switch", "DAC R2 Mux" },
  2796. { "Mono DAC MIXL", "DAC L1 Switch", "DAC1 MIXL" },
  2797. { "Mono DAC MIXL", "DAC R1 Switch", "DAC1 MIXR" },
  2798. { "Mono DAC MIXL", "DAC L2 Switch", "DAC L2 Mux" },
  2799. { "Mono DAC MIXL", "DAC R2 Switch", "DAC R2 Mux" },
  2800. { "Mono DAC MIXR", "DAC L1 Switch", "DAC1 MIXL" },
  2801. { "Mono DAC MIXR", "DAC R1 Switch", "DAC1 MIXR" },
  2802. { "Mono DAC MIXR", "DAC R2 Switch", "DAC R2 Mux" },
  2803. { "Mono DAC MIXR", "DAC L2 Switch", "DAC L2 Mux" },
  2804. { "DAC MIXL", "Stereo DAC Mixer", "Stereo DAC MIXL" },
  2805. { "DAC MIXL", "Mono DAC Mixer", "Mono DAC MIXL" },
  2806. { "DAC MIXR", "Stereo DAC Mixer", "Stereo DAC MIXR" },
  2807. { "DAC MIXR", "Mono DAC Mixer", "Mono DAC MIXR" },
  2808. { "DAC L1 Source", NULL, "DAC L1 Power" },
  2809. { "DAC L1 Source", "DAC", "DAC1 MIXL" },
  2810. { "DAC L1 Source", "Stereo DAC Mixer", "Stereo DAC MIXL" },
  2811. { "DAC R1 Source", NULL, "DAC R1 Power" },
  2812. { "DAC R1 Source", "DAC", "DAC1 MIXR" },
  2813. { "DAC R1 Source", "Stereo DAC Mixer", "Stereo DAC MIXR" },
  2814. { "DAC L2 Source", "Stereo DAC Mixer", "Stereo DAC MIXL" },
  2815. { "DAC L2 Source", "Mono DAC Mixer", "Mono DAC MIXL" },
  2816. { "DAC L2 Source", NULL, "DAC L2 Power" },
  2817. { "DAC R2 Source", "Stereo DAC Mixer", "Stereo DAC MIXR" },
  2818. { "DAC R2 Source", "Mono DAC Mixer", "Mono DAC MIXR" },
  2819. { "DAC R2 Source", NULL, "DAC R2 Power" },
  2820. { "DAC L1", NULL, "DAC L1 Source" },
  2821. { "DAC R1", NULL, "DAC R1 Source" },
  2822. { "DAC L2", NULL, "DAC L2 Source" },
  2823. { "DAC R2", NULL, "DAC R2 Source" },
  2824. { "SPK MIXL", "DAC L2 Switch", "DAC L2" },
  2825. { "SPK MIXL", "BST1 Switch", "BST1" },
  2826. { "SPK MIXL", "INL Switch", "INL VOL" },
  2827. { "SPK MIXL", "INR Switch", "INR VOL" },
  2828. { "SPK MIXL", "BST3 Switch", "BST3" },
  2829. { "SPK MIXR", "DAC R2 Switch", "DAC R2" },
  2830. { "SPK MIXR", "BST4 Switch", "BST4" },
  2831. { "SPK MIXR", "INL Switch", "INL VOL" },
  2832. { "SPK MIXR", "INR Switch", "INR VOL" },
  2833. { "SPK MIXR", "BST3 Switch", "BST3" },
  2834. { "MONOVOL MIX", "DAC L2 Switch", "DAC L2" },
  2835. { "MONOVOL MIX", "DAC R2 Switch", "DAC R2" },
  2836. { "MONOVOL MIX", "BST1 Switch", "BST1" },
  2837. { "MONOVOL MIX", "BST2 Switch", "BST2" },
  2838. { "MONOVOL MIX", "BST3 Switch", "BST3" },
  2839. { "OUT MIXL", "DAC L2 Switch", "DAC L2" },
  2840. { "OUT MIXL", "INL Switch", "INL VOL" },
  2841. { "OUT MIXL", "BST1 Switch", "BST1" },
  2842. { "OUT MIXL", "BST2 Switch", "BST2" },
  2843. { "OUT MIXL", "BST3 Switch", "BST3" },
  2844. { "OUT MIXR", "DAC R2 Switch", "DAC R2" },
  2845. { "OUT MIXR", "INR Switch", "INR VOL" },
  2846. { "OUT MIXR", "BST2 Switch", "BST2" },
  2847. { "OUT MIXR", "BST3 Switch", "BST3" },
  2848. { "OUT MIXR", "BST4 Switch", "BST4" },
  2849. { "SPKVOL L", "Switch", "SPK MIXL" },
  2850. { "SPKVOL R", "Switch", "SPK MIXR" },
  2851. { "SPO L MIX", "DAC L2 Switch", "DAC L2" },
  2852. { "SPO L MIX", "SPKVOL L Switch", "SPKVOL L" },
  2853. { "SPO R MIX", "DAC R2 Switch", "DAC R2" },
  2854. { "SPO R MIX", "SPKVOL R Switch", "SPKVOL R" },
  2855. { "SPK Amp", NULL, "SPO L MIX" },
  2856. { "SPK Amp", NULL, "SPO R MIX" },
  2857. { "SPK Amp", NULL, "SYS CLK DET" },
  2858. { "SPO Playback", "Switch", "SPK Amp" },
  2859. { "SPOL", NULL, "SPO Playback" },
  2860. { "SPOR", NULL, "SPO Playback" },
  2861. { "MONOVOL", "Switch", "MONOVOL MIX" },
  2862. { "Mono MIX", "DAC L2 Switch", "DAC L2" },
  2863. { "Mono MIX", "MONOVOL Switch", "MONOVOL" },
  2864. { "Mono Amp", NULL, "Mono MIX" },
  2865. { "Mono Amp", NULL, "Mono Vref" },
  2866. { "Mono Amp", NULL, "SYS CLK DET" },
  2867. { "Mono Playback", "Switch", "Mono Amp" },
  2868. { "MONOOUT", NULL, "Mono Playback" },
  2869. { "HP Amp", NULL, "DAC L1" },
  2870. { "HP Amp", NULL, "DAC R1" },
  2871. { "HP Amp", NULL, "Charge Pump" },
  2872. { "HP Amp", NULL, "SYS CLK DET" },
  2873. { "HPO L Playback", "Switch", "HP Amp"},
  2874. { "HPO R Playback", "Switch", "HP Amp"},
  2875. { "HPOL", NULL, "HPO L Playback" },
  2876. { "HPOR", NULL, "HPO R Playback" },
  2877. { "OUTVOL L", "Switch", "OUT MIXL" },
  2878. { "OUTVOL R", "Switch", "OUT MIXR" },
  2879. { "LOUT L MIX", "DAC L2 Switch", "DAC L2" },
  2880. { "LOUT L MIX", "OUTVOL L Switch", "OUTVOL L" },
  2881. { "LOUT R MIX", "DAC R2 Switch", "DAC R2" },
  2882. { "LOUT R MIX", "OUTVOL R Switch", "OUTVOL R" },
  2883. { "LOUT Amp", NULL, "LOUT L MIX" },
  2884. { "LOUT Amp", NULL, "LOUT R MIX" },
  2885. { "LOUT Amp", NULL, "SYS CLK DET" },
  2886. { "LOUT L Playback", "Switch", "LOUT Amp" },
  2887. { "LOUT R Playback", "Switch", "LOUT Amp" },
  2888. { "LOUTL", NULL, "LOUT L Playback" },
  2889. { "LOUTR", NULL, "LOUT R Playback" },
  2890. { "PDM L Mux", "Mono DAC", "Mono DAC MIXL" },
  2891. { "PDM L Mux", "Stereo DAC", "Stereo DAC MIXL" },
  2892. { "PDM L Mux", NULL, "PDM Power" },
  2893. { "PDM R Mux", "Mono DAC", "Mono DAC MIXR" },
  2894. { "PDM R Mux", "Stereo DAC", "Stereo DAC MIXR" },
  2895. { "PDM R Mux", NULL, "PDM Power" },
  2896. { "PDM L Playback", "Switch", "PDM L Mux" },
  2897. { "PDM R Playback", "Switch", "PDM R Mux" },
  2898. { "PDML", NULL, "PDM L Playback" },
  2899. { "PDMR", NULL, "PDM R Playback" },
  2900. { "SPDIF Mux", "IF3_DAC", "IF3 DAC" },
  2901. { "SPDIF Mux", "IF2_DAC", "IF2 DAC" },
  2902. { "SPDIF Mux", "IF1_DAC2", "IF1 DAC2" },
  2903. { "SPDIF Mux", "IF1_DAC1", "IF1 DAC1" },
  2904. { "SPDIF", NULL, "SPDIF Mux" },
  2905. };
  2906. static int rt5659_hw_params(struct snd_pcm_substream *substream,
  2907. struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
  2908. {
  2909. struct snd_soc_codec *codec = dai->codec;
  2910. struct rt5659_priv *rt5659 = snd_soc_codec_get_drvdata(codec);
  2911. unsigned int val_len = 0, val_clk, mask_clk;
  2912. int pre_div, frame_size;
  2913. rt5659->lrck[dai->id] = params_rate(params);
  2914. pre_div = rl6231_get_clk_info(rt5659->sysclk, rt5659->lrck[dai->id]);
  2915. if (pre_div < 0) {
  2916. dev_err(codec->dev, "Unsupported clock setting %d for DAI %d\n",
  2917. rt5659->lrck[dai->id], dai->id);
  2918. return -EINVAL;
  2919. }
  2920. frame_size = snd_soc_params_to_frame_size(params);
  2921. if (frame_size < 0) {
  2922. dev_err(codec->dev, "Unsupported frame size: %d\n", frame_size);
  2923. return -EINVAL;
  2924. }
  2925. dev_dbg(dai->dev, "lrck is %dHz and pre_div is %d for iis %d\n",
  2926. rt5659->lrck[dai->id], pre_div, dai->id);
  2927. switch (params_width(params)) {
  2928. case 16:
  2929. break;
  2930. case 20:
  2931. val_len |= RT5659_I2S_DL_20;
  2932. break;
  2933. case 24:
  2934. val_len |= RT5659_I2S_DL_24;
  2935. break;
  2936. case 8:
  2937. val_len |= RT5659_I2S_DL_8;
  2938. break;
  2939. default:
  2940. return -EINVAL;
  2941. }
  2942. switch (dai->id) {
  2943. case RT5659_AIF1:
  2944. mask_clk = RT5659_I2S_PD1_MASK;
  2945. val_clk = pre_div << RT5659_I2S_PD1_SFT;
  2946. snd_soc_update_bits(codec, RT5659_I2S1_SDP,
  2947. RT5659_I2S_DL_MASK, val_len);
  2948. break;
  2949. case RT5659_AIF2:
  2950. mask_clk = RT5659_I2S_PD2_MASK;
  2951. val_clk = pre_div << RT5659_I2S_PD2_SFT;
  2952. snd_soc_update_bits(codec, RT5659_I2S2_SDP,
  2953. RT5659_I2S_DL_MASK, val_len);
  2954. break;
  2955. case RT5659_AIF3:
  2956. mask_clk = RT5659_I2S_PD3_MASK;
  2957. val_clk = pre_div << RT5659_I2S_PD3_SFT;
  2958. snd_soc_update_bits(codec, RT5659_I2S3_SDP,
  2959. RT5659_I2S_DL_MASK, val_len);
  2960. break;
  2961. default:
  2962. dev_err(codec->dev, "Invalid dai->id: %d\n", dai->id);
  2963. return -EINVAL;
  2964. }
  2965. snd_soc_update_bits(codec, RT5659_ADDA_CLK_1, mask_clk, val_clk);
  2966. switch (rt5659->lrck[dai->id]) {
  2967. case 192000:
  2968. snd_soc_update_bits(codec, RT5659_ADDA_CLK_1,
  2969. RT5659_DAC_OSR_MASK, RT5659_DAC_OSR_32);
  2970. break;
  2971. case 96000:
  2972. snd_soc_update_bits(codec, RT5659_ADDA_CLK_1,
  2973. RT5659_DAC_OSR_MASK, RT5659_DAC_OSR_64);
  2974. break;
  2975. default:
  2976. snd_soc_update_bits(codec, RT5659_ADDA_CLK_1,
  2977. RT5659_DAC_OSR_MASK, RT5659_DAC_OSR_128);
  2978. break;
  2979. }
  2980. return 0;
  2981. }
  2982. static int rt5659_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  2983. {
  2984. struct snd_soc_codec *codec = dai->codec;
  2985. struct rt5659_priv *rt5659 = snd_soc_codec_get_drvdata(codec);
  2986. unsigned int reg_val = 0;
  2987. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  2988. case SND_SOC_DAIFMT_CBM_CFM:
  2989. rt5659->master[dai->id] = 1;
  2990. break;
  2991. case SND_SOC_DAIFMT_CBS_CFS:
  2992. reg_val |= RT5659_I2S_MS_S;
  2993. rt5659->master[dai->id] = 0;
  2994. break;
  2995. default:
  2996. return -EINVAL;
  2997. }
  2998. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  2999. case SND_SOC_DAIFMT_NB_NF:
  3000. break;
  3001. case SND_SOC_DAIFMT_IB_NF:
  3002. reg_val |= RT5659_I2S_BP_INV;
  3003. break;
  3004. default:
  3005. return -EINVAL;
  3006. }
  3007. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  3008. case SND_SOC_DAIFMT_I2S:
  3009. break;
  3010. case SND_SOC_DAIFMT_LEFT_J:
  3011. reg_val |= RT5659_I2S_DF_LEFT;
  3012. break;
  3013. case SND_SOC_DAIFMT_DSP_A:
  3014. reg_val |= RT5659_I2S_DF_PCM_A;
  3015. break;
  3016. case SND_SOC_DAIFMT_DSP_B:
  3017. reg_val |= RT5659_I2S_DF_PCM_B;
  3018. break;
  3019. default:
  3020. return -EINVAL;
  3021. }
  3022. switch (dai->id) {
  3023. case RT5659_AIF1:
  3024. snd_soc_update_bits(codec, RT5659_I2S1_SDP,
  3025. RT5659_I2S_MS_MASK | RT5659_I2S_BP_MASK |
  3026. RT5659_I2S_DF_MASK, reg_val);
  3027. break;
  3028. case RT5659_AIF2:
  3029. snd_soc_update_bits(codec, RT5659_I2S2_SDP,
  3030. RT5659_I2S_MS_MASK | RT5659_I2S_BP_MASK |
  3031. RT5659_I2S_DF_MASK, reg_val);
  3032. break;
  3033. case RT5659_AIF3:
  3034. snd_soc_update_bits(codec, RT5659_I2S3_SDP,
  3035. RT5659_I2S_MS_MASK | RT5659_I2S_BP_MASK |
  3036. RT5659_I2S_DF_MASK, reg_val);
  3037. break;
  3038. default:
  3039. dev_err(codec->dev, "Invalid dai->id: %d\n", dai->id);
  3040. return -EINVAL;
  3041. }
  3042. return 0;
  3043. }
  3044. static int rt5659_set_dai_sysclk(struct snd_soc_dai *dai,
  3045. int clk_id, unsigned int freq, int dir)
  3046. {
  3047. struct snd_soc_codec *codec = dai->codec;
  3048. struct rt5659_priv *rt5659 = snd_soc_codec_get_drvdata(codec);
  3049. unsigned int reg_val = 0;
  3050. if (freq == rt5659->sysclk && clk_id == rt5659->sysclk_src)
  3051. return 0;
  3052. switch (clk_id) {
  3053. case RT5659_SCLK_S_MCLK:
  3054. reg_val |= RT5659_SCLK_SRC_MCLK;
  3055. break;
  3056. case RT5659_SCLK_S_PLL1:
  3057. reg_val |= RT5659_SCLK_SRC_PLL1;
  3058. break;
  3059. case RT5659_SCLK_S_RCCLK:
  3060. reg_val |= RT5659_SCLK_SRC_RCCLK;
  3061. break;
  3062. default:
  3063. dev_err(codec->dev, "Invalid clock id (%d)\n", clk_id);
  3064. return -EINVAL;
  3065. }
  3066. snd_soc_update_bits(codec, RT5659_GLB_CLK,
  3067. RT5659_SCLK_SRC_MASK, reg_val);
  3068. rt5659->sysclk = freq;
  3069. rt5659->sysclk_src = clk_id;
  3070. dev_dbg(dai->dev, "Sysclk is %dHz and clock id is %d\n", freq, clk_id);
  3071. return 0;
  3072. }
  3073. static int rt5659_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int Source,
  3074. unsigned int freq_in, unsigned int freq_out)
  3075. {
  3076. struct snd_soc_codec *codec = dai->codec;
  3077. struct rt5659_priv *rt5659 = snd_soc_codec_get_drvdata(codec);
  3078. struct rl6231_pll_code pll_code;
  3079. int ret;
  3080. if (Source == rt5659->pll_src && freq_in == rt5659->pll_in &&
  3081. freq_out == rt5659->pll_out)
  3082. return 0;
  3083. if (!freq_in || !freq_out) {
  3084. dev_dbg(codec->dev, "PLL disabled\n");
  3085. rt5659->pll_in = 0;
  3086. rt5659->pll_out = 0;
  3087. snd_soc_update_bits(codec, RT5659_GLB_CLK,
  3088. RT5659_SCLK_SRC_MASK, RT5659_SCLK_SRC_MCLK);
  3089. return 0;
  3090. }
  3091. switch (Source) {
  3092. case RT5659_PLL1_S_MCLK:
  3093. snd_soc_update_bits(codec, RT5659_GLB_CLK,
  3094. RT5659_PLL1_SRC_MASK, RT5659_PLL1_SRC_MCLK);
  3095. break;
  3096. case RT5659_PLL1_S_BCLK1:
  3097. snd_soc_update_bits(codec, RT5659_GLB_CLK,
  3098. RT5659_PLL1_SRC_MASK, RT5659_PLL1_SRC_BCLK1);
  3099. break;
  3100. case RT5659_PLL1_S_BCLK2:
  3101. snd_soc_update_bits(codec, RT5659_GLB_CLK,
  3102. RT5659_PLL1_SRC_MASK, RT5659_PLL1_SRC_BCLK2);
  3103. break;
  3104. case RT5659_PLL1_S_BCLK3:
  3105. snd_soc_update_bits(codec, RT5659_GLB_CLK,
  3106. RT5659_PLL1_SRC_MASK, RT5659_PLL1_SRC_BCLK3);
  3107. break;
  3108. default:
  3109. dev_err(codec->dev, "Unknown PLL Source %d\n", Source);
  3110. return -EINVAL;
  3111. }
  3112. ret = rl6231_pll_calc(freq_in, freq_out, &pll_code);
  3113. if (ret < 0) {
  3114. dev_err(codec->dev, "Unsupport input clock %d\n", freq_in);
  3115. return ret;
  3116. }
  3117. dev_dbg(codec->dev, "bypass=%d m=%d n=%d k=%d\n",
  3118. pll_code.m_bp, (pll_code.m_bp ? 0 : pll_code.m_code),
  3119. pll_code.n_code, pll_code.k_code);
  3120. snd_soc_write(codec, RT5659_PLL_CTRL_1,
  3121. pll_code.n_code << RT5659_PLL_N_SFT | pll_code.k_code);
  3122. snd_soc_write(codec, RT5659_PLL_CTRL_2,
  3123. (pll_code.m_bp ? 0 : pll_code.m_code) << RT5659_PLL_M_SFT |
  3124. pll_code.m_bp << RT5659_PLL_M_BP_SFT);
  3125. rt5659->pll_in = freq_in;
  3126. rt5659->pll_out = freq_out;
  3127. rt5659->pll_src = Source;
  3128. return 0;
  3129. }
  3130. static int rt5659_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
  3131. unsigned int rx_mask, int slots, int slot_width)
  3132. {
  3133. struct snd_soc_codec *codec = dai->codec;
  3134. unsigned int val = 0;
  3135. if (rx_mask || tx_mask)
  3136. val |= (1 << 15);
  3137. switch (slots) {
  3138. case 4:
  3139. val |= (1 << 10);
  3140. val |= (1 << 8);
  3141. break;
  3142. case 6:
  3143. val |= (2 << 10);
  3144. val |= (2 << 8);
  3145. break;
  3146. case 8:
  3147. val |= (3 << 10);
  3148. val |= (3 << 8);
  3149. break;
  3150. case 2:
  3151. break;
  3152. default:
  3153. return -EINVAL;
  3154. }
  3155. switch (slot_width) {
  3156. case 20:
  3157. val |= (1 << 6);
  3158. val |= (1 << 4);
  3159. break;
  3160. case 24:
  3161. val |= (2 << 6);
  3162. val |= (2 << 4);
  3163. break;
  3164. case 32:
  3165. val |= (3 << 6);
  3166. val |= (3 << 4);
  3167. break;
  3168. case 16:
  3169. break;
  3170. default:
  3171. return -EINVAL;
  3172. }
  3173. snd_soc_update_bits(codec, RT5659_TDM_CTRL_1, 0x8ff0, val);
  3174. return 0;
  3175. }
  3176. static int rt5659_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio)
  3177. {
  3178. struct snd_soc_codec *codec = dai->codec;
  3179. struct rt5659_priv *rt5659 = snd_soc_codec_get_drvdata(codec);
  3180. dev_dbg(codec->dev, "%s ratio=%d\n", __func__, ratio);
  3181. rt5659->bclk[dai->id] = ratio;
  3182. if (ratio == 64) {
  3183. switch (dai->id) {
  3184. case RT5659_AIF2:
  3185. snd_soc_update_bits(codec, RT5659_ADDA_CLK_1,
  3186. RT5659_I2S_BCLK_MS2_MASK,
  3187. RT5659_I2S_BCLK_MS2_64);
  3188. break;
  3189. case RT5659_AIF3:
  3190. snd_soc_update_bits(codec, RT5659_ADDA_CLK_1,
  3191. RT5659_I2S_BCLK_MS3_MASK,
  3192. RT5659_I2S_BCLK_MS3_64);
  3193. break;
  3194. }
  3195. }
  3196. return 0;
  3197. }
  3198. static int rt5659_set_bias_level(struct snd_soc_codec *codec,
  3199. enum snd_soc_bias_level level)
  3200. {
  3201. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  3202. struct rt5659_priv *rt5659 = snd_soc_codec_get_drvdata(codec);
  3203. int ret;
  3204. switch (level) {
  3205. case SND_SOC_BIAS_PREPARE:
  3206. regmap_update_bits(rt5659->regmap, RT5659_DIG_MISC,
  3207. RT5659_DIG_GATE_CTRL, RT5659_DIG_GATE_CTRL);
  3208. regmap_update_bits(rt5659->regmap, RT5659_PWR_DIG_1,
  3209. RT5659_PWR_LDO, RT5659_PWR_LDO);
  3210. regmap_update_bits(rt5659->regmap, RT5659_PWR_ANLG_1,
  3211. RT5659_PWR_MB | RT5659_PWR_VREF1 | RT5659_PWR_VREF2,
  3212. RT5659_PWR_MB | RT5659_PWR_VREF1 | RT5659_PWR_VREF2);
  3213. msleep(20);
  3214. regmap_update_bits(rt5659->regmap, RT5659_PWR_ANLG_1,
  3215. RT5659_PWR_FV1 | RT5659_PWR_FV2,
  3216. RT5659_PWR_FV1 | RT5659_PWR_FV2);
  3217. break;
  3218. case SND_SOC_BIAS_STANDBY:
  3219. if (dapm->bias_level == SND_SOC_BIAS_OFF) {
  3220. ret = clk_prepare_enable(rt5659->mclk);
  3221. if (ret) {
  3222. dev_err(codec->dev,
  3223. "failed to enable MCLK: %d\n", ret);
  3224. return ret;
  3225. }
  3226. }
  3227. break;
  3228. case SND_SOC_BIAS_OFF:
  3229. regmap_update_bits(rt5659->regmap, RT5659_PWR_DIG_1,
  3230. RT5659_PWR_LDO, 0);
  3231. regmap_update_bits(rt5659->regmap, RT5659_PWR_ANLG_1,
  3232. RT5659_PWR_MB | RT5659_PWR_VREF1 | RT5659_PWR_VREF2
  3233. | RT5659_PWR_FV1 | RT5659_PWR_FV2,
  3234. RT5659_PWR_MB | RT5659_PWR_VREF2);
  3235. regmap_update_bits(rt5659->regmap, RT5659_DIG_MISC,
  3236. RT5659_DIG_GATE_CTRL, 0);
  3237. clk_disable_unprepare(rt5659->mclk);
  3238. break;
  3239. default:
  3240. break;
  3241. }
  3242. return 0;
  3243. }
  3244. static int rt5659_probe(struct snd_soc_codec *codec)
  3245. {
  3246. struct rt5659_priv *rt5659 = snd_soc_codec_get_drvdata(codec);
  3247. rt5659->codec = codec;
  3248. return 0;
  3249. }
  3250. static int rt5659_remove(struct snd_soc_codec *codec)
  3251. {
  3252. struct rt5659_priv *rt5659 = snd_soc_codec_get_drvdata(codec);
  3253. regmap_write(rt5659->regmap, RT5659_RESET, 0);
  3254. return 0;
  3255. }
  3256. #ifdef CONFIG_PM
  3257. static int rt5659_suspend(struct snd_soc_codec *codec)
  3258. {
  3259. struct rt5659_priv *rt5659 = snd_soc_codec_get_drvdata(codec);
  3260. regcache_cache_only(rt5659->regmap, true);
  3261. regcache_mark_dirty(rt5659->regmap);
  3262. return 0;
  3263. }
  3264. static int rt5659_resume(struct snd_soc_codec *codec)
  3265. {
  3266. struct rt5659_priv *rt5659 = snd_soc_codec_get_drvdata(codec);
  3267. regcache_cache_only(rt5659->regmap, false);
  3268. regcache_sync(rt5659->regmap);
  3269. return 0;
  3270. }
  3271. #else
  3272. #define rt5659_suspend NULL
  3273. #define rt5659_resume NULL
  3274. #endif
  3275. #define RT5659_STEREO_RATES SNDRV_PCM_RATE_8000_192000
  3276. #define RT5659_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
  3277. SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S8)
  3278. static const struct snd_soc_dai_ops rt5659_aif_dai_ops = {
  3279. .hw_params = rt5659_hw_params,
  3280. .set_fmt = rt5659_set_dai_fmt,
  3281. .set_sysclk = rt5659_set_dai_sysclk,
  3282. .set_tdm_slot = rt5659_set_tdm_slot,
  3283. .set_pll = rt5659_set_dai_pll,
  3284. .set_bclk_ratio = rt5659_set_bclk_ratio,
  3285. };
  3286. static struct snd_soc_dai_driver rt5659_dai[] = {
  3287. {
  3288. .name = "rt5659-aif1",
  3289. .id = RT5659_AIF1,
  3290. .playback = {
  3291. .stream_name = "AIF1 Playback",
  3292. .channels_min = 1,
  3293. .channels_max = 2,
  3294. .rates = RT5659_STEREO_RATES,
  3295. .formats = RT5659_FORMATS,
  3296. },
  3297. .capture = {
  3298. .stream_name = "AIF1 Capture",
  3299. .channels_min = 1,
  3300. .channels_max = 2,
  3301. .rates = RT5659_STEREO_RATES,
  3302. .formats = RT5659_FORMATS,
  3303. },
  3304. .ops = &rt5659_aif_dai_ops,
  3305. },
  3306. {
  3307. .name = "rt5659-aif2",
  3308. .id = RT5659_AIF2,
  3309. .playback = {
  3310. .stream_name = "AIF2 Playback",
  3311. .channels_min = 1,
  3312. .channels_max = 2,
  3313. .rates = RT5659_STEREO_RATES,
  3314. .formats = RT5659_FORMATS,
  3315. },
  3316. .capture = {
  3317. .stream_name = "AIF2 Capture",
  3318. .channels_min = 1,
  3319. .channels_max = 2,
  3320. .rates = RT5659_STEREO_RATES,
  3321. .formats = RT5659_FORMATS,
  3322. },
  3323. .ops = &rt5659_aif_dai_ops,
  3324. },
  3325. {
  3326. .name = "rt5659-aif3",
  3327. .id = RT5659_AIF3,
  3328. .playback = {
  3329. .stream_name = "AIF3 Playback",
  3330. .channels_min = 1,
  3331. .channels_max = 2,
  3332. .rates = RT5659_STEREO_RATES,
  3333. .formats = RT5659_FORMATS,
  3334. },
  3335. .capture = {
  3336. .stream_name = "AIF3 Capture",
  3337. .channels_min = 1,
  3338. .channels_max = 2,
  3339. .rates = RT5659_STEREO_RATES,
  3340. .formats = RT5659_FORMATS,
  3341. },
  3342. .ops = &rt5659_aif_dai_ops,
  3343. },
  3344. };
  3345. static struct snd_soc_codec_driver soc_codec_dev_rt5659 = {
  3346. .probe = rt5659_probe,
  3347. .remove = rt5659_remove,
  3348. .suspend = rt5659_suspend,
  3349. .resume = rt5659_resume,
  3350. .set_bias_level = rt5659_set_bias_level,
  3351. .idle_bias_off = true,
  3352. .component_driver = {
  3353. .controls = rt5659_snd_controls,
  3354. .num_controls = ARRAY_SIZE(rt5659_snd_controls),
  3355. .dapm_widgets = rt5659_dapm_widgets,
  3356. .num_dapm_widgets = ARRAY_SIZE(rt5659_dapm_widgets),
  3357. .dapm_routes = rt5659_dapm_routes,
  3358. .num_dapm_routes = ARRAY_SIZE(rt5659_dapm_routes),
  3359. },
  3360. };
  3361. static const struct regmap_config rt5659_regmap = {
  3362. .reg_bits = 16,
  3363. .val_bits = 16,
  3364. .max_register = 0x0400,
  3365. .volatile_reg = rt5659_volatile_register,
  3366. .readable_reg = rt5659_readable_register,
  3367. .cache_type = REGCACHE_RBTREE,
  3368. .reg_defaults = rt5659_reg,
  3369. .num_reg_defaults = ARRAY_SIZE(rt5659_reg),
  3370. };
  3371. static const struct i2c_device_id rt5659_i2c_id[] = {
  3372. { "rt5658", 0 },
  3373. { "rt5659", 0 },
  3374. { }
  3375. };
  3376. MODULE_DEVICE_TABLE(i2c, rt5659_i2c_id);
  3377. static int rt5659_parse_dt(struct rt5659_priv *rt5659, struct device *dev)
  3378. {
  3379. rt5659->pdata.in1_diff = device_property_read_bool(dev,
  3380. "realtek,in1-differential");
  3381. rt5659->pdata.in3_diff = device_property_read_bool(dev,
  3382. "realtek,in3-differential");
  3383. rt5659->pdata.in4_diff = device_property_read_bool(dev,
  3384. "realtek,in4-differential");
  3385. device_property_read_u32(dev, "realtek,dmic1-data-pin",
  3386. &rt5659->pdata.dmic1_data_pin);
  3387. device_property_read_u32(dev, "realtek,dmic2-data-pin",
  3388. &rt5659->pdata.dmic2_data_pin);
  3389. device_property_read_u32(dev, "realtek,jd-src",
  3390. &rt5659->pdata.jd_src);
  3391. return 0;
  3392. }
  3393. static void rt5659_calibrate(struct rt5659_priv *rt5659)
  3394. {
  3395. int value, count;
  3396. /* Calibrate HPO Start */
  3397. /* Fine tune HP Performance */
  3398. regmap_write(rt5659->regmap, RT5659_BIAS_CUR_CTRL_8, 0xa502);
  3399. regmap_write(rt5659->regmap, RT5659_CHOP_DAC, 0x3030);
  3400. regmap_write(rt5659->regmap, RT5659_PRE_DIV_1, 0xef00);
  3401. regmap_write(rt5659->regmap, RT5659_PRE_DIV_2, 0xeffc);
  3402. regmap_write(rt5659->regmap, RT5659_MICBIAS_2, 0x0280);
  3403. regmap_write(rt5659->regmap, RT5659_DIG_MISC, 0x0001);
  3404. regmap_write(rt5659->regmap, RT5659_GLB_CLK, 0x8000);
  3405. regmap_write(rt5659->regmap, RT5659_PWR_ANLG_1, 0xaa7e);
  3406. msleep(60);
  3407. regmap_write(rt5659->regmap, RT5659_PWR_ANLG_1, 0xfe7e);
  3408. msleep(50);
  3409. regmap_write(rt5659->regmap, RT5659_PWR_ANLG_3, 0x0004);
  3410. regmap_write(rt5659->regmap, RT5659_PWR_DIG_2, 0x0400);
  3411. msleep(50);
  3412. regmap_write(rt5659->regmap, RT5659_PWR_DIG_1, 0x0080);
  3413. usleep_range(10000, 10005);
  3414. regmap_write(rt5659->regmap, RT5659_DEPOP_1, 0x0009);
  3415. msleep(50);
  3416. regmap_write(rt5659->regmap, RT5659_PWR_DIG_1, 0x0f80);
  3417. msleep(50);
  3418. regmap_write(rt5659->regmap, RT5659_HP_CHARGE_PUMP_1, 0x0e16);
  3419. msleep(50);
  3420. /* Enalbe K ADC Power And Clock */
  3421. regmap_write(rt5659->regmap, RT5659_CAL_REC, 0x0505);
  3422. msleep(50);
  3423. regmap_write(rt5659->regmap, RT5659_PWR_ANLG_3, 0x0184);
  3424. regmap_write(rt5659->regmap, RT5659_CALIB_ADC_CTRL, 0x3c05);
  3425. regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_2, 0x20c1);
  3426. /* K Headphone */
  3427. regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_2, 0x2cc1);
  3428. regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_1, 0x5100);
  3429. regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_7, 0x0014);
  3430. regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_1, 0xd100);
  3431. msleep(60);
  3432. /* Manual K ADC Offset */
  3433. regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_2, 0x2cc1);
  3434. regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_1, 0x4900);
  3435. regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_7, 0x0016);
  3436. regmap_update_bits(rt5659->regmap, RT5659_HP_CALIB_CTRL_1,
  3437. 0x8000, 0x8000);
  3438. count = 0;
  3439. while (true) {
  3440. regmap_read(rt5659->regmap, RT5659_HP_CALIB_CTRL_1, &value);
  3441. if (value & 0x8000)
  3442. usleep_range(10000, 10005);
  3443. else
  3444. break;
  3445. if (count > 30) {
  3446. dev_err(rt5659->codec->dev,
  3447. "HP Calibration 1 Failure\n");
  3448. return;
  3449. }
  3450. count++;
  3451. }
  3452. /* Manual K Internal Path Offset */
  3453. regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_2, 0x2cc1);
  3454. regmap_write(rt5659->regmap, RT5659_HP_VOL, 0x0000);
  3455. regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_1, 0x4500);
  3456. regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_7, 0x001f);
  3457. regmap_update_bits(rt5659->regmap, RT5659_HP_CALIB_CTRL_1,
  3458. 0x8000, 0x8000);
  3459. count = 0;
  3460. while (true) {
  3461. regmap_read(rt5659->regmap, RT5659_HP_CALIB_CTRL_1, &value);
  3462. if (value & 0x8000)
  3463. usleep_range(10000, 10005);
  3464. else
  3465. break;
  3466. if (count > 85) {
  3467. dev_err(rt5659->codec->dev,
  3468. "HP Calibration 2 Failure\n");
  3469. return;
  3470. }
  3471. count++;
  3472. }
  3473. regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_7, 0x0000);
  3474. regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_2, 0x20c0);
  3475. /* Calibrate HPO End */
  3476. /* Calibrate SPO Start */
  3477. regmap_write(rt5659->regmap, RT5659_CLASSD_0, 0x2021);
  3478. regmap_write(rt5659->regmap, RT5659_CLASSD_CTRL_1, 0x0260);
  3479. regmap_write(rt5659->regmap, RT5659_PWR_MIXER, 0x3000);
  3480. regmap_write(rt5659->regmap, RT5659_PWR_VOL, 0xc000);
  3481. regmap_write(rt5659->regmap, RT5659_A_DAC_MUX, 0x000c);
  3482. regmap_write(rt5659->regmap, RT5659_DIG_MISC, 0x8000);
  3483. regmap_write(rt5659->regmap, RT5659_SPO_VOL, 0x0808);
  3484. regmap_write(rt5659->regmap, RT5659_SPK_L_MIXER, 0x001e);
  3485. regmap_write(rt5659->regmap, RT5659_SPK_R_MIXER, 0x001e);
  3486. regmap_write(rt5659->regmap, RT5659_CLASSD_1, 0x0803);
  3487. regmap_write(rt5659->regmap, RT5659_CLASSD_2, 0x0554);
  3488. regmap_write(rt5659->regmap, RT5659_SPO_AMP_GAIN, 0x1103);
  3489. /* Enalbe K ADC Power And Clock */
  3490. regmap_write(rt5659->regmap, RT5659_CAL_REC, 0x0909);
  3491. regmap_update_bits(rt5659->regmap, RT5659_HP_CALIB_CTRL_2, 0x0001,
  3492. 0x0001);
  3493. /* Start Calibration */
  3494. regmap_write(rt5659->regmap, RT5659_SPK_DC_CAILB_CTRL_3, 0x0000);
  3495. regmap_write(rt5659->regmap, RT5659_CLASSD_0, 0x0021);
  3496. regmap_write(rt5659->regmap, RT5659_SPK_DC_CAILB_CTRL_1, 0x3e80);
  3497. regmap_update_bits(rt5659->regmap, RT5659_SPK_DC_CAILB_CTRL_1,
  3498. 0x8000, 0x8000);
  3499. count = 0;
  3500. while (true) {
  3501. regmap_read(rt5659->regmap,
  3502. RT5659_SPK_DC_CAILB_CTRL_1, &value);
  3503. if (value & 0x8000)
  3504. usleep_range(10000, 10005);
  3505. else
  3506. break;
  3507. if (count > 10) {
  3508. dev_err(rt5659->codec->dev,
  3509. "SPK Calibration Failure\n");
  3510. return;
  3511. }
  3512. count++;
  3513. }
  3514. /* Calibrate SPO End */
  3515. /* Calibrate MONO Start */
  3516. regmap_write(rt5659->regmap, RT5659_DIG_MISC, 0x0000);
  3517. regmap_write(rt5659->regmap, RT5659_MONOMIX_IN_GAIN, 0x021f);
  3518. regmap_write(rt5659->regmap, RT5659_MONO_OUT, 0x480a);
  3519. /* MONO NG2 GAIN 5dB */
  3520. regmap_write(rt5659->regmap, RT5659_MONO_GAIN, 0x0003);
  3521. regmap_write(rt5659->regmap, RT5659_MONO_NG2_CTRL_5, 0x0009);
  3522. /* Start Calibration */
  3523. regmap_write(rt5659->regmap, RT5659_SPK_DC_CAILB_CTRL_3, 0x000f);
  3524. regmap_write(rt5659->regmap, RT5659_MONO_AMP_CALIB_CTRL_1, 0x1e00);
  3525. regmap_update_bits(rt5659->regmap, RT5659_MONO_AMP_CALIB_CTRL_1,
  3526. 0x8000, 0x8000);
  3527. count = 0;
  3528. while (true) {
  3529. regmap_read(rt5659->regmap, RT5659_MONO_AMP_CALIB_CTRL_1,
  3530. &value);
  3531. if (value & 0x8000)
  3532. usleep_range(10000, 10005);
  3533. else
  3534. break;
  3535. if (count > 35) {
  3536. dev_err(rt5659->codec->dev,
  3537. "Mono Calibration Failure\n");
  3538. return;
  3539. }
  3540. count++;
  3541. }
  3542. regmap_write(rt5659->regmap, RT5659_SPK_DC_CAILB_CTRL_3, 0x0003);
  3543. /* Calibrate MONO End */
  3544. /* Power Off */
  3545. regmap_write(rt5659->regmap, RT5659_CAL_REC, 0x0808);
  3546. regmap_write(rt5659->regmap, RT5659_PWR_ANLG_3, 0x0000);
  3547. regmap_write(rt5659->regmap, RT5659_CALIB_ADC_CTRL, 0x2005);
  3548. regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_2, 0x20c0);
  3549. regmap_write(rt5659->regmap, RT5659_DEPOP_1, 0x0000);
  3550. regmap_write(rt5659->regmap, RT5659_CLASSD_1, 0x0011);
  3551. regmap_write(rt5659->regmap, RT5659_CLASSD_2, 0x0150);
  3552. regmap_write(rt5659->regmap, RT5659_PWR_ANLG_1, 0xfe3e);
  3553. regmap_write(rt5659->regmap, RT5659_MONO_OUT, 0xc80a);
  3554. regmap_write(rt5659->regmap, RT5659_MONO_AMP_CALIB_CTRL_1, 0x1e04);
  3555. regmap_write(rt5659->regmap, RT5659_PWR_MIXER, 0x0000);
  3556. regmap_write(rt5659->regmap, RT5659_PWR_VOL, 0x0000);
  3557. regmap_write(rt5659->regmap, RT5659_PWR_DIG_1, 0x0000);
  3558. regmap_write(rt5659->regmap, RT5659_PWR_DIG_2, 0x0000);
  3559. regmap_write(rt5659->regmap, RT5659_PWR_ANLG_1, 0x003e);
  3560. regmap_write(rt5659->regmap, RT5659_CLASSD_CTRL_1, 0x0060);
  3561. regmap_write(rt5659->regmap, RT5659_CLASSD_0, 0x2021);
  3562. regmap_write(rt5659->regmap, RT5659_GLB_CLK, 0x0000);
  3563. regmap_write(rt5659->regmap, RT5659_MICBIAS_2, 0x0080);
  3564. regmap_write(rt5659->regmap, RT5659_HP_VOL, 0x8080);
  3565. regmap_write(rt5659->regmap, RT5659_HP_CHARGE_PUMP_1, 0x0c16);
  3566. }
  3567. static int rt5659_i2c_probe(struct i2c_client *i2c,
  3568. const struct i2c_device_id *id)
  3569. {
  3570. struct rt5659_platform_data *pdata = dev_get_platdata(&i2c->dev);
  3571. struct rt5659_priv *rt5659;
  3572. int ret;
  3573. unsigned int val;
  3574. rt5659 = devm_kzalloc(&i2c->dev, sizeof(struct rt5659_priv),
  3575. GFP_KERNEL);
  3576. if (rt5659 == NULL)
  3577. return -ENOMEM;
  3578. i2c_set_clientdata(i2c, rt5659);
  3579. if (pdata)
  3580. rt5659->pdata = *pdata;
  3581. else
  3582. rt5659_parse_dt(rt5659, &i2c->dev);
  3583. rt5659->gpiod_ldo1_en = devm_gpiod_get_optional(&i2c->dev, "ldo1-en",
  3584. GPIOD_OUT_HIGH);
  3585. if (IS_ERR(rt5659->gpiod_ldo1_en))
  3586. dev_warn(&i2c->dev, "Request ldo1-en GPIO failed\n");
  3587. rt5659->gpiod_reset = devm_gpiod_get_optional(&i2c->dev, "reset",
  3588. GPIOD_OUT_HIGH);
  3589. /* Sleep for 300 ms miniumum */
  3590. usleep_range(300000, 350000);
  3591. rt5659->regmap = devm_regmap_init_i2c(i2c, &rt5659_regmap);
  3592. if (IS_ERR(rt5659->regmap)) {
  3593. ret = PTR_ERR(rt5659->regmap);
  3594. dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
  3595. ret);
  3596. return ret;
  3597. }
  3598. regmap_read(rt5659->regmap, RT5659_DEVICE_ID, &val);
  3599. if (val != DEVICE_ID) {
  3600. dev_err(&i2c->dev,
  3601. "Device with ID register %x is not rt5659\n", val);
  3602. return -ENODEV;
  3603. }
  3604. regmap_write(rt5659->regmap, RT5659_RESET, 0);
  3605. /* Check if MCLK provided */
  3606. rt5659->mclk = devm_clk_get(&i2c->dev, "mclk");
  3607. if (IS_ERR(rt5659->mclk)) {
  3608. if (PTR_ERR(rt5659->mclk) != -ENOENT)
  3609. return PTR_ERR(rt5659->mclk);
  3610. /* Otherwise mark the mclk pointer to NULL */
  3611. rt5659->mclk = NULL;
  3612. }
  3613. rt5659_calibrate(rt5659);
  3614. /* line in diff mode*/
  3615. if (rt5659->pdata.in1_diff)
  3616. regmap_update_bits(rt5659->regmap, RT5659_IN1_IN2,
  3617. RT5659_IN1_DF_MASK, RT5659_IN1_DF_MASK);
  3618. if (rt5659->pdata.in3_diff)
  3619. regmap_update_bits(rt5659->regmap, RT5659_IN3_IN4,
  3620. RT5659_IN3_DF_MASK, RT5659_IN3_DF_MASK);
  3621. if (rt5659->pdata.in4_diff)
  3622. regmap_update_bits(rt5659->regmap, RT5659_IN3_IN4,
  3623. RT5659_IN4_DF_MASK, RT5659_IN4_DF_MASK);
  3624. /* DMIC pin*/
  3625. if (rt5659->pdata.dmic1_data_pin != RT5659_DMIC1_NULL ||
  3626. rt5659->pdata.dmic2_data_pin != RT5659_DMIC2_NULL) {
  3627. regmap_update_bits(rt5659->regmap, RT5659_GPIO_CTRL_1,
  3628. RT5659_GP2_PIN_MASK, RT5659_GP2_PIN_DMIC1_SCL);
  3629. switch (rt5659->pdata.dmic1_data_pin) {
  3630. case RT5659_DMIC1_DATA_IN2N:
  3631. regmap_update_bits(rt5659->regmap, RT5659_DMIC_CTRL_1,
  3632. RT5659_DMIC_1_DP_MASK, RT5659_DMIC_1_DP_IN2N);
  3633. break;
  3634. case RT5659_DMIC1_DATA_GPIO5:
  3635. regmap_update_bits(rt5659->regmap,
  3636. RT5659_GPIO_CTRL_3,
  3637. RT5659_I2S2_PIN_MASK,
  3638. RT5659_I2S2_PIN_GPIO);
  3639. regmap_update_bits(rt5659->regmap, RT5659_DMIC_CTRL_1,
  3640. RT5659_DMIC_1_DP_MASK, RT5659_DMIC_1_DP_GPIO5);
  3641. regmap_update_bits(rt5659->regmap, RT5659_GPIO_CTRL_1,
  3642. RT5659_GP5_PIN_MASK, RT5659_GP5_PIN_DMIC1_SDA);
  3643. break;
  3644. case RT5659_DMIC1_DATA_GPIO9:
  3645. regmap_update_bits(rt5659->regmap, RT5659_DMIC_CTRL_1,
  3646. RT5659_DMIC_1_DP_MASK, RT5659_DMIC_1_DP_GPIO9);
  3647. regmap_update_bits(rt5659->regmap, RT5659_GPIO_CTRL_1,
  3648. RT5659_GP9_PIN_MASK, RT5659_GP9_PIN_DMIC1_SDA);
  3649. break;
  3650. case RT5659_DMIC1_DATA_GPIO11:
  3651. regmap_update_bits(rt5659->regmap, RT5659_DMIC_CTRL_1,
  3652. RT5659_DMIC_1_DP_MASK, RT5659_DMIC_1_DP_GPIO11);
  3653. regmap_update_bits(rt5659->regmap, RT5659_GPIO_CTRL_1,
  3654. RT5659_GP11_PIN_MASK,
  3655. RT5659_GP11_PIN_DMIC1_SDA);
  3656. break;
  3657. default:
  3658. dev_dbg(&i2c->dev, "no DMIC1\n");
  3659. break;
  3660. }
  3661. switch (rt5659->pdata.dmic2_data_pin) {
  3662. case RT5659_DMIC2_DATA_IN2P:
  3663. regmap_update_bits(rt5659->regmap,
  3664. RT5659_DMIC_CTRL_1,
  3665. RT5659_DMIC_2_DP_MASK,
  3666. RT5659_DMIC_2_DP_IN2P);
  3667. break;
  3668. case RT5659_DMIC2_DATA_GPIO6:
  3669. regmap_update_bits(rt5659->regmap,
  3670. RT5659_DMIC_CTRL_1,
  3671. RT5659_DMIC_2_DP_MASK,
  3672. RT5659_DMIC_2_DP_GPIO6);
  3673. regmap_update_bits(rt5659->regmap,
  3674. RT5659_GPIO_CTRL_1,
  3675. RT5659_GP6_PIN_MASK,
  3676. RT5659_GP6_PIN_DMIC2_SDA);
  3677. break;
  3678. case RT5659_DMIC2_DATA_GPIO10:
  3679. regmap_update_bits(rt5659->regmap,
  3680. RT5659_DMIC_CTRL_1,
  3681. RT5659_DMIC_2_DP_MASK,
  3682. RT5659_DMIC_2_DP_GPIO10);
  3683. regmap_update_bits(rt5659->regmap,
  3684. RT5659_GPIO_CTRL_1,
  3685. RT5659_GP10_PIN_MASK,
  3686. RT5659_GP10_PIN_DMIC2_SDA);
  3687. break;
  3688. case RT5659_DMIC2_DATA_GPIO12:
  3689. regmap_update_bits(rt5659->regmap,
  3690. RT5659_DMIC_CTRL_1,
  3691. RT5659_DMIC_2_DP_MASK,
  3692. RT5659_DMIC_2_DP_GPIO12);
  3693. regmap_update_bits(rt5659->regmap,
  3694. RT5659_GPIO_CTRL_1,
  3695. RT5659_GP12_PIN_MASK,
  3696. RT5659_GP12_PIN_DMIC2_SDA);
  3697. break;
  3698. default:
  3699. dev_dbg(&i2c->dev, "no DMIC2\n");
  3700. break;
  3701. }
  3702. } else {
  3703. regmap_update_bits(rt5659->regmap, RT5659_GPIO_CTRL_1,
  3704. RT5659_GP2_PIN_MASK | RT5659_GP5_PIN_MASK |
  3705. RT5659_GP9_PIN_MASK | RT5659_GP11_PIN_MASK |
  3706. RT5659_GP6_PIN_MASK | RT5659_GP10_PIN_MASK |
  3707. RT5659_GP12_PIN_MASK,
  3708. RT5659_GP2_PIN_GPIO2 | RT5659_GP5_PIN_GPIO5 |
  3709. RT5659_GP9_PIN_GPIO9 | RT5659_GP11_PIN_GPIO11 |
  3710. RT5659_GP6_PIN_GPIO6 | RT5659_GP10_PIN_GPIO10 |
  3711. RT5659_GP12_PIN_GPIO12);
  3712. regmap_update_bits(rt5659->regmap, RT5659_DMIC_CTRL_1,
  3713. RT5659_DMIC_1_DP_MASK | RT5659_DMIC_2_DP_MASK,
  3714. RT5659_DMIC_1_DP_IN2N | RT5659_DMIC_2_DP_IN2P);
  3715. }
  3716. switch (rt5659->pdata.jd_src) {
  3717. case RT5659_JD3:
  3718. regmap_write(rt5659->regmap, RT5659_EJD_CTRL_1, 0xa880);
  3719. regmap_write(rt5659->regmap, RT5659_RC_CLK_CTRL, 0x9000);
  3720. regmap_write(rt5659->regmap, RT5659_GPIO_CTRL_1, 0xc800);
  3721. regmap_update_bits(rt5659->regmap, RT5659_PWR_ANLG_1,
  3722. RT5659_PWR_MB, RT5659_PWR_MB);
  3723. regmap_write(rt5659->regmap, RT5659_PWR_ANLG_2, 0x0001);
  3724. regmap_write(rt5659->regmap, RT5659_IRQ_CTRL_2, 0x0040);
  3725. break;
  3726. case RT5659_JD_NULL:
  3727. break;
  3728. default:
  3729. dev_warn(&i2c->dev, "Currently, support JD3 only\n");
  3730. break;
  3731. }
  3732. INIT_DELAYED_WORK(&rt5659->jack_detect_work, rt5659_jack_detect_work);
  3733. if (i2c->irq) {
  3734. ret = devm_request_threaded_irq(&i2c->dev, i2c->irq, NULL,
  3735. rt5659_irq, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING
  3736. | IRQF_ONESHOT, "rt5659", rt5659);
  3737. if (ret)
  3738. dev_err(&i2c->dev, "Failed to reguest IRQ: %d\n", ret);
  3739. /* Enable IRQ output for GPIO1 pin any way */
  3740. regmap_update_bits(rt5659->regmap, RT5659_GPIO_CTRL_1,
  3741. RT5659_GP1_PIN_MASK, RT5659_GP1_PIN_IRQ);
  3742. }
  3743. return snd_soc_register_codec(&i2c->dev, &soc_codec_dev_rt5659,
  3744. rt5659_dai, ARRAY_SIZE(rt5659_dai));
  3745. }
  3746. static int rt5659_i2c_remove(struct i2c_client *i2c)
  3747. {
  3748. snd_soc_unregister_codec(&i2c->dev);
  3749. return 0;
  3750. }
  3751. static void rt5659_i2c_shutdown(struct i2c_client *client)
  3752. {
  3753. struct rt5659_priv *rt5659 = i2c_get_clientdata(client);
  3754. regmap_write(rt5659->regmap, RT5659_RESET, 0);
  3755. }
  3756. #ifdef CONFIG_OF
  3757. static const struct of_device_id rt5659_of_match[] = {
  3758. { .compatible = "realtek,rt5658", },
  3759. { .compatible = "realtek,rt5659", },
  3760. { },
  3761. };
  3762. MODULE_DEVICE_TABLE(of, rt5659_of_match);
  3763. #endif
  3764. #ifdef CONFIG_ACPI
  3765. static struct acpi_device_id rt5659_acpi_match[] = {
  3766. { "10EC5658", 0, },
  3767. { "10EC5659", 0, },
  3768. { },
  3769. };
  3770. MODULE_DEVICE_TABLE(acpi, rt5659_acpi_match);
  3771. #endif
  3772. struct i2c_driver rt5659_i2c_driver = {
  3773. .driver = {
  3774. .name = "rt5659",
  3775. .owner = THIS_MODULE,
  3776. .of_match_table = of_match_ptr(rt5659_of_match),
  3777. .acpi_match_table = ACPI_PTR(rt5659_acpi_match),
  3778. },
  3779. .probe = rt5659_i2c_probe,
  3780. .remove = rt5659_i2c_remove,
  3781. .shutdown = rt5659_i2c_shutdown,
  3782. .id_table = rt5659_i2c_id,
  3783. };
  3784. module_i2c_driver(rt5659_i2c_driver);
  3785. MODULE_DESCRIPTION("ASoC RT5659 driver");
  3786. MODULE_AUTHOR("Bard Liao <bardliao@realtek.com>");
  3787. MODULE_LICENSE("GPL v2");