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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339
  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,111 @@
  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 defined(CONFIG_LTQ_SUPPORT_NAND_FLASH)
  2416. +#define ebu_region1_enable 1
  2417. +#else
  2418. +#define ebu_region1_enable 0
  2419. +#endif
  2420. +
  2421. +struct ltq_ebu_regs {
  2422. + u32 clc;
  2423. + u32 rsvd0;
  2424. + u32 id;
  2425. + u32 rsvd1;
  2426. + u32 con;
  2427. + u32 rsvd2[3];
  2428. + u32 addr_sel_0;
  2429. + u32 addr_sel_1;
  2430. + u32 addr_sel_2;
  2431. + u32 addr_sel_3;
  2432. + u32 rsvd3[12];
  2433. + u32 con_0;
  2434. + u32 con_1;
  2435. + u32 con_2;
  2436. + u32 con_3;
  2437. +};
  2438. +
  2439. +static struct ltq_ebu_regs *ltq_ebu_regs =
  2440. + (struct ltq_ebu_regs *) CKSEG1ADDR(LTQ_EBU_BASE);
  2441. +
  2442. +void ltq_ebu_init(void)
  2443. +{
  2444. + if (ebu_region0_enable) {
  2445. + /*
  2446. + * Map EBU region 0 to range 0x10000000-0x13ffffff and enable
  2447. + * region control. This supports up to 32 MiB NOR flash in
  2448. + * bank 0.
  2449. + */
  2450. + ltq_writel(&ltq_ebu_regs->addr_sel_0, LTQ_EBU_REGION0_BASE |
  2451. + EBU_ADDRSEL_MASK(1) | EBU_ADDRSEL_REGEN);
  2452. +
  2453. + ltq_writel(&ltq_ebu_regs->con_0, EBU_CON_AGEN_DEMUX |
  2454. + EBU_CON_WAIT_DIS | EBU_CON_PW_16BIT |
  2455. + EBU_CON_ALEC(3) | EBU_CON_BCGEN_INTEL |
  2456. + EBU_CON_WAITWRC(7) | EBU_CON_WAITRDC(3) |
  2457. + EBU_CON_HOLDC(3) | EBU_CON_RECOVC(3) |
  2458. + EBU_CON_CMULT_16);
  2459. + } else
  2460. + ltq_clrbits(&ltq_ebu_regs->addr_sel_0, EBU_ADDRSEL_REGEN);
  2461. +
  2462. + if (ebu_region1_enable) {
  2463. + /*
  2464. + * Map EBU region 1 to range 0x14000000-0x13ffffff and enable
  2465. + * region control. This supports NAND flash in bank 1.
  2466. + */
  2467. + ltq_writel(&ltq_ebu_regs->addr_sel_1, LTQ_EBU_REGION1_BASE |
  2468. + EBU_ADDRSEL_MASK(3) | EBU_ADDRSEL_REGEN);
  2469. +
  2470. + ltq_writel(&ltq_ebu_regs->con_1, EBU_CON_AGEN_DEMUX |
  2471. + EBU_CON_SETUP | EBU_CON_WAIT_DIS | EBU_CON_PW_8BIT |
  2472. + EBU_CON_ALEC(3) | EBU_CON_BCGEN_INTEL |
  2473. + EBU_CON_WAITWRC(2) | EBU_CON_WAITRDC(2) |
  2474. + EBU_CON_HOLDC(1) | EBU_CON_RECOVC(1) |
  2475. + EBU_CON_CMULT_4);
  2476. + } else
  2477. + ltq_clrbits(&ltq_ebu_regs->addr_sel_1, EBU_ADDRSEL_REGEN);
  2478. +}
  2479. +
  2480. +void *flash_swap_addr(unsigned long addr)
  2481. +{
  2482. + return (void *)(addr ^ 2);
  2483. +}
  2484. --- /dev/null
  2485. +++ b/arch/mips/cpu/mips32/vrx200/gphy.c
  2486. @@ -0,0 +1,58 @@
  2487. +/*
  2488. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  2489. + *
  2490. + * SPDX-License-Identifier: GPL-2.0+
  2491. + */
  2492. +
  2493. +#include <common.h>
  2494. +#include <asm/lantiq/io.h>
  2495. +#include <asm/arch/soc.h>
  2496. +#include <asm/arch/gphy.h>
  2497. +
  2498. +static inline void ltq_gphy_copy(const void *fw_start, const void *fw_end,
  2499. + ulong dst_addr)
  2500. +{
  2501. + const ulong fw_len = (ulong) fw_end - (ulong) fw_start;
  2502. + const ulong addr = CKSEG1ADDR(dst_addr);
  2503. +
  2504. + debug("ltq_gphy_copy: addr %08lx, fw_start %p, fw_end %p\n",
  2505. + addr, fw_start, fw_end);
  2506. +
  2507. + memcpy((void *) addr, fw_start, fw_len);
  2508. +}
  2509. +
  2510. +void ltq_gphy_phy11g_a1x_load(ulong addr)
  2511. +{
  2512. + extern ulong __ltq_fw_phy11g_a1x_start;
  2513. + extern ulong __ltq_fw_phy11g_a1x_end;
  2514. +
  2515. + ltq_gphy_copy(&__ltq_fw_phy11g_a1x_start, &__ltq_fw_phy11g_a1x_end,
  2516. + addr);
  2517. +}
  2518. +
  2519. +void ltq_gphy_phy11g_a2x_load(ulong addr)
  2520. +{
  2521. + extern ulong __ltq_fw_phy11g_a2x_start;
  2522. + extern ulong __ltq_fw_phy11g_a2x_end;
  2523. +
  2524. + ltq_gphy_copy(&__ltq_fw_phy11g_a2x_start, &__ltq_fw_phy11g_a2x_end,
  2525. + addr);
  2526. +}
  2527. +
  2528. +void ltq_gphy_phy22f_a1x_load(ulong addr)
  2529. +{
  2530. + extern ulong __ltq_fw_phy22f_a1x_start;
  2531. + extern ulong __ltq_fw_phy22f_a1x_end;
  2532. +
  2533. + ltq_gphy_copy(&__ltq_fw_phy22f_a1x_start, &__ltq_fw_phy22f_a1x_end,
  2534. + addr);
  2535. +}
  2536. +
  2537. +void ltq_gphy_phy22f_a2x_load(ulong addr)
  2538. +{
  2539. + extern ulong __ltq_fw_phy22f_a2x_start;
  2540. + extern ulong __ltq_fw_phy22f_a2x_end;
  2541. +
  2542. + ltq_gphy_copy(&__ltq_fw_phy22f_a2x_start, &__ltq_fw_phy22f_a2x_end,
  2543. + addr);
  2544. +}
  2545. --- /dev/null
  2546. +++ b/arch/mips/cpu/mips32/vrx200/gphy_fw.S
  2547. @@ -0,0 +1,27 @@
  2548. +/*
  2549. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  2550. + *
  2551. + * SPDX-License-Identifier: GPL-2.0+
  2552. + */
  2553. +
  2554. +#include <asm/asm.h>
  2555. +
  2556. + .section .rodata.__ltq_fw_phy11g_a1x
  2557. +EXPORT(__ltq_fw_phy11g_a1x_start)
  2558. + .incbin "fw_phy11g_a1x.blob"
  2559. +EXPORT(__ltq_fw_phy11g_a1x_end)
  2560. +
  2561. + .section .rodata.__ltq_fw_phy11g_a2x
  2562. +EXPORT(__ltq_fw_phy11g_a2x_start)
  2563. + .incbin "fw_phy11g_a2x.blob"
  2564. +EXPORT(__ltq_fw_phy11g_a2x_end)
  2565. +
  2566. + .section .rodata.__ltq_fw_phy22f_a1x
  2567. +EXPORT(__ltq_fw_phy22f_a1x_start)
  2568. + .incbin "fw_phy22f_a1x.blob"
  2569. +EXPORT(__ltq_fw_phy22f_a1x_end)
  2570. +
  2571. + .section .rodata.__ltq_fw_phy22f_a2x
  2572. +EXPORT(__ltq_fw_phy22f_a2x_start)
  2573. + .incbin "fw_phy22f_a2x.blob"
  2574. +EXPORT(__ltq_fw_phy22f_a2x_end)
  2575. --- /dev/null
  2576. +++ b/arch/mips/cpu/mips32/vrx200/mem.c
  2577. @@ -0,0 +1,57 @@
  2578. +/*
  2579. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  2580. + *
  2581. + * SPDX-License-Identifier: GPL-2.0+
  2582. + */
  2583. +
  2584. +#include <common.h>
  2585. +#include <asm/arch/soc.h>
  2586. +#include <asm/lantiq/io.h>
  2587. +
  2588. +#define LTQ_CCR03_EIGHT_BANK_MODE (1 << 0)
  2589. +#define LTQ_CCR08_CS_MAP_SHIFT 24
  2590. +#define LTQ_CCR08_CS_MAP_MASK (0x3 << LTQ_CCR08_CS_MAP_SHIFT)
  2591. +#define LTQ_CCR11_COLUMN_SIZE_SHIFT 24
  2592. +#define LTQ_CCR11_COLUMN_SIZE_MASK (0x7 << LTQ_CCR11_COLUMN_SIZE_SHIFT)
  2593. +#define LTQ_CCR11_ADDR_PINS_MASK 0x7
  2594. +#define LTQ_CCR15_MAX_COL_REG_SHIFT 24
  2595. +#define LTQ_CCR15_MAX_COL_REG_MASK (0xF << LTQ_CCR15_MAX_COL_REG_SHIFT)
  2596. +#define LTQ_CCR16_MAX_ROW_REG_MASK 0xF
  2597. +
  2598. +static void *ltq_mc_ddr_base = (void *) CKSEG1ADDR(LTQ_MC_DDR_BASE);
  2599. +
  2600. +static inline u32 ltq_mc_ccr_read(u32 index)
  2601. +{
  2602. + return ltq_readl(ltq_mc_ddr_base + LTQ_MC_DDR_CCR_OFFSET(index));
  2603. +}
  2604. +
  2605. +phys_size_t initdram(int board_type)
  2606. +{
  2607. + u32 max_col_reg, max_row_reg, column_size, addr_pins;
  2608. + u32 banks, cs_map;
  2609. + phys_size_t size;
  2610. +
  2611. + banks = (ltq_mc_ccr_read(3) & LTQ_CCR03_EIGHT_BANK_MODE) ? 8 : 4;
  2612. +
  2613. + cs_map = (ltq_mc_ccr_read(8) & LTQ_CCR08_CS_MAP_MASK) >>
  2614. + LTQ_CCR08_CS_MAP_SHIFT;
  2615. +
  2616. + column_size = (ltq_mc_ccr_read(11) & LTQ_CCR11_COLUMN_SIZE_MASK) >>
  2617. + LTQ_CCR11_COLUMN_SIZE_SHIFT;
  2618. +
  2619. + addr_pins = ltq_mc_ccr_read(11) & LTQ_CCR11_ADDR_PINS_MASK;
  2620. +
  2621. + max_col_reg = (ltq_mc_ccr_read(15) & LTQ_CCR15_MAX_COL_REG_MASK) >>
  2622. + LTQ_CCR15_MAX_COL_REG_SHIFT;
  2623. +
  2624. + max_row_reg = ltq_mc_ccr_read(16) & LTQ_CCR16_MAX_ROW_REG_MASK;
  2625. +
  2626. + /*
  2627. + * size (bytes) = 2 ^ rowsize * 2 ^ colsize * banks * chipselects
  2628. + * * datawidth (bytes)
  2629. + */
  2630. + size = (2 << (max_col_reg - column_size - 1)) *
  2631. + (2 << (max_row_reg - addr_pins - 1)) * banks * cs_map * 2;
  2632. +
  2633. + return size;
  2634. +}
  2635. --- /dev/null
  2636. +++ b/arch/mips/cpu/mips32/vrx200/mem_init.S
  2637. @@ -0,0 +1,233 @@
  2638. +/*
  2639. + * Copyright (C) 2010 Lantiq Deutschland GmbH
  2640. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  2641. + *
  2642. + * SPDX-License-Identifier: GPL-2.0+
  2643. + */
  2644. +
  2645. +#include <config.h>
  2646. +#include <asm/asm.h>
  2647. +#include <asm/regdef.h>
  2648. +#include <asm/addrspace.h>
  2649. +#include <asm/arch/soc.h>
  2650. +
  2651. +/* Must be configured in BOARDDIR */
  2652. +#include <ddr_settings.h>
  2653. +
  2654. +#define LTQ_MC_DDR_START (1 << 8)
  2655. +#define LTQ_MC_DDR_DLL_LOCK_IND 1
  2656. +
  2657. +#define CCS_ALWAYS_LAST 0x0430
  2658. +#define CCS_AHBM_CR_BURST_EN (1 << 2)
  2659. +#define CCS_FPIM_CR_BURST_EN (1 << 1)
  2660. +
  2661. +#define CCR03_EIGHT_BANK_MODE (1 << 0)
  2662. +
  2663. + /* Store given value in MC DDR CCRx register */
  2664. + .macro ccr_sw num, val
  2665. + li t1, \val
  2666. + sw t1, LTQ_MC_DDR_CCR_OFFSET(\num)(t0)
  2667. + .endm
  2668. +
  2669. +LEAF(ltq_mem_init)
  2670. + /* Load MC DDR module base */
  2671. + li t0, (LTQ_MC_DDR_BASE | KSEG1)
  2672. +
  2673. + /* Put memory controller in inactive mode */
  2674. + sw zero, LTQ_MC_DDR_CCR_OFFSET(7)(t0)
  2675. +
  2676. + /* Init MC DDR CCR registers with values from ddr_settings.h */
  2677. + ccr_sw 0, MC_CCR00_VALUE
  2678. + ccr_sw 1, MC_CCR01_VALUE
  2679. + ccr_sw 2, MC_CCR02_VALUE
  2680. + ccr_sw 3, MC_CCR03_VALUE
  2681. + ccr_sw 4, MC_CCR04_VALUE
  2682. + ccr_sw 5, MC_CCR05_VALUE
  2683. + ccr_sw 6, MC_CCR06_VALUE
  2684. + ccr_sw 7, MC_CCR07_VALUE
  2685. + ccr_sw 8, MC_CCR08_VALUE
  2686. + ccr_sw 9, MC_CCR09_VALUE
  2687. +
  2688. + ccr_sw 10, MC_CCR10_VALUE
  2689. + ccr_sw 11, MC_CCR11_VALUE
  2690. + ccr_sw 12, MC_CCR12_VALUE
  2691. + ccr_sw 13, MC_CCR13_VALUE
  2692. + ccr_sw 14, MC_CCR14_VALUE
  2693. + ccr_sw 15, MC_CCR15_VALUE
  2694. + ccr_sw 16, MC_CCR16_VALUE
  2695. + ccr_sw 17, MC_CCR17_VALUE
  2696. + ccr_sw 18, MC_CCR18_VALUE
  2697. + ccr_sw 19, MC_CCR19_VALUE
  2698. +
  2699. + ccr_sw 20, MC_CCR20_VALUE
  2700. + ccr_sw 21, MC_CCR21_VALUE
  2701. + ccr_sw 22, MC_CCR22_VALUE
  2702. + ccr_sw 23, MC_CCR23_VALUE
  2703. + ccr_sw 24, MC_CCR24_VALUE
  2704. + ccr_sw 25, MC_CCR25_VALUE
  2705. + ccr_sw 26, MC_CCR26_VALUE
  2706. + ccr_sw 27, MC_CCR27_VALUE
  2707. + ccr_sw 28, MC_CCR28_VALUE
  2708. + ccr_sw 29, MC_CCR29_VALUE
  2709. +
  2710. + ccr_sw 30, MC_CCR30_VALUE
  2711. + ccr_sw 31, MC_CCR31_VALUE
  2712. + ccr_sw 32, MC_CCR32_VALUE
  2713. + ccr_sw 33, MC_CCR33_VALUE
  2714. + ccr_sw 34, MC_CCR34_VALUE
  2715. + ccr_sw 35, MC_CCR35_VALUE
  2716. + ccr_sw 36, MC_CCR36_VALUE
  2717. + ccr_sw 37, MC_CCR37_VALUE
  2718. + ccr_sw 38, MC_CCR38_VALUE
  2719. + ccr_sw 39, MC_CCR39_VALUE
  2720. +
  2721. + ccr_sw 40, MC_CCR40_VALUE
  2722. + ccr_sw 41, MC_CCR41_VALUE
  2723. + ccr_sw 42, MC_CCR42_VALUE
  2724. + ccr_sw 43, MC_CCR43_VALUE
  2725. + ccr_sw 44, MC_CCR44_VALUE
  2726. + ccr_sw 45, MC_CCR45_VALUE
  2727. + ccr_sw 46, MC_CCR46_VALUE
  2728. +
  2729. + ccr_sw 52, MC_CCR52_VALUE
  2730. + ccr_sw 53, MC_CCR53_VALUE
  2731. + ccr_sw 54, MC_CCR54_VALUE
  2732. + ccr_sw 55, MC_CCR55_VALUE
  2733. + ccr_sw 56, MC_CCR56_VALUE
  2734. + ccr_sw 57, MC_CCR57_VALUE
  2735. + ccr_sw 58, MC_CCR58_VALUE
  2736. + ccr_sw 59, MC_CCR59_VALUE
  2737. +
  2738. + ccr_sw 60, MC_CCR60_VALUE
  2739. + ccr_sw 61, MC_CCR61_VALUE
  2740. +
  2741. + /* Disable bursts between FPI Master bus and XBAR bus */
  2742. + li t4, (LTQ_MC_GLOBAL_BASE | KSEG1)
  2743. + li t5, CCS_AHBM_CR_BURST_EN
  2744. + sw t5, CCS_ALWAYS_LAST(t4)
  2745. +
  2746. + /* Init abort condition for DRAM probe */
  2747. + move t4, zero
  2748. +
  2749. + /*
  2750. + * Put memory controller in active mode and start initialitation
  2751. + * sequence for connected DDR-SDRAM device
  2752. + */
  2753. +mc_start:
  2754. + lw t1, LTQ_MC_DDR_CCR_OFFSET(7)(t0)
  2755. + li t2, LTQ_MC_DDR_START
  2756. + or t1, t1, t2
  2757. + sw t1, LTQ_MC_DDR_CCR_OFFSET(7)(t0)
  2758. +
  2759. + /*
  2760. + * Wait until DLL has locked and core is ready for data transfers.
  2761. + * DLL lock indication is in register CCR47 and CCR48
  2762. + */
  2763. +wait_ready:
  2764. + li t1, LTQ_MC_DDR_DLL_LOCK_IND
  2765. + lw t2, LTQ_MC_DDR_CCR_OFFSET(47)(t0)
  2766. + and t2, t2, t1
  2767. + bne t1, t2, wait_ready
  2768. +
  2769. + lw t2, LTQ_MC_DDR_CCR_OFFSET(48)(t0)
  2770. + and t2, t2, t1
  2771. + bne t1, t2, wait_ready
  2772. +
  2773. +#ifdef CONFIG_SYS_DRAM_PROBE
  2774. +dram_probe:
  2775. + /* Initialization is finished after the second MC start */
  2776. + bnez t4, mc_finished
  2777. +
  2778. + /*
  2779. + * Preload register values for CCR03 and CCR11. Initial settings
  2780. + * are 8-bank mode enabled, 14 use address row bits, 10 used
  2781. + * column address bits.
  2782. + */
  2783. + li t1, CONFIG_SYS_SDRAM_BASE_UC
  2784. + li t5, MC_CCR03_VALUE
  2785. + li t6, MC_CCR11_VALUE
  2786. + addi t4, t4, 1
  2787. +
  2788. + /*
  2789. + * Store test values to DRAM at offsets 0 and 2^13 (bit 2 in bank select
  2790. + * address BA[3]) and read back the value at offset 0. If the resulting
  2791. + * value is equal to 1 we can skip to the next test. Otherwise
  2792. + * the 8-bank mode does not work with the current DRAM device,
  2793. + * thus we need to clear the according bit in register CCR03.
  2794. + */
  2795. + li t2, 1
  2796. + sw t2, 0x0(t1)
  2797. + li t3, (1 << 13)
  2798. + add t3, t3, t1
  2799. + sw zero, 0(t3)
  2800. + lw t3, 0(t1)
  2801. + bnez t3, row_col_test
  2802. +
  2803. + /* Clear CCR03.EIGHT_BANK_MODE */
  2804. + li t3, ~CCR03_EIGHT_BANK_MODE
  2805. + and t5, t5, t3
  2806. +
  2807. +row_col_test:
  2808. + /*
  2809. + * Store test values to DRAM at offsets 0, 2^27 (bit 13 of row address
  2810. + * RA[14]) and 2^26 (bit 12 of RA[14]). The chosen test values
  2811. + * represent the difference between max. row address bits (14) and used
  2812. + * row address bits. Then the read back value at offset 0 indicates
  2813. + * the useable row address bits with the current DRAM device. This
  2814. + * value must be set in the CCR11 register.
  2815. + */
  2816. + sw zero, 0(t1)
  2817. +
  2818. + li t2, 1
  2819. + li t3, (1 << 27)
  2820. + add t3, t3, t1
  2821. + sw t2, 0(t3)
  2822. +
  2823. + li t2, 2
  2824. + li t3, (1 << 26)
  2825. + add t3, t3, t1
  2826. + sw t2, 0(t3)
  2827. +
  2828. + /* Update CCR11.ADDR_PINS */
  2829. + lw t3, 0(t1)
  2830. + add t6, t6, t3
  2831. +
  2832. + /*
  2833. + * Store test values to DRAM at offsets 0, 2^10 (bit 9 of column address
  2834. + * CA[10]) and 2^9 (bit 8 of CA[10]). The chosen test values represent
  2835. + * the difference between max. column address bits (12) and used
  2836. + * column address bits. Then the read back value at offset 0 indicates
  2837. + * the useable column address bits with the current DRAM device. This
  2838. + * value must be set in the CCR11 register.
  2839. + */
  2840. + sw zero, 0(t1)
  2841. +
  2842. + li t2, 1
  2843. + li t3, (1 << 10)
  2844. + add t3, t3, t1
  2845. + sw t2, 0(t3)
  2846. +
  2847. + li t2, 2
  2848. + li t3, (1 << 9)
  2849. + add t3, t3, t1
  2850. + sw t2, 0(t3)
  2851. +
  2852. + /* Update CCR11.COLUMN_SIZE */
  2853. + lw t3, 0(t1)
  2854. + sll t3, t3, 24
  2855. + add t6, t6, t3
  2856. +
  2857. + /* Put memory controller in inactive mode */
  2858. + sw zero, LTQ_MC_DDR_CCR_OFFSET(7)(t0)
  2859. +
  2860. + /* Update CCR03 and CCR11 and restart memory controller initialiation */
  2861. + sw t5, LTQ_MC_DDR_CCR_OFFSET(3)(t0)
  2862. + sw t6, LTQ_MC_DDR_CCR_OFFSET(11)(t0)
  2863. + b mc_start
  2864. +
  2865. +mc_finished:
  2866. +#endif /* CONFIG_SYS_DRAM_PROBE */
  2867. +
  2868. + jr ra
  2869. +
  2870. + END(ltq_mem_init)
  2871. --- /dev/null
  2872. +++ b/arch/mips/cpu/mips32/vrx200/pmu.c
  2873. @@ -0,0 +1,130 @@
  2874. +/*
  2875. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  2876. + *
  2877. + * SPDX-License-Identifier: GPL-2.0+
  2878. + */
  2879. +
  2880. +#include <common.h>
  2881. +#include <asm/lantiq/io.h>
  2882. +#include <asm/lantiq/pm.h>
  2883. +#include <asm/arch/soc.h>
  2884. +
  2885. +#define LTQ_PMU_PWDCR_RESERVED ((1 << 13) | (1 << 4))
  2886. +
  2887. +#define LTQ_PMU_PWDCR_PCIELOC_EN (1 << 31)
  2888. +#define LTQ_PMU_PWDCR_GPHY (1 << 30)
  2889. +#define LTQ_PMU_PWDCR_PPE_TOP (1 << 29)
  2890. +#define LTQ_PMU_PWDCR_SWITCH (1 << 28)
  2891. +#define LTQ_PMU_PWDCR_USB1 (1 << 27)
  2892. +#define LTQ_PMU_PWDCR_USB1_PHY (1 << 26)
  2893. +#define LTQ_PMU_PWDCR_TDM (1 << 25)
  2894. +#define LTQ_PMU_PWDCR_PPE_DPLUS (1 << 24)
  2895. +#define LTQ_PMU_PWDCR_PPE_DPLUM (1 << 23)
  2896. +#define LTQ_PMU_PWDCR_PPE_EMA (1 << 22)
  2897. +#define LTQ_PMU_PWDCR_PPE_TC (1 << 21)
  2898. +#define LTQ_PMU_PWDCR_DEU (1 << 20)
  2899. +#define LTQ_PMU_PWDCR_PPE_SLL01 (1 << 19)
  2900. +#define LTQ_PMU_PWDCR_PPE_QSB (1 << 18)
  2901. +#define LTQ_PMU_PWDCR_UART1 (1 << 17)
  2902. +#define LTQ_PMU_PWDCR_SDIO (1 << 16)
  2903. +#define LTQ_PMU_PWDCR_AHBM (1 << 15)
  2904. +#define LTQ_PMU_PWDCR_FPIM (1 << 14)
  2905. +#define LTQ_PMU_PWDCR_GPTC (1 << 12)
  2906. +#define LTQ_PMU_PWDCR_LEDC (1 << 11)
  2907. +#define LTQ_PMU_PWDCR_EBU (1 << 10)
  2908. +#define LTQ_PMU_PWDCR_DSL (1 << 9)
  2909. +#define LTQ_PMU_PWDCR_SPI (1 << 8)
  2910. +#define LTQ_PMU_PWDCR_USIF (1 << 7)
  2911. +#define LTQ_PMU_PWDCR_USB0 (1 << 6)
  2912. +#define LTQ_PMU_PWDCR_DMA (1 << 5)
  2913. +#define LTQ_PMU_PWDCR_DFEV1 (1 << 3)
  2914. +#define LTQ_PMU_PWDCR_DFEV0 (1 << 2)
  2915. +#define LTQ_PMU_PWDCR_FPIS (1 << 1)
  2916. +#define LTQ_PMU_PWDCR_USB0_PHY (1 << 0)
  2917. +
  2918. +struct ltq_pmu_regs {
  2919. + u32 rsvd0[7];
  2920. + u32 pwdcr; /* Power down control */
  2921. + u32 sr; /* Power down status */
  2922. + u32 pwdcr1; /* Power down control 1 */
  2923. + u32 sr1; /* Power down status 1 */
  2924. +};
  2925. +
  2926. +static struct ltq_pmu_regs *ltq_pmu_regs =
  2927. + (struct ltq_pmu_regs *) CKSEG1ADDR(LTQ_PMU_BASE);
  2928. +
  2929. +u32 ltq_pm_map(enum ltq_pm_modules module)
  2930. +{
  2931. + u32 val;
  2932. +
  2933. + switch (module) {
  2934. + case LTQ_PM_CORE:
  2935. + val = LTQ_PMU_PWDCR_UART1 | LTQ_PMU_PWDCR_FPIM |
  2936. + LTQ_PMU_PWDCR_LEDC | LTQ_PMU_PWDCR_EBU;
  2937. + break;
  2938. + case LTQ_PM_DMA:
  2939. + val = LTQ_PMU_PWDCR_DMA;
  2940. + break;
  2941. + case LTQ_PM_ETH:
  2942. + val = LTQ_PMU_PWDCR_GPHY | LTQ_PMU_PWDCR_PPE_TOP |
  2943. + LTQ_PMU_PWDCR_SWITCH | LTQ_PMU_PWDCR_PPE_DPLUS |
  2944. + LTQ_PMU_PWDCR_PPE_DPLUM | LTQ_PMU_PWDCR_PPE_EMA |
  2945. + LTQ_PMU_PWDCR_PPE_TC | LTQ_PMU_PWDCR_PPE_SLL01 |
  2946. + LTQ_PMU_PWDCR_PPE_QSB;
  2947. + break;
  2948. + case LTQ_PM_SPI:
  2949. + val = LTQ_PMU_PWDCR_SPI;
  2950. + break;
  2951. + default:
  2952. + val = 0;
  2953. + break;
  2954. + }
  2955. +
  2956. + return val;
  2957. +}
  2958. +
  2959. +int ltq_pm_enable(enum ltq_pm_modules module)
  2960. +{
  2961. + const unsigned long timeout = 1000;
  2962. + unsigned long timebase;
  2963. + u32 sr, val;
  2964. +
  2965. + val = ltq_pm_map(module);
  2966. + if (unlikely(!val))
  2967. + return 1;
  2968. +
  2969. + ltq_clrbits(&ltq_pmu_regs->pwdcr, val);
  2970. +
  2971. + timebase = get_timer(0);
  2972. +
  2973. + do {
  2974. + sr = ltq_readl(&ltq_pmu_regs->sr);
  2975. + if (~sr & val)
  2976. + return 0;
  2977. + } while (get_timer(timebase) < timeout);
  2978. +
  2979. + return 1;
  2980. +}
  2981. +
  2982. +int ltq_pm_disable(enum ltq_pm_modules module)
  2983. +{
  2984. + u32 val;
  2985. +
  2986. + val = ltq_pm_map(module);
  2987. + if (unlikely(!val))
  2988. + return 1;
  2989. +
  2990. + ltq_setbits(&ltq_pmu_regs->pwdcr, val);
  2991. +
  2992. + return 0;
  2993. +}
  2994. +
  2995. +void ltq_pmu_init(void)
  2996. +{
  2997. + u32 set, clr;
  2998. +
  2999. + clr = ltq_pm_map(LTQ_PM_CORE);
  3000. + set = ~(LTQ_PMU_PWDCR_RESERVED | clr);
  3001. +
  3002. + ltq_clrsetbits(&ltq_pmu_regs->pwdcr, clr, set);
  3003. +}
  3004. --- /dev/null
  3005. +++ b/arch/mips/cpu/mips32/vrx200/rcu.c
  3006. @@ -0,0 +1,194 @@
  3007. +/*
  3008. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  3009. + *
  3010. + * SPDX-License-Identifier: GPL-2.0+
  3011. + */
  3012. +
  3013. +#include <common.h>
  3014. +#include <asm/lantiq/io.h>
  3015. +#include <asm/lantiq/reset.h>
  3016. +#include <asm/lantiq/cpu.h>
  3017. +#include <asm/arch/soc.h>
  3018. +
  3019. +#define LTQ_RCU_RD_GPHY0 (1 << 31) /* GPHY0 */
  3020. +#define LTQ_RCU_RD_SRST (1 << 30) /* Global SW Reset */
  3021. +#define LTQ_RCU_RD_GPHY1 (1 << 29) /* GPHY1 */
  3022. +#define LTQ_RCU_RD_ENMIP2 (1 << 28) /* Enable NMI of PLL2 */
  3023. +#define LTQ_RCU_RD_REG25_PD (1 << 26) /* Power down 2.5V regulator */
  3024. +#define LTQ_RCU_RD_ENDINIT (1 << 25) /* FPI slave bus access */
  3025. +#define LTQ_RCU_RD_PPE_ATM_TC (1 << 23) /* PPE ATM TC */
  3026. +#define LTQ_RCU_RD_PCIE (1 << 22) /* PCI-E core */
  3027. +#define LTQ_RCU_RD_ETHSW (1 << 21) /* Ethernet switch */
  3028. +#define LTQ_RCU_RD_DSP_DEN (1 << 20) /* Enable DSP JTAG */
  3029. +#define LTQ_RCU_RD_TDM (1 << 19) /* TDM module interface */
  3030. +#define LTQ_RCU_RD_ENMIP1 (1 << 18) /* Enable NMI of PLL1 */
  3031. +#define LTQ_RCU_RD_SWBCK (1 << 17) /* Switch backward compat */
  3032. +#define LTQ_RCU_RD_HSNAND (1 << 16) /* HSNAND controller */
  3033. +#define LTQ_RCU_RD_ENMIP0 (1 << 15) /* Enable NMI of PLL0 */
  3034. +#define LTQ_RCU_RD_MC (1 << 14) /* Memory Controller */
  3035. +#define LTQ_RCU_RD_PCI (1 << 13) /* PCI core */
  3036. +#define LTQ_RCU_RD_PCIE_PHY (1 << 12) /* PCI-E Phy */
  3037. +#define LTQ_RCU_RD_DFE_CORE (1 << 11) /* DFE core */
  3038. +#define LTQ_RCU_RD_SDIO (1 << 10) /* SDIO core */
  3039. +#define LTQ_RCU_RD_DMA (1 << 9) /* DMA core */
  3040. +#define LTQ_RCU_RD_PPE (1 << 8) /* PPE core */
  3041. +#define LTQ_RCU_RD_DFE (1 << 7) /* DFE core */
  3042. +#define LTQ_RCU_RD_AHB (1 << 6) /* AHB bus */
  3043. +#define LTQ_RCU_RD_HRST_CFG (1 << 5) /* HW reset configuration */
  3044. +#define LTQ_RCU_RD_USB (1 << 4) /* USB and Phy core */
  3045. +#define LTQ_RCU_RD_PPE_DSP (1 << 3) /* PPE DSP interface */
  3046. +#define LTQ_RCU_RD_FPI (1 << 2) /* FPI bus */
  3047. +#define LTQ_RCU_RD_CPU (1 << 1) /* CPU subsystem */
  3048. +#define LTQ_RCU_RD_HRST (1 << 0) /* HW reset via HRST pin */
  3049. +
  3050. +#define LTQ_RCU_STAT_BOOT_SHIFT 17
  3051. +#define LTQ_RCU_STAT_BOOT_MASK (0xF << LTQ_RCU_STAT_BOOT_SHIFT)
  3052. +#define LTQ_RCU_STAT_BOOT_H (1 << 12)
  3053. +
  3054. +#define LTQ_RCU_GP_STRAP_CLOCKSOURCE (1 << 15)
  3055. +
  3056. +struct ltq_rcu_regs {
  3057. + u32 rsvd0[4];
  3058. + u32 req; /* Reset request */
  3059. + u32 stat; /* Reset status */
  3060. + u32 usb0_cfg; /* USB0 configure */
  3061. + u32 gp_strap; /* GPIO strapping */
  3062. + u32 gfs_add0; /* GPHY0 firmware base addr */
  3063. + u32 stat2; /* SLIC and USB reset status */
  3064. + u32 pci_rdy; /* PCI boot ready */
  3065. + u32 ppe_conf; /* PPE ethernet config */
  3066. + u32 pcie_phy_con; /* PCIE PHY config/status */
  3067. + u32 usb1_cfg; /* USB1 configure */
  3068. + u32 usb_ana_cfg1a; /* USB analog config 1a */
  3069. + u32 usb_ana_cfg1b; /* USB analog config 1b */
  3070. + u32 rsvd1;
  3071. + u32 gf_mdio_add; /* GPHY0/1 MDIO address */
  3072. + u32 req2; /* SLIC and USB reset request */
  3073. + u32 ahb_endian; /* AHB bus endianess */
  3074. + u32 rsvd2[4];
  3075. + u32 gcc; /* General CPU config */
  3076. + u32 rsvd3;
  3077. + u32 gfs_add1; /* GPHY1 firmware base addr */
  3078. +};
  3079. +
  3080. +static struct ltq_rcu_regs *ltq_rcu_regs =
  3081. + (struct ltq_rcu_regs *) CKSEG1ADDR(LTQ_RCU_BASE);
  3082. +
  3083. +u32 ltq_reset_map(enum ltq_reset_modules module)
  3084. +{
  3085. + u32 val;
  3086. +
  3087. + switch (module) {
  3088. + case LTQ_RESET_CORE:
  3089. + case LTQ_RESET_SOFT:
  3090. + val = LTQ_RCU_RD_SRST | LTQ_RCU_RD_CPU | LTQ_RCU_RD_ENMIP2 |
  3091. + LTQ_RCU_RD_GPHY1 | LTQ_RCU_RD_GPHY0;
  3092. + break;
  3093. + case LTQ_RESET_DMA:
  3094. + val = LTQ_RCU_RD_DMA;
  3095. + break;
  3096. + case LTQ_RESET_ETH:
  3097. + val = LTQ_RCU_RD_PPE | LTQ_RCU_RD_ETHSW;
  3098. + break;
  3099. + case LTQ_RESET_PHY:
  3100. + val = LTQ_RCU_RD_GPHY1 | LTQ_RCU_RD_GPHY0;
  3101. + break;
  3102. + case LTQ_RESET_HARD:
  3103. + val = LTQ_RCU_RD_HRST;
  3104. + break;
  3105. + default:
  3106. + val = 0;
  3107. + break;
  3108. + }
  3109. +
  3110. + return val;
  3111. +}
  3112. +
  3113. +int ltq_reset_activate(enum ltq_reset_modules module)
  3114. +{
  3115. + u32 val;
  3116. +
  3117. + val = ltq_reset_map(module);
  3118. + if (unlikely(!val))
  3119. + return 1;
  3120. +
  3121. + ltq_setbits(&ltq_rcu_regs->req, val);
  3122. +
  3123. + return 0;
  3124. +}
  3125. +
  3126. +int ltq_reset_deactivate(enum ltq_reset_modules module)
  3127. +{
  3128. + u32 val;
  3129. +
  3130. + val = ltq_reset_map(module);
  3131. + if (unlikely(!val))
  3132. + return 1;
  3133. +
  3134. + ltq_clrbits(&ltq_rcu_regs->req, val);
  3135. +
  3136. + return 0;
  3137. +}
  3138. +
  3139. +enum ltq_boot_select ltq_boot_select(void)
  3140. +{
  3141. + u32 stat;
  3142. + unsigned int bootstrap;
  3143. +
  3144. + /*
  3145. + * Boot select value is built from bits 20-17 and bit 12.
  3146. + * The bit sequence is read as 4-2-1-0-3.
  3147. + */
  3148. + stat = ltq_readl(&ltq_rcu_regs->stat);
  3149. + bootstrap = ((stat & LTQ_RCU_STAT_BOOT_H) << 4) |
  3150. + ((stat & LTQ_RCU_STAT_BOOT_MASK) >> LTQ_RCU_STAT_BOOT_SHIFT);
  3151. +
  3152. + switch (bootstrap) {
  3153. + case 0:
  3154. + return BOOT_NOR_NO_BOOTROM;
  3155. + case 1:
  3156. + return BOOT_RGMII1;
  3157. + case 2:
  3158. + return BOOT_NOR;
  3159. + case 4:
  3160. + return BOOT_UART_NO_EEPROM;
  3161. + case 6:
  3162. + return BOOT_PCI;
  3163. + case 8:
  3164. + return BOOT_UART;
  3165. + case 10:
  3166. + return BOOT_SPI;
  3167. + case 12:
  3168. + return BOOT_NAND;
  3169. + default:
  3170. + return BOOT_UNKNOWN;
  3171. + }
  3172. +}
  3173. +
  3174. +void ltq_rcu_gphy_boot(unsigned int id, ulong addr)
  3175. +{
  3176. + u32 module;
  3177. + void *gfs_add;
  3178. +
  3179. + switch (id) {
  3180. + case 0:
  3181. + module = LTQ_RCU_RD_GPHY0;
  3182. + gfs_add = &ltq_rcu_regs->gfs_add0;
  3183. + break;
  3184. + case 1:
  3185. + module = LTQ_RCU_RD_GPHY1;
  3186. + gfs_add = &ltq_rcu_regs->gfs_add1;
  3187. + break;
  3188. + default:
  3189. + BUG();
  3190. + }
  3191. +
  3192. + /* Stop and reset GPHY */
  3193. + ltq_setbits(&ltq_rcu_regs->req, module);
  3194. +
  3195. + /* Configure firmware and boot address */
  3196. + ltq_writel(gfs_add, CPHYSADDR(addr & 0xFFFFC000));
  3197. +
  3198. + /* Start GPHY by releasing reset */
  3199. + ltq_clrbits(&ltq_rcu_regs->req, module);
  3200. +}
  3201. --- /dev/null
  3202. +++ b/arch/mips/include/asm/arch-danube/config.h
  3203. @@ -0,0 +1,163 @@
  3204. +/*
  3205. + * Copyright (C) 2007-2010 Lantiq Deutschland GmbH
  3206. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  3207. + *
  3208. + * SPDX-License-Identifier: GPL-2.0+
  3209. + *
  3210. + * Common board configuration for Lantiq XWAY Danube family
  3211. + *
  3212. + * Use following defines in your board config to enable specific features
  3213. + * and drivers for this SoC:
  3214. + *
  3215. + * CONFIG_LTQ_SUPPORT_UART
  3216. + * - support the Danube ASC/UART interface and console
  3217. + *
  3218. + * CONFIG_LTQ_SUPPORT_NOR_FLASH
  3219. + * - support a parallel NOR flash via the CFI interface in flash bank 0
  3220. + *
  3221. + * CONFIG_LTQ_SUPPORT_ETHERNET
  3222. + * - support the Danube ETOP and MAC interface
  3223. + *
  3224. + * CONFIG_LTQ_SUPPORT_SPI_FLASH
  3225. + * - support the Danube SPI interface and serial flash drivers
  3226. + * - specific SPI flash drivers must be configured separately
  3227. + */
  3228. +
  3229. +#ifndef __DANUBE_CONFIG_H__
  3230. +#define __DANUBE_CONFIG_H__
  3231. +
  3232. +/* CPU and SoC type */
  3233. +#define CONFIG_SOC_LANTIQ
  3234. +#define CONFIG_SOC_XWAY_DANUBE
  3235. +
  3236. +/* Cache configuration */
  3237. +#define CONFIG_SYS_MIPS_CACHE_MODE CONF_CM_CACHABLE_NONCOHERENT
  3238. +#define CONFIG_SYS_DCACHE_SIZE (16 * 1024)
  3239. +#define CONFIG_SYS_ICACHE_SIZE (16 * 1024)
  3240. +#define CONFIG_SYS_CACHELINE_SIZE 32
  3241. +#define CONFIG_SYS_MIPS_CACHE_EXT_INIT
  3242. +
  3243. +/*
  3244. + * Supported clock modes
  3245. + * PLL0 clock output is 333 MHz
  3246. + * PLL1 clock output is 262.144 MHz
  3247. + */
  3248. +#define LTQ_CLK_CPU_333_DDR_167 0 /* Base PLL0, OCP 2 */
  3249. +#define LTQ_CLK_CPU_111_DDR_111 1 /* Base PLL0, OCP 1 */
  3250. +
  3251. +/* CPU speed */
  3252. +#define CONFIG_SYS_CLOCK_MODE LTQ_CLK_CPU_333_DDR_167
  3253. +#define CONFIG_SYS_MIPS_TIMER_FREQ 166666667
  3254. +#define CONFIG_SYS_HZ 1000
  3255. +
  3256. +/* RAM */
  3257. +#define CONFIG_NR_DRAM_BANKS 1
  3258. +#define CONFIG_SYS_SDRAM_BASE 0x80000000
  3259. +#define CONFIG_SYS_MEMTEST_START 0x81000000
  3260. +#define CONFIG_SYS_MEMTEST_END 0x82000000
  3261. +#define CONFIG_SYS_LOAD_ADDR 0x81000000
  3262. +#define CONFIG_SYS_INIT_SP_OFFSET 0x4000
  3263. +
  3264. +/* SRAM */
  3265. +#define CONFIG_SYS_SRAM_BASE 0xBE1A0000
  3266. +#define CONFIG_SYS_SRAM_SIZE 0x10000
  3267. +
  3268. +/* ASC/UART driver and console */
  3269. +#define CONFIG_LANTIQ_SERIAL
  3270. +#define CONFIG_SYS_BAUDRATE_TABLE { 9600, 19200, 38400, 57600, 115200 }
  3271. +
  3272. +/* GPIO */
  3273. +#define CONFIG_LANTIQ_GPIO
  3274. +#define CONFIG_LTQ_GPIO_MAX_BANKS 2
  3275. +
  3276. +/* FLASH driver */
  3277. +#if defined(CONFIG_LTQ_SUPPORT_NOR_FLASH)
  3278. +#define CONFIG_SYS_MAX_FLASH_BANKS 1
  3279. +#define CONFIG_SYS_MAX_FLASH_SECT 256
  3280. +#define CONFIG_SYS_FLASH_BASE 0xB0000000
  3281. +#define CONFIG_FLASH_16BIT
  3282. +#define CONFIG_SYS_FLASH_CFI
  3283. +#define CONFIG_FLASH_CFI_DRIVER
  3284. +#define CONFIG_SYS_FLASH_CFI_WIDTH FLASH_CFI_16BIT
  3285. +#define CONFIG_SYS_FLASH_USE_BUFFER_WRITE
  3286. +#define CONFIG_FLASH_SHOW_PROGRESS 50
  3287. +#define CONFIG_SYS_FLASH_PROTECTION
  3288. +#define CONFIG_CFI_FLASH_USE_WEAK_ADDR_SWAP
  3289. +
  3290. +#define CONFIG_CMD_FLASH
  3291. +#else
  3292. +#define CONFIG_SYS_NO_FLASH
  3293. +#endif /* CONFIG_NOR_FLASH */
  3294. +
  3295. +#if defined(CONFIG_LTQ_SUPPORT_SPI_FLASH)
  3296. +#define CONFIG_LANTIQ_SPI
  3297. +#define CONFIG_SPI_FLASH
  3298. +
  3299. +#define CONFIG_CMD_SF
  3300. +#define CONFIG_CMD_SPI
  3301. +#endif
  3302. +
  3303. +#if defined(CONFIG_LTQ_SUPPORT_NAND_FLASH)
  3304. +#define CONFIG_NAND_LANTIQ
  3305. +#define CONFIG_SYS_MAX_NAND_DEVICE 1
  3306. +#define CONFIG_SYS_NAND_BASE 0xB4000000
  3307. +
  3308. +#define CONFIG_CMD_NAND
  3309. +#endif
  3310. +
  3311. +#if defined(CONFIG_LTQ_SUPPORT_ETHERNET)
  3312. +#define CONFIG_LANTIQ_DMA
  3313. +#define CONFIG_LANTIQ_DANUBE_ETOP
  3314. +
  3315. +#define CONFIG_PHYLIB
  3316. +#define CONFIG_MII
  3317. +
  3318. +#define CONFIG_CMD_MII
  3319. +#define CONFIG_CMD_NET
  3320. +#endif
  3321. +
  3322. +#define CONFIG_SPL_MAX_SIZE (32 * 1024)
  3323. +#define CONFIG_SPL_BSS_MAX_SIZE (8 * 1024)
  3324. +#define CONFIG_SPL_STACK_MAX_SIZE (8 * 1024)
  3325. +#define CONFIG_SPL_MALLOC_MAX_SIZE (32 * 1024)
  3326. +/*#define CONFIG_SPL_STACK_BSS_IN_SRAM*/
  3327. +
  3328. +#if defined(CONFIG_SPL_STACK_BSS_IN_SRAM)
  3329. +#define CONFIG_SPL_STACK_BASE (CONFIG_SYS_SRAM_BASE + \
  3330. + CONFIG_SPL_MAX_SIZE + \
  3331. + CONFIG_SPL_STACK_MAX_SIZE - 1)
  3332. +#define CONFIG_SPL_BSS_BASE (CONFIG_SPL_STACK_BASE + 1)
  3333. +#define CONFIG_SPL_MALLOC_BASE (CONFIG_SYS_SDRAM_BASE + \
  3334. + CONFIG_SYS_INIT_SP_OFFSET)
  3335. +#else
  3336. +#define CONFIG_SPL_STACK_BASE (CONFIG_SYS_SDRAM_BASE + \
  3337. + CONFIG_SYS_INIT_SP_OFFSET + \
  3338. + CONFIG_SPL_STACK_MAX_SIZE - 1)
  3339. +#define CONFIG_SPL_BSS_BASE (CONFIG_SPL_STACK_BASE + 1)
  3340. +#define CONFIG_SPL_MALLOC_BASE (CONFIG_SPL_BSS_BASE + \
  3341. + CONFIG_SPL_BSS_MAX_SIZE)
  3342. +#endif
  3343. +
  3344. +#if defined(CONFIG_SYS_BOOT_RAM)
  3345. +#define CONFIG_SYS_TEXT_BASE 0xa0100000
  3346. +#define CONFIG_SKIP_LOWLEVEL_INIT
  3347. +#define CONFIG_SYS_DISABLE_CACHE
  3348. +#endif
  3349. +
  3350. +#if defined(CONFIG_SYS_BOOT_NOR)
  3351. +#define CONFIG_SYS_TEXT_BASE 0xB0000000
  3352. +#endif
  3353. +
  3354. +#if defined(CONFIG_SYS_BOOT_NORSPL)
  3355. +#define CONFIG_SYS_TEXT_BASE 0x80100000
  3356. +#define CONFIG_SPL_TEXT_BASE 0xB0000000
  3357. +#endif
  3358. +
  3359. +#if defined(CONFIG_SYS_BOOT_NOR) || defined(CONFIG_SYS_BOOT_NORSPL)
  3360. +#define CONFIG_SYS_XWAY_EBU_BOOTCFG 0x688C688C
  3361. +#define CONFIG_XWAY_SWAP_BYTES
  3362. +#endif
  3363. +
  3364. +#define CONFIG_SYS_MONITOR_BASE CONFIG_SYS_TEXT_BASE
  3365. +
  3366. +#endif /* __DANUBE_CONFIG_H__ */
  3367. --- /dev/null
  3368. +++ b/arch/mips/include/asm/arch-danube/gpio.h
  3369. @@ -0,0 +1,12 @@
  3370. +/*
  3371. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  3372. + *
  3373. + * SPDX-License-Identifier: GPL-2.0+
  3374. + */
  3375. +
  3376. +#ifndef __DANUBE_GPIO_H__
  3377. +#define __DANUBE_GPIO_H__
  3378. +
  3379. +#include <asm/lantiq/gpio.h>
  3380. +
  3381. +#endif /* __DANUBE_GPIO_H__ */
  3382. --- /dev/null
  3383. +++ b/arch/mips/include/asm/arch-danube/nand.h
  3384. @@ -0,0 +1,13 @@
  3385. +/*
  3386. + * Copyright (C) 2012-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  3387. + *
  3388. + * SPDX-License-Identifier: GPL-2.0+
  3389. + */
  3390. +
  3391. +#ifndef __DANUBE_NAND_H__
  3392. +#define __DANUBE_NAND_H__
  3393. +
  3394. +struct nand_chip;
  3395. +int ltq_nand_init(struct nand_chip *nand);
  3396. +
  3397. +#endif /* __DANUBE_NAND_H__ */
  3398. --- /dev/null
  3399. +++ b/arch/mips/include/asm/arch-danube/soc.h
  3400. @@ -0,0 +1,38 @@
  3401. +/*
  3402. + * Copyright (C) 2007-2010 Lantiq Deutschland GmbH
  3403. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  3404. + *
  3405. + * SPDX-License-Identifier: GPL-2.0+
  3406. + */
  3407. +
  3408. +#ifndef __DANUBE_SOC_H__
  3409. +#define __DANUBE_SOC_H__
  3410. +
  3411. +#define LTQ_ASC0_BASE 0x1E100400
  3412. +#define LTQ_SPI_BASE 0x1E100800
  3413. +#define LTQ_GPIO_BASE 0x1E100B00
  3414. +#define LTQ_SSIO_BASE 0x1E100BB0
  3415. +#define LTQ_ASC1_BASE 0x1E100C00
  3416. +#define LTQ_DMA_BASE 0x1E104100
  3417. +
  3418. +#define LTQ_EBU_BASE 0x1E105300
  3419. +#define LTQ_EBU_REGION0_BASE 0x10000000
  3420. +#define LTQ_EBU_REGION1_BASE 0x14000000
  3421. +#define LTQ_EBU_NAND_BASE (LTQ_EBU_BASE + 0xB0)
  3422. +
  3423. +#define LTQ_PPE_BASE 0x1E180000
  3424. +#define LTQ_PPE_ETOP_BASE (LTQ_PPE_BASE + 0x11800)
  3425. +#define LTQ_PPE_ENET0_BASE (LTQ_PPE_BASE + 0x11840)
  3426. +
  3427. +#define LTQ_PMU_BASE 0x1F102000
  3428. +#define LTQ_CGU_BASE 0x1F103000
  3429. +#define LTQ_MPS_BASE 0x1F107000
  3430. +#define LTQ_CHIPID_BASE (LTQ_MPS_BASE + 0x340)
  3431. +#define LTQ_RCU_BASE 0x1F203000
  3432. +
  3433. +#define LTQ_MC_GEN_BASE 0x1F800000
  3434. +#define LTQ_MC_SDR_BASE 0x1F800200
  3435. +#define LTQ_MC_DDR_BASE 0x1F801000
  3436. +#define LTQ_MC_DDR_DC_OFFSET(x) (x * 0x10)
  3437. +
  3438. +#endif /* __DANUBE_SOC_H__ */
  3439. --- /dev/null
  3440. +++ b/arch/mips/include/asm/arch-vrx200/config.h
  3441. @@ -0,0 +1,184 @@
  3442. +/*
  3443. + * Copyright (C) 2010 Lantiq Deutschland GmbH
  3444. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  3445. + *
  3446. + * SPDX-License-Identifier: GPL-2.0+
  3447. + *
  3448. + * Common board configuration for Lantiq XWAY VRX200 family
  3449. + *
  3450. + * Use following defines in your board config to enable specific features
  3451. + * and drivers for this SoC:
  3452. + *
  3453. + * CONFIG_LTQ_SUPPORT_UART
  3454. + * - support the VRX200 ASC/UART interface and console
  3455. + *
  3456. + * CONFIG_LTQ_SUPPORT_NOR_FLASH
  3457. + * - support a parallel NOR flash via the CFI interface in flash bank 0
  3458. + *
  3459. + * CONFIG_LTQ_SUPPORT_ETHERNET
  3460. + * - support the VRX200 internal switch
  3461. + *
  3462. + * CONFIG_LTQ_SUPPORT_SPI_FLASH
  3463. + * - support the VRX200 SPI interface and serial flash drivers
  3464. + * - specific SPI flash drivers must be configured separately
  3465. + *
  3466. + * CONFIG_LTQ_SUPPORT_SPL_SPI_FLASH
  3467. + * - build a preloader that runs in the internal SRAM and loads
  3468. + * the U-Boot from SPI flash into RAM
  3469. + */
  3470. +
  3471. +#ifndef __VRX200_CONFIG_H__
  3472. +#define __VRX200_CONFIG_H__
  3473. +
  3474. +/* CPU and SoC type */
  3475. +#define CONFIG_SOC_LANTIQ
  3476. +#define CONFIG_SOC_XWAY_VRX200
  3477. +
  3478. +/* Cache configuration */
  3479. +#define CONFIG_SYS_MIPS_CACHE_MODE CONF_CM_CACHABLE_NONCOHERENT
  3480. +#define CONFIG_SYS_DCACHE_SIZE (32 * 1024)
  3481. +#define CONFIG_SYS_ICACHE_SIZE (32 * 1024)
  3482. +#define CONFIG_SYS_CACHELINE_SIZE 32
  3483. +#define CONFIG_SYS_MIPS_CACHE_EXT_INIT
  3484. +
  3485. +/*
  3486. + * Supported clock modes
  3487. + * PLL0 clock output is 1000 MHz
  3488. + * PLL1 clock output is 393.219 MHz
  3489. + */
  3490. +#define LTQ_CLK_CPU_600_DDR_300 0 /* Base PLL0, OCP 2 */
  3491. +#define LTQ_CLK_CPU_600_DDR_200 1 /* Base PLL0, OCP 3 */
  3492. +#define LTQ_CLK_CPU_500_DDR_250 2 /* Base PLL0, OCP 2 */
  3493. +#define LTQ_CLK_CPU_500_DDR_200 3 /* Base PLL0, OCP 2.5 */
  3494. +#define LTQ_CLK_CPU_333_DDR_167 4 /* Base PLL0, OCP 2 */
  3495. +#define LTQ_CLK_CPU_167_DDR_167 5 /* Base PLL0, OCP 1 */
  3496. +#define LTQ_CLK_CPU_125_DDR_125 6 /* Base PLL0, OCP 1 */
  3497. +#define LTQ_CLK_CPU_393_DDR_197 7 /* Base PLL1, OCP 2 */
  3498. +#define LTQ_CLK_CPU_197_DDR_197 8 /* Base PLL1, OCP 1 */
  3499. +
  3500. +/* CPU speed */
  3501. +#define CONFIG_SYS_CLOCK_MODE LTQ_CLK_CPU_500_DDR_250
  3502. +#define CONFIG_SYS_MIPS_TIMER_FREQ 250000000
  3503. +#define CONFIG_SYS_HZ 1000
  3504. +
  3505. +/* RAM */
  3506. +#define CONFIG_NR_DRAM_BANKS 1
  3507. +#define CONFIG_SYS_SDRAM_BASE 0x80000000
  3508. +#define CONFIG_SYS_SDRAM_BASE_UC 0xa0000000
  3509. +#define CONFIG_SYS_MEMTEST_START 0x81000000
  3510. +#define CONFIG_SYS_MEMTEST_END 0x82000000
  3511. +#define CONFIG_SYS_LOAD_ADDR 0x81000000
  3512. +#define CONFIG_SYS_INIT_SP_OFFSET (32 * 1024)
  3513. +
  3514. +/* SRAM */
  3515. +#define CONFIG_SYS_SRAM_BASE 0xBE220000
  3516. +#define CONFIG_SYS_SRAM_SIZE 0x10000
  3517. +
  3518. +/* ASC/UART driver and console */
  3519. +#define CONFIG_LANTIQ_SERIAL
  3520. +#define CONFIG_SYS_BAUDRATE_TABLE { 9600, 19200, 38400, 57600, 115200 }
  3521. +
  3522. +/* GPIO */
  3523. +#define CONFIG_LANTIQ_GPIO
  3524. +#define CONFIG_LTQ_GPIO_MAX_BANKS 3
  3525. +#define CONFIG_LTQ_HAS_GPIO_BANK3
  3526. +
  3527. +/* FLASH driver */
  3528. +#if defined(CONFIG_LTQ_SUPPORT_NOR_FLASH)
  3529. +#define CONFIG_SYS_MAX_FLASH_BANKS 1
  3530. +#define CONFIG_SYS_MAX_FLASH_SECT 256
  3531. +#define CONFIG_SYS_FLASH_BASE 0xB0000000
  3532. +#define CONFIG_FLASH_16BIT
  3533. +#define CONFIG_SYS_FLASH_CFI
  3534. +#define CONFIG_FLASH_CFI_DRIVER
  3535. +#define CONFIG_SYS_FLASH_CFI_WIDTH FLASH_CFI_16BIT
  3536. +#define CONFIG_SYS_FLASH_USE_BUFFER_WRITE
  3537. +#define CONFIG_FLASH_SHOW_PROGRESS 50
  3538. +#define CONFIG_SYS_FLASH_PROTECTION
  3539. +#define CONFIG_CFI_FLASH_USE_WEAK_ADDR_SWAP
  3540. +
  3541. +#define CONFIG_CMD_FLASH
  3542. +#else
  3543. +#define CONFIG_SYS_NO_FLASH
  3544. +#endif /* CONFIG_NOR_FLASH */
  3545. +
  3546. +#if defined(CONFIG_LTQ_SUPPORT_SPI_FLASH)
  3547. +#define CONFIG_LANTIQ_SPI
  3548. +#define CONFIG_SPI_FLASH
  3549. +
  3550. +#define CONFIG_CMD_SF
  3551. +#define CONFIG_CMD_SPI
  3552. +#endif
  3553. +
  3554. +#if defined(CONFIG_LTQ_SUPPORT_NAND_FLASH)
  3555. +#define CONFIG_NAND_LANTIQ
  3556. +#define CONFIG_SYS_MAX_NAND_DEVICE 1
  3557. +#define CONFIG_SYS_NAND_BASE 0xB4000000
  3558. +
  3559. +#define CONFIG_CMD_NAND
  3560. +#endif
  3561. +
  3562. +#if defined(CONFIG_LTQ_SUPPORT_ETHERNET)
  3563. +#define CONFIG_LANTIQ_DMA
  3564. +#define CONFIG_LANTIQ_VRX200_SWITCH
  3565. +#define CONFIG_PHY_LANTIQ
  3566. +
  3567. +#define CONFIG_SYS_RX_ETH_BUFFER 8
  3568. +#define CONFIG_PHYLIB
  3569. +#define CONFIG_MII
  3570. +#define CONFIG_UDP_CHECKSUM
  3571. +
  3572. +#define CONFIG_CMD_MII
  3573. +#define CONFIG_CMD_NET
  3574. +#endif
  3575. +
  3576. +#define CONFIG_SPL_MAX_SIZE (32 * 1024)
  3577. +#define CONFIG_SPL_BSS_MAX_SIZE (8 * 1024)
  3578. +#define CONFIG_SPL_STACK_MAX_SIZE (8 * 1024)
  3579. +#define CONFIG_SPL_MALLOC_MAX_SIZE (32 * 1024)
  3580. +#define CONFIG_SPL_STACK_BSS_IN_SRAM
  3581. +
  3582. +#if defined(CONFIG_SPL_STACK_BSS_IN_SRAM)
  3583. +#define CONFIG_SPL_STACK_BASE (CONFIG_SYS_SRAM_BASE + \
  3584. + CONFIG_SPL_MAX_SIZE + \
  3585. + CONFIG_SPL_STACK_MAX_SIZE - 1)
  3586. +#define CONFIG_SPL_BSS_BASE (CONFIG_SPL_STACK_BASE + 1)
  3587. +#define CONFIG_SPL_MALLOC_BASE (CONFIG_SYS_SDRAM_BASE + \
  3588. + CONFIG_SYS_INIT_SP_OFFSET)
  3589. +#else
  3590. +#define CONFIG_SPL_STACK_BASE (CONFIG_SYS_SDRAM_BASE + \
  3591. + CONFIG_SYS_INIT_SP_OFFSET + \
  3592. + CONFIG_SPL_STACK_MAX_SIZE - 1)
  3593. +#define CONFIG_SPL_BSS_BASE (CONFIG_SPL_STACK_BASE + 1)
  3594. +#define CONFIG_SPL_MALLOC_BASE (CONFIG_SPL_BSS_BASE + \
  3595. + CONFIG_SPL_BSS_MAX_SIZE)
  3596. +#endif
  3597. +
  3598. +#if defined(CONFIG_SYS_BOOT_RAM)
  3599. +#define CONFIG_SYS_TEXT_BASE 0xA0100000
  3600. +#define CONFIG_SKIP_LOWLEVEL_INIT
  3601. +#define CONFIG_SYS_DISABLE_CACHE
  3602. +#endif
  3603. +
  3604. +#if defined(CONFIG_SYS_BOOT_NOR)
  3605. +#define CONFIG_SYS_TEXT_BASE 0xB0000000
  3606. +#endif
  3607. +
  3608. +#if defined(CONFIG_SYS_BOOT_SFSPL)
  3609. +#define CONFIG_SYS_TEXT_BASE 0x80100000
  3610. +#define CONFIG_SPL_TEXT_BASE 0xBE220000
  3611. +#endif
  3612. +
  3613. +#if defined(CONFIG_SYS_BOOT_NORSPL)
  3614. +#define CONFIG_SYS_TEXT_BASE 0x80100000
  3615. +#define CONFIG_SPL_TEXT_BASE 0xB0000000
  3616. +#endif
  3617. +
  3618. +#if defined(CONFIG_SYS_BOOT_NOR) || defined(CONFIG_SYS_BOOT_NORSPL)
  3619. +#define CONFIG_SYS_XWAY_EBU_BOOTCFG 0x688C688C
  3620. +#define CONFIG_XWAY_SWAP_BYTES
  3621. +#endif
  3622. +
  3623. +#define CONFIG_SYS_MONITOR_BASE CONFIG_SYS_TEXT_BASE
  3624. +
  3625. +#endif /* __VRX200_CONFIG_H__ */
  3626. --- /dev/null
  3627. +++ b/arch/mips/include/asm/arch-vrx200/gphy.h
  3628. @@ -0,0 +1,65 @@
  3629. +/*
  3630. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  3631. + *
  3632. + * SPDX-License-Identifier: GPL-2.0+
  3633. + */
  3634. +
  3635. +#ifndef __VRX200_GPHY_H__
  3636. +#define __VRX200_GPHY_H__
  3637. +
  3638. +enum ltq_gphy_clk {
  3639. + /* XTAL 36 MHz input */
  3640. + LTQ_GPHY_CLK_36MHZ_XTAL = 1,
  3641. + /* 25 MHz from PLL0 with divider */
  3642. + LTQ_GPHY_CLK_25MHZ_PLL0 = 2,
  3643. + /* derived from PLL2 output (XTAL is 36 MHz) */
  3644. + LTQ_GPHY_CLK_24MHZ_PLL2 = 3,
  3645. + /* 25 MHz Clock from Pin GPIO3 */
  3646. + LTQ_GPHY_CLK_25MHZ_GPIO3 = 4,
  3647. +};
  3648. +
  3649. +/*
  3650. + * Load PHY11G firmware for VRX200 v1.1 to given RAM address
  3651. + *
  3652. + * Address must be 16k aligned!
  3653. + */
  3654. +extern void ltq_gphy_phy11g_a1x_load(ulong addr);
  3655. +
  3656. +/*
  3657. + * Load PHY11G firmware for VRX200 v1.2 to given RAM address
  3658. + *
  3659. + * Address must be 16k aligned!
  3660. + */
  3661. +extern void ltq_gphy_phy11g_a2x_load(ulong addr);
  3662. +
  3663. +/*
  3664. + * Load PHY22F firmware for VRX200 v1.1 to given RAM address
  3665. + *
  3666. + * Address must be 16k aligned!
  3667. + */
  3668. +extern void ltq_gphy_phy22f_a1x_load(ulong addr);
  3669. +
  3670. +/*
  3671. + * Load PHY22F firmware for VRX200 v1.2 to given RAM address
  3672. + *
  3673. + * Address must be 16k aligned!
  3674. + */
  3675. +extern void ltq_gphy_phy22f_a2x_load(ulong addr);
  3676. +
  3677. +/*
  3678. + * Set clock source of internal GPHYs
  3679. + *
  3680. + * According registers resides in CGU address space. Thus this function
  3681. + * is implemented by the CGU driver.
  3682. + */
  3683. +extern void ltq_cgu_gphy_clk_src(enum ltq_gphy_clk clk);
  3684. +
  3685. +/*
  3686. + * Boot internal GPHY with id from given RAM address
  3687. + *
  3688. + * According registers resides in RCU address space. Thus this function
  3689. + * is implemented by the RCU driver.
  3690. + */
  3691. +extern void ltq_rcu_gphy_boot(unsigned int id, ulong addr);
  3692. +
  3693. +#endif /* __VRX200_GPHY_H__ */
  3694. --- /dev/null
  3695. +++ b/arch/mips/include/asm/arch-vrx200/gpio.h
  3696. @@ -0,0 +1,12 @@
  3697. +/*
  3698. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  3699. + *
  3700. + * SPDX-License-Identifier: GPL-2.0+
  3701. + */
  3702. +
  3703. +#ifndef __VRX200_GPIO_H__
  3704. +#define __VRX200_GPIO_H__
  3705. +
  3706. +#include <asm/lantiq/gpio.h>
  3707. +
  3708. +#endif /* __VRX200_GPIO_H__ */
  3709. --- /dev/null
  3710. +++ b/arch/mips/include/asm/arch-vrx200/nand.h
  3711. @@ -0,0 +1,13 @@
  3712. +/*
  3713. + * Copyright (C) 2012-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  3714. + *
  3715. + * SPDX-License-Identifier: GPL-2.0+
  3716. + */
  3717. +
  3718. +#ifndef __VRX200_NAND_H__
  3719. +#define __VRX200_NAND_H__
  3720. +
  3721. +struct nand_chip;
  3722. +int ltq_nand_init(struct nand_chip *nand);
  3723. +
  3724. +#endif /* __VRX200_NAND_H__ */
  3725. --- /dev/null
  3726. +++ b/arch/mips/include/asm/arch-vrx200/soc.h
  3727. @@ -0,0 +1,45 @@
  3728. +/*
  3729. + * Copyright (C) 2010 Lantiq Deutschland GmbH
  3730. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  3731. + *
  3732. + * SPDX-License-Identifier: GPL-2.0+
  3733. + */
  3734. +
  3735. +#ifndef __VRX200_SOC_H__
  3736. +#define __VRX200_SOC_H__
  3737. +
  3738. +#define LTQ_ASC0_BASE 0x1E100400
  3739. +#define LTQ_SPI_BASE 0x1E100800
  3740. +#define LTQ_GPIO_BASE 0x1E100B00
  3741. +#define LTQ_SSIO_BASE 0x1E100BB0
  3742. +#define LTQ_ASC1_BASE 0x1E100C00
  3743. +#define LTQ_DMA_BASE 0x1E104100
  3744. +
  3745. +#define LTQ_EBU_BASE 0x1E105300
  3746. +#define LTQ_EBU_REGION0_BASE 0x10000000
  3747. +#define LTQ_EBU_REGION1_BASE 0x14000000
  3748. +#define LTQ_EBU_NAND_BASE (LTQ_EBU_BASE + 0xB0)
  3749. +
  3750. +#define LTQ_SWITCH_BASE 0x1E108000
  3751. +#define LTQ_SWITCH_CORE_BASE LTQ_SWITCH_BASE
  3752. +#define LTQ_SWITCH_TOP_PDI_BASE LTQ_SWITCH_CORE_BASE
  3753. +#define LTQ_SWITCH_BM_PDI_BASE (LTQ_SWITCH_CORE_BASE + 4 * 0x40)
  3754. +#define LTQ_SWITCH_MAC_PDI_0_BASE (LTQ_SWITCH_CORE_BASE + 4 * 0x900)
  3755. +#define LTQ_SWITCH_MAC_PDI_X_BASE(x) (LTQ_SWITCH_MAC_PDI_0_BASE + x * 0x30)
  3756. +#define LTQ_SWITCH_TOPLEVEL_BASE (LTQ_SWITCH_BASE + 4 * 0xC40)
  3757. +#define LTQ_SWITCH_MDIO_PDI_BASE (LTQ_SWITCH_TOPLEVEL_BASE)
  3758. +#define LTQ_SWITCH_MII_PDI_BASE (LTQ_SWITCH_TOPLEVEL_BASE + 4 * 0x36)
  3759. +#define LTQ_SWITCH_PMAC_PDI_BASE (LTQ_SWITCH_TOPLEVEL_BASE + 4 * 0x82)
  3760. +
  3761. +#define LTQ_PMU_BASE 0x1F102000
  3762. +#define LTQ_CGU_BASE 0x1F103000
  3763. +#define LTQ_DCDC_BASE 0x1F106A00
  3764. +#define LTQ_MPS_BASE 0x1F107000
  3765. +#define LTQ_CHIPID_BASE (LTQ_MPS_BASE + 0x340)
  3766. +#define LTQ_RCU_BASE 0x1F203000
  3767. +
  3768. +#define LTQ_MC_GLOBAL_BASE 0x1F400000
  3769. +#define LTQ_MC_DDR_BASE 0x1F401000
  3770. +#define LTQ_MC_DDR_CCR_OFFSET(x) (x * 0x10)
  3771. +
  3772. +#endif /* __VRX200_SOC_H__ */
  3773. --- /dev/null
  3774. +++ b/arch/mips/include/asm/arch-vrx200/switch.h
  3775. @@ -0,0 +1,502 @@
  3776. +/*
  3777. + * Copyright (C) 2012-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  3778. + *
  3779. + * SPDX-License-Identifier: GPL-2.0+
  3780. + */
  3781. +
  3782. +#ifndef __VRX200_SWITCH_H__
  3783. +#define __VRX200_SWITCH_H__
  3784. +
  3785. +/* Switch core registers */
  3786. +struct vr9_switch_core_regs {
  3787. + __be32 swres;
  3788. + /* TODO: implement registers */
  3789. + __be32 rsvd0[0x3f];
  3790. +};
  3791. +
  3792. +/* Switch buffer management registers */
  3793. +struct vr9_switch_bm_regs {
  3794. + struct bm_core {
  3795. + __be32 ram_val3; /* RAM value 3 */
  3796. + __be32 ram_val2; /* RAM value 2 */
  3797. + __be32 ram_val1; /* RAM value 1 */
  3798. + __be32 ram_val0; /* RAM value 0 */
  3799. + __be32 ram_addr; /* RAM address */
  3800. + __be32 ram_ctrl; /* RAM access control */
  3801. + __be32 fsqm_gctrl; /* Free segment queue global control */
  3802. + __be32 cons_sel; /* Number of consumed segments */
  3803. + __be32 cons_pkt; /* Number of consumed packet pointers */
  3804. + __be32 gctrl; /* Global control */
  3805. + __be32 queue_gctrl; /* Queue manager global control */
  3806. + /* TODO: implement registers */
  3807. + __be32 rsvd0[0x35];
  3808. + } core;
  3809. +
  3810. + struct bm_port {
  3811. + __be32 pcfg; /* Port config */
  3812. + __be32 rmon_ctrl; /* RMON control */
  3813. + } port[13];
  3814. +
  3815. + __be32 rsvd0[0x66];
  3816. +
  3817. + struct bm_queue {
  3818. + __be32 rsvd0;
  3819. + __be32 pqm_rs; /* Packet queue manager rate shape assignment */
  3820. + } queue[32];
  3821. +
  3822. + struct bm_shaper {
  3823. + __be32 ctrl; /* Rate shaper control */
  3824. + __be32 cbs; /* Rate shaper committed burst size */
  3825. + __be32 ibs; /* Rate shaper instantaneous burst size */
  3826. + __be32 cir_ext; /* Rate shaper rate exponent */
  3827. + __be32 cir_mant; /* Rate shaper rate mantissa */
  3828. + } shaper[16];
  3829. +
  3830. + __be32 rsvd1[0x2a8];
  3831. +};
  3832. +
  3833. +/* Switch parser and classification engine registers */
  3834. +struct vr9_switch_pce_regs {
  3835. + struct pce_core {
  3836. + __be32 tbl_key[16]; /* Table key data */
  3837. + __be32 tbl_mask; /* Table mask */
  3838. + __be32 tbl_val[5]; /* Table value */
  3839. + __be32 tbl_addr; /* Table entry address */
  3840. + __be32 tbl_ctrl; /* Table access control */
  3841. + __be32 tbl_stat; /* Table general status */
  3842. + __be32 age_0; /* Aging counter config 0 */
  3843. + __be32 age_1; /* Aging counter config 1 */
  3844. + __be32 pmap_1; /* Port map (monitoring) */
  3845. + __be32 pmap_2; /* Port map (multicast) */
  3846. + __be32 pmap_3; /* Port map (unknown unicast) */
  3847. + __be32 gctrl_0; /* Global control 0 */
  3848. + __be32 gctrl_1; /* Global control 1 */
  3849. + __be32 tcm_gctrl; /* Three-color marker global control */
  3850. + __be32 igmp_ctrl; /* IGMP control */
  3851. + __be32 igmp_drpm; /* IGMP default router port map */
  3852. + __be32 igmp_age_0; /* IGMP aging 0 */
  3853. + __be32 igmp_age_1; /* IGMP aging 1 */
  3854. + __be32 igmp_stat; /* IGMP status */
  3855. + __be32 wol_gctrl; /* Wake-on-LAN control */
  3856. + __be32 wol_da_0; /* Wake-on-LAN destination address 0 */
  3857. + __be32 wol_da_1; /* Wake-on-LAN destination address 1 */
  3858. + __be32 wol_da_2; /* Wake-on-LAN destination address 2 */
  3859. + __be32 wol_pw_0; /* Wake-on-LAN password 0 */
  3860. + __be32 wol_pw_1; /* Wake-on-LAN password 1 */
  3861. + __be32 wol_pw_2; /* Wake-on-LAN password 2 */
  3862. + __be32 ier_0; /* PCE global interrupt enable 0 */
  3863. + __be32 ier_1; /* PCE global interrupt enable 1 */
  3864. + __be32 isr_0; /* PCE global interrupt status 0 */
  3865. + __be32 isr_1; /* PCE global interrupt status 1 */
  3866. + __be32 parser_stat; /* Parser status */
  3867. + __be32 rsvd0[0x6];
  3868. + } core;
  3869. +
  3870. + __be32 rsvd0[0x10];
  3871. +
  3872. + struct pce_port {
  3873. + __be32 pctrl_0; /* Port control 0 */
  3874. + __be32 pctrl_1; /* Port control 1 */
  3875. + __be32 pctrl_2; /* Port control 2 */
  3876. + __be32 pctrl_3; /* Port control 3 */
  3877. + __be32 wol_ctrl; /* Wake-on-LAN control */
  3878. + __be32 vlan_ctrl; /* VLAN control */
  3879. + __be32 def_pvid; /* Default port VID */
  3880. + __be32 pstat; /* Port status */
  3881. + __be32 pier; /* Interrupt enable */
  3882. + __be32 pisr; /* Interrupt status */
  3883. + } port[13];
  3884. +
  3885. + __be32 rsvd1[0x7e];
  3886. +
  3887. + struct pce_meter {
  3888. + /* TODO: implement registers */
  3889. + __be32 rsvd0[0x7];
  3890. + } meter[8];
  3891. +
  3892. + __be32 rsvd2[0x308];
  3893. +};
  3894. +
  3895. +static inline unsigned int to_pce_tbl_key_id(unsigned int id)
  3896. +{
  3897. + BUG_ON(id > 15);
  3898. +
  3899. + return 15 - id;
  3900. +}
  3901. +
  3902. +static inline unsigned int to_pce_tbl_value_id(unsigned int id)
  3903. +{
  3904. + BUG_ON(id > 4);
  3905. +
  3906. + return 4 - id;
  3907. +}
  3908. +
  3909. +/* Switch ethernet MAC registers */
  3910. +struct vr9_switch_mac_regs {
  3911. + struct mac_core {
  3912. + __be32 test; /* MAC test */
  3913. + __be32 pfad_cfg; /* Pause frame source address config */
  3914. + __be32 pfsa_0; /* Pause frame source address 0 */
  3915. + __be32 pfsa_1; /* Pause frame source address 1 */
  3916. + __be32 pfsa_2; /* Pause frame source address 2 */
  3917. + __be32 flen; /* Frame length */
  3918. + __be32 vlan_etype_0; /* VLAN ethertype 0 */
  3919. + __be32 vlan_etype_1; /* VLAN ethertype 1 */
  3920. + __be32 ier; /* Interrupt enable */
  3921. + __be32 isr; /* Interrupt status */
  3922. + __be32 rsvd0[0x36];
  3923. + } core;
  3924. +
  3925. + struct mac_port {
  3926. + __be32 pstat; /* Port status */
  3927. + __be32 pisr; /* Interrupt status */
  3928. + __be32 pier; /* Interrupt enable */
  3929. + __be32 ctrl_0; /* Control 0 */
  3930. + __be32 ctrl_1; /* Control 1 */
  3931. + __be32 ctrl_2; /* Control 2 */
  3932. + __be32 ctrl_3; /* Control 3 */
  3933. + __be32 ctrl_4; /* Control 4 */
  3934. + __be32 ctrl_5; /* Control 5 */
  3935. + __be32 rsvd0[0x2];
  3936. + __be32 testen; /* Test enable */
  3937. + } port[13];
  3938. +
  3939. + __be32 rsvd0[0xa4];
  3940. +};
  3941. +
  3942. +/* Switch Fetch DMA registers */
  3943. +struct vr9_switch_fdma_regs {
  3944. + struct fdma_core {
  3945. + __be32 ctrl; /* FDMA control */
  3946. + __be32 stetype; /* Special tag ethertype control */
  3947. + __be32 vtetype; /* VLAN tag ethertype control */
  3948. + __be32 stat; /* FDMA status */
  3949. + __be32 ier; /* FDMA interrupt enable */
  3950. + __be32 isr; /* FDMA interrupt status */
  3951. + } core;
  3952. +
  3953. + __be32 rsvd0[0x3a];
  3954. +
  3955. + struct fdma_port {
  3956. + __be32 pctrl; /* Port control */
  3957. + __be32 prio; /* Port priority */
  3958. + __be32 pstat_0; /* Port status 0 */
  3959. + __be32 pstat_1; /* Port status 1 */
  3960. + __be32 tstamp_0; /* Egress time stamp 0 */
  3961. + __be32 tstamp_1; /* Egress time stamp 1 */
  3962. + } port[13];
  3963. +
  3964. + __be32 rsvd1[0x72];
  3965. +};
  3966. +
  3967. +/* Switch Store DMA registers */
  3968. +struct vr9_switch_sdma_regs {
  3969. + struct sdma_core {
  3970. + __be32 ctrl; /* SDMA Control */
  3971. + __be32 fcthr_1; /* Flow control threshold 1 */
  3972. + __be32 rsvd0;
  3973. + __be32 fcthr_3; /* Flow control threshold 3 */
  3974. + __be32 fcthr_4; /* Flow control threshold 4 */
  3975. + __be32 fcthr_5; /* Flow control threshold 5 */
  3976. + __be32 fcthr_6; /* Flow control threshold 6 */
  3977. + __be32 fcthr_7; /* Flow control threshold 7 */
  3978. + __be32 stat_0; /* SDMA status 0 */
  3979. + __be32 stat_1; /* SDMA status 1 */
  3980. + __be32 stat_2; /* SDMA status 2 */
  3981. + __be32 ier; /* SDMA interrupt enable */
  3982. + __be32 isr; /* SDMA interrupt status */
  3983. + } core;
  3984. +
  3985. + __be32 rsvd0[0x73];
  3986. +
  3987. + struct sdma_port {
  3988. + __be32 pctrl; /* Port control */
  3989. + __be32 prio; /* Port priority */
  3990. + __be32 pstat_0; /* Port status 0 */
  3991. + __be32 pstat_1; /* Port status 1 */
  3992. + __be32 tstamp_0; /* Ingress time stamp 0 */
  3993. + __be32 tstamp_1; /* Ingress time stamp 1 */
  3994. + } port[13];
  3995. +
  3996. + __be32 rsvd1[0x32];
  3997. +};
  3998. +
  3999. +/* Switch MDIO control and status registers */
  4000. +struct vr9_switch_mdio_regs {
  4001. + __be32 glob_ctrl; /* Global control 0 */
  4002. + __be32 rsvd0[7];
  4003. + __be32 mdio_ctrl; /* MDIO control */
  4004. + __be32 mdio_read; /* MDIO read data */
  4005. + __be32 mdio_write; /* MDIO write data */
  4006. + __be32 mdc_cfg_0; /* MDC clock configuration 0 */
  4007. + __be32 mdc_cfg_1; /* MDC clock configuration 1 */
  4008. + __be32 rsvd1[0x3];
  4009. + __be32 phy_addr[6]; /* PHY address port 5..0 */
  4010. + __be32 mdio_stat[6]; /* MDIO PHY polling status port 0..5 */
  4011. + __be32 aneg_eee[6]; /* EEE auto-neg overrides port 0..5 */
  4012. + __be32 rsvd2[0x14];
  4013. +};
  4014. +
  4015. +static inline unsigned int to_mdio_phyaddr_id(unsigned int id)
  4016. +{
  4017. + BUG_ON(id > 5);
  4018. +
  4019. + return 5 - id;
  4020. +}
  4021. +
  4022. +/* Switch xMII control registers */
  4023. +struct vr9_switch_mii_regs {
  4024. + __be32 mii_cfg0; /* xMII port 0 configuration */
  4025. + __be32 pcdu0; /* Port 0 clock delay configuration */
  4026. + __be32 mii_cfg1; /* xMII port 1 configuration */
  4027. + __be32 pcdu1; /* Port 1 clock delay configuration */
  4028. + __be32 rsvd0[0x6];
  4029. + __be32 mii_cfg5; /* xMII port 5 configuration */
  4030. + __be32 pcdu5; /* Port 5 clock delay configuration */
  4031. + __be32 rsvd1[0x14];
  4032. + __be32 rxb_ctl_0; /* Port 0 receive buffer control */
  4033. + __be32 rxb_ctl_1; /* Port 1 receive buffer control */
  4034. + __be32 rxb_ctl_5; /* Port 5 receive buffer control */
  4035. + __be32 rsvd2[0x28];
  4036. + __be32 dbg_ctl; /* Debug control */
  4037. +};
  4038. +
  4039. +/* Switch Pseudo-MAC registers */
  4040. +struct vr9_switch_pmac_regs {
  4041. + __be32 hd_ctl; /* PMAC header control */
  4042. + __be32 tl; /* PMAC type/length */
  4043. + __be32 sa1; /* PMAC source address 1 */
  4044. + __be32 sa2; /* PMAC source address 2 */
  4045. + __be32 sa3; /* PMAC source address 3 */
  4046. + __be32 da1; /* PMAC destination address 1 */
  4047. + __be32 da2; /* PMAC destination address 2 */
  4048. + __be32 da3; /* PMAC destination address 3 */
  4049. + __be32 vlan; /* PMAC VLAN */
  4050. + __be32 rx_ipg; /* PMAC interpacket gap in RX direction */
  4051. + __be32 st_etype; /* PMAC special tag ethertype */
  4052. + __be32 ewan; /* PMAC ethernet WAN group */
  4053. + __be32 ctl; /* PMAC control */
  4054. + __be32 rsvd0[0x2];
  4055. +};
  4056. +
  4057. +struct vr9_switch_regs {
  4058. + struct vr9_switch_core_regs core;
  4059. + struct vr9_switch_bm_regs bm;
  4060. + struct vr9_switch_pce_regs pce;
  4061. + struct vr9_switch_mac_regs mac;
  4062. + struct vr9_switch_fdma_regs fdma;
  4063. + struct vr9_switch_sdma_regs sdma;
  4064. + struct vr9_switch_mdio_regs mdio;
  4065. + struct vr9_switch_mii_regs mii;
  4066. + struct vr9_switch_pmac_regs pmac;
  4067. +};
  4068. +
  4069. +static inline void *to_pce_tbl_key(struct vr9_switch_regs *regs,
  4070. + unsigned int id)
  4071. +{
  4072. + return &regs->pce.core.tbl_key[to_pce_tbl_key_id(id)];
  4073. +}
  4074. +
  4075. +static inline void *to_pce_tbl_value(struct vr9_switch_regs *regs,
  4076. + unsigned int id)
  4077. +{
  4078. + return &regs->pce.core.tbl_val[to_pce_tbl_value_id(id)];
  4079. +}
  4080. +
  4081. +static inline void *to_mac_ctrl(struct vr9_switch_regs *regs,
  4082. + unsigned int id, unsigned int ctrl)
  4083. +{
  4084. + struct mac_port *mac = &regs->mac.port[id];
  4085. +
  4086. + switch (ctrl) {
  4087. + case 0:
  4088. + return &mac->ctrl_0;
  4089. + case 1:
  4090. + return &mac->ctrl_1;
  4091. + case 2:
  4092. + return &mac->ctrl_2;
  4093. + case 3:
  4094. + return &mac->ctrl_3;
  4095. + case 4:
  4096. + return &mac->ctrl_4;
  4097. + case 5:
  4098. + return &mac->ctrl_5;
  4099. + default:
  4100. + return NULL;
  4101. + }
  4102. +}
  4103. +
  4104. +static inline void *to_mdio_phyaddr(struct vr9_switch_regs *regs,
  4105. + unsigned int id)
  4106. +{
  4107. + return &regs->mdio.phy_addr[to_mdio_phyaddr_id(id)];
  4108. +}
  4109. +
  4110. +static inline void *to_mii_miicfg(struct vr9_switch_regs *regs,
  4111. + unsigned int id)
  4112. +{
  4113. + switch (id) {
  4114. + case 0:
  4115. + return &regs->mii.mii_cfg0;
  4116. + case 1:
  4117. + return &regs->mii.mii_cfg1;
  4118. + case 5:
  4119. + return &regs->mii.mii_cfg5;
  4120. + default:
  4121. + return NULL;
  4122. + }
  4123. +}
  4124. +
  4125. +static inline void *to_mii_pcdu(struct vr9_switch_regs *regs,
  4126. + unsigned int id)
  4127. +{
  4128. + switch (id) {
  4129. + case 0:
  4130. + return &regs->mii.pcdu0;
  4131. + case 1:
  4132. + return &regs->mii.pcdu1;
  4133. + case 5:
  4134. + return &regs->mii.pcdu5;
  4135. + default:
  4136. + return NULL;
  4137. + }
  4138. +}
  4139. +
  4140. +#define VR9_SWITCH_REG_OFFSET(reg) (4 * (reg))
  4141. +
  4142. +#define BUILD_CHECK_VR9_REG(name, offset) \
  4143. + BUILD_BUG_ON(offsetof(struct vr9_switch_regs, name) != (4 * offset))
  4144. +
  4145. +static inline void build_check_vr9_registers(void)
  4146. +{
  4147. + BUILD_CHECK_VR9_REG(core, 0x0);
  4148. + BUILD_CHECK_VR9_REG(bm.core, 0x40);
  4149. + BUILD_CHECK_VR9_REG(bm.core.queue_gctrl, 0x4a);
  4150. + BUILD_CHECK_VR9_REG(bm.port[0], 0x80);
  4151. + BUILD_CHECK_VR9_REG(bm.queue, 0x100);
  4152. + BUILD_CHECK_VR9_REG(bm.shaper, 0x140);
  4153. + BUILD_CHECK_VR9_REG(pce.core, 0x438);
  4154. + BUILD_CHECK_VR9_REG(pce.core.tbl_ctrl, 0x44f);
  4155. + BUILD_CHECK_VR9_REG(pce.core.parser_stat, 0x469);
  4156. + BUILD_CHECK_VR9_REG(pce.port[0], 0x480);
  4157. + BUILD_CHECK_VR9_REG(pce.meter[0], 0x580);
  4158. + BUILD_CHECK_VR9_REG(mac.core, 0x8c0);
  4159. + BUILD_CHECK_VR9_REG(mac.port[0].pstat, 0x900);
  4160. + BUILD_CHECK_VR9_REG(mac.port[0].ctrl_0, 0x903);
  4161. + BUILD_CHECK_VR9_REG(mac.port[1].pstat, 0x90c);
  4162. + BUILD_CHECK_VR9_REG(mac.port[1].ctrl_0, 0x90f);
  4163. + BUILD_CHECK_VR9_REG(mac.port[2].pstat, 0x918);
  4164. + BUILD_CHECK_VR9_REG(mac.port[2].ctrl_0, 0x91b);
  4165. + BUILD_CHECK_VR9_REG(fdma.core, 0xa40);
  4166. + BUILD_CHECK_VR9_REG(fdma.port[0], 0xa80);
  4167. + BUILD_CHECK_VR9_REG(sdma.core, 0xb40);
  4168. + BUILD_CHECK_VR9_REG(sdma.port[0], 0xbc0);
  4169. + BUILD_CHECK_VR9_REG(mdio, 0xc40);
  4170. + BUILD_CHECK_VR9_REG(mii, (0xc40 + 0x36));
  4171. + BUILD_CHECK_VR9_REG(pmac, (0xc40 + 0x82));
  4172. +}
  4173. +
  4174. +#define BM_GCTRL_F_SRES 1
  4175. +
  4176. +#define MAC_CTRL0_BM (1 << 12)
  4177. +#define MAC_CTRL0_APADEN (1 << 11)
  4178. +#define MAC_CTRL0_VPAD2EN (1 << 10)
  4179. +#define MAC_CTRL0_VPADEN (1 << 9)
  4180. +#define MAC_CTRL0_PADEN (1 << 8)
  4181. +#define MAC_CTRL0_FCS (1 << 7)
  4182. +#define MAC_CTRL0_FCON_SHIFT 4
  4183. +#define MAC_CTRL0_FCON_AUTO (0x0 << MAC_CTRL0_FCON_SHIFT)
  4184. +#define MAC_CTRL0_FCON_RX (0x1 << MAC_CTRL0_FCON_SHIFT)
  4185. +#define MAC_CTRL0_FCON_TX (0x2 << MAC_CTRL0_FCON_SHIFT)
  4186. +#define MAC_CTRL0_FCON_RXTX (0x3 << MAC_CTRL0_FCON_SHIFT)
  4187. +#define MAC_CTRL0_FCON_NONE (0x4 << MAC_CTRL0_FCON_SHIFT)
  4188. +#define MAC_CTRL0_FDUP_SHIFT 2
  4189. +#define MAC_CTRL0_FDUP_AUTO (0x0 << MAC_CTRL0_FDUP_SHIFT)
  4190. +#define MAC_CTRL0_FDUP_EN (0x1 << MAC_CTRL0_FDUP_SHIFT)
  4191. +#define MAC_CTRL0_FDUP_DIS (0x3 << MAC_CTRL0_FDUP_SHIFT)
  4192. +#define MAC_CTRL0_GMII_AUTO 0x0
  4193. +#define MAC_CTRL0_GMII_MII 0x1
  4194. +#define MAC_CTRL0_GMII_GMII 0x2
  4195. +#define MAC_CTRL0_GMII_GMII_2G 0x3
  4196. +
  4197. +#define MAC_CTRL1_DEFERMODE (1 << 15)
  4198. +#define MAC_CTRL1_SHORTPRE (1 << 8)
  4199. +
  4200. +#define MAC_CTRL2_MLEN (1 << 3)
  4201. +#define MAC_CTRL2_LCHKL (1 << 2)
  4202. +#define MAC_CTRL2_LCHKS_DIS 0x0
  4203. +#define MAC_CTRL2_LCHKS_UNTAG 0x1
  4204. +#define MAC_CTRL2_LCHKS_TAG 0x2
  4205. +
  4206. +#define PHY_ADDR_LNKST_SHIFT 13
  4207. +#define PHY_ADDR_LNKST_AUTO (0x0 << PHY_ADDR_LNKST_SHIFT)
  4208. +#define PHY_ADDR_LNKST_UP (0x1 << PHY_ADDR_LNKST_SHIFT)
  4209. +#define PHY_ADDR_LNKST_DOWN (0x2 << PHY_ADDR_LNKST_SHIFT)
  4210. +#define PHY_ADDR_SPEED_SHIFT 11
  4211. +#define PHY_ADDR_SPEED_M10 (0x0 << PHY_ADDR_SPEED_SHIFT)
  4212. +#define PHY_ADDR_SPEED_M100 (0x1 << PHY_ADDR_SPEED_SHIFT)
  4213. +#define PHY_ADDR_SPEED_G1 (0x2 << PHY_ADDR_SPEED_SHIFT)
  4214. +#define PHY_ADDR_SPEED_AUTO (0x3 << PHY_ADDR_SPEED_SHIFT)
  4215. +#define PHY_ADDR_FDUP_SHIFT 9
  4216. +#define PHY_ADDR_FDUP_AUTO (0x0 << PHY_ADDR_FDUP_SHIFT)
  4217. +#define PHY_ADDR_FDUP_EN (0x1 << PHY_ADDR_FDUP_SHIFT)
  4218. +#define PHY_ADDR_FDUP_DIS (0x3 << PHY_ADDR_FDUP_SHIFT)
  4219. +#define PHY_ADDR_FCONTX_SHIFT 7
  4220. +#define PHY_ADDR_FCONTX_AUTO (0x0 << PHY_ADDR_FCONTX_SHIFT)
  4221. +#define PHY_ADDR_FCONTX_EN (0x1 << PHY_ADDR_FCONTX_SHIFT)
  4222. +#define PHY_ADDR_FCONTX_DIS (0x3 << PHY_ADDR_FCONTX_SHIFT)
  4223. +#define PHY_ADDR_FCONRX_SHIFT 5
  4224. +#define PHY_ADDR_FCONRX_AUTO (0x0 << PHY_ADDR_FCONRX_SHIFT)
  4225. +#define PHY_ADDR_FCONRX_EN (0x1 << PHY_ADDR_FCONRX_SHIFT)
  4226. +#define PHY_ADDR_FCONRX_DIS (0x3 << PHY_ADDR_FCONRX_SHIFT)
  4227. +
  4228. +#define MII_CFG_RES (1 << 15)
  4229. +#define MII_CFG_EN (1 << 14)
  4230. +#define MII_CFG_LDCLKDIS (1 << 12)
  4231. +#define MII_CFG_MIIRATE_SHIFT 4
  4232. +#define MII_CFG_MIIRATE_MASK (0x7 << MII_CFG_MIIRATE_SHIFT)
  4233. +#define MII_CFG_MIIRATE_M2P5 (0x0 << MII_CFG_MIIRATE_SHIFT)
  4234. +#define MII_CFG_MIIRATE_M25 (0x1 << MII_CFG_MIIRATE_SHIFT)
  4235. +#define MII_CFG_MIIRATE_M125 (0x2 << MII_CFG_MIIRATE_SHIFT)
  4236. +#define MII_CFG_MIIRATE_M50 (0x3 << MII_CFG_MIIRATE_SHIFT)
  4237. +#define MII_CFG_MIIRATE_AUTO (0x4 << MII_CFG_MIIRATE_SHIFT)
  4238. +#define MII_CFG_MIIMODE_MASK 0xf
  4239. +#define MII_CFG_MIIMODE_MIIP 0x0
  4240. +#define MII_CFG_MIIMODE_MIIM 0x1
  4241. +#define MII_CFG_MIIMODE_RMIIP 0x2
  4242. +#define MII_CFG_MIIMODE_RMIIM 0x3
  4243. +#define MII_CFG_MIIMODE_RGMII 0x4
  4244. +
  4245. +#define PCDU_RXDLY_SHIFT 7
  4246. +#define PCDU_RXDLY_MASK (0x7 << PCDU_RXDLY_SHIFT)
  4247. +#define PCDU_TXDLY_MASK 0x7
  4248. +
  4249. +#define PMAC_HD_CTL_FC (1 << 10)
  4250. +#define PMAC_HD_CTL_CCRC (1 << 9)
  4251. +#define PMAC_HD_CTL_RST (1 << 8)
  4252. +#define PMAC_HD_CTL_AST (1 << 7)
  4253. +#define PMAC_HD_CTL_RXSH (1 << 6)
  4254. +#define PMAC_HD_CTL_RC (1 << 4)
  4255. +#define PMAC_HD_CTL_AS (1 << 3)
  4256. +#define PMAC_HD_CTL_AC (1 << 2)
  4257. +
  4258. +#define PCE_PCTRL_0_IGSTEN (1 << 11)
  4259. +
  4260. +#define FDMA_PCTRL_STEN (1 << 1)
  4261. +#define FDMA_PCTRL_EN (1 << 0)
  4262. +
  4263. +#define SDMA_PCTRL_EN (1 << 0)
  4264. +
  4265. +#define MDIO_GLOB_CTRL_SE (1 << 15)
  4266. +
  4267. +#define MDIO_MDC_CFG1_RES (1 << 15)
  4268. +#define MDIO_MDC_CFG1_MCEN (1 << 8)
  4269. +
  4270. +#define MDIO_CTRL_MBUSY (1 << 12)
  4271. +#define MDIO_CTRL_OP_READ (1 << 11)
  4272. +#define MDIO_CTRL_OP_WRITE (1 << 10)
  4273. +#define MDIO_CTRL_PHYAD_SHIFT 5
  4274. +#define MDIO_CTRL_PHYAD_MASK (0x1f << MDIO_CTRL_PHYAD_SHIFT)
  4275. +#define MDIO_CTRL_REGAD_MASK 0x1f
  4276. +
  4277. +#endif /* __VRX200_SWITCH_H__ */
  4278. --- a/arch/mips/include/asm/asm.h
  4279. +++ b/arch/mips/include/asm/asm.h
  4280. @@ -53,6 +53,7 @@
  4281. .align 2; \
  4282. .type symbol, @function; \
  4283. .ent symbol, 0; \
  4284. + .section .text.symbol,"x"; \
  4285. symbol: .frame sp, 0, ra
  4286. /*
  4287. @@ -62,7 +63,8 @@ symbol: .frame sp, 0, ra
  4288. .globl symbol; \
  4289. .align 2; \
  4290. .type symbol, @function; \
  4291. - .ent symbol, 0; \
  4292. + .ent symbol, 0; \
  4293. + .section .text.symbol,"x"; \
  4294. symbol: .frame sp, framesize, rpc
  4295. /*
  4296. --- /dev/null
  4297. +++ b/arch/mips/include/asm/gpio.h
  4298. @@ -0,0 +1,6 @@
  4299. +/*
  4300. + * SPDX-License-Identifier: GPL-2.0+
  4301. + */
  4302. +
  4303. +#include <asm/arch/gpio.h>
  4304. +#include <asm-generic/gpio.h>
  4305. --- /dev/null
  4306. +++ b/arch/mips/include/asm/lantiq/chipid.h
  4307. @@ -0,0 +1,73 @@
  4308. +/*
  4309. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  4310. + *
  4311. + * SPDX-License-Identifier: GPL-2.0+
  4312. + */
  4313. +
  4314. +#ifndef __LANTIQ_CHIPID_H__
  4315. +#define __LANTIQ_CHIPID_H__
  4316. +
  4317. +enum ltq_chip_partnum {
  4318. + LTQ_SOC_UNKNOWN = 0,
  4319. + LTQ_SOC_VRX288_2 = 0x000B, /* VRX288 v1.2 */
  4320. + LTQ_SOC_VRX268_2 = 0x000C, /* VRX268 v1.2 */
  4321. + LTQ_SOC_GRX288_2 = 0x000D, /* GRX288 v1.2 */
  4322. + LTQ_SOC_DANUBE = 0x0129,
  4323. + LTQ_SOC_DANUBE_S = 0x012B,
  4324. + LTQ_SOC_TWINPASS = 0x012D,
  4325. + LTQ_SOC_VRX288 = 0x01C0, /* VRX288 v1.1 */
  4326. + LTQ_SOC_VRX268 = 0x01C2, /* VRX268 v1.1 */
  4327. + LTQ_SOC_GRX288 = 0x01C9, /* GRX288 v1.1 */
  4328. +};
  4329. +
  4330. +extern unsigned int ltq_chip_version_get(void);
  4331. +extern unsigned int ltq_chip_partnum_get(void);
  4332. +extern const char *ltq_chip_partnum_str(void);
  4333. +
  4334. +extern void ltq_chip_print_info(void);
  4335. +
  4336. +#ifdef CONFIG_SOC_XWAY_DANUBE
  4337. +static inline int ltq_soc_is_danube(void)
  4338. +{
  4339. + return 1;
  4340. +}
  4341. +#else
  4342. +static inline int ltq_soc_is_danube(void)
  4343. +{
  4344. + return 0;
  4345. +}
  4346. +#endif
  4347. +
  4348. +#ifdef CONFIG_SOC_XWAY_VRX200
  4349. +static inline int ltq_soc_is_vrx200(void)
  4350. +{
  4351. + return 1;
  4352. +}
  4353. +
  4354. +static inline int ltq_soc_is_vrx200_v1(void)
  4355. +{
  4356. + return ltq_chip_version_get() == 1;
  4357. +}
  4358. +
  4359. +static inline int ltq_soc_is_vrx200_v2(void)
  4360. +{
  4361. + return ltq_chip_version_get() == 2;
  4362. +}
  4363. +#else
  4364. +static inline int ltq_soc_is_vrx200(void)
  4365. +{
  4366. + return 0;
  4367. +}
  4368. +
  4369. +static inline int ltq_soc_is_vrx200_v1(void)
  4370. +{
  4371. + return 0;
  4372. +}
  4373. +
  4374. +static inline int ltq_soc_is_vrx200_v2(void)
  4375. +{
  4376. + return 0;
  4377. +}
  4378. +#endif
  4379. +
  4380. +#endif /* __LANTIQ_CHIPID_H__ */
  4381. --- /dev/null
  4382. +++ b/arch/mips/include/asm/lantiq/clk.h
  4383. @@ -0,0 +1,30 @@
  4384. +/*
  4385. + * Copyright (C) 2007-2010 Lantiq Deutschland GmbH
  4386. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  4387. + * *
  4388. + * SPDX-License-Identifier: GPL-2.0+
  4389. + */
  4390. +
  4391. +#ifndef __LANTIQ_CLK_H__
  4392. +#define __LANTIQ_CLK_H__
  4393. +
  4394. +/* Symbolic clock speeds */
  4395. +enum ltq_clk {
  4396. + CLOCK_83_MHZ = 83333333,
  4397. + CLOCK_111_MHZ = 111111111,
  4398. + CLOCK_125_MHZ = 125000000,
  4399. + CLOCK_133_MHZ = 133333333,
  4400. + CLOCK_166_MHZ = 166666667,
  4401. + CLOCK_197_MHZ = 197000000,
  4402. + CLOCK_333_MHZ = 333333333,
  4403. + CLOCK_393_MHZ = 393219000,
  4404. + CLOCK_500_MHZ = 500000000,
  4405. + CLOCK_600_MHZ = 600000000,
  4406. + CLOCK_1000_MHZ = 1000000000,
  4407. +};
  4408. +
  4409. +extern unsigned long ltq_get_cpu_clock(void);
  4410. +extern unsigned long ltq_get_bus_clock(void);
  4411. +extern unsigned long ltq_get_io_region_clock(void);
  4412. +
  4413. +#endif /* __LANTIQ_CLK_H__ */
  4414. --- /dev/null
  4415. +++ b/arch/mips/include/asm/lantiq/config.h
  4416. @@ -0,0 +1,164 @@
  4417. +/*
  4418. + * Copyright (C) 2007-2010 Lantiq Deutschland GmbH
  4419. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  4420. + *
  4421. + * SPDX-License-Identifier: GPL-2.0+
  4422. + */
  4423. +
  4424. +#ifndef __LANTIQ_CONFIG_H__
  4425. +#define __LANTIQ_CONFIG_H__
  4426. +
  4427. +/* Memory usage */
  4428. +#define CONFIG_SYS_MAXARGS 24
  4429. +#define CONFIG_SYS_MALLOC_LEN 1024*1024
  4430. +#define CONFIG_SYS_BOOTPARAMS_LEN 128*1024
  4431. +
  4432. +/* Command line */
  4433. +#define CONFIG_SYS_PROMPT CONFIG_MACH_TYPE " # "
  4434. +#define CONFIG_SYS_CBSIZE 512
  4435. +#define CONFIG_SYS_PBSIZE (CONFIG_SYS_CBSIZE + \
  4436. + sizeof(CONFIG_SYS_PROMPT)+16)
  4437. +
  4438. +#define CONFIG_SYS_HUSH_PARSER
  4439. +#define CONFIG_SYS_PROMPT_HUSH_PS2 "> "
  4440. +
  4441. +/*
  4442. + * Enable advanced console features on demand to reduce
  4443. + * flash and RAM footprint
  4444. + */
  4445. +#if defined(CONFIG_LTQ_ADVANCED_CONSOLE)
  4446. +#define CONFIG_SYS_LONGHELP
  4447. +#define CONFIG_AUTO_COMPLETE
  4448. +#define CONFIG_CMDLINE_EDITING
  4449. +#endif
  4450. +
  4451. +/* SPI flash SPL */
  4452. +#if defined(CONFIG_LTQ_SUPPORT_SPL_SPI_FLASH) && defined(CONFIG_SYS_BOOT_SFSPL)
  4453. +#define CONFIG_SPL
  4454. +#define CONFIG_SPL_SPI_SUPPORT
  4455. +#define CONFIG_SPL_SPI_FLASH_SUPPORT
  4456. +#define CONFIG_SPI_SPL_SIMPLE
  4457. +#endif
  4458. +
  4459. +#if defined(CONFIG_LTQ_SUPPORT_SPL_NOR_FLASH) && defined(CONFIG_SYS_BOOT_NORSPL)
  4460. +#define CONFIG_SPL
  4461. +#endif
  4462. +
  4463. +/* Common SPL */
  4464. +#if defined(CONFIG_SPL)
  4465. +#define CONFIG_SKIP_LOWLEVEL_INIT
  4466. +#define CONFIG_SPL_LIBGENERIC_SUPPORT
  4467. +#define CONFIG_SPL_GPIO_SUPPORT
  4468. +#define CONFIG_SPL_START_S_PATH \
  4469. + "arch/mips/cpu/mips32/lantiq-common"
  4470. +#define CONFIG_SPL_LDSCRIPT \
  4471. + "arch/mips/cpu/mips32/lantiq-common/u-boot-spl.lds"
  4472. +#endif
  4473. +
  4474. +#if defined(CONFIG_LTQ_SPL_CONSOLE)
  4475. +#define CONFIG_SPL_SERIAL_SUPPORT
  4476. +#define CONFIG_SPL_LIBCOMMON_SUPPORT
  4477. +#endif
  4478. +
  4479. +#if defined(CONFIG_LTQ_SPL_COMP_LZMA)
  4480. +#define CONFIG_LZMA
  4481. +#define CONFIG_SPL_LZMA_SUPPORT
  4482. +#endif
  4483. +
  4484. +#if defined(CONFIG_LTQ_SPL_COMP_LZO)
  4485. +#define CONFIG_LZO
  4486. +#define CONFIG_SPL_LZO_SUPPORT
  4487. +#endif
  4488. +
  4489. +/* Basic commands */
  4490. +#define CONFIG_CMD_BDI
  4491. +#define CONFIG_CMD_EDITENV
  4492. +#define CONFIG_CMD_IMI
  4493. +#define CONFIG_CMD_MEMORY
  4494. +#define CONFIG_CMD_RUN
  4495. +#define CONFIG_CMD_SAVEENV
  4496. +#define CONFIG_CMD_LOADB
  4497. +
  4498. +/* Other U-Boot settings */
  4499. +#define CONFIG_TIMESTAMP
  4500. +
  4501. +/* Default environment */
  4502. +#define CONFIG_ENV_CONSOLEDEV \
  4503. + "consoledev=" CONFIG_CONSOLE_DEV "\0"
  4504. +
  4505. +#define CONFIG_ENV_ADDCONSOLE \
  4506. + "addconsole=setenv bootargs $bootargs" \
  4507. + " console=$consoledev,$baudrate\0"
  4508. +
  4509. +#if defined(CONFIG_NET_DEV)
  4510. +#define CONFIG_ENV_NETDEV \
  4511. + "netdev=" CONFIG_NET_DEV "\0"
  4512. +#else
  4513. +#define CONFIG_ENV_NETDEV \
  4514. + "netdev=eth0\0"
  4515. +#endif
  4516. +
  4517. +#define CONFIG_ENV_ADDIP \
  4518. + "addip=setenv bootargs $bootargs" \
  4519. + " ip=$ipaddr:$serverip::::$netdev:off\0"
  4520. +
  4521. +#define CONFIG_ENV_ADDETH \
  4522. + "addeth=setenv bootargs $bootargs" \
  4523. + " ethaddr=$ethaddr\0"
  4524. +
  4525. +#define CONFIG_ENV_ADDMACHTYPE \
  4526. + "addmachtype=setenv bootargs $bootargs" \
  4527. + " machtype=" CONFIG_MACH_TYPE "\0"
  4528. +
  4529. +#if defined(CONFIG_LTQ_SUPPORT_NOR_FLASH)
  4530. +#define CONFIG_ENV_WRITE_UBOOT_NOR \
  4531. + "write-uboot-nor=" \
  4532. + "protect off " __stringify(CONFIG_SYS_FLASH_BASE) " +$filesize && " \
  4533. + "erase " __stringify(CONFIG_SYS_FLASH_BASE) " +$filesize && " \
  4534. + "cp.b $fileaddr " __stringify(CONFIG_SYS_FLASH_BASE) " $filesize\0"
  4535. +
  4536. +#define CONFIG_ENV_LOAD_UBOOT_NOR \
  4537. + "load-uboot-nor=tftpboot u-boot.bin\0" \
  4538. + "load-uboot-norspl=tftpboot u-boot.ltq.norspl\0" \
  4539. + "load-uboot-norspl-lzo=tftpboot u-boot.ltq.lzo.norspl\0" \
  4540. + "load-uboot-norspl-lzma=tftpboot u-boot.ltq.lzma.norspl\0"
  4541. +#else
  4542. +#define CONFIG_ENV_WRITE_UBOOT_NOR
  4543. +#define CONFIG_ENV_LOAD_UBOOT_NOR
  4544. +#endif
  4545. +
  4546. +#if defined(CONFIG_LTQ_SUPPORT_SPI_FLASH)
  4547. +#define CONFIG_ENV_SF_PROBE \
  4548. + "sf-probe=sf probe " __stringify(CONFIG_ENV_SPI_CS) " " \
  4549. + __stringify(CONFIG_ENV_SPI_MAX_HZ) " " \
  4550. + __stringify(CONFIG_ENV_SPI_MODE) " \0"
  4551. +
  4552. +#define CONFIG_ENV_WRITE_UBOOT_SF \
  4553. + "write-uboot-sf=" \
  4554. + "run sf-probe && sf erase 0 +$filesize && " \
  4555. + "sf write $fileaddr 0 $filesize\0"
  4556. +
  4557. +#define CONFIG_ENV_LOAD_UBOOT_SF \
  4558. + "load-uboot-sfspl=tftpboot u-boot.ltq.sfspl\0" \
  4559. + "load-uboot-sfspl-lzo=tftpboot u-boot.ltq.lzo.sfspl\0" \
  4560. + "load-uboot-sfspl-lzma=tftpboot u-boot.ltq.lzma.sfspl\0"
  4561. +#else
  4562. +#define CONFIG_ENV_SF_PROBE
  4563. +#define CONFIG_ENV_WRITE_UBOOT_SF
  4564. +#define CONFIG_ENV_LOAD_UBOOT_SF
  4565. +#endif
  4566. +
  4567. +#define CONFIG_ENV_LANTIQ_DEFAULTS \
  4568. + CONFIG_ENV_CONSOLEDEV \
  4569. + CONFIG_ENV_ADDCONSOLE \
  4570. + CONFIG_ENV_NETDEV \
  4571. + CONFIG_ENV_ADDIP \
  4572. + CONFIG_ENV_ADDETH \
  4573. + CONFIG_ENV_ADDMACHTYPE \
  4574. + CONFIG_ENV_WRITE_UBOOT_NOR \
  4575. + CONFIG_ENV_LOAD_UBOOT_NOR \
  4576. + CONFIG_ENV_SF_PROBE \
  4577. + CONFIG_ENV_WRITE_UBOOT_SF \
  4578. + CONFIG_ENV_LOAD_UBOOT_SF
  4579. +
  4580. +#endif /* __LANTIQ_CONFIG_H__ */
  4581. --- /dev/null
  4582. +++ b/arch/mips/include/asm/lantiq/cpu.h
  4583. @@ -0,0 +1,34 @@
  4584. +/*
  4585. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  4586. + *
  4587. + * SPDX-License-Identifier: GPL-2.0+
  4588. + */
  4589. +
  4590. +#ifndef __LANTIQ_CPU_H__
  4591. +#define __LANTIQ_CPU_H__
  4592. +
  4593. +enum ltq_boot_select {
  4594. + BOOT_NOR,
  4595. + BOOT_NOR_NO_BOOTROM,
  4596. + BOOT_UART,
  4597. + BOOT_UART_NO_EEPROM,
  4598. + BOOT_SPI,
  4599. + BOOT_NAND,
  4600. + BOOT_PCI,
  4601. + BOOT_MII0,
  4602. + BOOT_RMII0,
  4603. + BOOT_RGMII1,
  4604. + BOOT_UNKNOWN,
  4605. +};
  4606. +
  4607. +enum ltq_boot_select ltq_boot_select(void);
  4608. +const char *ltq_boot_select_str(void);
  4609. +
  4610. +void ltq_pmu_init(void);
  4611. +void ltq_ebu_init(void);
  4612. +void ltq_gpio_init(void);
  4613. +
  4614. +void ltq_pll_init(void);
  4615. +void ltq_dcdc_init(unsigned int dig_ref);
  4616. +
  4617. +#endif /* __LANTIQ_CPU_H__ */
  4618. --- /dev/null
  4619. +++ b/arch/mips/include/asm/lantiq/dma.h
  4620. @@ -0,0 +1,94 @@
  4621. +/*
  4622. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  4623. + *
  4624. + * SPDX-License-Identifier: GPL-2.0+
  4625. + */
  4626. +
  4627. +#ifndef __LANTIQ_DMA_H__
  4628. +#define __LANTIQ_DMA_H__
  4629. +
  4630. +enum ltq_dma_endianess {
  4631. + LTQ_DMA_ENDIANESS_B0_B1_B2_B3, /* No byte swapping */
  4632. + LTQ_DMA_ENDIANESS_B1_B0_B3_B2, /* B0B1B2B3 => B1B0B3B2 */
  4633. + LTQ_DMA_ENDIANESS_B2_B3_B0_B1, /* B0B1B2B3 => B2B3B0B1 */
  4634. + LTQ_DMA_ENDIANESS_B3_B2_B1_B0, /* B0B1B2B3 => B3B2B1B0 */
  4635. +};
  4636. +
  4637. +enum ltq_dma_burst_len {
  4638. + LTQ_DMA_BURST_2WORDS = 1,
  4639. + LTQ_DMA_BURST_4WORDS = 2,
  4640. + LTQ_DMA_BURST_8WORDS = 3,
  4641. +};
  4642. +
  4643. +struct ltq_dma_desc {
  4644. + u32 ctl;
  4645. + u32 addr;
  4646. +};
  4647. +
  4648. +struct ltq_dma_channel {
  4649. + struct ltq_dma_device *dev;
  4650. + u8 chan_no;
  4651. + u8 class;
  4652. + u16 num_desc;
  4653. + struct ltq_dma_desc *desc_base;
  4654. + void *mem_base;
  4655. + u32 dma_addr;
  4656. +};
  4657. +
  4658. +struct ltq_dma_device {
  4659. + enum ltq_dma_endianess rx_endian_swap;
  4660. + enum ltq_dma_endianess tx_endian_swap;
  4661. + enum ltq_dma_burst_len rx_burst_len;
  4662. + enum ltq_dma_burst_len tx_burst_len;
  4663. + struct ltq_dma_channel rx_chan;
  4664. + struct ltq_dma_channel tx_chan;
  4665. + u8 port;
  4666. +};
  4667. +
  4668. +/**
  4669. + * Initialize DMA hardware and driver
  4670. + */
  4671. +void ltq_dma_init(void);
  4672. +
  4673. +/**
  4674. + * Register given DMA client context
  4675. + *
  4676. + * @returns 0 on success, negative value otherwise
  4677. + */
  4678. +int ltq_dma_register(struct ltq_dma_device *dev);
  4679. +
  4680. +/**
  4681. + * Reset and halt all channels related to given DMA client
  4682. + */
  4683. +void ltq_dma_reset(struct ltq_dma_device *dev);
  4684. +void ltq_dma_enable(struct ltq_dma_device *dev);
  4685. +void ltq_dma_disable(struct ltq_dma_device *dev);
  4686. +
  4687. +/**
  4688. + * Map RX DMA descriptor to memory region
  4689. + *
  4690. + * @returns 0 on success, negative value otherwise
  4691. + */
  4692. +int ltq_dma_rx_map(struct ltq_dma_device *dev, int index, void *data, int len);
  4693. +
  4694. +/**
  4695. + * Check if new data is available.
  4696. + *
  4697. + * @returns length of received data, 0 otherwise
  4698. + */
  4699. +int ltq_dma_rx_poll(struct ltq_dma_device *dev, int index);
  4700. +
  4701. +int ltq_dma_rx_length(struct ltq_dma_device *dev, int index);
  4702. +
  4703. +/**
  4704. + * Map TX DMA descriptor to memory region
  4705. + *
  4706. + * @returns 0 on success, negative value otherwise
  4707. + */
  4708. +int ltq_dma_tx_map(struct ltq_dma_device *dev, int index, void *data, int len,
  4709. + unsigned long timeout);
  4710. +
  4711. +int ltq_dma_tx_wait(struct ltq_dma_device *dev, int index,
  4712. + unsigned long timeout);
  4713. +
  4714. +#endif /* __LANTIQ_DMA_H__ */
  4715. --- /dev/null
  4716. +++ b/arch/mips/include/asm/lantiq/eth.h
  4717. @@ -0,0 +1,35 @@
  4718. +/*
  4719. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  4720. + *
  4721. + * SPDX-License-Identifier: GPL-2.0+
  4722. + */
  4723. +
  4724. +#ifndef __LANTIQ_ETH_H__
  4725. +#define __LANTIQ_ETH_H__
  4726. +
  4727. +#include <phy.h>
  4728. +
  4729. +enum LTQ_ETH_PORT_FLAGS {
  4730. + LTQ_ETH_PORT_NONE = 0,
  4731. + LTQ_ETH_PORT_PHY = 1,
  4732. + LTQ_ETH_PORT_SWITCH = (1 << 1),
  4733. + LTQ_ETH_PORT_MAC = (1 << 2),
  4734. +};
  4735. +
  4736. +struct ltq_eth_port_config {
  4737. + u8 num;
  4738. + u8 phy_addr;
  4739. + u16 flags;
  4740. + phy_interface_t phy_if;
  4741. + u8 rgmii_rx_delay;
  4742. + u8 rgmii_tx_delay;
  4743. +};
  4744. +
  4745. +struct ltq_eth_board_config {
  4746. + const struct ltq_eth_port_config *ports;
  4747. + int num_ports;
  4748. +};
  4749. +
  4750. +extern int ltq_eth_initialize(const struct ltq_eth_board_config *board_config);
  4751. +
  4752. +#endif /* __LANTIQ_ETH_H__ */
  4753. --- /dev/null
  4754. +++ b/arch/mips/include/asm/lantiq/gpio.h
  4755. @@ -0,0 +1,50 @@
  4756. +/*
  4757. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  4758. + *
  4759. + * SPDX-License-Identifier: GPL-2.0+
  4760. + */
  4761. +
  4762. +#ifndef __LANTIQ_GPIO_H__
  4763. +#define __LANTIQ_GPIO_H__
  4764. +
  4765. +enum ltq_gpio_dir {
  4766. + GPIO_DIR_IN = 0,
  4767. + GPIO_DIR_OUT
  4768. +};
  4769. +
  4770. +enum ltq_gpio_od {
  4771. + GPIO_OD_ACTIVE = 0,
  4772. + GPIO_OD_NORMAL
  4773. +};
  4774. +
  4775. +enum ltq_gpio_altsel {
  4776. + GPIO_ALTSEL_CLR = 0,
  4777. + GPIO_ALTSEL_SET
  4778. +};
  4779. +
  4780. +extern int gpio_set_altfunc(unsigned gpio, int altsel0, int altsel1, int dir);
  4781. +extern int gpio_set_opendrain(unsigned gpio, int od);
  4782. +
  4783. +static inline int gpio_to_port(unsigned gpio)
  4784. +{
  4785. + return gpio >> 4;
  4786. +}
  4787. +
  4788. +static inline int gpio_to_pin(unsigned gpio)
  4789. +{
  4790. + return gpio & 0xF;
  4791. +}
  4792. +
  4793. +static inline int gpio_to_bit(unsigned gpio)
  4794. +{
  4795. + return 1 << gpio_to_pin(gpio);
  4796. +}
  4797. +
  4798. +static inline int gpio_to_gpio(unsigned port, unsigned pin)
  4799. +{
  4800. + return (port << 4) | (pin & 0xF);
  4801. +}
  4802. +
  4803. +#include <asm-generic/gpio.h>
  4804. +
  4805. +#endif /* __LANTIQ_GPIO_H__ */
  4806. --- /dev/null
  4807. +++ b/arch/mips/include/asm/lantiq/io.h
  4808. @@ -0,0 +1,37 @@
  4809. +/*
  4810. + * Copyright (C) 2010 John Crispin <blogic@openwrt.org>
  4811. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  4812. + *
  4813. + * SPDX-License-Identifier: GPL-2.0+
  4814. + */
  4815. +
  4816. +#ifndef __LANTIQ_IO_H__
  4817. +#define __LANTIQ_IO_H__
  4818. +
  4819. +#include <asm/io.h>
  4820. +
  4821. +#define ltq_readb(a) __raw_readb(a)
  4822. +#define ltq_writeb(a, v) __raw_writeb(v, a)
  4823. +
  4824. +#define ltq_readl(a) __raw_readl(a)
  4825. +#define ltq_writel(a, v) __raw_writel(v, a)
  4826. +
  4827. +#define ltq_clrbits(a, clear) \
  4828. + ltq_writel(a, ltq_readl(a) & ~(clear))
  4829. +
  4830. +#define ltq_setbits(a, set) \
  4831. + ltq_writel(a, ltq_readl(a) | (set))
  4832. +
  4833. +#define ltq_clrsetbits(a, clear, set) \
  4834. + ltq_writel(a, (ltq_readl(a) & ~(clear)) | (set))
  4835. +
  4836. +static inline void ltq_reg_dump(const void *addr, const char *desc)
  4837. +{
  4838. + u32 data;
  4839. +
  4840. + data = ltq_readl(addr);
  4841. + printf("ltq_reg_dump: %s 0x%p = 0x%08x\n",
  4842. + desc, addr, data);
  4843. +}
  4844. +
  4845. +#endif /* __LANTIQ_IO_H__ */
  4846. --- /dev/null
  4847. +++ b/arch/mips/include/asm/lantiq/pm.h
  4848. @@ -0,0 +1,21 @@
  4849. +/*
  4850. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  4851. + *
  4852. + * SPDX-License-Identifier: GPL-2.0+
  4853. + */
  4854. +
  4855. +#ifndef __LANTIQ_PM_H__
  4856. +#define __LANTIQ_PM_H__
  4857. +
  4858. +enum ltq_pm_modules {
  4859. + LTQ_PM_CORE,
  4860. + LTQ_PM_DMA,
  4861. + LTQ_PM_ETH,
  4862. + LTQ_PM_SPI,
  4863. +};
  4864. +
  4865. +u32 ltq_pm_map(enum ltq_pm_modules module);
  4866. +int ltq_pm_enable(enum ltq_pm_modules module);
  4867. +int ltq_pm_disable(enum ltq_pm_modules module);
  4868. +
  4869. +#endif /* __LANTIQ_PM_H__ */
  4870. --- /dev/null
  4871. +++ b/arch/mips/include/asm/lantiq/reset.h
  4872. @@ -0,0 +1,37 @@
  4873. +/*
  4874. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  4875. + *
  4876. + * SPDX-License-Identifier: GPL-2.0+
  4877. + */
  4878. +
  4879. +#ifndef __LANTIQ_RESET_H__
  4880. +#define __LANTIQ_RESET_H__
  4881. +
  4882. +enum ltq_reset_modules {
  4883. + LTQ_RESET_CORE,
  4884. + LTQ_RESET_DMA,
  4885. + LTQ_RESET_ETH,
  4886. + LTQ_RESET_PHY,
  4887. + LTQ_RESET_HARD,
  4888. + LTQ_RESET_SOFT,
  4889. +};
  4890. +
  4891. +extern u32 ltq_reset_map(enum ltq_reset_modules module);
  4892. +extern int ltq_reset_activate(enum ltq_reset_modules module);
  4893. +extern int ltq_reset_deactivate(enum ltq_reset_modules module);
  4894. +
  4895. +static inline int ltq_reset_once(enum ltq_reset_modules module, ulong usec)
  4896. +{
  4897. + int ret;
  4898. +
  4899. + ret = ltq_reset_activate(module);
  4900. + if (ret)
  4901. + return ret;
  4902. +
  4903. + __udelay(usec);
  4904. + ret = ltq_reset_deactivate(module);
  4905. +
  4906. + return ret;
  4907. +}
  4908. +
  4909. +#endif /* __LANTIQ_RESET_H__ */
  4910. --- a/arch/mips/include/asm/mipsregs.h
  4911. +++ b/arch/mips/include/asm/mipsregs.h
  4912. @@ -46,7 +46,10 @@
  4913. #define CP0_ENTRYLO1 $3
  4914. #define CP0_CONF $3
  4915. #define CP0_CONTEXT $4
  4916. +#define CP0_CONTEXTCONFIG $4,1
  4917. +#define CP0_USERLOCAL $4,1
  4918. #define CP0_PAGEMASK $5
  4919. +#define CP0_PAGEGRAIN $5,1
  4920. #define CP0_WIRED $6
  4921. #define CP0_INFO $7
  4922. #define CP0_BADVADDR $8
  4923. @@ -54,10 +57,19 @@
  4924. #define CP0_ENTRYHI $10
  4925. #define CP0_COMPARE $11
  4926. #define CP0_STATUS $12
  4927. +#define CP0_INTCTL $12,1
  4928. +#define CP0_SRSCTL $12,2
  4929. +#define CP0_SRSMAP $12,3
  4930. +#define CP0_SRSHIGH $12,4
  4931. #define CP0_CAUSE $13
  4932. #define CP0_EPC $14
  4933. #define CP0_PRID $15
  4934. +#define CP0_EBASE $15,1
  4935. #define CP0_CONFIG $16
  4936. +#define CP0_CONFIG1 $16,1
  4937. +#define CP0_CONFIG2 $16,2
  4938. +#define CP0_CONFIG3 $16,3
  4939. +#define CP0_CONFIG7 $16,7
  4940. #define CP0_LLADDR $17
  4941. #define CP0_WATCHLO $18
  4942. #define CP0_WATCHHI $19
  4943. @@ -70,7 +82,17 @@
  4944. #define CP0_ECC $26
  4945. #define CP0_CACHEERR $27
  4946. #define CP0_TAGLO $28
  4947. +#define CP0_ITAGLO $28
  4948. +#define CP0_IDATALO $28,1
  4949. +#define CP0_DTAGLO $28,2
  4950. +#define CP0_DDATALO $28,3
  4951. +#define CP0_L23TAGLO $28,4
  4952. +#define CP0_L23DATALO $28,5
  4953. #define CP0_TAGHI $29
  4954. +#define CP0_IDATAHI $29,1
  4955. +#define CP0_DTAGHI $29,2
  4956. +#define CP0_L23TAGHI $29,4
  4957. +#define CP0_L23DATAHI $29,5
  4958. #define CP0_ERROREPC $30
  4959. #define CP0_DESAVE $31
  4960. @@ -395,6 +417,12 @@
  4961. #define CAUSEF_BD (_ULCAST_(1) << 31)
  4962. /*
  4963. + * Bits in the coprocessor 0 EBase register.
  4964. + */
  4965. +#define EBASEB_CPUNUM 0
  4966. +#define EBASEF_CPUNUM (_ULCAST_(1023))
  4967. +
  4968. +/*
  4969. * Bits in the coprocessor 0 config register.
  4970. */
  4971. /* Generic bits. */
  4972. --- a/arch/mips/include/asm/u-boot-mips.h
  4973. +++ b/arch/mips/include/asm/u-boot-mips.h
  4974. @@ -23,3 +23,4 @@ static inline unsigned long image_copy_e
  4975. }
  4976. extern int incaip_set_cpuclk(void);
  4977. +extern int arch_cpu_init(void);
  4978. --- a/arch/mips/lib/board.c
  4979. +++ b/arch/mips/lib/board.c
  4980. @@ -33,6 +33,16 @@ static char *failed = "*** failed ***\n"
  4981. */
  4982. const unsigned long mips_io_port_base = -1;
  4983. +int __arch_cpu_init(void)
  4984. +{
  4985. + /*
  4986. + * Nothing to do in this dummy implementation
  4987. + */
  4988. + return 0;
  4989. +}
  4990. +int arch_cpu_init(void)
  4991. + __attribute__((weak, alias("__arch_cpu_init")));
  4992. +
  4993. int __board_early_init_f(void)
  4994. {
  4995. /*
  4996. @@ -106,6 +116,7 @@ static int init_baudrate(void)
  4997. typedef int (init_fnc_t)(void);
  4998. init_fnc_t *init_sequence[] = {
  4999. + arch_cpu_init,
  5000. board_early_init_f,
  5001. timer_init,
  5002. env_init, /* initialize environment */
  5003. --- /dev/null
  5004. +++ b/board/lantiq/easy50712/Makefile
  5005. @@ -0,0 +1,27 @@
  5006. +#
  5007. +# Copyright (C) 2000-2011 Wolfgang Denk, DENX Software Engineering, wd@denx.de
  5008. +#
  5009. +# SPDX-License-Identifier: GPL-2.0+
  5010. +#
  5011. +
  5012. +include $(TOPDIR)/config.mk
  5013. +
  5014. +LIB = $(obj)lib$(BOARD).o
  5015. +
  5016. +COBJS = $(BOARD).o
  5017. +
  5018. +SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c)
  5019. +OBJS := $(addprefix $(obj),$(COBJS))
  5020. +SOBJS := $(addprefix $(obj),$(SOBJS))
  5021. +
  5022. +$(LIB): $(obj).depend $(OBJS) $(SOBJS)
  5023. + $(call cmd_link_o_target, $(OBJS) $(SOBJS))
  5024. +
  5025. +#########################################################################
  5026. +
  5027. +# defines $(obj).depend target
  5028. +include $(SRCTREE)/rules.mk
  5029. +
  5030. +sinclude $(obj).depend
  5031. +
  5032. +#########################################################################
  5033. --- /dev/null
  5034. +++ b/board/lantiq/easy50712/config.mk
  5035. @@ -0,0 +1,7 @@
  5036. +#
  5037. +# Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  5038. +#
  5039. +# SPDX-License-Identifier: GPL-2.0+
  5040. +#
  5041. +
  5042. +PLATFORM_CPPFLAGS += -I$(TOPDIR)/board/$(BOARDDIR)
  5043. --- /dev/null
  5044. +++ b/board/lantiq/easy50712/ddr_settings.h
  5045. @@ -0,0 +1,54 @@
  5046. +/*
  5047. + * Copyright (C) 2007-2010 Lantiq Deutschland GmbH
  5048. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  5049. + *
  5050. + * SPDX-License-Identifier: GPL-2.0+
  5051. + */
  5052. +
  5053. +#define MC_DC00_VALUE 0x1B1B
  5054. +#define MC_DC01_VALUE 0x0
  5055. +#define MC_DC02_VALUE 0x0
  5056. +#define MC_DC03_VALUE 0x0
  5057. +#define MC_DC04_VALUE 0x0
  5058. +#define MC_DC05_VALUE 0x200
  5059. +#define MC_DC06_VALUE 0x605
  5060. +#define MC_DC07_VALUE 0x303
  5061. +#define MC_DC08_VALUE 0x102
  5062. +#define MC_DC09_VALUE 0x70a
  5063. +#define MC_DC10_VALUE 0x203
  5064. +#define MC_DC11_VALUE 0xc02
  5065. +#define MC_DC12_VALUE 0x1C8
  5066. +#define MC_DC13_VALUE 0x1
  5067. +#define MC_DC14_VALUE 0x0
  5068. +#define MC_DC15_VALUE 0x13c
  5069. +#define MC_DC16_VALUE 0xC800
  5070. +#define MC_DC17_VALUE 0xd
  5071. +#define MC_DC18_VALUE 0x300
  5072. +#define MC_DC19_VALUE 0x200
  5073. +#define MC_DC20_VALUE 0xA04
  5074. +#define MC_DC21_VALUE 0xd00
  5075. +#define MC_DC22_VALUE 0xd0d
  5076. +#define MC_DC23_VALUE 0x0
  5077. +#define MC_DC24_VALUE 0x62
  5078. +#define MC_DC25_VALUE 0x0
  5079. +#define MC_DC26_VALUE 0x0
  5080. +#define MC_DC27_VALUE 0x0
  5081. +#define MC_DC28_VALUE 0x510
  5082. +#define MC_DC29_VALUE 0x2d89
  5083. +#define MC_DC30_VALUE 0x8300
  5084. +#define MC_DC31_VALUE 0x0
  5085. +#define MC_DC32_VALUE 0x0
  5086. +#define MC_DC33_VALUE 0x0
  5087. +#define MC_DC34_VALUE 0x0
  5088. +#define MC_DC35_VALUE 0x0
  5089. +#define MC_DC36_VALUE 0x0
  5090. +#define MC_DC37_VALUE 0x0
  5091. +#define MC_DC38_VALUE 0x0
  5092. +#define MC_DC39_VALUE 0x0
  5093. +#define MC_DC40_VALUE 0x0
  5094. +#define MC_DC41_VALUE 0x0
  5095. +#define MC_DC42_VALUE 0x0
  5096. +#define MC_DC43_VALUE 0x0
  5097. +#define MC_DC44_VALUE 0x0
  5098. +#define MC_DC45_VALUE 0x500
  5099. +#define MC_DC46_VALUE 0x0
  5100. --- /dev/null
  5101. +++ b/board/lantiq/easy50712/easy50712.c
  5102. @@ -0,0 +1,112 @@
  5103. +/*
  5104. + * Copyright (C) 2010 Thomas Langer <thomas.langer@lantiq.com>
  5105. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  5106. + *
  5107. + * SPDX-License-Identifier: GPL-2.0+
  5108. + */
  5109. +
  5110. +#include <common.h>
  5111. +#include <switch.h>
  5112. +#include <spi.h>
  5113. +#include <asm/gpio.h>
  5114. +#include <asm/lantiq/eth.h>
  5115. +#include <asm/lantiq/reset.h>
  5116. +#include <asm/lantiq/chipid.h>
  5117. +
  5118. +static void gpio_init(void)
  5119. +{
  5120. + /* SPI/CS output (low-active) for serial flash */
  5121. + gpio_direction_output(22, 1);
  5122. +
  5123. + /* EBU.FL_CS1 as output for NAND CE */
  5124. + gpio_set_altfunc(23, GPIO_ALTSEL_SET, GPIO_ALTSEL_CLR, GPIO_DIR_OUT);
  5125. + /* EBU.FL_A23 as output for NAND CLE */
  5126. + gpio_set_altfunc(24, GPIO_ALTSEL_SET, GPIO_ALTSEL_CLR, GPIO_DIR_OUT);
  5127. + /* EBU.FL_A24 as output for NAND ALE */
  5128. + gpio_set_altfunc(13, GPIO_ALTSEL_SET, GPIO_ALTSEL_CLR, GPIO_DIR_OUT);
  5129. +
  5130. + /* enable CLK_OUT2 for external switch */
  5131. + gpio_set_altfunc(3, GPIO_ALTSEL_SET, GPIO_ALTSEL_CLR, GPIO_DIR_OUT);
  5132. +}
  5133. +
  5134. +int board_early_init_f(void)
  5135. +{
  5136. + gpio_init();
  5137. +
  5138. + return 0;
  5139. +}
  5140. +
  5141. +int checkboard(void)
  5142. +{
  5143. + puts("Board: " CONFIG_BOARD_NAME "\n");
  5144. + ltq_chip_print_info();
  5145. +
  5146. + return 0;
  5147. +}
  5148. +
  5149. +static const struct ltq_eth_port_config eth_port_config[] = {
  5150. + /* MAC0: Lantiq ADM6996I switch */
  5151. + { 0, 0x0, LTQ_ETH_PORT_SWITCH, PHY_INTERFACE_MODE_RMII },
  5152. +};
  5153. +
  5154. +static const struct ltq_eth_board_config eth_board_config = {
  5155. + .ports = eth_port_config,
  5156. + .num_ports = ARRAY_SIZE(eth_port_config),
  5157. +};
  5158. +
  5159. +int board_eth_init(bd_t *bis)
  5160. +{
  5161. + return ltq_eth_initialize(&eth_board_config);
  5162. +}
  5163. +
  5164. +static struct switch_device adm6996i_dev = {
  5165. + .name = "adm6996i",
  5166. + .cpu_port = 5,
  5167. + .port_mask = 0xF,
  5168. +};
  5169. +
  5170. +int board_switch_init(void)
  5171. +{
  5172. + /* Deactivate HRST line to release reset of ADM6996I switch */
  5173. + ltq_reset_once(LTQ_RESET_HARD, 200000);
  5174. +
  5175. + /* ADM6996I needs some time to come out of reset */
  5176. + __udelay(50000);
  5177. +
  5178. + return switch_device_register(&adm6996i_dev);
  5179. +}
  5180. +
  5181. +int spi_cs_is_valid(unsigned int bus, unsigned int cs)
  5182. +{
  5183. + if (bus)
  5184. + return 0;
  5185. +
  5186. + switch (cs) {
  5187. + case 2:
  5188. + return 1;
  5189. + default:
  5190. + return 0;
  5191. + }
  5192. +}
  5193. +
  5194. +void spi_cs_activate(struct spi_slave *slave)
  5195. +{
  5196. + switch (slave->cs) {
  5197. + case 2:
  5198. + gpio_set_value(22, 0);
  5199. + break;
  5200. + default:
  5201. + break;
  5202. + }
  5203. +}
  5204. +
  5205. +void spi_cs_deactivate(struct spi_slave *slave)
  5206. +{
  5207. + switch (slave->cs) {
  5208. + case 2:
  5209. + gpio_set_value(22, 1);
  5210. + break;
  5211. + default:
  5212. + break;
  5213. + }
  5214. +}
  5215. --- /dev/null
  5216. +++ b/board/lantiq/easy80920/Makefile
  5217. @@ -0,0 +1,27 @@
  5218. +#
  5219. +# Copyright (C) 2000-2011 Wolfgang Denk, DENX Software Engineering, wd@denx.de
  5220. +#
  5221. +# SPDX-License-Identifier: GPL-2.0+
  5222. +#
  5223. +
  5224. +include $(TOPDIR)/config.mk
  5225. +
  5226. +LIB = $(obj)lib$(BOARD).o
  5227. +
  5228. +COBJS = $(BOARD).o
  5229. +
  5230. +SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c)
  5231. +OBJS := $(addprefix $(obj),$(COBJS))
  5232. +SOBJS := $(addprefix $(obj),$(SOBJS))
  5233. +
  5234. +$(LIB): $(obj).depend $(OBJS) $(SOBJS)
  5235. + $(call cmd_link_o_target, $(OBJS) $(SOBJS))
  5236. +
  5237. +#########################################################################
  5238. +
  5239. +# defines $(obj).depend target
  5240. +include $(SRCTREE)/rules.mk
  5241. +
  5242. +sinclude $(obj).depend
  5243. +
  5244. +#########################################################################
  5245. --- /dev/null
  5246. +++ b/board/lantiq/easy80920/config.mk
  5247. @@ -0,0 +1,7 @@
  5248. +#
  5249. +# Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  5250. +#
  5251. +# SPDX-License-Identifier: GPL-2.0+
  5252. +#
  5253. +
  5254. +PLATFORM_CPPFLAGS += -I$(TOPDIR)/board/$(BOARDDIR)
  5255. --- /dev/null
  5256. +++ b/board/lantiq/easy80920/ddr_settings.h
  5257. @@ -0,0 +1,69 @@
  5258. +/*
  5259. + * Copyright (C) 2007-2010 Lantiq Deutschland GmbH
  5260. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  5261. + *
  5262. + * SPDX-License-Identifier: GPL-2.0+
  5263. + */
  5264. +
  5265. +#define MC_CCR00_VALUE 0x101
  5266. +#define MC_CCR01_VALUE 0x1000100
  5267. +#define MC_CCR02_VALUE 0x1010000
  5268. +#define MC_CCR03_VALUE 0x101
  5269. +#define MC_CCR04_VALUE 0x1000000
  5270. +#define MC_CCR05_VALUE 0x1000101
  5271. +#define MC_CCR06_VALUE 0x1000100
  5272. +#define MC_CCR07_VALUE 0x1010000
  5273. +#define MC_CCR08_VALUE 0x1000101
  5274. +#define MC_CCR09_VALUE 0x0
  5275. +#define MC_CCR10_VALUE 0x2000100
  5276. +#define MC_CCR11_VALUE 0x2000300
  5277. +#define MC_CCR12_VALUE 0x30000
  5278. +#define MC_CCR13_VALUE 0x202
  5279. +#define MC_CCR14_VALUE 0x7080A0F
  5280. +#define MC_CCR15_VALUE 0x2040F
  5281. +#define MC_CCR16_VALUE 0x40000
  5282. +#define MC_CCR17_VALUE 0x70102
  5283. +#define MC_CCR18_VALUE 0x4020002
  5284. +#define MC_CCR19_VALUE 0x30302
  5285. +#define MC_CCR20_VALUE 0x8000700
  5286. +#define MC_CCR21_VALUE 0x40F020A
  5287. +#define MC_CCR22_VALUE 0x0
  5288. +#define MC_CCR23_VALUE 0xC020000
  5289. +#define MC_CCR24_VALUE 0x4401B04
  5290. +#define MC_CCR25_VALUE 0x0
  5291. +#define MC_CCR26_VALUE 0x0
  5292. +#define MC_CCR27_VALUE 0x6420000
  5293. +#define MC_CCR28_VALUE 0x0
  5294. +#define MC_CCR29_VALUE 0x0
  5295. +#define MC_CCR30_VALUE 0x798
  5296. +#define MC_CCR31_VALUE 0x0
  5297. +#define MC_CCR32_VALUE 0x0
  5298. +#define MC_CCR33_VALUE 0x650000
  5299. +#define MC_CCR34_VALUE 0x200C8
  5300. +#define MC_CCR35_VALUE 0x1D445D
  5301. +#define MC_CCR36_VALUE 0xC8
  5302. +#define MC_CCR37_VALUE 0xC351
  5303. +#define MC_CCR38_VALUE 0x0
  5304. +#define MC_CCR39_VALUE 0x141F04
  5305. +#define MC_CCR40_VALUE 0x142704
  5306. +#define MC_CCR41_VALUE 0x141b42
  5307. +#define MC_CCR42_VALUE 0x141b42
  5308. +#define MC_CCR43_VALUE 0x566504
  5309. +#define MC_CCR44_VALUE 0x566504
  5310. +#define MC_CCR45_VALUE 0x565F17
  5311. +#define MC_CCR46_VALUE 0x565F17
  5312. +#define MC_CCR47_VALUE 0x0
  5313. +#define MC_CCR48_VALUE 0x0
  5314. +#define MC_CCR49_VALUE 0x0
  5315. +#define MC_CCR50_VALUE 0x0
  5316. +#define MC_CCR51_VALUE 0x0
  5317. +#define MC_CCR52_VALUE 0x133
  5318. +#define MC_CCR53_VALUE 0xF3014B27
  5319. +#define MC_CCR54_VALUE 0xF3014B27
  5320. +#define MC_CCR55_VALUE 0xF3014B27
  5321. +#define MC_CCR56_VALUE 0xF3014B27
  5322. +#define MC_CCR57_VALUE 0x7800301
  5323. +#define MC_CCR58_VALUE 0x7800301
  5324. +#define MC_CCR59_VALUE 0x7800301
  5325. +#define MC_CCR60_VALUE 0x7800301
  5326. +#define MC_CCR61_VALUE 0x4
  5327. --- /dev/null
  5328. +++ b/board/lantiq/easy80920/easy80920.c
  5329. @@ -0,0 +1,138 @@
  5330. +/*
  5331. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  5332. + *
  5333. + * SPDX-License-Identifier: GPL-2.0+
  5334. + */
  5335. +
  5336. +#include <common.h>
  5337. +#include <spi.h>
  5338. +#include <asm/gpio.h>
  5339. +#include <asm/lantiq/eth.h>
  5340. +#include <asm/lantiq/chipid.h>
  5341. +#include <asm/lantiq/cpu.h>
  5342. +#include <asm/arch/gphy.h>
  5343. +
  5344. +#if defined(CONFIG_SPL_BUILD)
  5345. +#define do_gpio_init 1
  5346. +#define do_pll_init 1
  5347. +#define do_dcdc_init 0
  5348. +#elif defined(CONFIG_SYS_BOOT_RAM)
  5349. +#define do_gpio_init 1
  5350. +#define do_pll_init 0
  5351. +#define do_dcdc_init 1
  5352. +#elif defined(CONFIG_SYS_BOOT_NOR)
  5353. +#define do_gpio_init 1
  5354. +#define do_pll_init 1
  5355. +#define do_dcdc_init 1
  5356. +#else
  5357. +#define do_gpio_init 0
  5358. +#define do_pll_init 0
  5359. +#define do_dcdc_init 1
  5360. +#endif
  5361. +
  5362. +static void gpio_init(void)
  5363. +{
  5364. + /* SPI CS 0.4 to serial flash */
  5365. + gpio_direction_output(10, 1);
  5366. +
  5367. + /* EBU.FL_CS1 as output for NAND CE */
  5368. + gpio_set_altfunc(23, GPIO_ALTSEL_SET, GPIO_ALTSEL_CLR, GPIO_DIR_OUT);
  5369. + /* EBU.FL_A23 as output for NAND CLE */
  5370. + gpio_set_altfunc(24, GPIO_ALTSEL_SET, GPIO_ALTSEL_CLR, GPIO_DIR_OUT);
  5371. + /* EBU.FL_A24 as output for NAND ALE */
  5372. + gpio_set_altfunc(13, GPIO_ALTSEL_SET, GPIO_ALTSEL_CLR, GPIO_DIR_OUT);
  5373. + /* GPIO 3.0 as input for NAND Ready Busy */
  5374. + gpio_set_altfunc(48, GPIO_ALTSEL_SET, GPIO_ALTSEL_CLR, GPIO_DIR_IN);
  5375. + /* GPIO 3.1 as output for NAND Read */
  5376. + gpio_set_altfunc(49, GPIO_ALTSEL_SET, GPIO_ALTSEL_CLR, GPIO_DIR_OUT);
  5377. +}
  5378. +
  5379. +int board_early_init_f(void)
  5380. +{
  5381. + if (do_gpio_init)
  5382. + gpio_init();
  5383. +
  5384. + if (do_pll_init)
  5385. + ltq_pll_init();
  5386. +
  5387. + if (do_dcdc_init)
  5388. + ltq_dcdc_init(0x7F);
  5389. +
  5390. + return 0;
  5391. +}
  5392. +
  5393. +int checkboard(void)
  5394. +{
  5395. + puts("Board: " CONFIG_BOARD_NAME "\n");
  5396. + ltq_chip_print_info();
  5397. +
  5398. + return 0;
  5399. +}
  5400. +
  5401. +static const struct ltq_eth_port_config eth_port_config[] = {
  5402. + /* GMAC0: external Lantiq PEF7071 10/100/1000 PHY for LAN port 0 */
  5403. + { 0, 0x0, LTQ_ETH_PORT_PHY, PHY_INTERFACE_MODE_RGMII },
  5404. + /* GMAC1: external Lantiq PEF7071 10/100/1000 PHY for LAN port 1 */
  5405. + { 1, 0x1, LTQ_ETH_PORT_PHY, PHY_INTERFACE_MODE_RGMII },
  5406. + /* GMAC2: internal GPHY0 with 10/100/1000 firmware for LAN port 2 */
  5407. + { 2, 0x11, LTQ_ETH_PORT_PHY, PHY_INTERFACE_MODE_GMII },
  5408. + /* GMAC3: unused */
  5409. + { 3, 0x0, LTQ_ETH_PORT_NONE, PHY_INTERFACE_MODE_NONE },
  5410. + /* GMAC4: internal GPHY1 with 10/100/1000 firmware for LAN port 3 */
  5411. + { 4, 0x13, LTQ_ETH_PORT_PHY, PHY_INTERFACE_MODE_GMII },
  5412. + /* GMAC5: external Lantiq PEF7071 10/100/1000 PHY for WANoE port */
  5413. + { 5, 0x5, LTQ_ETH_PORT_PHY, PHY_INTERFACE_MODE_RGMII },
  5414. +};
  5415. +
  5416. +static const struct ltq_eth_board_config eth_board_config = {
  5417. + .ports = eth_port_config,
  5418. + .num_ports = ARRAY_SIZE(eth_port_config),
  5419. +};
  5420. +
  5421. +int board_eth_init(bd_t * bis)
  5422. +{
  5423. + const enum ltq_gphy_clk clk = LTQ_GPHY_CLK_25MHZ_PLL0;
  5424. + const ulong fw_addr = 0x80FF0000;
  5425. +
  5426. + ltq_gphy_phy11g_a1x_load(fw_addr);
  5427. +
  5428. + ltq_cgu_gphy_clk_src(clk);
  5429. +
  5430. + ltq_rcu_gphy_boot(0, fw_addr);
  5431. + ltq_rcu_gphy_boot(1, fw_addr);
  5432. +
  5433. + return ltq_eth_initialize(&eth_board_config);
  5434. +}
  5435. +
  5436. +int spi_cs_is_valid(unsigned int bus, unsigned int cs)
  5437. +{
  5438. + if (bus)
  5439. + return 0;
  5440. +
  5441. + if (cs == 4)
  5442. + return 1;
  5443. +
  5444. + return 0;
  5445. +}
  5446. +
  5447. +void spi_cs_activate(struct spi_slave *slave)
  5448. +{
  5449. + switch (slave->cs) {
  5450. + case 4:
  5451. + gpio_set_value(10, 0);
  5452. + break;
  5453. + default:
  5454. + break;
  5455. + }
  5456. +}
  5457. +
  5458. +void spi_cs_deactivate(struct spi_slave *slave)
  5459. +{
  5460. + switch (slave->cs) {
  5461. + case 4:
  5462. + gpio_set_value(10, 1);
  5463. + break;
  5464. + default:
  5465. + break;
  5466. + }
  5467. +}
  5468. --- a/boards.cfg
  5469. +++ b/boards.cfg
  5470. @@ -502,10 +502,17 @@ Active mips mips32 au1x0
  5471. Active mips mips32 au1x00 - dbau1x00 dbau1550 dbau1x00:DBAU1550 Thomas Lange <thomas@corelatus.se>
  5472. Active mips mips32 au1x00 - dbau1x00 dbau1550_el dbau1x00:DBAU1550,SYS_LITTLE_ENDIAN Thomas Lange <thomas@corelatus.se>
  5473. Active mips mips32 au1x00 - pb1x00 pb1000 pb1x00:PB1000 -
  5474. +Active mips mips32 danube lantiq easy50712 easy50712_nor easy50712:SYS_BOOT_NOR Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
  5475. +Active mips mips32 danube lantiq easy50712 easy50712_norspl easy50712:SYS_BOOT_NORSPL Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
  5476. +Active mips mips32 danube lantiq easy50712 easy50712_ram easy50712:SYS_BOOT_RAM Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
  5477. Active mips mips32 incaip - incaip incaip - Wolfgang Denk <wd@denx.de>
  5478. Active mips mips32 incaip - incaip incaip_100MHz incaip:CPU_CLOCK_RATE=100000000 Wolfgang Denk <wd@denx.de>
  5479. Active mips mips32 incaip - incaip incaip_133MHz incaip:CPU_CLOCK_RATE=133000000 Wolfgang Denk <wd@denx.de>
  5480. Active mips mips32 incaip - incaip incaip_150MHz incaip:CPU_CLOCK_RATE=150000000 Wolfgang Denk <wd@denx.de>
  5481. +Active mips mips32 vrx200 lantiq easy80920 easy80920_nor easy80920:SYS_BOOT_NOR Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
  5482. +Active mips mips32 vrx200 lantiq easy80920 easy80920_norspl easy80920:SYS_BOOT_NORSPL Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
  5483. +Active mips mips32 vrx200 lantiq easy80920 easy80920_ram easy80920:SYS_BOOT_RAM Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
  5484. +Active mips mips32 vrx200 lantiq easy80920 easy80920_sfspl easy80920:SYS_BOOT_SFSPL Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
  5485. Active mips mips64 - - qemu-mips qemu_mips64 qemu-mips64:SYS_BIG_ENDIAN -
  5486. Active mips mips64 - - qemu-mips qemu_mips64el qemu-mips64:SYS_LITTLE_ENDIAN -
  5487. Active nds32 n1213 ag101 AndesTech adp-ag101 adp-ag101 - Andes <uboot@andestech.com>
  5488. --- a/drivers/dma/Makefile
  5489. +++ b/drivers/dma/Makefile
  5490. @@ -12,6 +12,7 @@ LIB := $(obj)libdma.o
  5491. COBJS-$(CONFIG_FSLDMAFEC) += MCD_tasksInit.o MCD_dmaApi.o MCD_tasks.o
  5492. COBJS-$(CONFIG_APBH_DMA) += apbh_dma.o
  5493. COBJS-$(CONFIG_FSL_DMA) += fsl_dma.o
  5494. +COBJS-$(CONFIG_LANTIQ_DMA) += lantiq_dma.o
  5495. COBJS-$(CONFIG_OMAP3_DMA) += omap3_dma.o
  5496. COBJS := $(COBJS-y)
  5497. --- /dev/null
  5498. +++ b/drivers/dma/lantiq_dma.c
  5499. @@ -0,0 +1,387 @@
  5500. +/*
  5501. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  5502. + *
  5503. + * SPDX-License-Identifier: GPL-2.0+
  5504. + */
  5505. +
  5506. +#include <common.h>
  5507. +#include <malloc.h>
  5508. +#include <watchdog.h>
  5509. +#include <linux/compiler.h>
  5510. +#include <asm/lantiq/io.h>
  5511. +#include <asm/lantiq/dma.h>
  5512. +#include <asm/lantiq/pm.h>
  5513. +#include <asm/lantiq/reset.h>
  5514. +#include <asm/arch/soc.h>
  5515. +#include <asm/processor.h>
  5516. +
  5517. +#define DMA_CTRL_PKTARB (1 << 31)
  5518. +#define DMA_CTRL_MBRSTARB (1 << 30)
  5519. +#define DMA_CTRL_MBRSTCNT_SHIFT 16
  5520. +#define DMA_CTRL_MBRSTCNT_MASK (0x3ff << DMA_CTRL_MBRSTCNT_SHIFT)
  5521. +#define DMA_CTRL_DRB (1 << 8)
  5522. +#define DMA_CTRL_RESET (1 << 0)
  5523. +
  5524. +#define DMA_CPOLL_EN (1 << 31)
  5525. +#define DMA_CPOLL_CNT_SHIFT 4
  5526. +#define DMA_CPOLL_CNT_MASK (0xFFF << DMA_CPOLL_CNT_SHIFT)
  5527. +
  5528. +#define DMA_CCTRL_TXWGT_SHIFT 16
  5529. +#define DMA_CCTRL_TXWGT_MASK (0x3 << DMA_CCTRL_TXWGT_SHIFT)
  5530. +#define DMA_CCTRL_CLASS_SHIFT 9
  5531. +#define DMA_CCTRL_CLASS_MASK (0x3 << DMA_CCTRL_CLASS_SHIFT)
  5532. +#define DMA_CCTRL_RST (1 << 1)
  5533. +#define DMA_CCTRL_ONOFF (1 << 0)
  5534. +
  5535. +#define DMA_PCTRL_TXBL_SHIFT 4
  5536. +#define DMA_PCTRL_TXBL_2WORDS (1 << DMA_PCTRL_TXBL_SHIFT)
  5537. +#define DMA_PCTRL_TXBL_4WORDS (2 << DMA_PCTRL_TXBL_SHIFT)
  5538. +#define DMA_PCTRL_TXBL_8WORDS (3 << DMA_PCTRL_TXBL_SHIFT)
  5539. +#define DMA_PCTRL_RXBL_SHIFT 2
  5540. +#define DMA_PCTRL_RXBL_2WORDS (1 << DMA_PCTRL_RXBL_SHIFT)
  5541. +#define DMA_PCTRL_RXBL_4WORDS (2 << DMA_PCTRL_RXBL_SHIFT)
  5542. +#define DMA_PCTRL_RXBL_8WORDS (3 << DMA_PCTRL_RXBL_SHIFT)
  5543. +#define DMA_PCTRL_TXENDI_SHIFT 10
  5544. +#define DMA_PCTRL_TXENDI_MASK (0x3 << DMA_PCTRL_TXENDI_SHIFT)
  5545. +#define DMA_PCTRL_RXENDI_SHIFT 8
  5546. +#define DMA_PCTRL_RXENDI_MASK (0x3 << DMA_PCTRL_RXENDI_SHIFT)
  5547. +
  5548. +#define DMA_DESC_OWN (1 << 31)
  5549. +#define DMA_DESC_C (1 << 30)
  5550. +#define DMA_DESC_SOP (1 << 29)
  5551. +#define DMA_DESC_EOP (1 << 28)
  5552. +#define DMA_DESC_TX_OFFSET(x) ((x & 0x1f) << 23)
  5553. +#define DMA_DESC_RX_OFFSET(x) ((x & 0x3) << 23)
  5554. +#define DMA_DESC_LENGTH(x) (x & 0xffff)
  5555. +
  5556. +#define PTR_ALIGN(p, a) ((typeof(p))ALIGN((unsigned long)(p), (a)))
  5557. +
  5558. +struct ltq_dma_regs {
  5559. + u32 clc; /* Clock control */
  5560. + u32 rsvd0;
  5561. + u32 id; /* Identification */
  5562. + u32 rsvd1;
  5563. + u32 ctrl; /* Control */
  5564. + u32 cpoll; /* Channel polling */
  5565. + u32 cs; /* Channel select */
  5566. + u32 cctrl; /* Channel control */
  5567. + u32 cdba; /* Channel descriptor base address */
  5568. + u32 cdlen; /* Channel descriptor length */
  5569. + u32 cis; /* Channel interrupt status */
  5570. + u32 cie; /* Channel interrupt enable */
  5571. + u32 cgbl; /* Channel global buffer length */
  5572. + u32 cdptnrd; /* Current descriptor pointer */
  5573. + u32 rsvd2[2];
  5574. + u32 ps; /* Port select */
  5575. + u32 pctrl; /* Port control */
  5576. + u32 rsvd3[43];
  5577. + u32 irnen; /* Interrupt node enable */
  5578. + u32 irncr; /* Interrupt node control */
  5579. + u32 irnicr; /* Interrupt capture */
  5580. +};
  5581. +
  5582. +static struct ltq_dma_regs *ltq_dma_regs =
  5583. + (struct ltq_dma_regs *) CKSEG1ADDR(LTQ_DMA_BASE);
  5584. +
  5585. +static inline unsigned long ltq_dma_addr_to_virt(u32 dma_addr)
  5586. +{
  5587. + return KSEG0ADDR(dma_addr);
  5588. +}
  5589. +
  5590. +static inline u32 ltq_virt_to_dma_addr(void *addr)
  5591. +{
  5592. + return CPHYSADDR(addr);
  5593. +}
  5594. +
  5595. +static inline int ltq_dma_burst_align(enum ltq_dma_burst_len burst_len)
  5596. +{
  5597. + switch (burst_len) {
  5598. + case LTQ_DMA_BURST_2WORDS:
  5599. + return 2 * 4;
  5600. + case LTQ_DMA_BURST_4WORDS:
  5601. + return 4 * 4;
  5602. + case LTQ_DMA_BURST_8WORDS:
  5603. + return 8 * 4;
  5604. + }
  5605. +
  5606. + return 0;
  5607. +}
  5608. +
  5609. +static inline void ltq_dma_sync(void)
  5610. +{
  5611. + __asm__ __volatile__("sync");
  5612. +}
  5613. +
  5614. +static inline void ltq_dma_dcache_wb_inv(const void *ptr, size_t size)
  5615. +{
  5616. + unsigned long addr = (unsigned long) ptr;
  5617. +
  5618. + flush_dcache_range(addr, addr + size);
  5619. + ltq_dma_sync();
  5620. +}
  5621. +
  5622. +static inline void ltq_dma_dcache_inv(const void *ptr, size_t size)
  5623. +{
  5624. + unsigned long addr = (unsigned long) ptr;
  5625. +
  5626. + invalidate_dcache_range(addr, addr + size);
  5627. +}
  5628. +
  5629. +void ltq_dma_init(void)
  5630. +{
  5631. + /* Power up DMA */
  5632. + ltq_pm_enable(LTQ_PM_DMA);
  5633. +
  5634. + /* Reset DMA */
  5635. + ltq_setbits(&ltq_dma_regs->ctrl, DMA_CTRL_RESET);
  5636. +
  5637. + /* Disable and clear all interrupts */
  5638. + ltq_writel(&ltq_dma_regs->irnen, 0);
  5639. + ltq_writel(&ltq_dma_regs->irncr, 0xFFFFF);
  5640. +
  5641. +#if 0
  5642. + /* Enable packet arbitration */
  5643. + ltq_setbits(&ltq_dma_regs->ctrl, DMA_CTRL_PKTARB);
  5644. +#endif
  5645. +
  5646. +#if 0
  5647. + /* Enable descriptor read back */
  5648. + ltq_setbits(&ltq_dma_regs->ctrl, DMA_CTRL_DRB);
  5649. +#endif
  5650. +
  5651. + /* Enable polling for descriptor fetching for all channels */
  5652. + ltq_writel(&ltq_dma_regs->cpoll, DMA_CPOLL_EN |
  5653. + (4 << DMA_CPOLL_CNT_SHIFT));
  5654. +}
  5655. +
  5656. +static void ltq_dma_channel_reset(struct ltq_dma_channel *chan)
  5657. +{
  5658. + ltq_writel(&ltq_dma_regs->cs, chan->chan_no);
  5659. + ltq_setbits(&ltq_dma_regs->cctrl, DMA_CCTRL_RST);
  5660. +}
  5661. +
  5662. +static void ltq_dma_channel_enable(struct ltq_dma_channel *chan)
  5663. +{
  5664. + ltq_writel(&ltq_dma_regs->cs, chan->chan_no);
  5665. + ltq_setbits(&ltq_dma_regs->cctrl, DMA_CCTRL_ONOFF);
  5666. +}
  5667. +
  5668. +static void ltq_dma_channel_disable(struct ltq_dma_channel *chan)
  5669. +{
  5670. + ltq_writel(&ltq_dma_regs->cs, chan->chan_no);
  5671. + ltq_clrbits(&ltq_dma_regs->cctrl, DMA_CCTRL_ONOFF);
  5672. +}
  5673. +
  5674. +static void ltq_dma_port_init(struct ltq_dma_device *dev)
  5675. +{
  5676. + u32 pctrl;
  5677. +
  5678. + pctrl = dev->tx_endian_swap << DMA_PCTRL_TXENDI_SHIFT;
  5679. + pctrl |= dev->rx_endian_swap << DMA_PCTRL_RXENDI_SHIFT;
  5680. + pctrl |= dev->tx_burst_len << DMA_PCTRL_TXBL_SHIFT;
  5681. + pctrl |= dev->rx_burst_len << DMA_PCTRL_RXBL_SHIFT;
  5682. +
  5683. + ltq_writel(&ltq_dma_regs->ps, dev->port);
  5684. + ltq_writel(&ltq_dma_regs->pctrl, pctrl);
  5685. +}
  5686. +
  5687. +static int ltq_dma_alloc_descriptors(struct ltq_dma_device *dev,
  5688. + struct ltq_dma_channel *chan)
  5689. +{
  5690. + size_t size;
  5691. + void *desc_base;
  5692. +
  5693. + size = ALIGN(sizeof(struct ltq_dma_desc) * chan->num_desc +
  5694. + ARCH_DMA_MINALIGN, ARCH_DMA_MINALIGN);
  5695. +
  5696. + chan->mem_base = malloc(size);
  5697. + if (!chan->mem_base)
  5698. + return 1;
  5699. +
  5700. + memset(chan->mem_base, 0, size);
  5701. + ltq_dma_dcache_wb_inv(chan->mem_base, size);
  5702. +
  5703. + desc_base = PTR_ALIGN(chan->mem_base, ARCH_DMA_MINALIGN);
  5704. +
  5705. + debug("DMA: mem %p, desc %p\n", chan->mem_base, desc_base);
  5706. +
  5707. + /* Align descriptor base to 8 bytes */
  5708. + chan->desc_base = (void *) CKSEG1ADDR(desc_base);
  5709. + chan->dma_addr = CPHYSADDR(desc_base);
  5710. + chan->dev = dev;
  5711. +
  5712. + debug("DMA: desc_base %p, size %u\n", chan->desc_base, size);
  5713. +
  5714. + /* Configure hardware with location of descriptor list */
  5715. + ltq_writel(&ltq_dma_regs->cs, chan->chan_no);
  5716. + ltq_writel(&ltq_dma_regs->cdba, chan->dma_addr);
  5717. + ltq_writel(&ltq_dma_regs->cdlen, chan->num_desc);
  5718. + ltq_writel(&ltq_dma_regs->cctrl, (3 << DMA_CCTRL_TXWGT_SHIFT) |
  5719. + (chan->class << DMA_CCTRL_CLASS_SHIFT));
  5720. + ltq_writel(&ltq_dma_regs->cctrl, DMA_CCTRL_RST);
  5721. +
  5722. + return 0;
  5723. +}
  5724. +
  5725. +static void ltq_dma_free_descriptors(struct ltq_dma_channel *chan)
  5726. +{
  5727. + ltq_writel(&ltq_dma_regs->cs, chan->chan_no);
  5728. + ltq_writel(&ltq_dma_regs->cdba, 0);
  5729. + ltq_writel(&ltq_dma_regs->cdlen, 0);
  5730. +
  5731. + ltq_dma_channel_reset(chan);
  5732. +
  5733. + free(chan->mem_base);
  5734. +}
  5735. +
  5736. +int ltq_dma_register(struct ltq_dma_device *dev)
  5737. +{
  5738. + int ret;
  5739. +
  5740. + ltq_dma_port_init(dev);
  5741. +
  5742. + ret = ltq_dma_alloc_descriptors(dev, &dev->rx_chan);
  5743. + if (ret)
  5744. + return ret;
  5745. +
  5746. + ret = ltq_dma_alloc_descriptors(dev, &dev->tx_chan);
  5747. + if (ret) {
  5748. + ltq_dma_free_descriptors(&dev->rx_chan);
  5749. + return ret;
  5750. + }
  5751. +
  5752. + return 0;
  5753. +}
  5754. +
  5755. +void ltq_dma_reset(struct ltq_dma_device *dev)
  5756. +{
  5757. + ltq_dma_channel_reset(&dev->rx_chan);
  5758. + ltq_dma_channel_reset(&dev->tx_chan);
  5759. +}
  5760. +
  5761. +void ltq_dma_enable(struct ltq_dma_device *dev)
  5762. +{
  5763. + ltq_dma_channel_enable(&dev->rx_chan);
  5764. + ltq_dma_channel_enable(&dev->tx_chan);
  5765. +}
  5766. +
  5767. +void ltq_dma_disable(struct ltq_dma_device *dev)
  5768. +{
  5769. + ltq_dma_channel_disable(&dev->rx_chan);
  5770. + ltq_dma_channel_disable(&dev->tx_chan);
  5771. +}
  5772. +
  5773. +int ltq_dma_rx_map(struct ltq_dma_device *dev, int index, void *data, int len)
  5774. +{
  5775. + struct ltq_dma_channel *chan = &dev->rx_chan;
  5776. + struct ltq_dma_desc *desc = &chan->desc_base[index];
  5777. + u32 dma_addr = ltq_virt_to_dma_addr(data);
  5778. + unsigned int offset;
  5779. +
  5780. + offset = dma_addr % ltq_dma_burst_align(dev->rx_burst_len);
  5781. +
  5782. + ltq_dma_dcache_inv(data, len);
  5783. +
  5784. +#if 0
  5785. + printf("%s: index %d, data %p, dma_addr %08x, offset %u, len %d\n",
  5786. + __func__, index, data, dma_addr, offset, len);
  5787. +#endif
  5788. +
  5789. +
  5790. + desc->addr = dma_addr - offset;
  5791. + desc->ctl = DMA_DESC_OWN | DMA_DESC_RX_OFFSET(offset) |
  5792. + DMA_DESC_LENGTH(len);
  5793. +
  5794. +#if 0
  5795. + printf("%s: index %d, desc %p, desc->ctl %08x\n",
  5796. + __func__, index, desc, desc->ctl);
  5797. +#endif
  5798. +
  5799. + return 0;
  5800. +}
  5801. +
  5802. +int ltq_dma_rx_poll(struct ltq_dma_device *dev, int index)
  5803. +{
  5804. + struct ltq_dma_channel *chan = &dev->rx_chan;
  5805. + struct ltq_dma_desc *desc = &chan->desc_base[index];
  5806. +
  5807. +#if 0
  5808. + printf("%s: index %d, desc %p, desc->ctl %08x\n",
  5809. + __func__, index, desc, desc->ctl);
  5810. +#endif
  5811. +
  5812. + if (desc->ctl & DMA_DESC_OWN)
  5813. + return 0;
  5814. +
  5815. + if (desc->ctl & DMA_DESC_C)
  5816. + return 1;
  5817. +
  5818. + return 0;
  5819. +}
  5820. +
  5821. +int ltq_dma_rx_length(struct ltq_dma_device *dev, int index)
  5822. +{
  5823. + struct ltq_dma_channel *chan = &dev->rx_chan;
  5824. + struct ltq_dma_desc *desc = &chan->desc_base[index];
  5825. +
  5826. + return DMA_DESC_LENGTH(desc->ctl);
  5827. +}
  5828. +
  5829. +int ltq_dma_tx_map(struct ltq_dma_device *dev, int index, void *data, int len,
  5830. + unsigned long timeout)
  5831. +{
  5832. + struct ltq_dma_channel *chan = &dev->tx_chan;
  5833. + struct ltq_dma_desc *desc = &chan->desc_base[index];
  5834. + unsigned int offset;
  5835. + unsigned long timebase = get_timer(0);
  5836. + u32 dma_addr = ltq_virt_to_dma_addr(data);
  5837. +
  5838. + while (desc->ctl & DMA_DESC_OWN) {
  5839. + WATCHDOG_RESET();
  5840. +
  5841. + if (get_timer(timebase) >= timeout) {
  5842. +#if 0
  5843. + printf("%s: timeout: index %d, desc %p, desc->ctl %08x\n",
  5844. + __func__, index, desc, desc->ctl);
  5845. +#endif
  5846. + return -1;
  5847. + }
  5848. + }
  5849. +
  5850. + offset = dma_addr % ltq_dma_burst_align(dev->rx_burst_len);
  5851. +
  5852. +#if 0
  5853. + printf("%s: index %d, desc %p, data %p, dma_addr %08x, offset %u, len %d\n",
  5854. + __func__, index, desc, data, dma_addr, offset, len);
  5855. +#endif
  5856. +
  5857. + ltq_dma_dcache_wb_inv(data, len);
  5858. +
  5859. + desc->addr = dma_addr - offset;
  5860. + desc->ctl = DMA_DESC_OWN | DMA_DESC_SOP | DMA_DESC_EOP |
  5861. + DMA_DESC_TX_OFFSET(offset) | DMA_DESC_LENGTH(len);
  5862. +
  5863. +#if 0
  5864. + printf("%s: index %d, desc %p, desc->ctl %08x\n",
  5865. + __func__, index, desc, desc->ctl);
  5866. +#endif
  5867. +
  5868. + return 0;
  5869. +}
  5870. +
  5871. +int ltq_dma_tx_wait(struct ltq_dma_device *dev, int index,
  5872. + unsigned long timeout)
  5873. +{
  5874. + struct ltq_dma_channel *chan = &dev->tx_chan;
  5875. + struct ltq_dma_desc *desc = &chan->desc_base[index];
  5876. + unsigned long timebase = get_timer(0);
  5877. +
  5878. + while ((desc->ctl & (DMA_DESC_OWN | DMA_DESC_C)) != DMA_DESC_C) {
  5879. + WATCHDOG_RESET();
  5880. +
  5881. + if (get_timer(timebase) >= timeout)
  5882. + return -1;
  5883. + }
  5884. +
  5885. + return 0;
  5886. +}
  5887. --- a/drivers/gpio/Makefile
  5888. +++ b/drivers/gpio/Makefile
  5889. @@ -12,6 +12,7 @@ LIB := $(obj)libgpio.o
  5890. COBJS-$(CONFIG_AT91_GPIO) += at91_gpio.o
  5891. COBJS-$(CONFIG_INTEL_ICH6_GPIO) += intel_ich6_gpio.o
  5892. COBJS-$(CONFIG_KIRKWOOD_GPIO) += kw_gpio.o
  5893. +COBJS-$(CONFIG_LANTIQ_GPIO) += lantiq_gpio.o
  5894. COBJS-$(CONFIG_MARVELL_GPIO) += mvgpio.o
  5895. COBJS-$(CONFIG_MARVELL_MFP) += mvmfp.o
  5896. COBJS-$(CONFIG_MXC_GPIO) += mxc_gpio.o
  5897. --- /dev/null
  5898. +++ b/drivers/gpio/lantiq_gpio.c
  5899. @@ -0,0 +1,329 @@
  5900. +/*
  5901. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  5902. + *
  5903. + * SPDX-License-Identifier: GPL-2.0+
  5904. + */
  5905. +
  5906. +#include <common.h>
  5907. +#include <asm/arch/soc.h>
  5908. +#include <asm/arch/gpio.h>
  5909. +#include <asm/lantiq/io.h>
  5910. +
  5911. +#define SSIO_GPIO_BASE 64
  5912. +
  5913. +#define SSIO_CON0_SWU (1 << 31)
  5914. +#define SSIO_CON0_RZFL (1 << 26)
  5915. +#define SSIO_CON0_GPHY1_SHIFT 27
  5916. +#define SSIO_CON0_GPHY1_CONFIG ((CONFIG_LTQ_SSIO_GPHY1_MODE & 0x7) << 27)
  5917. +
  5918. +#define SSIO_CON1_US_FPI (2 << 30)
  5919. +#define SSIO_CON1_FPID_2HZ (0 << 23)
  5920. +#define SSIO_CON1_FPID_4HZ (1 << 23)
  5921. +#define SSIO_CON1_FPID_8HZ (2 << 23)
  5922. +#define SSIO_CON1_FPID_10HZ (3 << 23)
  5923. +#define SSIO_CON1_FPIS_1_2 (1 << 20)
  5924. +#define SSIO_CON1_FPIS_1_32 (2 << 20)
  5925. +#define SSIO_CON1_FPIS_1_64 (3 << 20)
  5926. +
  5927. +#define SSIO_CON1_GPHY2_SHIFT 15
  5928. +#define SSIO_CON1_GPHY2_CONFIG ((CONFIG_LTQ_SSIO_GPHY2_MODE & 0x7) << 15)
  5929. +
  5930. +#define SSIO_CON1_GROUP2 (1 << 2)
  5931. +#define SSIO_CON1_GROUP1 (1 << 1)
  5932. +#define SSIO_CON1_GROUP0 (1 << 0)
  5933. +#define SSIO_CON1_GROUP_CONFIG (0x3)
  5934. +
  5935. +#ifdef CONFIG_LTQ_SSIO_SHIFT_REGS
  5936. +#define enable_ssio 1
  5937. +#else
  5938. +#define enable_ssio 0
  5939. +
  5940. +#define CONFIG_LTQ_SSIO_GPHY1_MODE 0
  5941. +#define CONFIG_LTQ_SSIO_GPHY2_MODE 0
  5942. +#define CONFIG_LTQ_SSIO_INIT_VALUE 0
  5943. +#endif
  5944. +
  5945. +#ifdef CONFIG_LTQ_SSIO_EDGE_FALLING
  5946. +#define SSIO_RZFL_CONFIG SSIO_CON0_RZFL
  5947. +#else
  5948. +#define SSIO_RZFL_CONFIG 0
  5949. +#endif
  5950. +
  5951. +struct ltq_gpio_port_regs {
  5952. + __be32 out;
  5953. + __be32 in;
  5954. + __be32 dir;
  5955. + __be32 altsel0;
  5956. + __be32 altsel1;
  5957. + __be32 od;
  5958. + __be32 stoff;
  5959. + __be32 pudsel;
  5960. + __be32 puden;
  5961. + __be32 rsvd1[3];
  5962. +};
  5963. +
  5964. +struct ltq_gpio_regs {
  5965. + u32 rsvd[4];
  5966. + struct ltq_gpio_port_regs ports[CONFIG_LTQ_GPIO_MAX_BANKS];
  5967. +};
  5968. +
  5969. +struct ltq_gpio3_regs {
  5970. + u32 rsvd0[13];
  5971. + __be32 od;
  5972. + __be32 pudsel;
  5973. + __be32 puden;
  5974. + u32 rsvd1[9];
  5975. + __be32 altsel1;
  5976. + u32 rsvd2[14];
  5977. + __be32 out;
  5978. + __be32 in;
  5979. + __be32 dir;
  5980. + __be32 altsel0;
  5981. +};
  5982. +
  5983. +struct ltq_ssio_regs {
  5984. + __be32 con0;
  5985. + __be32 con1;
  5986. + __be32 cpu0;
  5987. + __be32 cpu1;
  5988. + __be32 ar;
  5989. +};
  5990. +
  5991. +static struct ltq_gpio_regs *ltq_gpio_regs =
  5992. + (struct ltq_gpio_regs *) CKSEG1ADDR(LTQ_GPIO_BASE);
  5993. +
  5994. +static struct ltq_gpio3_regs *ltq_gpio3_regs =
  5995. + (struct ltq_gpio3_regs *) CKSEG1ADDR(LTQ_GPIO_BASE);
  5996. +
  5997. +static struct ltq_ssio_regs *ltq_ssio_regs =
  5998. + (struct ltq_ssio_regs *) CKSEG1ADDR(LTQ_SSIO_BASE);
  5999. +
  6000. +static int is_gpio_bank3(unsigned int port)
  6001. +{
  6002. +#ifdef CONFIG_LTQ_HAS_GPIO_BANK3
  6003. + return port == 3;
  6004. +#else
  6005. + return 0;
  6006. +#endif
  6007. +}
  6008. +
  6009. +static int is_gpio_ssio(unsigned int gpio)
  6010. +{
  6011. +#ifdef CONFIG_LTQ_SSIO_SHIFT_REGS
  6012. + return gpio >= SSIO_GPIO_BASE;
  6013. +#else
  6014. + return 0;
  6015. +#endif
  6016. +}
  6017. +
  6018. +static inline int ssio_gpio_to_bit(unsigned gpio)
  6019. +{
  6020. + return 1 << (gpio - SSIO_GPIO_BASE);
  6021. +}
  6022. +
  6023. +int ltq_gpio_init(void)
  6024. +{
  6025. + ltq_writel(&ltq_ssio_regs->ar, 0);
  6026. + ltq_writel(&ltq_ssio_regs->cpu0, CONFIG_LTQ_SSIO_INIT_VALUE);
  6027. + ltq_writel(&ltq_ssio_regs->cpu1, 0);
  6028. + ltq_writel(&ltq_ssio_regs->con0, SSIO_CON0_SWU);
  6029. +
  6030. + if (enable_ssio) {
  6031. + ltq_writel(&ltq_ssio_regs->con0, SSIO_CON0_GPHY1_CONFIG |
  6032. + SSIO_RZFL_CONFIG);
  6033. + ltq_writel(&ltq_ssio_regs->con1, SSIO_CON1_US_FPI |
  6034. + SSIO_CON1_FPID_8HZ | SSIO_CON1_GPHY2_CONFIG |
  6035. + SSIO_CON1_GROUP_CONFIG);
  6036. + }
  6037. +
  6038. + return 0;
  6039. +}
  6040. +
  6041. +int gpio_request(unsigned gpio, const char *label)
  6042. +{
  6043. + return 0;
  6044. +}
  6045. +
  6046. +int gpio_free(unsigned gpio)
  6047. +{
  6048. + return 0;
  6049. +}
  6050. +
  6051. +int gpio_direction_input(unsigned gpio)
  6052. +{
  6053. + unsigned port = gpio_to_port(gpio);
  6054. + const void *gpio_od = &ltq_gpio_regs->ports[port].od;
  6055. + const void *gpio_altsel0 = &ltq_gpio_regs->ports[port].altsel0;
  6056. + const void *gpio_altsel1 = &ltq_gpio_regs->ports[port].altsel1;
  6057. + const void *gpio_dir = &ltq_gpio_regs->ports[port].dir;
  6058. +
  6059. + if (is_gpio_ssio(gpio))
  6060. + return 0;
  6061. +
  6062. + if (is_gpio_bank3(port)) {
  6063. + gpio_od = &ltq_gpio3_regs->od;
  6064. + gpio_altsel0 = &ltq_gpio3_regs->altsel0;
  6065. + gpio_altsel1 = &ltq_gpio3_regs->altsel1;
  6066. + gpio_dir = &ltq_gpio3_regs->dir;
  6067. + }
  6068. +
  6069. + /*
  6070. + * Reset open drain and altsel configs to workaround improper
  6071. + * reset values or unwanted modifications by BootROM
  6072. + */
  6073. + ltq_clrbits(gpio_od, gpio_to_bit(gpio));
  6074. + ltq_clrbits(gpio_altsel0, gpio_to_bit(gpio));
  6075. + ltq_clrbits(gpio_altsel1, gpio_to_bit(gpio));
  6076. +
  6077. + /* Switch to input */
  6078. + ltq_clrbits(gpio_dir, gpio_to_bit(gpio));
  6079. +
  6080. + return 0;
  6081. +}
  6082. +
  6083. +int gpio_direction_output(unsigned gpio, int value)
  6084. +{
  6085. + unsigned port = gpio_to_port(gpio);
  6086. + const void *gpio_od = &ltq_gpio_regs->ports[port].od;
  6087. + const void *gpio_altsel0 = &ltq_gpio_regs->ports[port].altsel0;
  6088. + const void *gpio_altsel1 = &ltq_gpio_regs->ports[port].altsel1;
  6089. + const void *gpio_dir = &ltq_gpio_regs->ports[port].dir;
  6090. + const void *gpio_out = &ltq_gpio_regs->ports[port].out;
  6091. + u32 data = gpio_to_bit(gpio);
  6092. +
  6093. + if (is_gpio_ssio(gpio)) {
  6094. + data = ssio_gpio_to_bit(gpio);
  6095. + if (value)
  6096. + ltq_setbits(&ltq_ssio_regs->cpu0, data);
  6097. + else
  6098. + ltq_clrbits(&ltq_ssio_regs->cpu0, data);
  6099. +
  6100. + return 0;
  6101. + }
  6102. +
  6103. + if (is_gpio_bank3(port)) {
  6104. + gpio_od = &ltq_gpio3_regs->od;
  6105. + gpio_altsel0 = &ltq_gpio3_regs->altsel0;
  6106. + gpio_altsel1 = &ltq_gpio3_regs->altsel1;
  6107. + gpio_dir = &ltq_gpio3_regs->dir;
  6108. + gpio_out = &ltq_gpio3_regs->out;
  6109. + }
  6110. +
  6111. + /*
  6112. + * Reset open drain and altsel configs to workaround improper
  6113. + * reset values or unwanted modifications by BootROM
  6114. + */
  6115. + ltq_setbits(gpio_od, data);
  6116. + ltq_clrbits(gpio_altsel0, data);
  6117. + ltq_clrbits(gpio_altsel1, data);
  6118. +
  6119. + if (value)
  6120. + ltq_setbits(gpio_out, data);
  6121. + else
  6122. + ltq_clrbits(gpio_out, data);
  6123. +
  6124. + /* Switch to output */
  6125. + ltq_setbits(gpio_dir, data);
  6126. +
  6127. + return 0;
  6128. +}
  6129. +
  6130. +int gpio_get_value(unsigned gpio)
  6131. +{
  6132. + unsigned port = gpio_to_port(gpio);
  6133. + const void *gpio_in = &ltq_gpio_regs->ports[port].in;
  6134. + u32 data = gpio_to_bit(gpio);
  6135. + u32 val;
  6136. +
  6137. + if (is_gpio_ssio(gpio)) {
  6138. + gpio_in = &ltq_ssio_regs->cpu0;
  6139. + data = ssio_gpio_to_bit(gpio);
  6140. + }
  6141. +
  6142. + if (is_gpio_bank3(port))
  6143. + gpio_in = &ltq_gpio3_regs->in;
  6144. +
  6145. + val = ltq_readl(gpio_in);
  6146. +
  6147. + return !!(val & data);
  6148. +}
  6149. +
  6150. +int gpio_set_value(unsigned gpio, int value)
  6151. +{
  6152. + unsigned port = gpio_to_port(gpio);
  6153. + const void *gpio_out = &ltq_gpio_regs->ports[port].out;
  6154. + u32 data = gpio_to_bit(gpio);
  6155. +
  6156. + if (is_gpio_ssio(gpio)) {
  6157. + gpio_out = &ltq_ssio_regs->cpu0;
  6158. + data = ssio_gpio_to_bit(gpio);
  6159. + }
  6160. +
  6161. + if (is_gpio_bank3(port))
  6162. + gpio_out = &ltq_gpio3_regs->out;
  6163. +
  6164. + if (value)
  6165. + ltq_setbits(gpio_out, data);
  6166. + else
  6167. + ltq_clrbits(gpio_out, data);
  6168. +
  6169. + return 0;
  6170. +}
  6171. +
  6172. +int gpio_set_altfunc(unsigned gpio, int altsel0, int altsel1, int dir)
  6173. +{
  6174. + unsigned port = gpio_to_port(gpio);
  6175. + const void *gpio_od = &ltq_gpio_regs->ports[port].od;
  6176. + const void *gpio_altsel0 = &ltq_gpio_regs->ports[port].altsel0;
  6177. + const void *gpio_altsel1 = &ltq_gpio_regs->ports[port].altsel1;
  6178. + const void *gpio_dir = &ltq_gpio_regs->ports[port].dir;
  6179. +
  6180. + if (is_gpio_ssio(gpio))
  6181. + return 0;
  6182. +
  6183. + if (is_gpio_bank3(port)) {
  6184. + gpio_od = &ltq_gpio3_regs->od;
  6185. + gpio_altsel0 = &ltq_gpio3_regs->altsel0;
  6186. + gpio_altsel1 = &ltq_gpio3_regs->altsel1;
  6187. + gpio_dir = &ltq_gpio3_regs->dir;
  6188. + }
  6189. +
  6190. + if (altsel0)
  6191. + ltq_setbits(gpio_altsel0, gpio_to_bit(gpio));
  6192. + else
  6193. + ltq_clrbits(gpio_altsel0, gpio_to_bit(gpio));
  6194. +
  6195. + if (altsel1)
  6196. + ltq_setbits(gpio_altsel1, gpio_to_bit(gpio));
  6197. + else
  6198. + ltq_clrbits(gpio_altsel1, gpio_to_bit(gpio));
  6199. +
  6200. + if (dir) {
  6201. + ltq_setbits(gpio_od, gpio_to_bit(gpio));
  6202. + ltq_setbits(gpio_dir, gpio_to_bit(gpio));
  6203. + } else {
  6204. + ltq_clrbits(gpio_od, gpio_to_bit(gpio));
  6205. + ltq_clrbits(gpio_dir, gpio_to_bit(gpio));
  6206. + }
  6207. +
  6208. + return 0;
  6209. +}
  6210. +
  6211. +int gpio_set_opendrain(unsigned gpio, int od)
  6212. +{
  6213. + unsigned port = gpio_to_port(gpio);
  6214. + const void *gpio_od = &ltq_gpio_regs->ports[port].od;
  6215. +
  6216. + if (is_gpio_ssio(gpio))
  6217. + return 0;
  6218. +
  6219. + if (is_gpio_bank3(port))
  6220. + gpio_od = &ltq_gpio3_regs->od;
  6221. +
  6222. + if (od)
  6223. + ltq_setbits(gpio_od, gpio_to_bit(gpio));
  6224. + else
  6225. + ltq_clrbits(gpio_od, gpio_to_bit(gpio));
  6226. +
  6227. + return 0;
  6228. +}
  6229. --- a/drivers/mtd/cfi_flash.c
  6230. +++ b/drivers/mtd/cfi_flash.c
  6231. @@ -161,6 +161,18 @@ u64 flash_read64(void *addr)__attribute_
  6232. #define flash_read64 __flash_read64
  6233. #endif
  6234. +static inline void *__flash_swap_addr(unsigned long addr)
  6235. +{
  6236. + return (void *) addr;
  6237. +}
  6238. +
  6239. +#ifdef CONFIG_CFI_FLASH_USE_WEAK_ADDR_SWAP
  6240. +void *flash_swap_addr(unsigned long addr)
  6241. + __attribute__((weak, alias("__flash_swap_addr")));
  6242. +#else
  6243. +#define flash_swap_addr __flash_swap_addr
  6244. +#endif
  6245. +
  6246. /*-----------------------------------------------------------------------
  6247. */
  6248. #if defined(CONFIG_ENV_IS_IN_FLASH) || defined(CONFIG_ENV_ADDR_REDUND) || (CONFIG_SYS_MONITOR_BASE >= CONFIG_SYS_FLASH_BASE)
  6249. @@ -196,7 +208,7 @@ flash_map (flash_info_t * info, flash_se
  6250. {
  6251. unsigned int byte_offset = offset * info->portwidth;
  6252. - return (void *)(info->start[sect] + byte_offset);
  6253. + return flash_swap_addr(info->start[sect] + byte_offset);
  6254. }
  6255. static inline void flash_unmap(flash_info_t *info, flash_sect_t sect,
  6256. --- a/drivers/mtd/nand/Makefile
  6257. +++ b/drivers/mtd/nand/Makefile
  6258. @@ -53,6 +53,7 @@ COBJS-$(CONFIG_NAND_JZ4740) += jz4740_na
  6259. COBJS-$(CONFIG_NAND_KB9202) += kb9202_nand.o
  6260. COBJS-$(CONFIG_NAND_KIRKWOOD) += kirkwood_nand.o
  6261. COBJS-$(CONFIG_NAND_KMETER1) += kmeter1_nand.o
  6262. +COBJS-$(CONFIG_NAND_LANTIQ) += lantiq_nand.o
  6263. COBJS-$(CONFIG_NAND_MPC5121_NFC) += mpc5121_nfc.o
  6264. COBJS-$(CONFIG_NAND_MXC) += mxc_nand.o
  6265. COBJS-$(CONFIG_NAND_MXS) += mxs_nand.o
  6266. --- /dev/null
  6267. +++ b/drivers/mtd/nand/lantiq_nand.c
  6268. @@ -0,0 +1,126 @@
  6269. +/*
  6270. + * Copyright (C) 2012-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  6271. + *
  6272. + * SPDX-License-Identifier: GPL-2.0+
  6273. + */
  6274. +
  6275. +#include <common.h>
  6276. +#include <linux/mtd/nand.h>
  6277. +#include <linux/compiler.h>
  6278. +#include <asm/arch/soc.h>
  6279. +#include <asm/arch/nand.h>
  6280. +#include <asm/lantiq/io.h>
  6281. +
  6282. +#define NAND_CON_ECC_ON (1 << 31)
  6283. +#define NAND_CON_LATCH_PRE (1 << 23)
  6284. +#define NAND_CON_LATCH_WP (1 << 22)
  6285. +#define NAND_CON_LATCH_SE (1 << 21)
  6286. +#define NAND_CON_LATCH_CS (1 << 20)
  6287. +#define NAND_CON_LATCH_CLE (1 << 19)
  6288. +#define NAND_CON_LATCH_ALE (1 << 18)
  6289. +#define NAND_CON_OUT_CS1 (1 << 10)
  6290. +#define NAND_CON_IN_CS1 (1 << 8)
  6291. +#define NAND_CON_PRE_P (1 << 7)
  6292. +#define NAND_CON_WP_P (1 << 6)
  6293. +#define NAND_CON_SE_P (1 << 5)
  6294. +#define NAND_CON_CS_P (1 << 4)
  6295. +#define NAND_CON_CLE_P (1 << 3)
  6296. +#define NAND_CON_ALE_P (1 << 2)
  6297. +#define NAND_CON_CSMUX (1 << 1)
  6298. +#define NAND_CON_NANDM (1 << 0)
  6299. +
  6300. +#define NAND_WAIT_WR_C (1 << 3)
  6301. +#define NAND_WAIT_RDBY (1 << 0)
  6302. +
  6303. +#define NAND_CMD_ALE (1 << 2)
  6304. +#define NAND_CMD_CLE (1 << 3)
  6305. +#define NAND_CMD_CS (1 << 4)
  6306. +#define NAND_CMD_SE (1 << 5)
  6307. +#define NAND_CMD_WP (1 << 6)
  6308. +#define NAND_CMD_PRE (1 << 7)
  6309. +
  6310. +struct ltq_nand_regs {
  6311. + __be32 con; /* NAND controller control */
  6312. + __be32 wait; /* NAND Flash Device RD/BY State */
  6313. + __be32 ecc0; /* NAND Flash ECC Register 0 */
  6314. + __be32 ecc_ac; /* NAND Flash ECC Register address counter */
  6315. + __be32 ecc_cr; /* NAND Flash ECC Comparison */
  6316. +};
  6317. +
  6318. +static struct ltq_nand_regs *ltq_nand_regs =
  6319. + (struct ltq_nand_regs *) CKSEG1ADDR(LTQ_EBU_NAND_BASE);
  6320. +
  6321. +static void ltq_nand_wait_ready(void)
  6322. +{
  6323. + while ((ltq_readl(&ltq_nand_regs->wait) & NAND_WAIT_WR_C) == 0)
  6324. + ;
  6325. +}
  6326. +
  6327. +static int ltq_nand_dev_ready(struct mtd_info *mtd)
  6328. +{
  6329. + u32 data = ltq_readl(&ltq_nand_regs->wait);
  6330. + return data & NAND_WAIT_RDBY;
  6331. +}
  6332. +
  6333. +static void ltq_nand_select_chip(struct mtd_info *mtd, int chip)
  6334. +{
  6335. + if (chip == 0) {
  6336. + ltq_setbits(&ltq_nand_regs->con, NAND_CON_NANDM);
  6337. + ltq_setbits(&ltq_nand_regs->con, NAND_CON_LATCH_CS);
  6338. + } else {
  6339. + ltq_clrbits(&ltq_nand_regs->con, NAND_CON_LATCH_CS);
  6340. + ltq_clrbits(&ltq_nand_regs->con, NAND_CON_NANDM);
  6341. + }
  6342. +}
  6343. +
  6344. +static void ltq_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
  6345. +{
  6346. + struct nand_chip *chip = mtd->priv;
  6347. + unsigned long addr = (unsigned long) chip->IO_ADDR_W;
  6348. +
  6349. + if (ctrl & NAND_CTRL_CHANGE) {
  6350. + if (ctrl & NAND_ALE)
  6351. + addr |= NAND_CMD_ALE;
  6352. + else
  6353. + addr &= ~NAND_CMD_ALE;
  6354. +
  6355. + if (ctrl & NAND_CLE)
  6356. + addr |= NAND_CMD_CLE;
  6357. + else
  6358. + addr &= ~NAND_CMD_CLE;
  6359. +
  6360. + chip->IO_ADDR_W = (void __iomem *) addr;
  6361. + }
  6362. +
  6363. + if (cmd != NAND_CMD_NONE) {
  6364. + writeb(cmd, chip->IO_ADDR_W);
  6365. + ltq_nand_wait_ready();
  6366. + }
  6367. +}
  6368. +
  6369. +int ltq_nand_init(struct nand_chip *nand)
  6370. +{
  6371. + /* Enable NAND, set NAND CS to EBU CS1, enable EBU CS mux */
  6372. + ltq_writel(&ltq_nand_regs->con, NAND_CON_OUT_CS1 | NAND_CON_IN_CS1 |
  6373. + NAND_CON_PRE_P | NAND_CON_WP_P | NAND_CON_SE_P |
  6374. + NAND_CON_CS_P | NAND_CON_CSMUX);
  6375. +
  6376. + nand->dev_ready = ltq_nand_dev_ready;
  6377. + nand->select_chip = ltq_nand_select_chip;
  6378. + nand->cmd_ctrl = ltq_nand_cmd_ctrl;
  6379. +
  6380. + nand->chip_delay = 30;
  6381. + nand->options = 0;
  6382. + nand->ecc.mode = NAND_ECC_SOFT;
  6383. +
  6384. + /* Enable CS bit in address offset */
  6385. + nand->IO_ADDR_R = nand->IO_ADDR_R + NAND_CMD_CS;
  6386. + nand->IO_ADDR_W = nand->IO_ADDR_W + NAND_CMD_CS;
  6387. +
  6388. + return 0;
  6389. +}
  6390. +
  6391. +__weak int board_nand_init(struct nand_chip *chip)
  6392. +{
  6393. + return ltq_nand_init(chip);
  6394. +}
  6395. --- a/drivers/net/Makefile
  6396. +++ b/drivers/net/Makefile
  6397. @@ -37,6 +37,8 @@ COBJS-$(CONFIG_INCA_IP_SWITCH) += inca-i
  6398. COBJS-$(CONFIG_DRIVER_KS8695ETH) += ks8695eth.o
  6399. COBJS-$(CONFIG_KS8851_MLL) += ks8851_mll.o
  6400. COBJS-$(CONFIG_LAN91C96) += lan91c96.o
  6401. +COBJS-$(CONFIG_LANTIQ_DANUBE_ETOP) += lantiq_danube_etop.o
  6402. +COBJS-$(CONFIG_LANTIQ_VRX200_SWITCH) += lantiq_vrx200_switch.o
  6403. COBJS-$(CONFIG_MACB) += macb.o
  6404. COBJS-$(CONFIG_MCFFEC) += mcffec.o mcfmii.o
  6405. COBJS-$(CONFIG_MPC5xxx_FEC) += mpc5xxx_fec.o
  6406. --- /dev/null
  6407. +++ b/drivers/net/lantiq_danube_etop.c
  6408. @@ -0,0 +1,410 @@
  6409. +/*
  6410. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  6411. + *
  6412. + * SPDX-License-Identifier: GPL-2.0+
  6413. + */
  6414. +
  6415. +#include <common.h>
  6416. +#include <malloc.h>
  6417. +#include <netdev.h>
  6418. +#include <miiphy.h>
  6419. +#include <switch.h>
  6420. +#include <asm/lantiq/io.h>
  6421. +#include <asm/lantiq/eth.h>
  6422. +#include <asm/lantiq/pm.h>
  6423. +#include <asm/lantiq/reset.h>
  6424. +#include <asm/lantiq/dma.h>
  6425. +#include <asm/arch/soc.h>
  6426. +
  6427. +#define LTQ_PPE_ETOP_MDIO_ACC_RA (1 << 31)
  6428. +#define LTQ_PPE_ETOP_MDIO_CFG_UMM1 (1 << 2)
  6429. +#define LTQ_PPE_ETOP_MDIO_CFG_UMM0 (1 << 1)
  6430. +
  6431. +#define LTQ_PPE_ETOP_CFG_TCKINV1 (1 << 11)
  6432. +#define LTQ_PPE_ETOP_CFG_TCKINV0 (1 << 10)
  6433. +#define LTQ_PPE_ETOP_CFG_FEN1 (1 << 9)
  6434. +#define LTQ_PPE_ETOP_CFG_FEN0 (1 << 8)
  6435. +#define LTQ_PPE_ETOP_CFG_SEN1 (1 << 7)
  6436. +#define LTQ_PPE_ETOP_CFG_SEN0 (1 << 6)
  6437. +#define LTQ_PPE_ETOP_CFG_TURBO1 (1 << 5)
  6438. +#define LTQ_PPE_ETOP_CFG_REMII1 (1 << 4)
  6439. +#define LTQ_PPE_ETOP_CFG_OFF1 (1 << 3)
  6440. +#define LTQ_PPE_ETOP_CFG_TURBO0 (1 << 2)
  6441. +#define LTQ_PPE_ETOP_CFG_REMII0 (1 << 1)
  6442. +#define LTQ_PPE_ETOP_CFG_OFF0 (1 << 0)
  6443. +
  6444. +#define LTQ_PPE_ENET0_MAC_CFG_CGEN (1 << 11)
  6445. +#define LTQ_PPE_ENET0_MAC_CFG_DUPLEX (1 << 2)
  6446. +#define LTQ_PPE_ENET0_MAC_CFG_SPEED (1 << 1)
  6447. +#define LTQ_PPE_ENET0_MAC_CFG_LINK (1 << 0)
  6448. +
  6449. +#define LTQ_PPE_ENETS0_CFG_FTUC (1 << 28)
  6450. +
  6451. +#define LTQ_ETH_RX_BUFFER_CNT PKTBUFSRX
  6452. +#define LTQ_ETH_TX_BUFFER_CNT 8
  6453. +#define LTQ_ETH_RX_DATA_SIZE PKTSIZE_ALIGN
  6454. +#define LTQ_ETH_IP_ALIGN 2
  6455. +
  6456. +#define LTQ_MDIO_DRV_NAME "ltq-mdio"
  6457. +#define LTQ_ETH_DRV_NAME "ltq-eth"
  6458. +
  6459. +struct ltq_ppe_etop_regs {
  6460. + u32 mdio_cfg; /* MDIO configuration */
  6461. + u32 mdio_acc; /* MDIO access */
  6462. + u32 cfg; /* ETOP configuration */
  6463. + u32 ig_vlan_cos; /* IG VLAN priority CoS mapping */
  6464. + u32 ig_dscp_cos3; /* IG DSCP CoS mapping 3 */
  6465. + u32 ig_dscp_cos2; /* IG DSCP CoS mapping 2 */
  6466. + u32 ig_dscp_cos1; /* IG DSCP CoS mapping 1 */
  6467. + u32 ig_dscp_cos0; /* IG DSCP CoS mapping 0 */
  6468. + u32 ig_plen_ctrl; /* IG frame length control */
  6469. + u32 rsvd0[3];
  6470. + u32 vpid; /* VLAN protocol ID */
  6471. +};
  6472. +
  6473. +struct ltq_ppe_enet_regs {
  6474. + u32 mac_cfg; /* MAC configuration */
  6475. + u32 rsvd0[3];
  6476. + u32 ig_cfg; /* Ingress configuration */
  6477. + u32 ig_pgcnt; /* Ingress buffer used page count */
  6478. + u32 rsvd1;
  6479. + u32 ig_buf_ctrl; /* Ingress buffer backpressure ctrl */
  6480. + u32 cos_cfg; /* Classification configuration */
  6481. + u32 ig_drop; /* Total ingress drop frames */
  6482. + u32 ig_err; /* Total ingress error frames */
  6483. + u32 mac_da0; /* Ingress MAC address 0 */
  6484. + u32 mac_da1; /* Ingress MAC address 1 */
  6485. + u32 rsvd2[22];
  6486. + u32 pgcnt; /* Page counter */
  6487. + u32 rsvd3;
  6488. + u32 hf_ctrl; /* Half duplex control */
  6489. + u32 tx_ctrl; /* Transmit control */
  6490. + u32 rsvd4;
  6491. + u32 vlcos0; /* VLAN insertion config CoS 0 */
  6492. + u32 vlcos1; /* VLAN insertion config CoS 1 */
  6493. + u32 vlcos2; /* VLAN insertion config CoS 2 */
  6494. + u32 vlcos3; /* VLAN insertion config CoS 3 */
  6495. + u32 eg_col; /* Total egress collision frames */
  6496. + u32 eg_drop; /* Total egress drop frames */
  6497. +};
  6498. +
  6499. +struct ltq_eth_priv {
  6500. + struct ltq_dma_device dma_dev;
  6501. + struct mii_dev *bus;
  6502. + struct eth_device *dev;
  6503. + int rx_num;
  6504. + int tx_num;
  6505. +};
  6506. +
  6507. +struct ltq_mdio_access {
  6508. + union {
  6509. + struct {
  6510. + unsigned ra:1;
  6511. + unsigned rw:1;
  6512. + unsigned rsvd:4;
  6513. + unsigned phya:5;
  6514. + unsigned rega:5;
  6515. + unsigned phyd:16;
  6516. + } reg;
  6517. + u32 val;
  6518. + };
  6519. +};
  6520. +
  6521. +static struct ltq_ppe_etop_regs *ltq_ppe_etop_regs =
  6522. + (struct ltq_ppe_etop_regs *) CKSEG1ADDR(LTQ_PPE_ETOP_BASE);
  6523. +
  6524. +static struct ltq_ppe_enet_regs *ltq_ppe_enet0_regs =
  6525. + (struct ltq_ppe_enet_regs *) CKSEG1ADDR(LTQ_PPE_ENET0_BASE);
  6526. +
  6527. +static inline int ltq_mdio_poll(void)
  6528. +{
  6529. + struct ltq_mdio_access acc;
  6530. + unsigned cnt = 10000;
  6531. +
  6532. + while (likely(cnt--)) {
  6533. + acc.val = ltq_readl(&ltq_ppe_etop_regs->mdio_acc);
  6534. + if (!acc.reg.ra)
  6535. + return 0;
  6536. + }
  6537. +
  6538. + return 1;
  6539. +}
  6540. +
  6541. +static int ltq_mdio_read(struct mii_dev *bus, int addr, int dev_addr,
  6542. + int regnum)
  6543. +{
  6544. + struct ltq_mdio_access acc;
  6545. + int ret;
  6546. +
  6547. + acc.val = 0;
  6548. + acc.reg.ra = 1;
  6549. + acc.reg.rw = 1;
  6550. + acc.reg.phya = addr;
  6551. + acc.reg.rega = regnum;
  6552. +
  6553. + ret = ltq_mdio_poll();
  6554. + if (ret)
  6555. + return ret;
  6556. +
  6557. + ltq_writel(&ltq_ppe_etop_regs->mdio_acc, acc.val);
  6558. +
  6559. + ret = ltq_mdio_poll();
  6560. + if (ret)
  6561. + return ret;
  6562. +
  6563. + acc.val = ltq_readl(&ltq_ppe_etop_regs->mdio_acc);
  6564. +
  6565. + return acc.reg.phyd;
  6566. +}
  6567. +
  6568. +static int ltq_mdio_write(struct mii_dev *bus, int addr, int dev_addr,
  6569. + int regnum, u16 val)
  6570. +{
  6571. + struct ltq_mdio_access acc;
  6572. + int ret;
  6573. +
  6574. + acc.val = 0;
  6575. + acc.reg.ra = 1;
  6576. + acc.reg.rw = 0;
  6577. + acc.reg.phya = addr;
  6578. + acc.reg.rega = regnum;
  6579. + acc.reg.phyd = val;
  6580. +
  6581. + ret = ltq_mdio_poll();
  6582. + if (ret)
  6583. + return ret;
  6584. +
  6585. + ltq_writel(&ltq_ppe_etop_regs->mdio_acc, acc.val);
  6586. +
  6587. + return 0;
  6588. +}
  6589. +
  6590. +static inline void ltq_eth_write_hwaddr(const struct eth_device *dev)
  6591. +{
  6592. + u32 da0, da1;
  6593. +
  6594. + da0 = (dev->enetaddr[0] << 24) + (dev->enetaddr[1] << 16) +
  6595. + (dev->enetaddr[2] << 8) + dev->enetaddr[3];
  6596. + da1 = (dev->enetaddr[4] << 24) + (dev->enetaddr[5] << 16);
  6597. +
  6598. + ltq_writel(&ltq_ppe_enet0_regs->mac_da0, da0);
  6599. + ltq_writel(&ltq_ppe_enet0_regs->mac_da1, da1);
  6600. +}
  6601. +
  6602. +static inline u8 *ltq_eth_rx_packet_align(int rx_num)
  6603. +{
  6604. + u8 *packet = (u8 *) NetRxPackets[rx_num];
  6605. +
  6606. + /*
  6607. + * IP header needs
  6608. + */
  6609. + return packet + LTQ_ETH_IP_ALIGN;
  6610. +}
  6611. +
  6612. +static int ltq_eth_init(struct eth_device *dev, bd_t *bis)
  6613. +{
  6614. + struct ltq_eth_priv *priv = dev->priv;
  6615. + struct ltq_dma_device *dma_dev = &priv->dma_dev;
  6616. + int i;
  6617. +
  6618. + ltq_eth_write_hwaddr(dev);
  6619. +
  6620. + for (i = 0; i < LTQ_ETH_RX_BUFFER_CNT; i++)
  6621. + ltq_dma_rx_map(dma_dev, i, ltq_eth_rx_packet_align(i),
  6622. + LTQ_ETH_RX_DATA_SIZE);
  6623. +
  6624. + ltq_dma_enable(dma_dev);
  6625. +
  6626. + priv->rx_num = 0;
  6627. + priv->tx_num = 0;
  6628. +
  6629. + return 0;
  6630. +}
  6631. +
  6632. +static void ltq_eth_halt(struct eth_device *dev)
  6633. +{
  6634. + struct ltq_eth_priv *priv = dev->priv;
  6635. + struct ltq_dma_device *dma_dev = &priv->dma_dev;
  6636. +
  6637. + ltq_dma_reset(dma_dev);
  6638. +}
  6639. +
  6640. +static int ltq_eth_send(struct eth_device *dev, void *packet, int length)
  6641. +{
  6642. + struct ltq_eth_priv *priv = dev->priv;
  6643. + struct ltq_dma_device *dma_dev = &priv->dma_dev;
  6644. + int err;
  6645. +
  6646. + /* Minimum payload length w/ CRC is 60 bytes */
  6647. + if (length < 60)
  6648. + length = 60;
  6649. +
  6650. + err = ltq_dma_tx_map(dma_dev, priv->tx_num, packet, length, 10);
  6651. + if (err) {
  6652. + puts("NET: timeout on waiting for TX descriptor\n");
  6653. + return -1;
  6654. + }
  6655. +
  6656. + priv->tx_num = (priv->tx_num + 1) % LTQ_ETH_TX_BUFFER_CNT;
  6657. +
  6658. + return err;
  6659. +}
  6660. +
  6661. +static int ltq_eth_recv(struct eth_device *dev)
  6662. +{
  6663. + struct ltq_eth_priv *priv = dev->priv;
  6664. + struct ltq_dma_device *dma_dev = &priv->dma_dev;
  6665. + u8 *packet;
  6666. + int len;
  6667. +
  6668. + if (!ltq_dma_rx_poll(dma_dev, priv->rx_num))
  6669. + return 0;
  6670. +
  6671. +#if 0
  6672. + printf("%s: rx_num %d\n", __func__, priv->rx_num);
  6673. +#endif
  6674. +
  6675. + len = ltq_dma_rx_length(dma_dev, priv->rx_num);
  6676. + packet = ltq_eth_rx_packet_align(priv->rx_num);
  6677. +
  6678. +#if 0
  6679. + printf("%s: received: packet %p, len %u, rx_num %d\n",
  6680. + __func__, packet, len, priv->rx_num);
  6681. +#endif
  6682. +
  6683. + if (len)
  6684. + NetReceive(packet, len);
  6685. +
  6686. + ltq_dma_rx_map(dma_dev, priv->rx_num, packet,
  6687. + LTQ_ETH_RX_DATA_SIZE);
  6688. +
  6689. + priv->rx_num = (priv->rx_num + 1) % LTQ_ETH_RX_BUFFER_CNT;
  6690. +
  6691. + return 0;
  6692. +}
  6693. +
  6694. +static void ltq_eth_hw_init(const struct ltq_eth_port_config *port)
  6695. +{
  6696. + u32 data;
  6697. +
  6698. + /* Power up ethernet subsystems */
  6699. + ltq_pm_enable(LTQ_PM_ETH);
  6700. +
  6701. + /* Reset ethernet subsystems */
  6702. + ltq_reset_once(LTQ_RESET_ETH, 1);
  6703. +
  6704. + /* Disable MDIO auto-detection */
  6705. + ltq_clrbits(&ltq_ppe_etop_regs->mdio_cfg, LTQ_PPE_ETOP_MDIO_CFG_UMM1 |
  6706. + LTQ_PPE_ETOP_MDIO_CFG_UMM0);
  6707. +
  6708. + /* Enable CRC generation, Full Duplex, 100Mbps, Link up */
  6709. + ltq_writel(&ltq_ppe_enet0_regs->mac_cfg, LTQ_PPE_ENET0_MAC_CFG_CGEN |
  6710. + LTQ_PPE_ENET0_MAC_CFG_DUPLEX |
  6711. + LTQ_PPE_ENET0_MAC_CFG_SPEED |
  6712. + LTQ_PPE_ENET0_MAC_CFG_LINK);
  6713. +
  6714. + /* Reset ETOP cfg and disable all */
  6715. + data = LTQ_PPE_ETOP_CFG_OFF0 | LTQ_PPE_ETOP_CFG_OFF1;
  6716. +
  6717. + /* Enable ENET0, enable store and fetch */
  6718. + data &= ~LTQ_PPE_ETOP_CFG_OFF0;
  6719. + data |= LTQ_PPE_ETOP_CFG_SEN0 | LTQ_PPE_ETOP_CFG_FEN0;
  6720. +
  6721. + if (port->phy_if == PHY_INTERFACE_MODE_RMII)
  6722. + data |= LTQ_PPE_ETOP_CFG_REMII0;
  6723. + else
  6724. + data &= ~LTQ_PPE_ETOP_CFG_REMII0;
  6725. +
  6726. + ltq_writel(&ltq_ppe_etop_regs->cfg, data);
  6727. +
  6728. + /* Set allowed packet length from 64 bytes to 1518 bytes */
  6729. + ltq_writel(&ltq_ppe_etop_regs->ig_plen_ctrl, (64 << 16) | 1518);
  6730. +
  6731. + /* Enable filter for unicast packets */
  6732. + ltq_setbits(&ltq_ppe_enet0_regs->ig_cfg, LTQ_PPE_ENETS0_CFG_FTUC);
  6733. +}
  6734. +
  6735. +int ltq_eth_initialize(const struct ltq_eth_board_config *board_config)
  6736. +{
  6737. + struct eth_device *dev;
  6738. + struct mii_dev *bus;
  6739. + struct ltq_eth_priv *priv;
  6740. + struct ltq_dma_device *dma_dev;
  6741. + const struct ltq_eth_port_config *port = &board_config->ports[0];
  6742. + struct phy_device *phy;
  6743. + struct switch_device *sw;
  6744. + int ret;
  6745. +
  6746. + ltq_dma_init();
  6747. + ltq_eth_hw_init(port);
  6748. +
  6749. + dev = calloc(1, sizeof(*dev));
  6750. + if (!dev)
  6751. + return -1;
  6752. +
  6753. + priv = calloc(1, sizeof(*priv));
  6754. + if (!priv)
  6755. + return -1;
  6756. +
  6757. + bus = mdio_alloc();
  6758. + if (!bus)
  6759. + return -1;
  6760. +
  6761. + sprintf(dev->name, LTQ_ETH_DRV_NAME);
  6762. + dev->priv = priv;
  6763. + dev->init = ltq_eth_init;
  6764. + dev->halt = ltq_eth_halt;
  6765. + dev->recv = ltq_eth_recv;
  6766. + dev->send = ltq_eth_send;
  6767. +
  6768. + sprintf(bus->name, LTQ_MDIO_DRV_NAME);
  6769. + bus->read = ltq_mdio_read;
  6770. + bus->write = ltq_mdio_write;
  6771. + bus->priv = priv;
  6772. +
  6773. + dma_dev = &priv->dma_dev;
  6774. + dma_dev->port = 0;
  6775. + dma_dev->rx_chan.chan_no = 6;
  6776. + dma_dev->rx_chan.class = 3;
  6777. + dma_dev->rx_chan.num_desc = LTQ_ETH_RX_BUFFER_CNT;
  6778. + dma_dev->rx_endian_swap = LTQ_DMA_ENDIANESS_B3_B2_B1_B0;
  6779. + dma_dev->rx_burst_len = LTQ_DMA_BURST_2WORDS;
  6780. + dma_dev->tx_chan.chan_no = 7;
  6781. + dma_dev->tx_chan.class = 3;
  6782. + dma_dev->tx_chan.num_desc = LTQ_ETH_TX_BUFFER_CNT;
  6783. + dma_dev->tx_endian_swap = LTQ_DMA_ENDIANESS_B3_B2_B1_B0;
  6784. + dma_dev->tx_burst_len = LTQ_DMA_BURST_2WORDS;
  6785. +
  6786. + priv->bus = bus;
  6787. + priv->dev = dev;
  6788. +
  6789. + ret = ltq_dma_register(dma_dev);
  6790. + if (ret)
  6791. + return ret;
  6792. +
  6793. + ret = mdio_register(bus);
  6794. + if (ret)
  6795. + return ret;
  6796. +
  6797. + ret = eth_register(dev);
  6798. + if (ret)
  6799. + return ret;
  6800. +
  6801. + if (port->flags & LTQ_ETH_PORT_SWITCH) {
  6802. + sw = switch_connect(bus);
  6803. + if (!sw)
  6804. + return -1;
  6805. +
  6806. + switch_setup(sw);
  6807. + }
  6808. +
  6809. + if (port->flags & LTQ_ETH_PORT_PHY) {
  6810. + phy = phy_connect(bus, port->phy_addr, dev, port->phy_if);
  6811. + if (!phy)
  6812. + return -1;
  6813. +
  6814. + phy_config(phy);
  6815. + }
  6816. +
  6817. + return 0;
  6818. +}
  6819. --- /dev/null
  6820. +++ b/drivers/net/lantiq_vrx200_switch.c
  6821. @@ -0,0 +1,675 @@
  6822. +/*
  6823. + * Copyright (C) 2010-2011 Lantiq Deutschland GmbH
  6824. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  6825. + *
  6826. + * SPDX-License-Identifier: GPL-2.0+
  6827. + */
  6828. +
  6829. +#define DEBUG
  6830. +
  6831. +#include <common.h>
  6832. +#include <malloc.h>
  6833. +#include <netdev.h>
  6834. +#include <miiphy.h>
  6835. +#include <linux/compiler.h>
  6836. +#include <asm/gpio.h>
  6837. +#include <asm/processor.h>
  6838. +#include <asm/lantiq/io.h>
  6839. +#include <asm/lantiq/eth.h>
  6840. +#include <asm/lantiq/pm.h>
  6841. +#include <asm/lantiq/reset.h>
  6842. +#include <asm/lantiq/dma.h>
  6843. +#include <asm/arch/soc.h>
  6844. +#include <asm/arch/switch.h>
  6845. +
  6846. +#define LTQ_ETH_RX_BUFFER_CNT PKTBUFSRX
  6847. +#define LTQ_ETH_TX_BUFFER_CNT 8
  6848. +#define LTQ_ETH_RX_DATA_SIZE PKTSIZE_ALIGN
  6849. +#define LTQ_ETH_IP_ALIGN 2
  6850. +
  6851. +#define LTQ_MDIO_DRV_NAME "ltq-mdio"
  6852. +#define LTQ_ETH_DRV_NAME "ltq-eth"
  6853. +
  6854. +#define LTQ_ETHSW_MAX_GMAC 6
  6855. +#define LTQ_ETHSW_PMAC 6
  6856. +
  6857. +struct ltq_mdio_phy_addr_reg {
  6858. + union {
  6859. + struct {
  6860. + unsigned rsvd:1;
  6861. + unsigned lnkst:2; /* Link status control */
  6862. + unsigned speed:2; /* Speed control */
  6863. + unsigned fdup:2; /* Full duplex control */
  6864. + unsigned fcontx:2; /* Flow control mode TX */
  6865. + unsigned fconrx:2; /* Flow control mode RX */
  6866. + unsigned addr:5; /* PHY address */
  6867. + } bits;
  6868. + u16 val;
  6869. + };
  6870. +};
  6871. +
  6872. +enum ltq_mdio_phy_addr_lnkst {
  6873. + LTQ_MDIO_PHY_ADDR_LNKST_AUTO = 0,
  6874. + LTQ_MDIO_PHY_ADDR_LNKST_UP = 1,
  6875. + LTQ_MDIO_PHY_ADDR_LNKST_DOWN = 2,
  6876. +};
  6877. +
  6878. +enum ltq_mdio_phy_addr_speed {
  6879. + LTQ_MDIO_PHY_ADDR_SPEED_M10 = 0,
  6880. + LTQ_MDIO_PHY_ADDR_SPEED_M100 = 1,
  6881. + LTQ_MDIO_PHY_ADDR_SPEED_G1 = 2,
  6882. + LTQ_MDIO_PHY_ADDR_SPEED_AUTO = 3,
  6883. +};
  6884. +
  6885. +enum ltq_mdio_phy_addr_fdup {
  6886. + LTQ_MDIO_PHY_ADDR_FDUP_AUTO = 0,
  6887. + LTQ_MDIO_PHY_ADDR_FDUP_ENABLE = 1,
  6888. + LTQ_MDIO_PHY_ADDR_FDUP_DISABLE = 3,
  6889. +};
  6890. +
  6891. +enum ltq_mdio_phy_addr_fcon {
  6892. + LTQ_MDIO_PHY_ADDR_FCON_AUTO = 0,
  6893. + LTQ_MDIO_PHY_ADDR_FCON_ENABLE = 1,
  6894. + LTQ_MDIO_PHY_ADDR_FCON_DISABLE = 3,
  6895. +};
  6896. +
  6897. +struct ltq_mii_mii_cfg_reg {
  6898. + union {
  6899. + struct {
  6900. + unsigned res:1; /* Hardware reset */
  6901. + unsigned en:1; /* xMII interface enable */
  6902. + unsigned isol:1; /* xMII interface isolate */
  6903. + unsigned ldclkdis:1; /* Link down clock disable */
  6904. + unsigned rsvd:1;
  6905. + unsigned crs:2; /* CRS sensitivity config */
  6906. + unsigned rgmii_ibs:1; /* RGMII In Band status */
  6907. + unsigned rmii:1; /* RMII ref clock direction */
  6908. + unsigned miirate:3; /* xMII interface clock rate */
  6909. + unsigned miimode:4; /* xMII interface mode */
  6910. + } bits;
  6911. + u16 val;
  6912. + };
  6913. +};
  6914. +
  6915. +enum ltq_mii_mii_cfg_miirate {
  6916. + LTQ_MII_MII_CFG_MIIRATE_M2P5 = 0,
  6917. + LTQ_MII_MII_CFG_MIIRATE_M25 = 1,
  6918. + LTQ_MII_MII_CFG_MIIRATE_M125 = 2,
  6919. + LTQ_MII_MII_CFG_MIIRATE_M50 = 3,
  6920. + LTQ_MII_MII_CFG_MIIRATE_AUTO = 4,
  6921. +};
  6922. +
  6923. +enum ltq_mii_mii_cfg_miimode {
  6924. + LTQ_MII_MII_CFG_MIIMODE_MIIP = 0,
  6925. + LTQ_MII_MII_CFG_MIIMODE_MIIM = 1,
  6926. + LTQ_MII_MII_CFG_MIIMODE_RMIIP = 2,
  6927. + LTQ_MII_MII_CFG_MIIMODE_RMIIM = 3,
  6928. + LTQ_MII_MII_CFG_MIIMODE_RGMII = 4,
  6929. +};
  6930. +
  6931. +struct ltq_eth_priv {
  6932. + struct ltq_dma_device dma_dev;
  6933. + struct mii_dev *bus;
  6934. + struct eth_device *dev;
  6935. + struct phy_device *phymap[LTQ_ETHSW_MAX_GMAC];
  6936. + int rx_num;
  6937. + int tx_num;
  6938. +};
  6939. +
  6940. +static struct vr9_switch_regs *switch_regs =
  6941. + (struct vr9_switch_regs *) CKSEG1ADDR(LTQ_SWITCH_BASE);
  6942. +
  6943. +static inline void vr9_switch_sync(void)
  6944. +{
  6945. + __asm__("sync");
  6946. +}
  6947. +
  6948. +static inline int vr9_switch_mdio_is_busy(void)
  6949. +{
  6950. + u32 mdio_ctrl = ltq_readl(&switch_regs->mdio.mdio_ctrl);
  6951. +
  6952. + return mdio_ctrl & MDIO_CTRL_MBUSY;
  6953. +}
  6954. +
  6955. +static inline void vr9_switch_mdio_poll(void)
  6956. +{
  6957. + while (vr9_switch_mdio_is_busy())
  6958. + cpu_relax();
  6959. +}
  6960. +
  6961. +static int vr9_switch_mdio_read(struct mii_dev *bus, int phyad, int devad,
  6962. + int regad)
  6963. +{
  6964. + u32 mdio_ctrl;
  6965. + int retval;
  6966. +
  6967. + mdio_ctrl = MDIO_CTRL_OP_READ |
  6968. + ((phyad << MDIO_CTRL_PHYAD_SHIFT) & MDIO_CTRL_PHYAD_MASK) |
  6969. + (regad & MDIO_CTRL_REGAD_MASK);
  6970. +
  6971. + vr9_switch_mdio_poll();
  6972. + ltq_writel(&switch_regs->mdio.mdio_ctrl, mdio_ctrl);
  6973. + vr9_switch_mdio_poll();
  6974. + retval = ltq_readl(&switch_regs->mdio.mdio_read);
  6975. +
  6976. + return retval;
  6977. +}
  6978. +
  6979. +static int vr9_switch_mdio_write(struct mii_dev *bus, int phyad, int devad,
  6980. + int regad, u16 val)
  6981. +{
  6982. + u32 mdio_ctrl;
  6983. +
  6984. + mdio_ctrl = MDIO_CTRL_OP_WRITE |
  6985. + ((phyad << MDIO_CTRL_PHYAD_SHIFT) & MDIO_CTRL_PHYAD_MASK) |
  6986. + (regad & MDIO_CTRL_REGAD_MASK);
  6987. +
  6988. + vr9_switch_mdio_poll();
  6989. + ltq_writel(&switch_regs->mdio.mdio_write, val);
  6990. + ltq_writel(&switch_regs->mdio.mdio_ctrl, mdio_ctrl);
  6991. +
  6992. + return 0;
  6993. +}
  6994. +
  6995. +static void ltq_eth_gmac_update(struct phy_device *phydev, int num)
  6996. +{
  6997. + struct ltq_mdio_phy_addr_reg phy_addr_reg;
  6998. + struct ltq_mii_mii_cfg_reg mii_cfg_reg;
  6999. +
  7000. + phy_addr_reg.val = ltq_readl(to_mdio_phyaddr(switch_regs, num));
  7001. +
  7002. + switch (num) {
  7003. + case 0:
  7004. + case 1:
  7005. + case 5:
  7006. + mii_cfg_reg.val = ltq_readl(to_mii_miicfg(switch_regs, num));
  7007. + break;
  7008. + default:
  7009. + mii_cfg_reg.val = 0;
  7010. + break;
  7011. + }
  7012. +
  7013. + phy_addr_reg.bits.addr = phydev->addr;
  7014. +
  7015. + if (phydev->link)
  7016. + phy_addr_reg.bits.lnkst = LTQ_MDIO_PHY_ADDR_LNKST_UP;
  7017. + else
  7018. + phy_addr_reg.bits.lnkst = LTQ_MDIO_PHY_ADDR_LNKST_DOWN;
  7019. +
  7020. + switch (phydev->speed) {
  7021. + case SPEED_1000:
  7022. + phy_addr_reg.bits.speed = LTQ_MDIO_PHY_ADDR_SPEED_G1;
  7023. + mii_cfg_reg.bits.miirate = LTQ_MII_MII_CFG_MIIRATE_M125;
  7024. + break;
  7025. + case SPEED_100:
  7026. + phy_addr_reg.bits.speed = LTQ_MDIO_PHY_ADDR_SPEED_M100;
  7027. + switch (mii_cfg_reg.bits.miimode) {
  7028. + case LTQ_MII_MII_CFG_MIIMODE_RMIIM:
  7029. + case LTQ_MII_MII_CFG_MIIMODE_RMIIP:
  7030. + mii_cfg_reg.bits.miirate = LTQ_MII_MII_CFG_MIIRATE_M50;
  7031. + break;
  7032. + default:
  7033. + mii_cfg_reg.bits.miirate = LTQ_MII_MII_CFG_MIIRATE_M25;
  7034. + break;
  7035. + }
  7036. + break;
  7037. + default:
  7038. + phy_addr_reg.bits.speed = LTQ_MDIO_PHY_ADDR_SPEED_M10;
  7039. + mii_cfg_reg.bits.miirate = LTQ_MII_MII_CFG_MIIRATE_M2P5;
  7040. + break;
  7041. + }
  7042. +
  7043. + if (phydev->duplex == DUPLEX_FULL)
  7044. + phy_addr_reg.bits.fdup = LTQ_MDIO_PHY_ADDR_FDUP_ENABLE;
  7045. + else
  7046. + phy_addr_reg.bits.fdup = LTQ_MDIO_PHY_ADDR_FDUP_DISABLE;
  7047. +
  7048. + ltq_writel(to_mdio_phyaddr(switch_regs, num), phy_addr_reg.val);
  7049. +
  7050. + switch (num) {
  7051. + case 0:
  7052. + case 1:
  7053. + case 5:
  7054. + ltq_writel(to_mii_miicfg(switch_regs, num), mii_cfg_reg.val);
  7055. + break;
  7056. + default:
  7057. + break;
  7058. + }
  7059. +}
  7060. +
  7061. +static inline u8 *ltq_eth_rx_packet_align(int rx_num)
  7062. +{
  7063. + u8 *packet = (u8 *) NetRxPackets[rx_num];
  7064. +
  7065. + /*
  7066. + * IP header needs
  7067. + */
  7068. + return packet + LTQ_ETH_IP_ALIGN;
  7069. +}
  7070. +
  7071. +static int ltq_eth_init(struct eth_device *dev, bd_t *bis)
  7072. +{
  7073. + struct ltq_eth_priv *priv = dev->priv;
  7074. + struct ltq_dma_device *dma_dev = &priv->dma_dev;
  7075. + struct phy_device *phydev;
  7076. + int i;
  7077. +
  7078. + for (i = 0; i < LTQ_ETHSW_MAX_GMAC; i++) {
  7079. + phydev = priv->phymap[i];
  7080. + if (!phydev)
  7081. + continue;
  7082. +
  7083. + phy_startup(phydev);
  7084. + ltq_eth_gmac_update(phydev, i);
  7085. + }
  7086. +
  7087. + for (i = 0; i < LTQ_ETH_RX_BUFFER_CNT; i++)
  7088. + ltq_dma_rx_map(dma_dev, i, ltq_eth_rx_packet_align(i),
  7089. + LTQ_ETH_RX_DATA_SIZE);
  7090. +
  7091. + ltq_dma_enable(dma_dev);
  7092. +
  7093. + priv->rx_num = 0;
  7094. + priv->tx_num = 0;
  7095. +
  7096. + return 0;
  7097. +}
  7098. +
  7099. +static void ltq_eth_halt(struct eth_device *dev)
  7100. +{
  7101. + struct ltq_eth_priv *priv = dev->priv;
  7102. + struct ltq_dma_device *dma_dev = &priv->dma_dev;
  7103. + struct phy_device *phydev;
  7104. + int i;
  7105. +
  7106. + ltq_dma_reset(dma_dev);
  7107. +
  7108. + for (i = 0; i < LTQ_ETHSW_MAX_GMAC; i++) {
  7109. + phydev = priv->phymap[i];
  7110. + if (!phydev)
  7111. + continue;
  7112. +
  7113. + phy_shutdown(phydev);
  7114. + phydev->link = 0;
  7115. + ltq_eth_gmac_update(phydev, i);
  7116. + }
  7117. +}
  7118. +
  7119. +static int ltq_eth_send(struct eth_device *dev, void *packet, int length)
  7120. +{
  7121. + struct ltq_eth_priv *priv = dev->priv;
  7122. + struct ltq_dma_device *dma_dev = &priv->dma_dev;
  7123. +
  7124. +#if 0
  7125. + printf("%s: packet %p, len %d\n", __func__, packet, length);
  7126. +#endif
  7127. +
  7128. + ltq_dma_tx_map(dma_dev, priv->tx_num, packet, length, 10);
  7129. + priv->tx_num = (priv->tx_num + 1) % LTQ_ETH_TX_BUFFER_CNT;
  7130. +
  7131. + return 0;
  7132. +}
  7133. +
  7134. +static int ltq_eth_recv(struct eth_device *dev)
  7135. +{
  7136. + struct ltq_eth_priv *priv = dev->priv;
  7137. + struct ltq_dma_device *dma_dev = &priv->dma_dev;
  7138. + u8 *packet;
  7139. + int len;
  7140. +
  7141. + if (!ltq_dma_rx_poll(dma_dev, priv->rx_num))
  7142. + return 0;
  7143. +
  7144. +#if 0
  7145. + printf("%s: rx_num %d\n", __func__, priv->rx_num);
  7146. +#endif
  7147. +
  7148. + len = ltq_dma_rx_length(dma_dev, priv->rx_num);
  7149. + packet = ltq_eth_rx_packet_align(priv->rx_num);
  7150. +
  7151. +#if 0
  7152. + printf("%s: received: packet %p, len %u, rx_num %d\n",
  7153. + __func__, packet, len, priv->rx_num);
  7154. +#endif
  7155. +
  7156. + if (len)
  7157. + NetReceive(packet, len);
  7158. +
  7159. + ltq_dma_rx_map(dma_dev, priv->rx_num, packet,
  7160. + LTQ_ETH_RX_DATA_SIZE);
  7161. +
  7162. + priv->rx_num = (priv->rx_num + 1) % LTQ_ETH_RX_BUFFER_CNT;
  7163. +
  7164. + return 0;
  7165. +}
  7166. +
  7167. +static void ltq_eth_gmac_init(int num)
  7168. +{
  7169. + struct ltq_mdio_phy_addr_reg phy_addr_reg;
  7170. + struct ltq_mii_mii_cfg_reg mii_cfg_reg;
  7171. +
  7172. + /* Reset PHY status to link down */
  7173. + phy_addr_reg.val = ltq_readl(to_mdio_phyaddr(switch_regs, num));
  7174. + phy_addr_reg.bits.addr = num;
  7175. + phy_addr_reg.bits.lnkst = LTQ_MDIO_PHY_ADDR_LNKST_DOWN;
  7176. + phy_addr_reg.bits.speed = LTQ_MDIO_PHY_ADDR_SPEED_M10;
  7177. + phy_addr_reg.bits.fdup = LTQ_MDIO_PHY_ADDR_FDUP_DISABLE;
  7178. + ltq_writel(to_mdio_phyaddr(switch_regs, num), phy_addr_reg.val);
  7179. +
  7180. + /* Reset and disable MII interface */
  7181. + switch (num) {
  7182. + case 0:
  7183. + case 1:
  7184. + case 5:
  7185. + mii_cfg_reg.val = ltq_readl(to_mii_miicfg(switch_regs, num));
  7186. + mii_cfg_reg.bits.en = 0;
  7187. + mii_cfg_reg.bits.res = 1;
  7188. + mii_cfg_reg.bits.miirate = LTQ_MII_MII_CFG_MIIRATE_M2P5;
  7189. + ltq_writel(to_mii_miicfg(switch_regs, num), mii_cfg_reg.val);
  7190. + break;
  7191. + default:
  7192. + break;
  7193. + }
  7194. +
  7195. + /*
  7196. + * - enable frame checksum generation
  7197. + * - enable padding of short frames
  7198. + * - disable flow control
  7199. + */
  7200. + ltq_writel(to_mac_ctrl(switch_regs, num, 0),
  7201. + MAC_CTRL0_PADEN | MAC_CTRL0_FCS | MAC_CTRL0_FCON_NONE);
  7202. +
  7203. + vr9_switch_sync();
  7204. +}
  7205. +
  7206. +static void ltq_eth_pmac_init(void)
  7207. +{
  7208. + /*
  7209. + * WAR: buffer congestion:
  7210. + * - shorten preambel to 1 byte
  7211. + * - set TX IPG to 7 bytes
  7212. + */
  7213. +#if 1
  7214. + ltq_writel(to_mac_ctrl(switch_regs, LTQ_ETHSW_PMAC, 1),
  7215. + MAC_CTRL1_SHORTPRE | 7);
  7216. +#endif
  7217. +
  7218. + /*
  7219. + * WAR: systematical concept weakness ACM bug
  7220. + * - set maximum number of used buffer segments to 254
  7221. + * - soft-reset BM FSQM
  7222. + */
  7223. +#if 1
  7224. + ltq_writel(&switch_regs->bm.core.fsqm_gctrl, 253);
  7225. + ltq_setbits(&switch_regs->bm.core.gctrl, BM_GCTRL_F_SRES);
  7226. + ltq_clrbits(&switch_regs->bm.core.gctrl, BM_GCTRL_F_SRES);
  7227. +#endif
  7228. +
  7229. + /*
  7230. + * WAR: switch MAC drop bug
  7231. + */
  7232. +#if 1
  7233. + ltq_writel(to_pce_tbl_key(switch_regs, 0), 0xf);
  7234. + ltq_writel(to_pce_tbl_value(switch_regs, 0), 0x40);
  7235. + ltq_writel(&switch_regs->pce.core.tbl_addr, 0x3);
  7236. + ltq_writel(&switch_regs->pce.core.tbl_ctrl, 0x902f);
  7237. +#endif
  7238. +
  7239. + /*
  7240. + * Configure frame header control:
  7241. + * - enable flow control
  7242. + * - enable CRC check for packets from DMA to PMAC
  7243. + * - remove special tag from packets from PMAC to DMA
  7244. + * - add CRC for packets from DMA to PMAC
  7245. + */
  7246. + ltq_writel(&switch_regs->pmac.hd_ctl, /*PMAC_HD_CTL_FC |*/
  7247. + PMAC_HD_CTL_CCRC | PMAC_HD_CTL_RST | PMAC_HD_CTL_AC |
  7248. + PMAC_HD_CTL_RC);
  7249. +
  7250. +#if 1
  7251. + ltq_writel(&switch_regs->pmac.rx_ipg, 0x8b);
  7252. +#endif
  7253. +
  7254. + /*
  7255. + * - enable frame checksum generation
  7256. + * - enable padding of short frames
  7257. + * - disable flow control
  7258. + */
  7259. + ltq_writel(to_mac_ctrl(switch_regs, LTQ_ETHSW_PMAC, 0),
  7260. + MAC_CTRL0_PADEN | MAC_CTRL0_FCS | MAC_CTRL0_FCON_NONE);
  7261. +
  7262. + vr9_switch_sync();
  7263. +}
  7264. +
  7265. +static void ltq_eth_hw_init(void)
  7266. +{
  7267. + int i;
  7268. +
  7269. + /* Power up ethernet and switch subsystems */
  7270. + ltq_pm_enable(LTQ_PM_ETH);
  7271. +
  7272. + /* Reset ethernet and switch subsystems */
  7273. +#if 0
  7274. + ltq_reset_once(LTQ_RESET_ETH, 10);
  7275. +#endif
  7276. +
  7277. + /* Enable switch macro */
  7278. + ltq_setbits(&switch_regs->mdio.glob_ctrl, MDIO_GLOB_CTRL_SE);
  7279. +
  7280. + /* Disable MDIO auto-polling for all ports */
  7281. + ltq_writel(&switch_regs->mdio.mdc_cfg_0, 0);
  7282. +
  7283. + /*
  7284. + * Enable and set MDIO management clock to 2.5 MHz. This is the
  7285. + * maximum clock for FE PHYs.
  7286. + * Formula for clock is:
  7287. + *
  7288. + * 50 MHz
  7289. + * x = ----------- - 1
  7290. + * 2 * f_MDC
  7291. + */
  7292. + ltq_writel(&switch_regs->mdio.mdc_cfg_1, MDIO_MDC_CFG1_RES |
  7293. + MDIO_MDC_CFG1_MCEN | 5);
  7294. +
  7295. + vr9_switch_sync();
  7296. +
  7297. + /* Init MAC connected to CPU */
  7298. + ltq_eth_pmac_init();
  7299. +
  7300. + /* Init MACs connected to external MII interfaces */
  7301. + for (i = 0; i < LTQ_ETHSW_MAX_GMAC; i++)
  7302. + ltq_eth_gmac_init(i);
  7303. +}
  7304. +
  7305. +static void ltq_eth_port_config(struct ltq_eth_priv *priv,
  7306. + const struct ltq_eth_port_config *port)
  7307. +{
  7308. + struct ltq_mii_mii_cfg_reg mii_cfg_reg;
  7309. + struct phy_device *phydev;
  7310. + int setup_gpio = 0;
  7311. +
  7312. + switch (port->num) {
  7313. + case 0: /* xMII0 */
  7314. + case 1: /* xMII1 */
  7315. + mii_cfg_reg.val = ltq_readl(to_mii_miicfg(switch_regs,
  7316. + port->num));
  7317. + mii_cfg_reg.bits.en = port->flags ? 1 : 0;
  7318. +
  7319. + switch (port->phy_if) {
  7320. + case PHY_INTERFACE_MODE_MII:
  7321. + if (port->flags & LTQ_ETH_PORT_PHY)
  7322. + /* MII MAC mode, connected to external PHY */
  7323. + mii_cfg_reg.bits.miimode =
  7324. + LTQ_MII_MII_CFG_MIIMODE_MIIM;
  7325. + else
  7326. + /* MII PHY mode, connected to external MAC */
  7327. + mii_cfg_reg.bits.miimode =
  7328. + LTQ_MII_MII_CFG_MIIMODE_MIIP;
  7329. + setup_gpio = 1;
  7330. + break;
  7331. + case PHY_INTERFACE_MODE_RMII:
  7332. + if (port->flags & LTQ_ETH_PORT_PHY)
  7333. + /* RMII MAC mode, connected to external PHY */
  7334. + mii_cfg_reg.bits.miimode =
  7335. + LTQ_MII_MII_CFG_MIIMODE_RMIIM;
  7336. + else
  7337. + /* RMII PHY mode, connected to external MAC */
  7338. + mii_cfg_reg.bits.miimode =
  7339. + LTQ_MII_MII_CFG_MIIMODE_RMIIP;
  7340. + setup_gpio = 1;
  7341. + break;
  7342. + case PHY_INTERFACE_MODE_RGMII:
  7343. + /* RGMII MAC mode, connected to external PHY */
  7344. + mii_cfg_reg.bits.miimode =
  7345. + LTQ_MII_MII_CFG_MIIMODE_RGMII;
  7346. + setup_gpio = 1;
  7347. +
  7348. + /* RGMII clock delays */
  7349. + ltq_writel(to_mii_pcdu(switch_regs, port->num),
  7350. + port->rgmii_rx_delay << PCDU_RXDLY_SHIFT |
  7351. + port->rgmii_tx_delay);
  7352. + break;
  7353. + default:
  7354. + break;
  7355. + }
  7356. +
  7357. + ltq_writel(to_mii_miicfg(switch_regs, port->num),
  7358. + mii_cfg_reg.val);
  7359. + break;
  7360. + case 2: /* internal GPHY0 */
  7361. + case 3: /* internal GPHY0 */
  7362. + case 4: /* internal GPHY1 */
  7363. + switch (port->phy_if) {
  7364. + case PHY_INTERFACE_MODE_MII:
  7365. + case PHY_INTERFACE_MODE_GMII:
  7366. + setup_gpio = 1;
  7367. + break;
  7368. + default:
  7369. + break;
  7370. + }
  7371. + break;
  7372. + case 5: /* internal GPHY1 or xMII2 */
  7373. + mii_cfg_reg.val = ltq_readl(to_mii_miicfg(switch_regs,
  7374. + port->num));
  7375. + mii_cfg_reg.bits.en = port->flags ? 1 : 0;
  7376. +
  7377. + switch (port->phy_if) {
  7378. + case PHY_INTERFACE_MODE_MII:
  7379. + /* MII MAC mode, connected to internal GPHY */
  7380. + mii_cfg_reg.bits.miimode =
  7381. + LTQ_MII_MII_CFG_MIIMODE_MIIM;
  7382. + setup_gpio = 1;
  7383. + break;
  7384. + case PHY_INTERFACE_MODE_RGMII:
  7385. + /* RGMII MAC mode, connected to external PHY */
  7386. + mii_cfg_reg.bits.miimode =
  7387. + LTQ_MII_MII_CFG_MIIMODE_RGMII;
  7388. + setup_gpio = 1;
  7389. +
  7390. + /* RGMII clock delays */
  7391. + ltq_writel(to_mii_pcdu(switch_regs, port->num),
  7392. + port->rgmii_rx_delay << PCDU_RXDLY_SHIFT |
  7393. + port->rgmii_tx_delay);
  7394. + break;
  7395. + default:
  7396. + break;
  7397. + }
  7398. +
  7399. + ltq_writel(to_mii_miicfg(switch_regs, port->num),
  7400. + mii_cfg_reg.val);
  7401. + break;
  7402. + default:
  7403. + break;
  7404. + }
  7405. +
  7406. + /* Setup GPIOs for MII with external PHYs/MACs */
  7407. + if (setup_gpio) {
  7408. + /* MII/MDIO */
  7409. + gpio_set_altfunc(42, GPIO_ALTSEL_SET, GPIO_ALTSEL_CLR,
  7410. + GPIO_DIR_OUT);
  7411. + /* MII/MDC */
  7412. + gpio_set_altfunc(43, GPIO_ALTSEL_SET, GPIO_ALTSEL_CLR,
  7413. + GPIO_DIR_OUT);
  7414. + }
  7415. +
  7416. + /* Connect to internal/external PHYs */
  7417. + if (port->flags & LTQ_ETH_PORT_PHY) {
  7418. + phydev = phy_connect(priv->bus, port->phy_addr, priv->dev,
  7419. + port->phy_if);
  7420. + if (phydev)
  7421. + phy_config(phydev);
  7422. +
  7423. + priv->phymap[port->num] = phydev;
  7424. + }
  7425. +}
  7426. +
  7427. +int ltq_eth_initialize(const struct ltq_eth_board_config *board_config)
  7428. +{
  7429. + struct eth_device *dev;
  7430. + struct mii_dev *bus;
  7431. + struct ltq_eth_priv *priv;
  7432. + struct ltq_dma_device *dma_dev;
  7433. + int i, ret;
  7434. +
  7435. + build_check_vr9_registers();
  7436. +
  7437. + ltq_dma_init();
  7438. + ltq_eth_hw_init();
  7439. +
  7440. + dev = calloc(1, sizeof(struct eth_device));
  7441. + if (!dev)
  7442. + return -1;
  7443. +
  7444. + priv = calloc(1, sizeof(struct ltq_eth_priv));
  7445. + if (!priv)
  7446. + return -1;
  7447. +
  7448. + bus = mdio_alloc();
  7449. + if (!bus)
  7450. + return -1;
  7451. +
  7452. + sprintf(dev->name, LTQ_ETH_DRV_NAME);
  7453. + dev->priv = priv;
  7454. + dev->init = ltq_eth_init;
  7455. + dev->halt = ltq_eth_halt;
  7456. + dev->recv = ltq_eth_recv;
  7457. + dev->send = ltq_eth_send;
  7458. +
  7459. + sprintf(bus->name, LTQ_MDIO_DRV_NAME);
  7460. + bus->read = vr9_switch_mdio_read;
  7461. + bus->write = vr9_switch_mdio_write;
  7462. + bus->priv = priv;
  7463. +
  7464. + dma_dev = &priv->dma_dev;
  7465. + dma_dev->port = 0;
  7466. + dma_dev->rx_chan.chan_no = 0;
  7467. + dma_dev->rx_chan.class = 0;
  7468. + dma_dev->rx_chan.num_desc = LTQ_ETH_RX_BUFFER_CNT;
  7469. + dma_dev->rx_endian_swap = LTQ_DMA_ENDIANESS_B3_B2_B1_B0;
  7470. + dma_dev->rx_burst_len = LTQ_DMA_BURST_2WORDS;
  7471. + dma_dev->tx_chan.chan_no = 1;
  7472. + dma_dev->tx_chan.class = 0;
  7473. + dma_dev->tx_chan.num_desc = LTQ_ETH_TX_BUFFER_CNT;
  7474. + dma_dev->tx_endian_swap = LTQ_DMA_ENDIANESS_B3_B2_B1_B0;
  7475. + dma_dev->tx_burst_len = LTQ_DMA_BURST_2WORDS;
  7476. +
  7477. + priv->bus = bus;
  7478. + priv->dev = dev;
  7479. +
  7480. + ret = ltq_dma_register(dma_dev);
  7481. + if (ret)
  7482. + return -1;
  7483. +
  7484. + ret = mdio_register(bus);
  7485. + if (ret)
  7486. + return -1;
  7487. +
  7488. + ret = eth_register(dev);
  7489. + if (ret)
  7490. + return -1;
  7491. +
  7492. + for (i = 0; i < board_config->num_ports; i++)
  7493. + ltq_eth_port_config(priv, &board_config->ports[i]);
  7494. +
  7495. + return 0;
  7496. +}
  7497. --- a/drivers/net/phy/Makefile
  7498. +++ b/drivers/net/phy/Makefile
  7499. @@ -20,6 +20,7 @@ COBJS-$(CONFIG_PHY_BROADCOM) += broadcom
  7500. COBJS-$(CONFIG_PHY_DAVICOM) += davicom.o
  7501. COBJS-$(CONFIG_PHY_ET1011C) += et1011c.o
  7502. COBJS-$(CONFIG_PHY_ICPLUS) += icplus.o
  7503. +COBJS-$(CONFIG_PHY_LANTIQ) += lantiq.o
  7504. COBJS-$(CONFIG_PHY_LXT) += lxt.o
  7505. COBJS-$(CONFIG_PHY_MARVELL) += marvell.o
  7506. COBJS-$(CONFIG_PHY_MICREL) += micrel.o
  7507. --- /dev/null
  7508. +++ b/drivers/net/phy/lantiq.c
  7509. @@ -0,0 +1,238 @@
  7510. +/*
  7511. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  7512. + *
  7513. + * SPDX-License-Identifier: GPL-2.0+
  7514. + */
  7515. +
  7516. +#define DEBUG
  7517. +
  7518. +#include <common.h>
  7519. +#include <miiphy.h>
  7520. +
  7521. +#define ADVERTIZE_MPD (1 << 10)
  7522. +
  7523. +DECLARE_GLOBAL_DATA_PTR;
  7524. +
  7525. +/*
  7526. + * Update link status.
  7527. + *
  7528. + * Based on genphy_update_link in phylib.c
  7529. + */
  7530. +static int ltq_phy_update_link(struct phy_device *phydev)
  7531. +{
  7532. + unsigned int mii_reg;
  7533. +
  7534. + mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
  7535. +
  7536. + /*
  7537. + * If we already saw the link up, and it hasn't gone down, then
  7538. + * we don't need to wait for autoneg again
  7539. + */
  7540. + if (phydev->link && mii_reg & BMSR_LSTATUS)
  7541. + return 0;
  7542. +
  7543. + if ((mii_reg & BMSR_ANEGCAPABLE) && !(mii_reg & BMSR_ANEGCOMPLETE)) {
  7544. + phydev->link = 0;
  7545. + return 0;
  7546. + } else {
  7547. + /* Read the link a second time to clear the latched state */
  7548. + mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
  7549. +
  7550. + if (mii_reg & BMSR_LSTATUS)
  7551. + phydev->link = 1;
  7552. + else
  7553. + phydev->link = 0;
  7554. + }
  7555. +
  7556. + return 0;
  7557. +}
  7558. +
  7559. +/*
  7560. + * Update speed and duplex.
  7561. + *
  7562. + * Based on genphy_parse_link in phylib.c
  7563. + */
  7564. +static int ltq_phy_parse_link(struct phy_device *phydev)
  7565. +{
  7566. + unsigned int mii_reg;
  7567. +
  7568. + mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
  7569. +
  7570. + /* We're using autonegotiation */
  7571. + if (mii_reg & BMSR_ANEGCAPABLE) {
  7572. + u32 lpa = 0;
  7573. + u32 gblpa = 0;
  7574. +
  7575. + /* Check for gigabit capability */
  7576. + if (mii_reg & BMSR_ERCAP) {
  7577. + /* We want a list of states supported by
  7578. + * both PHYs in the link
  7579. + */
  7580. + gblpa = phy_read(phydev, MDIO_DEVAD_NONE, MII_STAT1000);
  7581. + gblpa &= phy_read(phydev,
  7582. + MDIO_DEVAD_NONE, MII_CTRL1000) << 2;
  7583. + }
  7584. +
  7585. + /* Set the baseline so we only have to set them
  7586. + * if they're different
  7587. + */
  7588. + phydev->speed = SPEED_10;
  7589. + phydev->duplex = DUPLEX_HALF;
  7590. +
  7591. + /* Check the gigabit fields */
  7592. + if (gblpa & (PHY_1000BTSR_1000FD | PHY_1000BTSR_1000HD)) {
  7593. + phydev->speed = SPEED_1000;
  7594. +
  7595. + if (gblpa & PHY_1000BTSR_1000FD)
  7596. + phydev->duplex = DUPLEX_FULL;
  7597. +
  7598. + /* We're done! */
  7599. + return 0;
  7600. + }
  7601. +
  7602. + lpa = phy_read(phydev, MDIO_DEVAD_NONE, MII_ADVERTISE);
  7603. + lpa &= phy_read(phydev, MDIO_DEVAD_NONE, MII_LPA);
  7604. +
  7605. + if (lpa & (LPA_100FULL | LPA_100HALF)) {
  7606. + phydev->speed = SPEED_100;
  7607. +
  7608. + if (lpa & LPA_100FULL)
  7609. + phydev->duplex = DUPLEX_FULL;
  7610. +
  7611. + } else if (lpa & LPA_10FULL)
  7612. + phydev->duplex = DUPLEX_FULL;
  7613. + } else {
  7614. + u32 bmcr = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);
  7615. +
  7616. + phydev->speed = SPEED_10;
  7617. + phydev->duplex = DUPLEX_HALF;
  7618. +
  7619. + if (bmcr & BMCR_FULLDPLX)
  7620. + phydev->duplex = DUPLEX_FULL;
  7621. +
  7622. + if (bmcr & BMCR_SPEED1000)
  7623. + phydev->speed = SPEED_1000;
  7624. + else if (bmcr & BMCR_SPEED100)
  7625. + phydev->speed = SPEED_100;
  7626. + }
  7627. +
  7628. + return 0;
  7629. +}
  7630. +
  7631. +static int ltq_phy_config(struct phy_device *phydev)
  7632. +{
  7633. + u16 val;
  7634. +
  7635. + /* Advertise as Multi-port device */
  7636. + val = phy_read(phydev, MDIO_DEVAD_NONE, MII_CTRL1000);
  7637. + val |= ADVERTIZE_MPD;
  7638. + phy_write(phydev, MDIO_DEVAD_NONE, MII_CTRL1000, val);
  7639. +
  7640. + genphy_config_aneg(phydev);
  7641. +
  7642. + return 0;
  7643. +}
  7644. +
  7645. +static int ltq_phy_startup(struct phy_device *phydev)
  7646. +{
  7647. + /*
  7648. + * Update PHY status immediately without any delays as genphy_startup
  7649. + * does because VRX200 switch needs to be configured dependent
  7650. + * on this information.
  7651. + */
  7652. + ltq_phy_update_link(phydev);
  7653. + ltq_phy_parse_link(phydev);
  7654. +
  7655. + debug("ltq_phy: addr %d, link %d, speed %d, duplex %d\n",
  7656. + phydev->addr, phydev->link, phydev->speed, phydev->duplex);
  7657. +
  7658. + return 0;
  7659. +}
  7660. +
  7661. +static struct phy_driver xrx_11g_13_driver = {
  7662. + .name = "Lantiq XWAY XRX PHY11G v1.3 and earlier",
  7663. + .uid = 0x030260D0,
  7664. + .mask = 0xFFFFFFF0,
  7665. + .features = PHY_GBIT_FEATURES,
  7666. + .config = ltq_phy_config,
  7667. + .startup = ltq_phy_startup,
  7668. + .shutdown = genphy_shutdown,
  7669. +};
  7670. +
  7671. +static struct phy_driver xrx_11g_14_driver = {
  7672. + .name = "Lantiq XWAY XRX PHY11G v1.4 and later",
  7673. + .uid = 0xd565a408,
  7674. + .mask = 0xFFFFFFF8,
  7675. + .features = PHY_GBIT_FEATURES,
  7676. + .config = ltq_phy_config,
  7677. + .startup = ltq_phy_startup,
  7678. + .shutdown = genphy_shutdown,
  7679. +};
  7680. +
  7681. +static struct phy_driver xrx_22f_14_driver = {
  7682. + .name = "Lantiq XWAY XRX PHY22F v1.4 and later",
  7683. + .uid = 0xd565a418,
  7684. + .mask = 0xFFFFFFF8,
  7685. + .features = PHY_BASIC_FEATURES,
  7686. + .config = ltq_phy_config,
  7687. + .startup = ltq_phy_startup,
  7688. + .shutdown = genphy_shutdown,
  7689. +};
  7690. +
  7691. +static struct phy_driver pef7071_driver = {
  7692. + .name = "Lantiq XWAY PEF7071",
  7693. + .uid = 0xd565a400,
  7694. + .mask = 0xFFFFFFFF,
  7695. + .features = PHY_GBIT_FEATURES,
  7696. + .config = ltq_phy_config,
  7697. + .startup = ltq_phy_startup,
  7698. + .shutdown = genphy_shutdown,
  7699. +};
  7700. +
  7701. +static struct phy_driver xrx_genphy_driver = {
  7702. + .name = "Generic PHY at Lantiq XWAY XRX switch",
  7703. + .uid = 0,
  7704. + .mask = 0,
  7705. + .features = 0,
  7706. + .config = genphy_config,
  7707. + .startup = ltq_phy_startup,
  7708. + .shutdown = genphy_shutdown,
  7709. +};
  7710. +
  7711. +int phy_lantiq_init(void)
  7712. +{
  7713. +#ifdef CONFIG_NEEDS_MANUAL_RELOC
  7714. + xrx_11g_13_driver.config = ltq_phy_config;
  7715. + xrx_11g_13_driver.startup = ltq_phy_startup;
  7716. + xrx_11g_13_driver.shutdown = genphy_shutdown;
  7717. + xrx_11g_13_driver.name += gd->reloc_off;
  7718. +
  7719. + xrx_11g_14_driver.config = ltq_phy_config;
  7720. + xrx_11g_14_driver.startup = ltq_phy_startup;
  7721. + xrx_11g_14_driver.shutdown = genphy_shutdown;
  7722. + xrx_11g_14_driver.name += gd->reloc_off;
  7723. +
  7724. + xrx_22f_14_driver.config = ltq_phy_config;
  7725. + xrx_22f_14_driver.startup = ltq_phy_startup;
  7726. + xrx_22f_14_driver.shutdown = genphy_shutdown;
  7727. + xrx_22f_14_driver.name += gd->reloc_off;
  7728. +
  7729. + pef7071_driver.config = ltq_phy_config;
  7730. + pef7071_driver.startup = ltq_phy_startup;
  7731. + pef7071_driver.shutdown = genphy_shutdown;
  7732. + pef7071_driver.name += gd->reloc_off;
  7733. +
  7734. + xrx_genphy_driver.config = genphy_config;
  7735. + xrx_genphy_driver.startup = ltq_phy_startup;
  7736. + xrx_genphy_driver.shutdown = genphy_shutdown;
  7737. + xrx_genphy_driver.name += gd->reloc_off;
  7738. +#endif
  7739. +
  7740. + phy_register(&xrx_11g_13_driver);
  7741. + phy_register(&xrx_11g_14_driver);
  7742. + phy_register(&xrx_22f_14_driver);
  7743. + phy_register(&pef7071_driver);
  7744. + phy_register(&xrx_genphy_driver);
  7745. +
  7746. + return 0;
  7747. +}
  7748. --- a/drivers/net/phy/phy.c
  7749. +++ b/drivers/net/phy/phy.c
  7750. @@ -16,9 +16,10 @@
  7751. #include <command.h>
  7752. #include <miiphy.h>
  7753. #include <phy.h>
  7754. -#include <errno.h>
  7755. #include <linux/err.h>
  7756. +DECLARE_GLOBAL_DATA_PTR;
  7757. +
  7758. /* Generic PHY support and helper functions */
  7759. /**
  7760. @@ -440,6 +441,16 @@ static LIST_HEAD(phy_drivers);
  7761. int phy_init(void)
  7762. {
  7763. +#ifdef CONFIG_NEEDS_MANUAL_RELOC
  7764. + INIT_LIST_HEAD(&phy_drivers);
  7765. +
  7766. + genphy_driver.config = genphy_config;
  7767. + genphy_driver.startup = genphy_startup;
  7768. + genphy_driver.shutdown = genphy_shutdown;
  7769. +
  7770. + genphy_driver.name += gd->reloc_off;
  7771. +#endif
  7772. +
  7773. #ifdef CONFIG_PHY_ATHEROS
  7774. phy_atheros_init();
  7775. #endif
  7776. @@ -455,6 +466,9 @@ int phy_init(void)
  7777. #ifdef CONFIG_PHY_ICPLUS
  7778. phy_icplus_init();
  7779. #endif
  7780. +#ifdef CONFIG_PHY_LANTIQ
  7781. + phy_lantiq_init();
  7782. +#endif
  7783. #ifdef CONFIG_PHY_LXT
  7784. phy_lxt_init();
  7785. #endif
  7786. --- a/drivers/serial/Makefile
  7787. +++ b/drivers/serial/Makefile
  7788. @@ -24,6 +24,7 @@ COBJS-$(CONFIG_SYS_NS16550_SERIAL) += se
  7789. COBJS-$(CONFIG_IMX_SERIAL) += serial_imx.o
  7790. COBJS-$(CONFIG_IXP_SERIAL) += serial_ixp.o
  7791. COBJS-$(CONFIG_KS8695_SERIAL) += serial_ks8695.o
  7792. +COBJS-$(CONFIG_LANTIQ_SERIAL) += serial_lantiq.o
  7793. COBJS-$(CONFIG_MAX3100_SERIAL) += serial_max3100.o
  7794. COBJS-$(CONFIG_MXC_UART) += serial_mxc.o
  7795. COBJS-$(CONFIG_PL010_SERIAL) += serial_pl01x.o
  7796. --- a/drivers/serial/serial.c
  7797. +++ b/drivers/serial/serial.c
  7798. @@ -160,6 +160,7 @@ serial_initfunc(sa1100_serial_initialize
  7799. serial_initfunc(sh_serial_initialize);
  7800. serial_initfunc(arm_dcc_initialize);
  7801. serial_initfunc(mxs_auart_initialize);
  7802. +serial_initfunc(ltq_serial_initialize);
  7803. /**
  7804. * serial_register() - Register serial driver with serial driver core
  7805. @@ -253,6 +254,7 @@ void serial_initialize(void)
  7806. sh_serial_initialize();
  7807. arm_dcc_initialize();
  7808. mxs_auart_initialize();
  7809. + ltq_serial_initialize();
  7810. serial_assign(default_serial_console()->name);
  7811. }
  7812. --- /dev/null
  7813. +++ b/drivers/serial/serial_lantiq.c
  7814. @@ -0,0 +1,263 @@
  7815. +/*
  7816. + * Copyright (C) 2010 Thomas Langer <thomas.langer@lantiq.com>
  7817. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  7818. + *
  7819. + * SPDX-License-Identifier: GPL-2.0+
  7820. + */
  7821. +
  7822. +#include <common.h>
  7823. +#include <serial.h>
  7824. +#include <asm/errno.h>
  7825. +#include <asm/arch/soc.h>
  7826. +#include <asm/lantiq/clk.h>
  7827. +#include <asm/lantiq/io.h>
  7828. +
  7829. +#if CONFIG_CONSOLE_ASC == 0
  7830. +#define LTQ_ASC_BASE LTQ_ASC0_BASE
  7831. +#else
  7832. +#define LTQ_ASC_BASE LTQ_ASC1_BASE
  7833. +#endif
  7834. +
  7835. +#define LTQ_ASC_ID_TXFS_SHIFT 24
  7836. +#define LTQ_ASC_ID_TXFS_MASK (0x3F << LTQ_ASC_ID_TXFS_SHIFT)
  7837. +#define LTQ_ASC_ID_RXFS_SHIFT 16
  7838. +#define LTQ_ASC_ID_RXFS_MASK (0x3F << LTQ_ASC_ID_RXFS_SHIFT)
  7839. +
  7840. +#define LTQ_ASC_MCON_R (1 << 15)
  7841. +#define LTQ_ASC_MCON_FDE (1 << 9)
  7842. +
  7843. +#define LTQ_ASC_WHBSTATE_SETREN (1 << 1)
  7844. +#define LTQ_ASC_WHBSTATE_CLRREN (1 << 0)
  7845. +
  7846. +#define LTQ_ASC_RXFCON_RXFITL_SHIFT 8
  7847. +#define LTQ_ASC_RXFCON_RXFITL_MASK (0x3F << LTQ_ASC_RXFCON_RXFITL_SHIFT)
  7848. +#define LTQ_ASC_RXFCON_RXFITL_RXFFLU (1 << 1)
  7849. +#define LTQ_ASC_RXFCON_RXFITL_RXFEN (1 << 0)
  7850. +
  7851. +#define LTQ_ASC_TXFCON_TXFITL_SHIFT 8
  7852. +#define LTQ_ASC_TXFCON_TXFITL_MASK (0x3F << LTQ_ASC_TXFCON_TXFITL_SHIFT)
  7853. +#define LTQ_ASC_TXFCON_TXFITL_TXFFLU (1 << 1)
  7854. +#define LTQ_ASC_TXFCON_TXFITL_TXFEN (1 << 0)
  7855. +
  7856. +#define LTQ_ASC_FSTAT_TXFREE_SHIFT 24
  7857. +#define LTQ_ASC_FSTAT_TXFREE_MASK (0x3F << LTQ_ASC_FSTAT_TXFREE_SHIFT)
  7858. +#define LTQ_ASC_FSTAT_RXFREE_SHIFT 16
  7859. +#define LTQ_ASC_FSTAT_RXFREE_MASK (0x3F << LTQ_ASC_FSTAT_RXFREE_SHIFT)
  7860. +#define LTQ_ASC_FSTAT_TXFFL_SHIFT 8
  7861. +#define LTQ_ASC_FSTAT_TXFFL_MASK (0x3F << LTQ_ASC_FSTAT_TXFFL_SHIFT)
  7862. +#define LTQ_ASC_FSTAT_RXFFL_MASK 0x3F
  7863. +
  7864. +#ifdef __BIG_ENDIAN
  7865. +#define LTQ_ASC_RBUF_OFFSET 3
  7866. +#define LTQ_ASC_TBUF_OFFSET 3
  7867. +#else
  7868. +#define LTQ_ASC_RBUF_OFFSET 0
  7869. +#define LTQ_ASC_TBUF_OFFSET 0
  7870. +#endif
  7871. +
  7872. +struct ltq_asc_regs {
  7873. + u32 clc;
  7874. + u32 pisel;
  7875. + u32 id;
  7876. + u32 rsvd0;
  7877. + u32 mcon;
  7878. + u32 state;
  7879. + u32 whbstate;
  7880. + u32 rsvd1;
  7881. + u8 tbuf[4];
  7882. + u8 rbuf[4];
  7883. + u32 rsvd2[2];
  7884. + u32 abcon;
  7885. + u32 abstat;
  7886. + u32 whbabcon;
  7887. + u32 whbabstat;
  7888. + u32 rxfcon;
  7889. + u32 txfcon;
  7890. + u32 fstat;
  7891. + u32 rsvd3;
  7892. + u32 bg;
  7893. + u32 bg_timer;
  7894. + u32 fdv;
  7895. + u32 pmw;
  7896. + u32 modcon;
  7897. + u32 modstat;
  7898. +};
  7899. +
  7900. +DECLARE_GLOBAL_DATA_PTR;
  7901. +
  7902. +static struct ltq_asc_regs *ltq_asc_regs =
  7903. + (struct ltq_asc_regs *) CKSEG1ADDR(LTQ_ASC_BASE);
  7904. +
  7905. +static int ltq_serial_init(void)
  7906. +{
  7907. + /* Set clock divider for normal run mode to 1 and enable module */
  7908. + ltq_writel(&ltq_asc_regs->clc, 0x100);
  7909. +
  7910. + /* Reset MCON register */
  7911. + ltq_writel(&ltq_asc_regs->mcon, 0);
  7912. +
  7913. + /* Use Port A as receiver input */
  7914. + ltq_writel(&ltq_asc_regs->pisel, 0);
  7915. +
  7916. + /* Enable and flush RX/TX FIFOs */
  7917. + ltq_setbits(&ltq_asc_regs->rxfcon,
  7918. + LTQ_ASC_RXFCON_RXFITL_RXFFLU | LTQ_ASC_RXFCON_RXFITL_RXFEN);
  7919. + ltq_setbits(&ltq_asc_regs->txfcon,
  7920. + LTQ_ASC_TXFCON_TXFITL_TXFFLU | LTQ_ASC_TXFCON_TXFITL_TXFEN);
  7921. +
  7922. + serial_setbrg();
  7923. +
  7924. + /* Disable error flags, enable receiver */
  7925. + ltq_writel(&ltq_asc_regs->whbstate, LTQ_ASC_WHBSTATE_SETREN);
  7926. +
  7927. + return 0;
  7928. +}
  7929. +
  7930. +/*
  7931. + * fdv asc_clk
  7932. + * Baudrate = ----- * -------------
  7933. + * 512 16 * (bg + 1)
  7934. + */
  7935. +static void ltq_serial_calc_br_fdv(unsigned long asc_clk,
  7936. + unsigned long baudrate, u16 *fdv,
  7937. + u16 *bg)
  7938. +{
  7939. + const u32 c = asc_clk / (16 * 512);
  7940. + u32 diff1, diff2;
  7941. + u32 bg_calc, br_calc, i;
  7942. +
  7943. + diff1 = baudrate;
  7944. + for (i = 512; i > 0; i--) {
  7945. + /* Calc bg for current fdv value */
  7946. + bg_calc = i * c / baudrate;
  7947. +
  7948. + /* Impossible baudrate */
  7949. + if (!bg_calc)
  7950. + return;
  7951. +
  7952. + /*
  7953. + * Calc diff to target baudrate dependent on current
  7954. + * bg and fdv values
  7955. + */
  7956. + br_calc = i * c / bg_calc;
  7957. + if (br_calc > baudrate)
  7958. + diff2 = br_calc - baudrate;
  7959. + else
  7960. + diff2 = baudrate - br_calc;
  7961. +
  7962. + /* Perfect values found */
  7963. + if (diff2 == 0) {
  7964. + *fdv = i;
  7965. + *bg = bg_calc - 1;
  7966. + return;
  7967. + }
  7968. +
  7969. + if (diff2 < diff1) {
  7970. + *fdv = i;
  7971. + *bg = bg_calc - 1;
  7972. + diff1 = diff2;
  7973. + }
  7974. + }
  7975. +}
  7976. +
  7977. +static void ltq_serial_setbrg(void)
  7978. +{
  7979. + unsigned long asc_clk, baudrate;
  7980. + u16 bg = 0;
  7981. + u16 fdv = 511;
  7982. +
  7983. + /* ASC clock is same as FPI clock with CLC.RMS = 1 */
  7984. + asc_clk = ltq_get_bus_clock();
  7985. + baudrate = gd->baudrate;
  7986. +
  7987. + /* Calculate FDV and BG values */
  7988. + ltq_serial_calc_br_fdv(asc_clk, baudrate, &fdv, &bg);
  7989. +
  7990. + /* Disable baudrate generator */
  7991. + ltq_clrbits(&ltq_asc_regs->mcon, LTQ_ASC_MCON_R);
  7992. +
  7993. + /* Enable fractional divider */
  7994. + ltq_setbits(&ltq_asc_regs->mcon, LTQ_ASC_MCON_FDE);
  7995. +
  7996. + /* Set fdv and bg values */
  7997. + ltq_writel(&ltq_asc_regs->fdv, fdv);
  7998. + ltq_writel(&ltq_asc_regs->bg, bg);
  7999. +
  8000. + /* Enable baudrate generator */
  8001. + ltq_setbits(&ltq_asc_regs->mcon, LTQ_ASC_MCON_R);
  8002. +}
  8003. +
  8004. +static unsigned int ltq_serial_tx_free(void)
  8005. +{
  8006. + unsigned int txfree;
  8007. +
  8008. + txfree = (ltq_readl(&ltq_asc_regs->fstat) &
  8009. + LTQ_ASC_FSTAT_TXFREE_MASK) >>
  8010. + LTQ_ASC_FSTAT_TXFREE_SHIFT;
  8011. +
  8012. + return txfree;
  8013. +}
  8014. +
  8015. +static unsigned int ltq_serial_rx_fill(void)
  8016. +{
  8017. + unsigned int rxffl;
  8018. +
  8019. + rxffl = ltq_readl(&ltq_asc_regs->fstat) & LTQ_ASC_FSTAT_RXFFL_MASK;
  8020. +
  8021. + return rxffl;
  8022. +}
  8023. +
  8024. +static void ltq_serial_tx(const char c)
  8025. +{
  8026. + ltq_writeb(&ltq_asc_regs->tbuf[LTQ_ASC_TBUF_OFFSET], c);
  8027. +}
  8028. +
  8029. +static u8 ltq_serial_rx(void)
  8030. +{
  8031. + return ltq_readb(&ltq_asc_regs->rbuf[LTQ_ASC_RBUF_OFFSET]);
  8032. +}
  8033. +
  8034. +static void ltq_serial_putc(const char c)
  8035. +{
  8036. + if (c == '\n')
  8037. + ltq_serial_putc('\r');
  8038. +
  8039. + while (!ltq_serial_tx_free())
  8040. + ;
  8041. +
  8042. + ltq_serial_tx(c);
  8043. +}
  8044. +
  8045. +static int ltq_serial_getc(void)
  8046. +{
  8047. + while (!ltq_serial_rx_fill())
  8048. + ;
  8049. +
  8050. + return ltq_serial_rx();
  8051. +}
  8052. +
  8053. +static int ltq_serial_tstc(void)
  8054. +{
  8055. + return (0 != ltq_serial_rx_fill());
  8056. +}
  8057. +
  8058. +static struct serial_device ltq_serial_drv = {
  8059. + .name = "ltq_serial",
  8060. + .start = ltq_serial_init,
  8061. + .stop = NULL,
  8062. + .setbrg = ltq_serial_setbrg,
  8063. + .putc = ltq_serial_putc,
  8064. + .puts = default_serial_puts,
  8065. + .getc = ltq_serial_getc,
  8066. + .tstc = ltq_serial_tstc,
  8067. +};
  8068. +
  8069. +void ltq_serial_initialize(void)
  8070. +{
  8071. + serial_register(&ltq_serial_drv);
  8072. +}
  8073. +
  8074. +__weak struct serial_device *default_serial_console(void)
  8075. +{
  8076. + return &ltq_serial_drv;
  8077. +}
  8078. --- a/drivers/spi/Makefile
  8079. +++ b/drivers/spi/Makefile
  8080. @@ -25,6 +25,7 @@ COBJS-$(CONFIG_DAVINCI_SPI) += davinci_s
  8081. COBJS-$(CONFIG_EXYNOS_SPI) += exynos_spi.o
  8082. COBJS-$(CONFIG_ICH_SPI) += ich.o
  8083. COBJS-$(CONFIG_KIRKWOOD_SPI) += kirkwood_spi.o
  8084. +COBJS-$(CONFIG_LANTIQ_SPI) += lantiq_spi.o
  8085. COBJS-$(CONFIG_MPC52XX_SPI) += mpc52xx_spi.o
  8086. COBJS-$(CONFIG_MPC8XXX_SPI) += mpc8xxx_spi.o
  8087. COBJS-$(CONFIG_MXC_SPI) += mxc_spi.o
  8088. --- /dev/null
  8089. +++ b/drivers/spi/lantiq_spi.c
  8090. @@ -0,0 +1,666 @@
  8091. +/*
  8092. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  8093. + *
  8094. + * SPDX-License-Identifier: GPL-2.0+
  8095. + */
  8096. +
  8097. +#include <common.h>
  8098. +#include <spi.h>
  8099. +#include <malloc.h>
  8100. +#include <watchdog.h>
  8101. +#include <asm/gpio.h>
  8102. +#include <asm/lantiq/io.h>
  8103. +#include <asm/lantiq/clk.h>
  8104. +#include <asm/lantiq/pm.h>
  8105. +#include <asm/arch/soc.h>
  8106. +
  8107. +#define LTQ_SPI_CLC_RMC_SHIFT 8
  8108. +#define LTQ_SPI_CLC_RMC_MASK (0xFF << LTQ_SPI_CLC_RMC_SHIFT)
  8109. +#define LTQ_SPI_CLC_DISS (1 << 1)
  8110. +#define LTQ_SPI_CLC_DISR 1
  8111. +
  8112. +#define LTQ_SPI_ID_TXFS_SHIFT 24
  8113. +#define LTQ_SPI_ID_TXFS_MASK (0x3F << LTQ_SPI_ID_TXFS_SHIFT)
  8114. +#define LTQ_SPI_ID_RXFS_SHIFT 16
  8115. +#define LTQ_SPI_ID_RXFS_MASK (0x3F << LTQ_SPI_ID_RXFS_SHIFT)
  8116. +
  8117. +#define LTQ_SPI_CON_ENBV (1 << 22)
  8118. +#define LTQ_SPI_CON_BM_SHIFT 16
  8119. +#define LTQ_SPI_CON_BM_MASK (0x1F << LTQ_SPI_CON_BM_SHIFT)
  8120. +#define LTQ_SPI_CON_IDLE (1 << 23)
  8121. +#define LTQ_SPI_CON_RUEN (1 << 12)
  8122. +#define LTQ_SPI_CON_AEN (1 << 10)
  8123. +#define LTQ_SPI_CON_REN (1 << 9)
  8124. +#define LTQ_SPI_CON_TEN (1 << 8)
  8125. +#define LTQ_SPI_CON_LB (1 << 7)
  8126. +#define LTQ_SPI_CON_PO (1 << 6)
  8127. +#define LTQ_SPI_CON_PH (1 << 5)
  8128. +#define LTQ_SPI_CON_HB (1 << 4)
  8129. +#define LTQ_SPI_CON_RXOFF (1 << 1)
  8130. +#define LTQ_SPI_CON_TXOFF 1
  8131. +
  8132. +#define LTQ_SPI_STAT_RXBV_SHIFT 28
  8133. +#define LTQ_SPI_STAT_RXBV_MASK (0x7 << LTQ_SPI_STAT_RXBV_SHIFT)
  8134. +#define LTQ_SPI_STAT_BSY (1 << 13)
  8135. +
  8136. +#define LTQ_SPI_WHBSTATE_SETMS (1 << 3)
  8137. +#define LTQ_SPI_WHBSTATE_CLRMS (1 << 2)
  8138. +#define LTQ_SPI_WHBSTATE_SETEN (1 << 1)
  8139. +#define LTQ_SPI_WHBSTATE_CLREN 1
  8140. +#define LTQ_SPI_WHBSTATE_CLR_ERRORS 0x0F50
  8141. +
  8142. +#define LTQ_SPI_TXFCON_TXFLU (1 << 1)
  8143. +#define LTQ_SPI_TXFCON_TXFEN 1
  8144. +
  8145. +#define LTQ_SPI_RXFCON_RXFLU (1 << 1)
  8146. +#define LTQ_SPI_RXFCON_RXFEN 1
  8147. +
  8148. +#define LTQ_SPI_FSTAT_RXFFL_MASK 0x3f
  8149. +#define LTQ_SPI_FSTAT_TXFFL_SHIFT 8
  8150. +#define LTQ_SPI_FSTAT_TXFFL_MASK (0x3f << LTQ_SPI_FSTAT_TXFFL_SHIFT)
  8151. +
  8152. +#define LTQ_SPI_RXREQ_RXCNT_MASK 0xFFFF
  8153. +#define LTQ_SPI_RXCNT_TODO_MASK 0xFFFF
  8154. +
  8155. +#define LTQ_SPI_GPIO_DIN 16
  8156. +#define LTQ_SPI_GPIO_DOUT 17
  8157. +#define LTQ_SPI_GPIO_CLK 18
  8158. +
  8159. +struct ltq_spi_regs {
  8160. + __be32 clc; /* Clock control */
  8161. + __be32 pisel; /* Port input select */
  8162. + __be32 id; /* Identification */
  8163. + __be32 rsvd0;
  8164. + __be32 con; /* Control */
  8165. + __be32 stat; /* Status */
  8166. + __be32 whbstate; /* Write HW modified state */
  8167. + __be32 rsvd1;
  8168. + __be32 tb; /* Transmit buffer */
  8169. + __be32 rb; /* Receive buffer */
  8170. + __be32 rsvd2[2];
  8171. + __be32 rxfcon; /* Recevie FIFO control */
  8172. + __be32 txfcon; /* Transmit FIFO control */
  8173. + __be32 fstat; /* FIFO status */
  8174. + __be32 rsvd3;
  8175. + __be32 brt; /* Baudrate timer */
  8176. + __be32 brstat; /* Baudrate timer status */
  8177. + __be32 rsvd4[6];
  8178. + __be32 sfcon; /* Serial frame control */
  8179. + __be32 sfstat; /* Serial frame status */
  8180. + __be32 rsvd5[2];
  8181. + __be32 gpocon; /* General purpose output control */
  8182. + __be32 gpostat; /* General purpose output status */
  8183. + __be32 fgpo; /* Force general purpose output */
  8184. + __be32 rsvd6;
  8185. + __be32 rxreq; /* Receive request */
  8186. + __be32 rxcnt; /* Receive count */
  8187. + __be32 rsvd7[25];
  8188. + __be32 dmacon; /* DMA control */
  8189. + __be32 rsvd8;
  8190. + __be32 irnen; /* Interrupt node enable */
  8191. + __be32 irnicr; /* Interrupt node interrupt capture */
  8192. + __be32 irncr; /* Interrupt node control */
  8193. +};
  8194. +
  8195. +struct ltq_spi_drv_data {
  8196. + struct ltq_spi_regs __iomem *regs;
  8197. +
  8198. + struct spi_slave slave;
  8199. + unsigned int max_hz;
  8200. + unsigned int mode;
  8201. + unsigned int tx_todo;
  8202. + unsigned int rx_todo;
  8203. + unsigned int rx_req;
  8204. + unsigned int bits_per_word;
  8205. + unsigned int speed_hz;
  8206. + const u8 *tx;
  8207. + u8 *rx;
  8208. + int status;
  8209. +};
  8210. +
  8211. +static struct ltq_spi_drv_data *to_ltq_spi_slave(struct spi_slave *slave)
  8212. +{
  8213. + return container_of(slave, struct ltq_spi_drv_data, slave);
  8214. +}
  8215. +
  8216. +#ifdef CONFIG_SPL_BUILD
  8217. +/*
  8218. + * We do not have or want malloc in a SPI flash SPL.
  8219. + * Neither we have to support multiple SPI slaves. Thus we put the
  8220. + * SPI slave context in BSS for SPL builds.
  8221. + */
  8222. +static struct ltq_spi_drv_data ltq_spi_slave;
  8223. +
  8224. +static struct ltq_spi_drv_data *ltq_spi_slave_alloc(unsigned int bus,
  8225. + unsigned int cs)
  8226. +{
  8227. + ltq_spi_slave.slave.bus = bus;
  8228. + ltq_spi_slave.slave.cs = cs;
  8229. +
  8230. + return &ltq_spi_slave;
  8231. +}
  8232. +
  8233. +static void ltq_spi_slave_free(struct spi_slave *slave)
  8234. +{
  8235. +}
  8236. +#else
  8237. +static struct ltq_spi_drv_data *ltq_spi_slave_alloc(unsigned int bus,
  8238. + unsigned int cs)
  8239. +{
  8240. + return spi_alloc_slave(struct ltq_spi_drv_data, bus, cs);
  8241. +}
  8242. +
  8243. +static void ltq_spi_slave_free(struct spi_slave *slave)
  8244. +{
  8245. + struct ltq_spi_drv_data *drv;
  8246. +
  8247. + if (slave) {
  8248. + drv = to_ltq_spi_slave(slave);
  8249. + free(drv);
  8250. + }
  8251. +}
  8252. +#endif
  8253. +
  8254. +static unsigned int tx_fifo_size(struct ltq_spi_drv_data *drv)
  8255. +{
  8256. + u32 id = ltq_readl(&drv->regs->id);
  8257. +
  8258. + return (id & LTQ_SPI_ID_TXFS_MASK) >> LTQ_SPI_ID_TXFS_SHIFT;
  8259. +}
  8260. +
  8261. +static unsigned int rx_fifo_size(struct ltq_spi_drv_data *drv)
  8262. +{
  8263. + u32 id = ltq_readl(&drv->regs->id);
  8264. +
  8265. + return (id & LTQ_SPI_ID_RXFS_MASK) >> LTQ_SPI_ID_RXFS_SHIFT;
  8266. +}
  8267. +
  8268. +static unsigned int tx_fifo_level(struct ltq_spi_drv_data *drv)
  8269. +{
  8270. + u32 fstat = ltq_readl(&drv->regs->fstat);
  8271. +
  8272. + return (fstat & LTQ_SPI_FSTAT_TXFFL_MASK) >> LTQ_SPI_FSTAT_TXFFL_SHIFT;
  8273. +}
  8274. +
  8275. +static unsigned int rx_fifo_level(struct ltq_spi_drv_data *drv)
  8276. +{
  8277. + u32 fstat = ltq_readl(&drv->regs->fstat);
  8278. +
  8279. + return fstat & LTQ_SPI_FSTAT_RXFFL_MASK;
  8280. +}
  8281. +
  8282. +static unsigned int tx_fifo_free(struct ltq_spi_drv_data *drv)
  8283. +{
  8284. + return tx_fifo_size(drv) - tx_fifo_level(drv);
  8285. +}
  8286. +
  8287. +static void hw_power_on(struct ltq_spi_drv_data *drv)
  8288. +{
  8289. + u32 clc;
  8290. +
  8291. + /* Power-up mdule */
  8292. + ltq_pm_enable(LTQ_PM_SPI);
  8293. +
  8294. + /*
  8295. + * Set clock divider for run mode to 1 to
  8296. + * run at same frequency as FPI bus
  8297. + */
  8298. + clc = (1 << LTQ_SPI_CLC_RMC_SHIFT);
  8299. + ltq_writel(&drv->regs->clc, clc);
  8300. +}
  8301. +
  8302. +static void hw_reset_fifos(struct ltq_spi_drv_data *drv)
  8303. +{
  8304. + u32 val;
  8305. +
  8306. + val = LTQ_SPI_TXFCON_TXFEN | LTQ_SPI_TXFCON_TXFLU;
  8307. + ltq_writel(&drv->regs->txfcon, val);
  8308. +
  8309. + val = LTQ_SPI_RXFCON_RXFEN | LTQ_SPI_RXFCON_RXFLU;
  8310. + ltq_writel(&drv->regs->rxfcon, val);
  8311. +}
  8312. +
  8313. +static int hw_is_busy(struct ltq_spi_drv_data *drv)
  8314. +{
  8315. + u32 stat = ltq_readl(&drv->regs->stat);
  8316. +
  8317. + return stat & LTQ_SPI_STAT_BSY;
  8318. +}
  8319. +
  8320. +static void hw_enter_config_mode(struct ltq_spi_drv_data *drv)
  8321. +{
  8322. + ltq_writel(&drv->regs->whbstate, LTQ_SPI_WHBSTATE_CLREN);
  8323. +}
  8324. +
  8325. +static void hw_enter_active_mode(struct ltq_spi_drv_data *drv)
  8326. +{
  8327. + ltq_writel(&drv->regs->whbstate, LTQ_SPI_WHBSTATE_SETEN);
  8328. +}
  8329. +
  8330. +static void hw_setup_speed_hz(struct ltq_spi_drv_data *drv,
  8331. + unsigned int max_speed_hz)
  8332. +{
  8333. + unsigned int spi_hz, speed_hz, brt;
  8334. +
  8335. + /*
  8336. + * SPI module clock is derived from FPI bus clock dependent on
  8337. + * divider value in CLC.RMS which is always set to 1.
  8338. + *
  8339. + * f_SPI
  8340. + * baudrate = --------------
  8341. + * 2 * (BR + 1)
  8342. + */
  8343. + spi_hz = ltq_get_bus_clock() / 2;
  8344. +
  8345. + /* TODO: optimize baudrate calculation */
  8346. + for (brt = 0; brt < 0xFFFF; brt++) {
  8347. + speed_hz = spi_hz / (brt + 1);
  8348. + if (speed_hz <= max_speed_hz)
  8349. + break;
  8350. + }
  8351. +
  8352. + ltq_writel(&drv->regs->brt, brt);
  8353. +}
  8354. +
  8355. +static void hw_setup_bits_per_word(struct ltq_spi_drv_data *drv,
  8356. + unsigned int bits_per_word)
  8357. +{
  8358. + u32 bm;
  8359. +
  8360. + /* CON.BM value = bits_per_word - 1 */
  8361. + bm = (bits_per_word - 1) << LTQ_SPI_CON_BM_SHIFT;
  8362. +
  8363. + ltq_clrsetbits(&drv->regs->con, LTQ_SPI_CON_BM_MASK, bm);
  8364. +}
  8365. +
  8366. +static void hw_setup_clock_mode(struct ltq_spi_drv_data *drv, unsigned int mode)
  8367. +{
  8368. + u32 con_set = 0, con_clr = 0;
  8369. +
  8370. + /*
  8371. + * SPI mode mapping in CON register:
  8372. + * Mode CPOL CPHA CON.PO CON.PH
  8373. + * 0 0 0 0 1
  8374. + * 1 0 1 0 0
  8375. + * 2 1 0 1 1
  8376. + * 3 1 1 1 0
  8377. + */
  8378. + if (mode & SPI_CPHA)
  8379. + con_clr |= LTQ_SPI_CON_PH;
  8380. + else
  8381. + con_set |= LTQ_SPI_CON_PH;
  8382. +
  8383. + if (mode & SPI_CPOL)
  8384. + con_set |= LTQ_SPI_CON_PO | LTQ_SPI_CON_IDLE;
  8385. + else
  8386. + con_clr |= LTQ_SPI_CON_PO | LTQ_SPI_CON_IDLE;
  8387. +
  8388. + /* Set heading control */
  8389. + if (mode & SPI_LSB_FIRST)
  8390. + con_clr |= LTQ_SPI_CON_HB;
  8391. + else
  8392. + con_set |= LTQ_SPI_CON_HB;
  8393. +
  8394. + /* Set loopback mode */
  8395. + if (mode & SPI_LOOP)
  8396. + con_set |= LTQ_SPI_CON_LB;
  8397. + else
  8398. + con_clr |= LTQ_SPI_CON_LB;
  8399. +
  8400. + ltq_clrsetbits(&drv->regs->con, con_clr, con_set);
  8401. +}
  8402. +
  8403. +static void hw_set_rxtx(struct ltq_spi_drv_data *drv)
  8404. +{
  8405. + u32 con;
  8406. +
  8407. + /* Configure transmitter and receiver */
  8408. + con = ltq_readl(&drv->regs->con);
  8409. + if (drv->tx)
  8410. + con &= ~LTQ_SPI_CON_TXOFF;
  8411. + else
  8412. + con |= LTQ_SPI_CON_TXOFF;
  8413. +
  8414. + if (drv->rx)
  8415. + con &= ~LTQ_SPI_CON_RXOFF;
  8416. + else
  8417. + con |= LTQ_SPI_CON_RXOFF;
  8418. +
  8419. + ltq_writel(&drv->regs->con, con);
  8420. +}
  8421. +
  8422. +static void hw_init(struct ltq_spi_drv_data *drv)
  8423. +{
  8424. + hw_power_on(drv);
  8425. +
  8426. + /* Put controller into config mode */
  8427. + hw_enter_config_mode(drv);
  8428. +
  8429. + /* Disable all interrupts */
  8430. + ltq_writel(&drv->regs->irnen, 0);
  8431. +
  8432. + /* Clear error flags */
  8433. + ltq_clrsetbits(&drv->regs->whbstate, 0, LTQ_SPI_WHBSTATE_CLR_ERRORS);
  8434. +
  8435. + /* Enable error checking, disable TX/RX */
  8436. + ltq_writel(&drv->regs->con, LTQ_SPI_CON_RUEN | LTQ_SPI_CON_AEN |
  8437. + LTQ_SPI_CON_TEN | LTQ_SPI_CON_REN | LTQ_SPI_CON_TXOFF |
  8438. + LTQ_SPI_CON_RXOFF);
  8439. +
  8440. + /* Setup default SPI mode */
  8441. + drv->bits_per_word = 8;
  8442. + drv->speed_hz = 0;
  8443. + hw_setup_bits_per_word(drv, drv->bits_per_word);
  8444. + hw_setup_clock_mode(drv, SPI_MODE_0);
  8445. +
  8446. + /* Enable master mode and clear error flags */
  8447. + ltq_writel(&drv->regs->whbstate, LTQ_SPI_WHBSTATE_SETMS |
  8448. + LTQ_SPI_WHBSTATE_CLR_ERRORS);
  8449. +
  8450. + /* Reset GPIO/CS registers */
  8451. + ltq_writel(&drv->regs->gpocon, 0);
  8452. + ltq_writel(&drv->regs->fgpo, 0xFF00);
  8453. +
  8454. + /* Enable and flush FIFOs */
  8455. + hw_reset_fifos(drv);
  8456. +
  8457. + /* SPI/DIN input */
  8458. + gpio_set_altfunc(16, GPIO_ALTSEL_SET, GPIO_ALTSEL_CLR, GPIO_DIR_IN);
  8459. + /* SPI/DOUT output */
  8460. + gpio_set_altfunc(17, GPIO_ALTSEL_SET, GPIO_ALTSEL_CLR, GPIO_DIR_OUT);
  8461. + /* SPI/CLK output */
  8462. + gpio_set_altfunc(18, GPIO_ALTSEL_SET, GPIO_ALTSEL_CLR, GPIO_DIR_OUT);
  8463. +}
  8464. +
  8465. +static void tx_fifo_write(struct ltq_spi_drv_data *drv)
  8466. +{
  8467. + const u8 *tx8;
  8468. + const u16 *tx16;
  8469. + const u32 *tx32;
  8470. + u32 data;
  8471. + unsigned int tx_free = tx_fifo_free(drv);
  8472. +
  8473. + while (drv->tx_todo && tx_free) {
  8474. + switch (drv->bits_per_word) {
  8475. + case 8:
  8476. + tx8 = drv->tx;
  8477. + data = *tx8;
  8478. + drv->tx_todo--;
  8479. + drv->tx++;
  8480. + break;
  8481. + case 16:
  8482. + tx16 = (u16 *) drv->tx;
  8483. + data = *tx16;
  8484. + drv->tx_todo -= 2;
  8485. + drv->tx += 2;
  8486. + break;
  8487. + case 32:
  8488. + tx32 = (u32 *) drv->tx;
  8489. + data = *tx32;
  8490. + drv->tx_todo -= 4;
  8491. + drv->tx += 4;
  8492. + break;
  8493. + default:
  8494. + return;
  8495. + }
  8496. +
  8497. + ltq_writel(&drv->regs->tb, data);
  8498. + tx_free--;
  8499. + }
  8500. +}
  8501. +
  8502. +static void rx_fifo_read_full_duplex(struct ltq_spi_drv_data *drv)
  8503. +{
  8504. + u8 *rx8;
  8505. + u16 *rx16;
  8506. + u32 *rx32;
  8507. + u32 data;
  8508. + unsigned int rx_fill = rx_fifo_level(drv);
  8509. +
  8510. + while (rx_fill) {
  8511. + data = ltq_readl(&drv->regs->rb);
  8512. +
  8513. + switch (drv->bits_per_word) {
  8514. + case 8:
  8515. + rx8 = drv->rx;
  8516. + *rx8 = data;
  8517. + drv->rx_todo--;
  8518. + drv->rx++;
  8519. + break;
  8520. + case 16:
  8521. + rx16 = (u16 *) drv->rx;
  8522. + *rx16 = data;
  8523. + drv->rx_todo -= 2;
  8524. + drv->rx += 2;
  8525. + break;
  8526. + case 32:
  8527. + rx32 = (u32 *) drv->rx;
  8528. + *rx32 = data;
  8529. + drv->rx_todo -= 4;
  8530. + drv->rx += 4;
  8531. + break;
  8532. + default:
  8533. + return;
  8534. + }
  8535. +
  8536. + rx_fill--;
  8537. + }
  8538. +}
  8539. +
  8540. +static void rx_fifo_read_half_duplex(struct ltq_spi_drv_data *drv)
  8541. +{
  8542. + u32 data, *rx32;
  8543. + u8 *rx8;
  8544. + unsigned int rxbv, shift;
  8545. + unsigned int rx_fill = rx_fifo_level(drv);
  8546. +
  8547. + /*
  8548. + * In RX-only mode the bits per word value is ignored by HW. A value
  8549. + * of 32 is used instead. Thus all 4 bytes per FIFO must be read.
  8550. + * If remaining RX bytes are less than 4, the FIFO must be read
  8551. + * differently. The amount of received and valid bytes is indicated
  8552. + * by STAT.RXBV register value.
  8553. + */
  8554. + while (rx_fill) {
  8555. + if (drv->rx_todo < 4) {
  8556. + rxbv = (ltq_readl(&drv->regs->stat) &
  8557. + LTQ_SPI_STAT_RXBV_MASK) >>
  8558. + LTQ_SPI_STAT_RXBV_SHIFT;
  8559. + data = ltq_readl(&drv->regs->rb);
  8560. +
  8561. + shift = (rxbv - 1) * 8;
  8562. + rx8 = drv->rx;
  8563. +
  8564. + while (rxbv) {
  8565. + *rx8++ = (data >> shift) & 0xFF;
  8566. + rxbv--;
  8567. + shift -= 8;
  8568. + drv->rx_todo--;
  8569. + drv->rx++;
  8570. +
  8571. + if (drv->rx_req)
  8572. + drv->rx_req --;
  8573. + }
  8574. + } else {
  8575. + data = ltq_readl(&drv->regs->rb);
  8576. + rx32 = (u32 *) drv->rx;
  8577. +
  8578. + *rx32++ = data;
  8579. + drv->rx_todo -= 4;
  8580. + drv->rx += 4;
  8581. +
  8582. + if (drv->rx_req >= 4)
  8583. + drv->rx_req -= 4;
  8584. + }
  8585. + rx_fill--;
  8586. + }
  8587. +}
  8588. +
  8589. +static void rx_request(struct ltq_spi_drv_data *drv)
  8590. +{
  8591. + unsigned int rxreq, rxreq_max;
  8592. +
  8593. + if (drv->rx_req)
  8594. + return;
  8595. +
  8596. + /*
  8597. + * To avoid receive overflows at high clocks it is better to request
  8598. + * only the amount of bytes that fits into all FIFOs. This value
  8599. + * depends on the FIFO size implemented in hardware.
  8600. + */
  8601. + rxreq = drv->rx_todo;
  8602. + rxreq_max = rx_fifo_size(drv) * 4;
  8603. + if (rxreq > rxreq_max)
  8604. + rxreq = rxreq_max;
  8605. +
  8606. + drv->rx_req = rxreq;
  8607. + ltq_writel(&drv->regs->rxreq, rxreq);
  8608. +}
  8609. +
  8610. +void spi_init(void)
  8611. +{
  8612. +}
  8613. +
  8614. +struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
  8615. + unsigned int max_hz, unsigned int mode)
  8616. +{
  8617. + struct ltq_spi_drv_data *drv;
  8618. +
  8619. + if (!spi_cs_is_valid(bus, cs))
  8620. + return NULL;
  8621. +
  8622. + drv = ltq_spi_slave_alloc(bus, cs);
  8623. + if (!drv)
  8624. + return NULL;
  8625. +
  8626. + drv->regs = (struct ltq_spi_regs *) CKSEG1ADDR(LTQ_SPI_BASE);
  8627. +
  8628. + hw_init(drv);
  8629. +
  8630. + drv->max_hz = max_hz;
  8631. + drv->mode = mode;
  8632. +
  8633. + return &drv->slave;
  8634. +}
  8635. +
  8636. +void spi_free_slave(struct spi_slave *slave)
  8637. +{
  8638. + ltq_spi_slave_free(slave);
  8639. +}
  8640. +
  8641. +static int ltq_spi_wait_ready(struct ltq_spi_drv_data *drv)
  8642. +{
  8643. + const unsigned long timeout = 20000;
  8644. + unsigned long timebase;
  8645. +
  8646. + timebase = get_timer(0);
  8647. +
  8648. + do {
  8649. + WATCHDOG_RESET();
  8650. +
  8651. + if (!hw_is_busy(drv))
  8652. + return 0;
  8653. + } while (get_timer(timebase) < timeout);
  8654. +
  8655. + return 1;
  8656. +}
  8657. +
  8658. +int spi_claim_bus(struct spi_slave *slave)
  8659. +{
  8660. + struct ltq_spi_drv_data *drv = to_ltq_spi_slave(slave);
  8661. + int ret;
  8662. +
  8663. + ret = ltq_spi_wait_ready(drv);
  8664. + if (ret) {
  8665. + debug("cannot claim bus\n");
  8666. + return ret;
  8667. + }
  8668. +
  8669. + hw_enter_config_mode(drv);
  8670. + hw_setup_clock_mode(drv, drv->mode);
  8671. + hw_setup_speed_hz(drv, drv->max_hz);
  8672. + hw_setup_bits_per_word(drv, drv->bits_per_word);
  8673. + hw_enter_active_mode(drv);
  8674. +
  8675. + return 0;
  8676. +}
  8677. +
  8678. +void spi_release_bus(struct spi_slave *slave)
  8679. +{
  8680. + struct ltq_spi_drv_data *drv = to_ltq_spi_slave(slave);
  8681. +
  8682. + hw_enter_config_mode(drv);
  8683. +}
  8684. +
  8685. +int spi_xfer(struct spi_slave *slave, unsigned int bitlen,
  8686. + const void *dout, void *din, unsigned long flags)
  8687. +{
  8688. +
  8689. + struct ltq_spi_drv_data *drv = to_ltq_spi_slave(slave);
  8690. + int ret = 0;
  8691. +
  8692. + if (bitlen % 8)
  8693. + return 1;
  8694. +
  8695. + if (!bitlen) {
  8696. + ret = 0;
  8697. + goto done;
  8698. + }
  8699. +
  8700. + if (flags & SPI_XFER_BEGIN)
  8701. + spi_cs_activate(slave);
  8702. +
  8703. + drv->tx = dout;
  8704. + drv->tx_todo = 0;
  8705. + drv->rx = din;
  8706. + drv->rx_todo = 0;
  8707. + hw_set_rxtx(drv);
  8708. +
  8709. + if (drv->tx) {
  8710. + drv->tx_todo = bitlen / 8;
  8711. +
  8712. + tx_fifo_write(drv);
  8713. + }
  8714. +
  8715. + if (drv->rx) {
  8716. + drv->rx_todo = bitlen / 8;
  8717. +
  8718. + if (!drv->tx)
  8719. + rx_request(drv);
  8720. + }
  8721. +
  8722. + for (;;) {
  8723. + if (drv->tx) {
  8724. + if (drv->rx && drv->rx_todo)
  8725. + rx_fifo_read_full_duplex(drv);
  8726. +
  8727. + if (drv->tx_todo)
  8728. + tx_fifo_write(drv);
  8729. + else
  8730. + goto done;
  8731. + } else if (drv->rx) {
  8732. + if (drv->rx_todo) {
  8733. + rx_fifo_read_half_duplex(drv);
  8734. +
  8735. + if (drv->rx_todo)
  8736. + rx_request(drv);
  8737. + else
  8738. + goto done;
  8739. + } else {
  8740. + goto done;
  8741. + }
  8742. + }
  8743. + }
  8744. +
  8745. +done:
  8746. + ret = ltq_spi_wait_ready(drv);
  8747. +
  8748. + drv->rx = NULL;
  8749. + drv->tx = NULL;
  8750. + hw_set_rxtx(drv);
  8751. +
  8752. + if (flags & SPI_XFER_END)
  8753. + spi_cs_deactivate(slave);
  8754. +
  8755. + return ret;
  8756. +}
  8757. --- /dev/null
  8758. +++ b/include/configs/easy50712.h
  8759. @@ -0,0 +1,79 @@
  8760. +/*
  8761. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  8762. + *
  8763. + * SPDX-License-Identifier: GPL-2.0+
  8764. + */
  8765. +
  8766. +#ifndef __CONFIG_H
  8767. +#define __CONFIG_H
  8768. +
  8769. +#define CONFIG_MACH_TYPE "EASY50712"
  8770. +#define CONFIG_IDENT_STRING " "CONFIG_MACH_TYPE
  8771. +#define CONFIG_BOARD_NAME "Lantiq EASY50712 Danube Reference Board"
  8772. +
  8773. +/* Configure SoC */
  8774. +#define CONFIG_LTQ_SUPPORT_UART /* Enable ASC and UART */
  8775. +
  8776. +#define CONFIG_LTQ_SUPPORT_ETHERNET /* Enable ethernet */
  8777. +
  8778. +#define CONFIG_LTQ_SUPPORT_NOR_FLASH /* Have a parallel NOR flash */
  8779. +
  8780. +#define CONFIG_LTQ_SUPPORT_SPI_FLASH
  8781. +#define CONFIG_SPI_FLASH_ATMEL /* Have an AT45DB321D serial flash */
  8782. +
  8783. +#define CONFIG_LTQ_SUPPORT_NAND_FLASH
  8784. +
  8785. +#define CONFIG_LTQ_SUPPORT_SPL_NOR_FLASH /* Build NOR flash SPL */
  8786. +
  8787. +#define CONFIG_LTQ_SPL_COMP_LZO
  8788. +#define CONFIG_LTQ_SPL_CONSOLE
  8789. +
  8790. +/* Switch devices */
  8791. +#define CONFIG_SWITCH_MULTI
  8792. +#define CONFIG_SWITCH_ADM6996I
  8793. +
  8794. +/* Environment */
  8795. +#define CONFIG_ENV_SPI_BUS 0
  8796. +#define CONFIG_ENV_SPI_CS 2
  8797. +#define CONFIG_ENV_SPI_MAX_HZ 20000000
  8798. +#define CONFIG_ENV_SPI_MODE 0
  8799. +
  8800. +#if defined(CONFIG_SYS_BOOT_NOR)
  8801. +#define CONFIG_ENV_IS_IN_FLASH
  8802. +#define CONFIG_ENV_OVERWRITE
  8803. +#define CONFIG_ENV_OFFSET (256 * 1024)
  8804. +#define CONFIG_ENV_SECT_SIZE (64 * 1024)
  8805. +#elif defined(CONFIG_SYS_BOOT_NORSPL)
  8806. +#define CONFIG_ENV_IS_IN_FLASH
  8807. +#define CONFIG_ENV_OVERWRITE
  8808. +#define CONFIG_ENV_OFFSET (128 * 1024)
  8809. +#define CONFIG_ENV_SECT_SIZE (64 * 1024)
  8810. +#else
  8811. +#define CONFIG_ENV_IS_NOWHERE
  8812. +#endif
  8813. +
  8814. +#define CONFIG_ENV_SIZE (8 * 1024)
  8815. +
  8816. +#define CONFIG_LOADADDR CONFIG_SYS_LOAD_ADDR
  8817. +
  8818. +/* Console */
  8819. +#define CONFIG_LTQ_ADVANCED_CONSOLE
  8820. +#define CONFIG_BAUDRATE 115200
  8821. +#define CONFIG_CONSOLE_ASC 1
  8822. +#define CONFIG_CONSOLE_DEV "ttyLTQ1"
  8823. +
  8824. +/* Commands */
  8825. +#define CONFIG_CMD_PING
  8826. +
  8827. +/* Pull in default board configs for Lantiq XWAY Danube */
  8828. +#include <asm/lantiq/config.h>
  8829. +#include <asm/arch/config.h>
  8830. +
  8831. +#define CONFIG_ENV_UPDATE_UBOOT_NOR \
  8832. + "update-uboot-nor=run load-uboot-norspl-lzo write-uboot-nor\0"
  8833. +
  8834. +#define CONFIG_EXTRA_ENV_SETTINGS \
  8835. + CONFIG_ENV_LANTIQ_DEFAULTS \
  8836. + CONFIG_ENV_UPDATE_UBOOT_NOR
  8837. +
  8838. +#endif /* __CONFIG_H */
  8839. --- /dev/null
  8840. +++ b/include/configs/easy80920.h
  8841. @@ -0,0 +1,92 @@
  8842. +/*
  8843. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  8844. + *
  8845. + * SPDX-License-Identifier: GPL-2.0+
  8846. + */
  8847. +
  8848. +#ifndef __CONFIG_H
  8849. +#define __CONFIG_H
  8850. +
  8851. +#define CONFIG_MACH_TYPE "EASY80920"
  8852. +#define CONFIG_IDENT_STRING " "CONFIG_MACH_TYPE
  8853. +#define CONFIG_BOARD_NAME "Lantiq EASY80920 VRX200 Family Board"
  8854. +
  8855. +/* Configure SoC */
  8856. +#define CONFIG_LTQ_SUPPORT_UART /* Enable ASC and UART */
  8857. +
  8858. +#define CONFIG_LTQ_SUPPORT_ETHERNET /* Enable ethernet */
  8859. +
  8860. +#define CONFIG_LTQ_SUPPORT_NOR_FLASH /* Have a parallel NOR flash */
  8861. +
  8862. +#define CONFIG_LTQ_SUPPORT_SPI_FLASH
  8863. +#define CONFIG_SPI_FLASH_MACRONIX /* Have a MX29LV620 serial flash */
  8864. +
  8865. +#define CONFIG_LTQ_SUPPORT_NAND_FLASH
  8866. +
  8867. +#define CONFIG_LTQ_SUPPORT_SPL_SPI_FLASH /* Build SPI flash SPL */
  8868. +#define CONFIG_SPL_SPI_BUS 0
  8869. +#define CONFIG_SPL_SPI_CS 4
  8870. +#define CONFIG_SPL_SPI_MAX_HZ 25000000
  8871. +#define CONFIG_SPL_SPI_MODE 0
  8872. +
  8873. +#define CONFIG_LTQ_SUPPORT_SPL_NOR_FLASH /* Build NOR flash SPL */
  8874. +
  8875. +#define CONFIG_LTQ_SPL_COMP_LZO
  8876. +#define CONFIG_LTQ_SPL_CONSOLE
  8877. +
  8878. +#define CONFIG_SYS_DRAM_PROBE
  8879. +
  8880. +/* Environment */
  8881. +#define CONFIG_ENV_SPI_BUS CONFIG_SPL_SPI_BUS
  8882. +#define CONFIG_ENV_SPI_CS CONFIG_SPL_SPI_CS
  8883. +#define CONFIG_ENV_SPI_MAX_HZ CONFIG_SPL_SPI_MAX_HZ
  8884. +#define CONFIG_ENV_SPI_MODE CONFIG_SPL_SPI_MODE
  8885. +
  8886. +#if defined(CONFIG_SYS_BOOT_NOR)
  8887. +#define CONFIG_ENV_IS_IN_FLASH
  8888. +#define CONFIG_ENV_OVERWRITE
  8889. +#define CONFIG_ENV_OFFSET (384 * 1024)
  8890. +#define CONFIG_ENV_SECT_SIZE (64 * 1024)
  8891. +#elif defined(CONFIG_SYS_BOOT_NORSPL)
  8892. +#define CONFIG_ENV_IS_IN_FLASH
  8893. +#define CONFIG_ENV_OVERWRITE
  8894. +#define CONFIG_ENV_OFFSET (192 * 1024)
  8895. +#define CONFIG_ENV_SECT_SIZE (64 * 1024)
  8896. +#elif defined(CONFIG_SYS_BOOT_SFSPL)
  8897. +#define CONFIG_ENV_IS_IN_SPI_FLASH
  8898. +#define CONFIG_ENV_OVERWRITE
  8899. +#define CONFIG_ENV_OFFSET (192 * 1024)
  8900. +#define CONFIG_ENV_SECT_SIZE (64 * 1024)
  8901. +#else
  8902. +#define CONFIG_ENV_IS_NOWHERE
  8903. +#endif
  8904. +
  8905. +#define CONFIG_ENV_SIZE (8 * 1024)
  8906. +
  8907. +#define CONFIG_LOADADDR CONFIG_SYS_LOAD_ADDR
  8908. +
  8909. +/* Console */
  8910. +#define CONFIG_LTQ_ADVANCED_CONSOLE
  8911. +#define CONFIG_BAUDRATE 115200
  8912. +#define CONFIG_CONSOLE_ASC 1
  8913. +#define CONFIG_CONSOLE_DEV "ttyLTQ1"
  8914. +
  8915. +/* Commands */
  8916. +#define CONFIG_CMD_PING
  8917. +
  8918. +/* Pull in default board configs for Lantiq XWAY VRX200 */
  8919. +#include <asm/lantiq/config.h>
  8920. +#include <asm/arch/config.h>
  8921. +
  8922. +#define CONFIG_ENV_UPDATE_UBOOT_NOR \
  8923. + "update-uboot-nor=run load-uboot-norspl-lzo write-uboot-nor\0"
  8924. +
  8925. +#define CONFIG_ENV_UPDATE_UBOOT_SF \
  8926. + "update-uboot-sf=run load-uboot-sfspl-lzo write-uboot-sf\0"
  8927. +
  8928. +#define CONFIG_EXTRA_ENV_SETTINGS \
  8929. + CONFIG_ENV_LANTIQ_DEFAULTS \
  8930. + CONFIG_ENV_UPDATE_UBOOT_NOR \
  8931. + CONFIG_ENV_UPDATE_UBOOT_SF
  8932. +
  8933. +#endif /* __CONFIG_H */
  8934. --- a/include/phy.h
  8935. +++ b/include/phy.h
  8936. @@ -214,6 +214,7 @@ int phy_atheros_init(void);
  8937. int phy_broadcom_init(void);
  8938. int phy_davicom_init(void);
  8939. int phy_et1011c_init(void);
  8940. +int phy_lantiq_init(void);
  8941. int phy_lxt_init(void);
  8942. int phy_marvell_init(void);
  8943. int phy_micrel_init(void);
  8944. --- a/spl/Makefile
  8945. +++ b/spl/Makefile
  8946. @@ -100,6 +100,8 @@ LIBS-$(CONFIG_SPL_USBETH_SUPPORT) += dri
  8947. LIBS-$(CONFIG_SPL_MUSB_NEW_SUPPORT) += drivers/usb/musb-new/libusb_musb-new.o
  8948. LIBS-$(CONFIG_SPL_USBETH_SUPPORT) += drivers/usb/gadget/libusb_gadget.o
  8949. LIBS-$(CONFIG_SPL_WATCHDOG_SUPPORT) += drivers/watchdog/libwatchdog.o
  8950. +LIBS-$(CONFIG_SPL_LZMA_SUPPORT) += lib/lzma/liblzma.o
  8951. +LIBS-$(CONFIG_SPL_LZO_SUPPORT) += lib/lzo/liblzo.o
  8952. ifneq ($(CONFIG_OMAP_COMMON),)
  8953. LIBS-y += $(CPUDIR)/omap-common/libomap-common.o
  8954. --- a/tools/.gitignore
  8955. +++ b/tools/.gitignore
  8956. @@ -2,6 +2,7 @@
  8957. /envcrc
  8958. /gen_eth_addr
  8959. /img2srec
  8960. +/ltq-boot-image
  8961. /kwboot
  8962. /mkenvimage
  8963. /mkimage
  8964. --- a/tools/Makefile
  8965. +++ b/tools/Makefile
  8966. @@ -49,6 +49,7 @@ BIN_FILES-$(CONFIG_VIDEO_LOGO) += bmp_lo
  8967. BIN_FILES-$(CONFIG_BUILD_ENVCRC) += envcrc$(SFX)
  8968. BIN_FILES-$(CONFIG_CMD_NET) += gen_eth_addr$(SFX)
  8969. BIN_FILES-$(CONFIG_CMD_LOADS) += img2srec$(SFX)
  8970. +BIN_FILES-$(CONFIG_SOC_LANTIQ) += ltq-boot-image$(SFX)
  8971. BIN_FILES-$(CONFIG_XWAY_SWAP_BYTES) += xway-swap-bytes$(SFX)
  8972. BIN_FILES-y += mkenvimage$(SFX)
  8973. BIN_FILES-y += mkimage$(SFX)
  8974. @@ -95,6 +96,7 @@ OBJ_FILES-$(CONFIG_MX28) += mxsboot.o
  8975. OBJ_FILES-$(CONFIG_NETCONSOLE) += ncb.o
  8976. OBJ_FILES-$(CONFIG_SHA1_CHECK_UB_IMG) += ubsha1.o
  8977. OBJ_FILES-$(CONFIG_SMDK5250) += mkexynosspl.o
  8978. +OBJ_FILES-$(CONFIG_SOC_LANTIQ) += ltq-boot-image.o
  8979. OBJ_FILES-$(CONFIG_VIDEO_LOGO) += bmp_logo.o
  8980. OBJ_FILES-$(CONFIG_XWAY_SWAP_BYTES) += xway-swap-bytes.o
  8981. @@ -195,6 +197,10 @@ $(obj)img2srec$(SFX): $(obj)img2srec.o
  8982. $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
  8983. $(HOSTSTRIP) $@
  8984. +$(obj)ltq-boot-image$(SFX): $(obj)ltq-boot-image.o
  8985. + $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
  8986. + $(HOSTSTRIP) $@
  8987. +
  8988. $(obj)xway-swap-bytes$(SFX): $(obj)xway-swap-bytes.o
  8989. $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
  8990. $(HOSTSTRIP) $@
  8991. --- /dev/null
  8992. +++ b/tools/ltq-boot-image.c
  8993. @@ -0,0 +1,315 @@
  8994. +/*
  8995. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  8996. + *
  8997. + * SPDX-License-Identifier: GPL-2.0+
  8998. + */
  8999. +
  9000. +#include <stdio.h>
  9001. +#include <stdlib.h>
  9002. +#include <string.h>
  9003. +#include <unistd.h>
  9004. +#include <getopt.h>
  9005. +#include <compiler.h>
  9006. +#include <sys/stat.h>
  9007. +
  9008. +enum image_types {
  9009. + IMAGE_NONE,
  9010. + IMAGE_SFSPL
  9011. +};
  9012. +
  9013. +/* Lantiq non-volatile bootstrap command IDs */
  9014. +enum nvb_cmd_ids {
  9015. + NVB_CMD_DEBUG = 0x11,
  9016. + NVB_CMD_REGCFG = 0x22,
  9017. + NVB_CMD_IDWNLD = 0x33,
  9018. + NVB_CMD_CDWNLD = 0x44,
  9019. + NVB_CMD_DWNLD = 0x55,
  9020. + NVB_CMD_IFCFG = 0x66,
  9021. + NVB_CMD_START = 0x77
  9022. +};
  9023. +
  9024. +/* Lantiq non-volatile bootstrap command flags */
  9025. +enum nvb_cmd_flags {
  9026. + NVB_FLAG_START = 1,
  9027. + NVB_FLAG_DEC = (1 << 1),
  9028. + NVB_FLAG_DBG = (1 << 2),
  9029. + NVB_FLAG_SDBG = (1 << 3),
  9030. + NVB_FLAG_CFG0 = (1 << 4),
  9031. + NVB_FLAG_CFG1 = (1 << 5),
  9032. + NVB_FLAG_CFG2 = (1 << 6),
  9033. + NVB_FLAG_RST = (1 << 7)
  9034. +};
  9035. +
  9036. +struct args {
  9037. + enum image_types type;
  9038. + __u32 entry_addr;
  9039. + const char *uboot_bin;
  9040. + const char *spl_bin;
  9041. + const char *out_bin;
  9042. +};
  9043. +
  9044. +static void usage_msg(const char *name)
  9045. +{
  9046. + fprintf(stderr, "%s: [-h] -t type -e entry-addr -u uboot-bin [-s spl-bin] -o out-bin\n",
  9047. + name);
  9048. + fprintf(stderr, " Image types:\n"
  9049. + " sfspl - SPL + [compressed] U-Boot for SPI flash\n");
  9050. +}
  9051. +
  9052. +static enum image_types parse_image_type(const char *type)
  9053. +{
  9054. + if (!type)
  9055. + return IMAGE_NONE;
  9056. +
  9057. + if (!strncmp(type, "sfspl", 6))
  9058. + return IMAGE_SFSPL;
  9059. +
  9060. + return IMAGE_NONE;
  9061. +}
  9062. +
  9063. +static int parse_args(int argc, char *argv[], struct args *arg)
  9064. +{
  9065. + int opt;
  9066. +
  9067. + memset(arg, 0, sizeof(*arg));
  9068. +
  9069. + while ((opt = getopt(argc, argv, "ht:e:u:s:o:")) != -1) {
  9070. + switch (opt) {
  9071. + case 'h':
  9072. + usage_msg(argv[0]);
  9073. + return 1;
  9074. + case 't':
  9075. + arg->type = parse_image_type(optarg);
  9076. + break;
  9077. + case 'e':
  9078. + arg->entry_addr = strtoul(optarg, NULL, 16);
  9079. + break;
  9080. + case 'u':
  9081. + arg->uboot_bin = optarg;
  9082. + break;
  9083. + case 's':
  9084. + arg->spl_bin = optarg;
  9085. + break;
  9086. + case 'o':
  9087. + arg->out_bin = optarg;
  9088. + break;
  9089. + default:
  9090. + fprintf(stderr, "Invalid option -%c\n", opt);
  9091. + goto parse_error;
  9092. + }
  9093. + }
  9094. +
  9095. + if (arg->type == IMAGE_NONE) {
  9096. + fprintf(stderr, "Invalid image type\n");
  9097. + goto parse_error;
  9098. + }
  9099. +
  9100. + if (!arg->uboot_bin) {
  9101. + fprintf(stderr, "Missing U-Boot binary\n");
  9102. + goto parse_error;
  9103. + }
  9104. +
  9105. + if (!arg->out_bin) {
  9106. + fprintf(stderr, "Missing output binary\n");
  9107. + goto parse_error;
  9108. + }
  9109. +
  9110. + if (arg->type == IMAGE_SFSPL && !arg->spl_bin) {
  9111. + fprintf(stderr, "Missing SPL binary\n");
  9112. + goto parse_error;
  9113. + }
  9114. +
  9115. + return 0;
  9116. +
  9117. +parse_error:
  9118. + usage_msg(argv[0]);
  9119. + return -1;
  9120. +}
  9121. +
  9122. +static __u32 build_nvb_command(unsigned cmdid, unsigned cmdflags)
  9123. +{
  9124. + __u32 cmd;
  9125. + __u16 tag;
  9126. +
  9127. + tag = (cmdid << 8) | cmdflags;
  9128. + cmd = (tag << 16) | (0xFFFF - tag);
  9129. +
  9130. + return cpu_to_be32(cmd);
  9131. +}
  9132. +
  9133. +static int write_header(int fd, const void *hdr, size_t size)
  9134. +{
  9135. + ssize_t n;
  9136. +
  9137. + n = write(fd, hdr, size);
  9138. + if (n != size) {
  9139. + fprintf(stderr, "Cannot write header: %s\n",
  9140. + strerror(errno));
  9141. + return -1;
  9142. + }
  9143. +
  9144. + return 0;
  9145. +}
  9146. +
  9147. +static int write_nvb_dwnld_header(int fd, size_t size, __u32 addr)
  9148. +{
  9149. + __u32 hdr[3];
  9150. +
  9151. + hdr[0] = build_nvb_command(NVB_CMD_DWNLD, NVB_FLAG_START |
  9152. + NVB_FLAG_SDBG);
  9153. + hdr[1] = cpu_to_be32(size + 4);
  9154. + hdr[2] = cpu_to_be32(addr);
  9155. +
  9156. + return write_header(fd, hdr, sizeof(hdr));
  9157. +}
  9158. +
  9159. +static int write_nvb_start_header(int fd, __u32 addr)
  9160. +{
  9161. + __u32 hdr[3];
  9162. +
  9163. + hdr[0] = build_nvb_command(NVB_CMD_START, NVB_FLAG_SDBG);
  9164. + hdr[1] = cpu_to_be32(4);
  9165. + hdr[2] = cpu_to_be32(addr);
  9166. +
  9167. + return write_header(fd, hdr, sizeof(hdr));
  9168. +}
  9169. +
  9170. +static int open_input_bin(const char *name, void **ptr, size_t *size)
  9171. +{
  9172. + struct stat sbuf;
  9173. + int ret, fd;
  9174. +
  9175. + fd = open(name, O_RDONLY | O_BINARY);
  9176. + if (0 > fd) {
  9177. + fprintf(stderr, "Cannot open %s: %s\n", name,
  9178. + strerror(errno));
  9179. + return -1;
  9180. + }
  9181. +
  9182. + ret = fstat(fd, &sbuf);
  9183. + if (0 > ret) {
  9184. + fprintf(stderr, "Cannot fstat %s: %s\n", name,
  9185. + strerror(errno));
  9186. + return -1;
  9187. + }
  9188. +
  9189. + *ptr = mmap(0, sbuf.st_size, PROT_READ, MAP_SHARED, fd, 0);
  9190. + if (*ptr == MAP_FAILED) {
  9191. + fprintf(stderr, "Cannot mmap %s: %s\n", name,
  9192. + strerror(errno));
  9193. + return -1;
  9194. + }
  9195. +
  9196. + *size = sbuf.st_size;
  9197. +
  9198. + return fd;
  9199. +}
  9200. +
  9201. +static void close_input_bin(int fd, void *ptr, size_t size)
  9202. +{
  9203. + munmap(ptr, size);
  9204. + close(fd);
  9205. +}
  9206. +
  9207. +static int copy_bin(int fd, void *ptr, size_t size)
  9208. +{
  9209. + ssize_t n;
  9210. +
  9211. + n = write(fd, ptr, size);
  9212. + if (n != size) {
  9213. + fprintf(stderr, "Cannot copy binary: %s\n", strerror(errno));
  9214. + return -1;
  9215. + }
  9216. +
  9217. + return 0;
  9218. +}
  9219. +
  9220. +static int open_output_bin(const char *name)
  9221. +{
  9222. + int fd;
  9223. +
  9224. + fd = open(name, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0666);
  9225. + if (0 > fd) {
  9226. + fprintf(stderr, "Cannot open %s: %s\n", name,
  9227. + strerror(errno));
  9228. + return -1;
  9229. + }
  9230. +
  9231. + return fd;
  9232. +}
  9233. +
  9234. +static int create_sfspl(const struct args *arg)
  9235. +{
  9236. + int out_fd, uboot_fd, spl_fd, ret;
  9237. + void *uboot_ptr, *spl_ptr;
  9238. + size_t uboot_size, spl_size;
  9239. +
  9240. + out_fd = open_output_bin(arg->out_bin);
  9241. + if (0 > out_fd)
  9242. + goto err;
  9243. +
  9244. + spl_fd = open_input_bin(arg->spl_bin, &spl_ptr, &spl_size);
  9245. + if (0 > spl_fd)
  9246. + goto err_spl;
  9247. +
  9248. + uboot_fd = open_input_bin(arg->uboot_bin, &uboot_ptr, &uboot_size);
  9249. + if (0 > uboot_fd)
  9250. + goto err_uboot;
  9251. +
  9252. + ret = write_nvb_dwnld_header(out_fd, spl_size, arg->entry_addr);
  9253. + if (ret)
  9254. + goto err_write;
  9255. +
  9256. + ret = copy_bin(out_fd, spl_ptr, spl_size);
  9257. + if (ret)
  9258. + goto err_write;
  9259. +
  9260. + ret = write_nvb_start_header(out_fd, arg->entry_addr);
  9261. + if (ret)
  9262. + goto err_write;
  9263. +
  9264. + ret = copy_bin(out_fd, uboot_ptr, uboot_size);
  9265. + if (ret)
  9266. + goto err_write;
  9267. +
  9268. + close_input_bin(uboot_fd, uboot_ptr, uboot_size);
  9269. + close_input_bin(spl_fd, spl_ptr, spl_size);
  9270. + close(out_fd);
  9271. +
  9272. + return 0;
  9273. +
  9274. +err_write:
  9275. + close_input_bin(uboot_fd, uboot_ptr, uboot_size);
  9276. +err_uboot:
  9277. + close_input_bin(spl_fd, spl_ptr, spl_size);
  9278. +err_spl:
  9279. + close(out_fd);
  9280. +err:
  9281. + return -1;
  9282. +}
  9283. +
  9284. +int main(int argc, char *argv[])
  9285. +{
  9286. + int ret;
  9287. + struct args arg;
  9288. +
  9289. + ret = parse_args(argc, argv, &arg);
  9290. + if (ret)
  9291. + goto done;
  9292. +
  9293. + switch (arg.type) {
  9294. + case IMAGE_SFSPL:
  9295. + ret = create_sfspl(&arg);
  9296. + break;
  9297. + default:
  9298. + fprintf(stderr, "Image type not implemented\n");
  9299. + ret = -1;
  9300. + break;
  9301. + }
  9302. +
  9303. +done:
  9304. + if (ret >= 0)
  9305. + return EXIT_SUCCESS;
  9306. +
  9307. + return EXIT_FAILURE;
  9308. +}