500-alsa.patch 253 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366
  1. --- a/sound/soc/Kconfig
  2. +++ b/sound/soc/Kconfig
  3. @@ -56,6 +56,7 @@ source "sound/soc/spear/Kconfig"
  4. source "sound/soc/tegra/Kconfig"
  5. source "sound/soc/txx9/Kconfig"
  6. source "sound/soc/ux500/Kconfig"
  7. +source "sound/soc/mtk/Kconfig"
  8. # Supported codecs
  9. source "sound/soc/codecs/Kconfig"
  10. --- a/sound/soc/Makefile
  11. +++ b/sound/soc/Makefile
  12. @@ -33,3 +33,4 @@ obj-$(CONFIG_SND_SOC) += spear/
  13. obj-$(CONFIG_SND_SOC) += tegra/
  14. obj-$(CONFIG_SND_SOC) += txx9/
  15. obj-$(CONFIG_SND_SOC) += ux500/
  16. +obj-$(CONFIG_SND_SOC) += mtk/
  17. --- a/sound/soc/codecs/Kconfig
  18. +++ b/sound/soc/codecs/Kconfig
  19. @@ -725,7 +725,7 @@ config SND_SOC_WM8955
  20. tristate
  21. config SND_SOC_WM8960
  22. - tristate
  23. + tristate "WM8960"
  24. config SND_SOC_WM8961
  25. tristate
  26. --- /dev/null
  27. +++ b/sound/soc/mtk/Kconfig
  28. @@ -0,0 +1,35 @@
  29. +config SND_MT76XX_SOC
  30. + tristate "SoC Audio for MT76XX APSoC Machine"
  31. + depends on SND_SOC && (SOC_MT7620 || SOC_MT7621)
  32. +
  33. + help
  34. + Say Y or M if you want to add support for codecs attached to
  35. + the MTK I2S interface.
  36. +
  37. +choice
  38. + prompt "Selected SoC type"
  39. + depends on SND_MT76XX_SOC
  40. + default SND_MT76XX_SOC_MT7620
  41. +
  42. +config SND_MT76XX_SOC_MT7620
  43. + bool "MT7620"
  44. + depends on SOC_MT7620
  45. +
  46. +config SND_MT76XX_SOC_MT7628
  47. + bool "MT7628"
  48. + depends on SOC_MT7620
  49. +
  50. +config SND_MT76XX_SOC_MT7621
  51. + bool "MT7621"
  52. + depends on SOC_MT7621
  53. +
  54. +endchoice
  55. +
  56. +config SND_MT76XX_PCM
  57. + tristate "MTK SoC Audio PCM Platform"
  58. + depends on SND_MT76XX_SOC
  59. +
  60. +config SND_MT76XX_I2S
  61. + tristate "MTK SoC I2S Support"
  62. + depends on SND_MT76XX_SOC
  63. +
  64. --- /dev/null
  65. +++ b/sound/soc/mtk/Makefile
  66. @@ -0,0 +1,40 @@
  67. +KBUILD_CFLAGS += -I$(srctree)
  68. +
  69. +ifeq ($(CONFIG_SND_MT76XX_SOC_MT7620),y)
  70. +KBUILD_CFLAGS += -DCONFIG_MT7620 -DCONFIG_RALINK_MT7620
  71. +endif
  72. +ifeq ($(CONFIG_SND_MT76XX_SOC_MT7628),y)
  73. +KBUILD_CFLAGS += -DCONFIG_MT7628 -DCONFIG_RALINK_MT7628
  74. +endif
  75. +ifeq ($(CONFIG_SOC_MT7620),y)
  76. +KBUILD_CFLAGS += -DRALINK_SYSCTL_BASE=0xB0000000
  77. +KBUILD_CFLAGS += -DRALINK_INTCL_BASE=0xB0000200
  78. +KBUILD_CFLAGS += -DRALINK_PIO_BASE=0xB0000600
  79. +KBUILD_CFLAGS += -DRALINK_I2S_BASE=0xB0000A00
  80. +KBUILD_CFLAGS += -DRALINK_GDMA_BASE=0xB0002800
  81. +KBUILD_CFLAGS += -DCONFIG_GDMA_EVERYBODY
  82. +KBUILD_CFLAGS += -DCONFIG_SND_MT76XX_SOC
  83. +KBUILD_CFLAGS += -DCONFIG_I2S_WM8960
  84. +#KBUILD_CFLAGS += -DCONFIG_I2S_MCLK_12P288MHZ
  85. +KBUILD_CFLAGS += -DCONFIG_I2S_MCLK_12MHZ
  86. +KBUILD_CFLAGS += -DCONFIG_GDMA_EVERYBODY
  87. +KBUILD_CFLAGS += -DSURFBOARDINT_DMA=15
  88. +KBUILD_CFLAGS += -DRALINK_INTCTL_DMA=128
  89. +KBUILD_CFLAGS += -DCONFIG_SND_SOC_WM8960
  90. +endif
  91. +
  92. +# MTK APSoC Platform Support
  93. +snd-soc-mt76xx-i2s-ctl-objs := i2s_ctrl.o i2s_debug.o #i2c_wm8960.o
  94. +snd-soc-mt76xx-pcm-objs := mt76xx_pcm.o
  95. +snd-soc-mt76xx-i2s-objs := mt76xx_i2s.o
  96. +
  97. +obj-$(CONFIG_SND_MT76XX_PCM) += snd-soc-mt76xx-pcm.o
  98. +obj-$(CONFIG_SND_MT76XX_I2S) += snd-soc-mt76xx-i2s-ctl.o snd-soc-mt76xx-i2s.o
  99. +
  100. +# MTK APSoC Machine Support
  101. +snd-soc-mt76xx-machine-objs := mt76xx_machine.o
  102. +
  103. +obj-$(CONFIG_SND_MT76XX_SOC) += i2c_wm8960.o ralink_gdma.o snd-soc-mt76xx-machine.o
  104. +
  105. +
  106. +
  107. --- /dev/null
  108. +++ b/sound/soc/mtk/i2c_wm8960.c
  109. @@ -0,0 +1,492 @@
  110. +#include <linux/kernel.h>
  111. +#include <linux/version.h>
  112. +#include <linux/init.h>
  113. +#include <linux/module.h>
  114. +#include <linux/slab.h>
  115. +#include <linux/i2c.h>
  116. +#include <linux/delay.h>
  117. +#include <linux/interrupt.h>
  118. +#include <linux/fs.h>
  119. +#include <linux/fcntl.h>
  120. +#include <linux/cdev.h>
  121. +#if defined(CONFIG_ARCH_MT7623)
  122. +#include <mt_i2c.h>
  123. +#include <mach/mt_gpio.h>
  124. +#endif
  125. +#include "i2c_wm8960.h"
  126. +#include "i2s_ctrl.h"
  127. +
  128. +
  129. +#define BUF_SIZE 20
  130. +
  131. +#undef MSG
  132. +#define MSG printk
  133. +
  134. +
  135. +#if defined(CONFIG_ARCH_MT7623)
  136. +/*FIXME*/
  137. +//static struct i2c_board_info __initdata i2c_devs1 = { I2C_BOARD_INFO("codec_wm8960", (0X34>>1))};
  138. +static struct i2c_board_info __initdata i2c_devs1 = { I2C_BOARD_INFO("codec_wm8960", (0X34))};
  139. +
  140. +#endif
  141. +unsigned long wm_reg_data[56];
  142. +struct wm8960_data *wmio;
  143. +
  144. +struct wm8960_data {
  145. + struct i2c_client *client;
  146. + struct device *dev;
  147. + const char *name;
  148. +};
  149. +
  150. +
  151. +void i2c_WM8960_write(u32 reg, u32 data)
  152. +{
  153. + int ret;
  154. + struct i2c_msg msg;
  155. + u8 buf[2]={0};
  156. +
  157. +#if defined(CONFIG_ARCH_MT7623)
  158. + unsigned int ext_flag = 0;
  159. +
  160. + ext_flag &= 0x7FFFFFFF;
  161. + ext_flag |= I2C_A_FILTER_MSG;
  162. + ext_flag |= I2C_POLLING_FLAG;
  163. +#endif
  164. +
  165. + wm_reg_data[reg] = data;
  166. +
  167. + buf[0]= (reg<<1)|(0x01&(data>>8));
  168. + buf[1]= (data&0xFF);
  169. +
  170. +#if defined(CONFIG_ARCH_MT7623)
  171. + /*FIXME*/
  172. + //msg.addr = wmio->client->addr;
  173. + msg.addr = wmio->client->addr>>1;
  174. +
  175. +#else
  176. + msg.addr = wmio->client->addr>>1;
  177. +#endif
  178. + msg.flags = 0;
  179. + msg.buf = (char *)buf;
  180. + msg.len = 2;
  181. +#if defined(CONFIG_ARCH_MT7623)
  182. + msg.timing = 80;
  183. + msg.ext_flag = ext_flag & 0x7FFFFFFF;
  184. +#endif
  185. +
  186. + ret = i2c_transfer(wmio->client->adapter, &msg, 1);
  187. + MSG("[WM8960(%02X)=0x%08X]\n",(unsigned int)reg,(unsigned int)data);
  188. +
  189. + if (ret <= 0)
  190. + printk("%s: i2c write error!\n", __func__);
  191. +}
  192. +
  193. +
  194. +
  195. +// Reset and power up the WM8960
  196. +void audiohw_preinit(void)
  197. +{
  198. + memset(wm_reg_data, 0 , sizeof(unsigned long)*55);
  199. +
  200. + i2c_WM8960_write(RESET, RESET_RESET); // Reset (0x0F)
  201. +
  202. + mdelay(50);
  203. + wm_reg_data[RESET] = 0xFFFF;
  204. + mdelay(50);
  205. +}
  206. +
  207. +void audiohw_set_apll(int srate)
  208. +{
  209. + unsigned long data;
  210. +
  211. + if((srate==8000) || (srate==12000) || (srate==16000) || (srate==24000) || (srate==32000) || (srate==48000))
  212. + {
  213. + // Provide 12.288MHz SYSCLK
  214. + data = wm_reg_data[PLL1];
  215. + i2c_WM8960_write(PLL1, data | PLL1_OPCLKDIV_1 | PLL1_SDM_FRACTIONAL | PLL1_PLLPRESCALE_1 | PLL1_PLLN(0x8)); // PLL1 (0x34)
  216. +
  217. + i2c_WM8960_write(PLL2, PLL2_PLLK_23_16(0x31)); // PLL2 (0x35)
  218. + i2c_WM8960_write(PLL3, PLL3_PLLK_15_8(0x26)); // PLL3 (0x36)
  219. + i2c_WM8960_write(PLL4, PLL4_PLLK_7_0(0xe9)); // PLL4 (0x37)
  220. + }
  221. + else if ((srate==11025) || (srate==22050) || (srate==44100))
  222. + {
  223. + //Provide 11.2896MHz SYSCLK
  224. + data = wm_reg_data[PLL1];
  225. + i2c_WM8960_write(PLL1, data | PLL1_OPCLKDIV_1 | PLL1_SDM_FRACTIONAL | PLL1_PLLPRESCALE_1 | PLL1_PLLN(0x7)); //PLL1 (0x34)
  226. +
  227. + i2c_WM8960_write(PLL2, PLL2_PLLK_23_16(0x86)); //PLL2 (0x35)
  228. + i2c_WM8960_write(PLL3, PLL3_PLLK_15_8(0xc2)); //PLL3 (0x36)
  229. + i2c_WM8960_write(PLL4, PLL4_PLLK_7_0(0x26)); //PLL4 (0x37)
  230. + }
  231. + else
  232. + {
  233. + printk("Not support this srate\n");
  234. + }
  235. + mdelay(3);
  236. +}
  237. +
  238. +
  239. +void audiohw_set_frequency(int fsel, int pll_en)
  240. +{
  241. + MSG("audiohw_set_frequency_=0x%08X\n",fsel);
  242. +
  243. + if (pll_en)
  244. + {
  245. + printk("PLL enable\n");
  246. + i2c_WM8960_write(CLOCKING1, (fsel<<3) | CLOCKING1_SYSCLKDIV_2 | CLOCKING1_CLKSEL_PLL); //CLOCKING (0x04)=>0x05
  247. +
  248. + }
  249. + else
  250. + {
  251. + printk("PLL disable\n");
  252. + i2c_WM8960_write(CLOCKING1, (fsel<<3));//| CLOCKING1_SYSCLKDIV_2); //CLOCKING (0x04)
  253. + }
  254. +
  255. +}
  256. +
  257. +//FIXME
  258. +int audiohw_set_lineout_vol(int Aout, int vol_l, int vol_r)
  259. +{
  260. + MSG("audiohw_set_lineout_vol_\n");
  261. + switch(Aout)
  262. + {
  263. + case 1:
  264. + //i2c_WM8960_write(LOUT1, LOUT1_LO1VU|LOUT1_LO1ZC|LOUT1_LOUT1VOL(0x7f)); //LOUT1(0x02)
  265. + //i2c_WM8960_write(ROUT1, ROUT1_RO1VU|ROUT1_RO1ZC|ROUT1_ROUT1VOL(0x7f)); //ROUT1(0x03)
  266. + i2c_WM8960_write(LOUT1, LOUT1_LO1VU|LOUT1_LO1ZC|LOUT1_LOUT1VOL(vol_l)); //LOUT1(0x02)
  267. + i2c_WM8960_write(ROUT1, ROUT1_RO1VU|ROUT1_RO1ZC|ROUT1_ROUT1VOL(vol_r)); //ROUT1(0x03)
  268. + break;
  269. + case 2:
  270. + i2c_WM8960_write(LSPK, LSPK_SPKLVU|LSPK_SPKLZC| LSPK_SPKLVOL(vol_l));
  271. + i2c_WM8960_write(RSPK, RSPK_SPKRVU|RSPK_SPKRZC| RSPK_SPKRVOL(vol_r));
  272. + break;
  273. + default:
  274. + break;
  275. + }
  276. + return 0;
  277. +}
  278. +
  279. +//FIXME
  280. +int audiohw_set_linein_vol(int vol_l, int vol_r)
  281. +{
  282. + MSG("audiohw_set_linein_vol_\n");
  283. +
  284. + i2c_WM8960_write(LINV, LINV_IPVU|LINV_LINVOL(vol_l)); //LINV(0x00)=>0x12b
  285. + i2c_WM8960_write(RINV, RINV_IPVU|RINV_RINVOL(vol_r)); //LINV(0x01)=>0x12b
  286. +
  287. + return 0;
  288. +}
  289. +
  290. +//Set signal path
  291. +int audiohw_postinit(int bSlave, int AIn, int AOut, int pll_en, int wordLen24b)
  292. +{
  293. +
  294. + int i;
  295. + unsigned long data;
  296. +
  297. + if(wm_reg_data[RESET]!=0xFFFF)
  298. + return 0;
  299. +
  300. + if(bSlave)
  301. + {
  302. + MSG("WM8960 slave.....\n");
  303. + if(wordLen24b)
  304. + {
  305. + printk("24 bit word length\n");
  306. + i2c_WM8960_write(AINTFCE1, AINTFCE1_WL_24 | AINTFCE1_FORMAT_I2S); //AINTFCE1(0x07)
  307. + }
  308. + else
  309. + {
  310. + printk("16 bit word length\n");
  311. + i2c_WM8960_write(AINTFCE1, AINTFCE1_WL_16 | AINTFCE1_FORMAT_I2S); //AINTFCE1(0x07)
  312. + }
  313. + }
  314. + else
  315. + {
  316. + MSG("WM8960 master.....\n");
  317. + i2c_WM8960_write(CLOCKING2, 0x1c4);//CLOCKING2_BCLKDIV(0x1c4)); //CLOCKING2(0x08)
  318. +
  319. + if(wordLen24b)
  320. + {
  321. + printk("24 bit word length\n");
  322. + i2c_WM8960_write(AINTFCE1, AINTFCE1_MS | AINTFCE1_WL_24 | AINTFCE1_FORMAT_I2S); //AINTFCE1(0x07)
  323. + }
  324. + else
  325. + {
  326. + printk("16 bit word length\n");
  327. + i2c_WM8960_write(AINTFCE1, AINTFCE1_MS | AINTFCE1_WL_16 | AINTFCE1_FORMAT_I2S); //AINTFCE1(0x07)
  328. + }
  329. + mdelay(5);
  330. + }
  331. +
  332. +
  333. + //From app notes: allow Vref to stabilize to reduce clicks
  334. + for(i = 0; i < 1000*HZ; i++);
  335. +
  336. + if(AIn > 0)
  337. + {
  338. + data = wm_reg_data[PWRMGMT1];
  339. + i2c_WM8960_write(PWRMGMT1, data|PWRMGMT1_ADCL|PWRMGMT1_ADCR|PWRMGMT1_AINL |PWRMGMT1_AINR);//|PWRMGMT1_MICB);//PWRMGMT1(0x19)
  340. +
  341. + data = wm_reg_data[ADDITIONAL1];
  342. + i2c_WM8960_write(ADDITIONAL1, data|ADDITIONAL1_DATSEL(0x01)); //ADDITIONAL1(0x17)
  343. + i2c_WM8960_write(LADCVOL, LADCVOL_LAVU_EN|LADCVOL_LADCVOL(0xc3)); //LADCVOL(0x15)
  344. + i2c_WM8960_write(RADCVOL, RADCVOL_RAVU_EN|RADCVOL_RADCVOL(0xc3)); //RADCVOL(0x16)
  345. + i2c_WM8960_write(ADCLPATH, ADCLPATH_LMN1|ADCLPATH_LMIC2B);//|ADCLPATH_LMICBOOST_13DB); //ADCLPATH(0x20)=>(0x108)
  346. + i2c_WM8960_write(ADCRPATH, ADCRPATH_RMN1|ADCRPATH_RMIC2B);//|ADCRPATH_RMICBOOST_13DB); //ADCRPATH(0x21)=>(0x108)
  347. + i2c_WM8960_write(PWRMGMT3, PWRMGMT3_LMIC|PWRMGMT3_RMIC); //PWRMGMT3(0x2f)
  348. +
  349. + //i2c_WM8960_write(LINBMIX, 0x000); //LINBMIX(0x2B)
  350. +
  351. + if (AOut<=0)
  352. + {
  353. + i2c_WM8960_write(AINTFCE2, 0x40); //FIXME:(0x09)
  354. +
  355. + data = wm_reg_data[PWRMGMT2];
  356. + if(pll_en)
  357. + {
  358. + i2c_WM8960_write(PWRMGMT2, data|PWRMGMT2_PLL_EN|PWRMGMT2_DACL|PWRMGMT2_DACR); //PWRMGMT2(0x1a)
  359. + }
  360. + else
  361. + {
  362. + i2c_WM8960_write(PWRMGMT2, data|PWRMGMT2_DACL|PWRMGMT2_DACR); //PWRMGMT2(0x1a)
  363. +
  364. + }
  365. + }
  366. + }
  367. + if(AOut>0)
  368. + {
  369. + //Power management 2 setting
  370. + data = wm_reg_data[PWRMGMT2];
  371. +
  372. + if(pll_en)
  373. + {
  374. + i2c_WM8960_write(PWRMGMT2, data|PWRMGMT2_PLL_EN|PWRMGMT2_DACL|PWRMGMT2_DACR|PWRMGMT2_LOUT1|PWRMGMT2_ROUT1|PWRMGMT2_SPKL|PWRMGMT2_SPKR); //PWRMGMT2(0x1a)
  375. + }
  376. + else
  377. + {
  378. + i2c_WM8960_write(PWRMGMT2, data|PWRMGMT2_DACL|PWRMGMT2_DACR|PWRMGMT2_LOUT1|PWRMGMT2_ROUT1|PWRMGMT2_SPKL|PWRMGMT2_SPKR); //PWRMGMT2(0x1a)
  379. +
  380. + }
  381. +
  382. + mdelay(10);
  383. +
  384. + i2c_WM8960_write(AINTFCE2, 0x40); //FIXME:(0x09)
  385. +
  386. + i2c_WM8960_write(LEFTGAIN, LEFTGAIN_LDVU|LEFTGAIN_LDACVOL(0xff)); //LEFTGAIN(0x0a)
  387. + i2c_WM8960_write(RIGHTGAIN, RIGHTGAIN_RDVU|RIGHTGAIN_RDACVOL(0xff)); //RIGHTGAIN(0x0b)
  388. +
  389. + i2c_WM8960_write(LEFTMIX1, 0x100); //LEFTMIX1(0x22)
  390. + i2c_WM8960_write(RIGHTMIX2, 0x100); //RIGHTMIX2(0x25)
  391. +
  392. + data = wm_reg_data[PWRMGMT3]; //FIXME
  393. + i2c_WM8960_write(PWRMGMT3, data|PWRMGMT3_ROMIX|PWRMGMT3_LOMIX); //PWRMGMT3(0x2f)
  394. +
  395. + data = wm_reg_data[CLASSDCTRL1]; //CLASSDCTRL1(0x31) SPEAKER FIXME
  396. + i2c_WM8960_write(CLASSDCTRL1, 0xf7);//data|CLASSDCTRL1_OP_LRSPK);
  397. +
  398. + data = wm_reg_data[CLASSDCTRL3]; //CLASSDCTRL3(0x33)
  399. + i2c_WM8960_write(CLASSDCTRL3, 0xad);//data|(0x1b));
  400. + }
  401. +
  402. + i2c_WM8960_write(DACCTRL1, 0x000); //DACCTRL1(0x05)
  403. +
  404. + data = wm_reg_data[PWRMGMT1];
  405. + i2c_WM8960_write(PWRMGMT1, data|0x1c0); //FIXME:PWRMGMT1(0x19)
  406. +
  407. +
  408. + printk("WM8960 All initial ok!\n");
  409. +
  410. + return 0;
  411. +
  412. +}
  413. +
  414. +void audiohw_micboost(int boostgain)
  415. +{
  416. + unsigned long data;
  417. +
  418. + data = wm_reg_data[ADCLPATH];
  419. + i2c_WM8960_write(ADCLPATH, data|(boostgain << 4));
  420. +
  421. + data = wm_reg_data[ADCRPATH];
  422. + i2c_WM8960_write(ADCRPATH, data|(boostgain << 4));
  423. +}
  424. +
  425. +void audiohw_micin(int enableMic)
  426. +{
  427. + unsigned long data;
  428. +
  429. + if (enableMic==1)
  430. + {
  431. + data = wm_reg_data[PWRMGMT1];
  432. + i2c_WM8960_write(PWRMGMT1, data|PWRMGMT1_MICB);
  433. + }
  434. +#if 1
  435. + else
  436. + {
  437. + data = wm_reg_data[PWRMGMT1];
  438. + i2c_WM8960_write(PWRMGMT1, data & (~(PWRMGMT1_MICB)));
  439. + }
  440. +#endif
  441. +}
  442. +
  443. +void audiohw_mute( bool mute)
  444. +{
  445. + //Mute: Set DACMU = 1 to soft-mute the audio DACs.
  446. + //Unmute: Set DACMU = 0 to soft-un-mute the audio DACs.
  447. + i2c_WM8960_write(DACCTRL1, mute ? DACCTRL1_DACMU : 0);
  448. +}
  449. +
  450. +
  451. +//Nice shutdown of WM8960 codec
  452. +void audiohw_close(void)
  453. +{
  454. + i2c_WM8960_write(DACCTRL1,DACCTRL1_DACMU); //0x05->0x08
  455. + i2c_WM8960_write(PWRMGMT1, 0x000); //0x19->0x000
  456. + mdelay(400);
  457. + i2c_WM8960_write(PWRMGMT2, 0x000); //0x1a->0x000
  458. +
  459. +}
  460. +
  461. +void audiohw_loopback(int fsel)
  462. +{
  463. +}
  464. +
  465. +void audiohw_codec_exlbk(void)
  466. +{
  467. + memset(wm_reg_data, 0 , sizeof(unsigned long)*55);
  468. +
  469. + i2c_WM8960_write(LINV, 0x117); //0x00->0x117
  470. + i2c_WM8960_write(RINV, 0x117); //0x01->0x117
  471. + i2c_WM8960_write(LOUT1, 0x179); //0x02->0x179
  472. + i2c_WM8960_write(ROUT1, 0x179); //0x03->0x179
  473. + i2c_WM8960_write(CLOCKING1, 0x00); //0x04->0x00
  474. + //i2c_WM8960_write(CLOCKING1, 0x40); //0x04->0x00
  475. + i2c_WM8960_write(DACCTRL1, 0x00); //0x05->0x00
  476. + i2c_WM8960_write(AINTFCE2, 0x41); //0x09->0x41
  477. + i2c_WM8960_write(LADCVOL, 0x1c3); //0x15->0x1c3
  478. + i2c_WM8960_write(RADCVOL, 0x1c3); //0x16->0x1c3
  479. + i2c_WM8960_write(PWRMGMT1, 0xfc); //0x19->0xfc
  480. + i2c_WM8960_write(PWRMGMT2, 0x1e0); //0x1a->0x1e0
  481. + i2c_WM8960_write(ADCLPATH, 0x108); //0x20->0x108
  482. + i2c_WM8960_write(ADCRPATH, 0x108); //0x21->0x108
  483. + i2c_WM8960_write(LEFTMIX1, 0x150); //0x22->0x150
  484. + i2c_WM8960_write(RIGHTMIX2, 0x150); //0x25->0x150
  485. + i2c_WM8960_write(BYPASS1, 0x00); //0x2d->0x00
  486. + i2c_WM8960_write(BYPASS2, 0x00); //0x2e->0x00
  487. + i2c_WM8960_write(PWRMGMT3, 0x3c); //0x2f->0x3c
  488. +}
  489. +
  490. +void audiohw_bypass(void)
  491. +{
  492. + int i;
  493. +
  494. + memset(wm_reg_data, 0 , sizeof(unsigned long)*55);
  495. + i2c_WM8960_write(RESET, 0x000); //0x0f(R15)->0x000
  496. +
  497. + for(i = 0; i < 1000*HZ; i++);
  498. +
  499. + i2c_WM8960_write(PWRMGMT1, 0xf0); //0x19(R25)->0xf0
  500. + i2c_WM8960_write(PWRMGMT2, 0x60); //0x1a(R26)->0x60
  501. + i2c_WM8960_write(PWRMGMT3, 0x3c); //0x2f(R47)->0x3c
  502. + i2c_WM8960_write(LINV, 0x117); // 0x00(R0)->0x117
  503. + i2c_WM8960_write(RINV, 0x117); // 0x01(R1)->0x117
  504. + i2c_WM8960_write(ADCLPATH, 0x108); //0x20(R32)->0x108
  505. + i2c_WM8960_write(ADCRPATH, 0x108); //0x21(R33)->0x108
  506. + i2c_WM8960_write(BYPASS1, 0x80); //0x2d(R45)->0x80
  507. + i2c_WM8960_write(BYPASS2, 0x80); //0x2e(R46)->0x80
  508. + i2c_WM8960_write(LOUT1, 0x179); // 0x02(R2)->0x179
  509. + i2c_WM8960_write(ROUT1, 0x179); // 0x03(R3)->0x179
  510. +}
  511. +EXPORT_SYMBOL(audiohw_set_frequency);
  512. +EXPORT_SYMBOL(audiohw_close);
  513. +EXPORT_SYMBOL(audiohw_postinit);
  514. +EXPORT_SYMBOL(audiohw_preinit);
  515. +EXPORT_SYMBOL(audiohw_set_apll);
  516. +EXPORT_SYMBOL(audiohw_codec_exlbk);
  517. +EXPORT_SYMBOL(audiohw_bypass);
  518. +EXPORT_SYMBOL(audiohw_set_lineout_vol);
  519. +EXPORT_SYMBOL(audiohw_set_linein_vol);
  520. +EXPORT_SYMBOL(audiohw_micin);
  521. +EXPORT_SYMBOL(audiohw_mute);
  522. +EXPORT_SYMBOL(audiohw_loopback);
  523. +EXPORT_SYMBOL(audiohw_micboost);
  524. +
  525. +static int codec_wm8960_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
  526. +{
  527. + struct wm8960_data *wm;
  528. +
  529. +printk("*******Enter %s********\n", __func__);
  530. +
  531. + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
  532. + return -EIO;
  533. +
  534. + wm = devm_kzalloc(&client->dev, sizeof(struct wm8960_data), GFP_KERNEL);
  535. + if (!wm)
  536. + return -ENOMEM;
  537. +
  538. +#if defined(CONFIG_ARCH_MT7623)
  539. + mt_set_gpio_mode(GPIO242, GPIO_MODE_04);
  540. + mt_set_gpio_mode(GPIO243, GPIO_MODE_04);
  541. +#endif
  542. + wm->client = client;
  543. + wm->dev = &client->dev;
  544. + wm->name = id->name;
  545. + i2c_set_clientdata(client, wm);
  546. + wmio = wm;
  547. +
  548. + memset(wm_reg_data, 0 , sizeof(unsigned long)*55);
  549. +
  550. + return 0;
  551. +}
  552. +
  553. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0)
  554. +static int codec_wm8960_i2c_remove(struct i2c_client *client)
  555. +#else
  556. +static int __devexit codec_wm8960_i2c_remove(struct i2c_client *client)
  557. +#endif
  558. +{
  559. + struct wm8960_data *wm = i2c_get_clientdata(client);
  560. + kfree(wm);
  561. +
  562. + return 0;
  563. +}
  564. +
  565. +static const struct i2c_device_id wm8960_id[] = {
  566. + { "codec_wm8960", 0 },
  567. + {}
  568. +};
  569. +
  570. +static struct i2c_driver codec_wm8960_i2c_driver = {
  571. + .driver = {
  572. + .name = "codec_wm8960"
  573. + },
  574. + .probe = codec_wm8960_i2c_probe,
  575. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0)
  576. + .remove = codec_wm8960_i2c_remove,
  577. +#else
  578. + .remove = __devexit_p(codec_wm8960_i2c_remove),
  579. +#endif
  580. + .id_table = wm8960_id,
  581. +};
  582. +static int __init wm8960_i2c_init(void)
  583. +{
  584. +#if defined(CONFIG_ARCH_MT7623)
  585. + i2c_register_board_info(1, &i2c_devs1, 1);
  586. +#endif
  587. + return i2c_add_driver(&codec_wm8960_i2c_driver);;
  588. +}
  589. +
  590. +static void __exit wm8960_i2c_exit(void)
  591. +{
  592. + i2c_del_driver(&codec_wm8960_i2c_driver);
  593. +}
  594. +
  595. +module_init(wm8960_i2c_init);
  596. +module_exit(wm8960_i2c_exit);
  597. +
  598. +MODULE_AUTHOR("Ryder Lee <ryder.lee@mediatek.com>");
  599. +MODULE_DESCRIPTION("WM8960 I2C client driver");
  600. +MODULE_LICENSE("GPL");
  601. +
  602. --- /dev/null
  603. +++ b/sound/soc/mtk/i2c_wm8960.h
  604. @@ -0,0 +1,288 @@
  605. +/* wm8960.h -- WM8960 Soc Audio driver */
  606. +#ifndef _WM8960_H
  607. +#define _WM8960_H
  608. +
  609. +#define bool unsigned char
  610. +#define false 0
  611. +#define true 1
  612. +
  613. +/* volume/balance/treble/bass interdependency */
  614. +#define VOLUME_MIN -730
  615. +#define VOLUME_MAX 60
  616. +
  617. +
  618. +/* Register addresses and bits */
  619. +#define OUTPUT_MUTED 0x2f
  620. +#define OUTPUT_0DB 0x79
  621. +
  622. +#define LINV 0x00
  623. +#define LINV_IPVU (1 << 8) /* FIXME */
  624. +#define LINV_LINMUTE (1 << 7)
  625. +#define LINV_LIZC (1 << 6)
  626. +#define LINV_LINVOL(x) ((x) & 0x3f)
  627. +
  628. +#define RINV 0x01
  629. +#define RINV_IPVU (1 << 8) /* FIXME */
  630. +#define RINV_RINMUTE (1 << 7)
  631. +#define RINV_RIZC (1 << 6)
  632. +#define RINV_RINVOL(x) ((x) & 0x3f)
  633. +
  634. +#define LOUT1 0x02
  635. +#define LOUT1_LO1VU (1 << 8)
  636. +#define LOUT1_LO1ZC (1 << 7)
  637. +#define LOUT1_LOUT1VOL(x) ((x) & 0x7f)
  638. +
  639. +#define ROUT1 0x03
  640. +#define ROUT1_RO1VU (1 << 8)
  641. +#define ROUT1_RO1ZC (1 << 7)
  642. +#define ROUT1_ROUT1VOL(x) ((x) & 0x7f)
  643. +
  644. +#define CLOCKING1 0x04 /* FIXME */
  645. +#define CLOCKING1_ADCDIV(x) (((x) & 0x7) << 6)
  646. +#define CLOCKING1_DACDIV(x) (((x) & 0x7) << 3)
  647. +#define CLOCKING1_SYSCLKDIV_1 (0 << 1)
  648. +#define CLOCKING1_SYSCLKDIV_2 (2 << 1)
  649. +#define CLOCKING1_CLKSEL_MCLK (0 << 0)
  650. +#define CLOCKING1_CLKSEL_PLL (1 << 0)
  651. +
  652. +#define DACCTRL1 0x05
  653. +#define DACCTRL1_DATTENUATE (1 << 7)
  654. +#define DACCTRL1_DACMU (1 << 3)
  655. +#define DACCTRL1_DEEMPH_48 (3 << 1)
  656. +#define DACCTRL1_DEEMPH_44 (2 << 1)
  657. +#define DACCTRL1_DEEMPH_32 (1 << 1)
  658. +#define DACCTRL1_DEEMPH_NONE (0 << 1)
  659. +#define DACCTRL1_DEEMPH(x) ((x) & (0x3 << 1))
  660. +
  661. +#define DACCTRL2 0x06
  662. +
  663. +#define AINTFCE1 0x07
  664. +#define AINTFCE1_BCLKINV (1 << 7)
  665. +#define AINTFCE1_MS (1 << 6)
  666. +#define AINTFCE1_LRSWAP (1 << 5)
  667. +#define AINTFCE1_LRP (1 << 4)
  668. +#define AINTFCE1_WL_32 (3 << 2)
  669. +#define AINTFCE1_WL_24 (2 << 2)
  670. +#define AINTFCE1_WL_20 (1 << 2)
  671. +#define AINTFCE1_WL_16 (0 << 2)
  672. +#define AINTFCE1_WL(x) (((x) & 0x3) << 2)
  673. +#define AINTFCE1_FORMAT_DSP (3 << 0)
  674. +#define AINTFCE1_FORMAT_I2S (2 << 0)
  675. +#define AINTFCE1_FORMAT_LJUST (1 << 0)
  676. +#define AINTFCE1_FORMAT_RJUST (0 << 0)
  677. +#define AINTFCE1_FORMAT(x) ((x) & 0x3)
  678. +
  679. +/* FIXME */
  680. +#define CLOCKING2 0x08
  681. +#define CLOCKING2_DCLKDIV(x) (((x) & 0x7) << 6)
  682. +#define CLOCKING2_BCLKDIV(x) (((x) & 0xf) << 0)
  683. +
  684. +#define AINTFCE2 0x09
  685. +#define AINTFCE2_ALRCGPIO_ALRC (0 << 6)
  686. +#define AINTFCE2_ALRCGPIO_GPIO (1 << 6)
  687. +#define AINTFCE2_LOOPBACK (1 << 0)
  688. +
  689. +#define LEFTGAIN 0x0a
  690. +#define LEFTGAIN_LDVU (1 << 8)
  691. +#define LEFTGAIN_LDACVOL(x) ((x) & 0xff)
  692. +
  693. +#define RIGHTGAIN 0x0b
  694. +#define RIGHTGAIN_RDVU (1 << 8)
  695. +#define RIGHTGAIN_RDACVOL(x) ((x) & 0xff)
  696. +
  697. +#define RESET 0x0f
  698. +#define RESET_RESET 0x000
  699. +
  700. +#define ALC1 0x11
  701. +#define ALC1_ALCOFF (0x0 << 7)
  702. +#define ALC1_ALCRONLY (0x1 << 7)
  703. +#define ALC1_ALCLONLY (0x2 << 7)
  704. +#define ALC1_ALCSTEREO (0x3 << 7)
  705. +#define ALC1_ALCSEL(x) (((x) & 0x3) << 7)
  706. +#define ALC1_SET_MAXGAIN(x) ((x & 0x7) << 4)
  707. +#define ALC1_GET_MAXGAIN(x) ((x) & (0x7 << 4))
  708. +#define ALC1_ALCL(x) ((x) & 0x0f)
  709. +
  710. +#define ALC2 0x12
  711. +#define ALC2_MINGAIN(x) ((x & 0x7) << 4)
  712. +#define ALC2_HLD(x) ((x) & 0x0f)
  713. +
  714. +#define ALC3 0x13
  715. +#define ALC3_SET_DCY(x) ((x & 0x0f) << 4)
  716. +#define ALC3_GET_DCY(x) ((x) & (0x0f << 4))
  717. +#define ALC3_ATK(x) ((x) & 0x0f)
  718. +
  719. +#define NOISEGATE 0x14
  720. +#define NOISEGATE_SET_NGTH(x) ((x & 0x1f) << 3)
  721. +#define NOISEGATE_GET_NGTH(x) ((x) & (0x1f << 3))
  722. +#define NOISEGATE_NGAT_ENABLE 1
  723. +
  724. +#define LADCVOL 0x15
  725. +#define LADCVOL_LAVU_EN (1 << 8)
  726. +#define LADCVOL_LADCVOL(x) ((x) & 0x0ff)
  727. +
  728. +#define RADCVOL 0x16
  729. +#define RADCVOL_RAVU_EN (1 << 8)
  730. +#define RADCVOL_RADCVOL(x) ((x) & 0x0ff)
  731. +
  732. +#define ADDITIONAL1 0x17
  733. +#define ADDITIONAL1_TSDEN (1 << 8)
  734. +#define ADDITIONAL1_VSEL_LOWEST (0 << 6)
  735. +#define ADDITIONAL1_VSEL_LOW (1 << 6)
  736. +#define ADDITIONAL1_VSEL_DEFAULT2 (2 << 6)
  737. +#define ADDITIONAL1_VSEL_DEFAULT (3 << 6)
  738. +#define ADDITIONAL1_VSEL(x) (((x) & 0x3) << 6)
  739. +#define ADDITIONAL1_DMONOMIX_STEREO (0 << 4)
  740. +#define ADDITIONAL1_DMONOMIX_MONO (1 << 4)
  741. +#define ADDITIONAL1_DATSEL(x) (((x) & 0x3) << 2)
  742. +#define ADDITIONAL1_TOCLKSEL (1 << 1)
  743. +#define ADDITIONAL1_TOEN (1 << 0)
  744. +
  745. +#define ADDITIONAL2 0x18
  746. +#define ADDITIONAL2_HPSWEN (1 << 6)
  747. +#define ADDITIONAL2_HPSWPOL (1 << 5)
  748. +#define ADDITIONAL2_TRIS (1 << 3)
  749. +#define ADDITIONAL2_LRCM_ON (1 << 2)
  750. +
  751. +#define PWRMGMT1 0x19
  752. +#define PWRMGMT1_VMIDSEL_DISABLED (0 << 7)
  753. +#define PWRMGMT1_VMIDSEL_50K (1 << 7)
  754. +#define PWRMGMT1_VMIDSEL_250K (2 << 7)
  755. +#define PWRMGMT1_VMIDSEL_5K (3 << 7)
  756. +#define PWRMGMT1_VREF (1 << 6)
  757. +#define PWRMGMT1_AINL (1 << 5)
  758. +#define PWRMGMT1_AINR (1 << 4)
  759. +#define PWRMGMT1_ADCL (1 << 3)
  760. +#define PWRMGMT1_ADCR (1 << 2)
  761. +#define PWRMGMT1_MICB (1 << 1)
  762. +#define PWRMGMT1_DIGENB (1 << 0)
  763. +
  764. +#define PWRMGMT2 0x1a
  765. +#define PWRMGMT2_DACL (1 << 8)
  766. +#define PWRMGMT2_DACR (1 << 7)
  767. +#define PWRMGMT2_LOUT1 (1 << 6)
  768. +#define PWRMGMT2_ROUT1 (1 << 5)
  769. +#define PWRMGMT2_SPKL (1 << 4)
  770. +#define PWRMGMT2_SPKR (1 << 3)
  771. +#define PWRMGMT2_OUT3 (1 << 1)
  772. +#define PWRMGMT2_PLL_EN (1 << 0)
  773. +
  774. +#define ADDITIONAL3 0x1b
  775. +#define ADDITIONAL3_VROI (1 << 6)
  776. +#define ADDITIONAL3_OUT3CAP (1 << 3)
  777. +#define ADDITIONAL3_ADC_ALC_SR(x) ((x) & 0x7)
  778. +
  779. +#define ANTIPOP1 0x1c
  780. +#define ANTIPOP2 0x1d
  781. +
  782. +#define ADCLPATH 0x20
  783. +#define ADCLPATH_LMN1 (1 << 8)
  784. +#define ADCLPATH_LMP3 (1 << 7)
  785. +#define ADCLPATH_LMP2 (1 << 6)
  786. +#define ADCLPATH_LMICBOOST_29DB (0x3 << 4)
  787. +#define ADCLPATH_LMICBOOST_20DB (0x2 << 4)
  788. +#define ADCLPATH_LMICBOOST_13DB (0x1 << 4)
  789. +#define ADCLPATH_SET_LMICBOOST(x) ((x & 0x3) << 4)
  790. +#define ADCLPATH_LMIC2B (1 << 3)
  791. +
  792. +
  793. +#define ADCRPATH 0x21
  794. +#define ADCRPATH_RMN1 (1 << 8)
  795. +#define ADCRPATH_RMP3 (1 << 7)
  796. +#define ADCRPATH_RMP2 (1 << 6)
  797. +#define ADCRPATH_RMICBOOST_29DB (0x3 << 4)
  798. +#define ADCRPATH_RMICBOOST_20DB (0x2 << 4)
  799. +#define ADCRPATH_RMICBOOST_13DB (0x1 << 4)
  800. +#define ADCRPATH_SET_RMICBOOST(x) ((x & 0x3) << 4)
  801. +#define ADCRPATH_RMIC2B (1 << 3)
  802. +
  803. +
  804. +#define LEFTMIX1 0x22
  805. +#define LEFTMIX1_LD2LO (1 << 8)
  806. +#define LEFTMIX1_LI2LO (1 << 7)
  807. +#define LEFTMIX1_LI2LO_DEFAULT (5 << 4)
  808. +#define LEFTMIX1_LI2LOVOL(x) (((x) & 0x7) << 4)
  809. +
  810. +#define RIGHTMIX2 0x25
  811. +#define RIGHTMIX2_RD2RO (1 << 8)
  812. +#define RIGHTMIX2_RI2RO (1 << 7)
  813. +#define RIGHTMIX2_RI2RO_DEFAULT (5 << 4)
  814. +#define RIGHTMIX2_RI2ROVOL(x) (((x) & 0x7) << 4)
  815. +
  816. +#define MONOMIX1 0x26
  817. +#define MONOMIX1_L2MO (1 << 7)
  818. +
  819. +#define MONOMIX2 0x27
  820. +#define MONOMIX2_R2MO (1 << 7)
  821. +
  822. +#define LSPK 0x28
  823. +#define LSPK_SPKLVU (1 << 8)
  824. +#define LSPK_SPKLZC (1 << 7)
  825. +#define LSPK_SPKLVOL(x) ((x) & 0x7f)
  826. +
  827. +#define RSPK 0x29
  828. +#define RSPK_SPKRVU (1 << 8)
  829. +#define RSPK_SPKRZC (1 << 7)
  830. +#define RSPK_SPKRVOL(x) ((x) & 0x7f)
  831. +
  832. +#define OUT3V 0x2a
  833. +#define LINBMIX 0x2b
  834. +#define RINBMIX 0x2c
  835. +#define BYPASS1 0x2d
  836. +#define BYPASS2 0x2e
  837. +
  838. +#define PWRMGMT3 0x2f
  839. +#define PWRMGMT3_LMIC (1<<5)
  840. +#define PWRMGMT3_RMIC (1<<4)
  841. +#define PWRMGMT3_LOMIX (1<<3)
  842. +#define PWRMGMT3_ROMIX (1<<2)
  843. +
  844. +#define ADDITIONAL4 0x30
  845. +
  846. +#define CLASSDCTRL1 0x31
  847. +#define CLASSDCTRL1_OP_OFF (0<<6)
  848. +#define CLASSDCTRL1_OP_LSPK (1<<6)
  849. +#define CLASSDCTRL1_OP_RSPK (2<<6)
  850. +#define CLASSDCTRL1_OP_LRSPK (3<<6)
  851. +
  852. +#define CLASSDCTRL3 0x33
  853. +
  854. +#define PLL1 0x34
  855. +#define PLL1_OPCLKDIV_1 (0<<6)
  856. +#define PLL1_OPCLKDIV_2 (1<<6)
  857. +#define PLL1_OPCLKDIV_3 (2<<6)
  858. +#define PLL1_OPCLKDIV_4 (3<<6)
  859. +#define PLL1_OPCLKDIV_5p5 (4<<6)
  860. +#define PLL1_OPCLKDIV_6 (5<<6)
  861. +#define PLL1_SDM_INTERGER (0<<5)
  862. +#define PLL1_SDM_FRACTIONAL (1<<5)
  863. +#define PLL1_PLLPRESCALE_1 (0<<4)
  864. +#define PLL1_PLLPRESCALE_2 (1<<4)
  865. +#define PLL1_PLLN(x) ((x) & 0xf)
  866. +
  867. +#define PLL2 0x35
  868. +#define PLL2_PLLK_23_16(x) ((x) & 0x1ff)
  869. +
  870. +#define PLL3 0x36
  871. +#define PLL3_PLLK_15_8(x) ((x) & 0x1ff)
  872. +
  873. +#define PLL4 0x37
  874. +#define PLL4_PLLK_7_0(x) ((x) & 0x1ff)
  875. +
  876. +/* codec API */
  877. +void audiohw_preinit(void);
  878. +int audiohw_postinit(int bSlave, int AIn, int AOut, int pll_en, int wordLen24b);
  879. +void audiohw_close(void);
  880. +void audiohw_set_frequency(int fsel, int pll_en);
  881. +void audiohw_mute(bool mute);
  882. +void audiohw_micboost(int boostgain);
  883. +void audiohw_micin(int enableMic);
  884. +void audiohw_set_apll(int srate);
  885. +int audiohw_set_lineout_vol(int Aout, int vol_l, int vol_r);
  886. +int audiohw_set_linein_vol(int vol_l, int vol_r);
  887. +void audiohw_mute( bool mute);
  888. +void audiohw_loopback(int fsel);
  889. +void audiohw_codec_exlbk(void);
  890. +void audiohw_bypass(void);
  891. +
  892. +#endif /* _WM875x_H */
  893. --- /dev/null
  894. +++ b/sound/soc/mtk/i2s_ctrl.c
  895. @@ -0,0 +1,3524 @@
  896. +#include <linux/init.h>
  897. +#include <linux/version.h>
  898. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,35)
  899. +#include <linux/sched.h>
  900. +#endif
  901. +#include <linux/module.h>
  902. +#include <linux/kernel.h> /* _printk() */
  903. +#include <linux/slab.h> /* kmalloc() */
  904. +#include <linux/fs.h> /* everything... */
  905. +#include <linux/errno.h> /* error codes */
  906. +#include <linux/types.h> /* size_t */
  907. +#include <linux/proc_fs.h>
  908. +#include <linux/fcntl.h> /* O_ACCMODE */
  909. +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,14)
  910. +#include <asm/system.h> /* cli(), *_flags */
  911. +#endif
  912. +#include <asm/uaccess.h> /* copy_from/to_user */
  913. +#include <linux/interrupt.h>
  914. +#include <linux/mm.h>
  915. +#include <linux/mm_types.h>
  916. +#include <linux/pci.h>
  917. +#include <linux/delay.h>
  918. +#include "ralink_gdma.h"
  919. +#if defined(CONFIG_I2S_WITH_AEC)
  920. +#include "../aec/aec_api.h"
  921. +#endif
  922. +
  923. +#ifdef CONFIG_DEVFS_FS
  924. +#include <linux/devfs_fs_kernel.h>
  925. +static devfs_handle_t devfs_handle;
  926. +#endif
  927. +
  928. +#include "i2s_ctrl.h"
  929. +
  930. +#if defined(CONFIG_SND_MT76XX_SOC)
  931. +#include <sound/soc/mtk/mt76xx_machine.h>
  932. +#endif
  933. +
  934. +#if defined(CONFIG_I2S_WM8750)
  935. +#include "../codec/i2c_wm8750.h"
  936. +#endif
  937. +#if defined(CONFIG_I2S_WM8751)
  938. +#include "../codec/i2c_wm8751.h"
  939. +#endif
  940. +#if defined(CONFIG_I2S_WM8960)
  941. +#include "i2c_wm8960.h"
  942. +#endif
  943. +
  944. +static int i2sdrv_major = 191;
  945. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,35)
  946. +#else
  947. +static struct class *i2smodule_class;
  948. +#endif
  949. +
  950. +static int _printk(char *fmt, ...)
  951. +{
  952. + return 0;
  953. +}
  954. +
  955. +/* external functions declarations */
  956. +#if defined(CONFIG_I2S_WM8960)
  957. +extern void audiohw_set_frequency(int fsel, int codec_pll_en);
  958. +void audiohw_set_apll(int srate);
  959. +#elif defined(CONFIG_I2S_WM8750)||defined(CONFIG_I2S_WM8751)
  960. +extern void audiohw_set_frequency(int fsel);
  961. +#endif
  962. +#if defined(CONFIG_I2S_WM8960)||defined(CONFIG_I2S_WM8750)||defined(CONFIG_I2S_WM8751)
  963. +extern int audiohw_set_lineout_vol(int Aout, int vol_l, int vol_r);
  964. +extern int audiohw_set_master_vol(int vol_l, int vol_r);
  965. +extern int audiohw_set_linein_vol(int vol_l, int vol_r);
  966. +#endif
  967. +
  968. +extern void audiohw_micboost(int boostgain);
  969. +
  970. +extern int GdmaI2sTx(uint32_t Src, uint32_t Dst, uint8_t TxNo, uint16_t TransCount,
  971. + void (*DoneIntCallback)(uint32_t data),
  972. + void (*UnMaskIntCallback)(uint32_t data));
  973. +
  974. +extern int GdmaI2sRx(uint32_t Src, uint32_t Dst, uint8_t RxNo, uint16_t TransCount,
  975. + void (*DoneIntCallback)(uint32_t data),
  976. + void (*UnMaskIntCallback)(uint32_t data));
  977. +
  978. +extern int GdmaMaskChannel(uint32_t ChNum);
  979. +
  980. +extern int GdmaUnMaskChannel(uint32_t ChNum);
  981. +
  982. +/* internal functions declarations */
  983. +irqreturn_t i2s_irq_isr(int irq, void *irqaction);
  984. +int i2s_debug_cmd(unsigned int cmd, unsigned long arg);
  985. +
  986. +/* forward declarations for _fops */
  987. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,35)
  988. +static long i2s_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
  989. +#else
  990. +static int i2s_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg);
  991. +#endif
  992. +static int i2s_mmap(struct file *file, struct vm_area_struct *vma);
  993. +static int i2s_open(struct inode *inode, struct file *file);
  994. +static int i2s_release(struct inode *inode, struct file *file);
  995. +int i2s_mmap_alloc(unsigned long size);
  996. +int i2s_mmap_remap(struct vm_area_struct *vma, unsigned long size);
  997. +
  998. +/* global varable definitions */
  999. +i2s_config_type i2s_config;
  1000. +i2s_status_type i2s_status;
  1001. +i2s_config_type* pi2s_config = &i2s_config;;
  1002. +i2s_status_type* pi2s_status = &i2s_status;;
  1003. +
  1004. +static inline long
  1005. +ugly_hack_sleep_on_timeout(wait_queue_head_t *q, long timeout)
  1006. +{
  1007. + unsigned long flags;
  1008. + wait_queue_t wait;
  1009. +
  1010. + init_waitqueue_entry(&wait, current);
  1011. +
  1012. + __set_current_state(TASK_INTERRUPTIBLE);
  1013. + spin_lock_irqsave(&q->lock, flags);
  1014. + __add_wait_queue(q, &wait);
  1015. + spin_unlock(&q->lock);
  1016. +
  1017. + timeout = schedule_timeout(timeout);
  1018. +
  1019. + spin_lock_irq(&q->lock);
  1020. + __remove_wait_queue(q, &wait);
  1021. + spin_unlock_irqrestore(&q->lock, flags);
  1022. +
  1023. + return timeout;
  1024. +}
  1025. +
  1026. +#define interruptible_sleep_on(x) \
  1027. + ugly_hack_sleep_on_timeout(x, MAX_SCHEDULE_TIMEOUT);
  1028. +
  1029. +
  1030. +#if defined(ARM_ARCH)
  1031. +static dma_addr_t i2s_txdma_addr0, i2s_txdma_addr1;
  1032. +static dma_addr_t i2s_rxdma_addr0, i2s_rxdma_addr1;
  1033. +#define I2S_TX_FIFO_WREG_PHY (I2S_TX_FIFO_WREG & 0x1FFFFFFF)
  1034. +#define I2S_RX_FIFO_RREG_PHY (I2S_RX_FIFO_RREG & 0x1FFFFFFF)
  1035. +#else
  1036. +static dma_addr_t i2s_txdma_addr, i2s_rxdma_addr;
  1037. +#endif
  1038. +static dma_addr_t i2s_mmap_addr[MAX_I2S_PAGE*2];
  1039. + /* 8khz 11.025khz 12khz 16khz 22.05khz 24Khz 32khz 44.1khz 48khz 88.2khz 96khz*/
  1040. +unsigned long i2s_inclk_15p625Mhz[11] = {60<<8, 43<<8, 40<<8, 30<<8, 21<<8, 19<<8, 14<<8, 10<<8, 9<<8, 7<<8, 4<<8};
  1041. +unsigned long i2s_exclk_12p288Mhz[11] = {47<<8, 34<<8, 31<<8, 23<<8, 16<<8, 15<<8, 11<<8, 8<<8, 7<<8, 5<<8, 3<<8};
  1042. +unsigned long i2s_exclk_12Mhz[11] = {46<<8, 33<<8, 30<<8, 22<<8, 16<<8, 15<<8, 11<<8, 8<<8, 7<<8, 5<<8, 3<<8};
  1043. +#if defined(CONFIG_I2S_WM8750) || defined(CONFIG_SND_SOC_WM8750)
  1044. + /* 8k 11.025k 12k 16k 22.05k 24k 32k 44.1k 48k 88.2k 96k*/
  1045. +unsigned long i2s_codec_12p288Mhz[11] = {0x0C, 0x00, 0x10, 0x14, 0x38, 0x38, 0x18, 0x20, 0x00, 0x00, 0x1C};
  1046. +unsigned long i2s_codec_12Mhz[11] = {0x0C, 0x32, 0x10, 0x14, 0x37, 0x38, 0x18, 0x22, 0x00, 0x3E, 0x1C};
  1047. +unsigned long i2s_codec_24p576Mhz[11] = {0x4C, 0x00, 0x50, 0x54, 0x00, 0x78, 0x58, 0x00, 0x40, 0x00, 0x5C};
  1048. +unsigned long i2s_codec_18p432Mhz[11] = {0x0e, 0x32, 0x12, 0x16, 0x36, 0x3a, 0x1a, 0x22, 0x02, 0x3e, 0x1e};
  1049. +#endif
  1050. +#if defined(CONFIG_I2S_WM8751) || defined(CONFIG_SND_SOC_WM8751)
  1051. +unsigned long i2s_codec_12p288Mhz[11] = {0x04, 0x00, 0x10, 0x14, 0x38, 0x38, 0x18, 0x20, 0x00, 0x00, 0x1C};
  1052. +unsigned long i2s_codec_12Mhz[11] = {0x04, 0x32, 0x10, 0x14, 0x37, 0x38, 0x18, 0x22, 0x00, 0x3E, 0x1C};
  1053. +#endif
  1054. +#if defined(CONFIG_I2S_WM8960) || defined(CONFIG_SND_SOC_WM8960)
  1055. +unsigned long i2s_codec_12p288Mhz[11] = {0x36, 0x24, 0x24, 0x1b, 0x12, 0x12, 0x09, 0x00, 0x00, 0x00, 0x00};
  1056. +unsigned long i2s_codec_12Mhz[11] = {0x36, 0x24, 0x24, 0x1b, 0x12, 0x12, 0x09, 0x00, 0x00, 0x00, 0x00};
  1057. +#endif
  1058. +EXPORT_SYMBOL(i2s_codec_12p288Mhz);
  1059. +EXPORT_SYMBOL(i2s_codec_12Mhz);
  1060. +
  1061. +#if defined(CONFIG_RALINK_RT6855A)
  1062. + /* 8K 11.025k 12k 16k 22.05k 24k 32k 44.1K 48k 88.2k 96k */
  1063. +unsigned long i2s_inclk_int[11] = { 97, 70, 65, 48, 35, 32, 24, 17, 16, 12, 8};
  1064. +unsigned long i2s_inclk_comp[11] = { 336, 441, 53, 424, 220, 282, 212, 366, 141, 185, 70};
  1065. +#elif defined (CONFIG_RALINK_MT7621)
  1066. +#ifdef MT7621_ASIC_BOARD
  1067. +#if defined (CONFIG_I2S_MCLK_12P288MHZ)
  1068. +unsigned long i2s_inclk_int[11] = { 576, 384, 0, 288, 192, 192, 144, 96, 96, 48, 48};
  1069. +unsigned long i2s_inclk_comp[11] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  1070. +#elif defined(CONFIG_I2S_MCLK_12MHZ)
  1071. +unsigned long i2s_inclk_int[11] = {1171, 850, 0, 585, 425, 390, 292, 212, 195, 106, 97};
  1072. +unsigned long i2s_inclk_comp[11] = { 448, 174, 0, 480, 87, 320, 496, 299, 160, 149, 336};
  1073. +#endif
  1074. +#else //MT7621_FPGA_BOARD
  1075. +unsigned long i2s_inclk_int[11] = { 529, 384, 0, 264, 192, 176, 132, 96, 88, 48, 44};
  1076. +unsigned long i2s_inclk_comp[11] = { 102, 0, 0, 307, 0, 204, 153, 0, 102, 0, 51};
  1077. +#endif
  1078. +#elif defined (CONFIG_RALINK_MT7628)
  1079. +#ifdef MT7628_ASIC_BOARD
  1080. + /* 8K 11.025k 12k 16k 22.05k 24k 32k 44.1K 48k 88.2k 96k 176k 192k */
  1081. +unsigned long i2s_inclk_int_16bit[13] = {937, 680, 0, 468, 340, 312, 234, 170, 156, 85, 78, 42, 39};
  1082. +unsigned long i2s_inclk_comp_16bit[13]= {256, 139, 0, 384, 69, 256, 192, 34, 128, 17, 64, 267, 32};
  1083. +unsigned long i2s_inclk_int_24bit[13] = {625, 404, 0, 312, 226, 208, 156, 113, 104, 56, 52, 28, 26};
  1084. +unsigned long i2s_inclk_comp_24bit[13]= { 0, 404, 0, 256, 387, 170, 128, 193, 85, 352, 42, 176, 21};
  1085. +#else
  1086. + /* 8K 11.025k 12k 16k 22.05k 24k 32k 44.1K 48k 88.2k 96k 176k 192k */
  1087. +unsigned long i2s_inclk_int_16bit[13] = {468, 340, 0, 234, 170, 156, 117, 85, 78, 42, 39, 21, 19};
  1088. +unsigned long i2s_inclk_comp_16bit[13]= {384, 69, 0, 192, 34, 128, 96, 17, 64, 264, 32, 133, 272};
  1089. +unsigned long i2s_inclk_int_24bit[13] = {312, 202, 0, 156, 113, 104, 78, 56, 52, 28, 26, 14, 13};
  1090. +unsigned long i2s_inclk_comp_24bit[13]= {256, 202, 0, 128, 193, 85, 64, 352, 42, 176, 21, 88, 10};
  1091. +#endif
  1092. +#elif defined (CONFIG_ARCH_MT7623)
  1093. +#if defined MT7623_ASIC_BOARD
  1094. + /* 8K 11.025k 12k 16k 22.05k 24k 32k 44.1K 48k 88.2k 96k 176k 192k */
  1095. +unsigned long i2s_inclk_int_16bit[13] = {576, 384, 0, 288, 192, 192, 144, 96, 96, 48, 48, 24, 24};
  1096. +unsigned long i2s_inclk_comp_16bit[13]= { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  1097. +unsigned long i2s_inclk_int_24bit[13] = {384, 256, 0, 192, 128, 128, 96, 64, 64, 32, 32, 16, 16};
  1098. +unsigned long i2s_inclk_comp_24bit[13]= { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  1099. +#else
  1100. + /* 8K 11.025k 12k 16k 22.05k 24k 32k 44.1K 48k 88.2k 96k 176k 192k */
  1101. +unsigned long i2s_inclk_int_16bit[13] = {72, 48, 0, 36, 24, 24, 18, 12, 12, 6, 6, 3, 3};
  1102. +unsigned long i2s_inclk_comp_16bit[13]= { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  1103. +unsigned long i2s_inclk_int_24bit[13] = {48, 32, 0, 24, 16, 16, 12, 8, 8, 4, 4, 2, 2};
  1104. +unsigned long i2s_inclk_comp_24bit[13]= { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  1105. +#endif
  1106. +#else
  1107. + /* 8K 11.025k 12k 16k 22.05k 24k 32k 44.1K 48k 88.2k 96k */
  1108. +unsigned long i2s_inclk_int[11] = { 78, 56, 52, 39, 28, 26, 19, 14, 13, 9, 6};
  1109. +unsigned long i2s_inclk_comp[11] = { 64, 352, 42, 32, 176, 21, 272, 88, 10, 455, 261};
  1110. +#endif
  1111. +
  1112. +#if defined(CONFIG_I2S_WITH_AEC)
  1113. +aecFuncTbl_t *aecFuncP;
  1114. +#endif
  1115. +/* USB mode 22.05Khz register value in datasheet is 0x36 but will cause slow clock, 0x37 is correct value */
  1116. +/* USB mode 44.1Khz register value in datasheet is 0x22 but will cause slow clock, 0x23 is correct value */
  1117. +
  1118. +struct tasklet_struct i2s_tx_tasklet;
  1119. +struct tasklet_struct i2s_rx_tasklet;
  1120. +EXPORT_SYMBOL(i2s_tx_tasklet);
  1121. +EXPORT_SYMBOL(i2s_rx_tasklet);
  1122. +
  1123. +char test_buf[I2S_PAGE_SIZE];
  1124. +char test_buf_1[I2S_PAGE_SIZE];
  1125. +char test_buf_2[I2S_PAGE_SIZE];
  1126. +
  1127. +static const struct file_operations i2s_fops = {
  1128. + owner : THIS_MODULE,
  1129. + mmap : i2s_mmap,
  1130. + open : i2s_open,
  1131. + release : i2s_release,
  1132. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,35)
  1133. + unlocked_ioctl: i2s_ioctl,
  1134. +#else
  1135. + ioctl : i2s_ioctl,
  1136. +#endif
  1137. +};
  1138. +
  1139. +int __init i2s_mod_init(void)
  1140. +{
  1141. + int result;
  1142. +
  1143. + _printk("******* i2s module init **********\n");
  1144. + /* register device with kernel */
  1145. +#ifdef CONFIG_DEVFS_FS
  1146. + if(devfs_register_chrdev(i2sdrv_major, I2SDRV_DEVNAME , &i2s_fops)) {
  1147. + _printk(KERN_WARNING " i2s: can't create device node - %s\n", I2SDRV_DEVNAME);
  1148. + return -EIO;
  1149. + }
  1150. +
  1151. + devfs_handle = devfs_register(NULL, I2SDRV_DEVNAME, DEVFS_FL_DEFAULT, i2sdrv_major, 0,
  1152. + S_IFCHR | S_IRUGO | S_IWUGO, &i2s_fops, NULL);
  1153. +#else
  1154. + result = register_chrdev(i2sdrv_major, I2SDRV_DEVNAME, &i2s_fops);
  1155. + if (result < 0) {
  1156. + _printk(KERN_WARNING "i2s: can't get major %d\n",i2sdrv_major);
  1157. + return result;
  1158. + }
  1159. +
  1160. + if (i2sdrv_major == 0) {
  1161. + i2sdrv_major = result; /* dynamic */
  1162. + }
  1163. +#endif
  1164. +
  1165. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,35)
  1166. +#else
  1167. + i2smodule_class=class_create(THIS_MODULE, I2SDRV_DEVNAME);
  1168. + if (IS_ERR(i2smodule_class))
  1169. + return -EFAULT;
  1170. + device_create(i2smodule_class, NULL, MKDEV(i2sdrv_major, 0), I2SDRV_DEVNAME);
  1171. +#endif
  1172. +
  1173. +#if defined(CONFIG_I2S_WITH_AEC)
  1174. + _printk("AEC FuncP init \n");
  1175. + /*Add by mtk04880*/
  1176. + aecFuncP = kmalloc(sizeof(aecFuncTbl_t), GFP_KERNEL);
  1177. + /*If aecFuncP cannot request memory,it will be ignored in I2S module. Since AEC & I2S are independent
  1178. + * when AEC module is inserted,It will return err message (but I2S will keep running without AEC support)
  1179. + * */
  1180. + if(aecFuncP){
  1181. + memset(aecFuncP,0,sizeof(aecFuncTbl_t));
  1182. + }
  1183. +#endif
  1184. +
  1185. + return 0;
  1186. +}
  1187. +
  1188. +void i2s_mod_exit(void)
  1189. +{
  1190. + _printk("************ i2s module exit *************\n");
  1191. +#ifdef CONFIG_DEVFS_FS
  1192. + devfs_unregister_chrdev(i2sdrv_major, I2SDRV_DEVNAME);
  1193. + devfs_unregister(devfs_handle);
  1194. +#else
  1195. + unregister_chrdev(i2sdrv_major, I2SDRV_DEVNAME);
  1196. +#endif
  1197. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,35)
  1198. +#else
  1199. + device_destroy(i2smodule_class,MKDEV(i2sdrv_major, 0));
  1200. + class_destroy(i2smodule_class);
  1201. +#endif
  1202. + return ;
  1203. +}
  1204. +
  1205. +
  1206. +int i2s_open(struct inode *inode, struct file *filp)
  1207. +{
  1208. +#if defined(I2S_HW_INTERRUPT_EN)&&(I2S_SW_IRQ_EN)
  1209. + int Ret;
  1210. +#endif
  1211. + int minor = iminor(inode);
  1212. +
  1213. + if (minor >= I2S_MAX_DEV)
  1214. + return -ENODEV;
  1215. +
  1216. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
  1217. + MOD_INC_USE_COUNT;
  1218. +#else
  1219. + try_module_get(THIS_MODULE);
  1220. +#endif
  1221. +
  1222. + if (filp->f_flags & O_NONBLOCK) {
  1223. + MSG("filep->f_flags O_NONBLOCK set\n");
  1224. + return -EAGAIN;
  1225. + }
  1226. +
  1227. + /* set i2s_config */
  1228. + filp->private_data = pi2s_config;
  1229. + memset(pi2s_config, 0, sizeof(i2s_config_type));
  1230. +#ifdef I2S_STATISTIC
  1231. + memset(pi2s_status, 0, sizeof(i2s_status_type));
  1232. +#endif
  1233. + i2s_param_init(pi2s_config);
  1234. +
  1235. +#if defined(I2S_HW_INTERRUPT_EN)&&(I2S_SW_IRQ_EN)
  1236. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,35)
  1237. + Ret = request_irq(SURFBOARDINT_I2S, i2s_irq_isr, IRQF_DISABLED, "Ralink_I2S", NULL);
  1238. +#else
  1239. + Ret = request_irq(SURFBOARDINT_I2S, i2s_irq_isr, SA_INTERRUPT, "Ralink_I2S", NULL);
  1240. +#endif
  1241. +
  1242. + if(Ret){
  1243. + MSG("IRQ %d is not free.\n", SURFBOARDINT_I2S);
  1244. + i2s_release(inode, filp);
  1245. + return -1;
  1246. + }
  1247. +#endif
  1248. +
  1249. + init_waitqueue_head(&(pi2s_config->i2s_tx_qh));
  1250. + init_waitqueue_head(&(pi2s_config->i2s_rx_qh));
  1251. + spin_lock_init(&pi2s_config->lock);
  1252. +
  1253. + return 0;
  1254. +}
  1255. +
  1256. +
  1257. +static int i2s_release(struct inode *inode, struct file *filp)
  1258. +{
  1259. + i2s_config_type* ptri2s_config;
  1260. +
  1261. + /* decrement usage count */
  1262. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
  1263. + MOD_DEC_USE_COUNT;
  1264. +#else
  1265. + module_put(THIS_MODULE);
  1266. +#endif
  1267. +
  1268. +#if defined(I2S_HW_INTERRUPT_EN)&&(I2S_SW_IRQ_EN)
  1269. + free_irq(SURFBOARDINT_I2S, NULL);
  1270. +#endif
  1271. +
  1272. + ptri2s_config = filp->private_data;
  1273. + if(ptri2s_config==NULL)
  1274. + goto EXIT;
  1275. +#ifdef CONFIG_I2S_MMAP
  1276. + i2s_mem_unmap(ptri2s_config);
  1277. +#else
  1278. + i2s_txbuf_free(ptri2s_config);
  1279. + i2s_rxbuf_free(ptri2s_config);
  1280. +#endif
  1281. + /* free buffer */
  1282. + i2s_txPagebuf_free(ptri2s_config);
  1283. + i2s_rxPagebuf_free(ptri2s_config);
  1284. +EXIT:
  1285. + MSG("i2s_release succeeds\n");
  1286. + return 0;
  1287. +}
  1288. +
  1289. +int i2s_mmap_alloc(unsigned long size)
  1290. +{
  1291. + int i;
  1292. + u32 page_size;
  1293. + int first_index;
  1294. +
  1295. + page_size = I2S_PAGE_SIZE;
  1296. +
  1297. + if ((pi2s_config->mmap_index == 0) || (pi2s_config->mmap_index == MAX_I2S_PAGE))
  1298. + {
  1299. + MSG("mmap_index=%d\n", pi2s_config->mmap_index);
  1300. +
  1301. + first_index = pi2s_config->mmap_index;
  1302. + pi2s_config->pMMAPBufPtr[pi2s_config->mmap_index] = kmalloc(size, GFP_DMA);
  1303. + i2s_mmap_addr[pi2s_config->mmap_index] = (dma_addr_t)dma_map_single(NULL, pi2s_config->pMMAPBufPtr[pi2s_config->mmap_index], size, DMA_BIDIRECTIONAL);
  1304. +
  1305. + if( pi2s_config->pMMAPBufPtr[pi2s_config->mmap_index] == NULL )
  1306. + {
  1307. + MSG("i2s_mmap failed\n");
  1308. + return -1;
  1309. + }
  1310. + }
  1311. + else
  1312. + {
  1313. + _printk("illegal index:%d\n", pi2s_config->mmap_index);
  1314. + return -1;
  1315. + }
  1316. +
  1317. + _printk("MMAP[%d]=0x%08X, i2s_mmap_addr[%d]=0x%08x\n",
  1318. + pi2s_config->mmap_index, (u32)pi2s_config->pMMAPBufPtr[pi2s_config->mmap_index],
  1319. + pi2s_config->mmap_index, i2s_mmap_addr[pi2s_config->mmap_index]);
  1320. +
  1321. + memset(pi2s_config->pMMAPBufPtr[pi2s_config->mmap_index], 0, size);
  1322. + pi2s_config->mmap_index++;
  1323. +
  1324. + for (i=1; i<MAX_I2S_PAGE; i++)
  1325. + {
  1326. + i2s_mmap_addr[pi2s_config->mmap_index] = i2s_mmap_addr[first_index] + i*page_size;
  1327. + pi2s_config->pMMAPBufPtr[pi2s_config->mmap_index] = pi2s_config->pMMAPBufPtr[first_index] + i*page_size;
  1328. +
  1329. + _printk("MMAP[%d]=0x%08X, i2s_mmap_addr[%d]=0x%08x\n",pi2s_config->mmap_index, (u32)pi2s_config->pMMAPBufPtr[pi2s_config->mmap_index], pi2s_config->mmap_index, i2s_mmap_addr[pi2s_config->mmap_index]);
  1330. +
  1331. + /* Notice: The last mmap_index's value should be MAX_I2S_PAGE or MAX_I2S_PAGE*2 */
  1332. + pi2s_config->mmap_index++;
  1333. + }
  1334. +
  1335. + return 0;
  1336. +}
  1337. +
  1338. +int i2s_mmap_remap(struct vm_area_struct *vma, unsigned long size)
  1339. +{
  1340. + int nRet;
  1341. +
  1342. + if((pi2s_config->pMMAPBufPtr[0]!=NULL) && (pi2s_config->mmap_index == MAX_I2S_PAGE))
  1343. + {
  1344. + MSG("i2s_mmap_remap:0\n");
  1345. + nRet = remap_pfn_range(vma, vma->vm_start, virt_to_phys((void *)pi2s_config->pMMAPBufPtr[0]) >> PAGE_SHIFT, size, vma->vm_page_prot);
  1346. +
  1347. + if( nRet != 0 )
  1348. + {
  1349. + _printk("i2s_mmap->remap_pfn_range failed\n");
  1350. + return -EIO;
  1351. + }
  1352. + }
  1353. +
  1354. + if((pi2s_config->pMMAPBufPtr[MAX_I2S_PAGE]!=NULL) && (pi2s_config->mmap_index == MAX_I2S_PAGE*2))
  1355. + {
  1356. + MSG("i2s_mmap_remap:%d\n", MAX_I2S_PAGE);
  1357. +
  1358. + nRet = remap_pfn_range(vma, vma->vm_start, virt_to_phys((void *)pi2s_config->pMMAPBufPtr[MAX_I2S_PAGE]) >> PAGE_SHIFT, size, vma->vm_page_prot);
  1359. +
  1360. + if( nRet != 0 )
  1361. + {
  1362. + _printk("i2s_mmap->remap_pfn_range failed\n");
  1363. + return -EIO;
  1364. + }
  1365. + }
  1366. +
  1367. + return 0;
  1368. +}
  1369. +
  1370. +static int i2s_mmap(struct file *filp, struct vm_area_struct *vma)
  1371. +{
  1372. + unsigned long size = vma->vm_end-vma->vm_start;
  1373. + _printk("page_size=%d, ksize=%lu\n", I2S_PAGE_SIZE, size);
  1374. +
  1375. + if((pi2s_config->pMMAPBufPtr[0]==NULL)&&(pi2s_config->mmap_index!=0))
  1376. + pi2s_config->mmap_index = 0;
  1377. +
  1378. + _printk("%s: vm_start=%08X,vm_end=%08X\n", __func__, (u32)vma->vm_start, (u32)vma->vm_end);
  1379. +
  1380. + /* Do memory allocate and dma sync */
  1381. + i2s_mmap_alloc(size);
  1382. +
  1383. + i2s_mmap_remap(vma, size);
  1384. +
  1385. +
  1386. + return 0;
  1387. +}
  1388. +
  1389. +int i2s_mem_unmap(i2s_config_type* ptri2s_config)
  1390. +{
  1391. + u32 page_size;
  1392. +
  1393. + page_size = I2S_PAGE_SIZE;
  1394. +
  1395. + if(ptri2s_config->pMMAPBufPtr[0])
  1396. + {
  1397. + _printk("ummap MMAP[0]=0x%08X\n", (u32)ptri2s_config->pMMAPBufPtr[0]);
  1398. + dma_unmap_single(NULL, i2s_mmap_addr[0], MAX_I2S_PAGE*page_size, DMA_BIDIRECTIONAL);
  1399. + kfree(ptri2s_config->pMMAPBufPtr[0]);
  1400. + }
  1401. +
  1402. + if(ptri2s_config->pMMAPBufPtr[MAX_I2S_PAGE])
  1403. + {
  1404. + _printk("ummap MMAP[%d]=0x%08X\n", MAX_I2S_PAGE, (u32)ptri2s_config->pMMAPBufPtr[MAX_I2S_PAGE]);
  1405. + dma_unmap_single(NULL, i2s_mmap_addr[MAX_I2S_PAGE], MAX_I2S_PAGE*page_size, DMA_BIDIRECTIONAL);
  1406. + kfree(ptri2s_config->pMMAPBufPtr[MAX_I2S_PAGE]);
  1407. + }
  1408. +
  1409. + ptri2s_config->mmap_index = 0;
  1410. +
  1411. + return 0;
  1412. +}
  1413. +
  1414. +int i2s_param_init(i2s_config_type* ptri2s_config)
  1415. +{
  1416. + ptri2s_config->dmach = GDMA_I2S_TX0;
  1417. + ptri2s_config->tx_ff_thres = CONFIG_I2S_TFF_THRES;
  1418. + ptri2s_config->tx_ch_swap = CONFIG_I2S_CH_SWAP;
  1419. + ptri2s_config->rx_ff_thres = CONFIG_I2S_TFF_THRES;
  1420. + ptri2s_config->rx_ch_swap = CONFIG_I2S_CH_SWAP;
  1421. + ptri2s_config->slave_en = CONFIG_I2S_SLAVE_EN;
  1422. + ptri2s_config->codec_pll_en = CONFIG_I2S_CODEC_PLL_EN;
  1423. +
  1424. + ptri2s_config->bRxDMAEnable = 0;
  1425. + ptri2s_config->bTxDMAEnable = 0;
  1426. + //ptri2s_config->bALSAEnable = 0;
  1427. + ptri2s_config->srate = 44100;
  1428. + ptri2s_config->txvol = 0;
  1429. + ptri2s_config->rxvol = 0;
  1430. + ptri2s_config->lbk = 0;
  1431. + ptri2s_config->extlbk = 0;
  1432. + ptri2s_config->txrx_coexist = 0;
  1433. + ptri2s_config->wordlen_24b = 0;
  1434. +#if defined(CONFIG_RALINK_MT7628) || defined(CONFIG_ARCH_MT7623)
  1435. + ptri2s_config->sys_endian = 0;
  1436. + ptri2s_config->fmt = 0;
  1437. +#endif
  1438. + ptri2s_config->micboost = 0;
  1439. + ptri2s_config->micin = 0;
  1440. +
  1441. + return 0;
  1442. +}
  1443. +
  1444. +int i2s_txbuf_alloc(i2s_config_type* ptri2s_config)
  1445. +{
  1446. + int i;
  1447. +
  1448. + for( i = 0 ; i < MAX_I2S_PAGE ; i ++ )
  1449. + {
  1450. +#if defined(CONFIG_I2S_MMAP)
  1451. + ptri2s_config->pMMAPTxBufPtr[i] = ptri2s_config->pMMAPBufPtr[i];
  1452. +#else
  1453. + if(ptri2s_config->pMMAPTxBufPtr[i]==NULL)
  1454. + ptri2s_config->pMMAPTxBufPtr[i] = kmalloc(I2S_PAGE_SIZE, GFP_KERNEL);
  1455. +#endif
  1456. + memset(ptri2s_config->pMMAPTxBufPtr[i], 0, I2S_PAGE_SIZE);
  1457. + }
  1458. +
  1459. + return 0;
  1460. +}
  1461. +
  1462. +int i2s_rxbuf_alloc(i2s_config_type* ptri2s_config)
  1463. +{
  1464. + int i;
  1465. +
  1466. + for( i = 0 ; i < MAX_I2S_PAGE ; i ++ )
  1467. + {
  1468. +#if defined(CONFIG_I2S_MMAP)
  1469. + ptri2s_config->pMMAPRxBufPtr[i] = ptri2s_config->pMMAPBufPtr[i+(ptri2s_config->mmap_index-MAX_I2S_PAGE)];
  1470. +#else
  1471. + if(ptri2s_config->pMMAPRxBufPtr[i]==NULL)
  1472. + ptri2s_config->pMMAPRxBufPtr[i] = kmalloc(I2S_PAGE_SIZE, GFP_KERNEL);
  1473. +#endif
  1474. + memset(ptri2s_config->pMMAPRxBufPtr[i], 0, I2S_PAGE_SIZE);
  1475. + }
  1476. +
  1477. + return 0;
  1478. +}
  1479. +
  1480. +int i2s_txPagebuf_alloc(i2s_config_type* ptri2s_config)
  1481. +{
  1482. +#if defined(ARM_ARCH)
  1483. + ptri2s_config->pPage0TxBuf8ptr = (u8*)pci_alloc_consistent(NULL, I2S_PAGE_SIZE , &i2s_txdma_addr0);
  1484. + ptri2s_config->pPage1TxBuf8ptr = (u8*)pci_alloc_consistent(NULL, I2S_PAGE_SIZE , &i2s_txdma_addr1);
  1485. + if(ptri2s_config->pPage0TxBuf8ptr==NULL)
  1486. + {
  1487. + MSG("Allocate Tx Page0 Buffer Failed\n");
  1488. + return -1;
  1489. + }
  1490. + if(ptri2s_config->pPage1TxBuf8ptr==NULL)
  1491. + {
  1492. + MSG("Allocate Tx Page1 Buffer Failed\n");
  1493. + return -1;
  1494. + }
  1495. +#else
  1496. + ptri2s_config->pPage0TxBuf8ptr = (u8*)pci_alloc_consistent(NULL, I2S_PAGE_SIZE*2 , &i2s_txdma_addr);
  1497. + if(ptri2s_config->pPage0TxBuf8ptr==NULL)
  1498. + {
  1499. + MSG("Allocate Tx Page Buffer Failed\n");
  1500. + return -1;
  1501. + }
  1502. + ptri2s_config->pPage1TxBuf8ptr = ptri2s_config->pPage0TxBuf8ptr + I2S_PAGE_SIZE;
  1503. +#endif
  1504. + return 0;
  1505. +}
  1506. +
  1507. +int i2s_rxPagebuf_alloc(i2s_config_type* ptri2s_config)
  1508. +{
  1509. +#if defined(ARM_ARCH)
  1510. + ptri2s_config->pPage0RxBuf8ptr = (u8*)pci_alloc_consistent(NULL, I2S_PAGE_SIZE, &i2s_rxdma_addr0);
  1511. + ptri2s_config->pPage1RxBuf8ptr = (u8*)pci_alloc_consistent(NULL, I2S_PAGE_SIZE, &i2s_rxdma_addr1);
  1512. + if(ptri2s_config->pPage0RxBuf8ptr==NULL)
  1513. + {
  1514. + MSG("Allocate Rx Page Buffer Failed\n");
  1515. + return -1;
  1516. + }
  1517. + if(ptri2s_config->pPage1RxBuf8ptr==NULL)
  1518. + {
  1519. + MSG("Allocate Rx Page Buffer Failed\n");
  1520. + return -1;
  1521. + }
  1522. +#else
  1523. + ptri2s_config->pPage0RxBuf8ptr = (u8*)pci_alloc_consistent(NULL, I2S_PAGE_SIZE*2 , &i2s_rxdma_addr);
  1524. + if(ptri2s_config->pPage0RxBuf8ptr==NULL)
  1525. + {
  1526. + MSG("Allocate Rx Page Buffer Failed\n");
  1527. + return -1;
  1528. + }
  1529. + ptri2s_config->pPage1RxBuf8ptr = ptri2s_config->pPage0RxBuf8ptr + I2S_PAGE_SIZE;
  1530. +#endif
  1531. + return 0;
  1532. +}
  1533. +
  1534. +int i2s_txbuf_free(i2s_config_type* ptri2s_config)
  1535. +{
  1536. + int i;
  1537. +
  1538. + for(i = 0 ; i < MAX_I2S_PAGE ; i ++)
  1539. + {
  1540. + if(ptri2s_config->pMMAPTxBufPtr[i] != NULL)
  1541. + {
  1542. +#if defined(CONFIG_I2S_MMAP)
  1543. + ptri2s_config->pMMAPTxBufPtr[i] = NULL;
  1544. +#else
  1545. + kfree(ptri2s_config->pMMAPTxBufPtr[i]);
  1546. + ptri2s_config->pMMAPTxBufPtr[i] = NULL;
  1547. +#endif
  1548. + }
  1549. + }
  1550. + return 0;
  1551. +}
  1552. +
  1553. +int i2s_rxbuf_free(i2s_config_type* ptri2s_config)
  1554. +{
  1555. + int i;
  1556. +
  1557. + for(i = 0 ; i < MAX_I2S_PAGE ; i ++)
  1558. + {
  1559. + if(ptri2s_config->pMMAPRxBufPtr[i] != NULL)
  1560. + {
  1561. +#if defined(CONFIG_I2S_MMAP)
  1562. + ptri2s_config->pMMAPRxBufPtr[i] = NULL;
  1563. +#else
  1564. + kfree(ptri2s_config->pMMAPRxBufPtr[i]);
  1565. + ptri2s_config->pMMAPRxBufPtr[i] = NULL;
  1566. +#endif
  1567. + }
  1568. + }
  1569. +
  1570. + return 0;
  1571. +}
  1572. +
  1573. +int i2s_txPagebuf_free(i2s_config_type* ptri2s_config)
  1574. +{
  1575. +#if defined(ARM_ARCH)
  1576. + if (ptri2s_config->pPage0TxBuf8ptr)
  1577. + {
  1578. + pci_free_consistent(NULL, I2S_PAGE_SIZE, ptri2s_config->pPage0TxBuf8ptr, i2s_txdma_addr0);
  1579. + ptri2s_config->pPage0TxBuf8ptr = NULL;
  1580. + }
  1581. +
  1582. + if (ptri2s_config->pPage1TxBuf8ptr)
  1583. + {
  1584. + pci_free_consistent(NULL, I2S_PAGE_SIZE, ptri2s_config->pPage1TxBuf8ptr, i2s_txdma_addr1);
  1585. + ptri2s_config->pPage1TxBuf8ptr = NULL;
  1586. + }
  1587. + _printk("Free tx page buffer\n");
  1588. +#else
  1589. + if (ptri2s_config->pPage0TxBuf8ptr)
  1590. + {
  1591. + pci_free_consistent(NULL, I2S_PAGE_SIZE*2, ptri2s_config->pPage0TxBuf8ptr, i2s_txdma_addr);
  1592. + ptri2s_config->pPage0TxBuf8ptr = NULL;
  1593. + }
  1594. +#endif
  1595. + return 0;
  1596. +
  1597. +}
  1598. +
  1599. +int i2s_rxPagebuf_free(i2s_config_type* ptri2s_config)
  1600. +{
  1601. +#if defined(ARM_ARCH)
  1602. + if (ptri2s_config->pPage0RxBuf8ptr)
  1603. + {
  1604. + pci_free_consistent(NULL, I2S_PAGE_SIZE, ptri2s_config->pPage0RxBuf8ptr, i2s_rxdma_addr0);
  1605. + ptri2s_config->pPage0RxBuf8ptr = NULL;
  1606. + }
  1607. + if (ptri2s_config->pPage1RxBuf8ptr)
  1608. + {
  1609. + pci_free_consistent(NULL, I2S_PAGE_SIZE, ptri2s_config->pPage1RxBuf8ptr, i2s_rxdma_addr1);
  1610. + ptri2s_config->pPage1RxBuf8ptr = NULL;
  1611. + }
  1612. + _printk("Free rx page buffer\n");
  1613. +#else
  1614. + if (ptri2s_config->pPage0RxBuf8ptr)
  1615. + {
  1616. + pci_free_consistent(NULL, I2S_PAGE_SIZE*2, ptri2s_config->pPage0RxBuf8ptr, i2s_rxdma_addr);
  1617. + ptri2s_config->pPage0RxBuf8ptr = NULL;
  1618. + }
  1619. +#endif
  1620. + return 0;
  1621. +}
  1622. +
  1623. +int i2s_reset_tx_param(i2s_config_type* ptri2s_config)
  1624. +{
  1625. + ptri2s_config->tx_isr_cnt = 0;
  1626. + ptri2s_config->tx_w_idx = 0;
  1627. + ptri2s_config->tx_r_idx = 0;
  1628. + ptri2s_config->enLable = 0;
  1629. + ptri2s_config->tx_pause_en = 0;
  1630. + ptri2s_config->end_cnt = 0;
  1631. + ptri2s_config->tx_stop_cnt = 0;
  1632. +
  1633. +#ifdef I2S_STATISTIC
  1634. + pi2s_status->txbuffer_unrun = 0;
  1635. + pi2s_status->txbuffer_ovrun = 0;
  1636. + pi2s_status->txdmafault = 0;
  1637. + pi2s_status->txovrun = 0;
  1638. + pi2s_status->txunrun = 0;
  1639. + pi2s_status->txthres = 0;
  1640. + pi2s_status->txbuffer_len = 0;
  1641. +#endif
  1642. +
  1643. + return 0;
  1644. +}
  1645. +
  1646. +int i2s_reset_rx_param(i2s_config_type* ptri2s_config)
  1647. +{
  1648. + ptri2s_config->rx_isr_cnt = 0;
  1649. + ptri2s_config->rx_w_idx = 0;
  1650. + ptri2s_config->rx_r_idx = 0;
  1651. + ptri2s_config->enLable = 0;
  1652. + ptri2s_config->rx_pause_en = 0;
  1653. + ptri2s_config->rx_stop_cnt = 0;
  1654. +
  1655. +#ifdef I2S_STATISTIC
  1656. + pi2s_status->rxbuffer_unrun = 0;
  1657. + pi2s_status->rxbuffer_ovrun = 0;
  1658. + pi2s_status->rxdmafault = 0;
  1659. + pi2s_status->rxovrun = 0;
  1660. + pi2s_status->rxunrun = 0;
  1661. + pi2s_status->rxthres = 0;
  1662. + pi2s_status->rxbuffer_len = 0;
  1663. +#endif
  1664. +
  1665. + return 0;
  1666. +}
  1667. +#ifdef MT7621_ASIC_BOARD
  1668. +int i2s_pll_config_mt7621(unsigned long index)
  1669. +{
  1670. + unsigned long data;
  1671. + unsigned long regValue;
  1672. + bool xtal_20M_en = 0;
  1673. +// bool xtal_25M_en = 0;
  1674. + bool xtal_40M_en = 0;
  1675. +
  1676. + regValue = i2s_inw(RALINK_SYSCTL_BASE + 0x10);
  1677. + regValue = (regValue >> 6) & 0x7;
  1678. + if (regValue < 3)
  1679. + {
  1680. + xtal_20M_en = 1;
  1681. + MSG("Xtal is 20MHz. \n");
  1682. + }
  1683. + else if (regValue < 6)
  1684. + {
  1685. + xtal_40M_en = 1;
  1686. + MSG("Xtal is 40M.\n");
  1687. + }
  1688. + else
  1689. + {
  1690. + //xtal_25M_en = 1;
  1691. + MSG("Xtal is 25M.\n");
  1692. + }
  1693. +
  1694. +#if defined (CONFIG_I2S_MCLK_12P288MHZ)
  1695. + _printk("MT7621 provide 12.288M/11.298MHz REFCLK\n");
  1696. + /* Firstly, reset all required register to default value */
  1697. + i2s_outw(RALINK_ANA_CTRL_BASE, 0x00008000);
  1698. + i2s_outw(RALINK_ANA_CTRL_BASE+0x0014, 0x01001d61);//0x01401d61);
  1699. + i2s_outw(RALINK_ANA_CTRL_BASE+0x0018, 0x38233d0e);
  1700. + i2s_outw(RALINK_ANA_CTRL_BASE+0x001c, 0x80100004);//0x80120004);
  1701. + i2s_outw(RALINK_ANA_CTRL_BASE+0x0020, 0x1c7dbf48);
  1702. +
  1703. + /* toggle RG_XPTL_CHG */
  1704. + i2s_outw(RALINK_ANA_CTRL_BASE, 0x00008800);
  1705. + i2s_outw(RALINK_ANA_CTRL_BASE, 0x00008c00);
  1706. +
  1707. + data = i2s_inw(RALINK_ANA_CTRL_BASE+0x0014);
  1708. + data &= ~(0x0000ffc0);
  1709. + if ((xtal_40M_en) || (xtal_20M_en))
  1710. + {
  1711. + data |= REGBIT(0x1d, 8); /* for 40M or 20M */
  1712. + }
  1713. + else
  1714. + {
  1715. + data |= REGBIT(0x17, 8); /* for 25M */
  1716. + }
  1717. +
  1718. + if (xtal_40M_en)
  1719. + {
  1720. + data |= REGBIT(0x1, 6); /* for 40M */
  1721. + }
  1722. + i2s_outw(RALINK_ANA_CTRL_BASE+0x0014, data);
  1723. +
  1724. +
  1725. + data = i2s_inw(RALINK_ANA_CTRL_BASE+0x0018);
  1726. + data &= ~(0xf0773f00);
  1727. + data |= REGBIT(0x3, 28);
  1728. + data |= REGBIT(0x2, 20);
  1729. + if ((xtal_40M_en) || (xtal_20M_en))
  1730. + {
  1731. + data |= REGBIT(0x3, 16); /* for 40M or 20M */
  1732. + }
  1733. + else
  1734. + {
  1735. + data |= REGBIT(0x2, 16); /* for 25M */
  1736. + }
  1737. + data |= REGBIT(0x3, 12);
  1738. + if ((xtal_40M_en) || (xtal_20M_en))
  1739. + {
  1740. + data |= REGBIT(0xd, 8); /* for 40M or 20M */
  1741. + }
  1742. + else
  1743. + {
  1744. + data |= REGBIT(0x7, 8); /* for 25M */
  1745. + }
  1746. + i2s_outw(RALINK_ANA_CTRL_BASE+0x0018, data);
  1747. +
  1748. + if((index==1)|(index==4)|(index==7)|(index==9))// 270 MHz for 22.05K, 44.1K, 88.2K, 176.4K
  1749. + {
  1750. + if ((xtal_40M_en) || (xtal_20M_en))
  1751. + {
  1752. + i2s_outw(RALINK_ANA_CTRL_BASE+0x0020, 0x1a18548a); /* for 40M or 20M */
  1753. + }
  1754. + else
  1755. + {
  1756. + i2s_outw(RALINK_ANA_CTRL_BASE+0x0020, 0x14ad106e); /* for 25M */
  1757. + }
  1758. + }
  1759. + else if ((index==0)|(index==3)|(index==5)|(index==6)|(index==8)|(index==10))// 294 MHZ for 24K, 48K, 96K, 192K
  1760. + {
  1761. + if ((xtal_40M_en) || (xtal_20M_en))
  1762. + {
  1763. + i2s_outw(RALINK_ANA_CTRL_BASE+0x0020, 0x1c7dbf48); /* for 40M or 20M */
  1764. + }
  1765. + else
  1766. + {
  1767. + i2s_outw(RALINK_ANA_CTRL_BASE+0x0020, 0x1697cc39); /* for 25M */
  1768. + }
  1769. + }
  1770. + else if (index==2)
  1771. + {
  1772. + _printk("Not support 12KHz sampling rate!\n");
  1773. + return -1;
  1774. + }
  1775. + else
  1776. + {
  1777. + _printk("Wrong sampling rate!\n");
  1778. + return -1;
  1779. + }
  1780. +
  1781. + //*Common setting - Set PLLGP_CTRL_4 *//
  1782. + /* 1. Bit 31 */
  1783. + data = i2s_inw(RALINK_ANA_CTRL_BASE+0x001c);
  1784. + data &= ~(REGBIT(0x1, 31));
  1785. + i2s_outw(RALINK_ANA_CTRL_BASE+0x001c, data);
  1786. + ndelay(10);
  1787. +
  1788. + /* 2. Bit 0 */
  1789. + data = i2s_inw(RALINK_ANA_CTRL_BASE+0x001c);
  1790. + data |= REGBIT(0x1, 0);
  1791. + i2s_outw(RALINK_ANA_CTRL_BASE+0x001c, data);
  1792. + udelay(200);
  1793. +
  1794. + /* 3. Bit 3 */
  1795. + data = i2s_inw(RALINK_ANA_CTRL_BASE+0x001c);
  1796. + data |= REGBIT(0x1, 3);
  1797. + i2s_outw(RALINK_ANA_CTRL_BASE+0x001c, data);
  1798. + udelay(1);
  1799. +
  1800. + /* 4. Bit 8 */
  1801. + data = i2s_inw(RALINK_ANA_CTRL_BASE+0x001c);
  1802. + data |= REGBIT(0x1, 8);
  1803. + i2s_outw(RALINK_ANA_CTRL_BASE+0x001c, data);
  1804. + ndelay(40);
  1805. +
  1806. + /* 5. Bit 6 */
  1807. + data = i2s_inw(RALINK_ANA_CTRL_BASE+0x001c);
  1808. + data |= REGBIT(0x1, 6);
  1809. + i2s_outw(RALINK_ANA_CTRL_BASE+0x001c, data);
  1810. + ndelay(40);
  1811. +
  1812. + /* 6. Bit 5 & Bit 7*/
  1813. + data = i2s_inw(RALINK_ANA_CTRL_BASE+0x001c);
  1814. + data |= REGBIT(0x1, 5);
  1815. + data |= REGBIT(0x1, 7);
  1816. + i2s_outw(RALINK_ANA_CTRL_BASE+0x001c, data);
  1817. + udelay(1);
  1818. +
  1819. + /* 7. Bit 17 */
  1820. + data = i2s_inw(RALINK_ANA_CTRL_BASE+0x001c);
  1821. + data |= REGBIT(0x1, 17);
  1822. + i2s_outw(RALINK_ANA_CTRL_BASE+0x001c, data);
  1823. +
  1824. +#elif defined(CONFIG_I2S_MCLK_12MHZ)
  1825. + _printk("MT7621 provide 12MHz REFCLK\n");
  1826. + /* Firstly, reset all required register to default value */
  1827. + i2s_outw(RALINK_ANA_CTRL_BASE+0x0014, 0x01401d61);//0x01401d61);
  1828. + i2s_outw(RALINK_ANA_CTRL_BASE+0x001c, 0x80120004);//0x80100004);
  1829. + i2s_outw(RALINK_ANA_CTRL_BASE+0x0018, 0x38233d0e);
  1830. +
  1831. + if (xtal_40M_en)
  1832. + {
  1833. + data = i2s_inw(RALINK_ANA_CTRL_BASE+0x001c);
  1834. + data &= ~REGBIT(0x1, 17);
  1835. + i2s_outw(RALINK_ANA_CTRL_BASE+0x001c, data);
  1836. +
  1837. + data = i2s_inw(RALINK_ANA_CTRL_BASE+0x0014);
  1838. + data &= ~REGBIT(0x3, 4);
  1839. + data |= REGBIT(0x1, 4);
  1840. + i2s_outw(RALINK_ANA_CTRL_BASE+0x0014, data);
  1841. +
  1842. + data = i2s_inw(RALINK_ANA_CTRL_BASE+0x001c);
  1843. + data &= ~REGBIT(0x1, 31);
  1844. + i2s_outw(RALINK_ANA_CTRL_BASE+0x001c, data);
  1845. + }
  1846. + else if (xtal_20M_en)
  1847. + {
  1848. + data = i2s_inw(RALINK_ANA_CTRL_BASE+0x001c);
  1849. + data &= ~REGBIT(0x1, 17);
  1850. + i2s_outw(RALINK_ANA_CTRL_BASE+0x001c, data);
  1851. +
  1852. + data = i2s_inw(RALINK_ANA_CTRL_BASE+0x0014);
  1853. + data &= ~REGBIT(0x3, 6);
  1854. + i2s_outw(RALINK_ANA_CTRL_BASE+0x0014, data);
  1855. +
  1856. + data = i2s_inw(RALINK_ANA_CTRL_BASE+0x0014);
  1857. + data &= ~REGBIT(0x3, 4);
  1858. + data |= REGBIT(0x1, 4);
  1859. + i2s_outw(RALINK_ANA_CTRL_BASE+0x0014, data);
  1860. +
  1861. + data = i2s_inw(RALINK_ANA_CTRL_BASE+0x001c);
  1862. + data &= ~REGBIT(0x1, 31);
  1863. + i2s_outw(RALINK_ANA_CTRL_BASE+0x001c, data);
  1864. + }
  1865. + else
  1866. + {
  1867. + data = i2s_inw(RALINK_ANA_CTRL_BASE+0x001c);
  1868. + data &= ~REGBIT(0x1, 17);
  1869. + i2s_outw(RALINK_ANA_CTRL_BASE+0x001c, data);
  1870. +
  1871. + data = i2s_inw(RALINK_ANA_CTRL_BASE+0x0014);
  1872. + data &= ~REGBIT(0x7f, 8);
  1873. + data |= REGBIT(0x17, 8);
  1874. + i2s_outw(RALINK_ANA_CTRL_BASE+0x0014, data);
  1875. +
  1876. + data = i2s_inw(RALINK_ANA_CTRL_BASE+0x0014);
  1877. + data &= ~REGBIT(0x3, 6);
  1878. + i2s_outw(RALINK_ANA_CTRL_BASE+0x0014, data);
  1879. +
  1880. + data = i2s_inw(RALINK_ANA_CTRL_BASE+0x0018);
  1881. + data &= ~REGBIT(0x7, 16);
  1882. + data |= REGBIT(0x2, 16);
  1883. + i2s_outw(RALINK_ANA_CTRL_BASE+0x0018, data);
  1884. +
  1885. + data = i2s_inw(RALINK_ANA_CTRL_BASE+0x0018);
  1886. + data &= ~REGBIT(0xf, 8);
  1887. + data |= REGBIT(0x7, 8);
  1888. + i2s_outw(RALINK_ANA_CTRL_BASE+0x0018, data);
  1889. +
  1890. +
  1891. + data = i2s_inw(RALINK_ANA_CTRL_BASE+0x0014);
  1892. + data &= ~REGBIT(0x3, 4);
  1893. + data |= REGBIT(0x1, 4);
  1894. + i2s_outw(RALINK_ANA_CTRL_BASE+0x0014, data);
  1895. +
  1896. + data = i2s_inw(RALINK_ANA_CTRL_BASE+0x001c);
  1897. + data &= ~REGBIT(0x1, 31);
  1898. + i2s_outw(RALINK_ANA_CTRL_BASE+0x001c, data);
  1899. +
  1900. + }
  1901. +#endif
  1902. + return 0;
  1903. +}
  1904. +#if defined(CONFIG_I2S_IN_MCLK)
  1905. +int i2s_pll_refclk_set(void)
  1906. +{
  1907. + unsigned long data;
  1908. +
  1909. + /* Set APLL register for REFCLK */
  1910. + data = i2s_inw(RALINK_SYSCTL_BASE+0x90);
  1911. + data &= ~(0x0000f000);
  1912. + data |= REGBIT(0x1, 12);
  1913. + i2s_outw(RALINK_SYSCTL_BASE+0x0090, data);
  1914. +
  1915. + data = i2s_inw(RALINK_SYSCTL_BASE+0x0090);
  1916. + data &= ~(0x00000300);
  1917. + i2s_outw(RALINK_SYSCTL_BASE+0x0090, data);
  1918. + MSG("Set 0x90 register\n");
  1919. +
  1920. + return 0;
  1921. +}
  1922. +#endif
  1923. +#endif
  1924. +
  1925. +#ifdef MT7623_ASIC_BOARD
  1926. +int i2s_pll_config_mt7623(unsigned long index)
  1927. +{
  1928. + unsigned long data;
  1929. +
  1930. + /* xPLL PWR ON */
  1931. + data = i2s_inw(AUD2PLL_PWR_CON0);
  1932. + data |= 0x1;
  1933. + i2s_outw(AUD2PLL_PWR_CON0, data);
  1934. + udelay(5);
  1935. +
  1936. + /* xPLL ISO Disable */
  1937. + data = i2s_inw(AUD2PLL_PWR_CON0);
  1938. + data &= ~(0x2);
  1939. + i2s_outw(AUD2PLL_PWR_CON0, data);
  1940. +
  1941. + /* xPLL Frequency Set */
  1942. + data = i2s_inw(AUD2PLL_CON0);
  1943. + data |= 0x1;
  1944. + i2s_outw(AUD2PLL_CON0, data);
  1945. +
  1946. + /* AUD1PLL Frequency Set(change from 98.304MHz to 294.912MHz) */
  1947. + i2s_outw(AUD1PLL_CON0, 0x121);
  1948. + i2s_outw(AUD1PLL_CON1, 0xad5efee6);
  1949. + udelay(40);
  1950. +
  1951. + /* Audio clock setting */
  1952. + if((index==1)|(index==4)|(index==7)|(index==9)|(index==11))// for 22.05K, 44.1K, 88.2K, 176.4K
  1953. + {
  1954. + _printk("\n*****%s:index=%d(270MHz)*****\n", __func__, (int)index);
  1955. + data = i2s_inw(0xFB00002c);
  1956. + //data &= ~REGBIT(0x8, 1);
  1957. + data &= ~(0x80);
  1958. + i2s_outw(0xFB00002C, data); /* AUD1PLL 270.9204MHz */
  1959. + }
  1960. + else if ((index==0)|(index==3)|(index==5)|(index==6)|(index==8)|(index==10)|(index==12)) //for 24K, 48K, 96K, 192K
  1961. + {
  1962. + _printk("\n*****%s:index=%d(294MHz)*****\n", __func__, (int)index);
  1963. + data = i2s_inw(0xFB00002c);
  1964. + //data |= REGBIT(0x8, 1);
  1965. + data |= (0x80);
  1966. + i2s_outw(0xFB00002c, data); /* AUD1PLL 294.912MHz */
  1967. + }
  1968. + else if (index==2)
  1969. + {
  1970. + _printk("Not support 12KHz sampling rate!\n");
  1971. + return -1;
  1972. + }
  1973. + else
  1974. + {
  1975. + _printk("Wrong sampling rate!\n");
  1976. + return -1;
  1977. + }
  1978. + return 0;
  1979. +}
  1980. +#endif
  1981. +
  1982. +#if defined(MT7628_ASIC_BOARD) || defined(CONFIG_ARCH_MT7623)
  1983. +int i2s_driving_strength_adjust(void)
  1984. +{
  1985. +#if defined(MT7628_ASIC_BOARD)
  1986. + unsigned long data;
  1987. +
  1988. + MSG("Adjust MT7628 current's driving strngth\n");
  1989. + /* Adjust REFCLK0's driving strength of current which can avoid
  1990. + * the glitch of REFCKL0
  1991. + * E4 = 0xb0001354[5]; E8 = 0xb0001364[5]
  1992. + * (E4,E8)=(0,0)-> 4 mA;
  1993. + * =(1,0)-> 8 mA;
  1994. + * =(0,1)-> 12 mA;
  1995. + * =(1,1)-> 16 mA*/
  1996. +
  1997. + /* Set to 12mA */
  1998. + data = i2s_inw(0xb0001354);
  1999. + data &= ~(0x1<<5);
  2000. + i2s_outw(0xb0001354, data);
  2001. +
  2002. + data = i2s_inw(0xb0001364);
  2003. + data |= (0x1<<5);
  2004. + i2s_outw(0xb0001364, data);
  2005. +#endif
  2006. +#if defined(CONFIG_ARCH_MT7623)
  2007. + MSG("Adjust MT7623 current's driving strngth\n");
  2008. +
  2009. + i2s_outw(0xF0005F80, 0x7777);
  2010. +#endif
  2011. +
  2012. + return 0;
  2013. +}
  2014. +#endif
  2015. +
  2016. +#if defined(CONFIG_I2S_IN_MCLK)
  2017. +#if defined(CONFIG_I2S_MCLK_12MHZ)
  2018. +int i2s_refclk_12m_enable(void)
  2019. +{
  2020. + unsigned long data;
  2021. +
  2022. + MSG("Enable SoC MCLK 12Mhz\n");
  2023. +
  2024. +#if defined(CONFIG_RALINK_RT6855A)
  2025. + data = i2s_inw(RALINK_SYSCTL_BASE+0x860);
  2026. + data |= (0x1<<17);
  2027. + data &= ~(0x7<<18);
  2028. + data |= (0x1<<18);
  2029. + i2s_outw(RALINK_SYSCTL_BASE+0x860, data);
  2030. +#elif defined(CONFIG_RALINK_RT3350)
  2031. + data = i2s_inw(RALINK_SYSCTL_BASE+0x2c);
  2032. + data |= (0x1<<8);
  2033. + i2s_outw(RALINK_SYSCTL_BASE+0x2c, data);
  2034. +#elif defined(CONFIG_RALINK_RT3883)
  2035. + data = i2s_inw(RALINK_SYSCTL_BASE+0x2c);
  2036. + data &= ~(0x03<<13);
  2037. + data |= (0x1<<13);
  2038. + i2s_outw(RALINK_SYSCTL_BASE+0x2c, data);
  2039. +#elif defined(CONFIG_RALINK_RT3352)||defined(CONFIG_RALINK_RT5350) || defined (CONFIG_RALINK_RT6855)
  2040. + data = i2s_inw(RALINK_SYSCTL_BASE+0x2c);
  2041. + data &= ~(0x0F<<8);
  2042. + data |= (0x3<<8);
  2043. + i2s_outw(RALINK_SYSCTL_BASE+0x2c, data);
  2044. +#elif defined(CONFIG_RALINK_MT7620)
  2045. + data = i2s_inw(RALINK_SYSCTL_BASE+0x2c);
  2046. + data &= ~(0x07<<9);
  2047. + data |= (1<<9);
  2048. + i2s_outw(RALINK_SYSCTL_BASE+0x2c, data);
  2049. +#elif defined(CONFIG_RALINK_MT7621)
  2050. + data = i2s_inw(RALINK_SYSCTL_BASE+0x2c);
  2051. + data &= ~(0x1f<<18);
  2052. + data |= REGBIT(0x19, 18);
  2053. + data &= ~(0x1f<<12);
  2054. + data |= REGBIT(0x1, 12);
  2055. + data &= ~(0x7<<9);
  2056. + data |= REGBIT(0x5, 9);
  2057. + i2s_outw(RALINK_SYSCTL_BASE+0x2c, data);
  2058. +#elif defined(CONFIG_RALINK_MT7628)
  2059. + data = i2s_inw(RALINK_SYSCTL_BASE+0x2c);
  2060. + MSG("turn on REFCLK output for MCLK1\n");
  2061. + data &= ~(0x7<<9);
  2062. + data |= (0x1<<9); /* output for MCLK */
  2063. + i2s_outw(RALINK_SYSCTL_BASE+0x2c, data);
  2064. +#else
  2065. + #error "This SoC does not provide 12MHz clock to audio codec\n");
  2066. +#endif
  2067. + i2s_refclk_gpio_out_config();
  2068. +
  2069. + return 0;
  2070. +}
  2071. +#endif
  2072. +
  2073. +#if defined(CONFIG_I2S_MCLK_12P288MHZ)
  2074. +int i2s_refclk_12p288m_enable(void)
  2075. +{
  2076. + unsigned long data;
  2077. + MSG("Enable SoC MCLK 12.288Mhz\n");
  2078. +
  2079. +#if defined(CONFIG_RALINK_RT3352)||defined(CONFIG_RALINK_RT5350) || defined (CONFIG_RALINK_RT6855)
  2080. + data = i2s_inw(RALINK_SYSCTL_BASE+0x2c);
  2081. + data &= ~(0x01F<<18);
  2082. + data |= 31<<18;
  2083. + data &= ~(0x01F<<12);
  2084. + data |= 1<<12;
  2085. + data |= (0xF<<8);
  2086. + i2s_outw(RALINK_SYSCTL_BASE+0x2c, data);
  2087. +#elif defined(CONFIG_RALINK_MT7621)
  2088. + data = i2s_inw(RALINK_SYSCTL_BASE+0x2c);
  2089. + data &= ~(0x1f<<18);
  2090. + data |= REGBIT(0xc, 18);
  2091. + data &= ~(0x1f<<12);
  2092. + data |= REGBIT(0x1, 12);
  2093. + data &= ~(0x7<<9);
  2094. + data |= REGBIT(0x5, 9);
  2095. + i2s_outw(RALINK_SYSCTL_BASE+0x2c, data);
  2096. + _printk("MT7621 provide REFCLK 12.288MHz/11.289MHz\n");
  2097. +#elif defined(CONFIG_ARCH_MT7623)
  2098. + /* MT7623 does not need to set divider for REFCLK */
  2099. + /* GPIO126 - I2S0_MCLK */
  2100. + data = i2s_inw(0xF00058F0);
  2101. + data &= ~(0x7<<3);
  2102. + data |= (0x6<<3);
  2103. + i2s_outw(0xF00058F0, data);
  2104. + /* GPIO_DIR8: OUT */
  2105. + data = i2s_inw(0xF0005070);
  2106. + data |= (0x1<<14);
  2107. + i2s_outw(0xF0005070, data);
  2108. +#else
  2109. + #error "This SoC does not provide 12.288Mhz clock to audio codec\n");
  2110. +#endif
  2111. +
  2112. + return 0;
  2113. +}
  2114. +#endif
  2115. +
  2116. +#if defined(CONFIG_I2S_MCLK_18P432MHZ)
  2117. +int i2s_refclk_18p432m_enable(unsigned long index)
  2118. +{
  2119. + unsigned long data;
  2120. + MSG("Enable SoC MCLK 18.432MHz/16.934MHz");
  2121. +
  2122. + if((index==1)|(index==4)|(index==7)|(index==9))// 16.934MHz for 22.05K, 44.1K, 88.2K, 176.4K
  2123. + {
  2124. + data = i2s_inw(ETHDMASYS_SYSCTL_BASE+0x2c);
  2125. + data &= ~(0x1<<7);
  2126. + i2s_outw(ETHDMASYS_SYSCTL_BASE+0x2c, data);
  2127. + }
  2128. + else if((index==0)|(index==3)|(index==5)|(index==6)|(index==8)|(index==10))// 18.432MHZ for 24K, 48K, 96K, 192K
  2129. + {
  2130. + data = i2s_inw(ETHDMASYS_SYSCTL_BASE+0x2c);
  2131. + data |= (0x1<<7);
  2132. + i2s_outw(ETHDMASYS_SYSCTL_BASE+0x2c, data);
  2133. + }
  2134. +
  2135. + data = i2s_inw(ETHDMASYS_SYSCTL_BASE+0x30);
  2136. + data |= (0x1<<17);
  2137. + i2s_outw(ETHDMASYS_SYSCTL_BASE+0x30, data);
  2138. +
  2139. + return 0;
  2140. +}
  2141. +#endif
  2142. +#endif
  2143. +
  2144. +int i2s_refclk_disable(void)
  2145. +{
  2146. + unsigned long data;
  2147. +
  2148. +#if defined(CONFIG_RALINK_RT6855A)
  2149. + data = i2s_inw(RALINK_SYSCTL_BASE+0x860);
  2150. + data &= ~(1<<17);
  2151. + i2s_outw(RALINK_SYSCTL_BASE+0x860, data);
  2152. +#elif defined(CONFIG_RALINK_RT3350)
  2153. + data = i2s_inw(RALINK_SYSCTL_BASE+0x2c);
  2154. + data &= ~(0x1<<8);
  2155. + i2s_outw(RALINK_SYSCTL_BASE+0x2c, data);
  2156. +#elif defined(CONFIG_RALINK_RT3883)
  2157. + data = i2s_inw(RALINK_SYSCTL_BASE+0x2c);
  2158. + data &= ~(0x0F<<13);
  2159. + i2s_outw(RALINK_SYSCTL_BASE+0x2c, data);
  2160. +#elif defined(CONFIG_RALINK_RT3352)||defined(CONFIG_RALINK_RT5350)||defined (CONFIG_RALINK_RT6855)
  2161. + data = i2s_inw(RALINK_SYSCTL_BASE+0x2c);
  2162. + data &= ~(0x0F<<8);
  2163. + i2s_outw(RALINK_SYSCTL_BASE+0x2c, data);
  2164. +#elif defined (CONFIG_RALINK_MT7620)||defined (CONFIG_RALINK_MT7621)||defined (CONFIG_RALINK_MT7628)
  2165. + _printk("turn off REFCLK output from internal CLK\n");
  2166. + data = i2s_inw(RALINK_SYSCTL_BASE+0x2c);
  2167. + data &= ~(0x07<<9);
  2168. + i2s_outw(RALINK_SYSCTL_BASE+0x2c, data);
  2169. +#elif defined (CONFIG_ARCH_MT7623) /*FIXME:2*/
  2170. +#ifdef MT7623_ASIC_BOARD
  2171. + _printk("turn off REFCLK output from internal CLK\n");
  2172. + /* GPIO126 - I2S0_MCLK */
  2173. + data = i2s_inw(0xF00058F0);
  2174. + data &= ~(0x7<<3);
  2175. + //data |= (0x2<<3);
  2176. + i2s_outw(0xF00058F0, data);
  2177. + /* GPIO126 => GPIO_DIR8: IN */
  2178. + data = i2s_inw(0xF0005070);
  2179. + data &= ~(0x1<<14);
  2180. + i2s_outw(0xF0005070, data);
  2181. +#else
  2182. + _printk("turn off REFCLK output from internal CLK\n");
  2183. + data = i2s_inw(ETHDMASYS_SYSCTL_BASE+0x30);
  2184. + data &= ~(0x1<<17);
  2185. + i2s_outw(ETHDMASYS_SYSCTL_BASE+0x30, data);
  2186. +#endif
  2187. +#endif
  2188. + return 0;
  2189. +}
  2190. +
  2191. +int i2s_refclk_gpio_out_config(void)
  2192. +{
  2193. +#ifndef CONFIG_ARCH_MT7623
  2194. + unsigned long data; /* FIXME */
  2195. +#endif
  2196. +
  2197. + /* Set REFCLK GPIO pin as REFCLK mode*/
  2198. +#if defined(CONFIG_RALINK_MT7620)
  2199. + data = i2s_inw(RALINK_SYSCTL_BASE+0x60);
  2200. + data &= ~(0x03<<21); /* WDT */
  2201. + data |= (1<<21);
  2202. + //data &= ~(0x03<<16); /* PERST */
  2203. + //data |= (1<<16);
  2204. + i2s_outw(RALINK_SYSCTL_BASE+0x60, data);
  2205. +#endif
  2206. +#if defined(CONFIG_RALINK_MT7621)
  2207. + data = i2s_inw(RALINK_SYSCTL_BASE+0x60);
  2208. + //data &= ~(0x3<<10); /* PERST */
  2209. + //data |= (0x2<<10);
  2210. + data &= ~(0x3<<8); /* WDT */
  2211. + data |= (0x2<<8);
  2212. + i2s_outw(RALINK_SYSCTL_BASE+0x60, data);
  2213. + MSG("Set 0x60 register\n");
  2214. +#endif
  2215. +#if defined(CONFIG_RALINK_MT7628)
  2216. + data = i2s_inw(RALINK_SYSCTL_BASE+0x60);
  2217. + data &= ~(0x1<<18);
  2218. + i2s_outw(RALINK_SYSCTL_BASE+0x60, data);
  2219. +#endif
  2220. +
  2221. + return 0;
  2222. +}
  2223. +
  2224. +int i2s_refclk_gpio_in_config(void)
  2225. +{
  2226. +#ifndef CONFIG_ARCH_MT7623
  2227. + unsigned long data; /* FIXME */
  2228. +#endif
  2229. +
  2230. +#if defined (CONFIG_RALINK_MT7620)
  2231. + data = i2s_inw(RALINK_SYSCTL_BASE+0x60);
  2232. + data &= ~(0x03<<21); /* WDT */
  2233. + data |= (1<<21);
  2234. + //data &= ~(0x03<<16); /* PERST */
  2235. + //data |= (1<<16);
  2236. + i2s_outw(RALINK_SYSCTL_BASE+0x60, data);
  2237. +
  2238. + data = i2s_inw(RALINK_PIO_BASE);
  2239. + data &= ~(0x1<<17); /* GPIO share ping 17 for WDT */
  2240. + i2s_outw(RALINK_PIO_BASE, data);
  2241. +
  2242. + //data = i2s_inw(RALINK_PIO_BASE+0x04);
  2243. + //data &= ~(0x1<<4); /* GPIO share ping 36 for PERST */
  2244. + //i2s_outw(RALINK_PIO_BASE+0x04, data);
  2245. +#endif
  2246. +#if defined (CONFIG_RALINK_MT7621)
  2247. + data = i2s_inw(RALINK_SYSCTL_BASE+0x60);
  2248. + //data &= ~(0x3<<10); /* PERST */
  2249. + //data |= (0x1<<10);
  2250. + data &= ~(0x3<<8); /* WDT */
  2251. + data |= (0x1<<8);
  2252. + i2s_outw(RALINK_SYSCTL_BASE+0x60, data);
  2253. +
  2254. + data = i2s_inw(RALINK_PIO_BASE);
  2255. + //data &= ~(0x1<<19); /* GPIO share ping 19 for RERST */
  2256. + data &= ~(0x1<<18); /* GPIO share ping 18 for WDT */
  2257. + i2s_outw(RALINK_PIO_BASE, data);
  2258. +#endif
  2259. +#if defined (CONFIG_RALINK_MT7628)
  2260. + /* To use external OSC, set REFCLK_GPIO ping as GPIO mode and set it as input direction */
  2261. + data = i2s_inw(RALINK_SYSCTL_BASE+0x60);
  2262. + data |= (0x1<<18);
  2263. + i2s_outw(RALINK_SYSCTL_BASE+0x60, data);
  2264. +
  2265. + data = i2s_inw(RALINK_PIO_BASE+0x04);
  2266. + data &= ~(0x1<<5); /* GPIO share ping 37*/
  2267. + i2s_outw(RALINK_PIO_BASE+0x04, data);
  2268. +#endif
  2269. +
  2270. + return 0;
  2271. +}
  2272. +
  2273. +int i2s_slave_clock_gpio_in_mt7623(void)
  2274. +{
  2275. + unsigned long data;
  2276. +
  2277. + /* GPIO74(I2S0_BCLK)=>GPIO_DIR5: IN */
  2278. + data = i2s_inw(0xF0005040);
  2279. + data &= ~(0x1<<10);
  2280. + i2s_outw(0xF0005040, data);
  2281. +
  2282. + /* GPIO73(I2S0_LRCK)=>GPIO_DIR5: IN */
  2283. + data = i2s_inw(0xF0005040);
  2284. + data &= ~(0x1<<9);
  2285. + i2s_outw(0xF0005040, data);
  2286. +
  2287. + _printk("i2s_slave_clock_gpio_in_mt7623\n");
  2288. +
  2289. + return 0;
  2290. +}
  2291. +
  2292. +int i2s_master_clock_gpio_out_mt7623(void)
  2293. +{
  2294. + unsigned long data;
  2295. +
  2296. + /* GPIO74(I2S0_BCLK)=>GPIO_DIR5: OUT */
  2297. + data = i2s_inw(0xF0005040);
  2298. + data |= (0x1<<10);
  2299. + i2s_outw(0xF0005040, data);
  2300. +
  2301. + /* GPIO73(I2S0_LRCK)=>GPIO_DIR5: OUT */
  2302. + data = i2s_inw(0xF0005040);
  2303. + data |= (0x1<<9);
  2304. + i2s_outw(0xF0005040, data);
  2305. +
  2306. + _printk("i2s_master_clock_gpio_out_mt7623\n");
  2307. +
  2308. + return 0;
  2309. +}
  2310. +
  2311. +int i2s_share_pin_mt7623(i2s_config_type* ptri2s_config)
  2312. +{
  2313. + unsigned long data;
  2314. +
  2315. + _printk("\nConfig MT7623 I2S pinmux\n");
  2316. + /* GPIO74 - I2S0_BCLK */
  2317. + data = i2s_inw(0xF0005840);
  2318. + data &= ~(0x7<<12);
  2319. + data |= (0x6<<12);
  2320. + i2s_outw(0xF0005840, data);
  2321. +
  2322. + /* GPIO73 - I2S0_LRCK */
  2323. + data = i2s_inw(0xF0005840);
  2324. + data &= ~(0x7<<9);
  2325. + data |= (0x6<<9);
  2326. + i2s_outw(0xF0005840, data);
  2327. +
  2328. + if(ptri2s_config->slave_en==0)
  2329. + i2s_master_clock_gpio_out_mt7623();
  2330. + else
  2331. + i2s_slave_clock_gpio_in_mt7623();
  2332. +
  2333. + /* GPIO49 - I2S0_DATA */
  2334. + data = i2s_inw(0xF00057F0);
  2335. + data &= ~(0x7<<12);
  2336. + data |= (0x6<<12);
  2337. + i2s_outw(0xF00057F0, data);
  2338. + /* GPIO_DIR4: OUT */
  2339. + data = i2s_inw(0xF0005030);
  2340. + data |= (0x1<<1);
  2341. + i2s_outw(0xF0005030, data);
  2342. +
  2343. + /* GPIO72 - I2S0_DATA_IN */
  2344. + data = i2s_inw(0xF0005840);
  2345. + data &= ~(0x7<<6);
  2346. + data |= (0x6<<6);
  2347. + i2s_outw(0xF0005840, data);
  2348. + /* GPIO_DIR5: IN */
  2349. + data = i2s_inw(0xF0005040);
  2350. + data &= ~(0x1<<8);
  2351. + i2s_outw(0xF0005040, data);
  2352. +
  2353. + return 0;
  2354. +}
  2355. +
  2356. +int i2s_share_pin_config(i2s_config_type* ptri2s_config)
  2357. +{
  2358. +#ifndef CONFIG_ARCH_MT7623
  2359. + unsigned long data; /*FIXME*/
  2360. +#endif
  2361. +
  2362. + /* set share pins to i2s/gpio mode and i2c mode */
  2363. +#if defined(CONFIG_RALINK_RT6855A)
  2364. + data = i2s_inw(RALINK_SYSCTL_BASE+0x860);
  2365. + data |= 0x00008080;
  2366. + i2s_outw(RALINK_SYSCTL_BASE+0x860, data);
  2367. +#elif defined(CONFIG_RALINK_MT7621)
  2368. + data = i2s_inw(RALINK_SYSCTL_BASE+0x60);
  2369. + data &= 0xFFFFFFE3;
  2370. + data |= 0x00000010;
  2371. + i2s_outw(RALINK_SYSCTL_BASE+0x60, data);
  2372. +#elif defined(CONFIG_RALINK_MT7628)
  2373. + data = i2s_inw(RALINK_SYSCTL_BASE+0x60);
  2374. + data &= ~(0x3<<6); /* I2S_MODE */
  2375. + data &= ~(0x3<<20); /* I2C_MODE */
  2376. + i2s_outw(RALINK_SYSCTL_BASE+0x60, data);
  2377. +#elif defined(CONFIG_ARCH_MT7623)
  2378. + i2s_share_pin_mt7623(ptri2s_config);
  2379. +#else
  2380. + data = i2s_inw(RALINK_SYSCTL_BASE+0x60);
  2381. + data &= 0xFFFFFFE2;
  2382. + data |= 0x00000018;
  2383. + i2s_outw(RALINK_SYSCTL_BASE+0x60, data);
  2384. +#endif
  2385. + return 0;
  2386. +}
  2387. +
  2388. +int i2s_ws_config(i2s_config_type* ptri2s_config, unsigned long index)
  2389. +{
  2390. + unsigned long data;
  2391. + unsigned long* pTable;
  2392. +
  2393. +#if defined(CONFIG_I2S_IN_CLK)
  2394. + /* REFCLK is 15.625Mhz or 40Mhz(fractional division) */
  2395. +#if defined(CONFIG_I2S_FRAC_DIV)
  2396. + MSG("Internal REFCLK with fractional division\n");
  2397. +#if defined(CONFIG_RALINK_MT7628) || defined(CONFIG_ARCH_MT7623)
  2398. + if (ptri2s_config->wordlen_24b == 1)
  2399. + {
  2400. + MSG("24 bit int table\n");
  2401. + pTable = i2s_inclk_int_24bit;
  2402. + }
  2403. + else
  2404. + {
  2405. + MSG("16 bit int table\n");
  2406. + pTable = i2s_inclk_int_16bit;
  2407. + }
  2408. +#else
  2409. + pTable = i2s_inclk_int;
  2410. +#endif /* CONFIG_RALINK_MT7628 */
  2411. +
  2412. + data = (unsigned long)(pTable[index]);
  2413. + i2s_outw(I2S_DIVINT_CFG, data);
  2414. +
  2415. +#if defined(CONFIG_RALINK_MT7628) || defined(CONFIG_ARCH_MT7623)
  2416. + if (ptri2s_config->wordlen_24b == 1)
  2417. + {
  2418. + MSG("24 bit comp table\n");
  2419. + pTable = i2s_inclk_comp_24bit;
  2420. + }
  2421. + else
  2422. + {
  2423. + MSG("16 bit comp table\n");
  2424. + pTable = i2s_inclk_comp_16bit;
  2425. + }
  2426. +#else
  2427. + pTable = i2s_inclk_comp;
  2428. +#endif /* CONFIG_RALINK_MT7628 */
  2429. +
  2430. + data = (unsigned long)(pTable[index]);
  2431. + data |= REGBIT(1, I2S_CLKDIV_EN);
  2432. + i2s_outw(I2S_DIVCOMP_CFG, data);
  2433. +#else
  2434. + MSG("Internal REFCLK 15.625Mhz \n");
  2435. + pTable = i2s_inclk_15p625Mhz;
  2436. + data = i2s_inw(RALINK_SYSCTL_BASE+0x30);
  2437. + data &= 0xFFFF00FF;
  2438. + data |= (unsigned long)(pTable[index]);
  2439. + data |= 0x00008000;
  2440. + i2s_outw(RALINK_SYSCTL_BASE+0x30, data);
  2441. +#endif /* CONFIG_I2S_FRAC_DIV */
  2442. +#else
  2443. +#if defined(CONFIG_I2S_MCLK_12MHZ)
  2444. + /* REFCLK = MCLK = 12Mhz */
  2445. + MSG("External REFCLK 12Mhz \n");
  2446. + pTable = i2s_exclk_12Mhz;
  2447. + data = i2s_inw(RALINK_SYSCTL_BASE+0x30);
  2448. + data &= 0xFFFF00FF;
  2449. + data |= (unsigned long)(pTable[index]);
  2450. + data |= 0x0000C000;
  2451. + i2s_outw(RALINK_SYSCTL_BASE+0x30, data);
  2452. +#else
  2453. + /* REFCLK = MCLK = 12.288Mhz */
  2454. + pTable = i2s_exclk_12p288Mhz;
  2455. + MSG("External REFCLK 12.288Mhz \n");
  2456. + data = i2s_inw(RALINK_SYSCTL_BASE+0x30);
  2457. + data &= 0xFFFF00FF;
  2458. + data |= (unsigned long)(pTable[index]);
  2459. + data |= 0x0000C000;
  2460. + i2s_outw(RALINK_SYSCTL_BASE+0x30, data);
  2461. +#endif /* CONFIG_I2S_MCLK_12MHZ */
  2462. +#endif /* Not CONFIG_I2S_IN_CLK */
  2463. +
  2464. +#if defined(CONFIG_I2S_WS_EDGE)
  2465. + data = i2s_inw(I2S_I2SCFG);
  2466. + data |= REGBIT(0x1, I2S_WS_INV);
  2467. + i2s_outw(I2S_I2SCFG, data);
  2468. +#endif
  2469. +
  2470. + return 0;
  2471. +}
  2472. +
  2473. +int i2s_mode_config(u32 slave_en)
  2474. +{
  2475. + unsigned long data;
  2476. +
  2477. + if(slave_en==0)
  2478. + {
  2479. + /* Master mode*/
  2480. + _printk("This SoC is in Master mode\n");
  2481. +#if defined(CONFIG_RALINK_RT3052)
  2482. + data = i2s_inw(I2S_I2SCFG);
  2483. + data &= ~REGBIT(0x1, I2S_SLAVE_EN);
  2484. + data &= ~REGBIT(0x1, I2S_CLK_OUT_DIS);
  2485. + i2s_outw(I2S_I2SCFG, data);
  2486. +#elif defined(CONFIG_RALINK_RT3883)||defined(CONFIG_RALINK_RT3352)||\
  2487. + defined(CONFIG_RALINK_RT5350)||defined(CONFIG_RALINK_RT6855)||\
  2488. + defined(CONFIG_RALINK_MT7620)||defined(CONFIG_RALINK_RT6855A)||\
  2489. + defined(CONFIG_RALINK_MT7621)||defined(CONFIG_RALINK_MT7628)||\
  2490. + defined(CONFIG_ARCH_MT7623)
  2491. + data = i2s_inw(I2S_I2SCFG);
  2492. + data &= ~REGBIT(0x1, I2S_SLAVE_MODE);
  2493. + i2s_outw(I2S_I2SCFG, data);
  2494. +#else
  2495. + #error "a strange clock mode"
  2496. +#endif
  2497. + }
  2498. + else
  2499. + {
  2500. + /* Slave mode */
  2501. + _printk("This SoC is in Slave mode\n");
  2502. +#if defined(CONFIG_RALINK_RT3052)
  2503. + data = i2s_inw(I2S_I2SCFG);
  2504. + data |= REGBIT(0x1, I2S_SLAVE_EN);
  2505. + data |= REGBIT(0x1, I2S_CLK_OUT_DIS);
  2506. + i2s_outw(I2S_I2SCFG, data);
  2507. +#elif defined(CONFIG_RALINK_RT3883)||defined(CONFIG_RALINK_RT3352)||\
  2508. + defined(CONFIG_RALINK_RT5350)||defined(CONFIG_RALINK_RT6855)||\
  2509. + defined(CONFIG_RALINK_MT7620)||defined(CONFIG_RALINK_RT6855A)||\
  2510. + defined(CONFIG_RALINK_MT7621)||defined(CONFIG_RALINK_MT7628)||\
  2511. + defined(CONFIG_ARCH_MT7623)
  2512. + data = i2s_inw(I2S_I2SCFG);
  2513. + data |= REGBIT(0x1, I2S_SLAVE_MODE);
  2514. + i2s_outw(I2S_I2SCFG, data);
  2515. +#else
  2516. + #error "a strange clock mode "
  2517. +#endif
  2518. + }
  2519. +
  2520. + return 0;
  2521. +}
  2522. +
  2523. +int i2s_codec_frequency_config(i2s_config_type* ptri2s_config, unsigned long index)
  2524. +{
  2525. +#if defined(CONFIG_I2S_WM8960)||defined(CONFIG_I2S_WM8750)||defined(CONFIG_I2S_WM8751)
  2526. + unsigned long data;
  2527. + unsigned long* pTable;
  2528. +#endif
  2529. +
  2530. +#if defined(CONFIG_I2S_MCLK_12MHZ)
  2531. +#if defined(CONFIG_I2S_WM8960)||defined(CONFIG_I2S_WM8750)||defined(CONFIG_I2S_WM8751)
  2532. + pTable = i2s_codec_12Mhz;
  2533. + data = pTable[index];
  2534. +#endif
  2535. +#if defined(CONFIG_I2S_WM8960)
  2536. + audiohw_set_frequency(data, ptri2s_config->codec_pll_en);
  2537. +#elif defined(CONFIG_I2S_WM8750)||defined(CONFIG_I2S_WM8751)
  2538. + audiohw_set_frequency(data|0x01);
  2539. +#endif
  2540. +#else
  2541. +#if defined(CONFIG_I2S_WM8960)||defined(CONFIG_I2S_WM8750)||defined(CONFIG_I2S_WM8751)
  2542. +#if defined(MT7623_FPGA_BOARD) && defined(CONFIG_I2S_WM8750)
  2543. + pTable = i2s_codec_18p432Mhz;
  2544. +#else
  2545. + pTable = i2s_codec_12p288Mhz;
  2546. +#endif
  2547. + data = pTable[index];
  2548. +#endif
  2549. +#if defined(CONFIG_I2S_WM8960)
  2550. + audiohw_set_frequency(data, ptri2s_config->codec_pll_en);
  2551. +#elif defined(CONFIG_I2S_WM8750)||defined(CONFIG_I2S_WM8751)
  2552. + audiohw_set_frequency(data);
  2553. +#endif
  2554. +#endif
  2555. + return 0;
  2556. +}
  2557. +
  2558. +/*
  2559. + * Ralink Audio System Clock Enable
  2560. + *
  2561. + * I2S_WS : signal direction opposite to/same as I2S_CLK
  2562. + *
  2563. + * I2S_CLK : Integer division or fractional division
  2564. + * REFCLK from Internal or External (external REFCLK not support for fractional division)
  2565. + * Suppose external REFCLK always be the same as external MCLK
  2566. + *
  2567. + * MCLK : External OSC or internal generation
  2568. + *
  2569. + */
  2570. +int i2s_clock_enable(i2s_config_type* ptri2s_config)
  2571. +{
  2572. + unsigned long index;
  2573. + /* audio sampling rate decision */
  2574. + switch(ptri2s_config->srate)
  2575. + {
  2576. + case 8000:
  2577. + index = 0;
  2578. + break;
  2579. + case 11025:
  2580. + index = 1;
  2581. + break;
  2582. + case 12000:
  2583. + index = 2;
  2584. + break;
  2585. + case 16000:
  2586. + index = 3;
  2587. + break;
  2588. + case 22050:
  2589. + index = 4;
  2590. + break;
  2591. + case 24000:
  2592. + index = 5;
  2593. + break;
  2594. + case 32000:
  2595. + index = 6;
  2596. + break;
  2597. + case 44100:
  2598. + index = 7;
  2599. + break;
  2600. + case 48000:
  2601. + index = 8;
  2602. + break;
  2603. + case 88200:
  2604. + index = 9;
  2605. + break;
  2606. + case 96000:
  2607. + index = 10;
  2608. + break;
  2609. +#if defined(CONFIG_RALINK_MT7628) || defined(CONFIG_ARCH_MT7623)
  2610. + case 176000:
  2611. + index = 11;
  2612. + break;
  2613. + case 192000:
  2614. + index = 12;
  2615. + break;
  2616. +#endif
  2617. + default:
  2618. + index = 7;
  2619. + }
  2620. +#ifdef MT7621_ASIC_BOARD
  2621. + /* Set pll config */
  2622. + i2s_pll_config_mt7621(index);
  2623. +#endif
  2624. +#ifdef MT7623_ASIC_BOARD
  2625. + /* Set pll config */
  2626. + i2s_pll_config_mt7623(index);
  2627. +#endif
  2628. +
  2629. + /* enable internal MCLK */
  2630. +#if defined(CONFIG_I2S_IN_MCLK)
  2631. +#if defined(CONFIG_RALINK_MT7621)
  2632. + i2s_pll_refclk_set();
  2633. +#endif
  2634. +#if defined(CONFIG_I2S_MCLK_12MHZ)
  2635. +#if defined(MT7628_ASIC_BOARD) || defined(CONFIG_ARCH_MT7623)
  2636. + i2s_driving_strength_adjust();
  2637. +#endif
  2638. + i2s_refclk_12m_enable();
  2639. +#endif /* MCLK_12MHZ */
  2640. +#if defined(CONFIG_I2S_MCLK_12P288MHZ)
  2641. + i2s_refclk_12p288m_enable();
  2642. +#endif /* MCLK_12P288MHZ */
  2643. +#if defined(CONFIG_I2S_MCLK_18P432MHZ)
  2644. + i2s_refclk_18p432m_enable(index);
  2645. +#endif
  2646. + i2s_refclk_gpio_out_config();
  2647. +
  2648. +#else
  2649. + MSG("Disable SoC MCLK, use external OSC\n");
  2650. + i2s_refclk_disable();
  2651. + i2s_refclk_gpio_in_config();
  2652. +#endif /* CONFIG_I2S_IN_MCLK */
  2653. +
  2654. + i2s_share_pin_config(ptri2s_config);
  2655. +
  2656. + if(ptri2s_config->slave_en==0)
  2657. + {
  2658. + /* Setup I2S_WS and I2S_CLK */
  2659. + i2s_ws_config(ptri2s_config, index);
  2660. + }
  2661. +
  2662. + i2s_mode_config(ptri2s_config->slave_en);
  2663. +
  2664. + if(!ptri2s_config->bALSAEnable)
  2665. + {
  2666. +#if defined(CONFIG_I2S_WM8750) || defined(CONFIG_I2S_WM8751)|| defined(CONFIG_I2S_WM8960)
  2667. + i2s_codec_enable(ptri2s_config);
  2668. +#endif
  2669. + i2s_codec_frequency_config(ptri2s_config,index);
  2670. + }
  2671. +
  2672. + return 0;
  2673. +}
  2674. +
  2675. +int i2s_clock_disable(i2s_config_type* ptri2s_config)
  2676. +{
  2677. + if(!ptri2s_config->bALSAEnable)
  2678. + {
  2679. +#if defined(CONFIG_I2S_WM8960) || defined(CONFIG_I2S_WM8750) || defined(CONFIG_I2S_WM8751)
  2680. + i2s_codec_disable(ptri2s_config);
  2681. +#endif
  2682. + }
  2683. +
  2684. + /* disable internal MCLK */
  2685. +#if defined(CONFIG_I2S_IN_MCLK)
  2686. + i2s_refclk_disable();
  2687. + i2s_refclk_gpio_in_config();
  2688. +#endif
  2689. + return 0;
  2690. +}
  2691. +
  2692. +
  2693. +int i2s_codec_enable(i2s_config_type* ptri2s_config)
  2694. +{
  2695. +
  2696. + int AIn = 0, AOut = 0;
  2697. +#if 1
  2698. +#if defined(CONFIG_I2S_WM8960) || defined(CONFIG_I2S_WM8750) || defined(CONFIG_I2S_WM8751)
  2699. + /* Codec initialization */
  2700. + audiohw_preinit();
  2701. +#endif
  2702. +#endif
  2703. +
  2704. +#if defined(CONFIG_I2S_WM8960)
  2705. + if(ptri2s_config->codec_pll_en)
  2706. + {
  2707. + MSG("Codec PLL EN = %d\n", pi2s_config->codec_pll_en);
  2708. + audiohw_set_apll(ptri2s_config->srate);
  2709. + }
  2710. +#endif
  2711. +
  2712. +#if defined(CONFIG_I2S_TXRX)
  2713. + if((ptri2s_config->bTxDMAEnable) || (ptri2s_config->txrx_coexist))
  2714. + AOut = 1;
  2715. + if((ptri2s_config->bRxDMAEnable) || (ptri2s_config->txrx_coexist))
  2716. + AIn = 1;
  2717. +#if defined(CONFIG_I2S_WM8960)
  2718. + audiohw_postinit(!(ptri2s_config->slave_en), AIn, AOut, ptri2s_config->codec_pll_en, ptri2s_config->wordlen_24b);
  2719. + audiohw_micboost(ptri2s_config->micboost);
  2720. + audiohw_micin(ptri2s_config->micin);
  2721. +#elif defined(CONFIG_I2S_WM8750)
  2722. + audiohw_postinit(!(ptri2s_config->slave_en), AIn, AOut, ptri2s_config->wordlen_24b);
  2723. +#endif
  2724. + MSG("AOut=%d, AIn=%d\n", AOut, AIn);
  2725. +#else
  2726. +#if defined(CONFIG_I2S_WM8750)
  2727. + audiohw_postinit(!(ptri2s_config->slave_en), 0, 1);
  2728. +#elif defined(CONFIG_I2S_WM8960)
  2729. + audiohw_postinit(!(ptri2s_config->slave_en), 1, 1, ptri2s_config->codec_pll_en);
  2730. +#elif defined(CONFIG_I2S_WM8751)
  2731. + if(ptri2s_config->slave_en==0)
  2732. + audiohw_postinit(1,1);
  2733. + else
  2734. + audiohw_postinit(0,1);
  2735. +#endif
  2736. +#endif
  2737. + return 0;
  2738. +}
  2739. +
  2740. +int i2s_codec_disable(i2s_config_type* ptri2s_config)
  2741. +{
  2742. +#if defined(CONFIG_I2S_WM8960) || defined(CONFIG_I2S_WM8750) || defined(CONFIG_I2S_WM8751)
  2743. + audiohw_close();
  2744. +#endif
  2745. + return 0;
  2746. +}
  2747. +
  2748. +int i2s_reset_config(i2s_config_type* ptri2s_config)
  2749. +{
  2750. + unsigned long data;
  2751. +
  2752. + /* RESET bit: write 1 clear */
  2753. +#if defined(CONFIG_RALINK_RT6855A)
  2754. + data = i2s_inw(RALINK_SYSCTL_BASE+0x834);
  2755. + data |= (1<<17);
  2756. + i2s_outw(RALINK_SYSCTL_BASE+0x834, data);
  2757. +
  2758. + data = i2s_inw(RALINK_SYSCTL_BASE+0x834);
  2759. + data &= ~(1<<17);
  2760. + i2s_outw(RALINK_SYSCTL_BASE+0x834, data);
  2761. +#elif defined(CONFIG_ARCH_MT7623)
  2762. + data = i2s_inw(0xFB000000+0x34);
  2763. + data |= (1<<17);
  2764. + i2s_outw(0xFB000000+0x34, data);
  2765. +
  2766. + data = i2s_inw(0xFB000000+0x34);
  2767. + data &= ~(1<<17);
  2768. + i2s_outw(0xFB000000+0x34, data);
  2769. +#else
  2770. + data = i2s_inw(RALINK_SYSCTL_BASE+0x34);
  2771. + data |= (1<<17);
  2772. + i2s_outw(RALINK_SYSCTL_BASE+0x34, data);
  2773. +
  2774. + data = i2s_inw(RALINK_SYSCTL_BASE+0x34);
  2775. + data &= ~(1<<17);
  2776. + i2s_outw(RALINK_SYSCTL_BASE+0x34, data);
  2777. +
  2778. +#if 0 /* Reset GDMA */
  2779. + data = i2s_inw(RALINK_SYSCTL_BASE+0x34);
  2780. + data |= (1<<14);
  2781. + i2s_outw(RALINK_SYSCTL_BASE+0x34, data);
  2782. +
  2783. + data = i2s_inw(RALINK_SYSCTL_BASE+0x34);
  2784. + data &= ~(1<<14);
  2785. + i2s_outw(RALINK_SYSCTL_BASE+0x34, data);
  2786. +#endif
  2787. +#endif
  2788. + _printk("I2S reset complete!!\n");
  2789. + return 0;
  2790. +}
  2791. +
  2792. +int i2s_tx_config(i2s_config_type* ptri2s_config)
  2793. +{
  2794. + unsigned long data;
  2795. + /* set I2S_I2SCFG */
  2796. + data = i2s_inw(I2S_I2SCFG);
  2797. + data &= 0xFFFFFF81;
  2798. + data |= REGBIT(ptri2s_config->tx_ff_thres, I2S_TX_FF_THRES);
  2799. + data |= REGBIT(ptri2s_config->tx_ch_swap, I2S_TX_CH_SWAP);
  2800. +#if defined(CONFIG_RALINK_RT6855A)
  2801. + data |= REGBIT(1, I2S_BYTE_SWAP);
  2802. +#endif
  2803. +#if defined(CONFIG_RALINK_MT7628) || defined(CONFIG_ARCH_MT7623)
  2804. + MSG("TX:wordLen=%d, sysEndian=%d\n", ptri2s_config->wordlen_24b, ptri2s_config->sys_endian);
  2805. + data |= REGBIT(ptri2s_config->wordlen_24b, I2S_DATA_24BIT);
  2806. + data |= REGBIT(ptri2s_config->sys_endian, I2S_SYS_ENDIAN);
  2807. + data |= REGBIT(ptri2s_config->little_edn, I2S_LITTLE_ENDIAN);
  2808. +#endif
  2809. + data &= ~REGBIT(1, I2S_TX_CH0_OFF);
  2810. + data &= ~REGBIT(1, I2S_TX_CH1_OFF);
  2811. + i2s_outw(I2S_I2SCFG, data);
  2812. +
  2813. + /* set I2S_I2SCFG1 */
  2814. + MSG("internal loopback: %d\n", ptri2s_config->lbk);
  2815. + data = i2s_inw(I2S_I2SCFG1);
  2816. + data |= REGBIT(ptri2s_config->lbk, I2S_LBK_EN);
  2817. + data |= REGBIT(ptri2s_config->extlbk, I2S_EXT_LBK_EN);
  2818. + data &= 0xFFFFFFFC;
  2819. +#if defined(CONFIG_RALINK_MT7628) || defined(CONFIG_ARCH_MT7623)
  2820. + data |= REGBIT(ptri2s_config->fmt, I2S_DATA_FMT);
  2821. +#endif
  2822. + i2s_outw(I2S_I2SCFG1, data);
  2823. +
  2824. + return 0;
  2825. +}
  2826. +
  2827. +int i2s_rx_config(i2s_config_type* ptri2s_config)
  2828. +{
  2829. + unsigned long data;
  2830. + /* set I2S_I2SCFG */
  2831. + data = i2s_inw(I2S_I2SCFG);
  2832. + data &= 0xFFFF81FF;
  2833. + data |= REGBIT(ptri2s_config->rx_ff_thres, I2S_RX_FF_THRES);
  2834. + data |= REGBIT(ptri2s_config->rx_ch_swap, I2S_RX_CH_SWAP);
  2835. + data &= ~REGBIT(1, I2S_RX_CH0_OFF);
  2836. + data &= ~REGBIT(1, I2S_RX_CH1_OFF);
  2837. +#if defined(CONFIG_RALINK_MT7628) || defined(CONFIG_ARCH_MT7623)
  2838. + MSG("RX:wordLen=%d, sysEndian=%d\n", ptri2s_config->wordlen_24b, ptri2s_config->sys_endian);
  2839. + data |= REGBIT(ptri2s_config->wordlen_24b, I2S_DATA_24BIT);
  2840. + data |= REGBIT(ptri2s_config->sys_endian, I2S_SYS_ENDIAN);
  2841. + data |= REGBIT(ptri2s_config->little_edn, I2S_LITTLE_ENDIAN);
  2842. +#endif
  2843. + i2s_outw(I2S_I2SCFG, data);
  2844. +
  2845. + /* set I2S_I2SCFG1 */
  2846. + data = i2s_inw(I2S_I2SCFG1);
  2847. + data |= REGBIT(ptri2s_config->lbk, I2S_LBK_EN);
  2848. + data |= REGBIT(ptri2s_config->extlbk, I2S_EXT_LBK_EN);
  2849. +#if defined(CONFIG_RALINK_MT7628) || defined(CONFIG_ARCH_MT7623)
  2850. + data &= 0xFFFFFFFC;
  2851. + data |= REGBIT(ptri2s_config->fmt, I2S_DATA_FMT);
  2852. +#endif
  2853. + i2s_outw(I2S_I2SCFG1, data);
  2854. +
  2855. + return 0;
  2856. +}
  2857. +
  2858. +/* Turn On Tx DMA and INT */
  2859. +int i2s_tx_enable(i2s_config_type* ptri2s_config)
  2860. +{
  2861. + unsigned long data;
  2862. +
  2863. +#if defined(I2S_HW_INTERRUPT_EN)
  2864. + data = i2s_inw(I2S_INT_EN);
  2865. + data |= REGBIT(0x1, I2S_TX_INT3_EN); /* FIFO DMA fault */
  2866. + data |= REGBIT(0x1, I2S_TX_INT2_EN); /* FIFO overrun */
  2867. + data |= REGBIT(0x1, I2S_TX_INT1_EN); /* FIFO underrun */
  2868. + data |= REGBIT(0x1, I2S_TX_INT0_EN); /* FIFO below threshold */
  2869. + i2s_outw(I2S_INT_EN, data);
  2870. +#endif
  2871. +
  2872. + data = i2s_inw(I2S_I2SCFG);
  2873. +#if defined(CONFIG_I2S_TXRX)
  2874. + data |= REGBIT(0x1, I2S_TX_EN);
  2875. +#endif
  2876. + data |= REGBIT(0x1, I2S_DMA_EN);
  2877. + i2s_outw(I2S_I2SCFG, data);
  2878. +
  2879. + data = i2s_inw(I2S_I2SCFG);
  2880. + data |= REGBIT(0x1, I2S_EN);
  2881. + i2s_outw(I2S_I2SCFG, data);
  2882. +
  2883. + MSG("i2s_tx_enable done\n");
  2884. + return I2S_OK;
  2885. +}
  2886. +
  2887. +/* Turn On Rx DMA and INT */
  2888. +int i2s_rx_enable(i2s_config_type* ptri2s_config)
  2889. +{
  2890. + unsigned long data;
  2891. +
  2892. +#if defined(I2S_HW_INTERRUPT_EN)
  2893. + data = i2s_inw(I2S_INT_EN);
  2894. + data |= REGBIT(0x1, I2S_RX_INT3_EN); /* FIFO DMA fault */
  2895. + data |= REGBIT(0x1, I2S_RX_INT2_EN); /* FIFO overrun */
  2896. + data |= REGBIT(0x1, I2S_RX_INT1_EN); /* FIFO underrun */
  2897. + data |= REGBIT(0x1, I2S_RX_INT0_EN); /* FIFO below threshold */
  2898. + i2s_outw(I2S_INT_EN, data);
  2899. +#endif
  2900. +
  2901. + data = i2s_inw(I2S_I2SCFG);
  2902. +#if defined(CONFIG_I2S_TXRX)
  2903. + data |= REGBIT(0x1, I2S_RX_EN);
  2904. +#endif
  2905. + data |= REGBIT(0x1, I2S_DMA_EN);
  2906. + i2s_outw(I2S_I2SCFG, data);
  2907. +
  2908. + data = i2s_inw(I2S_I2SCFG);
  2909. + data |= REGBIT(0x1, I2S_EN);
  2910. + i2s_outw(I2S_I2SCFG, data);
  2911. +
  2912. + MSG("i2s_rx_enable done\n");
  2913. + return I2S_OK;
  2914. +}
  2915. +/* Turn Off Tx DMA and INT */
  2916. +int i2s_tx_disable(i2s_config_type* ptri2s_config)
  2917. +{
  2918. + unsigned long data;
  2919. +
  2920. +#if defined(I2S_HW_INTERRUPT_EN)
  2921. + data = i2s_inw(I2S_INT_EN);
  2922. + data &= ~REGBIT(0x1, I2S_TX_INT3_EN);
  2923. + data &= ~REGBIT(0x1, I2S_TX_INT2_EN);
  2924. + data &= ~REGBIT(0x1, I2S_TX_INT1_EN);
  2925. + data &= ~REGBIT(0x1, I2S_TX_INT0_EN);
  2926. + i2s_outw(I2S_INT_EN, data);
  2927. +#endif
  2928. +
  2929. + data = i2s_inw(I2S_I2SCFG);
  2930. +#if defined(CONFIG_I2S_TXRX)
  2931. + data &= ~REGBIT(0x1, I2S_TX_EN);
  2932. +#endif
  2933. + if(ptri2s_config->bRxDMAEnable==0)
  2934. + {
  2935. + ptri2s_config->bTxDMAEnable = 0;
  2936. + data &= ~REGBIT(0x1, I2S_DMA_EN);
  2937. + data &= ~REGBIT(0x1, I2S_EN);
  2938. + }
  2939. + i2s_outw(I2S_I2SCFG, data);
  2940. + return I2S_OK;
  2941. +}
  2942. +/* Turn Off Rx DMA and INT */
  2943. +int i2s_rx_disable(i2s_config_type* ptri2s_config)
  2944. +{
  2945. + unsigned long data;
  2946. +
  2947. +#if defined(I2S_HW_INTERRUPT_EN)
  2948. + data = i2s_inw(I2S_INT_EN);
  2949. + data &= ~REGBIT(0x1, I2S_RX_INT3_EN);
  2950. + data &= ~REGBIT(0x1, I2S_RX_INT2_EN);
  2951. + data &= ~REGBIT(0x1, I2S_RX_INT1_EN);
  2952. + data &= ~REGBIT(0x1, I2S_RX_INT0_EN);
  2953. + i2s_outw(I2S_INT_EN, data);
  2954. +#endif
  2955. +
  2956. + data = i2s_inw(I2S_I2SCFG);
  2957. +#if defined(CONFIG_I2S_TXRX)
  2958. + data &= ~REGBIT(0x1, I2S_RX_EN);
  2959. +#endif
  2960. + if(ptri2s_config->bTxDMAEnable==0)
  2961. + {
  2962. + ptri2s_config->bRxDMAEnable = 0;
  2963. + data &= ~REGBIT(0x1, I2S_DMA_EN);
  2964. + data &= ~REGBIT(0x1, I2S_EN);
  2965. + }
  2966. + i2s_outw(I2S_I2SCFG, data);
  2967. + return I2S_OK;
  2968. +}
  2969. +
  2970. +int i2s_dma_tx_transf_data(i2s_config_type* ptri2s_config, u32 dma_ch)
  2971. +{
  2972. + int tx_r_idx;
  2973. +
  2974. + if ((pi2s_config->bALSAEnable==1) && (pi2s_config->bALSAMMAPEnable==1))
  2975. + tx_r_idx = (pi2s_config->tx_r_idx + ALSA_MMAP_IDX_SHIFT)%MAX_I2S_PAGE;
  2976. + else
  2977. + tx_r_idx = pi2s_config->tx_r_idx;
  2978. +
  2979. + if(dma_ch==GDMA_I2S_TX0)
  2980. + {
  2981. +#if defined(CONFIG_I2S_MMAP)
  2982. + dma_sync_single_for_device(NULL, i2s_mmap_addr[tx_r_idx], I2S_PAGE_SIZE, DMA_TO_DEVICE);
  2983. +#if defined(ARM_ARCH)
  2984. + GdmaI2sTx(i2s_mmap_addr[tx_r_idx], I2S_TX_FIFO_WREG_PHY, 0, I2S_PAGE_SIZE, i2s_dma_tx_handler, i2s_dma_tx_unmask_handler);
  2985. +#else
  2986. + GdmaI2sTx((u32)(pi2s_config->pMMAPTxBufPtr[tx_r_idx]), I2S_TX_FIFO_WREG, 0, I2S_PAGE_SIZE, i2s_dma_tx_handler, i2s_dma_tx_unmask_handler);
  2987. +#endif
  2988. +#else
  2989. + memcpy(pi2s_config->pPage0TxBuf8ptr, pi2s_config->pMMAPTxBufPtr[tx_r_idx], I2S_PAGE_SIZE);
  2990. +#if defined(ARM_ARCH)
  2991. + GdmaI2sTx(i2s_txdma_addr0, I2S_TX_FIFO_WREG_PHY, 0, I2S_PAGE_SIZE, i2s_dma_tx_handler, i2s_dma_tx_unmask_handler);
  2992. +#else
  2993. + GdmaI2sTx((u32)(pi2s_config->pPage0TxBuf8ptr), I2S_TX_FIFO_WREG, 0, I2S_PAGE_SIZE, i2s_dma_tx_handler, i2s_dma_tx_unmask_handler);
  2994. +#endif
  2995. +#endif
  2996. + pi2s_config->dmach = GDMA_I2S_TX0;
  2997. + pi2s_config->tx_r_idx = (pi2s_config->tx_r_idx+1)%MAX_I2S_PAGE;
  2998. + }
  2999. + else
  3000. + {
  3001. +#if defined(CONFIG_I2S_MMAP)
  3002. + dma_sync_single_for_device(NULL, i2s_mmap_addr[tx_r_idx], I2S_PAGE_SIZE, DMA_TO_DEVICE);
  3003. +#if defined(ARM_ARCH)
  3004. + GdmaI2sTx(i2s_mmap_addr[tx_r_idx], I2S_TX_FIFO_WREG_PHY, 1, I2S_PAGE_SIZE, i2s_dma_tx_handler, i2s_dma_tx_unmask_handler);
  3005. +#else
  3006. + GdmaI2sTx((u32)(pi2s_config->pMMAPTxBufPtr[tx_r_idx]), I2S_TX_FIFO_WREG, 1, I2S_PAGE_SIZE, i2s_dma_tx_handler, i2s_dma_tx_unmask_handler);
  3007. +#endif
  3008. +#else
  3009. + memcpy(pi2s_config->pPage1TxBuf8ptr, pi2s_config->pMMAPTxBufPtr[tx_r_idx], I2S_PAGE_SIZE);
  3010. +#if defined(ARM_ARCH)
  3011. + GdmaI2sTx(i2s_txdma_addr1, I2S_TX_FIFO_WREG_PHY, 1, I2S_PAGE_SIZE, i2s_dma_tx_handler, i2s_dma_tx_unmask_handler);
  3012. +#else
  3013. + GdmaI2sTx((u32)(pi2s_config->pPage1TxBuf8ptr), I2S_TX_FIFO_WREG, 1, I2S_PAGE_SIZE, i2s_dma_tx_handler, i2s_dma_tx_unmask_handler);
  3014. +#endif
  3015. +#endif
  3016. + pi2s_config->dmach = GDMA_I2S_TX1;
  3017. + pi2s_config->tx_r_idx = (pi2s_config->tx_r_idx+1)%MAX_I2S_PAGE;
  3018. + }
  3019. +#if defined(CONFIG_I2S_WITH_AEC)
  3020. + if(aecFuncP->AECFeEnq){
  3021. + aecFuncP->AECFeEnq(0,pi2s_config->pMMAPTxBufPtr[pi2s_config->tx_r_idx],I2S_PAGE_SIZE);
  3022. + }
  3023. +#endif
  3024. + return 0;
  3025. +}
  3026. +
  3027. +int i2s_dma_tx_transf_zero(i2s_config_type* ptri2s_config, u32 dma_ch)
  3028. +{
  3029. + if(dma_ch==GDMA_I2S_TX0)
  3030. + {
  3031. + memset(pi2s_config->pPage0TxBuf8ptr, 0, I2S_PAGE_SIZE);
  3032. +#if defined(ARM_ARCH)
  3033. + GdmaI2sTx(i2s_txdma_addr0, I2S_TX_FIFO_WREG_PHY, 0, I2S_PAGE_SIZE, i2s_dma_tx_handler, i2s_dma_tx_unmask_handler);
  3034. +#else
  3035. + GdmaI2sTx((u32)pi2s_config->pPage0TxBuf8ptr, I2S_TX_FIFO_WREG, 0, I2S_PAGE_SIZE, i2s_dma_tx_handler, i2s_dma_tx_unmask_handler);
  3036. +#endif
  3037. + }
  3038. + else
  3039. + {
  3040. + memset(pi2s_config->pPage1TxBuf8ptr, 0, I2S_PAGE_SIZE);
  3041. +#if defined(ARM_ARCH)
  3042. + GdmaI2sTx(i2s_txdma_addr1, I2S_TX_FIFO_WREG_PHY, 1, I2S_PAGE_SIZE, i2s_dma_tx_handler, i2s_dma_tx_unmask_handler);
  3043. +#else
  3044. + GdmaI2sTx((u32)pi2s_config->pPage1TxBuf8ptr, I2S_TX_FIFO_WREG, 1, I2S_PAGE_SIZE, i2s_dma_tx_handler, i2s_dma_tx_unmask_handler);
  3045. +#endif
  3046. + }
  3047. + return 0;
  3048. +}
  3049. +
  3050. +int i2s_dma_rx_transf_data(i2s_config_type* ptri2s_config, u32 dma_ch)
  3051. +{
  3052. + int rx_w_idx;
  3053. +
  3054. + pi2s_config->rx_w_idx = (pi2s_config->rx_w_idx+1)%MAX_I2S_PAGE;
  3055. +
  3056. + if ((pi2s_config->bALSAEnable==1) && (pi2s_config->bALSAMMAPEnable==1))
  3057. + rx_w_idx = (pi2s_config->rx_w_idx+ALSA_MMAP_IDX_SHIFT)%MAX_I2S_PAGE;
  3058. + else
  3059. + rx_w_idx = (pi2s_config->rx_w_idx)%MAX_I2S_PAGE;
  3060. +
  3061. + if(dma_ch==GDMA_I2S_RX0)
  3062. + {
  3063. +
  3064. +#ifdef CONFIG_I2S_MMAP
  3065. + dma_sync_single_for_device(NULL, i2s_mmap_addr[rx_w_idx+(pi2s_config->mmap_index-MAX_I2S_PAGE)], I2S_PAGE_SIZE, DMA_FROM_DEVICE);
  3066. +#if defined(ARM_ARCH)
  3067. + GdmaI2sRx(I2S_RX_FIFO_RREG_PHY, (u32)i2s_mmap_addr[rx_w_idx+(pi2s_config->mmap_index-MAX_I2S_PAGE)], 0, I2S_PAGE_SIZE, i2s_dma_rx_handler, i2s_dma_rx_unmask_handler);
  3068. +#else
  3069. + GdmaI2sRx(I2S_RX_FIFO_RREG, (u32)(pi2s_config->pMMAPRxBufPtr[rx_w_idx]), 0, I2S_PAGE_SIZE, i2s_dma_rx_handler, i2s_dma_rx_unmask_handler);
  3070. +#endif
  3071. +#else
  3072. + memcpy(pi2s_config->pMMAPRxBufPtr[rx_w_idx], pi2s_config->pPage0RxBuf8ptr, I2S_PAGE_SIZE);
  3073. +#if defined(ARM_ARCH)
  3074. + GdmaI2sRx(I2S_RX_FIFO_RREG_PHY, i2s_rxdma_addr0, 0, I2S_PAGE_SIZE, i2s_dma_rx_handler, i2s_dma_rx_unmask_handler);
  3075. +#else
  3076. + GdmaI2sRx(I2S_RX_FIFO_RREG, (u32)(pi2s_config->pPage0RxBuf8ptr), 0, I2S_PAGE_SIZE, i2s_dma_rx_handler, i2s_dma_rx_unmask_handler);
  3077. +#endif
  3078. +#endif
  3079. + pi2s_config->dmach = GDMA_I2S_RX0;
  3080. + }
  3081. + else
  3082. + {
  3083. +
  3084. +#ifdef CONFIG_I2S_MMAP
  3085. + dma_sync_single_for_device(NULL, i2s_mmap_addr[rx_w_idx+(pi2s_config->mmap_index-MAX_I2S_PAGE)], I2S_PAGE_SIZE, DMA_FROM_DEVICE);
  3086. +#if defined(ARM_ARCH)
  3087. + GdmaI2sRx(I2S_RX_FIFO_RREG_PHY, (u32)i2s_mmap_addr[rx_w_idx+(pi2s_config->mmap_index-MAX_I2S_PAGE)], 1, I2S_PAGE_SIZE, i2s_dma_rx_handler, i2s_dma_rx_unmask_handler);
  3088. +#else
  3089. + GdmaI2sRx(I2S_RX_FIFO_RREG, (u32)(pi2s_config->pMMAPRxBufPtr[rx_w_idx]), 1, I2S_PAGE_SIZE, i2s_dma_rx_handler, i2s_dma_rx_unmask_handler);
  3090. +#endif
  3091. +#else
  3092. + memcpy(pi2s_config->pMMAPRxBufPtr[rx_w_idx], pi2s_config->pPage1RxBuf8ptr, I2S_PAGE_SIZE);
  3093. +#if defined(ARM_ARCH)
  3094. + GdmaI2sRx(I2S_RX_FIFO_RREG_PHY, i2s_rxdma_addr1, 1, I2S_PAGE_SIZE, i2s_dma_rx_handler, i2s_dma_rx_unmask_handler);
  3095. +#else
  3096. + GdmaI2sRx(I2S_RX_FIFO_RREG, (u32)(pi2s_config->pPage1RxBuf8ptr), 1, I2S_PAGE_SIZE, i2s_dma_rx_handler, i2s_dma_rx_unmask_handler);
  3097. +#endif
  3098. +#endif
  3099. + pi2s_config->dmach = GDMA_I2S_RX1;
  3100. +
  3101. + }
  3102. +#if defined(CONFIG_I2S_WITH_AEC)
  3103. + if(aecFuncP->AECNeEnq){
  3104. + aecFuncP->AECNeEnq(0,pi2s_config->pMMAPRxBufPtr[rx_w_idx],I2S_PAGE_SIZE);
  3105. + }
  3106. +#endif
  3107. + return 0;
  3108. +}
  3109. +
  3110. +int i2s_dma_rx_transf_zero(i2s_config_type* ptri2s_config, u32 dma_ch)
  3111. +{
  3112. + if(dma_ch==GDMA_I2S_RX0)
  3113. + {
  3114. + memset(pi2s_config->pPage0RxBuf8ptr, 0, I2S_PAGE_SIZE);
  3115. +#if defined(ARM_ARCH)
  3116. + GdmaI2sRx(I2S_RX_FIFO_RREG_PHY, i2s_rxdma_addr0, 0, I2S_PAGE_SIZE, i2s_dma_rx_handler, i2s_dma_rx_unmask_handler);
  3117. +#else
  3118. + GdmaI2sRx(I2S_RX_FIFO_RREG, (u32)pi2s_config->pPage0RxBuf8ptr, 0, I2S_PAGE_SIZE, i2s_dma_rx_handler, i2s_dma_rx_unmask_handler);
  3119. +#endif
  3120. + }
  3121. + else
  3122. + {
  3123. + memset(pi2s_config->pPage1RxBuf8ptr, 0, I2S_PAGE_SIZE);
  3124. +#if defined(ARM_ARCH)
  3125. + GdmaI2sRx(I2S_RX_FIFO_RREG_PHY, i2s_rxdma_addr1, 1, I2S_PAGE_SIZE, i2s_dma_rx_handler, i2s_dma_rx_unmask_handler);
  3126. +#else
  3127. + GdmaI2sRx(I2S_RX_FIFO_RREG, (u32)pi2s_config->pPage1RxBuf8ptr, 1, I2S_PAGE_SIZE, i2s_dma_rx_handler, i2s_dma_rx_unmask_handler);
  3128. +#endif
  3129. + }
  3130. + return 0;
  3131. +}
  3132. +
  3133. +void i2s_dma_tx_handler(u32 dma_ch)
  3134. +{
  3135. + pi2s_config->enLable = 1; /* TX:enLabel=1; RX:enLabel=2 */
  3136. +
  3137. + if(pi2s_config->bTxDMAEnable==0)
  3138. + {
  3139. + if(pi2s_config->end_cnt != 0)
  3140. + {
  3141. + i2s_dma_tx_transf_data(pi2s_config, dma_ch);
  3142. + pi2s_config->end_cnt --;
  3143. + MSG("end_cnt = %d, r_idx = %d\n", pi2s_config->end_cnt, pi2s_config->tx_r_idx);
  3144. + }
  3145. + else
  3146. + {
  3147. + pi2s_config->tx_stop_cnt++;
  3148. + i2s_dma_tx_soft_stop(pi2s_config, dma_ch);
  3149. + MSG("tx_stop=%d, ch=%d\n", pi2s_config->tx_stop_cnt, dma_ch);
  3150. + if (pi2s_config->tx_stop_cnt == 3)
  3151. + {
  3152. + wake_up_interruptible(&(pi2s_config->i2s_tx_qh));
  3153. + _printk("T:wake up!!\n");
  3154. + }
  3155. + }
  3156. + return;
  3157. + }
  3158. +
  3159. + pi2s_config->tx_isr_cnt++;
  3160. +
  3161. +#ifdef I2S_STATISTIC
  3162. + i2s_int_status(dma_ch);
  3163. +#endif
  3164. + /* FIXME */
  3165. + if(pi2s_config->bALSAEnable)
  3166. + {
  3167. + if(pi2s_config->dmaStat[STREAM_PLAYBACK])
  3168. + {
  3169. + if(!pi2s_config->bTrigger[STREAM_PLAYBACK]){
  3170. + //_printk("trigger stop: rIdx:%d widx:%d\n", pi2s_config->tx_r_idx,pi2s_config->tx_w_idx);
  3171. + i2s_dma_tx_transf_zero(pi2s_config, dma_ch);
  3172. + if(pi2s_config->bPreTrigger[STREAM_PLAYBACK]){
  3173. + /* mtk04880 commented:
  3174. + * for corner case, there are cases which ALSA Trigger stop before disabling DMA.
  3175. + * For which case, it needs to keep call snd_pcm_elapased to keep ALSA hw ptr updating.
  3176. + * It is so called post stop handlment.
  3177. + */
  3178. + //_printk("post-stop\n");
  3179. + goto EXIT;
  3180. + }
  3181. + else{
  3182. + //_printk("pre-stop\n");
  3183. + wake_up_interruptible(&(pi2s_config->i2s_tx_qh));
  3184. + return;
  3185. + }
  3186. + }
  3187. + else{
  3188. + if(!pi2s_config->bPreTrigger[STREAM_PLAYBACK])
  3189. + pi2s_config->bPreTrigger[STREAM_PLAYBACK] = 1;
  3190. +
  3191. + }
  3192. + }
  3193. + }
  3194. + else
  3195. + {
  3196. + if(pi2s_config->tx_r_idx==pi2s_config->tx_w_idx)
  3197. + {
  3198. + /* Buffer Empty */
  3199. + MSG("TXBE r=%d w=%d[i=%u,c=%u]\n",pi2s_config->tx_r_idx,pi2s_config->tx_w_idx,pi2s_config->tx_isr_cnt,dma_ch);
  3200. +#ifdef I2S_STATISTIC
  3201. + pi2s_status->txbuffer_unrun++;
  3202. +#endif
  3203. + i2s_dma_tx_transf_zero(pi2s_config, dma_ch);
  3204. + goto EXIT;
  3205. + }
  3206. + }
  3207. +
  3208. + if(pi2s_config->pMMAPTxBufPtr[pi2s_config->tx_r_idx]==NULL)
  3209. + {
  3210. + MSG("mmap buf NULL [%d]\n",pi2s_config->tx_r_idx);
  3211. + i2s_dma_tx_transf_zero(pi2s_config, dma_ch);
  3212. +
  3213. + goto EXIT;
  3214. + }
  3215. +
  3216. + if(pi2s_config->tx_pause_en == 1)
  3217. + {
  3218. + /* Enable PAUSE */
  3219. + MSG("TX pause now\n");
  3220. + i2s_dma_tx_transf_zero(pi2s_config, dma_ch);
  3221. +
  3222. + goto EXIT;
  3223. + }
  3224. +
  3225. +#ifdef I2S_STATISTIC
  3226. + pi2s_status->txbuffer_len--;
  3227. +#endif
  3228. + i2s_dma_tx_transf_data(pi2s_config, dma_ch);
  3229. +
  3230. +EXIT:
  3231. +#if defined(CONFIG_SND_MT76XX_SOC)
  3232. + if(pi2s_config->bALSAEnable == 1){
  3233. + if(pi2s_config->pss[STREAM_PLAYBACK])
  3234. + snd_pcm_period_elapsed(pi2s_config->pss[STREAM_PLAYBACK]);
  3235. + }
  3236. +#endif
  3237. + wake_up_interruptible(&(pi2s_config->i2s_tx_qh));
  3238. + return;
  3239. +}
  3240. +
  3241. +void i2s_dma_rx_handler(u32 dma_ch)
  3242. +{
  3243. + pi2s_config->enLable = 2; /* TX:enLabel=1; RX:enLabel=2 */
  3244. +#if defined(CONFIG_I2S_TXRX)
  3245. + if(pi2s_config->rx_isr_cnt==0)
  3246. + {
  3247. + pi2s_config->next_p0_idx = 0;
  3248. + pi2s_config->next_p1_idx = 1;
  3249. + }
  3250. + pi2s_config->rx_isr_cnt++;
  3251. +
  3252. +#ifdef I2S_STATISTIC
  3253. + i2s_int_status(dma_ch);
  3254. +#endif
  3255. +
  3256. + if (pi2s_config->bRxDMAEnable==0)
  3257. + {
  3258. + pi2s_config->rx_stop_cnt++;
  3259. + i2s_dma_rx_soft_stop(pi2s_config, dma_ch);
  3260. + MSG("rx_stop=%d\n", pi2s_config->rx_stop_cnt);
  3261. +
  3262. + if(pi2s_config->rx_stop_cnt == 2)
  3263. + {
  3264. + wake_up_interruptible(&(pi2s_config->i2s_rx_qh));
  3265. + _printk("R:wake up!!\n");
  3266. + }
  3267. + return;
  3268. + }
  3269. +
  3270. + if(pi2s_config->bALSAEnable)
  3271. + {
  3272. + if(pi2s_config->dmaStat[STREAM_CAPTURE]){
  3273. + if(!pi2s_config->bTrigger[STREAM_CAPTURE]){
  3274. + MSG("trigger stop: rIdx:%d widx:%d\n", pi2s_config->rx_r_idx,pi2s_config->rx_w_idx);
  3275. + i2s_dma_rx_transf_zero(pi2s_config, dma_ch);
  3276. + wake_up_interruptible(&(pi2s_config->i2s_rx_qh));
  3277. + return;
  3278. + }
  3279. + }
  3280. + }
  3281. + else
  3282. + {
  3283. + if(((pi2s_config->rx_w_idx+1)%MAX_I2S_PAGE)==pi2s_config->rx_r_idx){
  3284. + /* Buffer Full */
  3285. + MSG("RXBF r=%d w=%d[i=%u,c=%u]\n",pi2s_config->rx_r_idx,pi2s_config->rx_w_idx,pi2s_config->rx_isr_cnt,dma_ch);
  3286. +#ifdef I2S_STATISTIC
  3287. + pi2s_status->rxbuffer_unrun++;
  3288. +#endif
  3289. + i2s_dma_rx_transf_zero(pi2s_config, dma_ch);
  3290. + goto EXIT;
  3291. + }
  3292. + }
  3293. +
  3294. + if(pi2s_config->rx_pause_en == 1)
  3295. + {
  3296. + /* Enable PAUSE */
  3297. + i2s_dma_rx_transf_zero(pi2s_config, dma_ch);
  3298. +
  3299. + goto EXIT;
  3300. + }
  3301. +
  3302. +#ifdef I2S_STATISTIC
  3303. + pi2s_status->rxbuffer_len++;
  3304. +#endif
  3305. + i2s_dma_rx_transf_data(pi2s_config, dma_ch);
  3306. +
  3307. +EXIT:
  3308. +#if defined(CONFIG_SND_MT76XX_SOC)
  3309. + if(pi2s_config->bALSAEnable == 1){
  3310. + if(pi2s_config->pss[STREAM_CAPTURE])
  3311. + snd_pcm_period_elapsed(pi2s_config->pss[STREAM_CAPTURE]);
  3312. + }
  3313. +#endif
  3314. + wake_up_interruptible(&(pi2s_config->i2s_rx_qh));
  3315. +#endif
  3316. + return;
  3317. +}
  3318. +
  3319. +#ifdef I2S_STATISTIC
  3320. +void i2s_int_status(u32 dma_ch)
  3321. +{
  3322. + u32 i2s_status;
  3323. +
  3324. + if((pi2s_config->tx_isr_cnt>0)||(pi2s_config->rx_isr_cnt>0))
  3325. + {
  3326. + i2s_status = i2s_inw(I2S_INT_STATUS);
  3327. +
  3328. + if(i2s_status&REGBIT(1, I2S_TX_DMA_FAULT))
  3329. + {
  3330. + pi2s_status->txdmafault++;
  3331. + }
  3332. + if(i2s_status&REGBIT(1, I2S_TX_OVRUN))
  3333. + {
  3334. + pi2s_status->txovrun++;
  3335. + }
  3336. + if(i2s_status&REGBIT(1, I2S_TX_UNRUN))
  3337. + {
  3338. + pi2s_status->txunrun++;
  3339. + }
  3340. + if(i2s_status&REGBIT(1, I2S_TX_THRES))
  3341. + {
  3342. + pi2s_status->txthres++;
  3343. + }
  3344. + if(i2s_status&REGBIT(1, I2S_RX_DMA_FAULT))
  3345. + {
  3346. + pi2s_status->rxdmafault++;
  3347. + }
  3348. + if(i2s_status&REGBIT(1, I2S_RX_OVRUN))
  3349. + {
  3350. + pi2s_status->rxovrun++;
  3351. + }
  3352. + if(i2s_status&REGBIT(1, I2S_RX_UNRUN))
  3353. + {
  3354. + pi2s_status->rxunrun++;
  3355. + }
  3356. + if(i2s_status&REGBIT(1, I2S_RX_THRES))
  3357. + {
  3358. + pi2s_status->rxthres++;
  3359. + }
  3360. + }
  3361. +#if 0
  3362. + if(pi2s_config->enLable == 1)
  3363. + {
  3364. + if((pi2s_config->tx_isr_cnt>0) && (pi2s_config->tx_isr_cnt%40==0))
  3365. + {
  3366. + MSG("tisr i=%u,ch=%u,o=%u,u=%d,s=%X [r=%d,w=%d]\n",\
  3367. + pi2s_config->tx_isr_cnt,dma_ch,pi2s_status->txovrun,pi2s_status->txunrun,\
  3368. + i2s_inw(I2S_INT_STATUS),pi2s_config->tx_r_idx,pi2s_config->tx_w_idx);
  3369. + }
  3370. + }
  3371. +
  3372. + if(pi2s_config->enLable == 2)
  3373. + {
  3374. + if((pi2s_config->rx_isr_cnt>0) && (pi2s_config->rx_isr_cnt%40==0))
  3375. + {
  3376. + MSG("risr i=%u,ch=%u,o=%u,u=%d,s=%X [r=%d,w=%d]\n",\
  3377. + pi2s_config->rx_isr_cnt,dma_ch,pi2s_status->rxovrun,pi2s_status->rxunrun,\
  3378. + i2s_inw(I2S_INT_STATUS),pi2s_config->rx_r_idx,pi2s_config->rx_w_idx);
  3379. + }
  3380. + }
  3381. +#endif
  3382. +
  3383. + *(unsigned long*)(I2S_INT_STATUS) = 0xFFFFFFFF;
  3384. +}
  3385. +#endif
  3386. +
  3387. +#if defined(I2S_HW_INTERRUPT_EN)&&(I2S_SW_IRQ_EN)
  3388. +irqreturn_t i2s_irq_isr(int irq, void *irqaction)
  3389. +{
  3390. + u32 i2s_status;
  3391. +
  3392. + //MSG("i2s_irq_isr [0x%08X]\n",i2s_inw(I2S_INT_STATUS));
  3393. + if((pi2s_config->tx_isr_cnt>0)||(pi2s_config->rx_isr_cnt>0))
  3394. + {
  3395. + i2s_status = i2s_inw(I2S_INT_STATUS);
  3396. + MSG("i2s_irq_isr [0x%08X]\n",i2s_status);
  3397. + }
  3398. + else
  3399. + return IRQ_HANDLED;
  3400. +
  3401. + if(i2s_status&REGBIT(1, I2S_TX_DMA_FAULT))
  3402. + {
  3403. +#ifdef I2S_STATISTIC
  3404. + pi2s_status->txdmafault++;
  3405. +#endif
  3406. + }
  3407. + if(i2s_status&REGBIT(1, I2S_TX_OVRUN))
  3408. + {
  3409. +#ifdef I2S_STATISTIC
  3410. + pi2s_status->txovrun++;
  3411. +#endif
  3412. + }
  3413. + if(i2s_status&REGBIT(1, I2S_TX_UNRUN))
  3414. + {
  3415. +#ifdef I2S_STATISTIC
  3416. + pi2s_status->txunrun++;
  3417. +#endif
  3418. + }
  3419. + if(i2s_status&REGBIT(1, I2S_TX_THRES))
  3420. + {
  3421. +#ifdef I2S_STATISTIC
  3422. + pi2s_status->txthres++;
  3423. +#endif
  3424. + }
  3425. + if(i2s_status&REGBIT(1, I2S_RX_DMA_FAULT))
  3426. + {
  3427. +#ifdef I2S_STATISTIC
  3428. + pi2s_status->rxdmafault++;
  3429. +#endif
  3430. + }
  3431. + if(i2s_status&REGBIT(1, I2S_RX_OVRUN))
  3432. + {
  3433. +#ifdef I2S_STATISTIC
  3434. + pi2s_status->rxovrun++;
  3435. +#endif
  3436. + }
  3437. + if(i2s_status&REGBIT(1, I2S_RX_UNRUN))
  3438. + {
  3439. +#ifdef I2S_STATISTIC
  3440. + pi2s_status->rxunrun++;
  3441. +#endif
  3442. + }
  3443. + if(i2s_status&REGBIT(1, I2S_RX_THRES))
  3444. + {
  3445. +#ifdef I2S_STATISTIC
  3446. + pi2s_status->rxthres++;
  3447. +#endif
  3448. + }
  3449. + i2s_outw(I2S_INT_STATUS, 0xFFFFFFFF);
  3450. + return IRQ_HANDLED;
  3451. +}
  3452. +#endif
  3453. +
  3454. +void i2s_tx_task(unsigned long pData)
  3455. +{
  3456. + unsigned long flags;
  3457. + spin_lock_irqsave(&pi2s_config->lock, flags);
  3458. + //if (pi2s_config->bTxDMAEnable!=0)
  3459. + {
  3460. + if (pi2s_config->tx_unmask_ch!=0)
  3461. + {
  3462. + u32 dmach = pi2s_config->tx_unmask_ch;
  3463. + u32 ch;
  3464. + for (ch = 0; ch < 16; ch++)
  3465. + {
  3466. + if (dmach& (1<<ch))
  3467. + {
  3468. + MSG("do unmask ch%d tisr=%d in tx_isr\n",ch,pi2s_config->tx_isr_cnt);
  3469. + GdmaUnMaskChannel(ch);
  3470. + }
  3471. + }
  3472. + pi2s_config->tx_unmask_ch = 0;
  3473. + }
  3474. + }
  3475. + spin_unlock_irqrestore(&pi2s_config->lock, flags);
  3476. +}
  3477. +
  3478. +void i2s_rx_task(unsigned long pData)
  3479. +{
  3480. + unsigned long flags;
  3481. + spin_lock_irqsave(&pi2s_config->lock, flags);
  3482. + //if (pi2s_config->bRxDMAEnable!=0)
  3483. + {
  3484. + if (pi2s_config->rx_unmask_ch!=0)
  3485. + {
  3486. + u32 dmach = pi2s_config->rx_unmask_ch;
  3487. + u32 ch;
  3488. + for (ch = 0; ch < 16; ch++)
  3489. + {
  3490. + if (dmach& (1<<ch))
  3491. + {
  3492. + MSG("do unmask ch%d risr=%d in rx_isr\n",ch,pi2s_config->rx_isr_cnt);
  3493. + GdmaUnMaskChannel(ch);
  3494. + }
  3495. + }
  3496. + pi2s_config->rx_unmask_ch = 0;
  3497. +
  3498. + }
  3499. + }
  3500. + spin_unlock_irqrestore(&pi2s_config->lock, flags);
  3501. +}
  3502. +
  3503. +
  3504. +void i2s_dma_unmask_handler(u32 dma_ch)
  3505. +{
  3506. + MSG("i2s_dma_unmask_handler ch=%d\n",dma_ch);
  3507. +
  3508. + GdmaUnMaskChannel(dma_ch);
  3509. +
  3510. + return;
  3511. +}
  3512. +
  3513. +void i2s_dma_tx_unmask_handler(u32 dma_ch)
  3514. +{
  3515. + MSG("i2s_dma_tx_unmask_handler ch=%d\n",dma_ch);
  3516. + pi2s_config->tx_unmask_ch |= (1<<dma_ch);
  3517. + tasklet_hi_schedule(&i2s_tx_tasklet);
  3518. + return;
  3519. +}
  3520. +
  3521. +void i2s_dma_rx_unmask_handler(u32 dma_ch)
  3522. +{
  3523. + MSG("i2s_dma_rx_unmask_handler ch=%d\n",dma_ch);
  3524. + pi2s_config->rx_unmask_ch |= (1<<dma_ch);
  3525. + tasklet_hi_schedule(&i2s_rx_tasklet);
  3526. + return;
  3527. +}
  3528. +
  3529. +void i2s_dma_mask_handler(u32 dma_ch)
  3530. +{
  3531. + MSG("i2s_dma_mask_handler ch=%d\n", dma_ch);
  3532. + GdmaMaskChannel(dma_ch);
  3533. + return;
  3534. +}
  3535. +
  3536. +void i2s_dma_tx_init(i2s_config_type* ptri2s_config)
  3537. +{
  3538. + memset(pi2s_config->pPage0TxBuf8ptr, 0, I2S_PAGE_SIZE);
  3539. + memset(pi2s_config->pPage1TxBuf8ptr, 0, I2S_PAGE_SIZE);
  3540. +#if defined(ARM_ARCH)
  3541. + GdmaI2sTx(i2s_txdma_addr0, I2S_TX_FIFO_WREG_PHY, 0, I2S_PAGE_SIZE, i2s_dma_tx_handler, i2s_dma_tx_unmask_handler);
  3542. + GdmaI2sTx(i2s_txdma_addr1, I2S_TX_FIFO_WREG_PHY, 1, I2S_PAGE_SIZE, i2s_dma_tx_handler, i2s_dma_tx_unmask_handler);
  3543. +#else
  3544. + GdmaI2sTx((u32)ptri2s_config->pPage0TxBuf8ptr, I2S_FIFO_WREG, 0, I2S_PAGE_SIZE, i2s_dma_tx_handler, i2s_dma_tx_unmask_handler);
  3545. + GdmaI2sTx((u32)ptri2s_config->pPage1TxBuf8ptr, I2S_FIFO_WREG, 1, I2S_PAGE_SIZE, i2s_dma_tx_handler, i2s_dma_tx_unmask_handler);
  3546. +#endif
  3547. +
  3548. + return;
  3549. +}
  3550. +
  3551. +void i2s_dma_rx_init(i2s_config_type* ptri2s_config)
  3552. +{
  3553. + memset(pi2s_config->pPage0RxBuf8ptr, 0, I2S_PAGE_SIZE);
  3554. + memset(pi2s_config->pPage1RxBuf8ptr, 0, I2S_PAGE_SIZE);
  3555. +
  3556. +#if defined(ARM_ARCH)
  3557. + GdmaI2sRx(I2S_RX_FIFO_RREG_PHY, i2s_rxdma_addr0, 0, I2S_PAGE_SIZE, i2s_dma_rx_handler, i2s_dma_rx_unmask_handler);
  3558. + GdmaI2sRx(I2S_RX_FIFO_RREG_PHY, i2s_rxdma_addr1, 1, I2S_PAGE_SIZE, i2s_dma_rx_handler, i2s_dma_rx_unmask_handler);
  3559. +#else
  3560. + GdmaI2sRx(I2S_RX_FIFO_RREG, (u32)ptri2s_config->pPage0RxBuf8ptr, 0, I2S_PAGE_SIZE, i2s_dma_rx_handler, i2s_dma_rx_unmask_handler);
  3561. + GdmaI2sRx(I2S_RX_FIFO_RREG, (u32)ptri2s_config->pPage1RxBuf8ptr, 1, I2S_PAGE_SIZE, i2s_dma_rx_handler, i2s_dma_rx_unmask_handler);
  3562. +#endif
  3563. +
  3564. + return;
  3565. +}
  3566. +
  3567. +void i2s_dma_tx_end_handle(i2s_config_type* ptri2s_config)
  3568. +{
  3569. + if (ptri2s_config->tx_w_idx < ptri2s_config->tx_r_idx)
  3570. + {
  3571. + ptri2s_config->end_cnt = (ptri2s_config->tx_w_idx + MAX_I2S_PAGE)-ptri2s_config->tx_r_idx;
  3572. + _printk("case1: w=%d, r=%d, end=%d\n", ptri2s_config->tx_w_idx, ptri2s_config->tx_r_idx, ptri2s_config->end_cnt);
  3573. + }
  3574. + else if (ptri2s_config->tx_w_idx > ptri2s_config->tx_r_idx)
  3575. + {
  3576. + ptri2s_config->end_cnt = ptri2s_config->tx_w_idx-ptri2s_config->tx_r_idx;
  3577. + _printk("case2: w=%d, r=%d, end=%d\n", ptri2s_config->tx_w_idx, ptri2s_config->tx_r_idx, ptri2s_config->end_cnt);
  3578. + }
  3579. + else
  3580. + {
  3581. + _printk("case3: w=%d, r=%d, end=%d\n", ptri2s_config->tx_w_idx, ptri2s_config->tx_r_idx, ptri2s_config->end_cnt);
  3582. +
  3583. + }
  3584. +
  3585. + if (ptri2s_config->end_cnt > 0)
  3586. + {
  3587. + interruptible_sleep_on(&(ptri2s_config->i2s_tx_qh));
  3588. + }
  3589. +
  3590. + return;
  3591. +}
  3592. +
  3593. +void i2s_tx_end_sleep_on(i2s_config_type* ptri2s_config)
  3594. +{
  3595. + while(ptri2s_config->tx_stop_cnt<3)
  3596. + interruptible_sleep_on(&(ptri2s_config->i2s_tx_qh));
  3597. +
  3598. + return;
  3599. +}
  3600. +
  3601. +void i2s_rx_end_sleep_on(i2s_config_type* ptri2s_config)
  3602. +{
  3603. + while(ptri2s_config->rx_stop_cnt<2)
  3604. + interruptible_sleep_on(&(ptri2s_config->i2s_rx_qh));
  3605. + return;
  3606. +}
  3607. +
  3608. +int i2s_dma_tx_soft_stop(i2s_config_type* ptri2s_config, u32 dma_ch)
  3609. +{
  3610. + if(dma_ch==GDMA_I2S_TX0)
  3611. + {
  3612. +#if defined(ARM_ARCH)
  3613. + GdmaI2sTx(i2s_txdma_addr0, I2S_TX_FIFO_WREG_PHY, 0, 4, i2s_dma_tx_handler, i2s_dma_tx_unmask_handler);
  3614. +#else
  3615. + GdmaI2sTx((u32)pi2s_config->pPage0TxBuf8ptr, I2S_TX_FIFO_WREG, 0, 4, i2s_dma_tx_handler, i2s_dma_tx_unmask_handler);
  3616. +#endif
  3617. + }
  3618. + else
  3619. + {
  3620. +#if defined(ARM_ARCH)
  3621. + GdmaI2sTx(i2s_txdma_addr1, I2S_TX_FIFO_WREG_PHY, 1, 4, i2s_dma_tx_handler, i2s_dma_tx_unmask_handler);
  3622. +#else
  3623. + GdmaI2sTx((u32)pi2s_config->pPage1TxBuf8ptr, I2S_TX_FIFO_WREG, 1, 4, i2s_dma_tx_handler, i2s_dma_tx_unmask_handler);
  3624. +#endif
  3625. + }
  3626. +
  3627. + return 0;
  3628. +}
  3629. +
  3630. +int i2s_dma_rx_soft_stop(i2s_config_type* ptri2s_config, u32 dma_ch)
  3631. +{
  3632. + if(dma_ch==GDMA_I2S_RX0)
  3633. + {
  3634. + memset(pi2s_config->pPage0RxBuf8ptr, 0, I2S_PAGE_SIZE);
  3635. +#if defined(ARM_ARCH)
  3636. + GdmaI2sRx(I2S_RX_FIFO_RREG_PHY, i2s_rxdma_addr0, 0, 4, i2s_dma_rx_handler, i2s_dma_rx_unmask_handler);
  3637. +#else
  3638. + GdmaI2sRx(I2S_RX_FIFO_RREG, (u32)pi2s_config->pPage0RxBuf8ptr, 0, 4, i2s_dma_rx_handler, i2s_dma_rx_unmask_handler);
  3639. +#endif
  3640. + }
  3641. + else
  3642. + {
  3643. + memset(pi2s_config->pPage1RxBuf8ptr, 0, I2S_PAGE_SIZE);
  3644. +#if defined(ARM_ARCH)
  3645. + GdmaI2sRx(I2S_RX_FIFO_RREG_PHY, i2s_rxdma_addr1, 1, 4, i2s_dma_rx_handler, i2s_dma_rx_unmask_handler);
  3646. +#else
  3647. + GdmaI2sRx(I2S_RX_FIFO_RREG, (u32)pi2s_config->pPage1RxBuf8ptr, 1, 4, i2s_dma_rx_handler, i2s_dma_rx_unmask_handler);
  3648. +#endif
  3649. + }
  3650. +
  3651. + return 0;
  3652. +}
  3653. +
  3654. +void i2s_gen_test_pattern(void)
  3655. +{
  3656. + int i;
  3657. + for (i=0; i<I2S_PAGE_SIZE; i++)
  3658. + {
  3659. + test_buf[i] = 0x5A;
  3660. + test_buf_1[i] = 0x11;
  3661. + test_buf_2[i] = 0x22;
  3662. +
  3663. + }
  3664. +}
  3665. +
  3666. +int i2s_put_audio(i2s_config_type* ptri2s_config, unsigned long arg)
  3667. +{
  3668. + unsigned long flags;
  3669. + int tx_w_idx;
  3670. +
  3671. + do{
  3672. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  3673. +
  3674. + if(((ptri2s_config->tx_w_idx+4)%MAX_I2S_PAGE)!=ptri2s_config->tx_r_idx)
  3675. + {
  3676. + ptri2s_config->tx_w_idx = (ptri2s_config->tx_w_idx+1)%MAX_I2S_PAGE;
  3677. + tx_w_idx = ptri2s_config->tx_w_idx;
  3678. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  3679. + //_printk("put TB[%d] for user write\n",ptri2s_config->tx_w_idx);
  3680. +#if defined(CONFIG_I2S_MMAP)
  3681. + put_user(tx_w_idx, (int*)arg);
  3682. +#else
  3683. + copy_from_user(ptri2s_config->pMMAPTxBufPtr[tx_w_idx], (char*)arg, I2S_PAGE_SIZE);
  3684. +#endif
  3685. + pi2s_status->txbuffer_len++;
  3686. + //spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  3687. + break;
  3688. + }
  3689. + else
  3690. + {
  3691. + /* Buffer Full */
  3692. + //_printk("TBF tr=%d, tw=%d\n", ptri2s_config->tx_r_idx, ptri2s_config->tx_w_idx);
  3693. + pi2s_status->txbuffer_ovrun++;
  3694. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  3695. + interruptible_sleep_on(&(ptri2s_config->i2s_tx_qh));
  3696. + if (ptri2s_config->bTxDMAEnable==0 && ptri2s_config->end_cnt==0)
  3697. + {
  3698. + _printk("wake up for exit i2s driver\n");
  3699. + put_user(-1, (int*)arg);
  3700. + break;
  3701. + }
  3702. + }
  3703. + }while(1);
  3704. +
  3705. + return 0;
  3706. +}
  3707. +
  3708. +int i2s_get_audio(i2s_config_type* ptri2s_config, unsigned long arg)
  3709. +{
  3710. + unsigned long flags;
  3711. + int rx_r_idx;
  3712. +
  3713. + do{
  3714. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  3715. + //_printk("GA rr=%d, rw=%d,i=%d\n", ptri2s_config->rx_r_idx, ptri2s_config->rx_w_idx,ptri2s_config->rx_isr_cnt);
  3716. + if(((ptri2s_config->rx_r_idx+2)%MAX_I2S_PAGE)!=ptri2s_config->rx_w_idx)
  3717. + {
  3718. + rx_r_idx = ptri2s_config->rx_r_idx;
  3719. + ptri2s_config->rx_r_idx = (ptri2s_config->rx_r_idx+1)%MAX_I2S_PAGE;
  3720. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  3721. +#if defined(CONFIG_I2S_MMAP)
  3722. + put_user(rx_r_idx, (int*)arg);
  3723. +#else
  3724. + copy_to_user((char*)arg, ptri2s_config->pMMAPRxBufPtr[rx_r_idx], I2S_PAGE_SIZE);
  3725. +#endif
  3726. + //_printk("rx_r_idx=%d\n", ptri2s_config->rx_r_idx);
  3727. + //ptri2s_config->rx_r_idx = (ptri2s_config->rx_r_idx+1)%MAX_I2S_PAGE;
  3728. + pi2s_status->rxbuffer_len--;
  3729. + //spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  3730. + break;
  3731. + }
  3732. + else
  3733. + {
  3734. + /* Buffer Full */
  3735. + //_printk("RBF rr=%d, rw=%d\n", ptri2s_config->rx_r_idx, ptri2s_config->rx_w_idx);
  3736. + pi2s_status->rxbuffer_ovrun++;
  3737. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  3738. + interruptible_sleep_on(&(ptri2s_config->i2s_rx_qh));
  3739. + }
  3740. +#if defined(CONFIG_I2S_WITH_AEC)
  3741. + if(aecFuncP->AECECDeq){
  3742. + aecFuncP->AECECDeq(0,pi2s_config->pMMAPRxBufPtr[ptri2s_config->rx_r_idx],I2S_PAGE_SIZE);
  3743. + }
  3744. +#endif
  3745. + }while(1);
  3746. +
  3747. + return 0;
  3748. +}
  3749. +
  3750. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,35)
  3751. +long i2s_ioctl (struct file *filp, unsigned int cmd, unsigned long arg)
  3752. +#else
  3753. +int i2s_ioctl (struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)
  3754. +#endif
  3755. +{
  3756. + int i ;
  3757. + i2s_config_type* ptri2s_config;
  3758. + unsigned long flags;
  3759. +
  3760. + ptri2s_config = filp->private_data;
  3761. + switch (cmd) {
  3762. + case I2S_RESET:
  3763. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  3764. + i2s_reset_config(ptri2s_config);
  3765. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  3766. + break;
  3767. + case I2S_SRATE:
  3768. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  3769. +#if defined(CONFIG_I2S_WM8960)
  3770. + if((arg>MAX_SRATE_HZ)||(arg<MIN_SRATE_HZ))
  3771. + {
  3772. + MSG("Audio sampling rate %u should be %d ~ %d Hz. Set SRate to 48000Hz\n", (u32)arg, MIN_SRATE_HZ, MAX_SRATE_HZ);
  3773. + ptri2s_config->srate = 48000;
  3774. + spin_unlock(&ptri2s_config->lock);
  3775. + break;
  3776. + }
  3777. +#elif defined(CONFIG_I2S_WM8750)
  3778. + if((arg>MAX_SRATE_HZ)||(arg<MIN_SRATE_HZ))
  3779. + {
  3780. + MSG("Audio sampling rate %u should be %d ~ %d Hz. Set SRate to 96000Hz\n", (u32)arg, MIN_SRATE_HZ, MAX_SRATE_HZ);
  3781. + ptri2s_config->srate = 96000;
  3782. + spin_unlock(&ptri2s_config->lock);
  3783. + break;
  3784. + }
  3785. +#endif
  3786. + ptri2s_config->srate = arg;
  3787. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  3788. + MSG("set audio sampling rate to %d Hz\n", ptri2s_config->srate);
  3789. + break;
  3790. + case I2S_TX_VOL:
  3791. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  3792. +
  3793. + if((int)arg > 127)
  3794. + ptri2s_config->txvol = 127;
  3795. + else if((int)arg < 48)
  3796. + ptri2s_config->txvol = 48;
  3797. + else
  3798. + ptri2s_config->txvol = arg;
  3799. +
  3800. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  3801. +
  3802. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  3803. +#if (defined(CONFIG_I2S_WM8750) || defined(CONFIG_I2S_WM8751))
  3804. + audiohw_set_master_vol(arg,arg);
  3805. +#elif defined(CONFIG_I2S_WM8960)
  3806. + audiohw_set_lineout_vol(1, ptri2s_config->txvol, ptri2s_config->txvol);
  3807. +#endif
  3808. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  3809. + break;
  3810. + case I2S_RX_VOL:
  3811. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  3812. +
  3813. + if((int)arg > 63)
  3814. + ptri2s_config->rxvol = 63;
  3815. + else if((int)arg < 0)
  3816. + ptri2s_config->rxvol = 0;
  3817. + else
  3818. + ptri2s_config->rxvol = arg;
  3819. +
  3820. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  3821. + break;
  3822. +#if defined (CONFIG_RALINK_MT7628) || defined(CONFIG_ARCH_MT7623)
  3823. + case I2S_WORD_LEN:
  3824. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  3825. + if((int)arg == 16)
  3826. + {
  3827. + ptri2s_config->wordlen_24b = 0;
  3828. + MSG("Enable 16 bit word length.\n");
  3829. + }
  3830. + else if ((int)arg == 24)
  3831. + {
  3832. + ptri2s_config->wordlen_24b = 1;
  3833. + MSG("Enable 24 bit word length.\n");
  3834. + }
  3835. + else
  3836. + {
  3837. + MSG("MT7628 only support 16bit/24bit word length.\n");
  3838. + spin_unlock(&ptri2s_config->lock);
  3839. + break;
  3840. + }
  3841. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  3842. + break;
  3843. + case I2S_ENDIAN_FMT:
  3844. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  3845. + if((int)arg == 1)
  3846. + {
  3847. + ptri2s_config->little_edn = 1;
  3848. + MSG("Little endian format.\n");
  3849. + }
  3850. + else
  3851. + {
  3852. + ptri2s_config->little_edn = 0;
  3853. + MSG("Big endian format.\n");
  3854. + }
  3855. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  3856. + break;
  3857. +#endif
  3858. + case I2S_INTERNAL_LBK:
  3859. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  3860. + if((int)arg == 1)
  3861. + {
  3862. + ptri2s_config->lbk = 1;
  3863. + MSG("Enable internal loopback.\n");
  3864. + }
  3865. + else
  3866. + {
  3867. + ptri2s_config->lbk = 0;
  3868. + MSG("Disable internal loopback.\n");
  3869. + }
  3870. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  3871. + break;
  3872. + case I2S_EXTERNAL_LBK:
  3873. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  3874. + if((int)arg == 1)
  3875. + {
  3876. + ptri2s_config->extlbk = 1;
  3877. + MSG("Enable external loopback.\n");
  3878. + }
  3879. + else
  3880. + {
  3881. + ptri2s_config->extlbk = 0;
  3882. + MSG("Disable external loopback.\n");
  3883. + }
  3884. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  3885. + break;
  3886. + case I2S_TXRX_COEXIST:
  3887. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  3888. + if((int)arg == 1)
  3889. + {
  3890. + ptri2s_config->txrx_coexist = 1;
  3891. + MSG("TX/RX coexist.\n");
  3892. + }
  3893. + else
  3894. + {
  3895. + ptri2s_config->txrx_coexist = 0;
  3896. + MSG("TX/RX coexist.\n");
  3897. + }
  3898. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  3899. + break;
  3900. +
  3901. + case I2S_TX_ENABLE:
  3902. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  3903. + MSG("I2S_TXENABLE\n");
  3904. +
  3905. + pi2s_config->tx_unmask_ch = 0;
  3906. + tasklet_init(&i2s_tx_tasklet, i2s_tx_task, (u32)pi2s_config);
  3907. +
  3908. + pi2s_config->dis_match = 0;
  3909. + pi2s_config->start_cnt = 0;
  3910. + i2s_gen_test_pattern();
  3911. +
  3912. + /* allocate tx buffer */
  3913. + i2s_txPagebuf_alloc(ptri2s_config);
  3914. + i2s_txbuf_alloc(ptri2s_config);
  3915. +
  3916. + /* Init two dma channels */
  3917. + i2s_dma_tx_init(ptri2s_config);
  3918. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  3919. +
  3920. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  3921. + /* Init & config all tx param */
  3922. + i2s_reset_tx_param(ptri2s_config);
  3923. + ptri2s_config->bTxDMAEnable = 1;
  3924. + /* Clear all ALSA related config */
  3925. + ptri2s_config->bALSAEnable = 0;
  3926. + ptri2s_config->bALSAMMAPEnable = 0;
  3927. +
  3928. + i2s_tx_config(ptri2s_config);
  3929. +
  3930. + if(ptri2s_config->bRxDMAEnable==0)
  3931. + i2s_clock_enable(ptri2s_config);
  3932. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  3933. +
  3934. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  3935. +#if defined(CONFIG_I2S_WM8960)||defined(CONFIG_I2S_WM8750)||defined(CONFIG_I2S_WM8751)
  3936. + audiohw_set_lineout_vol(1, ptri2s_config->txvol, ptri2s_config->txvol);
  3937. +#endif
  3938. + GdmaUnMaskChannel(GDMA_I2S_TX0);
  3939. +
  3940. + i2s_tx_enable(ptri2s_config);
  3941. +
  3942. + /* Kick off dma channel */
  3943. + //GdmaUnMaskChannel(GDMA_I2S_TX0);
  3944. +
  3945. + MSG("I2S_TXENABLE done\n");
  3946. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  3947. + break;
  3948. + case I2S_TX_DISABLE:
  3949. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  3950. + MSG("I2S_TXDISABLE\n");
  3951. +
  3952. + //tasklet_kill(&i2s_tx_tasklet);
  3953. +
  3954. + /* Handle tx end data */
  3955. + ptri2s_config->bTxDMAEnable = 0;
  3956. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  3957. +
  3958. + i2s_tx_end_sleep_on(ptri2s_config);
  3959. +
  3960. + tasklet_kill(&i2s_tx_tasklet);
  3961. +
  3962. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  3963. + i2s_reset_tx_param(ptri2s_config);
  3964. + i2s_tx_disable(ptri2s_config);
  3965. + if((ptri2s_config->bRxDMAEnable==0)&&(ptri2s_config->bTxDMAEnable==0))
  3966. + i2s_clock_disable(ptri2s_config);
  3967. +
  3968. + i2s_txbuf_free(ptri2s_config);
  3969. + if(ptri2s_config->mmap_index <= MAX_I2S_PAGE)
  3970. + ptri2s_config->mmap_index = 0;
  3971. +
  3972. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  3973. + break;
  3974. + case I2S_RX_ENABLE:
  3975. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  3976. + MSG("I2S_RXENABLE\n");
  3977. + pi2s_config->rx_unmask_ch = 0;
  3978. + tasklet_init(&i2s_rx_tasklet, i2s_rx_task, (u32)pi2s_config);
  3979. +
  3980. + /* allocate rx buffer */
  3981. + i2s_rxPagebuf_alloc(ptri2s_config);
  3982. + i2s_rxbuf_alloc(ptri2s_config);
  3983. +
  3984. + /* Init two dma channels */
  3985. + i2s_dma_rx_init(ptri2s_config);
  3986. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  3987. +
  3988. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  3989. + /* Init & config all rx param */
  3990. + i2s_reset_rx_param(ptri2s_config);
  3991. + ptri2s_config->bRxDMAEnable = 1;
  3992. + ptri2s_config->bALSAEnable = 0;
  3993. + ptri2s_config->bALSAMMAPEnable = 0;
  3994. +
  3995. + i2s_rx_config(ptri2s_config);
  3996. +
  3997. + if(ptri2s_config->bTxDMAEnable==0)
  3998. + i2s_clock_enable(ptri2s_config);
  3999. +
  4000. +#if defined(CONFIG_I2S_TXRX)
  4001. +#if defined(CONFIG_I2S_WM8960)||defined(CONFIG_I2S_WM8750)||defined(CONFIG_I2S_WM8751)
  4002. + audiohw_set_linein_vol(ptri2s_config->rxvol, ptri2s_config->rxvol);
  4003. +#endif
  4004. +#endif
  4005. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  4006. +
  4007. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  4008. + /* Kick off dma channel */
  4009. + GdmaUnMaskChannel(GDMA_I2S_RX0);
  4010. +
  4011. + i2s_rx_enable(ptri2s_config);
  4012. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  4013. + break;
  4014. + case I2S_RX_DISABLE:
  4015. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  4016. + MSG("I2S_RXDISABLE\n");
  4017. + //tasklet_kill(&i2s_rx_tasklet);
  4018. +
  4019. + ptri2s_config->bRxDMAEnable = 0;
  4020. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  4021. +
  4022. + i2s_rx_end_sleep_on(ptri2s_config);
  4023. + tasklet_kill(&i2s_rx_tasklet);
  4024. +
  4025. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  4026. + i2s_reset_rx_param(ptri2s_config);
  4027. + i2s_rx_disable(ptri2s_config);
  4028. + if((ptri2s_config->bRxDMAEnable==0)&&(ptri2s_config->bTxDMAEnable==0))
  4029. + i2s_clock_disable(ptri2s_config);
  4030. +
  4031. + i2s_rxbuf_free(ptri2s_config);
  4032. + if(ptri2s_config->mmap_index <= MAX_I2S_PAGE)
  4033. + ptri2s_config->mmap_index = 0;
  4034. + //i2s_rxPagebuf_free(ptri2s_config);
  4035. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  4036. + break;
  4037. + case I2S_PUT_AUDIO:
  4038. + i2s_put_audio(ptri2s_config, arg);
  4039. + break;
  4040. + case I2S_GET_AUDIO:
  4041. + i2s_get_audio(ptri2s_config, arg);
  4042. + break;
  4043. + case I2S_TX_STOP:
  4044. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  4045. + MSG("TxGDMA STOP\n");
  4046. + ptri2s_config->bTxDMAEnable = 0;
  4047. + ptri2s_config->end_cnt = 0;
  4048. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  4049. +
  4050. + while(ptri2s_config->tx_stop_cnt<3)
  4051. + interruptible_sleep_on(&(ptri2s_config->i2s_tx_qh));
  4052. +
  4053. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  4054. + i2s_reset_tx_param(ptri2s_config);
  4055. + i2s_tx_disable(ptri2s_config);
  4056. + if((ptri2s_config->bRxDMAEnable==0)&&(ptri2s_config->bTxDMAEnable==0))
  4057. + i2s_clock_disable(ptri2s_config);
  4058. +
  4059. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  4060. +
  4061. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  4062. + i2s_txbuf_free(ptri2s_config);
  4063. + if(ptri2s_config->mmap_index <= MAX_I2S_PAGE)
  4064. + ptri2s_config->mmap_index = 0;
  4065. + //i2s_txPagebuf_free(ptri2s_config);
  4066. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  4067. + break;
  4068. + case I2S_TX_PAUSE:
  4069. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  4070. + ptri2s_config->tx_pause_en = 1;
  4071. + MSG("* tx_pause_en = 1 *\n");
  4072. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  4073. + break;
  4074. + case I2S_TX_RESUME:
  4075. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  4076. + ptri2s_config->tx_pause_en = 0;
  4077. + MSG("# tx_pause_en = 0 #\n");
  4078. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  4079. + break;
  4080. + case I2S_RX_STOP:
  4081. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  4082. + MSG("I2S_RX_STOP\n");
  4083. + ptri2s_config->bRxDMAEnable = 0;
  4084. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  4085. +
  4086. + while(ptri2s_config->rx_stop_cnt<2)
  4087. + interruptible_sleep_on(&(ptri2s_config->i2s_rx_qh));
  4088. +
  4089. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  4090. + i2s_reset_rx_param(ptri2s_config);
  4091. + i2s_rx_disable(ptri2s_config);
  4092. + if((ptri2s_config->bRxDMAEnable==0)&&(ptri2s_config->bTxDMAEnable==0))
  4093. + i2s_clock_disable(ptri2s_config);
  4094. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  4095. +
  4096. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  4097. + i2s_rxbuf_free(ptri2s_config);
  4098. + if(ptri2s_config->mmap_index <= MAX_I2S_PAGE)
  4099. + ptri2s_config->mmap_index = 0;
  4100. + //i2s_rxPagebuf_free(ptri2s_config);
  4101. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  4102. + break;
  4103. + case I2S_RX_PAUSE:
  4104. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  4105. + ptri2s_config->rx_pause_en = 1;
  4106. + MSG("* rx_pause_en = 1 *\n");
  4107. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  4108. + break;
  4109. + case I2S_RX_RESUME:
  4110. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  4111. + ptri2s_config->rx_pause_en = 0;
  4112. + MSG("# rx_pause_en = 0 #\n");
  4113. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  4114. + break;
  4115. + case I2S_CODEC_MIC_BOOST:
  4116. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  4117. + if((int)arg > 3)
  4118. + ptri2s_config->micboost = 3;
  4119. + else if((int)arg < 0)
  4120. + ptri2s_config->micboost = 0;
  4121. + else
  4122. + ptri2s_config->micboost = arg;
  4123. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  4124. + break;
  4125. + case I2S_CODEC_MIC_IN:
  4126. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  4127. + if((int)arg == 1)
  4128. + ptri2s_config->micin = 1;
  4129. + else
  4130. + ptri2s_config->micin = 0;
  4131. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  4132. + break;
  4133. + case I2S_CLOCK_ENABLE:
  4134. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  4135. + i2s_clock_disable(ptri2s_config);
  4136. +#if defined(CONFIG_RALINK_MT7628) || defined(CONFIG_ARCH_MT7623)
  4137. + ptri2s_config->wordlen_24b = 1;
  4138. +#endif
  4139. + i2s_tx_config(ptri2s_config);
  4140. + i2s_clock_enable(ptri2s_config);
  4141. + i2s_tx_enable(ptri2s_config);
  4142. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  4143. + break;
  4144. + case I2S_DEBUG_CODEC:
  4145. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  4146. + for (i=0; i<10; i++)
  4147. + {
  4148. + _printk("### i=%d ###\n", i);
  4149. + i2s_clock_enable(ptri2s_config);
  4150. + i2s_clock_disable(ptri2s_config);
  4151. + }
  4152. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  4153. + break;
  4154. +#if defined(CONFIG_I2S_MS_CTRL)
  4155. + case I2S_MS_MODE_CTRL:
  4156. + spin_lock_irqsave(&ptri2s_config->lock, flags);
  4157. + if((int)arg == 1)
  4158. + {
  4159. + ptri2s_config->slave_en = 1;
  4160. + _printk("I2S in slave mode.\n");
  4161. + }
  4162. + else
  4163. + {
  4164. + ptri2s_config->slave_en = 0;
  4165. + _printk("I2S in master mode.\n");
  4166. + }
  4167. + spin_unlock_irqrestore(&ptri2s_config->lock, flags);
  4168. + break;
  4169. +#endif
  4170. + case I2S_DEBUG_CLKGEN:
  4171. + case I2S_DEBUG_INLBK:
  4172. + case I2S_DEBUG_EXLBK:
  4173. + case I2S_DEBUG_CODECBYPASS:
  4174. + case I2S_DEBUG_FMT:
  4175. +#if defined(CONFIG_I2S_WM8960)
  4176. + case I2S_DEBUG_CODEC_EXLBK:
  4177. +#endif
  4178. + case I2S_DEBUG_RESET:
  4179. + i2s_debug_cmd(cmd, arg);
  4180. + break;
  4181. + default :
  4182. + MSG("i2s_ioctl: command format error\n");
  4183. + }
  4184. +
  4185. + return 0;
  4186. +}
  4187. +
  4188. +/************************
  4189. + * API for ALSA *
  4190. + * *
  4191. + ************************/
  4192. +char* i2s_memPool_Alloc(i2s_config_type* ptri2s_config,int dir)
  4193. +{
  4194. + //_printk("%s\n",__func__);
  4195. + if(!ptri2s_config)
  4196. + return NULL;
  4197. + if(dir == STREAM_PLAYBACK){
  4198. +#if defined(CONFIG_I2S_MMAP)
  4199. + i2s_mmap_alloc(I2S_TOTAL_PAGE_SIZE);
  4200. +#endif
  4201. + i2s_txbuf_alloc(ptri2s_config);
  4202. + return ptri2s_config->pMMAPTxBufPtr[0];
  4203. + }else{
  4204. +#if defined(CONFIG_I2S_MMAP)
  4205. + i2s_mmap_alloc(I2S_TOTAL_PAGE_SIZE);
  4206. +#endif
  4207. + i2s_rxbuf_alloc(ptri2s_config);
  4208. + return ptri2s_config->pMMAPRxBufPtr[0];
  4209. + }
  4210. + return NULL;
  4211. +}
  4212. +
  4213. +void i2s_memPool_free(i2s_config_type* ptri2s_config,int dir)
  4214. +{
  4215. + if(!ptri2s_config)
  4216. + return;
  4217. + if(dir == STREAM_PLAYBACK){
  4218. +#if defined(CONFIG_I2S_MMAP)
  4219. + i2s_mem_unmap(ptri2s_config);
  4220. +#endif
  4221. + i2s_txbuf_free(ptri2s_config);
  4222. + }else{
  4223. +#if defined(CONFIG_I2S_MMAP)
  4224. + i2s_mem_unmap(ptri2s_config);
  4225. +#endif
  4226. + i2s_rxbuf_free(ptri2s_config);
  4227. + }
  4228. +
  4229. + return;
  4230. +}
  4231. +
  4232. +int i2s_page_prepare(i2s_config_type* ptri2s_config,int dir)
  4233. +{
  4234. + if(dir == STREAM_PLAYBACK){
  4235. + /* allocate tx buffer */
  4236. + i2s_txPagebuf_alloc(ptri2s_config);
  4237. + i2s_dma_tx_init(ptri2s_config);
  4238. + }else{
  4239. + /* allocate rx buffer */
  4240. + i2s_rxPagebuf_alloc(ptri2s_config);
  4241. + i2s_dma_rx_init(ptri2s_config);
  4242. + }
  4243. + return 0;
  4244. +}
  4245. +
  4246. +int i2s_page_release(i2s_config_type* ptri2s_config,int dir)
  4247. +{
  4248. + if(!ptri2s_config)
  4249. + return (-1);
  4250. + if(dir == STREAM_PLAYBACK)
  4251. + i2s_txPagebuf_free(ptri2s_config);
  4252. + else
  4253. + i2s_rxPagebuf_free(ptri2s_config);
  4254. +
  4255. + return 0;
  4256. +}
  4257. +
  4258. +int i2s_startup(void)
  4259. +{
  4260. + memset(pi2s_config, 0, sizeof(i2s_config_type));
  4261. +
  4262. +#ifdef I2S_STATISTIC
  4263. + memset(pi2s_status, 0, sizeof(i2s_status_type));
  4264. +#endif
  4265. +
  4266. + i2s_param_init(pi2s_config);
  4267. + pi2s_config->bALSAEnable = 1;
  4268. +#if defined(CONFIG_I2S_MMAP)
  4269. + pi2s_config->bALSAMMAPEnable = 1;
  4270. +#endif
  4271. +
  4272. +#if defined (CONFIG_RALINK_MT7628) || defined(CONFIG_ARCH_MT7623)
  4273. + pi2s_config->little_edn = 1;
  4274. +#endif
  4275. +
  4276. + init_waitqueue_head(&(pi2s_config->i2s_tx_qh));
  4277. + init_waitqueue_head(&(pi2s_config->i2s_rx_qh));
  4278. + spin_lock_init(&pi2s_config->lock);
  4279. +
  4280. + return 0;
  4281. +}
  4282. +
  4283. +int gdma_En_Switch(i2s_config_type* ptri2s_config,int dir,int enabled){
  4284. + if(!ptri2s_config)
  4285. + return (-1);
  4286. + if(dir == STREAM_PLAYBACK){
  4287. + ptri2s_config->bTxDMAEnable = enabled;
  4288. + //MSG("%s:%d\n",__func__,ptri2s_config->bTxDMAEnable);
  4289. + }else{
  4290. + ptri2s_config->bRxDMAEnable = enabled;
  4291. + }
  4292. + return 0;
  4293. +}
  4294. +
  4295. +int i2s_audio_exchange(i2s_config_type* ptri2s_config,int dir,unsigned long arg)
  4296. +{
  4297. + //MSG("I2S_PUT_AUDIO\n");
  4298. + if(!ptri2s_config)
  4299. + return (-1);
  4300. + if(dir == STREAM_PLAYBACK){
  4301. + i2s_put_audio(ptri2s_config, arg);
  4302. + }else{
  4303. + i2s_get_audio(ptri2s_config, arg);
  4304. + }
  4305. + return 0;
  4306. +}
  4307. +
  4308. +void gdma_mask_handler(u32 dma_ch)
  4309. +{
  4310. + i2s_dma_mask_handler(dma_ch);
  4311. + return;
  4312. +}
  4313. +
  4314. +void gdma_unmask_handler(u32 dma_ch)
  4315. +{
  4316. + i2s_dma_unmask_handler(dma_ch);
  4317. + return;
  4318. +}
  4319. +
  4320. +u32 i2s_mmap_phys_addr(i2s_config_type* ptri2s_config)
  4321. +{
  4322. + if((ptri2s_config->pMMAPBufPtr[0]!=NULL) && (ptri2s_config->mmap_index == MAX_I2S_PAGE))
  4323. + return (dma_addr_t)i2s_mmap_addr[0];
  4324. + else if((ptri2s_config->pMMAPBufPtr[MAX_I2S_PAGE]!=NULL) && (ptri2s_config->mmap_index == MAX_I2S_PAGE*2))
  4325. + return (dma_addr_t)i2s_mmap_addr[MAX_I2S_PAGE];
  4326. + else
  4327. + return -1;
  4328. +}
  4329. +
  4330. +EXPORT_SYMBOL(i2s_startup);
  4331. +EXPORT_SYMBOL(i2s_mem_unmap);
  4332. +EXPORT_SYMBOL(i2s_mmap_alloc);
  4333. +EXPORT_SYMBOL(i2s_mmap_remap);
  4334. +EXPORT_SYMBOL(i2s_param_init);
  4335. +EXPORT_SYMBOL(i2s_txbuf_alloc);
  4336. +EXPORT_SYMBOL(i2s_rxbuf_alloc);
  4337. +EXPORT_SYMBOL(i2s_txPagebuf_alloc);
  4338. +EXPORT_SYMBOL(i2s_rxPagebuf_alloc);
  4339. +EXPORT_SYMBOL(i2s_txbuf_free);
  4340. +EXPORT_SYMBOL(i2s_rxbuf_free);
  4341. +EXPORT_SYMBOL(i2s_txPagebuf_free);
  4342. +EXPORT_SYMBOL(i2s_rxPagebuf_free);
  4343. +EXPORT_SYMBOL(i2s_rx_disable);
  4344. +EXPORT_SYMBOL(i2s_tx_disable);
  4345. +EXPORT_SYMBOL(i2s_rx_enable);
  4346. +EXPORT_SYMBOL(i2s_tx_enable);
  4347. +EXPORT_SYMBOL(i2s_rx_config);
  4348. +EXPORT_SYMBOL(i2s_tx_config);
  4349. +EXPORT_SYMBOL(i2s_reset_config);
  4350. +EXPORT_SYMBOL(i2s_clock_disable);
  4351. +EXPORT_SYMBOL(i2s_clock_enable);
  4352. +EXPORT_SYMBOL(i2s_reset_rx_param);
  4353. +EXPORT_SYMBOL(i2s_reset_tx_param);
  4354. +EXPORT_SYMBOL(i2s_dma_rx_handler);
  4355. +EXPORT_SYMBOL(i2s_dma_tx_handler);
  4356. +EXPORT_SYMBOL(i2s_dma_unmask_handler);
  4357. +EXPORT_SYMBOL(i2s_dma_tx_unmask_handler);
  4358. +EXPORT_SYMBOL(i2s_dma_rx_unmask_handler);
  4359. +EXPORT_SYMBOL(i2s_dma_mask_handler);
  4360. +EXPORT_SYMBOL(i2s_dma_tx_init);
  4361. +EXPORT_SYMBOL(i2s_dma_rx_init);
  4362. +EXPORT_SYMBOL(i2s_tx_end_sleep_on);
  4363. +EXPORT_SYMBOL(i2s_rx_end_sleep_on);
  4364. +EXPORT_SYMBOL(i2s_mmap_phys_addr);
  4365. +EXPORT_SYMBOL(i2s_open);
  4366. +EXPORT_SYMBOL(pi2s_config);
  4367. +#if defined(CONFIG_I2S_IN_MCLK)
  4368. +#if defined(CONFIG_I2S_MCLK_12MHZ)
  4369. +EXPORT_SYMBOL(i2s_refclk_12m_enable);
  4370. +#endif
  4371. +#if defined(CONFIG_I2S_MCLK_12P288MHZ)
  4372. +EXPORT_SYMBOL(i2s_refclk_12p288m_enable);
  4373. +#endif
  4374. +#endif
  4375. +#if defined(MT7628_ASIC_BOARD) || defined(CONFIG_ARCH_MT7623)
  4376. +EXPORT_SYMBOL(i2s_driving_strength_adjust);
  4377. +#endif
  4378. +EXPORT_SYMBOL(i2s_refclk_disable);
  4379. +EXPORT_SYMBOL(i2s_refclk_gpio_out_config);
  4380. +EXPORT_SYMBOL(i2s_refclk_gpio_in_config);
  4381. +EXPORT_SYMBOL(i2s_share_pin_config);
  4382. +EXPORT_SYMBOL(i2s_share_pin_mt7623);
  4383. +EXPORT_SYMBOL(i2s_ws_config);
  4384. +EXPORT_SYMBOL(i2s_mode_config);
  4385. +EXPORT_SYMBOL(i2s_codec_frequency_config);
  4386. +EXPORT_SYMBOL(i2s_dma_tx_transf_data);
  4387. +EXPORT_SYMBOL(i2s_dma_tx_transf_zero);
  4388. +EXPORT_SYMBOL(i2s_dma_rx_transf_data);
  4389. +EXPORT_SYMBOL(i2s_dma_rx_transf_zero);
  4390. +EXPORT_SYMBOL(i2s_dma_tx_end_handle);
  4391. +EXPORT_SYMBOL(i2s_dma_tx_soft_stop);
  4392. +EXPORT_SYMBOL(i2s_dma_rx_soft_stop);
  4393. +EXPORT_SYMBOL(i2s_tx_task);
  4394. +EXPORT_SYMBOL(i2s_rx_task);
  4395. +
  4396. +EXPORT_SYMBOL(i2s_memPool_Alloc);
  4397. +EXPORT_SYMBOL(i2s_memPool_free);
  4398. +EXPORT_SYMBOL(i2s_page_prepare);
  4399. +EXPORT_SYMBOL(i2s_page_release);
  4400. +EXPORT_SYMBOL(gdma_En_Switch);
  4401. +EXPORT_SYMBOL(i2s_audio_exchange);
  4402. +EXPORT_SYMBOL(gdma_mask_handler);
  4403. +EXPORT_SYMBOL(gdma_unmask_handler);
  4404. +#if defined(CONFIG_I2S_WITH_AEC)
  4405. +EXPORT_SYMBOL(aecFuncP);
  4406. +#endif
  4407. +module_init(i2s_mod_init);
  4408. +module_exit(i2s_mod_exit);
  4409. +
  4410. +MODULE_DESCRIPTION("Ralink SoC I2S Controller Module");
  4411. +MODULE_AUTHOR("Qwert Chin <qwert.chin@ralinktech.com.tw>");
  4412. +MODULE_SUPPORTED_DEVICE("I2S");
  4413. +MODULE_VERSION(I2S_MOD_VERSION);
  4414. +MODULE_LICENSE("GPL");
  4415. +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,12)
  4416. +MODULE_PARM (i2sdrv_major, "i");
  4417. +#else
  4418. +module_param (i2sdrv_major, int, 0);
  4419. +#endif
  4420. --- /dev/null
  4421. +++ b/sound/soc/mtk/i2s_ctrl.h
  4422. @@ -0,0 +1,523 @@
  4423. +#ifndef __RALINK_I2S_H_
  4424. +#define __RALINK_I2S_H_
  4425. +
  4426. +#ifdef __KERNEL__
  4427. +//#include <asm/rt2880/rt_mmap.h>
  4428. +#endif
  4429. +
  4430. +#if defined(CONFIG_I2S_WITH_AEC)
  4431. +#include "aec/aec_api.h"
  4432. +#endif
  4433. +
  4434. +#define I2S_MAX_DEV 1
  4435. +#define I2S_MOD_VERSION "0.1"
  4436. +#define phys_to_bus(a) (a & 0x1FFFFFFF)
  4437. +
  4438. +#ifndef u32
  4439. +#define u32 unsigned int
  4440. +#endif
  4441. +
  4442. +#ifndef u16
  4443. +#define u16 unsigned short
  4444. +#endif
  4445. +
  4446. +#ifndef u8
  4447. +#define u8 unsigned char
  4448. +#endif
  4449. +
  4450. +#ifndef REGBIT
  4451. +#define REGBIT(x, n) (x << n)
  4452. +#endif
  4453. +
  4454. +#define Virtual2Physical(x) (((int)x) & 0x1fffffff)
  4455. +#define Physical2Virtual(x) (((int)x) | 0x80000000)
  4456. +#define Virtual2NonCache(x) (((int)x) | 0x20000000)
  4457. +#define Physical2NonCache(x) (((int)x) | 0xa0000000)
  4458. +#define NonCache2Virtual(x) (((int)x) & 0xDFFFFFFF)
  4459. +
  4460. +#if defined(CONFIG_I2S_MCLK_12MHZ)
  4461. +#define CONFIG_I2S_CODEC_PLL_EN 1
  4462. +#else
  4463. +#define CONFIG_I2S_CODEC_PLL_EN 0
  4464. +#endif
  4465. +
  4466. +//#define CONFIG_I2S_MS_CTRL
  4467. +//#define CONFIG_I2S_MS_MODE
  4468. +//#define memory_test
  4469. +
  4470. +#if defined (CONFIG_ARCH_MT7623)
  4471. +#define MT7623_ASIC_BOARD
  4472. +#define ARM_ARCH
  4473. +#endif
  4474. +
  4475. +#if defined (CONFIG_RALINK_MT7621)
  4476. +#define MT7621_ASIC_BOARD
  4477. +#endif
  4478. +
  4479. +#if defined (CONFIG_RALINK_MT7628)
  4480. +#define MT7628_ASIC_BOARD
  4481. +#endif
  4482. +
  4483. +//#define I2S_DEBUG_PRN
  4484. +#ifdef I2S_DEBUG_PRN
  4485. +#define MSG(fmt, args...) printk("I2S: " fmt, ## args)
  4486. +#else
  4487. +#define MSG(fmt, args...) { }
  4488. +#endif
  4489. +
  4490. +#ifdef I2S_DEBUG_PRN
  4491. +#define i2s_outw(address, value) do{printk("0x%08X = 0x%08X\n",(u32)address,(u32)value);*((volatile uint32_t *)(address)) = cpu_to_le32(value);}while(0)
  4492. +#else
  4493. +#define i2s_outw(address, value) *((volatile uint32_t *)(address)) = cpu_to_le32(value)
  4494. +#endif
  4495. +#define i2s_inw(address) le32_to_cpu(*(volatile u32 *)(address))
  4496. +
  4497. +/* HW feature definiations */
  4498. +#if defined(CONFIG_RALINK_RT3883)
  4499. +#define CONFIG_I2S_TXRX 1
  4500. +#define CONFIG_I2S_IN_MCLK 1
  4501. +//#define CONFIG_I2S_WS_EDGE 1
  4502. +#define CONFIG_I2S_FRAC_DIV 1
  4503. +#define CONFIG_I2S_IN_CLK 1
  4504. +#define CONFIG_I2S_MS_MODE 1
  4505. +#endif
  4506. +
  4507. +#if defined(CONFIG_RALINK_RT3352)||defined(CONFIG_RALINK_RT5350) || defined (CONFIG_RALINK_RT6855) \
  4508. + || defined(CONFIG_RALINK_RT6855A) || defined(CONFIG_RALINK_MT7620) || defined(CONFIG_RALINK_MT7621) \
  4509. + || defined (CONFIG_RALINK_MT7628) || defined(CONFIG_ARCH_MT7623)
  4510. +#define CONFIG_I2S_TXRX 1
  4511. +//#define CONFIG_I2S_WS_EDGE 1
  4512. +#define CONFIG_I2S_FRAC_DIV 1
  4513. +#define CONFIG_I2S_IN_CLK 1
  4514. +#endif
  4515. +
  4516. +#if defined(CONFIG_RALINK_RT3350)
  4517. +#define CONFIG_I2S_IN_MCLK 1
  4518. +#endif
  4519. +
  4520. +#if defined(CONFIG_RALINK_RT3052)
  4521. +#define CONFIG_I2S_MS_MODE 1
  4522. +#endif
  4523. +
  4524. +/* This is decided in menuconfig */
  4525. +#define CONFIG_I2S_MMAP 1
  4526. +
  4527. +/* For MT7623 ASIC PLL Setting */
  4528. +#if defined(CONFIG_ARCH_MT7623)
  4529. +#define AUD1PLL_CON0 (0xF0209270)
  4530. +#define AUD1PLL_CON1 (0xF0209274)
  4531. +#define AUD1PLL_CON2 (0xF0209278)
  4532. +#define AUD1PLL_PWR_CON0 (0xF020927C)
  4533. +#define AUD2PLL_CON0 (0xF02092C0)
  4534. +#define AUD2PLL_CON1 (0xF02092C4)
  4535. +#define AUD2PLL_CON2 (0xF02092C8)
  4536. +#define AUD2PLL_PWR_CON0 (0xF02092CC)
  4537. +#endif
  4538. +
  4539. +/* Register Map, Ref to RT3052 Data Sheet */
  4540. +
  4541. +/* Register Map Detail */
  4542. +#if defined(CONFIG_ARCH_MT7623)
  4543. +#define I2S_I2SCFG (ETHDMASYS_I2S_BASE+0x0000)
  4544. +#define I2S_INT_STATUS (ETHDMASYS_I2S_BASE+0x0004)
  4545. +#define I2S_INT_EN (ETHDMASYS_I2S_BASE+0x0008)
  4546. +#define I2S_FF_STATUS (ETHDMASYS_I2S_BASE+0x000c)
  4547. +#define I2S_FIFO_WREG (ETHDMASYS_I2S_BASE+0x0010)
  4548. +#define I2S_TX_FIFO_WREG I2S_FIFO_WREG
  4549. +#define I2S_RX_FIFO_RREG (ETHDMASYS_I2S_BASE+0x0014)
  4550. +#define I2S_I2SCFG1 (ETHDMASYS_I2S_BASE+0x0018)
  4551. +#define I2S_DIVINT_CFG (ETHDMASYS_I2S_BASE+0x0024)
  4552. +#define I2S_DIVCOMP_CFG (ETHDMASYS_I2S_BASE+0x0020)
  4553. +#else
  4554. +#define I2S_I2SCFG (RALINK_I2S_BASE+0x0000)
  4555. +#define I2S_INT_STATUS (RALINK_I2S_BASE+0x0004)
  4556. +#define I2S_INT_EN (RALINK_I2S_BASE+0x0008)
  4557. +#define I2S_FF_STATUS (RALINK_I2S_BASE+0x000c)
  4558. +#define I2S_FIFO_WREG (RALINK_I2S_BASE+0x0010)
  4559. +#define I2S_TX_FIFO_WREG I2S_FIFO_WREG
  4560. +#define I2S_RX_FIFO_RREG (RALINK_I2S_BASE+0x0014)
  4561. +#define I2S_I2SCFG1 (RALINK_I2S_BASE+0x0018)
  4562. +#define I2S_DIVINT_CFG (RALINK_I2S_BASE+0x0024)
  4563. +#define I2S_DIVCOMP_CFG (RALINK_I2S_BASE+0x0020)
  4564. +#endif
  4565. +
  4566. +
  4567. +/* I2SCFG bit field */
  4568. +#define I2S_EN 31
  4569. +#define I2S_DMA_EN 30
  4570. +#if defined(CONFIG_RALINK_MT7628) || defined(CONFIG_ARCH_MT7623)
  4571. +#define I2S_LITTLE_ENDIAN 29
  4572. +#define I2S_SYS_ENDIAN 28
  4573. +#elif defined(CONFIG_RALINK_RT6855A)
  4574. +#define I2S_BYTE_SWAP 28
  4575. +#endif
  4576. +#define I2S_TX_EN 24
  4577. +#define I2S_RX_EN 20
  4578. +#if defined(CONFIG_RALINK_MT7628) || defined(CONFIG_ARCH_MT7623)
  4579. +#define I2S_NORM_24BIT 18
  4580. +#define I2S_DATA_24BIT 17
  4581. +#endif
  4582. +#define I2S_SLAVE_MODE 16
  4583. +#define I2S_RX_FF_THRES 12
  4584. +#define I2S_RX_CH_SWAP 11
  4585. +#define I2S_RX_CH1_OFF 10
  4586. +#define I2S_RX_CH0_OFF 9
  4587. +#if defined(CONFIG_RALINK_RT3052)
  4588. +#define I2S_CLK_OUT_DIS 8
  4589. +#endif
  4590. +#define I2S_TX_FF_THRES 4
  4591. +#define I2S_TX_CH_SWAP 3
  4592. +#define I2S_TX_CH1_OFF 2
  4593. +#define I2S_TX_CH0_OFF 1
  4594. +#if defined(CONFIG_RALINK_RT3052)
  4595. +#define I2S_SLAVE_EN 0
  4596. +#else
  4597. +#define I2S_WS_INV 0
  4598. +#endif
  4599. +/* INT_EN bit field */
  4600. +#define I2S_RX_INT3_EN 7
  4601. +#define I2S_RX_INT2_EN 6
  4602. +#define I2S_RX_INT1_EN 5
  4603. +#define I2S_RX_INT0_EN 4
  4604. +#define I2S_TX_INT3_EN 3
  4605. +#define I2S_TX_INT2_EN 2
  4606. +#define I2S_TX_INT1_EN 1
  4607. +#define I2S_TX_INT0_EN 0
  4608. +
  4609. +/* INT_STATUS bit field */
  4610. +#define I2S_RX_DMA_FAULT 7
  4611. +#define I2S_RX_OVRUN 6
  4612. +#define I2S_RX_UNRUN 5
  4613. +#define I2S_RX_THRES 4
  4614. +#define I2S_TX_DMA_FAULT 3
  4615. +#define I2S_TX_OVRUN 2
  4616. +#define I2S_TX_UNRUN 1
  4617. +#define I2S_TX_THRES 0
  4618. +
  4619. +/* FF_STATUS bit field */
  4620. +#define I2S_RX_EPCNT 4
  4621. +#define I2S_TX_EPCNT 0
  4622. +/* I2S_DIVCOMP_CFG bit field */
  4623. +#define I2S_CLKDIV_EN 31
  4624. +
  4625. +/* I2S_CFG1 bit field */
  4626. +#define I2S_LBK_EN 31
  4627. +#define I2S_EXT_LBK_EN 30
  4628. +#if defined(CONFIG_RALINK_MT7628) || defined(CONFIG_ARCH_MT7623)
  4629. +#define I2S_DATA_FMT 0
  4630. +#endif
  4631. +
  4632. +/* FIFO_WREG bit field */
  4633. +#define I2S_FIFO_WDATA 0
  4634. +
  4635. +/* Constant definition */
  4636. +#define NFF_THRES 4
  4637. +#define I2S_PAGE_SIZE 3072//(3*4096)//(1152*2*2*2)
  4638. +#define I2S_MIN_PAGE_SIZE 4096
  4639. +#define MAX_I2S_PAGE 8
  4640. +#define I2S_TOTAL_PAGE_SIZE (I2S_PAGE_SIZE*MAX_I2S_PAGE)
  4641. +
  4642. +#if defined(CONFIG_I2S_WM8960)
  4643. +#define MAX_SRATE_HZ 48000
  4644. +#define MIN_SRATE_HZ 8000
  4645. +#elif defined(CONFIG_I2S_WM8750)
  4646. +#define MAX_SRATE_HZ 96000
  4647. +#define MIN_SRATE_HZ 8000
  4648. +#endif
  4649. +
  4650. +#define MAX_VOL_DB +0
  4651. +#define MIN_VOL_DB -127
  4652. +
  4653. +#define ALSA_MMAP_IDX_SHIFT 2
  4654. +#if defined(CONFIG_SND_MT76XX_SOC)
  4655. +#define STREAM_PLAYBACK SNDRV_PCM_STREAM_PLAYBACK
  4656. +#define STREAM_CAPTURE SNDRV_PCM_STREAM_CAPTURE
  4657. +#else
  4658. +#define STREAM_PLAYBACK 0
  4659. +#define STREAM_CAPTURE 1
  4660. +#endif
  4661. +
  4662. +/* I2S I/O command */
  4663. +#define I2S_SRATE 0
  4664. +#define I2S_VOL 1
  4665. +#define I2S_ENABLE 2
  4666. +#define I2S_DISABLE 3
  4667. +#define I2S_TX_ENABLE 27
  4668. +#define I2S_TX_DISABLE 3
  4669. +#define I2S_GET_WBUF 4
  4670. +#define I2S_PUT_WBUF 5
  4671. +#define I2S_RX_ENABLE 6
  4672. +#define I2S_RX_DISABLE 7
  4673. +#define I2S_PUT_AUDIO 4
  4674. +#define I2S_GET_AUDIO 5
  4675. +#define I2S_TX_VOL 1
  4676. +#define I2S_RX_VOL 8
  4677. +#define I2S_WORD_LEN 9
  4678. +#define I2S_ENDIAN_FMT 10
  4679. +#define I2S_INTERNAL_LBK 11
  4680. +#define I2S_TX_STOP 12
  4681. +#define I2S_DEBUG_CODEC 13
  4682. +#define I2S_MS_MODE_CTRL 14
  4683. +#define I2S_TX_PAUSE 15
  4684. +#define I2S_TX_RESUME 16
  4685. +#define I2S_RESET 17
  4686. +#define I2S_RX_STOP 18
  4687. +#define I2S_EXTERNAL_LBK 19
  4688. +#define I2S_TXRX_COEXIST 20
  4689. +#define I2S_RX_PAUSE 21
  4690. +#define I2S_RX_RESUME 22
  4691. +#define I2S_CODEC_MIC_BOOST 23
  4692. +#define I2S_CODEC_MIC_IN 24
  4693. +#define I2S_CLOCK_ENABLE 25
  4694. +#define I2S_TEST_TEST 26
  4695. +
  4696. +#define I2S_DEBUG 30
  4697. +#define I2S_DEBUG_CLKGEN 30
  4698. +#define I2S_DEBUG_INLBK 31
  4699. +#define I2S_DEBUG_EXLBK 32
  4700. +#define I2S_DEBUG_FMT 33
  4701. +#define I2S_DEBUG_RESET 34
  4702. +#define I2S_DEBUG_CODECBYPASS 35
  4703. +#if defined(CONFIG_I2S_WM8960)
  4704. +#define I2S_DEBUG_CODEC_EXLBK 36
  4705. +#endif
  4706. +
  4707. +/* configuration */
  4708. +#define CONFIG_I2S_TFF_THRES NFF_THRES
  4709. +#define CONFIG_I2S_CH_SWAP 0
  4710. +#if defined(CONFIG_I2S_MS_MODE)
  4711. +#define CONFIG_I2S_SLAVE_EN 0
  4712. +#else
  4713. +#define CONFIG_I2S_SLAVE_EN 1
  4714. +#endif
  4715. +
  4716. +/* driver status definition */
  4717. +#define I2S_OK 0
  4718. +#define I2S_OUTOFMEM 0x01
  4719. +#define I2S_GDMAFAILED 0x02
  4720. +#define I2S_REQUEST_IRQ_FAILED 0x04
  4721. +#define I2S_REG_SETUP_FAILED 0x08
  4722. +
  4723. +#define I2S_STATISTIC
  4724. +//#define I2S_HW_INTERRUPT_EN
  4725. +//#define I2S_SW_IRQ_EN
  4726. +#define I2S_MAJOR 234
  4727. +
  4728. +/* parameter for ALSA */
  4729. +/*GDMA for I2S Status*/
  4730. +#define GDMA_I2S_DIS (0)
  4731. +#define GDMA_I2S_EN (1)
  4732. +
  4733. +
  4734. +typedef struct i2s_status_t
  4735. +{
  4736. + u32 txdmafault;
  4737. + u32 txovrun;
  4738. + u32 txunrun;
  4739. + u32 txthres;
  4740. + int txbuffer_unrun;
  4741. + int txbuffer_ovrun;
  4742. + int txbuffer_len;
  4743. +
  4744. + u32 rxdmafault;
  4745. + u32 rxovrun;
  4746. + u32 rxunrun;
  4747. + u32 rxthres;
  4748. + int rxbuffer_unrun;
  4749. + int rxbuffer_ovrun;
  4750. + int rxbuffer_len;
  4751. +}i2s_status_type;
  4752. +
  4753. +
  4754. +typedef struct i2s_config_t
  4755. +{
  4756. +
  4757. + int srate;
  4758. + int txvol;
  4759. + int rxvol;
  4760. + u32 pos;
  4761. + u32 tx_isr_cnt;
  4762. + u32 rx_isr_cnt;
  4763. + int bSleep;
  4764. + int bTxDMAEnable;
  4765. + int bRxDMAEnable;
  4766. + int enLable;
  4767. + int micboost;
  4768. + int micin;
  4769. +
  4770. + /* parameters fo ALSA */
  4771. + int bALSAEnable;
  4772. + int bALSAMMAPEnable;
  4773. + unsigned char bTrigger[2];
  4774. + unsigned char bPreTrigger[2];
  4775. + unsigned char dmaStat[2];
  4776. + unsigned char i2sStat[2];
  4777. + unsigned int hw_base_frame[2];
  4778. + struct snd_pcm_substream *pss[2];
  4779. +
  4780. +#ifdef __KERNEL__
  4781. + spinlock_t lock;
  4782. + wait_queue_head_t i2s_tx_qh, i2s_rx_qh;
  4783. +#endif
  4784. + u32 dmach;
  4785. + u32 tx_unmask_ch;
  4786. + u32 rx_unmask_ch;
  4787. + u32 dma_unmask_status;
  4788. + u32 dma_done_status;
  4789. + u32 tx_ff_thres;
  4790. + u32 tx_ch_swap;
  4791. + u32 rx_ff_thres;
  4792. + u32 rx_ch_swap;
  4793. + u32 slave_en;
  4794. +
  4795. + u32 dis_match;
  4796. + int start_cnt;
  4797. +#if defined (CONFIG_RALINK_MT7628) || defined(CONFIG_ARCH_MT7623)
  4798. + int little_edn; /* test file's fmt: little endian->1; big endian->0 */
  4799. + int sys_endian; /* kernal' system fmt: little endian->0; big endian->1 */
  4800. +#endif
  4801. + int wordlen_24b;
  4802. + int codec_pll_en;
  4803. + int codec_num;
  4804. + int tx_pause_en;
  4805. + int rx_pause_en;
  4806. + int end_cnt;
  4807. + int txrx_coexist;
  4808. + int tx_stop_cnt;
  4809. + int rx_stop_cnt;
  4810. + /* for I2S_CFG1 */
  4811. + u32 lbk;
  4812. + u32 extlbk;
  4813. + u32 fmt;
  4814. +
  4815. + int w_idx;
  4816. + int r_idx;
  4817. +
  4818. + int tx_w_idx;
  4819. + int tx_r_idx;
  4820. + int rx_w_idx;
  4821. + int rx_r_idx;
  4822. + int mmap_index;
  4823. + int next_p0_idx;
  4824. + int next_p1_idx;
  4825. +
  4826. + u8* buf8ptr;
  4827. + char* pMMAPBufPtr[MAX_I2S_PAGE*2];
  4828. + char* pMMAPTxBufPtr[MAX_I2S_PAGE];
  4829. + char* pMMAPRxBufPtr[MAX_I2S_PAGE];
  4830. +
  4831. + union {
  4832. + u16* pPage0TxBuf16Ptr;
  4833. + u8* pPage0TxBuf8ptr;
  4834. + };
  4835. + union {
  4836. + u16* pPage1TxBuf16Ptr;
  4837. + u8* pPage1TxBuf8ptr;
  4838. + };
  4839. +
  4840. + union {
  4841. + u16* pPage0RxBuf16Ptr;
  4842. + u8* pPage0RxBuf8ptr;
  4843. + };
  4844. + union {
  4845. + u16* pPage1RxBuf16Ptr;
  4846. + u8* pPage1RxBuf8ptr;
  4847. + };
  4848. +
  4849. +}i2s_config_type;
  4850. +
  4851. +
  4852. +void i2s_gen_test_pattern(void);
  4853. +int i2s_mem_unmap(i2s_config_type* ptri2s_config);
  4854. +int i2s_param_init(i2s_config_type* ptri2s_config);
  4855. +int i2s_txbuf_alloc(i2s_config_type* ptri2s_config);
  4856. +int i2s_rxbuf_alloc(i2s_config_type* ptri2s_config);
  4857. +int i2s_txPagebuf_alloc(i2s_config_type* ptri2s_config);
  4858. +int i2s_rxPagebuf_alloc(i2s_config_type* ptri2s_config);
  4859. +int i2s_txbuf_free(i2s_config_type* ptri2s_config);
  4860. +int i2s_rxbuf_free(i2s_config_type* ptri2s_config);
  4861. +int i2s_txPagebuf_free(i2s_config_type* ptri2s_config);
  4862. +int i2s_rxPagebuf_free(i2s_config_type* ptri2s_config);
  4863. +int i2s_reset_tx_param(i2s_config_type* ptri2s_config);
  4864. +int i2s_reset_rx_param(i2s_config_type* ptri2s_config);
  4865. +int i2s_tx_config(i2s_config_type* ptri2s_config);
  4866. +int i2s_rx_config(i2s_config_type* ptri2s_config);
  4867. +int i2s_tx_enable(i2s_config_type* ptri2s_config);
  4868. +int i2s_tx_disable(i2s_config_type* ptri2s_config);
  4869. +int i2s_rx_enable(i2s_config_type* ptri2s_config);
  4870. +int i2s_rx_disable(i2s_config_type* ptri2s_config);
  4871. +int i2s_codec_enable(i2s_config_type* ptri2s_config);
  4872. +int i2s_codec_disable(i2s_config_type* ptri2s_config);
  4873. +int i2s_clock_enable(i2s_config_type* ptri2s_config);
  4874. +int i2s_clock_disable(i2s_config_type* ptri2s_config);
  4875. +int i2s_reset_config(i2s_config_type* ptri2s_config);
  4876. +int i2s_refclk_disable(void);
  4877. +int i2s_refclk_gpio_out_config(void);
  4878. +int i2s_refclk_gpio_in_config(void);
  4879. +int i2s_share_pin_config(i2s_config_type* ptri2s_config);
  4880. +int i2s_share_pin_mt7623(i2s_config_type* ptri2s_config);
  4881. +int i2s_master_clock_gpio_out_mt7623(void);
  4882. +int i2s_slave_clock_gpio_in_mt7623(void);
  4883. +int i2s_ws_config(i2s_config_type* ptri2s_config, unsigned long index);
  4884. +int i2s_mode_config(u32 slave_en);
  4885. +int i2s_codec_frequency_config(i2s_config_type* ptri2s_config, unsigned long index);
  4886. +void i2s_tx_end_sleep_on(i2s_config_type* ptri2s_config);
  4887. +void i2s_rx_end_sleep_on(i2s_config_type* ptri2s_config);
  4888. +
  4889. +#if defined(CONFIG_I2S_MCLK_12MHZ)
  4890. +int i2s_refclk_12m_enable(void);
  4891. +#endif
  4892. +#if defined(CONFIG_I2S_MCLK_12P288MHZ)
  4893. +int i2s_refclk_12p288m_enable(void);
  4894. +#endif
  4895. +
  4896. +#if defined(MT7621_ASIC_BOARD)
  4897. +int i2s_pll_config_mt7621(unsigned long index);
  4898. +int i2s_pll_refclk_set(void);
  4899. +#endif
  4900. +#if defined(MT7623_ASIC_BOARD)
  4901. +int i2s_pll_config_mt7623(unsigned long index);
  4902. +#endif
  4903. +#if defined(MT7628_ASIC_BOARD) || defined(CONFIG_ARCH_MT7623)
  4904. +int i2s_driving_strength_adjust(void);
  4905. +#endif
  4906. +#if defined(I2S_STATISTIC)
  4907. +void i2s_int_status(u32 dma_ch);
  4908. +#endif
  4909. +void i2s_dma_tx_handler(u32 dma_ch);
  4910. +void i2s_dma_rx_handler(u32 dma_ch);
  4911. +void i2s_dma_unmask_handler(u32 dma_ch);
  4912. +void i2s_dma_mask_handler(u32 dma_ch);
  4913. +void i2s_dma_tx_init(i2s_config_type* ptri2s_config);
  4914. +void i2s_dma_rx_init(i2s_config_type* ptri2s_config);
  4915. +void i2s_tx_task(unsigned long pData);
  4916. +void i2s_rx_task(unsigned long pData);
  4917. +void i2s_dma_tx_unmask_handler(u32 dma_ch);
  4918. +void i2s_dma_rx_unmask_handler(u32 dma_ch);
  4919. +int i2s_dma_tx_transf_data(i2s_config_type* ptri2s_config, u32 dma_ch);
  4920. +int i2s_dma_tx_transf_zero(i2s_config_type* ptri2s_config, u32 dma_ch);
  4921. +int i2s_dma_rx_transf_data(i2s_config_type* ptri2s_config, u32 dma_ch);
  4922. +int i2s_dma_rx_transf_zero(i2s_config_type* ptri2s_config, u32 dma_ch);
  4923. +void i2s_dma_tx_end_handle(i2s_config_type* ptri2s_config);
  4924. +int i2s_dma_tx_soft_stop(i2s_config_type* ptri2s_config, u32 dma_ch);
  4925. +int i2s_dma_rx_soft_stop(i2s_config_type* ptri2s_config, u32 dma_ch);
  4926. +
  4927. +int i2s_page_prepare(i2s_config_type* ptri2s_config,int dir);
  4928. +int i2s_page_release(i2s_config_type* ptri2s_config,int dir);
  4929. +int gdma_En_Switch(i2s_config_type* ptri2s_config,int dir,int enabled);
  4930. +int i2s_startup(void);
  4931. +int i2s_audio_exchange(i2s_config_type* ptri2s_config,int dir,unsigned long arg);
  4932. +void gdma_unmask_handler(u32 dma_ch);
  4933. +char* i2s_memPool_Alloc(i2s_config_type* ptri2s_config,int dir);
  4934. +void i2s_memPool_free(i2s_config_type* ptri2s_config,int dir);
  4935. +u32 i2s_mmap_phys_addr(i2s_config_type* ptri2s_config);
  4936. +
  4937. +#if !defined(CONFIG_I2S_TXRX)
  4938. +#define GdmaI2sRx //GdmaI2sRx
  4939. +#endif
  4940. +
  4941. +#define RALINK_I2S_VERSION "1.0"
  4942. +#define I2SDRV_DEVNAME "i2s0"
  4943. +
  4944. +#endif /* __RALINK_I2S_H_ */
  4945. +
  4946. --- /dev/null
  4947. +++ b/sound/soc/mtk/mt76xx_i2s.c
  4948. @@ -0,0 +1,304 @@
  4949. +/*
  4950. + * mtk_audio_drv.c
  4951. + *
  4952. + * Created on: 2013/8/20
  4953. + * Author: MTK04880
  4954. + */
  4955. +#include <linux/init.h>
  4956. +#include <linux/version.h>
  4957. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,35)
  4958. +#include <linux/sched.h>
  4959. +#endif
  4960. +#include <linux/module.h>
  4961. +#include <linux/kernel.h> /* printk() */
  4962. +#include <linux/slab.h> /* kmalloc() */
  4963. +#include <linux/fs.h> /* everything... */
  4964. +#include <linux/errno.h> /* error codes */
  4965. +#include <linux/types.h> /* size_t */
  4966. +#include <linux/proc_fs.h>
  4967. +#include <linux/fcntl.h> /* O_ACCMODE */
  4968. +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,36)
  4969. +#include <asm/system.h> /* cli(), *_flags */
  4970. +#endif
  4971. +#include <asm/uaccess.h> /* copy_from/to_user */
  4972. +#include <linux/interrupt.h>
  4973. +#include <linux/mm.h>
  4974. +#include <linux/dma-mapping.h>
  4975. +#include <sound/core.h>
  4976. +#include <linux/pci.h>
  4977. +#include <sound/pcm.h>
  4978. +#include <sound/pcm_params.h>
  4979. +#include <sound/soc.h>
  4980. +#include <sound/soc-dapm.h>
  4981. +#include <sound/initval.h>
  4982. +#include "ralink_gdma.h"
  4983. +#include "mt76xx_i2s.h"
  4984. +
  4985. +/****************************/
  4986. +/*GLOBAL VARIABLE DEFINITION*/
  4987. +/****************************/
  4988. +extern i2s_config_type* pi2s_config;
  4989. +
  4990. +/****************************/
  4991. +/*FUNCTION DECLRATION */
  4992. +/****************************/
  4993. +static int mt76xx_i2s_set_fmt(struct snd_soc_dai *cpu_dai,\
  4994. + unsigned int fmt);
  4995. +
  4996. +//static int mt76xx_i2s_shutdown(struct snd_pcm_substream *substream,
  4997. +// struct snd_soc_dai *dai);
  4998. +static int mt76xx_i2s_startup(struct snd_pcm_substream *substream,
  4999. + struct snd_soc_dai *dai);
  5000. +static int mt76xx_i2s_hw_params(struct snd_pcm_substream *substream,\
  5001. + struct snd_pcm_hw_params *params,\
  5002. + struct snd_soc_dai *dai);
  5003. +static int mt76xx_i2s_play_prepare(struct snd_pcm_substream *substream,struct snd_soc_dai *dai);
  5004. +static int mt76xx_i2s_rec_prepare(struct snd_pcm_substream *substream,struct snd_soc_dai *dai);
  5005. +static int mt76xx_i2s_hw_free(struct snd_pcm_substream *substream,struct snd_soc_dai *dai);
  5006. +static int mt76xx_i2s_prepare(struct snd_pcm_substream *substream, struct snd_soc_dai *dai);
  5007. +
  5008. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,20)
  5009. +static int mt76xx_i2s_drv_probe(struct platform_device *pdev);
  5010. +static int mt76xx_i2s_drv_remove(struct platform_device *pdev);
  5011. +#endif
  5012. +/****************************/
  5013. +/*STRUCTURE DEFINITION */
  5014. +/****************************/
  5015. +
  5016. +
  5017. +static struct snd_soc_dai_ops mt76xx_i2s_dai_ops = {
  5018. + .startup = mt76xx_i2s_startup,
  5019. + .hw_params = mt76xx_i2s_hw_params,
  5020. + .hw_free = mt76xx_i2s_hw_free,
  5021. + //.shutdown = mt76xx_i2s_shutdown,
  5022. + .prepare = mt76xx_i2s_prepare,
  5023. + .set_fmt = mt76xx_i2s_set_fmt,
  5024. + //.set_sysclk = mt76xx_i2s_set_sysclk,
  5025. +};
  5026. +
  5027. +const struct snd_soc_component_driver mt76xx_i2s_component = {
  5028. + .name = "mt76xx-i2s",
  5029. +};
  5030. +
  5031. +struct snd_soc_dai_driver mt76xx_i2s_dai = {
  5032. + .playback = {
  5033. + .channels_min = 1,
  5034. + .channels_max = 2,
  5035. + .rates = (SNDRV_PCM_RATE_8000|SNDRV_PCM_RATE_11025|\
  5036. + SNDRV_PCM_RATE_16000|SNDRV_PCM_RATE_22050|SNDRV_PCM_RATE_32000|\
  5037. + SNDRV_PCM_RATE_44100|SNDRV_PCM_RATE_48000),
  5038. +
  5039. + .formats = (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
  5040. + SNDRV_PCM_FMTBIT_S24_LE),
  5041. + },
  5042. + .capture = {
  5043. + .channels_min = 1,
  5044. + .channels_max = 2,
  5045. + .rates = (SNDRV_PCM_RATE_8000|SNDRV_PCM_RATE_11025|\
  5046. + SNDRV_PCM_RATE_16000|SNDRV_PCM_RATE_22050|SNDRV_PCM_RATE_32000|\
  5047. + SNDRV_PCM_RATE_44100|SNDRV_PCM_RATE_48000),
  5048. + .formats = (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
  5049. + SNDRV_PCM_FMTBIT_S24_LE),
  5050. + },
  5051. + .ops = &mt76xx_i2s_dai_ops,
  5052. + .symmetric_rates = 1,
  5053. +};
  5054. +
  5055. +/****************************/
  5056. +/*FUNCTION BODY */
  5057. +/****************************/
  5058. +
  5059. +static int mt76xx_i2s_set_fmt(struct snd_soc_dai *cpu_dai,
  5060. + unsigned int fmt)
  5061. +{//TODO
  5062. +
  5063. + //printk("******* %s *******\n", __func__);
  5064. + return 0;
  5065. +}
  5066. +
  5067. +static int mt76xx_i2s_play_prepare(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
  5068. +{
  5069. + //printk("******* %s *******\n", __func__);
  5070. + i2s_config_type* rtd = (i2s_config_type*)substream->runtime->private_data;
  5071. + rtd->pss[SNDRV_PCM_STREAM_PLAYBACK] = substream;
  5072. + if(! rtd->i2sStat[SNDRV_PCM_STREAM_PLAYBACK]){
  5073. + i2s_reset_tx_param( rtd);
  5074. + i2s_tx_config( rtd);
  5075. + gdma_En_Switch(rtd, STREAM_PLAYBACK, GDMA_I2S_EN);
  5076. +
  5077. + if( rtd->bRxDMAEnable==0)
  5078. + i2s_clock_enable( rtd);
  5079. +
  5080. + i2s_tx_enable( rtd);
  5081. + rtd->i2sStat[SNDRV_PCM_STREAM_PLAYBACK] = 1;
  5082. + MSG("I2S_TXENABLE done\n");
  5083. + }
  5084. +
  5085. + return 0;
  5086. +}
  5087. +
  5088. +static int mt76xx_i2s_rec_prepare(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
  5089. +{
  5090. +
  5091. + //printk("******* %s *******\n", __func__);
  5092. + i2s_config_type* rtd = (i2s_config_type*)substream->runtime->private_data;
  5093. + rtd->pss[SNDRV_PCM_STREAM_CAPTURE] = substream;
  5094. + if(! rtd->i2sStat[SNDRV_PCM_STREAM_CAPTURE]) {
  5095. + i2s_reset_rx_param(rtd);
  5096. + i2s_rx_config(rtd);
  5097. + gdma_En_Switch(rtd, STREAM_CAPTURE, GDMA_I2S_EN);
  5098. +
  5099. + if(rtd->bTxDMAEnable==0)
  5100. + i2s_clock_enable(rtd);
  5101. +
  5102. + i2s_rx_enable(rtd);
  5103. + rtd->i2sStat[SNDRV_PCM_STREAM_CAPTURE] = 1;
  5104. + }
  5105. + return 0;
  5106. +}
  5107. +
  5108. +/*static int mt76xx_i2s_shutdown(struct snd_pcm_substream *substream,
  5109. + struct snd_soc_dai *dai)
  5110. +{
  5111. + //i2s_config_type* rtd = (i2s_config_type*)substream->runtime->private_data;
  5112. + //printk("******* %s *******\n", __func__);
  5113. + return 0;
  5114. +}
  5115. +*/
  5116. +static int mt76xx_i2s_startup(struct snd_pcm_substream *substream,
  5117. + struct snd_soc_dai *dai)
  5118. +{
  5119. +
  5120. + //printk("******* %s *******\n", __func__);
  5121. + if((!pi2s_config->i2sStat[SNDRV_PCM_STREAM_PLAYBACK]) && (!pi2s_config->i2sStat[SNDRV_PCM_STREAM_CAPTURE])){
  5122. + i2s_startup();
  5123. + if(!pi2s_config)
  5124. + return -1;
  5125. + i2s_reset_config(pi2s_config);
  5126. + }
  5127. + substream->runtime->private_data = pi2s_config;
  5128. + return 0;
  5129. +}
  5130. +
  5131. +static int mt76xx_i2s_hw_params(struct snd_pcm_substream *substream,\
  5132. + struct snd_pcm_hw_params *params,\
  5133. + struct snd_soc_dai *dai){
  5134. + unsigned int srate = 0;
  5135. + //unsigned long data;
  5136. + struct snd_pcm_runtime *runtime = substream->runtime;
  5137. + i2s_config_type* rtd = runtime->private_data;
  5138. +
  5139. + //printk("******* %s *******\n", __func__);
  5140. + switch(params_rate(params)){
  5141. + case 8000:
  5142. + srate = 8000;
  5143. + break;
  5144. + case 16000:
  5145. + srate = 16000;
  5146. + break;
  5147. + case 32000:
  5148. + srate = 32000;
  5149. + break;
  5150. + case 44100:
  5151. + srate = 44100;
  5152. + break;
  5153. + case 48000:
  5154. + srate = 48000;
  5155. + break;
  5156. + default:
  5157. + srate = 44100;
  5158. + //MSG("audio sampling rate %u should be %d ~ %d Hz\n", (u32)params_rate(params), MIN_SRATE_HZ, MAX_SRATE_HZ);
  5159. + break;
  5160. + }
  5161. + if(srate){
  5162. + if((rtd->bRxDMAEnable != GDMA_I2S_EN) && (rtd->bTxDMAEnable != GDMA_I2S_EN)){
  5163. + rtd->srate = srate;
  5164. + MSG("set audio sampling rate to %d Hz\n", rtd->srate);
  5165. + }
  5166. + }
  5167. +
  5168. + return 0;
  5169. +}
  5170. +static int mt76xx_i2s_hw_free(struct snd_pcm_substream *substream,struct snd_soc_dai *dai){
  5171. +
  5172. + //printk("******* %s *******\n", __func__);
  5173. + i2s_config_type* rtd = (i2s_config_type*)substream->runtime->private_data;
  5174. + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK){
  5175. + if(rtd->i2sStat[SNDRV_PCM_STREAM_PLAYBACK]){
  5176. + MSG("I2S_TXDISABLE\n");
  5177. + i2s_reset_tx_param(rtd);
  5178. +
  5179. + if((rtd->bRxDMAEnable==0)&&(rtd->bTxDMAEnable==0)){
  5180. + i2s_clock_disable(rtd);
  5181. + }
  5182. + rtd->i2sStat[SNDRV_PCM_STREAM_PLAYBACK] = 0;
  5183. + }
  5184. + }
  5185. + else{
  5186. + if(rtd->i2sStat[SNDRV_PCM_STREAM_CAPTURE]){
  5187. + MSG("I2S_RXDISABLE\n");
  5188. + i2s_reset_rx_param(rtd);
  5189. +
  5190. + if((rtd->bRxDMAEnable==0)&&(rtd->bTxDMAEnable==0)){
  5191. + i2s_clock_disable(rtd);
  5192. + }
  5193. + rtd->i2sStat[SNDRV_PCM_STREAM_CAPTURE] = 0;
  5194. + }
  5195. + }
  5196. + return 0;
  5197. +}
  5198. +static int mt76xx_i2s_prepare(struct snd_pcm_substream *substream,struct snd_soc_dai *dai)
  5199. +{
  5200. +
  5201. + //printk("******* %s *******\n", __func__);
  5202. + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  5203. + return mt76xx_i2s_play_prepare(substream, dai);
  5204. + else
  5205. + return mt76xx_i2s_rec_prepare(substream, dai);
  5206. +
  5207. + return 0;
  5208. +}
  5209. +
  5210. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,20)
  5211. +static int mt76xx_i2s_drv_probe(struct platform_device *pdev)
  5212. +{
  5213. + //printk("****** %s ******\n", __func__);
  5214. + return snd_soc_register_component(&pdev->dev, &mt76xx_i2s_component,
  5215. + &mt76xx_i2s_dai, 1);
  5216. +}
  5217. +
  5218. +static int mt76xx_i2s_drv_remove(struct platform_device *pdev)
  5219. +{
  5220. + snd_soc_unregister_component(&pdev->dev);
  5221. + return 0;
  5222. +}
  5223. +
  5224. +static struct platform_driver mt76xx_i2s_driver = {
  5225. + .probe = mt76xx_i2s_drv_probe,
  5226. + .remove = mt76xx_i2s_drv_remove,
  5227. + .driver = {
  5228. + .name = "mt76xx-i2s",
  5229. + .owner = THIS_MODULE,
  5230. + },
  5231. +};
  5232. +
  5233. +static int __init mt76xx_i2s_init(void)
  5234. +{
  5235. +
  5236. + //printk("****** %s ******\n", __func__);
  5237. + return platform_driver_register(&mt76xx_i2s_driver);
  5238. +}
  5239. +
  5240. +static void __exit mt76xx_i2s_exit(void)
  5241. +{
  5242. + //printk("****** %s ******\n", __func__);
  5243. + platform_driver_unregister(&mt76xx_i2s_driver);
  5244. +}
  5245. +
  5246. +module_init(mt76xx_i2s_init);
  5247. +module_exit(mt76xx_i2s_exit);
  5248. +
  5249. +MODULE_AUTHOR("Dora Chen");
  5250. +MODULE_DESCRIPTION("Stretch MT76xx I2S Interface");
  5251. +MODULE_LICENSE("GPL");
  5252. +#endif
  5253. --- /dev/null
  5254. +++ b/sound/soc/mtk/mt76xx_i2s.h
  5255. @@ -0,0 +1,18 @@
  5256. +/*
  5257. + * mtk_i2s.h
  5258. + *
  5259. + * Created on: 2013/8/20
  5260. + * Author: MTK04880
  5261. + */
  5262. +
  5263. +#ifndef MTK_I2S_H_
  5264. +#define MTK_I2S_H_
  5265. +
  5266. +
  5267. +#ifdef __KERNEL__
  5268. +//#include <asm/rt2880/rt_mmap.h>
  5269. +#include <linux/fs.h>
  5270. +#endif
  5271. +
  5272. +#include "i2s_ctrl.h"
  5273. +#endif /* MTK_I2S_H_ */
  5274. --- /dev/null
  5275. +++ b/sound/soc/mtk/mt76xx_machine.c
  5276. @@ -0,0 +1,317 @@
  5277. +/*
  5278. + * mt76xx_machine.c
  5279. + *
  5280. + */
  5281. +#include <linux/init.h>
  5282. +#include <linux/version.h>
  5283. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,35)
  5284. +#include <linux/sched.h>
  5285. +#endif
  5286. +#include <linux/module.h>
  5287. +#include <linux/kernel.h> /* printk() */
  5288. +#include <linux/slab.h> /* kmalloc() */
  5289. +#include <linux/fs.h> /* everything... */
  5290. +#include <linux/errno.h> /* error codes */
  5291. +#include <linux/types.h> /* size_t */
  5292. +#include <linux/proc_fs.h>
  5293. +#include <linux/fcntl.h> /* O_ACCMODE */
  5294. +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,36)
  5295. +#include <asm/system.h> /* cli(), *_flags */
  5296. +#endif
  5297. +#include <asm/uaccess.h> /* copy_from/to_user */
  5298. +#include <linux/interrupt.h>
  5299. +#include <linux/mm.h>
  5300. +#include <linux/dma-mapping.h>
  5301. +#include <sound/core.h>
  5302. +#include <linux/pci.h>
  5303. +#include <sound/pcm.h>
  5304. +#include <sound/pcm_params.h>
  5305. +#include <sound/soc.h>
  5306. +#include <sound/soc-dapm.h>
  5307. +#include <sound/initval.h>
  5308. +#include <linux/i2c.h>
  5309. +#include <linux/ioport.h>
  5310. +#include <linux/delay.h>
  5311. +#include "ralink_gdma.h"
  5312. +#include "mt76xx_i2s.h"
  5313. +#include "mt76xx_machine.h"
  5314. +#if defined(CONFIG_SND_SOC_WM8960)
  5315. +#include "../codecs/wm8960.h"
  5316. +#endif
  5317. +
  5318. +#define I2C_AUDIO_DEV_ID (0)
  5319. +/****************************/
  5320. +/*FUNCTION DECLRATION */
  5321. +/****************************/
  5322. +extern unsigned long i2s_codec_12p288Mhz[11];
  5323. +extern unsigned long i2s_codec_12Mhz[11];
  5324. +
  5325. +
  5326. +static int mt76xx_codec_clock_hwparams(struct snd_pcm_substream *substream,\
  5327. + struct snd_pcm_hw_params *params);
  5328. +static int mt76xx_codec_startup(struct snd_pcm_substream *substream);
  5329. +static int mt76xx_codec_init(struct snd_soc_pcm_runtime *rtd);
  5330. +extern struct snd_soc_dai_driver mt76xx_i2s_dai;
  5331. +extern struct snd_soc_platform_driver mt76xx_soc_platform;
  5332. +struct platform_device *mt76xx_audio_device;
  5333. +
  5334. +#if defined(CONFIG_SND_SOC_WM8960)
  5335. +extern struct snd_soc_dai wm8960_dai;
  5336. +extern struct snd_soc_codec_device soc_codec_dev_wm8960;
  5337. +#endif
  5338. +
  5339. +static struct snd_soc_ops mtk_audio_ops = {
  5340. + .hw_params = mt76xx_codec_clock_hwparams,
  5341. + .startup = mt76xx_codec_startup,
  5342. +};
  5343. +
  5344. +static struct snd_soc_dai_link mtk_audio_dai = {
  5345. + .name = "mtk_dai",
  5346. + .stream_name = "WMserious PCM",
  5347. + .cpu_dai_name = "mt76xx-i2s",
  5348. + .codec_dai_name = "wm8960-hifi",
  5349. + .codec_name = "wm8960.0-001a",
  5350. + .platform_name = "mt76xx-pcm",
  5351. + .ignore_pmdown_time = true,
  5352. + .init = mt76xx_codec_init,
  5353. + .ops = &mtk_audio_ops,
  5354. +};
  5355. +
  5356. +static struct snd_soc_card mtk_audio_card = {
  5357. + .name = "MTK APSoC I2S",
  5358. + .owner = THIS_MODULE,
  5359. + .dai_link = &mtk_audio_dai,//I2S/Codec
  5360. + .num_links = 1,
  5361. +};
  5362. +
  5363. +static int mt76xx_codec_clock_hwparams(struct snd_pcm_substream *substream,
  5364. + struct snd_pcm_hw_params *params)
  5365. +{
  5366. + struct snd_soc_pcm_runtime *p = substream->private_data;
  5367. + struct snd_soc_dai *codec_dai = p->codec_dai;
  5368. + struct snd_pcm_runtime *runtime = substream->runtime;
  5369. + i2s_config_type* rtd = runtime->private_data;
  5370. + unsigned long data,index = 0;
  5371. + unsigned long* pTable;
  5372. + int mclk,ret,targetClk = 0;
  5373. +
  5374. + /*For duplex mode, avoid setting twice.*/
  5375. + if((rtd->bRxDMAEnable == GDMA_I2S_EN) || (rtd->bTxDMAEnable == GDMA_I2S_EN))
  5376. + return 0;
  5377. +#if defined(CONFIG_I2S_MCLK_12MHZ)
  5378. + mclk = 12000000;
  5379. +#elif defined(CONFIG_I2S_MCLK_12P288MHZ)
  5380. + mclk = 12288000;
  5381. +#else
  5382. + mclk = 12000000;
  5383. +#endif
  5384. + //snd_soc_dai_set_sysclk(codec_dai,0,mclk, SND_SOC_CLOCK_IN);
  5385. +
  5386. + switch(params_rate(params)){
  5387. + case 8000:
  5388. + index = 0;
  5389. + targetClk = 12288000;
  5390. + break;
  5391. + case 12000:
  5392. + index = 2;
  5393. + targetClk = 12288000;
  5394. + break;
  5395. + case 16000:
  5396. + index = 3;
  5397. + targetClk = 12288000;
  5398. + break;
  5399. + case 24000:
  5400. + index = 5;
  5401. + targetClk = 12288000;
  5402. + break;
  5403. + case 32000:
  5404. + index = 6;
  5405. + targetClk = 12288000;
  5406. + break;
  5407. + case 48000:
  5408. + index = 8;
  5409. + targetClk = 12288000;
  5410. + break;
  5411. + case 11025:
  5412. + index = 1;
  5413. + targetClk = 11289600;
  5414. + break;
  5415. + case 22050:
  5416. + index = 4;
  5417. + targetClk = 11289600;
  5418. + break;
  5419. + case 44100:
  5420. + index = 7;
  5421. + targetClk = 11289600;
  5422. + break;
  5423. + case 88200:
  5424. + index = 9;
  5425. + targetClk = 11289600;
  5426. + break;
  5427. + case 96000:
  5428. + index = 10;
  5429. + targetClk = 11289600;
  5430. + break;
  5431. + default:
  5432. + index = 7;
  5433. + targetClk = 12288000;
  5434. + //MSG("audio sampling rate %u should be %d ~ %d Hz\n", (u32)params_rate(params), MIN_SRATE_HZ, MAX_SRATE_HZ);
  5435. + break;
  5436. + }
  5437. +#if defined(CONFIG_SND_SOC_WM8960)
  5438. + /*
  5439. + * There is a fixed divide by 4 in the PLL and a selectable
  5440. + * divide by N after the PLL which should be set to divide by 2 to meet this requirement.
  5441. + * */
  5442. + ret = snd_soc_dai_set_pll(codec_dai, 0, 0,mclk, targetClk*2);
  5443. + /* From app notes: allow Vref to stabilize to reduce clicks */
  5444. + if(rtd->slave_en){
  5445. + //printk("WM8960 is in master mode\n");
  5446. + ret = snd_soc_dai_set_clkdiv(codec_dai, WM8960_DCLKDIV, 0x1c4);
  5447. + ret = snd_soc_dai_set_clkdiv(codec_dai, WM8960_SYSCLKDIV, 0x5);
  5448. + }
  5449. +
  5450. +#endif
  5451. + if(!rtd->slave_en)
  5452. + snd_soc_dai_set_fmt(codec_dai,SND_SOC_DAIFMT_CBS_CFS|SND_SOC_DAIFMT_I2S|SND_SOC_DAIFMT_NB_NF);
  5453. + else{
  5454. + snd_soc_dai_set_fmt(codec_dai,SND_SOC_DAIFMT_CBM_CFM|SND_SOC_DAIFMT_I2S|SND_SOC_DAIFMT_NB_NF);
  5455. + }
  5456. + mdelay(5);
  5457. +
  5458. +#if defined(CONFIG_SND_SOC_WM8960)
  5459. +#if defined(CONFIG_I2S_MCLK_12MHZ)
  5460. + pTable = i2s_codec_12Mhz;
  5461. + data = pTable[index];
  5462. +#else
  5463. + pTable = i2s_codec_12p288Mhz;
  5464. + data = pTable[index];
  5465. +#endif
  5466. + if(rtd->codec_pll_en)
  5467. + ret = snd_soc_dai_set_clkdiv(codec_dai, WM8960_DACDIV, (data<<3)|0x5);
  5468. + else
  5469. + ret = snd_soc_dai_set_clkdiv(codec_dai, WM8960_DACDIV, (data<<3|0x4));
  5470. +#endif
  5471. +
  5472. + return 0;
  5473. +}
  5474. +
  5475. +static int mt76xx_codec_startup(struct snd_pcm_substream *substream)
  5476. +{
  5477. + //printk("******* %s *******\n", __func__);
  5478. + return 0;
  5479. +}
  5480. +static int mt76xx_codec_init(struct snd_soc_pcm_runtime *rtd)
  5481. +{
  5482. +
  5483. + //printk("******* %s *******\n", __func__);
  5484. + return 0;
  5485. +}
  5486. +
  5487. +static struct i2c_board_info i2c_board_info[] = {
  5488. + {
  5489. +#if defined(CONFIG_SND_SOC_WM8750)
  5490. + I2C_BOARD_INFO("wm8750", (0x36 >> 1)),
  5491. +#elif defined(CONFIG_SND_SOC_WM8960)
  5492. + I2C_BOARD_INFO("codec_wm8960", (0x34)),
  5493. + }, {
  5494. + I2C_BOARD_INFO("wm8960", (0x34 >> 1)),
  5495. +#endif
  5496. + }
  5497. +};
  5498. +
  5499. +static struct platform_device *soc_mtk_i2s_dev;
  5500. +static struct platform_device *soc_mtk_pcm_dev;
  5501. +
  5502. +static int __init mt76xx_machine_init(void)
  5503. +{
  5504. + //struct snd_soc_device *socdev = &mtk_audio_devdata;
  5505. + //struct i2c_adapter *adapter = NULL;
  5506. + //struct i2c_client *client = NULL;
  5507. + int ret = 0;
  5508. + struct i2c_adapter *adapter = NULL;
  5509. + struct i2c_client *client = NULL;
  5510. +
  5511. + adapter = i2c_get_adapter(I2C_AUDIO_DEV_ID);
  5512. + if (!adapter)
  5513. + return -ENODEV;
  5514. + client = i2c_new_device(adapter, &i2c_board_info[0]);
  5515. + if (!client)
  5516. + return -ENODEV;
  5517. + i2c_get_clientdata(client);
  5518. +
  5519. + client = i2c_new_device(adapter, &i2c_board_info[1]);
  5520. + if (!client)
  5521. + return -ENODEV;
  5522. + i2c_get_clientdata(client);
  5523. +
  5524. + i2c_put_adapter(adapter);
  5525. +
  5526. + soc_mtk_i2s_dev =
  5527. + platform_device_register_simple("mt76xx-i2s", -1, NULL, 0);
  5528. + if (IS_ERR(soc_mtk_i2s_dev))
  5529. + return PTR_ERR(soc_mtk_i2s_dev);
  5530. +
  5531. + soc_mtk_pcm_dev =
  5532. + platform_device_register_simple("mt76xx-pcm", -1, NULL, 0);
  5533. + if (IS_ERR(soc_mtk_pcm_dev))
  5534. + return PTR_ERR(soc_mtk_pcm_dev);
  5535. +
  5536. + mt76xx_audio_device = platform_device_alloc("soc-audio",-1);
  5537. + if (mt76xx_audio_device == NULL) {
  5538. + ret = -ENOMEM;
  5539. + goto err_device_alloc;
  5540. + }
  5541. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38)
  5542. + platform_set_drvdata(mt76xx_audio_device, &mtk_audio_card);
  5543. +#else
  5544. + platform_set_drvdata(mt76xx_audio_device, &mtk_audio_devdata);
  5545. + mtk_audio_devdata.dev = &mt76xx_audio_device->dev;
  5546. +#endif
  5547. +
  5548. + /*Ralink I2S register process end*/
  5549. + ret = platform_device_add(mt76xx_audio_device);
  5550. + if (ret) {
  5551. + printk("mtk audio device : platform_device_add failed (%d)\n",ret);
  5552. + goto err_device_add;
  5553. + }
  5554. +
  5555. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38)
  5556. +#else
  5557. + snd_soc_register_dai(&mt76xx_i2s_dai);
  5558. +#endif
  5559. +
  5560. + return 0;
  5561. +
  5562. +err_device_add:
  5563. + if (mt76xx_audio_device!= NULL) {
  5564. + platform_device_put(mt76xx_audio_device);
  5565. + mt76xx_audio_device = NULL;
  5566. + }
  5567. +err_device_alloc:
  5568. + return ret;
  5569. +}
  5570. +
  5571. +
  5572. +static void __exit mt76xx_machine_exit(void)
  5573. +{
  5574. +
  5575. + platform_device_unregister(mt76xx_audio_device);
  5576. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,20)
  5577. + /* Do nothing */
  5578. +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38)
  5579. + snd_soc_unregister_platform(&mt76xx_audio_device->dev);
  5580. +#else
  5581. + snd_soc_unregister_platform(&mt76xx_soc_platform);
  5582. +#endif
  5583. + platform_device_unregister(soc_mtk_i2s_dev);
  5584. + platform_device_unregister(soc_mtk_pcm_dev);
  5585. +
  5586. + mt76xx_audio_device = NULL;
  5587. +}
  5588. +
  5589. +//module_init(mt76xx_machine_init);
  5590. +late_initcall(mt76xx_machine_init);
  5591. +module_exit(mt76xx_machine_exit);
  5592. +//EXPORT_SYMBOL_GPL(mt76xx_soc_platform);
  5593. +MODULE_LICENSE("GPL");
  5594. --- /dev/null
  5595. +++ b/sound/soc/mtk/mt76xx_machine.h
  5596. @@ -0,0 +1,21 @@
  5597. +/*
  5598. + * mtk_audio_device.h
  5599. + *
  5600. + * Created on: 2013/10/23
  5601. + * Author: MTK04880
  5602. + */
  5603. +
  5604. +#ifndef MT76XX_MACHINE_H_
  5605. +#define MT76XX_MACHINE_H_
  5606. +#include <sound/pcm.h>
  5607. +#include <sound/pcm_params.h>
  5608. +#include <sound/soc.h>
  5609. +#include <sound/soc-dapm.h>
  5610. +
  5611. +#if 0
  5612. +#ifdef CONFIG_I2S_MMAP
  5613. +#undef CONFIG_I2S_MMAP
  5614. +#endif
  5615. +#endif
  5616. +
  5617. +#endif /* MT76XX_MACHINE_H_ */
  5618. --- /dev/null
  5619. +++ b/sound/soc/mtk/mt76xx_pcm.c
  5620. @@ -0,0 +1,499 @@
  5621. +/*
  5622. + * mt76xx_pcm.c
  5623. + *
  5624. + * Created on: 2013/9/6
  5625. + * Author: MTK04880
  5626. + */
  5627. +
  5628. +#include <linux/init.h>
  5629. +#include <linux/version.h>
  5630. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,35)
  5631. +#include <linux/sched.h>
  5632. +#endif
  5633. +#include <linux/module.h>
  5634. +#include <linux/kernel.h> /* printk() */
  5635. +#include <linux/slab.h> /* kmalloc() */
  5636. +#include <linux/fs.h> /* everything... */
  5637. +#include <linux/errno.h> /* error codes */
  5638. +#include <linux/types.h> /* size_t */
  5639. +#include <linux/proc_fs.h>
  5640. +#include <linux/fcntl.h> /* O_ACCMODE */
  5641. +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,36)
  5642. +#include <asm/system.h> /* cli(), *_flags */
  5643. +#endif
  5644. +#include <asm/uaccess.h> /* copy_from/to_user */
  5645. +#include <linux/interrupt.h>
  5646. +#include <linux/mm.h>
  5647. +#include <linux/dma-mapping.h>
  5648. +#include <sound/core.h>
  5649. +#include <linux/pci.h>
  5650. +#include <sound/pcm.h>
  5651. +#include <sound/pcm_params.h>
  5652. +#include <sound/soc.h>
  5653. +#include <sound/soc-dapm.h>
  5654. +#include <sound/initval.h>
  5655. +#include "ralink_gdma.h"
  5656. +#include "mt76xx_i2s.h"
  5657. +
  5658. +#define GDMA_PAGE_SIZE I2S_PAGE_SIZE
  5659. +#define GDMA_PAGE_NUM MAX_I2S_PAGE
  5660. +#define GDMA_TOTAL_PAGE_SIZE I2S_TOTAL_PAGE_SIZE
  5661. +
  5662. +dma_addr_t i2s_txdma_addr, i2s_rxdma_addr;
  5663. +dma_addr_t i2s_mmap_addr[GDMA_PAGE_NUM*2];
  5664. +
  5665. +extern struct tasklet_struct i2s_tx_tasklet;
  5666. +extern struct tasklet_struct i2s_rx_tasklet;
  5667. +extern int i2s_mmap_remap(struct vm_area_struct *vma, unsigned long size);
  5668. +extern void i2s_tx_end_sleep_on(i2s_config_type* ptri2s_config);
  5669. +extern void i2s_rx_end_sleep_on(i2s_config_type* ptri2s_config);
  5670. +
  5671. +static int mt76xx_pcm_open(struct snd_pcm_substream *substream);
  5672. +static int mt76xx_pcm_new(struct snd_soc_pcm_runtime *rtd);
  5673. +static void mt76xx_pcm_free(struct snd_pcm *pcm);
  5674. +static int mt76xx_pcm_close(struct snd_pcm_substream *substream);
  5675. +static snd_pcm_uframes_t mt76xx_pcm_pointer(struct snd_pcm_substream *substream);
  5676. +static int mt76xx_pcm_trigger(struct snd_pcm_substream *substream, int cmd);
  5677. +static int mt76xx_pcm_prepare(struct snd_pcm_substream *substream);
  5678. +static int mt76xx_pcm_hw_params(struct snd_pcm_substream *substream,\
  5679. + struct snd_pcm_hw_params *hw_params);
  5680. +static int mt76xx_pcm_copy(struct snd_pcm_substream *substream, int channel,\
  5681. + snd_pcm_uframes_t pos,void __user *buf, snd_pcm_uframes_t count);
  5682. +static int mt76xx_pcm_mmap(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
  5683. +static int mt76xx_pcm_hw_free(struct snd_pcm_substream *substream);
  5684. +
  5685. +static int mt76xx_pcm_free_dma_buffer(struct snd_pcm_substream *substream,int stream);
  5686. +static int mt76xx_pcm_allocate_dma_buffer(struct snd_pcm_substream *substream,int stream);
  5687. +
  5688. +#if LINUX_VERSION_CODE > KERNEL_VERSION(3,10,20)
  5689. +static int mt76xx_platform_drv_probe(struct platform_device *pdev);
  5690. +static int mt76xx_platform_drv_remove(struct platform_device *pdev);
  5691. +#endif
  5692. +
  5693. +static const struct snd_pcm_hardware mt76xx_pcm_hwparam = {
  5694. +#if defined(CONFIG_I2S_MMAP)
  5695. + .info = (SNDRV_PCM_INFO_INTERLEAVED |
  5696. + SNDRV_PCM_INFO_PAUSE |
  5697. + SNDRV_PCM_INFO_RESUME |
  5698. + SNDRV_PCM_INFO_MMAP |
  5699. + SNDRV_PCM_INFO_MMAP_VALID),
  5700. +#else
  5701. + .info = (SNDRV_PCM_INFO_INTERLEAVED |
  5702. + SNDRV_PCM_INFO_PAUSE |
  5703. + SNDRV_PCM_INFO_RESUME),
  5704. +#endif
  5705. + .formats = SNDRV_PCM_FMTBIT_S16_LE,
  5706. + .period_bytes_min = GDMA_PAGE_SIZE,
  5707. + .period_bytes_max = GDMA_PAGE_SIZE,
  5708. + .periods_min = 1,
  5709. + .periods_max = GDMA_PAGE_NUM,
  5710. + .buffer_bytes_max = GDMA_TOTAL_PAGE_SIZE,
  5711. +};
  5712. +
  5713. +static struct snd_pcm_ops mt76xx_pcm_ops = {
  5714. +
  5715. + .open = mt76xx_pcm_open,
  5716. + .ioctl = snd_pcm_lib_ioctl,
  5717. + .hw_params = mt76xx_pcm_hw_params,
  5718. + .hw_free = mt76xx_pcm_hw_free,
  5719. + .trigger = mt76xx_pcm_trigger,
  5720. + .prepare = mt76xx_pcm_prepare,
  5721. + .pointer = mt76xx_pcm_pointer,
  5722. + .close = mt76xx_pcm_close,
  5723. +#if defined(CONFIG_I2S_MMAP)
  5724. + .mmap = mt76xx_pcm_mmap,
  5725. +#endif
  5726. + .copy = mt76xx_pcm_copy,
  5727. +};
  5728. +#if LINUX_VERSION_CODE > KERNEL_VERSION(3,10,0)
  5729. +struct snd_soc_platform_driver mt76xx_soc_platform = {
  5730. + .ops = &mt76xx_pcm_ops,
  5731. + .pcm_new = mt76xx_pcm_new,
  5732. + .pcm_free = mt76xx_pcm_free,
  5733. +};
  5734. +#else
  5735. +struct snd_soc_platform mt76xx_soc_platform = {
  5736. + .name = "mtk-dma",
  5737. + .pcm_ops = &mt76xx_pcm_ops,
  5738. + .pcm_new = mt76xx_pcm_new,
  5739. + .pcm_free = mt76xx_pcm_free,
  5740. +};
  5741. +#endif
  5742. +
  5743. +static int mt76xx_pcm_close(struct snd_pcm_substream *substream){
  5744. +
  5745. + //printk("******* %s *********\n", __func__);
  5746. + return 0;
  5747. +}
  5748. +
  5749. +static snd_pcm_uframes_t mt76xx_pcm_pointer(struct snd_pcm_substream *substream)
  5750. +{
  5751. + struct snd_pcm_runtime *runtime = substream->runtime;
  5752. + i2s_config_type* rtd = runtime->private_data;
  5753. + unsigned int offset = 0;
  5754. + //int buff_frame_bond = bytes_to_frames(runtime, GDMA_PAGE_SIZE);
  5755. + //printk("\n******* %s *********\n", __func__);
  5756. +
  5757. + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK){
  5758. + offset = bytes_to_frames(runtime, GDMA_PAGE_SIZE*rtd->tx_r_idx);
  5759. + //printk("r:%d w:%d (%d) \n",rtd->tx_r_idx,rtd->tx_w_idx,(runtime->control->appl_ptr/buff_frame_bond)%GDMA_PAGE_NUM);
  5760. + }
  5761. + else{
  5762. + offset = bytes_to_frames(runtime, GDMA_PAGE_SIZE*rtd->rx_w_idx);
  5763. + //printk("w:%d r:%d appl_ptr:%x\n",rtd->rx_w_idx,rtd->rx_r_idx,(runtime->control->appl_ptr/buff_frame_bond)%GDMA_PAGE_NUM);
  5764. + }
  5765. + return offset;
  5766. +}
  5767. +
  5768. +
  5769. +static int mt76xx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  5770. +{
  5771. + int ret = 0;
  5772. + i2s_config_type* rtd = (i2s_config_type*)substream->runtime->private_data;
  5773. + //struct snd_pcm_runtime *runtime= substream->runtime;
  5774. +
  5775. + //printk("******* %s *********\n", __func__);
  5776. +/* printk("trigger cmd:%s\n",(cmd==SNDRV_PCM_TRIGGER_START)?"START":\
  5777. + (cmd==SNDRV_PCM_TRIGGER_RESUME)?"RESUME":\
  5778. + (cmd==SNDRV_PCM_TRIGGER_PAUSE_RELEASE)?"PAUSE_RELEASE":\
  5779. + (cmd==SNDRV_PCM_TRIGGER_STOP)?"STOP":\
  5780. + (cmd==SNDRV_PCM_TRIGGER_SUSPEND)?"SUSPEND":\
  5781. + (cmd==SNDRV_PCM_TRIGGER_PAUSE_PUSH)?"PAUSE_PUSH":"default");
  5782. +*/
  5783. + switch (cmd) {
  5784. + case SNDRV_PCM_TRIGGER_START:
  5785. + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  5786. + rtd->bTrigger[SNDRV_PCM_STREAM_PLAYBACK] = 1;
  5787. + } else {
  5788. + rtd->bTrigger[SNDRV_PCM_STREAM_CAPTURE] = 1;
  5789. + }
  5790. + break;
  5791. + case SNDRV_PCM_TRIGGER_STOP:
  5792. + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  5793. + rtd->bTrigger[SNDRV_PCM_STREAM_PLAYBACK] = 0;
  5794. + } else {
  5795. + rtd->bTrigger[SNDRV_PCM_STREAM_CAPTURE] = 0;
  5796. + }
  5797. + break;
  5798. + case SNDRV_PCM_TRIGGER_RESUME:
  5799. + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  5800. + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK){
  5801. + rtd->tx_pause_en = 0;
  5802. + } else {
  5803. + rtd->rx_pause_en = 0;
  5804. + }
  5805. + break;
  5806. +
  5807. + case SNDRV_PCM_TRIGGER_SUSPEND:
  5808. + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  5809. + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK){
  5810. + rtd->tx_pause_en = 1;
  5811. + } else {
  5812. + rtd->rx_pause_en = 1;
  5813. + }
  5814. + break;
  5815. + default:
  5816. + ret = -EINVAL;
  5817. + break;
  5818. + }
  5819. + return ret;
  5820. +}
  5821. +
  5822. +static int mt76xx_pcm_copy(struct snd_pcm_substream *substream, int channel,\
  5823. + snd_pcm_uframes_t pos,void __user *buf, snd_pcm_uframes_t count)
  5824. +{
  5825. + struct snd_pcm_runtime *runtime= substream->runtime;
  5826. + i2s_config_type* rtd = runtime->private_data;
  5827. + int tx_w_idx = 0;
  5828. + int rx_r_idx = 0;
  5829. + char *hwbuf = NULL;
  5830. +
  5831. + //printk("******* %s *********\n", __func__);
  5832. + hwbuf = runtime->dma_area + frames_to_bytes(runtime, pos);
  5833. + //MSG("%s bur:%x\n",__func__,hwbuf);
  5834. + //printk("hw_ptr:%d, buffer_size:%d, appl_prt:%d, boundary:%d\n",
  5835. + // runtime->status->hw_ptr, runtime->buffer_size, runtime->control->appl_ptr, runtime->boundary);
  5836. +
  5837. + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK){
  5838. + rtd->tx_w_idx = (rtd->tx_w_idx+1)%MAX_I2S_PAGE;
  5839. + tx_w_idx = rtd->tx_w_idx;
  5840. + //printk("put TB[%d - %x] for user write\n",rtd->tx_w_idx,pos);
  5841. + copy_from_user(rtd->pMMAPTxBufPtr[tx_w_idx], (char*)buf, I2S_PAGE_SIZE);
  5842. + }
  5843. + else{
  5844. + rx_r_idx = rtd->rx_r_idx;
  5845. + rtd->rx_r_idx = (rtd->rx_r_idx+1)%MAX_I2S_PAGE;
  5846. + copy_to_user((char*)buf, rtd->pMMAPRxBufPtr[rx_r_idx], I2S_PAGE_SIZE);
  5847. + }
  5848. + return 0;
  5849. +}
  5850. +
  5851. +static int mt76xx_pcm_mmap(struct snd_pcm_substream *substream, struct vm_area_struct *vma)
  5852. +{
  5853. + int ret;
  5854. + unsigned long size;
  5855. +
  5856. + size = vma->vm_end-vma->vm_start;
  5857. + printk("******* %s: size :%lx end:%lx start:%lx *******\n", __func__,size,vma->vm_end,vma->vm_start);
  5858. + ret = i2s_mmap_remap(vma, size);
  5859. +
  5860. + return ret;
  5861. +}
  5862. +
  5863. +
  5864. +static int mt76xx_pcm_prepare(struct snd_pcm_substream *substream)
  5865. +{
  5866. + struct snd_pcm_runtime *runtime= substream->runtime;
  5867. + i2s_config_type *rtd = (i2s_config_type*)runtime->private_data;
  5868. + //runtime->buffer_size = GDMA_PAGE_NUM*GDMA_PAGE_SIZE;
  5869. + //runtime->boundary = (GDMA_PAGE_NUM*GDMA_PAGE_SIZE)/4;
  5870. +
  5871. + //printk("******* %s *******\n", __func__);
  5872. + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK){
  5873. + //printk("===== %s:%s:%d =====\n", __FILE__, __func__, __LINE__);
  5874. + mt76xx_pcm_allocate_dma_buffer(substream,SNDRV_PCM_STREAM_PLAYBACK);
  5875. +
  5876. + if(! rtd->dmaStat[SNDRV_PCM_STREAM_PLAYBACK]){
  5877. + i2s_page_prepare(rtd,STREAM_PLAYBACK);
  5878. + tasklet_init(&i2s_tx_tasklet, i2s_tx_task, (u32)rtd);
  5879. + rtd->dmaStat[SNDRV_PCM_STREAM_PLAYBACK] = 1;
  5880. + gdma_unmask_handler(GDMA_I2S_TX0);
  5881. + }
  5882. + } else {
  5883. + mt76xx_pcm_allocate_dma_buffer(substream,SNDRV_PCM_STREAM_CAPTURE);
  5884. +
  5885. + if(! rtd->dmaStat[SNDRV_PCM_STREAM_CAPTURE]){
  5886. + i2s_page_prepare(rtd,STREAM_CAPTURE); /* TX:enLabel=1; RX:enLabel=2 */
  5887. + tasklet_init(&i2s_rx_tasklet, i2s_rx_task, (u32)rtd);
  5888. + rtd->dmaStat[SNDRV_PCM_STREAM_CAPTURE] = 1;
  5889. + gdma_unmask_handler(GDMA_I2S_RX0);
  5890. + }
  5891. + }
  5892. +
  5893. + return 0;
  5894. +}
  5895. +
  5896. +
  5897. +static int mt76xx_pcm_hw_params(struct snd_pcm_substream *substream,
  5898. + struct snd_pcm_hw_params *hw_params)
  5899. +{
  5900. + /*struct snd_pcm_runtime *runtime = substream->runtime;
  5901. + i2s_config_type *rtd = (i2s_config_type*)runtime->private_data;
  5902. + */
  5903. + int ret,i;
  5904. + ret = i = 0;
  5905. +
  5906. + //printk("******* %s *******\n", __func__);
  5907. + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK){
  5908. + //i2s_page_prepare(rtd,STREAM_PLAYBACK);
  5909. + } else {
  5910. + //i2s_page_prepare(rtd,STREAM_CAPTURE);
  5911. + }
  5912. +
  5913. + return ret;
  5914. +}
  5915. +
  5916. +static int mt76xx_pcm_hw_free(struct snd_pcm_substream *substream)
  5917. +{
  5918. + i2s_config_type* rtd = (i2s_config_type*)substream->runtime->private_data;
  5919. + //struct snd_dma_buffer *buf = &substream->dma_buffer;
  5920. +
  5921. + //printk("******* %s *******\n", __func__);
  5922. + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK){
  5923. + if(rtd->dmaStat[SNDRV_PCM_STREAM_PLAYBACK]){
  5924. +
  5925. + gdma_En_Switch(rtd,STREAM_PLAYBACK,GDMA_I2S_DIS);
  5926. + i2s_tx_end_sleep_on(rtd);
  5927. + tasklet_kill(&i2s_tx_tasklet);
  5928. + i2s_tx_disable(rtd);
  5929. + //mt76xx_pcm_free_dma_buffer(substream,substream->stream);
  5930. + i2s_page_release(rtd,STREAM_PLAYBACK);
  5931. + rtd->dmaStat[SNDRV_PCM_STREAM_PLAYBACK] = 0;
  5932. + }
  5933. + mt76xx_pcm_free_dma_buffer(substream,substream->stream);
  5934. + }
  5935. + else{
  5936. + if(rtd->dmaStat[SNDRV_PCM_STREAM_CAPTURE]){
  5937. +
  5938. + gdma_En_Switch(rtd,STREAM_CAPTURE,GDMA_I2S_DIS);
  5939. + i2s_rx_end_sleep_on(rtd);
  5940. + tasklet_kill(&i2s_rx_tasklet);
  5941. + i2s_rx_disable(rtd);
  5942. + //mt76xx_pcm_free_dma_buffer(substream,substream->stream);
  5943. + i2s_page_release(rtd,STREAM_CAPTURE);
  5944. + rtd->dmaStat[SNDRV_PCM_STREAM_CAPTURE] = 0;
  5945. + }
  5946. + mt76xx_pcm_free_dma_buffer(substream,substream->stream);
  5947. + }
  5948. + return 0;
  5949. +}
  5950. +
  5951. +static int mt76xx_pcm_free_dma_buffer(struct snd_pcm_substream *substream,
  5952. + int stream)
  5953. +{
  5954. +
  5955. + //struct snd_pcm_substream *substream = pcm->streams[stream].substream;
  5956. + struct snd_dma_buffer *buf = &substream->dma_buffer;
  5957. + i2s_config_type* rtd = (i2s_config_type*)substream->runtime->private_data;
  5958. +
  5959. + //printk("******* %s *******\n", __func__);
  5960. + if (!buf->area)
  5961. + return 0;
  5962. + if(substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  5963. + i2s_memPool_free(rtd,STREAM_PLAYBACK);
  5964. + else
  5965. + i2s_memPool_free(rtd,STREAM_CAPTURE);
  5966. + buf->area = NULL;
  5967. + snd_pcm_set_runtime_buffer(substream, NULL);
  5968. + return 0;
  5969. +}
  5970. +
  5971. +static int mt76xx_pcm_allocate_dma_buffer(struct snd_pcm_substream *substream,
  5972. + int stream)
  5973. +{
  5974. + //struct snd_pcm_substream *substream = pcm->streams[stream].substream;
  5975. + struct snd_dma_buffer *buf = &substream->dma_buffer;
  5976. + i2s_config_type* rtd = (i2s_config_type*)substream->runtime->private_data;
  5977. +
  5978. + //printk("******* %s *******\n", __func__);
  5979. + if(!buf->area){
  5980. +#if defined(CONFIG_I2S_MMAP)
  5981. + printk("\n############## MMAP ##############\n");
  5982. + buf->dev.type = SNDRV_DMA_TYPE_DEV;
  5983. +#else
  5984. + buf->dev.type = SNDRV_DMA_TYPE_UNKNOWN;
  5985. +#endif
  5986. + buf->dev.dev = NULL;
  5987. + buf->private_data = NULL;
  5988. + if(stream == SNDRV_PCM_STREAM_PLAYBACK)
  5989. + buf->area = i2s_memPool_Alloc(rtd,STREAM_PLAYBACK);
  5990. + else
  5991. + buf->area = i2s_memPool_Alloc(rtd,STREAM_CAPTURE);
  5992. +
  5993. + if (!buf->area)
  5994. + return -ENOMEM;
  5995. + buf->bytes = GDMA_TOTAL_PAGE_SIZE;
  5996. +#if defined(CONFIG_I2S_MMAP)
  5997. + buf->addr = i2s_mmap_phys_addr(rtd);
  5998. +#endif
  5999. + snd_pcm_set_runtime_buffer(substream, buf);
  6000. + } else{
  6001. + //printk("Buffer have been allocated!\n");
  6002. + }
  6003. +
  6004. + return 0;
  6005. +}
  6006. +
  6007. +static int mt76xx_pcm_open(struct snd_pcm_substream *substream)
  6008. +{
  6009. + struct snd_pcm_runtime *runtime= substream->runtime;
  6010. + struct snd_dma_buffer *buf = &substream->dma_buffer;
  6011. + int stream = substream->stream;
  6012. + int ret = 0;
  6013. +
  6014. + //printk("******* %s *******\n", __func__);
  6015. + snd_soc_set_runtime_hwparams(substream, &mt76xx_pcm_hwparam);
  6016. + /* ensure that buffer size is a multiple of period size */
  6017. + ret = snd_pcm_hw_constraint_integer(runtime,
  6018. + SNDRV_PCM_HW_PARAM_PERIODS);
  6019. + if (ret < 0)
  6020. + goto out;
  6021. +
  6022. +#if 1
  6023. + if(stream == SNDRV_PCM_STREAM_PLAYBACK){
  6024. + ret = mt76xx_pcm_allocate_dma_buffer(substream,
  6025. + SNDRV_PCM_STREAM_PLAYBACK);
  6026. + }
  6027. + else{
  6028. + ret = mt76xx_pcm_allocate_dma_buffer(substream,
  6029. + SNDRV_PCM_STREAM_CAPTURE);
  6030. + }
  6031. +#endif
  6032. +
  6033. + if (ret)
  6034. + goto out;
  6035. +
  6036. + if(buf)
  6037. + memset(buf->area,0,sizeof(I2S_PAGE_SIZE*MAX_I2S_PAGE));
  6038. +
  6039. + out:
  6040. + return ret;
  6041. +}
  6042. +
  6043. +
  6044. +
  6045. +static int mt76xx_pcm_new(struct snd_soc_pcm_runtime *rtd)
  6046. +{
  6047. +// int ret = 0;
  6048. +
  6049. + //printk("******* %s *******\n", __func__);
  6050. + return 0;
  6051. +}
  6052. +
  6053. +static void mt76xx_pcm_free(struct snd_pcm *pcm)
  6054. +{
  6055. + /*struct snd_pcm_substream *substream;
  6056. + struct snd_dma_buffer *buf;
  6057. + i2s_config_type* rtd;
  6058. + int stream;
  6059. +*/
  6060. + //printk("******* %s *******\n", __func__);
  6061. + //return 0;
  6062. +}
  6063. +
  6064. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,20)
  6065. +static int mt76xx_platform_drv_probe(struct platform_device *pdev)
  6066. +{
  6067. + //printk("******* %s *******\n", __func__);
  6068. + return snd_soc_register_platform(&pdev->dev, &mt76xx_soc_platform);
  6069. +}
  6070. +
  6071. +static int mt76xx_platform_drv_remove(struct platform_device *pdev)
  6072. +{
  6073. + //printk("******* %s *******\n", __func__);
  6074. + snd_soc_unregister_platform(&pdev->dev);
  6075. + return 0;
  6076. +}
  6077. +
  6078. +static struct platform_driver mt76xx_pcm_driver = {
  6079. + .driver = {
  6080. + .name = "mt76xx-pcm",
  6081. + .owner = THIS_MODULE,
  6082. + },
  6083. +
  6084. + .probe = mt76xx_platform_drv_probe,
  6085. + .remove = mt76xx_platform_drv_remove,
  6086. +};
  6087. +
  6088. +static int __init mt76xx_pcm_init(void)
  6089. +{
  6090. +
  6091. + printk("******* %s *******\n", __func__);
  6092. + return platform_driver_register(&mt76xx_pcm_driver);
  6093. +}
  6094. +
  6095. +static void __exit mt76xx_pcm_exit(void)
  6096. +{
  6097. + platform_driver_unregister(&mt76xx_pcm_driver);
  6098. +}
  6099. +#else
  6100. +static int __init mt76xx_pcm_init(void)
  6101. +{
  6102. +
  6103. + printk("******* %s *******\n", __func__);
  6104. + return snd_soc_register_platform(&mt76xx_soc_platform);
  6105. +}
  6106. +
  6107. +static void __exit mt76xx_pcm_exit(void)
  6108. +{
  6109. + printk("******* %s *******\n", __func__);
  6110. + snd_soc_unregister_platform(&mt76xx_soc_platform);
  6111. +}
  6112. +#endif
  6113. +module_init(mt76xx_pcm_init);
  6114. +module_exit(mt76xx_pcm_exit);
  6115. +
  6116. +MODULE_AUTHOR("Dora Chen");
  6117. +MODULE_DESCRIPTION("MTK APSoC I2S DMA driver");
  6118. +MODULE_LICENSE("GPL");
  6119. +
  6120. --- /dev/null
  6121. +++ b/sound/soc/mtk/ralink_gdma.c
  6122. @@ -0,0 +1,918 @@
  6123. +/*
  6124. + ***************************************************************************
  6125. + * Ralink Tech Inc.
  6126. + * 5F., No.36, Taiyuan St., Jhubei City,
  6127. + * Hsinchu County 302,
  6128. + * Taiwan, R.O.C.
  6129. + *
  6130. + * (c) Copyright, Ralink Technology, Inc.
  6131. + *
  6132. + * This program is free software; you can redistribute it and/or modify it
  6133. + * under the terms of the GNU General Public License as published by the
  6134. + * Free Software Foundation; either version 2 of the License, or (at your
  6135. + * option) any later version.
  6136. + *
  6137. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  6138. + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  6139. + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  6140. + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  6141. + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  6142. + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  6143. + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  6144. + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  6145. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  6146. + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  6147. + *
  6148. + * You should have received a copy of the GNU General Public License along
  6149. + * with this program; if not, write to the Free Software Foundation, Inc.,
  6150. + * 675 Mass Ave, Cambridge, MA 02139, USA.
  6151. + *
  6152. + *
  6153. + ***************************************************************************
  6154. + *
  6155. + Module Name:
  6156. + ralink_gdma.c
  6157. +
  6158. + Abstract:
  6159. +
  6160. + Revision History:
  6161. + Who When What
  6162. + -------- ---------- ----------------------------------------------
  6163. + Name Date Modification logs
  6164. + Steven Liu 2009-03-24 Support RT3883
  6165. + *
  6166. + */
  6167. +#include <linux/init.h>
  6168. +#include <linux/version.h>
  6169. +#include <linux/module.h>
  6170. +#include <linux/kernel.h>
  6171. +#include <linux/interrupt.h>
  6172. +#include <linux/fs.h>
  6173. +#if defined (CONFIG_MIPS)
  6174. + #include <asm/uaccess.h>
  6175. + #include <asm/addrspace.h>
  6176. +#endif
  6177. +
  6178. +#include "ralink_gdma.h"
  6179. +
  6180. +/*
  6181. + * RT305x:
  6182. + * Ch0 : Pcm0_Rx0 | Pcm0_Rx0 | ALL
  6183. + * Ch1 : Pcm0_Rx1 | Pcm0_Rx1 | ALL
  6184. + * Ch2 : Pcm0_Tx0 | Pcm0_Tx0 | ALL
  6185. + * Ch3 : Pcm0_Tx1 | Pcm0_Tx1 | ALL
  6186. + * Ch4 : Pcm1_Rx0 | I2S_Tx0 | ALL
  6187. + * Ch5 : Pcm1_Rx1 | I2S_Tx1 | ALL
  6188. + * Ch6 : Pcm1_Tx0 | ALL | ALL
  6189. + * Ch7 : Pcm1_Tx1 | ALL | ALL
  6190. + *
  6191. + * RT3883:
  6192. + * Ch0 : Pcm0_Rx0 | Pcm0_Rx0 | ALL
  6193. + * Ch1 : Pcm0_Rx1 | Pcm0_Rx1 | ALL
  6194. + * Ch2 : Pcm0_Tx0 | Pcm0_Tx0 | ALL
  6195. + * Ch3 : Pcm0_Tx1 | Pcm0_Tx1 | ALL
  6196. + * Ch4 : Pcm1_Rx0 | I2S_Tx0 | ALL
  6197. + * Ch5 : Pcm1_Rx1 | I2S_Tx1 | ALL
  6198. + * Ch6 : Pcm1_Tx0 | I2S_Rx0 | ALL
  6199. + * Ch7 : Pcm1_Tx1 | I2S_Rx1 | ALL
  6200. + * Ch8 : ALL | ALL | ALL
  6201. + * Ch9 : ALL | ALL | ALL
  6202. + * Ch10 : ALL | ALL | ALL
  6203. + * Ch11 : ALL | ALL | ALL
  6204. + * Ch12 : ALL | ALL | ALL PCI TX
  6205. + * Ch13 : ALL | ALL | ALL PCI RX
  6206. + * Ch14 : ALL | ALL | ALL
  6207. + * Ch15 : ALL | ALL | ALL
  6208. + *
  6209. + */
  6210. +
  6211. +spinlock_t gdma_lock;
  6212. +spinlock_t gdma_lock_mem;
  6213. +spinlock_t gdma_int_lock;
  6214. +void (*GdmaDoneIntCallback[MAX_GDMA_CHANNEL])(uint32_t);
  6215. +void (*GdmaUnMaskIntCallback[MAX_GDMA_CHANNEL])(uint32_t);
  6216. +
  6217. +
  6218. +/**
  6219. + * @brief Get free GDMA channel
  6220. + *
  6221. + * @param ChNum GDMA channel number
  6222. + * @retval 1 channel is available
  6223. + * @retval 0 channels are all busy
  6224. + */
  6225. +int _GdmaGetFreeCh(uint32_t *ChNum)
  6226. +{
  6227. + unsigned long flags;
  6228. + uint32_t Data=0;
  6229. + uint32_t Ch=0;
  6230. +#if defined (CONFIG_GDMA_DEBUG)
  6231. + static uint32_t Ch_RR=0;
  6232. +#endif
  6233. +
  6234. + spin_lock_irqsave(&gdma_lock, flags);
  6235. +
  6236. +#if defined (CONFIG_GDMA_PCM_ONLY)
  6237. +#if defined (CONFIG_RALINK_RT3883) || defined (CONFIG_RALINK_RT3352) || defined (CONFIG_RALINK_RT5350) || defined (CONFIG_RALINK_RT6855) || defined (CONFIG_RALINK_RT6855A) || defined (CONFIG_RALINK_MT7620) || defined (CONFIG_RALINK_MT7621) || defined (CONFIG_RALINK_MT7628) || defined (CONFIG_ARCH_MT7623)
  6238. + for(Ch=14; Ch<MAX_GDMA_CHANNEL;Ch++) //channel 14~max_channe, channel 0~13 be usedl
  6239. +#else
  6240. + for(Ch=MAX_GDMA_CHANNEL; Ch<MAX_GDMA_CHANNEL;Ch++) //no free channel
  6241. +#endif
  6242. +#elif defined (CONFIG_GDMA_PCM_I2S_OTHERS)
  6243. +#if defined (CONFIG_RALINK_RT3883) || defined (CONFIG_RALINK_RT3352) || defined (CONFIG_RALINK_RT5350) || defined (CONFIG_RALINK_RT6855) || defined (CONFIG_RALINK_RT6855A) || defined (CONFIG_RALINK_MT7620) || defined (CONFIG_RALINK_MT7621) || defined (CONFIG_RALINK_MT7628) || defined (CONFIG_ARCH_MT7623)
  6244. + for(Ch=14; Ch<MAX_GDMA_CHANNEL;Ch++) //channel 14~max_channe, channel 0~13 be usedl
  6245. +#else
  6246. + for(Ch=6; Ch<MAX_GDMA_CHANNEL;Ch++) //channel 6~max_channel
  6247. +#endif
  6248. +#elif defined (CONFIG_GDMA_EVERYBODY)
  6249. + for(Ch=0; Ch<MAX_GDMA_CHANNEL;Ch++) //all channel
  6250. +#elif defined (CONFIG_GDMA_DEBUG)
  6251. + for(Ch=(Ch_RR++)%MAX_GDMA_CHANNEL; Ch<MAX_GDMA_CHANNEL;Ch++) //round robin
  6252. +#endif
  6253. + {
  6254. + Data=GDMA_READ_REG(GDMA_CTRL_REG(Ch));
  6255. +
  6256. + /* hardware will reset this bit if transaction is done.
  6257. + * It means channel is free */
  6258. + if((Data & (0x01<<CH_EBL_OFFSET))==0) {
  6259. + *ChNum = Ch;
  6260. + spin_unlock_irqrestore(&gdma_lock, flags);
  6261. + return 1; //Channel is free
  6262. + }
  6263. + }
  6264. +
  6265. + spin_unlock_irqrestore(&gdma_lock, flags);
  6266. + return 0; // Channels are all busy
  6267. +
  6268. +}
  6269. +
  6270. +/**
  6271. + * @brief Set channel is masked
  6272. + *
  6273. + * When channel is masked, the GDMA transaction will stop.
  6274. + * When GDMA controller comes back from another channel (chain feature)
  6275. + *
  6276. + * >> Channel Mask=0: It's strange, and turns on related bit in GDMA interrupt
  6277. + * status register (16:23 Unmasked)
  6278. + *
  6279. + * >> Channel Mask=1: It'll start GDMA transation, and clear this bit.
  6280. + *
  6281. + * @param ChNum GDMA channel number
  6282. + * @retval 1 success
  6283. + * @retval 0 fail
  6284. + */
  6285. +int GdmaMaskChannel(uint32_t ChNum)
  6286. +{
  6287. + uint32_t Data=0;
  6288. +
  6289. + Data=GDMA_READ_REG(GDMA_CTRL_REG1(ChNum));
  6290. + Data |= ( 0x01 << CH_MASK_OFFSET);
  6291. + GDMA_WRITE_REG(GDMA_CTRL_REG1(ChNum), Data);
  6292. + GDMA_PRINT("%s: Write %0X to %X\n", __FUNCTION__, Data, GDMA_CTRL_REG1(ChNum));
  6293. +
  6294. + return 1;
  6295. +}
  6296. +
  6297. +/**
  6298. + * @brief Set channel is unmasked
  6299. + *
  6300. + * You can unmask the channel to start GDMA transaction.
  6301. + *
  6302. + * When GDMA controller comes back from another channel (chain feature)
  6303. + *
  6304. + * >> Channel Mask=0: It's strange, and turns on related bit in GDMA interrupt
  6305. + * status register (16:23 Unmasked)
  6306. + *
  6307. + * >> Channel Mask=1: It'll start GDMA transation, and clear this bit.
  6308. + *
  6309. + * @param ChNum GDMA channel number
  6310. + * @retval 1 success
  6311. + * @retval 0 fail
  6312. + */
  6313. +int GdmaUnMaskChannel(uint32_t ChNum)
  6314. +{
  6315. + uint32_t Data=0;
  6316. +
  6317. + Data=GDMA_READ_REG(GDMA_CTRL_REG1(ChNum));
  6318. + Data &= ~( 0x01 << CH_MASK_OFFSET);
  6319. + GDMA_WRITE_REG(GDMA_CTRL_REG1(ChNum), Data);
  6320. + GDMA_PRINT("%s: Write %0X to %X\n", __FUNCTION__, Data, GDMA_CTRL_REG1(ChNum));
  6321. +
  6322. + return 1;
  6323. +}
  6324. +
  6325. +/**
  6326. + * @brief Insert new GDMA entry to start GDMA transaction
  6327. + *
  6328. + * @param ChNum GDMA channel number
  6329. + * @retval 1 success
  6330. + * @retval 0 fail
  6331. + */
  6332. +int GdmaReqQuickIns(uint32_t ChNum)
  6333. +{
  6334. + uint32_t Data=0;
  6335. +
  6336. + //Mask Channel
  6337. + Data = GDMA_READ_REG(GDMA_CTRL_REG1(ChNum));
  6338. + Data |= ( 0x1 << CH_MASK_OFFSET);
  6339. + GDMA_WRITE_REG(GDMA_CTRL_REG1(ChNum), Data);
  6340. +
  6341. + //Channel Enable
  6342. + Data = GDMA_READ_REG(GDMA_CTRL_REG(ChNum));
  6343. + Data |= (0x01<<CH_EBL_OFFSET);
  6344. + GDMA_WRITE_REG(GDMA_CTRL_REG(ChNum), Data);
  6345. +
  6346. + return 1;
  6347. +
  6348. +}
  6349. +
  6350. +int _GdmaReqEntryIns(GdmaReqEntry *NewEntry)
  6351. +{
  6352. + uint32_t Data=0;
  6353. +
  6354. + GDMA_PRINT("== << GDMA Control Reg (Channel=%d) >> ===\n", NewEntry->ChNum);
  6355. + GDMA_PRINT(" Channel Source Addr = %x \n", NewEntry->Src);
  6356. + GDMA_PRINT(" Channel Dest Addr = %x \n", NewEntry->Dst);
  6357. + GDMA_PRINT(" Transfer Count=%d\n", NewEntry->TransCount);
  6358. + GDMA_PRINT(" Source DMA Req= DMA_REQ%d\n", NewEntry->SrcReqNum);
  6359. + GDMA_PRINT(" Dest DMA Req= DMA_REQ%d\n", NewEntry->DstReqNum);
  6360. + GDMA_PRINT(" Source Burst Mode=%s\n", NewEntry->SrcBurstMode ? "Fix" : "Inc");
  6361. + GDMA_PRINT(" Dest Burst Mode=%s\n", NewEntry->DstBurstMode ? "Fix" : "Inc");
  6362. + GDMA_PRINT(" Burst Size=%s\n", NewEntry->BurstSize ==0 ? "1 transfer" : \
  6363. + NewEntry->BurstSize ==1 ? "2 transfer" :\
  6364. + NewEntry->BurstSize ==2 ? "4 transfer" :\
  6365. + NewEntry->BurstSize ==3 ? "8 transfer" :\
  6366. + NewEntry->BurstSize ==4 ? "16 transfer" :\
  6367. + "Error");
  6368. + GDMA_PRINT(" Hardware/Software Mode = %s\n", NewEntry->SoftMode ?
  6369. + "Soft" : "Hw");
  6370. + GDMA_PRINT("== << GDMA Control Reg1 (Channel=%d) >> =\n", NewEntry->ChNum);
  6371. + GDMA_PRINT("Channel Done Interrput=%s\n", (NewEntry->DoneIntCallback!=NULL) ?
  6372. + "Enable" : "Disable");
  6373. + GDMA_PRINT("Channel Unmasked Int=%s\n", (NewEntry->UnMaskIntCallback!=NULL) ?
  6374. + "Enable" : "Disable");
  6375. +#if !defined (CONFIG_RALINK_RT3052) && !defined (CONFIG_RALINK_RT3883)
  6376. + GDMA_PRINT("Coherent Interrupt =%s\n", (NewEntry->CoherentIntEbl==1)?
  6377. + "Enable" : "Disable");
  6378. +#endif
  6379. + GDMA_PRINT("Next Unmasked Channel=%d\n", NewEntry->NextUnMaskCh);
  6380. + GDMA_PRINT("Channel Mask=%d\n", NewEntry->ChMask);
  6381. + GDMA_PRINT("========================================\n");
  6382. +
  6383. + GDMA_WRITE_REG(GDMA_SRC_REG(NewEntry->ChNum), NewEntry->Src);
  6384. + GDMA_PRINT("SrcAddr: Write %0X to %X\n", \
  6385. + NewEntry->Src, GDMA_SRC_REG(NewEntry->ChNum));
  6386. +
  6387. + GDMA_WRITE_REG(GDMA_DST_REG(NewEntry->ChNum), NewEntry->Dst);
  6388. + GDMA_PRINT("DstAddr: Write %0X to %X\n", \
  6389. + NewEntry->Dst, GDMA_DST_REG(NewEntry->ChNum));
  6390. +
  6391. + Data |= ( (NewEntry->NextUnMaskCh) << NEXT_UNMASK_CH_OFFSET);
  6392. + Data |= ( NewEntry->ChMask << CH_MASK_OFFSET);
  6393. +#if !defined (CONFIG_RALINK_RT3052) && !defined (CONFIG_RALINK_RT3883)
  6394. + Data |= ( NewEntry->CoherentIntEbl << COHERENT_INT_EBL_OFFSET);
  6395. +#endif
  6396. +
  6397. + if(NewEntry->UnMaskIntCallback!=NULL) {
  6398. + Data |= (0x01<<CH_UNMASKINT_EBL_OFFSET);
  6399. + GdmaUnMaskIntCallback[NewEntry->ChNum] = NewEntry->UnMaskIntCallback;
  6400. + }
  6401. +
  6402. +#if defined (CONFIG_RALINK_RT3883) || defined (CONFIG_RALINK_RT3352) || defined (CONFIG_RALINK_RT5350) || defined (CONFIG_RALINK_RT6855) || defined (CONFIG_RALINK_RT6855A) || defined (CONFIG_RALINK_MT7620) || defined (CONFIG_RALINK_MT7621) || defined (CONFIG_RALINK_MT7628) || defined (CONFIG_ARCH_MT7623)
  6403. + Data |= (NewEntry->SrcReqNum << SRC_DMA_REQ_OFFSET);
  6404. + Data |= (NewEntry->DstReqNum << DST_DMA_REQ_OFFSET);
  6405. +#endif
  6406. +
  6407. + GDMA_WRITE_REG(GDMA_CTRL_REG1(NewEntry->ChNum), Data);
  6408. + GDMA_PRINT("CTRL1: Write %08X to %8X\n", Data, GDMA_CTRL_REG1(NewEntry->ChNum));
  6409. +
  6410. + Data = ((NewEntry->TransCount) << TRANS_CNT_OFFSET);
  6411. +#if defined (CONFIG_RALINK_RT3052)
  6412. + Data |= (NewEntry->SrcReqNum << SRC_DMA_REQ_OFFSET);
  6413. + Data |= (NewEntry->DstReqNum << DST_DMA_REQ_OFFSET);
  6414. +#endif
  6415. + Data |= (NewEntry->SrcBurstMode << SRC_BRST_MODE_OFFSET);
  6416. + Data |= (NewEntry->DstBurstMode << DST_BRST_MODE_OFFSET);
  6417. + Data |= (NewEntry->BurstSize << BRST_SIZE_OFFSET);
  6418. +
  6419. + if(NewEntry->DoneIntCallback!=NULL) {
  6420. + Data |= (0x01<<CH_DONEINT_EBL_OFFSET);
  6421. + GdmaDoneIntCallback[NewEntry->ChNum] = NewEntry->DoneIntCallback;
  6422. + }
  6423. +
  6424. + if(NewEntry->SoftMode) {
  6425. + Data |= (0x01<<MODE_SEL_OFFSET);
  6426. + }
  6427. +
  6428. + Data |= (0x01<<CH_EBL_OFFSET);
  6429. + GDMA_WRITE_REG(GDMA_CTRL_REG(NewEntry->ChNum), Data);
  6430. + //GDMA_READ_REG(GDMA_CTRL_REG(NewEntry->ChNum));
  6431. + GDMA_PRINT("CTRL: Write %08X to %8X\n", Data, GDMA_CTRL_REG(NewEntry->ChNum));
  6432. + //if there is no interrupt handler, this function will
  6433. + //return 1 until GDMA done.
  6434. + if(NewEntry->DoneIntCallback==NULL) {
  6435. + //wait for GDMA processing done
  6436. +#if defined (CONFIG_RALINK_RT3052)
  6437. + while((GDMA_READ_REG(RALINK_GDMAISTS) &
  6438. + (0x1<<NewEntry->ChNum))==0);
  6439. + //write 1 clear
  6440. + GDMA_WRITE_REG(RALINK_GDMAISTS, 1<< NewEntry->ChNum);
  6441. +#elif defined (CONFIG_RALINK_RT3883) || defined (CONFIG_RALINK_RT3352) || defined (CONFIG_RALINK_RT5350) || defined (CONFIG_RALINK_RT6855) || defined (CONFIG_RALINK_RT6855A) || defined (CONFIG_RALINK_MT7620) || defined (CONFIG_RALINK_MT7621) || defined (CONFIG_RALINK_MT7628) || defined (CONFIG_ARCH_MT7623)
  6442. + while((GDMA_READ_REG(RALINK_GDMA_DONEINT) &
  6443. + (0x1<<NewEntry->ChNum))==0);
  6444. + //write 1 clear
  6445. + GDMA_WRITE_REG(RALINK_GDMA_DONEINT, 1<< NewEntry->ChNum);
  6446. +#endif
  6447. + }
  6448. +
  6449. + return 1;
  6450. +
  6451. +}
  6452. +
  6453. +#if defined(CONFIG_RALINK_MT7620) || defined (CONFIG_RALINK_MT7621) || defined (CONFIG_RALINK_MT7628) || defined (CONFIG_ARCH_MT7623)
  6454. +/**
  6455. + * @brief Start GDMA transaction for sending data to SPI
  6456. + *
  6457. + * @param *Src source address
  6458. + * @param *Dst destination address
  6459. +
  6460. + * @param TransCount data length
  6461. + * @param *DoneIntCallback callback function when transcation is done
  6462. + * @param *UnMaskIntCallback callback func when ch mask field is incorrect
  6463. + * @retval 1 success
  6464. + * @retval 0 fail
  6465. + */
  6466. +int GdmaSpiTx(
  6467. + uint32_t Src,
  6468. + uint32_t Dst,
  6469. + uint16_t TransCount,
  6470. + void (*DoneIntCallback)(uint32_t data),
  6471. + void (*UnMaskIntCallback)(uint32_t data)
  6472. + )
  6473. +{
  6474. + GdmaReqEntry Entry;
  6475. +
  6476. + #if defined (CONFIG_MIPS)
  6477. + Entry.Src= (Src & 0x1FFFFFFF);
  6478. + Entry.Dst= (Dst & 0x1FFFFFFF);
  6479. + #else
  6480. + Entry.Src= Src;
  6481. + Entry.Dst= Dst;
  6482. + #endif
  6483. + Entry.TransCount = TransCount;
  6484. + Entry.SrcBurstMode=INC_MODE;
  6485. + Entry.DstBurstMode=FIX_MODE;
  6486. + Entry.BurstSize=BUSTER_SIZE_4B;
  6487. + Entry.SrcReqNum=DMA_MEM_REQ;
  6488. + Entry.DstReqNum=DMA_SPI_TX_REQ;
  6489. + Entry.DoneIntCallback=DoneIntCallback;
  6490. + Entry.UnMaskIntCallback=UnMaskIntCallback;
  6491. + Entry.SoftMode=0;
  6492. + Entry.ChMask=0;
  6493. + Entry.CoherentIntEbl=0;
  6494. +
  6495. + //enable chain feature
  6496. + Entry.ChNum = GDMA_SPI_TX;
  6497. + Entry.NextUnMaskCh = GDMA_SPI_TX;
  6498. +
  6499. + return _GdmaReqEntryIns(&Entry);
  6500. +}
  6501. +
  6502. +int GdmaSpiRx(
  6503. + uint32_t Src,
  6504. + uint32_t Dst,
  6505. + uint16_t TransCount,
  6506. + void (*DoneIntCallback)(uint32_t data),
  6507. + void (*UnMaskIntCallback)(uint32_t data)
  6508. + )
  6509. +{
  6510. + GdmaReqEntry Entry;
  6511. +
  6512. + #if defined (CONFIG_MIPS)
  6513. + Entry.Src= (Src & 0x1FFFFFFF);
  6514. + Entry.Dst= (Dst & 0x1FFFFFFF);
  6515. + #else
  6516. + Entry.Src= Src;
  6517. + Entry.Dst= Dst;
  6518. + #endif
  6519. + Entry.TransCount = TransCount;
  6520. + Entry.SrcBurstMode=FIX_MODE;
  6521. + Entry.DstBurstMode=INC_MODE;
  6522. + Entry.BurstSize=BUSTER_SIZE_4B;
  6523. + Entry.SrcReqNum=DMA_SPI_RX_REQ;
  6524. + Entry.DstReqNum=DMA_MEM_REQ;
  6525. + Entry.DoneIntCallback=DoneIntCallback;
  6526. + Entry.UnMaskIntCallback=UnMaskIntCallback;
  6527. + Entry.SoftMode=0;
  6528. + Entry.ChMask=0;
  6529. + Entry.CoherentIntEbl=1;
  6530. +
  6531. +
  6532. + //enable chain feature
  6533. + Entry.ChNum=GDMA_SPI_RX;
  6534. + Entry.NextUnMaskCh=GDMA_SPI_RX;
  6535. +
  6536. +
  6537. + return _GdmaReqEntryIns(&Entry);
  6538. +
  6539. +}
  6540. +#endif
  6541. +
  6542. +
  6543. +/**
  6544. + * @brief Start GDMA transaction for sending data to I2S
  6545. + *
  6546. + * @param *Src source address
  6547. + * @param *Dst destination address
  6548. + * @param TxNo I2S Tx number
  6549. + * @param TransCount data length
  6550. + * @param *DoneIntCallback callback function when transcation is done
  6551. + * @param *UnMaskIntCallback callback func when ch mask field is incorrect
  6552. + * @retval 1 success
  6553. + * @retval 0 fail
  6554. + */
  6555. +int GdmaI2sTx(
  6556. + uint32_t Src,
  6557. + uint32_t Dst,
  6558. + uint8_t TxNo,
  6559. + uint16_t TransCount,
  6560. + void (*DoneIntCallback)(uint32_t data),
  6561. + void (*UnMaskIntCallback)(uint32_t data)
  6562. + )
  6563. +{
  6564. + GdmaReqEntry Entry;
  6565. +
  6566. + #if defined (CONFIG_MIPS)
  6567. + Entry.Src= (Src & 0x1FFFFFFF);
  6568. + Entry.Dst= (Dst & 0x1FFFFFFF);
  6569. + #else
  6570. + Entry.Src= Src;
  6571. + Entry.Dst= Dst;
  6572. + #endif
  6573. + Entry.TransCount = TransCount;
  6574. + Entry.SrcBurstMode=INC_MODE;
  6575. + Entry.DstBurstMode=FIX_MODE;
  6576. + Entry.BurstSize=BUSTER_SIZE_4B;
  6577. + Entry.SrcReqNum=DMA_MEM_REQ;
  6578. + Entry.DstReqNum=DMA_I2S_TX_REQ;
  6579. + Entry.DoneIntCallback=DoneIntCallback;
  6580. + Entry.UnMaskIntCallback=UnMaskIntCallback;
  6581. + Entry.SoftMode=0;
  6582. + Entry.ChMask=1;
  6583. + Entry.CoherentIntEbl=0;
  6584. +
  6585. + if(TxNo==0) { //TX0
  6586. + //enable chain feature
  6587. + Entry.ChNum=GDMA_I2S_TX0;
  6588. + Entry.NextUnMaskCh= (TransCount==4) ? GDMA_I2S_TX0 : GDMA_I2S_TX1;
  6589. + }else if(TxNo==1) { //TX1
  6590. + //enable chain feature
  6591. + Entry.ChNum=GDMA_I2S_TX1;
  6592. + Entry.NextUnMaskCh= (TransCount==4) ? GDMA_I2S_TX1 : GDMA_I2S_TX0;
  6593. + }else {
  6594. + GDMA_PRINT("I2S Tx Number %x is invalid\n", TxNo);
  6595. + return 0;
  6596. + }
  6597. +
  6598. + return _GdmaReqEntryIns(&Entry);
  6599. +
  6600. +}
  6601. +
  6602. +
  6603. +#if defined (CONFIG_RALINK_RT3883) || defined (CONFIG_RALINK_RT3352) || defined (CONFIG_RALINK_RT5350) || defined (CONFIG_RALINK_RT6855) || defined (CONFIG_RALINK_RT6855A) || defined (CONFIG_RALINK_MT7620) || defined (CONFIG_RALINK_MT7621) || defined (CONFIG_RALINK_MT7628) || defined (CONFIG_ARCH_MT7623)
  6604. +/**
  6605. + * @brief Start GDMA transaction for receiving data to I2S
  6606. + *
  6607. + * @param *Src source address
  6608. + * @param *Dst destination address
  6609. + * @param TxNo I2S Tx number
  6610. + * @param TransCount data length
  6611. + * @param *DoneIntCallback callback function when transcation is done
  6612. + * @param *UnMaskIntCallback callback func when ch mask field is incorrect
  6613. + * @retval 1 success
  6614. + * @retval 0 fail
  6615. + */
  6616. +int GdmaI2sRx(
  6617. + uint32_t Src,
  6618. + uint32_t Dst,
  6619. + uint8_t RxNo,
  6620. + uint16_t TransCount,
  6621. + void (*DoneIntCallback)(uint32_t data),
  6622. + void (*UnMaskIntCallback)(uint32_t data)
  6623. + )
  6624. +{
  6625. + GdmaReqEntry Entry;
  6626. + #if defined (CONFIG_MIPS)
  6627. + Entry.Src= (Src & 0x1FFFFFFF);
  6628. + Entry.Dst= (Dst & 0x1FFFFFFF);
  6629. + #else
  6630. + Entry.Src= Src;
  6631. + Entry.Dst= Dst;
  6632. + #endif
  6633. + Entry.TransCount = TransCount;
  6634. + Entry.SrcBurstMode=FIX_MODE;
  6635. + Entry.DstBurstMode=INC_MODE;
  6636. + Entry.BurstSize=BUSTER_SIZE_4B;
  6637. + Entry.SrcReqNum=DMA_I2S_RX_REQ;
  6638. + Entry.DstReqNum=DMA_MEM_REQ;
  6639. + Entry.DoneIntCallback=DoneIntCallback;
  6640. + Entry.UnMaskIntCallback=UnMaskIntCallback;
  6641. + Entry.SoftMode=0;
  6642. + Entry.ChMask=1;
  6643. + Entry.CoherentIntEbl=1;
  6644. +
  6645. + if(RxNo==0) { //RX0
  6646. + //enable chain feature
  6647. + Entry.ChNum=GDMA_I2S_RX0;
  6648. + Entry.NextUnMaskCh=(TransCount==4) ? GDMA_I2S_RX0 : GDMA_I2S_RX1;
  6649. + }else if(RxNo==1) { //RX1
  6650. + //enable chain feature
  6651. + Entry.ChNum=GDMA_I2S_RX1;
  6652. + Entry.NextUnMaskCh=(TransCount==4) ? GDMA_I2S_RX1 : GDMA_I2S_RX0;
  6653. + }else {
  6654. + GDMA_PRINT("I2S Rx Number %x is invalid\n", RxNo);
  6655. + return 0;
  6656. + }
  6657. +
  6658. + return _GdmaReqEntryIns(&Entry);
  6659. +
  6660. +}
  6661. +
  6662. +#endif
  6663. +
  6664. +/**
  6665. + * @brief Start GDMA transaction for receiving data from PCM
  6666. + *
  6667. + * @param *Src source address
  6668. + * @param *Dst destination address
  6669. + * @param TransCount data length
  6670. + * @param PcmNo PCM channel
  6671. + * @param RxNo PCM Rx number
  6672. + * @param *DoneIntCallback callback function when transcation is done
  6673. + * @param *UnMaskIntCallback callback func when ch mask field is incorrect
  6674. + * @retval 1 success
  6675. + * @retval 0 fail
  6676. + */
  6677. +int GdmaPcmRx(
  6678. + uint32_t Src,
  6679. + uint32_t Dst,
  6680. + uint8_t PcmNo,
  6681. + uint8_t RxNo,
  6682. + uint16_t TransCount,
  6683. + void (*DoneIntCallback)(uint32_t data),
  6684. + void (*UnMaskIntCallback)(uint32_t data)
  6685. + )
  6686. +{
  6687. + GdmaReqEntry Entry;
  6688. +
  6689. + #if defined (CONFIG_MIPS)
  6690. + Entry.Src= (Src & 0x1FFFFFFF);
  6691. + Entry.Dst= (Dst & 0x1FFFFFFF);
  6692. + #else
  6693. + Entry.Src= Src;
  6694. + Entry.Dst= Dst;
  6695. + #endif
  6696. + Entry.TransCount = TransCount;
  6697. + Entry.SrcBurstMode=FIX_MODE;
  6698. + Entry.DstBurstMode=INC_MODE;
  6699. + Entry.BurstSize=BUSTER_SIZE_4B;
  6700. + Entry.DstReqNum=DMA_MEM_REQ;
  6701. + Entry.DoneIntCallback=DoneIntCallback;
  6702. + Entry.UnMaskIntCallback=UnMaskIntCallback;
  6703. + Entry.SoftMode=0;
  6704. + Entry.ChMask=1;
  6705. + Entry.CoherentIntEbl=1;
  6706. +
  6707. + if(RxNo > 2) {
  6708. + GDMA_PRINT("PCM Rx Number %x is invalid\n", RxNo);
  6709. + return 0;
  6710. + }
  6711. +
  6712. + switch(PcmNo)
  6713. + {
  6714. + case 0:
  6715. + Entry.SrcReqNum=DMA_PCM_RX0_REQ;
  6716. + break;
  6717. + case 1:
  6718. + Entry.SrcReqNum=DMA_PCM_RX1_REQ;
  6719. + break;
  6720. +#if defined(CONFIG_RALINK_MT7620) || defined (CONFIG_RALINK_MT7621) || defined (CONFIG_RALINK_MT7628) || defined (CONFIG_ARCH_MT7623)
  6721. + case 2:
  6722. + Entry.SrcReqNum=DMA_PCM_RX2_REQ;
  6723. + break;
  6724. + case 3:
  6725. + Entry.SrcReqNum=DMA_PCM_RX3_REQ;
  6726. + break;
  6727. +#endif
  6728. + default:
  6729. + GDMA_PRINT("PCM Channel %x is invalid\n", PcmNo);
  6730. + return 0;
  6731. + }
  6732. + Entry.ChNum=GDMA_PCM_RX(PcmNo,RxNo);
  6733. + Entry.NextUnMaskCh=GDMA_PCM_RX(PcmNo,1-RxNo);
  6734. +
  6735. + return _GdmaReqEntryIns(&Entry);
  6736. +
  6737. +}
  6738. +
  6739. +/**
  6740. + * @brief Start GDMA transaction for sending data to PCM
  6741. + *
  6742. + * @param *Src source address
  6743. + * @param *Dst destination address
  6744. + * @param TransCount data length
  6745. + * @param PcmNo PCM channel
  6746. + * @param TxNo PCM Tx number
  6747. + * @param *DoneIntCallback callback func when transcation is done
  6748. + * @param *UnMaskIntCallback callback func when ch mask field is incorrect
  6749. + * @retval 1 success
  6750. + * @retval 0 fail
  6751. + */
  6752. +int GdmaPcmTx(
  6753. + uint32_t Src,
  6754. + uint32_t Dst,
  6755. + uint8_t PcmNo,
  6756. + uint8_t TxNo,
  6757. + uint16_t TransCount,
  6758. + void (*DoneIntCallback)(uint32_t data),
  6759. + void (*UnMaskIntCallback)(uint32_t data)
  6760. + )
  6761. +{
  6762. + GdmaReqEntry Entry;
  6763. +
  6764. + #if defined (CONFIG_MIPS)
  6765. + Entry.Src= (Src & 0x1FFFFFFF);
  6766. + Entry.Dst= (Dst & 0x1FFFFFFF);
  6767. + #else
  6768. + Entry.Src= Src;
  6769. + Entry.Dst= Dst;
  6770. + #endif
  6771. + Entry.TransCount = TransCount;
  6772. + Entry.SrcBurstMode=INC_MODE;
  6773. + Entry.DstBurstMode=FIX_MODE;
  6774. + Entry.BurstSize=BUSTER_SIZE_4B;
  6775. + Entry.SrcReqNum=DMA_MEM_REQ;
  6776. + Entry.DoneIntCallback=DoneIntCallback;
  6777. + Entry.UnMaskIntCallback=UnMaskIntCallback;
  6778. + Entry.SoftMode=0; //Hardware Mode
  6779. + Entry.ChMask=1;
  6780. + Entry.CoherentIntEbl=0;
  6781. +
  6782. + if(TxNo > 2) {
  6783. + GDMA_PRINT("PCM Tx Number %x is invalid\n", TxNo);
  6784. + return 0;
  6785. + }
  6786. + switch(PcmNo)
  6787. + {
  6788. + case 0:
  6789. + Entry.DstReqNum=DMA_PCM_TX0_REQ;
  6790. + break;
  6791. + case 1:
  6792. + Entry.DstReqNum=DMA_PCM_TX1_REQ;
  6793. + break;
  6794. +#if defined(CONFIG_RALINK_MT7620) || defined (CONFIG_RALINK_MT7621) || defined (CONFIG_RALINK_MT7628) || defined (CONFIG_ARCH_MT7623)
  6795. + case 2:
  6796. + Entry.DstReqNum=DMA_PCM_TX2_REQ;
  6797. + break;
  6798. + case 3:
  6799. + Entry.DstReqNum=DMA_PCM_TX3_REQ;
  6800. + break;
  6801. +#endif
  6802. + default:
  6803. + GDMA_PRINT("PCM Channel %x is invalid\n", PcmNo);
  6804. + return 0;
  6805. + }
  6806. + Entry.ChNum=GDMA_PCM_TX(PcmNo,TxNo);
  6807. + Entry.NextUnMaskCh=GDMA_PCM_TX(PcmNo,1-TxNo);
  6808. +
  6809. + return _GdmaReqEntryIns(&Entry);
  6810. +
  6811. +}
  6812. +
  6813. +
  6814. +/**
  6815. + * @brief Start GDMA transaction for memory to memory copy
  6816. + *
  6817. + * @param *Src source address
  6818. + * @param *Dst destination address
  6819. + * @param TransCount data length
  6820. + * @param *DoneIntCallback callback function when transcation is done
  6821. + * @retval 1 success
  6822. + * @retval 0 fail
  6823. + */
  6824. +int GdmaMem2Mem(
  6825. + uint32_t Src,
  6826. + uint32_t Dst,
  6827. + uint16_t TransCount,
  6828. + void (*DoneIntCallback)(uint32_t data)
  6829. + )
  6830. +
  6831. +{
  6832. +
  6833. + GdmaReqEntry Entry;
  6834. + #if defined (CONFIG_MIPS)
  6835. + Entry.Src= (Src & 0x1FFFFFFF);
  6836. + Entry.Dst= (Dst & 0x1FFFFFFF);
  6837. + #else
  6838. + Entry.Src= Src;
  6839. + Entry.Dst= Dst;
  6840. + #endif
  6841. +
  6842. + //Entry.Src= virt_to_phys(Src);
  6843. + //Entry.Dst= virt_to_phys(Dst);
  6844. +
  6845. +
  6846. +
  6847. + Entry.TransCount = TransCount;
  6848. + Entry.SrcBurstMode=INC_MODE;
  6849. + Entry.DstBurstMode=INC_MODE;
  6850. + Entry.BurstSize=BUSTER_SIZE_64B;
  6851. + Entry.SrcReqNum=DMA_MEM_REQ;
  6852. + Entry.DstReqNum=DMA_MEM_REQ;
  6853. + Entry.DoneIntCallback=DoneIntCallback;
  6854. + Entry.UnMaskIntCallback=NULL;
  6855. + Entry.SoftMode=1;
  6856. + Entry.ChMask=0;
  6857. +
  6858. + Entry.CoherentIntEbl=1;
  6859. +
  6860. + //No reserved channel for Memory to Memory GDMA,
  6861. + //get free channel on demand
  6862. + if(!_GdmaGetFreeCh(&Entry.ChNum)) {
  6863. + GDMA_PRINT("GDMA Channels are all busy\n");
  6864. + return 0;
  6865. + }
  6866. +
  6867. +
  6868. + //set next channel to their own channel
  6869. + //to disable chain feature
  6870. + Entry.NextUnMaskCh= Entry.ChNum;
  6871. + //printk ("ChNum = %d\n", Entry.ChNum);
  6872. + //set next channel to another channel
  6873. + //to enable chain feature
  6874. + //Entry.NextUnMaskCh= (Entry.ChNum+1) % MAX_GDMA_CHANNEL;
  6875. +
  6876. + return _GdmaReqEntryIns(&Entry);
  6877. +
  6878. +
  6879. +}
  6880. +
  6881. +/**
  6882. + * @brief GDMA interrupt handler
  6883. + *
  6884. + * When GDMA transcation is done, call related handler
  6885. + * to do the remain job.
  6886. + *
  6887. + */
  6888. +irqreturn_t GdmaIrqHandler(
  6889. + int irq,
  6890. + void *irqaction
  6891. + )
  6892. +{
  6893. +
  6894. + u32 Ch=0;
  6895. + unsigned long flags;
  6896. +#if defined (CONFIG_RALINK_RT3052)
  6897. + u32 GdmaUnMaskStatus=GDMA_READ_REG(RALINK_GDMAISTS) & 0xFF0000;
  6898. + u32 GdmaDoneStatus=GDMA_READ_REG(RALINK_GDMAISTS) & 0xFF;
  6899. +#elif defined (CONFIG_RALINK_RT3883) || defined (CONFIG_RALINK_RT3352) || defined (CONFIG_RALINK_RT5350) || defined (CONFIG_RALINK_RT6855) || defined (CONFIG_RALINK_RT6855A) || defined (CONFIG_RALINK_MT7620) || defined (CONFIG_RALINK_MT7621) || defined (CONFIG_RALINK_MT7628) || defined (CONFIG_ARCH_MT7623)
  6900. + u32 GdmaUnMaskStatus=GDMA_READ_REG(RALINK_GDMA_UNMASKINT);
  6901. + u32 GdmaDoneStatus=GDMA_READ_REG(RALINK_GDMA_DONEINT);
  6902. +#endif
  6903. + //printk("********GDMA Interrupt*******************\n");
  6904. +
  6905. + //GDMA_PRINT("========================================\n");
  6906. + //GDMA_PRINT("GdmaUnMask Interrupt=%x\n",GdmaUnMaskStatus);
  6907. + //GDMA_PRINT("GdmaDone Interrupt=%x\n",GdmaDoneStatus);
  6908. + //GDMA_PRINT("========================================\n");
  6909. +
  6910. + spin_lock_irqsave(&gdma_int_lock, flags);
  6911. +
  6912. + //write 1 clear
  6913. +#if defined (CONFIG_RALINK_RT3052)
  6914. + GDMA_WRITE_REG(RALINK_GDMAISTS, GdmaUnMaskStatus);
  6915. +#elif defined (CONFIG_RALINK_RT3883) || defined (CONFIG_RALINK_RT3352) || defined (CONFIG_RALINK_RT5350) || defined (CONFIG_RALINK_RT6855) || defined (CONFIG_RALINK_RT6855A) || defined (CONFIG_RALINK_MT7620) || defined (CONFIG_RALINK_MT7621) || defined (CONFIG_RALINK_MT7628) || defined (CONFIG_ARCH_MT7623)
  6916. + GDMA_WRITE_REG(RALINK_GDMA_UNMASKINT, GdmaUnMaskStatus);
  6917. +#endif
  6918. +
  6919. + //UnMask error
  6920. + for(Ch=0;Ch<MAX_GDMA_CHANNEL;Ch++) {
  6921. +
  6922. + if(GdmaUnMaskStatus & (0x1 << (UNMASK_INT_STATUS(Ch))) ) {
  6923. + if(GdmaUnMaskIntCallback[Ch] != NULL) {
  6924. + GdmaUnMaskIntCallback[Ch](Ch);
  6925. + // printk("GdmaUnMaskIntCallback \n");
  6926. + }
  6927. + }
  6928. + }
  6929. +
  6930. + //write 1 clear
  6931. +#if defined (CONFIG_RALINK_RT3052)
  6932. + GDMA_WRITE_REG(RALINK_GDMAISTS, GdmaDoneStatus);
  6933. +#elif defined (CONFIG_RALINK_RT3883) || defined (CONFIG_RALINK_RT3352) || defined (CONFIG_RALINK_RT5350) || defined (CONFIG_RALINK_RT6855) || defined (CONFIG_RALINK_RT6855A) || defined (CONFIG_RALINK_MT7620) || defined (CONFIG_RALINK_MT7621) || defined (CONFIG_RALINK_MT7628) || defined (CONFIG_ARCH_MT7623)
  6934. + GDMA_WRITE_REG(RALINK_GDMA_DONEINT, GdmaDoneStatus);
  6935. +#endif
  6936. +
  6937. + //printk("interrupt status = %x \n", GdmaDoneStatus);
  6938. + //processing done
  6939. + for(Ch=0;Ch<MAX_GDMA_CHANNEL;Ch++) {
  6940. + if(GdmaDoneStatus & (0x1<<Ch)) {
  6941. + if(GdmaDoneIntCallback[Ch] != NULL) {
  6942. + //printk("*************Interrupt Ch=%d***********\n", Ch);
  6943. + GdmaDoneIntCallback[Ch](Ch);
  6944. + }
  6945. + }
  6946. + }
  6947. +
  6948. +//printk("interrupt status clear = %x \n", GDMA_READ_REG(RALINK_GDMA_DONEINT));
  6949. + spin_unlock_irqrestore(&gdma_int_lock, flags);
  6950. +
  6951. + return IRQ_HANDLED;
  6952. +
  6953. +}
  6954. +
  6955. +static int RalinkGdmaInit(void)
  6956. +{
  6957. +
  6958. + uint32_t Ret=0;
  6959. + uint32_t val = 0;
  6960. + printk("Enable Ralink GDMA Controller Module \n");
  6961. +#if defined (CONFIG_RALINK_RT3883) || defined (CONFIG_RALINK_RT3352) || defined (CONFIG_RALINK_RT5350) || defined (CONFIG_RALINK_RT6855) || defined (CONFIG_RALINK_RT6855A) || defined (CONFIG_RALINK_MT7620) || defined (CONFIG_RALINK_MT7621) || defined (CONFIG_RALINK_MT7628) || defined (CONFIG_ARCH_MT7623)
  6962. + printk("GDMA IP Version=%d\n", GET_GDMA_IP_VER);
  6963. +#endif
  6964. +spin_lock_init(&gdma_int_lock);
  6965. +spin_lock_init(&gdma_lock);
  6966. +//spin_lock_init(&gdma_lock_mem);
  6967. +
  6968. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,35)
  6969. + #if defined (CONFIG_MIPS)
  6970. + Ret = request_irq(SURFBOARDINT_DMA, GdmaIrqHandler, \
  6971. + IRQF_DISABLED, "Ralink_DMA", NULL);
  6972. + #else
  6973. + Ret = request_irq(SURFBOARDINT_DMA, GdmaIrqHandler, \
  6974. + IRQF_TRIGGER_LOW, "Ralink_DMA", NULL);
  6975. + #endif
  6976. +#else
  6977. + Ret = request_irq(SURFBOARDINT_DMA, GdmaIrqHandler, \
  6978. + SA_INTERRUPT, "Ralink_DMA", NULL);
  6979. +#endif
  6980. +
  6981. +/*
  6982. + Ret = request_irq(131, GdmaIrqHandler, \
  6983. + IRQF_TRIGGER_LOW, "Ralink_DMA", NULL);
  6984. + */
  6985. + if(Ret){
  6986. + GDMA_PRINT("IRQ %d is not free.\n", SURFBOARDINT_DMA);
  6987. + return 1;
  6988. + }
  6989. +
  6990. +#if defined (CONFIG_MIPS)
  6991. + //Enable GDMA interrupt
  6992. + val = le32_to_cpu(*(volatile u32 *)(RALINK_REG_INTENA));
  6993. + val |= RALINK_INTCTL_DMA;
  6994. + GDMA_WRITE_REG(RALINK_REG_INTENA, val);
  6995. +#endif
  6996. +
  6997. + //Channel0~Channel7 are round-robin
  6998. +#if defined (CONFIG_RALINK_RT3052)
  6999. + GDMA_WRITE_REG(RALINK_GDMAGCT, 0x01);
  7000. +#elif defined (CONFIG_RALINK_RT3883) || defined (CONFIG_RALINK_RT3352) || defined (CONFIG_RALINK_RT5350) || defined (CONFIG_RALINK_RT6855) || defined (CONFIG_RALINK_RT6855A) || defined (CONFIG_RALINK_MT7620) || defined (CONFIG_RALINK_MT7621) || defined (CONFIG_RALINK_MT7628) || defined (CONFIG_ARCH_MT7623)
  7001. + GDMA_WRITE_REG(RALINK_GDMA_GCT, 0x01);
  7002. +#else
  7003. +#error Please Choose System Type
  7004. +#endif
  7005. +
  7006. + return 0;
  7007. +}
  7008. +
  7009. +static void __exit RalinkGdmaExit(void)
  7010. +{
  7011. +
  7012. + printk("Disable Ralink GDMA Controller Module\n");
  7013. +#if defined (CONFIG_MIPS)
  7014. + //Disable GDMA interrupt
  7015. + GDMA_WRITE_REG(RALINK_REG_INTDIS, RALINK_INTCTL_DMA);
  7016. +#endif
  7017. + free_irq(SURFBOARDINT_DMA, NULL);
  7018. +}
  7019. +
  7020. +module_init(RalinkGdmaInit);
  7021. +module_exit(RalinkGdmaExit);
  7022. +
  7023. +EXPORT_SYMBOL(GdmaI2sRx);
  7024. +EXPORT_SYMBOL(GdmaI2sTx);
  7025. +EXPORT_SYMBOL(GdmaPcmRx);
  7026. +EXPORT_SYMBOL(GdmaPcmTx);
  7027. +#if defined(CONFIG_RALINK_MT7620) || defined (CONFIG_RALINK_MT7621) || defined (CONFIG_RALINK_MT7628) || defined (CONFIG_ARCH_MT7623)
  7028. +EXPORT_SYMBOL(GdmaSpiRx);
  7029. +EXPORT_SYMBOL(GdmaSpiTx);
  7030. +#endif
  7031. +EXPORT_SYMBOL(GdmaMem2Mem);
  7032. +EXPORT_SYMBOL(GdmaReqQuickIns);
  7033. +EXPORT_SYMBOL(GdmaMaskChannel);
  7034. +EXPORT_SYMBOL(GdmaUnMaskChannel);
  7035. +
  7036. +
  7037. +MODULE_DESCRIPTION("Ralink SoC GDMA Controller API Module");
  7038. +MODULE_AUTHOR("Steven Liu <steven_liu@ralinktech.com.tw>");
  7039. +MODULE_LICENSE("GPL");
  7040. +MODULE_VERSION(MOD_VERSION);
  7041. --- /dev/null
  7042. +++ b/sound/soc/mtk/ralink_gdma.h
  7043. @@ -0,0 +1,326 @@
  7044. +/*
  7045. + ***************************************************************************
  7046. + * Ralink Tech Inc.
  7047. + * 5F., No.36, Taiyuan St., Jhubei City,
  7048. + * Hsinchu County 302,
  7049. + * Taiwan, R.O.C.
  7050. + *
  7051. + * (c) Copyright, Ralink Technology, Inc.
  7052. + *
  7053. + * This program is free software; you can redistribute it and/or modify it
  7054. + * under the terms of the GNU General Public License as published by the
  7055. + * Free Software Foundation; either version 2 of the License, or (at your
  7056. + * option) any later version.
  7057. + *
  7058. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  7059. + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  7060. + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  7061. + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  7062. + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  7063. + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  7064. + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  7065. + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  7066. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  7067. + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7068. + *
  7069. + * You should have received a copy of the GNU General Public License along
  7070. + * with this program; if not, write to the Free Software Foundation, Inc.,
  7071. + * 675 Mass Ave, Cambridge, MA 02139, USA.
  7072. + *
  7073. + *
  7074. + ***************************************************************************
  7075. + */
  7076. +
  7077. +#ifndef __RALINK_DMA_CTRL_H__
  7078. +#define __RALINK_DMA_CTRL_H__
  7079. +
  7080. +//#include <asm/rt2880/rt_mmap.h>
  7081. +
  7082. +/*
  7083. + * DEFINITIONS AND MACROS
  7084. + */
  7085. +#define MOD_VERSION "0.4"
  7086. +
  7087. +#if defined (CONFIG_RALINK_MT7621) || defined (CONFIG_ARCH_MT7623)
  7088. +#define MAX_GDMA_CHANNEL 16
  7089. +#elif defined (CONFIG_RALINK_RT3052)
  7090. +#define MAX_GDMA_CHANNEL 8
  7091. +#elif defined (CONFIG_RALINK_RT3883) || defined (CONFIG_RALINK_RT3352) || defined (CONFIG_RALINK_RT5350) || defined (CONFIG_RALINK_RT6855) || defined (CONFIG_RALINK_RT6855A) || defined (CONFIG_RALINK_MT7620) || defined (CONFIG_RALINK_MT7628)
  7092. +#define MAX_GDMA_CHANNEL 16
  7093. +#else
  7094. +#error Please Choose System Type
  7095. +#endif
  7096. +
  7097. +
  7098. +#define RALINK_GDMA_CTRL_BASE (RALINK_GDMA_BASE)
  7099. +#if defined (CONFIG_RALINK_RT3052)
  7100. +#define RALINK_GDMAISTS (RALINK_GDMA_BASE + 0x80)
  7101. +#define RALINK_GDMAGCT (RALINK_GDMA_BASE + 0x88)
  7102. +#elif defined (CONFIG_RALINK_RT3883) || defined (CONFIG_RALINK_RT3352) || defined (CONFIG_RALINK_RT5350) || defined (CONFIG_RALINK_RT6855) || defined (CONFIG_RALINK_RT6855A) || defined (CONFIG_RALINK_MT7620) || defined (CONFIG_RALINK_MT7621) || defined (CONFIG_RALINK_MT7628) || defined (CONFIG_ARCH_MT7623)
  7103. +#define RALINK_GDMA_UNMASKINT (RALINK_GDMA_BASE + 0x200)
  7104. +#define RALINK_GDMA_DONEINT (RALINK_GDMA_BASE + 0x204)
  7105. +#define RALINK_GDMA_GCT (RALINK_GDMA_BASE + 0x220)
  7106. +#endif
  7107. +
  7108. +#define KSEG1 0xa0000000
  7109. +#define PHYS_TO_VIRT(x) ((void *)((x) | KSEG1))
  7110. +#define VIRT_TO_PHYS(x) ((unsigned long)(x) & ~KSEG1)
  7111. +
  7112. +
  7113. +
  7114. +
  7115. +#if defined (CONFIG_ARCH_MT7623)
  7116. +#include <mach/sync_write.h>
  7117. +#define GDMA_READ_REG(phys) (*(volatile unsigned int *)((phys)))
  7118. +#define GDMA_WRITE_REG(phys, val) mt65xx_reg_sync_writel((val), (phys))
  7119. +
  7120. +#else
  7121. +#define GDMA_READ_REG(addr) (le32_to_cpu(*(volatile u32 *)(addr)))
  7122. +#define GDMA_WRITE_REG(addr, val) *((volatile uint32_t *)(addr)) = cpu_to_le32(val)
  7123. +
  7124. +
  7125. +
  7126. +#endif
  7127. +
  7128. +
  7129. +#define GET_GDMA_IP_VER (GDMA_READ_REG(RALINK_GDMA_GCT) & 0x6) >> 1 //GDMA_GCT[2:1]
  7130. +
  7131. +#define RALINK_IRQ_ADDR RALINK_INTCL_BASE
  7132. +#if defined (CONFIG_RALINK_MT7621) || defined (CONFIG_ARCH_MT7628)
  7133. +#define RALINK_REG_INTENA (RALINK_IRQ_ADDR + 0x80)
  7134. +#define RALINK_REG_INTDIS (RALINK_IRQ_ADDR + 0x78)
  7135. +#else
  7136. +#define RALINK_REG_INTENA (RALINK_IRQ_ADDR + 0x34)
  7137. +#define RALINK_REG_INTDIS (RALINK_IRQ_ADDR + 0x38)
  7138. +#endif
  7139. +
  7140. +/*
  7141. + * 12bytes=GDMA Channel n Source Address(4) +
  7142. + * GDMA Channel n Destination Address(4) +
  7143. + * GDMA Channel n Control Register(4)
  7144. + *
  7145. + */
  7146. +#define GDMA_SRC_REG(ch) (RALINK_GDMA_BASE + ch*16)
  7147. +#define GDMA_DST_REG(ch) (GDMA_SRC_REG(ch) + 4)
  7148. +#define GDMA_CTRL_REG(ch) (GDMA_DST_REG(ch) + 4)
  7149. +#define GDMA_CTRL_REG1(ch) (GDMA_CTRL_REG(ch) + 4)
  7150. +
  7151. +//GDMA Interrupt Status Register
  7152. +#if defined (CONFIG_RALINK_RT3052)
  7153. +#define UNMASK_INT_STATUS(ch) (ch+16)
  7154. +#elif defined (CONFIG_RALINK_RT3883) || defined (CONFIG_RALINK_RT3352) || defined (CONFIG_RALINK_RT5350) || defined (CONFIG_RALINK_RT6855) || defined (CONFIG_RALINK_RT6855A) || defined (CONFIG_RALINK_MT7620) || defined (CONFIG_RALINK_MT7621) || defined (CONFIG_RALINK_MT7628) || defined (CONFIG_ARCH_MT7623)
  7155. +#define UNMASK_INT_STATUS(ch) (ch)
  7156. +#endif
  7157. +#define TXDONE_INT_STATUS(ch) (ch)
  7158. +
  7159. +//Control Reg0
  7160. +#define MODE_SEL_OFFSET 0
  7161. +#define CH_EBL_OFFSET 1
  7162. +#define CH_DONEINT_EBL_OFFSET 2
  7163. +#define BRST_SIZE_OFFSET 3
  7164. +#define DST_BRST_MODE_OFFSET 6
  7165. +#define SRC_BRST_MODE_OFFSET 7
  7166. +#define TRANS_CNT_OFFSET 16
  7167. +
  7168. +//Control Reg1
  7169. +#if defined (CONFIG_RALINK_RT3052)
  7170. +#define CH_UNMASKINT_EBL_OFFSET 4
  7171. +#define NEXT_UNMASK_CH_OFFSET 1
  7172. +#elif defined (CONFIG_RALINK_RT3883) || defined (CONFIG_RALINK_RT3352) || defined (CONFIG_RALINK_RT5350) || defined (CONFIG_RALINK_RT6855) || defined (CONFIG_RALINK_RT6855A) || defined (CONFIG_RALINK_MT7620) || defined (CONFIG_RALINK_MT7621) || defined (CONFIG_RALINK_MT7628) || defined (CONFIG_ARCH_MT7623)
  7173. +#define CH_UNMASKINT_EBL_OFFSET 1
  7174. +#define NEXT_UNMASK_CH_OFFSET 3
  7175. +#endif
  7176. +#define COHERENT_INT_EBL_OFFSET 2
  7177. +#define CH_MASK_OFFSET 0
  7178. +
  7179. +
  7180. +#if defined (CONFIG_RALINK_RT3052)
  7181. +//Control Reg0
  7182. +#define DST_DMA_REQ_OFFSET 8
  7183. +#define SRC_DMA_REQ_OFFSET 12
  7184. +#elif defined (CONFIG_RALINK_RT3883) || defined (CONFIG_RALINK_RT3352) || defined (CONFIG_RALINK_RT5350) || defined (CONFIG_RALINK_RT6855) || defined (CONFIG_RALINK_RT6855A) || defined (CONFIG_RALINK_MT7620) || defined (CONFIG_RALINK_MT7621) || defined (CONFIG_RALINK_MT7628) || defined (CONFIG_ARCH_MT7623)
  7185. +//Control Reg1
  7186. +#define DST_DMA_REQ_OFFSET 8
  7187. +#define SRC_DMA_REQ_OFFSET 16
  7188. +#endif
  7189. +
  7190. +#define GDMA_PCM0_RX0 0
  7191. +#define GDMA_PCM0_RX1 1
  7192. +#define GDMA_PCM0_TX0 2
  7193. +#define GDMA_PCM0_TX1 3
  7194. +
  7195. +#define GDMA_PCM1_RX0 4
  7196. +#define GDMA_PCM1_RX1 5
  7197. +#define GDMA_PCM1_TX0 6
  7198. +#define GDMA_PCM1_TX1 7
  7199. +
  7200. +#define GDMA_PCM_RX(i,j) (0+((i)<<2)+j)
  7201. +#define GDMA_PCM_TX(i,j) (2+((i)<<2)+j)
  7202. +
  7203. +#define GDMA_I2S_TX0 4
  7204. +#define GDMA_I2S_TX1 5
  7205. +#define GDMA_I2S_RX0 6
  7206. +#define GDMA_I2S_RX1 7
  7207. +
  7208. +#define GDMA_SPI_TX 13
  7209. +#define GDMA_SPI_RX 12
  7210. +
  7211. +
  7212. +//#define GDMA_DEBUG
  7213. +#ifdef GDMA_DEBUG
  7214. +#define GDMA_PRINT(fmt, args...) printk(KERN_INFO "GDMA: " fmt, ## args)
  7215. +#else
  7216. +#define GDMA_PRINT(fmt, args...) { }
  7217. +#endif
  7218. +
  7219. +/*
  7220. + * TYPEDEFS AND STRUCTURES
  7221. + */
  7222. +
  7223. +enum GdmaBusterMode {
  7224. + INC_MODE=0,
  7225. + FIX_MODE=1
  7226. +};
  7227. +
  7228. +enum GdmaBusterSize {
  7229. + BUSTER_SIZE_4B=0, /* 1 transfer */
  7230. + BUSTER_SIZE_8B=1, /* 2 transfer */
  7231. + BUSTER_SIZE_16B=2, /* 4 transfer */
  7232. + BUSTER_SIZE_32B=3, /* 8 transfer */
  7233. + BUSTER_SIZE_64B=4 /* 16 transfer */
  7234. +};
  7235. +
  7236. +enum GdmaDmaReqNum {
  7237. +#if defined (CONFIG_RALINK_RT3052)
  7238. + DMA_REQ0=0,
  7239. + DMA_NAND_REQ=1,
  7240. + DMA_I2S_TX_REQ=2,
  7241. + DMA_PCM_RX0_REQ=3,
  7242. + DMA_PCM_RX1_REQ=4,
  7243. + DMA_PCM_TX0_REQ=5,
  7244. + DMA_PCM_TX1_REQ=6,
  7245. + DMA_REG7=7,
  7246. + DMA_MEM_REQ=8
  7247. +#elif defined (CONFIG_RALINK_RT3883) || defined (CONFIG_RALINK_RT3352) || defined (CONFIG_RALINK_RT5350) || defined (CONFIG_RALINK_RT6855)
  7248. + DMA_REQ0=0,
  7249. + DMA_NAND_REQ=1,
  7250. + DMA_I2S_TX_REQ=2,
  7251. + DMA_I2S_RX_REQ=3,
  7252. + DMA_PCM_RX0_REQ=4,
  7253. + DMA_PCM_RX1_REQ=5,
  7254. + DMA_PCM_TX0_REQ=6,
  7255. + DMA_PCM_TX1_REQ=7,
  7256. + DMA_CODEC0_REQ8=8,
  7257. + DMA_CODEC1_REQ9=9,
  7258. + DMA_REQ10=10,
  7259. + DMA_REQ11=11,
  7260. + DMA_REQ12=12,
  7261. + DMA_REQ13=13,
  7262. + DMA_REQ14=14,
  7263. + DMA_REQ15=15,
  7264. +
  7265. + #if defined (CONFIG_RALINK_RT3883)
  7266. + DMA_MEM_REQ=16
  7267. + #elif defined (CONFIG_RALINK_RT3352) || defined (CONFIG_RALINK_RT5350) || defined (CONFIG_RALINK_RT6855)
  7268. + DMA_MEM_REQ=32
  7269. + #endif
  7270. +
  7271. +#elif defined(CONFIG_RALINK_MT7620) || defined (CONFIG_RALINK_MT7621) || defined (CONFIG_RALINK_MT7628) || defined (CONFIG_ARCH_MT7623)
  7272. + DMA_REQ0=0,
  7273. + DMA_NAND_REQ=1,
  7274. + DMA_I2S_TX_REQ=2,
  7275. + DMA_I2S_RX_REQ=3,
  7276. + DMA_PCM_RX0_REQ=4,
  7277. + DMA_PCM_RX1_REQ=5,
  7278. + DMA_PCM_TX0_REQ=6,
  7279. + DMA_PCM_TX1_REQ=7,
  7280. + DMA_PCM_RX2_REQ=8,
  7281. + DMA_PCM_RX3_REQ=9,
  7282. + DMA_PCM_TX2_REQ=10,
  7283. + DMA_PCM_TX3_REQ=11,
  7284. + DMA_SPI_RX_REQ=12,
  7285. + DMA_SPI_TX_REQ=13,
  7286. + DMA_MEM_REQ=32
  7287. +
  7288. +#elif defined (CONFIG_RALINK_RT6855A)
  7289. + DMA_NAND_REQ=0,
  7290. + DMA_I2S_TX_REQ=1,
  7291. + DMA_I2S_RX_REQ=2,
  7292. + DMA_REQ0=3,
  7293. + DMA_PCM_RX0_REQ=4,
  7294. + DMA_PCM_RX1_REQ=5,
  7295. + DMA_PCM_TX0_REQ=6,
  7296. + DMA_PCM_TX1_REQ=7,
  7297. + DMA_CODEC0_REQ8=8,
  7298. + DMA_CODEC1_REQ9=9,
  7299. + DMA_REQ10=10,
  7300. + DMA_REQ11=11,
  7301. + DMA_REQ12=12,
  7302. + DMA_REQ13=13,
  7303. + DMA_REQ14=14,
  7304. + DMA_REQ15=15,
  7305. + DMA_MEM_REQ=32
  7306. +#else
  7307. +#error Please Choose System Type
  7308. +#endif
  7309. +};
  7310. +
  7311. +
  7312. +
  7313. +typedef struct {
  7314. + uint32_t Src;
  7315. + uint32_t Dst;
  7316. + uint16_t TransCount;
  7317. + uint8_t SoftMode;
  7318. + uint8_t NextUnMaskCh;
  7319. + uint8_t ChMask;
  7320. + uint8_t CoherentIntEbl;
  7321. + uint32_t ChNum;
  7322. + enum GdmaDmaReqNum SrcReqNum;
  7323. + enum GdmaDmaReqNum DstReqNum;
  7324. + enum GdmaBusterMode SrcBurstMode;
  7325. + enum GdmaBusterMode DstBurstMode;
  7326. + enum GdmaBusterSize BurstSize;
  7327. + void (*DoneIntCallback)(uint32_t);
  7328. + void (*UnMaskIntCallback)(uint32_t);
  7329. +} GdmaReqEntry;
  7330. +
  7331. +/*
  7332. + * EXPORT FUNCTION
  7333. + */
  7334. +int GdmaI2sTx(uint32_t Src, uint32_t Dst, uint8_t TxNo, uint16_t TransCount,
  7335. + void (*DoneIntCallback)(uint32_t data),
  7336. + void (*UnMaskIntCallback)(uint32_t data));
  7337. +
  7338. +int GdmaI2sRx(uint32_t Src, uint32_t Dst, uint8_t RxNo, uint16_t TransCount,
  7339. + void (*DoneIntCallback)(uint32_t data),
  7340. + void (*UnMaskIntCallback)(uint32_t data));
  7341. +
  7342. +int GdmaPcmRx(uint32_t Src, uint32_t Dst, uint8_t PcmNo, uint8_t RxNo, uint16_t TransCount,
  7343. + void (*DoneIntCallback)(uint32_t data),
  7344. + void (*UnMaskIntCallback)(uint32_t data));
  7345. +
  7346. +int GdmaPcmTx(uint32_t Src, uint32_t Dst, uint8_t PcmNo, uint8_t TxNo, uint16_t TransCount,
  7347. + void (*DoneIntCallback)(uint32_t data),
  7348. + void (*UnMaskIntCallback)(uint32_t data));
  7349. +
  7350. +int GdmaSpiTx(uint32_t Src, uint32_t Dst, uint16_t TransCount,
  7351. + void (*DoneIntCallback)(uint32_t data),
  7352. + void (*UnMaskIntCallback)(uint32_t data));
  7353. +
  7354. +int GdmaSpiRx(uint32_t Src, uint32_t Dst, uint16_t TransCount,
  7355. + void (*DoneIntCallback)(uint32_t data),
  7356. + void (*UnMaskIntCallback)(uint32_t data));
  7357. +
  7358. +
  7359. +int GdmaMem2Mem(uint32_t Src, uint32_t Dst, uint16_t TransCount,
  7360. + void (*DoneIntCallback)(uint32_t data));
  7361. +
  7362. +int GdmaMaskChannel(uint32_t ChNum);
  7363. +
  7364. +int GdmaUnMaskChannel(uint32_t ChNum);
  7365. +
  7366. +int GdmaReqQuickIns(uint32_t ChNum);
  7367. +
  7368. +
  7369. +#endif
  7370. --- a/sound/soc/soc-core.c
  7371. +++ b/sound/soc/soc-core.c
  7372. @@ -1851,7 +1851,8 @@ static int soc_probe(struct platform_dev
  7373. /* Bodge while we unpick instantiation */
  7374. card->dev = &pdev->dev;
  7375. - return snd_soc_register_card(card);
  7376. + snd_soc_register_card(card);
  7377. + return 0;
  7378. }
  7379. static int soc_cleanup_card_resources(struct snd_soc_card *card)
  7380. --- /dev/null
  7381. +++ b/sound/soc/mtk/i2s_debug.c
  7382. @@ -0,0 +1,698 @@
  7383. +#include <linux/init.h>
  7384. +#include <linux/version.h>
  7385. +#include <linux/module.h>
  7386. +#include <linux/kernel.h> /* printk() */
  7387. +#include "i2s_ctrl.h"
  7388. +#include <linux/delay.h>
  7389. +#include <linux/jiffies.h>
  7390. +#include <linux/random.h>
  7391. +#include <linux/slab.h>
  7392. +#include <asm/uaccess.h> /* copy_from/to_user */
  7393. +
  7394. +#if defined(CONFIG_SND_RALINK_SOC)
  7395. +#include <sound/soc/mtk/mtk_audio_device.h>
  7396. +#endif
  7397. +
  7398. +#if defined(CONFIG_I2S_WM8750)
  7399. +#include "../codec/i2c_wm8750.h"
  7400. +#endif
  7401. +#if defined(CONFIG_I2S_WM8751)
  7402. +#include "../codec/i2c_wm8751.h"
  7403. +#endif
  7404. +#if defined(CONFIG_I2S_WM8960)
  7405. +#include "i2c_wm8960.h"
  7406. +#endif
  7407. +
  7408. +
  7409. +//#define INTERNAL_LOOPBACK_DEBUG
  7410. +
  7411. +extern unsigned long i2s_codec_12p288Mhz[11];
  7412. +extern unsigned long i2s_codec_12Mhz[11];
  7413. +#if defined(CONFIG_RALINK_MT7628) || defined(CONFIG_ARCH_MT7623)
  7414. +extern unsigned long i2s_inclk_int_16bit[13];
  7415. +extern unsigned long i2s_inclk_comp_16bit[13];
  7416. +extern unsigned long i2s_inclk_int_24bit[13];
  7417. +extern unsigned long i2s_inclk_comp_24bit[13];
  7418. +#else
  7419. +extern unsigned long i2s_inclk_int[11];
  7420. +extern unsigned long i2s_inclk_comp[11];
  7421. +#endif
  7422. +extern int i2s_pll_config_mt7621(unsigned long index);
  7423. +extern int i2s_pll_config_mt7623(unsigned long index);
  7424. +
  7425. +#if defined(CONFIG_I2S_WM8960) || defined(CONFIG_I2S_WM8750) || defined(CONFIG_I2S_WM8751)
  7426. +extern void audiohw_loopback(int fsel);
  7427. +extern void audiohw_bypass(void);
  7428. +extern int audiohw_set_lineout_vol(int Aout, int vol_l, int vol_r);
  7429. +extern int audiohw_set_linein_vol(int vol_l, int vol_r);
  7430. +#endif
  7431. +
  7432. +#if defined(CONFIG_I2S_WM8960)
  7433. +extern void audiohw_codec_exlbk(void);
  7434. +#endif
  7435. +
  7436. +unsigned long txbuffer[512] = {
  7437. + 0x01020304, 0x05060708, 0x090a0b0c, 0x0d0e0f10, 0x11121314, 0x15161718, 0x191a1b1c, 0x1d1e1f20,
  7438. + 0x21222324, 0x25262728, 0x292a2b2c, 0x2d2e2f30, 0x31323334, 0x35363738, 0x393a3b3c, 0x3d3e3f40,
  7439. + 0x41424344, 0x45464748, 0x494a4b4c, 0x4d4e4f50, 0x51525354, 0x55565758, 0x595a5b5c, 0x5d5e5f60,
  7440. + 0x61626364, 0x65666768, 0x696a6b6c, 0x6d6e6f70, 0x71727374, 0x75767778, 0x797a7b7c, 0x7d7e7f80,
  7441. + 0x81828384, 0x85868788, 0x898a8b8c, 0x8d8e8f90, 0x91929394, 0x95969798, 0x999a9b9c, 0x9d9e9fa0,
  7442. + 0xa1a2a3a4, 0xa5a6a7a8, 0xa9aaabac, 0xadaeafb0, 0xb1b2b3b4, 0xb5b6b7b8, 0xb9babbbc, 0xbdbebfc0,
  7443. + 0xc1c2c3c4, 0xc5c6c7c8, 0xc9cacbcc, 0xcdcecfd0, 0xd1d2d3d4, 0xd5d6d7d8, 0xd9dadbdc, 0xdddedfe0,
  7444. + 0xe1e2e3e4, 0xe5e6e7e8, 0xe9eaebec, 0xedeeeff0, 0xf1f2f3f4, 0xf5f6f7f8, 0xf9fafbfc, 0xfdfeff00, //round 1
  7445. +0x01020304, 0x05060708, 0x090a0b0c, 0x0d0e0f10, 0x11121314, 0x15161718, 0x191a1b1c, 0x1d1e1f20,
  7446. + 0x21222324, 0x25262728, 0x292a2b2c, 0x2d2e2f30, 0x31323334, 0x35363738, 0x393a3b3c, 0x3d3e3f40,
  7447. + 0x41424344, 0x45464748, 0x494a4b4c, 0x4d4e4f50, 0x51525354, 0x55565758, 0x595a5b5c, 0x5d5e5f60,
  7448. + 0x61626364, 0x65666768, 0x696a6b6c, 0x6d6e6f70, 0x71727374, 0x75767778, 0x797a7b7c, 0x7d7e7f80,
  7449. + 0x81828384, 0x85868788, 0x898a8b8c, 0x8d8e8f90, 0x91929394, 0x95969798, 0x999a9b9c, 0x9d9e9fa0,
  7450. + 0xa1a2a3a4, 0xa5a6a7a8, 0xa9aaabac, 0xadaeafb0, 0xb1b2b3b4, 0xb5b6b7b8, 0xb9babbbc, 0xbdbebfc0,
  7451. + 0xc1c2c3c4, 0xc5c6c7c8, 0xc9cacbcc, 0xcdcecfd0, 0xd1d2d3d4, 0xd5d6d7d8, 0xd9dadbdc, 0xdddedfe0,
  7452. + 0xe1e2e3e4, 0xe5e6e7e8, 0xe9eaebec, 0xedeeeff0, 0xf1f2f3f4, 0xf5f6f7f8, 0xf9fafbfc, 0xfdfeff00, //round 2
  7453. +0x01020304, 0x05060708, 0x090a0b0c, 0x0d0e0f10, 0x11121314, 0x15161718, 0x191a1b1c, 0x1d1e1f20,
  7454. + 0x21222324, 0x25262728, 0x292a2b2c, 0x2d2e2f30, 0x31323334, 0x35363738, 0x393a3b3c, 0x3d3e3f40,
  7455. + 0x41424344, 0x45464748, 0x494a4b4c, 0x4d4e4f50, 0x51525354, 0x55565758, 0x595a5b5c, 0x5d5e5f60,
  7456. + 0x61626364, 0x65666768, 0x696a6b6c, 0x6d6e6f70, 0x71727374, 0x75767778, 0x797a7b7c, 0x7d7e7f80,
  7457. + 0x81828384, 0x85868788, 0x898a8b8c, 0x8d8e8f90, 0x91929394, 0x95969798, 0x999a9b9c, 0x9d9e9fa0,
  7458. + 0xa1a2a3a4, 0xa5a6a7a8, 0xa9aaabac, 0xadaeafb0, 0xb1b2b3b4, 0xb5b6b7b8, 0xb9babbbc, 0xbdbebfc0,
  7459. + 0xc1c2c3c4, 0xc5c6c7c8, 0xc9cacbcc, 0xcdcecfd0, 0xd1d2d3d4, 0xd5d6d7d8, 0xd9dadbdc, 0xdddedfe0,
  7460. + 0xe1e2e3e4, 0xe5e6e7e8, 0xe9eaebec, 0xedeeeff0, 0xf1f2f3f4, 0xf5f6f7f8, 0xf9fafbfc, 0xfdfeff00, //round 3
  7461. +0x01020304, 0x05060708, 0x090a0b0c, 0x0d0e0f10, 0x11121314, 0x15161718, 0x191a1b1c, 0x1d1e1f20,
  7462. + 0x21222324, 0x25262728, 0x292a2b2c, 0x2d2e2f30, 0x31323334, 0x35363738, 0x393a3b3c, 0x3d3e3f40,
  7463. + 0x41424344, 0x45464748, 0x494a4b4c, 0x4d4e4f50, 0x51525354, 0x55565758, 0x595a5b5c, 0x5d5e5f60,
  7464. + 0x61626364, 0x65666768, 0x696a6b6c, 0x6d6e6f70, 0x71727374, 0x75767778, 0x797a7b7c, 0x7d7e7f80,
  7465. + 0x81828384, 0x85868788, 0x898a8b8c, 0x8d8e8f90, 0x91929394, 0x95969798, 0x999a9b9c, 0x9d9e9fa0,
  7466. + 0xa1a2a3a4, 0xa5a6a7a8, 0xa9aaabac, 0xadaeafb0, 0xb1b2b3b4, 0xb5b6b7b8, 0xb9babbbc, 0xbdbebfc0,
  7467. + 0xc1c2c3c4, 0xc5c6c7c8, 0xc9cacbcc, 0xcdcecfd0, 0xd1d2d3d4, 0xd5d6d7d8, 0xd9dadbdc, 0xdddedfe0,
  7468. + 0xe1e2e3e4, 0xe5e6e7e8, 0xe9eaebec, 0xedeeeff0, 0xf1f2f3f4, 0xf5f6f7f8, 0xf9fafbfc, 0xfdfeff00, //round 4
  7469. +0x01020304, 0x05060708, 0x090a0b0c, 0x0d0e0f10, 0x11121314, 0x15161718, 0x191a1b1c, 0x1d1e1f20,
  7470. + 0x21222324, 0x25262728, 0x292a2b2c, 0x2d2e2f30, 0x31323334, 0x35363738, 0x393a3b3c, 0x3d3e3f40,
  7471. + 0x41424344, 0x45464748, 0x494a4b4c, 0x4d4e4f50, 0x51525354, 0x55565758, 0x595a5b5c, 0x5d5e5f60,
  7472. + 0x61626364, 0x65666768, 0x696a6b6c, 0x6d6e6f70, 0x71727374, 0x75767778, 0x797a7b7c, 0x7d7e7f80,
  7473. + 0x81828384, 0x85868788, 0x898a8b8c, 0x8d8e8f90, 0x91929394, 0x95969798, 0x999a9b9c, 0x9d9e9fa0,
  7474. + 0xa1a2a3a4, 0xa5a6a7a8, 0xa9aaabac, 0xadaeafb0, 0xb1b2b3b4, 0xb5b6b7b8, 0xb9babbbc, 0xbdbebfc0,
  7475. + 0xc1c2c3c4, 0xc5c6c7c8, 0xc9cacbcc, 0xcdcecfd0, 0xd1d2d3d4, 0xd5d6d7d8, 0xd9dadbdc, 0xdddedfe0,
  7476. + 0xe1e2e3e4, 0xe5e6e7e8, 0xe9eaebec, 0xedeeeff0, 0xf1f2f3f4, 0xf5f6f7f8, 0xf9fafbfc, 0xfdfeff00, //round 5
  7477. +0x01020304, 0x05060708, 0x090a0b0c, 0x0d0e0f10, 0x11121314, 0x15161718, 0x191a1b1c, 0x1d1e1f20,
  7478. + 0x21222324, 0x25262728, 0x292a2b2c, 0x2d2e2f30, 0x31323334, 0x35363738, 0x393a3b3c, 0x3d3e3f40,
  7479. + 0x41424344, 0x45464748, 0x494a4b4c, 0x4d4e4f50, 0x51525354, 0x55565758, 0x595a5b5c, 0x5d5e5f60,
  7480. + 0x61626364, 0x65666768, 0x696a6b6c, 0x6d6e6f70, 0x71727374, 0x75767778, 0x797a7b7c, 0x7d7e7f80,
  7481. + 0x81828384, 0x85868788, 0x898a8b8c, 0x8d8e8f90, 0x91929394, 0x95969798, 0x999a9b9c, 0x9d9e9fa0,
  7482. + 0xa1a2a3a4, 0xa5a6a7a8, 0xa9aaabac, 0xadaeafb0, 0xb1b2b3b4, 0xb5b6b7b8, 0xb9babbbc, 0xbdbebfc0,
  7483. + 0xc1c2c3c4, 0xc5c6c7c8, 0xc9cacbcc, 0xcdcecfd0, 0xd1d2d3d4, 0xd5d6d7d8, 0xd9dadbdc, 0xdddedfe0,
  7484. + 0xe1e2e3e4, 0xe5e6e7e8, 0xe9eaebec, 0xedeeeff0, 0xf1f2f3f4, 0xf5f6f7f8, 0xf9fafbfc, 0xfdfeff00, //round 6
  7485. +0x01020304, 0x05060708, 0x090a0b0c, 0x0d0e0f10, 0x11121314, 0x15161718, 0x191a1b1c, 0x1d1e1f20,
  7486. + 0x21222324, 0x25262728, 0x292a2b2c, 0x2d2e2f30, 0x31323334, 0x35363738, 0x393a3b3c, 0x3d3e3f40,
  7487. + 0x41424344, 0x45464748, 0x494a4b4c, 0x4d4e4f50, 0x51525354, 0x55565758, 0x595a5b5c, 0x5d5e5f60,
  7488. + 0x61626364, 0x65666768, 0x696a6b6c, 0x6d6e6f70, 0x71727374, 0x75767778, 0x797a7b7c, 0x7d7e7f80,
  7489. + 0x81828384, 0x85868788, 0x898a8b8c, 0x8d8e8f90, 0x91929394, 0x95969798, 0x999a9b9c, 0x9d9e9fa0,
  7490. + 0xa1a2a3a4, 0xa5a6a7a8, 0xa9aaabac, 0xadaeafb0, 0xb1b2b3b4, 0xb5b6b7b8, 0xb9babbbc, 0xbdbebfc0,
  7491. + 0xc1c2c3c4, 0xc5c6c7c8, 0xc9cacbcc, 0xcdcecfd0, 0xd1d2d3d4, 0xd5d6d7d8, 0xd9dadbdc, 0xdddedfe0,
  7492. + 0xe1e2e3e4, 0xe5e6e7e8, 0xe9eaebec, 0xedeeeff0, 0xf1f2f3f4, 0xf5f6f7f8, 0xf9fafbfc, 0xfdfeff00, //round 7
  7493. +0x01020304, 0x05060708, 0x090a0b0c, 0x0d0e0f10, 0x11121314, 0x15161718, 0x191a1b1c, 0x1d1e1f20,
  7494. + 0x21222324, 0x25262728, 0x292a2b2c, 0x2d2e2f30, 0x31323334, 0x35363738, 0x393a3b3c, 0x3d3e3f40,
  7495. + 0x41424344, 0x45464748, 0x494a4b4c, 0x4d4e4f50, 0x51525354, 0x55565758, 0x595a5b5c, 0x5d5e5f60,
  7496. + 0x61626364, 0x65666768, 0x696a6b6c, 0x6d6e6f70, 0x71727374, 0x75767778, 0x797a7b7c, 0x7d7e7f80,
  7497. + 0x81828384, 0x85868788, 0x898a8b8c, 0x8d8e8f90, 0x91929394, 0x95969798, 0x999a9b9c, 0x9d9e9fa0,
  7498. + 0xa1a2a3a4, 0xa5a6a7a8, 0xa9aaabac, 0xadaeafb0, 0xb1b2b3b4, 0xb5b6b7b8, 0xb9babbbc, 0xbdbebfc0,
  7499. + 0xc1c2c3c4, 0xc5c6c7c8, 0xc9cacbcc, 0xcdcecfd0, 0xd1d2d3d4, 0xd5d6d7d8, 0xd9dadbdc, 0xdddedfe0,
  7500. + 0xe1e2e3e4, 0xe5e6e7e8, 0xe9eaebec, 0xedeeeff0, 0xf1f2f3f4, 0xf5f6f7f8, 0xf9fafbfc, 0xfdfeff00 //round 8
  7501. + };
  7502. +
  7503. +int i2s_debug_cmd(unsigned int cmd, unsigned long arg)
  7504. +{
  7505. + unsigned long data, index;
  7506. + unsigned long *pTable;
  7507. + int i;
  7508. +
  7509. + switch(cmd)
  7510. + {
  7511. + case I2S_DEBUG_CLKGEN:
  7512. + MSG("I2S_DEBUG_CLKGEN\n");
  7513. +#if defined(CONFIG_RALINK_RT3052)
  7514. + *(volatile unsigned long*)(0xB0000060) = 0x00000016;
  7515. + *(volatile unsigned long*)(0xB0000030) = 0x00009E00;
  7516. + *(volatile unsigned long*)(0xB0000A00) = 0xC0000040;
  7517. +#elif defined(CONFIG_RALINK_RT3350)
  7518. + *(volatile unsigned long*)(0xB0000060) = 0x00000018;
  7519. + *(volatile unsigned long*)(0xB000002C) = 0x00000100;
  7520. + *(volatile unsigned long*)(0xB0000030) = 0x00009E00;
  7521. + *(volatile unsigned long*)(0xB0000A00) = 0xC0000040;
  7522. +#elif defined(CONFIG_RALINK_RT3883)
  7523. + *(volatile unsigned long*)(0xB0000060) = 0x00000018;
  7524. + *(volatile unsigned long*)(0xB000002C) = 0x00003000;
  7525. + *(volatile unsigned long*)(0xB0000A00) = 0xC1104040;
  7526. + *(volatile unsigned long*)(0xB0000A24) = 0x00000027;
  7527. + *(volatile unsigned long*)(0xB0000A20) = 0x80000020;
  7528. +#elif (defined(CONFIG_RALINK_RT3352)||defined(CONFIG_RALINK_RT5350)) || defined (CONFIG_RALINK_RT6855)
  7529. + *(volatile unsigned long*)(0xB0000060) = 0x00000018;
  7530. + *(volatile unsigned long*)(0xB000002C) = 0x00000300;
  7531. + *(volatile unsigned long*)(0xB0000A00) = 0xC1104040;
  7532. + *(volatile unsigned long*)(0xB0000A24) = 0x00000027;
  7533. + *(volatile unsigned long*)(0xB0000A20) = 0x80000020;
  7534. +#elif defined(CONFIG_RALINK_RT6855A)
  7535. + *(volatile unsigned long*)(RALINK_SYSCTL_BASE+0x860) = 0x00008080;
  7536. + *(volatile unsigned long*)(RALINK_SYSCTL_BASE+0x82C) = 0x00000300;
  7537. + *(volatile unsigned long*)(RALINK_I2S_BASE+0x00) = 0xC1104040;
  7538. + *(volatile unsigned long*)(RALINK_I2S_BASE+0x24) = 0x00000027;
  7539. + *(volatile unsigned long*)(RALINK_I2S_BASE+0x20) = 0x80000020;
  7540. +#else
  7541. +//#error "I2S debug mode not support this Chip"
  7542. +#endif
  7543. + break;
  7544. + case I2S_DEBUG_INLBK:
  7545. + MSG("I2S_DEBUG_INLBK\n");
  7546. +#if defined(CONFIG_RALINK_MT7621)
  7547. + switch(96000)
  7548. + {
  7549. + case 8000:
  7550. + index = 0;
  7551. + break;
  7552. + case 11025:
  7553. + index = 1;
  7554. + break;
  7555. + case 12000:
  7556. + index = 2;
  7557. + break;
  7558. + case 16000:
  7559. + index = 3;
  7560. + break;
  7561. + case 22050:
  7562. + index = 4;
  7563. + break;
  7564. + case 24000:
  7565. + index = 5;
  7566. + break;
  7567. + case 32000:
  7568. + index = 6;
  7569. + break;
  7570. + case 44100:
  7571. + index = 7;
  7572. + break;
  7573. + case 48000:
  7574. + index = 8;
  7575. + break;
  7576. + case 88200:
  7577. + index = 9;
  7578. + break;
  7579. + case 96000:
  7580. + index = 10;
  7581. + break;
  7582. + case 192000:
  7583. + index = 11;
  7584. + break;
  7585. + default:
  7586. + index = 7;
  7587. + }
  7588. + i2s_pll_config_mt7621(index);
  7589. +#elif defined(CONFIG_ARCH_MT7623)
  7590. + i2s_pll_config_mt7623(11);
  7591. +#endif
  7592. +
  7593. +
  7594. +#if defined(CONFIG_RALINK_RT3052)
  7595. + break;
  7596. +#endif
  7597. +#if defined(CONFIG_RALINK_RT6855A)
  7598. + *(volatile unsigned long*)(RALINK_SYSCTL_BASE+0x834) |= 0x00020000;
  7599. + *(volatile unsigned long*)(RALINK_SYSCTL_BASE+0x834) &= 0xFFFDFFFF;
  7600. + *(volatile unsigned long*)(RALINK_I2S_BASE+0x0) &= 0x7FFFFFFF; //Rest I2S to default vaule
  7601. + *(volatile unsigned long*)(RALINK_SYSCTL_BASE+0x860) |= 0x00008080;
  7602. + *(volatile unsigned long*)(RALINK_SYSCTL_BASE+0x82C) = 0x00000300;
  7603. +#elif defined(CONFIG_RALINK_MT7621)
  7604. + *(volatile unsigned long*)(RALINK_SYSCTL_BASE+0x34) |= 0x00020000;
  7605. + *(volatile unsigned long*)(RALINK_SYSCTL_BASE+0x34) &= 0xFFFDFFFF;
  7606. + *(volatile unsigned long*)(RALINK_I2S_BASE+0x0) &= 0x7FFFFFFF; //Rest I2S to default vaule
  7607. + *(volatile unsigned long*)(RALINK_SYSCTL_BASE+0x60) = 0x00000010; //GPIO purpose selection
  7608. +#elif defined(CONFIG_RALINK_MT7628)
  7609. + *(volatile unsigned long*)(RALINK_SYSCTL_BASE+0x34) |= 0x00020000;
  7610. + *(volatile unsigned long*)(RALINK_SYSCTL_BASE+0x34) &= 0xFFFDFFFF;
  7611. + *(volatile unsigned long*)(RALINK_I2S_BASE+0x0) &= 0x7FFFFFFF; //Rest I2S to default vaule
  7612. + *(volatile unsigned long*)(RALINK_SYSCTL_BASE+0x60) &= ~((0x3)<<6); //GPIO purpose selection /*FIXME*/
  7613. +#elif defined(CONFIG_ARCH_MT7623)
  7614. + *(volatile unsigned long*)(0xFB000034) |= 0x00020000;
  7615. + *(volatile unsigned long*)(0xFB000034) &= 0xFFFDFFFF;
  7616. + *(volatile unsigned long*)(ETHDMASYS_I2S_BASE+0x0) &= 0x7FFFFFFF; //Rest I2S to default vaule
  7617. +
  7618. + *(volatile unsigned long*)(0xF0005840) &= ~((0x7)<<12);
  7619. + *(volatile unsigned long*)(0xF0005840) |= ((0x6)<<12);
  7620. + *(volatile unsigned long*)(0xF0005840) &= ~((0x7)<<9);
  7621. + *(volatile unsigned long*)(0xF0005840) |= ((0x6)<<9);
  7622. + *(volatile unsigned long*)(0xF0005040) |= ((0x1)<<10);
  7623. + *(volatile unsigned long*)(0xF0005040) |= ((0x1)<<9);
  7624. +
  7625. + *(volatile unsigned long*)(0xF00057F0) &= ~((0x7)<<12);
  7626. + *(volatile unsigned long*)(0xF00057F0) |= ((0x6)<<12);
  7627. + *(volatile unsigned long*)(0xF0005030) |= ((0x1)<<1);
  7628. +
  7629. + *(volatile unsigned long*)(0xF0005840) &= ~((0x7)<<6);
  7630. + *(volatile unsigned long*)(0xF0005840) |= ((0x6)<<6);
  7631. + *(volatile unsigned long*)(0xF0005040) &= ~((0x1)<<8);
  7632. +
  7633. + *(volatile unsigned long*)(0xF00058F0) &= ~((0x7)<<3);
  7634. + *(volatile unsigned long*)(0xF00058F0) |= ((0x6)<<3);
  7635. + *(volatile unsigned long*)(0xF0005070) |= ((0x1)<<14);
  7636. +
  7637. +
  7638. +#else
  7639. + *(volatile unsigned long*)(0xB0000034) |= 0x00020000;
  7640. + *(volatile unsigned long*)(0xB0000034) &= 0xFFFDFFFF;
  7641. + *(volatile unsigned long*)(0xB0000A00) &= 0x7FFFFFFF; //Rest I2S to default vaule
  7642. + *(volatile unsigned long*)(0xB0000060) = 0x00000018;
  7643. +
  7644. +#if defined(CONFIG_RALINK_RT3883)
  7645. + *(volatile unsigned long*)(0xB000002C) = 0x00003000;
  7646. +#elif defined(CONFIG_ARCH_MT7623)
  7647. +
  7648. +#else
  7649. + *(volatile unsigned long*)(0xB000002C) = 0x00000300;
  7650. +#endif
  7651. +#endif
  7652. +#if defined(CONFIG_RALINK_MT7621)
  7653. + *(volatile unsigned long*)(RALINK_I2S_BASE+0x18) = 0x80000000;
  7654. + *(volatile unsigned long*)(RALINK_I2S_BASE+0x00) = 0xc1104040;
  7655. +
  7656. + pTable = i2s_inclk_int;
  7657. + data = pTable[index];
  7658. + //*(volatile unsigned long*)(RALINK_I2S_BASE+0x24) = data;
  7659. + i2s_outw(RALINK_I2S_BASE+0x24, data);
  7660. +
  7661. + pTable = i2s_inclk_comp;
  7662. + data = pTable[index];
  7663. + //*(volatile unsigned long*)(RALINK_I2S_BASE+0x20) = data;
  7664. + i2s_outw(RALINK_I2S_BASE+0x20, (data|0x80000000));
  7665. +#elif defined(CONFIG_RALINK_MT7628)
  7666. + index =11; /* SR: 192k */
  7667. + *(volatile unsigned long*)(RALINK_I2S_BASE+0x18) = 0x80000000;
  7668. + *(volatile unsigned long*)(RALINK_I2S_BASE+0x00) = 0xc1104040;
  7669. +
  7670. + pTable = i2s_inclk_int_16bit;
  7671. + //pTable = i2s_inclk_int_24bit;
  7672. + data = pTable[index];
  7673. + //*(volatile unsigned long*)(RALINK_I2S_BASE+0x24) = data;
  7674. + i2s_outw(RALINK_I2S_BASE+0x24, data);
  7675. +
  7676. + pTable = i2s_inclk_comp_16bit;
  7677. + //pTable = i2s_inclk_comp_24bit;
  7678. + data = pTable[index];
  7679. + //*(volatile unsigned long*)(RALINK_I2S_BASE+0x20) = data;
  7680. + i2s_outw(RALINK_I2S_BASE+0x20, (data|0x80000000));
  7681. + mdelay(5);
  7682. +#elif defined(CONFIG_ARCH_MT7623)
  7683. + index = 11;
  7684. + *(volatile unsigned long*)(I2S_I2SCFG1) = 0x80000000;
  7685. + *(volatile unsigned long*)(I2S_I2SCFG) = 0xE1104040;
  7686. + *(volatile unsigned long*)(ETHDMASYS_SYSCTL_BASE+0x30) |= 0x00020000;
  7687. + *(volatile unsigned long*)(ETHDMASYS_SYSCTL_BASE+0x2c) |= 0x00000080;
  7688. +
  7689. + pTable = i2s_inclk_int_16bit;
  7690. + //pTable = i2s_inclk_int_24bit;
  7691. + data = pTable[index];
  7692. + i2s_outw(I2S_DIVINT_CFG, data);
  7693. +
  7694. + pTable = i2s_inclk_comp_16bit;
  7695. + //pTable = i2s_inclk_comp_24bit;
  7696. + data = pTable[index];
  7697. + i2s_outw(I2S_DIVCOMP_CFG, (data|0x80000000));
  7698. + mdelay(5);
  7699. +#else
  7700. + *(volatile unsigned long*)(RALINK_I2S_BASE+0x18) = 0x80000000;
  7701. + *(volatile unsigned long*)(RALINK_I2S_BASE+0x00) = 0xC1104040;
  7702. + *(volatile unsigned long*)(RALINK_I2S_BASE+0x24) = 0x00000006;
  7703. + *(volatile unsigned long*)(RALINK_I2S_BASE+0x20) = 0x80000105;
  7704. +#endif
  7705. + {
  7706. + int count = 0;
  7707. + int k=0;
  7708. + int enable_cnt=0;
  7709. + unsigned long param[4];
  7710. + unsigned long data;
  7711. + //unsigned long data_tmp;
  7712. + unsigned long ff_status;
  7713. + //unsigned long* txbuffer;
  7714. +#if 0
  7715. + int j=0;
  7716. + int temp = 0;
  7717. +#endif
  7718. +#if defined (INTERNAL_LOOPBACK_DEBUG)
  7719. + int count2 = 0;
  7720. +#endif
  7721. + memset(param, 0, 4*sizeof(unsigned long) );
  7722. + copy_from_user(param, (unsigned long*)arg, sizeof(long)*2);
  7723. +#if 0
  7724. + txbuffer = (unsigned long*)kcalloc(param[0], sizeof(unsigned long), GFP_KERNEL);
  7725. + if(txbuffer == NULL)
  7726. + return -1;
  7727. +#endif
  7728. +
  7729. + //ff_status = *(volatile unsigned long*)(RALINK_I2S_BASE+0x0C);
  7730. + ff_status = *(volatile unsigned long*)(I2S_FF_STATUS);
  7731. + printk("ff status=[0x%08X]\n",(u32)ff_status);
  7732. +
  7733. +#if 0
  7734. + for(i = 0; i < param[0]; i++)
  7735. + {
  7736. + if (i==0)
  7737. + {
  7738. + txbuffer[i] = 0x555A555A;
  7739. + printk("%d: 0x%8lx\n", i, txbuffer[i]);
  7740. + }
  7741. + else
  7742. + {
  7743. + #if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,14)
  7744. + srandom32(jiffies);
  7745. + txbuffer[i] = random32()%(0x555A555A)+1;
  7746. + //printk("%d: 0x%8x\n", i, txbuffer[i]);
  7747. + #else
  7748. + //TODO:do we need to implement random32()
  7749. + txbuffer[i] = 0x01010101;
  7750. + #endif
  7751. + }
  7752. + }
  7753. +#endif
  7754. +
  7755. + for( i = 0 ; i < param[0] ; i ++ )
  7756. + {
  7757. + ff_status = *(volatile unsigned long*)(I2S_FF_STATUS);
  7758. + #if defined(CONFIG_RALINK_MT7628) || defined(CONFIG_ARCH_MT7623)
  7759. + if((ff_status&0xFF) > 0)
  7760. + #else
  7761. + if((ff_status&0x0F) > 0)
  7762. + #endif
  7763. + {
  7764. + *(volatile unsigned long*)(I2S_TX_FIFO_WREG) = txbuffer[i];
  7765. + mdelay(1);
  7766. + }
  7767. + else
  7768. + {
  7769. + mdelay(1);
  7770. + printk("[%d]NO TX FREE FIFO ST=[0x%08X]\n", i, (u32)ff_status);
  7771. + continue;
  7772. + }
  7773. +
  7774. + //if(i >= 16)
  7775. + {
  7776. +
  7777. + ff_status = *(volatile unsigned long*)(I2S_FF_STATUS);
  7778. + #if defined(CONFIG_RALINK_MT7628)
  7779. + if(((ff_status>>8)&0xFF) > 0)
  7780. + #else
  7781. + if(((ff_status>>4)&0x0F) > 0)
  7782. + #endif
  7783. + {
  7784. + data = *(volatile unsigned long*)(I2S_RX_FIFO_RREG);
  7785. + //data_tmp = *(volatile unsigned long*)(I2S_RX_FIFO_RREG);
  7786. + //MSG("[0x%08X] vs [0x%08X]\n", (u32)data, (u32)data_tmp);
  7787. + }
  7788. + else
  7789. + {
  7790. + printk("*[%d]NO RX FREE FIFO ST=[0x%08X]\n", i, (u32)ff_status);
  7791. + continue;
  7792. + }
  7793. +
  7794. + if (data == txbuffer[0])
  7795. + {
  7796. + k = i;
  7797. + enable_cnt = 1;
  7798. + }
  7799. + if (enable_cnt==1)
  7800. + {
  7801. + if(data!= txbuffer[i-k])
  7802. + {
  7803. + MSG("[%d][0x%08X] vs [0x%08X]\n", (i-k), (u32)data, (u32)txbuffer[i-k]);
  7804. + }
  7805. + else
  7806. + {
  7807. + //MSG("**[%d][0x%08X] vs [0x%08X]\n" ,(i-k), (u32)data , (u32)txbuffer[i-k]);
  7808. + count++;
  7809. + data=0;
  7810. + }
  7811. + }
  7812. +
  7813. + }
  7814. + }
  7815. +#if 0
  7816. + temp = i-k;
  7817. + for (j=0; j<k; j++)
  7818. + {
  7819. +
  7820. + //ff_status = *(volatile unsigned long*)(RALINK_I2S_BASE+0x0C);
  7821. + ff_status = *(volatile unsigned long*)(I2S_FF_STATUS);
  7822. + #if defined(CONFIG_RALINK_MT7628) || defined(CONFIG_ARCH_MT7623)
  7823. + if(((ff_status>>8)&0xFF) > 0)
  7824. + #else
  7825. + if(((ff_status>>4)&0x0F) > 0)
  7826. + #endif
  7827. + {
  7828. + //data = *(volatile unsigned long*)(RALINK_I2S_BASE+0x14);
  7829. + data = *(volatile unsigned long*)(I2S_RX_FIFO_RREG);
  7830. + }
  7831. + else
  7832. + {
  7833. + printk("*NO RX FREE FIFO ST=[0x%08X]\n", (u32)ff_status);
  7834. + continue;
  7835. + }
  7836. +
  7837. + if(data!= txbuffer[temp+j])
  7838. + {
  7839. + MSG("[%d][0x%08X] vs [0x%08X]\n", (temp+j), (u32)data, (u32)txbuffer[temp+j]);
  7840. + }
  7841. + else
  7842. + {
  7843. + //MSG("&&[%d][0x%08X] vs [0x%08X]\n" ,(temp+j), (u32)data , (u32)txbuffer[temp+j]);
  7844. + count++;
  7845. + data=0;
  7846. + }
  7847. + if ((temp+j)==128)
  7848. + {
  7849. + //ff_status = *(volatile unsigned long*)(RALINK_I2S_BASE+0x0C);
  7850. + ff_status = *(volatile unsigned long*)(I2S_FF_STATUS);
  7851. + //printk("[%d]FIFO ST=[0x%08X]\n", (temp+j), (u32)ff_status);
  7852. + }
  7853. + }
  7854. +#endif
  7855. +
  7856. +#if defined (INTERNAL_LOOPBACK_DEBUG)
  7857. + for( i = 0 ; i < param[0] ; i ++ )
  7858. + {
  7859. + //ff_status = *(volatile unsigned long*)(RALINK_I2S_BASE+0x0C);
  7860. + ff_status = *(volatile unsigned long*)(I2S_FF_STATUS);
  7861. + #if defined(CONFIG_RALINK_MT7628)|| defined(CONFIG_ARCH_MT7623)
  7862. + if((ff_status&0xFF) > 0)
  7863. + #else
  7864. + if((ff_status&0x0F) > 0)
  7865. + #endif
  7866. + {
  7867. + //*(volatile unsigned long*)(RALINK_I2S_BASE+0x10) = txbuffer[i];
  7868. + *(volatile unsigned long*)(I2S_TX_FIFO_WREG) = txbuffer[i];
  7869. + mdelay(1);
  7870. + }
  7871. + else
  7872. + {
  7873. + mdelay(1);
  7874. + printk("[%d]NO TX FREE FIFO ST=[0x%08X]\n", i, (u32)ff_status);
  7875. + continue;
  7876. + }
  7877. +
  7878. + //if(i >= 16)
  7879. + {
  7880. +
  7881. + //ff_status = *(volatile unsigned long*)(RALINK_I2S_BASE+0x0C);
  7882. + ff_status = *(volatile unsigned long*)(I2S_FF_STATUS);
  7883. + #if defined(CONFIG_RALINK_MT7628)|| defined(CONFIG_ARCH_MT7623)
  7884. + if(((ff_status>>8)&0xFF) > 0)
  7885. + #else
  7886. + if(((ff_status>>4)&0x0F) > 0)
  7887. + #endif
  7888. + {
  7889. + //data = *(volatile unsigned long*)(RALINK_I2S_BASE+0x14);
  7890. + data = *(volatile unsigned long*)(I2S_RX_FIFO_RREG);
  7891. + }
  7892. + else
  7893. + {
  7894. + printk("*[%d]NO RX FREE FIFO ST=[0x%08X]\n", i, (u32)ff_status);
  7895. + continue;
  7896. + }
  7897. +
  7898. + {
  7899. + if(data!= txbuffer[i])
  7900. + {
  7901. + MSG("[%d][0x%08X] vs [0x%08X]\n", (i), (u32)data, (u32)txbuffer[i]);
  7902. + }
  7903. + else
  7904. + {
  7905. + MSG("**[%d][0x%08X] vs [0x%08X]\n" ,(i), (u32)data , (u32)txbuffer[i]);
  7906. + count2++;
  7907. + data=0;
  7908. + }
  7909. + }
  7910. +
  7911. + }
  7912. + }
  7913. + printk("Pattern match done count2=%d.\n", count2);
  7914. +#endif
  7915. + printk("Pattern match done count=%d.\n", count);
  7916. +
  7917. + }
  7918. +#if defined(CONFIG_ARCH_MT7623)
  7919. + *(volatile unsigned long*)(0xFB000034) |= 0x00020000;
  7920. + *(volatile unsigned long*)(0xFB000034) &= 0xFFFDFFFF;
  7921. + *(volatile unsigned long*)(ETHDMASYS_I2S_BASE+0x0) &= 0x7FFFFFFF; //Rest I2S to default vaule
  7922. +#endif
  7923. +
  7924. +#if !defined(CONFIG_RALINK_RT3052)
  7925. + break;
  7926. +#endif
  7927. + case I2S_DEBUG_EXLBK:
  7928. + MSG("I2S_DEBUG_EXLBK\n");
  7929. +#if !defined(CONFIG_ARCH_MT7623)
  7930. + switch(arg)
  7931. + {
  7932. + case 8000:
  7933. + index = 0;
  7934. + break;
  7935. + case 11025:
  7936. + index = 1;
  7937. + break;
  7938. + case 12000:
  7939. + index = 2;
  7940. + break;
  7941. + case 16000:
  7942. + index = 3;
  7943. + break;
  7944. + case 22050:
  7945. + index = 4;
  7946. + break;
  7947. + case 24000:
  7948. + index = 5;
  7949. + break;
  7950. + case 32000:
  7951. + index = 6;
  7952. + break;
  7953. + case 44100:
  7954. + index = 7;
  7955. + break;
  7956. + case 48000:
  7957. + index = 8;
  7958. + break;
  7959. + case 88200:
  7960. + index = 9;
  7961. + break;
  7962. + case 96000:
  7963. + index = 10;
  7964. + break;
  7965. + default:
  7966. + index = 7;
  7967. + }
  7968. +#if defined(CONFIG_RALINK_RT3052)
  7969. + break;
  7970. +#endif
  7971. +#if defined(CONFIG_RALINK_RT6855A)
  7972. + *(volatile unsigned long*)(RALINK_SYSCTL_BASE+0x860) = 0x00008080;
  7973. + //*(volatile unsigned long*)(RALINK_SYSCTL_BASE+0x82C) = 0x00000300;
  7974. +#else
  7975. + *(volatile unsigned long*)(RALINK_SYSCTL_BASE+0x60) = 0x00000018;
  7976. +#if defined(CONFIG_RALINK_RT3883)
  7977. + *(volatile unsigned long*)(RALINK_SYSCTL_BASE+0x2C) = 0x00003000;
  7978. +#else
  7979. + *(volatile unsigned long*)(RALINK_SYSCTL_BASE+0x2C) = 0x00000300;
  7980. +#endif
  7981. +#endif
  7982. +
  7983. + *(volatile unsigned long*)(RALINK_I2S_BASE+0x18) = 0x40000000;
  7984. + *(volatile unsigned long*)(RALINK_I2S_BASE+0x00) = 0x81104040;
  7985. +#if defined(CONFIG_RALINK_MT7628)
  7986. + pTable = i2s_inclk_int_16bit;
  7987. +#else
  7988. + pTable = i2s_inclk_int;
  7989. +#endif
  7990. + data = (volatile unsigned long)(pTable[index]);
  7991. + i2s_outw(I2S_DIVINT_CFG, data);
  7992. +#if defined(CONFIG_RALINK_MT7628)
  7993. + pTable = i2s_inclk_comp_16bit;
  7994. +#else
  7995. + pTable = i2s_inclk_comp;
  7996. +#endif
  7997. + data = (volatile unsigned long)(pTable[index]);
  7998. + data |= REGBIT(1, I2S_CLKDIV_EN);
  7999. + i2s_outw(I2S_DIVCOMP_CFG, data);
  8000. +
  8001. + #if defined(CONFIG_I2S_MCLK_12MHZ)
  8002. + pTable = i2s_codec_12Mhz;
  8003. + #if defined(CONFIG_I2S_WM8960)
  8004. + data = pTable[index];
  8005. + #else
  8006. + data = pTable[index]|0x01;
  8007. + #endif
  8008. + #else
  8009. + pTable = i2s_codec_12p288Mhz;
  8010. + data = pTable[index];
  8011. + #endif
  8012. +
  8013. + #if defined(CONFIG_I2S_WM8960) || defined(CONFIG_I2S_WM8750) || defined(CONFIG_I2S_WM8751)
  8014. + audiohw_preinit();
  8015. + #endif
  8016. +
  8017. +
  8018. + #if defined (CONFIG_I2S_WM8960)
  8019. + audiohw_postinit(1, 1, 1, 1, 0); // for codec apll enable, 16 bit word length
  8020. + #elif defined(CONFIG_I2S_WM8750) || defined(CONFIG_I2S_WM8751)
  8021. + audiohw_postinit(1, 1, 1, 0); // for 16 bit word length
  8022. + #endif
  8023. +
  8024. +
  8025. + #if defined (CONFIG_I2S_WM8960)
  8026. + audiohw_set_frequency(data, 1); // for codec apll enable
  8027. + #elif defined(CONFIG_I2S_WM8750) || defined(CONFIG_I2S_WM8751)
  8028. + audiohw_set_frequency(data|0x1);
  8029. + #endif
  8030. +
  8031. +
  8032. + #if defined(CONFIG_I2S_WM8960) || defined(CONFIG_I2S_WM8750) || defined(CONFIG_I2S_WM8751)
  8033. + audiohw_set_lineout_vol(1, 100, 100);
  8034. + audiohw_set_linein_vol(100, 100);
  8035. + #endif
  8036. +
  8037. +
  8038. + #if defined(CONFIG_I2S_TXRX)
  8039. + //audiohw_loopback(data);
  8040. + #endif
  8041. + #if !defined(CONFIG_RALINK_RT3052)
  8042. + break;
  8043. + #endif
  8044. +#endif
  8045. + case I2S_DEBUG_CODECBYPASS:
  8046. + #if defined(CONFIG_I2S_TXRX)
  8047. + #if defined(CONFIG_RALINK_MT7628)
  8048. + data = i2s_inw(RALINK_SYSCTL_BASE+0x60);
  8049. + //data &= ~(0x3<<4);
  8050. + data &= ~(0x3<<6);
  8051. + data &= ~(0x3<<16);
  8052. + data &= ~(0x1<<14);
  8053. + i2s_outw(RALINK_SYSCTL_BASE+0x60, data);
  8054. +
  8055. + data = i2s_inw(RALINK_SYSCTL_BASE+0x2c);
  8056. + data &= ~(0x07<<9);
  8057. + i2s_outw(RALINK_SYSCTL_BASE+0x2c, data);
  8058. + #endif
  8059. +
  8060. + #if defined(CONFIG_I2S_WM8960) || defined(CONFIG_I2S_WM8750) || defined(CONFIG_I2S_WM8751)
  8061. + audiohw_bypass(); /* did not work */
  8062. + #endif
  8063. + #endif
  8064. + break;
  8065. + case I2S_DEBUG_FMT:
  8066. + break;
  8067. + case I2S_DEBUG_RESET:
  8068. + break;
  8069. +#if defined(CONFIG_I2S_WM8960)
  8070. + case I2S_DEBUG_CODEC_EXLBK:
  8071. + audiohw_codec_exlbk();
  8072. + break;
  8073. +#endif
  8074. + default:
  8075. + MSG("Not support this debug cmd [%d]\n", cmd);
  8076. + break;
  8077. + }
  8078. +
  8079. + return 0;
  8080. +}
  8081. --- a/sound/soc/codecs/wm8960.c
  8082. +++ b/sound/soc/codecs/wm8960.c
  8083. @@ -53,10 +53,10 @@
  8084. * using 2 wire for device control, so we cache them instead.
  8085. */
  8086. static const struct reg_default wm8960_reg_defaults[] = {
  8087. - { 0x0, 0x00a7 },
  8088. - { 0x1, 0x00a7 },
  8089. - { 0x2, 0x0000 },
  8090. - { 0x3, 0x0000 },
  8091. + { 0x0, 0x002b },
  8092. + { 0x1, 0x002b },
  8093. + { 0x2, 0x00ff },
  8094. + { 0x3, 0x00ff },
  8095. { 0x4, 0x0000 },
  8096. { 0x5, 0x0008 },
  8097. { 0x6, 0x0000 },
  8098. @@ -88,8 +88,8 @@ static const struct reg_default wm8960_r
  8099. { 0x25, 0x0050 },
  8100. { 0x26, 0x0000 },
  8101. { 0x27, 0x0000 },
  8102. - { 0x28, 0x0000 },
  8103. - { 0x29, 0x0000 },
  8104. + { 0x28, 0x007b },
  8105. + { 0x29, 0x007b },
  8106. { 0x2a, 0x0040 },
  8107. { 0x2b, 0x0000 },
  8108. { 0x2c, 0x0000 },
  8109. @@ -126,8 +126,7 @@ struct wm8960_priv {
  8110. bool deemph;
  8111. int playback_fs;
  8112. };
  8113. -
  8114. -#define wm8960_reset(c) snd_soc_write(c, WM8960_RESET, 0)
  8115. +static char init_mtk;
  8116. /* enumerated controls */
  8117. static const char *wm8960_polarity[] = {"No Inversion", "Left Inverted",
  8118. @@ -181,8 +180,8 @@ static int wm8960_get_deemph(struct snd_
  8119. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  8120. struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
  8121. - ucontrol->value.integer.value[0] = wm8960->deemph;
  8122. - return 0;
  8123. + //ucontrol->value.integer.value[0] = wm8960->deemph;
  8124. + return wm8960->deemph;
  8125. }
  8126. static int wm8960_put_deemph(struct snd_kcontrol *kcontrol,
  8127. @@ -200,6 +199,65 @@ static int wm8960_put_deemph(struct snd_
  8128. return wm8960_set_deemph(codec);
  8129. }
  8130. +static void wm8960_reset(struct snd_soc_codec *codec)
  8131. +{
  8132. + snd_soc_write(codec, WM8960_RESET, 0);
  8133. + init_mtk = false;
  8134. +}
  8135. +
  8136. +static int wm8960_init(struct snd_soc_codec *codec)
  8137. +{
  8138. + u32 data;
  8139. + // In
  8140. + data = snd_soc_read(codec, WM8960_POWER1);
  8141. + snd_soc_write(codec, WM8960_POWER1, data|WM8960_PWR1_ADCL|WM8960_PWR1_ADCR|WM8960_PWR1_AINL |WM8960_PWR1_AINR|WM8960_PWR1_MICB|WM8960_PWR1_VMIDSEL_5K|WM8960_PWR1_VREF);//0x19
  8142. + data = snd_soc_read(codec, WM8960_ADDCTL1);
  8143. + snd_soc_write(codec, WM8960_ADDCTL1, data|ADDITIONAL1_DATSEL(0x01));//0x17
  8144. + snd_soc_write(codec, WM8960_LADC, LEFTGAIN_LDVU|LEFTGAIN_LDACVOL(0xce));//0x15
  8145. + snd_soc_write(codec, WM8960_RADC, LEFTGAIN_LDVU|LEFTGAIN_LDACVOL(0xce));//0x16
  8146. + snd_soc_write(codec, WM8960_LINPATH, 0x168);//0x20
  8147. + snd_soc_write(codec, WM8960_RINPATH, 0x168);//0x21
  8148. + snd_soc_write(codec, WM8960_POWER3, WM8960_PWR3_LMIC|WM8960_PWR3_RMIC|WM8960_PWR3_ROMIX|WM8960_PWR3_LOMIX);//0x2f
  8149. +
  8150. + // Out
  8151. + data = snd_soc_read(codec, WM8960_POWER2);
  8152. + snd_soc_write(codec, WM8960_POWER2, data|WM8960_PWR2_DACL|WM8960_PWR2_DACR|WM8960_PWR2_LOUT1|WM8960_PWR2_ROUT1|WM8960_PWR2_SPKL|WM8960_PWR2_SPKR);//0x1a
  8153. + mdelay(10);
  8154. + snd_soc_write(codec, WM8960_IFACE2, 0x40);
  8155. + snd_soc_write(codec, WM8960_LDAC, LEFTGAIN_LDVU|LEFTGAIN_LDACVOL(0xff));//0x0a
  8156. + snd_soc_write(codec, WM8960_RDAC, RIGHTGAIN_RDVU|RIGHTGAIN_RDACVOL(0xff));//0x0b
  8157. + snd_soc_write(codec, WM8960_LOUTMIX, 0x100);//0x22
  8158. + snd_soc_write(codec, WM8960_ROUTMIX, 0x100);//0x25
  8159. +
  8160. + snd_soc_write(codec, WM8960_CLASSD1, 0xf7);//0x31
  8161. + snd_soc_write(codec, WM8960_CLASSD3, 0xad);//0x33
  8162. + snd_soc_write(codec, WM8960_DACCTL1, 0x000);//0x05
  8163. +
  8164. + snd_soc_write(codec, WM8960_LOUT1, LOUT1_LO1VU|LOUT1_LO1ZC|LOUT1_LOUT1VOL(120));//0x02
  8165. + snd_soc_write(codec, WM8960_ROUT1, ROUT1_RO1VU|ROUT1_RO1ZC|ROUT1_ROUT1VOL(120));//0x03
  8166. +
  8167. + data = snd_soc_read(codec, WM8960_LINVOL);
  8168. + data &= ~LINV_LINMUTE;
  8169. + snd_soc_write(codec, WM8960_LINVOL, data|LINV_IPVU|LINV_LINVOL(96));//LINV(0x00)
  8170. +
  8171. + data = snd_soc_read(codec, WM8960_RINVOL);
  8172. + data &= ~RINV_RINMUTE;
  8173. + snd_soc_write(codec, WM8960_RINVOL, data|RINV_IPVU|RINV_RINVOL(96)); //LINV(0x01)
  8174. +
  8175. + init_mtk = true;
  8176. + return 0;
  8177. +}
  8178. +
  8179. +static int wm8960_close(struct snd_soc_codec *codec)
  8180. +{
  8181. + snd_soc_write(codec, WM8960_DACCTL1,0x8); //0x05->0x08
  8182. + snd_soc_write(codec, WM8960_POWER1, 0x000); //0x19->0x000
  8183. + mdelay(300);
  8184. + snd_soc_write(codec, WM8960_POWER2, 0x000); //0x1a->0x000
  8185. +
  8186. + return 0;
  8187. +}
  8188. +
  8189. static const DECLARE_TLV_DB_SCALE(adc_tlv, -9700, 50, 0);
  8190. static const DECLARE_TLV_DB_SCALE(dac_tlv, -12700, 50, 1);
  8191. static const DECLARE_TLV_DB_SCALE(bypass_tlv, -2100, 300, 0);
  8192. @@ -542,6 +600,9 @@ static int wm8960_set_dai_fmt(struct snd
  8193. /* set iface */
  8194. snd_soc_write(codec, WM8960_IFACE1, iface);
  8195. + if (!init_mtk)
  8196. + wm8960_init(codec);
  8197. +
  8198. return 0;
  8199. }
  8200. @@ -623,11 +684,15 @@ static int wm8960_set_bias_level_out3(st
  8201. break;
  8202. case SND_SOC_BIAS_PREPARE:
  8203. +#if 0
  8204. /* Set VMID to 2x50k */
  8205. snd_soc_update_bits(codec, WM8960_POWER1, 0x180, 0x80);
  8206. +#endif
  8207. break;
  8208. case SND_SOC_BIAS_STANDBY:
  8209. +#if 0
  8210. +
  8211. if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
  8212. regcache_sync(wm8960->regmap);
  8213. @@ -650,9 +715,13 @@ static int wm8960_set_bias_level_out3(st
  8214. /* Set VMID to 2x250k */
  8215. snd_soc_update_bits(codec, WM8960_POWER1, 0x180, 0x100);
  8216. +#endif
  8217. break;
  8218. case SND_SOC_BIAS_OFF:
  8219. +#if 0
  8220. + wm8960_close(codec);
  8221. +
  8222. /* Enable anti-pop features */
  8223. snd_soc_write(codec, WM8960_APOP1,
  8224. WM8960_POBCTRL | WM8960_SOFT_ST |
  8225. @@ -661,6 +730,7 @@ static int wm8960_set_bias_level_out3(st
  8226. /* Disable VMID and VREF, let them discharge */
  8227. snd_soc_write(codec, WM8960_POWER1, 0);
  8228. msleep(600);
  8229. +#endif
  8230. break;
  8231. }
  8232. @@ -853,7 +923,6 @@ static int wm8960_set_dai_pll(struct snd
  8233. if (pll_div.k) {
  8234. reg |= 0x20;
  8235. -
  8236. snd_soc_write(codec, WM8960_PLL2, (pll_div.k >> 16) & 0xff);
  8237. snd_soc_write(codec, WM8960_PLL3, (pll_div.k >> 8) & 0xff);
  8238. snd_soc_write(codec, WM8960_PLL4, pll_div.k & 0xff);
  8239. @@ -962,7 +1031,7 @@ static int wm8960_probe(struct snd_soc_c
  8240. {
  8241. struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
  8242. struct wm8960_data *pdata = dev_get_platdata(codec->dev);
  8243. - int ret;
  8244. + int ret = 0;
  8245. wm8960->set_bias_level = wm8960_set_bias_level_out3;
  8246. @@ -973,26 +1042,9 @@ static int wm8960_probe(struct snd_soc_c
  8247. wm8960->set_bias_level = wm8960_set_bias_level_capless;
  8248. }
  8249. - ret = wm8960_reset(codec);
  8250. - if (ret < 0) {
  8251. - dev_err(codec->dev, "Failed to issue reset\n");
  8252. - return ret;
  8253. - }
  8254. -
  8255. - wm8960->set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  8256. -
  8257. - /* Latch the update bits */
  8258. - snd_soc_update_bits(codec, WM8960_LINVOL, 0x100, 0x100);
  8259. - snd_soc_update_bits(codec, WM8960_RINVOL, 0x100, 0x100);
  8260. - snd_soc_update_bits(codec, WM8960_LADC, 0x100, 0x100);
  8261. - snd_soc_update_bits(codec, WM8960_RADC, 0x100, 0x100);
  8262. - snd_soc_update_bits(codec, WM8960_LDAC, 0x100, 0x100);
  8263. - snd_soc_update_bits(codec, WM8960_RDAC, 0x100, 0x100);
  8264. - snd_soc_update_bits(codec, WM8960_LOUT1, 0x100, 0x100);
  8265. - snd_soc_update_bits(codec, WM8960_ROUT1, 0x100, 0x100);
  8266. - snd_soc_update_bits(codec, WM8960_LOUT2, 0x100, 0x100);
  8267. - snd_soc_update_bits(codec, WM8960_ROUT2, 0x100, 0x100);
  8268. -
  8269. + wm8960_reset(codec);
  8270. + //mdelay(400);
  8271. +
  8272. snd_soc_add_codec_controls(codec, wm8960_snd_controls,
  8273. ARRAY_SIZE(wm8960_snd_controls));
  8274. wm8960_add_widgets(codec);
  8275. --- a/sound/soc/codecs/wm8960.h
  8276. +++ b/sound/soc/codecs/wm8960.h
  8277. @@ -110,4 +110,68 @@
  8278. #define WM8960_OPCLK_DIV_5_5 (4 << 0)
  8279. #define WM8960_OPCLK_DIV_6 (5 << 0)
  8280. +/*
  8281. + * WM8960 Power management
  8282. + */
  8283. +#define WM8960_PWR1_VMIDSEL_DISABLED (0 << 7)
  8284. +#define WM8960_PWR1_VMIDSEL_50K (1 << 7)
  8285. +#define WM8960_PWR1_VMIDSEL_250K (2 << 7)
  8286. +#define WM8960_PWR1_VMIDSEL_5K (3 << 7)
  8287. +#define WM8960_PWR1_VREF (1 << 6)
  8288. +#define WM8960_PWR1_AINL (1 << 5)
  8289. +#define WM8960_PWR1_AINR (1 << 4)
  8290. +#define WM8960_PWR1_ADCL (1 << 3)
  8291. +#define WM8960_PWR1_ADCR (1 << 2)
  8292. +#define WM8960_PWR1_MICB (1 << 1)
  8293. +#define WM8960_PWR1_DIGENB (1 << 0)
  8294. +
  8295. +#define WM8960_PWR2_DACL (1 << 8)
  8296. +#define WM8960_PWR2_DACR (1 << 7)
  8297. +//#define WM8960_PWR2_LOUT1 (1 << 6)
  8298. +//#define WM8960_PWR2_ROUT1 (1 << 5)
  8299. +#define WM8960_PWR2_SPKL (1 << 4)
  8300. +#define WM8960_PWR2_SPKR (1 << 3)
  8301. +//#define WM8960_PWR2_OUT3 (1 << 1)
  8302. +#define WM8960_PWR2_PLL_EN (1 << 0)
  8303. +
  8304. +#define WM8960_PWR3_LMIC (1 << 5)
  8305. +#define WM8960_PWR3_RMIC (1 << 4)
  8306. +#define WM8960_PWR3_LOMIX (1 << 3)
  8307. +#define WM8960_PWR3_ROMIX (1 << 2)
  8308. +
  8309. +#define LEFTGAIN 0x0a
  8310. +#define LEFTGAIN_LDVU (1 << 8)
  8311. +#define LEFTGAIN_LDACVOL(x) ((x) & 0xff)
  8312. +
  8313. +#define RIGHTGAIN 0x0b
  8314. +#define RIGHTGAIN_RDVU (1 << 8)
  8315. +#define RIGHTGAIN_RDACVOL(x) ((x) & 0xff)
  8316. +
  8317. +#define ADDITIONAL1_DATSEL(x) (((x) & 0x3) << 2)
  8318. +
  8319. +#define AINTFCE1_WL_32 (3 << 2)
  8320. +#define AINTFCE1_WL_24 (2 << 2)
  8321. +#define AINTFCE1_WL_20 (1 << 2)
  8322. +#define AINTFCE1_WL_16 (0 << 2)
  8323. +#define AINTFCE1_FORMAT_I2S (2 << 0)
  8324. +
  8325. +#define LOUT1_LO1VU (1 << 8)
  8326. +#define LOUT1_LO1ZC (1 << 7)
  8327. +#define LOUT1_LOUT1VOL(x) ((x) & 0x7f)
  8328. +
  8329. +#define ROUT1_RO1VU (1 << 8)
  8330. +#define ROUT1_RO1ZC (1 << 7)
  8331. +#define ROUT1_ROUT1VOL(x) ((x) & 0x7f)
  8332. +
  8333. +#define LINV_IPVU (1 << 8) /* FIXME */
  8334. +
  8335. +#define LINV_LINMUTE (1 << 7)
  8336. +#define LINV_LIZC (1 << 6)
  8337. +#define LINV_LINVOL(x) ((x) & 0x3f)
  8338. +
  8339. +#define RINV_IPVU (1 << 8) /* FIXME */
  8340. +#define RINV_RINMUTE (1 << 7)
  8341. +#define RINV_RIZC (1 << 6)
  8342. +#define RINV_RINVOL(x) ((x) & 0x3f)
  8343. +#define MBSEL (1 << 0)
  8344. #endif