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

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