0014-MIPS-add-support-for-Lantiq-XWAY-SoCs.patch 216 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705
  1. From 11553b0de8992ded6240d034bd49f561d17bea53 Mon Sep 17 00:00:00 2001
  2. From: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
  3. Date: Thu, 13 Jun 2013 01:18:02 +0200
  4. Subject: MIPS: add support for Lantiq XWAY SoCs
  5. Signed-off-by: Luka Perkov <luka@openwrt.org>
  6. Signed-off-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
  7. --- a/.gitignore
  8. +++ b/.gitignore
  9. @@ -49,6 +49,13 @@
  10. /u-boot.sb
  11. /u-boot.bd
  12. /u-boot.geany
  13. +/u-boot.bin.lzma
  14. +/u-boot.bin.lzo
  15. +/u-boot.ltq.lzma.norspl
  16. +/u-boot.ltq.lzo.norspl
  17. +/u-boot.ltq.norspl
  18. +/u-boot.lzma.img
  19. +/u-boot.lzo.img
  20. #
  21. # Generated files
  22. --- a/Makefile
  23. +++ b/Makefile
  24. @@ -435,6 +435,12 @@ $(obj)u-boot.bin: $(obj)u-boot
  25. $(OBJCOPY) ${OBJCFLAGS} -O binary $< $@
  26. $(BOARD_SIZE_CHECK)
  27. +$(obj)u-boot.bin.lzma: $(obj)u-boot.bin
  28. + cat $< | lzma -9 -f - > $@
  29. +
  30. +$(obj)u-boot.bin.lzo: $(obj)u-boot.bin
  31. + cat $< | lzop -9 -f - > $@
  32. +
  33. $(obj)u-boot.ldr: $(obj)u-boot
  34. $(CREATE_LDR_ENV)
  35. $(LDR) -T $(CONFIG_BFIN_CPU) -c $@ $< $(LDR_FLAGS)
  36. @@ -454,13 +460,23 @@ ifndef CONFIG_SYS_UBOOT_START
  37. CONFIG_SYS_UBOOT_START := 0
  38. endif
  39. -$(obj)u-boot.img: $(obj)u-boot.bin
  40. - $(obj)tools/mkimage -A $(ARCH) -T firmware -C none \
  41. +define GEN_UBOOT_IMAGE
  42. + $(obj)tools/mkimage -A $(ARCH) -T firmware -C $(1) \
  43. -O u-boot -a $(CONFIG_SYS_TEXT_BASE) \
  44. -e $(CONFIG_SYS_UBOOT_START) \
  45. -n $(shell sed -n -e 's/.*U_BOOT_VERSION//p' $(VERSION_FILE) | \
  46. sed -e 's/"[ ]*$$/ for $(BOARD) board"/') \
  47. -d $< $@
  48. +endef
  49. +
  50. +$(obj)u-boot.img: $(obj)u-boot.bin
  51. + $(call GEN_UBOOT_IMAGE,none)
  52. +
  53. +$(obj)u-boot.lzma.img: $(obj)u-boot.bin.lzma
  54. + $(call GEN_UBOOT_IMAGE,lzma)
  55. +
  56. +$(obj)u-boot.lzo.img: $(obj)u-boot.bin.lzo
  57. + $(call GEN_UBOOT_IMAGE,lzo)
  58. $(obj)u-boot.imx: $(obj)u-boot.bin depend
  59. $(MAKE) -C $(SRCTREE)/arch/arm/imx-common $(OBJTREE)/u-boot.imx
  60. @@ -571,6 +587,27 @@ $(obj)u-boot-img-spl-at-end.bin: $(obj)s
  61. conv=notrunc 2>/dev/null
  62. cat $(obj)u-boot-pad.img $(obj)spl/u-boot-spl.bin > $@
  63. +$(obj)u-boot.ltq.sfspl: $(obj)u-boot.img $(obj)spl/u-boot-spl.bin
  64. + $(obj)tools/ltq-boot-image -t sfspl -e $(CONFIG_SPL_TEXT_BASE) \
  65. + -s $(obj)spl/u-boot-spl.bin -u $< -o $@
  66. +
  67. +$(obj)u-boot.ltq.lzo.sfspl: $(obj)u-boot.lzo.img $(obj)spl/u-boot-spl.bin
  68. + $(obj)tools/ltq-boot-image -t sfspl -e $(CONFIG_SPL_TEXT_BASE) \
  69. + -s $(obj)spl/u-boot-spl.bin -u $< -o $@
  70. +
  71. +$(obj)u-boot.ltq.lzma.sfspl: $(obj)u-boot.lzma.img $(obj)spl/u-boot-spl.bin
  72. + $(obj)tools/ltq-boot-image -t sfspl -e $(CONFIG_SPL_TEXT_BASE) \
  73. + -s $(obj)spl/u-boot-spl.bin -u $< -o $@
  74. +
  75. +$(obj)u-boot.ltq.norspl: $(obj)u-boot.img $(obj)spl/u-boot-spl.bin
  76. + cat $(obj)spl/u-boot-spl.bin $< > $@
  77. +
  78. +$(obj)u-boot.ltq.lzo.norspl: $(obj)u-boot.lzo.img $(obj)spl/u-boot-spl.bin
  79. + cat $(obj)spl/u-boot-spl.bin $< > $@
  80. +
  81. +$(obj)u-boot.ltq.lzma.norspl: $(obj)u-boot.lzma.img $(obj)spl/u-boot-spl.bin
  82. + cat $(obj)spl/u-boot-spl.bin $< > $@
  83. +
  84. ifeq ($(CONFIG_SANDBOX),y)
  85. GEN_UBOOT = \
  86. cd $(LNDIR) && $(CC) $(SYMS) -T $(obj)u-boot.lds \
  87. --- a/README
  88. +++ b/README
  89. @@ -468,6 +468,11 @@ The following options need to be configu
  90. CONF_CM_CACHABLE_CUW
  91. CONF_CM_CACHABLE_ACCELERATED
  92. + CONFIG_SYS_MIPS_CACHE_EXT_INIT
  93. +
  94. + Enable this to use extended cache initialization for recent
  95. + MIPS CPU cores.
  96. +
  97. CONFIG_SYS_XWAY_EBU_BOOTCFG
  98. Special option for Lantiq XWAY SoCs for booting from NOR flash.
  99. --- a/arch/mips/config.mk
  100. +++ b/arch/mips/config.mk
  101. @@ -45,9 +45,13 @@ PLATFORM_CPPFLAGS += -DCONFIG_MIPS -D__M
  102. # On the other hand, we want PIC in the U-Boot code to relocate it from ROM
  103. # to RAM. $28 is always used as gp.
  104. #
  105. -PLATFORM_CPPFLAGS += -G 0 -mabicalls -fpic $(ENDIANNESS)
  106. +PF_ABICALLS ?= -mabicalls
  107. +PF_PIC ?= -fpic
  108. +PF_PIE ?= -pie
  109. +
  110. +PLATFORM_CPPFLAGS += -G 0 $(PF_ABICALLS) $(PF_PIC) $(ENDIANNESS)
  111. PLATFORM_CPPFLAGS += -msoft-float
  112. PLATFORM_LDFLAGS += -G 0 -static -n -nostdlib $(ENDIANNESS)
  113. PLATFORM_RELFLAGS += -ffunction-sections -fdata-sections
  114. -LDFLAGS_FINAL += --gc-sections -pie
  115. +LDFLAGS_FINAL += --gc-sections $(PF_PIE)
  116. OBJCFLAGS += --remove-section=.dynsym
  117. --- a/arch/mips/cpu/mips32/cache.S
  118. +++ b/arch/mips/cpu/mips32/cache.S
  119. @@ -29,7 +29,11 @@
  120. */
  121. #define MIPS_MAX_CACHE_SIZE 0x10000
  122. +#ifdef CONFIG_SYS_MIPS_CACHE_EXT_INIT
  123. +#define INDEX_BASE 0x9fc00000
  124. +#else
  125. #define INDEX_BASE CKSEG0
  126. +#endif
  127. .macro cache_op op addr
  128. .set push
  129. @@ -65,7 +69,11 @@
  130. */
  131. LEAF(mips_init_icache)
  132. blez a1, 9f
  133. +#ifdef CONFIG_SYS_MIPS_CACHE_EXT_INIT
  134. + mtc0 zero, CP0_ITAGLO
  135. +#else
  136. mtc0 zero, CP0_TAGLO
  137. +#endif
  138. /* clear tag to invalidate */
  139. PTR_LI t0, INDEX_BASE
  140. PTR_ADDU t1, t0, a1
  141. @@ -90,7 +98,11 @@ LEAF(mips_init_icache)
  142. */
  143. LEAF(mips_init_dcache)
  144. blez a1, 9f
  145. +#ifdef CONFIG_SYS_MIPS_CACHE_EXT_INIT
  146. + mtc0 zero, CP0_DTAGLO
  147. +#else
  148. mtc0 zero, CP0_TAGLO
  149. +#endif
  150. /* clear all tags */
  151. PTR_LI t0, INDEX_BASE
  152. PTR_ADDU t1, t0, a1
  153. --- /dev/null
  154. +++ b/arch/mips/cpu/mips32/danube/Makefile
  155. @@ -0,0 +1,31 @@
  156. +#
  157. +# Copyright (C) 2000-2011 Wolfgang Denk, DENX Software Engineering, wd@denx.de
  158. +#
  159. +# SPDX-License-Identifier: GPL-2.0+
  160. +#
  161. +
  162. +include $(TOPDIR)/config.mk
  163. +
  164. +LIB = $(obj)lib$(SOC).o
  165. +
  166. +COBJS-y += cgu.o chipid.o ebu.o mem.o pmu.o rcu.o
  167. +SOBJS-y += cgu_init.o mem_init.o
  168. +
  169. +COBJS := $(COBJS-y)
  170. +SOBJS := $(SOBJS-y)
  171. +SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c)
  172. +OBJS := $(addprefix $(obj),$(SOBJS) $(COBJS))
  173. +
  174. +all: $(LIB)
  175. +
  176. +$(LIB): $(obj).depend $(OBJS)
  177. + $(call cmd_link_o_target, $(OBJS))
  178. +
  179. +#########################################################################
  180. +
  181. +# defines $(obj).depend target
  182. +include $(SRCTREE)/rules.mk
  183. +
  184. +sinclude $(obj).depend
  185. +
  186. +#########################################################################
  187. --- /dev/null
  188. +++ b/arch/mips/cpu/mips32/danube/cgu.c
  189. @@ -0,0 +1,117 @@
  190. +/*
  191. + * Copyright (C) 2007-2010 Lantiq Deutschland GmbH
  192. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  193. + *
  194. + * SPDX-License-Identifier: GPL-2.0+
  195. + */
  196. +
  197. +#include <common.h>
  198. +#include <asm/arch/soc.h>
  199. +#include <asm/lantiq/clk.h>
  200. +#include <asm/lantiq/io.h>
  201. +
  202. +#define LTQ_CGU_SYS_DDR_MASK 0x0003
  203. +#define LTQ_CGU_SYS_DDR_SHIFT 0
  204. +#define LTQ_CGU_SYS_CPU0_MASK 0x000C
  205. +#define LTQ_CGU_SYS_CPU0_SHIFT 2
  206. +#define LTQ_CGU_SYS_FPI_MASK 0x0040
  207. +#define LTQ_CGU_SYS_FPI_SHIFT 6
  208. +
  209. +struct ltq_cgu_regs {
  210. + u32 rsvd0;
  211. + u32 pll0_cfg; /* PLL0 config */
  212. + u32 pll1_cfg; /* PLL1 config */
  213. + u32 pll2_cfg; /* PLL2 config */
  214. + u32 sys; /* System clock */
  215. + u32 update; /* CGU update control */
  216. + u32 if_clk; /* Interface clock */
  217. + u32 osc_con; /* Update OSC Control */
  218. + u32 smd; /* SDRAM Memory Control */
  219. + u32 rsvd1[3];
  220. + u32 pcm_cr; /* PCM control */
  221. + u32 pci_cr; /* PCI clock control */
  222. +};
  223. +
  224. +static struct ltq_cgu_regs *ltq_cgu_regs =
  225. + (struct ltq_cgu_regs *) CKSEG1ADDR(LTQ_CGU_BASE);
  226. +
  227. +static inline u32 ltq_cgu_sys_readl(u32 mask, u32 shift)
  228. +{
  229. + return (ltq_readl(&ltq_cgu_regs->sys) & mask) >> shift;
  230. +}
  231. +
  232. +unsigned long ltq_get_io_region_clock(void)
  233. +{
  234. + u32 ddr_sel;
  235. + unsigned long clk;
  236. +
  237. + ddr_sel = ltq_cgu_sys_readl(LTQ_CGU_SYS_DDR_MASK,
  238. + LTQ_CGU_SYS_DDR_SHIFT);
  239. +
  240. + switch (ddr_sel) {
  241. + case 0:
  242. + clk = CLOCK_166_MHZ;
  243. + break;
  244. + case 1:
  245. + clk = CLOCK_133_MHZ;
  246. + break;
  247. + case 2:
  248. + clk = CLOCK_111_MHZ;
  249. + break;
  250. + case 3:
  251. + clk = CLOCK_83_MHZ;
  252. + break;
  253. + default:
  254. + clk = 0;
  255. + break;
  256. + }
  257. +
  258. + return clk;
  259. +}
  260. +
  261. +unsigned long ltq_get_cpu_clock(void)
  262. +{
  263. + u32 cpu0_sel;
  264. + unsigned long clk;
  265. +
  266. + cpu0_sel = ltq_cgu_sys_readl(LTQ_CGU_SYS_CPU0_MASK,
  267. + LTQ_CGU_SYS_CPU0_SHIFT);
  268. +
  269. + switch (cpu0_sel) {
  270. + /* Same as PLL0 output (333,33 MHz) */
  271. + case 0:
  272. + clk = CLOCK_333_MHZ;
  273. + break;
  274. + /* 1/1 fixed ratio to DDR clock */
  275. + case 1:
  276. + clk = ltq_get_io_region_clock();
  277. + break;
  278. + /* 1/2 fixed ratio to DDR clock */
  279. + case 2:
  280. + clk = ltq_get_io_region_clock() << 1;
  281. + break;
  282. + default:
  283. + clk = 0;
  284. + break;
  285. + }
  286. +
  287. + return clk;
  288. +}
  289. +
  290. +unsigned long ltq_get_bus_clock(void)
  291. +{
  292. + u32 fpi_sel;
  293. + unsigned long clk;
  294. +
  295. + fpi_sel = ltq_cgu_sys_readl(LTQ_CGU_SYS_FPI_MASK,
  296. + LTQ_CGU_SYS_FPI_SHIFT);
  297. +
  298. + if (fpi_sel)
  299. + /* Half the DDR clock */
  300. + clk = ltq_get_io_region_clock() >> 1;
  301. + else
  302. + /* Same as DDR clock */
  303. + clk = ltq_get_io_region_clock();
  304. +
  305. + return clk;
  306. +}
  307. --- /dev/null
  308. +++ b/arch/mips/cpu/mips32/danube/cgu_init.S
  309. @@ -0,0 +1,142 @@
  310. +/*
  311. + * Copyright (C) 2007-2010 Lantiq Deutschland GmbH
  312. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  313. + *
  314. + * SPDX-License-Identifier: GPL-2.0+
  315. + */
  316. +
  317. +#include <config.h>
  318. +#include <asm/asm.h>
  319. +#include <asm/regdef.h>
  320. +#include <asm/addrspace.h>
  321. +#include <asm/arch/soc.h>
  322. +
  323. +/* RCU module register */
  324. +#define LTQ_RCU_RST_REQ 0x0010
  325. +#define LTQ_RCU_RST_STAT 0x0014
  326. +#define LTQ_RCU_RST_REQ_VALUE 0x40000008
  327. +#define LTQ_RCU_RST_STAT_XTAL_F 0x20000
  328. +
  329. +/* CGU module register */
  330. +#define LTQ_CGU_PLL0_CFG 0x0004 /* PLL0 config */
  331. +#define LTQ_CGU_PLL1_CFG 0x0008 /* PLL1 config */
  332. +#define LTQ_CGU_PLL2_CFG 0x000C /* PLL2 config */
  333. +#define LTQ_CGU_SYS 0x0010 /* System clock */
  334. +
  335. +/* Valid SYS.CPU0/1 values */
  336. +#define LTQ_CGU_SYS_CPU0_SHIFT 2
  337. +#define LTQ_CGU_SYS_CPU1_SHIFT 4
  338. +#define LTQ_CGU_SYS_CPU_PLL0 0x0
  339. +#define LTQ_CGU_SYS_CPU_DDR_EQUAL 0x1
  340. +#define LTQ_CGU_SYS_CPU_DDR_TWICE 0x2
  341. +
  342. +/* Valid SYS.DDR values */
  343. +#define LTQ_CGU_SYS_DDR_SHIFT 0
  344. +#define LTQ_CGU_SYS_DDR_167_MHZ 0x0
  345. +#define LTQ_CGU_SYS_DDR_133_MHZ 0x1
  346. +#define LTQ_CGU_SYS_DDR_111_MHZ 0x2
  347. +#define LTQ_CGU_SYS_DDR_83_MHZ 0x3
  348. +
  349. +/* Valid SYS.FPI values */
  350. +#define LTQ_CGU_SYS_FPI_SHIFT 6
  351. +#define LTQ_CGU_SYS_FPI_DDR_EQUAL 0x0
  352. +#define LTQ_CGU_SYS_FPI_DDR_HALF 0x1
  353. +
  354. +/* Valid SYS.PPE values */
  355. +#define LTQ_CGU_SYS_PPE_SHIFT 7
  356. +#define LTQ_CGU_SYS_PPE_266_MHZ 0x0
  357. +#define LTQ_CGU_SYS_PPE_240_MHZ 0x1
  358. +#define LTQ_CGU_SYS_PPE_222_MHZ 0x2
  359. +#define LTQ_CGU_SYS_PPE_133_MHZ 0x3
  360. +
  361. +#if (CONFIG_SYS_CLOCK_MODE == LTQ_CLK_CPU_333_DDR_167)
  362. +#define LTQ_CGU_SYS_CPU_CONFIG LTQ_CGU_SYS_CPU_DDR_TWICE
  363. +#define LTQ_CGU_SYS_DDR_CONFIG LTQ_CGU_SYS_DDR_167_MHZ
  364. +#define LTQ_CGU_SYS_FPI_CONFIG LTQ_CGU_SYS_FPI_DDR_HALF
  365. +#define LTQ_CGU_SYS_PPE_CONFIG LTQ_CGU_SYS_PPE_266_MHZ
  366. +#elif (CONFIG_SYS_CLOCK_MODE == LTQ_CLK_CPU_111_DDR_111)
  367. +#define LTQ_CGU_SYS_CPU_CONFIG LTQ_CGU_SYS_CPU_DDR_EQUAL
  368. +#define LTQ_CGU_SYS_DDR_CONFIG LTQ_CGU_SYS_DDR_111_MHZ
  369. +#define LTQ_CGU_SYS_FPI_CONFIG LTQ_CGU_SYS_FPI_DDR_HALF
  370. +#define LTQ_CGU_SYS_PPE_CONFIG LTQ_CGU_SYS_PPE_133_MHZ
  371. +#else
  372. +#error "Invalid system clock configuration!"
  373. +#endif
  374. +
  375. +/* Build register values */
  376. +#define LTQ_CGU_SYS_VALUE ((LTQ_CGU_SYS_PPE_CONFIG << \
  377. + LTQ_CGU_SYS_PPE_SHIFT) | \
  378. + (LTQ_CGU_SYS_FPI_CONFIG << \
  379. + LTQ_CGU_SYS_FPI_SHIFT) | \
  380. + (LTQ_CGU_SYS_CPU_CONFIG << \
  381. + LTQ_CGU_SYS_CPU1_SHIFT) | \
  382. + (LTQ_CGU_SYS_CPU_CONFIG << \
  383. + LTQ_CGU_SYS_CPU0_SHIFT) | \
  384. + LTQ_CGU_SYS_DDR_CONFIG)
  385. +
  386. +/* Reset values for PLL registers for usage with 35.328 MHz crystal */
  387. +#define PLL0_35MHZ_CONFIG 0x9D861059
  388. +#define PLL1_35MHZ_CONFIG 0x1A260CD9
  389. +#define PLL2_35MHZ_CONFIG 0x8000f1e5
  390. +
  391. +/* Reset values for PLL registers for usage with 36 MHz crystal */
  392. +#define PLL0_36MHZ_CONFIG 0x1000125D
  393. +#define PLL1_36MHZ_CONFIG 0x1B1E0C99
  394. +#define PLL2_36MHZ_CONFIG 0x8002f2a1
  395. +
  396. +LEAF(ltq_cgu_init)
  397. + /* Load current CGU register value */
  398. + li t0, (LTQ_CGU_BASE | KSEG1)
  399. + lw t1, LTQ_CGU_SYS(t0)
  400. +
  401. + /* Load target CGU register values */
  402. + li t3, LTQ_CGU_SYS_VALUE
  403. +
  404. + /* Only update registers if values differ */
  405. + beq t1, t3, finished
  406. +
  407. + /*
  408. + * Check whether the XTAL_F bit in RST_STAT register is set or not.
  409. + * This bit is latched in via pin strapping. If bit is set then
  410. + * clock source is a 36 MHz crystal. Otherwise a 35.328 MHz crystal.
  411. + */
  412. + li t1, (LTQ_RCU_BASE | KSEG1)
  413. + lw t2, LTQ_RCU_RST_STAT(t1)
  414. + and t2, t2, LTQ_RCU_RST_STAT_XTAL_F
  415. + beq t2, LTQ_RCU_RST_STAT_XTAL_F, boot_36mhz
  416. +
  417. +boot_35mhz:
  418. + /* Configure PLL for 35.328 MHz */
  419. + li t2, PLL0_35MHZ_CONFIG
  420. + sw t2, LTQ_CGU_PLL0_CFG(t0)
  421. + li t2, PLL1_35MHZ_CONFIG
  422. + sw t2, LTQ_CGU_PLL1_CFG(t0)
  423. + li t2, PLL2_35MHZ_CONFIG
  424. + sw t2, LTQ_CGU_PLL2_CFG(t0)
  425. +
  426. + b do_reset
  427. +
  428. +boot_36mhz:
  429. + /* Configure PLL for 36 MHz */
  430. + li t2, PLL0_36MHZ_CONFIG
  431. + sw t2, LTQ_CGU_PLL0_CFG(t0)
  432. + li t2, PLL1_36MHZ_CONFIG
  433. + sw t2, LTQ_CGU_PLL1_CFG(t0)
  434. + li t2, PLL2_36MHZ_CONFIG
  435. + sw t2, LTQ_CGU_PLL2_CFG(t0)
  436. +
  437. +do_reset:
  438. + /* Store new clock config */
  439. + sw t3, LTQ_CGU_SYS(t0)
  440. +
  441. + /* Perform software reset to activate new clock config */
  442. + li t2, LTQ_RCU_RST_REQ_VALUE
  443. + sw t2, LTQ_RCU_RST_REQ(t1)
  444. +
  445. +wait_reset:
  446. + b wait_reset
  447. +
  448. +finished:
  449. + jr ra
  450. +
  451. + END(ltq_cgu_init)
  452. --- /dev/null
  453. +++ b/arch/mips/cpu/mips32/danube/chipid.c
  454. @@ -0,0 +1,59 @@
  455. +/*
  456. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  457. + *
  458. + * SPDX-License-Identifier: GPL-2.0+
  459. + */
  460. +
  461. +#include <common.h>
  462. +#include <asm/lantiq/io.h>
  463. +#include <asm/lantiq/chipid.h>
  464. +#include <asm/arch/soc.h>
  465. +
  466. +#define LTQ_CHIPID_VERSION_SHIFT 28
  467. +#define LTQ_CHIPID_VERSION_MASK (0xF << LTQ_CHIPID_VERSION_SHIFT)
  468. +#define LTQ_CHIPID_PNUM_SHIFT 12
  469. +#define LTQ_CHIPID_PNUM_MASK (0xFFFF << LTQ_CHIPID_PNUM_SHIFT)
  470. +
  471. +struct ltq_chipid_regs {
  472. + u32 manid; /* Manufacturer identification */
  473. + u32 chipid; /* Chip identification */
  474. +};
  475. +
  476. +static struct ltq_chipid_regs *ltq_chipid_regs =
  477. + (struct ltq_chipid_regs *) CKSEG1ADDR(LTQ_CHIPID_BASE);
  478. +
  479. +unsigned int ltq_chip_version_get(void)
  480. +{
  481. + u32 chipid;
  482. +
  483. + chipid = ltq_readl(&ltq_chipid_regs->chipid);
  484. +
  485. + return (chipid & LTQ_CHIPID_VERSION_MASK) >> LTQ_CHIPID_VERSION_SHIFT;
  486. +}
  487. +
  488. +unsigned int ltq_chip_partnum_get(void)
  489. +{
  490. + u32 chipid;
  491. +
  492. + chipid = ltq_readl(&ltq_chipid_regs->chipid);
  493. +
  494. + return (chipid & LTQ_CHIPID_PNUM_MASK) >> LTQ_CHIPID_PNUM_SHIFT;
  495. +}
  496. +
  497. +const char *ltq_chip_partnum_str(void)
  498. +{
  499. + enum ltq_chip_partnum partnum = ltq_chip_partnum_get();
  500. +
  501. + switch (partnum) {
  502. + case LTQ_SOC_DANUBE:
  503. + return "Danube";
  504. + case LTQ_SOC_DANUBE_S:
  505. + return "Danube-S";
  506. + case LTQ_SOC_TWINPASS:
  507. + return "Twinpass";
  508. + default:
  509. + printf("Unknown partnum: %x\n", partnum);
  510. + }
  511. +
  512. + return "";
  513. +}
  514. --- /dev/null
  515. +++ b/arch/mips/cpu/mips32/danube/config.mk
  516. @@ -0,0 +1,25 @@
  517. +#
  518. +# Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  519. +#
  520. +# SPDX-License-Identifier: GPL-2.0+
  521. +#
  522. +
  523. +PF_CPPFLAGS_DANUBE := $(call cc-option,-mtune=24kec,)
  524. +PLATFORM_CPPFLAGS += $(PF_CPPFLAGS_DANUBE)
  525. +
  526. +ifdef CONFIG_SPL_BUILD
  527. +PF_ABICALLS := -mno-abicalls
  528. +PF_PIC := -fno-pic
  529. +PF_PIE :=
  530. +USE_PRIVATE_LIBGCC := yes
  531. +endif
  532. +
  533. +LIBS-y += $(CPUDIR)/lantiq-common/liblantiq-common.o
  534. +
  535. +ifndef CONFIG_SPL_BUILD
  536. +ifdef CONFIG_SYS_BOOT_NORSPL
  537. +ALL-y += $(obj)u-boot.ltq.norspl
  538. +ALL-$(CONFIG_SPL_LZO_SUPPORT) += $(obj)u-boot.ltq.lzo.norspl
  539. +ALL-$(CONFIG_SPL_LZMA_SUPPORT) += $(obj)u-boot.ltq.lzma.norspl
  540. +endif
  541. +endif
  542. --- /dev/null
  543. +++ b/arch/mips/cpu/mips32/danube/ebu.c
  544. @@ -0,0 +1,105 @@
  545. +/*
  546. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  547. + *
  548. + * SPDX-License-Identifier: GPL-2.0+
  549. + */
  550. +
  551. +#include <common.h>
  552. +#include <asm/arch/soc.h>
  553. +#include <asm/lantiq/io.h>
  554. +
  555. +#define EBU_ADDRSEL_MASK(mask) ((mask & 0xf) << 4)
  556. +#define EBU_ADDRSEL_REGEN (1 << 0)
  557. +
  558. +#define EBU_CON_WRDIS (1 << 31)
  559. +#define EBU_CON_AGEN_DEMUX (0x0 << 24)
  560. +#define EBU_CON_AGEN_MUX (0x2 << 24)
  561. +#define EBU_CON_SETUP (1 << 22)
  562. +#define EBU_CON_WAIT_DIS (0x0 << 20)
  563. +#define EBU_CON_WAIT_ASYNC (0x1 << 20)
  564. +#define EBU_CON_WAIT_SYNC (0x2 << 20)
  565. +#define EBU_CON_WINV (1 << 19)
  566. +#define EBU_CON_PW_8BIT (0x0 << 16)
  567. +#define EBU_CON_PW_16BIT (0x1 << 16)
  568. +#define EBU_CON_ALEC(cycles) ((cycles & 0x3) << 14)
  569. +#define EBU_CON_BCGEN_CS (0x0 << 12)
  570. +#define EBU_CON_BCGEN_INTEL (0x1 << 12)
  571. +#define EBU_CON_BCGEN_MOTOROLA (0x2 << 12)
  572. +#define EBU_CON_WAITWRC(cycles) ((cycles & 0x7) << 8)
  573. +#define EBU_CON_WAITRDC(cycles) ((cycles & 0x3) << 6)
  574. +#define EBU_CON_HOLDC(cycles) ((cycles & 0x3) << 4)
  575. +#define EBU_CON_RECOVC(cycles) ((cycles & 0x3) << 2)
  576. +#define EBU_CON_CMULT_1 0x0
  577. +#define EBU_CON_CMULT_4 0x1
  578. +#define EBU_CON_CMULT_8 0x2
  579. +#define EBU_CON_CMULT_16 0x3
  580. +
  581. +#if defined(CONFIG_LTQ_SUPPORT_NOR_FLASH)
  582. +#define ebu_region0_enable 1
  583. +#else
  584. +#define ebu_region0_enable 0
  585. +#endif
  586. +
  587. +#if defined(CONFIG_LTQ_SUPPORT_NAND_FLASH)
  588. +#define ebu_region1_enable 1
  589. +#else
  590. +#define ebu_region1_enable 0
  591. +#endif
  592. +
  593. +struct ltq_ebu_regs {
  594. + u32 clc;
  595. + u32 rsvd0[3];
  596. + u32 con;
  597. + u32 rsvd1[3];
  598. + u32 addr_sel_0;
  599. + u32 addr_sel_1;
  600. + u32 rsvd2[14];
  601. + u32 con_0;
  602. + u32 con_1;
  603. +};
  604. +
  605. +static struct ltq_ebu_regs *ltq_ebu_regs =
  606. + (struct ltq_ebu_regs *) CKSEG1ADDR(LTQ_EBU_BASE);
  607. +
  608. +void ltq_ebu_init(void)
  609. +{
  610. + if (ebu_region0_enable) {
  611. + /*
  612. + * Map EBU region 0 to range 0x10000000-0x13ffffff and enable
  613. + * region control. This supports up to 32 MiB NOR flash in
  614. + * bank 0.
  615. + */
  616. + ltq_writel(&ltq_ebu_regs->addr_sel_0, LTQ_EBU_REGION0_BASE |
  617. + EBU_ADDRSEL_MASK(1) | EBU_ADDRSEL_REGEN);
  618. +
  619. + ltq_writel(&ltq_ebu_regs->con_0, EBU_CON_AGEN_DEMUX |
  620. + EBU_CON_WAIT_DIS | EBU_CON_PW_16BIT |
  621. + EBU_CON_ALEC(3) | EBU_CON_BCGEN_INTEL |
  622. + EBU_CON_WAITWRC(7) | EBU_CON_WAITRDC(3) |
  623. + EBU_CON_HOLDC(3) | EBU_CON_RECOVC(3) |
  624. + EBU_CON_CMULT_16);
  625. + } else
  626. + ltq_clrbits(&ltq_ebu_regs->addr_sel_0, EBU_ADDRSEL_REGEN);
  627. +
  628. + if (ebu_region1_enable) {
  629. + /*
  630. + * Map EBU region 1 to range 0x14000000-0x13ffffff and enable
  631. + * region control. This supports NAND flash in bank 1.
  632. + */
  633. + ltq_writel(&ltq_ebu_regs->addr_sel_1, LTQ_EBU_REGION1_BASE |
  634. + EBU_ADDRSEL_MASK(3) | EBU_ADDRSEL_REGEN);
  635. +
  636. + ltq_writel(&ltq_ebu_regs->con_1, EBU_CON_AGEN_DEMUX |
  637. + EBU_CON_SETUP | EBU_CON_WAIT_DIS | EBU_CON_PW_8BIT |
  638. + EBU_CON_ALEC(3) | EBU_CON_BCGEN_INTEL |
  639. + EBU_CON_WAITWRC(2) | EBU_CON_WAITRDC(2) |
  640. + EBU_CON_HOLDC(1) | EBU_CON_RECOVC(1) |
  641. + EBU_CON_CMULT_4);
  642. + } else
  643. + ltq_clrbits(&ltq_ebu_regs->addr_sel_1, EBU_ADDRSEL_REGEN);
  644. +}
  645. +
  646. +void *flash_swap_addr(unsigned long addr)
  647. +{
  648. + return (void *)(addr ^ 2);
  649. +}
  650. --- /dev/null
  651. +++ b/arch/mips/cpu/mips32/danube/mem.c
  652. @@ -0,0 +1,30 @@
  653. +/*
  654. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  655. + *
  656. + * SPDX-License-Identifier: GPL-2.0+
  657. + */
  658. +
  659. +#include <common.h>
  660. +#include <asm/arch/soc.h>
  661. +#include <asm/lantiq/io.h>
  662. +
  663. +static void *ltq_mc_ddr_base = (void *) CKSEG1ADDR(LTQ_MC_DDR_BASE);
  664. +
  665. +static inline u32 ltq_mc_dc_read(u32 index)
  666. +{
  667. + return ltq_readl(ltq_mc_ddr_base + LTQ_MC_DDR_DC_OFFSET(index));
  668. +}
  669. +
  670. +phys_size_t initdram(int board_type)
  671. +{
  672. + u32 col, row, dc04, dc19, dc20;
  673. +
  674. + dc04 = ltq_mc_dc_read(4);
  675. + dc19 = ltq_mc_dc_read(19);
  676. + dc20 = ltq_mc_dc_read(20);
  677. +
  678. + row = (dc04 & 0xF) - ((dc19 & 0x700) >> 8);
  679. + col = ((dc04 & 0xF00) >> 8) - (dc20 & 0x7);
  680. +
  681. + return (1 << (row + col)) * 4 * 2;
  682. +}
  683. --- /dev/null
  684. +++ b/arch/mips/cpu/mips32/danube/mem_init.S
  685. @@ -0,0 +1,114 @@
  686. +/*
  687. + * Copyright (C) 2007-2010 Lantiq Deutschland GmbH
  688. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  689. + *
  690. + * SPDX-License-Identifier: GPL-2.0+
  691. + */
  692. +
  693. +#include <config.h>
  694. +#include <asm/asm.h>
  695. +#include <asm/regdef.h>
  696. +#include <asm/addrspace.h>
  697. +#include <asm/arch/soc.h>
  698. +
  699. +/* Must be configured in BOARDDIR */
  700. +#include <ddr_settings.h>
  701. +
  702. +#define LTQ_MC_GEN_ERRCAUSE 0x0010
  703. +#define LTQ_MC_GEN_ERRADDR 0x0020
  704. +#define LTQ_MC_GEN_CON 0x0060
  705. +#define LTQ_MC_GEN_STAT 0x0070
  706. +#define LTQ_MC_GEN_CON_SRAM_DDR_ENABLE 0x5
  707. +#define LTQ_MC_GEN_STAT_DLCK_PWRON 0xC
  708. +
  709. +#define LTQ_MC_DDR_DC03_MC_START 0x100
  710. +
  711. + /* Store given value in MC DDR CCRx register */
  712. + .macro dc_sw num, val
  713. + li t2, \val
  714. + sw t2, LTQ_MC_DDR_DC_OFFSET(\num)(t1)
  715. + .endm
  716. +
  717. +LEAF(ltq_mem_init)
  718. + /* Load MC General and MC DDR module base */
  719. + li t0, (LTQ_MC_GEN_BASE | KSEG1)
  720. + li t1, (LTQ_MC_DDR_BASE | KSEG1)
  721. +
  722. + /* Clear access error log registers */
  723. + sw zero, LTQ_MC_GEN_ERRCAUSE(t0)
  724. + sw zero, LTQ_MC_GEN_ERRADDR(t0)
  725. +
  726. + /* Enable DDR and SRAM module in memory controller */
  727. + li t2, LTQ_MC_GEN_CON_SRAM_DDR_ENABLE
  728. + sw t2, LTQ_MC_GEN_CON(t0)
  729. +
  730. + /* Clear start bit of DDR memory controller */
  731. + sw zero, LTQ_MC_DDR_DC_OFFSET(3)(t1)
  732. +
  733. + /* Init memory controller registers with values ddr_settings.h */
  734. + dc_sw 0, MC_DC00_VALUE
  735. + dc_sw 1, MC_DC01_VALUE
  736. + dc_sw 2, MC_DC02_VALUE
  737. + dc_sw 4, MC_DC04_VALUE
  738. + dc_sw 5, MC_DC05_VALUE
  739. + dc_sw 6, MC_DC06_VALUE
  740. + dc_sw 7, MC_DC07_VALUE
  741. + dc_sw 8, MC_DC08_VALUE
  742. + dc_sw 9, MC_DC09_VALUE
  743. +
  744. + dc_sw 10, MC_DC10_VALUE
  745. + dc_sw 11, MC_DC11_VALUE
  746. + dc_sw 12, MC_DC12_VALUE
  747. + dc_sw 13, MC_DC13_VALUE
  748. + dc_sw 14, MC_DC14_VALUE
  749. + dc_sw 15, MC_DC15_VALUE
  750. + dc_sw 16, MC_DC16_VALUE
  751. + dc_sw 17, MC_DC17_VALUE
  752. + dc_sw 18, MC_DC18_VALUE
  753. + dc_sw 19, MC_DC19_VALUE
  754. +
  755. + dc_sw 20, MC_DC20_VALUE
  756. + dc_sw 21, MC_DC21_VALUE
  757. + dc_sw 22, MC_DC22_VALUE
  758. + dc_sw 23, MC_DC23_VALUE
  759. + dc_sw 24, MC_DC24_VALUE
  760. + dc_sw 25, MC_DC25_VALUE
  761. + dc_sw 26, MC_DC26_VALUE
  762. + dc_sw 27, MC_DC27_VALUE
  763. + dc_sw 28, MC_DC28_VALUE
  764. + dc_sw 29, MC_DC29_VALUE
  765. +
  766. + dc_sw 30, MC_DC30_VALUE
  767. + dc_sw 31, MC_DC31_VALUE
  768. + dc_sw 32, MC_DC32_VALUE
  769. + dc_sw 33, MC_DC33_VALUE
  770. + dc_sw 34, MC_DC34_VALUE
  771. + dc_sw 35, MC_DC35_VALUE
  772. + dc_sw 36, MC_DC36_VALUE
  773. + dc_sw 37, MC_DC37_VALUE
  774. + dc_sw 38, MC_DC38_VALUE
  775. + dc_sw 39, MC_DC39_VALUE
  776. +
  777. + dc_sw 40, MC_DC40_VALUE
  778. + dc_sw 41, MC_DC41_VALUE
  779. + dc_sw 42, MC_DC42_VALUE
  780. + dc_sw 43, MC_DC43_VALUE
  781. + dc_sw 44, MC_DC44_VALUE
  782. + dc_sw 45, MC_DC45_VALUE
  783. + dc_sw 46, MC_DC46_VALUE
  784. +
  785. + /* Set start bit of DDR memory controller */
  786. + li t2, LTQ_MC_DDR_DC03_MC_START
  787. + sw t2, LTQ_MC_DDR_DC_OFFSET(3)(t1)
  788. +
  789. + /* Wait until DLL has locked and core is ready for data transfers */
  790. +wait_ready:
  791. + lw t2, LTQ_MC_GEN_STAT(t0)
  792. + li t3, LTQ_MC_GEN_STAT_DLCK_PWRON
  793. + and t2, t3
  794. + bne t2, t3, wait_ready
  795. +
  796. +finished:
  797. + jr ra
  798. +
  799. + END(ltq_mem_init)
  800. --- /dev/null
  801. +++ b/arch/mips/cpu/mips32/danube/pmu.c
  802. @@ -0,0 +1,117 @@
  803. +/*
  804. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  805. + *
  806. + * SPDX-License-Identifier: GPL-2.0+
  807. + */
  808. +
  809. +#include <common.h>
  810. +#include <asm/lantiq/io.h>
  811. +#include <asm/lantiq/pm.h>
  812. +#include <asm/arch/soc.h>
  813. +
  814. +#define LTQ_PMU_PWDCR_RESERVED 0xFD0C001C
  815. +
  816. +#define LTQ_PMU_PWDCR_TDM (1 << 25)
  817. +#define LTQ_PMU_PWDCR_PPE_ENET0 (1 << 23)
  818. +#define LTQ_PMU_PWDCR_PPE_ENET1 (1 << 22)
  819. +#define LTQ_PMU_PWDCR_PPE_TC (1 << 21)
  820. +#define LTQ_PMU_PWDCR_DEU (1 << 20)
  821. +#define LTQ_PMU_PWDCR_UART1 (1 << 17)
  822. +#define LTQ_PMU_PWDCR_SDIO (1 << 16)
  823. +#define LTQ_PMU_PWDCR_AHB (1 << 15)
  824. +#define LTQ_PMU_PWDCR_FPI0 (1 << 14)
  825. +#define LTQ_PMU_PWDCR_PPE (1 << 13)
  826. +#define LTQ_PMU_PWDCR_GPTC (1 << 12)
  827. +#define LTQ_PMU_PWDCR_LEDC (1 << 11)
  828. +#define LTQ_PMU_PWDCR_EBU (1 << 10)
  829. +#define LTQ_PMU_PWDCR_DSL (1 << 9)
  830. +#define LTQ_PMU_PWDCR_SPI (1 << 8)
  831. +#define LTQ_PMU_PWDCR_UART0 (1 << 7)
  832. +#define LTQ_PMU_PWDCR_USB (1 << 6)
  833. +#define LTQ_PMU_PWDCR_DMA (1 << 5)
  834. +#define LTQ_PMU_PWDCR_FPI1 (1 << 1)
  835. +#define LTQ_PMU_PWDCR_USB_PHY (1 << 0)
  836. +
  837. +struct ltq_pmu_regs {
  838. + u32 rsvd0[7];
  839. + u32 pwdcr;
  840. + u32 sr;
  841. + u32 pwdcr1;
  842. + u32 sr1;
  843. +};
  844. +
  845. +static struct ltq_pmu_regs *ltq_pmu_regs =
  846. + (struct ltq_pmu_regs *) CKSEG1ADDR(LTQ_PMU_BASE);
  847. +
  848. +u32 ltq_pm_map(enum ltq_pm_modules module)
  849. +{
  850. + u32 val;
  851. +
  852. + switch (module) {
  853. + case LTQ_PM_CORE:
  854. + val = LTQ_PMU_PWDCR_UART1 | LTQ_PMU_PWDCR_FPI0 |
  855. + LTQ_PMU_PWDCR_LEDC | LTQ_PMU_PWDCR_EBU;
  856. + break;
  857. + case LTQ_PM_DMA:
  858. + val = LTQ_PMU_PWDCR_DMA;
  859. + break;
  860. + case LTQ_PM_ETH:
  861. + val = LTQ_PMU_PWDCR_PPE_ENET0 | LTQ_PMU_PWDCR_PPE_TC |
  862. + LTQ_PMU_PWDCR_PPE;
  863. + break;
  864. + case LTQ_PM_SPI:
  865. + val = LTQ_PMU_PWDCR_SPI;
  866. + break;
  867. + default:
  868. + val = 0;
  869. + break;
  870. + }
  871. +
  872. + return val;
  873. +}
  874. +
  875. +int ltq_pm_enable(enum ltq_pm_modules module)
  876. +{
  877. + const unsigned long timeout = 1000;
  878. + unsigned long timebase;
  879. + u32 sr, val;
  880. +
  881. + val = ltq_pm_map(module);
  882. + if (unlikely(!val))
  883. + return 1;
  884. +
  885. + ltq_clrbits(&ltq_pmu_regs->pwdcr, val);
  886. +
  887. + timebase = get_timer(0);
  888. +
  889. + do {
  890. + sr = ltq_readl(&ltq_pmu_regs->sr);
  891. + if (~sr & val)
  892. + return 0;
  893. + } while (get_timer(timebase) < timeout);
  894. +
  895. + return 1;
  896. +}
  897. +
  898. +int ltq_pm_disable(enum ltq_pm_modules module)
  899. +{
  900. + u32 val;
  901. +
  902. + val = ltq_pm_map(module);
  903. + if (unlikely(!val))
  904. + return 1;
  905. +
  906. + ltq_setbits(&ltq_pmu_regs->pwdcr, val);
  907. +
  908. + return 0;
  909. +}
  910. +
  911. +void ltq_pmu_init(void)
  912. +{
  913. + u32 set, clr;
  914. +
  915. + clr = ltq_pm_map(LTQ_PM_CORE);
  916. + set = ~(LTQ_PMU_PWDCR_RESERVED | clr);
  917. +
  918. + ltq_clrsetbits(&ltq_pmu_regs->pwdcr, clr, set);
  919. +}
  920. --- /dev/null
  921. +++ b/arch/mips/cpu/mips32/danube/rcu.c
  922. @@ -0,0 +1,125 @@
  923. +/*
  924. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  925. + *
  926. + * SPDX-License-Identifier: GPL-2.0+
  927. + */
  928. +
  929. +#include <common.h>
  930. +#include <asm/lantiq/io.h>
  931. +#include <asm/lantiq/reset.h>
  932. +#include <asm/lantiq/cpu.h>
  933. +#include <asm/arch/soc.h>
  934. +
  935. +#define LTQ_RCU_RD_SRST (1 << 30) /* Global SW Reset */
  936. +#define LTQ_RCU_RD_MC (1 << 14) /* Memory Controller */
  937. +#define LTQ_RCU_RD_PCI (1 << 13) /* PCI core */
  938. +#define LTQ_RCU_RD_DFE_AFE (1 << 12) /* Voice DFE/AFE */
  939. +#define LTQ_RCU_RD_DSL_AFE (1 << 11) /* DSL AFE */
  940. +#define LTQ_RCU_RD_SDIO (1 << 10) /* SDIO core */
  941. +#define LTQ_RCU_RD_DMA (1 << 9) /* DMA core */
  942. +#define LTQ_RCU_RD_PPE (1 << 8) /* PPE core */
  943. +#define LTQ_RCU_RD_ARC_DFE (1 << 7) /* ARC/DFE core */
  944. +#define LTQ_RCU_RD_AHB (1 << 6) /* AHB bus */
  945. +#define LTQ_RCU_RD_ENET_MAC1 (1 << 5) /* Ethernet MAC1 */
  946. +#define LTQ_RCU_RD_USB (1 << 4) /* USB and Phy core */
  947. +#define LTQ_RCU_RD_CPU1 (1 << 3) /* CPU1 subsystem */
  948. +#define LTQ_RCU_RD_FPI (1 << 2) /* FPI bus */
  949. +#define LTQ_RCU_RD_CPU0 (1 << 1) /* CPU0 subsystem */
  950. +#define LTQ_RCU_RD_HRST (1 << 0) /* HW reset via HRST pin */
  951. +
  952. +#define LTQ_RCU_STAT_BOOT_SHIFT 18
  953. +#define LTQ_RCU_STAT_BOOT_MASK (0x7 << LTQ_RCU_STAT_BOOT_SHIFT)
  954. +
  955. +struct ltq_rcu_regs {
  956. + u32 rsvd0[4];
  957. + u32 req; /* Reset request */
  958. + u32 stat; /* Reset status */
  959. + u32 usb_cfg; /* USB configure */
  960. + u32 rsvd1[2];
  961. + u32 pci_rdy; /* PCI boot ready */
  962. +};
  963. +
  964. +static struct ltq_rcu_regs *ltq_rcu_regs =
  965. + (struct ltq_rcu_regs *) CKSEG1ADDR(LTQ_RCU_BASE);
  966. +
  967. +u32 ltq_reset_map(enum ltq_reset_modules module)
  968. +{
  969. + u32 val;
  970. +
  971. + switch (module) {
  972. + case LTQ_RESET_CORE:
  973. + case LTQ_RESET_SOFT:
  974. + val = LTQ_RCU_RD_SRST | LTQ_RCU_RD_CPU1;
  975. + break;
  976. + case LTQ_RESET_DMA:
  977. + val = LTQ_RCU_RD_DMA;
  978. + break;
  979. + case LTQ_RESET_ETH:
  980. + val = LTQ_RCU_RD_PPE;
  981. + break;
  982. + case LTQ_RESET_HARD:
  983. + val = LTQ_RCU_RD_HRST;
  984. + break;
  985. + default:
  986. + val = 0;
  987. + break;
  988. + }
  989. +
  990. + return val;
  991. +}
  992. +
  993. +int ltq_reset_activate(enum ltq_reset_modules module)
  994. +{
  995. + u32 val;
  996. +
  997. + val = ltq_reset_map(module);
  998. + if (unlikely(!val))
  999. + return 1;
  1000. +
  1001. + ltq_setbits(&ltq_rcu_regs->req, val);
  1002. +
  1003. + return 0;
  1004. +}
  1005. +
  1006. +int ltq_reset_deactivate(enum ltq_reset_modules module)
  1007. +{
  1008. + u32 val;
  1009. +
  1010. + val = ltq_reset_map(module);
  1011. + if (unlikely(!val))
  1012. + return 1;
  1013. +
  1014. + ltq_clrbits(&ltq_rcu_regs->req, val);
  1015. +
  1016. + return 0;
  1017. +}
  1018. +
  1019. +enum ltq_boot_select ltq_boot_select(void)
  1020. +{
  1021. + u32 stat;
  1022. + unsigned int bootstrap;
  1023. +
  1024. + stat = ltq_readl(&ltq_rcu_regs->stat);
  1025. + bootstrap = (stat & LTQ_RCU_STAT_BOOT_MASK) >> LTQ_RCU_STAT_BOOT_SHIFT;
  1026. +
  1027. + switch (bootstrap) {
  1028. + case 0:
  1029. + return BOOT_NOR_NO_BOOTROM;
  1030. + case 1:
  1031. + return BOOT_NOR;
  1032. + case 2:
  1033. + return BOOT_MII0;
  1034. + case 3:
  1035. + return BOOT_PCI;
  1036. + case 4:
  1037. + return BOOT_UART;
  1038. + case 5:
  1039. + return BOOT_SPI;
  1040. + case 6:
  1041. + return BOOT_NAND;
  1042. + case 7:
  1043. + return BOOT_RMII0;
  1044. + default:
  1045. + return BOOT_UNKNOWN;
  1046. + }
  1047. +}
  1048. --- /dev/null
  1049. +++ b/arch/mips/cpu/mips32/lantiq-common/Makefile
  1050. @@ -0,0 +1,34 @@
  1051. +#
  1052. +# Copyright (C) 2000-2011 Wolfgang Denk, DENX Software Engineering, wd@denx.de
  1053. +#
  1054. +# SPDX-License-Identifier: GPL-2.0+
  1055. +#
  1056. +
  1057. +include $(TOPDIR)/config.mk
  1058. +
  1059. +LIB = $(obj)liblantiq-common.o
  1060. +
  1061. +START = start.o
  1062. +COBJS-y = cpu.o pmu.o
  1063. +COBJS-$(CONFIG_SPL_BUILD) += spl.o
  1064. +SOBJS-y = lowlevel_init.o
  1065. +
  1066. +COBJS := $(COBJS-y)
  1067. +SOBJS := $(SOBJS-y)
  1068. +SRCS := $(START:.o=.S) $(SOBJS:.o=.S) $(COBJS:.o=.c)
  1069. +OBJS := $(addprefix $(obj),$(SOBJS) $(COBJS))
  1070. +START := $(addprefix $(obj),$(START))
  1071. +
  1072. +all: $(LIB)
  1073. +
  1074. +$(LIB): $(obj).depend $(OBJS)
  1075. + $(call cmd_link_o_target, $(OBJS))
  1076. +
  1077. +#########################################################################
  1078. +
  1079. +# defines $(obj).depend target
  1080. +include $(SRCTREE)/rules.mk
  1081. +
  1082. +sinclude $(obj).depend
  1083. +
  1084. +#########################################################################
  1085. --- /dev/null
  1086. +++ b/arch/mips/cpu/mips32/lantiq-common/cpu.c
  1087. @@ -0,0 +1,59 @@
  1088. +/*
  1089. + * Copyright (C) 2012-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  1090. + *
  1091. + * SPDX-License-Identifier: GPL-2.0+
  1092. + */
  1093. +
  1094. +#include <common.h>
  1095. +#include <asm/lantiq/chipid.h>
  1096. +#include <asm/lantiq/clk.h>
  1097. +#include <asm/lantiq/reset.h>
  1098. +#include <asm/lantiq/cpu.h>
  1099. +
  1100. +static const char ltq_bootsel_strings[][16] = {
  1101. + "NOR",
  1102. + "NOR w/o BootROM",
  1103. + "UART",
  1104. + "UART w/o EEPROM",
  1105. + "SPI",
  1106. + "NAND",
  1107. + "PCI",
  1108. + "MII0",
  1109. + "RMII0",
  1110. + "RGMII1",
  1111. + "unknown",
  1112. +};
  1113. +
  1114. +const char *ltq_boot_select_str(void)
  1115. +{ enum ltq_boot_select bootsel = ltq_boot_select();
  1116. +
  1117. + if (bootsel > BOOT_UNKNOWN)
  1118. + bootsel = BOOT_UNKNOWN;
  1119. +
  1120. + return ltq_bootsel_strings[bootsel];
  1121. +}
  1122. +
  1123. +void ltq_chip_print_info(void)
  1124. +{
  1125. + char buf[32];
  1126. +
  1127. + printf("SoC: Lantiq %s v1.%u\n", ltq_chip_partnum_str(),
  1128. + ltq_chip_version_get());
  1129. + printf("CPU: %s MHz\n", strmhz(buf, ltq_get_cpu_clock()));
  1130. + printf("IO: %s MHz\n", strmhz(buf, ltq_get_io_region_clock()));
  1131. + printf("BUS: %s MHz\n", strmhz(buf, ltq_get_bus_clock()));
  1132. + printf("BOOT: %s\n", ltq_boot_select_str());
  1133. +}
  1134. +
  1135. +int arch_cpu_init(void)
  1136. +{
  1137. + ltq_pmu_init();
  1138. + ltq_ebu_init();
  1139. +
  1140. + return 0;
  1141. +}
  1142. +
  1143. +void _machine_restart(void)
  1144. +{
  1145. + ltq_reset_activate(LTQ_RESET_CORE);
  1146. +}
  1147. --- /dev/null
  1148. +++ b/arch/mips/cpu/mips32/lantiq-common/lowlevel_init.S
  1149. @@ -0,0 +1,20 @@
  1150. +/*
  1151. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  1152. + *
  1153. + * SPDX-License-Identifier: GPL-2.0+
  1154. + */
  1155. +
  1156. +#include <asm/asm.h>
  1157. +#include <asm/regdef.h>
  1158. +
  1159. +NESTED(lowlevel_init, 0, ra)
  1160. + move t8, ra
  1161. +
  1162. + la t7, ltq_cgu_init
  1163. + jalr t7
  1164. +
  1165. + la t7, ltq_mem_init
  1166. + jalr t7
  1167. +
  1168. + jr t8
  1169. + END(lowlevel_init)
  1170. --- /dev/null
  1171. +++ b/arch/mips/cpu/mips32/lantiq-common/pmu.c
  1172. @@ -0,0 +1,9 @@
  1173. +/*
  1174. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  1175. + *
  1176. + * SPDX-License-Identifier: GPL-2.0+
  1177. + */
  1178. +
  1179. +#include <common.h>
  1180. +#include <asm/lantiq/pm.h>
  1181. +
  1182. --- /dev/null
  1183. +++ b/arch/mips/cpu/mips32/lantiq-common/spl.c
  1184. @@ -0,0 +1,403 @@
  1185. +/*
  1186. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  1187. + *
  1188. + * SPDX-License-Identifier: GPL-2.0+
  1189. + */
  1190. +
  1191. +#include <common.h>
  1192. +#include <image.h>
  1193. +#include <version.h>
  1194. +#include <spi_flash.h>
  1195. +#include <linux/compiler.h>
  1196. +#include <lzma/LzmaDec.h>
  1197. +#include <linux/lzo.h>
  1198. +#include <asm/mipsregs.h>
  1199. +
  1200. +#if defined(CONFIG_LTQ_SPL_CONSOLE)
  1201. +#define spl_has_console 1
  1202. +
  1203. +#if defined(CONFIG_LTQ_SPL_DEBUG)
  1204. +#define spl_has_debug 1
  1205. +#else
  1206. +#define spl_has_debug 0
  1207. +#endif
  1208. +
  1209. +#else
  1210. +#define spl_has_console 0
  1211. +#define spl_has_debug 0
  1212. +#endif
  1213. +
  1214. +#define spl_debug(fmt, args...) \
  1215. + do { \
  1216. + if (spl_has_debug) \
  1217. + printf(fmt, ##args); \
  1218. + } while (0)
  1219. +
  1220. +#define spl_puts(msg) \
  1221. + do { \
  1222. + if (spl_has_console) \
  1223. + puts(msg); \
  1224. + } while (0)
  1225. +
  1226. +#if defined(CONFIG_LTQ_SUPPORT_SPL_SPI_FLASH) && defined(CONFIG_SYS_BOOT_SFSPL)
  1227. +#define spl_boot_spi_flash 1
  1228. +#else
  1229. +#define spl_boot_spi_flash 0
  1230. +#ifndef CONFIG_SPL_SPI_BUS
  1231. +#define CONFIG_SPL_SPI_BUS 0
  1232. +#endif
  1233. +#ifndef CONFIG_SPL_SPI_CS
  1234. +#define CONFIG_SPL_SPI_CS 0
  1235. +#endif
  1236. +#ifndef CONFIG_SPL_SPI_MAX_HZ
  1237. +#define CONFIG_SPL_SPI_MAX_HZ 0
  1238. +#endif
  1239. +#ifndef CONFIG_SPL_SPI_MODE
  1240. +#define CONFIG_SPL_SPI_MODE 0
  1241. +#endif
  1242. +#endif
  1243. +
  1244. +#if defined(CONFIG_LTQ_SUPPORT_SPL_NOR_FLASH) && defined(CONFIG_SYS_BOOT_NORSPL)
  1245. +#define spl_boot_nor_flash 1
  1246. +#else
  1247. +#define spl_boot_nor_flash 0
  1248. +#endif
  1249. +
  1250. +#define spl_sync() __asm__ __volatile__("sync");
  1251. +
  1252. +struct spl_image {
  1253. + ulong data_addr;
  1254. + ulong entry_addr;
  1255. + ulong data_size;
  1256. + ulong entry_size;
  1257. + ulong data_crc;
  1258. + u8 comp;
  1259. +};
  1260. +
  1261. +DECLARE_GLOBAL_DATA_PTR;
  1262. +
  1263. +/* Emulated malloc area needed for LZMA allocator in BSS */
  1264. +static u8 *spl_mem_ptr __maybe_unused;
  1265. +static size_t spl_mem_size __maybe_unused;
  1266. +
  1267. +static int spl_is_comp_lzma(const struct spl_image *spl)
  1268. +{
  1269. +#if defined(CONFIG_LTQ_SPL_COMP_LZMA)
  1270. + return spl->comp == IH_COMP_LZMA;
  1271. +#else
  1272. + return 0;
  1273. +#endif
  1274. +}
  1275. +
  1276. +static int spl_is_comp_lzo(const struct spl_image *spl)
  1277. +{
  1278. +#if defined(CONFIG_LTQ_SPL_COMP_LZO)
  1279. + return spl->comp == IH_COMP_LZO;
  1280. +#else
  1281. + return 0;
  1282. +#endif
  1283. +}
  1284. +
  1285. +static int spl_is_compressed(const struct spl_image *spl)
  1286. +{
  1287. + if (spl_is_comp_lzma(spl))
  1288. + return 1;
  1289. +
  1290. + if (spl_is_comp_lzo(spl))
  1291. + return 1;
  1292. +
  1293. + return 0;
  1294. +}
  1295. +
  1296. +static void spl_console_init(void)
  1297. +{
  1298. + if (!spl_has_console)
  1299. + return;
  1300. +
  1301. + gd->flags |= GD_FLG_RELOC;
  1302. + gd->baudrate = CONFIG_BAUDRATE;
  1303. +
  1304. + serial_init();
  1305. +
  1306. + gd->have_console = 1;
  1307. +
  1308. + spl_puts("\nU-Boot SPL " PLAIN_VERSION " (" U_BOOT_DATE " - " \
  1309. + U_BOOT_TIME ")\n");
  1310. +}
  1311. +
  1312. +static int spl_parse_image(const image_header_t *hdr, struct spl_image *spl)
  1313. +{
  1314. + spl_puts("SPL: checking U-Boot image\n");
  1315. +
  1316. + if (!image_check_magic(hdr)) {
  1317. + spl_puts("SPL: invalid magic\n");
  1318. + return -1;
  1319. + }
  1320. +
  1321. + if (!image_check_hcrc(hdr)) {
  1322. + spl_puts("SPL: invalid header CRC\n");
  1323. + return -1;
  1324. + }
  1325. +
  1326. + spl->data_addr += image_get_header_size();
  1327. + spl->entry_addr = image_get_load(hdr);
  1328. + spl->data_size = image_get_data_size(hdr);
  1329. + spl->data_crc = image_get_dcrc(hdr);
  1330. + spl->comp = image_get_comp(hdr);
  1331. +
  1332. + spl_debug("SPL: data %08lx, size %lu, entry %08lx, comp %u\n",
  1333. + spl->data_addr, spl->data_size, spl->entry_addr, spl->comp);
  1334. +
  1335. + return 0;
  1336. +}
  1337. +
  1338. +static int spl_check_data(const struct spl_image *spl, ulong loadaddr)
  1339. +{
  1340. + ulong dcrc = crc32(0, (unsigned char *)loadaddr, spl->data_size);
  1341. +
  1342. + if (dcrc != spl->data_crc) {
  1343. + spl_puts("SPL: invalid data CRC\n");
  1344. + return 0;
  1345. + }
  1346. +
  1347. + return 1;
  1348. +}
  1349. +
  1350. +static void *spl_lzma_alloc(void *p, size_t size)
  1351. +{
  1352. + u8 *ret;
  1353. +
  1354. + if (size > spl_mem_size)
  1355. + return NULL;
  1356. +
  1357. + ret = spl_mem_ptr;
  1358. + spl_mem_ptr += size;
  1359. + spl_mem_size -= size;
  1360. +
  1361. + return ret;
  1362. +}
  1363. +
  1364. +static void spl_lzma_free(void *p, void *addr)
  1365. +{
  1366. +}
  1367. +
  1368. +static int spl_copy_image(struct spl_image *spl)
  1369. +{
  1370. + spl_puts("SPL: copying U-Boot to RAM\n");
  1371. +
  1372. + memcpy((void *) spl->entry_addr, (const void *) spl->data_addr,
  1373. + spl->data_size);
  1374. +
  1375. + spl->entry_size = spl->data_size;
  1376. +
  1377. + return 0;
  1378. +}
  1379. +
  1380. +static int spl_uncompress_lzma(struct spl_image *spl, unsigned long loadaddr)
  1381. +{
  1382. + SRes res;
  1383. + const Byte *prop = (const Byte *) loadaddr;
  1384. + const Byte *src = (const Byte *) loadaddr + LZMA_PROPS_SIZE +
  1385. + sizeof(uint64_t);
  1386. + Byte *dest = (Byte *) spl->entry_addr;
  1387. + SizeT dest_len = 0xFFFFFFFF;
  1388. + SizeT src_len = spl->data_size - LZMA_PROPS_SIZE;
  1389. + ELzmaStatus status = 0;
  1390. + ISzAlloc alloc;
  1391. +
  1392. + spl_puts("SPL: decompressing U-Boot with LZMA\n");
  1393. +
  1394. + alloc.Alloc = spl_lzma_alloc;
  1395. + alloc.Free = spl_lzma_free;
  1396. + spl_mem_ptr = (u8 *) CONFIG_SPL_MALLOC_BASE;
  1397. + spl_mem_size = CONFIG_SPL_MALLOC_MAX_SIZE;
  1398. +
  1399. + res = LzmaDecode(dest, &dest_len, src, &src_len, prop, LZMA_PROPS_SIZE,
  1400. + LZMA_FINISH_ANY, &status, &alloc);
  1401. + if (res != SZ_OK)
  1402. + return 1;
  1403. +
  1404. + spl->entry_size = dest_len;
  1405. +
  1406. + return 0;
  1407. +}
  1408. +
  1409. +static int spl_uncompress_lzo(struct spl_image *spl, unsigned long loadaddr)
  1410. +{
  1411. + size_t len;
  1412. + int ret;
  1413. +
  1414. + spl_puts("SPL: decompressing U-Boot with LZO\n");
  1415. +
  1416. + ret = lzop_decompress(
  1417. + (const unsigned char*) loadaddr, spl->data_size,
  1418. + (unsigned char *) spl->entry_addr, &len);
  1419. +
  1420. + spl->entry_size = len;
  1421. +
  1422. + return ret;
  1423. +}
  1424. +
  1425. +static int spl_uncompress(struct spl_image *spl, unsigned long loadaddr)
  1426. +{
  1427. + int ret;
  1428. +
  1429. + if (spl_is_comp_lzma(spl))
  1430. + ret = spl_uncompress_lzma(spl, loadaddr);
  1431. + else if (spl_is_comp_lzo(spl))
  1432. + ret = spl_uncompress_lzo(spl, loadaddr);
  1433. + else
  1434. + ret = 1;
  1435. +
  1436. + return ret;
  1437. +}
  1438. +
  1439. +static int spl_load_spi_flash(struct spl_image *spl)
  1440. +{
  1441. + struct spi_flash sf = { 0 };
  1442. + image_header_t hdr;
  1443. + int ret;
  1444. + unsigned long loadaddr;
  1445. +
  1446. + /*
  1447. + * Image format:
  1448. + *
  1449. + * - 12 byte non-volatile bootstrap header
  1450. + * - SPL binary
  1451. + * - 12 byte non-volatile bootstrap header
  1452. + * - 64 byte U-Boot mkimage header
  1453. + * - U-Boot binary
  1454. + */
  1455. + spl->data_addr = image_copy_end() - CONFIG_SPL_TEXT_BASE + 24;
  1456. +
  1457. + spl_puts("SPL: probing SPI flash\n");
  1458. +
  1459. + spi_init();
  1460. + ret = spl_spi_flash_probe(&sf);
  1461. + if (ret)
  1462. + return ret;
  1463. +
  1464. + spl_debug("SPL: reading image header at offset %lx\n", spl->data_addr);
  1465. +
  1466. + ret = spi_flash_read(&sf, spl->data_addr, sizeof(hdr), &hdr);
  1467. + if (ret)
  1468. + return ret;
  1469. +
  1470. + spl_debug("SPL: checking image header at offset %lx\n", spl->data_addr);
  1471. +
  1472. + ret = spl_parse_image(&hdr, spl);
  1473. + if (ret)
  1474. + return ret;
  1475. +
  1476. + if (spl_is_compressed(spl))
  1477. + loadaddr = CONFIG_LOADADDR;
  1478. + else
  1479. + loadaddr = spl->entry_addr;
  1480. +
  1481. + spl_puts("SPL: loading U-Boot to RAM\n");
  1482. +
  1483. + ret = spi_flash_read(&sf, spl->data_addr, spl->data_size,
  1484. + (void *) loadaddr);
  1485. +
  1486. + if (!spl_check_data(spl, loadaddr))
  1487. + return -1;
  1488. +
  1489. + if (spl_is_compressed(spl))
  1490. + ret = spl_uncompress(spl, loadaddr);
  1491. +
  1492. + return ret;
  1493. +}
  1494. +
  1495. +static int spl_load_nor_flash(struct spl_image *spl)
  1496. +{
  1497. + const image_header_t *hdr;
  1498. + int ret;
  1499. +
  1500. + /*
  1501. + * Image format:
  1502. + *
  1503. + * - SPL binary
  1504. + * - 64 byte U-Boot mkimage header
  1505. + * - U-Boot binary
  1506. + */
  1507. + spl->data_addr = image_copy_end();
  1508. + hdr = (const image_header_t *) image_copy_end();
  1509. +
  1510. + spl_debug("SPL: checking image header at address %p\n", hdr);
  1511. +
  1512. + ret = spl_parse_image(hdr, spl);
  1513. + if (ret)
  1514. + return ret;
  1515. +
  1516. + if (spl_is_compressed(spl))
  1517. + ret = spl_uncompress(spl, spl->data_addr);
  1518. + else
  1519. + ret = spl_copy_image(spl);
  1520. +
  1521. + return ret;
  1522. +}
  1523. +
  1524. +static int spl_load(struct spl_image *spl)
  1525. +{
  1526. + int ret;
  1527. +
  1528. + if (spl_boot_spi_flash)
  1529. + ret = spl_load_spi_flash(spl);
  1530. + else if (spl_boot_nor_flash)
  1531. + ret = spl_load_nor_flash(spl);
  1532. + else
  1533. + ret = 1;
  1534. +
  1535. + return ret;
  1536. +}
  1537. +
  1538. +void __noreturn spl_lantiq_init(void)
  1539. +{
  1540. + void (*uboot)(void) __noreturn;
  1541. + struct spl_image spl;
  1542. + gd_t gd_data;
  1543. + int ret;
  1544. +
  1545. + gd = &gd_data;
  1546. + barrier();
  1547. + memset((void *)gd, 0, sizeof(gd_t));
  1548. +
  1549. + spl_console_init();
  1550. +
  1551. + spl_debug("SPL: initializing\n");
  1552. +
  1553. +#if 0
  1554. + spl_debug("CP0_CONFIG: %08x\n", read_c0_config());
  1555. + spl_debug("CP0_CONFIG1: %08x\n", read_c0_config1());
  1556. + spl_debug("CP0_CONFIG2: %08x\n", read_c0_config2());
  1557. + spl_debug("CP0_CONFIG3: %08x\n", read_c0_config3());
  1558. + spl_debug("CP0_CONFIG6: %08x\n", read_c0_config6());
  1559. + spl_debug("CP0_CONFIG7: %08x\n", read_c0_config7());
  1560. + spl_debug("CP0_STATUS: %08x\n", read_c0_status());
  1561. + spl_debug("CP0_PRID: %08x\n", read_c0_prid());
  1562. +#endif
  1563. +
  1564. + board_early_init_f();
  1565. + timer_init();
  1566. +
  1567. + memset(&spl, 0, sizeof(spl));
  1568. +
  1569. + ret = spl_load(&spl);
  1570. + if (ret)
  1571. + goto hang;
  1572. +
  1573. + spl_debug("SPL: U-Boot entry %08lx\n", spl.entry_addr);
  1574. + spl_puts("SPL: jumping to U-Boot\n");
  1575. +
  1576. + flush_cache(spl.entry_addr, spl.entry_size);
  1577. + spl_sync();
  1578. +
  1579. + uboot = (void *) spl.entry_addr;
  1580. + uboot();
  1581. +
  1582. +hang:
  1583. + spl_puts("SPL: cannot start U-Boot\n");
  1584. +
  1585. + for (;;)
  1586. + ;
  1587. +}
  1588. --- /dev/null
  1589. +++ b/arch/mips/cpu/mips32/lantiq-common/start.S
  1590. @@ -0,0 +1,143 @@
  1591. +/*
  1592. + * Copyright (C) 2010 Lantiq Deutschland GmbH
  1593. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  1594. + *
  1595. + * SPDX-License-Identifier: GPL-2.0+
  1596. + */
  1597. +
  1598. +#include <config.h>
  1599. +#include <asm/regdef.h>
  1600. +#include <asm/mipsregs.h>
  1601. +
  1602. +#define S_PRIdCoID 16 /* Company ID (R) */
  1603. +#define M_PRIdCoID (0xff << S_PRIdCoID)
  1604. +#define S_PRIdImp 8 /* Implementation ID (R) */
  1605. +#define M_PRIdImp (0xff << S_PRIdImp)
  1606. +
  1607. +#define K_CacheAttrCWTnWA 0 /* Cacheable, write-thru, no write allocate */
  1608. +#define K_CacheAttrCWTWA 1 /* Cacheable, write-thru, write allocate */
  1609. +#define K_CacheAttrU 2 /* Uncached */
  1610. +#define K_CacheAttrC 3 /* Cacheable */
  1611. +#define K_CacheAttrCN 3 /* Cacheable, non-coherent */
  1612. +#define K_CacheAttrCCE 4 /* Cacheable, coherent, exclusive */
  1613. +#define K_CacheAttrCCS 5 /* Cacheable, coherent, shared */
  1614. +#define K_CacheAttrCCU 6 /* Cacheable, coherent, update */
  1615. +#define K_CacheAttrUA 7 /* Uncached accelerated */
  1616. +
  1617. +#define S_ConfigK23 28 /* Kseg2/3 coherency algorithm (FM MMU only) (R/W) */
  1618. +#define M_ConfigK23 (0x7 << S_ConfigK23)
  1619. +#define W_ConfigK23 3
  1620. +#define S_ConfigKU 25 /* Kuseg coherency algorithm (FM MMU only) (R/W) */
  1621. +#define M_ConfigKU (0x7 << S_ConfigKU)
  1622. +#define W_ConfigKU 3
  1623. +
  1624. +#define S_ConfigMM 18 /* Merge mode (implementation specific) */
  1625. +#define M_ConfigMM (0x1 << S_ConfigMM)
  1626. +
  1627. +#define S_StatusBEV 22 /* Enable Boot Exception Vectors (R/W) */
  1628. +#define M_StatusBEV (0x1 << S_StatusBEV)
  1629. +
  1630. +#define S_StatusFR 26 /* Enable 64-bit FPRs (R/W) */
  1631. +#define M_StatusFR (0x1 << S_StatusFR)
  1632. +
  1633. +#define S_ConfigK0 0 /* Kseg0 coherency algorithm (R/W) */
  1634. +#define M_ConfigK0 (0x7 << S_ConfigK0)
  1635. +
  1636. +#define CONFIG0_MIPS32_64_MSK 0x8000ffff
  1637. +#define STATUS_MIPS32_64_MSK 0xfffcffff
  1638. +
  1639. +#define STATUS_MIPS24K 0
  1640. +#define CONFIG0_MIPS24K ((K_CacheAttrCN << S_ConfigK23) |\
  1641. + (K_CacheAttrCN << S_ConfigKU) |\
  1642. + (M_ConfigMM))
  1643. +
  1644. +#define STATUS_MIPS34K 0
  1645. +#define CONFIG0_MIPS34K ((K_CacheAttrCN << S_ConfigK23) |\
  1646. + (K_CacheAttrCN << S_ConfigKU) |\
  1647. + (M_ConfigMM))
  1648. +
  1649. +#define STATUS_MIPS32_64 (M_StatusBEV | M_StatusFR)
  1650. +#define CONFIG0_MIPS32_64 (K_CacheAttrCN << S_ConfigK0)
  1651. +
  1652. +#ifdef CONFIG_SOC_XWAY_DANUBE
  1653. +#define CONFIG0_LANTIQ (CONFIG0_MIPS24K | CONFIG0_MIPS32_64)
  1654. +#define STATUS_LANTIQ (STATUS_MIPS24K | STATUS_MIPS32_64)
  1655. +#endif
  1656. +
  1657. +#ifdef CONFIG_SOC_XWAY_VRX200
  1658. +#define CONFIG0_LANTIQ (CONFIG0_MIPS34K | CONFIG0_MIPS32_64)
  1659. +#define STATUS_LANTIQ (STATUS_MIPS34K | STATUS_MIPS32_64)
  1660. +#endif
  1661. +
  1662. +
  1663. + .set noreorder
  1664. +
  1665. + .globl _start
  1666. + .text
  1667. +_start:
  1668. + /* Entry point */
  1669. + b main
  1670. + nop
  1671. +
  1672. + /* Lantiq SoC Boot config word */
  1673. + .org 0x10
  1674. +#ifdef CONFIG_SYS_XWAY_EBU_BOOTCFG
  1675. + .word CONFIG_SYS_XWAY_EBU_BOOTCFG
  1676. +#else
  1677. + .word 0
  1678. +#endif
  1679. + .word 0
  1680. +
  1681. + .align 4
  1682. +main:
  1683. +
  1684. + /* Init Timer */
  1685. + mtc0 zero, CP0_COUNT
  1686. + mtc0 zero, CP0_COMPARE
  1687. +
  1688. + /* Setup MIPS24K/MIPS34K specifics (implementation dependent fields) */
  1689. + mfc0 t0, CP0_CONFIG
  1690. + li t1, CONFIG0_MIPS32_64_MSK
  1691. + and t0, t1
  1692. + li t1, CONFIG0_LANTIQ
  1693. + or t0, t1
  1694. + mtc0 t0, CP0_CONFIG
  1695. +
  1696. + mfc0 t0, CP0_STATUS
  1697. + li t1, STATUS_MIPS32_64_MSK
  1698. + and t0, t1
  1699. + li t1, STATUS_LANTIQ
  1700. + or t0, t1
  1701. + mtc0 t0, CP0_STATUS
  1702. +
  1703. + /* Initialize CGU */
  1704. + la t9, ltq_cgu_init
  1705. + jalr t9
  1706. + nop
  1707. +
  1708. + /* Initialize memory controller */
  1709. + la t9, ltq_mem_init
  1710. + jalr t9
  1711. + nop
  1712. +
  1713. + /* Initialize caches... */
  1714. + la t9, mips_cache_reset
  1715. + jalr t9
  1716. + nop
  1717. +
  1718. + /* Clear BSS */
  1719. + la t1, __bss_start
  1720. + la t2, __bss_end
  1721. + sub t1, 4
  1722. +1:
  1723. + addi t1, 4
  1724. + bltl t1, t2, 1b
  1725. + sw zero, 0(t1)
  1726. +
  1727. + /* Setup stack pointer and force alignment on a 16 byte boundary */
  1728. + li t0, (CONFIG_SPL_STACK_BASE & ~0xF)
  1729. + la sp, 0(t0)
  1730. +
  1731. + la t9, spl_lantiq_init
  1732. + jr t9
  1733. + nop
  1734. --- /dev/null
  1735. +++ b/arch/mips/cpu/mips32/lantiq-common/u-boot-spl.lds
  1736. @@ -0,0 +1,48 @@
  1737. +/*
  1738. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  1739. + *
  1740. + * SPDX-License-Identifier: GPL-2.0+
  1741. + */
  1742. +
  1743. +MEMORY { .spl_mem : ORIGIN = CONFIG_SPL_TEXT_BASE, \
  1744. + LENGTH = CONFIG_SPL_MAX_SIZE }
  1745. +MEMORY { .bss_mem : ORIGIN = CONFIG_SPL_BSS_BASE, \
  1746. + LENGTH = CONFIG_SPL_BSS_MAX_SIZE }
  1747. +
  1748. +OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradlittlemips")
  1749. +OUTPUT_ARCH(mips)
  1750. +ENTRY(_start)
  1751. +SECTIONS
  1752. +{
  1753. + . = ALIGN(4);
  1754. + .text : {
  1755. + *(.text*)
  1756. + } > .spl_mem
  1757. +
  1758. + . = ALIGN(4);
  1759. + .rodata : {
  1760. + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*)))
  1761. + } > .spl_mem
  1762. +
  1763. + . = ALIGN(4);
  1764. + .data : {
  1765. + *(SORT_BY_ALIGNMENT(.data*))
  1766. + *(SORT_BY_ALIGNMENT(.sdata*))
  1767. + } > .spl_mem
  1768. +
  1769. + . = ALIGN(4);
  1770. + __image_copy_end = .;
  1771. + uboot_end_data = .;
  1772. +
  1773. + .bss : {
  1774. + __bss_start = .;
  1775. + *(.bss*)
  1776. + *(.sbss*)
  1777. + . = ALIGN(4);
  1778. + __bss_end = .;
  1779. + } > .bss_mem
  1780. +
  1781. + . = ALIGN(4);
  1782. + __end = .;
  1783. + uboot_end = .;
  1784. +}
  1785. --- a/arch/mips/cpu/mips32/start.S
  1786. +++ b/arch/mips/cpu/mips32/start.S
  1787. @@ -105,7 +105,7 @@ reset:
  1788. mtc0 zero, CP0_COUNT
  1789. mtc0 zero, CP0_COMPARE
  1790. -#ifndef CONFIG_SKIP_LOWLEVEL_INIT
  1791. +#if !defined(CONFIG_SKIP_LOWLEVEL_INIT) || defined(CONFIG_SYS_DISABLE_CACHE)
  1792. /* CONFIG0 register */
  1793. li t0, CONF_CM_UNCACHED
  1794. mtc0 t0, CP0_CONFIG
  1795. --- /dev/null
  1796. +++ b/arch/mips/cpu/mips32/vrx200/Makefile
  1797. @@ -0,0 +1,32 @@
  1798. +#
  1799. +# Copyright (C) 2000-2011 Wolfgang Denk, DENX Software Engineering, wd@denx.de
  1800. +#
  1801. +# SPDX-License-Identifier: GPL-2.0+
  1802. +#
  1803. +
  1804. +include $(TOPDIR)/config.mk
  1805. +
  1806. +LIB = $(obj)lib$(SOC).o
  1807. +
  1808. +COBJS-y += cgu.o chipid.o dcdc.o ebu.o gphy.o mem.o pmu.o rcu.o
  1809. +SOBJS-y += cgu_init.o mem_init.o
  1810. +SOBJS-y += gphy_fw.o
  1811. +
  1812. +COBJS := $(COBJS-y)
  1813. +SOBJS := $(SOBJS-y)
  1814. +SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c)
  1815. +OBJS := $(addprefix $(obj),$(SOBJS) $(COBJS))
  1816. +
  1817. +all: $(LIB)
  1818. +
  1819. +$(LIB): $(obj).depend $(OBJS)
  1820. + $(call cmd_link_o_target, $(OBJS))
  1821. +
  1822. +#########################################################################
  1823. +
  1824. +# defines $(obj).depend target
  1825. +include $(SRCTREE)/rules.mk
  1826. +
  1827. +sinclude $(obj).depend
  1828. +
  1829. +#########################################################################
  1830. --- /dev/null
  1831. +++ b/arch/mips/cpu/mips32/vrx200/cgu.c
  1832. @@ -0,0 +1,208 @@
  1833. +/*
  1834. + * Copyright (C) 2010 Lantiq Deutschland GmbH
  1835. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  1836. + *
  1837. + * SPDX-License-Identifier: GPL-2.0+
  1838. + */
  1839. +
  1840. +#include <common.h>
  1841. +#include <asm/arch/soc.h>
  1842. +#include <asm/arch/gphy.h>
  1843. +#include <asm/lantiq/clk.h>
  1844. +#include <asm/lantiq/io.h>
  1845. +
  1846. +#define LTQ_CGU_PLL1_PLLN_SHIFT 6
  1847. +#define LTQ_CGU_PLL1_PLLN_MASK (0x3F << LTQ_CGU_PLL1_PLLN_SHIFT)
  1848. +#define LTQ_CGU_PLL1_PLLM_SHIFT 2
  1849. +#define LTQ_CGU_PLL1_PLLM_MASK (0xF << LTQ_CGU_PLL1_PLLM_SHIFT)
  1850. +#define LTQ_CGU_PLL1_PLLL (1 << 1)
  1851. +#define LTQ_CGU_PLL1_PLL_EN 1
  1852. +
  1853. +#define LTQ_CGU_SYS_OCP_SHIFT 0
  1854. +#define LTQ_CGU_SYS_OCP_MASK (0x3 << LTQ_CGU_SYS_OCP_SHIFT)
  1855. +#define LTQ_CGU_SYS_CPU_SHIFT 4
  1856. +#define LTQ_CGU_SYS_CPU_MASK (0xF << LTQ_CGU_SYS_CPU_SHIFT)
  1857. +
  1858. +#define LTQ_CGU_UPDATE 1
  1859. +
  1860. +#define LTQ_CGU_IFCLK_GPHY_SEL_SHIFT 2
  1861. +#define LTQ_CGU_IFCLK_GPHY_SEL_MASK (0x7 << LTQ_CGU_IFCLK_GPHY_SEL_SHIFT)
  1862. +
  1863. +struct ltq_cgu_regs {
  1864. + u32 rsvd0;
  1865. + u32 pll0_cfg; /* PLL0 config */
  1866. + u32 pll1_cfg; /* PLL1 config */
  1867. + u32 sys; /* System clock */
  1868. + u32 clk_fsr; /* Clock frequency select */
  1869. + u32 clk_gsr; /* Clock gating status */
  1870. + u32 clk_gcr0; /* Clock gating control 0 */
  1871. + u32 clk_gcr1; /* Clock gating control 1 */
  1872. + u32 update; /* CGU update control */
  1873. + u32 if_clk; /* Interface clock */
  1874. + u32 ddr; /* DDR memory control */
  1875. + u32 ct1_sr; /* CT status 1 */
  1876. + u32 ct_kval; /* CT K value */
  1877. + u32 pcm_cr; /* PCM control */
  1878. + u32 pci_cr; /* PCI clock control */
  1879. + u32 rsvd1;
  1880. + u32 gphy1_cfg; /* GPHY1 config */
  1881. + u32 gphy0_cfg; /* GPHY0 config */
  1882. + u32 rsvd2[6];
  1883. + u32 pll2_cfg; /* PLL2 config */
  1884. +};
  1885. +
  1886. +static struct ltq_cgu_regs *ltq_cgu_regs =
  1887. + (struct ltq_cgu_regs *) CKSEG1ADDR(LTQ_CGU_BASE);
  1888. +
  1889. +static inline u32 ltq_cgu_sys_readl(u32 mask, u32 shift)
  1890. +{
  1891. + return (ltq_readl(&ltq_cgu_regs->sys) & mask) >> shift;
  1892. +}
  1893. +
  1894. +unsigned long ltq_get_io_region_clock(void)
  1895. +{
  1896. + unsigned int ocp_sel;
  1897. + unsigned long clk, cpu_clk;
  1898. +
  1899. + cpu_clk = ltq_get_cpu_clock();
  1900. +
  1901. + ocp_sel = ltq_cgu_sys_readl(LTQ_CGU_SYS_OCP_MASK,
  1902. + LTQ_CGU_SYS_OCP_SHIFT);
  1903. +
  1904. + switch (ocp_sel) {
  1905. + case 0:
  1906. + /* OCP ratio 1 */
  1907. + clk = cpu_clk;
  1908. + break;
  1909. + case 2:
  1910. + /* OCP ratio 2 */
  1911. + clk = cpu_clk / 2;
  1912. + break;
  1913. + case 3:
  1914. + /* OCP ratio 2.5 */
  1915. + clk = (cpu_clk * 2) / 5;
  1916. + break;
  1917. + case 4:
  1918. + /* OCP ratio 3 */
  1919. + clk = cpu_clk / 3;
  1920. + break;
  1921. + default:
  1922. + clk = 0;
  1923. + break;
  1924. + }
  1925. +
  1926. + return clk;
  1927. +}
  1928. +
  1929. +unsigned long ltq_get_cpu_clock(void)
  1930. +{
  1931. + unsigned int cpu_sel;
  1932. + unsigned long clk;
  1933. +
  1934. + cpu_sel = ltq_cgu_sys_readl(LTQ_CGU_SYS_CPU_MASK,
  1935. + LTQ_CGU_SYS_CPU_SHIFT);
  1936. +
  1937. + switch (cpu_sel) {
  1938. + case 0:
  1939. + clk = CLOCK_600_MHZ;
  1940. + break;
  1941. + case 1:
  1942. + clk = CLOCK_500_MHZ;
  1943. + break;
  1944. + case 2:
  1945. + clk = CLOCK_393_MHZ;
  1946. + break;
  1947. + case 3:
  1948. + clk = CLOCK_333_MHZ;
  1949. + break;
  1950. + case 5:
  1951. + case 6:
  1952. + clk = CLOCK_197_MHZ;
  1953. + break;
  1954. + case 7:
  1955. + clk = CLOCK_166_MHZ;
  1956. + break;
  1957. + case 4:
  1958. + case 8:
  1959. + case 9:
  1960. + clk = CLOCK_125_MHZ;
  1961. + break;
  1962. + default:
  1963. + clk = 0;
  1964. + break;
  1965. + }
  1966. +
  1967. + return clk;
  1968. +}
  1969. +
  1970. +unsigned long ltq_get_bus_clock(void)
  1971. +{
  1972. + return ltq_get_io_region_clock();
  1973. +}
  1974. +
  1975. +void ltq_cgu_gphy_clk_src(enum ltq_gphy_clk clk)
  1976. +{
  1977. + ltq_clrbits(&ltq_cgu_regs->if_clk, LTQ_CGU_IFCLK_GPHY_SEL_MASK);
  1978. + ltq_setbits(&ltq_cgu_regs->if_clk, clk << LTQ_CGU_IFCLK_GPHY_SEL_SHIFT);
  1979. +}
  1980. +
  1981. +static inline int ltq_cgu_pll1_locked(void)
  1982. +{
  1983. + u32 pll1_cfg = ltq_readl(&ltq_cgu_regs->pll1_cfg);
  1984. +
  1985. + return pll1_cfg & LTQ_CGU_PLL1_PLLL;
  1986. +}
  1987. +
  1988. +static inline void ltq_cgu_pll1_restart(unsigned m, unsigned n)
  1989. +{
  1990. + u32 pll1_cfg;
  1991. +
  1992. + ltq_clrbits(&ltq_cgu_regs->pll1_cfg, LTQ_CGU_PLL1_PLL_EN);
  1993. + ltq_setbits(&ltq_cgu_regs->update, LTQ_CGU_UPDATE);
  1994. +
  1995. + pll1_cfg = ltq_readl(&ltq_cgu_regs->pll1_cfg);
  1996. + pll1_cfg &= ~(LTQ_CGU_PLL1_PLLN_MASK | LTQ_CGU_PLL1_PLLM_MASK);
  1997. + pll1_cfg |= n << LTQ_CGU_PLL1_PLLN_SHIFT;
  1998. + pll1_cfg |= m << LTQ_CGU_PLL1_PLLM_SHIFT;
  1999. + pll1_cfg |= LTQ_CGU_PLL1_PLL_EN;
  2000. + ltq_writel(&ltq_cgu_regs->pll1_cfg, pll1_cfg);
  2001. + ltq_setbits(&ltq_cgu_regs->update, LTQ_CGU_UPDATE);
  2002. +
  2003. + __udelay(1000);
  2004. +}
  2005. +
  2006. +/*
  2007. + * From chapter 9 in errata sheet:
  2008. + *
  2009. + * Under certain condition, the PLL1 may failed to enter into lock
  2010. + * status by hardware default N, M setting.
  2011. + *
  2012. + * Since system always starts from PLL0, the system software can run
  2013. + * and re-program the PLL1 settings.
  2014. + */
  2015. +static void ltq_cgu_pll1_init(void)
  2016. +{
  2017. + unsigned i;
  2018. + const unsigned pll1_m[] = { 1, 2, 3, 4 };
  2019. + const unsigned pll1_n[] = { 21, 32, 43, 54 };
  2020. +
  2021. + /* Check if PLL1 has locked with hardware default settings */
  2022. + if (ltq_cgu_pll1_locked())
  2023. + return;
  2024. +
  2025. + for (i = 0; i < 4; i++) {
  2026. + ltq_cgu_pll1_restart(pll1_m[i], pll1_n[i]);
  2027. +
  2028. + if (ltq_cgu_pll1_locked())
  2029. + goto done;
  2030. + }
  2031. +
  2032. +done:
  2033. + /* Restart with hardware default values M=5, N=64 */
  2034. + ltq_cgu_pll1_restart(5, 64);
  2035. +}
  2036. +
  2037. +void ltq_pll_init(void)
  2038. +{
  2039. + ltq_cgu_pll1_init();
  2040. +}
  2041. --- /dev/null
  2042. +++ b/arch/mips/cpu/mips32/vrx200/cgu_init.S
  2043. @@ -0,0 +1,119 @@
  2044. +/*
  2045. + * Copyright (C) 2010 Lantiq Deutschland GmbH
  2046. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  2047. + *
  2048. + * SPDX-License-Identifier: GPL-2.0+
  2049. + */
  2050. +
  2051. +#include <config.h>
  2052. +#include <asm/asm.h>
  2053. +#include <asm/regdef.h>
  2054. +#include <asm/addrspace.h>
  2055. +#include <asm/arch/soc.h>
  2056. +
  2057. +/* RCU module register */
  2058. +#define LTQ_RCU_RST_REQ 0x0010 /* Reset request */
  2059. +#define LTQ_RCU_RST_REQ_VALUE ((1 << 14) | (1 << 1))
  2060. +
  2061. +/* CGU module register */
  2062. +#define LTQ_CGU_PLL0_CFG 0x0004 /* PLL0 config */
  2063. +#define LTQ_CGU_PLL1_CFG 0x0008 /* PLL1 config */
  2064. +#define LTQ_CGU_PLL2_CFG 0x0060 /* PLL2 config */
  2065. +#define LTQ_CGU_SYS 0x000C /* System clock */
  2066. +#define LTQ_CGU_CLK_FSR 0x0010 /* Clock frequency select */
  2067. +#define LTQ_CGU_UPDATE 0x0020 /* Clock update control */
  2068. +
  2069. +/* Valid SYS.CPU values */
  2070. +#define LTQ_CGU_SYS_CPU_SHIFT 4
  2071. +#define LTQ_CGU_SYS_CPU_600_MHZ 0x0
  2072. +#define LTQ_CGU_SYS_CPU_500_MHZ 0x1
  2073. +#define LTQ_CGU_SYS_CPU_393_MHZ 0x2
  2074. +#define LTQ_CGU_SYS_CPU_333_MHZ 0x3
  2075. +#define LTQ_CGU_SYS_CPU_197_MHZ 0x5
  2076. +#define LTQ_CGU_SYS_CPU_166_MHZ 0x7
  2077. +#define LTQ_CGU_SYS_CPU_125_MHZ 0x9
  2078. +
  2079. +/* Valid SYS.OCP values */
  2080. +#define LTQ_CGU_SYS_OCP_SHIFT 0
  2081. +#define LTQ_CGU_SYS_OCP_1 0x0
  2082. +#define LTQ_CGU_SYS_OCP_2 0x2
  2083. +#define LTQ_CGU_SYS_OCP_2_5 0x3
  2084. +#define LTQ_CGU_SYS_OCP_3 0x4
  2085. +
  2086. +/* Valid CLK_FSR.ETH values */
  2087. +#define LTQ_CGU_CLK_FSR_ETH_SHIFT 24
  2088. +#define LTQ_CGU_CLK_FSR_ETH_50_MHZ 0x0
  2089. +#define LTQ_CGU_CLK_FSR_ETH_25_MHZ 0x1
  2090. +#define LTQ_CGU_CLK_FSR_ETH_2_5_MHZ 0x2
  2091. +#define LTQ_CGU_CLK_FSR_ETH_125_MHZ 0x3
  2092. +
  2093. +/* Valid CLK_FSR.PPE values */
  2094. +#define LTQ_CGU_CLK_FSR_PPE_SHIFT 16
  2095. +#define LTQ_CGU_CLK_FSR_PPE_500_MHZ 0x0 /* Overclock frequency */
  2096. +#define LTQ_CGU_CLK_FSR_PPE_450_MHZ 0x1 /* High frequency */
  2097. +#define LTQ_CGU_CLK_FSR_PPE_400_MHZ 0x2 /* Low frequency */
  2098. +
  2099. +#if (CONFIG_SYS_CLOCK_MODE == LTQ_CLK_CPU_500_DDR_250)
  2100. +#define LTQ_CGU_SYS_CPU_CONFIG LTQ_CGU_SYS_CPU_500_MHZ
  2101. +#define LTQ_CGU_SYS_OCP_CONFIG LTQ_CGU_SYS_OCP_2
  2102. +#define LTQ_CGU_CLK_FSR_ETH_CONFIG LTQ_CGU_CLK_FSR_ETH_125_MHZ
  2103. +#define LTQ_CGU_CLK_FSR_PPE_CONFIG LTQ_CGU_CLK_FSR_PPE_450_MHZ
  2104. +#else
  2105. +#error "Invalid system clock configuration!"
  2106. +#endif
  2107. +
  2108. +/* Build register values */
  2109. +#define LTQ_CGU_SYS_VALUE ((LTQ_CGU_SYS_CPU_CONFIG << \
  2110. + LTQ_CGU_SYS_CPU_SHIFT) | \
  2111. + LTQ_CGU_SYS_OCP_CONFIG)
  2112. +
  2113. +#define LTQ_CGU_CLK_FSR_VALUE ((LTQ_CGU_CLK_FSR_ETH_CONFIG << \
  2114. + LTQ_CGU_CLK_FSR_ETH_SHIFT) | \
  2115. + (LTQ_CGU_CLK_FSR_PPE_CONFIG << \
  2116. + LTQ_CGU_CLK_FSR_PPE_SHIFT))
  2117. +
  2118. + .set noreorder
  2119. +
  2120. +LEAF(ltq_cgu_init)
  2121. + /* Load current CGU register values */
  2122. + li t0, (LTQ_CGU_BASE | KSEG1)
  2123. + lw t1, LTQ_CGU_SYS(t0)
  2124. + lw t2, LTQ_CGU_CLK_FSR(t0)
  2125. +
  2126. + /* Load target CGU register values */
  2127. + li t3, LTQ_CGU_SYS_VALUE
  2128. + li t4, LTQ_CGU_CLK_FSR_VALUE
  2129. +
  2130. + /* Only update registers if values differ */
  2131. + bne t1, t3, update
  2132. + nop
  2133. + beq t2, t4, finished
  2134. + nop
  2135. +
  2136. +update:
  2137. + /* Store target register values */
  2138. + sw t3, LTQ_CGU_SYS(t0)
  2139. + sw t4, LTQ_CGU_CLK_FSR(t0)
  2140. +
  2141. + /* Perform software reset to activate new clock config */
  2142. +#if 0
  2143. + li t0, (LTQ_RCU_BASE | KSEG1)
  2144. + lw t1, LTQ_RCU_RST_REQ(t0)
  2145. + or t1, LTQ_RCU_RST_REQ_VALUE
  2146. + sw t1, LTQ_RCU_RST_REQ(t0)
  2147. +#else
  2148. + li t1, 1
  2149. + sw t1, LTQ_CGU_UPDATE(t0)
  2150. +#endif
  2151. +
  2152. +#if 0
  2153. +wait_reset:
  2154. + b wait_reset
  2155. + nop
  2156. +#endif
  2157. +
  2158. +finished:
  2159. + jr ra
  2160. + nop
  2161. +
  2162. + END(ltq_cgu_init)
  2163. --- /dev/null
  2164. +++ b/arch/mips/cpu/mips32/vrx200/chipid.c
  2165. @@ -0,0 +1,62 @@
  2166. +/*
  2167. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  2168. + *
  2169. + * SPDX-License-Identifier: GPL-2.0+
  2170. + */
  2171. +
  2172. +#include <common.h>
  2173. +#include <asm/lantiq/io.h>
  2174. +#include <asm/lantiq/chipid.h>
  2175. +#include <asm/arch/soc.h>
  2176. +
  2177. +#define LTQ_CHIPID_VERSION_SHIFT 28
  2178. +#define LTQ_CHIPID_VERSION_MASK (0x7 << LTQ_CHIPID_VERSION_SHIFT)
  2179. +#define LTQ_CHIPID_PNUM_SHIFT 12
  2180. +#define LTQ_CHIPID_PNUM_MASK (0xFFFF << LTQ_CHIPID_PNUM_SHIFT)
  2181. +
  2182. +struct ltq_chipid_regs {
  2183. + u32 manid; /* Manufacturer identification */
  2184. + u32 chipid; /* Chip identification */
  2185. +};
  2186. +
  2187. +static struct ltq_chipid_regs *ltq_chipid_regs =
  2188. + (struct ltq_chipid_regs *) CKSEG1ADDR(LTQ_CHIPID_BASE);
  2189. +
  2190. +unsigned int ltq_chip_version_get(void)
  2191. +{
  2192. + u32 chipid;
  2193. +
  2194. + chipid = ltq_readl(&ltq_chipid_regs->chipid);
  2195. +
  2196. + return (chipid & LTQ_CHIPID_VERSION_MASK) >> LTQ_CHIPID_VERSION_SHIFT;
  2197. +}
  2198. +
  2199. +unsigned int ltq_chip_partnum_get(void)
  2200. +{
  2201. + u32 chipid;
  2202. +
  2203. + chipid = ltq_readl(&ltq_chipid_regs->chipid);
  2204. +
  2205. + return (chipid & LTQ_CHIPID_PNUM_MASK) >> LTQ_CHIPID_PNUM_SHIFT;
  2206. +}
  2207. +
  2208. +const char *ltq_chip_partnum_str(void)
  2209. +{
  2210. + enum ltq_chip_partnum partnum = ltq_chip_partnum_get();
  2211. +
  2212. + switch (partnum) {
  2213. + case LTQ_SOC_VRX268:
  2214. + case LTQ_SOC_VRX268_2:
  2215. + return "VRX268";
  2216. + case LTQ_SOC_VRX288:
  2217. + case LTQ_SOC_VRX288_2:
  2218. + return "VRX288";
  2219. + case LTQ_SOC_GRX288:
  2220. + case LTQ_SOC_GRX288_2:
  2221. + return "GRX288";
  2222. + default:
  2223. + printf("Unknown partnum: %x\n", partnum);
  2224. + }
  2225. +
  2226. + return "";
  2227. +}
  2228. --- /dev/null
  2229. +++ b/arch/mips/cpu/mips32/vrx200/config.mk
  2230. @@ -0,0 +1,30 @@
  2231. +#
  2232. +# Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  2233. +#
  2234. +# SPDX-License-Identifier: GPL-2.0+
  2235. +#
  2236. +
  2237. +PF_CPPFLAGS_XRX := $(call cc-option,-mtune=34kc,)
  2238. +PLATFORM_CPPFLAGS += $(PF_CPPFLAGS_XRX)
  2239. +
  2240. +ifdef CONFIG_SPL_BUILD
  2241. +PF_ABICALLS := -mno-abicalls
  2242. +PF_PIC := -fno-pic
  2243. +PF_PIE :=
  2244. +USE_PRIVATE_LIBGCC := yes
  2245. +endif
  2246. +
  2247. +LIBS-y += $(CPUDIR)/lantiq-common/liblantiq-common.o
  2248. +
  2249. +ifndef CONFIG_SPL_BUILD
  2250. +ifdef CONFIG_SYS_BOOT_SFSPL
  2251. +ALL-y += $(obj)u-boot.ltq.sfspl
  2252. +ALL-$(CONFIG_SPL_LZO_SUPPORT) += $(obj)u-boot.ltq.lzo.sfspl
  2253. +ALL-$(CONFIG_SPL_LZMA_SUPPORT) += $(obj)u-boot.ltq.lzma.sfspl
  2254. +endif
  2255. +ifdef CONFIG_SYS_BOOT_NORSPL
  2256. +ALL-y += $(obj)u-boot.ltq.norspl
  2257. +ALL-$(CONFIG_SPL_LZO_SUPPORT) += $(obj)u-boot.ltq.lzo.norspl
  2258. +ALL-$(CONFIG_SPL_LZMA_SUPPORT) += $(obj)u-boot.ltq.lzma.norspl
  2259. +endif
  2260. +endif
  2261. --- /dev/null
  2262. +++ b/arch/mips/cpu/mips32/vrx200/dcdc.c
  2263. @@ -0,0 +1,106 @@
  2264. +/*
  2265. + * Copyright (C) 2010 Lantiq Deutschland GmbH
  2266. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  2267. + *
  2268. + * SPDX-License-Identifier: GPL-2.0+
  2269. + */
  2270. +
  2271. +#include <common.h>
  2272. +#include <asm/arch/soc.h>
  2273. +#include <asm/lantiq/io.h>
  2274. +
  2275. +#define LTQ_DCDC_CLK_SET0_CLK_SEL_P (1 << 6)
  2276. +#define LTQ_DCDC_CLK_SET1_SEL_DIV25 (1 << 5)
  2277. +#define LTQ_DCDC_CONF_TEST_DIG_PID_FREEZE (1 << 5)
  2278. +
  2279. +struct ltq_dcdc_regs {
  2280. + u8 b0_coeh; /* Coefficient b0 */
  2281. + u8 b0_coel; /* Coefficient b0 */
  2282. + u8 b1_coeh; /* Coefficient b1 */
  2283. + u8 b1_coel; /* Coefficient b1 */
  2284. + u8 b2_coeh; /* Coefficient b2 */
  2285. + u8 b2_coel; /* Coefficient b2 */
  2286. + u8 clk_set0; /* Clock setup */
  2287. + u8 clk_set1; /* Clock setup */
  2288. + u8 pwm_confh; /* Configure PWM */
  2289. + u8 pwm_confl; /* Configure PWM */
  2290. + u8 bias_vreg0; /* Bias and regulator setup */
  2291. + u8 bias_vreg1; /* Bias and regulator setup */
  2292. + u8 adc_gen0; /* ADC and general control */
  2293. + u8 adc_gen1; /* ADC and general control */
  2294. + u8 adc_con0; /* ADC and general config */
  2295. + u8 adc_con1; /* ADC and general config */
  2296. + u8 conf_test_ana; /* not documented */
  2297. + u8 conf_test_dig; /* not documented */
  2298. + u8 dcdc_status; /* not documented */
  2299. + u8 pid_status; /* not documented */
  2300. + u8 duty_cycle; /* not documented */
  2301. + u8 non_ov_delay; /* not documented */
  2302. + u8 analog_gain; /* not documented */
  2303. + u8 duty_cycle_max_sat; /* not documented */
  2304. + u8 duty_cycle_min_sat; /* not documented */
  2305. + u8 duty_cycle_max; /* not documented */
  2306. + u8 duty_cycle_min; /* not documented */
  2307. + u8 error_max; /* not documented */
  2308. + u8 error_read; /* not documented */
  2309. + u8 delay_deglitch; /* not documented */
  2310. + u8 latch_control; /* not documented */
  2311. + u8 rsvd[240];
  2312. + u8 osc_conf; /* OSC general config */
  2313. + u8 osc_stat; /* OSC general status */
  2314. +};
  2315. +
  2316. +static struct ltq_dcdc_regs *ltq_dcdc_regs =
  2317. + (struct ltq_dcdc_regs *) CKSEG1ADDR(LTQ_DCDC_BASE);
  2318. +
  2319. +void ltq_dcdc_init(unsigned int dig_ref)
  2320. +{
  2321. + u8 dig_ref_cur, val;
  2322. +
  2323. + /* Set duty cycle max sat. to 70/90, enable PID freeze */
  2324. + ltq_writeb(&ltq_dcdc_regs->duty_cycle_max_sat, 0x5A);
  2325. + ltq_writeb(&ltq_dcdc_regs->duty_cycle_min_sat, 0x46);
  2326. + val = ltq_readb(&ltq_dcdc_regs->conf_test_dig);
  2327. + val |= LTQ_DCDC_CONF_TEST_DIG_PID_FREEZE;
  2328. + ltq_writeb(&ltq_dcdc_regs->conf_test_dig, val);
  2329. +
  2330. + /* Program new coefficients */
  2331. + ltq_writeb(&ltq_dcdc_regs->b0_coeh, 0x00);
  2332. + ltq_writeb(&ltq_dcdc_regs->b0_coel, 0x00);
  2333. + ltq_writeb(&ltq_dcdc_regs->b1_coeh, 0xFF);
  2334. + ltq_writeb(&ltq_dcdc_regs->b1_coel, 0xE6);
  2335. + ltq_writeb(&ltq_dcdc_regs->b2_coeh, 0x00);
  2336. + ltq_writeb(&ltq_dcdc_regs->b2_coel, 0x1B);
  2337. + ltq_writeb(&ltq_dcdc_regs->non_ov_delay, 0x8B);
  2338. +
  2339. + /* Set duty cycle max sat. to 60/108, disable PID freeze */
  2340. + ltq_writeb(&ltq_dcdc_regs->duty_cycle_max_sat, 0x6C);
  2341. + ltq_writeb(&ltq_dcdc_regs->duty_cycle_min_sat, 0x3C);
  2342. + val = ltq_readb(&ltq_dcdc_regs->conf_test_dig);
  2343. + val &= ~LTQ_DCDC_CONF_TEST_DIG_PID_FREEZE;
  2344. + ltq_writeb(&ltq_dcdc_regs->conf_test_dig, val);
  2345. +
  2346. + /* Init clock and DLL settings */
  2347. + val = ltq_readb(&ltq_dcdc_regs->clk_set0);
  2348. + val |= LTQ_DCDC_CLK_SET0_CLK_SEL_P;
  2349. + ltq_writeb(&ltq_dcdc_regs->clk_set0, val);
  2350. + val = ltq_readb(&ltq_dcdc_regs->clk_set1);
  2351. + val |= LTQ_DCDC_CLK_SET1_SEL_DIV25;
  2352. + ltq_writeb(&ltq_dcdc_regs->clk_set1, val);
  2353. + ltq_writeb(&ltq_dcdc_regs->pwm_confh, 0xF9);
  2354. +
  2355. + wmb();
  2356. +
  2357. + /* Adapt value of digital reference of DCDC converter */
  2358. + dig_ref_cur = ltq_readb(&ltq_dcdc_regs->bias_vreg1);
  2359. +
  2360. + while (dig_ref_cur != dig_ref) {
  2361. + if (dig_ref >= dig_ref_cur)
  2362. + dig_ref_cur++;
  2363. + else if (dig_ref < dig_ref_cur)
  2364. + dig_ref_cur--;
  2365. +
  2366. + ltq_writeb(&ltq_dcdc_regs->bias_vreg1, dig_ref_cur);
  2367. + __udelay(1000);
  2368. + }
  2369. +}
  2370. --- /dev/null
  2371. +++ b/arch/mips/cpu/mips32/vrx200/ebu.c
  2372. @@ -0,0 +1,126 @@
  2373. +/*
  2374. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  2375. + *
  2376. + * SPDX-License-Identifier: GPL-2.0+
  2377. + */
  2378. +
  2379. +#include <common.h>
  2380. +#include <asm/arch/soc.h>
  2381. +#include <asm/lantiq/io.h>
  2382. +
  2383. +#define EBU_ADDRSEL_MASK(mask) ((mask & 0xf) << 4)
  2384. +#define EBU_ADDRSEL_REGEN (1 << 0)
  2385. +
  2386. +#define EBU_CON_WRDIS (1 << 31)
  2387. +#define EBU_CON_AGEN_DEMUX (0x0 << 24)
  2388. +#define EBU_CON_AGEN_MUX (0x2 << 24)
  2389. +#define EBU_CON_SETUP (1 << 22)
  2390. +#define EBU_CON_WAIT_DIS (0x0 << 20)
  2391. +#define EBU_CON_WAIT_ASYNC (0x1 << 20)
  2392. +#define EBU_CON_WAIT_SYNC (0x2 << 20)
  2393. +#define EBU_CON_WINV (1 << 19)
  2394. +#define EBU_CON_PW_8BIT (0x0 << 16)
  2395. +#define EBU_CON_PW_16BIT (0x1 << 16)
  2396. +#define EBU_CON_ALEC(cycles) ((cycles & 0x3) << 14)
  2397. +#define EBU_CON_BCGEN_CS (0x0 << 12)
  2398. +#define EBU_CON_BCGEN_INTEL (0x1 << 12)
  2399. +#define EBU_CON_BCGEN_MOTOROLA (0x2 << 12)
  2400. +#define EBU_CON_WAITWRC(cycles) ((cycles & 0x7) << 8)
  2401. +#define EBU_CON_WAITRDC(cycles) ((cycles & 0x3) << 6)
  2402. +#define EBU_CON_HOLDC(cycles) ((cycles & 0x3) << 4)
  2403. +#define EBU_CON_RECOVC(cycles) ((cycles & 0x3) << 2)
  2404. +#define EBU_CON_CMULT_1 0x0
  2405. +#define EBU_CON_CMULT_4 0x1
  2406. +#define EBU_CON_CMULT_8 0x2
  2407. +#define EBU_CON_CMULT_16 0x3
  2408. +
  2409. +#if defined(CONFIG_LTQ_SUPPORT_NOR_FLASH)
  2410. +#define ebu_region0_enable 1
  2411. +#else
  2412. +#define ebu_region0_enable 0
  2413. +#endif
  2414. +
  2415. +#if ((CONFIG_SYS_MAX_FLASH_BANKS == 2) && defined(CONFIG_LTQ_SUPPORT_NOR_FLASH) )
  2416. +#define ebu_region0_addrsel_mask 3
  2417. +#else
  2418. +#define ebu_region0_addrsel_mask 1
  2419. +#endif
  2420. +
  2421. +#if defined(CONFIG_LTQ_SUPPORT_NAND_FLASH) || ((CONFIG_SYS_MAX_FLASH_BANKS == 2) && defined(CONFIG_LTQ_SUPPORT_NOR_FLASH) )
  2422. +#define ebu_region1_enable 1
  2423. +#else
  2424. +#define ebu_region1_enable 0
  2425. +#endif
  2426. +
  2427. +struct ltq_ebu_regs {
  2428. + u32 clc;
  2429. + u32 rsvd0;
  2430. + u32 id;
  2431. + u32 rsvd1;
  2432. + u32 con;
  2433. + u32 rsvd2[3];
  2434. + u32 addr_sel_0;
  2435. + u32 addr_sel_1;
  2436. + u32 addr_sel_2;
  2437. + u32 addr_sel_3;
  2438. + u32 rsvd3[12];
  2439. + u32 con_0;
  2440. + u32 con_1;
  2441. + u32 con_2;
  2442. + u32 con_3;
  2443. +};
  2444. +
  2445. +static struct ltq_ebu_regs *ltq_ebu_regs =
  2446. + (struct ltq_ebu_regs *) CKSEG1ADDR(LTQ_EBU_BASE);
  2447. +
  2448. +void ltq_ebu_init(void)
  2449. +{
  2450. + if (ebu_region0_enable) {
  2451. + /*
  2452. + * Map EBU region 0 to range 0x10000000-0x13ffffff and enable
  2453. + * region control. This supports up to 32 MiB NOR flash in
  2454. + * bank 0.
  2455. + */
  2456. + ltq_writel(&ltq_ebu_regs->addr_sel_0, LTQ_EBU_REGION0_BASE |
  2457. + EBU_ADDRSEL_MASK(ebu_region0_addrsel_mask) | EBU_ADDRSEL_REGEN);
  2458. +
  2459. + ltq_writel(&ltq_ebu_regs->con_0, EBU_CON_AGEN_DEMUX |
  2460. + EBU_CON_WAIT_DIS | EBU_CON_PW_16BIT |
  2461. + EBU_CON_ALEC(3) | EBU_CON_BCGEN_INTEL |
  2462. + EBU_CON_WAITWRC(7) | EBU_CON_WAITRDC(3) |
  2463. + EBU_CON_HOLDC(3) | EBU_CON_RECOVC(3) |
  2464. + EBU_CON_CMULT_16);
  2465. + } else
  2466. + ltq_clrbits(&ltq_ebu_regs->addr_sel_0, EBU_ADDRSEL_REGEN);
  2467. +
  2468. + if (ebu_region1_enable) {
  2469. + /*
  2470. + * Map EBU region 1 to range 0x14000000-0x13ffffff and enable
  2471. + * region control. This supports NAND flash in bank 1. (and NOR flash in bank 2)
  2472. + */
  2473. + ltq_writel(&ltq_ebu_regs->addr_sel_1, LTQ_EBU_REGION1_BASE |
  2474. + EBU_ADDRSEL_MASK(3) | EBU_ADDRSEL_REGEN);
  2475. +
  2476. + if (ebu_region0_addrsel_mask == 1)
  2477. + ltq_writel(&ltq_ebu_regs->con_1, EBU_CON_AGEN_DEMUX |
  2478. + EBU_CON_SETUP | EBU_CON_WAIT_DIS | EBU_CON_PW_8BIT |
  2479. + EBU_CON_ALEC(3) | EBU_CON_BCGEN_INTEL |
  2480. + EBU_CON_WAITWRC(2) | EBU_CON_WAITRDC(2) |
  2481. + EBU_CON_HOLDC(1) | EBU_CON_RECOVC(1) |
  2482. + EBU_CON_CMULT_4);
  2483. +
  2484. + if (ebu_region0_addrsel_mask == 3)
  2485. + ltq_writel(&ltq_ebu_regs->con_1, EBU_CON_AGEN_DEMUX |
  2486. + EBU_CON_WAIT_DIS | EBU_CON_PW_16BIT |
  2487. + EBU_CON_ALEC(3) | EBU_CON_BCGEN_INTEL |
  2488. + EBU_CON_WAITWRC(7) | EBU_CON_WAITRDC(3) |
  2489. + EBU_CON_HOLDC(3) | EBU_CON_RECOVC(3) |
  2490. + EBU_CON_CMULT_16);
  2491. + } else
  2492. + ltq_clrbits(&ltq_ebu_regs->addr_sel_1, EBU_ADDRSEL_REGEN);
  2493. +}
  2494. +
  2495. +void *flash_swap_addr(unsigned long addr)
  2496. +{
  2497. + return (void *)(addr ^ 2);
  2498. +}
  2499. --- /dev/null
  2500. +++ b/arch/mips/cpu/mips32/vrx200/gphy.c
  2501. @@ -0,0 +1,68 @@
  2502. +/*
  2503. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  2504. + *
  2505. + * SPDX-License-Identifier: GPL-2.0+
  2506. + */
  2507. +
  2508. +#include <common.h>
  2509. +#include <asm/lantiq/io.h>
  2510. +#include <asm/arch/soc.h>
  2511. +#include <asm/arch/gphy.h>
  2512. +#include <lzma/LzmaTypes.h>
  2513. +#include <lzma/LzmaDec.h>
  2514. +#include <lzma/LzmaTools.h>
  2515. +
  2516. +static inline void ltq_gphy_decompress(const void *fw_start, const void *fw_end,
  2517. + ulong dst_addr)
  2518. +{
  2519. + const ulong fw_len = (ulong) fw_end - (ulong) fw_start;
  2520. + const ulong addr = CKSEG1ADDR(dst_addr);
  2521. +
  2522. + debug("ltq_gphy_decompress: addr %08lx, fw_start %p, fw_end %p\n",
  2523. + addr, fw_start, fw_end);
  2524. +
  2525. + SizeT lzma_len = 65536;
  2526. + int ret = lzmaBuffToBuffDecompress(
  2527. + (unsigned char *)addr, &lzma_len,
  2528. + (unsigned char *)fw_start, fw_len);
  2529. +}
  2530. +
  2531. +void ltq_gphy_phy11g_a1x_load(ulong addr)
  2532. +{
  2533. + extern ulong __ltq_fw_phy11g_a1x_start;
  2534. + extern ulong __ltq_fw_phy11g_a1x_end;
  2535. +
  2536. + ltq_gphy_decompress(&__ltq_fw_phy11g_a1x_start,
  2537. + &__ltq_fw_phy11g_a1x_end,
  2538. + addr);
  2539. +}
  2540. +
  2541. +void ltq_gphy_phy11g_a2x_load(ulong addr)
  2542. +{
  2543. + extern ulong __ltq_fw_phy11g_a2x_start;
  2544. + extern ulong __ltq_fw_phy11g_a2x_end;
  2545. +
  2546. + ltq_gphy_decompress(&__ltq_fw_phy11g_a2x_start,
  2547. + &__ltq_fw_phy11g_a2x_end,
  2548. + addr);
  2549. +}
  2550. +
  2551. +void ltq_gphy_phy22f_a1x_load(ulong addr)
  2552. +{
  2553. + extern ulong __ltq_fw_phy22f_a1x_start;
  2554. + extern ulong __ltq_fw_phy22f_a1x_end;
  2555. +
  2556. + ltq_gphy_decompress(&__ltq_fw_phy22f_a1x_start,
  2557. + &__ltq_fw_phy22f_a1x_end,
  2558. + addr);
  2559. +}
  2560. +
  2561. +void ltq_gphy_phy22f_a2x_load(ulong addr)
  2562. +{
  2563. + extern ulong __ltq_fw_phy22f_a2x_start;
  2564. + extern ulong __ltq_fw_phy22f_a2x_end;
  2565. +
  2566. + ltq_gphy_decompress(&__ltq_fw_phy22f_a2x_start,
  2567. + &__ltq_fw_phy22f_a2x_end,
  2568. + addr);
  2569. +}
  2570. --- /dev/null
  2571. +++ b/arch/mips/cpu/mips32/vrx200/gphy_fw.S
  2572. @@ -0,0 +1,27 @@
  2573. +/*
  2574. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  2575. + *
  2576. + * SPDX-License-Identifier: GPL-2.0+
  2577. + */
  2578. +
  2579. +#include <asm/asm.h>
  2580. +
  2581. + .section .rodata.__ltq_fw_phy11g_a1x
  2582. +EXPORT(__ltq_fw_phy11g_a1x_start)
  2583. + .incbin "fw_phy11g_a1x.blob"
  2584. +EXPORT(__ltq_fw_phy11g_a1x_end)
  2585. +
  2586. + .section .rodata.__ltq_fw_phy11g_a2x
  2587. +EXPORT(__ltq_fw_phy11g_a2x_start)
  2588. + .incbin "fw_phy11g_a2x.blob"
  2589. +EXPORT(__ltq_fw_phy11g_a2x_end)
  2590. +
  2591. + .section .rodata.__ltq_fw_phy22f_a1x
  2592. +EXPORT(__ltq_fw_phy22f_a1x_start)
  2593. + .incbin "fw_phy22f_a1x.blob"
  2594. +EXPORT(__ltq_fw_phy22f_a1x_end)
  2595. +
  2596. + .section .rodata.__ltq_fw_phy22f_a2x
  2597. +EXPORT(__ltq_fw_phy22f_a2x_start)
  2598. + .incbin "fw_phy22f_a2x.blob"
  2599. +EXPORT(__ltq_fw_phy22f_a2x_end)
  2600. --- /dev/null
  2601. +++ b/arch/mips/cpu/mips32/vrx200/mem.c
  2602. @@ -0,0 +1,57 @@
  2603. +/*
  2604. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  2605. + *
  2606. + * SPDX-License-Identifier: GPL-2.0+
  2607. + */
  2608. +
  2609. +#include <common.h>
  2610. +#include <asm/arch/soc.h>
  2611. +#include <asm/lantiq/io.h>
  2612. +
  2613. +#define LTQ_CCR03_EIGHT_BANK_MODE (1 << 0)
  2614. +#define LTQ_CCR08_CS_MAP_SHIFT 24
  2615. +#define LTQ_CCR08_CS_MAP_MASK (0x3 << LTQ_CCR08_CS_MAP_SHIFT)
  2616. +#define LTQ_CCR11_COLUMN_SIZE_SHIFT 24
  2617. +#define LTQ_CCR11_COLUMN_SIZE_MASK (0x7 << LTQ_CCR11_COLUMN_SIZE_SHIFT)
  2618. +#define LTQ_CCR11_ADDR_PINS_MASK 0x7
  2619. +#define LTQ_CCR15_MAX_COL_REG_SHIFT 24
  2620. +#define LTQ_CCR15_MAX_COL_REG_MASK (0xF << LTQ_CCR15_MAX_COL_REG_SHIFT)
  2621. +#define LTQ_CCR16_MAX_ROW_REG_MASK 0xF
  2622. +
  2623. +static void *ltq_mc_ddr_base = (void *) CKSEG1ADDR(LTQ_MC_DDR_BASE);
  2624. +
  2625. +static inline u32 ltq_mc_ccr_read(u32 index)
  2626. +{
  2627. + return ltq_readl(ltq_mc_ddr_base + LTQ_MC_DDR_CCR_OFFSET(index));
  2628. +}
  2629. +
  2630. +phys_size_t initdram(int board_type)
  2631. +{
  2632. + u32 max_col_reg, max_row_reg, column_size, addr_pins;
  2633. + u32 banks, cs_map;
  2634. + phys_size_t size;
  2635. +
  2636. + banks = (ltq_mc_ccr_read(3) & LTQ_CCR03_EIGHT_BANK_MODE) ? 8 : 4;
  2637. +
  2638. + cs_map = (ltq_mc_ccr_read(8) & LTQ_CCR08_CS_MAP_MASK) >>
  2639. + LTQ_CCR08_CS_MAP_SHIFT;
  2640. +
  2641. + column_size = (ltq_mc_ccr_read(11) & LTQ_CCR11_COLUMN_SIZE_MASK) >>
  2642. + LTQ_CCR11_COLUMN_SIZE_SHIFT;
  2643. +
  2644. + addr_pins = ltq_mc_ccr_read(11) & LTQ_CCR11_ADDR_PINS_MASK;
  2645. +
  2646. + max_col_reg = (ltq_mc_ccr_read(15) & LTQ_CCR15_MAX_COL_REG_MASK) >>
  2647. + LTQ_CCR15_MAX_COL_REG_SHIFT;
  2648. +
  2649. + max_row_reg = ltq_mc_ccr_read(16) & LTQ_CCR16_MAX_ROW_REG_MASK;
  2650. +
  2651. + /*
  2652. + * size (bytes) = 2 ^ rowsize * 2 ^ colsize * banks * chipselects
  2653. + * * datawidth (bytes)
  2654. + */
  2655. + size = (2 << (max_col_reg - column_size - 1)) *
  2656. + (2 << (max_row_reg - addr_pins - 1)) * banks * cs_map * 2;
  2657. +
  2658. + return size;
  2659. +}
  2660. --- /dev/null
  2661. +++ b/arch/mips/cpu/mips32/vrx200/mem_init.S
  2662. @@ -0,0 +1,233 @@
  2663. +/*
  2664. + * Copyright (C) 2010 Lantiq Deutschland GmbH
  2665. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  2666. + *
  2667. + * SPDX-License-Identifier: GPL-2.0+
  2668. + */
  2669. +
  2670. +#include <config.h>
  2671. +#include <asm/asm.h>
  2672. +#include <asm/regdef.h>
  2673. +#include <asm/addrspace.h>
  2674. +#include <asm/arch/soc.h>
  2675. +
  2676. +/* Must be configured in BOARDDIR */
  2677. +#include <ddr_settings.h>
  2678. +
  2679. +#define LTQ_MC_DDR_START (1 << 8)
  2680. +#define LTQ_MC_DDR_DLL_LOCK_IND 1
  2681. +
  2682. +#define CCS_ALWAYS_LAST 0x0430
  2683. +#define CCS_AHBM_CR_BURST_EN (1 << 2)
  2684. +#define CCS_FPIM_CR_BURST_EN (1 << 1)
  2685. +
  2686. +#define CCR03_EIGHT_BANK_MODE (1 << 0)
  2687. +
  2688. + /* Store given value in MC DDR CCRx register */
  2689. + .macro ccr_sw num, val
  2690. + li t1, \val
  2691. + sw t1, LTQ_MC_DDR_CCR_OFFSET(\num)(t0)
  2692. + .endm
  2693. +
  2694. +LEAF(ltq_mem_init)
  2695. + /* Load MC DDR module base */
  2696. + li t0, (LTQ_MC_DDR_BASE | KSEG1)
  2697. +
  2698. + /* Put memory controller in inactive mode */
  2699. + sw zero, LTQ_MC_DDR_CCR_OFFSET(7)(t0)
  2700. +
  2701. + /* Init MC DDR CCR registers with values from ddr_settings.h */
  2702. + ccr_sw 0, MC_CCR00_VALUE
  2703. + ccr_sw 1, MC_CCR01_VALUE
  2704. + ccr_sw 2, MC_CCR02_VALUE
  2705. + ccr_sw 3, MC_CCR03_VALUE
  2706. + ccr_sw 4, MC_CCR04_VALUE
  2707. + ccr_sw 5, MC_CCR05_VALUE
  2708. + ccr_sw 6, MC_CCR06_VALUE
  2709. + ccr_sw 7, MC_CCR07_VALUE
  2710. + ccr_sw 8, MC_CCR08_VALUE
  2711. + ccr_sw 9, MC_CCR09_VALUE
  2712. +
  2713. + ccr_sw 10, MC_CCR10_VALUE
  2714. + ccr_sw 11, MC_CCR11_VALUE
  2715. + ccr_sw 12, MC_CCR12_VALUE
  2716. + ccr_sw 13, MC_CCR13_VALUE
  2717. + ccr_sw 14, MC_CCR14_VALUE
  2718. + ccr_sw 15, MC_CCR15_VALUE
  2719. + ccr_sw 16, MC_CCR16_VALUE
  2720. + ccr_sw 17, MC_CCR17_VALUE
  2721. + ccr_sw 18, MC_CCR18_VALUE
  2722. + ccr_sw 19, MC_CCR19_VALUE
  2723. +
  2724. + ccr_sw 20, MC_CCR20_VALUE
  2725. + ccr_sw 21, MC_CCR21_VALUE
  2726. + ccr_sw 22, MC_CCR22_VALUE
  2727. + ccr_sw 23, MC_CCR23_VALUE
  2728. + ccr_sw 24, MC_CCR24_VALUE
  2729. + ccr_sw 25, MC_CCR25_VALUE
  2730. + ccr_sw 26, MC_CCR26_VALUE
  2731. + ccr_sw 27, MC_CCR27_VALUE
  2732. + ccr_sw 28, MC_CCR28_VALUE
  2733. + ccr_sw 29, MC_CCR29_VALUE
  2734. +
  2735. + ccr_sw 30, MC_CCR30_VALUE
  2736. + ccr_sw 31, MC_CCR31_VALUE
  2737. + ccr_sw 32, MC_CCR32_VALUE
  2738. + ccr_sw 33, MC_CCR33_VALUE
  2739. + ccr_sw 34, MC_CCR34_VALUE
  2740. + ccr_sw 35, MC_CCR35_VALUE
  2741. + ccr_sw 36, MC_CCR36_VALUE
  2742. + ccr_sw 37, MC_CCR37_VALUE
  2743. + ccr_sw 38, MC_CCR38_VALUE
  2744. + ccr_sw 39, MC_CCR39_VALUE
  2745. +
  2746. + ccr_sw 40, MC_CCR40_VALUE
  2747. + ccr_sw 41, MC_CCR41_VALUE
  2748. + ccr_sw 42, MC_CCR42_VALUE
  2749. + ccr_sw 43, MC_CCR43_VALUE
  2750. + ccr_sw 44, MC_CCR44_VALUE
  2751. + ccr_sw 45, MC_CCR45_VALUE
  2752. + ccr_sw 46, MC_CCR46_VALUE
  2753. +
  2754. + ccr_sw 52, MC_CCR52_VALUE
  2755. + ccr_sw 53, MC_CCR53_VALUE
  2756. + ccr_sw 54, MC_CCR54_VALUE
  2757. + ccr_sw 55, MC_CCR55_VALUE
  2758. + ccr_sw 56, MC_CCR56_VALUE
  2759. + ccr_sw 57, MC_CCR57_VALUE
  2760. + ccr_sw 58, MC_CCR58_VALUE
  2761. + ccr_sw 59, MC_CCR59_VALUE
  2762. +
  2763. + ccr_sw 60, MC_CCR60_VALUE
  2764. + ccr_sw 61, MC_CCR61_VALUE
  2765. +
  2766. + /* Disable bursts between FPI Master bus and XBAR bus */
  2767. + li t4, (LTQ_MC_GLOBAL_BASE | KSEG1)
  2768. + li t5, CCS_AHBM_CR_BURST_EN
  2769. + sw t5, CCS_ALWAYS_LAST(t4)
  2770. +
  2771. + /* Init abort condition for DRAM probe */
  2772. + move t4, zero
  2773. +
  2774. + /*
  2775. + * Put memory controller in active mode and start initialitation
  2776. + * sequence for connected DDR-SDRAM device
  2777. + */
  2778. +mc_start:
  2779. + lw t1, LTQ_MC_DDR_CCR_OFFSET(7)(t0)
  2780. + li t2, LTQ_MC_DDR_START
  2781. + or t1, t1, t2
  2782. + sw t1, LTQ_MC_DDR_CCR_OFFSET(7)(t0)
  2783. +
  2784. + /*
  2785. + * Wait until DLL has locked and core is ready for data transfers.
  2786. + * DLL lock indication is in register CCR47 and CCR48
  2787. + */
  2788. +wait_ready:
  2789. + li t1, LTQ_MC_DDR_DLL_LOCK_IND
  2790. + lw t2, LTQ_MC_DDR_CCR_OFFSET(47)(t0)
  2791. + and t2, t2, t1
  2792. + bne t1, t2, wait_ready
  2793. +
  2794. + lw t2, LTQ_MC_DDR_CCR_OFFSET(48)(t0)
  2795. + and t2, t2, t1
  2796. + bne t1, t2, wait_ready
  2797. +
  2798. +#ifdef CONFIG_SYS_DRAM_PROBE
  2799. +dram_probe:
  2800. + /* Initialization is finished after the second MC start */
  2801. + bnez t4, mc_finished
  2802. +
  2803. + /*
  2804. + * Preload register values for CCR03 and CCR11. Initial settings
  2805. + * are 8-bank mode enabled, 14 use address row bits, 10 used
  2806. + * column address bits.
  2807. + */
  2808. + li t1, CONFIG_SYS_SDRAM_BASE_UC
  2809. + li t5, MC_CCR03_VALUE
  2810. + li t6, MC_CCR11_VALUE
  2811. + addi t4, t4, 1
  2812. +
  2813. + /*
  2814. + * Store test values to DRAM at offsets 0 and 2^13 (bit 2 in bank select
  2815. + * address BA[3]) and read back the value at offset 0. If the resulting
  2816. + * value is equal to 1 we can skip to the next test. Otherwise
  2817. + * the 8-bank mode does not work with the current DRAM device,
  2818. + * thus we need to clear the according bit in register CCR03.
  2819. + */
  2820. + li t2, 1
  2821. + sw t2, 0x0(t1)
  2822. + li t3, (1 << 13)
  2823. + add t3, t3, t1
  2824. + sw zero, 0(t3)
  2825. + lw t3, 0(t1)
  2826. + bnez t3, row_col_test
  2827. +
  2828. + /* Clear CCR03.EIGHT_BANK_MODE */
  2829. + li t3, ~CCR03_EIGHT_BANK_MODE
  2830. + and t5, t5, t3
  2831. +
  2832. +row_col_test:
  2833. + /*
  2834. + * Store test values to DRAM at offsets 0, 2^27 (bit 13 of row address
  2835. + * RA[14]) and 2^26 (bit 12 of RA[14]). The chosen test values
  2836. + * represent the difference between max. row address bits (14) and used
  2837. + * row address bits. Then the read back value at offset 0 indicates
  2838. + * the useable row address bits with the current DRAM device. This
  2839. + * value must be set in the CCR11 register.
  2840. + */
  2841. + sw zero, 0(t1)
  2842. +
  2843. + li t2, 1
  2844. + li t3, (1 << 27)
  2845. + add t3, t3, t1
  2846. + sw t2, 0(t3)
  2847. +
  2848. + li t2, 2
  2849. + li t3, (1 << 26)
  2850. + add t3, t3, t1
  2851. + sw t2, 0(t3)
  2852. +
  2853. + /* Update CCR11.ADDR_PINS */
  2854. + lw t3, 0(t1)
  2855. + add t6, t6, t3
  2856. +
  2857. + /*
  2858. + * Store test values to DRAM at offsets 0, 2^10 (bit 9 of column address
  2859. + * CA[10]) and 2^9 (bit 8 of CA[10]). The chosen test values represent
  2860. + * the difference between max. column address bits (12) and used
  2861. + * column address bits. Then the read back value at offset 0 indicates
  2862. + * the useable column address bits with the current DRAM device. This
  2863. + * value must be set in the CCR11 register.
  2864. + */
  2865. + sw zero, 0(t1)
  2866. +
  2867. + li t2, 1
  2868. + li t3, (1 << 10)
  2869. + add t3, t3, t1
  2870. + sw t2, 0(t3)
  2871. +
  2872. + li t2, 2
  2873. + li t3, (1 << 9)
  2874. + add t3, t3, t1
  2875. + sw t2, 0(t3)
  2876. +
  2877. + /* Update CCR11.COLUMN_SIZE */
  2878. + lw t3, 0(t1)
  2879. + sll t3, t3, 24
  2880. + add t6, t6, t3
  2881. +
  2882. + /* Put memory controller in inactive mode */
  2883. + sw zero, LTQ_MC_DDR_CCR_OFFSET(7)(t0)
  2884. +
  2885. + /* Update CCR03 and CCR11 and restart memory controller initialiation */
  2886. + sw t5, LTQ_MC_DDR_CCR_OFFSET(3)(t0)
  2887. + sw t6, LTQ_MC_DDR_CCR_OFFSET(11)(t0)
  2888. + b mc_start
  2889. +
  2890. +mc_finished:
  2891. +#endif /* CONFIG_SYS_DRAM_PROBE */
  2892. +
  2893. + jr ra
  2894. +
  2895. + END(ltq_mem_init)
  2896. --- /dev/null
  2897. +++ b/arch/mips/cpu/mips32/vrx200/pmu.c
  2898. @@ -0,0 +1,130 @@
  2899. +/*
  2900. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  2901. + *
  2902. + * SPDX-License-Identifier: GPL-2.0+
  2903. + */
  2904. +
  2905. +#include <common.h>
  2906. +#include <asm/lantiq/io.h>
  2907. +#include <asm/lantiq/pm.h>
  2908. +#include <asm/arch/soc.h>
  2909. +
  2910. +#define LTQ_PMU_PWDCR_RESERVED ((1 << 13) | (1 << 4))
  2911. +
  2912. +#define LTQ_PMU_PWDCR_PCIELOC_EN (1 << 31)
  2913. +#define LTQ_PMU_PWDCR_GPHY (1 << 30)
  2914. +#define LTQ_PMU_PWDCR_PPE_TOP (1 << 29)
  2915. +#define LTQ_PMU_PWDCR_SWITCH (1 << 28)
  2916. +#define LTQ_PMU_PWDCR_USB1 (1 << 27)
  2917. +#define LTQ_PMU_PWDCR_USB1_PHY (1 << 26)
  2918. +#define LTQ_PMU_PWDCR_TDM (1 << 25)
  2919. +#define LTQ_PMU_PWDCR_PPE_DPLUS (1 << 24)
  2920. +#define LTQ_PMU_PWDCR_PPE_DPLUM (1 << 23)
  2921. +#define LTQ_PMU_PWDCR_PPE_EMA (1 << 22)
  2922. +#define LTQ_PMU_PWDCR_PPE_TC (1 << 21)
  2923. +#define LTQ_PMU_PWDCR_DEU (1 << 20)
  2924. +#define LTQ_PMU_PWDCR_PPE_SLL01 (1 << 19)
  2925. +#define LTQ_PMU_PWDCR_PPE_QSB (1 << 18)
  2926. +#define LTQ_PMU_PWDCR_UART1 (1 << 17)
  2927. +#define LTQ_PMU_PWDCR_SDIO (1 << 16)
  2928. +#define LTQ_PMU_PWDCR_AHBM (1 << 15)
  2929. +#define LTQ_PMU_PWDCR_FPIM (1 << 14)
  2930. +#define LTQ_PMU_PWDCR_GPTC (1 << 12)
  2931. +#define LTQ_PMU_PWDCR_LEDC (1 << 11)
  2932. +#define LTQ_PMU_PWDCR_EBU (1 << 10)
  2933. +#define LTQ_PMU_PWDCR_DSL (1 << 9)
  2934. +#define LTQ_PMU_PWDCR_SPI (1 << 8)
  2935. +#define LTQ_PMU_PWDCR_USIF (1 << 7)
  2936. +#define LTQ_PMU_PWDCR_USB0 (1 << 6)
  2937. +#define LTQ_PMU_PWDCR_DMA (1 << 5)
  2938. +#define LTQ_PMU_PWDCR_DFEV1 (1 << 3)
  2939. +#define LTQ_PMU_PWDCR_DFEV0 (1 << 2)
  2940. +#define LTQ_PMU_PWDCR_FPIS (1 << 1)
  2941. +#define LTQ_PMU_PWDCR_USB0_PHY (1 << 0)
  2942. +
  2943. +struct ltq_pmu_regs {
  2944. + u32 rsvd0[7];
  2945. + u32 pwdcr; /* Power down control */
  2946. + u32 sr; /* Power down status */
  2947. + u32 pwdcr1; /* Power down control 1 */
  2948. + u32 sr1; /* Power down status 1 */
  2949. +};
  2950. +
  2951. +static struct ltq_pmu_regs *ltq_pmu_regs =
  2952. + (struct ltq_pmu_regs *) CKSEG1ADDR(LTQ_PMU_BASE);
  2953. +
  2954. +u32 ltq_pm_map(enum ltq_pm_modules module)
  2955. +{
  2956. + u32 val;
  2957. +
  2958. + switch (module) {
  2959. + case LTQ_PM_CORE:
  2960. + val = LTQ_PMU_PWDCR_UART1 | LTQ_PMU_PWDCR_FPIM |
  2961. + LTQ_PMU_PWDCR_LEDC | LTQ_PMU_PWDCR_EBU;
  2962. + break;
  2963. + case LTQ_PM_DMA:
  2964. + val = LTQ_PMU_PWDCR_DMA;
  2965. + break;
  2966. + case LTQ_PM_ETH:
  2967. + val = LTQ_PMU_PWDCR_GPHY | LTQ_PMU_PWDCR_PPE_TOP |
  2968. + LTQ_PMU_PWDCR_SWITCH | LTQ_PMU_PWDCR_PPE_DPLUS |
  2969. + LTQ_PMU_PWDCR_PPE_DPLUM | LTQ_PMU_PWDCR_PPE_EMA |
  2970. + LTQ_PMU_PWDCR_PPE_TC | LTQ_PMU_PWDCR_PPE_SLL01 |
  2971. + LTQ_PMU_PWDCR_PPE_QSB;
  2972. + break;
  2973. + case LTQ_PM_SPI:
  2974. + val = LTQ_PMU_PWDCR_SPI;
  2975. + break;
  2976. + default:
  2977. + val = 0;
  2978. + break;
  2979. + }
  2980. +
  2981. + return val;
  2982. +}
  2983. +
  2984. +int ltq_pm_enable(enum ltq_pm_modules module)
  2985. +{
  2986. + const unsigned long timeout = 1000;
  2987. + unsigned long timebase;
  2988. + u32 sr, val;
  2989. +
  2990. + val = ltq_pm_map(module);
  2991. + if (unlikely(!val))
  2992. + return 1;
  2993. +
  2994. + ltq_clrbits(&ltq_pmu_regs->pwdcr, val);
  2995. +
  2996. + timebase = get_timer(0);
  2997. +
  2998. + do {
  2999. + sr = ltq_readl(&ltq_pmu_regs->sr);
  3000. + if (~sr & val)
  3001. + return 0;
  3002. + } while (get_timer(timebase) < timeout);
  3003. +
  3004. + return 1;
  3005. +}
  3006. +
  3007. +int ltq_pm_disable(enum ltq_pm_modules module)
  3008. +{
  3009. + u32 val;
  3010. +
  3011. + val = ltq_pm_map(module);
  3012. + if (unlikely(!val))
  3013. + return 1;
  3014. +
  3015. + ltq_setbits(&ltq_pmu_regs->pwdcr, val);
  3016. +
  3017. + return 0;
  3018. +}
  3019. +
  3020. +void ltq_pmu_init(void)
  3021. +{
  3022. + u32 set, clr;
  3023. +
  3024. + clr = ltq_pm_map(LTQ_PM_CORE);
  3025. + set = ~(LTQ_PMU_PWDCR_RESERVED | clr);
  3026. +
  3027. + ltq_clrsetbits(&ltq_pmu_regs->pwdcr, clr, set);
  3028. +}
  3029. --- /dev/null
  3030. +++ b/arch/mips/cpu/mips32/vrx200/rcu.c
  3031. @@ -0,0 +1,194 @@
  3032. +/*
  3033. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  3034. + *
  3035. + * SPDX-License-Identifier: GPL-2.0+
  3036. + */
  3037. +
  3038. +#include <common.h>
  3039. +#include <asm/lantiq/io.h>
  3040. +#include <asm/lantiq/reset.h>
  3041. +#include <asm/lantiq/cpu.h>
  3042. +#include <asm/arch/soc.h>
  3043. +
  3044. +#define LTQ_RCU_RD_GPHY0 (1 << 31) /* GPHY0 */
  3045. +#define LTQ_RCU_RD_SRST (1 << 30) /* Global SW Reset */
  3046. +#define LTQ_RCU_RD_GPHY1 (1 << 29) /* GPHY1 */
  3047. +#define LTQ_RCU_RD_ENMIP2 (1 << 28) /* Enable NMI of PLL2 */
  3048. +#define LTQ_RCU_RD_REG25_PD (1 << 26) /* Power down 2.5V regulator */
  3049. +#define LTQ_RCU_RD_ENDINIT (1 << 25) /* FPI slave bus access */
  3050. +#define LTQ_RCU_RD_PPE_ATM_TC (1 << 23) /* PPE ATM TC */
  3051. +#define LTQ_RCU_RD_PCIE (1 << 22) /* PCI-E core */
  3052. +#define LTQ_RCU_RD_ETHSW (1 << 21) /* Ethernet switch */
  3053. +#define LTQ_RCU_RD_DSP_DEN (1 << 20) /* Enable DSP JTAG */
  3054. +#define LTQ_RCU_RD_TDM (1 << 19) /* TDM module interface */
  3055. +#define LTQ_RCU_RD_ENMIP1 (1 << 18) /* Enable NMI of PLL1 */
  3056. +#define LTQ_RCU_RD_SWBCK (1 << 17) /* Switch backward compat */
  3057. +#define LTQ_RCU_RD_HSNAND (1 << 16) /* HSNAND controller */
  3058. +#define LTQ_RCU_RD_ENMIP0 (1 << 15) /* Enable NMI of PLL0 */
  3059. +#define LTQ_RCU_RD_MC (1 << 14) /* Memory Controller */
  3060. +#define LTQ_RCU_RD_PCI (1 << 13) /* PCI core */
  3061. +#define LTQ_RCU_RD_PCIE_PHY (1 << 12) /* PCI-E Phy */
  3062. +#define LTQ_RCU_RD_DFE_CORE (1 << 11) /* DFE core */
  3063. +#define LTQ_RCU_RD_SDIO (1 << 10) /* SDIO core */
  3064. +#define LTQ_RCU_RD_DMA (1 << 9) /* DMA core */
  3065. +#define LTQ_RCU_RD_PPE (1 << 8) /* PPE core */
  3066. +#define LTQ_RCU_RD_DFE (1 << 7) /* DFE core */
  3067. +#define LTQ_RCU_RD_AHB (1 << 6) /* AHB bus */
  3068. +#define LTQ_RCU_RD_HRST_CFG (1 << 5) /* HW reset configuration */
  3069. +#define LTQ_RCU_RD_USB (1 << 4) /* USB and Phy core */
  3070. +#define LTQ_RCU_RD_PPE_DSP (1 << 3) /* PPE DSP interface */
  3071. +#define LTQ_RCU_RD_FPI (1 << 2) /* FPI bus */
  3072. +#define LTQ_RCU_RD_CPU (1 << 1) /* CPU subsystem */
  3073. +#define LTQ_RCU_RD_HRST (1 << 0) /* HW reset via HRST pin */
  3074. +
  3075. +#define LTQ_RCU_STAT_BOOT_SHIFT 17
  3076. +#define LTQ_RCU_STAT_BOOT_MASK (0xF << LTQ_RCU_STAT_BOOT_SHIFT)
  3077. +#define LTQ_RCU_STAT_BOOT_H (1 << 12)
  3078. +
  3079. +#define LTQ_RCU_GP_STRAP_CLOCKSOURCE (1 << 15)
  3080. +
  3081. +struct ltq_rcu_regs {
  3082. + u32 rsvd0[4];
  3083. + u32 req; /* Reset request */
  3084. + u32 stat; /* Reset status */
  3085. + u32 usb0_cfg; /* USB0 configure */
  3086. + u32 gp_strap; /* GPIO strapping */
  3087. + u32 gfs_add0; /* GPHY0 firmware base addr */
  3088. + u32 stat2; /* SLIC and USB reset status */
  3089. + u32 pci_rdy; /* PCI boot ready */
  3090. + u32 ppe_conf; /* PPE ethernet config */
  3091. + u32 pcie_phy_con; /* PCIE PHY config/status */
  3092. + u32 usb1_cfg; /* USB1 configure */
  3093. + u32 usb_ana_cfg1a; /* USB analog config 1a */
  3094. + u32 usb_ana_cfg1b; /* USB analog config 1b */
  3095. + u32 rsvd1;
  3096. + u32 gf_mdio_add; /* GPHY0/1 MDIO address */
  3097. + u32 req2; /* SLIC and USB reset request */
  3098. + u32 ahb_endian; /* AHB bus endianess */
  3099. + u32 rsvd2[4];
  3100. + u32 gcc; /* General CPU config */
  3101. + u32 rsvd3;
  3102. + u32 gfs_add1; /* GPHY1 firmware base addr */
  3103. +};
  3104. +
  3105. +static struct ltq_rcu_regs *ltq_rcu_regs =
  3106. + (struct ltq_rcu_regs *) CKSEG1ADDR(LTQ_RCU_BASE);
  3107. +
  3108. +u32 ltq_reset_map(enum ltq_reset_modules module)
  3109. +{
  3110. + u32 val;
  3111. +
  3112. + switch (module) {
  3113. + case LTQ_RESET_CORE:
  3114. + case LTQ_RESET_SOFT:
  3115. + val = LTQ_RCU_RD_SRST | LTQ_RCU_RD_CPU | LTQ_RCU_RD_ENMIP2 |
  3116. + LTQ_RCU_RD_GPHY1 | LTQ_RCU_RD_GPHY0;
  3117. + break;
  3118. + case LTQ_RESET_DMA:
  3119. + val = LTQ_RCU_RD_DMA;
  3120. + break;
  3121. + case LTQ_RESET_ETH:
  3122. + val = LTQ_RCU_RD_PPE | LTQ_RCU_RD_ETHSW;
  3123. + break;
  3124. + case LTQ_RESET_PHY:
  3125. + val = LTQ_RCU_RD_GPHY1 | LTQ_RCU_RD_GPHY0;
  3126. + break;
  3127. + case LTQ_RESET_HARD:
  3128. + val = LTQ_RCU_RD_HRST;
  3129. + break;
  3130. + default:
  3131. + val = 0;
  3132. + break;
  3133. + }
  3134. +
  3135. + return val;
  3136. +}
  3137. +
  3138. +int ltq_reset_activate(enum ltq_reset_modules module)
  3139. +{
  3140. + u32 val;
  3141. +
  3142. + val = ltq_reset_map(module);
  3143. + if (unlikely(!val))
  3144. + return 1;
  3145. +
  3146. + ltq_setbits(&ltq_rcu_regs->req, val);
  3147. +
  3148. + return 0;
  3149. +}
  3150. +
  3151. +int ltq_reset_deactivate(enum ltq_reset_modules module)
  3152. +{
  3153. + u32 val;
  3154. +
  3155. + val = ltq_reset_map(module);
  3156. + if (unlikely(!val))
  3157. + return 1;
  3158. +
  3159. + ltq_clrbits(&ltq_rcu_regs->req, val);
  3160. +
  3161. + return 0;
  3162. +}
  3163. +
  3164. +enum ltq_boot_select ltq_boot_select(void)
  3165. +{
  3166. + u32 stat;
  3167. + unsigned int bootstrap;
  3168. +
  3169. + /*
  3170. + * Boot select value is built from bits 20-17 and bit 12.
  3171. + * The bit sequence is read as 4-2-1-0-3.
  3172. + */
  3173. + stat = ltq_readl(&ltq_rcu_regs->stat);
  3174. + bootstrap = ((stat & LTQ_RCU_STAT_BOOT_H) << 4) |
  3175. + ((stat & LTQ_RCU_STAT_BOOT_MASK) >> LTQ_RCU_STAT_BOOT_SHIFT);
  3176. +
  3177. + switch (bootstrap) {
  3178. + case 0:
  3179. + return BOOT_NOR_NO_BOOTROM;
  3180. + case 1:
  3181. + return BOOT_RGMII1;
  3182. + case 2:
  3183. + return BOOT_NOR;
  3184. + case 4:
  3185. + return BOOT_UART_NO_EEPROM;
  3186. + case 6:
  3187. + return BOOT_PCI;
  3188. + case 8:
  3189. + return BOOT_UART;
  3190. + case 10:
  3191. + return BOOT_SPI;
  3192. + case 12:
  3193. + return BOOT_NAND;
  3194. + default:
  3195. + return BOOT_UNKNOWN;
  3196. + }
  3197. +}
  3198. +
  3199. +void ltq_rcu_gphy_boot(unsigned int id, ulong addr)
  3200. +{
  3201. + u32 module;
  3202. + void *gfs_add;
  3203. +
  3204. + switch (id) {
  3205. + case 0:
  3206. + module = LTQ_RCU_RD_GPHY0;
  3207. + gfs_add = &ltq_rcu_regs->gfs_add0;
  3208. + break;
  3209. + case 1:
  3210. + module = LTQ_RCU_RD_GPHY1;
  3211. + gfs_add = &ltq_rcu_regs->gfs_add1;
  3212. + break;
  3213. + default:
  3214. + BUG();
  3215. + }
  3216. +
  3217. + /* Stop and reset GPHY */
  3218. + ltq_setbits(&ltq_rcu_regs->req, module);
  3219. +
  3220. + /* Configure firmware and boot address */
  3221. + ltq_writel(gfs_add, CPHYSADDR(addr & 0xFFFFC000));
  3222. +
  3223. + /* Start GPHY by releasing reset */
  3224. + ltq_clrbits(&ltq_rcu_regs->req, module);
  3225. +}
  3226. --- /dev/null
  3227. +++ b/arch/mips/include/asm/arch-danube/config.h
  3228. @@ -0,0 +1,163 @@
  3229. +/*
  3230. + * Copyright (C) 2007-2010 Lantiq Deutschland GmbH
  3231. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  3232. + *
  3233. + * SPDX-License-Identifier: GPL-2.0+
  3234. + *
  3235. + * Common board configuration for Lantiq XWAY Danube family
  3236. + *
  3237. + * Use following defines in your board config to enable specific features
  3238. + * and drivers for this SoC:
  3239. + *
  3240. + * CONFIG_LTQ_SUPPORT_UART
  3241. + * - support the Danube ASC/UART interface and console
  3242. + *
  3243. + * CONFIG_LTQ_SUPPORT_NOR_FLASH
  3244. + * - support a parallel NOR flash via the CFI interface in flash bank 0
  3245. + *
  3246. + * CONFIG_LTQ_SUPPORT_ETHERNET
  3247. + * - support the Danube ETOP and MAC interface
  3248. + *
  3249. + * CONFIG_LTQ_SUPPORT_SPI_FLASH
  3250. + * - support the Danube SPI interface and serial flash drivers
  3251. + * - specific SPI flash drivers must be configured separately
  3252. + */
  3253. +
  3254. +#ifndef __DANUBE_CONFIG_H__
  3255. +#define __DANUBE_CONFIG_H__
  3256. +
  3257. +/* CPU and SoC type */
  3258. +#define CONFIG_SOC_LANTIQ
  3259. +#define CONFIG_SOC_XWAY_DANUBE
  3260. +
  3261. +/* Cache configuration */
  3262. +#define CONFIG_SYS_MIPS_CACHE_MODE CONF_CM_CACHABLE_NONCOHERENT
  3263. +#define CONFIG_SYS_DCACHE_SIZE (16 * 1024)
  3264. +#define CONFIG_SYS_ICACHE_SIZE (16 * 1024)
  3265. +#define CONFIG_SYS_CACHELINE_SIZE 32
  3266. +#define CONFIG_SYS_MIPS_CACHE_EXT_INIT
  3267. +
  3268. +/*
  3269. + * Supported clock modes
  3270. + * PLL0 clock output is 333 MHz
  3271. + * PLL1 clock output is 262.144 MHz
  3272. + */
  3273. +#define LTQ_CLK_CPU_333_DDR_167 0 /* Base PLL0, OCP 2 */
  3274. +#define LTQ_CLK_CPU_111_DDR_111 1 /* Base PLL0, OCP 1 */
  3275. +
  3276. +/* CPU speed */
  3277. +#define CONFIG_SYS_CLOCK_MODE LTQ_CLK_CPU_333_DDR_167
  3278. +#define CONFIG_SYS_MIPS_TIMER_FREQ 166666667
  3279. +#define CONFIG_SYS_HZ 1000
  3280. +
  3281. +/* RAM */
  3282. +#define CONFIG_NR_DRAM_BANKS 1
  3283. +#define CONFIG_SYS_SDRAM_BASE 0x80000000
  3284. +#define CONFIG_SYS_MEMTEST_START 0x81000000
  3285. +#define CONFIG_SYS_MEMTEST_END 0x82000000
  3286. +#define CONFIG_SYS_LOAD_ADDR 0x81000000
  3287. +#define CONFIG_SYS_INIT_SP_OFFSET 0x4000
  3288. +
  3289. +/* SRAM */
  3290. +#define CONFIG_SYS_SRAM_BASE 0xBE1A0000
  3291. +#define CONFIG_SYS_SRAM_SIZE 0x10000
  3292. +
  3293. +/* ASC/UART driver and console */
  3294. +#define CONFIG_LANTIQ_SERIAL
  3295. +#define CONFIG_SYS_BAUDRATE_TABLE { 9600, 19200, 38400, 57600, 115200 }
  3296. +
  3297. +/* GPIO */
  3298. +#define CONFIG_LANTIQ_GPIO
  3299. +#define CONFIG_LTQ_GPIO_MAX_BANKS 2
  3300. +
  3301. +/* FLASH driver */
  3302. +#if defined(CONFIG_LTQ_SUPPORT_NOR_FLASH)
  3303. +#define CONFIG_SYS_MAX_FLASH_BANKS 1
  3304. +#define CONFIG_SYS_MAX_FLASH_SECT 256
  3305. +#define CONFIG_SYS_FLASH_BASE 0xB0000000
  3306. +#define CONFIG_FLASH_16BIT
  3307. +#define CONFIG_SYS_FLASH_CFI
  3308. +#define CONFIG_FLASH_CFI_DRIVER
  3309. +#define CONFIG_SYS_FLASH_CFI_WIDTH FLASH_CFI_16BIT
  3310. +#define CONFIG_SYS_FLASH_USE_BUFFER_WRITE
  3311. +#define CONFIG_FLASH_SHOW_PROGRESS 50
  3312. +#define CONFIG_SYS_FLASH_PROTECTION
  3313. +#define CONFIG_CFI_FLASH_USE_WEAK_ADDR_SWAP
  3314. +
  3315. +#define CONFIG_CMD_FLASH
  3316. +#else
  3317. +#define CONFIG_SYS_NO_FLASH
  3318. +#endif /* CONFIG_NOR_FLASH */
  3319. +
  3320. +#if defined(CONFIG_LTQ_SUPPORT_SPI_FLASH)
  3321. +#define CONFIG_LANTIQ_SPI
  3322. +#define CONFIG_SPI_FLASH
  3323. +
  3324. +#define CONFIG_CMD_SF
  3325. +#define CONFIG_CMD_SPI
  3326. +#endif
  3327. +
  3328. +#if defined(CONFIG_LTQ_SUPPORT_NAND_FLASH)
  3329. +#define CONFIG_NAND_LANTIQ
  3330. +#define CONFIG_SYS_MAX_NAND_DEVICE 1
  3331. +#define CONFIG_SYS_NAND_BASE 0xB4000000
  3332. +
  3333. +#define CONFIG_CMD_NAND
  3334. +#endif
  3335. +
  3336. +#if defined(CONFIG_LTQ_SUPPORT_ETHERNET)
  3337. +#define CONFIG_LANTIQ_DMA
  3338. +#define CONFIG_LANTIQ_DANUBE_ETOP
  3339. +
  3340. +#define CONFIG_PHYLIB
  3341. +#define CONFIG_MII
  3342. +
  3343. +#define CONFIG_CMD_MII
  3344. +#define CONFIG_CMD_NET
  3345. +#endif
  3346. +
  3347. +#define CONFIG_SPL_MAX_SIZE (32 * 1024)
  3348. +#define CONFIG_SPL_BSS_MAX_SIZE (8 * 1024)
  3349. +#define CONFIG_SPL_STACK_MAX_SIZE (8 * 1024)
  3350. +#define CONFIG_SPL_MALLOC_MAX_SIZE (32 * 1024)
  3351. +/*#define CONFIG_SPL_STACK_BSS_IN_SRAM*/
  3352. +
  3353. +#if defined(CONFIG_SPL_STACK_BSS_IN_SRAM)
  3354. +#define CONFIG_SPL_STACK_BASE (CONFIG_SYS_SRAM_BASE + \
  3355. + CONFIG_SPL_MAX_SIZE + \
  3356. + CONFIG_SPL_STACK_MAX_SIZE - 1)
  3357. +#define CONFIG_SPL_BSS_BASE (CONFIG_SPL_STACK_BASE + 1)
  3358. +#define CONFIG_SPL_MALLOC_BASE (CONFIG_SYS_SDRAM_BASE + \
  3359. + CONFIG_SYS_INIT_SP_OFFSET)
  3360. +#else
  3361. +#define CONFIG_SPL_STACK_BASE (CONFIG_SYS_SDRAM_BASE + \
  3362. + CONFIG_SYS_INIT_SP_OFFSET + \
  3363. + CONFIG_SPL_STACK_MAX_SIZE - 1)
  3364. +#define CONFIG_SPL_BSS_BASE (CONFIG_SPL_STACK_BASE + 1)
  3365. +#define CONFIG_SPL_MALLOC_BASE (CONFIG_SPL_BSS_BASE + \
  3366. + CONFIG_SPL_BSS_MAX_SIZE)
  3367. +#endif
  3368. +
  3369. +#if defined(CONFIG_SYS_BOOT_RAM)
  3370. +#define CONFIG_SYS_TEXT_BASE 0xa0100000
  3371. +#define CONFIG_SKIP_LOWLEVEL_INIT
  3372. +#define CONFIG_SYS_DISABLE_CACHE
  3373. +#endif
  3374. +
  3375. +#if defined(CONFIG_SYS_BOOT_NOR)
  3376. +#define CONFIG_SYS_TEXT_BASE 0xB0000000
  3377. +#endif
  3378. +
  3379. +#if defined(CONFIG_SYS_BOOT_NORSPL)
  3380. +#define CONFIG_SYS_TEXT_BASE 0x80100000
  3381. +#define CONFIG_SPL_TEXT_BASE 0xB0000000
  3382. +#endif
  3383. +
  3384. +#if defined(CONFIG_SYS_BOOT_NOR) || defined(CONFIG_SYS_BOOT_NORSPL)
  3385. +#define CONFIG_SYS_XWAY_EBU_BOOTCFG 0x688C688C
  3386. +#define CONFIG_XWAY_SWAP_BYTES
  3387. +#endif
  3388. +
  3389. +#define CONFIG_SYS_MONITOR_BASE CONFIG_SYS_TEXT_BASE
  3390. +
  3391. +#endif /* __DANUBE_CONFIG_H__ */
  3392. --- /dev/null
  3393. +++ b/arch/mips/include/asm/arch-danube/gpio.h
  3394. @@ -0,0 +1,12 @@
  3395. +/*
  3396. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  3397. + *
  3398. + * SPDX-License-Identifier: GPL-2.0+
  3399. + */
  3400. +
  3401. +#ifndef __DANUBE_GPIO_H__
  3402. +#define __DANUBE_GPIO_H__
  3403. +
  3404. +#include <asm/lantiq/gpio.h>
  3405. +
  3406. +#endif /* __DANUBE_GPIO_H__ */
  3407. --- /dev/null
  3408. +++ b/arch/mips/include/asm/arch-danube/nand.h
  3409. @@ -0,0 +1,13 @@
  3410. +/*
  3411. + * Copyright (C) 2012-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  3412. + *
  3413. + * SPDX-License-Identifier: GPL-2.0+
  3414. + */
  3415. +
  3416. +#ifndef __DANUBE_NAND_H__
  3417. +#define __DANUBE_NAND_H__
  3418. +
  3419. +struct nand_chip;
  3420. +int ltq_nand_init(struct nand_chip *nand);
  3421. +
  3422. +#endif /* __DANUBE_NAND_H__ */
  3423. --- /dev/null
  3424. +++ b/arch/mips/include/asm/arch-danube/soc.h
  3425. @@ -0,0 +1,38 @@
  3426. +/*
  3427. + * Copyright (C) 2007-2010 Lantiq Deutschland GmbH
  3428. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  3429. + *
  3430. + * SPDX-License-Identifier: GPL-2.0+
  3431. + */
  3432. +
  3433. +#ifndef __DANUBE_SOC_H__
  3434. +#define __DANUBE_SOC_H__
  3435. +
  3436. +#define LTQ_ASC0_BASE 0x1E100400
  3437. +#define LTQ_SPI_BASE 0x1E100800
  3438. +#define LTQ_GPIO_BASE 0x1E100B00
  3439. +#define LTQ_SSIO_BASE 0x1E100BB0
  3440. +#define LTQ_ASC1_BASE 0x1E100C00
  3441. +#define LTQ_DMA_BASE 0x1E104100
  3442. +
  3443. +#define LTQ_EBU_BASE 0x1E105300
  3444. +#define LTQ_EBU_REGION0_BASE 0x10000000
  3445. +#define LTQ_EBU_REGION1_BASE 0x14000000
  3446. +#define LTQ_EBU_NAND_BASE (LTQ_EBU_BASE + 0xB0)
  3447. +
  3448. +#define LTQ_PPE_BASE 0x1E180000
  3449. +#define LTQ_PPE_ETOP_BASE (LTQ_PPE_BASE + 0x11800)
  3450. +#define LTQ_PPE_ENET0_BASE (LTQ_PPE_BASE + 0x11840)
  3451. +
  3452. +#define LTQ_PMU_BASE 0x1F102000
  3453. +#define LTQ_CGU_BASE 0x1F103000
  3454. +#define LTQ_MPS_BASE 0x1F107000
  3455. +#define LTQ_CHIPID_BASE (LTQ_MPS_BASE + 0x340)
  3456. +#define LTQ_RCU_BASE 0x1F203000
  3457. +
  3458. +#define LTQ_MC_GEN_BASE 0x1F800000
  3459. +#define LTQ_MC_SDR_BASE 0x1F800200
  3460. +#define LTQ_MC_DDR_BASE 0x1F801000
  3461. +#define LTQ_MC_DDR_DC_OFFSET(x) (x * 0x10)
  3462. +
  3463. +#endif /* __DANUBE_SOC_H__ */
  3464. --- /dev/null
  3465. +++ b/arch/mips/include/asm/arch-vrx200/config.h
  3466. @@ -0,0 +1,187 @@
  3467. +/*
  3468. + * Copyright (C) 2010 Lantiq Deutschland GmbH
  3469. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  3470. + *
  3471. + * SPDX-License-Identifier: GPL-2.0+
  3472. + *
  3473. + * Common board configuration for Lantiq XWAY VRX200 family
  3474. + *
  3475. + * Use following defines in your board config to enable specific features
  3476. + * and drivers for this SoC:
  3477. + *
  3478. + * CONFIG_LTQ_SUPPORT_UART
  3479. + * - support the VRX200 ASC/UART interface and console
  3480. + *
  3481. + * CONFIG_LTQ_SUPPORT_NOR_FLASH
  3482. + * - support a parallel NOR flash via the CFI interface in flash bank 0
  3483. + *
  3484. + * CONFIG_LTQ_SUPPORT_ETHERNET
  3485. + * - support the VRX200 internal switch
  3486. + *
  3487. + * CONFIG_LTQ_SUPPORT_SPI_FLASH
  3488. + * - support the VRX200 SPI interface and serial flash drivers
  3489. + * - specific SPI flash drivers must be configured separately
  3490. + *
  3491. + * CONFIG_LTQ_SUPPORT_SPL_SPI_FLASH
  3492. + * - build a preloader that runs in the internal SRAM and loads
  3493. + * the U-Boot from SPI flash into RAM
  3494. + */
  3495. +
  3496. +#ifndef __VRX200_CONFIG_H__
  3497. +#define __VRX200_CONFIG_H__
  3498. +
  3499. +/* CPU and SoC type */
  3500. +#define CONFIG_SOC_LANTIQ
  3501. +#define CONFIG_SOC_XWAY_VRX200
  3502. +
  3503. +/* Cache configuration */
  3504. +#define CONFIG_SYS_MIPS_CACHE_MODE CONF_CM_CACHABLE_NONCOHERENT
  3505. +#define CONFIG_SYS_DCACHE_SIZE (32 * 1024)
  3506. +#define CONFIG_SYS_ICACHE_SIZE (32 * 1024)
  3507. +#define CONFIG_SYS_CACHELINE_SIZE 32
  3508. +#define CONFIG_SYS_MIPS_CACHE_EXT_INIT
  3509. +
  3510. +/*
  3511. + * Supported clock modes
  3512. + * PLL0 clock output is 1000 MHz
  3513. + * PLL1 clock output is 393.219 MHz
  3514. + */
  3515. +#define LTQ_CLK_CPU_600_DDR_300 0 /* Base PLL0, OCP 2 */
  3516. +#define LTQ_CLK_CPU_600_DDR_200 1 /* Base PLL0, OCP 3 */
  3517. +#define LTQ_CLK_CPU_500_DDR_250 2 /* Base PLL0, OCP 2 */
  3518. +#define LTQ_CLK_CPU_500_DDR_200 3 /* Base PLL0, OCP 2.5 */
  3519. +#define LTQ_CLK_CPU_333_DDR_167 4 /* Base PLL0, OCP 2 */
  3520. +#define LTQ_CLK_CPU_167_DDR_167 5 /* Base PLL0, OCP 1 */
  3521. +#define LTQ_CLK_CPU_125_DDR_125 6 /* Base PLL0, OCP 1 */
  3522. +#define LTQ_CLK_CPU_393_DDR_197 7 /* Base PLL1, OCP 2 */
  3523. +#define LTQ_CLK_CPU_197_DDR_197 8 /* Base PLL1, OCP 1 */
  3524. +
  3525. +/* CPU speed */
  3526. +#define CONFIG_SYS_CLOCK_MODE LTQ_CLK_CPU_500_DDR_250
  3527. +#define CONFIG_SYS_MIPS_TIMER_FREQ 250000000
  3528. +#define CONFIG_SYS_HZ 1000
  3529. +
  3530. +/* RAM */
  3531. +#define CONFIG_NR_DRAM_BANKS 1
  3532. +#define CONFIG_SYS_SDRAM_BASE 0x80000000
  3533. +#define CONFIG_SYS_SDRAM_BASE_UC 0xa0000000
  3534. +#define CONFIG_SYS_MEMTEST_START 0x81000000
  3535. +#define CONFIG_SYS_MEMTEST_END 0x82000000
  3536. +#define CONFIG_SYS_LOAD_ADDR 0x81000000
  3537. +#define CONFIG_SYS_INIT_SP_OFFSET (32 * 1024)
  3538. +
  3539. +/* SRAM */
  3540. +#define CONFIG_SYS_SRAM_BASE 0xBE220000
  3541. +#define CONFIG_SYS_SRAM_SIZE 0x10000
  3542. +
  3543. +/* ASC/UART driver and console */
  3544. +#define CONFIG_LANTIQ_SERIAL
  3545. +#define CONFIG_SYS_BAUDRATE_TABLE { 9600, 19200, 38400, 57600, 115200 }
  3546. +
  3547. +/* GPIO */
  3548. +#define CONFIG_LANTIQ_GPIO
  3549. +#define CONFIG_LTQ_GPIO_MAX_BANKS 3
  3550. +#define CONFIG_LTQ_HAS_GPIO_BANK3
  3551. +
  3552. +/* FLASH driver */
  3553. +#if defined(CONFIG_LTQ_SUPPORT_NOR_FLASH)
  3554. +#ifndef CONFIG_SYS_MAX_FLASH_BANKS
  3555. +#define CONFIG_SYS_MAX_FLASH_BANKS 1
  3556. +#endif
  3557. +#define CONFIG_SYS_MAX_FLASH_SECT 256
  3558. +#define CONFIG_SYS_FLASH_BASE 0xB0000000
  3559. +#define CONFIG_SYS_FLASH2_BASE 0xB4000000
  3560. +#define CONFIG_FLASH_16BIT
  3561. +#define CONFIG_SYS_FLASH_CFI
  3562. +#define CONFIG_FLASH_CFI_DRIVER
  3563. +#define CONFIG_SYS_FLASH_CFI_WIDTH FLASH_CFI_16BIT
  3564. +#define CONFIG_SYS_FLASH_USE_BUFFER_WRITE
  3565. +#define CONFIG_FLASH_SHOW_PROGRESS 50
  3566. +#define CONFIG_SYS_FLASH_PROTECTION
  3567. +#define CONFIG_CFI_FLASH_USE_WEAK_ADDR_SWAP
  3568. +
  3569. +#define CONFIG_CMD_FLASH
  3570. +#else
  3571. +#define CONFIG_SYS_NO_FLASH
  3572. +#endif /* CONFIG_NOR_FLASH */
  3573. +
  3574. +#if defined(CONFIG_LTQ_SUPPORT_SPI_FLASH)
  3575. +#define CONFIG_LANTIQ_SPI
  3576. +#define CONFIG_SPI_FLASH
  3577. +
  3578. +#define CONFIG_CMD_SF
  3579. +#define CONFIG_CMD_SPI
  3580. +#endif
  3581. +
  3582. +#if defined(CONFIG_LTQ_SUPPORT_NAND_FLASH)
  3583. +#define CONFIG_NAND_LANTIQ
  3584. +#define CONFIG_SYS_MAX_NAND_DEVICE 1
  3585. +#define CONFIG_SYS_NAND_BASE 0xB4000000
  3586. +
  3587. +#define CONFIG_CMD_NAND
  3588. +#endif
  3589. +
  3590. +#if defined(CONFIG_LTQ_SUPPORT_ETHERNET)
  3591. +#define CONFIG_LANTIQ_DMA
  3592. +#define CONFIG_LANTIQ_VRX200_SWITCH
  3593. +#define CONFIG_PHY_LANTIQ
  3594. +
  3595. +#define CONFIG_SYS_RX_ETH_BUFFER 8
  3596. +#define CONFIG_PHYLIB
  3597. +#define CONFIG_MII
  3598. +#define CONFIG_UDP_CHECKSUM
  3599. +
  3600. +#define CONFIG_CMD_MII
  3601. +#define CONFIG_CMD_NET
  3602. +#endif
  3603. +
  3604. +#define CONFIG_SPL_MAX_SIZE (32 * 1024)
  3605. +#define CONFIG_SPL_BSS_MAX_SIZE (8 * 1024)
  3606. +#define CONFIG_SPL_STACK_MAX_SIZE (8 * 1024)
  3607. +#define CONFIG_SPL_MALLOC_MAX_SIZE (32 * 1024)
  3608. +#define CONFIG_SPL_STACK_BSS_IN_SRAM
  3609. +
  3610. +#if defined(CONFIG_SPL_STACK_BSS_IN_SRAM)
  3611. +#define CONFIG_SPL_STACK_BASE (CONFIG_SYS_SRAM_BASE + \
  3612. + CONFIG_SPL_MAX_SIZE + \
  3613. + CONFIG_SPL_STACK_MAX_SIZE - 1)
  3614. +#define CONFIG_SPL_BSS_BASE (CONFIG_SPL_STACK_BASE + 1)
  3615. +#define CONFIG_SPL_MALLOC_BASE (CONFIG_SYS_SDRAM_BASE + \
  3616. + CONFIG_SYS_INIT_SP_OFFSET)
  3617. +#else
  3618. +#define CONFIG_SPL_STACK_BASE (CONFIG_SYS_SDRAM_BASE + \
  3619. + CONFIG_SYS_INIT_SP_OFFSET + \
  3620. + CONFIG_SPL_STACK_MAX_SIZE - 1)
  3621. +#define CONFIG_SPL_BSS_BASE (CONFIG_SPL_STACK_BASE + 1)
  3622. +#define CONFIG_SPL_MALLOC_BASE (CONFIG_SPL_BSS_BASE + \
  3623. + CONFIG_SPL_BSS_MAX_SIZE)
  3624. +#endif
  3625. +
  3626. +#if defined(CONFIG_SYS_BOOT_RAM)
  3627. +#define CONFIG_SYS_TEXT_BASE 0xA0100000
  3628. +#define CONFIG_SKIP_LOWLEVEL_INIT
  3629. +#define CONFIG_SYS_DISABLE_CACHE
  3630. +#endif
  3631. +
  3632. +#if defined(CONFIG_SYS_BOOT_NOR)
  3633. +#define CONFIG_SYS_TEXT_BASE 0xB0000000
  3634. +#endif
  3635. +
  3636. +#if defined(CONFIG_SYS_BOOT_SFSPL)
  3637. +#define CONFIG_SYS_TEXT_BASE 0x80100000
  3638. +#define CONFIG_SPL_TEXT_BASE 0xBE220000
  3639. +#endif
  3640. +
  3641. +#if defined(CONFIG_SYS_BOOT_NORSPL)
  3642. +#define CONFIG_SYS_TEXT_BASE 0x80100000
  3643. +#define CONFIG_SPL_TEXT_BASE 0xB0000000
  3644. +#endif
  3645. +
  3646. +#if defined(CONFIG_SYS_BOOT_NOR) || defined(CONFIG_SYS_BOOT_NORSPL)
  3647. +#define CONFIG_SYS_XWAY_EBU_BOOTCFG 0x688C688C
  3648. +#define CONFIG_XWAY_SWAP_BYTES
  3649. +#endif
  3650. +
  3651. +#define CONFIG_SYS_MONITOR_BASE CONFIG_SYS_TEXT_BASE
  3652. +
  3653. +#endif /* __VRX200_CONFIG_H__ */
  3654. --- /dev/null
  3655. +++ b/arch/mips/include/asm/arch-vrx200/gphy.h
  3656. @@ -0,0 +1,65 @@
  3657. +/*
  3658. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  3659. + *
  3660. + * SPDX-License-Identifier: GPL-2.0+
  3661. + */
  3662. +
  3663. +#ifndef __VRX200_GPHY_H__
  3664. +#define __VRX200_GPHY_H__
  3665. +
  3666. +enum ltq_gphy_clk {
  3667. + /* XTAL 36 MHz input */
  3668. + LTQ_GPHY_CLK_36MHZ_XTAL = 1,
  3669. + /* 25 MHz from PLL0 with divider */
  3670. + LTQ_GPHY_CLK_25MHZ_PLL0 = 2,
  3671. + /* derived from PLL2 output (XTAL is 36 MHz) */
  3672. + LTQ_GPHY_CLK_24MHZ_PLL2 = 3,
  3673. + /* 25 MHz Clock from Pin GPIO3 */
  3674. + LTQ_GPHY_CLK_25MHZ_GPIO3 = 4,
  3675. +};
  3676. +
  3677. +/*
  3678. + * Load PHY11G firmware for VRX200 v1.1 to given RAM address
  3679. + *
  3680. + * Address must be 16k aligned!
  3681. + */
  3682. +extern void ltq_gphy_phy11g_a1x_load(ulong addr);
  3683. +
  3684. +/*
  3685. + * Load PHY11G firmware for VRX200 v1.2 to given RAM address
  3686. + *
  3687. + * Address must be 16k aligned!
  3688. + */
  3689. +extern void ltq_gphy_phy11g_a2x_load(ulong addr);
  3690. +
  3691. +/*
  3692. + * Load PHY22F firmware for VRX200 v1.1 to given RAM address
  3693. + *
  3694. + * Address must be 16k aligned!
  3695. + */
  3696. +extern void ltq_gphy_phy22f_a1x_load(ulong addr);
  3697. +
  3698. +/*
  3699. + * Load PHY22F firmware for VRX200 v1.2 to given RAM address
  3700. + *
  3701. + * Address must be 16k aligned!
  3702. + */
  3703. +extern void ltq_gphy_phy22f_a2x_load(ulong addr);
  3704. +
  3705. +/*
  3706. + * Set clock source of internal GPHYs
  3707. + *
  3708. + * According registers resides in CGU address space. Thus this function
  3709. + * is implemented by the CGU driver.
  3710. + */
  3711. +extern void ltq_cgu_gphy_clk_src(enum ltq_gphy_clk clk);
  3712. +
  3713. +/*
  3714. + * Boot internal GPHY with id from given RAM address
  3715. + *
  3716. + * According registers resides in RCU address space. Thus this function
  3717. + * is implemented by the RCU driver.
  3718. + */
  3719. +extern void ltq_rcu_gphy_boot(unsigned int id, ulong addr);
  3720. +
  3721. +#endif /* __VRX200_GPHY_H__ */
  3722. --- /dev/null
  3723. +++ b/arch/mips/include/asm/arch-vrx200/gpio.h
  3724. @@ -0,0 +1,12 @@
  3725. +/*
  3726. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  3727. + *
  3728. + * SPDX-License-Identifier: GPL-2.0+
  3729. + */
  3730. +
  3731. +#ifndef __VRX200_GPIO_H__
  3732. +#define __VRX200_GPIO_H__
  3733. +
  3734. +#include <asm/lantiq/gpio.h>
  3735. +
  3736. +#endif /* __VRX200_GPIO_H__ */
  3737. --- /dev/null
  3738. +++ b/arch/mips/include/asm/arch-vrx200/nand.h
  3739. @@ -0,0 +1,13 @@
  3740. +/*
  3741. + * Copyright (C) 2012-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  3742. + *
  3743. + * SPDX-License-Identifier: GPL-2.0+
  3744. + */
  3745. +
  3746. +#ifndef __VRX200_NAND_H__
  3747. +#define __VRX200_NAND_H__
  3748. +
  3749. +struct nand_chip;
  3750. +int ltq_nand_init(struct nand_chip *nand);
  3751. +
  3752. +#endif /* __VRX200_NAND_H__ */
  3753. --- /dev/null
  3754. +++ b/arch/mips/include/asm/arch-vrx200/soc.h
  3755. @@ -0,0 +1,45 @@
  3756. +/*
  3757. + * Copyright (C) 2010 Lantiq Deutschland GmbH
  3758. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  3759. + *
  3760. + * SPDX-License-Identifier: GPL-2.0+
  3761. + */
  3762. +
  3763. +#ifndef __VRX200_SOC_H__
  3764. +#define __VRX200_SOC_H__
  3765. +
  3766. +#define LTQ_ASC0_BASE 0x1E100400
  3767. +#define LTQ_SPI_BASE 0x1E100800
  3768. +#define LTQ_GPIO_BASE 0x1E100B00
  3769. +#define LTQ_SSIO_BASE 0x1E100BB0
  3770. +#define LTQ_ASC1_BASE 0x1E100C00
  3771. +#define LTQ_DMA_BASE 0x1E104100
  3772. +
  3773. +#define LTQ_EBU_BASE 0x1E105300
  3774. +#define LTQ_EBU_REGION0_BASE 0x10000000
  3775. +#define LTQ_EBU_REGION1_BASE 0x14000000
  3776. +#define LTQ_EBU_NAND_BASE (LTQ_EBU_BASE + 0xB0)
  3777. +
  3778. +#define LTQ_SWITCH_BASE 0x1E108000
  3779. +#define LTQ_SWITCH_CORE_BASE LTQ_SWITCH_BASE
  3780. +#define LTQ_SWITCH_TOP_PDI_BASE LTQ_SWITCH_CORE_BASE
  3781. +#define LTQ_SWITCH_BM_PDI_BASE (LTQ_SWITCH_CORE_BASE + 4 * 0x40)
  3782. +#define LTQ_SWITCH_MAC_PDI_0_BASE (LTQ_SWITCH_CORE_BASE + 4 * 0x900)
  3783. +#define LTQ_SWITCH_MAC_PDI_X_BASE(x) (LTQ_SWITCH_MAC_PDI_0_BASE + x * 0x30)
  3784. +#define LTQ_SWITCH_TOPLEVEL_BASE (LTQ_SWITCH_BASE + 4 * 0xC40)
  3785. +#define LTQ_SWITCH_MDIO_PDI_BASE (LTQ_SWITCH_TOPLEVEL_BASE)
  3786. +#define LTQ_SWITCH_MII_PDI_BASE (LTQ_SWITCH_TOPLEVEL_BASE + 4 * 0x36)
  3787. +#define LTQ_SWITCH_PMAC_PDI_BASE (LTQ_SWITCH_TOPLEVEL_BASE + 4 * 0x82)
  3788. +
  3789. +#define LTQ_PMU_BASE 0x1F102000
  3790. +#define LTQ_CGU_BASE 0x1F103000
  3791. +#define LTQ_DCDC_BASE 0x1F106A00
  3792. +#define LTQ_MPS_BASE 0x1F107000
  3793. +#define LTQ_CHIPID_BASE (LTQ_MPS_BASE + 0x340)
  3794. +#define LTQ_RCU_BASE 0x1F203000
  3795. +
  3796. +#define LTQ_MC_GLOBAL_BASE 0x1F400000
  3797. +#define LTQ_MC_DDR_BASE 0x1F401000
  3798. +#define LTQ_MC_DDR_CCR_OFFSET(x) (x * 0x10)
  3799. +
  3800. +#endif /* __VRX200_SOC_H__ */
  3801. --- /dev/null
  3802. +++ b/arch/mips/include/asm/arch-vrx200/switch.h
  3803. @@ -0,0 +1,502 @@
  3804. +/*
  3805. + * Copyright (C) 2012-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  3806. + *
  3807. + * SPDX-License-Identifier: GPL-2.0+
  3808. + */
  3809. +
  3810. +#ifndef __VRX200_SWITCH_H__
  3811. +#define __VRX200_SWITCH_H__
  3812. +
  3813. +/* Switch core registers */
  3814. +struct vr9_switch_core_regs {
  3815. + __be32 swres;
  3816. + /* TODO: implement registers */
  3817. + __be32 rsvd0[0x3f];
  3818. +};
  3819. +
  3820. +/* Switch buffer management registers */
  3821. +struct vr9_switch_bm_regs {
  3822. + struct bm_core {
  3823. + __be32 ram_val3; /* RAM value 3 */
  3824. + __be32 ram_val2; /* RAM value 2 */
  3825. + __be32 ram_val1; /* RAM value 1 */
  3826. + __be32 ram_val0; /* RAM value 0 */
  3827. + __be32 ram_addr; /* RAM address */
  3828. + __be32 ram_ctrl; /* RAM access control */
  3829. + __be32 fsqm_gctrl; /* Free segment queue global control */
  3830. + __be32 cons_sel; /* Number of consumed segments */
  3831. + __be32 cons_pkt; /* Number of consumed packet pointers */
  3832. + __be32 gctrl; /* Global control */
  3833. + __be32 queue_gctrl; /* Queue manager global control */
  3834. + /* TODO: implement registers */
  3835. + __be32 rsvd0[0x35];
  3836. + } core;
  3837. +
  3838. + struct bm_port {
  3839. + __be32 pcfg; /* Port config */
  3840. + __be32 rmon_ctrl; /* RMON control */
  3841. + } port[13];
  3842. +
  3843. + __be32 rsvd0[0x66];
  3844. +
  3845. + struct bm_queue {
  3846. + __be32 rsvd0;
  3847. + __be32 pqm_rs; /* Packet queue manager rate shape assignment */
  3848. + } queue[32];
  3849. +
  3850. + struct bm_shaper {
  3851. + __be32 ctrl; /* Rate shaper control */
  3852. + __be32 cbs; /* Rate shaper committed burst size */
  3853. + __be32 ibs; /* Rate shaper instantaneous burst size */
  3854. + __be32 cir_ext; /* Rate shaper rate exponent */
  3855. + __be32 cir_mant; /* Rate shaper rate mantissa */
  3856. + } shaper[16];
  3857. +
  3858. + __be32 rsvd1[0x2a8];
  3859. +};
  3860. +
  3861. +/* Switch parser and classification engine registers */
  3862. +struct vr9_switch_pce_regs {
  3863. + struct pce_core {
  3864. + __be32 tbl_key[16]; /* Table key data */
  3865. + __be32 tbl_mask; /* Table mask */
  3866. + __be32 tbl_val[5]; /* Table value */
  3867. + __be32 tbl_addr; /* Table entry address */
  3868. + __be32 tbl_ctrl; /* Table access control */
  3869. + __be32 tbl_stat; /* Table general status */
  3870. + __be32 age_0; /* Aging counter config 0 */
  3871. + __be32 age_1; /* Aging counter config 1 */
  3872. + __be32 pmap_1; /* Port map (monitoring) */
  3873. + __be32 pmap_2; /* Port map (multicast) */
  3874. + __be32 pmap_3; /* Port map (unknown unicast) */
  3875. + __be32 gctrl_0; /* Global control 0 */
  3876. + __be32 gctrl_1; /* Global control 1 */
  3877. + __be32 tcm_gctrl; /* Three-color marker global control */
  3878. + __be32 igmp_ctrl; /* IGMP control */
  3879. + __be32 igmp_drpm; /* IGMP default router port map */
  3880. + __be32 igmp_age_0; /* IGMP aging 0 */
  3881. + __be32 igmp_age_1; /* IGMP aging 1 */
  3882. + __be32 igmp_stat; /* IGMP status */
  3883. + __be32 wol_gctrl; /* Wake-on-LAN control */
  3884. + __be32 wol_da_0; /* Wake-on-LAN destination address 0 */
  3885. + __be32 wol_da_1; /* Wake-on-LAN destination address 1 */
  3886. + __be32 wol_da_2; /* Wake-on-LAN destination address 2 */
  3887. + __be32 wol_pw_0; /* Wake-on-LAN password 0 */
  3888. + __be32 wol_pw_1; /* Wake-on-LAN password 1 */
  3889. + __be32 wol_pw_2; /* Wake-on-LAN password 2 */
  3890. + __be32 ier_0; /* PCE global interrupt enable 0 */
  3891. + __be32 ier_1; /* PCE global interrupt enable 1 */
  3892. + __be32 isr_0; /* PCE global interrupt status 0 */
  3893. + __be32 isr_1; /* PCE global interrupt status 1 */
  3894. + __be32 parser_stat; /* Parser status */
  3895. + __be32 rsvd0[0x6];
  3896. + } core;
  3897. +
  3898. + __be32 rsvd0[0x10];
  3899. +
  3900. + struct pce_port {
  3901. + __be32 pctrl_0; /* Port control 0 */
  3902. + __be32 pctrl_1; /* Port control 1 */
  3903. + __be32 pctrl_2; /* Port control 2 */
  3904. + __be32 pctrl_3; /* Port control 3 */
  3905. + __be32 wol_ctrl; /* Wake-on-LAN control */
  3906. + __be32 vlan_ctrl; /* VLAN control */
  3907. + __be32 def_pvid; /* Default port VID */
  3908. + __be32 pstat; /* Port status */
  3909. + __be32 pier; /* Interrupt enable */
  3910. + __be32 pisr; /* Interrupt status */
  3911. + } port[13];
  3912. +
  3913. + __be32 rsvd1[0x7e];
  3914. +
  3915. + struct pce_meter {
  3916. + /* TODO: implement registers */
  3917. + __be32 rsvd0[0x7];
  3918. + } meter[8];
  3919. +
  3920. + __be32 rsvd2[0x308];
  3921. +};
  3922. +
  3923. +static inline unsigned int to_pce_tbl_key_id(unsigned int id)
  3924. +{
  3925. + BUG_ON(id > 15);
  3926. +
  3927. + return 15 - id;
  3928. +}
  3929. +
  3930. +static inline unsigned int to_pce_tbl_value_id(unsigned int id)
  3931. +{
  3932. + BUG_ON(id > 4);
  3933. +
  3934. + return 4 - id;
  3935. +}
  3936. +
  3937. +/* Switch ethernet MAC registers */
  3938. +struct vr9_switch_mac_regs {
  3939. + struct mac_core {
  3940. + __be32 test; /* MAC test */
  3941. + __be32 pfad_cfg; /* Pause frame source address config */
  3942. + __be32 pfsa_0; /* Pause frame source address 0 */
  3943. + __be32 pfsa_1; /* Pause frame source address 1 */
  3944. + __be32 pfsa_2; /* Pause frame source address 2 */
  3945. + __be32 flen; /* Frame length */
  3946. + __be32 vlan_etype_0; /* VLAN ethertype 0 */
  3947. + __be32 vlan_etype_1; /* VLAN ethertype 1 */
  3948. + __be32 ier; /* Interrupt enable */
  3949. + __be32 isr; /* Interrupt status */
  3950. + __be32 rsvd0[0x36];
  3951. + } core;
  3952. +
  3953. + struct mac_port {
  3954. + __be32 pstat; /* Port status */
  3955. + __be32 pisr; /* Interrupt status */
  3956. + __be32 pier; /* Interrupt enable */
  3957. + __be32 ctrl_0; /* Control 0 */
  3958. + __be32 ctrl_1; /* Control 1 */
  3959. + __be32 ctrl_2; /* Control 2 */
  3960. + __be32 ctrl_3; /* Control 3 */
  3961. + __be32 ctrl_4; /* Control 4 */
  3962. + __be32 ctrl_5; /* Control 5 */
  3963. + __be32 rsvd0[0x2];
  3964. + __be32 testen; /* Test enable */
  3965. + } port[13];
  3966. +
  3967. + __be32 rsvd0[0xa4];
  3968. +};
  3969. +
  3970. +/* Switch Fetch DMA registers */
  3971. +struct vr9_switch_fdma_regs {
  3972. + struct fdma_core {
  3973. + __be32 ctrl; /* FDMA control */
  3974. + __be32 stetype; /* Special tag ethertype control */
  3975. + __be32 vtetype; /* VLAN tag ethertype control */
  3976. + __be32 stat; /* FDMA status */
  3977. + __be32 ier; /* FDMA interrupt enable */
  3978. + __be32 isr; /* FDMA interrupt status */
  3979. + } core;
  3980. +
  3981. + __be32 rsvd0[0x3a];
  3982. +
  3983. + struct fdma_port {
  3984. + __be32 pctrl; /* Port control */
  3985. + __be32 prio; /* Port priority */
  3986. + __be32 pstat_0; /* Port status 0 */
  3987. + __be32 pstat_1; /* Port status 1 */
  3988. + __be32 tstamp_0; /* Egress time stamp 0 */
  3989. + __be32 tstamp_1; /* Egress time stamp 1 */
  3990. + } port[13];
  3991. +
  3992. + __be32 rsvd1[0x72];
  3993. +};
  3994. +
  3995. +/* Switch Store DMA registers */
  3996. +struct vr9_switch_sdma_regs {
  3997. + struct sdma_core {
  3998. + __be32 ctrl; /* SDMA Control */
  3999. + __be32 fcthr_1; /* Flow control threshold 1 */
  4000. + __be32 rsvd0;
  4001. + __be32 fcthr_3; /* Flow control threshold 3 */
  4002. + __be32 fcthr_4; /* Flow control threshold 4 */
  4003. + __be32 fcthr_5; /* Flow control threshold 5 */
  4004. + __be32 fcthr_6; /* Flow control threshold 6 */
  4005. + __be32 fcthr_7; /* Flow control threshold 7 */
  4006. + __be32 stat_0; /* SDMA status 0 */
  4007. + __be32 stat_1; /* SDMA status 1 */
  4008. + __be32 stat_2; /* SDMA status 2 */
  4009. + __be32 ier; /* SDMA interrupt enable */
  4010. + __be32 isr; /* SDMA interrupt status */
  4011. + } core;
  4012. +
  4013. + __be32 rsvd0[0x73];
  4014. +
  4015. + struct sdma_port {
  4016. + __be32 pctrl; /* Port control */
  4017. + __be32 prio; /* Port priority */
  4018. + __be32 pstat_0; /* Port status 0 */
  4019. + __be32 pstat_1; /* Port status 1 */
  4020. + __be32 tstamp_0; /* Ingress time stamp 0 */
  4021. + __be32 tstamp_1; /* Ingress time stamp 1 */
  4022. + } port[13];
  4023. +
  4024. + __be32 rsvd1[0x32];
  4025. +};
  4026. +
  4027. +/* Switch MDIO control and status registers */
  4028. +struct vr9_switch_mdio_regs {
  4029. + __be32 glob_ctrl; /* Global control 0 */
  4030. + __be32 rsvd0[7];
  4031. + __be32 mdio_ctrl; /* MDIO control */
  4032. + __be32 mdio_read; /* MDIO read data */
  4033. + __be32 mdio_write; /* MDIO write data */
  4034. + __be32 mdc_cfg_0; /* MDC clock configuration 0 */
  4035. + __be32 mdc_cfg_1; /* MDC clock configuration 1 */
  4036. + __be32 rsvd1[0x3];
  4037. + __be32 phy_addr[6]; /* PHY address port 5..0 */
  4038. + __be32 mdio_stat[6]; /* MDIO PHY polling status port 0..5 */
  4039. + __be32 aneg_eee[6]; /* EEE auto-neg overrides port 0..5 */
  4040. + __be32 rsvd2[0x14];
  4041. +};
  4042. +
  4043. +static inline unsigned int to_mdio_phyaddr_id(unsigned int id)
  4044. +{
  4045. + BUG_ON(id > 5);
  4046. +
  4047. + return 5 - id;
  4048. +}
  4049. +
  4050. +/* Switch xMII control registers */
  4051. +struct vr9_switch_mii_regs {
  4052. + __be32 mii_cfg0; /* xMII port 0 configuration */
  4053. + __be32 pcdu0; /* Port 0 clock delay configuration */
  4054. + __be32 mii_cfg1; /* xMII port 1 configuration */
  4055. + __be32 pcdu1; /* Port 1 clock delay configuration */
  4056. + __be32 rsvd0[0x6];
  4057. + __be32 mii_cfg5; /* xMII port 5 configuration */
  4058. + __be32 pcdu5; /* Port 5 clock delay configuration */
  4059. + __be32 rsvd1[0x14];
  4060. + __be32 rxb_ctl_0; /* Port 0 receive buffer control */
  4061. + __be32 rxb_ctl_1; /* Port 1 receive buffer control */
  4062. + __be32 rxb_ctl_5; /* Port 5 receive buffer control */
  4063. + __be32 rsvd2[0x28];
  4064. + __be32 dbg_ctl; /* Debug control */
  4065. +};
  4066. +
  4067. +/* Switch Pseudo-MAC registers */
  4068. +struct vr9_switch_pmac_regs {
  4069. + __be32 hd_ctl; /* PMAC header control */
  4070. + __be32 tl; /* PMAC type/length */
  4071. + __be32 sa1; /* PMAC source address 1 */
  4072. + __be32 sa2; /* PMAC source address 2 */
  4073. + __be32 sa3; /* PMAC source address 3 */
  4074. + __be32 da1; /* PMAC destination address 1 */
  4075. + __be32 da2; /* PMAC destination address 2 */
  4076. + __be32 da3; /* PMAC destination address 3 */
  4077. + __be32 vlan; /* PMAC VLAN */
  4078. + __be32 rx_ipg; /* PMAC interpacket gap in RX direction */
  4079. + __be32 st_etype; /* PMAC special tag ethertype */
  4080. + __be32 ewan; /* PMAC ethernet WAN group */
  4081. + __be32 ctl; /* PMAC control */
  4082. + __be32 rsvd0[0x2];
  4083. +};
  4084. +
  4085. +struct vr9_switch_regs {
  4086. + struct vr9_switch_core_regs core;
  4087. + struct vr9_switch_bm_regs bm;
  4088. + struct vr9_switch_pce_regs pce;
  4089. + struct vr9_switch_mac_regs mac;
  4090. + struct vr9_switch_fdma_regs fdma;
  4091. + struct vr9_switch_sdma_regs sdma;
  4092. + struct vr9_switch_mdio_regs mdio;
  4093. + struct vr9_switch_mii_regs mii;
  4094. + struct vr9_switch_pmac_regs pmac;
  4095. +};
  4096. +
  4097. +static inline void *to_pce_tbl_key(struct vr9_switch_regs *regs,
  4098. + unsigned int id)
  4099. +{
  4100. + return &regs->pce.core.tbl_key[to_pce_tbl_key_id(id)];
  4101. +}
  4102. +
  4103. +static inline void *to_pce_tbl_value(struct vr9_switch_regs *regs,
  4104. + unsigned int id)
  4105. +{
  4106. + return &regs->pce.core.tbl_val[to_pce_tbl_value_id(id)];
  4107. +}
  4108. +
  4109. +static inline void *to_mac_ctrl(struct vr9_switch_regs *regs,
  4110. + unsigned int id, unsigned int ctrl)
  4111. +{
  4112. + struct mac_port *mac = &regs->mac.port[id];
  4113. +
  4114. + switch (ctrl) {
  4115. + case 0:
  4116. + return &mac->ctrl_0;
  4117. + case 1:
  4118. + return &mac->ctrl_1;
  4119. + case 2:
  4120. + return &mac->ctrl_2;
  4121. + case 3:
  4122. + return &mac->ctrl_3;
  4123. + case 4:
  4124. + return &mac->ctrl_4;
  4125. + case 5:
  4126. + return &mac->ctrl_5;
  4127. + default:
  4128. + return NULL;
  4129. + }
  4130. +}
  4131. +
  4132. +static inline void *to_mdio_phyaddr(struct vr9_switch_regs *regs,
  4133. + unsigned int id)
  4134. +{
  4135. + return &regs->mdio.phy_addr[to_mdio_phyaddr_id(id)];
  4136. +}
  4137. +
  4138. +static inline void *to_mii_miicfg(struct vr9_switch_regs *regs,
  4139. + unsigned int id)
  4140. +{
  4141. + switch (id) {
  4142. + case 0:
  4143. + return &regs->mii.mii_cfg0;
  4144. + case 1:
  4145. + return &regs->mii.mii_cfg1;
  4146. + case 5:
  4147. + return &regs->mii.mii_cfg5;
  4148. + default:
  4149. + return NULL;
  4150. + }
  4151. +}
  4152. +
  4153. +static inline void *to_mii_pcdu(struct vr9_switch_regs *regs,
  4154. + unsigned int id)
  4155. +{
  4156. + switch (id) {
  4157. + case 0:
  4158. + return &regs->mii.pcdu0;
  4159. + case 1:
  4160. + return &regs->mii.pcdu1;
  4161. + case 5:
  4162. + return &regs->mii.pcdu5;
  4163. + default:
  4164. + return NULL;
  4165. + }
  4166. +}
  4167. +
  4168. +#define VR9_SWITCH_REG_OFFSET(reg) (4 * (reg))
  4169. +
  4170. +#define BUILD_CHECK_VR9_REG(name, offset) \
  4171. + BUILD_BUG_ON(offsetof(struct vr9_switch_regs, name) != (4 * offset))
  4172. +
  4173. +static inline void build_check_vr9_registers(void)
  4174. +{
  4175. + BUILD_CHECK_VR9_REG(core, 0x0);
  4176. + BUILD_CHECK_VR9_REG(bm.core, 0x40);
  4177. + BUILD_CHECK_VR9_REG(bm.core.queue_gctrl, 0x4a);
  4178. + BUILD_CHECK_VR9_REG(bm.port[0], 0x80);
  4179. + BUILD_CHECK_VR9_REG(bm.queue, 0x100);
  4180. + BUILD_CHECK_VR9_REG(bm.shaper, 0x140);
  4181. + BUILD_CHECK_VR9_REG(pce.core, 0x438);
  4182. + BUILD_CHECK_VR9_REG(pce.core.tbl_ctrl, 0x44f);
  4183. + BUILD_CHECK_VR9_REG(pce.core.parser_stat, 0x469);
  4184. + BUILD_CHECK_VR9_REG(pce.port[0], 0x480);
  4185. + BUILD_CHECK_VR9_REG(pce.meter[0], 0x580);
  4186. + BUILD_CHECK_VR9_REG(mac.core, 0x8c0);
  4187. + BUILD_CHECK_VR9_REG(mac.port[0].pstat, 0x900);
  4188. + BUILD_CHECK_VR9_REG(mac.port[0].ctrl_0, 0x903);
  4189. + BUILD_CHECK_VR9_REG(mac.port[1].pstat, 0x90c);
  4190. + BUILD_CHECK_VR9_REG(mac.port[1].ctrl_0, 0x90f);
  4191. + BUILD_CHECK_VR9_REG(mac.port[2].pstat, 0x918);
  4192. + BUILD_CHECK_VR9_REG(mac.port[2].ctrl_0, 0x91b);
  4193. + BUILD_CHECK_VR9_REG(fdma.core, 0xa40);
  4194. + BUILD_CHECK_VR9_REG(fdma.port[0], 0xa80);
  4195. + BUILD_CHECK_VR9_REG(sdma.core, 0xb40);
  4196. + BUILD_CHECK_VR9_REG(sdma.port[0], 0xbc0);
  4197. + BUILD_CHECK_VR9_REG(mdio, 0xc40);
  4198. + BUILD_CHECK_VR9_REG(mii, (0xc40 + 0x36));
  4199. + BUILD_CHECK_VR9_REG(pmac, (0xc40 + 0x82));
  4200. +}
  4201. +
  4202. +#define BM_GCTRL_F_SRES 1
  4203. +
  4204. +#define MAC_CTRL0_BM (1 << 12)
  4205. +#define MAC_CTRL0_APADEN (1 << 11)
  4206. +#define MAC_CTRL0_VPAD2EN (1 << 10)
  4207. +#define MAC_CTRL0_VPADEN (1 << 9)
  4208. +#define MAC_CTRL0_PADEN (1 << 8)
  4209. +#define MAC_CTRL0_FCS (1 << 7)
  4210. +#define MAC_CTRL0_FCON_SHIFT 4
  4211. +#define MAC_CTRL0_FCON_AUTO (0x0 << MAC_CTRL0_FCON_SHIFT)
  4212. +#define MAC_CTRL0_FCON_RX (0x1 << MAC_CTRL0_FCON_SHIFT)
  4213. +#define MAC_CTRL0_FCON_TX (0x2 << MAC_CTRL0_FCON_SHIFT)
  4214. +#define MAC_CTRL0_FCON_RXTX (0x3 << MAC_CTRL0_FCON_SHIFT)
  4215. +#define MAC_CTRL0_FCON_NONE (0x4 << MAC_CTRL0_FCON_SHIFT)
  4216. +#define MAC_CTRL0_FDUP_SHIFT 2
  4217. +#define MAC_CTRL0_FDUP_AUTO (0x0 << MAC_CTRL0_FDUP_SHIFT)
  4218. +#define MAC_CTRL0_FDUP_EN (0x1 << MAC_CTRL0_FDUP_SHIFT)
  4219. +#define MAC_CTRL0_FDUP_DIS (0x3 << MAC_CTRL0_FDUP_SHIFT)
  4220. +#define MAC_CTRL0_GMII_AUTO 0x0
  4221. +#define MAC_CTRL0_GMII_MII 0x1
  4222. +#define MAC_CTRL0_GMII_GMII 0x2
  4223. +#define MAC_CTRL0_GMII_GMII_2G 0x3
  4224. +
  4225. +#define MAC_CTRL1_DEFERMODE (1 << 15)
  4226. +#define MAC_CTRL1_SHORTPRE (1 << 8)
  4227. +
  4228. +#define MAC_CTRL2_MLEN (1 << 3)
  4229. +#define MAC_CTRL2_LCHKL (1 << 2)
  4230. +#define MAC_CTRL2_LCHKS_DIS 0x0
  4231. +#define MAC_CTRL2_LCHKS_UNTAG 0x1
  4232. +#define MAC_CTRL2_LCHKS_TAG 0x2
  4233. +
  4234. +#define PHY_ADDR_LNKST_SHIFT 13
  4235. +#define PHY_ADDR_LNKST_AUTO (0x0 << PHY_ADDR_LNKST_SHIFT)
  4236. +#define PHY_ADDR_LNKST_UP (0x1 << PHY_ADDR_LNKST_SHIFT)
  4237. +#define PHY_ADDR_LNKST_DOWN (0x2 << PHY_ADDR_LNKST_SHIFT)
  4238. +#define PHY_ADDR_SPEED_SHIFT 11
  4239. +#define PHY_ADDR_SPEED_M10 (0x0 << PHY_ADDR_SPEED_SHIFT)
  4240. +#define PHY_ADDR_SPEED_M100 (0x1 << PHY_ADDR_SPEED_SHIFT)
  4241. +#define PHY_ADDR_SPEED_G1 (0x2 << PHY_ADDR_SPEED_SHIFT)
  4242. +#define PHY_ADDR_SPEED_AUTO (0x3 << PHY_ADDR_SPEED_SHIFT)
  4243. +#define PHY_ADDR_FDUP_SHIFT 9
  4244. +#define PHY_ADDR_FDUP_AUTO (0x0 << PHY_ADDR_FDUP_SHIFT)
  4245. +#define PHY_ADDR_FDUP_EN (0x1 << PHY_ADDR_FDUP_SHIFT)
  4246. +#define PHY_ADDR_FDUP_DIS (0x3 << PHY_ADDR_FDUP_SHIFT)
  4247. +#define PHY_ADDR_FCONTX_SHIFT 7
  4248. +#define PHY_ADDR_FCONTX_AUTO (0x0 << PHY_ADDR_FCONTX_SHIFT)
  4249. +#define PHY_ADDR_FCONTX_EN (0x1 << PHY_ADDR_FCONTX_SHIFT)
  4250. +#define PHY_ADDR_FCONTX_DIS (0x3 << PHY_ADDR_FCONTX_SHIFT)
  4251. +#define PHY_ADDR_FCONRX_SHIFT 5
  4252. +#define PHY_ADDR_FCONRX_AUTO (0x0 << PHY_ADDR_FCONRX_SHIFT)
  4253. +#define PHY_ADDR_FCONRX_EN (0x1 << PHY_ADDR_FCONRX_SHIFT)
  4254. +#define PHY_ADDR_FCONRX_DIS (0x3 << PHY_ADDR_FCONRX_SHIFT)
  4255. +
  4256. +#define MII_CFG_RES (1 << 15)
  4257. +#define MII_CFG_EN (1 << 14)
  4258. +#define MII_CFG_LDCLKDIS (1 << 12)
  4259. +#define MII_CFG_MIIRATE_SHIFT 4
  4260. +#define MII_CFG_MIIRATE_MASK (0x7 << MII_CFG_MIIRATE_SHIFT)
  4261. +#define MII_CFG_MIIRATE_M2P5 (0x0 << MII_CFG_MIIRATE_SHIFT)
  4262. +#define MII_CFG_MIIRATE_M25 (0x1 << MII_CFG_MIIRATE_SHIFT)
  4263. +#define MII_CFG_MIIRATE_M125 (0x2 << MII_CFG_MIIRATE_SHIFT)
  4264. +#define MII_CFG_MIIRATE_M50 (0x3 << MII_CFG_MIIRATE_SHIFT)
  4265. +#define MII_CFG_MIIRATE_AUTO (0x4 << MII_CFG_MIIRATE_SHIFT)
  4266. +#define MII_CFG_MIIMODE_MASK 0xf
  4267. +#define MII_CFG_MIIMODE_MIIP 0x0
  4268. +#define MII_CFG_MIIMODE_MIIM 0x1
  4269. +#define MII_CFG_MIIMODE_RMIIP 0x2
  4270. +#define MII_CFG_MIIMODE_RMIIM 0x3
  4271. +#define MII_CFG_MIIMODE_RGMII 0x4
  4272. +
  4273. +#define PCDU_RXDLY_SHIFT 7
  4274. +#define PCDU_RXDLY_MASK (0x7 << PCDU_RXDLY_SHIFT)
  4275. +#define PCDU_TXDLY_MASK 0x7
  4276. +
  4277. +#define PMAC_HD_CTL_FC (1 << 10)
  4278. +#define PMAC_HD_CTL_CCRC (1 << 9)
  4279. +#define PMAC_HD_CTL_RST (1 << 8)
  4280. +#define PMAC_HD_CTL_AST (1 << 7)
  4281. +#define PMAC_HD_CTL_RXSH (1 << 6)
  4282. +#define PMAC_HD_CTL_RC (1 << 4)
  4283. +#define PMAC_HD_CTL_AS (1 << 3)
  4284. +#define PMAC_HD_CTL_AC (1 << 2)
  4285. +
  4286. +#define PCE_PCTRL_0_IGSTEN (1 << 11)
  4287. +
  4288. +#define FDMA_PCTRL_STEN (1 << 1)
  4289. +#define FDMA_PCTRL_EN (1 << 0)
  4290. +
  4291. +#define SDMA_PCTRL_EN (1 << 0)
  4292. +
  4293. +#define MDIO_GLOB_CTRL_SE (1 << 15)
  4294. +
  4295. +#define MDIO_MDC_CFG1_RES (1 << 15)
  4296. +#define MDIO_MDC_CFG1_MCEN (1 << 8)
  4297. +
  4298. +#define MDIO_CTRL_MBUSY (1 << 12)
  4299. +#define MDIO_CTRL_OP_READ (1 << 11)
  4300. +#define MDIO_CTRL_OP_WRITE (1 << 10)
  4301. +#define MDIO_CTRL_PHYAD_SHIFT 5
  4302. +#define MDIO_CTRL_PHYAD_MASK (0x1f << MDIO_CTRL_PHYAD_SHIFT)
  4303. +#define MDIO_CTRL_REGAD_MASK 0x1f
  4304. +
  4305. +#endif /* __VRX200_SWITCH_H__ */
  4306. --- a/arch/mips/include/asm/asm.h
  4307. +++ b/arch/mips/include/asm/asm.h
  4308. @@ -53,6 +53,7 @@
  4309. .align 2; \
  4310. .type symbol, @function; \
  4311. .ent symbol, 0; \
  4312. + .section .text.symbol,"x"; \
  4313. symbol: .frame sp, 0, ra
  4314. /*
  4315. @@ -62,7 +63,8 @@ symbol: .frame sp, 0, ra
  4316. .globl symbol; \
  4317. .align 2; \
  4318. .type symbol, @function; \
  4319. - .ent symbol, 0; \
  4320. + .ent symbol, 0; \
  4321. + .section .text.symbol,"x"; \
  4322. symbol: .frame sp, framesize, rpc
  4323. /*
  4324. --- /dev/null
  4325. +++ b/arch/mips/include/asm/gpio.h
  4326. @@ -0,0 +1,6 @@
  4327. +/*
  4328. + * SPDX-License-Identifier: GPL-2.0+
  4329. + */
  4330. +
  4331. +#include <asm/arch/gpio.h>
  4332. +#include <asm-generic/gpio.h>
  4333. --- /dev/null
  4334. +++ b/arch/mips/include/asm/lantiq/chipid.h
  4335. @@ -0,0 +1,73 @@
  4336. +/*
  4337. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  4338. + *
  4339. + * SPDX-License-Identifier: GPL-2.0+
  4340. + */
  4341. +
  4342. +#ifndef __LANTIQ_CHIPID_H__
  4343. +#define __LANTIQ_CHIPID_H__
  4344. +
  4345. +enum ltq_chip_partnum {
  4346. + LTQ_SOC_UNKNOWN = 0,
  4347. + LTQ_SOC_VRX288_2 = 0x000B, /* VRX288 v1.2 */
  4348. + LTQ_SOC_VRX268_2 = 0x000C, /* VRX268 v1.2 */
  4349. + LTQ_SOC_GRX288_2 = 0x000D, /* GRX288 v1.2 */
  4350. + LTQ_SOC_DANUBE = 0x0129,
  4351. + LTQ_SOC_DANUBE_S = 0x012B,
  4352. + LTQ_SOC_TWINPASS = 0x012D,
  4353. + LTQ_SOC_VRX288 = 0x01C0, /* VRX288 v1.1 */
  4354. + LTQ_SOC_VRX268 = 0x01C2, /* VRX268 v1.1 */
  4355. + LTQ_SOC_GRX288 = 0x01C9, /* GRX288 v1.1 */
  4356. +};
  4357. +
  4358. +extern unsigned int ltq_chip_version_get(void);
  4359. +extern unsigned int ltq_chip_partnum_get(void);
  4360. +extern const char *ltq_chip_partnum_str(void);
  4361. +
  4362. +extern void ltq_chip_print_info(void);
  4363. +
  4364. +#ifdef CONFIG_SOC_XWAY_DANUBE
  4365. +static inline int ltq_soc_is_danube(void)
  4366. +{
  4367. + return 1;
  4368. +}
  4369. +#else
  4370. +static inline int ltq_soc_is_danube(void)
  4371. +{
  4372. + return 0;
  4373. +}
  4374. +#endif
  4375. +
  4376. +#ifdef CONFIG_SOC_XWAY_VRX200
  4377. +static inline int ltq_soc_is_vrx200(void)
  4378. +{
  4379. + return 1;
  4380. +}
  4381. +
  4382. +static inline int ltq_soc_is_vrx200_v1(void)
  4383. +{
  4384. + return ltq_chip_version_get() == 1;
  4385. +}
  4386. +
  4387. +static inline int ltq_soc_is_vrx200_v2(void)
  4388. +{
  4389. + return ltq_chip_version_get() == 2;
  4390. +}
  4391. +#else
  4392. +static inline int ltq_soc_is_vrx200(void)
  4393. +{
  4394. + return 0;
  4395. +}
  4396. +
  4397. +static inline int ltq_soc_is_vrx200_v1(void)
  4398. +{
  4399. + return 0;
  4400. +}
  4401. +
  4402. +static inline int ltq_soc_is_vrx200_v2(void)
  4403. +{
  4404. + return 0;
  4405. +}
  4406. +#endif
  4407. +
  4408. +#endif /* __LANTIQ_CHIPID_H__ */
  4409. --- /dev/null
  4410. +++ b/arch/mips/include/asm/lantiq/clk.h
  4411. @@ -0,0 +1,30 @@
  4412. +/*
  4413. + * Copyright (C) 2007-2010 Lantiq Deutschland GmbH
  4414. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  4415. + * *
  4416. + * SPDX-License-Identifier: GPL-2.0+
  4417. + */
  4418. +
  4419. +#ifndef __LANTIQ_CLK_H__
  4420. +#define __LANTIQ_CLK_H__
  4421. +
  4422. +/* Symbolic clock speeds */
  4423. +enum ltq_clk {
  4424. + CLOCK_83_MHZ = 83333333,
  4425. + CLOCK_111_MHZ = 111111111,
  4426. + CLOCK_125_MHZ = 125000000,
  4427. + CLOCK_133_MHZ = 133333333,
  4428. + CLOCK_166_MHZ = 166666667,
  4429. + CLOCK_197_MHZ = 197000000,
  4430. + CLOCK_333_MHZ = 333333333,
  4431. + CLOCK_393_MHZ = 393219000,
  4432. + CLOCK_500_MHZ = 500000000,
  4433. + CLOCK_600_MHZ = 600000000,
  4434. + CLOCK_1000_MHZ = 1000000000,
  4435. +};
  4436. +
  4437. +extern unsigned long ltq_get_cpu_clock(void);
  4438. +extern unsigned long ltq_get_bus_clock(void);
  4439. +extern unsigned long ltq_get_io_region_clock(void);
  4440. +
  4441. +#endif /* __LANTIQ_CLK_H__ */
  4442. --- /dev/null
  4443. +++ b/arch/mips/include/asm/lantiq/config.h
  4444. @@ -0,0 +1,164 @@
  4445. +/*
  4446. + * Copyright (C) 2007-2010 Lantiq Deutschland GmbH
  4447. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  4448. + *
  4449. + * SPDX-License-Identifier: GPL-2.0+
  4450. + */
  4451. +
  4452. +#ifndef __LANTIQ_CONFIG_H__
  4453. +#define __LANTIQ_CONFIG_H__
  4454. +
  4455. +/* Memory usage */
  4456. +#define CONFIG_SYS_MAXARGS 24
  4457. +#define CONFIG_SYS_MALLOC_LEN 1024*1024
  4458. +#define CONFIG_SYS_BOOTPARAMS_LEN 128*1024
  4459. +
  4460. +/* Command line */
  4461. +#define CONFIG_SYS_PROMPT CONFIG_MACH_TYPE " # "
  4462. +#define CONFIG_SYS_CBSIZE 512
  4463. +#define CONFIG_SYS_PBSIZE (CONFIG_SYS_CBSIZE + \
  4464. + sizeof(CONFIG_SYS_PROMPT)+16)
  4465. +
  4466. +#define CONFIG_SYS_HUSH_PARSER
  4467. +#define CONFIG_SYS_PROMPT_HUSH_PS2 "> "
  4468. +
  4469. +/*
  4470. + * Enable advanced console features on demand to reduce
  4471. + * flash and RAM footprint
  4472. + */
  4473. +#if defined(CONFIG_LTQ_ADVANCED_CONSOLE)
  4474. +#define CONFIG_SYS_LONGHELP
  4475. +#define CONFIG_AUTO_COMPLETE
  4476. +#define CONFIG_CMDLINE_EDITING
  4477. +#endif
  4478. +
  4479. +/* SPI flash SPL */
  4480. +#if defined(CONFIG_LTQ_SUPPORT_SPL_SPI_FLASH) && defined(CONFIG_SYS_BOOT_SFSPL)
  4481. +#define CONFIG_SPL
  4482. +#define CONFIG_SPL_SPI_SUPPORT
  4483. +#define CONFIG_SPL_SPI_FLASH_SUPPORT
  4484. +#define CONFIG_SPI_SPL_SIMPLE
  4485. +#endif
  4486. +
  4487. +#if defined(CONFIG_LTQ_SUPPORT_SPL_NOR_FLASH) && defined(CONFIG_SYS_BOOT_NORSPL)
  4488. +#define CONFIG_SPL
  4489. +#endif
  4490. +
  4491. +/* Common SPL */
  4492. +#if defined(CONFIG_SPL)
  4493. +#define CONFIG_SKIP_LOWLEVEL_INIT
  4494. +#define CONFIG_SPL_LIBGENERIC_SUPPORT
  4495. +#define CONFIG_SPL_GPIO_SUPPORT
  4496. +#define CONFIG_SPL_START_S_PATH \
  4497. + "arch/mips/cpu/mips32/lantiq-common"
  4498. +#define CONFIG_SPL_LDSCRIPT \
  4499. + "arch/mips/cpu/mips32/lantiq-common/u-boot-spl.lds"
  4500. +#endif
  4501. +
  4502. +#if defined(CONFIG_LTQ_SPL_CONSOLE)
  4503. +#define CONFIG_SPL_SERIAL_SUPPORT
  4504. +#define CONFIG_SPL_LIBCOMMON_SUPPORT
  4505. +#endif
  4506. +
  4507. +#if defined(CONFIG_LTQ_SPL_COMP_LZMA)
  4508. +#define CONFIG_LZMA
  4509. +#define CONFIG_SPL_LZMA_SUPPORT
  4510. +#endif
  4511. +
  4512. +#if defined(CONFIG_LTQ_SPL_COMP_LZO)
  4513. +#define CONFIG_LZO
  4514. +#define CONFIG_SPL_LZO_SUPPORT
  4515. +#endif
  4516. +
  4517. +/* Basic commands */
  4518. +#define CONFIG_CMD_BDI
  4519. +#define CONFIG_CMD_EDITENV
  4520. +#define CONFIG_CMD_IMI
  4521. +#define CONFIG_CMD_MEMORY
  4522. +#define CONFIG_CMD_RUN
  4523. +#define CONFIG_CMD_SAVEENV
  4524. +#define CONFIG_CMD_LOADB
  4525. +
  4526. +/* Other U-Boot settings */
  4527. +#define CONFIG_TIMESTAMP
  4528. +
  4529. +/* Default environment */
  4530. +#define CONFIG_ENV_CONSOLEDEV \
  4531. + "consoledev=" CONFIG_CONSOLE_DEV "\0"
  4532. +
  4533. +#define CONFIG_ENV_ADDCONSOLE \
  4534. + "addconsole=setenv bootargs $bootargs" \
  4535. + " console=$consoledev,$baudrate\0"
  4536. +
  4537. +#if defined(CONFIG_NET_DEV)
  4538. +#define CONFIG_ENV_NETDEV \
  4539. + "netdev=" CONFIG_NET_DEV "\0"
  4540. +#else
  4541. +#define CONFIG_ENV_NETDEV \
  4542. + "netdev=eth0\0"
  4543. +#endif
  4544. +
  4545. +#define CONFIG_ENV_ADDIP \
  4546. + "addip=setenv bootargs $bootargs" \
  4547. + " ip=$ipaddr:$serverip::::$netdev:off\0"
  4548. +
  4549. +#define CONFIG_ENV_ADDETH \
  4550. + "addeth=setenv bootargs $bootargs" \
  4551. + " ethaddr=$ethaddr\0"
  4552. +
  4553. +#define CONFIG_ENV_ADDMACHTYPE \
  4554. + "addmachtype=setenv bootargs $bootargs" \
  4555. + " machtype=" CONFIG_MACH_TYPE "\0"
  4556. +
  4557. +#if defined(CONFIG_LTQ_SUPPORT_NOR_FLASH)
  4558. +#define CONFIG_ENV_WRITE_UBOOT_NOR \
  4559. + "write-uboot-nor=" \
  4560. + "protect off " __stringify(CONFIG_SYS_FLASH_BASE) " +$filesize && " \
  4561. + "erase " __stringify(CONFIG_SYS_FLASH_BASE) " +$filesize && " \
  4562. + "cp.b $fileaddr " __stringify(CONFIG_SYS_FLASH_BASE) " $filesize\0"
  4563. +
  4564. +#define CONFIG_ENV_LOAD_UBOOT_NOR \
  4565. + "load-uboot-nor=tftpboot u-boot.bin\0" \
  4566. + "load-uboot-norspl=tftpboot u-boot.ltq.norspl\0" \
  4567. + "load-uboot-norspl-lzo=tftpboot u-boot.ltq.lzo.norspl\0" \
  4568. + "load-uboot-norspl-lzma=tftpboot u-boot.ltq.lzma.norspl\0"
  4569. +#else
  4570. +#define CONFIG_ENV_WRITE_UBOOT_NOR
  4571. +#define CONFIG_ENV_LOAD_UBOOT_NOR
  4572. +#endif
  4573. +
  4574. +#if defined(CONFIG_LTQ_SUPPORT_SPI_FLASH)
  4575. +#define CONFIG_ENV_SF_PROBE \
  4576. + "sf-probe=sf probe " __stringify(CONFIG_ENV_SPI_CS) " " \
  4577. + __stringify(CONFIG_ENV_SPI_MAX_HZ) " " \
  4578. + __stringify(CONFIG_ENV_SPI_MODE) " \0"
  4579. +
  4580. +#define CONFIG_ENV_WRITE_UBOOT_SF \
  4581. + "write-uboot-sf=" \
  4582. + "run sf-probe && sf erase 0 +$filesize && " \
  4583. + "sf write $fileaddr 0 $filesize\0"
  4584. +
  4585. +#define CONFIG_ENV_LOAD_UBOOT_SF \
  4586. + "load-uboot-sfspl=tftpboot u-boot.ltq.sfspl\0" \
  4587. + "load-uboot-sfspl-lzo=tftpboot u-boot.ltq.lzo.sfspl\0" \
  4588. + "load-uboot-sfspl-lzma=tftpboot u-boot.ltq.lzma.sfspl\0"
  4589. +#else
  4590. +#define CONFIG_ENV_SF_PROBE
  4591. +#define CONFIG_ENV_WRITE_UBOOT_SF
  4592. +#define CONFIG_ENV_LOAD_UBOOT_SF
  4593. +#endif
  4594. +
  4595. +#define CONFIG_ENV_LANTIQ_DEFAULTS \
  4596. + CONFIG_ENV_CONSOLEDEV \
  4597. + CONFIG_ENV_ADDCONSOLE \
  4598. + CONFIG_ENV_NETDEV \
  4599. + CONFIG_ENV_ADDIP \
  4600. + CONFIG_ENV_ADDETH \
  4601. + CONFIG_ENV_ADDMACHTYPE \
  4602. + CONFIG_ENV_WRITE_UBOOT_NOR \
  4603. + CONFIG_ENV_LOAD_UBOOT_NOR \
  4604. + CONFIG_ENV_SF_PROBE \
  4605. + CONFIG_ENV_WRITE_UBOOT_SF \
  4606. + CONFIG_ENV_LOAD_UBOOT_SF
  4607. +
  4608. +#endif /* __LANTIQ_CONFIG_H__ */
  4609. --- /dev/null
  4610. +++ b/arch/mips/include/asm/lantiq/cpu.h
  4611. @@ -0,0 +1,34 @@
  4612. +/*
  4613. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  4614. + *
  4615. + * SPDX-License-Identifier: GPL-2.0+
  4616. + */
  4617. +
  4618. +#ifndef __LANTIQ_CPU_H__
  4619. +#define __LANTIQ_CPU_H__
  4620. +
  4621. +enum ltq_boot_select {
  4622. + BOOT_NOR,
  4623. + BOOT_NOR_NO_BOOTROM,
  4624. + BOOT_UART,
  4625. + BOOT_UART_NO_EEPROM,
  4626. + BOOT_SPI,
  4627. + BOOT_NAND,
  4628. + BOOT_PCI,
  4629. + BOOT_MII0,
  4630. + BOOT_RMII0,
  4631. + BOOT_RGMII1,
  4632. + BOOT_UNKNOWN,
  4633. +};
  4634. +
  4635. +enum ltq_boot_select ltq_boot_select(void);
  4636. +const char *ltq_boot_select_str(void);
  4637. +
  4638. +void ltq_pmu_init(void);
  4639. +void ltq_ebu_init(void);
  4640. +void ltq_gpio_init(void);
  4641. +
  4642. +void ltq_pll_init(void);
  4643. +void ltq_dcdc_init(unsigned int dig_ref);
  4644. +
  4645. +#endif /* __LANTIQ_CPU_H__ */
  4646. --- /dev/null
  4647. +++ b/arch/mips/include/asm/lantiq/dma.h
  4648. @@ -0,0 +1,94 @@
  4649. +/*
  4650. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  4651. + *
  4652. + * SPDX-License-Identifier: GPL-2.0+
  4653. + */
  4654. +
  4655. +#ifndef __LANTIQ_DMA_H__
  4656. +#define __LANTIQ_DMA_H__
  4657. +
  4658. +enum ltq_dma_endianess {
  4659. + LTQ_DMA_ENDIANESS_B0_B1_B2_B3, /* No byte swapping */
  4660. + LTQ_DMA_ENDIANESS_B1_B0_B3_B2, /* B0B1B2B3 => B1B0B3B2 */
  4661. + LTQ_DMA_ENDIANESS_B2_B3_B0_B1, /* B0B1B2B3 => B2B3B0B1 */
  4662. + LTQ_DMA_ENDIANESS_B3_B2_B1_B0, /* B0B1B2B3 => B3B2B1B0 */
  4663. +};
  4664. +
  4665. +enum ltq_dma_burst_len {
  4666. + LTQ_DMA_BURST_2WORDS = 1,
  4667. + LTQ_DMA_BURST_4WORDS = 2,
  4668. + LTQ_DMA_BURST_8WORDS = 3,
  4669. +};
  4670. +
  4671. +struct ltq_dma_desc {
  4672. + u32 ctl;
  4673. + u32 addr;
  4674. +};
  4675. +
  4676. +struct ltq_dma_channel {
  4677. + struct ltq_dma_device *dev;
  4678. + u8 chan_no;
  4679. + u8 class;
  4680. + u16 num_desc;
  4681. + struct ltq_dma_desc *desc_base;
  4682. + void *mem_base;
  4683. + u32 dma_addr;
  4684. +};
  4685. +
  4686. +struct ltq_dma_device {
  4687. + enum ltq_dma_endianess rx_endian_swap;
  4688. + enum ltq_dma_endianess tx_endian_swap;
  4689. + enum ltq_dma_burst_len rx_burst_len;
  4690. + enum ltq_dma_burst_len tx_burst_len;
  4691. + struct ltq_dma_channel rx_chan;
  4692. + struct ltq_dma_channel tx_chan;
  4693. + u8 port;
  4694. +};
  4695. +
  4696. +/**
  4697. + * Initialize DMA hardware and driver
  4698. + */
  4699. +void ltq_dma_init(void);
  4700. +
  4701. +/**
  4702. + * Register given DMA client context
  4703. + *
  4704. + * @returns 0 on success, negative value otherwise
  4705. + */
  4706. +int ltq_dma_register(struct ltq_dma_device *dev);
  4707. +
  4708. +/**
  4709. + * Reset and halt all channels related to given DMA client
  4710. + */
  4711. +void ltq_dma_reset(struct ltq_dma_device *dev);
  4712. +void ltq_dma_enable(struct ltq_dma_device *dev);
  4713. +void ltq_dma_disable(struct ltq_dma_device *dev);
  4714. +
  4715. +/**
  4716. + * Map RX DMA descriptor to memory region
  4717. + *
  4718. + * @returns 0 on success, negative value otherwise
  4719. + */
  4720. +int ltq_dma_rx_map(struct ltq_dma_device *dev, int index, void *data, int len);
  4721. +
  4722. +/**
  4723. + * Check if new data is available.
  4724. + *
  4725. + * @returns length of received data, 0 otherwise
  4726. + */
  4727. +int ltq_dma_rx_poll(struct ltq_dma_device *dev, int index);
  4728. +
  4729. +int ltq_dma_rx_length(struct ltq_dma_device *dev, int index);
  4730. +
  4731. +/**
  4732. + * Map TX DMA descriptor to memory region
  4733. + *
  4734. + * @returns 0 on success, negative value otherwise
  4735. + */
  4736. +int ltq_dma_tx_map(struct ltq_dma_device *dev, int index, void *data, int len,
  4737. + unsigned long timeout);
  4738. +
  4739. +int ltq_dma_tx_wait(struct ltq_dma_device *dev, int index,
  4740. + unsigned long timeout);
  4741. +
  4742. +#endif /* __LANTIQ_DMA_H__ */
  4743. --- /dev/null
  4744. +++ b/arch/mips/include/asm/lantiq/eth.h
  4745. @@ -0,0 +1,35 @@
  4746. +/*
  4747. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  4748. + *
  4749. + * SPDX-License-Identifier: GPL-2.0+
  4750. + */
  4751. +
  4752. +#ifndef __LANTIQ_ETH_H__
  4753. +#define __LANTIQ_ETH_H__
  4754. +
  4755. +#include <phy.h>
  4756. +
  4757. +enum LTQ_ETH_PORT_FLAGS {
  4758. + LTQ_ETH_PORT_NONE = 0,
  4759. + LTQ_ETH_PORT_PHY = 1,
  4760. + LTQ_ETH_PORT_SWITCH = (1 << 1),
  4761. + LTQ_ETH_PORT_MAC = (1 << 2),
  4762. +};
  4763. +
  4764. +struct ltq_eth_port_config {
  4765. + u8 num;
  4766. + u8 phy_addr;
  4767. + u16 flags;
  4768. + phy_interface_t phy_if;
  4769. + u8 rgmii_rx_delay;
  4770. + u8 rgmii_tx_delay;
  4771. +};
  4772. +
  4773. +struct ltq_eth_board_config {
  4774. + const struct ltq_eth_port_config *ports;
  4775. + int num_ports;
  4776. +};
  4777. +
  4778. +extern int ltq_eth_initialize(const struct ltq_eth_board_config *board_config);
  4779. +
  4780. +#endif /* __LANTIQ_ETH_H__ */
  4781. --- /dev/null
  4782. +++ b/arch/mips/include/asm/lantiq/gpio.h
  4783. @@ -0,0 +1,50 @@
  4784. +/*
  4785. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  4786. + *
  4787. + * SPDX-License-Identifier: GPL-2.0+
  4788. + */
  4789. +
  4790. +#ifndef __LANTIQ_GPIO_H__
  4791. +#define __LANTIQ_GPIO_H__
  4792. +
  4793. +enum ltq_gpio_dir {
  4794. + GPIO_DIR_IN = 0,
  4795. + GPIO_DIR_OUT
  4796. +};
  4797. +
  4798. +enum ltq_gpio_od {
  4799. + GPIO_OD_ACTIVE = 0,
  4800. + GPIO_OD_NORMAL
  4801. +};
  4802. +
  4803. +enum ltq_gpio_altsel {
  4804. + GPIO_ALTSEL_CLR = 0,
  4805. + GPIO_ALTSEL_SET
  4806. +};
  4807. +
  4808. +extern int gpio_set_altfunc(unsigned gpio, int altsel0, int altsel1, int dir);
  4809. +extern int gpio_set_opendrain(unsigned gpio, int od);
  4810. +
  4811. +static inline int gpio_to_port(unsigned gpio)
  4812. +{
  4813. + return gpio >> 4;
  4814. +}
  4815. +
  4816. +static inline int gpio_to_pin(unsigned gpio)
  4817. +{
  4818. + return gpio & 0xF;
  4819. +}
  4820. +
  4821. +static inline int gpio_to_bit(unsigned gpio)
  4822. +{
  4823. + return 1 << gpio_to_pin(gpio);
  4824. +}
  4825. +
  4826. +static inline int gpio_to_gpio(unsigned port, unsigned pin)
  4827. +{
  4828. + return (port << 4) | (pin & 0xF);
  4829. +}
  4830. +
  4831. +#include <asm-generic/gpio.h>
  4832. +
  4833. +#endif /* __LANTIQ_GPIO_H__ */
  4834. --- /dev/null
  4835. +++ b/arch/mips/include/asm/lantiq/io.h
  4836. @@ -0,0 +1,37 @@
  4837. +/*
  4838. + * Copyright (C) 2010 John Crispin <blogic@openwrt.org>
  4839. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  4840. + *
  4841. + * SPDX-License-Identifier: GPL-2.0+
  4842. + */
  4843. +
  4844. +#ifndef __LANTIQ_IO_H__
  4845. +#define __LANTIQ_IO_H__
  4846. +
  4847. +#include <asm/io.h>
  4848. +
  4849. +#define ltq_readb(a) __raw_readb(a)
  4850. +#define ltq_writeb(a, v) __raw_writeb(v, a)
  4851. +
  4852. +#define ltq_readl(a) __raw_readl(a)
  4853. +#define ltq_writel(a, v) __raw_writel(v, a)
  4854. +
  4855. +#define ltq_clrbits(a, clear) \
  4856. + ltq_writel(a, ltq_readl(a) & ~(clear))
  4857. +
  4858. +#define ltq_setbits(a, set) \
  4859. + ltq_writel(a, ltq_readl(a) | (set))
  4860. +
  4861. +#define ltq_clrsetbits(a, clear, set) \
  4862. + ltq_writel(a, (ltq_readl(a) & ~(clear)) | (set))
  4863. +
  4864. +static inline void ltq_reg_dump(const void *addr, const char *desc)
  4865. +{
  4866. + u32 data;
  4867. +
  4868. + data = ltq_readl(addr);
  4869. + printf("ltq_reg_dump: %s 0x%p = 0x%08x\n",
  4870. + desc, addr, data);
  4871. +}
  4872. +
  4873. +#endif /* __LANTIQ_IO_H__ */
  4874. --- /dev/null
  4875. +++ b/arch/mips/include/asm/lantiq/pm.h
  4876. @@ -0,0 +1,21 @@
  4877. +/*
  4878. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  4879. + *
  4880. + * SPDX-License-Identifier: GPL-2.0+
  4881. + */
  4882. +
  4883. +#ifndef __LANTIQ_PM_H__
  4884. +#define __LANTIQ_PM_H__
  4885. +
  4886. +enum ltq_pm_modules {
  4887. + LTQ_PM_CORE,
  4888. + LTQ_PM_DMA,
  4889. + LTQ_PM_ETH,
  4890. + LTQ_PM_SPI,
  4891. +};
  4892. +
  4893. +u32 ltq_pm_map(enum ltq_pm_modules module);
  4894. +int ltq_pm_enable(enum ltq_pm_modules module);
  4895. +int ltq_pm_disable(enum ltq_pm_modules module);
  4896. +
  4897. +#endif /* __LANTIQ_PM_H__ */
  4898. --- /dev/null
  4899. +++ b/arch/mips/include/asm/lantiq/reset.h
  4900. @@ -0,0 +1,37 @@
  4901. +/*
  4902. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  4903. + *
  4904. + * SPDX-License-Identifier: GPL-2.0+
  4905. + */
  4906. +
  4907. +#ifndef __LANTIQ_RESET_H__
  4908. +#define __LANTIQ_RESET_H__
  4909. +
  4910. +enum ltq_reset_modules {
  4911. + LTQ_RESET_CORE,
  4912. + LTQ_RESET_DMA,
  4913. + LTQ_RESET_ETH,
  4914. + LTQ_RESET_PHY,
  4915. + LTQ_RESET_HARD,
  4916. + LTQ_RESET_SOFT,
  4917. +};
  4918. +
  4919. +extern u32 ltq_reset_map(enum ltq_reset_modules module);
  4920. +extern int ltq_reset_activate(enum ltq_reset_modules module);
  4921. +extern int ltq_reset_deactivate(enum ltq_reset_modules module);
  4922. +
  4923. +static inline int ltq_reset_once(enum ltq_reset_modules module, ulong usec)
  4924. +{
  4925. + int ret;
  4926. +
  4927. + ret = ltq_reset_activate(module);
  4928. + if (ret)
  4929. + return ret;
  4930. +
  4931. + __udelay(usec);
  4932. + ret = ltq_reset_deactivate(module);
  4933. +
  4934. + return ret;
  4935. +}
  4936. +
  4937. +#endif /* __LANTIQ_RESET_H__ */
  4938. --- a/arch/mips/include/asm/mipsregs.h
  4939. +++ b/arch/mips/include/asm/mipsregs.h
  4940. @@ -46,7 +46,10 @@
  4941. #define CP0_ENTRYLO1 $3
  4942. #define CP0_CONF $3
  4943. #define CP0_CONTEXT $4
  4944. +#define CP0_CONTEXTCONFIG $4,1
  4945. +#define CP0_USERLOCAL $4,1
  4946. #define CP0_PAGEMASK $5
  4947. +#define CP0_PAGEGRAIN $5,1
  4948. #define CP0_WIRED $6
  4949. #define CP0_INFO $7
  4950. #define CP0_BADVADDR $8
  4951. @@ -54,10 +57,19 @@
  4952. #define CP0_ENTRYHI $10
  4953. #define CP0_COMPARE $11
  4954. #define CP0_STATUS $12
  4955. +#define CP0_INTCTL $12,1
  4956. +#define CP0_SRSCTL $12,2
  4957. +#define CP0_SRSMAP $12,3
  4958. +#define CP0_SRSHIGH $12,4
  4959. #define CP0_CAUSE $13
  4960. #define CP0_EPC $14
  4961. #define CP0_PRID $15
  4962. +#define CP0_EBASE $15,1
  4963. #define CP0_CONFIG $16
  4964. +#define CP0_CONFIG1 $16,1
  4965. +#define CP0_CONFIG2 $16,2
  4966. +#define CP0_CONFIG3 $16,3
  4967. +#define CP0_CONFIG7 $16,7
  4968. #define CP0_LLADDR $17
  4969. #define CP0_WATCHLO $18
  4970. #define CP0_WATCHHI $19
  4971. @@ -70,7 +82,17 @@
  4972. #define CP0_ECC $26
  4973. #define CP0_CACHEERR $27
  4974. #define CP0_TAGLO $28
  4975. +#define CP0_ITAGLO $28
  4976. +#define CP0_IDATALO $28,1
  4977. +#define CP0_DTAGLO $28,2
  4978. +#define CP0_DDATALO $28,3
  4979. +#define CP0_L23TAGLO $28,4
  4980. +#define CP0_L23DATALO $28,5
  4981. #define CP0_TAGHI $29
  4982. +#define CP0_IDATAHI $29,1
  4983. +#define CP0_DTAGHI $29,2
  4984. +#define CP0_L23TAGHI $29,4
  4985. +#define CP0_L23DATAHI $29,5
  4986. #define CP0_ERROREPC $30
  4987. #define CP0_DESAVE $31
  4988. @@ -395,6 +417,12 @@
  4989. #define CAUSEF_BD (_ULCAST_(1) << 31)
  4990. /*
  4991. + * Bits in the coprocessor 0 EBase register.
  4992. + */
  4993. +#define EBASEB_CPUNUM 0
  4994. +#define EBASEF_CPUNUM (_ULCAST_(1023))
  4995. +
  4996. +/*
  4997. * Bits in the coprocessor 0 config register.
  4998. */
  4999. /* Generic bits. */
  5000. --- a/arch/mips/include/asm/u-boot-mips.h
  5001. +++ b/arch/mips/include/asm/u-boot-mips.h
  5002. @@ -23,3 +23,4 @@ static inline unsigned long image_copy_e
  5003. }
  5004. extern int incaip_set_cpuclk(void);
  5005. +extern int arch_cpu_init(void);
  5006. --- a/arch/mips/lib/board.c
  5007. +++ b/arch/mips/lib/board.c
  5008. @@ -33,6 +33,16 @@ static char *failed = "*** failed ***\n"
  5009. */
  5010. const unsigned long mips_io_port_base = -1;
  5011. +int __arch_cpu_init(void)
  5012. +{
  5013. + /*
  5014. + * Nothing to do in this dummy implementation
  5015. + */
  5016. + return 0;
  5017. +}
  5018. +int arch_cpu_init(void)
  5019. + __attribute__((weak, alias("__arch_cpu_init")));
  5020. +
  5021. int __board_early_init_f(void)
  5022. {
  5023. /*
  5024. @@ -106,6 +116,7 @@ static int init_baudrate(void)
  5025. typedef int (init_fnc_t)(void);
  5026. init_fnc_t *init_sequence[] = {
  5027. + arch_cpu_init,
  5028. board_early_init_f,
  5029. timer_init,
  5030. env_init, /* initialize environment */
  5031. --- a/drivers/dma/Makefile
  5032. +++ b/drivers/dma/Makefile
  5033. @@ -12,6 +12,7 @@ LIB := $(obj)libdma.o
  5034. COBJS-$(CONFIG_FSLDMAFEC) += MCD_tasksInit.o MCD_dmaApi.o MCD_tasks.o
  5035. COBJS-$(CONFIG_APBH_DMA) += apbh_dma.o
  5036. COBJS-$(CONFIG_FSL_DMA) += fsl_dma.o
  5037. +COBJS-$(CONFIG_LANTIQ_DMA) += lantiq_dma.o
  5038. COBJS-$(CONFIG_OMAP3_DMA) += omap3_dma.o
  5039. COBJS := $(COBJS-y)
  5040. --- /dev/null
  5041. +++ b/drivers/dma/lantiq_dma.c
  5042. @@ -0,0 +1,387 @@
  5043. +/*
  5044. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  5045. + *
  5046. + * SPDX-License-Identifier: GPL-2.0+
  5047. + */
  5048. +
  5049. +#include <common.h>
  5050. +#include <malloc.h>
  5051. +#include <watchdog.h>
  5052. +#include <linux/compiler.h>
  5053. +#include <asm/lantiq/io.h>
  5054. +#include <asm/lantiq/dma.h>
  5055. +#include <asm/lantiq/pm.h>
  5056. +#include <asm/lantiq/reset.h>
  5057. +#include <asm/arch/soc.h>
  5058. +#include <asm/processor.h>
  5059. +
  5060. +#define DMA_CTRL_PKTARB (1 << 31)
  5061. +#define DMA_CTRL_MBRSTARB (1 << 30)
  5062. +#define DMA_CTRL_MBRSTCNT_SHIFT 16
  5063. +#define DMA_CTRL_MBRSTCNT_MASK (0x3ff << DMA_CTRL_MBRSTCNT_SHIFT)
  5064. +#define DMA_CTRL_DRB (1 << 8)
  5065. +#define DMA_CTRL_RESET (1 << 0)
  5066. +
  5067. +#define DMA_CPOLL_EN (1 << 31)
  5068. +#define DMA_CPOLL_CNT_SHIFT 4
  5069. +#define DMA_CPOLL_CNT_MASK (0xFFF << DMA_CPOLL_CNT_SHIFT)
  5070. +
  5071. +#define DMA_CCTRL_TXWGT_SHIFT 16
  5072. +#define DMA_CCTRL_TXWGT_MASK (0x3 << DMA_CCTRL_TXWGT_SHIFT)
  5073. +#define DMA_CCTRL_CLASS_SHIFT 9
  5074. +#define DMA_CCTRL_CLASS_MASK (0x3 << DMA_CCTRL_CLASS_SHIFT)
  5075. +#define DMA_CCTRL_RST (1 << 1)
  5076. +#define DMA_CCTRL_ONOFF (1 << 0)
  5077. +
  5078. +#define DMA_PCTRL_TXBL_SHIFT 4
  5079. +#define DMA_PCTRL_TXBL_2WORDS (1 << DMA_PCTRL_TXBL_SHIFT)
  5080. +#define DMA_PCTRL_TXBL_4WORDS (2 << DMA_PCTRL_TXBL_SHIFT)
  5081. +#define DMA_PCTRL_TXBL_8WORDS (3 << DMA_PCTRL_TXBL_SHIFT)
  5082. +#define DMA_PCTRL_RXBL_SHIFT 2
  5083. +#define DMA_PCTRL_RXBL_2WORDS (1 << DMA_PCTRL_RXBL_SHIFT)
  5084. +#define DMA_PCTRL_RXBL_4WORDS (2 << DMA_PCTRL_RXBL_SHIFT)
  5085. +#define DMA_PCTRL_RXBL_8WORDS (3 << DMA_PCTRL_RXBL_SHIFT)
  5086. +#define DMA_PCTRL_TXENDI_SHIFT 10
  5087. +#define DMA_PCTRL_TXENDI_MASK (0x3 << DMA_PCTRL_TXENDI_SHIFT)
  5088. +#define DMA_PCTRL_RXENDI_SHIFT 8
  5089. +#define DMA_PCTRL_RXENDI_MASK (0x3 << DMA_PCTRL_RXENDI_SHIFT)
  5090. +
  5091. +#define DMA_DESC_OWN (1 << 31)
  5092. +#define DMA_DESC_C (1 << 30)
  5093. +#define DMA_DESC_SOP (1 << 29)
  5094. +#define DMA_DESC_EOP (1 << 28)
  5095. +#define DMA_DESC_TX_OFFSET(x) ((x & 0x1f) << 23)
  5096. +#define DMA_DESC_RX_OFFSET(x) ((x & 0x3) << 23)
  5097. +#define DMA_DESC_LENGTH(x) (x & 0xffff)
  5098. +
  5099. +#define PTR_ALIGN(p, a) ((typeof(p))ALIGN((unsigned long)(p), (a)))
  5100. +
  5101. +struct ltq_dma_regs {
  5102. + u32 clc; /* Clock control */
  5103. + u32 rsvd0;
  5104. + u32 id; /* Identification */
  5105. + u32 rsvd1;
  5106. + u32 ctrl; /* Control */
  5107. + u32 cpoll; /* Channel polling */
  5108. + u32 cs; /* Channel select */
  5109. + u32 cctrl; /* Channel control */
  5110. + u32 cdba; /* Channel descriptor base address */
  5111. + u32 cdlen; /* Channel descriptor length */
  5112. + u32 cis; /* Channel interrupt status */
  5113. + u32 cie; /* Channel interrupt enable */
  5114. + u32 cgbl; /* Channel global buffer length */
  5115. + u32 cdptnrd; /* Current descriptor pointer */
  5116. + u32 rsvd2[2];
  5117. + u32 ps; /* Port select */
  5118. + u32 pctrl; /* Port control */
  5119. + u32 rsvd3[43];
  5120. + u32 irnen; /* Interrupt node enable */
  5121. + u32 irncr; /* Interrupt node control */
  5122. + u32 irnicr; /* Interrupt capture */
  5123. +};
  5124. +
  5125. +static struct ltq_dma_regs *ltq_dma_regs =
  5126. + (struct ltq_dma_regs *) CKSEG1ADDR(LTQ_DMA_BASE);
  5127. +
  5128. +static inline unsigned long ltq_dma_addr_to_virt(u32 dma_addr)
  5129. +{
  5130. + return KSEG0ADDR(dma_addr);
  5131. +}
  5132. +
  5133. +static inline u32 ltq_virt_to_dma_addr(void *addr)
  5134. +{
  5135. + return CPHYSADDR(addr);
  5136. +}
  5137. +
  5138. +static inline int ltq_dma_burst_align(enum ltq_dma_burst_len burst_len)
  5139. +{
  5140. + switch (burst_len) {
  5141. + case LTQ_DMA_BURST_2WORDS:
  5142. + return 2 * 4;
  5143. + case LTQ_DMA_BURST_4WORDS:
  5144. + return 4 * 4;
  5145. + case LTQ_DMA_BURST_8WORDS:
  5146. + return 8 * 4;
  5147. + }
  5148. +
  5149. + return 0;
  5150. +}
  5151. +
  5152. +static inline void ltq_dma_sync(void)
  5153. +{
  5154. + __asm__ __volatile__("sync");
  5155. +}
  5156. +
  5157. +static inline void ltq_dma_dcache_wb_inv(const void *ptr, size_t size)
  5158. +{
  5159. + unsigned long addr = (unsigned long) ptr;
  5160. +
  5161. + flush_dcache_range(addr, addr + size);
  5162. + ltq_dma_sync();
  5163. +}
  5164. +
  5165. +static inline void ltq_dma_dcache_inv(const void *ptr, size_t size)
  5166. +{
  5167. + unsigned long addr = (unsigned long) ptr;
  5168. +
  5169. + invalidate_dcache_range(addr, addr + size);
  5170. +}
  5171. +
  5172. +void ltq_dma_init(void)
  5173. +{
  5174. + /* Power up DMA */
  5175. + ltq_pm_enable(LTQ_PM_DMA);
  5176. +
  5177. + /* Reset DMA */
  5178. + ltq_setbits(&ltq_dma_regs->ctrl, DMA_CTRL_RESET);
  5179. +
  5180. + /* Disable and clear all interrupts */
  5181. + ltq_writel(&ltq_dma_regs->irnen, 0);
  5182. + ltq_writel(&ltq_dma_regs->irncr, 0xFFFFF);
  5183. +
  5184. +#if 0
  5185. + /* Enable packet arbitration */
  5186. + ltq_setbits(&ltq_dma_regs->ctrl, DMA_CTRL_PKTARB);
  5187. +#endif
  5188. +
  5189. +#if 0
  5190. + /* Enable descriptor read back */
  5191. + ltq_setbits(&ltq_dma_regs->ctrl, DMA_CTRL_DRB);
  5192. +#endif
  5193. +
  5194. + /* Enable polling for descriptor fetching for all channels */
  5195. + ltq_writel(&ltq_dma_regs->cpoll, DMA_CPOLL_EN |
  5196. + (4 << DMA_CPOLL_CNT_SHIFT));
  5197. +}
  5198. +
  5199. +static void ltq_dma_channel_reset(struct ltq_dma_channel *chan)
  5200. +{
  5201. + ltq_writel(&ltq_dma_regs->cs, chan->chan_no);
  5202. + ltq_setbits(&ltq_dma_regs->cctrl, DMA_CCTRL_RST);
  5203. +}
  5204. +
  5205. +static void ltq_dma_channel_enable(struct ltq_dma_channel *chan)
  5206. +{
  5207. + ltq_writel(&ltq_dma_regs->cs, chan->chan_no);
  5208. + ltq_setbits(&ltq_dma_regs->cctrl, DMA_CCTRL_ONOFF);
  5209. +}
  5210. +
  5211. +static void ltq_dma_channel_disable(struct ltq_dma_channel *chan)
  5212. +{
  5213. + ltq_writel(&ltq_dma_regs->cs, chan->chan_no);
  5214. + ltq_clrbits(&ltq_dma_regs->cctrl, DMA_CCTRL_ONOFF);
  5215. +}
  5216. +
  5217. +static void ltq_dma_port_init(struct ltq_dma_device *dev)
  5218. +{
  5219. + u32 pctrl;
  5220. +
  5221. + pctrl = dev->tx_endian_swap << DMA_PCTRL_TXENDI_SHIFT;
  5222. + pctrl |= dev->rx_endian_swap << DMA_PCTRL_RXENDI_SHIFT;
  5223. + pctrl |= dev->tx_burst_len << DMA_PCTRL_TXBL_SHIFT;
  5224. + pctrl |= dev->rx_burst_len << DMA_PCTRL_RXBL_SHIFT;
  5225. +
  5226. + ltq_writel(&ltq_dma_regs->ps, dev->port);
  5227. + ltq_writel(&ltq_dma_regs->pctrl, pctrl);
  5228. +}
  5229. +
  5230. +static int ltq_dma_alloc_descriptors(struct ltq_dma_device *dev,
  5231. + struct ltq_dma_channel *chan)
  5232. +{
  5233. + size_t size;
  5234. + void *desc_base;
  5235. +
  5236. + size = ALIGN(sizeof(struct ltq_dma_desc) * chan->num_desc +
  5237. + ARCH_DMA_MINALIGN, ARCH_DMA_MINALIGN);
  5238. +
  5239. + chan->mem_base = malloc(size);
  5240. + if (!chan->mem_base)
  5241. + return 1;
  5242. +
  5243. + memset(chan->mem_base, 0, size);
  5244. + ltq_dma_dcache_wb_inv(chan->mem_base, size);
  5245. +
  5246. + desc_base = PTR_ALIGN(chan->mem_base, ARCH_DMA_MINALIGN);
  5247. +
  5248. + debug("DMA: mem %p, desc %p\n", chan->mem_base, desc_base);
  5249. +
  5250. + /* Align descriptor base to 8 bytes */
  5251. + chan->desc_base = (void *) CKSEG1ADDR(desc_base);
  5252. + chan->dma_addr = CPHYSADDR(desc_base);
  5253. + chan->dev = dev;
  5254. +
  5255. + debug("DMA: desc_base %p, size %u\n", chan->desc_base, size);
  5256. +
  5257. + /* Configure hardware with location of descriptor list */
  5258. + ltq_writel(&ltq_dma_regs->cs, chan->chan_no);
  5259. + ltq_writel(&ltq_dma_regs->cdba, chan->dma_addr);
  5260. + ltq_writel(&ltq_dma_regs->cdlen, chan->num_desc);
  5261. + ltq_writel(&ltq_dma_regs->cctrl, (3 << DMA_CCTRL_TXWGT_SHIFT) |
  5262. + (chan->class << DMA_CCTRL_CLASS_SHIFT));
  5263. + ltq_writel(&ltq_dma_regs->cctrl, DMA_CCTRL_RST);
  5264. +
  5265. + return 0;
  5266. +}
  5267. +
  5268. +static void ltq_dma_free_descriptors(struct ltq_dma_channel *chan)
  5269. +{
  5270. + ltq_writel(&ltq_dma_regs->cs, chan->chan_no);
  5271. + ltq_writel(&ltq_dma_regs->cdba, 0);
  5272. + ltq_writel(&ltq_dma_regs->cdlen, 0);
  5273. +
  5274. + ltq_dma_channel_reset(chan);
  5275. +
  5276. + free(chan->mem_base);
  5277. +}
  5278. +
  5279. +int ltq_dma_register(struct ltq_dma_device *dev)
  5280. +{
  5281. + int ret;
  5282. +
  5283. + ltq_dma_port_init(dev);
  5284. +
  5285. + ret = ltq_dma_alloc_descriptors(dev, &dev->rx_chan);
  5286. + if (ret)
  5287. + return ret;
  5288. +
  5289. + ret = ltq_dma_alloc_descriptors(dev, &dev->tx_chan);
  5290. + if (ret) {
  5291. + ltq_dma_free_descriptors(&dev->rx_chan);
  5292. + return ret;
  5293. + }
  5294. +
  5295. + return 0;
  5296. +}
  5297. +
  5298. +void ltq_dma_reset(struct ltq_dma_device *dev)
  5299. +{
  5300. + ltq_dma_channel_reset(&dev->rx_chan);
  5301. + ltq_dma_channel_reset(&dev->tx_chan);
  5302. +}
  5303. +
  5304. +void ltq_dma_enable(struct ltq_dma_device *dev)
  5305. +{
  5306. + ltq_dma_channel_enable(&dev->rx_chan);
  5307. + ltq_dma_channel_enable(&dev->tx_chan);
  5308. +}
  5309. +
  5310. +void ltq_dma_disable(struct ltq_dma_device *dev)
  5311. +{
  5312. + ltq_dma_channel_disable(&dev->rx_chan);
  5313. + ltq_dma_channel_disable(&dev->tx_chan);
  5314. +}
  5315. +
  5316. +int ltq_dma_rx_map(struct ltq_dma_device *dev, int index, void *data, int len)
  5317. +{
  5318. + struct ltq_dma_channel *chan = &dev->rx_chan;
  5319. + struct ltq_dma_desc *desc = &chan->desc_base[index];
  5320. + u32 dma_addr = ltq_virt_to_dma_addr(data);
  5321. + unsigned int offset;
  5322. +
  5323. + offset = dma_addr % ltq_dma_burst_align(dev->rx_burst_len);
  5324. +
  5325. + ltq_dma_dcache_inv(data, len);
  5326. +
  5327. +#if 0
  5328. + printf("%s: index %d, data %p, dma_addr %08x, offset %u, len %d\n",
  5329. + __func__, index, data, dma_addr, offset, len);
  5330. +#endif
  5331. +
  5332. +
  5333. + desc->addr = dma_addr - offset;
  5334. + desc->ctl = DMA_DESC_OWN | DMA_DESC_RX_OFFSET(offset) |
  5335. + DMA_DESC_LENGTH(len);
  5336. +
  5337. +#if 0
  5338. + printf("%s: index %d, desc %p, desc->ctl %08x\n",
  5339. + __func__, index, desc, desc->ctl);
  5340. +#endif
  5341. +
  5342. + return 0;
  5343. +}
  5344. +
  5345. +int ltq_dma_rx_poll(struct ltq_dma_device *dev, int index)
  5346. +{
  5347. + struct ltq_dma_channel *chan = &dev->rx_chan;
  5348. + struct ltq_dma_desc *desc = &chan->desc_base[index];
  5349. +
  5350. +#if 0
  5351. + printf("%s: index %d, desc %p, desc->ctl %08x\n",
  5352. + __func__, index, desc, desc->ctl);
  5353. +#endif
  5354. +
  5355. + if (desc->ctl & DMA_DESC_OWN)
  5356. + return 0;
  5357. +
  5358. + if (desc->ctl & DMA_DESC_C)
  5359. + return 1;
  5360. +
  5361. + return 0;
  5362. +}
  5363. +
  5364. +int ltq_dma_rx_length(struct ltq_dma_device *dev, int index)
  5365. +{
  5366. + struct ltq_dma_channel *chan = &dev->rx_chan;
  5367. + struct ltq_dma_desc *desc = &chan->desc_base[index];
  5368. +
  5369. + return DMA_DESC_LENGTH(desc->ctl);
  5370. +}
  5371. +
  5372. +int ltq_dma_tx_map(struct ltq_dma_device *dev, int index, void *data, int len,
  5373. + unsigned long timeout)
  5374. +{
  5375. + struct ltq_dma_channel *chan = &dev->tx_chan;
  5376. + struct ltq_dma_desc *desc = &chan->desc_base[index];
  5377. + unsigned int offset;
  5378. + unsigned long timebase = get_timer(0);
  5379. + u32 dma_addr = ltq_virt_to_dma_addr(data);
  5380. +
  5381. + while (desc->ctl & DMA_DESC_OWN) {
  5382. + WATCHDOG_RESET();
  5383. +
  5384. + if (get_timer(timebase) >= timeout) {
  5385. +#if 0
  5386. + printf("%s: timeout: index %d, desc %p, desc->ctl %08x\n",
  5387. + __func__, index, desc, desc->ctl);
  5388. +#endif
  5389. + return -1;
  5390. + }
  5391. + }
  5392. +
  5393. + offset = dma_addr % ltq_dma_burst_align(dev->rx_burst_len);
  5394. +
  5395. +#if 0
  5396. + printf("%s: index %d, desc %p, data %p, dma_addr %08x, offset %u, len %d\n",
  5397. + __func__, index, desc, data, dma_addr, offset, len);
  5398. +#endif
  5399. +
  5400. + ltq_dma_dcache_wb_inv(data, len);
  5401. +
  5402. + desc->addr = dma_addr - offset;
  5403. + desc->ctl = DMA_DESC_OWN | DMA_DESC_SOP | DMA_DESC_EOP |
  5404. + DMA_DESC_TX_OFFSET(offset) | DMA_DESC_LENGTH(len);
  5405. +
  5406. +#if 0
  5407. + printf("%s: index %d, desc %p, desc->ctl %08x\n",
  5408. + __func__, index, desc, desc->ctl);
  5409. +#endif
  5410. +
  5411. + return 0;
  5412. +}
  5413. +
  5414. +int ltq_dma_tx_wait(struct ltq_dma_device *dev, int index,
  5415. + unsigned long timeout)
  5416. +{
  5417. + struct ltq_dma_channel *chan = &dev->tx_chan;
  5418. + struct ltq_dma_desc *desc = &chan->desc_base[index];
  5419. + unsigned long timebase = get_timer(0);
  5420. +
  5421. + while ((desc->ctl & (DMA_DESC_OWN | DMA_DESC_C)) != DMA_DESC_C) {
  5422. + WATCHDOG_RESET();
  5423. +
  5424. + if (get_timer(timebase) >= timeout)
  5425. + return -1;
  5426. + }
  5427. +
  5428. + return 0;
  5429. +}
  5430. --- a/drivers/gpio/Makefile
  5431. +++ b/drivers/gpio/Makefile
  5432. @@ -12,6 +12,7 @@ LIB := $(obj)libgpio.o
  5433. COBJS-$(CONFIG_AT91_GPIO) += at91_gpio.o
  5434. COBJS-$(CONFIG_INTEL_ICH6_GPIO) += intel_ich6_gpio.o
  5435. COBJS-$(CONFIG_KIRKWOOD_GPIO) += kw_gpio.o
  5436. +COBJS-$(CONFIG_LANTIQ_GPIO) += lantiq_gpio.o
  5437. COBJS-$(CONFIG_MARVELL_GPIO) += mvgpio.o
  5438. COBJS-$(CONFIG_MARVELL_MFP) += mvmfp.o
  5439. COBJS-$(CONFIG_MXC_GPIO) += mxc_gpio.o
  5440. --- /dev/null
  5441. +++ b/drivers/gpio/lantiq_gpio.c
  5442. @@ -0,0 +1,329 @@
  5443. +/*
  5444. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  5445. + *
  5446. + * SPDX-License-Identifier: GPL-2.0+
  5447. + */
  5448. +
  5449. +#include <common.h>
  5450. +#include <asm/arch/soc.h>
  5451. +#include <asm/arch/gpio.h>
  5452. +#include <asm/lantiq/io.h>
  5453. +
  5454. +#define SSIO_GPIO_BASE 64
  5455. +
  5456. +#define SSIO_CON0_SWU (1 << 31)
  5457. +#define SSIO_CON0_RZFL (1 << 26)
  5458. +#define SSIO_CON0_GPHY1_SHIFT 27
  5459. +#define SSIO_CON0_GPHY1_CONFIG ((CONFIG_LTQ_SSIO_GPHY1_MODE & 0x7) << 27)
  5460. +
  5461. +#define SSIO_CON1_US_FPI (2 << 30)
  5462. +#define SSIO_CON1_FPID_2HZ (0 << 23)
  5463. +#define SSIO_CON1_FPID_4HZ (1 << 23)
  5464. +#define SSIO_CON1_FPID_8HZ (2 << 23)
  5465. +#define SSIO_CON1_FPID_10HZ (3 << 23)
  5466. +#define SSIO_CON1_FPIS_1_2 (1 << 20)
  5467. +#define SSIO_CON1_FPIS_1_32 (2 << 20)
  5468. +#define SSIO_CON1_FPIS_1_64 (3 << 20)
  5469. +
  5470. +#define SSIO_CON1_GPHY2_SHIFT 15
  5471. +#define SSIO_CON1_GPHY2_CONFIG ((CONFIG_LTQ_SSIO_GPHY2_MODE & 0x7) << 15)
  5472. +
  5473. +#define SSIO_CON1_GROUP2 (1 << 2)
  5474. +#define SSIO_CON1_GROUP1 (1 << 1)
  5475. +#define SSIO_CON1_GROUP0 (1 << 0)
  5476. +#define SSIO_CON1_GROUP_CONFIG (0x3)
  5477. +
  5478. +#ifdef CONFIG_LTQ_SSIO_SHIFT_REGS
  5479. +#define enable_ssio 1
  5480. +#else
  5481. +#define enable_ssio 0
  5482. +
  5483. +#define CONFIG_LTQ_SSIO_GPHY1_MODE 0
  5484. +#define CONFIG_LTQ_SSIO_GPHY2_MODE 0
  5485. +#define CONFIG_LTQ_SSIO_INIT_VALUE 0
  5486. +#endif
  5487. +
  5488. +#ifdef CONFIG_LTQ_SSIO_EDGE_FALLING
  5489. +#define SSIO_RZFL_CONFIG SSIO_CON0_RZFL
  5490. +#else
  5491. +#define SSIO_RZFL_CONFIG 0
  5492. +#endif
  5493. +
  5494. +struct ltq_gpio_port_regs {
  5495. + __be32 out;
  5496. + __be32 in;
  5497. + __be32 dir;
  5498. + __be32 altsel0;
  5499. + __be32 altsel1;
  5500. + __be32 od;
  5501. + __be32 stoff;
  5502. + __be32 pudsel;
  5503. + __be32 puden;
  5504. + __be32 rsvd1[3];
  5505. +};
  5506. +
  5507. +struct ltq_gpio_regs {
  5508. + u32 rsvd[4];
  5509. + struct ltq_gpio_port_regs ports[CONFIG_LTQ_GPIO_MAX_BANKS];
  5510. +};
  5511. +
  5512. +struct ltq_gpio3_regs {
  5513. + u32 rsvd0[13];
  5514. + __be32 od;
  5515. + __be32 pudsel;
  5516. + __be32 puden;
  5517. + u32 rsvd1[9];
  5518. + __be32 altsel1;
  5519. + u32 rsvd2[14];
  5520. + __be32 out;
  5521. + __be32 in;
  5522. + __be32 dir;
  5523. + __be32 altsel0;
  5524. +};
  5525. +
  5526. +struct ltq_ssio_regs {
  5527. + __be32 con0;
  5528. + __be32 con1;
  5529. + __be32 cpu0;
  5530. + __be32 cpu1;
  5531. + __be32 ar;
  5532. +};
  5533. +
  5534. +static struct ltq_gpio_regs *ltq_gpio_regs =
  5535. + (struct ltq_gpio_regs *) CKSEG1ADDR(LTQ_GPIO_BASE);
  5536. +
  5537. +static struct ltq_gpio3_regs *ltq_gpio3_regs =
  5538. + (struct ltq_gpio3_regs *) CKSEG1ADDR(LTQ_GPIO_BASE);
  5539. +
  5540. +static struct ltq_ssio_regs *ltq_ssio_regs =
  5541. + (struct ltq_ssio_regs *) CKSEG1ADDR(LTQ_SSIO_BASE);
  5542. +
  5543. +static int is_gpio_bank3(unsigned int port)
  5544. +{
  5545. +#ifdef CONFIG_LTQ_HAS_GPIO_BANK3
  5546. + return port == 3;
  5547. +#else
  5548. + return 0;
  5549. +#endif
  5550. +}
  5551. +
  5552. +static int is_gpio_ssio(unsigned int gpio)
  5553. +{
  5554. +#ifdef CONFIG_LTQ_SSIO_SHIFT_REGS
  5555. + return gpio >= SSIO_GPIO_BASE;
  5556. +#else
  5557. + return 0;
  5558. +#endif
  5559. +}
  5560. +
  5561. +static inline int ssio_gpio_to_bit(unsigned gpio)
  5562. +{
  5563. + return 1 << (gpio - SSIO_GPIO_BASE);
  5564. +}
  5565. +
  5566. +int ltq_gpio_init(void)
  5567. +{
  5568. + ltq_writel(&ltq_ssio_regs->ar, 0);
  5569. + ltq_writel(&ltq_ssio_regs->cpu0, CONFIG_LTQ_SSIO_INIT_VALUE);
  5570. + ltq_writel(&ltq_ssio_regs->cpu1, 0);
  5571. + ltq_writel(&ltq_ssio_regs->con0, SSIO_CON0_SWU);
  5572. +
  5573. + if (enable_ssio) {
  5574. + ltq_writel(&ltq_ssio_regs->con0, SSIO_CON0_GPHY1_CONFIG |
  5575. + SSIO_RZFL_CONFIG);
  5576. + ltq_writel(&ltq_ssio_regs->con1, SSIO_CON1_US_FPI |
  5577. + SSIO_CON1_FPID_8HZ | SSIO_CON1_GPHY2_CONFIG |
  5578. + SSIO_CON1_GROUP_CONFIG);
  5579. + }
  5580. +
  5581. + return 0;
  5582. +}
  5583. +
  5584. +int gpio_request(unsigned gpio, const char *label)
  5585. +{
  5586. + return 0;
  5587. +}
  5588. +
  5589. +int gpio_free(unsigned gpio)
  5590. +{
  5591. + return 0;
  5592. +}
  5593. +
  5594. +int gpio_direction_input(unsigned gpio)
  5595. +{
  5596. + unsigned port = gpio_to_port(gpio);
  5597. + const void *gpio_od = &ltq_gpio_regs->ports[port].od;
  5598. + const void *gpio_altsel0 = &ltq_gpio_regs->ports[port].altsel0;
  5599. + const void *gpio_altsel1 = &ltq_gpio_regs->ports[port].altsel1;
  5600. + const void *gpio_dir = &ltq_gpio_regs->ports[port].dir;
  5601. +
  5602. + if (is_gpio_ssio(gpio))
  5603. + return 0;
  5604. +
  5605. + if (is_gpio_bank3(port)) {
  5606. + gpio_od = &ltq_gpio3_regs->od;
  5607. + gpio_altsel0 = &ltq_gpio3_regs->altsel0;
  5608. + gpio_altsel1 = &ltq_gpio3_regs->altsel1;
  5609. + gpio_dir = &ltq_gpio3_regs->dir;
  5610. + }
  5611. +
  5612. + /*
  5613. + * Reset open drain and altsel configs to workaround improper
  5614. + * reset values or unwanted modifications by BootROM
  5615. + */
  5616. + ltq_clrbits(gpio_od, gpio_to_bit(gpio));
  5617. + ltq_clrbits(gpio_altsel0, gpio_to_bit(gpio));
  5618. + ltq_clrbits(gpio_altsel1, gpio_to_bit(gpio));
  5619. +
  5620. + /* Switch to input */
  5621. + ltq_clrbits(gpio_dir, gpio_to_bit(gpio));
  5622. +
  5623. + return 0;
  5624. +}
  5625. +
  5626. +int gpio_direction_output(unsigned gpio, int value)
  5627. +{
  5628. + unsigned port = gpio_to_port(gpio);
  5629. + const void *gpio_od = &ltq_gpio_regs->ports[port].od;
  5630. + const void *gpio_altsel0 = &ltq_gpio_regs->ports[port].altsel0;
  5631. + const void *gpio_altsel1 = &ltq_gpio_regs->ports[port].altsel1;
  5632. + const void *gpio_dir = &ltq_gpio_regs->ports[port].dir;
  5633. + const void *gpio_out = &ltq_gpio_regs->ports[port].out;
  5634. + u32 data = gpio_to_bit(gpio);
  5635. +
  5636. + if (is_gpio_ssio(gpio)) {
  5637. + data = ssio_gpio_to_bit(gpio);
  5638. + if (value)
  5639. + ltq_setbits(&ltq_ssio_regs->cpu0, data);
  5640. + else
  5641. + ltq_clrbits(&ltq_ssio_regs->cpu0, data);
  5642. +
  5643. + return 0;
  5644. + }
  5645. +
  5646. + if (is_gpio_bank3(port)) {
  5647. + gpio_od = &ltq_gpio3_regs->od;
  5648. + gpio_altsel0 = &ltq_gpio3_regs->altsel0;
  5649. + gpio_altsel1 = &ltq_gpio3_regs->altsel1;
  5650. + gpio_dir = &ltq_gpio3_regs->dir;
  5651. + gpio_out = &ltq_gpio3_regs->out;
  5652. + }
  5653. +
  5654. + /*
  5655. + * Reset open drain and altsel configs to workaround improper
  5656. + * reset values or unwanted modifications by BootROM
  5657. + */
  5658. + ltq_setbits(gpio_od, data);
  5659. + ltq_clrbits(gpio_altsel0, data);
  5660. + ltq_clrbits(gpio_altsel1, data);
  5661. +
  5662. + if (value)
  5663. + ltq_setbits(gpio_out, data);
  5664. + else
  5665. + ltq_clrbits(gpio_out, data);
  5666. +
  5667. + /* Switch to output */
  5668. + ltq_setbits(gpio_dir, data);
  5669. +
  5670. + return 0;
  5671. +}
  5672. +
  5673. +int gpio_get_value(unsigned gpio)
  5674. +{
  5675. + unsigned port = gpio_to_port(gpio);
  5676. + const void *gpio_in = &ltq_gpio_regs->ports[port].in;
  5677. + u32 data = gpio_to_bit(gpio);
  5678. + u32 val;
  5679. +
  5680. + if (is_gpio_ssio(gpio)) {
  5681. + gpio_in = &ltq_ssio_regs->cpu0;
  5682. + data = ssio_gpio_to_bit(gpio);
  5683. + }
  5684. +
  5685. + if (is_gpio_bank3(port))
  5686. + gpio_in = &ltq_gpio3_regs->in;
  5687. +
  5688. + val = ltq_readl(gpio_in);
  5689. +
  5690. + return !!(val & data);
  5691. +}
  5692. +
  5693. +int gpio_set_value(unsigned gpio, int value)
  5694. +{
  5695. + unsigned port = gpio_to_port(gpio);
  5696. + const void *gpio_out = &ltq_gpio_regs->ports[port].out;
  5697. + u32 data = gpio_to_bit(gpio);
  5698. +
  5699. + if (is_gpio_ssio(gpio)) {
  5700. + gpio_out = &ltq_ssio_regs->cpu0;
  5701. + data = ssio_gpio_to_bit(gpio);
  5702. + }
  5703. +
  5704. + if (is_gpio_bank3(port))
  5705. + gpio_out = &ltq_gpio3_regs->out;
  5706. +
  5707. + if (value)
  5708. + ltq_setbits(gpio_out, data);
  5709. + else
  5710. + ltq_clrbits(gpio_out, data);
  5711. +
  5712. + return 0;
  5713. +}
  5714. +
  5715. +int gpio_set_altfunc(unsigned gpio, int altsel0, int altsel1, int dir)
  5716. +{
  5717. + unsigned port = gpio_to_port(gpio);
  5718. + const void *gpio_od = &ltq_gpio_regs->ports[port].od;
  5719. + const void *gpio_altsel0 = &ltq_gpio_regs->ports[port].altsel0;
  5720. + const void *gpio_altsel1 = &ltq_gpio_regs->ports[port].altsel1;
  5721. + const void *gpio_dir = &ltq_gpio_regs->ports[port].dir;
  5722. +
  5723. + if (is_gpio_ssio(gpio))
  5724. + return 0;
  5725. +
  5726. + if (is_gpio_bank3(port)) {
  5727. + gpio_od = &ltq_gpio3_regs->od;
  5728. + gpio_altsel0 = &ltq_gpio3_regs->altsel0;
  5729. + gpio_altsel1 = &ltq_gpio3_regs->altsel1;
  5730. + gpio_dir = &ltq_gpio3_regs->dir;
  5731. + }
  5732. +
  5733. + if (altsel0)
  5734. + ltq_setbits(gpio_altsel0, gpio_to_bit(gpio));
  5735. + else
  5736. + ltq_clrbits(gpio_altsel0, gpio_to_bit(gpio));
  5737. +
  5738. + if (altsel1)
  5739. + ltq_setbits(gpio_altsel1, gpio_to_bit(gpio));
  5740. + else
  5741. + ltq_clrbits(gpio_altsel1, gpio_to_bit(gpio));
  5742. +
  5743. + if (dir) {
  5744. + ltq_setbits(gpio_od, gpio_to_bit(gpio));
  5745. + ltq_setbits(gpio_dir, gpio_to_bit(gpio));
  5746. + } else {
  5747. + ltq_clrbits(gpio_od, gpio_to_bit(gpio));
  5748. + ltq_clrbits(gpio_dir, gpio_to_bit(gpio));
  5749. + }
  5750. +
  5751. + return 0;
  5752. +}
  5753. +
  5754. +int gpio_set_opendrain(unsigned gpio, int od)
  5755. +{
  5756. + unsigned port = gpio_to_port(gpio);
  5757. + const void *gpio_od = &ltq_gpio_regs->ports[port].od;
  5758. +
  5759. + if (is_gpio_ssio(gpio))
  5760. + return 0;
  5761. +
  5762. + if (is_gpio_bank3(port))
  5763. + gpio_od = &ltq_gpio3_regs->od;
  5764. +
  5765. + if (od)
  5766. + ltq_setbits(gpio_od, gpio_to_bit(gpio));
  5767. + else
  5768. + ltq_clrbits(gpio_od, gpio_to_bit(gpio));
  5769. +
  5770. + return 0;
  5771. +}
  5772. --- a/drivers/mtd/cfi_flash.c
  5773. +++ b/drivers/mtd/cfi_flash.c
  5774. @@ -161,6 +161,18 @@ u64 flash_read64(void *addr)__attribute_
  5775. #define flash_read64 __flash_read64
  5776. #endif
  5777. +static inline void *__flash_swap_addr(unsigned long addr)
  5778. +{
  5779. + return (void *) addr;
  5780. +}
  5781. +
  5782. +#ifdef CONFIG_CFI_FLASH_USE_WEAK_ADDR_SWAP
  5783. +void *flash_swap_addr(unsigned long addr)
  5784. + __attribute__((weak, alias("__flash_swap_addr")));
  5785. +#else
  5786. +#define flash_swap_addr __flash_swap_addr
  5787. +#endif
  5788. +
  5789. /*-----------------------------------------------------------------------
  5790. */
  5791. #if defined(CONFIG_ENV_IS_IN_FLASH) || defined(CONFIG_ENV_ADDR_REDUND) || (CONFIG_SYS_MONITOR_BASE >= CONFIG_SYS_FLASH_BASE)
  5792. @@ -196,7 +208,7 @@ flash_map (flash_info_t * info, flash_se
  5793. {
  5794. unsigned int byte_offset = offset * info->portwidth;
  5795. - return (void *)(info->start[sect] + byte_offset);
  5796. + return flash_swap_addr(info->start[sect] + byte_offset);
  5797. }
  5798. static inline void flash_unmap(flash_info_t *info, flash_sect_t sect,
  5799. --- a/drivers/mtd/nand/Makefile
  5800. +++ b/drivers/mtd/nand/Makefile
  5801. @@ -53,6 +53,7 @@ COBJS-$(CONFIG_NAND_JZ4740) += jz4740_na
  5802. COBJS-$(CONFIG_NAND_KB9202) += kb9202_nand.o
  5803. COBJS-$(CONFIG_NAND_KIRKWOOD) += kirkwood_nand.o
  5804. COBJS-$(CONFIG_NAND_KMETER1) += kmeter1_nand.o
  5805. +COBJS-$(CONFIG_NAND_LANTIQ) += lantiq_nand.o
  5806. COBJS-$(CONFIG_NAND_MPC5121_NFC) += mpc5121_nfc.o
  5807. COBJS-$(CONFIG_NAND_MXC) += mxc_nand.o
  5808. COBJS-$(CONFIG_NAND_MXS) += mxs_nand.o
  5809. --- /dev/null
  5810. +++ b/drivers/mtd/nand/lantiq_nand.c
  5811. @@ -0,0 +1,126 @@
  5812. +/*
  5813. + * Copyright (C) 2012-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  5814. + *
  5815. + * SPDX-License-Identifier: GPL-2.0+
  5816. + */
  5817. +
  5818. +#include <common.h>
  5819. +#include <linux/mtd/nand.h>
  5820. +#include <linux/compiler.h>
  5821. +#include <asm/arch/soc.h>
  5822. +#include <asm/arch/nand.h>
  5823. +#include <asm/lantiq/io.h>
  5824. +
  5825. +#define NAND_CON_ECC_ON (1 << 31)
  5826. +#define NAND_CON_LATCH_PRE (1 << 23)
  5827. +#define NAND_CON_LATCH_WP (1 << 22)
  5828. +#define NAND_CON_LATCH_SE (1 << 21)
  5829. +#define NAND_CON_LATCH_CS (1 << 20)
  5830. +#define NAND_CON_LATCH_CLE (1 << 19)
  5831. +#define NAND_CON_LATCH_ALE (1 << 18)
  5832. +#define NAND_CON_OUT_CS1 (1 << 10)
  5833. +#define NAND_CON_IN_CS1 (1 << 8)
  5834. +#define NAND_CON_PRE_P (1 << 7)
  5835. +#define NAND_CON_WP_P (1 << 6)
  5836. +#define NAND_CON_SE_P (1 << 5)
  5837. +#define NAND_CON_CS_P (1 << 4)
  5838. +#define NAND_CON_CLE_P (1 << 3)
  5839. +#define NAND_CON_ALE_P (1 << 2)
  5840. +#define NAND_CON_CSMUX (1 << 1)
  5841. +#define NAND_CON_NANDM (1 << 0)
  5842. +
  5843. +#define NAND_WAIT_WR_C (1 << 3)
  5844. +#define NAND_WAIT_RDBY (1 << 0)
  5845. +
  5846. +#define NAND_CMD_ALE (1 << 2)
  5847. +#define NAND_CMD_CLE (1 << 3)
  5848. +#define NAND_CMD_CS (1 << 4)
  5849. +#define NAND_CMD_SE (1 << 5)
  5850. +#define NAND_CMD_WP (1 << 6)
  5851. +#define NAND_CMD_PRE (1 << 7)
  5852. +
  5853. +struct ltq_nand_regs {
  5854. + __be32 con; /* NAND controller control */
  5855. + __be32 wait; /* NAND Flash Device RD/BY State */
  5856. + __be32 ecc0; /* NAND Flash ECC Register 0 */
  5857. + __be32 ecc_ac; /* NAND Flash ECC Register address counter */
  5858. + __be32 ecc_cr; /* NAND Flash ECC Comparison */
  5859. +};
  5860. +
  5861. +static struct ltq_nand_regs *ltq_nand_regs =
  5862. + (struct ltq_nand_regs *) CKSEG1ADDR(LTQ_EBU_NAND_BASE);
  5863. +
  5864. +static void ltq_nand_wait_ready(void)
  5865. +{
  5866. + while ((ltq_readl(&ltq_nand_regs->wait) & NAND_WAIT_WR_C) == 0)
  5867. + ;
  5868. +}
  5869. +
  5870. +static int ltq_nand_dev_ready(struct mtd_info *mtd)
  5871. +{
  5872. + u32 data = ltq_readl(&ltq_nand_regs->wait);
  5873. + return data & NAND_WAIT_RDBY;
  5874. +}
  5875. +
  5876. +static void ltq_nand_select_chip(struct mtd_info *mtd, int chip)
  5877. +{
  5878. + if (chip == 0) {
  5879. + ltq_setbits(&ltq_nand_regs->con, NAND_CON_NANDM);
  5880. + ltq_setbits(&ltq_nand_regs->con, NAND_CON_LATCH_CS);
  5881. + } else {
  5882. + ltq_clrbits(&ltq_nand_regs->con, NAND_CON_LATCH_CS);
  5883. + ltq_clrbits(&ltq_nand_regs->con, NAND_CON_NANDM);
  5884. + }
  5885. +}
  5886. +
  5887. +static void ltq_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
  5888. +{
  5889. + struct nand_chip *chip = mtd->priv;
  5890. + unsigned long addr = (unsigned long) chip->IO_ADDR_W;
  5891. +
  5892. + if (ctrl & NAND_CTRL_CHANGE) {
  5893. + if (ctrl & NAND_ALE)
  5894. + addr |= NAND_CMD_ALE;
  5895. + else
  5896. + addr &= ~NAND_CMD_ALE;
  5897. +
  5898. + if (ctrl & NAND_CLE)
  5899. + addr |= NAND_CMD_CLE;
  5900. + else
  5901. + addr &= ~NAND_CMD_CLE;
  5902. +
  5903. + chip->IO_ADDR_W = (void __iomem *) addr;
  5904. + }
  5905. +
  5906. + if (cmd != NAND_CMD_NONE) {
  5907. + writeb(cmd, chip->IO_ADDR_W);
  5908. + ltq_nand_wait_ready();
  5909. + }
  5910. +}
  5911. +
  5912. +int ltq_nand_init(struct nand_chip *nand)
  5913. +{
  5914. + /* Enable NAND, set NAND CS to EBU CS1, enable EBU CS mux */
  5915. + ltq_writel(&ltq_nand_regs->con, NAND_CON_OUT_CS1 | NAND_CON_IN_CS1 |
  5916. + NAND_CON_PRE_P | NAND_CON_WP_P | NAND_CON_SE_P |
  5917. + NAND_CON_CS_P | NAND_CON_CSMUX);
  5918. +
  5919. + nand->dev_ready = ltq_nand_dev_ready;
  5920. + nand->select_chip = ltq_nand_select_chip;
  5921. + nand->cmd_ctrl = ltq_nand_cmd_ctrl;
  5922. +
  5923. + nand->chip_delay = 30;
  5924. + nand->options = 0;
  5925. + nand->ecc.mode = NAND_ECC_SOFT;
  5926. +
  5927. + /* Enable CS bit in address offset */
  5928. + nand->IO_ADDR_R = nand->IO_ADDR_R + NAND_CMD_CS;
  5929. + nand->IO_ADDR_W = nand->IO_ADDR_W + NAND_CMD_CS;
  5930. +
  5931. + return 0;
  5932. +}
  5933. +
  5934. +__weak int board_nand_init(struct nand_chip *chip)
  5935. +{
  5936. + return ltq_nand_init(chip);
  5937. +}
  5938. --- a/drivers/net/Makefile
  5939. +++ b/drivers/net/Makefile
  5940. @@ -37,6 +37,8 @@ COBJS-$(CONFIG_INCA_IP_SWITCH) += inca-i
  5941. COBJS-$(CONFIG_DRIVER_KS8695ETH) += ks8695eth.o
  5942. COBJS-$(CONFIG_KS8851_MLL) += ks8851_mll.o
  5943. COBJS-$(CONFIG_LAN91C96) += lan91c96.o
  5944. +COBJS-$(CONFIG_LANTIQ_DANUBE_ETOP) += lantiq_danube_etop.o
  5945. +COBJS-$(CONFIG_LANTIQ_VRX200_SWITCH) += lantiq_vrx200_switch.o
  5946. COBJS-$(CONFIG_MACB) += macb.o
  5947. COBJS-$(CONFIG_MCFFEC) += mcffec.o mcfmii.o
  5948. COBJS-$(CONFIG_MPC5xxx_FEC) += mpc5xxx_fec.o
  5949. --- /dev/null
  5950. +++ b/drivers/net/lantiq_danube_etop.c
  5951. @@ -0,0 +1,410 @@
  5952. +/*
  5953. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  5954. + *
  5955. + * SPDX-License-Identifier: GPL-2.0+
  5956. + */
  5957. +
  5958. +#include <common.h>
  5959. +#include <malloc.h>
  5960. +#include <netdev.h>
  5961. +#include <miiphy.h>
  5962. +#include <switch.h>
  5963. +#include <asm/lantiq/io.h>
  5964. +#include <asm/lantiq/eth.h>
  5965. +#include <asm/lantiq/pm.h>
  5966. +#include <asm/lantiq/reset.h>
  5967. +#include <asm/lantiq/dma.h>
  5968. +#include <asm/arch/soc.h>
  5969. +
  5970. +#define LTQ_PPE_ETOP_MDIO_ACC_RA (1 << 31)
  5971. +#define LTQ_PPE_ETOP_MDIO_CFG_UMM1 (1 << 2)
  5972. +#define LTQ_PPE_ETOP_MDIO_CFG_UMM0 (1 << 1)
  5973. +
  5974. +#define LTQ_PPE_ETOP_CFG_TCKINV1 (1 << 11)
  5975. +#define LTQ_PPE_ETOP_CFG_TCKINV0 (1 << 10)
  5976. +#define LTQ_PPE_ETOP_CFG_FEN1 (1 << 9)
  5977. +#define LTQ_PPE_ETOP_CFG_FEN0 (1 << 8)
  5978. +#define LTQ_PPE_ETOP_CFG_SEN1 (1 << 7)
  5979. +#define LTQ_PPE_ETOP_CFG_SEN0 (1 << 6)
  5980. +#define LTQ_PPE_ETOP_CFG_TURBO1 (1 << 5)
  5981. +#define LTQ_PPE_ETOP_CFG_REMII1 (1 << 4)
  5982. +#define LTQ_PPE_ETOP_CFG_OFF1 (1 << 3)
  5983. +#define LTQ_PPE_ETOP_CFG_TURBO0 (1 << 2)
  5984. +#define LTQ_PPE_ETOP_CFG_REMII0 (1 << 1)
  5985. +#define LTQ_PPE_ETOP_CFG_OFF0 (1 << 0)
  5986. +
  5987. +#define LTQ_PPE_ENET0_MAC_CFG_CGEN (1 << 11)
  5988. +#define LTQ_PPE_ENET0_MAC_CFG_DUPLEX (1 << 2)
  5989. +#define LTQ_PPE_ENET0_MAC_CFG_SPEED (1 << 1)
  5990. +#define LTQ_PPE_ENET0_MAC_CFG_LINK (1 << 0)
  5991. +
  5992. +#define LTQ_PPE_ENETS0_CFG_FTUC (1 << 28)
  5993. +
  5994. +#define LTQ_ETH_RX_BUFFER_CNT PKTBUFSRX
  5995. +#define LTQ_ETH_TX_BUFFER_CNT 8
  5996. +#define LTQ_ETH_RX_DATA_SIZE PKTSIZE_ALIGN
  5997. +#define LTQ_ETH_IP_ALIGN 2
  5998. +
  5999. +#define LTQ_MDIO_DRV_NAME "ltq-mdio"
  6000. +#define LTQ_ETH_DRV_NAME "ltq-eth"
  6001. +
  6002. +struct ltq_ppe_etop_regs {
  6003. + u32 mdio_cfg; /* MDIO configuration */
  6004. + u32 mdio_acc; /* MDIO access */
  6005. + u32 cfg; /* ETOP configuration */
  6006. + u32 ig_vlan_cos; /* IG VLAN priority CoS mapping */
  6007. + u32 ig_dscp_cos3; /* IG DSCP CoS mapping 3 */
  6008. + u32 ig_dscp_cos2; /* IG DSCP CoS mapping 2 */
  6009. + u32 ig_dscp_cos1; /* IG DSCP CoS mapping 1 */
  6010. + u32 ig_dscp_cos0; /* IG DSCP CoS mapping 0 */
  6011. + u32 ig_plen_ctrl; /* IG frame length control */
  6012. + u32 rsvd0[3];
  6013. + u32 vpid; /* VLAN protocol ID */
  6014. +};
  6015. +
  6016. +struct ltq_ppe_enet_regs {
  6017. + u32 mac_cfg; /* MAC configuration */
  6018. + u32 rsvd0[3];
  6019. + u32 ig_cfg; /* Ingress configuration */
  6020. + u32 ig_pgcnt; /* Ingress buffer used page count */
  6021. + u32 rsvd1;
  6022. + u32 ig_buf_ctrl; /* Ingress buffer backpressure ctrl */
  6023. + u32 cos_cfg; /* Classification configuration */
  6024. + u32 ig_drop; /* Total ingress drop frames */
  6025. + u32 ig_err; /* Total ingress error frames */
  6026. + u32 mac_da0; /* Ingress MAC address 0 */
  6027. + u32 mac_da1; /* Ingress MAC address 1 */
  6028. + u32 rsvd2[22];
  6029. + u32 pgcnt; /* Page counter */
  6030. + u32 rsvd3;
  6031. + u32 hf_ctrl; /* Half duplex control */
  6032. + u32 tx_ctrl; /* Transmit control */
  6033. + u32 rsvd4;
  6034. + u32 vlcos0; /* VLAN insertion config CoS 0 */
  6035. + u32 vlcos1; /* VLAN insertion config CoS 1 */
  6036. + u32 vlcos2; /* VLAN insertion config CoS 2 */
  6037. + u32 vlcos3; /* VLAN insertion config CoS 3 */
  6038. + u32 eg_col; /* Total egress collision frames */
  6039. + u32 eg_drop; /* Total egress drop frames */
  6040. +};
  6041. +
  6042. +struct ltq_eth_priv {
  6043. + struct ltq_dma_device dma_dev;
  6044. + struct mii_dev *bus;
  6045. + struct eth_device *dev;
  6046. + int rx_num;
  6047. + int tx_num;
  6048. +};
  6049. +
  6050. +struct ltq_mdio_access {
  6051. + union {
  6052. + struct {
  6053. + unsigned ra:1;
  6054. + unsigned rw:1;
  6055. + unsigned rsvd:4;
  6056. + unsigned phya:5;
  6057. + unsigned rega:5;
  6058. + unsigned phyd:16;
  6059. + } reg;
  6060. + u32 val;
  6061. + };
  6062. +};
  6063. +
  6064. +static struct ltq_ppe_etop_regs *ltq_ppe_etop_regs =
  6065. + (struct ltq_ppe_etop_regs *) CKSEG1ADDR(LTQ_PPE_ETOP_BASE);
  6066. +
  6067. +static struct ltq_ppe_enet_regs *ltq_ppe_enet0_regs =
  6068. + (struct ltq_ppe_enet_regs *) CKSEG1ADDR(LTQ_PPE_ENET0_BASE);
  6069. +
  6070. +static inline int ltq_mdio_poll(void)
  6071. +{
  6072. + struct ltq_mdio_access acc;
  6073. + unsigned cnt = 10000;
  6074. +
  6075. + while (likely(cnt--)) {
  6076. + acc.val = ltq_readl(&ltq_ppe_etop_regs->mdio_acc);
  6077. + if (!acc.reg.ra)
  6078. + return 0;
  6079. + }
  6080. +
  6081. + return 1;
  6082. +}
  6083. +
  6084. +static int ltq_mdio_read(struct mii_dev *bus, int addr, int dev_addr,
  6085. + int regnum)
  6086. +{
  6087. + struct ltq_mdio_access acc;
  6088. + int ret;
  6089. +
  6090. + acc.val = 0;
  6091. + acc.reg.ra = 1;
  6092. + acc.reg.rw = 1;
  6093. + acc.reg.phya = addr;
  6094. + acc.reg.rega = regnum;
  6095. +
  6096. + ret = ltq_mdio_poll();
  6097. + if (ret)
  6098. + return ret;
  6099. +
  6100. + ltq_writel(&ltq_ppe_etop_regs->mdio_acc, acc.val);
  6101. +
  6102. + ret = ltq_mdio_poll();
  6103. + if (ret)
  6104. + return ret;
  6105. +
  6106. + acc.val = ltq_readl(&ltq_ppe_etop_regs->mdio_acc);
  6107. +
  6108. + return acc.reg.phyd;
  6109. +}
  6110. +
  6111. +static int ltq_mdio_write(struct mii_dev *bus, int addr, int dev_addr,
  6112. + int regnum, u16 val)
  6113. +{
  6114. + struct ltq_mdio_access acc;
  6115. + int ret;
  6116. +
  6117. + acc.val = 0;
  6118. + acc.reg.ra = 1;
  6119. + acc.reg.rw = 0;
  6120. + acc.reg.phya = addr;
  6121. + acc.reg.rega = regnum;
  6122. + acc.reg.phyd = val;
  6123. +
  6124. + ret = ltq_mdio_poll();
  6125. + if (ret)
  6126. + return ret;
  6127. +
  6128. + ltq_writel(&ltq_ppe_etop_regs->mdio_acc, acc.val);
  6129. +
  6130. + return 0;
  6131. +}
  6132. +
  6133. +static inline void ltq_eth_write_hwaddr(const struct eth_device *dev)
  6134. +{
  6135. + u32 da0, da1;
  6136. +
  6137. + da0 = (dev->enetaddr[0] << 24) + (dev->enetaddr[1] << 16) +
  6138. + (dev->enetaddr[2] << 8) + dev->enetaddr[3];
  6139. + da1 = (dev->enetaddr[4] << 24) + (dev->enetaddr[5] << 16);
  6140. +
  6141. + ltq_writel(&ltq_ppe_enet0_regs->mac_da0, da0);
  6142. + ltq_writel(&ltq_ppe_enet0_regs->mac_da1, da1);
  6143. +}
  6144. +
  6145. +static inline u8 *ltq_eth_rx_packet_align(int rx_num)
  6146. +{
  6147. + u8 *packet = (u8 *) NetRxPackets[rx_num];
  6148. +
  6149. + /*
  6150. + * IP header needs
  6151. + */
  6152. + return packet + LTQ_ETH_IP_ALIGN;
  6153. +}
  6154. +
  6155. +static int ltq_eth_init(struct eth_device *dev, bd_t *bis)
  6156. +{
  6157. + struct ltq_eth_priv *priv = dev->priv;
  6158. + struct ltq_dma_device *dma_dev = &priv->dma_dev;
  6159. + int i;
  6160. +
  6161. + ltq_eth_write_hwaddr(dev);
  6162. +
  6163. + for (i = 0; i < LTQ_ETH_RX_BUFFER_CNT; i++)
  6164. + ltq_dma_rx_map(dma_dev, i, ltq_eth_rx_packet_align(i),
  6165. + LTQ_ETH_RX_DATA_SIZE);
  6166. +
  6167. + ltq_dma_enable(dma_dev);
  6168. +
  6169. + priv->rx_num = 0;
  6170. + priv->tx_num = 0;
  6171. +
  6172. + return 0;
  6173. +}
  6174. +
  6175. +static void ltq_eth_halt(struct eth_device *dev)
  6176. +{
  6177. + struct ltq_eth_priv *priv = dev->priv;
  6178. + struct ltq_dma_device *dma_dev = &priv->dma_dev;
  6179. +
  6180. + ltq_dma_reset(dma_dev);
  6181. +}
  6182. +
  6183. +static int ltq_eth_send(struct eth_device *dev, void *packet, int length)
  6184. +{
  6185. + struct ltq_eth_priv *priv = dev->priv;
  6186. + struct ltq_dma_device *dma_dev = &priv->dma_dev;
  6187. + int err;
  6188. +
  6189. + /* Minimum payload length w/ CRC is 60 bytes */
  6190. + if (length < 60)
  6191. + length = 60;
  6192. +
  6193. + err = ltq_dma_tx_map(dma_dev, priv->tx_num, packet, length, 10);
  6194. + if (err) {
  6195. + puts("NET: timeout on waiting for TX descriptor\n");
  6196. + return -1;
  6197. + }
  6198. +
  6199. + priv->tx_num = (priv->tx_num + 1) % LTQ_ETH_TX_BUFFER_CNT;
  6200. +
  6201. + return err;
  6202. +}
  6203. +
  6204. +static int ltq_eth_recv(struct eth_device *dev)
  6205. +{
  6206. + struct ltq_eth_priv *priv = dev->priv;
  6207. + struct ltq_dma_device *dma_dev = &priv->dma_dev;
  6208. + u8 *packet;
  6209. + int len;
  6210. +
  6211. + if (!ltq_dma_rx_poll(dma_dev, priv->rx_num))
  6212. + return 0;
  6213. +
  6214. +#if 0
  6215. + printf("%s: rx_num %d\n", __func__, priv->rx_num);
  6216. +#endif
  6217. +
  6218. + len = ltq_dma_rx_length(dma_dev, priv->rx_num);
  6219. + packet = ltq_eth_rx_packet_align(priv->rx_num);
  6220. +
  6221. +#if 0
  6222. + printf("%s: received: packet %p, len %u, rx_num %d\n",
  6223. + __func__, packet, len, priv->rx_num);
  6224. +#endif
  6225. +
  6226. + if (len)
  6227. + NetReceive(packet, len);
  6228. +
  6229. + ltq_dma_rx_map(dma_dev, priv->rx_num, packet,
  6230. + LTQ_ETH_RX_DATA_SIZE);
  6231. +
  6232. + priv->rx_num = (priv->rx_num + 1) % LTQ_ETH_RX_BUFFER_CNT;
  6233. +
  6234. + return 0;
  6235. +}
  6236. +
  6237. +static void ltq_eth_hw_init(const struct ltq_eth_port_config *port)
  6238. +{
  6239. + u32 data;
  6240. +
  6241. + /* Power up ethernet subsystems */
  6242. + ltq_pm_enable(LTQ_PM_ETH);
  6243. +
  6244. + /* Reset ethernet subsystems */
  6245. + ltq_reset_once(LTQ_RESET_ETH, 1);
  6246. +
  6247. + /* Disable MDIO auto-detection */
  6248. + ltq_clrbits(&ltq_ppe_etop_regs->mdio_cfg, LTQ_PPE_ETOP_MDIO_CFG_UMM1 |
  6249. + LTQ_PPE_ETOP_MDIO_CFG_UMM0);
  6250. +
  6251. + /* Enable CRC generation, Full Duplex, 100Mbps, Link up */
  6252. + ltq_writel(&ltq_ppe_enet0_regs->mac_cfg, LTQ_PPE_ENET0_MAC_CFG_CGEN |
  6253. + LTQ_PPE_ENET0_MAC_CFG_DUPLEX |
  6254. + LTQ_PPE_ENET0_MAC_CFG_SPEED |
  6255. + LTQ_PPE_ENET0_MAC_CFG_LINK);
  6256. +
  6257. + /* Reset ETOP cfg and disable all */
  6258. + data = LTQ_PPE_ETOP_CFG_OFF0 | LTQ_PPE_ETOP_CFG_OFF1;
  6259. +
  6260. + /* Enable ENET0, enable store and fetch */
  6261. + data &= ~LTQ_PPE_ETOP_CFG_OFF0;
  6262. + data |= LTQ_PPE_ETOP_CFG_SEN0 | LTQ_PPE_ETOP_CFG_FEN0;
  6263. +
  6264. + if (port->phy_if == PHY_INTERFACE_MODE_RMII)
  6265. + data |= LTQ_PPE_ETOP_CFG_REMII0;
  6266. + else
  6267. + data &= ~LTQ_PPE_ETOP_CFG_REMII0;
  6268. +
  6269. + ltq_writel(&ltq_ppe_etop_regs->cfg, data);
  6270. +
  6271. + /* Set allowed packet length from 64 bytes to 1518 bytes */
  6272. + ltq_writel(&ltq_ppe_etop_regs->ig_plen_ctrl, (64 << 16) | 1518);
  6273. +
  6274. + /* Enable filter for unicast packets */
  6275. + ltq_setbits(&ltq_ppe_enet0_regs->ig_cfg, LTQ_PPE_ENETS0_CFG_FTUC);
  6276. +}
  6277. +
  6278. +int ltq_eth_initialize(const struct ltq_eth_board_config *board_config)
  6279. +{
  6280. + struct eth_device *dev;
  6281. + struct mii_dev *bus;
  6282. + struct ltq_eth_priv *priv;
  6283. + struct ltq_dma_device *dma_dev;
  6284. + const struct ltq_eth_port_config *port = &board_config->ports[0];
  6285. + struct phy_device *phy;
  6286. + struct switch_device *sw;
  6287. + int ret;
  6288. +
  6289. + ltq_dma_init();
  6290. + ltq_eth_hw_init(port);
  6291. +
  6292. + dev = calloc(1, sizeof(*dev));
  6293. + if (!dev)
  6294. + return -1;
  6295. +
  6296. + priv = calloc(1, sizeof(*priv));
  6297. + if (!priv)
  6298. + return -1;
  6299. +
  6300. + bus = mdio_alloc();
  6301. + if (!bus)
  6302. + return -1;
  6303. +
  6304. + sprintf(dev->name, LTQ_ETH_DRV_NAME);
  6305. + dev->priv = priv;
  6306. + dev->init = ltq_eth_init;
  6307. + dev->halt = ltq_eth_halt;
  6308. + dev->recv = ltq_eth_recv;
  6309. + dev->send = ltq_eth_send;
  6310. +
  6311. + sprintf(bus->name, LTQ_MDIO_DRV_NAME);
  6312. + bus->read = ltq_mdio_read;
  6313. + bus->write = ltq_mdio_write;
  6314. + bus->priv = priv;
  6315. +
  6316. + dma_dev = &priv->dma_dev;
  6317. + dma_dev->port = 0;
  6318. + dma_dev->rx_chan.chan_no = 6;
  6319. + dma_dev->rx_chan.class = 3;
  6320. + dma_dev->rx_chan.num_desc = LTQ_ETH_RX_BUFFER_CNT;
  6321. + dma_dev->rx_endian_swap = LTQ_DMA_ENDIANESS_B3_B2_B1_B0;
  6322. + dma_dev->rx_burst_len = LTQ_DMA_BURST_2WORDS;
  6323. + dma_dev->tx_chan.chan_no = 7;
  6324. + dma_dev->tx_chan.class = 3;
  6325. + dma_dev->tx_chan.num_desc = LTQ_ETH_TX_BUFFER_CNT;
  6326. + dma_dev->tx_endian_swap = LTQ_DMA_ENDIANESS_B3_B2_B1_B0;
  6327. + dma_dev->tx_burst_len = LTQ_DMA_BURST_2WORDS;
  6328. +
  6329. + priv->bus = bus;
  6330. + priv->dev = dev;
  6331. +
  6332. + ret = ltq_dma_register(dma_dev);
  6333. + if (ret)
  6334. + return ret;
  6335. +
  6336. + ret = mdio_register(bus);
  6337. + if (ret)
  6338. + return ret;
  6339. +
  6340. + ret = eth_register(dev);
  6341. + if (ret)
  6342. + return ret;
  6343. +
  6344. + if (port->flags & LTQ_ETH_PORT_SWITCH) {
  6345. + sw = switch_connect(bus);
  6346. + if (!sw)
  6347. + return -1;
  6348. +
  6349. + switch_setup(sw);
  6350. + }
  6351. +
  6352. + if (port->flags & LTQ_ETH_PORT_PHY) {
  6353. + phy = phy_connect(bus, port->phy_addr, dev, port->phy_if);
  6354. + if (!phy)
  6355. + return -1;
  6356. +
  6357. + phy_config(phy);
  6358. + }
  6359. +
  6360. + return 0;
  6361. +}
  6362. --- /dev/null
  6363. +++ b/drivers/net/lantiq_vrx200_switch.c
  6364. @@ -0,0 +1,675 @@
  6365. +/*
  6366. + * Copyright (C) 2010-2011 Lantiq Deutschland GmbH
  6367. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  6368. + *
  6369. + * SPDX-License-Identifier: GPL-2.0+
  6370. + */
  6371. +
  6372. +#define DEBUG
  6373. +
  6374. +#include <common.h>
  6375. +#include <malloc.h>
  6376. +#include <netdev.h>
  6377. +#include <miiphy.h>
  6378. +#include <linux/compiler.h>
  6379. +#include <asm/gpio.h>
  6380. +#include <asm/processor.h>
  6381. +#include <asm/lantiq/io.h>
  6382. +#include <asm/lantiq/eth.h>
  6383. +#include <asm/lantiq/pm.h>
  6384. +#include <asm/lantiq/reset.h>
  6385. +#include <asm/lantiq/dma.h>
  6386. +#include <asm/arch/soc.h>
  6387. +#include <asm/arch/switch.h>
  6388. +
  6389. +#define LTQ_ETH_RX_BUFFER_CNT PKTBUFSRX
  6390. +#define LTQ_ETH_TX_BUFFER_CNT 8
  6391. +#define LTQ_ETH_RX_DATA_SIZE PKTSIZE_ALIGN
  6392. +#define LTQ_ETH_IP_ALIGN 2
  6393. +
  6394. +#define LTQ_MDIO_DRV_NAME "ltq-mdio"
  6395. +#define LTQ_ETH_DRV_NAME "ltq-eth"
  6396. +
  6397. +#define LTQ_ETHSW_MAX_GMAC 6
  6398. +#define LTQ_ETHSW_PMAC 6
  6399. +
  6400. +struct ltq_mdio_phy_addr_reg {
  6401. + union {
  6402. + struct {
  6403. + unsigned rsvd:1;
  6404. + unsigned lnkst:2; /* Link status control */
  6405. + unsigned speed:2; /* Speed control */
  6406. + unsigned fdup:2; /* Full duplex control */
  6407. + unsigned fcontx:2; /* Flow control mode TX */
  6408. + unsigned fconrx:2; /* Flow control mode RX */
  6409. + unsigned addr:5; /* PHY address */
  6410. + } bits;
  6411. + u16 val;
  6412. + };
  6413. +};
  6414. +
  6415. +enum ltq_mdio_phy_addr_lnkst {
  6416. + LTQ_MDIO_PHY_ADDR_LNKST_AUTO = 0,
  6417. + LTQ_MDIO_PHY_ADDR_LNKST_UP = 1,
  6418. + LTQ_MDIO_PHY_ADDR_LNKST_DOWN = 2,
  6419. +};
  6420. +
  6421. +enum ltq_mdio_phy_addr_speed {
  6422. + LTQ_MDIO_PHY_ADDR_SPEED_M10 = 0,
  6423. + LTQ_MDIO_PHY_ADDR_SPEED_M100 = 1,
  6424. + LTQ_MDIO_PHY_ADDR_SPEED_G1 = 2,
  6425. + LTQ_MDIO_PHY_ADDR_SPEED_AUTO = 3,
  6426. +};
  6427. +
  6428. +enum ltq_mdio_phy_addr_fdup {
  6429. + LTQ_MDIO_PHY_ADDR_FDUP_AUTO = 0,
  6430. + LTQ_MDIO_PHY_ADDR_FDUP_ENABLE = 1,
  6431. + LTQ_MDIO_PHY_ADDR_FDUP_DISABLE = 3,
  6432. +};
  6433. +
  6434. +enum ltq_mdio_phy_addr_fcon {
  6435. + LTQ_MDIO_PHY_ADDR_FCON_AUTO = 0,
  6436. + LTQ_MDIO_PHY_ADDR_FCON_ENABLE = 1,
  6437. + LTQ_MDIO_PHY_ADDR_FCON_DISABLE = 3,
  6438. +};
  6439. +
  6440. +struct ltq_mii_mii_cfg_reg {
  6441. + union {
  6442. + struct {
  6443. + unsigned res:1; /* Hardware reset */
  6444. + unsigned en:1; /* xMII interface enable */
  6445. + unsigned isol:1; /* xMII interface isolate */
  6446. + unsigned ldclkdis:1; /* Link down clock disable */
  6447. + unsigned rsvd:1;
  6448. + unsigned crs:2; /* CRS sensitivity config */
  6449. + unsigned rgmii_ibs:1; /* RGMII In Band status */
  6450. + unsigned rmii:1; /* RMII ref clock direction */
  6451. + unsigned miirate:3; /* xMII interface clock rate */
  6452. + unsigned miimode:4; /* xMII interface mode */
  6453. + } bits;
  6454. + u16 val;
  6455. + };
  6456. +};
  6457. +
  6458. +enum ltq_mii_mii_cfg_miirate {
  6459. + LTQ_MII_MII_CFG_MIIRATE_M2P5 = 0,
  6460. + LTQ_MII_MII_CFG_MIIRATE_M25 = 1,
  6461. + LTQ_MII_MII_CFG_MIIRATE_M125 = 2,
  6462. + LTQ_MII_MII_CFG_MIIRATE_M50 = 3,
  6463. + LTQ_MII_MII_CFG_MIIRATE_AUTO = 4,
  6464. +};
  6465. +
  6466. +enum ltq_mii_mii_cfg_miimode {
  6467. + LTQ_MII_MII_CFG_MIIMODE_MIIP = 0,
  6468. + LTQ_MII_MII_CFG_MIIMODE_MIIM = 1,
  6469. + LTQ_MII_MII_CFG_MIIMODE_RMIIP = 2,
  6470. + LTQ_MII_MII_CFG_MIIMODE_RMIIM = 3,
  6471. + LTQ_MII_MII_CFG_MIIMODE_RGMII = 4,
  6472. +};
  6473. +
  6474. +struct ltq_eth_priv {
  6475. + struct ltq_dma_device dma_dev;
  6476. + struct mii_dev *bus;
  6477. + struct eth_device *dev;
  6478. + struct phy_device *phymap[LTQ_ETHSW_MAX_GMAC];
  6479. + int rx_num;
  6480. + int tx_num;
  6481. +};
  6482. +
  6483. +static struct vr9_switch_regs *switch_regs =
  6484. + (struct vr9_switch_regs *) CKSEG1ADDR(LTQ_SWITCH_BASE);
  6485. +
  6486. +static inline void vr9_switch_sync(void)
  6487. +{
  6488. + __asm__("sync");
  6489. +}
  6490. +
  6491. +static inline int vr9_switch_mdio_is_busy(void)
  6492. +{
  6493. + u32 mdio_ctrl = ltq_readl(&switch_regs->mdio.mdio_ctrl);
  6494. +
  6495. + return mdio_ctrl & MDIO_CTRL_MBUSY;
  6496. +}
  6497. +
  6498. +static inline void vr9_switch_mdio_poll(void)
  6499. +{
  6500. + while (vr9_switch_mdio_is_busy())
  6501. + cpu_relax();
  6502. +}
  6503. +
  6504. +static int vr9_switch_mdio_read(struct mii_dev *bus, int phyad, int devad,
  6505. + int regad)
  6506. +{
  6507. + u32 mdio_ctrl;
  6508. + int retval;
  6509. +
  6510. + mdio_ctrl = MDIO_CTRL_OP_READ |
  6511. + ((phyad << MDIO_CTRL_PHYAD_SHIFT) & MDIO_CTRL_PHYAD_MASK) |
  6512. + (regad & MDIO_CTRL_REGAD_MASK);
  6513. +
  6514. + vr9_switch_mdio_poll();
  6515. + ltq_writel(&switch_regs->mdio.mdio_ctrl, mdio_ctrl);
  6516. + vr9_switch_mdio_poll();
  6517. + retval = ltq_readl(&switch_regs->mdio.mdio_read);
  6518. +
  6519. + return retval;
  6520. +}
  6521. +
  6522. +static int vr9_switch_mdio_write(struct mii_dev *bus, int phyad, int devad,
  6523. + int regad, u16 val)
  6524. +{
  6525. + u32 mdio_ctrl;
  6526. +
  6527. + mdio_ctrl = MDIO_CTRL_OP_WRITE |
  6528. + ((phyad << MDIO_CTRL_PHYAD_SHIFT) & MDIO_CTRL_PHYAD_MASK) |
  6529. + (regad & MDIO_CTRL_REGAD_MASK);
  6530. +
  6531. + vr9_switch_mdio_poll();
  6532. + ltq_writel(&switch_regs->mdio.mdio_write, val);
  6533. + ltq_writel(&switch_regs->mdio.mdio_ctrl, mdio_ctrl);
  6534. +
  6535. + return 0;
  6536. +}
  6537. +
  6538. +static void ltq_eth_gmac_update(struct phy_device *phydev, int num)
  6539. +{
  6540. + struct ltq_mdio_phy_addr_reg phy_addr_reg;
  6541. + struct ltq_mii_mii_cfg_reg mii_cfg_reg;
  6542. +
  6543. + phy_addr_reg.val = ltq_readl(to_mdio_phyaddr(switch_regs, num));
  6544. +
  6545. + switch (num) {
  6546. + case 0:
  6547. + case 1:
  6548. + case 5:
  6549. + mii_cfg_reg.val = ltq_readl(to_mii_miicfg(switch_regs, num));
  6550. + break;
  6551. + default:
  6552. + mii_cfg_reg.val = 0;
  6553. + break;
  6554. + }
  6555. +
  6556. + phy_addr_reg.bits.addr = phydev->addr;
  6557. +
  6558. + if (phydev->link)
  6559. + phy_addr_reg.bits.lnkst = LTQ_MDIO_PHY_ADDR_LNKST_UP;
  6560. + else
  6561. + phy_addr_reg.bits.lnkst = LTQ_MDIO_PHY_ADDR_LNKST_DOWN;
  6562. +
  6563. + switch (phydev->speed) {
  6564. + case SPEED_1000:
  6565. + phy_addr_reg.bits.speed = LTQ_MDIO_PHY_ADDR_SPEED_G1;
  6566. + mii_cfg_reg.bits.miirate = LTQ_MII_MII_CFG_MIIRATE_M125;
  6567. + break;
  6568. + case SPEED_100:
  6569. + phy_addr_reg.bits.speed = LTQ_MDIO_PHY_ADDR_SPEED_M100;
  6570. + switch (mii_cfg_reg.bits.miimode) {
  6571. + case LTQ_MII_MII_CFG_MIIMODE_RMIIM:
  6572. + case LTQ_MII_MII_CFG_MIIMODE_RMIIP:
  6573. + mii_cfg_reg.bits.miirate = LTQ_MII_MII_CFG_MIIRATE_M50;
  6574. + break;
  6575. + default:
  6576. + mii_cfg_reg.bits.miirate = LTQ_MII_MII_CFG_MIIRATE_M25;
  6577. + break;
  6578. + }
  6579. + break;
  6580. + default:
  6581. + phy_addr_reg.bits.speed = LTQ_MDIO_PHY_ADDR_SPEED_M10;
  6582. + mii_cfg_reg.bits.miirate = LTQ_MII_MII_CFG_MIIRATE_M2P5;
  6583. + break;
  6584. + }
  6585. +
  6586. + if (phydev->duplex == DUPLEX_FULL)
  6587. + phy_addr_reg.bits.fdup = LTQ_MDIO_PHY_ADDR_FDUP_ENABLE;
  6588. + else
  6589. + phy_addr_reg.bits.fdup = LTQ_MDIO_PHY_ADDR_FDUP_DISABLE;
  6590. +
  6591. + ltq_writel(to_mdio_phyaddr(switch_regs, num), phy_addr_reg.val);
  6592. +
  6593. + switch (num) {
  6594. + case 0:
  6595. + case 1:
  6596. + case 5:
  6597. + ltq_writel(to_mii_miicfg(switch_regs, num), mii_cfg_reg.val);
  6598. + break;
  6599. + default:
  6600. + break;
  6601. + }
  6602. +}
  6603. +
  6604. +static inline u8 *ltq_eth_rx_packet_align(int rx_num)
  6605. +{
  6606. + u8 *packet = (u8 *) NetRxPackets[rx_num];
  6607. +
  6608. + /*
  6609. + * IP header needs
  6610. + */
  6611. + return packet + LTQ_ETH_IP_ALIGN;
  6612. +}
  6613. +
  6614. +static int ltq_eth_init(struct eth_device *dev, bd_t *bis)
  6615. +{
  6616. + struct ltq_eth_priv *priv = dev->priv;
  6617. + struct ltq_dma_device *dma_dev = &priv->dma_dev;
  6618. + struct phy_device *phydev;
  6619. + int i;
  6620. +
  6621. + for (i = 0; i < LTQ_ETHSW_MAX_GMAC; i++) {
  6622. + phydev = priv->phymap[i];
  6623. + if (!phydev)
  6624. + continue;
  6625. +
  6626. + phy_startup(phydev);
  6627. + ltq_eth_gmac_update(phydev, i);
  6628. + }
  6629. +
  6630. + for (i = 0; i < LTQ_ETH_RX_BUFFER_CNT; i++)
  6631. + ltq_dma_rx_map(dma_dev, i, ltq_eth_rx_packet_align(i),
  6632. + LTQ_ETH_RX_DATA_SIZE);
  6633. +
  6634. + ltq_dma_enable(dma_dev);
  6635. +
  6636. + priv->rx_num = 0;
  6637. + priv->tx_num = 0;
  6638. +
  6639. + return 0;
  6640. +}
  6641. +
  6642. +static void ltq_eth_halt(struct eth_device *dev)
  6643. +{
  6644. + struct ltq_eth_priv *priv = dev->priv;
  6645. + struct ltq_dma_device *dma_dev = &priv->dma_dev;
  6646. + struct phy_device *phydev;
  6647. + int i;
  6648. +
  6649. + ltq_dma_reset(dma_dev);
  6650. +
  6651. + for (i = 0; i < LTQ_ETHSW_MAX_GMAC; i++) {
  6652. + phydev = priv->phymap[i];
  6653. + if (!phydev)
  6654. + continue;
  6655. +
  6656. + phy_shutdown(phydev);
  6657. + phydev->link = 0;
  6658. + ltq_eth_gmac_update(phydev, i);
  6659. + }
  6660. +}
  6661. +
  6662. +static int ltq_eth_send(struct eth_device *dev, void *packet, int length)
  6663. +{
  6664. + struct ltq_eth_priv *priv = dev->priv;
  6665. + struct ltq_dma_device *dma_dev = &priv->dma_dev;
  6666. +
  6667. +#if 0
  6668. + printf("%s: packet %p, len %d\n", __func__, packet, length);
  6669. +#endif
  6670. +
  6671. + ltq_dma_tx_map(dma_dev, priv->tx_num, packet, length, 10);
  6672. + priv->tx_num = (priv->tx_num + 1) % LTQ_ETH_TX_BUFFER_CNT;
  6673. +
  6674. + return 0;
  6675. +}
  6676. +
  6677. +static int ltq_eth_recv(struct eth_device *dev)
  6678. +{
  6679. + struct ltq_eth_priv *priv = dev->priv;
  6680. + struct ltq_dma_device *dma_dev = &priv->dma_dev;
  6681. + u8 *packet;
  6682. + int len;
  6683. +
  6684. + if (!ltq_dma_rx_poll(dma_dev, priv->rx_num))
  6685. + return 0;
  6686. +
  6687. +#if 0
  6688. + printf("%s: rx_num %d\n", __func__, priv->rx_num);
  6689. +#endif
  6690. +
  6691. + len = ltq_dma_rx_length(dma_dev, priv->rx_num);
  6692. + packet = ltq_eth_rx_packet_align(priv->rx_num);
  6693. +
  6694. +#if 0
  6695. + printf("%s: received: packet %p, len %u, rx_num %d\n",
  6696. + __func__, packet, len, priv->rx_num);
  6697. +#endif
  6698. +
  6699. + if (len)
  6700. + NetReceive(packet, len);
  6701. +
  6702. + ltq_dma_rx_map(dma_dev, priv->rx_num, packet,
  6703. + LTQ_ETH_RX_DATA_SIZE);
  6704. +
  6705. + priv->rx_num = (priv->rx_num + 1) % LTQ_ETH_RX_BUFFER_CNT;
  6706. +
  6707. + return 0;
  6708. +}
  6709. +
  6710. +static void ltq_eth_gmac_init(int num)
  6711. +{
  6712. + struct ltq_mdio_phy_addr_reg phy_addr_reg;
  6713. + struct ltq_mii_mii_cfg_reg mii_cfg_reg;
  6714. +
  6715. + /* Reset PHY status to link down */
  6716. + phy_addr_reg.val = ltq_readl(to_mdio_phyaddr(switch_regs, num));
  6717. + phy_addr_reg.bits.addr = num;
  6718. + phy_addr_reg.bits.lnkst = LTQ_MDIO_PHY_ADDR_LNKST_DOWN;
  6719. + phy_addr_reg.bits.speed = LTQ_MDIO_PHY_ADDR_SPEED_M10;
  6720. + phy_addr_reg.bits.fdup = LTQ_MDIO_PHY_ADDR_FDUP_DISABLE;
  6721. + ltq_writel(to_mdio_phyaddr(switch_regs, num), phy_addr_reg.val);
  6722. +
  6723. + /* Reset and disable MII interface */
  6724. + switch (num) {
  6725. + case 0:
  6726. + case 1:
  6727. + case 5:
  6728. + mii_cfg_reg.val = ltq_readl(to_mii_miicfg(switch_regs, num));
  6729. + mii_cfg_reg.bits.en = 0;
  6730. + mii_cfg_reg.bits.res = 1;
  6731. + mii_cfg_reg.bits.miirate = LTQ_MII_MII_CFG_MIIRATE_M2P5;
  6732. + ltq_writel(to_mii_miicfg(switch_regs, num), mii_cfg_reg.val);
  6733. + break;
  6734. + default:
  6735. + break;
  6736. + }
  6737. +
  6738. + /*
  6739. + * - enable frame checksum generation
  6740. + * - enable padding of short frames
  6741. + * - disable flow control
  6742. + */
  6743. + ltq_writel(to_mac_ctrl(switch_regs, num, 0),
  6744. + MAC_CTRL0_PADEN | MAC_CTRL0_FCS | MAC_CTRL0_FCON_NONE);
  6745. +
  6746. + vr9_switch_sync();
  6747. +}
  6748. +
  6749. +static void ltq_eth_pmac_init(void)
  6750. +{
  6751. + /*
  6752. + * WAR: buffer congestion:
  6753. + * - shorten preambel to 1 byte
  6754. + * - set TX IPG to 7 bytes
  6755. + */
  6756. +#if 1
  6757. + ltq_writel(to_mac_ctrl(switch_regs, LTQ_ETHSW_PMAC, 1),
  6758. + MAC_CTRL1_SHORTPRE | 7);
  6759. +#endif
  6760. +
  6761. + /*
  6762. + * WAR: systematical concept weakness ACM bug
  6763. + * - set maximum number of used buffer segments to 254
  6764. + * - soft-reset BM FSQM
  6765. + */
  6766. +#if 1
  6767. + ltq_writel(&switch_regs->bm.core.fsqm_gctrl, 253);
  6768. + ltq_setbits(&switch_regs->bm.core.gctrl, BM_GCTRL_F_SRES);
  6769. + ltq_clrbits(&switch_regs->bm.core.gctrl, BM_GCTRL_F_SRES);
  6770. +#endif
  6771. +
  6772. + /*
  6773. + * WAR: switch MAC drop bug
  6774. + */
  6775. +#if 1
  6776. + ltq_writel(to_pce_tbl_key(switch_regs, 0), 0xf);
  6777. + ltq_writel(to_pce_tbl_value(switch_regs, 0), 0x40);
  6778. + ltq_writel(&switch_regs->pce.core.tbl_addr, 0x3);
  6779. + ltq_writel(&switch_regs->pce.core.tbl_ctrl, 0x902f);
  6780. +#endif
  6781. +
  6782. + /*
  6783. + * Configure frame header control:
  6784. + * - enable flow control
  6785. + * - enable CRC check for packets from DMA to PMAC
  6786. + * - remove special tag from packets from PMAC to DMA
  6787. + * - add CRC for packets from DMA to PMAC
  6788. + */
  6789. + ltq_writel(&switch_regs->pmac.hd_ctl, /*PMAC_HD_CTL_FC |*/
  6790. + PMAC_HD_CTL_CCRC | PMAC_HD_CTL_RST | PMAC_HD_CTL_AC |
  6791. + PMAC_HD_CTL_RC);
  6792. +
  6793. +#if 1
  6794. + ltq_writel(&switch_regs->pmac.rx_ipg, 0x8b);
  6795. +#endif
  6796. +
  6797. + /*
  6798. + * - enable frame checksum generation
  6799. + * - enable padding of short frames
  6800. + * - disable flow control
  6801. + */
  6802. + ltq_writel(to_mac_ctrl(switch_regs, LTQ_ETHSW_PMAC, 0),
  6803. + MAC_CTRL0_PADEN | MAC_CTRL0_FCS | MAC_CTRL0_FCON_NONE);
  6804. +
  6805. + vr9_switch_sync();
  6806. +}
  6807. +
  6808. +static void ltq_eth_hw_init(void)
  6809. +{
  6810. + int i;
  6811. +
  6812. + /* Power up ethernet and switch subsystems */
  6813. + ltq_pm_enable(LTQ_PM_ETH);
  6814. +
  6815. + /* Reset ethernet and switch subsystems */
  6816. +#if 0
  6817. + ltq_reset_once(LTQ_RESET_ETH, 10);
  6818. +#endif
  6819. +
  6820. + /* Enable switch macro */
  6821. + ltq_setbits(&switch_regs->mdio.glob_ctrl, MDIO_GLOB_CTRL_SE);
  6822. +
  6823. + /* Disable MDIO auto-polling for all ports */
  6824. + ltq_writel(&switch_regs->mdio.mdc_cfg_0, 0);
  6825. +
  6826. + /*
  6827. + * Enable and set MDIO management clock to 2.5 MHz. This is the
  6828. + * maximum clock for FE PHYs.
  6829. + * Formula for clock is:
  6830. + *
  6831. + * 50 MHz
  6832. + * x = ----------- - 1
  6833. + * 2 * f_MDC
  6834. + */
  6835. + ltq_writel(&switch_regs->mdio.mdc_cfg_1, MDIO_MDC_CFG1_RES |
  6836. + MDIO_MDC_CFG1_MCEN | 5);
  6837. +
  6838. + vr9_switch_sync();
  6839. +
  6840. + /* Init MAC connected to CPU */
  6841. + ltq_eth_pmac_init();
  6842. +
  6843. + /* Init MACs connected to external MII interfaces */
  6844. + for (i = 0; i < LTQ_ETHSW_MAX_GMAC; i++)
  6845. + ltq_eth_gmac_init(i);
  6846. +}
  6847. +
  6848. +static void ltq_eth_port_config(struct ltq_eth_priv *priv,
  6849. + const struct ltq_eth_port_config *port)
  6850. +{
  6851. + struct ltq_mii_mii_cfg_reg mii_cfg_reg;
  6852. + struct phy_device *phydev;
  6853. + int setup_gpio = 0;
  6854. +
  6855. + switch (port->num) {
  6856. + case 0: /* xMII0 */
  6857. + case 1: /* xMII1 */
  6858. + mii_cfg_reg.val = ltq_readl(to_mii_miicfg(switch_regs,
  6859. + port->num));
  6860. + mii_cfg_reg.bits.en = port->flags ? 1 : 0;
  6861. +
  6862. + switch (port->phy_if) {
  6863. + case PHY_INTERFACE_MODE_MII:
  6864. + if (port->flags & LTQ_ETH_PORT_PHY)
  6865. + /* MII MAC mode, connected to external PHY */
  6866. + mii_cfg_reg.bits.miimode =
  6867. + LTQ_MII_MII_CFG_MIIMODE_MIIM;
  6868. + else
  6869. + /* MII PHY mode, connected to external MAC */
  6870. + mii_cfg_reg.bits.miimode =
  6871. + LTQ_MII_MII_CFG_MIIMODE_MIIP;
  6872. + setup_gpio = 1;
  6873. + break;
  6874. + case PHY_INTERFACE_MODE_RMII:
  6875. + if (port->flags & LTQ_ETH_PORT_PHY)
  6876. + /* RMII MAC mode, connected to external PHY */
  6877. + mii_cfg_reg.bits.miimode =
  6878. + LTQ_MII_MII_CFG_MIIMODE_RMIIM;
  6879. + else
  6880. + /* RMII PHY mode, connected to external MAC */
  6881. + mii_cfg_reg.bits.miimode =
  6882. + LTQ_MII_MII_CFG_MIIMODE_RMIIP;
  6883. + setup_gpio = 1;
  6884. + break;
  6885. + case PHY_INTERFACE_MODE_RGMII:
  6886. + /* RGMII MAC mode, connected to external PHY */
  6887. + mii_cfg_reg.bits.miimode =
  6888. + LTQ_MII_MII_CFG_MIIMODE_RGMII;
  6889. + setup_gpio = 1;
  6890. +
  6891. + /* RGMII clock delays */
  6892. + ltq_writel(to_mii_pcdu(switch_regs, port->num),
  6893. + port->rgmii_rx_delay << PCDU_RXDLY_SHIFT |
  6894. + port->rgmii_tx_delay);
  6895. + break;
  6896. + default:
  6897. + break;
  6898. + }
  6899. +
  6900. + ltq_writel(to_mii_miicfg(switch_regs, port->num),
  6901. + mii_cfg_reg.val);
  6902. + break;
  6903. + case 2: /* internal GPHY0 */
  6904. + case 3: /* internal GPHY0 */
  6905. + case 4: /* internal GPHY1 */
  6906. + switch (port->phy_if) {
  6907. + case PHY_INTERFACE_MODE_MII:
  6908. + case PHY_INTERFACE_MODE_GMII:
  6909. + setup_gpio = 1;
  6910. + break;
  6911. + default:
  6912. + break;
  6913. + }
  6914. + break;
  6915. + case 5: /* internal GPHY1 or xMII2 */
  6916. + mii_cfg_reg.val = ltq_readl(to_mii_miicfg(switch_regs,
  6917. + port->num));
  6918. + mii_cfg_reg.bits.en = port->flags ? 1 : 0;
  6919. +
  6920. + switch (port->phy_if) {
  6921. + case PHY_INTERFACE_MODE_MII:
  6922. + /* MII MAC mode, connected to internal GPHY */
  6923. + mii_cfg_reg.bits.miimode =
  6924. + LTQ_MII_MII_CFG_MIIMODE_MIIM;
  6925. + setup_gpio = 1;
  6926. + break;
  6927. + case PHY_INTERFACE_MODE_RGMII:
  6928. + /* RGMII MAC mode, connected to external PHY */
  6929. + mii_cfg_reg.bits.miimode =
  6930. + LTQ_MII_MII_CFG_MIIMODE_RGMII;
  6931. + setup_gpio = 1;
  6932. +
  6933. + /* RGMII clock delays */
  6934. + ltq_writel(to_mii_pcdu(switch_regs, port->num),
  6935. + port->rgmii_rx_delay << PCDU_RXDLY_SHIFT |
  6936. + port->rgmii_tx_delay);
  6937. + break;
  6938. + default:
  6939. + break;
  6940. + }
  6941. +
  6942. + ltq_writel(to_mii_miicfg(switch_regs, port->num),
  6943. + mii_cfg_reg.val);
  6944. + break;
  6945. + default:
  6946. + break;
  6947. + }
  6948. +
  6949. + /* Setup GPIOs for MII with external PHYs/MACs */
  6950. + if (setup_gpio) {
  6951. + /* MII/MDIO */
  6952. + gpio_set_altfunc(42, GPIO_ALTSEL_SET, GPIO_ALTSEL_CLR,
  6953. + GPIO_DIR_OUT);
  6954. + /* MII/MDC */
  6955. + gpio_set_altfunc(43, GPIO_ALTSEL_SET, GPIO_ALTSEL_CLR,
  6956. + GPIO_DIR_OUT);
  6957. + }
  6958. +
  6959. + /* Connect to internal/external PHYs */
  6960. + if (port->flags & LTQ_ETH_PORT_PHY) {
  6961. + phydev = phy_connect(priv->bus, port->phy_addr, priv->dev,
  6962. + port->phy_if);
  6963. + if (phydev)
  6964. + phy_config(phydev);
  6965. +
  6966. + priv->phymap[port->num] = phydev;
  6967. + }
  6968. +}
  6969. +
  6970. +int ltq_eth_initialize(const struct ltq_eth_board_config *board_config)
  6971. +{
  6972. + struct eth_device *dev;
  6973. + struct mii_dev *bus;
  6974. + struct ltq_eth_priv *priv;
  6975. + struct ltq_dma_device *dma_dev;
  6976. + int i, ret;
  6977. +
  6978. + build_check_vr9_registers();
  6979. +
  6980. + ltq_dma_init();
  6981. + ltq_eth_hw_init();
  6982. +
  6983. + dev = calloc(1, sizeof(struct eth_device));
  6984. + if (!dev)
  6985. + return -1;
  6986. +
  6987. + priv = calloc(1, sizeof(struct ltq_eth_priv));
  6988. + if (!priv)
  6989. + return -1;
  6990. +
  6991. + bus = mdio_alloc();
  6992. + if (!bus)
  6993. + return -1;
  6994. +
  6995. + sprintf(dev->name, LTQ_ETH_DRV_NAME);
  6996. + dev->priv = priv;
  6997. + dev->init = ltq_eth_init;
  6998. + dev->halt = ltq_eth_halt;
  6999. + dev->recv = ltq_eth_recv;
  7000. + dev->send = ltq_eth_send;
  7001. +
  7002. + sprintf(bus->name, LTQ_MDIO_DRV_NAME);
  7003. + bus->read = vr9_switch_mdio_read;
  7004. + bus->write = vr9_switch_mdio_write;
  7005. + bus->priv = priv;
  7006. +
  7007. + dma_dev = &priv->dma_dev;
  7008. + dma_dev->port = 0;
  7009. + dma_dev->rx_chan.chan_no = 0;
  7010. + dma_dev->rx_chan.class = 0;
  7011. + dma_dev->rx_chan.num_desc = LTQ_ETH_RX_BUFFER_CNT;
  7012. + dma_dev->rx_endian_swap = LTQ_DMA_ENDIANESS_B3_B2_B1_B0;
  7013. + dma_dev->rx_burst_len = LTQ_DMA_BURST_2WORDS;
  7014. + dma_dev->tx_chan.chan_no = 1;
  7015. + dma_dev->tx_chan.class = 0;
  7016. + dma_dev->tx_chan.num_desc = LTQ_ETH_TX_BUFFER_CNT;
  7017. + dma_dev->tx_endian_swap = LTQ_DMA_ENDIANESS_B3_B2_B1_B0;
  7018. + dma_dev->tx_burst_len = LTQ_DMA_BURST_2WORDS;
  7019. +
  7020. + priv->bus = bus;
  7021. + priv->dev = dev;
  7022. +
  7023. + ret = ltq_dma_register(dma_dev);
  7024. + if (ret)
  7025. + return -1;
  7026. +
  7027. + ret = mdio_register(bus);
  7028. + if (ret)
  7029. + return -1;
  7030. +
  7031. + ret = eth_register(dev);
  7032. + if (ret)
  7033. + return -1;
  7034. +
  7035. + for (i = 0; i < board_config->num_ports; i++)
  7036. + ltq_eth_port_config(priv, &board_config->ports[i]);
  7037. +
  7038. + return 0;
  7039. +}
  7040. --- a/drivers/net/phy/Makefile
  7041. +++ b/drivers/net/phy/Makefile
  7042. @@ -20,6 +20,7 @@ COBJS-$(CONFIG_PHY_BROADCOM) += broadcom
  7043. COBJS-$(CONFIG_PHY_DAVICOM) += davicom.o
  7044. COBJS-$(CONFIG_PHY_ET1011C) += et1011c.o
  7045. COBJS-$(CONFIG_PHY_ICPLUS) += icplus.o
  7046. +COBJS-$(CONFIG_PHY_LANTIQ) += lantiq.o
  7047. COBJS-$(CONFIG_PHY_LXT) += lxt.o
  7048. COBJS-$(CONFIG_PHY_MARVELL) += marvell.o
  7049. COBJS-$(CONFIG_PHY_MICREL) += micrel.o
  7050. --- /dev/null
  7051. +++ b/drivers/net/phy/lantiq.c
  7052. @@ -0,0 +1,238 @@
  7053. +/*
  7054. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  7055. + *
  7056. + * SPDX-License-Identifier: GPL-2.0+
  7057. + */
  7058. +
  7059. +#define DEBUG
  7060. +
  7061. +#include <common.h>
  7062. +#include <miiphy.h>
  7063. +
  7064. +#define ADVERTIZE_MPD (1 << 10)
  7065. +
  7066. +DECLARE_GLOBAL_DATA_PTR;
  7067. +
  7068. +/*
  7069. + * Update link status.
  7070. + *
  7071. + * Based on genphy_update_link in phylib.c
  7072. + */
  7073. +static int ltq_phy_update_link(struct phy_device *phydev)
  7074. +{
  7075. + unsigned int mii_reg;
  7076. +
  7077. + mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
  7078. +
  7079. + /*
  7080. + * If we already saw the link up, and it hasn't gone down, then
  7081. + * we don't need to wait for autoneg again
  7082. + */
  7083. + if (phydev->link && mii_reg & BMSR_LSTATUS)
  7084. + return 0;
  7085. +
  7086. + if ((mii_reg & BMSR_ANEGCAPABLE) && !(mii_reg & BMSR_ANEGCOMPLETE)) {
  7087. + phydev->link = 0;
  7088. + return 0;
  7089. + } else {
  7090. + /* Read the link a second time to clear the latched state */
  7091. + mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
  7092. +
  7093. + if (mii_reg & BMSR_LSTATUS)
  7094. + phydev->link = 1;
  7095. + else
  7096. + phydev->link = 0;
  7097. + }
  7098. +
  7099. + return 0;
  7100. +}
  7101. +
  7102. +/*
  7103. + * Update speed and duplex.
  7104. + *
  7105. + * Based on genphy_parse_link in phylib.c
  7106. + */
  7107. +static int ltq_phy_parse_link(struct phy_device *phydev)
  7108. +{
  7109. + unsigned int mii_reg;
  7110. +
  7111. + mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
  7112. +
  7113. + /* We're using autonegotiation */
  7114. + if (mii_reg & BMSR_ANEGCAPABLE) {
  7115. + u32 lpa = 0;
  7116. + u32 gblpa = 0;
  7117. +
  7118. + /* Check for gigabit capability */
  7119. + if (mii_reg & BMSR_ERCAP) {
  7120. + /* We want a list of states supported by
  7121. + * both PHYs in the link
  7122. + */
  7123. + gblpa = phy_read(phydev, MDIO_DEVAD_NONE, MII_STAT1000);
  7124. + gblpa &= phy_read(phydev,
  7125. + MDIO_DEVAD_NONE, MII_CTRL1000) << 2;
  7126. + }
  7127. +
  7128. + /* Set the baseline so we only have to set them
  7129. + * if they're different
  7130. + */
  7131. + phydev->speed = SPEED_10;
  7132. + phydev->duplex = DUPLEX_HALF;
  7133. +
  7134. + /* Check the gigabit fields */
  7135. + if (gblpa & (PHY_1000BTSR_1000FD | PHY_1000BTSR_1000HD)) {
  7136. + phydev->speed = SPEED_1000;
  7137. +
  7138. + if (gblpa & PHY_1000BTSR_1000FD)
  7139. + phydev->duplex = DUPLEX_FULL;
  7140. +
  7141. + /* We're done! */
  7142. + return 0;
  7143. + }
  7144. +
  7145. + lpa = phy_read(phydev, MDIO_DEVAD_NONE, MII_ADVERTISE);
  7146. + lpa &= phy_read(phydev, MDIO_DEVAD_NONE, MII_LPA);
  7147. +
  7148. + if (lpa & (LPA_100FULL | LPA_100HALF)) {
  7149. + phydev->speed = SPEED_100;
  7150. +
  7151. + if (lpa & LPA_100FULL)
  7152. + phydev->duplex = DUPLEX_FULL;
  7153. +
  7154. + } else if (lpa & LPA_10FULL)
  7155. + phydev->duplex = DUPLEX_FULL;
  7156. + } else {
  7157. + u32 bmcr = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);
  7158. +
  7159. + phydev->speed = SPEED_10;
  7160. + phydev->duplex = DUPLEX_HALF;
  7161. +
  7162. + if (bmcr & BMCR_FULLDPLX)
  7163. + phydev->duplex = DUPLEX_FULL;
  7164. +
  7165. + if (bmcr & BMCR_SPEED1000)
  7166. + phydev->speed = SPEED_1000;
  7167. + else if (bmcr & BMCR_SPEED100)
  7168. + phydev->speed = SPEED_100;
  7169. + }
  7170. +
  7171. + return 0;
  7172. +}
  7173. +
  7174. +static int ltq_phy_config(struct phy_device *phydev)
  7175. +{
  7176. + u16 val;
  7177. +
  7178. + /* Advertise as Multi-port device */
  7179. + val = phy_read(phydev, MDIO_DEVAD_NONE, MII_CTRL1000);
  7180. + val |= ADVERTIZE_MPD;
  7181. + phy_write(phydev, MDIO_DEVAD_NONE, MII_CTRL1000, val);
  7182. +
  7183. + genphy_config_aneg(phydev);
  7184. +
  7185. + return 0;
  7186. +}
  7187. +
  7188. +static int ltq_phy_startup(struct phy_device *phydev)
  7189. +{
  7190. + /*
  7191. + * Update PHY status immediately without any delays as genphy_startup
  7192. + * does because VRX200 switch needs to be configured dependent
  7193. + * on this information.
  7194. + */
  7195. + ltq_phy_update_link(phydev);
  7196. + ltq_phy_parse_link(phydev);
  7197. +
  7198. + debug("ltq_phy: addr %d, link %d, speed %d, duplex %d\n",
  7199. + phydev->addr, phydev->link, phydev->speed, phydev->duplex);
  7200. +
  7201. + return 0;
  7202. +}
  7203. +
  7204. +static struct phy_driver xrx_11g_13_driver = {
  7205. + .name = "Lantiq XWAY XRX PHY11G v1.3 and earlier",
  7206. + .uid = 0x030260D0,
  7207. + .mask = 0xFFFFFFF0,
  7208. + .features = PHY_GBIT_FEATURES,
  7209. + .config = ltq_phy_config,
  7210. + .startup = ltq_phy_startup,
  7211. + .shutdown = genphy_shutdown,
  7212. +};
  7213. +
  7214. +static struct phy_driver xrx_11g_14_driver = {
  7215. + .name = "Lantiq XWAY XRX PHY11G v1.4 and later",
  7216. + .uid = 0xd565a408,
  7217. + .mask = 0xFFFFFFF8,
  7218. + .features = PHY_GBIT_FEATURES,
  7219. + .config = ltq_phy_config,
  7220. + .startup = ltq_phy_startup,
  7221. + .shutdown = genphy_shutdown,
  7222. +};
  7223. +
  7224. +static struct phy_driver xrx_22f_14_driver = {
  7225. + .name = "Lantiq XWAY XRX PHY22F v1.4 and later",
  7226. + .uid = 0xd565a418,
  7227. + .mask = 0xFFFFFFF8,
  7228. + .features = PHY_BASIC_FEATURES,
  7229. + .config = ltq_phy_config,
  7230. + .startup = ltq_phy_startup,
  7231. + .shutdown = genphy_shutdown,
  7232. +};
  7233. +
  7234. +static struct phy_driver pef7071_driver = {
  7235. + .name = "Lantiq XWAY PEF7071",
  7236. + .uid = 0xd565a400,
  7237. + .mask = 0xFFFFFFFF,
  7238. + .features = PHY_GBIT_FEATURES,
  7239. + .config = ltq_phy_config,
  7240. + .startup = ltq_phy_startup,
  7241. + .shutdown = genphy_shutdown,
  7242. +};
  7243. +
  7244. +static struct phy_driver xrx_genphy_driver = {
  7245. + .name = "Generic PHY at Lantiq XWAY XRX switch",
  7246. + .uid = 0,
  7247. + .mask = 0,
  7248. + .features = 0,
  7249. + .config = genphy_config,
  7250. + .startup = ltq_phy_startup,
  7251. + .shutdown = genphy_shutdown,
  7252. +};
  7253. +
  7254. +int phy_lantiq_init(void)
  7255. +{
  7256. +#ifdef CONFIG_NEEDS_MANUAL_RELOC
  7257. + xrx_11g_13_driver.config = ltq_phy_config;
  7258. + xrx_11g_13_driver.startup = ltq_phy_startup;
  7259. + xrx_11g_13_driver.shutdown = genphy_shutdown;
  7260. + xrx_11g_13_driver.name += gd->reloc_off;
  7261. +
  7262. + xrx_11g_14_driver.config = ltq_phy_config;
  7263. + xrx_11g_14_driver.startup = ltq_phy_startup;
  7264. + xrx_11g_14_driver.shutdown = genphy_shutdown;
  7265. + xrx_11g_14_driver.name += gd->reloc_off;
  7266. +
  7267. + xrx_22f_14_driver.config = ltq_phy_config;
  7268. + xrx_22f_14_driver.startup = ltq_phy_startup;
  7269. + xrx_22f_14_driver.shutdown = genphy_shutdown;
  7270. + xrx_22f_14_driver.name += gd->reloc_off;
  7271. +
  7272. + pef7071_driver.config = ltq_phy_config;
  7273. + pef7071_driver.startup = ltq_phy_startup;
  7274. + pef7071_driver.shutdown = genphy_shutdown;
  7275. + pef7071_driver.name += gd->reloc_off;
  7276. +
  7277. + xrx_genphy_driver.config = genphy_config;
  7278. + xrx_genphy_driver.startup = ltq_phy_startup;
  7279. + xrx_genphy_driver.shutdown = genphy_shutdown;
  7280. + xrx_genphy_driver.name += gd->reloc_off;
  7281. +#endif
  7282. +
  7283. + phy_register(&xrx_11g_13_driver);
  7284. + phy_register(&xrx_11g_14_driver);
  7285. + phy_register(&xrx_22f_14_driver);
  7286. + phy_register(&pef7071_driver);
  7287. + phy_register(&xrx_genphy_driver);
  7288. +
  7289. + return 0;
  7290. +}
  7291. --- a/drivers/net/phy/phy.c
  7292. +++ b/drivers/net/phy/phy.c
  7293. @@ -16,9 +16,10 @@
  7294. #include <command.h>
  7295. #include <miiphy.h>
  7296. #include <phy.h>
  7297. -#include <errno.h>
  7298. #include <linux/err.h>
  7299. +DECLARE_GLOBAL_DATA_PTR;
  7300. +
  7301. /* Generic PHY support and helper functions */
  7302. /**
  7303. @@ -440,6 +441,16 @@ static LIST_HEAD(phy_drivers);
  7304. int phy_init(void)
  7305. {
  7306. +#ifdef CONFIG_NEEDS_MANUAL_RELOC
  7307. + INIT_LIST_HEAD(&phy_drivers);
  7308. +
  7309. + genphy_driver.config = genphy_config;
  7310. + genphy_driver.startup = genphy_startup;
  7311. + genphy_driver.shutdown = genphy_shutdown;
  7312. +
  7313. + genphy_driver.name += gd->reloc_off;
  7314. +#endif
  7315. +
  7316. #ifdef CONFIG_PHY_ATHEROS
  7317. phy_atheros_init();
  7318. #endif
  7319. @@ -455,6 +466,9 @@ int phy_init(void)
  7320. #ifdef CONFIG_PHY_ICPLUS
  7321. phy_icplus_init();
  7322. #endif
  7323. +#ifdef CONFIG_PHY_LANTIQ
  7324. + phy_lantiq_init();
  7325. +#endif
  7326. #ifdef CONFIG_PHY_LXT
  7327. phy_lxt_init();
  7328. #endif
  7329. --- a/drivers/serial/Makefile
  7330. +++ b/drivers/serial/Makefile
  7331. @@ -24,6 +24,7 @@ COBJS-$(CONFIG_SYS_NS16550_SERIAL) += se
  7332. COBJS-$(CONFIG_IMX_SERIAL) += serial_imx.o
  7333. COBJS-$(CONFIG_IXP_SERIAL) += serial_ixp.o
  7334. COBJS-$(CONFIG_KS8695_SERIAL) += serial_ks8695.o
  7335. +COBJS-$(CONFIG_LANTIQ_SERIAL) += serial_lantiq.o
  7336. COBJS-$(CONFIG_MAX3100_SERIAL) += serial_max3100.o
  7337. COBJS-$(CONFIG_MXC_UART) += serial_mxc.o
  7338. COBJS-$(CONFIG_PL010_SERIAL) += serial_pl01x.o
  7339. --- a/drivers/serial/serial.c
  7340. +++ b/drivers/serial/serial.c
  7341. @@ -160,6 +160,7 @@ serial_initfunc(sa1100_serial_initialize
  7342. serial_initfunc(sh_serial_initialize);
  7343. serial_initfunc(arm_dcc_initialize);
  7344. serial_initfunc(mxs_auart_initialize);
  7345. +serial_initfunc(ltq_serial_initialize);
  7346. /**
  7347. * serial_register() - Register serial driver with serial driver core
  7348. @@ -253,6 +254,7 @@ void serial_initialize(void)
  7349. sh_serial_initialize();
  7350. arm_dcc_initialize();
  7351. mxs_auart_initialize();
  7352. + ltq_serial_initialize();
  7353. serial_assign(default_serial_console()->name);
  7354. }
  7355. --- /dev/null
  7356. +++ b/drivers/serial/serial_lantiq.c
  7357. @@ -0,0 +1,263 @@
  7358. +/*
  7359. + * Copyright (C) 2010 Thomas Langer <thomas.langer@lantiq.com>
  7360. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  7361. + *
  7362. + * SPDX-License-Identifier: GPL-2.0+
  7363. + */
  7364. +
  7365. +#include <common.h>
  7366. +#include <serial.h>
  7367. +#include <asm/errno.h>
  7368. +#include <asm/arch/soc.h>
  7369. +#include <asm/lantiq/clk.h>
  7370. +#include <asm/lantiq/io.h>
  7371. +
  7372. +#if CONFIG_CONSOLE_ASC == 0
  7373. +#define LTQ_ASC_BASE LTQ_ASC0_BASE
  7374. +#else
  7375. +#define LTQ_ASC_BASE LTQ_ASC1_BASE
  7376. +#endif
  7377. +
  7378. +#define LTQ_ASC_ID_TXFS_SHIFT 24
  7379. +#define LTQ_ASC_ID_TXFS_MASK (0x3F << LTQ_ASC_ID_TXFS_SHIFT)
  7380. +#define LTQ_ASC_ID_RXFS_SHIFT 16
  7381. +#define LTQ_ASC_ID_RXFS_MASK (0x3F << LTQ_ASC_ID_RXFS_SHIFT)
  7382. +
  7383. +#define LTQ_ASC_MCON_R (1 << 15)
  7384. +#define LTQ_ASC_MCON_FDE (1 << 9)
  7385. +
  7386. +#define LTQ_ASC_WHBSTATE_SETREN (1 << 1)
  7387. +#define LTQ_ASC_WHBSTATE_CLRREN (1 << 0)
  7388. +
  7389. +#define LTQ_ASC_RXFCON_RXFITL_SHIFT 8
  7390. +#define LTQ_ASC_RXFCON_RXFITL_MASK (0x3F << LTQ_ASC_RXFCON_RXFITL_SHIFT)
  7391. +#define LTQ_ASC_RXFCON_RXFITL_RXFFLU (1 << 1)
  7392. +#define LTQ_ASC_RXFCON_RXFITL_RXFEN (1 << 0)
  7393. +
  7394. +#define LTQ_ASC_TXFCON_TXFITL_SHIFT 8
  7395. +#define LTQ_ASC_TXFCON_TXFITL_MASK (0x3F << LTQ_ASC_TXFCON_TXFITL_SHIFT)
  7396. +#define LTQ_ASC_TXFCON_TXFITL_TXFFLU (1 << 1)
  7397. +#define LTQ_ASC_TXFCON_TXFITL_TXFEN (1 << 0)
  7398. +
  7399. +#define LTQ_ASC_FSTAT_TXFREE_SHIFT 24
  7400. +#define LTQ_ASC_FSTAT_TXFREE_MASK (0x3F << LTQ_ASC_FSTAT_TXFREE_SHIFT)
  7401. +#define LTQ_ASC_FSTAT_RXFREE_SHIFT 16
  7402. +#define LTQ_ASC_FSTAT_RXFREE_MASK (0x3F << LTQ_ASC_FSTAT_RXFREE_SHIFT)
  7403. +#define LTQ_ASC_FSTAT_TXFFL_SHIFT 8
  7404. +#define LTQ_ASC_FSTAT_TXFFL_MASK (0x3F << LTQ_ASC_FSTAT_TXFFL_SHIFT)
  7405. +#define LTQ_ASC_FSTAT_RXFFL_MASK 0x3F
  7406. +
  7407. +#ifdef __BIG_ENDIAN
  7408. +#define LTQ_ASC_RBUF_OFFSET 3
  7409. +#define LTQ_ASC_TBUF_OFFSET 3
  7410. +#else
  7411. +#define LTQ_ASC_RBUF_OFFSET 0
  7412. +#define LTQ_ASC_TBUF_OFFSET 0
  7413. +#endif
  7414. +
  7415. +struct ltq_asc_regs {
  7416. + u32 clc;
  7417. + u32 pisel;
  7418. + u32 id;
  7419. + u32 rsvd0;
  7420. + u32 mcon;
  7421. + u32 state;
  7422. + u32 whbstate;
  7423. + u32 rsvd1;
  7424. + u8 tbuf[4];
  7425. + u8 rbuf[4];
  7426. + u32 rsvd2[2];
  7427. + u32 abcon;
  7428. + u32 abstat;
  7429. + u32 whbabcon;
  7430. + u32 whbabstat;
  7431. + u32 rxfcon;
  7432. + u32 txfcon;
  7433. + u32 fstat;
  7434. + u32 rsvd3;
  7435. + u32 bg;
  7436. + u32 bg_timer;
  7437. + u32 fdv;
  7438. + u32 pmw;
  7439. + u32 modcon;
  7440. + u32 modstat;
  7441. +};
  7442. +
  7443. +DECLARE_GLOBAL_DATA_PTR;
  7444. +
  7445. +static struct ltq_asc_regs *ltq_asc_regs =
  7446. + (struct ltq_asc_regs *) CKSEG1ADDR(LTQ_ASC_BASE);
  7447. +
  7448. +static int ltq_serial_init(void)
  7449. +{
  7450. + /* Set clock divider for normal run mode to 1 and enable module */
  7451. + ltq_writel(&ltq_asc_regs->clc, 0x100);
  7452. +
  7453. + /* Reset MCON register */
  7454. + ltq_writel(&ltq_asc_regs->mcon, 0);
  7455. +
  7456. + /* Use Port A as receiver input */
  7457. + ltq_writel(&ltq_asc_regs->pisel, 0);
  7458. +
  7459. + /* Enable and flush RX/TX FIFOs */
  7460. + ltq_setbits(&ltq_asc_regs->rxfcon,
  7461. + LTQ_ASC_RXFCON_RXFITL_RXFFLU | LTQ_ASC_RXFCON_RXFITL_RXFEN);
  7462. + ltq_setbits(&ltq_asc_regs->txfcon,
  7463. + LTQ_ASC_TXFCON_TXFITL_TXFFLU | LTQ_ASC_TXFCON_TXFITL_TXFEN);
  7464. +
  7465. + serial_setbrg();
  7466. +
  7467. + /* Disable error flags, enable receiver */
  7468. + ltq_writel(&ltq_asc_regs->whbstate, LTQ_ASC_WHBSTATE_SETREN);
  7469. +
  7470. + return 0;
  7471. +}
  7472. +
  7473. +/*
  7474. + * fdv asc_clk
  7475. + * Baudrate = ----- * -------------
  7476. + * 512 16 * (bg + 1)
  7477. + */
  7478. +static void ltq_serial_calc_br_fdv(unsigned long asc_clk,
  7479. + unsigned long baudrate, u16 *fdv,
  7480. + u16 *bg)
  7481. +{
  7482. + const u32 c = asc_clk / (16 * 512);
  7483. + u32 diff1, diff2;
  7484. + u32 bg_calc, br_calc, i;
  7485. +
  7486. + diff1 = baudrate;
  7487. + for (i = 512; i > 0; i--) {
  7488. + /* Calc bg for current fdv value */
  7489. + bg_calc = i * c / baudrate;
  7490. +
  7491. + /* Impossible baudrate */
  7492. + if (!bg_calc)
  7493. + return;
  7494. +
  7495. + /*
  7496. + * Calc diff to target baudrate dependent on current
  7497. + * bg and fdv values
  7498. + */
  7499. + br_calc = i * c / bg_calc;
  7500. + if (br_calc > baudrate)
  7501. + diff2 = br_calc - baudrate;
  7502. + else
  7503. + diff2 = baudrate - br_calc;
  7504. +
  7505. + /* Perfect values found */
  7506. + if (diff2 == 0) {
  7507. + *fdv = i;
  7508. + *bg = bg_calc - 1;
  7509. + return;
  7510. + }
  7511. +
  7512. + if (diff2 < diff1) {
  7513. + *fdv = i;
  7514. + *bg = bg_calc - 1;
  7515. + diff1 = diff2;
  7516. + }
  7517. + }
  7518. +}
  7519. +
  7520. +static void ltq_serial_setbrg(void)
  7521. +{
  7522. + unsigned long asc_clk, baudrate;
  7523. + u16 bg = 0;
  7524. + u16 fdv = 511;
  7525. +
  7526. + /* ASC clock is same as FPI clock with CLC.RMS = 1 */
  7527. + asc_clk = ltq_get_bus_clock();
  7528. + baudrate = gd->baudrate;
  7529. +
  7530. + /* Calculate FDV and BG values */
  7531. + ltq_serial_calc_br_fdv(asc_clk, baudrate, &fdv, &bg);
  7532. +
  7533. + /* Disable baudrate generator */
  7534. + ltq_clrbits(&ltq_asc_regs->mcon, LTQ_ASC_MCON_R);
  7535. +
  7536. + /* Enable fractional divider */
  7537. + ltq_setbits(&ltq_asc_regs->mcon, LTQ_ASC_MCON_FDE);
  7538. +
  7539. + /* Set fdv and bg values */
  7540. + ltq_writel(&ltq_asc_regs->fdv, fdv);
  7541. + ltq_writel(&ltq_asc_regs->bg, bg);
  7542. +
  7543. + /* Enable baudrate generator */
  7544. + ltq_setbits(&ltq_asc_regs->mcon, LTQ_ASC_MCON_R);
  7545. +}
  7546. +
  7547. +static unsigned int ltq_serial_tx_free(void)
  7548. +{
  7549. + unsigned int txfree;
  7550. +
  7551. + txfree = (ltq_readl(&ltq_asc_regs->fstat) &
  7552. + LTQ_ASC_FSTAT_TXFREE_MASK) >>
  7553. + LTQ_ASC_FSTAT_TXFREE_SHIFT;
  7554. +
  7555. + return txfree;
  7556. +}
  7557. +
  7558. +static unsigned int ltq_serial_rx_fill(void)
  7559. +{
  7560. + unsigned int rxffl;
  7561. +
  7562. + rxffl = ltq_readl(&ltq_asc_regs->fstat) & LTQ_ASC_FSTAT_RXFFL_MASK;
  7563. +
  7564. + return rxffl;
  7565. +}
  7566. +
  7567. +static void ltq_serial_tx(const char c)
  7568. +{
  7569. + ltq_writeb(&ltq_asc_regs->tbuf[LTQ_ASC_TBUF_OFFSET], c);
  7570. +}
  7571. +
  7572. +static u8 ltq_serial_rx(void)
  7573. +{
  7574. + return ltq_readb(&ltq_asc_regs->rbuf[LTQ_ASC_RBUF_OFFSET]);
  7575. +}
  7576. +
  7577. +static void ltq_serial_putc(const char c)
  7578. +{
  7579. + if (c == '\n')
  7580. + ltq_serial_putc('\r');
  7581. +
  7582. + while (!ltq_serial_tx_free())
  7583. + ;
  7584. +
  7585. + ltq_serial_tx(c);
  7586. +}
  7587. +
  7588. +static int ltq_serial_getc(void)
  7589. +{
  7590. + while (!ltq_serial_rx_fill())
  7591. + ;
  7592. +
  7593. + return ltq_serial_rx();
  7594. +}
  7595. +
  7596. +static int ltq_serial_tstc(void)
  7597. +{
  7598. + return (0 != ltq_serial_rx_fill());
  7599. +}
  7600. +
  7601. +static struct serial_device ltq_serial_drv = {
  7602. + .name = "ltq_serial",
  7603. + .start = ltq_serial_init,
  7604. + .stop = NULL,
  7605. + .setbrg = ltq_serial_setbrg,
  7606. + .putc = ltq_serial_putc,
  7607. + .puts = default_serial_puts,
  7608. + .getc = ltq_serial_getc,
  7609. + .tstc = ltq_serial_tstc,
  7610. +};
  7611. +
  7612. +void ltq_serial_initialize(void)
  7613. +{
  7614. + serial_register(&ltq_serial_drv);
  7615. +}
  7616. +
  7617. +__weak struct serial_device *default_serial_console(void)
  7618. +{
  7619. + return &ltq_serial_drv;
  7620. +}
  7621. --- a/drivers/spi/Makefile
  7622. +++ b/drivers/spi/Makefile
  7623. @@ -25,6 +25,7 @@ COBJS-$(CONFIG_DAVINCI_SPI) += davinci_s
  7624. COBJS-$(CONFIG_EXYNOS_SPI) += exynos_spi.o
  7625. COBJS-$(CONFIG_ICH_SPI) += ich.o
  7626. COBJS-$(CONFIG_KIRKWOOD_SPI) += kirkwood_spi.o
  7627. +COBJS-$(CONFIG_LANTIQ_SPI) += lantiq_spi.o
  7628. COBJS-$(CONFIG_MPC52XX_SPI) += mpc52xx_spi.o
  7629. COBJS-$(CONFIG_MPC8XXX_SPI) += mpc8xxx_spi.o
  7630. COBJS-$(CONFIG_MXC_SPI) += mxc_spi.o
  7631. --- /dev/null
  7632. +++ b/drivers/spi/lantiq_spi.c
  7633. @@ -0,0 +1,666 @@
  7634. +/*
  7635. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  7636. + *
  7637. + * SPDX-License-Identifier: GPL-2.0+
  7638. + */
  7639. +
  7640. +#include <common.h>
  7641. +#include <spi.h>
  7642. +#include <malloc.h>
  7643. +#include <watchdog.h>
  7644. +#include <asm/gpio.h>
  7645. +#include <asm/lantiq/io.h>
  7646. +#include <asm/lantiq/clk.h>
  7647. +#include <asm/lantiq/pm.h>
  7648. +#include <asm/arch/soc.h>
  7649. +
  7650. +#define LTQ_SPI_CLC_RMC_SHIFT 8
  7651. +#define LTQ_SPI_CLC_RMC_MASK (0xFF << LTQ_SPI_CLC_RMC_SHIFT)
  7652. +#define LTQ_SPI_CLC_DISS (1 << 1)
  7653. +#define LTQ_SPI_CLC_DISR 1
  7654. +
  7655. +#define LTQ_SPI_ID_TXFS_SHIFT 24
  7656. +#define LTQ_SPI_ID_TXFS_MASK (0x3F << LTQ_SPI_ID_TXFS_SHIFT)
  7657. +#define LTQ_SPI_ID_RXFS_SHIFT 16
  7658. +#define LTQ_SPI_ID_RXFS_MASK (0x3F << LTQ_SPI_ID_RXFS_SHIFT)
  7659. +
  7660. +#define LTQ_SPI_CON_ENBV (1 << 22)
  7661. +#define LTQ_SPI_CON_BM_SHIFT 16
  7662. +#define LTQ_SPI_CON_BM_MASK (0x1F << LTQ_SPI_CON_BM_SHIFT)
  7663. +#define LTQ_SPI_CON_IDLE (1 << 23)
  7664. +#define LTQ_SPI_CON_RUEN (1 << 12)
  7665. +#define LTQ_SPI_CON_AEN (1 << 10)
  7666. +#define LTQ_SPI_CON_REN (1 << 9)
  7667. +#define LTQ_SPI_CON_TEN (1 << 8)
  7668. +#define LTQ_SPI_CON_LB (1 << 7)
  7669. +#define LTQ_SPI_CON_PO (1 << 6)
  7670. +#define LTQ_SPI_CON_PH (1 << 5)
  7671. +#define LTQ_SPI_CON_HB (1 << 4)
  7672. +#define LTQ_SPI_CON_RXOFF (1 << 1)
  7673. +#define LTQ_SPI_CON_TXOFF 1
  7674. +
  7675. +#define LTQ_SPI_STAT_RXBV_SHIFT 28
  7676. +#define LTQ_SPI_STAT_RXBV_MASK (0x7 << LTQ_SPI_STAT_RXBV_SHIFT)
  7677. +#define LTQ_SPI_STAT_BSY (1 << 13)
  7678. +
  7679. +#define LTQ_SPI_WHBSTATE_SETMS (1 << 3)
  7680. +#define LTQ_SPI_WHBSTATE_CLRMS (1 << 2)
  7681. +#define LTQ_SPI_WHBSTATE_SETEN (1 << 1)
  7682. +#define LTQ_SPI_WHBSTATE_CLREN 1
  7683. +#define LTQ_SPI_WHBSTATE_CLR_ERRORS 0x0F50
  7684. +
  7685. +#define LTQ_SPI_TXFCON_TXFLU (1 << 1)
  7686. +#define LTQ_SPI_TXFCON_TXFEN 1
  7687. +
  7688. +#define LTQ_SPI_RXFCON_RXFLU (1 << 1)
  7689. +#define LTQ_SPI_RXFCON_RXFEN 1
  7690. +
  7691. +#define LTQ_SPI_FSTAT_RXFFL_MASK 0x3f
  7692. +#define LTQ_SPI_FSTAT_TXFFL_SHIFT 8
  7693. +#define LTQ_SPI_FSTAT_TXFFL_MASK (0x3f << LTQ_SPI_FSTAT_TXFFL_SHIFT)
  7694. +
  7695. +#define LTQ_SPI_RXREQ_RXCNT_MASK 0xFFFF
  7696. +#define LTQ_SPI_RXCNT_TODO_MASK 0xFFFF
  7697. +
  7698. +#define LTQ_SPI_GPIO_DIN 16
  7699. +#define LTQ_SPI_GPIO_DOUT 17
  7700. +#define LTQ_SPI_GPIO_CLK 18
  7701. +
  7702. +struct ltq_spi_regs {
  7703. + __be32 clc; /* Clock control */
  7704. + __be32 pisel; /* Port input select */
  7705. + __be32 id; /* Identification */
  7706. + __be32 rsvd0;
  7707. + __be32 con; /* Control */
  7708. + __be32 stat; /* Status */
  7709. + __be32 whbstate; /* Write HW modified state */
  7710. + __be32 rsvd1;
  7711. + __be32 tb; /* Transmit buffer */
  7712. + __be32 rb; /* Receive buffer */
  7713. + __be32 rsvd2[2];
  7714. + __be32 rxfcon; /* Recevie FIFO control */
  7715. + __be32 txfcon; /* Transmit FIFO control */
  7716. + __be32 fstat; /* FIFO status */
  7717. + __be32 rsvd3;
  7718. + __be32 brt; /* Baudrate timer */
  7719. + __be32 brstat; /* Baudrate timer status */
  7720. + __be32 rsvd4[6];
  7721. + __be32 sfcon; /* Serial frame control */
  7722. + __be32 sfstat; /* Serial frame status */
  7723. + __be32 rsvd5[2];
  7724. + __be32 gpocon; /* General purpose output control */
  7725. + __be32 gpostat; /* General purpose output status */
  7726. + __be32 fgpo; /* Force general purpose output */
  7727. + __be32 rsvd6;
  7728. + __be32 rxreq; /* Receive request */
  7729. + __be32 rxcnt; /* Receive count */
  7730. + __be32 rsvd7[25];
  7731. + __be32 dmacon; /* DMA control */
  7732. + __be32 rsvd8;
  7733. + __be32 irnen; /* Interrupt node enable */
  7734. + __be32 irnicr; /* Interrupt node interrupt capture */
  7735. + __be32 irncr; /* Interrupt node control */
  7736. +};
  7737. +
  7738. +struct ltq_spi_drv_data {
  7739. + struct ltq_spi_regs __iomem *regs;
  7740. +
  7741. + struct spi_slave slave;
  7742. + unsigned int max_hz;
  7743. + unsigned int mode;
  7744. + unsigned int tx_todo;
  7745. + unsigned int rx_todo;
  7746. + unsigned int rx_req;
  7747. + unsigned int bits_per_word;
  7748. + unsigned int speed_hz;
  7749. + const u8 *tx;
  7750. + u8 *rx;
  7751. + int status;
  7752. +};
  7753. +
  7754. +static struct ltq_spi_drv_data *to_ltq_spi_slave(struct spi_slave *slave)
  7755. +{
  7756. + return container_of(slave, struct ltq_spi_drv_data, slave);
  7757. +}
  7758. +
  7759. +#ifdef CONFIG_SPL_BUILD
  7760. +/*
  7761. + * We do not have or want malloc in a SPI flash SPL.
  7762. + * Neither we have to support multiple SPI slaves. Thus we put the
  7763. + * SPI slave context in BSS for SPL builds.
  7764. + */
  7765. +static struct ltq_spi_drv_data ltq_spi_slave;
  7766. +
  7767. +static struct ltq_spi_drv_data *ltq_spi_slave_alloc(unsigned int bus,
  7768. + unsigned int cs)
  7769. +{
  7770. + ltq_spi_slave.slave.bus = bus;
  7771. + ltq_spi_slave.slave.cs = cs;
  7772. +
  7773. + return &ltq_spi_slave;
  7774. +}
  7775. +
  7776. +static void ltq_spi_slave_free(struct spi_slave *slave)
  7777. +{
  7778. +}
  7779. +#else
  7780. +static struct ltq_spi_drv_data *ltq_spi_slave_alloc(unsigned int bus,
  7781. + unsigned int cs)
  7782. +{
  7783. + return spi_alloc_slave(struct ltq_spi_drv_data, bus, cs);
  7784. +}
  7785. +
  7786. +static void ltq_spi_slave_free(struct spi_slave *slave)
  7787. +{
  7788. + struct ltq_spi_drv_data *drv;
  7789. +
  7790. + if (slave) {
  7791. + drv = to_ltq_spi_slave(slave);
  7792. + free(drv);
  7793. + }
  7794. +}
  7795. +#endif
  7796. +
  7797. +static unsigned int tx_fifo_size(struct ltq_spi_drv_data *drv)
  7798. +{
  7799. + u32 id = ltq_readl(&drv->regs->id);
  7800. +
  7801. + return (id & LTQ_SPI_ID_TXFS_MASK) >> LTQ_SPI_ID_TXFS_SHIFT;
  7802. +}
  7803. +
  7804. +static unsigned int rx_fifo_size(struct ltq_spi_drv_data *drv)
  7805. +{
  7806. + u32 id = ltq_readl(&drv->regs->id);
  7807. +
  7808. + return (id & LTQ_SPI_ID_RXFS_MASK) >> LTQ_SPI_ID_RXFS_SHIFT;
  7809. +}
  7810. +
  7811. +static unsigned int tx_fifo_level(struct ltq_spi_drv_data *drv)
  7812. +{
  7813. + u32 fstat = ltq_readl(&drv->regs->fstat);
  7814. +
  7815. + return (fstat & LTQ_SPI_FSTAT_TXFFL_MASK) >> LTQ_SPI_FSTAT_TXFFL_SHIFT;
  7816. +}
  7817. +
  7818. +static unsigned int rx_fifo_level(struct ltq_spi_drv_data *drv)
  7819. +{
  7820. + u32 fstat = ltq_readl(&drv->regs->fstat);
  7821. +
  7822. + return fstat & LTQ_SPI_FSTAT_RXFFL_MASK;
  7823. +}
  7824. +
  7825. +static unsigned int tx_fifo_free(struct ltq_spi_drv_data *drv)
  7826. +{
  7827. + return tx_fifo_size(drv) - tx_fifo_level(drv);
  7828. +}
  7829. +
  7830. +static void hw_power_on(struct ltq_spi_drv_data *drv)
  7831. +{
  7832. + u32 clc;
  7833. +
  7834. + /* Power-up mdule */
  7835. + ltq_pm_enable(LTQ_PM_SPI);
  7836. +
  7837. + /*
  7838. + * Set clock divider for run mode to 1 to
  7839. + * run at same frequency as FPI bus
  7840. + */
  7841. + clc = (1 << LTQ_SPI_CLC_RMC_SHIFT);
  7842. + ltq_writel(&drv->regs->clc, clc);
  7843. +}
  7844. +
  7845. +static void hw_reset_fifos(struct ltq_spi_drv_data *drv)
  7846. +{
  7847. + u32 val;
  7848. +
  7849. + val = LTQ_SPI_TXFCON_TXFEN | LTQ_SPI_TXFCON_TXFLU;
  7850. + ltq_writel(&drv->regs->txfcon, val);
  7851. +
  7852. + val = LTQ_SPI_RXFCON_RXFEN | LTQ_SPI_RXFCON_RXFLU;
  7853. + ltq_writel(&drv->regs->rxfcon, val);
  7854. +}
  7855. +
  7856. +static int hw_is_busy(struct ltq_spi_drv_data *drv)
  7857. +{
  7858. + u32 stat = ltq_readl(&drv->regs->stat);
  7859. +
  7860. + return stat & LTQ_SPI_STAT_BSY;
  7861. +}
  7862. +
  7863. +static void hw_enter_config_mode(struct ltq_spi_drv_data *drv)
  7864. +{
  7865. + ltq_writel(&drv->regs->whbstate, LTQ_SPI_WHBSTATE_CLREN);
  7866. +}
  7867. +
  7868. +static void hw_enter_active_mode(struct ltq_spi_drv_data *drv)
  7869. +{
  7870. + ltq_writel(&drv->regs->whbstate, LTQ_SPI_WHBSTATE_SETEN);
  7871. +}
  7872. +
  7873. +static void hw_setup_speed_hz(struct ltq_spi_drv_data *drv,
  7874. + unsigned int max_speed_hz)
  7875. +{
  7876. + unsigned int spi_hz, speed_hz, brt;
  7877. +
  7878. + /*
  7879. + * SPI module clock is derived from FPI bus clock dependent on
  7880. + * divider value in CLC.RMS which is always set to 1.
  7881. + *
  7882. + * f_SPI
  7883. + * baudrate = --------------
  7884. + * 2 * (BR + 1)
  7885. + */
  7886. + spi_hz = ltq_get_bus_clock() / 2;
  7887. +
  7888. + /* TODO: optimize baudrate calculation */
  7889. + for (brt = 0; brt < 0xFFFF; brt++) {
  7890. + speed_hz = spi_hz / (brt + 1);
  7891. + if (speed_hz <= max_speed_hz)
  7892. + break;
  7893. + }
  7894. +
  7895. + ltq_writel(&drv->regs->brt, brt);
  7896. +}
  7897. +
  7898. +static void hw_setup_bits_per_word(struct ltq_spi_drv_data *drv,
  7899. + unsigned int bits_per_word)
  7900. +{
  7901. + u32 bm;
  7902. +
  7903. + /* CON.BM value = bits_per_word - 1 */
  7904. + bm = (bits_per_word - 1) << LTQ_SPI_CON_BM_SHIFT;
  7905. +
  7906. + ltq_clrsetbits(&drv->regs->con, LTQ_SPI_CON_BM_MASK, bm);
  7907. +}
  7908. +
  7909. +static void hw_setup_clock_mode(struct ltq_spi_drv_data *drv, unsigned int mode)
  7910. +{
  7911. + u32 con_set = 0, con_clr = 0;
  7912. +
  7913. + /*
  7914. + * SPI mode mapping in CON register:
  7915. + * Mode CPOL CPHA CON.PO CON.PH
  7916. + * 0 0 0 0 1
  7917. + * 1 0 1 0 0
  7918. + * 2 1 0 1 1
  7919. + * 3 1 1 1 0
  7920. + */
  7921. + if (mode & SPI_CPHA)
  7922. + con_clr |= LTQ_SPI_CON_PH;
  7923. + else
  7924. + con_set |= LTQ_SPI_CON_PH;
  7925. +
  7926. + if (mode & SPI_CPOL)
  7927. + con_set |= LTQ_SPI_CON_PO | LTQ_SPI_CON_IDLE;
  7928. + else
  7929. + con_clr |= LTQ_SPI_CON_PO | LTQ_SPI_CON_IDLE;
  7930. +
  7931. + /* Set heading control */
  7932. + if (mode & SPI_LSB_FIRST)
  7933. + con_clr |= LTQ_SPI_CON_HB;
  7934. + else
  7935. + con_set |= LTQ_SPI_CON_HB;
  7936. +
  7937. + /* Set loopback mode */
  7938. + if (mode & SPI_LOOP)
  7939. + con_set |= LTQ_SPI_CON_LB;
  7940. + else
  7941. + con_clr |= LTQ_SPI_CON_LB;
  7942. +
  7943. + ltq_clrsetbits(&drv->regs->con, con_clr, con_set);
  7944. +}
  7945. +
  7946. +static void hw_set_rxtx(struct ltq_spi_drv_data *drv)
  7947. +{
  7948. + u32 con;
  7949. +
  7950. + /* Configure transmitter and receiver */
  7951. + con = ltq_readl(&drv->regs->con);
  7952. + if (drv->tx)
  7953. + con &= ~LTQ_SPI_CON_TXOFF;
  7954. + else
  7955. + con |= LTQ_SPI_CON_TXOFF;
  7956. +
  7957. + if (drv->rx)
  7958. + con &= ~LTQ_SPI_CON_RXOFF;
  7959. + else
  7960. + con |= LTQ_SPI_CON_RXOFF;
  7961. +
  7962. + ltq_writel(&drv->regs->con, con);
  7963. +}
  7964. +
  7965. +static void hw_init(struct ltq_spi_drv_data *drv)
  7966. +{
  7967. + hw_power_on(drv);
  7968. +
  7969. + /* Put controller into config mode */
  7970. + hw_enter_config_mode(drv);
  7971. +
  7972. + /* Disable all interrupts */
  7973. + ltq_writel(&drv->regs->irnen, 0);
  7974. +
  7975. + /* Clear error flags */
  7976. + ltq_clrsetbits(&drv->regs->whbstate, 0, LTQ_SPI_WHBSTATE_CLR_ERRORS);
  7977. +
  7978. + /* Enable error checking, disable TX/RX */
  7979. + ltq_writel(&drv->regs->con, LTQ_SPI_CON_RUEN | LTQ_SPI_CON_AEN |
  7980. + LTQ_SPI_CON_TEN | LTQ_SPI_CON_REN | LTQ_SPI_CON_TXOFF |
  7981. + LTQ_SPI_CON_RXOFF);
  7982. +
  7983. + /* Setup default SPI mode */
  7984. + drv->bits_per_word = 8;
  7985. + drv->speed_hz = 0;
  7986. + hw_setup_bits_per_word(drv, drv->bits_per_word);
  7987. + hw_setup_clock_mode(drv, SPI_MODE_0);
  7988. +
  7989. + /* Enable master mode and clear error flags */
  7990. + ltq_writel(&drv->regs->whbstate, LTQ_SPI_WHBSTATE_SETMS |
  7991. + LTQ_SPI_WHBSTATE_CLR_ERRORS);
  7992. +
  7993. + /* Reset GPIO/CS registers */
  7994. + ltq_writel(&drv->regs->gpocon, 0);
  7995. + ltq_writel(&drv->regs->fgpo, 0xFF00);
  7996. +
  7997. + /* Enable and flush FIFOs */
  7998. + hw_reset_fifos(drv);
  7999. +
  8000. + /* SPI/DIN input */
  8001. + gpio_set_altfunc(16, GPIO_ALTSEL_SET, GPIO_ALTSEL_CLR, GPIO_DIR_IN);
  8002. + /* SPI/DOUT output */
  8003. + gpio_set_altfunc(17, GPIO_ALTSEL_SET, GPIO_ALTSEL_CLR, GPIO_DIR_OUT);
  8004. + /* SPI/CLK output */
  8005. + gpio_set_altfunc(18, GPIO_ALTSEL_SET, GPIO_ALTSEL_CLR, GPIO_DIR_OUT);
  8006. +}
  8007. +
  8008. +static void tx_fifo_write(struct ltq_spi_drv_data *drv)
  8009. +{
  8010. + const u8 *tx8;
  8011. + const u16 *tx16;
  8012. + const u32 *tx32;
  8013. + u32 data;
  8014. + unsigned int tx_free = tx_fifo_free(drv);
  8015. +
  8016. + while (drv->tx_todo && tx_free) {
  8017. + switch (drv->bits_per_word) {
  8018. + case 8:
  8019. + tx8 = drv->tx;
  8020. + data = *tx8;
  8021. + drv->tx_todo--;
  8022. + drv->tx++;
  8023. + break;
  8024. + case 16:
  8025. + tx16 = (u16 *) drv->tx;
  8026. + data = *tx16;
  8027. + drv->tx_todo -= 2;
  8028. + drv->tx += 2;
  8029. + break;
  8030. + case 32:
  8031. + tx32 = (u32 *) drv->tx;
  8032. + data = *tx32;
  8033. + drv->tx_todo -= 4;
  8034. + drv->tx += 4;
  8035. + break;
  8036. + default:
  8037. + return;
  8038. + }
  8039. +
  8040. + ltq_writel(&drv->regs->tb, data);
  8041. + tx_free--;
  8042. + }
  8043. +}
  8044. +
  8045. +static void rx_fifo_read_full_duplex(struct ltq_spi_drv_data *drv)
  8046. +{
  8047. + u8 *rx8;
  8048. + u16 *rx16;
  8049. + u32 *rx32;
  8050. + u32 data;
  8051. + unsigned int rx_fill = rx_fifo_level(drv);
  8052. +
  8053. + while (rx_fill) {
  8054. + data = ltq_readl(&drv->regs->rb);
  8055. +
  8056. + switch (drv->bits_per_word) {
  8057. + case 8:
  8058. + rx8 = drv->rx;
  8059. + *rx8 = data;
  8060. + drv->rx_todo--;
  8061. + drv->rx++;
  8062. + break;
  8063. + case 16:
  8064. + rx16 = (u16 *) drv->rx;
  8065. + *rx16 = data;
  8066. + drv->rx_todo -= 2;
  8067. + drv->rx += 2;
  8068. + break;
  8069. + case 32:
  8070. + rx32 = (u32 *) drv->rx;
  8071. + *rx32 = data;
  8072. + drv->rx_todo -= 4;
  8073. + drv->rx += 4;
  8074. + break;
  8075. + default:
  8076. + return;
  8077. + }
  8078. +
  8079. + rx_fill--;
  8080. + }
  8081. +}
  8082. +
  8083. +static void rx_fifo_read_half_duplex(struct ltq_spi_drv_data *drv)
  8084. +{
  8085. + u32 data, *rx32;
  8086. + u8 *rx8;
  8087. + unsigned int rxbv, shift;
  8088. + unsigned int rx_fill = rx_fifo_level(drv);
  8089. +
  8090. + /*
  8091. + * In RX-only mode the bits per word value is ignored by HW. A value
  8092. + * of 32 is used instead. Thus all 4 bytes per FIFO must be read.
  8093. + * If remaining RX bytes are less than 4, the FIFO must be read
  8094. + * differently. The amount of received and valid bytes is indicated
  8095. + * by STAT.RXBV register value.
  8096. + */
  8097. + while (rx_fill) {
  8098. + if (drv->rx_todo < 4) {
  8099. + rxbv = (ltq_readl(&drv->regs->stat) &
  8100. + LTQ_SPI_STAT_RXBV_MASK) >>
  8101. + LTQ_SPI_STAT_RXBV_SHIFT;
  8102. + data = ltq_readl(&drv->regs->rb);
  8103. +
  8104. + shift = (rxbv - 1) * 8;
  8105. + rx8 = drv->rx;
  8106. +
  8107. + while (rxbv) {
  8108. + *rx8++ = (data >> shift) & 0xFF;
  8109. + rxbv--;
  8110. + shift -= 8;
  8111. + drv->rx_todo--;
  8112. + drv->rx++;
  8113. +
  8114. + if (drv->rx_req)
  8115. + drv->rx_req --;
  8116. + }
  8117. + } else {
  8118. + data = ltq_readl(&drv->regs->rb);
  8119. + rx32 = (u32 *) drv->rx;
  8120. +
  8121. + *rx32++ = data;
  8122. + drv->rx_todo -= 4;
  8123. + drv->rx += 4;
  8124. +
  8125. + if (drv->rx_req >= 4)
  8126. + drv->rx_req -= 4;
  8127. + }
  8128. + rx_fill--;
  8129. + }
  8130. +}
  8131. +
  8132. +static void rx_request(struct ltq_spi_drv_data *drv)
  8133. +{
  8134. + unsigned int rxreq, rxreq_max;
  8135. +
  8136. + if (drv->rx_req)
  8137. + return;
  8138. +
  8139. + /*
  8140. + * To avoid receive overflows at high clocks it is better to request
  8141. + * only the amount of bytes that fits into all FIFOs. This value
  8142. + * depends on the FIFO size implemented in hardware.
  8143. + */
  8144. + rxreq = drv->rx_todo;
  8145. + rxreq_max = rx_fifo_size(drv) * 4;
  8146. + if (rxreq > rxreq_max)
  8147. + rxreq = rxreq_max;
  8148. +
  8149. + drv->rx_req = rxreq;
  8150. + ltq_writel(&drv->regs->rxreq, rxreq);
  8151. +}
  8152. +
  8153. +void spi_init(void)
  8154. +{
  8155. +}
  8156. +
  8157. +struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
  8158. + unsigned int max_hz, unsigned int mode)
  8159. +{
  8160. + struct ltq_spi_drv_data *drv;
  8161. +
  8162. + if (!spi_cs_is_valid(bus, cs))
  8163. + return NULL;
  8164. +
  8165. + drv = ltq_spi_slave_alloc(bus, cs);
  8166. + if (!drv)
  8167. + return NULL;
  8168. +
  8169. + drv->regs = (struct ltq_spi_regs *) CKSEG1ADDR(LTQ_SPI_BASE);
  8170. +
  8171. + hw_init(drv);
  8172. +
  8173. + drv->max_hz = max_hz;
  8174. + drv->mode = mode;
  8175. +
  8176. + return &drv->slave;
  8177. +}
  8178. +
  8179. +void spi_free_slave(struct spi_slave *slave)
  8180. +{
  8181. + ltq_spi_slave_free(slave);
  8182. +}
  8183. +
  8184. +static int ltq_spi_wait_ready(struct ltq_spi_drv_data *drv)
  8185. +{
  8186. + const unsigned long timeout = 20000;
  8187. + unsigned long timebase;
  8188. +
  8189. + timebase = get_timer(0);
  8190. +
  8191. + do {
  8192. + WATCHDOG_RESET();
  8193. +
  8194. + if (!hw_is_busy(drv))
  8195. + return 0;
  8196. + } while (get_timer(timebase) < timeout);
  8197. +
  8198. + return 1;
  8199. +}
  8200. +
  8201. +int spi_claim_bus(struct spi_slave *slave)
  8202. +{
  8203. + struct ltq_spi_drv_data *drv = to_ltq_spi_slave(slave);
  8204. + int ret;
  8205. +
  8206. + ret = ltq_spi_wait_ready(drv);
  8207. + if (ret) {
  8208. + debug("cannot claim bus\n");
  8209. + return ret;
  8210. + }
  8211. +
  8212. + hw_enter_config_mode(drv);
  8213. + hw_setup_clock_mode(drv, drv->mode);
  8214. + hw_setup_speed_hz(drv, drv->max_hz);
  8215. + hw_setup_bits_per_word(drv, drv->bits_per_word);
  8216. + hw_enter_active_mode(drv);
  8217. +
  8218. + return 0;
  8219. +}
  8220. +
  8221. +void spi_release_bus(struct spi_slave *slave)
  8222. +{
  8223. + struct ltq_spi_drv_data *drv = to_ltq_spi_slave(slave);
  8224. +
  8225. + hw_enter_config_mode(drv);
  8226. +}
  8227. +
  8228. +int spi_xfer(struct spi_slave *slave, unsigned int bitlen,
  8229. + const void *dout, void *din, unsigned long flags)
  8230. +{
  8231. +
  8232. + struct ltq_spi_drv_data *drv = to_ltq_spi_slave(slave);
  8233. + int ret = 0;
  8234. +
  8235. + if (bitlen % 8)
  8236. + return 1;
  8237. +
  8238. + if (!bitlen) {
  8239. + ret = 0;
  8240. + goto done;
  8241. + }
  8242. +
  8243. + if (flags & SPI_XFER_BEGIN)
  8244. + spi_cs_activate(slave);
  8245. +
  8246. + drv->tx = dout;
  8247. + drv->tx_todo = 0;
  8248. + drv->rx = din;
  8249. + drv->rx_todo = 0;
  8250. + hw_set_rxtx(drv);
  8251. +
  8252. + if (drv->tx) {
  8253. + drv->tx_todo = bitlen / 8;
  8254. +
  8255. + tx_fifo_write(drv);
  8256. + }
  8257. +
  8258. + if (drv->rx) {
  8259. + drv->rx_todo = bitlen / 8;
  8260. +
  8261. + if (!drv->tx)
  8262. + rx_request(drv);
  8263. + }
  8264. +
  8265. + for (;;) {
  8266. + if (drv->tx) {
  8267. + if (drv->rx && drv->rx_todo)
  8268. + rx_fifo_read_full_duplex(drv);
  8269. +
  8270. + if (drv->tx_todo)
  8271. + tx_fifo_write(drv);
  8272. + else
  8273. + goto done;
  8274. + } else if (drv->rx) {
  8275. + if (drv->rx_todo) {
  8276. + rx_fifo_read_half_duplex(drv);
  8277. +
  8278. + if (drv->rx_todo)
  8279. + rx_request(drv);
  8280. + else
  8281. + goto done;
  8282. + } else {
  8283. + goto done;
  8284. + }
  8285. + }
  8286. + }
  8287. +
  8288. +done:
  8289. + ret = ltq_spi_wait_ready(drv);
  8290. +
  8291. + drv->rx = NULL;
  8292. + drv->tx = NULL;
  8293. + hw_set_rxtx(drv);
  8294. +
  8295. + if (flags & SPI_XFER_END)
  8296. + spi_cs_deactivate(slave);
  8297. +
  8298. + return ret;
  8299. +}
  8300. --- a/include/phy.h
  8301. +++ b/include/phy.h
  8302. @@ -214,6 +214,7 @@ int phy_atheros_init(void);
  8303. int phy_broadcom_init(void);
  8304. int phy_davicom_init(void);
  8305. int phy_et1011c_init(void);
  8306. +int phy_lantiq_init(void);
  8307. int phy_lxt_init(void);
  8308. int phy_marvell_init(void);
  8309. int phy_micrel_init(void);
  8310. --- a/spl/Makefile
  8311. +++ b/spl/Makefile
  8312. @@ -100,6 +100,8 @@ LIBS-$(CONFIG_SPL_USBETH_SUPPORT) += dri
  8313. LIBS-$(CONFIG_SPL_MUSB_NEW_SUPPORT) += drivers/usb/musb-new/libusb_musb-new.o
  8314. LIBS-$(CONFIG_SPL_USBETH_SUPPORT) += drivers/usb/gadget/libusb_gadget.o
  8315. LIBS-$(CONFIG_SPL_WATCHDOG_SUPPORT) += drivers/watchdog/libwatchdog.o
  8316. +LIBS-$(CONFIG_SPL_LZMA_SUPPORT) += lib/lzma/liblzma.o
  8317. +LIBS-$(CONFIG_SPL_LZO_SUPPORT) += lib/lzo/liblzo.o
  8318. ifneq ($(CONFIG_OMAP_COMMON),)
  8319. LIBS-y += $(CPUDIR)/omap-common/libomap-common.o
  8320. --- a/tools/.gitignore
  8321. +++ b/tools/.gitignore
  8322. @@ -2,6 +2,7 @@
  8323. /envcrc
  8324. /gen_eth_addr
  8325. /img2srec
  8326. +/ltq-boot-image
  8327. /kwboot
  8328. /mkenvimage
  8329. /mkimage
  8330. --- a/tools/Makefile
  8331. +++ b/tools/Makefile
  8332. @@ -49,6 +49,7 @@ BIN_FILES-$(CONFIG_VIDEO_LOGO) += bmp_lo
  8333. BIN_FILES-$(CONFIG_BUILD_ENVCRC) += envcrc$(SFX)
  8334. BIN_FILES-$(CONFIG_CMD_NET) += gen_eth_addr$(SFX)
  8335. BIN_FILES-$(CONFIG_CMD_LOADS) += img2srec$(SFX)
  8336. +BIN_FILES-$(CONFIG_SOC_LANTIQ) += ltq-boot-image$(SFX)
  8337. BIN_FILES-$(CONFIG_XWAY_SWAP_BYTES) += xway-swap-bytes$(SFX)
  8338. BIN_FILES-y += mkenvimage$(SFX)
  8339. BIN_FILES-y += mkimage$(SFX)
  8340. @@ -95,6 +96,7 @@ OBJ_FILES-$(CONFIG_MX28) += mxsboot.o
  8341. OBJ_FILES-$(CONFIG_NETCONSOLE) += ncb.o
  8342. OBJ_FILES-$(CONFIG_SHA1_CHECK_UB_IMG) += ubsha1.o
  8343. OBJ_FILES-$(CONFIG_SMDK5250) += mkexynosspl.o
  8344. +OBJ_FILES-$(CONFIG_SOC_LANTIQ) += ltq-boot-image.o
  8345. OBJ_FILES-$(CONFIG_VIDEO_LOGO) += bmp_logo.o
  8346. OBJ_FILES-$(CONFIG_XWAY_SWAP_BYTES) += xway-swap-bytes.o
  8347. @@ -195,6 +197,10 @@ $(obj)img2srec$(SFX): $(obj)img2srec.o
  8348. $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
  8349. $(HOSTSTRIP) $@
  8350. +$(obj)ltq-boot-image$(SFX): $(obj)ltq-boot-image.o
  8351. + $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
  8352. + $(HOSTSTRIP) $@
  8353. +
  8354. $(obj)xway-swap-bytes$(SFX): $(obj)xway-swap-bytes.o
  8355. $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
  8356. $(HOSTSTRIP) $@
  8357. --- /dev/null
  8358. +++ b/tools/ltq-boot-image.c
  8359. @@ -0,0 +1,315 @@
  8360. +/*
  8361. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  8362. + *
  8363. + * SPDX-License-Identifier: GPL-2.0+
  8364. + */
  8365. +
  8366. +#include <stdio.h>
  8367. +#include <stdlib.h>
  8368. +#include <string.h>
  8369. +#include <unistd.h>
  8370. +#include <getopt.h>
  8371. +#include <compiler.h>
  8372. +#include <sys/stat.h>
  8373. +
  8374. +enum image_types {
  8375. + IMAGE_NONE,
  8376. + IMAGE_SFSPL
  8377. +};
  8378. +
  8379. +/* Lantiq non-volatile bootstrap command IDs */
  8380. +enum nvb_cmd_ids {
  8381. + NVB_CMD_DEBUG = 0x11,
  8382. + NVB_CMD_REGCFG = 0x22,
  8383. + NVB_CMD_IDWNLD = 0x33,
  8384. + NVB_CMD_CDWNLD = 0x44,
  8385. + NVB_CMD_DWNLD = 0x55,
  8386. + NVB_CMD_IFCFG = 0x66,
  8387. + NVB_CMD_START = 0x77
  8388. +};
  8389. +
  8390. +/* Lantiq non-volatile bootstrap command flags */
  8391. +enum nvb_cmd_flags {
  8392. + NVB_FLAG_START = 1,
  8393. + NVB_FLAG_DEC = (1 << 1),
  8394. + NVB_FLAG_DBG = (1 << 2),
  8395. + NVB_FLAG_SDBG = (1 << 3),
  8396. + NVB_FLAG_CFG0 = (1 << 4),
  8397. + NVB_FLAG_CFG1 = (1 << 5),
  8398. + NVB_FLAG_CFG2 = (1 << 6),
  8399. + NVB_FLAG_RST = (1 << 7)
  8400. +};
  8401. +
  8402. +struct args {
  8403. + enum image_types type;
  8404. + __u32 entry_addr;
  8405. + const char *uboot_bin;
  8406. + const char *spl_bin;
  8407. + const char *out_bin;
  8408. +};
  8409. +
  8410. +static void usage_msg(const char *name)
  8411. +{
  8412. + fprintf(stderr, "%s: [-h] -t type -e entry-addr -u uboot-bin [-s spl-bin] -o out-bin\n",
  8413. + name);
  8414. + fprintf(stderr, " Image types:\n"
  8415. + " sfspl - SPL + [compressed] U-Boot for SPI flash\n");
  8416. +}
  8417. +
  8418. +static enum image_types parse_image_type(const char *type)
  8419. +{
  8420. + if (!type)
  8421. + return IMAGE_NONE;
  8422. +
  8423. + if (!strncmp(type, "sfspl", 6))
  8424. + return IMAGE_SFSPL;
  8425. +
  8426. + return IMAGE_NONE;
  8427. +}
  8428. +
  8429. +static int parse_args(int argc, char *argv[], struct args *arg)
  8430. +{
  8431. + int opt;
  8432. +
  8433. + memset(arg, 0, sizeof(*arg));
  8434. +
  8435. + while ((opt = getopt(argc, argv, "ht:e:u:s:o:")) != -1) {
  8436. + switch (opt) {
  8437. + case 'h':
  8438. + usage_msg(argv[0]);
  8439. + return 1;
  8440. + case 't':
  8441. + arg->type = parse_image_type(optarg);
  8442. + break;
  8443. + case 'e':
  8444. + arg->entry_addr = strtoul(optarg, NULL, 16);
  8445. + break;
  8446. + case 'u':
  8447. + arg->uboot_bin = optarg;
  8448. + break;
  8449. + case 's':
  8450. + arg->spl_bin = optarg;
  8451. + break;
  8452. + case 'o':
  8453. + arg->out_bin = optarg;
  8454. + break;
  8455. + default:
  8456. + fprintf(stderr, "Invalid option -%c\n", opt);
  8457. + goto parse_error;
  8458. + }
  8459. + }
  8460. +
  8461. + if (arg->type == IMAGE_NONE) {
  8462. + fprintf(stderr, "Invalid image type\n");
  8463. + goto parse_error;
  8464. + }
  8465. +
  8466. + if (!arg->uboot_bin) {
  8467. + fprintf(stderr, "Missing U-Boot binary\n");
  8468. + goto parse_error;
  8469. + }
  8470. +
  8471. + if (!arg->out_bin) {
  8472. + fprintf(stderr, "Missing output binary\n");
  8473. + goto parse_error;
  8474. + }
  8475. +
  8476. + if (arg->type == IMAGE_SFSPL && !arg->spl_bin) {
  8477. + fprintf(stderr, "Missing SPL binary\n");
  8478. + goto parse_error;
  8479. + }
  8480. +
  8481. + return 0;
  8482. +
  8483. +parse_error:
  8484. + usage_msg(argv[0]);
  8485. + return -1;
  8486. +}
  8487. +
  8488. +static __u32 build_nvb_command(unsigned cmdid, unsigned cmdflags)
  8489. +{
  8490. + __u32 cmd;
  8491. + __u16 tag;
  8492. +
  8493. + tag = (cmdid << 8) | cmdflags;
  8494. + cmd = (tag << 16) | (0xFFFF - tag);
  8495. +
  8496. + return cpu_to_be32(cmd);
  8497. +}
  8498. +
  8499. +static int write_header(int fd, const void *hdr, size_t size)
  8500. +{
  8501. + ssize_t n;
  8502. +
  8503. + n = write(fd, hdr, size);
  8504. + if (n != size) {
  8505. + fprintf(stderr, "Cannot write header: %s\n",
  8506. + strerror(errno));
  8507. + return -1;
  8508. + }
  8509. +
  8510. + return 0;
  8511. +}
  8512. +
  8513. +static int write_nvb_dwnld_header(int fd, size_t size, __u32 addr)
  8514. +{
  8515. + __u32 hdr[3];
  8516. +
  8517. + hdr[0] = build_nvb_command(NVB_CMD_DWNLD, NVB_FLAG_START |
  8518. + NVB_FLAG_SDBG);
  8519. + hdr[1] = cpu_to_be32(size + 4);
  8520. + hdr[2] = cpu_to_be32(addr);
  8521. +
  8522. + return write_header(fd, hdr, sizeof(hdr));
  8523. +}
  8524. +
  8525. +static int write_nvb_start_header(int fd, __u32 addr)
  8526. +{
  8527. + __u32 hdr[3];
  8528. +
  8529. + hdr[0] = build_nvb_command(NVB_CMD_START, NVB_FLAG_SDBG);
  8530. + hdr[1] = cpu_to_be32(4);
  8531. + hdr[2] = cpu_to_be32(addr);
  8532. +
  8533. + return write_header(fd, hdr, sizeof(hdr));
  8534. +}
  8535. +
  8536. +static int open_input_bin(const char *name, void **ptr, size_t *size)
  8537. +{
  8538. + struct stat sbuf;
  8539. + int ret, fd;
  8540. +
  8541. + fd = open(name, O_RDONLY | O_BINARY);
  8542. + if (0 > fd) {
  8543. + fprintf(stderr, "Cannot open %s: %s\n", name,
  8544. + strerror(errno));
  8545. + return -1;
  8546. + }
  8547. +
  8548. + ret = fstat(fd, &sbuf);
  8549. + if (0 > ret) {
  8550. + fprintf(stderr, "Cannot fstat %s: %s\n", name,
  8551. + strerror(errno));
  8552. + return -1;
  8553. + }
  8554. +
  8555. + *ptr = mmap(0, sbuf.st_size, PROT_READ, MAP_SHARED, fd, 0);
  8556. + if (*ptr == MAP_FAILED) {
  8557. + fprintf(stderr, "Cannot mmap %s: %s\n", name,
  8558. + strerror(errno));
  8559. + return -1;
  8560. + }
  8561. +
  8562. + *size = sbuf.st_size;
  8563. +
  8564. + return fd;
  8565. +}
  8566. +
  8567. +static void close_input_bin(int fd, void *ptr, size_t size)
  8568. +{
  8569. + munmap(ptr, size);
  8570. + close(fd);
  8571. +}
  8572. +
  8573. +static int copy_bin(int fd, void *ptr, size_t size)
  8574. +{
  8575. + ssize_t n;
  8576. +
  8577. + n = write(fd, ptr, size);
  8578. + if (n != size) {
  8579. + fprintf(stderr, "Cannot copy binary: %s\n", strerror(errno));
  8580. + return -1;
  8581. + }
  8582. +
  8583. + return 0;
  8584. +}
  8585. +
  8586. +static int open_output_bin(const char *name)
  8587. +{
  8588. + int fd;
  8589. +
  8590. + fd = open(name, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0666);
  8591. + if (0 > fd) {
  8592. + fprintf(stderr, "Cannot open %s: %s\n", name,
  8593. + strerror(errno));
  8594. + return -1;
  8595. + }
  8596. +
  8597. + return fd;
  8598. +}
  8599. +
  8600. +static int create_sfspl(const struct args *arg)
  8601. +{
  8602. + int out_fd, uboot_fd, spl_fd, ret;
  8603. + void *uboot_ptr, *spl_ptr;
  8604. + size_t uboot_size, spl_size;
  8605. +
  8606. + out_fd = open_output_bin(arg->out_bin);
  8607. + if (0 > out_fd)
  8608. + goto err;
  8609. +
  8610. + spl_fd = open_input_bin(arg->spl_bin, &spl_ptr, &spl_size);
  8611. + if (0 > spl_fd)
  8612. + goto err_spl;
  8613. +
  8614. + uboot_fd = open_input_bin(arg->uboot_bin, &uboot_ptr, &uboot_size);
  8615. + if (0 > uboot_fd)
  8616. + goto err_uboot;
  8617. +
  8618. + ret = write_nvb_dwnld_header(out_fd, spl_size, arg->entry_addr);
  8619. + if (ret)
  8620. + goto err_write;
  8621. +
  8622. + ret = copy_bin(out_fd, spl_ptr, spl_size);
  8623. + if (ret)
  8624. + goto err_write;
  8625. +
  8626. + ret = write_nvb_start_header(out_fd, arg->entry_addr);
  8627. + if (ret)
  8628. + goto err_write;
  8629. +
  8630. + ret = copy_bin(out_fd, uboot_ptr, uboot_size);
  8631. + if (ret)
  8632. + goto err_write;
  8633. +
  8634. + close_input_bin(uboot_fd, uboot_ptr, uboot_size);
  8635. + close_input_bin(spl_fd, spl_ptr, spl_size);
  8636. + close(out_fd);
  8637. +
  8638. + return 0;
  8639. +
  8640. +err_write:
  8641. + close_input_bin(uboot_fd, uboot_ptr, uboot_size);
  8642. +err_uboot:
  8643. + close_input_bin(spl_fd, spl_ptr, spl_size);
  8644. +err_spl:
  8645. + close(out_fd);
  8646. +err:
  8647. + return -1;
  8648. +}
  8649. +
  8650. +int main(int argc, char *argv[])
  8651. +{
  8652. + int ret;
  8653. + struct args arg;
  8654. +
  8655. + ret = parse_args(argc, argv, &arg);
  8656. + if (ret)
  8657. + goto done;
  8658. +
  8659. + switch (arg.type) {
  8660. + case IMAGE_SFSPL:
  8661. + ret = create_sfspl(&arg);
  8662. + break;
  8663. + default:
  8664. + fprintf(stderr, "Image type not implemented\n");
  8665. + ret = -1;
  8666. + break;
  8667. + }
  8668. +
  8669. +done:
  8670. + if (ret >= 0)
  8671. + return EXIT_SUCCESS;
  8672. +
  8673. + return EXIT_FAILURE;
  8674. +}