ak7604.c 143 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821
  1. /*
  2. * ak7604.c -- audio driver for AK7604
  3. *
  4. * Copyright (C) 2017-2021 Asahi Kasei Microdevices Corporation
  5. * Author Date Revision
  6. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. * 17/11/27 1.0
  8. * 18/02/06 1.1
  9. * 18/03/07 1.2
  10. * 20/08/21 1.3 Kernel 4_14_XX
  11. * 21/02/10 1.4
  12. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License version 2 as
  16. * published by the Free Software Foundation.
  17. *
  18. */
  19. #include <linux/module.h>
  20. #include <linux/init.h>
  21. #include <linux/i2c.h>
  22. #include <linux/delay.h>
  23. #include <linux/slab.h>
  24. #include <linux/gpio.h>
  25. #include <sound/pcm.h>
  26. #include <sound/pcm_params.h>
  27. #include <sound/soc.h>
  28. #include <sound/soc-dapm.h>
  29. #include <sound/initval.h>
  30. #include <sound/tlv.h>
  31. #include <linux/ioctl.h>
  32. #include <linux/fs.h>
  33. #include <linux/uaccess.h>
  34. #include <linux/spi/spi.h>
  35. #include <linux/mutex.h>
  36. #include <linux/firmware.h>
  37. #include <linux/vmalloc.h>
  38. #include <linux/regmap.h>
  39. #include <linux/of_gpio.h>
  40. #include "ak7604.h"
  41. #include "ak7604_dsp_code.h"
  42. //#define KERNEL_3_18_XX
  43. //#define KERNEL_4_14_XX
  44. //#define AK7604_DEBUG //used at debug mode
  45. //#define ARK_CARPLAY_MODE
  46. #ifdef AK7604_DEBUG
  47. #define akdbgprt printk
  48. #else
  49. #define akdbgprt(format, arg...) do {} while (0)
  50. #endif
  51. #define SND_SOC_SPI 1
  52. #define SND_SOC_I2C 2
  53. /* AK7604 Codec Private Data */
  54. struct ak7604_priv {
  55. int control_type;
  56. struct snd_soc_component *component;
  57. struct spi_device *spi;
  58. struct i2c_client *i2c;
  59. struct regmap *regmap;
  60. int fs;
  61. int pdn_gpio;
  62. int MIRNo;
  63. int status;
  64. int dresetn;
  65. int DSPPramMode;
  66. int DSPCramMode;
  67. int DSPOfregMode;
  68. int PLLInput; // 0 : XTI, 1 : BICK1 ...3 : BICK3
  69. int XtiFs; // 0 : 12.288MHz, 1: 18.432MHz
  70. // 0:8kHz, 1:12kHz, 2:16kHz, 3:24kHz, 4:32kHz, 5:48kHz, 6:96kHz, 7:192kHz
  71. int SDfs[NUM_SYNCDOMAIN];
  72. // 0:64fs, 1:48fs, 2:32fs, 3:128fs, 4:256fs
  73. int SDBick[NUM_SYNCDOMAIN];
  74. // 0 : Slave Mode, 1 : Master
  75. int Master[NUM_SYNCDOMAIN];
  76. // 0 : Low, 1: PLLMCLK, 2:XTI, 3:BICK1, 4:BICK2, 5:BICK3
  77. int SDCks[NUM_SYNCDOMAIN];
  78. int TDMSDINbit[NUM_SDIO];
  79. int TDMSDOUTbit[NUM_SDIO];
  80. int DIEDGEbit[NUM_SDIO];
  81. int DOEDGEbit[NUM_SDIO];
  82. int DISLbit[NUM_SDIO];
  83. int DOSLbit[NUM_SDIO];
  84. int cramaddr;
  85. int cramcount;
  86. unsigned char cramvalue[48];
  87. };
  88. struct _ak7604_pd_handler {
  89. int ref_count;
  90. struct mutex lock;
  91. struct ak7604_priv *data;
  92. } ak7604_pd_handler = {
  93. .ref_count = -1,
  94. .data = NULL,
  95. };
  96. /* ak7604 register cache & default register settings */
  97. static const struct reg_default ak7604_reg[] = {
  98. #ifndef ARK_CARPLAY_MODE
  99. //(soc-salve)
  100. //ark音频链路plan:1
  101. //ark(i2s1)<->ak7604(i2s2)
  102. //ark(i2s2)->fm1505->ak7604(i2s1)
  103. //ak7604(mic-i2s1)->fm1505->ark(i2s0)
  104. { 0x0000, 0x0F },
  105. { 0x0001, 0x07 },
  106. { 0x0002, 0x90 },
  107. { 0x0003, 0x04 },
  108. { 0x0004, 0x03 }, // AK7604_04_SYNCDOMAIN_MS //[011]:[bit1->ak7604-i2s1:master bit2->ak7604-i2s2:master bit3->ak7604-i2s3:slave]
  109. { 0x0005, 0x08 },
  110. { 0x0006, 0x27 },
  111. { 0x0007, 0x08 },
  112. { 0x0008, 0x27 },
  113. { 0x0009, 0x08 },
  114. { 0x000A, 0x27 },
  115. { 0x000B, 0x08 },
  116. { 0x000C, 0x00 },
  117. { 0x000D, 0x12 },//default:0x12 only for beidou:0x11
  118. { 0x000E, 0x30 },
  119. { 0x000F, 0x12 },
  120. { 0x0010, 0x30 },
  121. { 0x0011, 0x12 },////default:0x10 241010:0x11(SDADC->SD1) 0x12(SDADC->SD2) //only for beidou:0x11(SDADC->SD1)
  122. { 0x0012, 0x11 },
  123. { 0x0013, 0x11 },
  124. { 0x0014, 0x11 },//(default:0x11) 20241016:0x12
  125. { 0x0015, 0x10 },
  126. { 0x0016, 0x00 },
  127. { 0x0017, 0x10 },
  128. { 0x0018, 0x00 },
  129. { 0x0019, 0x01 },//SDOUT1A Source Selector "arecord: ADC->SDOUT1A(0x0E)" //only for beidou:0x01
  130. { 0x001A, 0x00 },
  131. { 0x001B, 0x00 },
  132. { 0x001C, 0x00 },
  133. { 0x001D, 0x01 },//SDOUT2 Source Selector(default:0x00) "arecord: ADC->SDOUT2(0x0E)" 20241016:DSPOUT2->SDOUT1(0x09) //only for beidou:0x01
  134. { 0x001E, 0x00 },//SDOUT3 Source Selector(default:0x09) "arecord: SDOUT3->ADC(0x0E)"
  135. { 0x001F, 0x0E },//DAC1 Source Selector(default:0x08), 20250811:0x0E(ADC) "Playback : SDIN1(0x01) -> DSP1 -> DAC1 (SYNC1_Slave) or SDIN2(0x05) -> DSP1 -> DAC1 (SYNC1_Slave)"
  136. { 0x0020, 0x0A },//DAC2 Source Selector 0x0A
  137. { 0x0021, 0x00 },//DAC3 Source Selector
  138. { 0x0022, 0x01 },
  139. { 0x0023, 0x05 },//(default:0x05) 20241016:0x0E
  140. { 0x0024, 0x0F },
  141. { 0x0025, 0x00 },
  142. { 0x0026, 0x00 },
  143. { 0x0027, 0x00 },
  144. { 0x0028, 0x06 },
  145. { 0x0029, 0x00 },
  146. { 0x002A, 0x00 },
  147. { 0x002B, 0x00 },
  148. { 0x002C, 0x00 },
  149. { 0x002D, 0x00 },
  150. { 0x002E, 0x00 },
  151. { 0x002F, 0x00 },
  152. { 0x0030, 0x00 },
  153. { 0x0031, 0x00 },
  154. { 0x0032, 0x00 },
  155. { 0x0033, 0x00 },
  156. { 0x0034, 0x00 },
  157. { 0x0035, 0x00 },
  158. { 0x0036, 0x00 },
  159. { 0x0037, 0x00 },
  160. { 0x0038, 0x00 },
  161. { 0x0039, 0x00 },
  162. { 0x003A, 0x00 },
  163. { 0x003B, 0x00 },
  164. { 0x003C, 0x00 },
  165. { 0x003D, 0x00 },
  166. { 0x003E, 0x00 },
  167. { 0x003F, 0x00 },
  168. { 0x0040, 0x00 },
  169. { 0x0041, 0x00 },
  170. { 0x0042, 0x00 },
  171. { 0x0043, 0x00 },
  172. { 0x0044, 0x00 },
  173. { 0x0045, 0x00 },
  174. { 0x0046, 0x00 },
  175. { 0x0047, 0x00 },
  176. { 0x0048, 0x00 },
  177. { 0x0049, 0x00 },
  178. { 0x004A, 0x00 },
  179. { 0x004B, 0x00 },
  180. { 0x004C, 0x00 },
  181. { 0x004D, 0x00 },
  182. { 0x004E, 0x00 },
  183. { 0x004F, 0x00 },
  184. { 0x0050, 0x00 },
  185. { 0x0051, 0xE1 },
  186. { 0x0052, 0x00 },
  187. { 0x0053, 0x00 },
  188. { 0x0054, 0x00 },
  189. { 0x0055, 0x00 },
  190. { 0x0056, 0x00 },
  191. { 0x0057, 0x00 },
  192. { 0x0058, 0x00 },
  193. { 0x0059, 0x00 },
  194. { 0x005A, 0x00 },
  195. { 0x005B, 0x00 },
  196. { 0x005C, 0x00 },
  197. { 0x005D, 0x00 },
  198. { 0x005E, 0x00 },
  199. { 0x005F, 0x00 },
  200. { 0x0060, 0x00 },
  201. { 0x0061, 0x00 },
  202. { 0x0062, 0x00 },
  203. { 0x0063, 0x00 },
  204. { 0x0064, 0x00 },
  205. { 0x0065, 0x00 },
  206. { 0x0066, 0x00 },
  207. { 0x0067, 0x00 },
  208. { 0x0068, 0x00 },
  209. { 0x0069, 0x00 },
  210. { 0x006A, 0x00 },
  211. { 0x006B, 0x00 },
  212. { 0x006C, 0x00 },
  213. { 0x006D, 0x00 },
  214. { 0x006E, 0x00 },
  215. { 0x006F, 0x00 },
  216. { 0x0070, 0x00 },
  217. { 0x0071, 0x00 },
  218. { 0x0072, 0x00 },
  219. { 0x0073, 0x0F },
  220. { 0x0074, 0x00 },
  221. { 0x0075, 0x00 },
  222. { 0x0076, 0x00 },
  223. { 0x0077, 0x00 },
  224. { 0x0078, 0x00 },
  225. { 0x0079, 0x00 },
  226. { 0x007A, 0x00 },
  227. { 0x007B, 0x00 },
  228. { 0x007C, 0x00 },
  229. { 0x007D, 0x00 },
  230. { 0x007E, 0x00 },
  231. { 0x007F, 0x00 },
  232. { 0x0080, 0x00 },
  233. { 0x0081, 0x00 },
  234. { 0x0082, 0xFF },//MIC Input Volume L/R 36dB
  235. { 0x0083, 0x18 },//DAC1 Digital Volume L default:0x18(0.0db) 4b(-40.5db)
  236. { 0x0084, 0x18 },//DAC1 Digital Volume R default:0x18 4b(-40.5db)
  237. { 0x0085, 0x18 },//DAC2 Digital Volume L default:0x18 4b(-40.5db)
  238. { 0x0086, 0x18 },//DAC2 Digital Volume R default:0x18 4b(-40.5db)
  239. { 0x0087, 0x18 },//DAC3 Digital Volume L default:0x18 4b(-40.5db)
  240. { 0x0088, 0x18 },//DAC3 Digital Volume R default:0x18 4b(-40.5db)
  241. { 0x0089, 0x00 }, // AK7604_89_DAC_MUTEFILTER
  242. { 0x008A, 0x15 },
  243. { 0x008B, 0x20 },//ADC Digital Volume L default:0x30(0.0db) 0x1B:10.5db 0x02:(23.0db) 0x23 0x20
  244. { 0x008C, 0x3c },//ADC Digital Volume R default:0x30(0.0db) 0x1B:10.5db 0x02:(23.0db) 0x23 0x3c 0x48
  245. { 0x008D, 0x08 },//(default:AINL1/AINR1:0x02) 2025-08-11: AINL2/AINR2:0x08 INP1/INN1/INP2/INN2:0x0
  246. { 0x008E, 0x00 },// AK7604_8E_ADC_MUTEHPF
  247. { 0x008F, 0x00 },
  248. { 0x0090, 0x00 },
  249. { 0x0091, 0x00 },
  250. { 0x0092, 0x00 },
  251. { 0x0093, 0x00 },
  252. { 0x0094, 0x00 },
  253. { 0x0095, 0x00 },
  254. { 0x0096, 0x00 },
  255. { 0x0097, 0x00 },
  256. { 0x0098, 0x00 },
  257. { 0x0099, 0x00 },
  258. { 0x009A, 0x00 },
  259. { 0x009B, 0x00 },
  260. { 0x009C, 0x00 },
  261. { 0x009D, 0x00 },
  262. { 0x009E, 0x00 },
  263. { 0x009F, 0x00 },
  264. { 0x00A0, 0x00 },
  265. { 0x00A1, 0xBC },//(default:0xB0/0x80) 20241016:0x8c 2024-10-24:0xBC
  266. { 0x00A2, 0x10 },
  267. { 0x00A3, 0x07 },
  268. #else
  269. //ark音频链路方案2
  270. //ark(i2s1)<->ak7604(i2s1)
  271. //ark(i2s2)->fm1505->ak7604(i2s2)->功放
  272. //ak7604(mic-i2s2)->fm1505->ark(i2s0)
  273. { 0x0000, 0x0F },
  274. { 0x0001, 0x07 },
  275. { 0x0002, 0x90 },
  276. { 0x0003, 0x04 },
  277. { 0x0004, 0x03 }, // AK7604_04_SYNCDOMAIN_MS //[011] ->[bit1->ak7604-i2s1:master bit2->ak7604-i2s2:master bit3->ak7604-i2s3:slave]
  278. { 0x0005, 0x08 },
  279. { 0x0006, 0x27 },
  280. { 0x0007, 0x08 },
  281. { 0x0008, 0x27 },
  282. { 0x0009, 0x08 },
  283. { 0x000A, 0x27 },
  284. { 0x000B, 0x08 },
  285. { 0x000C, 0x00 },
  286. { 0x000D, 0x12 },//default:0x12 241010:0x11
  287. { 0x000E, 0x30 },
  288. { 0x000F, 0x12 },
  289. { 0x0010, 0x30 },
  290. { 0x0011, 0x12 },//default:0x10 241010:0x11(SDADC->SD1) 0x12(SDADC->SD2)
  291. { 0x0012, 0x11 },//default:0x11 241010:0x01(SDDAC->SD1) 0x02(SDDAC->SD2)
  292. { 0x0013, 0x11 },//default:0x11 241010:0x10(SDDO2->SD1) 0x20(SDDO2->SD2)
  293. { 0x0014, 0x11 },//default:0x11 241010:0x21
  294. { 0x0015, 0x10 },
  295. { 0x0016, 0x00 },
  296. { 0x0017, 0x10 },//default:0x10 241010:0x12
  297. { 0x0018, 0x00 },
  298. { 0x0019, 0x0E },//SDOUT1A Source Selector "arecord: SDOUT1A->ADC(0x0E)"
  299. { 0x001A, 0x00 },
  300. { 0x001B, 0x00 },
  301. { 0x001C, 0x00 },
  302. { 0x001D, 0x0E },//SDOUT2 Source Selector(default:0x00) "arecord: SDOUT2->ADC(0x0E)"
  303. { 0x001E, 0x09 },//SDOUT3 Source Selector(default:0x09) "arecord: SDOUT3->ADC(0x0E)"
  304. { 0x001F, 0x01 },//DAC1 Source Selector(default:0x08) "Playback : SDIN1(0x01) -> DSP1 -> DAC1 (SYNC1_Slave) or SDIN2(0x05) -> DSP1 -> DAC1 (SYNC1_Slave)"
  305. { 0x0020, 0x05 },//DAC2 Source Selector(default:0x0A)
  306. { 0x0021, 0x00 },//DAC3 Source Selector
  307. { 0x0022, 0x01 },//default:0x01 241010:0x05
  308. { 0x0023, 0x05 },
  309. { 0x0024, 0x0F },
  310. { 0x0025, 0x00 },
  311. { 0x0026, 0x00 },
  312. { 0x0027, 0x00 },
  313. { 0x0028, 0x06 },//default:0x06 241010:0x05
  314. { 0x0029, 0x00 },//default:0x00 241010:0x05
  315. { 0x002A, 0x00 },
  316. { 0x002B, 0x00 },
  317. { 0x002C, 0x00 },
  318. { 0x002D, 0x00 },
  319. { 0x002E, 0x00 },
  320. { 0x002F, 0x00 },
  321. { 0x0030, 0x00 },
  322. { 0x0031, 0x00 },
  323. { 0x0032, 0x00 },
  324. { 0x0033, 0x00 },
  325. { 0x0034, 0x00 },
  326. { 0x0035, 0x00 },
  327. { 0x0036, 0x00 },
  328. { 0x0037, 0x00 },
  329. { 0x0038, 0x00 },
  330. { 0x0039, 0x00 },
  331. { 0x003A, 0x00 },
  332. { 0x003B, 0x00 },
  333. { 0x003C, 0x00 },
  334. { 0x003D, 0x00 },
  335. { 0x003E, 0x00 },
  336. { 0x003F, 0x00 },
  337. { 0x0040, 0x00 },
  338. { 0x0041, 0x00 },
  339. { 0x0042, 0x00 },
  340. { 0x0043, 0x00 },
  341. { 0x0044, 0x00 },
  342. { 0x0045, 0x00 },
  343. { 0x0046, 0x00 },
  344. { 0x0047, 0x00 },
  345. { 0x0048, 0x00 },
  346. { 0x0049, 0x00 },
  347. { 0x004A, 0x00 },
  348. { 0x004B, 0x00 },
  349. { 0x004C, 0x00 },
  350. { 0x004D, 0x00 },
  351. { 0x004E, 0x00 },
  352. { 0x004F, 0x00 },
  353. { 0x0050, 0x00 },
  354. { 0x0051, 0xE1 },
  355. { 0x0052, 0x00 },
  356. { 0x0053, 0x00 },
  357. { 0x0054, 0x00 },
  358. { 0x0055, 0x00 },
  359. { 0x0056, 0x00 },
  360. { 0x0057, 0x00 },
  361. { 0x0058, 0x00 },
  362. { 0x0059, 0x00 },
  363. { 0x005A, 0x00 },
  364. { 0x005B, 0x00 },
  365. { 0x005C, 0x00 },
  366. { 0x005D, 0x00 },
  367. { 0x005E, 0x00 },
  368. { 0x005F, 0x00 },
  369. { 0x0060, 0x00 },
  370. { 0x0061, 0x00 },
  371. { 0x0062, 0x00 },
  372. { 0x0063, 0x00 },
  373. { 0x0064, 0x00 },
  374. { 0x0065, 0x00 },
  375. { 0x0066, 0x00 },
  376. { 0x0067, 0x00 },
  377. { 0x0068, 0x00 },
  378. { 0x0069, 0x00 },
  379. { 0x006A, 0x00 },
  380. { 0x006B, 0x00 },
  381. { 0x006C, 0x00 },
  382. { 0x006D, 0x00 },
  383. { 0x006E, 0x00 },
  384. { 0x006F, 0x00 },
  385. { 0x0070, 0x00 },
  386. { 0x0071, 0x00 },
  387. { 0x0072, 0x00 },
  388. { 0x0073, 0x0F },
  389. { 0x0074, 0x00 },
  390. { 0x0075, 0x00 },
  391. { 0x0076, 0x00 },
  392. { 0x0077, 0x00 },
  393. { 0x0078, 0x00 },
  394. { 0x0079, 0x00 },
  395. { 0x007A, 0x00 },
  396. { 0x007B, 0x00 },
  397. { 0x007C, 0x00 },
  398. { 0x007D, 0x00 },
  399. { 0x007E, 0x00 },
  400. { 0x007F, 0x00 },
  401. { 0x0080, 0x00 },
  402. { 0x0081, 0x00 },
  403. { 0x0082, 0xFF },//MIC Input Volume L/R 36dB
  404. { 0x0083, 0x4b },//DAC1 Digital Volume L default:0x18(0.0db) 69(-40.5db)
  405. { 0x0084, 0x4b },//DAC1 Digital Volume R default:0x18 69(-40.5db)
  406. { 0x0085, 0x4b },//DAC2 Digital Volume L default:0x18 69(-40.5db)
  407. { 0x0086, 0x4b },//DAC2 Digital Volume R default:0x18 69(-40.5db)
  408. { 0x0087, 0x4b },//DAC3 Digital Volume L default:0x18 69(-40.5db)
  409. { 0x0088, 0x4b },//DAC3 Digital Volume R default:0x18 69(-40.5db)
  410. { 0x0089, 0x00 }, // AK7604_89_DAC_MUTEFILTER
  411. { 0x008A, 0x15 },
  412. { 0x008B, 0x08 },//ADC Digital Volume L default:0x30(0.0db) 0x1B:10.5db 0x08:(20.0db)
  413. { 0x008C, 0x08 },//ADC Digital Volume R default:0x30(0.0db) 0x1B:10.5db 0x08:(20.0db)
  414. { 0x008D, 0x02 },
  415. { 0x008E, 0x00 },// AK7604_8E_ADC_MUTEHPF
  416. { 0x008F, 0x00 },
  417. { 0x0090, 0x00 },
  418. { 0x0091, 0x00 },
  419. { 0x0092, 0x00 },
  420. { 0x0093, 0x00 },
  421. { 0x0094, 0x00 },
  422. { 0x0095, 0x00 },
  423. { 0x0096, 0x00 },
  424. { 0x0097, 0x00 },
  425. { 0x0098, 0x00 },
  426. { 0x0099, 0x00 },
  427. { 0x009A, 0x00 },
  428. { 0x009B, 0x00 },
  429. { 0x009C, 0x00 },
  430. { 0x009D, 0x00 },
  431. { 0x009E, 0x00 },
  432. { 0x009F, 0x00 },
  433. { 0x00A0, 0x00 },
  434. { 0x00A1, 0xB0 },//default:0xB0 241010:0xbc
  435. { 0x00A2, 0x10 },//default:0x10 241010:0x30
  436. { 0x00A3, 0x03 },//default:0x07 241010:0x00
  437. // { 0x00A4, 0x00 }, //
  438. // { 0x00A5, 0x00 }, //
  439. // { 0x00A6, 0x00 }, //
  440. // { 0x00A7, 0x00 }, //
  441. // { 0x00A8, 0x00 }, //
  442. // { 0x00A9, 0x00 }, //
  443. // { 0x00AA, 0x00 }, //
  444. // { 0x00AB, 0x00 }, //
  445. // { 0x00AC, 0x00 }, //
  446. // { 0x00AD, 0x00 }, //
  447. // { 0x00AE, 0x00 }, //
  448. // { 0x00AF, 0x00 }, //
  449. // { 0x00B0, 0x00 }, //
  450. // { 0x00B1, 0x00 }, //
  451. // { 0x00B2, 0x00 }, //
  452. // { 0x00B3, 0x00 }, //
  453. // { 0x00B4, 0x00 }, //
  454. // { 0x00B5, 0x00 }, //
  455. // { 0x00B6, 0x00 }, //
  456. // { 0x00B7, 0x00 }, //
  457. // { 0x00B8, 0x00 }, //
  458. // { 0x00B9, 0x00 }, //
  459. // { 0x00BA, 0x00 }, //
  460. // { 0x00BB, 0x00 }, //
  461. // { 0x00BC, 0x00 }, //
  462. // { 0x00BD, 0x00 }, //
  463. // { 0x00BE, 0x00 }, //
  464. // { 0x00BF, 0x00 }, //
  465. // { 0x00C0, 0x04 }, // AK7604_C0_DEVICE_ID
  466. // { 0x00C1, 0x00 }, // AK7604_C1_REVISION_NUM
  467. // { 0x00C2, 0xA0 }, // AK7604_C2_DSPERROR_STATUS
  468. // { 0x00C3, 0x00 }, // AK7604_C3_SRC_STATUS
  469. // { 0x00C4, 0x00 }, //
  470. // { 0x00C5, 0x00 }, //
  471. // { 0x00C6, 0x80 }, // AK7604_C6_STO_READOUT
  472. // { 0x00C7, 0x00 }, // AK7604_VIRT_C7_DSPOUT1_MIX
  473. // { 0x00C8, 0x00 }, // AK7604_VIRT_C8_DSPOUT2_MIX
  474. // { 0x00C9, 0x00 }, // AK7604_VIRT_C9_DSPOUT3_MIX
  475. // { 0x00CA, 0x00 }, // AK7604_VIRT_CA_DSPOUT4_MIX
  476. // { 0x00CB, 0x00 }, // AK7604_VIRT_CB_DSPOUT5_MIX
  477. // { 0x00CC, 0x00 }, // AK7604_VIRT_CC_DSPOUT6_MIX
  478. #endif
  479. };
  480. // MIC Input Volume control:
  481. // from 0 to 36 dB (quantity of each step is various)
  482. static DECLARE_TLV_DB_MINMAX(mgn_tlv, 0, 3600);
  483. // ADC, ADC2 Digital Volume control:
  484. // from -103.5 to 24 dB in 0.5 dB steps (mute instead of -103.5 dB)
  485. static DECLARE_TLV_DB_SCALE(voladc_tlv, -10350, 50, 0);
  486. // DAC Digital Volume control:
  487. // from -115.5 to 12 dB in 0.5 dB steps (mute instead of -115.5 dB)
  488. static DECLARE_TLV_DB_SCALE(voldac_tlv, -11550, 50, 0);
  489. static const char * const atspad_texts[] = {
  490. "4/fs", "16/fs"
  491. };
  492. static const char * const atspda_texts[] = {
  493. "4/fs", "16/fs"
  494. };
  495. static const char * const dac_digfilsel_texts[] = {
  496. "Sharp",
  497. "Slow",
  498. "Short Delay Sharp",
  499. "Short Delay Slow",
  500. };
  501. static const char * const dac_deemphasis_texts[] = {
  502. "44.1kHz", "OFF", "48kHz", "32kHz"
  503. };
  504. static const struct soc_enum ak7604_codec_enum[] = {
  505. SOC_ENUM_SINGLE(AK7604_8E_ADC_MUTEHPF, 7, ARRAY_SIZE(atspad_texts), atspad_texts),
  506. SOC_ENUM_SINGLE(AK7604_89_DAC_MUTEFILTER, 7, ARRAY_SIZE(atspda_texts), atspda_texts),
  507. SOC_ENUM_SINGLE(AK7604_89_DAC_MUTEFILTER, 0,
  508. ARRAY_SIZE(dac_digfilsel_texts), dac_digfilsel_texts),
  509. SOC_ENUM_SINGLE(AK7604_8A_DAC_DEEM_, 0,
  510. ARRAY_SIZE(dac_deemphasis_texts), dac_deemphasis_texts),//DAC1
  511. SOC_ENUM_SINGLE(AK7604_8A_DAC_DEEM_, 2,
  512. ARRAY_SIZE(dac_deemphasis_texts), dac_deemphasis_texts),//DAC2
  513. SOC_ENUM_SINGLE(AK7604_8A_DAC_DEEM_, 4,
  514. ARRAY_SIZE(dac_deemphasis_texts), dac_deemphasis_texts),//DAC3
  515. };
  516. static const char * const sdselbit_texts[] = {
  517. "Low", "SYNC1", "SYNC2", "SYNC3", "SYNC4",
  518. };
  519. static const struct soc_enum ak7604_sdsel_enum[] = {
  520. SOC_ENUM_SINGLE(AK7604_11_SYNCDOMAIN_SEL3, 4,
  521. ARRAY_SIZE(sdselbit_texts), sdselbit_texts), //SDOUT1
  522. SOC_ENUM_SINGLE(AK7604_11_SYNCDOMAIN_SEL3, 0,
  523. ARRAY_SIZE(sdselbit_texts), sdselbit_texts), //SDOUT2
  524. SOC_ENUM_SINGLE(AK7604_12_SYNCDOMAIN_SEL4, 4,
  525. ARRAY_SIZE(sdselbit_texts), sdselbit_texts), //SDOUT3
  526. SOC_ENUM_SINGLE(AK7604_12_SYNCDOMAIN_SEL4, 0,
  527. ARRAY_SIZE(sdselbit_texts), sdselbit_texts), //DAC
  528. SOC_ENUM_SINGLE(AK7604_13_SYNCDOMAIN_SEL5, 4,
  529. ARRAY_SIZE(sdselbit_texts), sdselbit_texts), //ADC
  530. SOC_ENUM_SINGLE(AK7604_13_SYNCDOMAIN_SEL5, 0,
  531. ARRAY_SIZE(sdselbit_texts), sdselbit_texts), //DSP
  532. SOC_ENUM_SINGLE(AK7604_14_SYNCDOMAIN_SEL6, 4,
  533. ARRAY_SIZE(sdselbit_texts), sdselbit_texts), //DSPO1
  534. SOC_ENUM_SINGLE(AK7604_14_SYNCDOMAIN_SEL6, 0,
  535. ARRAY_SIZE(sdselbit_texts), sdselbit_texts), //DSPO2
  536. SOC_ENUM_SINGLE(AK7604_15_SYNCDOMAIN_SEL7, 4,
  537. ARRAY_SIZE(sdselbit_texts), sdselbit_texts), //DSPO3
  538. SOC_ENUM_SINGLE(AK7604_15_SYNCDOMAIN_SEL7, 0,
  539. ARRAY_SIZE(sdselbit_texts), sdselbit_texts), //DSPO4
  540. SOC_ENUM_SINGLE(AK7604_16_SYNCDOMAIN_SEL8, 4,
  541. ARRAY_SIZE(sdselbit_texts), sdselbit_texts), //DSPO5
  542. SOC_ENUM_SINGLE(AK7604_16_SYNCDOMAIN_SEL8, 0,
  543. ARRAY_SIZE(sdselbit_texts), sdselbit_texts), //DSPO6
  544. SOC_ENUM_SINGLE(AK7604_17_SYNCDOMAIN_SEL9, 4,
  545. ARRAY_SIZE(sdselbit_texts), sdselbit_texts), //SRCO1
  546. SOC_ENUM_SINGLE(AK7604_17_SYNCDOMAIN_SEL9, 0,
  547. ARRAY_SIZE(sdselbit_texts), sdselbit_texts), //SRCO2
  548. SOC_ENUM_SINGLE(AK7604_18_SYNCDOMAIN_SEL10, 4,
  549. ARRAY_SIZE(sdselbit_texts), sdselbit_texts), //SRCO3
  550. SOC_ENUM_SINGLE(AK7604_18_SYNCDOMAIN_SEL10, 0,
  551. ARRAY_SIZE(sdselbit_texts), sdselbit_texts), //SRCO4
  552. };
  553. static const char * const fsmodebit_texts[] = {
  554. "8kHz:8kHz", "12kHz:12kHz", "16kHz:16kHz", "24kHz:24kHz",
  555. "32kHz:32kHz", "32kHz:16kHz", "32kHz:8kHz", "48kHz:48kHz",
  556. "48kHz:24kHz", "48kHz:16kHz", "48kHz:8kHz", "96kHz:96kHz",
  557. "96kHz:48kHz", "96kHz:32kHz", "96kHz:24kHz", "96kHz:16kHz",
  558. "96kHz:8kHz"
  559. };
  560. static const struct soc_enum ak7604_fsmode_enum[] = {
  561. SOC_ENUM_SINGLE(AK7604_01_SYSTEMCLOCK_2, 0, ARRAY_SIZE(fsmodebit_texts), fsmodebit_texts),
  562. };
  563. // ak7604_set_dai_fmt() takes priority
  564. // This is for SD that is not assigned to BICK/LRCK pin
  565. static const char * const msnbit_texts[] = {
  566. "Slave", "Master"
  567. };
  568. static const struct soc_enum ak7604_msnbit_enum[] = {
  569. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(msnbit_texts), msnbit_texts),
  570. };
  571. static const struct soc_enum ak7604_portsdsel_enum[] = {
  572. SOC_ENUM_SINGLE(AK7604_0F_SYNCDOMAIN_SEL1, 4,
  573. ARRAY_SIZE(sdselbit_texts), sdselbit_texts), //SDBCK1[2:0]
  574. SOC_ENUM_SINGLE(AK7604_0F_SYNCDOMAIN_SEL1, 0,
  575. ARRAY_SIZE(sdselbit_texts), sdselbit_texts), //SDBCK2[2:0]
  576. SOC_ENUM_SINGLE(AK7604_10_SYNCDOMAIN_SEL2, 4,
  577. ARRAY_SIZE(sdselbit_texts), sdselbit_texts), //SDBCK3[2:0]
  578. };
  579. static const char * const sdcks_texts[] = {
  580. "Low", "PLLMCLK", "XTI", "BICK1", "BICK2", "BICK3"
  581. };
  582. static const struct soc_enum ak7604_sdcks_enum[] = {
  583. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(sdcks_texts), sdcks_texts),
  584. };
  585. static const char * const sd_fs_texts[] = {
  586. "8kHz", "12kHz", "16kHz", "24kHz",
  587. "32kHz", "48kHz", "96kHz"
  588. };
  589. static int sdfstab[] = {
  590. 8000, 12000, 16000, 24000,
  591. 32000, 48000, 96000
  592. };
  593. static const char * const sd_bick_texts[] = {
  594. "64fs", "48fs", "32fs", "128fs", "256fs"
  595. };
  596. static int sdbicktab[] = {
  597. 64, 48, 32, 128, 256
  598. };
  599. static const struct soc_enum ak7604_sd_fs_enum[] = {
  600. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(sd_fs_texts), sd_fs_texts),
  601. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(sd_bick_texts), sd_bick_texts),
  602. };
  603. static int XtiFsTab[] = {
  604. 12288000, 18432000
  605. };
  606. static int PLLInFsTab[] = {
  607. 256000, 384000, 512000, 768000, 1024000,
  608. 1152000, 1536000, 2048000, 2304000, 3072000,
  609. 4096000, 4608000, 6144000, 8192000, 9216000,
  610. 12288000, 18432000, 24576000
  611. };
  612. static int setPLLOut(
  613. struct snd_soc_component *component)
  614. {//akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  615. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  616. int nPLLInFs;
  617. int value, nBfs, fs;
  618. int n, nMax;
  619. value = (ak7604->PLLInput << 5);
  620. snd_soc_component_update_bits(component, AK7604_00_SYSTEMCLOCK_1, 0x60, value);
  621. if (ak7604->PLLInput == 0) {
  622. nPLLInFs = XtiFsTab[ak7604->XtiFs];
  623. } else {
  624. nBfs = sdbicktab[ak7604->SDBick[ak7604->PLLInput-1]];
  625. fs = sdfstab[ak7604->SDfs[ak7604->PLLInput-1]];
  626. akdbgprt("[AK7604] %s nBfs=%d fs=%d\n", __func__, nBfs, fs);
  627. nPLLInFs = nBfs * fs;
  628. }
  629. n = 0;
  630. nMax = ARRAY_SIZE(PLLInFsTab);
  631. do {
  632. //akdbgprt("[AK7604] %s n=%d PLL:%d %d\n", __func__, n, nPLLInFs, PLLInFsTab[n]);
  633. if (nPLLInFs == PLLInFsTab[n])
  634. break;
  635. n++;
  636. } while (n < nMax);
  637. if (n == nMax) {
  638. pr_err("%s: PLL1 setting Error!\n", __func__);
  639. return(-1);
  640. }
  641. snd_soc_component_update_bits(component, AK7604_00_SYSTEMCLOCK_1, 0x1F, n);
  642. return 0;
  643. }
  644. static int setSDMaster(
  645. struct snd_soc_component *component,
  646. int nSDNo,
  647. int nMaster)
  648. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  649. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  650. int addr;
  651. int value;
  652. if (nSDNo >= NUM_SYNCDOMAIN)
  653. return 0;
  654. ak7604->Master[nSDNo] = nMaster;
  655. addr = AK7604_05_SYNCDOMAIN1_SET1 + (2 * nSDNo);
  656. value = ak7604->SDCks[nSDNo] << 3;
  657. snd_soc_component_update_bits(component, addr, 0x38, value);
  658. printk("-->nMaster = %d,nSDNo = %d\n", nMaster, nSDNo);
  659. addr = AK7604_04_SYNCDOMAIN_MS;
  660. value = nMaster << nSDNo;
  661. printk("-->value = %d\n", value);
  662. snd_soc_component_update_bits(component, addr, 1<<nSDNo, value);
  663. return 0;
  664. }
  665. static int setSDClock(
  666. struct snd_soc_component *component,
  667. int nSDNo)
  668. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  669. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  670. int addr;
  671. int fs, bickfs;
  672. int cksBickFs;
  673. int sdv, bdv;
  674. int csksd;
  675. if (nSDNo >= NUM_SYNCDOMAIN)
  676. return 0;
  677. fs = sdfstab[ak7604->SDfs[nSDNo]];
  678. bickfs = sdbicktab[ak7604->SDBick[nSDNo]] * fs;
  679. addr = AK7604_05_SYNCDOMAIN1_SET1 + (2 * nSDNo);
  680. switch (ak7604->SDCks[nSDNo]) {
  681. case 3: // BICK1
  682. case 4: // BICK2
  683. case 5: // BICK3
  684. csksd = ak7604->SDCks[nSDNo] - 3;
  685. cksBickFs = sdbicktab[ak7604->SDBick[csksd]] * sdfstab[ak7604->SDfs[csksd]];
  686. bdv = cksBickFs / bickfs;
  687. if ((cksBickFs % bickfs) != 0)
  688. pr_err("[ak7604]%s: BDV Error! SD No = %d,cks=%d, bick=%d\n",
  689. __func__, nSDNo, cksBickFs, bickfs);
  690. break;
  691. case 2: // XTI
  692. bdv = XtiFsTab[ak7604->XtiFs] / bickfs;
  693. break;
  694. default:
  695. bdv = 122880000 / bickfs;
  696. break;
  697. }
  698. sdv = ak7604->SDBick[nSDNo];
  699. akdbgprt("\t[AK7604]%s, BDV=%d, SDV=%d\n", __func__, bdv, sdbicktab[sdv]);
  700. bdv--;
  701. if (bdv > 255) {
  702. pr_err("%s: BDV Error! SD No = %d, bdv bit = %d\n", __func__, nSDNo, bdv);
  703. bdv = 255;
  704. }
  705. snd_soc_component_update_bits(component, addr, 0x07, sdv);
  706. addr++;
  707. snd_soc_component_write(component, addr, bdv);
  708. if (ak7604->PLLInput == (nSDNo + 1))
  709. setPLLOut(component);
  710. return 0;
  711. }
  712. static int get_sd1_cks(
  713. struct snd_kcontrol *kcontrol,
  714. struct snd_ctl_elem_value *ucontrol)
  715. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  716. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  717. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  718. ucontrol->value.enumerated.item[0] = ak7604->SDCks[0];
  719. return 0;
  720. }
  721. static int set_sd1_cks(
  722. struct snd_kcontrol *kcontrol,
  723. struct snd_ctl_elem_value *ucontrol)
  724. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  725. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  726. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  727. int currMode = ucontrol->value.enumerated.item[0];
  728. if (currMode < ARRAY_SIZE(sdcks_texts)) {
  729. if (ak7604->SDCks[0] != currMode) {
  730. ak7604->SDCks[0] = currMode;
  731. setSDClock(component, 0);
  732. setSDMaster(component, 0, ak7604->Master[0]);
  733. }
  734. } else {
  735. akdbgprt(" [AK7604] %s Invalid Value selected!\n", __func__);
  736. }
  737. return 0;
  738. }
  739. static int get_sd2_cks(
  740. struct snd_kcontrol *kcontrol,
  741. struct snd_ctl_elem_value *ucontrol)
  742. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  743. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  744. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  745. ucontrol->value.enumerated.item[0] = ak7604->SDCks[1];
  746. return 0;
  747. }
  748. static int set_sd2_cks(
  749. struct snd_kcontrol *kcontrol,
  750. struct snd_ctl_elem_value *ucontrol)
  751. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  752. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  753. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  754. int currMode = ucontrol->value.enumerated.item[0];
  755. if (currMode < ARRAY_SIZE(sdcks_texts)) {
  756. if (ak7604->SDCks[1] != currMode) {
  757. ak7604->SDCks[1] = currMode;
  758. setSDClock(component, 1);
  759. setSDMaster(component, 1, ak7604->Master[1]);
  760. }
  761. } else {
  762. akdbgprt(" [AK7604] %s Invalid Value selected!\n", __func__);
  763. }
  764. return 0;
  765. }
  766. static int get_sd3_cks(
  767. struct snd_kcontrol *kcontrol,
  768. struct snd_ctl_elem_value *ucontrol)
  769. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  770. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  771. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  772. ucontrol->value.enumerated.item[0] = ak7604->SDCks[2];
  773. return 0;
  774. }
  775. static int set_sd3_cks(
  776. struct snd_kcontrol *kcontrol,
  777. struct snd_ctl_elem_value *ucontrol)
  778. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  779. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  780. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  781. int currMode = ucontrol->value.enumerated.item[0];
  782. if (currMode < ARRAY_SIZE(sdcks_texts)) {
  783. if (ak7604->SDCks[2] != currMode) {
  784. ak7604->SDCks[2] = currMode;
  785. setSDClock(component, 2);
  786. setSDMaster(component, 2, ak7604->Master[2]);
  787. }
  788. } else {
  789. akdbgprt(" [AK7604] %s Invalid Value selected!\n", __func__);
  790. }
  791. return 0;
  792. }
  793. static int get_sd4_cks(
  794. struct snd_kcontrol *kcontrol,
  795. struct snd_ctl_elem_value *ucontrol)
  796. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  797. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  798. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  799. ucontrol->value.enumerated.item[0] = ak7604->SDCks[3];
  800. return 0;
  801. }
  802. static int set_sd4_cks(
  803. struct snd_kcontrol *kcontrol,
  804. struct snd_ctl_elem_value *ucontrol)
  805. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  806. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  807. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  808. int currMode = ucontrol->value.enumerated.item[0];
  809. if (currMode < ARRAY_SIZE(sdcks_texts)) {
  810. if (ak7604->SDCks[3] != currMode) {
  811. ak7604->SDCks[3] = currMode;
  812. setSDClock(component, 3);
  813. setSDMaster(component, 3, ak7604->Master[3]);
  814. }
  815. } else {
  816. akdbgprt(" [AK7604] %s Invalid Value selected!\n", __func__);
  817. }
  818. return 0;
  819. }
  820. static int get_sd1_ms(
  821. struct snd_kcontrol *kcontrol,
  822. struct snd_ctl_elem_value *ucontrol)
  823. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  824. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  825. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  826. ucontrol->value.enumerated.item[0] = ak7604->Master[0];
  827. return 0;
  828. }
  829. static int set_sd1_ms(
  830. struct snd_kcontrol *kcontrol,
  831. struct snd_ctl_elem_value *ucontrol)
  832. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  833. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  834. int currMode = ucontrol->value.enumerated.item[0];
  835. setSDMaster(component, 0, currMode);
  836. return 0;
  837. }
  838. static int get_sd2_ms(
  839. struct snd_kcontrol *kcontrol,
  840. struct snd_ctl_elem_value *ucontrol)
  841. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  842. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  843. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  844. ucontrol->value.enumerated.item[0] = ak7604->Master[1];
  845. return 0;
  846. }
  847. static int set_sd2_ms(
  848. struct snd_kcontrol *kcontrol,
  849. struct snd_ctl_elem_value *ucontrol)
  850. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  851. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  852. int currMode = ucontrol->value.enumerated.item[0];
  853. setSDMaster(component, 1, currMode);
  854. return 0;
  855. }
  856. static int get_sd3_ms(
  857. struct snd_kcontrol *kcontrol,
  858. struct snd_ctl_elem_value *ucontrol)
  859. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  860. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  861. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  862. ucontrol->value.enumerated.item[0] = ak7604->Master[2];
  863. return 0;
  864. }
  865. static int set_sd3_ms(
  866. struct snd_kcontrol *kcontrol,
  867. struct snd_ctl_elem_value *ucontrol)
  868. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  869. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  870. int currMode = ucontrol->value.enumerated.item[0];
  871. setSDMaster(component, 2, currMode);
  872. return 0;
  873. }
  874. static int get_sd1_fs(
  875. struct snd_kcontrol *kcontrol,
  876. struct snd_ctl_elem_value *ucontrol)
  877. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  878. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  879. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  880. ucontrol->value.enumerated.item[0] = ak7604->SDfs[0];
  881. return 0;
  882. }
  883. static int set_sd1_fs(
  884. struct snd_kcontrol *kcontrol,
  885. struct snd_ctl_elem_value *ucontrol)
  886. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  887. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  888. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  889. int currMode = ucontrol->value.enumerated.item[0];
  890. if (currMode < ARRAY_SIZE(sd_fs_texts)) {
  891. if (ak7604->SDfs[0] != currMode) {
  892. ak7604->SDfs[0] = currMode;
  893. setSDClock(component, 0);
  894. setSDMaster(component, 0, ak7604->Master[0]);
  895. }
  896. } else {
  897. akdbgprt(" [AK7604] %s Invalid Value selected!\n", __func__);
  898. }
  899. return 0;
  900. }
  901. static int get_sd2_fs(
  902. struct snd_kcontrol *kcontrol,
  903. struct snd_ctl_elem_value *ucontrol)
  904. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  905. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  906. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  907. ucontrol->value.enumerated.item[0] = ak7604->SDfs[1];
  908. return 0;
  909. }
  910. static int set_sd2_fs(
  911. struct snd_kcontrol *kcontrol,
  912. struct snd_ctl_elem_value *ucontrol)
  913. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  914. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  915. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  916. int currMode = ucontrol->value.enumerated.item[0];
  917. if (currMode < ARRAY_SIZE(sd_fs_texts)) {
  918. if (ak7604->SDfs[1] != currMode) {
  919. ak7604->SDfs[1] = currMode;
  920. setSDClock(component, 1);
  921. setSDMaster(component, 1, ak7604->Master[1]);
  922. }
  923. } else {
  924. akdbgprt(" [AK7604] %s Invalid Value selected!\n", __func__);
  925. }
  926. return 0;
  927. }
  928. static int get_sd3_fs(
  929. struct snd_kcontrol *kcontrol,
  930. struct snd_ctl_elem_value *ucontrol)
  931. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  932. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  933. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  934. ucontrol->value.enumerated.item[0] = ak7604->SDfs[2];
  935. return 0;
  936. }
  937. static int set_sd3_fs(
  938. struct snd_kcontrol *kcontrol,
  939. struct snd_ctl_elem_value *ucontrol)
  940. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  941. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  942. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  943. int currMode = ucontrol->value.enumerated.item[0];
  944. if (currMode < ARRAY_SIZE(sd_fs_texts)) {
  945. if (ak7604->SDfs[2] != currMode) {
  946. ak7604->SDfs[2] = currMode;
  947. setSDClock(component, 2);
  948. setSDMaster(component, 2, ak7604->Master[2]);
  949. }
  950. } else {
  951. akdbgprt(" [AK7604] %s Invalid Value selected!\n", __func__);
  952. }
  953. return 0;
  954. }
  955. static int get_sd4_fs(
  956. struct snd_kcontrol *kcontrol,
  957. struct snd_ctl_elem_value *ucontrol)
  958. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  959. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  960. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  961. ucontrol->value.enumerated.item[0] = ak7604->SDfs[3];
  962. return 0;
  963. }
  964. static int set_sd4_fs(
  965. struct snd_kcontrol *kcontrol,
  966. struct snd_ctl_elem_value *ucontrol)
  967. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  968. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  969. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  970. int currMode = ucontrol->value.enumerated.item[0];
  971. if (currMode < ARRAY_SIZE(sd_fs_texts)) {
  972. if (ak7604->SDfs[3] != currMode) {
  973. ak7604->SDfs[3] = currMode;
  974. setSDClock(component, 3);
  975. setSDMaster(component, 3, ak7604->Master[3]);
  976. }
  977. } else {
  978. akdbgprt(" [AK7604] %s Invalid Value selected!\n", __func__);
  979. }
  980. return 0;
  981. }
  982. static int get_sd1_bick(
  983. struct snd_kcontrol *kcontrol,
  984. struct snd_ctl_elem_value *ucontrol)
  985. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  986. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  987. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  988. ucontrol->value.enumerated.item[0] = ak7604->SDBick[0];
  989. return 0;
  990. }
  991. static int set_sd1_bick(
  992. struct snd_kcontrol *kcontrol,
  993. struct snd_ctl_elem_value *ucontrol)
  994. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  995. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  996. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  997. int currMode = ucontrol->value.enumerated.item[0];
  998. if (currMode < ARRAY_SIZE(sd_bick_texts)) {
  999. if (ak7604->SDBick[0] != currMode) {
  1000. ak7604->SDBick[0] = currMode;
  1001. setSDClock(component, 0);
  1002. }
  1003. } else {
  1004. akdbgprt(" [AK7604] %s Invalid Value selected!\n", __func__);
  1005. }
  1006. return 0;
  1007. }
  1008. static int get_sd2_bick(
  1009. struct snd_kcontrol *kcontrol,
  1010. struct snd_ctl_elem_value *ucontrol)
  1011. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1012. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1013. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1014. ucontrol->value.enumerated.item[0] = ak7604->SDBick[1];
  1015. return 0;
  1016. }
  1017. static int set_sd2_bick(
  1018. struct snd_kcontrol *kcontrol,
  1019. struct snd_ctl_elem_value *ucontrol)
  1020. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1021. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1022. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1023. int currMode = ucontrol->value.enumerated.item[0];
  1024. if (currMode < ARRAY_SIZE(sd_bick_texts)) {
  1025. if (ak7604->SDBick[1] != currMode) {
  1026. ak7604->SDBick[1] = currMode;
  1027. setSDClock(component, 1);
  1028. }
  1029. } else {
  1030. akdbgprt(" [AK7604] %s Invalid Value selected!\n", __func__);
  1031. }
  1032. return 0;
  1033. }
  1034. static int get_sd3_bick(
  1035. struct snd_kcontrol *kcontrol,
  1036. struct snd_ctl_elem_value *ucontrol)
  1037. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1038. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1039. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1040. ucontrol->value.enumerated.item[0] = ak7604->SDBick[2];
  1041. return 0;
  1042. }
  1043. static int set_sd3_bick(
  1044. struct snd_kcontrol *kcontrol,
  1045. struct snd_ctl_elem_value *ucontrol)
  1046. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1047. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1048. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1049. int currMode = ucontrol->value.enumerated.item[0];
  1050. if (currMode < ARRAY_SIZE(sd_bick_texts)) {
  1051. if (ak7604->SDBick[2] != currMode) {
  1052. ak7604->SDBick[2] = currMode;
  1053. setSDClock(component, 2);
  1054. }
  1055. } else {
  1056. akdbgprt(" [AK7604] %s Invalid Value selected!\n", __func__);
  1057. }
  1058. return 0;
  1059. }
  1060. static int get_sd4_bick(
  1061. struct snd_kcontrol *kcontrol,
  1062. struct snd_ctl_elem_value *ucontrol)
  1063. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1064. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1065. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1066. ucontrol->value.enumerated.item[0] = ak7604->SDBick[3];
  1067. return 0;
  1068. }
  1069. static int set_sd4_bick(
  1070. struct snd_kcontrol *kcontrol,
  1071. struct snd_ctl_elem_value *ucontrol)
  1072. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1073. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1074. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1075. int currMode = ucontrol->value.enumerated.item[0];
  1076. if (currMode < ARRAY_SIZE(sd_bick_texts)) {
  1077. if (ak7604->SDBick[3] != currMode) {
  1078. ak7604->SDBick[3] = currMode;
  1079. setSDClock(component, 3);
  1080. }
  1081. } else {
  1082. akdbgprt(" [AK7604] %s Invalid Value selected!\n", __func__);
  1083. }
  1084. return 0;
  1085. }
  1086. static const char * const pllinput_texts[] = {
  1087. "XTI", "BICK1", "BICK2", "BICK3",
  1088. };
  1089. static const char * const xtifs_texts[] = {
  1090. "12.288MHz", "18.432MHz"
  1091. };
  1092. static const struct soc_enum ak7604_pllset_enum[] = {
  1093. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(pllinput_texts), pllinput_texts),
  1094. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(xtifs_texts), xtifs_texts),
  1095. };
  1096. static int get_pllinput(
  1097. struct snd_kcontrol *kcontrol,
  1098. struct snd_ctl_elem_value *ucontrol)
  1099. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1100. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1101. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1102. ucontrol->value.enumerated.item[0] = ak7604->PLLInput;
  1103. return 0;
  1104. }
  1105. static int set_pllinput(
  1106. struct snd_kcontrol *kcontrol,
  1107. struct snd_ctl_elem_value *ucontrol)
  1108. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1109. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1110. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1111. int currMode = ucontrol->value.enumerated.item[0];
  1112. if (currMode < ARRAY_SIZE(pllinput_texts)) {
  1113. if (ak7604->PLLInput != currMode) {
  1114. ak7604->PLLInput = currMode;
  1115. setPLLOut(component);
  1116. }
  1117. } else {
  1118. akdbgprt(" [AK7604] %s Invalid Value selected!\n", __func__);
  1119. }
  1120. return 0;
  1121. }
  1122. static int get_xtifs(
  1123. struct snd_kcontrol *kcontrol,
  1124. struct snd_ctl_elem_value *ucontrol)
  1125. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1126. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1127. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1128. ucontrol->value.enumerated.item[0] = ak7604->XtiFs;
  1129. return 0;
  1130. }
  1131. static int set_xtifs(
  1132. struct snd_kcontrol *kcontrol,
  1133. struct snd_ctl_elem_value *ucontrol)
  1134. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1135. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1136. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1137. int currMode = ucontrol->value.enumerated.item[0];
  1138. if (currMode < ARRAY_SIZE(xtifs_texts)) {
  1139. if (ak7604->XtiFs != currMode) {
  1140. ak7604->XtiFs = currMode;
  1141. setPLLOut(component);
  1142. }
  1143. } else {
  1144. akdbgprt(" [AK7604] %s Invalid Value selected!\n", __func__);
  1145. }
  1146. return 0;
  1147. }
  1148. static const char * const ak7604_tdm_texts[] = {
  1149. "TDM Off", "TDM On"
  1150. };
  1151. static const struct soc_enum ak7604_tdm_enum[] = {
  1152. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(ak7604_tdm_texts), ak7604_tdm_texts),
  1153. };
  1154. static int get_sdin1_tdm(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1155. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1156. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1157. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1158. ucontrol->value.enumerated.item[0] = ak7604->TDMSDINbit[0];
  1159. return 0;
  1160. }
  1161. static int set_sdin1_tdm(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1162. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1163. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1164. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1165. int currMode = ucontrol->value.enumerated.item[0];
  1166. if (currMode < 2) {
  1167. if (ak7604->TDMSDINbit[0] != currMode) {
  1168. ak7604->TDMSDINbit[0] = currMode;
  1169. ak7604->DIEDGEbit[0] = ak7604->TDMSDINbit[0];
  1170. }
  1171. } else {
  1172. akdbgprt(" [AK7604] %s Invalid Value selected!\n", __func__);
  1173. }
  1174. return 0;
  1175. }
  1176. static int get_sdout1_tdm(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1177. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1178. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1179. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1180. ucontrol->value.enumerated.item[0] = ak7604->TDMSDOUTbit[0];
  1181. return 0;
  1182. }
  1183. static int set_sdout1_tdm(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1184. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1185. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1186. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1187. int currMode = ucontrol->value.enumerated.item[0];
  1188. if (currMode < 2) {
  1189. if (ak7604->TDMSDOUTbit[0] != currMode) {
  1190. ak7604->TDMSDOUTbit[0] = currMode;
  1191. ak7604->DOEDGEbit[0] = ak7604->TDMSDOUTbit[0];
  1192. }
  1193. } else {
  1194. akdbgprt(" [AK7604] %s Invalid Value selected!\n", __func__);
  1195. }
  1196. return 0;
  1197. }
  1198. static const char * const ak7604_sd_ioformat_texts[] = {
  1199. "24bit",
  1200. "20bit",
  1201. "16bit",
  1202. "32bit",
  1203. };
  1204. static const struct soc_enum ak7604_slotlen_enum[] = {
  1205. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(ak7604_sd_ioformat_texts), ak7604_sd_ioformat_texts),
  1206. };
  1207. static int get_sdin1_slot(
  1208. struct snd_kcontrol *kcontrol,
  1209. struct snd_ctl_elem_value *ucontrol)
  1210. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1211. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1212. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1213. ucontrol->value.enumerated.item[0] = ak7604->DISLbit[0];
  1214. return 0;
  1215. }
  1216. static int set_sdin1_slot(
  1217. struct snd_kcontrol *kcontrol,
  1218. struct snd_ctl_elem_value *ucontrol)
  1219. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1220. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1221. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1222. int currMode = ucontrol->value.enumerated.item[0];
  1223. if (currMode < ARRAY_SIZE(ak7604_sd_ioformat_texts)) {
  1224. if (ak7604->DISLbit[0] != currMode)
  1225. ak7604->DISLbit[0] = currMode;
  1226. } else {
  1227. akdbgprt(" [AK7604] %s Invalid Value selected!\n", __func__);
  1228. }
  1229. return 0;
  1230. }
  1231. static int get_sdin2_slot(
  1232. struct snd_kcontrol *kcontrol,
  1233. struct snd_ctl_elem_value *ucontrol)
  1234. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1235. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1236. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1237. ucontrol->value.enumerated.item[0] = ak7604->DISLbit[1];
  1238. return 0;
  1239. }
  1240. static int set_sdin2_slot(
  1241. struct snd_kcontrol *kcontrol,
  1242. struct snd_ctl_elem_value *ucontrol)
  1243. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1244. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1245. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1246. int currMode = ucontrol->value.enumerated.item[0];
  1247. if (currMode < ARRAY_SIZE(ak7604_sd_ioformat_texts)) {
  1248. if (ak7604->DISLbit[1] != currMode)
  1249. ak7604->DISLbit[1] = currMode;
  1250. } else {
  1251. akdbgprt(" [AK7604] %s Invalid Value selected!\n", __func__);
  1252. }
  1253. return 0;
  1254. }
  1255. static int get_sdin3_slot(
  1256. struct snd_kcontrol *kcontrol,
  1257. struct snd_ctl_elem_value *ucontrol)
  1258. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1259. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1260. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1261. ucontrol->value.enumerated.item[0] = ak7604->DISLbit[2];
  1262. return 0;
  1263. }
  1264. static int set_sdin3_slot(
  1265. struct snd_kcontrol *kcontrol,
  1266. struct snd_ctl_elem_value *ucontrol)
  1267. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1268. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1269. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1270. int currMode = ucontrol->value.enumerated.item[0];
  1271. if (currMode < ARRAY_SIZE(ak7604_sd_ioformat_texts)) {
  1272. if (ak7604->DISLbit[2] != currMode)
  1273. ak7604->DISLbit[2] = currMode;
  1274. } else {
  1275. akdbgprt(" [AK7604] %s Invalid Value selected!\n", __func__);
  1276. }
  1277. return 0;
  1278. }
  1279. static int get_sdin4_slot(
  1280. struct snd_kcontrol *kcontrol,
  1281. struct snd_ctl_elem_value *ucontrol)
  1282. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1283. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1284. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1285. ucontrol->value.enumerated.item[0] = ak7604->DISLbit[3];
  1286. return 0;
  1287. }
  1288. static int set_sdin4_slot(
  1289. struct snd_kcontrol *kcontrol,
  1290. struct snd_ctl_elem_value *ucontrol)
  1291. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1292. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1293. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1294. int currMode = ucontrol->value.enumerated.item[0];
  1295. if (currMode < ARRAY_SIZE(ak7604_sd_ioformat_texts)) {
  1296. if (ak7604->DISLbit[3] != currMode)
  1297. ak7604->DISLbit[3] = currMode;
  1298. } else {
  1299. akdbgprt(" [AK7604] %s Invalid Value selected!\n", __func__);
  1300. }
  1301. return 0;
  1302. }
  1303. static int get_sdout1_slot(
  1304. struct snd_kcontrol *kcontrol,
  1305. struct snd_ctl_elem_value *ucontrol)
  1306. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1307. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1308. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1309. ucontrol->value.enumerated.item[0] = ak7604->DOSLbit[0];
  1310. return 0;
  1311. }
  1312. static int set_sdout1_slot(
  1313. struct snd_kcontrol *kcontrol,
  1314. struct snd_ctl_elem_value *ucontrol)
  1315. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1316. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1317. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1318. int currMode = ucontrol->value.enumerated.item[0];
  1319. if (currMode < ARRAY_SIZE(ak7604_sd_ioformat_texts)) {
  1320. if (ak7604->DOSLbit[0] != currMode)
  1321. ak7604->DOSLbit[0] = currMode;
  1322. } else {
  1323. akdbgprt(" [AK7604] %s Invalid Value selected!\n", __func__);
  1324. }
  1325. return 0;
  1326. }
  1327. static int get_sdout2_slot(
  1328. struct snd_kcontrol *kcontrol,
  1329. struct snd_ctl_elem_value *ucontrol)
  1330. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1331. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1332. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1333. ucontrol->value.enumerated.item[0] = ak7604->DOSLbit[1];
  1334. return 0;
  1335. }
  1336. static int set_sdout2_slot(
  1337. struct snd_kcontrol *kcontrol,
  1338. struct snd_ctl_elem_value *ucontrol)
  1339. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1340. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1341. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1342. int currMode = ucontrol->value.enumerated.item[0];
  1343. if (currMode < ARRAY_SIZE(ak7604_sd_ioformat_texts)) {
  1344. if (ak7604->DOSLbit[1] != currMode)
  1345. ak7604->DOSLbit[1] = currMode;
  1346. } else {
  1347. akdbgprt(" [AK7604] %s Invalid Value selected!\n", __func__);
  1348. }
  1349. return 0;
  1350. }
  1351. static int get_sdout3_slot(
  1352. struct snd_kcontrol *kcontrol,
  1353. struct snd_ctl_elem_value *ucontrol)
  1354. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1355. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1356. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1357. ucontrol->value.enumerated.item[0] = ak7604->DOSLbit[2];
  1358. return 0;
  1359. }
  1360. static int set_sdout3_slot(
  1361. struct snd_kcontrol *kcontrol,
  1362. struct snd_ctl_elem_value *ucontrol)
  1363. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1364. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1365. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1366. int currMode = ucontrol->value.enumerated.item[0];
  1367. if (currMode < ARRAY_SIZE(ak7604_sd_ioformat_texts)) {
  1368. if (ak7604->DOSLbit[2] != currMode)
  1369. ak7604->DOSLbit[2] = currMode;
  1370. } else {
  1371. akdbgprt(" [AK7604] %s Invalid Value selected!\n", __func__);
  1372. }
  1373. return 0;
  1374. }
  1375. static const char * const sdout_modeset_texts[] = {
  1376. "Slow", "Fast"
  1377. };
  1378. static const struct soc_enum ak7604_sdout_modeset_enum[] = {
  1379. SOC_ENUM_SINGLE(AK7604_50_INPUT_DATA, 4,
  1380. ARRAY_SIZE(sdout_modeset_texts), sdout_modeset_texts),
  1381. SOC_ENUM_SINGLE(AK7604_50_INPUT_DATA, 5,
  1382. ARRAY_SIZE(sdout_modeset_texts), sdout_modeset_texts),
  1383. SOC_ENUM_SINGLE(AK7604_50_INPUT_DATA, 6,
  1384. ARRAY_SIZE(sdout_modeset_texts), sdout_modeset_texts),
  1385. };
  1386. static const char * const do1sel_texts[] = {
  1387. "L", "SDOUT1"
  1388. };
  1389. static const char * const do2sel_texts[] = {
  1390. "L", "L1", "L2", "L3", "DZF", "DZF Invert", "SDOUT2", "RDY"
  1391. };
  1392. static const char * const do3sel_texts[] = {
  1393. "STO", "SDOUT3", "GPO", "GPO Invert", "L"
  1394. };
  1395. static const struct soc_enum ak7604_outportsel_enum[] = {
  1396. SOC_ENUM_SINGLE(AK7604_51_SELECT_DATA, 7, ARRAY_SIZE(do1sel_texts), do1sel_texts),
  1397. SOC_ENUM_SINGLE(AK7604_51_SELECT_DATA, 4, ARRAY_SIZE(do2sel_texts), do2sel_texts),
  1398. SOC_ENUM_SINGLE(AK7604_51_SELECT_DATA, 0, ARRAY_SIZE(do3sel_texts), do3sel_texts),
  1399. };
  1400. static const char * const di3sel_texts[] = {
  1401. "SDIN3", "JX3"
  1402. };
  1403. static const char * const bck3sel_texts[] = {
  1404. "BICK3", "JX1"
  1405. };
  1406. static const char * const lck3sel_texts[] = {
  1407. "LRCK3", "JX0", "N/A", "SDIN4"
  1408. };
  1409. static const struct soc_enum ak7604_inportsel_enum[] = {
  1410. SOC_ENUM_SINGLE(AK7604_50_INPUT_DATA, 3, ARRAY_SIZE(di3sel_texts), di3sel_texts),
  1411. SOC_ENUM_SINGLE(AK7604_50_INPUT_DATA, 2, ARRAY_SIZE(bck3sel_texts), bck3sel_texts),
  1412. SOC_ENUM_SINGLE(AK7604_50_INPUT_DATA, 0, ARRAY_SIZE(lck3sel_texts), lck3sel_texts),
  1413. };
  1414. static const char * const src_softmute_texts[] = {
  1415. "Manual", "Semi Auto"
  1416. };
  1417. static const struct soc_enum ak7604_src_softmute_enum[] = {
  1418. SOC_ENUM_SINGLE(AK7604_71_SRCMUTE_SETTING, 0,
  1419. ARRAY_SIZE(src_softmute_texts), src_softmute_texts),
  1420. SOC_ENUM_SINGLE(AK7604_71_SRCMUTE_SETTING, 1,
  1421. ARRAY_SIZE(src_softmute_texts), src_softmute_texts),
  1422. SOC_ENUM_SINGLE(AK7604_71_SRCMUTE_SETTING, 2,
  1423. ARRAY_SIZE(src_softmute_texts), src_softmute_texts),
  1424. SOC_ENUM_SINGLE(AK7604_71_SRCMUTE_SETTING, 3,
  1425. ARRAY_SIZE(src_softmute_texts), src_softmute_texts),
  1426. };
  1427. static const char * const src_softdfil_texts[] = {
  1428. "Voice", "Audio"
  1429. };
  1430. static const struct soc_enum ak7604_src_dfil_enum[] = {
  1431. SOC_ENUM_SINGLE(AK7604_73_SRCFILTER_SETTING, 0,
  1432. ARRAY_SIZE(src_softdfil_texts), src_softdfil_texts),
  1433. SOC_ENUM_SINGLE(AK7604_73_SRCFILTER_SETTING, 1,
  1434. ARRAY_SIZE(src_softdfil_texts), src_softdfil_texts),
  1435. SOC_ENUM_SINGLE(AK7604_73_SRCFILTER_SETTING, 2,
  1436. ARRAY_SIZE(src_softdfil_texts), src_softdfil_texts),
  1437. SOC_ENUM_SINGLE(AK7604_73_SRCFILTER_SETTING, 3,
  1438. ARRAY_SIZE(src_softdfil_texts), src_softdfil_texts),
  1439. };
  1440. static const char * const dsp_drmbk_texts[] = { // BANK1/BANK0
  1441. "0/6144", "1024/5120", "2048/4096", "3072/3072"
  1442. };
  1443. static const char * const dsp_assign_dram_texts[] = { // BANK1/BANK0
  1444. "Ring/Ring", "Ring/Linear", "Linear/Ring", "Linear/Linear"
  1445. };
  1446. static const struct soc_enum ak7604_dsp_dram_enum[] = {
  1447. SOC_ENUM_SINGLE(AK7604_60_DSP_SETTING1, 0,
  1448. ARRAY_SIZE(dsp_drmbk_texts), dsp_drmbk_texts),
  1449. SOC_ENUM_SINGLE(AK7604_60_DSP_SETTING1, 2,
  1450. ARRAY_SIZE(dsp_assign_dram_texts), dsp_assign_dram_texts),
  1451. };
  1452. static const struct soc_enum ak7604_firmware_enum[] = {
  1453. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(ak7604_firmware_pram), ak7604_firmware_pram),
  1454. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(ak7604_firmware_cram), ak7604_firmware_cram),
  1455. };
  1456. static int ak7604_firmware_write_ram(struct snd_soc_component *component, u16 mode, u16 cmd);
  1457. static int ak7604_set_status(struct snd_soc_component *component, enum ak7604_status status);
  1458. static int ak7604_write_cram(struct snd_soc_component *component,
  1459. int addr, int len, unsigned char *cram_data);
  1460. static int get_DSP_write_pram(
  1461. struct snd_kcontrol *kcontrol,
  1462. struct snd_ctl_elem_value *ucontrol)
  1463. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1464. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1465. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1466. /* Get the current output routing */
  1467. ucontrol->value.enumerated.item[0] = ak7604->DSPPramMode;
  1468. return 0;
  1469. }
  1470. static int set_DSP_write_pram(
  1471. struct snd_kcontrol *kcontrol,
  1472. struct snd_ctl_elem_value *ucontrol)
  1473. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1474. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1475. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1476. int currMode = ucontrol->value.enumerated.item[0];
  1477. int ret;
  1478. akdbgprt("\t%s PRAM mode =%d\n", __func__, currMode);
  1479. ret = ak7604_firmware_write_ram(component, RAMTYPE_PRAM, currMode);
  1480. if (ret != 0)
  1481. return(-1);
  1482. ak7604->DSPPramMode = currMode;
  1483. return 0;
  1484. }
  1485. static int get_DSP_write_cram(
  1486. struct snd_kcontrol *kcontrol,
  1487. struct snd_ctl_elem_value *ucontrol)
  1488. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1489. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1490. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1491. /* Get the current output routing */
  1492. ucontrol->value.enumerated.item[0] = ak7604->DSPCramMode;
  1493. return 0;
  1494. }
  1495. static int set_DSP_write_cram(
  1496. struct snd_kcontrol *kcontrol,
  1497. struct snd_ctl_elem_value *ucontrol)
  1498. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1499. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1500. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1501. int currMode = ucontrol->value.enumerated.item[0];
  1502. int ret;
  1503. akdbgprt("\t%s CRAM mode =%d\n", __func__, currMode);
  1504. ret = ak7604_firmware_write_ram(component, RAMTYPE_CRAM, currMode);
  1505. if (ret != 0)
  1506. return(-1);
  1507. ak7604->DSPCramMode = currMode;
  1508. return 0;
  1509. }
  1510. static int ak7604_reads(struct snd_soc_component *component, u8 *, size_t, u8 *, size_t);
  1511. static const char * const ak7604_cram_write_exec_texts[] = {
  1512. "Wait", "Execute",
  1513. };
  1514. static const struct soc_enum ak7604_cramope_enum[] = {
  1515. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(ak7604_cram_value), ak7604_cram_value),
  1516. SOC_ENUM_SINGLE_EXT(256, ak7604_cram_value),
  1517. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(ak7604_cram_write_exec_texts), ak7604_cram_write_exec_texts),
  1518. };
  1519. static int get_cram_write_addr(
  1520. struct snd_kcontrol *kcontrol,
  1521. struct snd_ctl_elem_value *ucontrol)
  1522. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1523. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1524. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1525. /* Get the current output routing */
  1526. ucontrol->value.enumerated.item[0] = ak7604->cramaddr;
  1527. return 0;
  1528. }
  1529. static int set_cram_write_addr(
  1530. struct snd_kcontrol *kcontrol,
  1531. struct snd_ctl_elem_value *ucontrol)
  1532. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1533. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1534. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1535. int n;
  1536. u32 currMode = ucontrol->value.enumerated.item[0];
  1537. if (currMode >= ARRAY_SIZE(ak7604_cram_value))
  1538. return -EINVAL;
  1539. ak7604->cramaddr = currMode;
  1540. ak7604->cramcount = 0;
  1541. for (n = 0; n < 48; n++)
  1542. ak7604->cramvalue[n] = 0xFF;
  1543. return 0;
  1544. }
  1545. static int get_cram_write_valueH(
  1546. struct snd_kcontrol *kcontrol,
  1547. struct snd_ctl_elem_value *ucontrol)
  1548. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1549. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1550. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1551. int n;
  1552. if ((ak7604->cramcount == 0) || (ak7604->cramcount > 16))
  1553. n = 0;
  1554. else
  1555. n = 3 * (ak7604->cramcount - 1);
  1556. ucontrol->value.enumerated.item[0] = ak7604->cramvalue[n];
  1557. return 0;
  1558. }
  1559. static int set_cram_write_valueH(
  1560. struct snd_kcontrol *kcontrol,
  1561. struct snd_ctl_elem_value *ucontrol)
  1562. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1563. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1564. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1565. u32 currMode = ucontrol->value.enumerated.item[0];
  1566. int n;
  1567. if (ak7604->cramcount > 15)
  1568. return -EINVAL;
  1569. n = 3 * ak7604->cramcount;
  1570. ak7604->cramvalue[n] = currMode;
  1571. return 0;
  1572. }
  1573. static int get_cram_write_valueM(
  1574. struct snd_kcontrol *kcontrol,
  1575. struct snd_ctl_elem_value *ucontrol)
  1576. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1577. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1578. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1579. int n;
  1580. if ((ak7604->cramcount == 0) || (ak7604->cramcount > 16))
  1581. n = 0;
  1582. else
  1583. n = 3 * (ak7604->cramcount - 1) + 1;
  1584. ucontrol->value.enumerated.item[0] = ak7604->cramvalue[n];
  1585. return 0;
  1586. }
  1587. static int set_cram_write_valueM(
  1588. struct snd_kcontrol *kcontrol,
  1589. struct snd_ctl_elem_value *ucontrol)
  1590. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1591. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1592. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1593. u32 currMode = ucontrol->value.enumerated.item[0];
  1594. int n;
  1595. if (ak7604->cramcount > 15)
  1596. return -EINVAL;
  1597. n = 3 * ak7604->cramcount + 1;
  1598. ak7604->cramvalue[n] = currMode;
  1599. return 0;
  1600. }
  1601. static int get_cram_write_valueL(
  1602. struct snd_kcontrol *kcontrol,
  1603. struct snd_ctl_elem_value *ucontrol)
  1604. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1605. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1606. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1607. int n;
  1608. if ((ak7604->cramcount == 0) || (ak7604->cramcount > 16))
  1609. n = 0;
  1610. else
  1611. n = 3 * (ak7604->cramcount - 1) + 2;
  1612. ucontrol->value.enumerated.item[0] = ak7604->cramvalue[n];
  1613. return 0;
  1614. }
  1615. static int set_cram_write_valueL(
  1616. struct snd_kcontrol *kcontrol,
  1617. struct snd_ctl_elem_value *ucontrol)
  1618. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1619. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1620. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1621. u32 currMode = ucontrol->value.enumerated.item[0];
  1622. int n;
  1623. if (ak7604->cramcount > 15)
  1624. return -EINVAL;
  1625. n = 3 * ak7604->cramcount + 2;
  1626. ak7604->cramvalue[n] = currMode;
  1627. ak7604->cramcount++;
  1628. return 0;
  1629. }
  1630. static int get_cram_write_exec(
  1631. struct snd_kcontrol *kcontrol,
  1632. struct snd_ctl_elem_value *ucontrol)
  1633. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1634. ucontrol->value.enumerated.item[0] = 0;
  1635. return 0;
  1636. }
  1637. static int set_cram_write_exec(
  1638. struct snd_kcontrol *kcontrol,
  1639. struct snd_ctl_elem_value *ucontrol)
  1640. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1641. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1642. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  1643. u32 currMode = ucontrol->value.enumerated.item[0];
  1644. int n, ret;
  1645. if (currMode > 1)
  1646. return(-EINVAL);
  1647. if (currMode == 0)
  1648. return 0;
  1649. if (ak7604->cramcount == 0)
  1650. return(-EINVAL);
  1651. if (ak7604->cramcount < 16)
  1652. n = 3 * ak7604->cramcount;
  1653. else
  1654. n = 48;
  1655. ret = ak7604_write_cram(component, ak7604->cramaddr, n, ak7604->cramvalue);
  1656. ak7604->cramcount = 0;
  1657. if (ret < 0)
  1658. return(-EINVAL);
  1659. return 0;
  1660. }
  1661. #ifdef AK7604_DEBUG
  1662. static bool ak7604_readable(struct device *dev, unsigned int reg);
  1663. static int test_read_ram(struct snd_soc_component *component, int mode)
  1664. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1665. u8 tx[3], rx[512];
  1666. int i, n, plen, clen;
  1667. akdbgprt("*****[AK7604] %s(%d)\n", __func__, __LINE__);
  1668. ak7604_set_status(component, DOWNLOAD);
  1669. mdelay(1);
  1670. if (mode == 0) {
  1671. plen = 16;
  1672. for (n = 0; n < (5 * plen); n++)
  1673. rx[n] = 0;
  1674. tx[0] = (COMMAND_WRITE_PRAM & 0x7F) + mode;
  1675. tx[1] = 0x0;
  1676. tx[2] = 0x0;
  1677. ak7604_reads(component, tx, 3, rx, 5 * plen);
  1678. akdbgprt("***** AK7604 PRAM LEN = %d *******\n", plen);
  1679. n = 0;
  1680. for (i = 0; i < plen; i++) {
  1681. akdbgprt("AK7604 PAddr=%03X : %02X%02X%02X%02X%02X\n", i,
  1682. (int)rx[n], (int)rx[n+1], (int)rx[n+2], (int)rx[n+3], (int)rx[n+4]);
  1683. n += 5;
  1684. }
  1685. } else {
  1686. clen = 16;
  1687. for (n = 0; n < (3 * clen); n++)
  1688. rx[n] = 0;
  1689. tx[0] = (COMMAND_WRITE_CRAM & 0x7F);
  1690. tx[1] = 0x0;
  1691. tx[2] = 0x0;
  1692. ak7604_reads(component, tx, 3, rx, 3 * clen);
  1693. akdbgprt("*****AK7604 CRAM CMD=%d, LEN = %d*******\n", (int)tx[0], clen);
  1694. n = 0;
  1695. for (i = 0; i < clen; i++) {
  1696. akdbgprt("AK7604 CAddr=%03X : %02X%02X%02X\n", i,
  1697. (int)rx[n], (int)rx[n+1], (int)rx[n+2]);
  1698. n += 3;
  1699. }
  1700. }
  1701. mdelay(1);
  1702. ak7604_set_status(component, DOWNLOAD_FINISH);
  1703. return 0;
  1704. }
  1705. static const char * const test_reg_select[] = {
  1706. "read AK7604 Reg 00:34",
  1707. "read AK7604 Reg 50:A3",
  1708. "read AK7604 Reg C0:C6",
  1709. "read DSP PRAM",
  1710. "read DSP CRAM",
  1711. };
  1712. static const struct soc_enum ak7604_test_enum[] = {
  1713. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(test_reg_select), test_reg_select),
  1714. };
  1715. static int get_test_reg(
  1716. struct snd_kcontrol *kcontrol,
  1717. struct snd_ctl_elem_value *ucontrol)
  1718. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1719. int nTestRegNo = 0;
  1720. /* Get the current output routing */
  1721. ucontrol->value.enumerated.item[0] = nTestRegNo;
  1722. return 0;
  1723. }
  1724. static int set_test_reg(
  1725. struct snd_kcontrol *kcontrol,
  1726. struct snd_ctl_elem_value *ucontrol)
  1727. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  1728. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1729. u32 currMode = ucontrol->value.enumerated.item[0];
  1730. int i, value;
  1731. int regs, rege;
  1732. int nTestRegNo = 0;
  1733. nTestRegNo = currMode;
  1734. if (currMode < 3) {
  1735. switch (currMode) {
  1736. case 0:
  1737. regs = 0x00;
  1738. rege = 0x34;
  1739. break;
  1740. case 1:
  1741. regs = 0x50;
  1742. rege = 0xA3;
  1743. break;
  1744. case 2:
  1745. default:
  1746. regs = 0xC0;
  1747. rege = 0xC6;
  1748. break;
  1749. }
  1750. for (i = regs; i <= rege; i++) {
  1751. if (ak7604_readable(NULL, i)) {
  1752. value = snd_soc_component_read(component, i);
  1753. akdbgprt("***AK7604 Addr,Reg=(%x, %x)\n", i, value);
  1754. }
  1755. }
  1756. } else if (currMode < 5) {
  1757. test_read_ram(component, (currMode - 3));
  1758. }
  1759. return 0;
  1760. }
  1761. #endif
  1762. static const struct snd_kcontrol_new ak7604_snd_controls[] = {
  1763. SOC_SINGLE_TLV("MIC Input Volume L", AK7604_82_MIC_GAIN, 4, 0x0F, 0, mgn_tlv),
  1764. SOC_SINGLE_TLV("MIC Input Volume R", AK7604_82_MIC_GAIN, 0, 0x0F, 0, mgn_tlv),
  1765. SOC_SINGLE_TLV("ADC Digital Volume L", AK7604_8B_ADCL_VOLUME, 0, 0xFF, 1, voladc_tlv),
  1766. SOC_SINGLE_TLV("ADC Digital Volume R", AK7604_8C_ADCR_VOLUME, 0, 0xFF, 1, voladc_tlv),
  1767. SOC_SINGLE_TLV("DAC1 Digital Volume L", AK7604_83_DAC1L_VOLUME, 0, 0xFF, 1, voldac_tlv),
  1768. SOC_SINGLE_TLV("DAC1 Digital Volume R", AK7604_84_DAC1R_VOLUME, 0, 0xFF, 1, voldac_tlv),
  1769. SOC_SINGLE_TLV("DAC2 Digital Volume L", AK7604_85_DAC2L_VOLUME, 0, 0xFF, 1, voldac_tlv),
  1770. SOC_SINGLE_TLV("DAC2 Digital Volume R", AK7604_86_DAC2R_VOLUME, 0, 0xFF, 1, voldac_tlv),
  1771. SOC_SINGLE_TLV("DAC3 Digital Volume L", AK7604_87_DAC3L_VOLUME, 0, 0xFF, 1, voldac_tlv),
  1772. SOC_SINGLE_TLV("DAC3 Digital Volume R", AK7604_88_DAC3R_VOLUME, 0, 0xFF, 1, voldac_tlv),
  1773. SOC_SINGLE("ADC Mute", AK7604_8E_ADC_MUTEHPF, 6, 1, 0),
  1774. SOC_ENUM("ADC Volume Transition Time", ak7604_codec_enum[0]),
  1775. SOC_SINGLE("DAC1 Mute", AK7604_89_DAC_MUTEFILTER, 6, 1, 0),
  1776. SOC_SINGLE("DAC2 Mute", AK7604_89_DAC_MUTEFILTER, 5, 1, 0),
  1777. SOC_SINGLE("DAC3 Mute", AK7604_89_DAC_MUTEFILTER, 4, 1, 0),
  1778. SOC_ENUM("DAC Volume Transition Time", ak7604_codec_enum[1]),
  1779. SOC_ENUM("DAC Digital Filter", ak7604_codec_enum[2]),
  1780. SOC_ENUM("DAC1 De-Emphasis Filter", ak7604_codec_enum[3]),
  1781. SOC_ENUM("DAC2 De-Emphasis Filter", ak7604_codec_enum[4]),
  1782. SOC_ENUM("DAC3 De-Emphasis Filter", ak7604_codec_enum[5]),
  1783. SOC_ENUM("SDOUT1 Sync Domain", ak7604_sdsel_enum[0]),
  1784. SOC_ENUM("SDOUT2 Sync Domain", ak7604_sdsel_enum[1]),
  1785. SOC_ENUM("SDOUT3 Sync Domain", ak7604_sdsel_enum[2]),
  1786. SOC_ENUM("DAC Sync Domain", ak7604_sdsel_enum[3]),
  1787. SOC_ENUM("ADC Sync Domain", ak7604_sdsel_enum[4]),
  1788. SOC_ENUM("DSP Sync Domain", ak7604_sdsel_enum[5]),
  1789. SOC_ENUM("DSPOUT1 Sync Domain", ak7604_sdsel_enum[6]),
  1790. SOC_ENUM("DSPOUT2 Sync Domain", ak7604_sdsel_enum[7]),
  1791. SOC_ENUM("DSPOUT3 Sync Domain", ak7604_sdsel_enum[8]),
  1792. SOC_ENUM("DSPOUT4 Sync Domain", ak7604_sdsel_enum[9]),
  1793. SOC_ENUM("DSPOUT5 Sync Domain", ak7604_sdsel_enum[10]),
  1794. SOC_ENUM("DSPOUT6 Sync Domain", ak7604_sdsel_enum[11]),
  1795. SOC_ENUM("SRC1OUT Sync Domain", ak7604_sdsel_enum[12]),
  1796. SOC_ENUM("SRC2OUT Sync Domain", ak7604_sdsel_enum[13]),
  1797. SOC_ENUM("SRC3OUT Sync Domain", ak7604_sdsel_enum[14]),
  1798. SOC_ENUM("SRC4OUT Sync Domain", ak7604_sdsel_enum[15]),
  1799. SOC_ENUM("CODEC Sampling Frequency", ak7604_fsmode_enum[0]),
  1800. SOC_ENUM_EXT("LRCK1/BICK1 Master", ak7604_msnbit_enum[0], get_sd1_ms, set_sd1_ms),
  1801. SOC_ENUM_EXT("LRCK2/BICK2 Master", ak7604_msnbit_enum[0], get_sd2_ms, set_sd2_ms),
  1802. SOC_ENUM_EXT("LRCK3/BICK3 Master", ak7604_msnbit_enum[0], get_sd3_ms, set_sd3_ms),
  1803. SOC_ENUM("LRCK1/BICK1 Sync Domain", ak7604_portsdsel_enum[0]),
  1804. SOC_ENUM("LRCK2/BICK2 Sync Domain", ak7604_portsdsel_enum[1]),
  1805. SOC_ENUM("LRCK3/BICK3 Sync Domain", ak7604_portsdsel_enum[2]),
  1806. SOC_ENUM_EXT("Sync Domain 1 Clock Source", ak7604_sdcks_enum[0], get_sd1_cks, set_sd1_cks),
  1807. SOC_ENUM_EXT("Sync Domain 2 Clock Source", ak7604_sdcks_enum[0], get_sd2_cks, set_sd2_cks),
  1808. SOC_ENUM_EXT("Sync Domain 3 Clock Source", ak7604_sdcks_enum[0], get_sd3_cks, set_sd3_cks),
  1809. SOC_ENUM_EXT("Sync Domain 4 Clock Source", ak7604_sdcks_enum[0], get_sd4_cks, set_sd4_cks),
  1810. SOC_ENUM_EXT("Sync Domain 1 fs", ak7604_sd_fs_enum[0], get_sd1_fs, set_sd1_fs),
  1811. SOC_ENUM_EXT("Sync Domain 2 fs", ak7604_sd_fs_enum[0], get_sd2_fs, set_sd2_fs),
  1812. SOC_ENUM_EXT("Sync Domain 3 fs", ak7604_sd_fs_enum[0], get_sd3_fs, set_sd3_fs),
  1813. SOC_ENUM_EXT("Sync Domain 4 fs", ak7604_sd_fs_enum[0], get_sd4_fs, set_sd4_fs),
  1814. SOC_ENUM_EXT("Sync Domain 1 BICK", ak7604_sd_fs_enum[1], get_sd1_bick, set_sd1_bick),
  1815. SOC_ENUM_EXT("Sync Domain 2 BICK", ak7604_sd_fs_enum[1], get_sd2_bick, set_sd2_bick),
  1816. SOC_ENUM_EXT("Sync Domain 3 BICK", ak7604_sd_fs_enum[1], get_sd3_bick, set_sd3_bick),
  1817. SOC_ENUM_EXT("Sync Domain 4 BICK", ak7604_sd_fs_enum[1], get_sd4_bick, set_sd4_bick),
  1818. SOC_ENUM_EXT("PLL Input Clock", ak7604_pllset_enum[0], get_pllinput, set_pllinput),
  1819. SOC_ENUM_EXT("XTI Frequency", ak7604_pllset_enum[1], get_xtifs, set_xtifs),
  1820. SOC_ENUM_EXT("SDIN1 TDM Setting", ak7604_tdm_enum[0], get_sdin1_tdm, set_sdin1_tdm),
  1821. SOC_ENUM_EXT("SDOUT1 TDM Setting", ak7604_tdm_enum[0], get_sdout1_tdm, set_sdout1_tdm),
  1822. SOC_ENUM_EXT("SDIN1 Slot Length", ak7604_slotlen_enum[0], get_sdin1_slot, set_sdin1_slot),
  1823. SOC_ENUM_EXT("SDIN2 Slot Length", ak7604_slotlen_enum[0], get_sdin2_slot, set_sdin2_slot),
  1824. SOC_ENUM_EXT("SDIN3 Slot Length", ak7604_slotlen_enum[0], get_sdin3_slot, set_sdin3_slot),
  1825. SOC_ENUM_EXT("SDIN4 Slot Length", ak7604_slotlen_enum[0], get_sdin4_slot, set_sdin4_slot),
  1826. SOC_ENUM_EXT("SDOUT1 Slot Length", ak7604_slotlen_enum[0],
  1827. get_sdout1_slot, set_sdout1_slot),
  1828. SOC_ENUM_EXT("SDOUT2 Slot Length", ak7604_slotlen_enum[0],
  1829. get_sdout2_slot, set_sdout2_slot),
  1830. SOC_ENUM_EXT("SDOUT3 Slot Length", ak7604_slotlen_enum[0],
  1831. get_sdout3_slot, set_sdout3_slot),
  1832. SOC_ENUM("SDOUT1 Fast Mode Setting", ak7604_sdout_modeset_enum[0]),
  1833. SOC_ENUM("SDOUT2 Fast Mode Setting", ak7604_sdout_modeset_enum[1]),
  1834. SOC_ENUM("SDOUT3 Fast Mode Setting", ak7604_sdout_modeset_enum[2]),
  1835. SOC_ENUM("SDOUT1 Pin Output Select", ak7604_outportsel_enum[0]),
  1836. SOC_ENUM("SDOUT2 Pin Output Select", ak7604_outportsel_enum[1]),
  1837. SOC_ENUM("SDOUT3 Pin Output Select", ak7604_outportsel_enum[2]),
  1838. SOC_ENUM("SDIN3 Pin Input Select", ak7604_inportsel_enum[0]),
  1839. SOC_ENUM("BICK3 Pin Input Select", ak7604_inportsel_enum[1]),
  1840. SOC_ENUM("LRCK3 Pin Input Select", ak7604_inportsel_enum[2]),
  1841. SOC_SINGLE("SRC1 Mute", AK7604_71_SRCMUTE_SETTING, 4, 1, 0),
  1842. SOC_SINGLE("SRC2 Mute", AK7604_71_SRCMUTE_SETTING, 5, 1, 0),
  1843. SOC_SINGLE("SRC3 Mute", AK7604_71_SRCMUTE_SETTING, 6, 1, 0),
  1844. SOC_SINGLE("SRC4 Mute", AK7604_71_SRCMUTE_SETTING, 7, 1, 0),
  1845. SOC_ENUM("SRC1 Mute Semi-Auto", ak7604_src_softmute_enum[0]),
  1846. SOC_ENUM("SRC2 Mute Semi-Auto", ak7604_src_softmute_enum[1]),
  1847. SOC_ENUM("SRC3 Mute Semi-Auto", ak7604_src_softmute_enum[2]),
  1848. SOC_ENUM("SRC4 Mute Semi-Auto", ak7604_src_softmute_enum[3]),
  1849. SOC_SINGLE("SRC1 Group Delay Matching", AK7604_72_SRCGROUTP_SETTING, 0, 3, 0),
  1850. SOC_SINGLE("SRC2 Group Delay Matching", AK7604_72_SRCGROUTP_SETTING, 2, 3, 0),
  1851. SOC_SINGLE("SRC3 Group Delay Matching", AK7604_72_SRCGROUTP_SETTING, 4, 3, 0),
  1852. SOC_SINGLE("SRC4 Group Delay Matching", AK7604_72_SRCGROUTP_SETTING, 6, 3, 0),
  1853. SOC_ENUM("SRC1 Digital Filter", ak7604_src_dfil_enum[0]),
  1854. SOC_ENUM("SRC2 Digital Filter", ak7604_src_dfil_enum[1]),
  1855. SOC_ENUM("SRC3 Digital Filter", ak7604_src_dfil_enum[2]),
  1856. SOC_ENUM("SRC4 Digital Filter", ak7604_src_dfil_enum[3]),
  1857. SOC_SINGLE("DSP JX0 Enable", AK7604_61_DSP_SETTING2, 4, 1, 0),
  1858. SOC_SINGLE("DSP JX1 Enable", AK7604_61_DSP_SETTING2, 5, 1, 0),
  1859. SOC_SINGLE("DSP JX2 Enable", AK7604_61_DSP_SETTING2, 6, 1, 0),
  1860. SOC_SINGLE("STO DSP WDT Error Out", AK7604_53_STO_SETTING, 6, 1, 1),
  1861. SOC_SINGLE("STO CRC Error Out", AK7604_53_STO_SETTING, 5, 1, 0),
  1862. SOC_SINGLE("STO PLL Lock Signal Out", AK7604_53_STO_SETTING, 4, 1, 0),
  1863. SOC_SINGLE("STO SRC4 Lock Out", AK7604_53_STO_SETTING, 3, 1, 0),
  1864. SOC_SINGLE("STO SRC3 Lock Out", AK7604_53_STO_SETTING, 2, 1, 0),
  1865. SOC_SINGLE("STO SRC2 Lock Out", AK7604_53_STO_SETTING, 1, 1, 0),
  1866. SOC_SINGLE("STO SRC1 Lock Out", AK7604_53_STO_SETTING, 0, 1, 0),
  1867. SOC_ENUM("DSP DRAM Bank Size", ak7604_dsp_dram_enum[0]),
  1868. SOC_ENUM("DSP DRAM Bank Addressing", ak7604_dsp_dram_enum[1]),
  1869. SOC_ENUM_EXT("DSP Firmware PRAM", ak7604_firmware_enum[0],
  1870. get_DSP_write_pram, set_DSP_write_pram),
  1871. SOC_ENUM_EXT("DSP Firmware CRAM", ak7604_firmware_enum[1],
  1872. get_DSP_write_cram, set_DSP_write_cram),
  1873. SOC_ENUM_EXT("Set CRAM Address", ak7604_cramope_enum[0],
  1874. get_cram_write_addr, set_cram_write_addr),
  1875. SOC_ENUM_EXT("Set CRAM Data H", ak7604_cramope_enum[1],
  1876. get_cram_write_valueH, set_cram_write_valueH),
  1877. SOC_ENUM_EXT("Set CRAM Data M", ak7604_cramope_enum[1],
  1878. get_cram_write_valueM, set_cram_write_valueM),
  1879. SOC_ENUM_EXT("Set CRAM Data L", ak7604_cramope_enum[1],
  1880. get_cram_write_valueL, set_cram_write_valueL),
  1881. SOC_ENUM_EXT("Execute CRAM Write", ak7604_cramope_enum[2],
  1882. get_cram_write_exec, set_cram_write_exec),
  1883. #ifdef AK7604_DEBUG
  1884. SOC_ENUM_EXT("Reg Read", ak7604_test_enum[0], get_test_reg, set_test_reg),
  1885. #endif
  1886. };
  1887. static const char * const ak7604_micbias1_select_texts[] = {
  1888. "LineIn", "MicBias"
  1889. };
  1890. static SOC_ENUM_SINGLE_VIRT_DECL(ak7604_micbias1_mux_enum, ak7604_micbias1_select_texts);
  1891. static const struct snd_kcontrol_new ak7604_micbias1_mux_control =
  1892. SOC_DAPM_ENUM("MicBias1 Select", ak7604_micbias1_mux_enum);
  1893. static const char * const ak7604_micbias2_select_texts[] = {
  1894. "LineIn", "MicBias"
  1895. };
  1896. static SOC_ENUM_SINGLE_VIRT_DECL(ak7604_micbias2_mux_enum, ak7604_micbias2_select_texts);
  1897. static const struct snd_kcontrol_new ak7604_micbias2_mux_control =
  1898. SOC_DAPM_ENUM("MicBias2 Select", ak7604_micbias2_mux_enum);
  1899. static const char * const ak7604_adc_input_texts[] = {
  1900. "INP_N", "AIN1_GND", "AIN1", "AIN2", "AIN3"
  1901. };
  1902. static int ak7604_adc_input_values[] = {
  1903. 0, 1, 2, 4, 6
  1904. };
  1905. static SOC_VALUE_ENUM_SINGLE_DECL(ak7604_adc_input_enum,
  1906. AK7604_8D_AIN_SELECT, 1,
  1907. 0x7, ak7604_adc_input_texts,
  1908. ak7604_adc_input_values);
  1909. static const struct snd_kcontrol_new ak7604_adc_input_mux_control =
  1910. SOC_DAPM_ENUM("ADC select", ak7604_adc_input_enum);
  1911. static const char * const ak7604_source_select_texts[] = {
  1912. "ALL0", "SDIN1A", "SDIN1B", "SDIN1C", "SDIN1D",
  1913. "SDIN2", "SDIN3", "SDIN4", "DSPO1", "DSPO2",
  1914. "DSPO3", "DSPO4", "DSPO5", "DSPO6", "ADC",
  1915. "SRC1O", "SRC2O", "SRC3O", "SRC4O"
  1916. };
  1917. static const struct soc_enum ak7604_sout1a_mux_enum =
  1918. SOC_ENUM_SINGLE(AK7604_19_SDOUT1A_SELECT, 0,
  1919. ARRAY_SIZE(ak7604_source_select_texts), ak7604_source_select_texts);
  1920. static const struct snd_kcontrol_new ak7604_sout1a_mux_control =
  1921. SOC_DAPM_ENUM("SOUT1A Select", ak7604_sout1a_mux_enum);
  1922. static const struct soc_enum ak7604_sout1b_mux_enum =
  1923. SOC_ENUM_SINGLE(AK7604_1A_SDOUT1B_SELECT, 0,
  1924. ARRAY_SIZE(ak7604_source_select_texts), ak7604_source_select_texts);
  1925. static const struct snd_kcontrol_new ak7604_sout1b_mux_control =
  1926. SOC_DAPM_ENUM("SOUT1B Select", ak7604_sout1b_mux_enum);
  1927. static const struct soc_enum ak7604_sout1c_mux_enum =
  1928. SOC_ENUM_SINGLE(AK7604_1B_SDOUT1C_SELECT, 0,
  1929. ARRAY_SIZE(ak7604_source_select_texts), ak7604_source_select_texts);
  1930. static const struct snd_kcontrol_new ak7604_sout1c_mux_control =
  1931. SOC_DAPM_ENUM("SOUT1C Select", ak7604_sout1c_mux_enum);
  1932. static const struct soc_enum ak7604_sout1d_mux_enum =
  1933. SOC_ENUM_SINGLE(AK7604_1C_SDOUT1D_SELECT, 0,
  1934. ARRAY_SIZE(ak7604_source_select_texts), ak7604_source_select_texts);
  1935. static const struct snd_kcontrol_new ak7604_sout1d_mux_control =
  1936. SOC_DAPM_ENUM("SOUT1D Select", ak7604_sout1d_mux_enum);
  1937. static const struct soc_enum ak7604_sout2_mux_enum =
  1938. SOC_ENUM_SINGLE(AK7604_1D_SDOUT2_SELECT, 0,
  1939. ARRAY_SIZE(ak7604_source_select_texts), ak7604_source_select_texts);
  1940. static const struct snd_kcontrol_new ak7604_sout2_mux_control =
  1941. SOC_DAPM_ENUM("SOUT2 Select", ak7604_sout2_mux_enum);
  1942. static const struct soc_enum ak7604_sout3_mux_enum =
  1943. SOC_ENUM_SINGLE(AK7604_1E_SDOUT3_SELECT, 0,
  1944. ARRAY_SIZE(ak7604_source_select_texts), ak7604_source_select_texts);
  1945. static const struct snd_kcontrol_new ak7604_sout3_mux_control =
  1946. SOC_DAPM_ENUM("SOUT3 Select", ak7604_sout3_mux_enum);
  1947. static const struct soc_enum ak7604_dac1_mux_enum =
  1948. SOC_ENUM_SINGLE(AK7604_1F_DAC1_SELECT, 0,
  1949. ARRAY_SIZE(ak7604_source_select_texts), ak7604_source_select_texts);
  1950. static const struct snd_kcontrol_new ak7604_dac1_mux_control =
  1951. SOC_DAPM_ENUM("DAC1 Select", ak7604_dac1_mux_enum);
  1952. static const struct soc_enum ak7604_dac2_mux_enum =
  1953. SOC_ENUM_SINGLE(AK7604_20_DAC2_SELECT, 0,
  1954. ARRAY_SIZE(ak7604_source_select_texts), ak7604_source_select_texts);
  1955. static const struct snd_kcontrol_new ak7604_dac2_mux_control =
  1956. SOC_DAPM_ENUM("DAC2 Select", ak7604_dac2_mux_enum);
  1957. static const struct soc_enum ak7604_dac3_mux_enum =
  1958. SOC_ENUM_SINGLE(AK7604_21_DAC3_SELECT, 0,
  1959. ARRAY_SIZE(ak7604_source_select_texts), ak7604_source_select_texts);
  1960. static const struct snd_kcontrol_new ak7604_dac3_mux_control =
  1961. SOC_DAPM_ENUM("DAC3 Select", ak7604_dac3_mux_enum);
  1962. static const struct soc_enum ak7604_dspin1_mux_enum =
  1963. SOC_ENUM_SINGLE(AK7604_22_DSPDIN1_SELECT, 0,
  1964. ARRAY_SIZE(ak7604_source_select_texts), ak7604_source_select_texts);
  1965. static const struct snd_kcontrol_new ak7604_dspin1_mux_control =
  1966. SOC_DAPM_ENUM("DSPIN1 Select", ak7604_dspin1_mux_enum);
  1967. static const struct soc_enum ak7604_dspin2_mux_enum =
  1968. SOC_ENUM_SINGLE(AK7604_23_DSPDIN2_SELECT, 0,
  1969. ARRAY_SIZE(ak7604_source_select_texts), ak7604_source_select_texts);
  1970. static const struct snd_kcontrol_new ak7604_dspin2_mux_control =
  1971. SOC_DAPM_ENUM("DSP1 IN2 Select", ak7604_dspin2_mux_enum);
  1972. static const struct soc_enum ak7604_dspin3_mux_enum =
  1973. SOC_ENUM_SINGLE(AK7604_24_DSPDIN3_SELECT, 0,
  1974. ARRAY_SIZE(ak7604_source_select_texts), ak7604_source_select_texts);
  1975. static const struct snd_kcontrol_new ak7604_dspin3_mux_control =
  1976. SOC_DAPM_ENUM("DSP1 IN3 Select", ak7604_dspin3_mux_enum);
  1977. static const struct soc_enum ak7604_dspin4_mux_enum =
  1978. SOC_ENUM_SINGLE(AK7604_25_DSPDIN4_SELECT, 0,
  1979. ARRAY_SIZE(ak7604_source_select_texts), ak7604_source_select_texts);
  1980. static const struct snd_kcontrol_new ak7604_dspin4_mux_control =
  1981. SOC_DAPM_ENUM("DSP1 IN4 Select", ak7604_dspin4_mux_enum);
  1982. static const struct soc_enum ak7604_dspin5_mux_enum =
  1983. SOC_ENUM_SINGLE(AK7604_26_DSPDIN5_SELECT, 0,
  1984. ARRAY_SIZE(ak7604_source_select_texts), ak7604_source_select_texts);
  1985. static const struct snd_kcontrol_new ak7604_dspin5_mux_control =
  1986. SOC_DAPM_ENUM("DSP1 IN5 Select", ak7604_dspin5_mux_enum);
  1987. static const struct soc_enum ak7604_dspin6_mux_enum =
  1988. SOC_ENUM_SINGLE(AK7604_27_DSPDIN6_SELECT, 0,
  1989. ARRAY_SIZE(ak7604_source_select_texts), ak7604_source_select_texts);
  1990. static const struct snd_kcontrol_new ak7604_dspin6_mux_control =
  1991. SOC_DAPM_ENUM("DSP1 IN6 Select", ak7604_dspin6_mux_enum);
  1992. static const struct soc_enum ak7604_src1_mux_enum =
  1993. SOC_ENUM_SINGLE(AK7604_28_SRC1_SELECT, 0,
  1994. ARRAY_SIZE(ak7604_source_select_texts), ak7604_source_select_texts);
  1995. static const struct snd_kcontrol_new ak7604_src1_mux_control =
  1996. SOC_DAPM_ENUM("SRC1 Select", ak7604_src1_mux_enum);
  1997. static const struct soc_enum ak7604_src2_mux_enum =
  1998. SOC_ENUM_SINGLE(AK7604_29_SRC2_SELECT, 0,
  1999. ARRAY_SIZE(ak7604_source_select_texts), ak7604_source_select_texts);
  2000. static const struct snd_kcontrol_new ak7604_src2_mux_control =
  2001. SOC_DAPM_ENUM("SRC2 Select", ak7604_src2_mux_enum);
  2002. static const struct soc_enum ak7604_src3_mux_enum =
  2003. SOC_ENUM_SINGLE(AK7604_2A_SRC3_SELECT, 0,
  2004. ARRAY_SIZE(ak7604_source_select_texts), ak7604_source_select_texts);
  2005. static const struct snd_kcontrol_new ak7604_src3_mux_control =
  2006. SOC_DAPM_ENUM("SRC3 Select", ak7604_src3_mux_enum);
  2007. static const struct soc_enum ak7604_src4_mux_enum =
  2008. SOC_ENUM_SINGLE(AK7604_2B_SRC4_SELECT, 0,
  2009. ARRAY_SIZE(ak7604_source_select_texts), ak7604_source_select_texts);
  2010. static const struct snd_kcontrol_new ak7604_src4_mux_control =
  2011. SOC_DAPM_ENUM("SRC4 Select", ak7604_src4_mux_enum);
  2012. static int ak7604_ClockReset(struct snd_soc_dapm_widget *w,
  2013. struct snd_kcontrol *kcontrol, int event)
  2014. {akdbgprt("\t[AK7604] %s(%d):event = %d\n", __func__, __LINE__, event);
  2015. #ifdef KERNEL_3_18_XX
  2016. //struct snd_soc_codec *codec = w->codec;
  2017. #else
  2018. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  2019. #endif
  2020. switch (event) {
  2021. case SND_SOC_DAPM_PRE_PMU:
  2022. // CKRESETN bit = 1
  2023. snd_soc_component_update_bits(component, AK7604_02_SYSTEMCLOCK_3, 0x80, 0x80);
  2024. mdelay(10);
  2025. // HRESETN bit = 1
  2026. snd_soc_component_update_bits(component, AK7604_A3_RESETCONTROL, 0x01, 0x01);
  2027. break;
  2028. case SND_SOC_DAPM_POST_PMD:
  2029. // // HRESETN bit = 0
  2030. // snd_soc_component_update_bits(component, AK7604_A3_RESETCONTROL, 0x01, 0x0);
  2031. // // CKRESETN bit = 0
  2032. // snd_soc_component_update_bits(component, AK7604_02_SYSTEMCLOCK_3, 0x80, 0x0);
  2033. break;
  2034. }
  2035. return 0;
  2036. }
  2037. static const struct snd_kcontrol_new dspout1_mixer_kctrl[] = {
  2038. SOC_DAPM_SINGLE("DSPIN1", AK7604_VIRT_C7_DSPOUT1_MIX, 0, 1, 0),
  2039. SOC_DAPM_SINGLE("DSPIN2", AK7604_VIRT_C7_DSPOUT1_MIX, 1, 1, 0),
  2040. SOC_DAPM_SINGLE("DSPIN3", AK7604_VIRT_C7_DSPOUT1_MIX, 2, 1, 0),
  2041. SOC_DAPM_SINGLE("DSPIN4", AK7604_VIRT_C7_DSPOUT1_MIX, 3, 1, 0),
  2042. SOC_DAPM_SINGLE("DSPIN5", AK7604_VIRT_C7_DSPOUT1_MIX, 4, 1, 0),
  2043. SOC_DAPM_SINGLE("DSPIN6", AK7604_VIRT_C7_DSPOUT1_MIX, 5, 1, 0),
  2044. };
  2045. static const struct snd_kcontrol_new dspout2_mixer_kctrl[] = {
  2046. SOC_DAPM_SINGLE("DSPIN1", AK7604_VIRT_C8_DSPOUT2_MIX, 0, 1, 0),
  2047. SOC_DAPM_SINGLE("DSPIN2", AK7604_VIRT_C8_DSPOUT2_MIX, 1, 1, 0),
  2048. SOC_DAPM_SINGLE("DSPIN3", AK7604_VIRT_C8_DSPOUT2_MIX, 2, 1, 0),
  2049. SOC_DAPM_SINGLE("DSPIN4", AK7604_VIRT_C8_DSPOUT2_MIX, 3, 1, 0),
  2050. SOC_DAPM_SINGLE("DSPIN5", AK7604_VIRT_C8_DSPOUT2_MIX, 4, 1, 0),
  2051. SOC_DAPM_SINGLE("DSPIN6", AK7604_VIRT_C8_DSPOUT2_MIX, 5, 1, 0),
  2052. };
  2053. static const struct snd_kcontrol_new dspout3_mixer_kctrl[] = {
  2054. SOC_DAPM_SINGLE("DSPIN1", AK7604_VIRT_C9_DSPOUT3_MIX, 0, 1, 0),
  2055. SOC_DAPM_SINGLE("DSPIN2", AK7604_VIRT_C9_DSPOUT3_MIX, 1, 1, 0),
  2056. SOC_DAPM_SINGLE("DSPIN3", AK7604_VIRT_C9_DSPOUT3_MIX, 2, 1, 0),
  2057. SOC_DAPM_SINGLE("DSPIN4", AK7604_VIRT_C9_DSPOUT3_MIX, 3, 1, 0),
  2058. SOC_DAPM_SINGLE("DSPIN5", AK7604_VIRT_C9_DSPOUT3_MIX, 4, 1, 0),
  2059. SOC_DAPM_SINGLE("DSPIN6", AK7604_VIRT_C9_DSPOUT3_MIX, 5, 1, 0),
  2060. };
  2061. static const struct snd_kcontrol_new dspout4_mixer_kctrl[] = {
  2062. SOC_DAPM_SINGLE("DSPIN1", AK7604_VIRT_CA_DSPOUT4_MIX, 0, 1, 0),
  2063. SOC_DAPM_SINGLE("DSPIN2", AK7604_VIRT_CA_DSPOUT4_MIX, 1, 1, 0),
  2064. SOC_DAPM_SINGLE("DSPIN3", AK7604_VIRT_CA_DSPOUT4_MIX, 2, 1, 0),
  2065. SOC_DAPM_SINGLE("DSPIN4", AK7604_VIRT_CA_DSPOUT4_MIX, 3, 1, 0),
  2066. SOC_DAPM_SINGLE("DSPIN5", AK7604_VIRT_CA_DSPOUT4_MIX, 4, 1, 0),
  2067. SOC_DAPM_SINGLE("DSPIN6", AK7604_VIRT_CA_DSPOUT4_MIX, 5, 1, 0),
  2068. };
  2069. static const struct snd_kcontrol_new dspout5_mixer_kctrl[] = {
  2070. SOC_DAPM_SINGLE("DSPIN1", AK7604_VIRT_CB_DSPOUT5_MIX, 0, 1, 0),
  2071. SOC_DAPM_SINGLE("DSPIN2", AK7604_VIRT_CB_DSPOUT5_MIX, 1, 1, 0),
  2072. SOC_DAPM_SINGLE("DSPIN3", AK7604_VIRT_CB_DSPOUT5_MIX, 2, 1, 0),
  2073. SOC_DAPM_SINGLE("DSPIN4", AK7604_VIRT_CB_DSPOUT5_MIX, 3, 1, 0),
  2074. SOC_DAPM_SINGLE("DSPIN5", AK7604_VIRT_CB_DSPOUT5_MIX, 4, 1, 0),
  2075. SOC_DAPM_SINGLE("DSPIN6", AK7604_VIRT_CB_DSPOUT5_MIX, 5, 1, 0),
  2076. };
  2077. static const struct snd_kcontrol_new dspout6_mixer_kctrl[] = {
  2078. SOC_DAPM_SINGLE("DSPIN1", AK7604_VIRT_CC_DSPOUT6_MIX, 0, 1, 0),
  2079. SOC_DAPM_SINGLE("DSPIN2", AK7604_VIRT_CC_DSPOUT6_MIX, 1, 1, 0),
  2080. SOC_DAPM_SINGLE("DSPIN3", AK7604_VIRT_CC_DSPOUT6_MIX, 2, 1, 0),
  2081. SOC_DAPM_SINGLE("DSPIN4", AK7604_VIRT_CC_DSPOUT6_MIX, 3, 1, 0),
  2082. SOC_DAPM_SINGLE("DSPIN5", AK7604_VIRT_CC_DSPOUT6_MIX, 4, 1, 0),
  2083. SOC_DAPM_SINGLE("DSPIN6", AK7604_VIRT_CC_DSPOUT6_MIX, 5, 1, 0),
  2084. };
  2085. static int ak7604_DSPPowerUp(struct snd_soc_dapm_widget *w,
  2086. struct snd_kcontrol *kcontrol, int event)
  2087. {akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  2088. #ifdef KERNEL_3_18_XX
  2089. //struct snd_soc_codec *codec = w->codec;
  2090. #else
  2091. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  2092. #endif
  2093. switch (event) {
  2094. case SND_SOC_DAPM_POST_PMU:
  2095. snd_soc_component_update_bits(component, AK7604_A3_RESETCONTROL, 0x04, 0x04);
  2096. break;
  2097. case SND_SOC_DAPM_POST_PMD:
  2098. snd_soc_component_update_bits(component, AK7604_A3_RESETCONTROL, 0x04, 0x00);
  2099. break;
  2100. }
  2101. return 0;
  2102. }
  2103. /* ak7604 dapm widgets */
  2104. static const struct snd_soc_dapm_widget ak7604_dapm_widgets[] = {
  2105. SND_SOC_DAPM_SUPPLY_S("Clock Power", 1, SND_SOC_NOPM, 0, 0, ak7604_ClockReset,
  2106. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2107. SND_SOC_DAPM_SUPPLY_S("CODEC Power", 2, AK7604_A3_RESETCONTROL, 1, 0, NULL, 0),
  2108. // CODEC
  2109. SND_SOC_DAPM_ADC("ADC", NULL, AK7604_A1_POWERMANAGEMENT1, 7, 0),
  2110. SND_SOC_DAPM_DAC("DAC1", NULL, AK7604_A1_POWERMANAGEMENT1, 4, 0),
  2111. SND_SOC_DAPM_DAC("DAC2", NULL, AK7604_A1_POWERMANAGEMENT1, 5, 0),
  2112. SND_SOC_DAPM_DAC("DAC3", NULL, AK7604_A1_POWERMANAGEMENT1, 6, 0),
  2113. // SRC
  2114. SND_SOC_DAPM_PGA("SRC1", AK7604_A2_POWERMANAGEMENT2, 4, 0, NULL, 0),
  2115. SND_SOC_DAPM_PGA("SRC2", AK7604_A2_POWERMANAGEMENT2, 5, 0, NULL, 0),
  2116. SND_SOC_DAPM_PGA("SRC3", AK7604_A2_POWERMANAGEMENT2, 6, 0, NULL, 0),
  2117. SND_SOC_DAPM_PGA("SRC4", AK7604_A2_POWERMANAGEMENT2, 7, 0, NULL, 0),
  2118. // DSP
  2119. SND_SOC_DAPM_SUPPLY_S("DSP", 3, AK7604_A3_RESETCONTROL, 2, 0, ak7604_DSPPowerUp,
  2120. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  2121. SND_SOC_DAPM_PGA("DSPO1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2122. SND_SOC_DAPM_PGA("DSPO2", SND_SOC_NOPM, 0, 0, NULL, 0),
  2123. SND_SOC_DAPM_PGA("DSPO3", SND_SOC_NOPM, 0, 0, NULL, 0),
  2124. SND_SOC_DAPM_PGA("DSPO4", SND_SOC_NOPM, 0, 0, NULL, 0),
  2125. SND_SOC_DAPM_PGA("DSPO5", SND_SOC_NOPM, 0, 0, NULL, 0),
  2126. SND_SOC_DAPM_PGA("DSPO6", SND_SOC_NOPM, 0, 0, NULL, 0),
  2127. // SND_SOC_DAPM_MIXER("DSPOUT1 Mixer", SND_SOC_NOPM, 0, 0,
  2128. // &dspout1_mixer_kctrl[0], ARRAY_SIZE(dspout1_mixer_kctrl)),
  2129. // SND_SOC_DAPM_MIXER("DSPOUT2 Mixer", SND_SOC_NOPM, 0, 0,
  2130. // &dspout2_mixer_kctrl[0], ARRAY_SIZE(dspout2_mixer_kctrl)),
  2131. // SND_SOC_DAPM_MIXER("DSPOUT3 Mixer", SND_SOC_NOPM, 0, 0,
  2132. // &dspout3_mixer_kctrl[0], ARRAY_SIZE(dspout3_mixer_kctrl)),
  2133. // SND_SOC_DAPM_MIXER("DSPOUT4 Mixer", SND_SOC_NOPM, 0, 0,
  2134. // &dspout4_mixer_kctrl[0], ARRAY_SIZE(dspout4_mixer_kctrl)),
  2135. // SND_SOC_DAPM_MIXER("DSPOUT5 Mixer", SND_SOC_NOPM, 0, 0,
  2136. // &dspout5_mixer_kctrl[0], ARRAY_SIZE(dspout5_mixer_kctrl)),
  2137. // SND_SOC_DAPM_MIXER("DSPOUT6 Mixer", SND_SOC_NOPM, 0, 0,
  2138. // &dspout6_mixer_kctrl[0], ARRAY_SIZE(dspout6_mixer_kctrl)),
  2139. // Digital Input/Output
  2140. SND_SOC_DAPM_AIF_IN("SDIN1A", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
  2141. SND_SOC_DAPM_AIF_IN("SDIN1B", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
  2142. SND_SOC_DAPM_AIF_IN("SDIN1C", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
  2143. SND_SOC_DAPM_AIF_IN("SDIN1D", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
  2144. SND_SOC_DAPM_AIF_IN("SDIN2", "AIF2 Playback", 0, SND_SOC_NOPM, 0, 0),
  2145. SND_SOC_DAPM_AIF_IN("SDIN3", "AIF3 Playback", 0, SND_SOC_NOPM, 0, 0),
  2146. SND_SOC_DAPM_AIF_IN("SDIN4", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
  2147. SND_SOC_DAPM_AIF_OUT("SDOUT1", "AIF1 Capture", 0, SND_SOC_NOPM, 0, 0),
  2148. SND_SOC_DAPM_AIF_OUT("SDOUT2", "AIF2 Capture", 0, SND_SOC_NOPM, 0, 0),
  2149. SND_SOC_DAPM_AIF_OUT("SDOUT3", "AIF3 Capture", 0, SND_SOC_NOPM, 0, 0),
  2150. // Analog Input
  2151. SND_SOC_DAPM_INPUT("INP_N"),
  2152. SND_SOC_DAPM_INPUT("AIN1_GND"),
  2153. SND_SOC_DAPM_INPUT("AIN1"),
  2154. SND_SOC_DAPM_INPUT("AIN2"),
  2155. SND_SOC_DAPM_INPUT("AIN3"),
  2156. SND_SOC_DAPM_MUX("ADC MUX", SND_SOC_NOPM, 0, 0, &ak7604_adc_input_mux_control),
  2157. // MIC Bias
  2158. SND_SOC_DAPM_MICBIAS("MicBias1", AK7604_A1_POWERMANAGEMENT1, 2, 0),
  2159. SND_SOC_DAPM_MUX("MicBias1 MUX", SND_SOC_NOPM, 0, 0, &ak7604_micbias1_mux_control),
  2160. SND_SOC_DAPM_MICBIAS("MicBias2", AK7604_A1_POWERMANAGEMENT1, 3, 0),
  2161. SND_SOC_DAPM_MUX("MicBias2 MUX", SND_SOC_NOPM, 0, 0, &ak7604_micbias2_mux_control),
  2162. // Analog Output
  2163. SND_SOC_DAPM_OUTPUT("AOUT1"),
  2164. SND_SOC_DAPM_OUTPUT("AOUT2"),
  2165. SND_SOC_DAPM_OUTPUT("AOUT3"),
  2166. // Source Selector
  2167. SND_SOC_DAPM_MUX("SDOUT1A Source Selector", SND_SOC_NOPM, 0, 0, &ak7604_sout1a_mux_control),
  2168. SND_SOC_DAPM_MUX("SDOUT1B Source Selector", SND_SOC_NOPM, 0, 0, &ak7604_sout1b_mux_control),
  2169. SND_SOC_DAPM_MUX("SDOUT1C Source Selector", SND_SOC_NOPM, 0, 0, &ak7604_sout1c_mux_control),
  2170. SND_SOC_DAPM_MUX("SDOUT1D Source Selector", SND_SOC_NOPM, 0, 0, &ak7604_sout1d_mux_control),
  2171. SND_SOC_DAPM_MUX("SDOUT2 Source Selector", SND_SOC_NOPM, 0, 0, &ak7604_sout2_mux_control),
  2172. SND_SOC_DAPM_MUX("SDOUT3 Source Selector", SND_SOC_NOPM, 0, 0, &ak7604_sout3_mux_control),
  2173. SND_SOC_DAPM_MUX("DAC1 Source Selector", SND_SOC_NOPM, 0, 0, &ak7604_dac1_mux_control),
  2174. SND_SOC_DAPM_MUX("DAC2 Source Selector", SND_SOC_NOPM, 0, 0, &ak7604_dac2_mux_control),
  2175. SND_SOC_DAPM_MUX("DAC3 Source Selector", SND_SOC_NOPM, 0, 0, &ak7604_dac3_mux_control),
  2176. SND_SOC_DAPM_MUX("DSPIN1 Source Selector", SND_SOC_NOPM, 0, 0, &ak7604_dspin1_mux_control),
  2177. SND_SOC_DAPM_MUX("DSPIN2 Source Selector", SND_SOC_NOPM, 0, 0, &ak7604_dspin2_mux_control),
  2178. SND_SOC_DAPM_MUX("DSPIN3 Source Selector", SND_SOC_NOPM, 0, 0, &ak7604_dspin3_mux_control),
  2179. SND_SOC_DAPM_MUX("DSPIN4 Source Selector", SND_SOC_NOPM, 0, 0, &ak7604_dspin4_mux_control),
  2180. SND_SOC_DAPM_MUX("DSPIN5 Source Selector", SND_SOC_NOPM, 0, 0, &ak7604_dspin5_mux_control),
  2181. SND_SOC_DAPM_MUX("DSPIN6 Source Selector", SND_SOC_NOPM, 0, 0, &ak7604_dspin6_mux_control),
  2182. SND_SOC_DAPM_MUX("SRC1 Source Selector", SND_SOC_NOPM, 0, 0, &ak7604_src1_mux_control),
  2183. SND_SOC_DAPM_MUX("SRC2 Source Selector", SND_SOC_NOPM, 0, 0, &ak7604_src2_mux_control),
  2184. SND_SOC_DAPM_MUX("SRC3 Source Selector", SND_SOC_NOPM, 0, 0, &ak7604_src3_mux_control),
  2185. SND_SOC_DAPM_MUX("SRC4 Source Selector", SND_SOC_NOPM, 0, 0, &ak7604_src4_mux_control),
  2186. };
  2187. static const struct snd_soc_dapm_route ak7604_intercon[] = {
  2188. {"CODEC Power", NULL, "Clock Power"},
  2189. {"SDOUT1", NULL, "Clock Power"},
  2190. {"SDOUT2", NULL, "Clock Power"},
  2191. {"SDOUT3", NULL, "Clock Power"},
  2192. {"ADC", NULL, "CODEC Power"},
  2193. {"DAC1", NULL, "CODEC Power"},
  2194. {"DAC2", NULL, "CODEC Power"},
  2195. {"DAC3", NULL, "CODEC Power"},
  2196. {"ADC MUX", "INP_N", "INP_N"},
  2197. {"ADC MUX", "AIN1_GND", "AIN1_GND"},
  2198. {"ADC MUX", "AIN1", "AIN1"},
  2199. {"ADC MUX", "AIN2", "AIN2"},
  2200. {"ADC MUX", "AIN3", "AIN3"},
  2201. {"MicBias1", NULL, "ADC MUX"},
  2202. {"MicBias1 MUX", "LineIn", "ADC MUX"},
  2203. {"MicBias1 MUX", "MicBias", "MicBias1"},
  2204. {"MicBias2", NULL, "MicBias1 MUX"},
  2205. {"MicBias2 MUX", "LineIn", "ADC MUX"},
  2206. {"MicBias2 MUX", "MicBias", "MicBias2"},
  2207. {"ADC", NULL, "MicBias2 MUX"},
  2208. {"SDOUT1", NULL, "SDOUT1A Source Selector"},
  2209. {"SDOUT1", NULL, "SDOUT1B Source Selector"},
  2210. {"SDOUT1", NULL, "SDOUT1C Source Selector"},
  2211. {"SDOUT1", NULL, "SDOUT1D Source Selector"},
  2212. {"SDOUT2", NULL, "SDOUT2 Source Selector"},
  2213. {"SDOUT3", NULL, "SDOUT3 Source Selector"},
  2214. {"DAC1", NULL, "DAC1 Source Selector"},
  2215. {"DAC2", NULL, "DAC2 Source Selector"},
  2216. {"DAC3", NULL, "DAC3 Source Selector"},
  2217. {"AOUT1", NULL, "DAC1"},
  2218. {"AOUT2", NULL, "DAC2"},
  2219. {"AOUT3", NULL, "DAC3"},
  2220. {"DSPO1", NULL, "DSP"},
  2221. {"DSPO2", NULL, "DSP"},
  2222. {"DSPO3", NULL, "DSP"},
  2223. {"DSPO4", NULL, "DSP"},
  2224. {"DSPO5", NULL, "DSP"},
  2225. {"DSPO6", NULL, "DSP"},
  2226. #if 0
  2227. {"DSPO1", NULL, "DSPOUT1 Mixer"},
  2228. {"DSPO2", NULL, "DSPOUT2 Mixer"},
  2229. {"DSPO3", NULL, "DSPOUT3 Mixer"},
  2230. {"DSPO4", NULL, "DSPOUT4 Mixer"},
  2231. {"DSPO5", NULL, "DSPOUT5 Mixer"},
  2232. {"DSPO6", NULL, "DSPOUT6 Mixer"},
  2233. {"DSPOUT1 Mixer", "DSPIN1", "DSPIN1 Source Selector"},
  2234. {"DSPOUT1 Mixer", "DSPIN2", "DSPIN2 Source Selector"},
  2235. {"DSPOUT1 Mixer", "DSPIN3", "DSPIN3 Source Selector"},
  2236. {"DSPOUT1 Mixer", "DSPIN4", "DSPIN4 Source Selector"},
  2237. {"DSPOUT1 Mixer", "DSPIN5", "DSPIN5 Source Selector"},
  2238. {"DSPOUT1 Mixer", "DSPIN6", "DSPIN6 Source Selector"},
  2239. {"DSPOUT2 Mixer", "DSPIN1", "DSPIN1 Source Selector"},
  2240. {"DSPOUT2 Mixer", "DSPIN2", "DSPIN2 Source Selector"},
  2241. {"DSPOUT2 Mixer", "DSPIN3", "DSPIN3 Source Selector"},
  2242. {"DSPOUT2 Mixer", "DSPIN4", "DSPIN4 Source Selector"},
  2243. {"DSPOUT2 Mixer", "DSPIN5", "DSPIN5 Source Selector"},
  2244. {"DSPOUT2 Mixer", "DSPIN6", "DSPIN6 Source Selector"},
  2245. {"DSPOUT3 Mixer", "DSPIN1", "DSPIN1 Source Selector"},
  2246. {"DSPOUT3 Mixer", "DSPIN2", "DSPIN2 Source Selector"},
  2247. {"DSPOUT3 Mixer", "DSPIN3", "DSPIN3 Source Selector"},
  2248. {"DSPOUT3 Mixer", "DSPIN4", "DSPIN4 Source Selector"},
  2249. {"DSPOUT3 Mixer", "DSPIN5", "DSPIN5 Source Selector"},
  2250. {"DSPOUT3 Mixer", "DSPIN6", "DSPIN6 Source Selector"},
  2251. {"DSPOUT4 Mixer", "DSPIN1", "DSPIN1 Source Selector"},
  2252. {"DSPOUT4 Mixer", "DSPIN2", "DSPIN2 Source Selector"},
  2253. {"DSPOUT4 Mixer", "DSPIN3", "DSPIN3 Source Selector"},
  2254. {"DSPOUT4 Mixer", "DSPIN4", "DSPIN4 Source Selector"},
  2255. {"DSPOUT4 Mixer", "DSPIN5", "DSPIN5 Source Selector"},
  2256. {"DSPOUT4 Mixer", "DSPIN6", "DSPIN6 Source Selector"},
  2257. {"DSPOUT5 Mixer", "DSPIN1", "DSPIN1 Source Selector"},
  2258. {"DSPOUT5 Mixer", "DSPIN2", "DSPIN2 Source Selector"},
  2259. {"DSPOUT5 Mixer", "DSPIN3", "DSPIN3 Source Selector"},
  2260. {"DSPOUT5 Mixer", "DSPIN4", "DSPIN4 Source Selector"},
  2261. {"DSPOUT5 Mixer", "DSPIN5", "DSPIN5 Source Selector"},
  2262. {"DSPOUT5 Mixer", "DSPIN6", "DSPIN6 Source Selector"},
  2263. {"DSPOUT6 Mixer", "DSPIN1", "DSPIN1 Source Selector"},
  2264. {"DSPOUT6 Mixer", "DSPIN2", "DSPIN2 Source Selector"},
  2265. {"DSPOUT6 Mixer", "DSPIN3", "DSPIN3 Source Selector"},
  2266. {"DSPOUT6 Mixer", "DSPIN4", "DSPIN4 Source Selector"},
  2267. {"DSPOUT6 Mixer", "DSPIN5", "DSPIN5 Source Selector"},
  2268. {"DSPOUT6 Mixer", "DSPIN6", "DSPIN6 Source Selector"},
  2269. #endif
  2270. {"SRC1", NULL, "SRC1 Source Selector"},
  2271. {"SRC2", NULL, "SRC2 Source Selector"},
  2272. {"SRC3", NULL, "SRC3 Source Selector"},
  2273. {"SRC4", NULL, "SRC4 Source Selector"},
  2274. {"DSPIN1 Source Selector", "SDIN1A", "SDIN1A"},
  2275. {"DSPIN1 Source Selector", "SDIN1B", "SDIN1B"},
  2276. {"DSPIN1 Source Selector", "SDIN1C", "SDIN1C"},
  2277. {"DSPIN1 Source Selector", "SDIN1D", "SDIN1D"},
  2278. {"DSPIN1 Source Selector", "SDIN2", "SDIN2"},
  2279. {"DSPIN1 Source Selector", "SDIN3", "SDIN3"},
  2280. {"DSPIN1 Source Selector", "SDIN4", "SDIN4"},
  2281. {"DSPIN1 Source Selector", "DSPO1", "DSPO1"},
  2282. {"DSPIN1 Source Selector", "DSPO2", "DSPO2"},
  2283. {"DSPIN1 Source Selector", "DSPO3", "DSPO3"},
  2284. {"DSPIN1 Source Selector", "DSPO4", "DSPO4"},
  2285. {"DSPIN1 Source Selector", "DSPO5", "DSPO5"},
  2286. {"DSPIN1 Source Selector", "DSPO6", "DSPO6"},
  2287. {"DSPIN1 Source Selector", "ADC", "ADC"},
  2288. {"DSPIN1 Source Selector", "SRC1O", "SRC1"},
  2289. {"DSPIN1 Source Selector", "SRC2O", "SRC2"},
  2290. {"DSPIN1 Source Selector", "SRC3O", "SRC3"},
  2291. {"DSPIN1 Source Selector", "SRC4O", "SRC4"},
  2292. {"DSPIN2 Source Selector", "SDIN1A", "SDIN1A"},
  2293. {"DSPIN2 Source Selector", "SDIN1B", "SDIN1B"},
  2294. {"DSPIN2 Source Selector", "SDIN1C", "SDIN1C"},
  2295. {"DSPIN2 Source Selector", "SDIN1D", "SDIN1D"},
  2296. {"DSPIN2 Source Selector", "SDIN2", "SDIN2"},
  2297. {"DSPIN2 Source Selector", "SDIN3", "SDIN3"},
  2298. {"DSPIN2 Source Selector", "SDIN4", "SDIN4"},
  2299. {"DSPIN2 Source Selector", "DSPO1", "DSPO1"},
  2300. {"DSPIN2 Source Selector", "DSPO2", "DSPO2"},
  2301. {"DSPIN2 Source Selector", "DSPO3", "DSPO3"},
  2302. {"DSPIN2 Source Selector", "DSPO4", "DSPO4"},
  2303. {"DSPIN2 Source Selector", "DSPO5", "DSPO5"},
  2304. {"DSPIN2 Source Selector", "DSPO6", "DSPO6"},
  2305. {"DSPIN2 Source Selector", "ADC", "ADC"},
  2306. {"DSPIN2 Source Selector", "SRC1O", "SRC1"},
  2307. {"DSPIN2 Source Selector", "SRC2O", "SRC2"},
  2308. {"DSPIN2 Source Selector", "SRC3O", "SRC3"},
  2309. {"DSPIN2 Source Selector", "SRC4O", "SRC4"},
  2310. {"DSPIN3 Source Selector", "SDIN1A", "SDIN1A"},
  2311. {"DSPIN3 Source Selector", "SDIN1B", "SDIN1B"},
  2312. {"DSPIN3 Source Selector", "SDIN1C", "SDIN1C"},
  2313. {"DSPIN3 Source Selector", "SDIN1D", "SDIN1D"},
  2314. {"DSPIN3 Source Selector", "SDIN2", "SDIN2"},
  2315. {"DSPIN3 Source Selector", "SDIN3", "SDIN3"},
  2316. {"DSPIN3 Source Selector", "SDIN4", "SDIN4"},
  2317. {"DSPIN3 Source Selector", "DSPO1", "DSPO1"},
  2318. {"DSPIN3 Source Selector", "DSPO2", "DSPO2"},
  2319. {"DSPIN3 Source Selector", "DSPO3", "DSPO3"},
  2320. {"DSPIN3 Source Selector", "DSPO4", "DSPO4"},
  2321. {"DSPIN3 Source Selector", "DSPO5", "DSPO5"},
  2322. {"DSPIN3 Source Selector", "DSPO6", "DSPO6"},
  2323. {"DSPIN3 Source Selector", "ADC", "ADC"},
  2324. {"DSPIN3 Source Selector", "SRC1O", "SRC1"},
  2325. {"DSPIN3 Source Selector", "SRC2O", "SRC2"},
  2326. {"DSPIN3 Source Selector", "SRC3O", "SRC3"},
  2327. {"DSPIN3 Source Selector", "SRC4O", "SRC4"},
  2328. {"DSPIN4 Source Selector", "SDIN1A", "SDIN1A"},
  2329. {"DSPIN4 Source Selector", "SDIN1B", "SDIN1B"},
  2330. {"DSPIN4 Source Selector", "SDIN1C", "SDIN1C"},
  2331. {"DSPIN4 Source Selector", "SDIN1D", "SDIN1D"},
  2332. {"DSPIN4 Source Selector", "SDIN2", "SDIN2"},
  2333. {"DSPIN4 Source Selector", "SDIN3", "SDIN3"},
  2334. {"DSPIN4 Source Selector", "SDIN4", "SDIN4"},
  2335. {"DSPIN4 Source Selector", "DSPO1", "DSPO1"},
  2336. {"DSPIN4 Source Selector", "DSPO2", "DSPO2"},
  2337. {"DSPIN4 Source Selector", "DSPO3", "DSPO3"},
  2338. {"DSPIN4 Source Selector", "DSPO4", "DSPO4"},
  2339. {"DSPIN4 Source Selector", "DSPO5", "DSPO5"},
  2340. {"DSPIN4 Source Selector", "DSPO6", "DSPO6"},
  2341. {"DSPIN4 Source Selector", "ADC", "ADC"},
  2342. {"DSPIN4 Source Selector", "SRC1O", "SRC1"},
  2343. {"DSPIN4 Source Selector", "SRC2O", "SRC2"},
  2344. {"DSPIN4 Source Selector", "SRC3O", "SRC3"},
  2345. {"DSPIN4 Source Selector", "SRC4O", "SRC4"},
  2346. {"DSPIN5 Source Selector", "SDIN1A", "SDIN1A"},
  2347. {"DSPIN5 Source Selector", "SDIN1B", "SDIN1B"},
  2348. {"DSPIN5 Source Selector", "SDIN1C", "SDIN1C"},
  2349. {"DSPIN5 Source Selector", "SDIN1D", "SDIN1D"},
  2350. {"DSPIN5 Source Selector", "SDIN2", "SDIN2"},
  2351. {"DSPIN5 Source Selector", "SDIN3", "SDIN3"},
  2352. {"DSPIN5 Source Selector", "SDIN4", "SDIN4"},
  2353. {"DSPIN5 Source Selector", "DSPO1", "DSPO1"},
  2354. {"DSPIN5 Source Selector", "DSPO2", "DSPO2"},
  2355. {"DSPIN5 Source Selector", "DSPO3", "DSPO3"},
  2356. {"DSPIN5 Source Selector", "DSPO4", "DSPO4"},
  2357. {"DSPIN5 Source Selector", "DSPO5", "DSPO5"},
  2358. {"DSPIN5 Source Selector", "DSPO6", "DSPO6"},
  2359. {"DSPIN5 Source Selector", "ADC", "ADC"},
  2360. {"DSPIN5 Source Selector", "SRC1O", "SRC1"},
  2361. {"DSPIN5 Source Selector", "SRC2O", "SRC2"},
  2362. {"DSPIN5 Source Selector", "SRC3O", "SRC3"},
  2363. {"DSPIN5 Source Selector", "SRC4O", "SRC4"},
  2364. {"DSPIN6 Source Selector", "SDIN1A", "SDIN1A"},
  2365. {"DSPIN6 Source Selector", "SDIN1B", "SDIN1B"},
  2366. {"DSPIN6 Source Selector", "SDIN1C", "SDIN1C"},
  2367. {"DSPIN6 Source Selector", "SDIN1D", "SDIN1D"},
  2368. {"DSPIN6 Source Selector", "SDIN2", "SDIN2"},
  2369. {"DSPIN6 Source Selector", "SDIN3", "SDIN3"},
  2370. {"DSPIN6 Source Selector", "SDIN4", "SDIN4"},
  2371. {"DSPIN6 Source Selector", "DSPO1", "DSPO1"},
  2372. {"DSPIN6 Source Selector", "DSPO2", "DSPO2"},
  2373. {"DSPIN6 Source Selector", "DSPO3", "DSPO3"},
  2374. {"DSPIN6 Source Selector", "DSPO4", "DSPO4"},
  2375. {"DSPIN6 Source Selector", "DSPO5", "DSPO5"},
  2376. {"DSPIN6 Source Selector", "DSPO6", "DSPO6"},
  2377. {"DSPIN6 Source Selector", "ADC", "ADC"},
  2378. {"DSPIN6 Source Selector", "SRC1O", "SRC1"},
  2379. {"DSPIN6 Source Selector", "SRC2O", "SRC2"},
  2380. {"DSPIN6 Source Selector", "SRC3O", "SRC3"},
  2381. {"DSPIN6 Source Selector", "SRC4O", "SRC4"},
  2382. {"SRC1 Source Selector", "SDIN1A", "SDIN1A"},
  2383. {"SRC1 Source Selector", "SDIN1B", "SDIN1B"},
  2384. {"SRC1 Source Selector", "SDIN1C", "SDIN1C"},
  2385. {"SRC1 Source Selector", "SDIN1D", "SDIN1D"},
  2386. {"SRC1 Source Selector", "SDIN2", "SDIN2"},
  2387. {"SRC1 Source Selector", "SDIN3", "SDIN3"},
  2388. {"SRC1 Source Selector", "SDIN4", "SDIN4"},
  2389. {"SRC1 Source Selector", "DSPO1", "DSPO1"},
  2390. {"SRC1 Source Selector", "DSPO2", "DSPO2"},
  2391. {"SRC1 Source Selector", "DSPO3", "DSPO3"},
  2392. {"SRC1 Source Selector", "DSPO4", "DSPO4"},
  2393. {"SRC1 Source Selector", "DSPO5", "DSPO5"},
  2394. {"SRC1 Source Selector", "DSPO6", "DSPO6"},
  2395. {"SRC1 Source Selector", "ADC", "ADC"},
  2396. {"SRC1 Source Selector", "SRC1O", "SRC1"},
  2397. {"SRC1 Source Selector", "SRC2O", "SRC2"},
  2398. {"SRC1 Source Selector", "SRC3O", "SRC3"},
  2399. {"SRC1 Source Selector", "SRC4O", "SRC4"},
  2400. {"SRC2 Source Selector", "SDIN1A", "SDIN1A"},
  2401. {"SRC2 Source Selector", "SDIN1B", "SDIN1B"},
  2402. {"SRC2 Source Selector", "SDIN1C", "SDIN1C"},
  2403. {"SRC2 Source Selector", "SDIN1D", "SDIN1D"},
  2404. {"SRC2 Source Selector", "SDIN2", "SDIN2"},
  2405. {"SRC2 Source Selector", "SDIN3", "SDIN3"},
  2406. {"SRC2 Source Selector", "SDIN4", "SDIN4"},
  2407. {"SRC2 Source Selector", "DSPO1", "DSPO1"},
  2408. {"SRC2 Source Selector", "DSPO2", "DSPO2"},
  2409. {"SRC2 Source Selector", "DSPO3", "DSPO3"},
  2410. {"SRC2 Source Selector", "DSPO4", "DSPO4"},
  2411. {"SRC2 Source Selector", "DSPO5", "DSPO5"},
  2412. {"SRC2 Source Selector", "DSPO6", "DSPO6"},
  2413. {"SRC2 Source Selector", "ADC", "ADC"},
  2414. {"SRC2 Source Selector", "SRC1O", "SRC1"},
  2415. {"SRC2 Source Selector", "SRC2O", "SRC2"},
  2416. {"SRC2 Source Selector", "SRC3O", "SRC3"},
  2417. {"SRC2 Source Selector", "SRC4O", "SRC4"},
  2418. {"SRC4 Source Selector", "SDIN1A", "SDIN1A"},
  2419. {"SRC4 Source Selector", "SDIN1B", "SDIN1B"},
  2420. {"SRC4 Source Selector", "SDIN1C", "SDIN1C"},
  2421. {"SRC4 Source Selector", "SDIN1D", "SDIN1D"},
  2422. {"SRC4 Source Selector", "SDIN2", "SDIN2"},
  2423. {"SRC4 Source Selector", "SDIN3", "SDIN3"},
  2424. {"SRC4 Source Selector", "SDIN4", "SDIN4"},
  2425. {"SRC4 Source Selector", "DSPO1", "DSPO1"},
  2426. {"SRC4 Source Selector", "DSPO2", "DSPO2"},
  2427. {"SRC4 Source Selector", "DSPO3", "DSPO3"},
  2428. {"SRC4 Source Selector", "DSPO4", "DSPO4"},
  2429. {"SRC4 Source Selector", "DSPO5", "DSPO5"},
  2430. {"SRC4 Source Selector", "DSPO6", "DSPO6"},
  2431. {"SRC4 Source Selector", "ADC", "ADC"},
  2432. {"SRC4 Source Selector", "SRC1O", "SRC1"},
  2433. {"SRC4 Source Selector", "SRC2O", "SRC2"},
  2434. {"SRC4 Source Selector", "SRC3O", "SRC3"},
  2435. {"SRC4 Source Selector", "SRC4O", "SRC4"},
  2436. {"SRC3 Source Selector", "SDIN1A", "SDIN1A"},
  2437. {"SRC3 Source Selector", "SDIN1B", "SDIN1B"},
  2438. {"SRC3 Source Selector", "SDIN1C", "SDIN1C"},
  2439. {"SRC3 Source Selector", "SDIN1D", "SDIN1D"},
  2440. {"SRC3 Source Selector", "SDIN2", "SDIN2"},
  2441. {"SRC3 Source Selector", "SDIN3", "SDIN3"},
  2442. {"SRC3 Source Selector", "SDIN4", "SDIN4"},
  2443. {"SRC3 Source Selector", "DSPO1", "DSPO1"},
  2444. {"SRC3 Source Selector", "DSPO2", "DSPO2"},
  2445. {"SRC3 Source Selector", "DSPO3", "DSPO3"},
  2446. {"SRC3 Source Selector", "DSPO4", "DSPO4"},
  2447. {"SRC3 Source Selector", "DSPO5", "DSPO5"},
  2448. {"SRC3 Source Selector", "DSPO6", "DSPO6"},
  2449. {"SRC3 Source Selector", "ADC", "ADC"},
  2450. {"SRC3 Source Selector", "SRC1O", "SRC1"},
  2451. {"SRC3 Source Selector", "SRC2O", "SRC2"},
  2452. {"SRC3 Source Selector", "SRC3O", "SRC3"},
  2453. {"SRC3 Source Selector", "SRC4O", "SRC4"},
  2454. {"SDOUT1A Source Selector", "SDIN1A", "SDIN1A"},
  2455. {"SDOUT1A Source Selector", "SDIN1B", "SDIN1B"},
  2456. {"SDOUT1A Source Selector", "SDIN1C", "SDIN1C"},
  2457. {"SDOUT1A Source Selector", "SDIN1D", "SDIN1D"},
  2458. {"SDOUT1A Source Selector", "SDIN2", "SDIN2"},
  2459. {"SDOUT1A Source Selector", "SDIN3", "SDIN3"},
  2460. {"SDOUT1A Source Selector", "SDIN4", "SDIN4"},
  2461. {"SDOUT1A Source Selector", "DSPO1", "DSPO1"},
  2462. {"SDOUT1A Source Selector", "DSPO2", "DSPO2"},
  2463. {"SDOUT1A Source Selector", "DSPO3", "DSPO3"},
  2464. {"SDOUT1A Source Selector", "DSPO4", "DSPO4"},
  2465. {"SDOUT1A Source Selector", "DSPO5", "DSPO5"},
  2466. {"SDOUT1A Source Selector", "DSPO6", "DSPO6"},
  2467. {"SDOUT1A Source Selector", "ADC", "ADC"},
  2468. {"SDOUT1A Source Selector", "SRC1O", "SRC1"},
  2469. {"SDOUT1A Source Selector", "SRC2O", "SRC2"},
  2470. {"SDOUT1A Source Selector", "SRC3O", "SRC3"},
  2471. {"SDOUT1A Source Selector", "SRC4O", "SRC4"},
  2472. {"SDOUT1B Source Selector", "SDIN1A", "SDIN1A"},
  2473. {"SDOUT1B Source Selector", "SDIN1B", "SDIN1B"},
  2474. {"SDOUT1B Source Selector", "SDIN1C", "SDIN1C"},
  2475. {"SDOUT1B Source Selector", "SDIN1D", "SDIN1D"},
  2476. {"SDOUT1B Source Selector", "SDIN2", "SDIN2"},
  2477. {"SDOUT1B Source Selector", "SDIN3", "SDIN3"},
  2478. {"SDOUT1B Source Selector", "SDIN4", "SDIN4"},
  2479. {"SDOUT1B Source Selector", "DSPO1", "DSPO1"},
  2480. {"SDOUT1B Source Selector", "DSPO2", "DSPO2"},
  2481. {"SDOUT1B Source Selector", "DSPO3", "DSPO3"},
  2482. {"SDOUT1B Source Selector", "DSPO4", "DSPO4"},
  2483. {"SDOUT1B Source Selector", "DSPO5", "DSPO5"},
  2484. {"SDOUT1B Source Selector", "DSPO6", "DSPO6"},
  2485. {"SDOUT1B Source Selector", "ADC", "ADC"},
  2486. {"SDOUT1B Source Selector", "SRC1O", "SRC1"},
  2487. {"SDOUT1B Source Selector", "SRC2O", "SRC2"},
  2488. {"SDOUT1B Source Selector", "SRC3O", "SRC3"},
  2489. {"SDOUT1B Source Selector", "SRC4O", "SRC4"},
  2490. {"SDOUT1C Source Selector", "SDIN1A", "SDIN1A"},
  2491. {"SDOUT1C Source Selector", "SDIN1B", "SDIN1B"},
  2492. {"SDOUT1C Source Selector", "SDIN1C", "SDIN1C"},
  2493. {"SDOUT1C Source Selector", "SDIN1D", "SDIN1D"},
  2494. {"SDOUT1C Source Selector", "SDIN2", "SDIN2"},
  2495. {"SDOUT1C Source Selector", "SDIN3", "SDIN3"},
  2496. {"SDOUT1C Source Selector", "SDIN4", "SDIN4"},
  2497. {"SDOUT1C Source Selector", "DSPO1", "DSPO1"},
  2498. {"SDOUT1C Source Selector", "DSPO2", "DSPO2"},
  2499. {"SDOUT1C Source Selector", "DSPO3", "DSPO3"},
  2500. {"SDOUT1C Source Selector", "DSPO4", "DSPO4"},
  2501. {"SDOUT1C Source Selector", "DSPO5", "DSPO5"},
  2502. {"SDOUT1C Source Selector", "DSPO6", "DSPO6"},
  2503. {"SDOUT1C Source Selector", "ADC", "ADC"},
  2504. {"SDOUT1C Source Selector", "SRC1O", "SRC1"},
  2505. {"SDOUT1C Source Selector", "SRC2O", "SRC2"},
  2506. {"SDOUT1C Source Selector", "SRC3O", "SRC3"},
  2507. {"SDOUT1C Source Selector", "SRC4O", "SRC4"},
  2508. {"SDOUT1D Source Selector", "SDIN1A", "SDIN1A"},
  2509. {"SDOUT1D Source Selector", "SDIN1B", "SDIN1B"},
  2510. {"SDOUT1D Source Selector", "SDIN1C", "SDIN1C"},
  2511. {"SDOUT1D Source Selector", "SDIN1D", "SDIN1D"},
  2512. {"SDOUT1D Source Selector", "SDIN2", "SDIN2"},
  2513. {"SDOUT1D Source Selector", "SDIN3", "SDIN3"},
  2514. {"SDOUT1D Source Selector", "SDIN4", "SDIN4"},
  2515. {"SDOUT1D Source Selector", "DSPO1", "DSPO1"},
  2516. {"SDOUT1D Source Selector", "DSPO2", "DSPO2"},
  2517. {"SDOUT1D Source Selector", "DSPO3", "DSPO3"},
  2518. {"SDOUT1D Source Selector", "DSPO4", "DSPO4"},
  2519. {"SDOUT1D Source Selector", "DSPO5", "DSPO5"},
  2520. {"SDOUT1D Source Selector", "DSPO6", "DSPO6"},
  2521. {"SDOUT1D Source Selector", "ADC", "ADC"},
  2522. {"SDOUT1D Source Selector", "SRC1O", "SRC1"},
  2523. {"SDOUT1D Source Selector", "SRC2O", "SRC2"},
  2524. {"SDOUT1D Source Selector", "SRC3O", "SRC3"},
  2525. {"SDOUT1D Source Selector", "SRC4O", "SRC4"},
  2526. {"SDOUT2 Source Selector", "SDIN1A", "SDIN1A"},
  2527. {"SDOUT2 Source Selector", "SDIN1B", "SDIN1B"},
  2528. {"SDOUT2 Source Selector", "SDIN1C", "SDIN1C"},
  2529. {"SDOUT2 Source Selector", "SDIN1D", "SDIN1D"},
  2530. {"SDOUT2 Source Selector", "SDIN2", "SDIN2"},
  2531. {"SDOUT2 Source Selector", "SDIN3", "SDIN3"},
  2532. {"SDOUT2 Source Selector", "SDIN4", "SDIN4"},
  2533. {"SDOUT2 Source Selector", "DSPO1", "DSPO1"},
  2534. {"SDOUT2 Source Selector", "DSPO2", "DSPO2"},
  2535. {"SDOUT2 Source Selector", "DSPO3", "DSPO3"},
  2536. {"SDOUT2 Source Selector", "DSPO4", "DSPO4"},
  2537. {"SDOUT2 Source Selector", "DSPO5", "DSPO5"},
  2538. {"SDOUT2 Source Selector", "DSPO6", "DSPO6"},
  2539. {"SDOUT2 Source Selector", "ADC", "ADC"},
  2540. {"SDOUT2 Source Selector", "SRC1O", "SRC1"},
  2541. {"SDOUT2 Source Selector", "SRC2O", "SRC2"},
  2542. {"SDOUT2 Source Selector", "SRC3O", "SRC3"},
  2543. {"SDOUT2 Source Selector", "SRC4O", "SRC4"},
  2544. {"SDOUT3 Source Selector", "SDIN1A", "SDIN1A"},
  2545. {"SDOUT3 Source Selector", "SDIN1B", "SDIN1B"},
  2546. {"SDOUT3 Source Selector", "SDIN1C", "SDIN1C"},
  2547. {"SDOUT3 Source Selector", "SDIN1D", "SDIN1D"},
  2548. {"SDOUT3 Source Selector", "SDIN2", "SDIN2"},
  2549. {"SDOUT3 Source Selector", "SDIN3", "SDIN3"},
  2550. {"SDOUT3 Source Selector", "SDIN4", "SDIN4"},
  2551. {"SDOUT3 Source Selector", "DSPO1", "DSPO1"},
  2552. {"SDOUT3 Source Selector", "DSPO2", "DSPO2"},
  2553. {"SDOUT3 Source Selector", "DSPO3", "DSPO3"},
  2554. {"SDOUT3 Source Selector", "DSPO4", "DSPO4"},
  2555. {"SDOUT3 Source Selector", "DSPO5", "DSPO5"},
  2556. {"SDOUT3 Source Selector", "DSPO6", "DSPO6"},
  2557. {"SDOUT3 Source Selector", "ADC", "ADC"},
  2558. {"SDOUT3 Source Selector", "SRC1O", "SRC1"},
  2559. {"SDOUT3 Source Selector", "SRC2O", "SRC2"},
  2560. {"SDOUT3 Source Selector", "SRC3O", "SRC3"},
  2561. {"SDOUT3 Source Selector", "SRC4O", "SRC4"},
  2562. {"DAC1 Source Selector", "SDIN1A", "SDIN1A"},
  2563. {"DAC1 Source Selector", "SDIN1B", "SDIN1B"},
  2564. {"DAC1 Source Selector", "SDIN1C", "SDIN1C"},
  2565. {"DAC1 Source Selector", "SDIN1D", "SDIN1D"},
  2566. {"DAC1 Source Selector", "SDIN2", "SDIN2"},
  2567. {"DAC1 Source Selector", "SDIN3", "SDIN3"},
  2568. {"DAC1 Source Selector", "DSPO1", "DSPO1"},
  2569. {"DAC1 Source Selector", "DSPO2", "DSPO2"},
  2570. {"DAC1 Source Selector", "DSPO3", "DSPO3"},
  2571. {"DAC1 Source Selector", "DSPO4", "DSPO4"},
  2572. {"DAC1 Source Selector", "DSPO5", "DSPO5"},
  2573. {"DAC1 Source Selector", "DSPO6", "DSPO6"},
  2574. {"DAC1 Source Selector", "ADC", "ADC"},
  2575. {"DAC1 Source Selector", "SRC1O", "SRC1"},
  2576. {"DAC1 Source Selector", "SRC2O", "SRC2"},
  2577. {"DAC1 Source Selector", "SRC3O", "SRC3"},
  2578. {"DAC1 Source Selector", "SRC4O", "SRC4"},
  2579. {"DAC2 Source Selector", "SDIN1A", "SDIN1A"},
  2580. {"DAC2 Source Selector", "SDIN1B", "SDIN1B"},
  2581. {"DAC2 Source Selector", "SDIN1C", "SDIN1C"},
  2582. {"DAC2 Source Selector", "SDIN1D", "SDIN1D"},
  2583. {"DAC2 Source Selector", "SDIN2", "SDIN2"},
  2584. {"DAC2 Source Selector", "SDIN3", "SDIN3"},
  2585. {"DAC2 Source Selector", "SDIN4", "SDIN4"},
  2586. {"DAC2 Source Selector", "DSPO1", "DSPO1"},
  2587. {"DAC2 Source Selector", "DSPO2", "DSPO2"},
  2588. {"DAC2 Source Selector", "DSPO3", "DSPO3"},
  2589. {"DAC2 Source Selector", "DSPO4", "DSPO4"},
  2590. {"DAC2 Source Selector", "DSPO5", "DSPO5"},
  2591. {"DAC2 Source Selector", "DSPO6", "DSPO6"},
  2592. {"DAC2 Source Selector", "ADC", "ADC"},
  2593. {"DAC2 Source Selector", "SRC1O", "SRC1"},
  2594. {"DAC2 Source Selector", "SRC2O", "SRC2"},
  2595. {"DAC2 Source Selector", "SRC3O", "SRC3"},
  2596. {"DAC2 Source Selector", "SRC4O", "SRC4"},
  2597. {"DAC3 Source Selector", "SDIN1A", "SDIN1A"},
  2598. {"DAC3 Source Selector", "SDIN1B", "SDIN1B"},
  2599. {"DAC3 Source Selector", "SDIN1C", "SDIN1C"},
  2600. {"DAC3 Source Selector", "SDIN1D", "SDIN1D"},
  2601. {"DAC3 Source Selector", "SDIN2", "SDIN2"},
  2602. {"DAC3 Source Selector", "SDIN3", "SDIN3"},
  2603. {"DAC3 Source Selector", "SDIN4", "SDIN4"},
  2604. {"DAC3 Source Selector", "DSPO1", "DSPO1"},
  2605. {"DAC3 Source Selector", "DSPO2", "DSPO2"},
  2606. {"DAC3 Source Selector", "DSPO3", "DSPO3"},
  2607. {"DAC3 Source Selector", "DSPO4", "DSPO4"},
  2608. {"DAC3 Source Selector", "DSPO5", "DSPO5"},
  2609. {"DAC3 Source Selector", "DSPO6", "DSPO6"},
  2610. {"DAC3 Source Selector", "ADC", "ADC"},
  2611. {"DAC3 Source Selector", "SRC1O", "SRC1"},
  2612. {"DAC3 Source Selector", "SRC2O", "SRC2"},
  2613. {"DAC3 Source Selector", "SRC3O", "SRC3"},
  2614. {"DAC3 Source Selector", "SRC4O", "SRC4"},
  2615. };
  2616. static int ak7604_hw_params(struct snd_pcm_substream *substream,
  2617. struct snd_pcm_hw_params *params,
  2618. struct snd_soc_dai *dai)
  2619. {
  2620. struct snd_soc_component *component = dai->component;
  2621. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  2622. int nSDNo;
  2623. int fsno, nmax;
  2624. int DIODLbit, addr, value;
  2625. akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  2626. ak7604->fs = params_rate(params);
  2627. akdbgprt("\t[AK7604] %s fs=%d\n", __func__, ak7604->fs);
  2628. mdelay(10);
  2629. DIODLbit = 2;
  2630. switch (params_format(params)) {
  2631. case SNDRV_PCM_FORMAT_S16_LE:
  2632. DIODLbit = 2;
  2633. break;
  2634. case SNDRV_PCM_FORMAT_S24_LE:
  2635. DIODLbit = 0;
  2636. break;
  2637. case SNDRV_PCM_FORMAT_S32_LE:
  2638. DIODLbit = 3;
  2639. break;
  2640. default:
  2641. pr_err("%s: invalid Audio format %u\n", __func__, params_format(params));
  2642. return -EINVAL;
  2643. }
  2644. akdbgprt("\t[AK7604] %s dai->id = %d\n", __func__, dai->id);
  2645. switch (dai->id) {
  2646. case AIF_PORT1:
  2647. nSDNo = 0;
  2648. break;
  2649. case AIF_PORT2:
  2650. nSDNo = 1;
  2651. break;
  2652. case AIF_PORT3:
  2653. nSDNo = 2;
  2654. break;
  2655. case AIF_PORT4:
  2656. nSDNo = 3;
  2657. break;
  2658. default:
  2659. pr_err("%s: Invalid dai id %d\n", __func__, dai->id);
  2660. return -EINVAL;
  2661. }
  2662. fsno = 0;
  2663. nmax = ARRAY_SIZE(sdfstab);
  2664. akdbgprt("\t[AK7604] %s nmax = %d\n", __func__, nmax);
  2665. do {
  2666. if (ak7604->fs <= sdfstab[fsno])
  2667. break;
  2668. fsno++;
  2669. } while (fsno < nmax);
  2670. akdbgprt("\t[AK7604] %s fsno = %d\n", __func__, fsno);
  2671. if (fsno == nmax) {
  2672. pr_err("%s: not support Sampling Frequency : %d\n", __func__, ak7604->fs);
  2673. return -EINVAL;
  2674. }
  2675. akdbgprt("\t[AK7604] %s setSDClock\n", __func__);
  2676. mdelay(10);
  2677. ak7604->SDfs[nSDNo] = fsno;
  2678. setSDClock(component, nSDNo);
  2679. /* set Word length */
  2680. addr = AK7604_2E_SDIN1_FORMAT + nSDNo;
  2681. value = DIODLbit;
  2682. snd_soc_component_update_bits(component, addr, 0x03, value);
  2683. addr = AK7604_32_SDOUT1_FORMAT + nSDNo;
  2684. snd_soc_component_update_bits(component, addr, 0x03, value);
  2685. return 0;
  2686. }
  2687. static int ak7604_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id,
  2688. unsigned int freq, int dir)
  2689. {
  2690. akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  2691. return 0;
  2692. }
  2693. static int ak7604_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  2694. {
  2695. struct snd_soc_component *component = dai->component;
  2696. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  2697. int format, diolsb, diedge, doedge, dislot, doslot;
  2698. int msnbit;
  2699. int nSDNo, value;
  2700. int addr, mask, shift;
  2701. akdbgprt("\t[AK7604] %s(%d),dai->id = %d\n", __func__, __LINE__, dai->id);
  2702. switch (dai->id) {
  2703. case AIF_PORT1:
  2704. nSDNo = 0;
  2705. break;
  2706. case AIF_PORT2:
  2707. nSDNo = 1;
  2708. break;
  2709. case AIF_PORT3:
  2710. nSDNo = 2;
  2711. break;
  2712. case AIF_PORT4:
  2713. nSDNo = 3;
  2714. break;
  2715. default:
  2716. pr_err("%s: Invalid dai id %d\n", __func__, dai->id);
  2717. return -EINVAL;
  2718. }
  2719. /* set master/slave audio interface */
  2720. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  2721. case SND_SOC_DAIFMT_CBS_CFS:
  2722. msnbit = 0;
  2723. akdbgprt("\t[AK7604] %s(Slave_nSDNo=%d)\n", __func__, nSDNo);
  2724. break;
  2725. case SND_SOC_DAIFMT_CBM_CFM:
  2726. msnbit = 1;
  2727. akdbgprt("\t[AK7604] %s(Master_nSDNo=%d)\n", __func__, nSDNo);
  2728. break;
  2729. case SND_SOC_DAIFMT_CBS_CFM:
  2730. case SND_SOC_DAIFMT_CBM_CFS:
  2731. default:
  2732. dev_err(component->dev, "Clock mode unsupported");
  2733. return -EINVAL;
  2734. }
  2735. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  2736. case SND_SOC_DAIFMT_I2S:
  2737. format = AK7604_LRIF_I2S_MODE; // 0
  2738. diolsb = 0;
  2739. diedge = ak7604->DIEDGEbit[nSDNo];
  2740. doedge = ak7604->DOEDGEbit[nSDNo];
  2741. dislot = 3;
  2742. doslot = 3;
  2743. break;
  2744. case SND_SOC_DAIFMT_LEFT_J:
  2745. format = AK7604_LRIF_MSB_MODE; // 5
  2746. diolsb = 0;
  2747. diedge = ak7604->DIEDGEbit[nSDNo];
  2748. doedge = ak7604->DOEDGEbit[nSDNo];
  2749. dislot = 3;
  2750. doslot = 3;
  2751. break;
  2752. case SND_SOC_DAIFMT_RIGHT_J:
  2753. format = AK7604_LRIF_LSB_MODE; // 5
  2754. diolsb = 1;
  2755. diedge = ak7604->DIEDGEbit[nSDNo];
  2756. doedge = ak7604->DOEDGEbit[nSDNo];
  2757. dislot = 3;
  2758. doslot = 3;
  2759. break;
  2760. case SND_SOC_DAIFMT_DSP_A:
  2761. format = AK7604_LRIF_PCM_SHORT_MODE; // 6
  2762. diolsb = 0;
  2763. diedge = 1;
  2764. doedge = 1;
  2765. dislot = ak7604->DISLbit[nSDNo];
  2766. doslot = ak7604->DOSLbit[nSDNo];
  2767. break;
  2768. case SND_SOC_DAIFMT_DSP_B:
  2769. format = AK7604_LRIF_PCM_LONG_MODE; // 7
  2770. diolsb = 0;
  2771. diedge = 1;
  2772. doedge = 1;
  2773. dislot = ak7604->DISLbit[nSDNo];
  2774. doslot = ak7604->DOSLbit[nSDNo];
  2775. break;
  2776. default:
  2777. return -EINVAL;
  2778. }
  2779. /* set format */
  2780. akdbgprt("\t[AK7604] %s(Master_nSDNo=%d,msnbit = =%d)\n", __func__, nSDNo, msnbit);
  2781. //setSDMaster(component, nSDNo, msnbit);
  2782. addr = AK7604_2C_CLOCKFORMAT1 + (nSDNo/2);
  2783. akdbgprt("\t[AK7604] %s(addr =0x%x)\n", __func__, addr);
  2784. shift = 4 * ((nSDNo+1) % 2);
  2785. value = (format << shift);
  2786. mask = 0xF << shift;
  2787. akdbgprt("\t[AK7604] %s(value = =0x%x,mask =0x%x)\n", __func__, value, mask);
  2788. snd_soc_component_update_bits(component, addr, mask, value);
  2789. /* set SDIO format */
  2790. /* set Slot length */
  2791. addr = AK7604_2E_SDIN1_FORMAT + nSDNo;
  2792. value = (diedge << 7) + (diolsb << 3) + (dislot << 4);
  2793. snd_soc_component_update_bits(component, addr, 0xB8, value);
  2794. addr = AK7604_32_SDOUT1_FORMAT + nSDNo;
  2795. value = (doedge << 7) + (diolsb << 3) + (doslot << 4);
  2796. snd_soc_component_update_bits(component, addr, 0xB8, value);
  2797. return 0;
  2798. }
  2799. static bool ak7604_volatile(struct device *dev, unsigned int reg)
  2800. {
  2801. bool ret;
  2802. #ifdef AK7604_DEBUG
  2803. if (reg < AK7604_VIRT_REGISTER)
  2804. ret = true;
  2805. else
  2806. ret = false;
  2807. #else
  2808. if (reg < AK7604_C0_DEVICE_ID)
  2809. ret = false;
  2810. else if (reg < AK7604_VIRT_REGISTER)
  2811. ret = true;
  2812. else
  2813. ret = false;
  2814. #endif
  2815. return(ret);
  2816. }
  2817. static bool ak7604_readable(struct device *dev, unsigned int reg)
  2818. {
  2819. bool ret;
  2820. if (reg == AK7604_03_RESERVED)
  2821. ret = false;
  2822. else if (reg <= AK7604_34_SDOUT3_FORMAT)
  2823. ret = true;
  2824. else if (reg < AK7604_50_INPUT_DATA)
  2825. ret = false;
  2826. else if (reg <= AK7604_53_STO_SETTING)
  2827. ret = true;
  2828. else if (reg < AK7604_60_DSP_SETTING1)
  2829. ret = false;
  2830. else if (reg <= AK7604_61_DSP_SETTING2)
  2831. ret = true;
  2832. else if (reg < AK7604_71_SRCMUTE_SETTING)
  2833. ret = false;
  2834. else if (reg <= AK7604_73_SRCFILTER_SETTING)
  2835. ret = true;
  2836. else if (reg < AK7604_81_MIC_SETTING)
  2837. ret = false;
  2838. else if (reg <= AK7604_8E_ADC_MUTEHPF)
  2839. ret = true;
  2840. else if (reg < AK7604_A1_POWERMANAGEMENT1)
  2841. ret = false;
  2842. else if (reg <= AK7604_A3_RESETCONTROL)
  2843. ret = true;
  2844. else if (reg < AK7604_C0_DEVICE_ID)
  2845. ret = false;
  2846. else if (reg <= AK7604_VIRT_CC_DSPOUT6_MIX)
  2847. ret = true;
  2848. else
  2849. ret = true;
  2850. return ret;
  2851. }
  2852. static bool ak7604_writeable(struct device *dev, unsigned int reg)
  2853. {
  2854. bool ret;
  2855. if (reg == AK7604_03_RESERVED)
  2856. ret = false;
  2857. else if (reg <= AK7604_34_SDOUT3_FORMAT)
  2858. ret = true;
  2859. else if (reg < AK7604_50_INPUT_DATA)
  2860. ret = false;
  2861. else if (reg <= AK7604_53_STO_SETTING)
  2862. ret = true;
  2863. else if (reg < AK7604_60_DSP_SETTING1)
  2864. ret = false;
  2865. else if (reg <= AK7604_61_DSP_SETTING2)
  2866. ret = true;
  2867. else if (reg < AK7604_71_SRCMUTE_SETTING)
  2868. ret = false;
  2869. else if (reg <= AK7604_73_SRCFILTER_SETTING)
  2870. ret = true;
  2871. else if (reg < AK7604_81_MIC_SETTING)
  2872. ret = false;
  2873. else if (reg <= AK7604_8E_ADC_MUTEHPF)
  2874. ret = true;
  2875. else if (reg < AK7604_A1_POWERMANAGEMENT1)
  2876. ret = false;
  2877. else if (reg <= AK7604_A3_RESETCONTROL)
  2878. ret = true;
  2879. else if (reg < AK7604_VIRT_C7_DSPOUT1_MIX)
  2880. ret = false;
  2881. else if (reg <= AK7604_VIRT_CC_DSPOUT6_MIX)
  2882. ret = true;
  2883. else
  2884. ret = false;
  2885. return ret;
  2886. }
  2887. static unsigned int ak7604_i2c_read(
  2888. struct i2c_client *client,
  2889. u8 *reg,
  2890. int reglen,
  2891. u8 *data,
  2892. int datalen)
  2893. {
  2894. struct i2c_msg xfer[2];
  2895. int ret;
  2896. /* Write register */
  2897. xfer[0].addr = client->addr;
  2898. xfer[0].flags = 0;
  2899. xfer[0].len = reglen;
  2900. xfer[0].buf = reg;
  2901. /* Read data */
  2902. xfer[1].addr = client->addr;
  2903. xfer[1].flags = I2C_M_RD;
  2904. xfer[1].len = datalen;
  2905. xfer[1].buf = data;
  2906. ret = i2c_transfer(client->adapter, xfer, 2);
  2907. if (ret == 2)
  2908. return 0;
  2909. else if (ret < 0)
  2910. return -ret;
  2911. else
  2912. return -EIO;
  2913. }
  2914. static unsigned int ak7604_read_register(struct snd_soc_component *component, unsigned int reg)
  2915. {
  2916. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  2917. unsigned char tx[3], rx[1];
  2918. int wlen, rlen;
  2919. int val, ret;
  2920. unsigned int rdata;
  2921. if (reg == SND_SOC_NOPM)
  2922. return 0;
  2923. BUG_ON(reg > AK7604_MAX_REGISTER);
  2924. if (!ak7604_readable(NULL, reg))
  2925. return 0xFF;
  2926. if (!ak7604_volatile(NULL, reg) && ak7604_readable(NULL, reg)) {
  2927. ret = regmap_read(ak7604->regmap, reg, &val);
  2928. if (ret >= 0) {
  2929. return val;
  2930. } else if (ret < 0) {
  2931. dev_err(component->dev, "Cache read from %x failed: %d\n", reg, ret);
  2932. return 0;
  2933. }
  2934. }
  2935. wlen = 3;
  2936. rlen = 1;
  2937. tx[0] = (unsigned char)(COMMAND_READ_REG & 0x7F);
  2938. tx[1] = (unsigned char)(0xFF & (reg >> 8));
  2939. tx[2] = (unsigned char)(0xFF & reg);
  2940. if (ak7604->control_type == SND_SOC_SPI)
  2941. ret = spi_write_then_read(ak7604->spi, tx, wlen, rx, rlen);
  2942. else
  2943. ret = ak7604_i2c_read(ak7604->i2c, tx, wlen, rx, rlen);
  2944. if (ret < 0) {
  2945. akdbgprt("\t[AK7604] %s error ret = %d\n", __func__, ret);
  2946. rdata = -EIO;
  2947. } else {
  2948. rdata = (unsigned int)rx[0];
  2949. }
  2950. return rdata;
  2951. }
  2952. static int ak7604_reads(struct snd_soc_component *component, u8 *tx, size_t wlen, u8 *rx, size_t rlen)
  2953. {
  2954. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  2955. int ret;
  2956. akdbgprt("*****[AK7604] %s tx[0]=%x, %d, %d\n", __func__, tx[0], (int)wlen, (int)rlen);
  2957. if (ak7604->control_type == SND_SOC_SPI)
  2958. ret = spi_write_then_read(ak7604->spi, tx, wlen, rx, rlen);
  2959. else
  2960. ret = ak7604_i2c_read(ak7604->i2c, tx, wlen, rx, rlen);
  2961. return ret;
  2962. }
  2963. static int ak7604_write_register(struct snd_soc_component *component,
  2964. unsigned int reg, unsigned int value)
  2965. {
  2966. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  2967. unsigned char tx[4];
  2968. int wlen;
  2969. int ret;
  2970. //akdbgprt("[AK7604] %s (%x, %x)\n", __func__, reg, value);
  2971. if (reg == SND_SOC_NOPM)
  2972. return 0;
  2973. if (!ak7604_volatile(NULL, reg)) {
  2974. ret = regmap_write(ak7604->regmap, reg, value);
  2975. if (ret != 0)
  2976. dev_err(component->dev, "Cache write to %x failed: %d\n", reg, ret);
  2977. }
  2978. if (reg >= AK7604_VIRT_REGISTER)
  2979. return 0;
  2980. wlen = 4;
  2981. tx[0] = (unsigned char)COMMAND_WRITE_REG;
  2982. tx[1] = (unsigned char)(0xFF & (reg >> 8));
  2983. tx[2] = (unsigned char)(0xFF & reg);
  2984. tx[3] = value;
  2985. if (ak7604->control_type == SND_SOC_SPI)
  2986. ret = spi_write(ak7604->spi, tx, wlen);
  2987. else
  2988. ret = i2c_master_send(ak7604->i2c, tx, wlen);
  2989. return ret;
  2990. }
  2991. static int ak7604_write_spidmy(struct snd_soc_component *component)
  2992. {
  2993. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  2994. unsigned char tx[4];
  2995. int wlen;
  2996. int rd;
  2997. akdbgprt("[AK7604] %s\n", __func__);
  2998. rd = 0;
  2999. wlen = 4;
  3000. tx[0] = (unsigned char)(0xDE);
  3001. tx[1] = (unsigned char)(0xAD);
  3002. tx[2] = (unsigned char)(0xDA);
  3003. tx[3] = (unsigned char)(0x7A);
  3004. if (ak7604->control_type == SND_SOC_SPI)
  3005. rd = spi_write(ak7604->spi, tx, wlen);
  3006. return rd;
  3007. }
  3008. static int ak7604_writes(struct snd_soc_component *component, const u8 *tx, size_t wlen)
  3009. {
  3010. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  3011. int rc;
  3012. akdbgprt("[AK7604W] %s tx[0]=%x tx[1]=%x, len=%d\n",
  3013. __func__, (int)tx[0], (int)tx[1], (int)wlen);
  3014. if (ak7604->control_type == SND_SOC_SPI)
  3015. rc = spi_write(ak7604->spi, tx, wlen);
  3016. else
  3017. rc = i2c_master_send(ak7604->i2c, tx, wlen);
  3018. return rc;
  3019. }
  3020. static int crc_read(struct snd_soc_component *component)
  3021. {
  3022. int rc;
  3023. u8 tx[3], rx[2];
  3024. tx[0] = COMMAND_CRC_READ;
  3025. tx[1] = 0;
  3026. tx[2] = 0;
  3027. rc = ak7604_reads(component, tx, 3, rx, 2);
  3028. return (rc < 0) ? rc : ((rx[0] << 8) + rx[1]);
  3029. }
  3030. static int ak7604_set_status(struct snd_soc_component *component, enum ak7604_status status)
  3031. {
  3032. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  3033. akdbgprt("\t[AK7604] %s status=%d\n", __func__, status);
  3034. switch (status) {
  3035. case RUN:
  3036. // CKRESETN bit = 1
  3037. snd_soc_component_update_bits(component, AK7604_02_SYSTEMCLOCK_3, 0x80, 0x80);
  3038. mdelay(10);
  3039. // CRESETN bit = D1RESETN = HRESETN = 1;
  3040. snd_soc_component_update_bits(component, AK7604_A3_RESETCONTROL, 0x07, 0x07);
  3041. break;
  3042. case DOWNLOAD:
  3043. ak7604->dresetn = snd_soc_component_read(component, AK7604_A3_RESETCONTROL);
  3044. ak7604->dresetn &= 0x4;
  3045. if (ak7604->dresetn)
  3046. // D1RESETN = 0;
  3047. snd_soc_component_update_bits(component, AK7604_A3_RESETCONTROL, 0x04, 0x0);
  3048. mdelay(1);
  3049. // DLRDY bit = 1
  3050. snd_soc_component_update_bits(component, AK7604_02_SYSTEMCLOCK_3, 0x01, 0x01);
  3051. break;
  3052. case DOWNLOAD_FINISH:
  3053. // DLRDY bit = 0
  3054. snd_soc_component_update_bits(component, AK7604_02_SYSTEMCLOCK_3, 0x01, 0x0);
  3055. mdelay(1);
  3056. snd_soc_component_update_bits(component, AK7604_A3_RESETCONTROL, 0x04, ak7604->dresetn);
  3057. break;
  3058. case STANDBY:
  3059. // CRESETN bit = D1RESETN = HRESETN = 0;
  3060. snd_soc_component_update_bits(component, AK7604_A3_RESETCONTROL, 0x07, 0x0);
  3061. // CKRESETN bit = 1
  3062. snd_soc_component_update_bits(component, AK7604_02_SYSTEMCLOCK_3, 0x80, 0x80);
  3063. break;
  3064. case SUSPEND:
  3065. case POWERDOWN:
  3066. // CRESETN bit = D1RESETN = HRESETN = 0;
  3067. snd_soc_component_update_bits(component, AK7604_A3_RESETCONTROL, 0x07, 0x0);
  3068. // CKRESETN bit = 0
  3069. snd_soc_component_update_bits(component, AK7604_02_SYSTEMCLOCK_3, 0x80, 0x0);
  3070. break;
  3071. default:
  3072. return -EINVAL;
  3073. }
  3074. ak7604->status = status;
  3075. return 0;
  3076. }
  3077. static int ak7604_ram_download(struct snd_soc_component *component, const u8 *tx_ram, u64 num, u16 crc)
  3078. {
  3079. int rc;
  3080. int nDSPRun;
  3081. u16 read_crc;
  3082. akdbgprt("\t[AK7604] %s num=%ld\n", __func__, (long)num);
  3083. nDSPRun = snd_soc_component_read(component, AK7604_A3_RESETCONTROL);
  3084. ak7604_set_status(component, DOWNLOAD);
  3085. rc = ak7604_writes(component, tx_ram, num);
  3086. if (rc < 0) {
  3087. snd_soc_component_write(component, AK7604_A3_RESETCONTROL, nDSPRun);
  3088. return rc;
  3089. }
  3090. if ((crc != 0) && (rc >= 0)) {
  3091. read_crc = crc_read(component);
  3092. akdbgprt("\t[AK7604] %s CRC Cal=%x Read=%x\n", __func__, (int)crc, (int)read_crc);
  3093. if (read_crc == crc)
  3094. rc = 0;
  3095. else
  3096. rc = 1;
  3097. }
  3098. ak7604_set_status(component, DOWNLOAD_FINISH);
  3099. snd_soc_component_write(component, AK7604_A3_RESETCONTROL, nDSPRun);
  3100. return rc;
  3101. }
  3102. static int calc_CRC(int length, u8 *data)
  3103. {
  3104. #define CRC16_CCITT (0x1021)
  3105. unsigned short crc = 0x0000;
  3106. int i, j;
  3107. for (i = 0; i < length; i++) {
  3108. crc ^= *data++ << 8;
  3109. for (j = 0; j < 8; j++) {
  3110. if (crc & 0x8000) {
  3111. crc <<= 1;
  3112. crc ^= CRC16_CCITT;
  3113. } else {
  3114. crc <<= 1;
  3115. }
  3116. }
  3117. }
  3118. akdbgprt("[AK7604] %s CRC=%x\n", __func__, crc);
  3119. return crc;
  3120. }
  3121. static int ak7604_write_ram(
  3122. struct snd_soc_component *component,
  3123. int nPCRam, // 0 : PRAM, 1 : CRAM
  3124. u8 *upRam,
  3125. int nWSize)
  3126. {
  3127. int n, ret;
  3128. int wCRC;
  3129. int nMaxSize;
  3130. akdbgprt("[AK7604] %s RamNo=%d, len=%d\n", __func__, nPCRam, nWSize);
  3131. switch (nPCRam) {
  3132. case RAMTYPE_PRAM:
  3133. nMaxSize = TOTAL_NUM_OF_PRAM_MAX;
  3134. if (nWSize > nMaxSize) {
  3135. akdbgprt("%s: PRAM Write size is over!\n", __func__);
  3136. return(-1);
  3137. }
  3138. break;
  3139. case RAMTYPE_CRAM:
  3140. nMaxSize = TOTAL_NUM_OF_CRAM_MAX;
  3141. if (nWSize > nMaxSize) {
  3142. akdbgprt("%s: CRAM Write size is over!\n", __func__);
  3143. return(-1);
  3144. }
  3145. break;
  3146. default:
  3147. return(-1);
  3148. }
  3149. wCRC = calc_CRC(nWSize, upRam);
  3150. n = MAX_LOOP_TIMES;
  3151. do {
  3152. ret = ak7604_ram_download(component, upRam, nWSize, wCRC);
  3153. if (ret >= 0)
  3154. break;
  3155. n--;
  3156. } while (n > 0);
  3157. if (ret < 0) {
  3158. akdbgprt("%s: RAM Write Error! RAM No = %d\n", __func__, nPCRam);
  3159. return(-1);
  3160. }
  3161. return 0;
  3162. }
  3163. static int ak7604_firmware_write_ram(struct snd_soc_component *component, u16 mode, u16 cmd)
  3164. {
  3165. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  3166. int ret = 0;
  3167. int nNumMode, nMaxLen;
  3168. int nRamSize;
  3169. u8 *ram_basic;
  3170. const struct firmware *fw;
  3171. u8 *fwdn;
  3172. char szFileName[32];
  3173. akdbgprt("[AK7604] %s mode=%d, cmd=%d\n", __func__, mode, cmd);
  3174. switch (mode) {
  3175. case RAMTYPE_PRAM:
  3176. nNumMode = ARRAY_SIZE(ak7604_firmware_pram);
  3177. break;
  3178. case RAMTYPE_CRAM:
  3179. nNumMode = ARRAY_SIZE(ak7604_firmware_cram);
  3180. break;
  3181. default:
  3182. akdbgprt("[AK7604] %s mode Error=%d\n", __func__, mode);
  3183. return(-EINVAL);
  3184. }
  3185. if (cmd == 0)
  3186. return 0;
  3187. if (cmd >= nNumMode) {
  3188. pr_err("%s: invalid command %d\n", __func__, cmd);
  3189. return(-EINVAL);
  3190. }
  3191. if (cmd == 1) {
  3192. switch (mode) {
  3193. case RAMTYPE_PRAM:
  3194. ram_basic = ak7604_pram_basic;
  3195. nRamSize = sizeof(ak7604_pram_basic);
  3196. break;
  3197. case RAMTYPE_CRAM:
  3198. ram_basic = ak7604_cram_basic;
  3199. nRamSize = sizeof(ak7604_cram_basic);
  3200. break;
  3201. default:
  3202. return(-EINVAL);
  3203. }
  3204. ret = ak7604_write_ram(component, (int)mode, ram_basic, nRamSize);
  3205. } else {
  3206. switch (mode) {
  3207. case RAMTYPE_PRAM:
  3208. sprintf(szFileName, "ak7604_pram_%s.bin", ak7604_firmware_pram[cmd]);
  3209. nMaxLen = TOTAL_NUM_OF_PRAM_MAX;
  3210. break;
  3211. case RAMTYPE_CRAM:
  3212. sprintf(szFileName, "ak7604_cram_%s.bin", ak7604_firmware_cram[cmd]);
  3213. nMaxLen = TOTAL_NUM_OF_CRAM_MAX;
  3214. break;
  3215. default:
  3216. return(-EINVAL);
  3217. }
  3218. if (ak7604->control_type == SND_SOC_SPI)
  3219. ret = request_firmware(&fw, szFileName, &(ak7604->spi->dev));
  3220. else
  3221. ret = request_firmware(&fw, szFileName, &(ak7604->i2c->dev));
  3222. if (ret) {
  3223. akdbgprt("[AK7604] %s could not load firmware=%d\n", szFileName, ret);
  3224. return -EINVAL;
  3225. }
  3226. akdbgprt("[AK7604] %s name=%s size=%d\n", __func__, szFileName, (int)fw->size);
  3227. if (fw->size > nMaxLen) {
  3228. akdbgprt("[AK7604] %s RAM Size Error : %d\n", __func__, (int)fw->size);
  3229. release_firmware(fw);
  3230. return -ENOMEM;
  3231. }
  3232. fwdn = kmalloc((unsigned long)fw->size, GFP_KERNEL);
  3233. if (fwdn == NULL) {
  3234. akdbgprt(KERN_ERR "failed to buffer vmalloc: %d\n", (int)fw->size);
  3235. release_firmware(fw);
  3236. return -ENOMEM;
  3237. }
  3238. memcpy((void *)fwdn, fw->data, fw->size);
  3239. ret = ak7604_write_ram(component, (int)mode, (u8 *)fwdn, (fw->size));
  3240. kfree(fwdn);
  3241. release_firmware(fw);
  3242. }
  3243. return ret;
  3244. }
  3245. static int ak7604_write_cram(
  3246. struct snd_soc_component *component,
  3247. int addr,
  3248. int len,
  3249. unsigned char *cram_data)
  3250. {
  3251. int i, n, ret;
  3252. int nDSPRun;
  3253. unsigned char tx[51];
  3254. akdbgprt("[AK7604] %s addr=%d, len=%d\n", __func__, addr, len);
  3255. if (len > 48) {
  3256. akdbgprt("[AK7604] %s Length over!\n", __func__);
  3257. return(-1);
  3258. }
  3259. nDSPRun = snd_soc_component_read(component, AK7604_A3_RESETCONTROL);
  3260. if (nDSPRun & 0x04) {
  3261. tx[0] = COMMAND_WRITE_CRAM_RUN + (unsigned char)((len / 3) - 1);
  3262. tx[1] = (unsigned char)(0xFF & (addr >> 8));
  3263. tx[2] = (unsigned char)(0xFF & addr);
  3264. } else {
  3265. ak7604_set_status(component, DOWNLOAD);
  3266. tx[0] = COMMAND_WRITE_CRAM;
  3267. tx[1] = (unsigned char)(0xFF & (addr >> 8));
  3268. tx[2] = (unsigned char)(0xFF & addr);
  3269. }
  3270. n = 3;
  3271. for (i = 0; i < len; i++)
  3272. tx[n++] = cram_data[i];
  3273. ret = ak7604_writes(component, tx, n);
  3274. if (nDSPRun & 0x04) {
  3275. tx[0] = COMMAND_WRITE_CRAM_EXEC;
  3276. tx[1] = 0;
  3277. tx[2] = 0;
  3278. ret = ak7604_writes(component, tx, 3);
  3279. } else {
  3280. ak7604_set_status(component, DOWNLOAD_FINISH);
  3281. snd_soc_component_write(component, AK7604_A3_RESETCONTROL, nDSPRun);
  3282. }
  3283. mdelay(1);
  3284. return ret;
  3285. }
  3286. #ifdef AK7604_IO_CONTROL
  3287. static unsigned long ak7604_readMIR(
  3288. struct snd_soc_component *component,
  3289. int nMIRNo,
  3290. unsigned long *dwMIRData)
  3291. {
  3292. unsigned char tx[3];
  3293. unsigned char rx[32];
  3294. int n, nRLen;
  3295. if (nMIRNo >= 8)
  3296. return(-1);
  3297. tx[0] = (unsigned char)COMMAND_MIR_READ;
  3298. tx[1] = 0;
  3299. tx[2] = 0;
  3300. nRLen = 4 * (nMIRNo + 1);
  3301. ak7604_reads(component, tx, 3, rx, nRLen);
  3302. n = 4 * nMIRNo;
  3303. *dwMIRData = ((0xFF & (unsigned long)rx[n++]) << 20);
  3304. *dwMIRData += ((0xFF & (unsigned long)rx[n++]) << 12);
  3305. *dwMIRData += ((0xFF & (unsigned long)rx[n++]) << 4);
  3306. *dwMIRData += ((0xFF & (unsigned long)rx[n++]) >> 4);
  3307. return 0;
  3308. }
  3309. static int ak7604_reg_cmd(struct snd_soc_component *component, REG_CMD *reg_param, int len)
  3310. {
  3311. int i;
  3312. int rc;
  3313. int addr, value;
  3314. akdbgprt("*****[AK7604] %s len = %d\n", __func__, len);
  3315. rc = 0;
  3316. for (i = 0; i < len; i++) {
  3317. addr = (int)(reg_param[i].addr);
  3318. value = (int)(reg_param[i].data);
  3319. if (addr != 0xFF) {
  3320. rc = snd_soc_component_write(component, addr, value);
  3321. if (rc < 0)
  3322. break;
  3323. } else {
  3324. mdelay(value);
  3325. }
  3326. }
  3327. if (rc != 0)
  3328. rc = 0;
  3329. return rc;
  3330. }
  3331. static long ak7604_ioctl(struct file *file, unsigned int cmd, unsigned long args)
  3332. {
  3333. struct ak7604_priv *ak7604 = (struct ak7604_priv *)file->private_data;
  3334. struct ak7604_wreg_handle ak7604_wreg;
  3335. struct ak7604_wcram_handle ak7604_wcram;
  3336. void __user *data = (void __user *)args;
  3337. int *val = (int *)args;
  3338. int i;
  3339. unsigned long dwMIRData;
  3340. int ret = 0;
  3341. REG_CMD regcmd[MAX_WREG];
  3342. unsigned char cram_data[MAX_WCRAM];
  3343. akdbgprt("*****[AK7604] %s cmd, val=%x, %x\n", __func__, cmd, val[0]);
  3344. switch (cmd) {
  3345. case AK7604_IOCTL_WRITECRAM:
  3346. if (copy_from_user(&ak7604_wcram, data, sizeof(struct ak7604_wcram_handle)))
  3347. return -EFAULT;
  3348. if ((ak7604_wcram.len % 3) != 0) {
  3349. akdbgprt(KERN_ERR "[AK7604] %s CRAM len error\n", __func__);
  3350. return -EFAULT;
  3351. }
  3352. if ((ak7604_wcram.len < 3) || (ak7604_wcram.len > MAX_WCRAM)) {
  3353. akdbgprt(KERN_ERR "[AK7604] %s CRAM len error2\n", __func__);
  3354. return -EFAULT;
  3355. }
  3356. for (i = 0; i < ak7604_wcram.len; i++)
  3357. cram_data[i] = ak7604_wcram.cram[i];
  3358. ret = ak7604_write_cram(ak7604->component, ak7604_wcram.addr,
  3359. ak7604_wcram.len, cram_data);
  3360. break;
  3361. case AK7604_IOCTL_WRITEREG:
  3362. if (copy_from_user(&ak7604_wreg, data, sizeof(struct ak7604_wreg_handle)))
  3363. return -EFAULT;
  3364. if ((ak7604_wreg.len < 1) || (ak7604_wreg.len > MAX_WREG)) {
  3365. akdbgprt(KERN_ERR "MAXREG ERROR %d\n", ak7604_wreg.len);
  3366. return -EFAULT;
  3367. }
  3368. for (i = 0; i < ak7604_wreg.len; i++) {
  3369. regcmd[i].addr = ak7604_wreg.regcmd[i].addr;
  3370. regcmd[i].data = ak7604_wreg.regcmd[i].data;
  3371. }
  3372. ak7604_reg_cmd(ak7604->component, regcmd, ak7604_wreg.len);
  3373. break;
  3374. case AK7604_IOCTL_SETSTATUS:
  3375. ret = ak7604_set_status(ak7604->component, val[0]);
  3376. if (ret < 0) {
  3377. akdbgprt(KERN_ERR "ak7604: set_status error:\n");
  3378. return ret;
  3379. }
  3380. break;
  3381. case AK7604_IOCTL_SETMIR:
  3382. ak7604->MIRNo = val[0];
  3383. if (ret < 0) {
  3384. akdbgprt(KERN_ERR "ak7604: set MIR error\n");
  3385. return -EFAULT;
  3386. }
  3387. break;
  3388. case AK7604_IOCTL_GETMIR:
  3389. ak7604_readMIR(ak7604->component, (0xF & (ak7604->MIRNo)), &dwMIRData);
  3390. ret = copy_to_user(data, (const void *)&dwMIRData, (unsigned long)4);
  3391. if (ret < 0) {
  3392. akdbgprt(KERN_ERR "ak7604: get status error\n");
  3393. return -EFAULT;
  3394. }
  3395. break;
  3396. default:
  3397. akdbgprt(KERN_ERR "Unknown command required: %d\n", cmd);
  3398. return -EINVAL;
  3399. }
  3400. return ret;
  3401. }
  3402. static int init_ak7604_pd(struct ak7604_priv *data)
  3403. {
  3404. struct _ak7604_pd_handler *ak7604 = &ak7604_pd_handler;
  3405. if (data == NULL)
  3406. return -EFAULT;
  3407. mutex_init(&ak7604->lock);
  3408. mutex_lock(&ak7604->lock);
  3409. ak7604->data = data;
  3410. mutex_unlock(&ak7604->lock);
  3411. return 0;
  3412. }
  3413. static struct ak7604_priv *get_ak7604_pd(void)
  3414. {
  3415. struct _ak7604_pd_handler *ak7604 = &ak7604_pd_handler;
  3416. if (ak7604->data == NULL)
  3417. return NULL;
  3418. mutex_lock(&ak7604->lock);
  3419. ak7604->ref_count++;
  3420. mutex_unlock(&ak7604->lock);
  3421. return ak7604->data;
  3422. }
  3423. static int rel_ak7604_pd(struct ak7604_priv *data)
  3424. {
  3425. struct _ak7604_pd_handler *ak7604 = &ak7604_pd_handler;
  3426. if (ak7604->data == NULL)
  3427. return -EFAULT;
  3428. mutex_lock(&ak7604->lock);
  3429. ak7604->ref_count--;
  3430. mutex_unlock(&ak7604->lock);
  3431. data = NULL;
  3432. return 0;
  3433. }
  3434. /* AK7604 Misc driver interfaces */
  3435. static int ak7604_open(struct inode *inode, struct file *file)
  3436. {
  3437. struct ak7604_priv *ak7604;
  3438. ak7604 = get_ak7604_pd();
  3439. file->private_data = ak7604;
  3440. return 0;
  3441. }
  3442. static int ak7604_close(struct inode *inode, struct file *file)
  3443. {
  3444. struct ak7604_priv *ak7604 = (struct ak7604_priv *)file->private_data;
  3445. rel_ak7604_pd(ak7604);
  3446. return 0;
  3447. }
  3448. static const struct file_operations ak7604_fops = {
  3449. .owner = THIS_MODULE,
  3450. .open = ak7604_open,
  3451. .release = ak7604_close,
  3452. .unlocked_ioctl = ak7604_ioctl,
  3453. };
  3454. static struct miscdevice ak7604_misc = {
  3455. .minor = MISC_DYNAMIC_MINOR,
  3456. .name = "ak7604-dsp",
  3457. .fops = &ak7604_fops,
  3458. };
  3459. #endif
  3460. static int ak7604_set_bias_level(struct snd_soc_component *component,
  3461. enum snd_soc_bias_level level)
  3462. {
  3463. #ifndef KERNEL_3_18_XX
  3464. struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
  3465. #endif
  3466. akdbgprt("\t[AK7604] %s(%d),level = %d\n", __func__, __LINE__, level);
  3467. switch (level) {
  3468. case SND_SOC_BIAS_ON:
  3469. case SND_SOC_BIAS_PREPARE:
  3470. case SND_SOC_BIAS_STANDBY:
  3471. break;
  3472. case SND_SOC_BIAS_OFF:
  3473. //ak7604_set_status(component, POWERDOWN);
  3474. break;
  3475. }
  3476. #ifdef KERNEL_3_18_XX
  3477. //component->dapm.bias_level = level;
  3478. #else
  3479. dapm->bias_level = level;
  3480. #endif
  3481. return 0;
  3482. }
  3483. //static int ak7604_set_dai_mute(struct snd_soc_dai *dai, int mute)
  3484. //{
  3485. // akdbgprt("\t[AK7604] %s Mute=[%s], play=%d cap=%d\n",
  3486. // __func__, mute ? "ON" : "OFF", dai->playback_active, dai->capture_active);
  3487. // return 0;
  3488. //}
  3489. #define AK7604_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
  3490. SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\
  3491. SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |\
  3492. SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 |\
  3493. SNDRV_PCM_RATE_96000)
  3494. #define AK7604_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE |\
  3495. SNDRV_PCM_FMTBIT_S32_LE)
  3496. static struct snd_soc_dai_ops ak7604_dai_ops = {
  3497. .hw_params = ak7604_hw_params,
  3498. .set_sysclk = ak7604_set_dai_sysclk,
  3499. .set_fmt = ak7604_set_dai_fmt,
  3500. // .digital_mute = ak7604_set_dai_mute,
  3501. };
  3502. #if 1
  3503. struct snd_soc_dai_driver ak7604_dai[] = {
  3504. #ifndef ARK_CARPLAY_MODE
  3505. //plan:1
  3506. //ark(i2s1)->ak7604(i2s2)
  3507. //fm1505->ak7604(i2s1)
  3508. {
  3509. .name = "ak7604-aif1",
  3510. .id = AIF_PORT2,
  3511. .playback = {
  3512. .stream_name = "AIF1 Playback",
  3513. .channels_min = 1,
  3514. .channels_max = 2,
  3515. .rates = AK7604_RATES,
  3516. .formats = AK7604_FORMATS,
  3517. },
  3518. .capture = {
  3519. .stream_name = "AIF1 Capture",
  3520. .channels_min = 1,
  3521. .channels_max = 2,
  3522. .rates = AK7604_RATES,
  3523. .formats = AK7604_FORMATS,
  3524. },
  3525. .ops = &ak7604_dai_ops,
  3526. },
  3527. {
  3528. .name = "ak7604-aif2",
  3529. .id = AIF_PORT1,//AIF_PORT1,
  3530. // .playback = {
  3531. // .stream_name = "AIF1 Playback",
  3532. // .channels_min = 1,
  3533. // .channels_max = 2,
  3534. // .rates = AK7604_RATES,
  3535. // .formats = AK7604_FORMATS,
  3536. // },
  3537. .capture = {
  3538. .stream_name = "AIF1 Capture",
  3539. .channels_min = 1,
  3540. .channels_max = 2,
  3541. .rates = AK7604_RATES,
  3542. .formats = AK7604_FORMATS,
  3543. },
  3544. .ops = &ak7604_dai_ops,
  3545. },
  3546. {
  3547. .name = "ak7604-aif3",
  3548. .id = AIF_PORT1,//AIF_PORT1,
  3549. .playback = {
  3550. .stream_name = "AIF1 Playback",
  3551. .channels_min = 1,
  3552. .channels_max = 2,
  3553. .rates = AK7604_RATES,
  3554. .formats = AK7604_FORMATS,
  3555. },
  3556. // .capture = {
  3557. // .stream_name = "AIF1 Capture",
  3558. // .channels_min = 1,
  3559. // .channels_max = 2,
  3560. // .rates = AK7604_RATES,
  3561. // .formats = AK7604_FORMATS,
  3562. // },
  3563. .ops = &ak7604_dai_ops,
  3564. },
  3565. #else
  3566. //plan:2
  3567. //ark(i2s1)->ak7604(i2s1)
  3568. //fm1505->ak7604(i2s2)
  3569. {
  3570. .name = "ak7604-aif1",
  3571. .id = AIF_PORT1,
  3572. .playback = {
  3573. .stream_name = "AIF1 Playback",
  3574. .channels_min = 1,
  3575. .channels_max = 2,
  3576. .rates = AK7604_RATES,
  3577. .formats = AK7604_FORMATS,
  3578. },
  3579. .capture = {
  3580. .stream_name = "AIF1 Capture",
  3581. .channels_min = 1,
  3582. .channels_max = 2,
  3583. .rates = AK7604_RATES,
  3584. .formats = AK7604_FORMATS,
  3585. },
  3586. .ops = &ak7604_dai_ops,
  3587. },
  3588. {
  3589. .name = "ak7604-aif2",
  3590. .id = AIF_PORT2,
  3591. // .playback = {
  3592. // .stream_name = "AIF1 Playback",
  3593. // .channels_min = 1,
  3594. // .channels_max = 2,
  3595. // .rates = AK7604_RATES,
  3596. // .formats = AK7604_FORMATS,
  3597. // },
  3598. .capture = {
  3599. .stream_name = "AIF2 Capture",
  3600. .channels_min = 1,
  3601. .channels_max = 2,
  3602. .rates = AK7604_RATES,
  3603. .formats = AK7604_FORMATS,
  3604. },
  3605. .ops = &ak7604_dai_ops,
  3606. },
  3607. {
  3608. .name = "ak7604-aif3",
  3609. .id = AIF_PORT2,
  3610. .playback = {
  3611. .stream_name = "AIF3 Playback",
  3612. .channels_min = 1,
  3613. .channels_max = 2,
  3614. .rates = AK7604_RATES,
  3615. .formats = AK7604_FORMATS,
  3616. },
  3617. // .capture = {
  3618. // .stream_name = "AIF1 Capture",
  3619. // .channels_min = 1,
  3620. // .channels_max = 2,
  3621. // .rates = AK7604_RATES,
  3622. // .formats = AK7604_FORMATS,
  3623. // },
  3624. .ops = &ak7604_dai_ops,
  3625. },
  3626. #endif
  3627. };
  3628. #else
  3629. struct snd_soc_dai_driver ak7604_dai[] = {
  3630. {
  3631. .name = "ak7604-aif1",
  3632. .id = AIF_PORT1,
  3633. .playback = {
  3634. .stream_name = "AIF1 Playback",
  3635. .channels_min = 1,
  3636. .channels_max = 2,
  3637. .rates = AK7604_RATES,
  3638. .formats = AK7604_FORMATS,
  3639. },
  3640. .capture = {
  3641. .stream_name = "AIF1 Capture",
  3642. .channels_min = 1,
  3643. .channels_max = 2,
  3644. .rates = AK7604_RATES,
  3645. .formats = AK7604_FORMATS,
  3646. },
  3647. .ops = &ak7604_dai_ops,
  3648. },
  3649. {
  3650. .name = "ak7604-aif2",
  3651. .id = AIF_PORT2,
  3652. .playback = {
  3653. .stream_name = "AIF2 Playback",
  3654. .channels_min = 1,
  3655. .channels_max = 2,
  3656. .rates = AK7604_RATES,
  3657. .formats = AK7604_FORMATS,
  3658. },
  3659. .capture = {
  3660. .stream_name = "AIF2 Capture",
  3661. .channels_min = 1,
  3662. .channels_max = 2,
  3663. .rates = AK7604_RATES,
  3664. .formats = AK7604_FORMATS,
  3665. },
  3666. .ops = &ak7604_dai_ops,
  3667. },
  3668. {
  3669. .name = "ak7604-aif3",
  3670. .id = AIF_PORT3,
  3671. .playback = {
  3672. .stream_name = "AIF3 Playback",
  3673. .channels_min = 1,
  3674. .channels_max = 2,
  3675. .rates = AK7604_RATES,
  3676. .formats = AK7604_FORMATS,
  3677. },
  3678. .capture = {
  3679. .stream_name = "AIF3 Capture",
  3680. .channels_min = 1,
  3681. .channels_max = 2,
  3682. .rates = AK7604_RATES,
  3683. .formats = AK7604_FORMATS,
  3684. },
  3685. .ops = &ak7604_dai_ops,
  3686. },
  3687. };
  3688. #endif
  3689. static int ak7604_init_reg(struct snd_soc_component *component)
  3690. {
  3691. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  3692. int i, devid;
  3693. if (ak7604->pdn_gpio > 0) {
  3694. gpio_set_value(ak7604->pdn_gpio, 0);
  3695. mdelay(1);
  3696. gpio_set_value(ak7604->pdn_gpio, 1);
  3697. mdelay(1);
  3698. }
  3699. if (ak7604->control_type == SND_SOC_SPI)
  3700. ak7604_write_spidmy(component);
  3701. devid = snd_soc_component_read(component, AK7604_C0_DEVICE_ID);
  3702. akdbgprt("[AK7604] %s Device ID = 0x%X\n", __func__, devid);
  3703. if (devid != 0x04) {
  3704. akdbgprt("********* This is not AK7604! *********\n");
  3705. akdbgprt("********* This is not AK7604! *********\n");
  3706. akdbgprt("********* This is not AK7604! *********\n");
  3707. }
  3708. ak7604->fs = 48000;
  3709. ak7604->PLLInput = 0;
  3710. ak7604->XtiFs = 0;
  3711. ak7604->dresetn = 0;
  3712. setPLLOut(component);
  3713. for (i = 0; i < (NUM_SYNCDOMAIN - 1); i++)
  3714. ak7604->Master[i] = 0;
  3715. ak7604->Master[3] = 1;//SYNC4 fixed master.
  3716. for (i = 0; i < NUM_SYNCDOMAIN; i++) {
  3717. ak7604->SDBick[i] = 0; //64fs
  3718. ak7604->SDfs[i] = 5; // 48kHz
  3719. ak7604->SDCks[i] = 0; // Low
  3720. setSDClock(component, i);
  3721. }
  3722. for (i = 0; i < NUM_SYNCDOMAIN; i++) {
  3723. ak7604->TDMSDINbit[i] = 0;
  3724. ak7604->TDMSDOUTbit[i] = 0;
  3725. ak7604->DIEDGEbit[i] = 0;
  3726. ak7604->DOEDGEbit[i] = 0;
  3727. ak7604->DISLbit[i] = 0;
  3728. ak7604->DOSLbit[i] = 0;
  3729. }
  3730. // DSP BANK Setting for Audio Effect
  3731. // snd_soc_component_write(component, AK7604_60_DSP_SETTING1, 0x02); // DRMBK -> 2048/4096, DRMA -> Ring/Ring
  3732. // snd_soc_component_write(component, AK7604_0F_SYNCDOMAIN_SEL1, 0x12);//SyncN -> LR/BICKN(if Master)
  3733. // snd_soc_component_write(component, AK7604_10_SYNCDOMAIN_SEL2, 0x30);//SyncN -> LR/BICKN(if Master)
  3734. // snd_soc_component_write(component, AK7604_0D_SDIN1_2_SYNC, 0x12); //SDIN1(LR/BICK1), SDIN2(LR/BICK2)
  3735. // snd_soc_component_write(component, AK7604_0E_SDIN3_4_SYNC, 0x31); //SDIN3(LR/BICK3), SDIN4(LR/BICK1)
  3736. // snd_soc_component_write(component, AK7604_81_MIC_SETTING, 0x3); // MIC Gain Zero Cross Enable
  3737. return 0;
  3738. }
  3739. static int ark_ak7604_init(struct snd_soc_component *component)
  3740. {
  3741. //struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  3742. //unsigned int val;
  3743. int i, ret;
  3744. int tabnum;
  3745. akdbgprt("[AK7604] %s ----->start<-----\n", __func__);
  3746. #if 0
  3747. for (i = 0; i < ARRAY_SIZE(ak7604_reg); i++) {
  3748. if (ak7604_writeable(NULL, ak7604_reg[i].reg)) {
  3749. ret = regmap_read(ak7604->regmap,
  3750. ak7604_reg[i].reg, &val);
  3751. if (ret >= 0)
  3752. snd_soc_component_write(component, ak7604_reg[i].reg, val);
  3753. }
  3754. }
  3755. // akdbgprt("[AK7604] %s ----->read<-----\n", __func__);
  3756. // for (i = 0; i < ARRAY_SIZE(ak7604_reg); i++) {
  3757. // if (ak7604_writeable(NULL, ak7604_reg[i].reg)) {akdbgprt("[AK7604] %s ----->read start<-----\n", __func__);
  3758. // ret = regmap_read(ak7604->regmap,
  3759. // ak7604_reg[i].reg, &val);
  3760. // if (ret >= 0)
  3761. // printk("%s(),ak7604 read error val=0x%x def=0x%x reg=0x%x\n", __FUNCTION__, val, ak7604_reg[i].def, ak7604_reg[i].reg);
  3762. // }
  3763. // }
  3764. #else
  3765. tabnum = ARRAY_SIZE(ak7604_reg);
  3766. for (i = 0 ; i < tabnum ; ++i) {
  3767. if (ak7604_reg[i].reg != AK7604_C0_DEVICE_ID)
  3768. {
  3769. if (ak7604_writeable(NULL, ak7604_reg[i].reg)) {
  3770. ret = ak7604_write_register(component, ak7604_reg[i].reg, ak7604_reg[i].def);
  3771. }
  3772. }
  3773. if (ret < 0)
  3774. printk("%s(),ak7604 write error reg=0x%x reg=%d\n", __func__, ak7604_reg[i].reg, ret);
  3775. }
  3776. // for(i=0 ; i<tabnum ; ++i){
  3777. // if(ak7604_reg[i].reg != AK7604_C0_DEVICE_ID)
  3778. // {
  3779. // if (ak7604_volatile(NULL, ak7604_reg[i].reg) && ak7604_readable(NULL, ak7604_reg[i].reg)) {
  3780. // val = ak7604_read_register(component, ak7604_reg[i].reg);
  3781. // if(val != ak7604_reg[i].def)
  3782. // printk("%s(),ak7604 read error val=0x%x def=0x%x reg=0x%x\n", __FUNCTION__, val, ak7604_reg[i].def, ak7604_reg[i].reg);
  3783. // else
  3784. // printk("ak7604 read reg=0x%x, def=0x%x\n", ak7604_reg[i].reg, ak7604_reg[i].def);
  3785. // }
  3786. // }
  3787. // }
  3788. #endif
  3789. //akdbgprt("[AK7604] %s ----->end<-----\n", __func__);
  3790. return 0;
  3791. }
  3792. static int ak7604_parse_dt(struct ak7604_priv *ak7604)
  3793. {
  3794. struct device *dev;
  3795. struct device_node *np;
  3796. if (ak7604->control_type == SND_SOC_SPI)
  3797. dev = &(ak7604->spi->dev);
  3798. else
  3799. dev = &(ak7604->i2c->dev);
  3800. np = dev->of_node;
  3801. if (!np) {
  3802. akdbgprt("\t[AK7604] %s np error!\n", __func__);
  3803. return 0;
  3804. }
  3805. ak7604->pdn_gpio = of_get_named_gpio(np, "ak7604,pdn-gpio", 0);
  3806. akdbgprt("\t[AK7604] %s pdn-gpio=%d\n", __func__, ak7604->pdn_gpio);
  3807. if (ak7604->pdn_gpio < 0) {
  3808. ak7604->pdn_gpio = -1;
  3809. return 0;
  3810. }
  3811. if (!gpio_is_valid(ak7604->pdn_gpio)) {
  3812. akdbgprt(KERN_ERR "ak7604 pdn pin(%u) is invalid\n", ak7604->pdn_gpio);
  3813. return 0;
  3814. }
  3815. return 0;
  3816. }
  3817. static int ak7604_probe(struct snd_soc_component *component)
  3818. {
  3819. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  3820. int ret = 0;
  3821. akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  3822. ak7604->component = component;
  3823. ret = ak7604_parse_dt(ak7604);
  3824. if (ret < 0) {
  3825. ak7604->pdn_gpio = -1;
  3826. ret = 0;
  3827. }
  3828. if (ak7604->pdn_gpio != -1) {
  3829. ret = gpio_request(ak7604->pdn_gpio, "ak7604 pdn");
  3830. akdbgprt("\t[AK7604] %s : gpio_request ret = %d\n", __func__, ret);
  3831. gpio_direction_output(ak7604->pdn_gpio, 0);
  3832. }
  3833. ak7604_init_reg(component);
  3834. ret = ark_ak7604_init(component);
  3835. ak7604->MIRNo = 0;
  3836. ak7604->status = POWERDOWN;
  3837. ak7604->DSPPramMode = 0;
  3838. ak7604->DSPCramMode = 0;
  3839. ak7604->cramaddr = 0;
  3840. ak7604->cramcount = 0;
  3841. #ifdef AK7604_IO_CONTROL
  3842. init_ak7604_pd(ak7604);
  3843. #endif
  3844. return 0;
  3845. }
  3846. static void ak7604_remove(struct snd_soc_component *component)
  3847. {akdbgprt("\t[ak7604] %s start\n", __func__);
  3848. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  3849. akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  3850. ak7604_set_bias_level(component, SND_SOC_BIAS_OFF);
  3851. if (ak7604->pdn_gpio != -1) {
  3852. gpio_set_value(ak7604->pdn_gpio, 0);
  3853. mdelay(1);
  3854. gpio_free(ak7604->pdn_gpio);
  3855. mdelay(1);
  3856. }
  3857. }
  3858. static int ak7604_suspend(struct snd_soc_component *component)
  3859. {akdbgprt("\t[ak7604] %s start\n", __func__);
  3860. struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  3861. ak7604_set_bias_level(component, SND_SOC_BIAS_OFF);
  3862. regcache_cache_only(ak7604->regmap, true);
  3863. regcache_mark_dirty(ak7604->regmap);
  3864. if (ak7604->pdn_gpio > 0) {
  3865. gpio_set_value(ak7604->pdn_gpio, 0);
  3866. mdelay(1);
  3867. }
  3868. return 0;
  3869. }
  3870. static int ak7604_resume(struct snd_soc_component *component)
  3871. {
  3872. // struct ak7604_priv *ak7604 = snd_soc_component_get_drvdata(component);
  3873. // unsigned int val;
  3874. // int i, ret;
  3875. akdbgprt("\t[ak7604] %s start\n", __func__);
  3876. // // Register value reset
  3877. // if (ak7604->pdn_gpio != -1) {
  3878. // gpio_set_value(ak7604->pdn_gpio, GPO_PDN_LOW);
  3879. // akdbgprt("\t[ak7604] %s External PDN[OFF]\n", __func__);
  3880. // mdelay(1);
  3881. // gpio_set_value(ak7604->pdn_gpio, GPO_PDN_HIGH);
  3882. // akdbgprt("\t[ak7604] %s External PDN[ON]\n", __func__);
  3883. // mdelay(1);
  3884. // }
  3885. // // State before suspend
  3886. // for (i = 0; i < ARRAY_SIZE(ak7604_reg); i++) {
  3887. // if (ak7604_writeable(NULL, ak7604_reg[i].reg)) {
  3888. // ret = regmap_read(ak7604->regmap,
  3889. // ak7604_reg[i].reg, &val);
  3890. // if (ret >= 0)
  3891. // //snd_soc_write(codec, ak7604_reg[i].reg, val);
  3892. // snd_soc_component_write(component, ak7604_reg[i].reg, val);
  3893. // }
  3894. // }
  3895. //ak7604_init_reg(component);
  3896. //ark_ak7604_init(component);
  3897. return 0;
  3898. }
  3899. struct snd_soc_component_driver soc_component_dev_ak7604 = {
  3900. .probe = ak7604_probe,
  3901. .remove = ak7604_remove,
  3902. .suspend = ak7604_suspend,
  3903. .resume = ak7604_resume,
  3904. .read = ak7604_read_register,
  3905. .write = ak7604_write_register,
  3906. .idle_bias_on = false,
  3907. .set_bias_level = ak7604_set_bias_level,
  3908. .controls = ak7604_snd_controls,
  3909. .num_controls = ARRAY_SIZE(ak7604_snd_controls),
  3910. .dapm_widgets = ak7604_dapm_widgets,
  3911. .num_dapm_widgets = ARRAY_SIZE(ak7604_dapm_widgets),
  3912. .dapm_routes = ak7604_intercon,
  3913. .num_dapm_routes = ARRAY_SIZE(ak7604_intercon),
  3914. };
  3915. EXPORT_SYMBOL_GPL(soc_component_dev_ak7604);
  3916. static const struct regmap_config ak7604_regmap = {
  3917. .reg_bits = 16,
  3918. .val_bits = 8,
  3919. .max_register = AK7604_MAX_REGISTER,
  3920. .volatile_reg = ak7604_volatile,
  3921. .writeable_reg = ak7604_writeable,
  3922. .readable_reg = ak7604_readable,
  3923. .reg_defaults = ak7604_reg,
  3924. .num_reg_defaults = ARRAY_SIZE(ak7604_reg),
  3925. .cache_type = REGCACHE_RBTREE,
  3926. };
  3927. static const struct of_device_id ak7604_dt_ids[] = {
  3928. { .compatible = "akm,ak7604"},
  3929. { }
  3930. };
  3931. MODULE_DEVICE_TABLE(of, ak7604_dt_ids);
  3932. #ifdef AK7604_I2C_IF
  3933. //static int ak7604_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
  3934. static int ak7604_i2c_probe(struct i2c_client *i2c)
  3935. {
  3936. struct ak7604_priv *ak7604;
  3937. int ret = 0;
  3938. akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  3939. ak7604 = devm_kzalloc(&i2c->dev, sizeof(struct ak7604_priv), GFP_KERNEL);
  3940. if (ak7604 == NULL)
  3941. return -ENOMEM;
  3942. ak7604->regmap = devm_regmap_init_i2c(i2c, &ak7604_regmap);
  3943. if (IS_ERR(ak7604->regmap)) {
  3944. devm_kfree(&i2c->dev, ak7604);
  3945. return PTR_ERR(ak7604->regmap);
  3946. }
  3947. regcache_cache_only(ak7604->regmap, true);
  3948. i2c_set_clientdata(i2c, ak7604);
  3949. ak7604->control_type = SND_SOC_I2C;
  3950. ak7604->i2c = i2c;
  3951. //ret = snd_soc_register_codec(&i2c->dev,
  3952. // &soc_codec_dev_ak7604, &ak7604_dai[0], ARRAY_SIZE(ak7604_dai));
  3953. ret = devm_snd_soc_register_component(&i2c->dev,
  3954. &soc_component_dev_ak7604, &ak7604_dai[0], ARRAY_SIZE(ak7604_dai));
  3955. if (ret < 0) {
  3956. devm_kfree(&i2c->dev, ak7604);
  3957. akdbgprt("\t[AK7604 Error!] %s(%d)\n", __func__, __LINE__);
  3958. }
  3959. return ret;
  3960. }
  3961. static void ak7604_i2c_remove(struct i2c_client *client)
  3962. {
  3963. //snd_soc_unregister_codec(&client->dev);
  3964. snd_soc_unregister_component(&client->dev);
  3965. return;
  3966. }
  3967. static const struct i2c_device_id ak7604_i2c_id[] = {
  3968. { "ak7604", 0 },
  3969. { }
  3970. };
  3971. MODULE_DEVICE_TABLE(i2c, ak7604_i2c_id);
  3972. static struct i2c_driver ak7604_i2c_driver = {
  3973. .driver = {
  3974. .name = "ak7604",
  3975. #if (defined KERNEL_3_18_XX || defined KERNEL_4_4_XX)
  3976. .owner = THIS_MODULE,
  3977. #endif
  3978. .of_match_table = of_match_ptr(ak7604_dt_ids),
  3979. },
  3980. .probe = ak7604_i2c_probe,
  3981. .remove = ak7604_i2c_remove,
  3982. .id_table = ak7604_i2c_id,
  3983. };
  3984. #else
  3985. static int ak7604_spi_probe(struct spi_device *spi)
  3986. {
  3987. struct ak7604_priv *ak7604;
  3988. int ret;
  3989. akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  3990. ak7604 = devm_kzalloc(&spi->dev, sizeof(struct ak7604_priv),
  3991. GFP_KERNEL);
  3992. if (ak7604 == NULL)
  3993. return -ENOMEM;
  3994. ak7604->regmap = devm_regmap_init_spi(spi, &ak7604_regmap);
  3995. if (IS_ERR(ak7604->regmap)) {
  3996. ret = PTR_ERR(ak7604->regmap);
  3997. dev_err(&spi->dev, "Failed to allocate register map: %d\n",
  3998. ret);
  3999. return ret;
  4000. }
  4001. regcache_cache_only(ak7604->regmap, true);
  4002. spi_set_drvdata(spi, ak7604);
  4003. ak7604->control_type = SND_SOC_SPI;
  4004. ak7604->spi = spi;
  4005. ret = devm_snd_soc_register_component(&spi->dev,
  4006. &soc_component_dev_ak7604, &ak7604_dai[0], ARRAY_SIZE(ak7604_dai));
  4007. if (ret != 0) {
  4008. dev_err(&spi->dev, "Failed to register CODEC: %d\n", ret);
  4009. return ret;
  4010. }
  4011. return 0;
  4012. }
  4013. static int ak7604_spi_remove(struct spi_device *spi)
  4014. {
  4015. snd_soc_unregister_component(&spi->dev);
  4016. return 0;
  4017. }
  4018. static struct spi_driver ak7604_spi_driver = {
  4019. .driver = {
  4020. .name = "ak7604",
  4021. .owner = THIS_MODULE,
  4022. .of_match_table = of_match_ptr(ak7604_dt_ids),
  4023. },
  4024. .probe = ak7604_spi_probe,
  4025. .remove = ak7604_spi_remove,
  4026. };
  4027. #endif
  4028. static int __init ak7604_modinit(void)
  4029. {
  4030. int ret = 0;
  4031. akdbgprt("\t[AK7604] %s(%d)\n", __func__, __LINE__);
  4032. #ifdef AK7604_I2C_IF
  4033. ret = i2c_add_driver(&ak7604_i2c_driver);
  4034. if (ret != 0)
  4035. akdbgprt(KERN_ERR "Failed to register AK7604 I2C driver: %d\n", ret);
  4036. #else
  4037. ret = spi_register_driver(&ak7604_spi_driver);
  4038. if (ret != 0)
  4039. akdbgprt(KERN_ERR "Failed to register AK7604 SPI driver: %d\n", ret);
  4040. #endif
  4041. #ifdef AK7604_IO_CONTROL
  4042. ret = misc_register(&ak7604_misc);
  4043. if (ret < 0)
  4044. akdbgprt(KERN_ERR "Failed to register AK7604 MISC driver: %d\n", ret);
  4045. #endif
  4046. return ret;
  4047. }
  4048. module_init(ak7604_modinit);
  4049. static void __exit ak7604_exit(void)
  4050. {
  4051. #ifdef AK7604_I2C_IF
  4052. i2c_del_driver(&ak7604_i2c_driver);
  4053. #else
  4054. spi_unregister_driver(&ak7604_spi_driver);
  4055. #endif
  4056. #ifdef AK7604_IO_CONTROL
  4057. misc_deregister(&ak7604_misc);
  4058. #endif
  4059. }
  4060. module_exit(ak7604_exit);
  4061. MODULE_DESCRIPTION("ak7604 codec driver");
  4062. MODULE_LICENSE("GPL v2");