fon2100.patch 183 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279
  1. diff -Nur linux-2.6.39-rc7.orig/arch/mips/Kbuild.platforms linux-2.6.39-rc7/arch/mips/Kbuild.platforms
  2. --- linux-2.6.39-rc7.orig/arch/mips/Kbuild.platforms 2011-05-10 04:33:54.000000000 +0200
  3. +++ linux-2.6.39-rc7/arch/mips/Kbuild.platforms 2011-05-15 21:34:57.000000000 +0200
  4. @@ -6,6 +6,7 @@
  5. platforms += bcm47xx
  6. platforms += bcm63xx
  7. platforms += cavium-octeon
  8. +platforms += ar231x
  9. platforms += cobalt
  10. platforms += dec
  11. platforms += emma
  12. diff -Nur linux-2.6.39-rc7.orig/arch/mips/Kconfig linux-2.6.39-rc7/arch/mips/Kconfig
  13. --- linux-2.6.39-rc7.orig/arch/mips/Kconfig 2011-05-10 04:33:54.000000000 +0200
  14. +++ linux-2.6.39-rc7/arch/mips/Kconfig 2011-05-16 12:11:11.000000000 +0200
  15. @@ -121,6 +121,21 @@
  16. help
  17. Support for BCM63XX based boards
  18. +config ATHEROS_AR231X
  19. + bool "Atheros 231x/531x SoC support"
  20. + select CEVT_R4K
  21. + select CSRC_R4K
  22. + select DMA_NONCOHERENT
  23. + select IRQ_CPU
  24. + select SYS_HAS_CPU_MIPS32_R1
  25. + select SYS_SUPPORTS_BIG_ENDIAN
  26. + select SYS_SUPPORTS_32BIT_KERNEL
  27. + select GENERIC_GPIO
  28. + select SYS_HAS_EARLY_PRINTK
  29. + select SYS_SUPPORTS_ZBOOT
  30. + help
  31. + Support for AR231x and AR531x based boards
  32. +
  33. config MIPS_COBALT
  34. bool "Cobalt Server"
  35. select CEVT_R4K
  36. @@ -738,6 +753,7 @@
  37. endchoice
  38. +source "arch/mips/ar231x/Kconfig"
  39. source "arch/mips/alchemy/Kconfig"
  40. source "arch/mips/ath79/Kconfig"
  41. source "arch/mips/bcm63xx/Kconfig"
  42. diff -Nur linux-2.6.39-rc7.orig/arch/mips/ar231x/Kconfig linux-2.6.39-rc7/arch/mips/ar231x/Kconfig
  43. --- linux-2.6.39-rc7.orig/arch/mips/ar231x/Kconfig 1970-01-01 01:00:00.000000000 +0100
  44. +++ linux-2.6.39-rc7/arch/mips/ar231x/Kconfig 2011-05-15 21:34:57.000000000 +0200
  45. @@ -0,0 +1,27 @@
  46. +config ATHEROS_AR5312
  47. + bool "Atheros 5312/2312+ support"
  48. + depends on ATHEROS_AR231X
  49. + default y
  50. +
  51. +config ATHEROS_AR2315
  52. + bool "Atheros 2315+ support"
  53. + depends on ATHEROS_AR231X
  54. + select DMA_NONCOHERENT
  55. + select CEVT_R4K
  56. + select CSRC_R4K
  57. + select IRQ_CPU
  58. + select SYS_HAS_CPU_MIPS32_R1
  59. + select SYS_SUPPORTS_32BIT_KERNEL
  60. + select SYS_SUPPORTS_BIG_ENDIAN
  61. + select GENERIC_GPIO
  62. + default y
  63. +
  64. +config ATHEROS_AR2315_PCI
  65. + bool "PCI support"
  66. + depends on ATHEROS_AR2315
  67. + select HW_HAS_PCI
  68. + select PCI
  69. + select USB_ARCH_HAS_HCD
  70. + select USB_ARCH_HAS_OHCI
  71. + select USB_ARCH_HAS_EHCI
  72. + default n
  73. diff -Nur linux-2.6.39-rc7.orig/arch/mips/ar231x/Makefile linux-2.6.39-rc7/arch/mips/ar231x/Makefile
  74. --- linux-2.6.39-rc7.orig/arch/mips/ar231x/Makefile 1970-01-01 01:00:00.000000000 +0100
  75. +++ linux-2.6.39-rc7/arch/mips/ar231x/Makefile 2011-05-15 21:34:57.000000000 +0200
  76. @@ -0,0 +1,17 @@
  77. +#
  78. +# This file is subject to the terms and conditions of the GNU General Public
  79. +# License. See the file "COPYING" in the main directory of this archive
  80. +# for more details.
  81. +#
  82. +# Copyright (C) 2006 FON Technology, SL.
  83. +# Copyright (C) 2006 Imre Kaloz <kaloz@openwrt.org>
  84. +# Copyright (C) 2006-2009 Felix Fietkau <nbd@openwrt.org>
  85. +#
  86. +
  87. +obj-y += board.o prom.o devices.o
  88. +
  89. +obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
  90. +
  91. +obj-$(CONFIG_ATHEROS_AR5312) += ar5312.o
  92. +obj-$(CONFIG_ATHEROS_AR2315) += ar2315.o
  93. +obj-$(CONFIG_ATHEROS_AR2315_PCI) += pci.o
  94. diff -Nur linux-2.6.39-rc7.orig/arch/mips/ar231x/Platform linux-2.6.39-rc7/arch/mips/ar231x/Platform
  95. --- linux-2.6.39-rc7.orig/arch/mips/ar231x/Platform 1970-01-01 01:00:00.000000000 +0100
  96. +++ linux-2.6.39-rc7/arch/mips/ar231x/Platform 2011-05-15 21:34:57.000000000 +0200
  97. @@ -0,0 +1,6 @@
  98. +#
  99. +# Atheros AR5312/AR2312 WiSoC
  100. +#
  101. +platform-$(CONFIG_ATHEROS_AR231X) += ar231x/
  102. +cflags-$(CONFIG_ATHEROS_AR231X) += -I$(srctree)/arch/mips/include/asm/mach-ar231x
  103. +load-$(CONFIG_ATHEROS_AR231X) += 0xffffffff80041000
  104. diff -Nur linux-2.6.39-rc7.orig/arch/mips/ar231x/ar2315.c linux-2.6.39-rc7/arch/mips/ar231x/ar2315.c
  105. --- linux-2.6.39-rc7.orig/arch/mips/ar231x/ar2315.c 1970-01-01 01:00:00.000000000 +0100
  106. +++ linux-2.6.39-rc7/arch/mips/ar231x/ar2315.c 2011-05-15 21:47:07.000000000 +0200
  107. @@ -0,0 +1,654 @@
  108. +/*
  109. + * This file is subject to the terms and conditions of the GNU General Public
  110. + * License. See the file "COPYING" in the main directory of this archive
  111. + * for more details.
  112. + *
  113. + * Copyright (C) 2003 Atheros Communications, Inc., All Rights Reserved.
  114. + * Copyright (C) 2006 FON Technology, SL.
  115. + * Copyright (C) 2006 Imre Kaloz <kaloz@openwrt.org>
  116. + * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
  117. + */
  118. +
  119. +/*
  120. + * Platform devices for Atheros SoCs
  121. + */
  122. +
  123. +#include <generated/autoconf.h>
  124. +#include <linux/init.h>
  125. +#include <linux/module.h>
  126. +#include <linux/types.h>
  127. +#include <linux/string.h>
  128. +#include <linux/platform_device.h>
  129. +#include <linux/kernel.h>
  130. +#include <linux/reboot.h>
  131. +#include <linux/delay.h>
  132. +#include <linux/leds.h>
  133. +#include <asm/bootinfo.h>
  134. +#include <asm/reboot.h>
  135. +#include <asm/time.h>
  136. +#include <asm/irq.h>
  137. +#include <asm/io.h>
  138. +#include <asm/gpio.h>
  139. +
  140. +#include <ar231x_platform.h>
  141. +#include <ar2315_regs.h>
  142. +#include <ar231x.h>
  143. +#include "devices.h"
  144. +#include "ar2315.h"
  145. +
  146. +static u32 gpiointmask = 0, gpiointval = 0;
  147. +
  148. +static inline void ar2315_gpio_irq(void)
  149. +{
  150. + u32 pend;
  151. + int bit = -1;
  152. +
  153. + /* only do one gpio interrupt at a time */
  154. + pend = (ar231x_read_reg(AR2315_GPIO_DI) ^ gpiointval) & gpiointmask;
  155. +
  156. + if (pend) {
  157. + bit = fls(pend) - 1;
  158. + pend &= ~(1 << bit);
  159. + gpiointval ^= (1 << bit);
  160. + }
  161. +
  162. + if (!pend)
  163. + ar231x_write_reg(AR2315_ISR, AR2315_ISR_GPIO);
  164. +
  165. + /* Enable interrupt with edge detection */
  166. + if ((ar231x_read_reg(AR2315_GPIO_CR) & AR2315_GPIO_CR_M(bit)) != AR2315_GPIO_CR_I(bit))
  167. + return;
  168. +
  169. + if (bit >= 0)
  170. + do_IRQ(AR531X_GPIO_IRQ_BASE + bit);
  171. +}
  172. +
  173. +#ifdef CONFIG_ATHEROS_AR2315_PCI
  174. +static inline void pci_abort_irq(void)
  175. +{
  176. + ar231x_write_reg(AR2315_PCI_INT_STATUS, AR2315_PCI_ABORT_INT);
  177. +}
  178. +
  179. +static inline void pci_ack_irq(void)
  180. +{
  181. + ar231x_write_reg(AR2315_PCI_INT_STATUS, AR2315_PCI_EXT_INT);
  182. +}
  183. +
  184. +void ar2315_pci_irq(int irq)
  185. +{
  186. + if (ar231x_read_reg(AR2315_PCI_INT_STATUS) == AR2315_PCI_ABORT_INT)
  187. + pci_abort_irq();
  188. + else {
  189. + do_IRQ(irq);
  190. + pci_ack_irq();
  191. + }
  192. +}
  193. +#endif /* CONFIG_ATHEROS_AR2315_PCI */
  194. +
  195. +/*
  196. + * Called when an interrupt is received, this function
  197. + * determines exactly which interrupt it was, and it
  198. + * invokes the appropriate handler.
  199. + *
  200. + * Implicitly, we also define interrupt priority by
  201. + * choosing which to dispatch first.
  202. + */
  203. +static asmlinkage void
  204. +ar2315_irq_dispatch(void)
  205. +{
  206. + int pending = read_c0_status() & read_c0_cause();
  207. +
  208. + if (pending & CAUSEF_IP3)
  209. + do_IRQ(AR2315_IRQ_WLAN0_INTRS);
  210. + else if (pending & CAUSEF_IP4)
  211. + do_IRQ(AR2315_IRQ_ENET0_INTRS);
  212. +#ifdef CONFIG_ATHEROS_AR2315_PCI
  213. + else if (pending & CAUSEF_IP5)
  214. + ar2315_pci_irq(AR2315_IRQ_LCBUS_PCI);
  215. +#endif
  216. + else if (pending & CAUSEF_IP2) {
  217. + unsigned int misc_intr = ar231x_read_reg(AR2315_ISR) & ar231x_read_reg(AR2315_IMR);
  218. +
  219. + if (misc_intr & AR2315_ISR_SPI)
  220. + do_IRQ(AR531X_MISC_IRQ_SPI);
  221. + else if (misc_intr & AR2315_ISR_TIMER)
  222. + do_IRQ(AR531X_MISC_IRQ_TIMER);
  223. + else if (misc_intr & AR2315_ISR_AHB)
  224. + do_IRQ(AR531X_MISC_IRQ_AHB_PROC);
  225. + else if (misc_intr & AR2315_ISR_GPIO)
  226. + ar2315_gpio_irq();
  227. + else if (misc_intr & AR2315_ISR_UART0)
  228. + do_IRQ(AR531X_MISC_IRQ_UART0);
  229. + else if (misc_intr & AR2315_ISR_WD)
  230. + do_IRQ(AR531X_MISC_IRQ_WATCHDOG);
  231. + else
  232. + do_IRQ(AR531X_MISC_IRQ_NONE);
  233. + } else if (pending & CAUSEF_IP7)
  234. + do_IRQ(AR531X_IRQ_CPU_CLOCK);
  235. +}
  236. +
  237. +static void ar2315_set_gpiointmask(int gpio, int level)
  238. +{
  239. + u32 reg;
  240. +
  241. + reg = ar231x_read_reg(AR2315_GPIO_INT);
  242. + reg &= ~(AR2315_GPIO_INT_M | AR2315_GPIO_INT_LVL_M);
  243. + reg |= gpio | AR2315_GPIO_INT_LVL(level);
  244. + ar231x_write_reg(AR2315_GPIO_INT, reg);
  245. +}
  246. +
  247. +static void ar2315_gpio_intr_enable(struct irq_data *d)
  248. +{
  249. + unsigned int gpio = d->irq - AR531X_GPIO_IRQ_BASE;
  250. +
  251. + /* Enable interrupt with edge detection */
  252. + if ((ar231x_read_reg(AR2315_GPIO_CR) & AR2315_GPIO_CR_M(gpio)) != AR2315_GPIO_CR_I(gpio))
  253. + return;
  254. +
  255. + gpiointmask |= (1 << gpio);
  256. + ar2315_set_gpiointmask(gpio, 3);
  257. +}
  258. +
  259. +static void ar2315_gpio_intr_disable(struct irq_data *d)
  260. +{
  261. + unsigned int gpio = d->irq - AR531X_GPIO_IRQ_BASE;
  262. +
  263. + /* Disable interrupt */
  264. + gpiointmask &= ~(1 << gpio);
  265. + ar2315_set_gpiointmask(gpio, 0);
  266. +}
  267. +
  268. +static struct irq_chip ar2315_gpio_intr_controller = {
  269. + .name = "AR2315-GPIO",
  270. + .irq_ack = ar2315_gpio_intr_disable,
  271. + .irq_mask_ack = ar2315_gpio_intr_disable,
  272. + .irq_mask = ar2315_gpio_intr_disable,
  273. + .irq_unmask = ar2315_gpio_intr_enable,
  274. +};
  275. +
  276. +static void
  277. +ar2315_misc_intr_enable(struct irq_data *d)
  278. +{
  279. + unsigned int imr;
  280. +
  281. + imr = ar231x_read_reg(AR2315_IMR);
  282. + switch(d->irq) {
  283. + case AR531X_MISC_IRQ_SPI:
  284. + imr |= AR2315_ISR_SPI;
  285. + break;
  286. + case AR531X_MISC_IRQ_TIMER:
  287. + imr |= AR2315_ISR_TIMER;
  288. + break;
  289. + case AR531X_MISC_IRQ_AHB_PROC:
  290. + imr |= AR2315_ISR_AHB;
  291. + break;
  292. + case AR531X_MISC_IRQ_GPIO:
  293. + imr |= AR2315_ISR_GPIO;
  294. + break;
  295. + case AR531X_MISC_IRQ_UART0:
  296. + imr |= AR2315_ISR_UART0;
  297. + break;
  298. + case AR531X_MISC_IRQ_WATCHDOG:
  299. + imr |= AR2315_ISR_WD;
  300. + break;
  301. + default:
  302. + break;
  303. + }
  304. + ar231x_write_reg(AR2315_IMR, imr);
  305. +}
  306. +
  307. +static void
  308. +ar2315_misc_intr_disable(struct irq_data *d)
  309. +{
  310. + unsigned int imr;
  311. +
  312. + imr = ar231x_read_reg(AR2315_IMR);
  313. + switch(d->irq) {
  314. + case AR531X_MISC_IRQ_SPI:
  315. + imr &= ~AR2315_ISR_SPI;
  316. + break;
  317. + case AR531X_MISC_IRQ_TIMER:
  318. + imr &= ~AR2315_ISR_TIMER;
  319. + break;
  320. + case AR531X_MISC_IRQ_AHB_PROC:
  321. + imr &= ~AR2315_ISR_AHB;
  322. + break;
  323. + case AR531X_MISC_IRQ_GPIO:
  324. + imr &= ~AR2315_ISR_GPIO;
  325. + break;
  326. + case AR531X_MISC_IRQ_UART0:
  327. + imr &= ~AR2315_ISR_UART0;
  328. + break;
  329. + case AR531X_MISC_IRQ_WATCHDOG:
  330. + imr &= ~AR2315_ISR_WD;
  331. + break;
  332. + default:
  333. + break;
  334. + }
  335. + ar231x_write_reg(AR2315_IMR, imr);
  336. +}
  337. +
  338. +
  339. +static struct irq_chip ar2315_misc_intr_controller = {
  340. + .name = "AR2315-MISC",
  341. + .irq_mask = ar2315_misc_intr_disable,
  342. + .irq_unmask = ar2315_misc_intr_enable,
  343. +};
  344. +
  345. +static irqreturn_t ar2315_ahb_proc_handler(int cpl, void *dev_id)
  346. +{
  347. + ar231x_write_reg(AR2315_AHB_ERR0, AHB_ERROR_DET);
  348. + ar231x_read_reg(AR2315_AHB_ERR1);
  349. +
  350. + printk(KERN_ERR "AHB fatal error\n");
  351. + machine_restart("AHB error"); /* Catastrophic failure */
  352. +
  353. + return IRQ_HANDLED;
  354. +}
  355. +
  356. +static struct irqaction ar2315_ahb_proc_interrupt = {
  357. + .handler = ar2315_ahb_proc_handler,
  358. + .flags = IRQF_DISABLED,
  359. + .name = "ar2315_ahb_proc_interrupt",
  360. +};
  361. +
  362. +static struct irqaction cascade = {
  363. + .handler = no_action,
  364. + .flags = IRQF_DISABLED,
  365. + .name = "cascade",
  366. +};
  367. +
  368. +void
  369. +ar2315_irq_init(void)
  370. +{
  371. + int i;
  372. +
  373. + if (!is_2315())
  374. + return;
  375. +
  376. + ar231x_irq_dispatch = ar2315_irq_dispatch;
  377. + gpiointval = ar231x_read_reg(AR2315_GPIO_DI);
  378. + for (i = 0; i < AR531X_MISC_IRQ_COUNT; i++) {
  379. + int irq = AR531X_MISC_IRQ_BASE + i;
  380. + irq_set_chip_and_handler(irq, &ar2315_misc_intr_controller,
  381. + handle_level_irq);
  382. + }
  383. + for (i = 0; i < AR531X_GPIO_IRQ_COUNT; i++) {
  384. + int irq = AR531X_GPIO_IRQ_BASE + i;
  385. + irq_set_chip_and_handler(irq, &ar2315_gpio_intr_controller,
  386. + handle_level_irq);
  387. + }
  388. + setup_irq(AR531X_MISC_IRQ_GPIO, &cascade);
  389. + setup_irq(AR531X_MISC_IRQ_AHB_PROC, &ar2315_ahb_proc_interrupt);
  390. + setup_irq(AR2315_IRQ_MISC_INTRS, &cascade);
  391. +}
  392. +
  393. +const struct ar231x_gpiodev ar2315_gpiodev;
  394. +
  395. +static u32
  396. +ar2315_gpio_get_output(void)
  397. +{
  398. + u32 reg;
  399. + reg = ar231x_read_reg(AR2315_GPIO_CR);
  400. + reg &= ar2315_gpiodev.valid_mask;
  401. + return reg;
  402. +}
  403. +
  404. +static u32
  405. +ar2315_gpio_set_output(u32 mask, u32 val)
  406. +{
  407. + u32 reg;
  408. +
  409. + reg = ar231x_read_reg(AR2315_GPIO_CR);
  410. + reg &= ~mask;
  411. + reg |= val;
  412. + ar231x_write_reg(AR2315_GPIO_CR, reg);
  413. + return reg;
  414. +}
  415. +
  416. +static u32
  417. +ar2315_gpio_get(void)
  418. +{
  419. + u32 reg;
  420. + reg = ar231x_read_reg(AR2315_GPIO_DI);
  421. + reg &= ar2315_gpiodev.valid_mask;
  422. + return reg;
  423. +}
  424. +
  425. +static u32
  426. +ar2315_gpio_set(u32 mask, u32 value)
  427. +{
  428. + u32 reg;
  429. + reg = ar231x_read_reg(AR2315_GPIO_DO);
  430. + reg &= ~mask;
  431. + reg |= value;
  432. + ar231x_write_reg(AR2315_GPIO_DO, reg);
  433. + return reg;
  434. +}
  435. +
  436. +const struct ar231x_gpiodev ar2315_gpiodev = {
  437. + .valid_mask = (1 << 22) - 1,
  438. + .get_output = ar2315_gpio_get_output,
  439. + .set_output = ar2315_gpio_set_output,
  440. + .get = ar2315_gpio_get,
  441. + .set = ar2315_gpio_set,
  442. +};
  443. +
  444. +static struct ar231x_eth ar2315_eth_data = {
  445. + .reset_base = AR2315_RESET,
  446. + .reset_mac = AR2315_RESET_ENET0,
  447. + .reset_phy = AR2315_RESET_EPHY0,
  448. + .phy_base = KSEG1ADDR(AR2315_ENET0),
  449. + .config = &ar231x_board,
  450. +};
  451. +
  452. +static struct resource ar2315_spiflash_res[] = {
  453. + {
  454. + .name = "flash_base",
  455. + .flags = IORESOURCE_MEM,
  456. + .start = KSEG1ADDR(AR2315_SPI_READ),
  457. + .end = KSEG1ADDR(AR2315_SPI_READ) + 0x1000000 - 1,
  458. + },
  459. + {
  460. + .name = "flash_regs",
  461. + .flags = IORESOURCE_MEM,
  462. + .start = 0x11300000,
  463. + .end = 0x11300012,
  464. + },
  465. +};
  466. +
  467. +static struct platform_device ar2315_spiflash = {
  468. + .id = 0,
  469. + .name = "spiflash",
  470. + .resource = ar2315_spiflash_res,
  471. + .num_resources = ARRAY_SIZE(ar2315_spiflash_res)
  472. +};
  473. +
  474. +static struct platform_device ar2315_wdt = {
  475. + .id = 0,
  476. + .name = "ar2315_wdt",
  477. +};
  478. +
  479. +#define SPI_FLASH_CTL 0x00
  480. +#define SPI_FLASH_OPCODE 0x04
  481. +#define SPI_FLASH_DATA 0x08
  482. +
  483. +static inline u32
  484. +spiflash_read_reg(int reg)
  485. +{
  486. + return ar231x_read_reg(AR2315_SPI + reg);
  487. +}
  488. +
  489. +static inline void
  490. +spiflash_write_reg(int reg, u32 data)
  491. +{
  492. + ar231x_write_reg(AR2315_SPI + reg, data);
  493. +}
  494. +
  495. +static u32
  496. +spiflash_wait_status(void)
  497. +{
  498. + u32 reg;
  499. +
  500. + do {
  501. + reg = spiflash_read_reg(SPI_FLASH_CTL);
  502. + } while (reg & SPI_CTL_BUSY);
  503. +
  504. + return reg;
  505. +}
  506. +
  507. +static u8
  508. +spiflash_probe(void)
  509. +{
  510. + u32 reg;
  511. +
  512. + reg = spiflash_wait_status();
  513. + reg &= ~SPI_CTL_TX_RX_CNT_MASK;
  514. + reg |= (1 << 4) | 4 | SPI_CTL_START;
  515. +
  516. + spiflash_write_reg(SPI_FLASH_OPCODE, 0xab);
  517. + spiflash_write_reg(SPI_FLASH_CTL, reg);
  518. +
  519. + reg = spiflash_wait_status();
  520. + reg = spiflash_read_reg(SPI_FLASH_DATA);
  521. + reg &= 0xff;
  522. +
  523. + return (u8) reg;
  524. +}
  525. +
  526. +
  527. +#define STM_8MBIT_SIGNATURE 0x13
  528. +#define STM_16MBIT_SIGNATURE 0x14
  529. +#define STM_32MBIT_SIGNATURE 0x15
  530. +#define STM_64MBIT_SIGNATURE 0x16
  531. +#define STM_128MBIT_SIGNATURE 0x17
  532. +
  533. +static u8 __init *
  534. +ar2315_flash_limit(void)
  535. +{
  536. + u32 flash_size = 0;
  537. +
  538. + /* probe the flash chip size */
  539. + switch(spiflash_probe()) {
  540. + case STM_8MBIT_SIGNATURE:
  541. + flash_size = 0x00100000;
  542. + break;
  543. + case STM_16MBIT_SIGNATURE:
  544. + flash_size = 0x00200000;
  545. + break;
  546. + case STM_32MBIT_SIGNATURE:
  547. + flash_size = 0x00400000;
  548. + break;
  549. + case STM_64MBIT_SIGNATURE:
  550. + flash_size = 0x00800000;
  551. + break;
  552. + case STM_128MBIT_SIGNATURE:
  553. + flash_size = 0x01000000;
  554. + break;
  555. + }
  556. +
  557. + ar2315_spiflash_res[0].end = ar2315_spiflash_res[0].start +
  558. + flash_size - 1;
  559. + return (u8 *) ar2315_spiflash_res[0].end + 1;
  560. +}
  561. +
  562. +#ifdef CONFIG_LEDS_GPIO
  563. +static struct gpio_led ar2315_leds[6];
  564. +static struct gpio_led_platform_data ar2315_led_data = {
  565. + .leds = (void *) ar2315_leds,
  566. +};
  567. +
  568. +static struct platform_device ar2315_gpio_leds = {
  569. + .name = "leds-gpio",
  570. + .id = -1,
  571. + .dev = {
  572. + .platform_data = (void *) &ar2315_led_data,
  573. + }
  574. +};
  575. +
  576. +static void __init
  577. +ar2315_init_gpio(void)
  578. +{
  579. + static char led_names[6][6];
  580. + int i, led = 0;
  581. +
  582. + ar2315_led_data.num_leds = 0;
  583. + for(i = 1; i < 8; i++)
  584. + {
  585. + if((i == AR2315_RESET_GPIO) ||
  586. + (i == ar231x_board.config->resetConfigGpio))
  587. + continue;
  588. +
  589. + if(i == ar231x_board.config->sysLedGpio)
  590. + strcpy(led_names[led], "wlan");
  591. + else
  592. + sprintf(led_names[led], "gpio%d", i);
  593. +
  594. + ar2315_leds[led].name = led_names[led];
  595. + ar2315_leds[led].gpio = i;
  596. + ar2315_leds[led].active_low = 0;
  597. + led++;
  598. + }
  599. + ar2315_led_data.num_leds = led;
  600. + platform_device_register(&ar2315_gpio_leds);
  601. +}
  602. +#else
  603. +static inline void ar2315_init_gpio(void)
  604. +{
  605. +}
  606. +#endif
  607. +
  608. +int __init
  609. +ar2315_init_devices(void)
  610. +{
  611. + if (!is_2315())
  612. + return 0;
  613. +
  614. + /* Find board configuration */
  615. + ar231x_find_config(ar2315_flash_limit());
  616. + ar2315_eth_data.macaddr = ar231x_board.config->enet0_mac;
  617. +
  618. + ar2315_init_gpio();
  619. + platform_device_register(&ar2315_wdt);
  620. + platform_device_register(&ar2315_spiflash);
  621. + ar231x_add_ethernet(0, KSEG1ADDR(AR2315_ENET0), AR2315_IRQ_ENET0_INTRS,
  622. + &ar2315_eth_data);
  623. + ar231x_add_wmac(0, AR2315_WLAN0, AR2315_IRQ_WLAN0_INTRS);
  624. +
  625. + return 0;
  626. +}
  627. +
  628. +static void
  629. +ar2315_restart(char *command)
  630. +{
  631. + void (*mips_reset_vec)(void) = (void *) 0xbfc00000;
  632. +
  633. + local_irq_disable();
  634. +
  635. + /* try reset the system via reset control */
  636. + ar231x_write_reg(AR2315_COLD_RESET,AR2317_RESET_SYSTEM);
  637. +
  638. + /* Cold reset does not work on the AR2315/6, use the GPIO reset bits a workaround.
  639. + * give it some time to attempt a gpio based hardware reset
  640. + * (atheros reference design workaround) */
  641. + gpio_direction_output(AR2315_RESET_GPIO, 0);
  642. + mdelay(100);
  643. +
  644. + /* Some boards (e.g. Senao EOC-2610) don't implement the reset logic
  645. + * workaround. Attempt to jump to the mips reset location -
  646. + * the boot loader itself might be able to recover the system */
  647. + mips_reset_vec();
  648. +}
  649. +
  650. +
  651. +/*
  652. + * This table is indexed by bits 5..4 of the CLOCKCTL1 register
  653. + * to determine the predevisor value.
  654. + */
  655. +static int __initdata CLOCKCTL1_PREDIVIDE_TABLE[4] = { 1, 2, 4, 5 };
  656. +static int __initdata PLLC_DIVIDE_TABLE[5] = { 2, 3, 4, 6, 3 };
  657. +
  658. +static unsigned int __init
  659. +ar2315_sys_clk(unsigned int clockCtl)
  660. +{
  661. + unsigned int pllcCtrl,cpuDiv;
  662. + unsigned int pllcOut,refdiv,fdiv,divby2;
  663. + unsigned int clkDiv;
  664. +
  665. + pllcCtrl = ar231x_read_reg(AR2315_PLLC_CTL);
  666. + refdiv = (pllcCtrl & PLLC_REF_DIV_M) >> PLLC_REF_DIV_S;
  667. + refdiv = CLOCKCTL1_PREDIVIDE_TABLE[refdiv];
  668. + fdiv = (pllcCtrl & PLLC_FDBACK_DIV_M) >> PLLC_FDBACK_DIV_S;
  669. + divby2 = (pllcCtrl & PLLC_ADD_FDBACK_DIV_M) >> PLLC_ADD_FDBACK_DIV_S;
  670. + divby2 += 1;
  671. + pllcOut = (40000000/refdiv)*(2*divby2)*fdiv;
  672. +
  673. +
  674. + /* clkm input selected */
  675. + switch(clockCtl & CPUCLK_CLK_SEL_M) {
  676. + case 0:
  677. + case 1:
  678. + clkDiv = PLLC_DIVIDE_TABLE[(pllcCtrl & PLLC_CLKM_DIV_M) >> PLLC_CLKM_DIV_S];
  679. + break;
  680. + case 2:
  681. + clkDiv = PLLC_DIVIDE_TABLE[(pllcCtrl & PLLC_CLKC_DIV_M) >> PLLC_CLKC_DIV_S];
  682. + break;
  683. + default:
  684. + pllcOut = 40000000;
  685. + clkDiv = 1;
  686. + break;
  687. + }
  688. + cpuDiv = (clockCtl & CPUCLK_CLK_DIV_M) >> CPUCLK_CLK_DIV_S;
  689. + cpuDiv = cpuDiv * 2 ?: 1;
  690. + return (pllcOut/(clkDiv * cpuDiv));
  691. +}
  692. +
  693. +static inline unsigned int
  694. +ar2315_cpu_frequency(void)
  695. +{
  696. + return ar2315_sys_clk(ar231x_read_reg(AR2315_CPUCLK));
  697. +}
  698. +
  699. +static inline unsigned int
  700. +ar2315_apb_frequency(void)
  701. +{
  702. + return ar2315_sys_clk(ar231x_read_reg(AR2315_AMBACLK));
  703. +}
  704. +
  705. +void __init
  706. +ar2315_time_init(void)
  707. +{
  708. + if (!is_2315())
  709. + return;
  710. +
  711. + mips_hpt_frequency = ar2315_cpu_frequency() / 2;
  712. +}
  713. +
  714. +void __init
  715. +ar2315_prom_init(void)
  716. +{
  717. + u32 memsize, memcfg, devid;
  718. +
  719. + if (!is_2315())
  720. + return;
  721. +
  722. + memcfg = ar231x_read_reg(AR2315_MEM_CFG);
  723. + memsize = 1 + ((memcfg & SDRAM_DATA_WIDTH_M) >> SDRAM_DATA_WIDTH_S);
  724. + memsize <<= 1 + ((memcfg & SDRAM_COL_WIDTH_M) >> SDRAM_COL_WIDTH_S);
  725. + memsize <<= 1 + ((memcfg & SDRAM_ROW_WIDTH_M) >> SDRAM_ROW_WIDTH_S);
  726. + memsize <<= 3;
  727. + add_memory_region(0, memsize, BOOT_MEM_RAM);
  728. +
  729. + /* Detect the hardware based on the device ID */
  730. + devid = ar231x_read_reg(AR2315_SREV) & AR2315_REV_CHIP;
  731. + switch(devid) {
  732. + case 0x90:
  733. + case 0x91:
  734. + ar231x_devtype = DEV_TYPE_AR2317;
  735. + break;
  736. + default:
  737. + ar231x_devtype = DEV_TYPE_AR2315;
  738. + break;
  739. + }
  740. + ar231x_gpiodev = &ar2315_gpiodev;
  741. + ar231x_board.devid = devid;
  742. +}
  743. +
  744. +void __init
  745. +ar2315_plat_setup(void)
  746. +{
  747. + u32 config;
  748. +
  749. + if (!is_2315())
  750. + return;
  751. +
  752. + /* Clear any lingering AHB errors */
  753. + config = read_c0_config();
  754. + write_c0_config(config & ~0x3);
  755. + ar231x_write_reg(AR2315_AHB_ERR0,AHB_ERROR_DET);
  756. + ar231x_read_reg(AR2315_AHB_ERR1);
  757. + ar231x_write_reg(AR2315_WDC, AR2315_WDC_IGNORE_EXPIRATION);
  758. +
  759. + _machine_restart = ar2315_restart;
  760. + ar231x_serial_setup(KSEG1ADDR(AR2315_UART0), ar2315_apb_frequency());
  761. +}
  762. diff -Nur linux-2.6.39-rc7.orig/arch/mips/ar231x/ar2315.h linux-2.6.39-rc7/arch/mips/ar231x/ar2315.h
  763. --- linux-2.6.39-rc7.orig/arch/mips/ar231x/ar2315.h 1970-01-01 01:00:00.000000000 +0100
  764. +++ linux-2.6.39-rc7/arch/mips/ar231x/ar2315.h 2011-05-15 21:34:57.000000000 +0200
  765. @@ -0,0 +1,37 @@
  766. +#ifndef __AR2315_H
  767. +#define __AR2315_H
  768. +
  769. +#ifdef CONFIG_ATHEROS_AR2315
  770. +
  771. +extern void ar2315_irq_init(void);
  772. +extern int ar2315_init_devices(void);
  773. +extern void ar2315_prom_init(void);
  774. +extern void ar2315_plat_setup(void);
  775. +extern void ar2315_time_init(void);
  776. +
  777. +#else
  778. +
  779. +static inline void ar2315_irq_init(void)
  780. +{
  781. +}
  782. +
  783. +static inline int ar2315_init_devices(void)
  784. +{
  785. + return 0;
  786. +}
  787. +
  788. +static inline void ar2315_prom_init(void)
  789. +{
  790. +}
  791. +
  792. +static inline void ar2315_plat_setup(void)
  793. +{
  794. +}
  795. +
  796. +static inline void ar2315_time_init(void)
  797. +{
  798. +}
  799. +
  800. +#endif
  801. +
  802. +#endif
  803. diff -Nur linux-2.6.39-rc7.orig/arch/mips/ar231x/ar5312.c linux-2.6.39-rc7/arch/mips/ar231x/ar5312.c
  804. --- linux-2.6.39-rc7.orig/arch/mips/ar231x/ar5312.c 1970-01-01 01:00:00.000000000 +0100
  805. +++ linux-2.6.39-rc7/arch/mips/ar231x/ar5312.c 2011-05-15 21:34:57.000000000 +0200
  806. @@ -0,0 +1,538 @@
  807. +/*
  808. + * This file is subject to the terms and conditions of the GNU General Public
  809. + * License. See the file "COPYING" in the main directory of this archive
  810. + * for more details.
  811. + *
  812. + * Copyright (C) 2003 Atheros Communications, Inc., All Rights Reserved.
  813. + * Copyright (C) 2006 FON Technology, SL.
  814. + * Copyright (C) 2006 Imre Kaloz <kaloz@openwrt.org>
  815. + * Copyright (C) 2006-2009 Felix Fietkau <nbd@openwrt.org>
  816. + */
  817. +
  818. +/*
  819. + * Platform devices for Atheros SoCs
  820. + */
  821. +
  822. +#include <generated/autoconf.h>
  823. +#include <linux/init.h>
  824. +#include <linux/module.h>
  825. +#include <linux/types.h>
  826. +#include <linux/string.h>
  827. +#include <linux/mtd/physmap.h>
  828. +#include <linux/platform_device.h>
  829. +#include <linux/kernel.h>
  830. +#include <linux/reboot.h>
  831. +#include <linux/leds.h>
  832. +#include <asm/bootinfo.h>
  833. +#include <asm/reboot.h>
  834. +#include <asm/time.h>
  835. +#include <asm/irq.h>
  836. +#include <asm/io.h>
  837. +#include <gpio.h>
  838. +
  839. +#include <ar231x_platform.h>
  840. +#include <ar5312_regs.h>
  841. +#include <ar231x.h>
  842. +#include "devices.h"
  843. +#include "ar5312.h"
  844. +
  845. +static void
  846. +ar5312_misc_irq_dispatch(void)
  847. +{
  848. + unsigned int ar231x_misc_intrs = ar231x_read_reg(AR531X_ISR) & ar231x_read_reg(AR531X_IMR);
  849. +
  850. + if (ar231x_misc_intrs & AR531X_ISR_TIMER) {
  851. + do_IRQ(AR531X_MISC_IRQ_TIMER);
  852. + (void)ar231x_read_reg(AR531X_TIMER);
  853. + } else if (ar231x_misc_intrs & AR531X_ISR_AHBPROC)
  854. + do_IRQ(AR531X_MISC_IRQ_AHB_PROC);
  855. + else if ((ar231x_misc_intrs & AR531X_ISR_UART0))
  856. + do_IRQ(AR531X_MISC_IRQ_UART0);
  857. + else if (ar231x_misc_intrs & AR531X_ISR_WD)
  858. + do_IRQ(AR531X_MISC_IRQ_WATCHDOG);
  859. + else
  860. + do_IRQ(AR531X_MISC_IRQ_NONE);
  861. +}
  862. +
  863. +static asmlinkage void
  864. +ar5312_irq_dispatch(void)
  865. +{
  866. + int pending = read_c0_status() & read_c0_cause();
  867. +
  868. + if (pending & CAUSEF_IP2)
  869. + do_IRQ(AR5312_IRQ_WLAN0_INTRS);
  870. + else if (pending & CAUSEF_IP3)
  871. + do_IRQ(AR5312_IRQ_ENET0_INTRS);
  872. + else if (pending & CAUSEF_IP4)
  873. + do_IRQ(AR5312_IRQ_ENET1_INTRS);
  874. + else if (pending & CAUSEF_IP5)
  875. + do_IRQ(AR5312_IRQ_WLAN1_INTRS);
  876. + else if (pending & CAUSEF_IP6)
  877. + ar5312_misc_irq_dispatch();
  878. + else if (pending & CAUSEF_IP7)
  879. + do_IRQ(AR531X_IRQ_CPU_CLOCK);
  880. +}
  881. +
  882. +
  883. +/* Enable the specified AR531X_MISC_IRQ interrupt */
  884. +static void
  885. +ar5312_misc_intr_enable(struct irq_data *d)
  886. +{
  887. + unsigned int imr;
  888. +
  889. + imr = ar231x_read_reg(AR531X_IMR);
  890. + imr |= (1 << (d->irq - AR531X_MISC_IRQ_BASE - 1));
  891. + ar231x_write_reg(AR531X_IMR, imr);
  892. +}
  893. +
  894. +/* Disable the specified AR531X_MISC_IRQ interrupt */
  895. +static void
  896. +ar5312_misc_intr_disable(struct irq_data *d)
  897. +{
  898. + unsigned int imr;
  899. +
  900. + imr = ar231x_read_reg(AR531X_IMR);
  901. + imr &= ~(1 << (d->irq - AR531X_MISC_IRQ_BASE - 1));
  902. + ar231x_write_reg(AR531X_IMR, imr);
  903. + ar231x_read_reg(AR531X_IMR); /* flush write buffer */
  904. +}
  905. +
  906. +static struct irq_chip ar5312_misc_intr_controller = {
  907. + .name = "AR5312-MISC",
  908. + .irq_mask = ar5312_misc_intr_disable,
  909. + .irq_unmask = ar5312_misc_intr_enable,
  910. +};
  911. +
  912. +
  913. +static irqreturn_t ar5312_ahb_proc_handler(int cpl, void *dev_id)
  914. +{
  915. + u32 proc1 = ar231x_read_reg(AR531X_PROC1);
  916. + u32 procAddr = ar231x_read_reg(AR531X_PROCADDR); /* clears error state */
  917. + u32 dma1 = ar231x_read_reg(AR531X_DMA1);
  918. + u32 dmaAddr = ar231x_read_reg(AR531X_DMAADDR); /* clears error state */
  919. +
  920. + printk("AHB interrupt: PROCADDR=0x%8.8x PROC1=0x%8.8x DMAADDR=0x%8.8x DMA1=0x%8.8x\n",
  921. + procAddr, proc1, dmaAddr, dma1);
  922. +
  923. + machine_restart("AHB error"); /* Catastrophic failure */
  924. + return IRQ_HANDLED;
  925. +}
  926. +
  927. +
  928. +static struct irqaction ar5312_ahb_proc_interrupt = {
  929. + .handler = ar5312_ahb_proc_handler,
  930. + .flags = IRQF_DISABLED,
  931. + .name = "ar5312_ahb_proc_interrupt",
  932. +};
  933. +
  934. +
  935. +static struct irqaction cascade = {
  936. + .handler = no_action,
  937. + .flags = IRQF_DISABLED,
  938. + .name = "cascade",
  939. +};
  940. +
  941. +void __init ar5312_irq_init(void)
  942. +{
  943. + int i;
  944. +
  945. + if (!is_5312())
  946. + return;
  947. +
  948. + ar231x_irq_dispatch = ar5312_irq_dispatch;
  949. + for (i = 0; i < AR531X_MISC_IRQ_COUNT; i++) {
  950. + int irq = AR531X_MISC_IRQ_BASE + i;
  951. + irq_set_chip_and_handler(irq, &ar5312_misc_intr_controller,
  952. + handle_level_irq);
  953. + }
  954. + setup_irq(AR531X_MISC_IRQ_AHB_PROC, &ar5312_ahb_proc_interrupt);
  955. + setup_irq(AR5312_IRQ_MISC_INTRS, &cascade);
  956. +}
  957. +
  958. +const struct ar231x_gpiodev ar5312_gpiodev;
  959. +
  960. +static u32
  961. +ar5312_gpio_get_output(void)
  962. +{
  963. + u32 reg;
  964. + reg = ~(ar231x_read_reg(AR531X_GPIO_CR));
  965. + reg &= ar5312_gpiodev.valid_mask;
  966. + return reg;
  967. +}
  968. +
  969. +static u32
  970. +ar5312_gpio_set_output(u32 mask, u32 val)
  971. +{
  972. + u32 reg;
  973. +
  974. + reg = ar231x_read_reg(AR531X_GPIO_CR);
  975. + reg |= mask;
  976. + reg &= ~val;
  977. + ar231x_write_reg(AR531X_GPIO_CR, reg);
  978. + return reg;
  979. +}
  980. +
  981. +static u32
  982. +ar5312_gpio_get(void)
  983. +{
  984. + u32 reg;
  985. + reg = ar231x_read_reg(AR531X_GPIO_DI);
  986. + reg &= ar5312_gpiodev.valid_mask;
  987. + return reg;
  988. +}
  989. +
  990. +static u32
  991. +ar5312_gpio_set(u32 mask, u32 value)
  992. +{
  993. + u32 reg;
  994. + reg = ar231x_read_reg(AR531X_GPIO_DO);
  995. + reg &= ~mask;
  996. + reg |= value;
  997. + ar231x_write_reg(AR531X_GPIO_DO, reg);
  998. + return reg;
  999. +}
  1000. +
  1001. +const struct ar231x_gpiodev ar5312_gpiodev = {
  1002. + .valid_mask = (1 << 8) - 1,
  1003. + .get_output = ar5312_gpio_get_output,
  1004. + .set_output = ar5312_gpio_set_output,
  1005. + .get = ar5312_gpio_get,
  1006. + .set = ar5312_gpio_set,
  1007. +};
  1008. +
  1009. +static struct physmap_flash_data ar5312_flash_data = {
  1010. + .width = 2,
  1011. +};
  1012. +
  1013. +static struct resource ar5312_flash_resource = {
  1014. + .start = AR531X_FLASH,
  1015. + .end = AR531X_FLASH + 0x800000 - 1,
  1016. + .flags = IORESOURCE_MEM,
  1017. +};
  1018. +
  1019. +static struct ar231x_eth ar5312_eth0_data = {
  1020. + .reset_base = AR531X_RESET,
  1021. + .reset_mac = AR531X_RESET_ENET0,
  1022. + .reset_phy = AR531X_RESET_EPHY0,
  1023. + .phy_base = KSEG1ADDR(AR531X_ENET0),
  1024. + .config = &ar231x_board,
  1025. +};
  1026. +
  1027. +static struct ar231x_eth ar5312_eth1_data = {
  1028. + .reset_base = AR531X_RESET,
  1029. + .reset_mac = AR531X_RESET_ENET1,
  1030. + .reset_phy = AR531X_RESET_EPHY1,
  1031. + .phy_base = KSEG1ADDR(AR531X_ENET1),
  1032. + .config = &ar231x_board,
  1033. +};
  1034. +
  1035. +static struct platform_device ar5312_physmap_flash = {
  1036. + .name = "physmap-flash",
  1037. + .id = 0,
  1038. + .dev.platform_data = &ar5312_flash_data,
  1039. + .resource = &ar5312_flash_resource,
  1040. + .num_resources = 1,
  1041. +};
  1042. +
  1043. +#ifdef CONFIG_LEDS_GPIO
  1044. +static struct gpio_led ar5312_leds[] = {
  1045. + { .name = "wlan", .gpio = 0, .active_low = 1, },
  1046. +};
  1047. +
  1048. +static const struct gpio_led_platform_data ar5312_led_data = {
  1049. + .num_leds = ARRAY_SIZE(ar5312_leds),
  1050. + .leds = (void *) ar5312_leds,
  1051. +};
  1052. +
  1053. +static struct platform_device ar5312_gpio_leds = {
  1054. + .name = "leds-gpio",
  1055. + .id = -1,
  1056. + .dev.platform_data = (void *) &ar5312_led_data,
  1057. +};
  1058. +#endif
  1059. +
  1060. +/*
  1061. + * NB: This mapping size is larger than the actual flash size,
  1062. + * but this shouldn't be a problem here, because the flash
  1063. + * will simply be mapped multiple times.
  1064. + */
  1065. +static char __init *ar5312_flash_limit(void)
  1066. +{
  1067. + u32 ctl;
  1068. + /*
  1069. + * Configure flash bank 0.
  1070. + * Assume 8M window size. Flash will be aliased if it's smaller
  1071. + */
  1072. + ctl = FLASHCTL_E |
  1073. + FLASHCTL_AC_8M |
  1074. + FLASHCTL_RBLE |
  1075. + (0x01 << FLASHCTL_IDCY_S) |
  1076. + (0x07 << FLASHCTL_WST1_S) |
  1077. + (0x07 << FLASHCTL_WST2_S) |
  1078. + (ar231x_read_reg(AR531X_FLASHCTL0) & FLASHCTL_MW);
  1079. +
  1080. + ar231x_write_reg(AR531X_FLASHCTL0, ctl);
  1081. +
  1082. + /* Disable other flash banks */
  1083. + ar231x_write_reg(AR531X_FLASHCTL1,
  1084. + ar231x_read_reg(AR531X_FLASHCTL1) & ~(FLASHCTL_E | FLASHCTL_AC));
  1085. +
  1086. + ar231x_write_reg(AR531X_FLASHCTL2,
  1087. + ar231x_read_reg(AR531X_FLASHCTL2) & ~(FLASHCTL_E | FLASHCTL_AC));
  1088. +
  1089. + return (char *) KSEG1ADDR(AR531X_FLASH + 0x800000);
  1090. +}
  1091. +
  1092. +int __init ar5312_init_devices(void)
  1093. +{
  1094. + struct ar231x_boarddata *config;
  1095. + u32 fctl = 0;
  1096. + const u8 *radio;
  1097. + u8 *c;
  1098. +
  1099. + if (!is_5312())
  1100. + return 0;
  1101. +
  1102. + /* Locate board/radio config data */
  1103. + ar231x_find_config(ar5312_flash_limit());
  1104. + config = ar231x_board.config;
  1105. +
  1106. +
  1107. + /*
  1108. + * Chip IDs and hardware detection for some Atheros
  1109. + * models are really broken!
  1110. + *
  1111. + * Atheros uses a disabled WMAC0 and Silicon ID of AR5312
  1112. + * as indication for AR2312, which is otherwise
  1113. + * indistinguishable from the real AR5312.
  1114. + */
  1115. + if (ar231x_board.radio) {
  1116. + radio = ar231x_board.radio + AR531X_RADIO_MASK_OFF;
  1117. + if ((*((const u32 *) radio) & AR531X_RADIO0_MASK) == 0)
  1118. + config->flags |= BD_ISCASPER;
  1119. + } else
  1120. + radio = NULL;
  1121. +
  1122. + /* AR2313 has CPU minor rev. 10 */
  1123. + if ((current_cpu_data.processor_id & 0xff) == 0x0a)
  1124. + ar231x_devtype = DEV_TYPE_AR2313;
  1125. +
  1126. + /* AR2312 shares the same Silicon ID as AR5312 */
  1127. + else if (config->flags & BD_ISCASPER)
  1128. + ar231x_devtype = DEV_TYPE_AR2312;
  1129. +
  1130. + /* Everything else is probably AR5312 or compatible */
  1131. + else
  1132. + ar231x_devtype = DEV_TYPE_AR5312;
  1133. +
  1134. + /* fixup flash width */
  1135. + fctl = ar231x_read_reg(AR531X_FLASHCTL) & FLASHCTL_MW;
  1136. + switch (fctl) {
  1137. + case FLASHCTL_MWx16:
  1138. + ar5312_flash_data.width = 2;
  1139. + break;
  1140. + case FLASHCTL_MWx8:
  1141. + default:
  1142. + ar5312_flash_data.width = 1;
  1143. + break;
  1144. + }
  1145. +
  1146. + platform_device_register(&ar5312_physmap_flash);
  1147. +
  1148. +#ifdef CONFIG_LEDS_GPIO
  1149. + ar5312_leds[0].gpio = config->sysLedGpio;
  1150. + platform_device_register(&ar5312_gpio_leds);
  1151. +#endif
  1152. +
  1153. + /* Fix up MAC addresses if necessary */
  1154. + if (!memcmp(config->enet0_mac, "\xff\xff\xff\xff\xff\xff", 6))
  1155. + memcpy(config->enet0_mac, config->enet1_mac, 6);
  1156. +
  1157. + /* If ENET0 and ENET1 have the same mac address,
  1158. + * increment the one from ENET1 */
  1159. + if (memcmp(config->enet0_mac, config->enet1_mac, 6) == 0) {
  1160. + c = config->enet1_mac + 5;
  1161. + while ((c >= config->enet1_mac) && !(++(*c)))
  1162. + c--;
  1163. + }
  1164. +
  1165. + switch(ar231x_devtype) {
  1166. + case DEV_TYPE_AR5312:
  1167. + ar5312_eth0_data.macaddr = config->enet0_mac;
  1168. + ar231x_add_ethernet(0, KSEG1ADDR(AR531X_ENET0),
  1169. + AR5312_IRQ_ENET0_INTRS, &ar5312_eth0_data);
  1170. +
  1171. + ar5312_eth1_data.macaddr = config->enet1_mac;
  1172. + ar231x_add_ethernet(1, KSEG1ADDR(AR531X_ENET1),
  1173. + AR5312_IRQ_ENET1_INTRS, &ar5312_eth1_data);
  1174. +
  1175. + if (!ar231x_board.radio)
  1176. + return 0;
  1177. +
  1178. + if ((*((u32 *) radio) & AR531X_RADIO0_MASK) &&
  1179. + (config->flags & BD_WLAN0))
  1180. + ar231x_add_wmac(0, AR531X_WLAN0,
  1181. + AR5312_IRQ_WLAN0_INTRS);
  1182. +
  1183. + break;
  1184. + /*
  1185. + * AR2312/3 ethernet uses the PHY of ENET0, but the MAC
  1186. + * of ENET1. Atheros calls it 'twisted' for a reason :)
  1187. + */
  1188. + case DEV_TYPE_AR2312:
  1189. + case DEV_TYPE_AR2313:
  1190. + ar5312_eth1_data.phy_base = ar5312_eth0_data.phy_base;
  1191. + ar5312_eth1_data.reset_phy = ar5312_eth0_data.reset_phy;
  1192. + ar5312_eth1_data.macaddr = config->enet0_mac;
  1193. + ar231x_add_ethernet(0, KSEG1ADDR(AR531X_ENET1),
  1194. + AR5312_IRQ_ENET1_INTRS, &ar5312_eth1_data);
  1195. +
  1196. + if (!ar231x_board.radio)
  1197. + return 0;
  1198. + break;
  1199. + default:
  1200. + break;
  1201. + }
  1202. +
  1203. + if ((*((u32 *) radio) & AR531X_RADIO1_MASK) &&
  1204. + (config->flags & BD_WLAN1))
  1205. + ar231x_add_wmac(1, AR531X_WLAN1,
  1206. + AR5312_IRQ_WLAN1_INTRS);
  1207. +
  1208. + return 0;
  1209. +}
  1210. +
  1211. +
  1212. +static void ar5312_restart(char *command)
  1213. +{
  1214. + /* reset the system */
  1215. + local_irq_disable();
  1216. + while(1) {
  1217. + ar231x_write_reg(AR531X_RESET, AR531X_RESET_SYSTEM);
  1218. + }
  1219. +}
  1220. +
  1221. +
  1222. +/*
  1223. + * This table is indexed by bits 5..4 of the CLOCKCTL1 register
  1224. + * to determine the predevisor value.
  1225. + */
  1226. +static int __initdata CLOCKCTL1_PREDIVIDE_TABLE[4] = { 1, 2, 4, 5 };
  1227. +
  1228. +
  1229. +static int __init
  1230. +ar5312_cpu_frequency(void)
  1231. +{
  1232. + unsigned int result;
  1233. + unsigned int predivide_mask, predivide_shift;
  1234. + unsigned int multiplier_mask, multiplier_shift;
  1235. + unsigned int clockCtl1, preDivideSelect, preDivisor, multiplier;
  1236. + unsigned int doubler_mask;
  1237. + u16 devid;
  1238. +
  1239. + /* Trust the bootrom's idea of cpu frequency. */
  1240. + if ((result = ar231x_read_reg(AR5312_SCRATCH)))
  1241. + return result;
  1242. +
  1243. + devid = ar231x_read_reg(AR531X_REV);
  1244. + devid &= AR531X_REV_MAJ;
  1245. + devid >>= AR531X_REV_MAJ_S;
  1246. + if (devid == AR531X_REV_MAJ_AR2313) {
  1247. + predivide_mask = AR2313_CLOCKCTL1_PREDIVIDE_MASK;
  1248. + predivide_shift = AR2313_CLOCKCTL1_PREDIVIDE_SHIFT;
  1249. + multiplier_mask = AR2313_CLOCKCTL1_MULTIPLIER_MASK;
  1250. + multiplier_shift = AR2313_CLOCKCTL1_MULTIPLIER_SHIFT;
  1251. + doubler_mask = AR2313_CLOCKCTL1_DOUBLER_MASK;
  1252. + } else { /* AR5312 and AR2312 */
  1253. + predivide_mask = AR5312_CLOCKCTL1_PREDIVIDE_MASK;
  1254. + predivide_shift = AR5312_CLOCKCTL1_PREDIVIDE_SHIFT;
  1255. + multiplier_mask = AR5312_CLOCKCTL1_MULTIPLIER_MASK;
  1256. + multiplier_shift = AR5312_CLOCKCTL1_MULTIPLIER_SHIFT;
  1257. + doubler_mask = AR5312_CLOCKCTL1_DOUBLER_MASK;
  1258. + }
  1259. +
  1260. + /*
  1261. + * Clocking is derived from a fixed 40MHz input clock.
  1262. + *
  1263. + * cpuFreq = InputClock * MULT (where MULT is PLL multiplier)
  1264. + * sysFreq = cpuFreq / 4 (used for APB clock, serial,
  1265. + * flash, Timer, Watchdog Timer)
  1266. + *
  1267. + * cntFreq = cpuFreq / 2 (use for CPU count/compare)
  1268. + *
  1269. + * So, for example, with a PLL multiplier of 5, we have
  1270. + *
  1271. + * cpuFreq = 200MHz
  1272. + * sysFreq = 50MHz
  1273. + * cntFreq = 100MHz
  1274. + *
  1275. + * We compute the CPU frequency, based on PLL settings.
  1276. + */
  1277. +
  1278. + clockCtl1 = ar231x_read_reg(AR5312_CLOCKCTL1);
  1279. + preDivideSelect = (clockCtl1 & predivide_mask) >> predivide_shift;
  1280. + preDivisor = CLOCKCTL1_PREDIVIDE_TABLE[preDivideSelect];
  1281. + multiplier = (clockCtl1 & multiplier_mask) >> multiplier_shift;
  1282. +
  1283. + if (clockCtl1 & doubler_mask) {
  1284. + multiplier = multiplier << 1;
  1285. + }
  1286. + return (40000000 / preDivisor) * multiplier;
  1287. +}
  1288. +
  1289. +static inline int
  1290. +ar5312_sys_frequency(void)
  1291. +{
  1292. + return ar5312_cpu_frequency() / 4;
  1293. +}
  1294. +
  1295. +void __init
  1296. +ar5312_time_init(void)
  1297. +{
  1298. + if (!is_5312())
  1299. + return;
  1300. +
  1301. + mips_hpt_frequency = ar5312_cpu_frequency() / 2;
  1302. +}
  1303. +
  1304. +
  1305. +void __init
  1306. +ar5312_prom_init(void)
  1307. +{
  1308. + u32 memsize, memcfg, bank0AC, bank1AC;
  1309. + u32 devid;
  1310. +
  1311. + if (!is_5312())
  1312. + return;
  1313. +
  1314. + /* Detect memory size */
  1315. + memcfg = ar231x_read_reg(AR531X_MEM_CFG1);
  1316. + bank0AC = (memcfg & MEM_CFG1_AC0) >> MEM_CFG1_AC0_S;
  1317. + bank1AC = (memcfg & MEM_CFG1_AC1) >> MEM_CFG1_AC1_S;
  1318. + memsize = (bank0AC ? (1 << (bank0AC+1)) : 0)
  1319. + + (bank1AC ? (1 << (bank1AC+1)) : 0);
  1320. + memsize <<= 20;
  1321. + add_memory_region(0, memsize, BOOT_MEM_RAM);
  1322. +
  1323. + devid = ar231x_read_reg(AR531X_REV);
  1324. + devid >>= AR531X_REV_WMAC_MIN_S;
  1325. + devid &= AR531X_REV_CHIP;
  1326. + ar231x_board.devid = (u16) devid;
  1327. + ar231x_gpiodev = &ar5312_gpiodev;
  1328. +}
  1329. +
  1330. +void __init
  1331. +ar5312_plat_setup(void)
  1332. +{
  1333. + if (!is_5312())
  1334. + return;
  1335. +
  1336. + /* Clear any lingering AHB errors */
  1337. + ar231x_read_reg(AR531X_PROCADDR);
  1338. + ar231x_read_reg(AR531X_DMAADDR);
  1339. + ar231x_write_reg(AR531X_WD_CTRL, AR531X_WD_CTRL_IGNORE_EXPIRATION);
  1340. +
  1341. + _machine_restart = ar5312_restart;
  1342. + ar231x_serial_setup(KSEG1ADDR(AR531X_UART0), ar5312_sys_frequency());
  1343. +}
  1344. +
  1345. diff -Nur linux-2.6.39-rc7.orig/arch/mips/ar231x/ar5312.h linux-2.6.39-rc7/arch/mips/ar231x/ar5312.h
  1346. --- linux-2.6.39-rc7.orig/arch/mips/ar231x/ar5312.h 1970-01-01 01:00:00.000000000 +0100
  1347. +++ linux-2.6.39-rc7/arch/mips/ar231x/ar5312.h 2011-05-15 21:34:57.000000000 +0200
  1348. @@ -0,0 +1,38 @@
  1349. +#ifndef __AR5312_H
  1350. +#define __AR5312_H
  1351. +
  1352. +#ifdef CONFIG_ATHEROS_AR5312
  1353. +
  1354. +extern void ar5312_irq_init(void);
  1355. +extern int ar5312_init_devices(void);
  1356. +extern void ar5312_prom_init(void);
  1357. +extern void ar5312_plat_setup(void);
  1358. +extern void ar5312_time_init(void);
  1359. +extern void ar5312_time_init(void);
  1360. +
  1361. +#else
  1362. +
  1363. +static inline void ar5312_irq_init(void)
  1364. +{
  1365. +}
  1366. +
  1367. +static inline int ar5312_init_devices(void)
  1368. +{
  1369. + return 0;
  1370. +}
  1371. +
  1372. +static inline void ar5312_prom_init(void)
  1373. +{
  1374. +}
  1375. +
  1376. +static inline void ar5312_plat_setup(void)
  1377. +{
  1378. +}
  1379. +
  1380. +static inline void ar5312_time_init(void)
  1381. +{
  1382. +}
  1383. +
  1384. +#endif
  1385. +
  1386. +#endif
  1387. diff -Nur linux-2.6.39-rc7.orig/arch/mips/ar231x/board.c linux-2.6.39-rc7/arch/mips/ar231x/board.c
  1388. --- linux-2.6.39-rc7.orig/arch/mips/ar231x/board.c 1970-01-01 01:00:00.000000000 +0100
  1389. +++ linux-2.6.39-rc7/arch/mips/ar231x/board.c 2011-05-15 22:16:11.000000000 +0200
  1390. @@ -0,0 +1,261 @@
  1391. +/*
  1392. + * This file is subject to the terms and conditions of the GNU General Public
  1393. + * License. See the file "COPYING" in the main directory of this archive
  1394. + * for more details.
  1395. + *
  1396. + * Copyright (C) 2003 Atheros Communications, Inc., All Rights Reserved.
  1397. + * Copyright (C) 2006 FON Technology, SL.
  1398. + * Copyright (C) 2006 Imre Kaloz <kaloz@openwrt.org>
  1399. + * Copyright (C) 2006-2009 Felix Fietkau <nbd@openwrt.org>
  1400. + */
  1401. +
  1402. +#include <generated/autoconf.h>
  1403. +#include <linux/init.h>
  1404. +#include <linux/module.h>
  1405. +#include <linux/types.h>
  1406. +#include <linux/string.h>
  1407. +#include <linux/platform_device.h>
  1408. +#include <linux/kernel.h>
  1409. +#include <linux/random.h>
  1410. +#include <linux/etherdevice.h>
  1411. +#include <asm/irq_cpu.h>
  1412. +#include <asm/reboot.h>
  1413. +#include <asm/io.h>
  1414. +
  1415. +#include <ar231x_platform.h>
  1416. +#include "devices.h"
  1417. +#include "ar5312.h"
  1418. +#include "ar2315.h"
  1419. +
  1420. +void (*ar231x_irq_dispatch)(void);
  1421. +
  1422. +static inline bool
  1423. +check_radio_magic(u8 *addr)
  1424. +{
  1425. + addr += 0x7a; /* offset for flash magic */
  1426. + if ((addr[0] == 0x5a) && (addr[1] == 0xa5)) {
  1427. + return 1;
  1428. + }
  1429. + return 0;
  1430. +}
  1431. +
  1432. +static inline bool
  1433. +check_board_data(u8 *flash_limit, u8 *addr, bool broken)
  1434. +{
  1435. + /* config magic found */
  1436. + if (*((u32 *)addr) == AR531X_BD_MAGIC)
  1437. + return 1;
  1438. +
  1439. + if (!broken)
  1440. + return 0;
  1441. +
  1442. + if (check_radio_magic(addr + 0xf8))
  1443. + ar231x_board.radio = addr + 0xf8;
  1444. + if ((addr < flash_limit + 0x10000) &&
  1445. + check_radio_magic(addr + 0x10000))
  1446. + ar231x_board.radio = addr + 0x10000;
  1447. +
  1448. + if (ar231x_board.radio) {
  1449. + /* broken board data detected, use radio data to find the offset,
  1450. + * user will fix this */
  1451. + return 1;
  1452. + }
  1453. + return 0;
  1454. +}
  1455. +
  1456. +static u8 *
  1457. +find_board_config(u8 *flash_limit, bool broken)
  1458. +{
  1459. + u8 *addr;
  1460. + int found = 0;
  1461. +
  1462. + for (addr = flash_limit - 0x1000;
  1463. + addr >= flash_limit - 0x30000;
  1464. + addr -= 0x1000) {
  1465. +
  1466. + if (check_board_data(flash_limit, addr, broken)) {
  1467. + found = 1;
  1468. + break;
  1469. + }
  1470. + }
  1471. +
  1472. + if (!found)
  1473. + addr = NULL;
  1474. +
  1475. + return addr;
  1476. +}
  1477. +
  1478. +static u8 *
  1479. +find_radio_config(u8 *flash_limit, u8 *board_config)
  1480. +{
  1481. + int found;
  1482. + u8 *radio_config;
  1483. +
  1484. + /*
  1485. + * Now find the start of Radio Configuration data, using heuristics:
  1486. + * Search forward from Board Configuration data by 0x1000 bytes
  1487. + * at a time until we find non-0xffffffff.
  1488. + */
  1489. + found = 0;
  1490. + for (radio_config = board_config + 0x1000;
  1491. + (radio_config < flash_limit);
  1492. + radio_config += 0x1000) {
  1493. + if ((*(u32 *)radio_config != 0xffffffff) &&
  1494. + check_radio_magic(radio_config)) {
  1495. + found = 1;
  1496. + break;
  1497. + }
  1498. + }
  1499. +
  1500. + /* AR2316 relocates radio config to new location */
  1501. + if (!found) {
  1502. + for (radio_config = board_config + 0xf8;
  1503. + (radio_config < flash_limit - 0x1000 + 0xf8);
  1504. + radio_config += 0x1000) {
  1505. + if ((*(u32 *)radio_config != 0xffffffff) &&
  1506. + check_radio_magic(radio_config)) {
  1507. + found = 1;
  1508. + break;
  1509. + }
  1510. + }
  1511. + }
  1512. +
  1513. + if (!found) {
  1514. + printk("Could not find Radio Configuration data\n");
  1515. + radio_config = 0;
  1516. + }
  1517. +
  1518. + return (u8 *) radio_config;
  1519. +}
  1520. +
  1521. +int __init
  1522. +ar231x_find_config(u8 *flash_limit)
  1523. +{
  1524. + struct ar231x_boarddata *config;
  1525. + unsigned int rcfg_size;
  1526. + int broken_boarddata = 0, i, tmp;
  1527. + u8 *bcfg, *rcfg;
  1528. + u8 *board_data;
  1529. + u8 *radio_data;
  1530. + u32 offset;
  1531. +
  1532. + ar231x_board.config = NULL;
  1533. + ar231x_board.radio = NULL;
  1534. + /* Copy the board and radio data to RAM, because accessing the mapped
  1535. + * memory of the flash directly after booting is not safe */
  1536. +
  1537. + /* Try to find valid board and radio data */
  1538. + bcfg = find_board_config(flash_limit, false);
  1539. +
  1540. + /* If that fails, try to at least find valid radio data */
  1541. + if (!bcfg) {
  1542. + bcfg = find_board_config(flash_limit, true);
  1543. + broken_boarddata = 1;
  1544. + }
  1545. +
  1546. + if (!bcfg) {
  1547. + printk(KERN_WARNING "WARNING: No board configuration data found!\n");
  1548. + return -ENODEV;
  1549. + }
  1550. +
  1551. + board_data = kzalloc(BOARD_CONFIG_BUFSZ, GFP_KERNEL);
  1552. + ar231x_board.config = (struct ar231x_boarddata *) board_data;
  1553. + memcpy(board_data, bcfg, 0x100);
  1554. + if (broken_boarddata) {
  1555. + printk(KERN_WARNING "WARNING: broken board data detected\n");
  1556. + config = ar231x_board.config;
  1557. + if (!memcmp(config->enet0_mac, "\x00\x00\x00\x00\x00\x00", 6)) {
  1558. + printk(KERN_INFO "Fixing up empty mac addresses\n");
  1559. + config->resetConfigGpio = 0xffff;
  1560. + config->sysLedGpio = 0xffff;
  1561. + random_ether_addr(config->wlan0_mac);
  1562. + config->wlan0_mac[0] &= ~0x06;
  1563. + random_ether_addr(config->enet0_mac);
  1564. + random_ether_addr(config->enet1_mac);
  1565. + }
  1566. + }
  1567. +
  1568. +
  1569. + /* Radio config starts 0x100 bytes after board config, regardless
  1570. + * of what the physical layout on the flash chip looks like */
  1571. +
  1572. + if (ar231x_board.radio)
  1573. + rcfg = (u8 *) ar231x_board.radio;
  1574. + else
  1575. + rcfg = find_radio_config(flash_limit, bcfg);
  1576. +
  1577. + if (!rcfg)
  1578. + return -ENODEV;
  1579. +
  1580. + radio_data = board_data + 0x100 + ((rcfg - bcfg) & 0xfff);
  1581. + ar231x_board.radio = radio_data;
  1582. + offset = radio_data - board_data;
  1583. + printk(KERN_INFO "Radio config found at offset 0x%x(0x%x)\n", rcfg - bcfg, offset);
  1584. + rcfg_size = BOARD_CONFIG_BUFSZ - offset;
  1585. + memcpy(radio_data, rcfg, rcfg_size);
  1586. +
  1587. + for (tmp = 0xff, i = 0; i < ETH_ALEN; i++)
  1588. + tmp &= radio_data[i + 0x1d * 2];
  1589. + if (tmp == 0xff) {
  1590. + u16 *eep = (u16 *)radio_data, *bcfgs = (u16 *)bcfg;
  1591. + printk(KERN_INFO "Radio MAC is blank; using board-data\n");
  1592. + eep[0x1f] = bcfgs[0x30];
  1593. + eep[0x1e] = bcfgs[0x34];
  1594. + eep[0x1d] = bcfgs[0x32];
  1595. + }
  1596. +
  1597. + return 0;
  1598. +}
  1599. +
  1600. +static void
  1601. +ar231x_halt(void)
  1602. +{
  1603. + local_irq_disable();
  1604. + while (1);
  1605. +}
  1606. +
  1607. +void __init
  1608. +plat_mem_setup(void)
  1609. +{
  1610. + _machine_halt = ar231x_halt;
  1611. + pm_power_off = ar231x_halt;
  1612. +
  1613. + ar5312_plat_setup();
  1614. + ar2315_plat_setup();
  1615. +
  1616. + /* Disable data watchpoints */
  1617. + write_c0_watchlo0(0);
  1618. +}
  1619. +
  1620. +
  1621. +asmlinkage void
  1622. +plat_irq_dispatch(void)
  1623. +{
  1624. + ar231x_irq_dispatch();
  1625. +}
  1626. +
  1627. +void __init
  1628. +plat_time_init(void)
  1629. +{
  1630. + ar5312_time_init();
  1631. + ar2315_time_init();
  1632. +}
  1633. +
  1634. +unsigned int __cpuinit
  1635. +get_c0_compare_int(void)
  1636. +{
  1637. + return CP0_LEGACY_COMPARE_IRQ;
  1638. +}
  1639. +
  1640. +void __init
  1641. +arch_init_irq(void)
  1642. +{
  1643. + clear_c0_status(ST0_IM);
  1644. + mips_cpu_irq_init();
  1645. +
  1646. + /* Initialize interrupt controllers */
  1647. + ar5312_irq_init();
  1648. + ar2315_irq_init();
  1649. +}
  1650. +
  1651. +
  1652. diff -Nur linux-2.6.39-rc7.orig/arch/mips/ar231x/devices.c linux-2.6.39-rc7/arch/mips/ar231x/devices.c
  1653. --- linux-2.6.39-rc7.orig/arch/mips/ar231x/devices.c 1970-01-01 01:00:00.000000000 +0100
  1654. +++ linux-2.6.39-rc7/arch/mips/ar231x/devices.c 2011-05-15 21:34:57.000000000 +0200
  1655. @@ -0,0 +1,175 @@
  1656. +#include <linux/kernel.h>
  1657. +#include <linux/init.h>
  1658. +#include <linux/serial.h>
  1659. +#include <linux/serial_core.h>
  1660. +#include <linux/serial_8250.h>
  1661. +#include <linux/platform_device.h>
  1662. +#include <ar231x_platform.h>
  1663. +#include <ar231x.h>
  1664. +#include "devices.h"
  1665. +#include "ar5312.h"
  1666. +#include "ar2315.h"
  1667. +
  1668. +struct ar231x_board_config ar231x_board;
  1669. +int ar231x_devtype = DEV_TYPE_UNKNOWN;
  1670. +const struct ar231x_gpiodev *ar231x_gpiodev;
  1671. +EXPORT_SYMBOL(ar231x_gpiodev);
  1672. +
  1673. +static struct resource ar231x_eth0_res[] = {
  1674. + {
  1675. + .name = "eth0_membase",
  1676. + .flags = IORESOURCE_MEM,
  1677. + },
  1678. + {
  1679. + .name = "eth0_irq",
  1680. + .flags = IORESOURCE_IRQ,
  1681. + }
  1682. +};
  1683. +
  1684. +static struct resource ar231x_eth1_res[] = {
  1685. + {
  1686. + .name = "eth1_membase",
  1687. + .flags = IORESOURCE_MEM,
  1688. + },
  1689. + {
  1690. + .name = "eth1_irq",
  1691. + .flags = IORESOURCE_IRQ,
  1692. + }
  1693. +};
  1694. +
  1695. +static struct platform_device ar231x_eth[] = {
  1696. + {
  1697. + .id = 0,
  1698. + .name = "ar231x-eth",
  1699. + .resource = ar231x_eth0_res,
  1700. + .num_resources = ARRAY_SIZE(ar231x_eth0_res)
  1701. + },
  1702. + {
  1703. + .id = 1,
  1704. + .name = "ar231x-eth",
  1705. + .resource = ar231x_eth1_res,
  1706. + .num_resources = ARRAY_SIZE(ar231x_eth1_res)
  1707. + }
  1708. +};
  1709. +
  1710. +static struct resource ar231x_wmac0_res[] = {
  1711. + {
  1712. + .name = "wmac0_membase",
  1713. + .flags = IORESOURCE_MEM,
  1714. + },
  1715. + {
  1716. + .name = "wmac0_irq",
  1717. + .flags = IORESOURCE_IRQ,
  1718. + }
  1719. +};
  1720. +
  1721. +static struct resource ar231x_wmac1_res[] = {
  1722. + {
  1723. + .name = "wmac1_membase",
  1724. + .flags = IORESOURCE_MEM,
  1725. + },
  1726. + {
  1727. + .name = "wmac1_irq",
  1728. + .flags = IORESOURCE_IRQ,
  1729. + }
  1730. +};
  1731. +
  1732. +
  1733. +static struct platform_device ar231x_wmac[] = {
  1734. + {
  1735. + .id = 0,
  1736. + .name = "ar231x-wmac",
  1737. + .resource = ar231x_wmac0_res,
  1738. + .num_resources = ARRAY_SIZE(ar231x_wmac0_res),
  1739. + .dev.platform_data = &ar231x_board,
  1740. + },
  1741. + {
  1742. + .id = 1,
  1743. + .name = "ar231x-wmac",
  1744. + .resource = ar231x_wmac1_res,
  1745. + .num_resources = ARRAY_SIZE(ar231x_wmac1_res),
  1746. + .dev.platform_data = &ar231x_board,
  1747. + },
  1748. +};
  1749. +
  1750. +static const char *devtype_strings[] = {
  1751. + [DEV_TYPE_AR5312] = "Atheros AR5312",
  1752. + [DEV_TYPE_AR2312] = "Atheros AR2312",
  1753. + [DEV_TYPE_AR2313] = "Atheros AR2313",
  1754. + [DEV_TYPE_AR2315] = "Atheros AR2315",
  1755. + [DEV_TYPE_AR2316] = "Atheros AR2316",
  1756. + [DEV_TYPE_AR2317] = "Atheros AR2317",
  1757. + [DEV_TYPE_UNKNOWN] = "Atheros (unknown)",
  1758. +};
  1759. +
  1760. +const char *get_system_type(void)
  1761. +{
  1762. + if ((ar231x_devtype >= ARRAY_SIZE(devtype_strings)) ||
  1763. + !devtype_strings[ar231x_devtype])
  1764. + return devtype_strings[DEV_TYPE_UNKNOWN];
  1765. + return devtype_strings[ar231x_devtype];
  1766. +}
  1767. +
  1768. +
  1769. +int __init
  1770. +ar231x_add_ethernet(int nr, u32 base, int irq, void *pdata)
  1771. +{
  1772. + struct resource *res;
  1773. +
  1774. + ar231x_eth[nr].dev.platform_data = pdata;
  1775. + res = &ar231x_eth[nr].resource[0];
  1776. + res->start = base;
  1777. + res->end = base + 0x2000 - 1;
  1778. + res++;
  1779. + res->start = irq;
  1780. + res->end = irq;
  1781. + return platform_device_register(&ar231x_eth[nr]);
  1782. +}
  1783. +
  1784. +void __init
  1785. +ar231x_serial_setup(u32 mapbase, unsigned int uartclk)
  1786. +{
  1787. + struct uart_port s;
  1788. +
  1789. + memset(&s, 0, sizeof(s));
  1790. +
  1791. + s.flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST;
  1792. + s.iotype = UPIO_MEM;
  1793. + s.irq = AR531X_MISC_IRQ_UART0;
  1794. + s.regshift = 2;
  1795. + s.mapbase = mapbase;
  1796. + s.uartclk = uartclk;
  1797. + s.membase = (void __iomem *)s.mapbase;
  1798. +
  1799. + early_serial_setup(&s);
  1800. +}
  1801. +
  1802. +int __init
  1803. +ar231x_add_wmac(int nr, u32 base, int irq)
  1804. +{
  1805. + struct resource *res;
  1806. +
  1807. + ar231x_wmac[nr].dev.platform_data = &ar231x_board;
  1808. + res = &ar231x_wmac[nr].resource[0];
  1809. + res->start = base;
  1810. + res->end = base + 0x10000 - 1;
  1811. + res++;
  1812. + res->start = irq;
  1813. + res->end = irq;
  1814. + return platform_device_register(&ar231x_wmac[nr]);
  1815. +}
  1816. +
  1817. +static int __init ar231x_register_devices(void)
  1818. +{
  1819. + static struct resource res = {
  1820. + .start = 0xFFFFFFFF,
  1821. + };
  1822. +
  1823. + platform_device_register_simple("GPIODEV", 0, &res, 1);
  1824. + ar5312_init_devices();
  1825. + ar2315_init_devices();
  1826. +
  1827. + return 0;
  1828. +}
  1829. +
  1830. +device_initcall(ar231x_register_devices);
  1831. diff -Nur linux-2.6.39-rc7.orig/arch/mips/ar231x/devices.h linux-2.6.39-rc7/arch/mips/ar231x/devices.h
  1832. --- linux-2.6.39-rc7.orig/arch/mips/ar231x/devices.h 1970-01-01 01:00:00.000000000 +0100
  1833. +++ linux-2.6.39-rc7/arch/mips/ar231x/devices.h 2011-05-15 21:34:57.000000000 +0200
  1834. @@ -0,0 +1,37 @@
  1835. +#ifndef __AR231X_DEVICES_H
  1836. +#define __AR231X_DEVICES_H
  1837. +
  1838. +enum {
  1839. + /* handled by ar5312.c */
  1840. + DEV_TYPE_AR2312,
  1841. + DEV_TYPE_AR2313,
  1842. + DEV_TYPE_AR5312,
  1843. +
  1844. + /* handled by ar2315.c */
  1845. + DEV_TYPE_AR2315,
  1846. + DEV_TYPE_AR2316,
  1847. + DEV_TYPE_AR2317,
  1848. +
  1849. + DEV_TYPE_UNKNOWN
  1850. +};
  1851. +
  1852. +extern int ar231x_devtype;
  1853. +extern struct ar231x_board_config ar231x_board;
  1854. +extern asmlinkage void (*ar231x_irq_dispatch)(void);
  1855. +
  1856. +extern int ar231x_find_config(u8 *flash_limit);
  1857. +extern void ar231x_serial_setup(u32 mapbase, unsigned int uartclk);
  1858. +extern int ar231x_add_wmac(int nr, u32 base, int irq);
  1859. +extern int ar231x_add_ethernet(int nr, u32 base, int irq, void *pdata);
  1860. +
  1861. +static inline bool is_2315(void)
  1862. +{
  1863. + return (current_cpu_data.cputype == CPU_4KEC);
  1864. +}
  1865. +
  1866. +static inline bool is_5312(void)
  1867. +{
  1868. + return !is_2315();
  1869. +}
  1870. +
  1871. +#endif
  1872. diff -Nur linux-2.6.39-rc7.orig/arch/mips/ar231x/early_printk.c linux-2.6.39-rc7/arch/mips/ar231x/early_printk.c
  1873. --- linux-2.6.39-rc7.orig/arch/mips/ar231x/early_printk.c 1970-01-01 01:00:00.000000000 +0100
  1874. +++ linux-2.6.39-rc7/arch/mips/ar231x/early_printk.c 2011-05-15 21:34:57.000000000 +0200
  1875. @@ -0,0 +1,44 @@
  1876. +/*
  1877. + * This file is subject to the terms and conditions of the GNU General Public
  1878. + * License. See the file "COPYING" in the main directory of this archive
  1879. + * for more details.
  1880. + *
  1881. + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
  1882. + */
  1883. +
  1884. +#include <linux/mm.h>
  1885. +#include <linux/io.h>
  1886. +#include <linux/serial_reg.h>
  1887. +#include <asm/addrspace.h>
  1888. +
  1889. +#include <asm/mach-ar231x/ar2315_regs.h>
  1890. +#include <asm/mach-ar231x/ar5312_regs.h>
  1891. +#include "devices.h"
  1892. +
  1893. +static inline void prom_uart_wr(void __iomem *base, unsigned reg,
  1894. + unsigned char ch)
  1895. +{
  1896. + __raw_writeb(ch, base + 4 * reg);
  1897. +}
  1898. +
  1899. +static inline unsigned char prom_uart_rr(void __iomem *base, unsigned reg)
  1900. +{
  1901. + return __raw_readb(base + 4 * reg);
  1902. +}
  1903. +
  1904. +void prom_putchar(unsigned char ch)
  1905. +{
  1906. + static void __iomem *base;
  1907. +
  1908. + if (unlikely(base == NULL)) {
  1909. + if (is_2315())
  1910. + base = (void __iomem *)(KSEG1ADDR(AR2315_UART0));
  1911. + else
  1912. + base = (void __iomem *)(KSEG1ADDR(AR531X_UART0));
  1913. + }
  1914. +
  1915. + while ((prom_uart_rr(base, UART_LSR) & UART_LSR_THRE) == 0);
  1916. + prom_uart_wr(base, UART_TX, ch);
  1917. + while ((prom_uart_rr(base, UART_LSR) & UART_LSR_THRE) == 0);
  1918. +}
  1919. +
  1920. diff -Nur linux-2.6.39-rc7.orig/arch/mips/ar231x/pci.c linux-2.6.39-rc7/arch/mips/ar231x/pci.c
  1921. --- linux-2.6.39-rc7.orig/arch/mips/ar231x/pci.c 1970-01-01 01:00:00.000000000 +0100
  1922. +++ linux-2.6.39-rc7/arch/mips/ar231x/pci.c 2011-05-15 21:34:57.000000000 +0200
  1923. @@ -0,0 +1,230 @@
  1924. +/*
  1925. + * This program is free software; you can redistribute it and/or
  1926. + * modify it under the terms of the GNU General Public License
  1927. + * as published by the Free Software Foundation; either version 2
  1928. + * of the License, or (at your option) any later version.
  1929. + *
  1930. + * This program is distributed in the hope that it will be useful,
  1931. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1932. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1933. + * GNU General Public License for more details.
  1934. + *
  1935. + * You should have received a copy of the GNU General Public License
  1936. + * along with this program; if not, write to the Free Software
  1937. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  1938. + */
  1939. +
  1940. +#include <linux/types.h>
  1941. +#include <linux/pci.h>
  1942. +#include <linux/kernel.h>
  1943. +#include <linux/init.h>
  1944. +#include <linux/mm.h>
  1945. +#include <linux/spinlock.h>
  1946. +#include <linux/delay.h>
  1947. +#include <linux/irq.h>
  1948. +#include <asm/bootinfo.h>
  1949. +#include <asm/paccess.h>
  1950. +#include <asm/irq_cpu.h>
  1951. +#include <asm/io.h>
  1952. +#include <ar231x_platform.h>
  1953. +#include <ar231x.h>
  1954. +#include <ar2315_regs.h>
  1955. +#include "devices.h"
  1956. +
  1957. +#define AR531X_MEM_BASE 0x80800000UL
  1958. +#define AR531X_MEM_SIZE 0x00ffffffUL
  1959. +#define AR531X_IO_SIZE 0x00007fffUL
  1960. +
  1961. +static unsigned long configspace;
  1962. +
  1963. +static int config_access(int devfn, int where, int size, u32 *ptr, bool write)
  1964. +{
  1965. + unsigned long flags;
  1966. + int func = PCI_FUNC(devfn);
  1967. + int dev = PCI_SLOT(devfn);
  1968. + u32 value = 0;
  1969. + int err = 0;
  1970. + u32 addr;
  1971. +
  1972. + if (((dev != 0) && (dev != 3)) || (func > 2))
  1973. + return PCIBIOS_DEVICE_NOT_FOUND;
  1974. +
  1975. + /* Select Configuration access */
  1976. + local_irq_save(flags);
  1977. + ar231x_mask_reg(AR2315_PCI_MISC_CONFIG, 0, AR2315_PCIMISC_CFG_SEL);
  1978. + mb();
  1979. +
  1980. + addr = (u32) configspace + (1 << (13 + dev)) + (func << 8) + where;
  1981. + if (size == 1)
  1982. + addr ^= 0x3;
  1983. + else if (size == 2)
  1984. + addr ^= 0x2;
  1985. +
  1986. + if (write) {
  1987. + value = *ptr;
  1988. + if (size == 1)
  1989. + err = put_dbe(value, (u8 *) addr);
  1990. + else if (size == 2)
  1991. + err = put_dbe(value, (u16 *) addr);
  1992. + else if (size == 4)
  1993. + err = put_dbe(value, (u32 *) addr);
  1994. + } else {
  1995. + if (size == 1)
  1996. + err = get_dbe(value, (u8 *) addr);
  1997. + else if (size == 2)
  1998. + err = get_dbe(value, (u16 *) addr);
  1999. + else if (size == 4)
  2000. + err = get_dbe(value, (u32 *) addr);
  2001. + if (err)
  2002. + *ptr = 0xffffffff;
  2003. + else
  2004. + *ptr = value;
  2005. + }
  2006. +
  2007. + /* Select Memory access */
  2008. + ar231x_mask_reg(AR2315_PCI_MISC_CONFIG, AR2315_PCIMISC_CFG_SEL, 0);
  2009. + local_irq_restore(flags);
  2010. +
  2011. + return (err ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL);
  2012. +}
  2013. +
  2014. +static int ar231x_pci_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 * value)
  2015. +{
  2016. + return config_access(devfn, where, size, value, 0);
  2017. +}
  2018. +
  2019. +static int ar231x_pci_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value)
  2020. +{
  2021. + return config_access(devfn, where, size, &value, 1);
  2022. +}
  2023. +
  2024. +struct pci_ops ar231x_pci_ops = {
  2025. + .read = ar231x_pci_read,
  2026. + .write = ar231x_pci_write,
  2027. +};
  2028. +
  2029. +static struct resource ar231x_mem_resource = {
  2030. + .name = "AR531x PCI MEM",
  2031. + .start = AR531X_MEM_BASE,
  2032. + .end = AR531X_MEM_BASE + AR531X_MEM_SIZE - AR531X_IO_SIZE - 1 + 0x4000000,
  2033. + .flags = IORESOURCE_MEM,
  2034. +};
  2035. +
  2036. +static struct resource ar231x_io_resource = {
  2037. + .name = "AR531x PCI I/O",
  2038. + .start = AR531X_MEM_BASE + AR531X_MEM_SIZE - AR531X_IO_SIZE,
  2039. + .end = AR531X_MEM_BASE + AR531X_MEM_SIZE - 1,
  2040. + .flags = IORESOURCE_IO,
  2041. +};
  2042. +
  2043. +struct pci_controller ar231x_pci_controller = {
  2044. + .pci_ops = &ar231x_pci_ops,
  2045. + .mem_resource = &ar231x_mem_resource,
  2046. + .io_resource = &ar231x_io_resource,
  2047. + .mem_offset = 0x00000000UL,
  2048. + .io_offset = 0x00000000UL,
  2049. +};
  2050. +
  2051. +int pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  2052. +{
  2053. + return AR2315_IRQ_LCBUS_PCI;
  2054. +}
  2055. +
  2056. +int pcibios_plat_dev_init(struct pci_dev *dev)
  2057. +{
  2058. + pci_write_config_byte(dev, PCI_INTERRUPT_LINE, 5);
  2059. + pci_write_config_word(dev, 0x40, 0);
  2060. +
  2061. + /* Clear any pending Abort or external Interrupts
  2062. + * and enable interrupt processing */
  2063. + ar231x_mask_reg(AR2315_PCI_INTEN_REG, AR2315_PCI_INT_ENABLE, 0);
  2064. + ar231x_write_reg(AR2315_PCI_INT_STATUS, (AR2315_PCI_ABORT_INT | AR2315_PCI_EXT_INT));
  2065. + ar231x_write_reg(AR2315_PCI_INT_MASK, (AR2315_PCI_ABORT_INT | AR2315_PCI_EXT_INT));
  2066. + ar231x_mask_reg(AR2315_PCI_INTEN_REG, 0, AR2315_PCI_INT_ENABLE);
  2067. +
  2068. + return 0;
  2069. +}
  2070. +
  2071. +static void
  2072. +ar2315_pci_fixup(struct pci_dev *dev)
  2073. +{
  2074. + unsigned int devfn = dev->devfn;
  2075. +
  2076. + if (dev->bus->number != 0)
  2077. + return;
  2078. +
  2079. + /* Only fix up the PCI host settings */
  2080. + if ((PCI_SLOT(devfn) != 3) || (PCI_FUNC(devfn) != 0))
  2081. + return;
  2082. +
  2083. + /* Fix up MBARs */
  2084. + pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, HOST_PCI_MBAR0);
  2085. + pci_write_config_dword(dev, PCI_BASE_ADDRESS_1, HOST_PCI_MBAR1);
  2086. + pci_write_config_dword(dev, PCI_BASE_ADDRESS_2, HOST_PCI_MBAR2);
  2087. + pci_write_config_dword(dev, PCI_COMMAND,
  2088. + PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | PCI_COMMAND_SPECIAL |
  2089. + PCI_COMMAND_INVALIDATE | PCI_COMMAND_PARITY | PCI_COMMAND_SERR |
  2090. + PCI_COMMAND_FAST_BACK);
  2091. +}
  2092. +DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, ar2315_pci_fixup);
  2093. +
  2094. +static int __init
  2095. +ar2315_pci_init(void)
  2096. +{
  2097. + u32 reg;
  2098. +
  2099. + if (ar231x_devtype != DEV_TYPE_AR2315)
  2100. + return -ENODEV;
  2101. +
  2102. + configspace = (unsigned long) ioremap_nocache(0x80000000, 1*1024*1024); /* Remap PCI config space */
  2103. + ar231x_pci_controller.io_map_base =
  2104. + (unsigned long) ioremap_nocache(AR531X_MEM_BASE + AR531X_MEM_SIZE, AR531X_IO_SIZE);
  2105. + set_io_port_base(ar231x_pci_controller.io_map_base); /* PCI I/O space */
  2106. +
  2107. + reg = ar231x_mask_reg(AR2315_RESET, 0, AR2315_RESET_PCIDMA);
  2108. + msleep(10);
  2109. +
  2110. + reg &= ~AR2315_RESET_PCIDMA;
  2111. + ar231x_write_reg(AR2315_RESET, reg);
  2112. + msleep(10);
  2113. +
  2114. + ar231x_mask_reg(AR2315_ENDIAN_CTL, 0,
  2115. + AR2315_CONFIG_PCIAHB | AR2315_CONFIG_PCIAHB_BRIDGE);
  2116. +
  2117. + ar231x_write_reg(AR2315_PCICLK, AR2315_PCICLK_PLLC_CLKM |
  2118. + (AR2315_PCICLK_IN_FREQ_DIV_6 << AR2315_PCICLK_DIV_S));
  2119. + ar231x_mask_reg(AR2315_AHB_ARB_CTL, 0, AR2315_ARB_PCI);
  2120. + ar231x_mask_reg(AR2315_IF_CTL, AR2315_IF_PCI_CLK_MASK | AR2315_IF_MASK,
  2121. + AR2315_IF_PCI | AR2315_IF_PCI_HOST | AR2315_IF_PCI_INTR |
  2122. + (AR2315_IF_PCI_CLK_OUTPUT_CLK << AR2315_IF_PCI_CLK_SHIFT));
  2123. +
  2124. + /* Reset the PCI bus by setting bits 5-4 in PCI_MCFG */
  2125. + ar231x_mask_reg(AR2315_PCI_MISC_CONFIG, AR2315_PCIMISC_RST_MODE,
  2126. + AR2315_PCIRST_LOW);
  2127. + msleep(100);
  2128. +
  2129. + /* Bring the PCI out of reset */
  2130. + ar231x_mask_reg(AR2315_PCI_MISC_CONFIG, AR2315_PCIMISC_RST_MODE,
  2131. + AR2315_PCIRST_HIGH | AR2315_PCICACHE_DIS | 0x8);
  2132. +
  2133. + ar231x_write_reg(AR2315_PCI_UNCACHE_CFG,
  2134. + 0x1E | /* 1GB uncached */
  2135. + (1 << 5) | /* Enable uncached */
  2136. + (0x2 << 30) /* Base: 0x80000000 */
  2137. + );
  2138. + ar231x_read_reg(AR2315_PCI_UNCACHE_CFG);
  2139. +
  2140. + msleep(500);
  2141. +
  2142. + /* dirty hack - anyone with a datasheet that knows the memory map ? */
  2143. + ioport_resource.start = 0x10000000;
  2144. + ioport_resource.end = 0xffffffff;
  2145. + iomem_resource.start = 0x10000000;
  2146. + iomem_resource.end = 0xffffffff;
  2147. +
  2148. + register_pci_controller(&ar231x_pci_controller);
  2149. +
  2150. + return 0;
  2151. +}
  2152. +
  2153. +arch_initcall(ar2315_pci_init);
  2154. diff -Nur linux-2.6.39-rc7.orig/arch/mips/ar231x/prom.c linux-2.6.39-rc7/arch/mips/ar231x/prom.c
  2155. --- linux-2.6.39-rc7.orig/arch/mips/ar231x/prom.c 1970-01-01 01:00:00.000000000 +0100
  2156. +++ linux-2.6.39-rc7/arch/mips/ar231x/prom.c 2011-05-15 21:34:57.000000000 +0200
  2157. @@ -0,0 +1,37 @@
  2158. +/*
  2159. + * This file is subject to the terms and conditions of the GNU General Public
  2160. + * License. See the file "COPYING" in the main directory of this archive
  2161. + * for more details.
  2162. + *
  2163. + * Copyright MontaVista Software Inc
  2164. + * Copyright (C) 2003 Atheros Communications, Inc., All Rights Reserved.
  2165. + * Copyright (C) 2006 FON Technology, SL.
  2166. + * Copyright (C) 2006 Imre Kaloz <kaloz@openwrt.org>
  2167. + * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
  2168. + */
  2169. +
  2170. +/*
  2171. + * Prom setup file for ar531x
  2172. + */
  2173. +
  2174. +#include <linux/init.h>
  2175. +#include <generated/autoconf.h>
  2176. +#include <linux/kernel.h>
  2177. +#include <linux/string.h>
  2178. +#include <linux/mm.h>
  2179. +#include <linux/bootmem.h>
  2180. +
  2181. +#include <asm/bootinfo.h>
  2182. +#include <asm/addrspace.h>
  2183. +#include "ar5312.h"
  2184. +#include "ar2315.h"
  2185. +
  2186. +void __init prom_init(void)
  2187. +{
  2188. + ar5312_prom_init();
  2189. + ar2315_prom_init();
  2190. +}
  2191. +
  2192. +void __init prom_free_prom_memory(void)
  2193. +{
  2194. +}
  2195. diff -Nur linux-2.6.39-rc7.orig/arch/mips/ar231x/reset.c linux-2.6.39-rc7/arch/mips/ar231x/reset.c
  2196. --- linux-2.6.39-rc7.orig/arch/mips/ar231x/reset.c 1970-01-01 01:00:00.000000000 +0100
  2197. +++ linux-2.6.39-rc7/arch/mips/ar231x/reset.c 2011-05-15 21:34:57.000000000 +0200
  2198. @@ -0,0 +1,161 @@
  2199. +#include <linux/init.h>
  2200. +#include <linux/module.h>
  2201. +#include <linux/timer.h>
  2202. +#include <linux/interrupt.h>
  2203. +#include <linux/kobject.h>
  2204. +#include <linux/workqueue.h>
  2205. +#include <linux/skbuff.h>
  2206. +#include <linux/netlink.h>
  2207. +#include <net/sock.h>
  2208. +#include <asm/uaccess.h>
  2209. +#include <ar231x_platform.h>
  2210. +#include <ar231x.h>
  2211. +#include <gpio.h>
  2212. +#include "devices.h"
  2213. +
  2214. +#define AR531X_RESET_GPIO_IRQ (AR531X_GPIO_IRQ(ar231x_board.config->resetConfigGpio))
  2215. +
  2216. +struct event_t {
  2217. + struct work_struct wq;
  2218. + int set;
  2219. + unsigned long jiffies;
  2220. +};
  2221. +
  2222. +static struct timer_list rst_button_timer;
  2223. +static unsigned long seen;
  2224. +
  2225. +struct sock *uevent_sock = NULL;
  2226. +EXPORT_SYMBOL_GPL(uevent_sock);
  2227. +extern u64 uevent_next_seqnum(void);
  2228. +
  2229. +static int no_release_workaround = 1;
  2230. +module_param(no_release_workaround, int, 0);
  2231. +
  2232. +static inline void
  2233. +add_msg(struct sk_buff *skb, char *msg)
  2234. +{
  2235. + char *scratch;
  2236. + scratch = skb_put(skb, strlen(msg) + 1);
  2237. + sprintf(scratch, msg);
  2238. +}
  2239. +
  2240. +static void
  2241. +hotplug_button(struct work_struct *wq)
  2242. +{
  2243. + struct sk_buff *skb;
  2244. + struct event_t *event;
  2245. + size_t len;
  2246. + char *scratch, *s;
  2247. + char buf[128];
  2248. +
  2249. + event = container_of(wq, struct event_t, wq);
  2250. + if (!uevent_sock)
  2251. + goto done;
  2252. +
  2253. + /* allocate message with the maximum possible size */
  2254. + s = event->set ? "pressed" : "released";
  2255. + len = strlen(s) + 2;
  2256. + skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
  2257. + if (!skb)
  2258. + goto done;
  2259. +
  2260. + /* add header */
  2261. + scratch = skb_put(skb, len);
  2262. + sprintf(scratch, "%s@",s);
  2263. +
  2264. + /* copy keys to our continuous event payload buffer */
  2265. + add_msg(skb, "HOME=/");
  2266. + add_msg(skb, "PATH=/sbin:/bin:/usr/sbin:/usr/bin");
  2267. + add_msg(skb, "SUBSYSTEM=button");
  2268. + add_msg(skb, "BUTTON=reset");
  2269. + add_msg(skb, (event->set ? "ACTION=pressed" : "ACTION=released"));
  2270. + sprintf(buf, "SEEN=%ld", (event->jiffies - seen)/HZ);
  2271. + add_msg(skb, buf);
  2272. + snprintf(buf, 128, "SEQNUM=%llu", uevent_next_seqnum());
  2273. + add_msg(skb, buf);
  2274. +
  2275. + NETLINK_CB(skb).dst_group = 1;
  2276. + netlink_broadcast(uevent_sock, skb, 0, 1, GFP_KERNEL);
  2277. +
  2278. +done:
  2279. + kfree(event);
  2280. +}
  2281. +
  2282. +static void
  2283. +reset_button_poll(unsigned long unused)
  2284. +{
  2285. + struct event_t *event;
  2286. + int gpio = ~0;
  2287. +
  2288. + if(!no_release_workaround)
  2289. + return;
  2290. +
  2291. + gpio = ar231x_gpiodev->get();
  2292. + gpio &= (1 << (AR531X_RESET_GPIO_IRQ - AR531X_GPIO_IRQ_BASE));
  2293. + if(gpio) {
  2294. + rst_button_timer.expires = jiffies + (HZ / 4);
  2295. + add_timer(&rst_button_timer);
  2296. + return;
  2297. + }
  2298. +
  2299. + event = (struct event_t *) kzalloc(sizeof(struct event_t), GFP_ATOMIC);
  2300. + if (!event)
  2301. + return;
  2302. +
  2303. + event->set = 0;
  2304. + event->jiffies = jiffies;
  2305. + INIT_WORK(&event->wq, hotplug_button);
  2306. + schedule_work(&event->wq);
  2307. +}
  2308. +
  2309. +static irqreturn_t
  2310. +button_handler(int irq, void *dev_id)
  2311. +{
  2312. + static int pressed = 0;
  2313. + struct event_t *event;
  2314. + u32 gpio = ~0;
  2315. +
  2316. + event = (struct event_t *) kzalloc(sizeof(struct event_t), GFP_ATOMIC);
  2317. + if (!event)
  2318. + return IRQ_NONE;
  2319. +
  2320. + pressed = !pressed;
  2321. +
  2322. + gpio = ar231x_gpiodev->get() & (1 << (irq - AR531X_GPIO_IRQ_BASE));
  2323. +
  2324. + event->set = gpio;
  2325. + if(!event->set)
  2326. + no_release_workaround = 0;
  2327. +
  2328. + event->jiffies = jiffies;
  2329. +
  2330. + INIT_WORK(&event->wq, hotplug_button);
  2331. + schedule_work(&event->wq);
  2332. +
  2333. + seen = jiffies;
  2334. + if(event->set && no_release_workaround)
  2335. + mod_timer(&rst_button_timer, jiffies + (HZ / 4));
  2336. +
  2337. + return IRQ_HANDLED;
  2338. +}
  2339. +
  2340. +
  2341. +static int __init
  2342. +ar231x_init_reset(void)
  2343. +{
  2344. + seen = jiffies;
  2345. +
  2346. + if (ar231x_board.config->resetConfigGpio == 0xffff)
  2347. + return -ENODEV;
  2348. +
  2349. + init_timer(&rst_button_timer);
  2350. + rst_button_timer.function = reset_button_poll;
  2351. + rst_button_timer.expires = jiffies + HZ / 50;
  2352. + add_timer(&rst_button_timer);
  2353. +
  2354. + request_irq(AR531X_RESET_GPIO_IRQ, &button_handler, IRQF_SAMPLE_RANDOM, "ar231x_reset", NULL);
  2355. +
  2356. + return 0;
  2357. +}
  2358. +
  2359. +module_init(ar231x_init_reset);
  2360. diff -Nur linux-2.6.39-rc7.orig/arch/mips/include/asm/mach-ar231x/ar2315_regs.h linux-2.6.39-rc7/arch/mips/include/asm/mach-ar231x/ar2315_regs.h
  2361. --- linux-2.6.39-rc7.orig/arch/mips/include/asm/mach-ar231x/ar2315_regs.h 1970-01-01 01:00:00.000000000 +0100
  2362. +++ linux-2.6.39-rc7/arch/mips/include/asm/mach-ar231x/ar2315_regs.h 2011-05-15 21:44:12.000000000 +0200
  2363. @@ -0,0 +1,580 @@
  2364. +/*
  2365. + * Register definitions for AR2315+
  2366. + *
  2367. + * This file is subject to the terms and conditions of the GNU General Public
  2368. + * License. See the file "COPYING" in the main directory of this archive
  2369. + * for more details.
  2370. + *
  2371. + * Copyright (C) 2003 Atheros Communications, Inc., All Rights Reserved.
  2372. + * Copyright (C) 2006 FON Technology, SL.
  2373. + * Copyright (C) 2006 Imre Kaloz <kaloz@openwrt.org>
  2374. + * Copyright (C) 2006-2008 Felix Fietkau <nbd@openwrt.org>
  2375. + */
  2376. +
  2377. +#ifndef __AR2315_REG_H
  2378. +#define __AR2315_REG_H
  2379. +
  2380. +/*
  2381. + * IRQs
  2382. + */
  2383. +#define AR2315_IRQ_MISC_INTRS MIPS_CPU_IRQ_BASE+2 /* C0_CAUSE: 0x0400 */
  2384. +#define AR2315_IRQ_WLAN0_INTRS MIPS_CPU_IRQ_BASE+3 /* C0_CAUSE: 0x0800 */
  2385. +#define AR2315_IRQ_ENET0_INTRS MIPS_CPU_IRQ_BASE+4 /* C0_CAUSE: 0x1000 */
  2386. +#define AR2315_IRQ_LCBUS_PCI MIPS_CPU_IRQ_BASE+5 /* C0_CAUSE: 0x2000 */
  2387. +#define AR2315_IRQ_WLAN0_POLL MIPS_CPU_IRQ_BASE+6 /* C0_CAUSE: 0x4000 */
  2388. +
  2389. +/*
  2390. + * Address map
  2391. + */
  2392. +#define AR2315_SPI_READ 0x08000000 /* SPI FLASH */
  2393. +#define AR2315_WLAN0 0x10000000 /* Wireless MMR */
  2394. +#define AR2315_PCI 0x10100000 /* PCI MMR */
  2395. +#define AR2315_SDRAMCTL 0x10300000 /* SDRAM MMR */
  2396. +#define AR2315_LOCAL 0x10400000 /* LOCAL BUS MMR */
  2397. +#define AR2315_ENET0 0x10500000 /* ETHERNET MMR */
  2398. +#define AR2315_DSLBASE 0x11000000 /* RESET CONTROL MMR */
  2399. +#define AR2315_UART0 0x11100003 /* UART MMR */
  2400. +#define AR2315_SPI 0x11300000 /* SPI FLASH MMR */
  2401. +#define AR2315_PCIEXT 0x80000000 /* pci external */
  2402. +
  2403. +/*
  2404. + * Reset Register
  2405. + */
  2406. +#define AR2315_COLD_RESET (AR2315_DSLBASE + 0x0000)
  2407. +
  2408. +#define AR2315_RESET_COLD_AHB 0x00000001
  2409. +#define AR2315_RESET_COLD_APB 0x00000002
  2410. +#define AR2315_RESET_COLD_CPU 0x00000004
  2411. +#define AR2315_RESET_COLD_CPUWARM 0x00000008
  2412. +#define AR2315_RESET_SYSTEM (RESET_COLD_CPU | RESET_COLD_APB | RESET_COLD_AHB) /* full system */
  2413. +#define AR2317_RESET_SYSTEM 0x00000010
  2414. +
  2415. +
  2416. +#define AR2315_RESET (AR2315_DSLBASE + 0x0004)
  2417. +
  2418. +#define AR2315_RESET_WARM_WLAN0_MAC 0x00000001 /* warm reset WLAN0 MAC */
  2419. +#define AR2315_RESET_WARM_WLAN0_BB 0x00000002 /* warm reset WLAN0 BaseBand */
  2420. +#define AR2315_RESET_MPEGTS_RSVD 0x00000004 /* warm reset MPEG-TS */
  2421. +#define AR2315_RESET_PCIDMA 0x00000008 /* warm reset PCI ahb/dma */
  2422. +#define AR2315_RESET_MEMCTL 0x00000010 /* warm reset memory controller */
  2423. +#define AR2315_RESET_LOCAL 0x00000020 /* warm reset local bus */
  2424. +#define AR2315_RESET_I2C_RSVD 0x00000040 /* warm reset I2C bus */
  2425. +#define AR2315_RESET_SPI 0x00000080 /* warm reset SPI interface */
  2426. +#define AR2315_RESET_UART0 0x00000100 /* warm reset UART0 */
  2427. +#define AR2315_RESET_IR_RSVD 0x00000200 /* warm reset IR interface */
  2428. +#define AR2315_RESET_EPHY0 0x00000400 /* cold reset ENET0 phy */
  2429. +#define AR2315_RESET_ENET0 0x00000800 /* cold reset ENET0 mac */
  2430. +
  2431. +/*
  2432. + * AHB master arbitration control
  2433. + */
  2434. +#define AR2315_AHB_ARB_CTL (AR2315_DSLBASE + 0x0008)
  2435. +
  2436. +#define AR2315_ARB_CPU 0x00000001 /* CPU, default */
  2437. +#define AR2315_ARB_WLAN 0x00000002 /* WLAN */
  2438. +#define AR2315_ARB_MPEGTS_RSVD 0x00000004 /* MPEG-TS */
  2439. +#define AR2315_ARB_LOCAL 0x00000008 /* LOCAL */
  2440. +#define AR2315_ARB_PCI 0x00000010 /* PCI */
  2441. +#define AR2315_ARB_ETHERNET 0x00000020 /* Ethernet */
  2442. +#define AR2315_ARB_RETRY 0x00000100 /* retry policy, debug only */
  2443. +
  2444. +/*
  2445. + * Config Register
  2446. + */
  2447. +#define AR2315_ENDIAN_CTL (AR2315_DSLBASE + 0x000c)
  2448. +
  2449. +#define AR2315_CONFIG_AHB 0x00000001 /* EC - AHB bridge endianess */
  2450. +#define AR2315_CONFIG_WLAN 0x00000002 /* WLAN byteswap */
  2451. +#define AR2315_CONFIG_MPEGTS_RSVD 0x00000004 /* MPEG-TS byteswap */
  2452. +#define AR2315_CONFIG_PCI 0x00000008 /* PCI byteswap */
  2453. +#define AR2315_CONFIG_MEMCTL 0x00000010 /* Memory controller endianess */
  2454. +#define AR2315_CONFIG_LOCAL 0x00000020 /* Local bus byteswap */
  2455. +#define AR2315_CONFIG_ETHERNET 0x00000040 /* Ethernet byteswap */
  2456. +
  2457. +#define AR2315_CONFIG_MERGE 0x00000200 /* CPU write buffer merge */
  2458. +#define AR2315_CONFIG_CPU 0x00000400 /* CPU big endian */
  2459. +#define AR2315_CONFIG_PCIAHB 0x00000800
  2460. +#define AR2315_CONFIG_PCIAHB_BRIDGE 0x00001000
  2461. +#define AR2315_CONFIG_SPI 0x00008000 /* SPI byteswap */
  2462. +#define AR2315_CONFIG_CPU_DRAM 0x00010000
  2463. +#define AR2315_CONFIG_CPU_PCI 0x00020000
  2464. +#define AR2315_CONFIG_CPU_MMR 0x00040000
  2465. +#define AR2315_CONFIG_BIG 0x00000400
  2466. +
  2467. +
  2468. +/*
  2469. + * NMI control
  2470. + */
  2471. +#define AR2315_NMI_CTL (AR2315_DSLBASE + 0x0010)
  2472. +
  2473. +#define AR2315_NMI_EN 1
  2474. +
  2475. +/*
  2476. + * Revision Register - Initial value is 0x3010 (WMAC 3.0, AR531X 1.0).
  2477. + */
  2478. +#define AR2315_SREV (AR2315_DSLBASE + 0x0014)
  2479. +
  2480. +#define AR2315_REV_MAJ 0x00f0
  2481. +#define AR2315_REV_MAJ_S 4
  2482. +#define AR2315_REV_MIN 0x000f
  2483. +#define AR2315_REV_MIN_S 0
  2484. +#define AR2315_REV_CHIP (AR2315_REV_MAJ|AR2315_REV_MIN)
  2485. +
  2486. +/*
  2487. + * Interface Enable
  2488. + */
  2489. +#define AR2315_IF_CTL (AR2315_DSLBASE + 0x0018)
  2490. +
  2491. +#define AR2315_IF_MASK 0x00000007
  2492. +#define AR2315_IF_DISABLED 0
  2493. +#define AR2315_IF_PCI 1
  2494. +#define AR2315_IF_TS_LOCAL 2
  2495. +#define AR2315_IF_ALL 3 /* only for emulation with separate pins */
  2496. +#define AR2315_IF_LOCAL_HOST 0x00000008
  2497. +#define AR2315_IF_PCI_HOST 0x00000010
  2498. +#define AR2315_IF_PCI_INTR 0x00000020
  2499. +#define AR2315_IF_PCI_CLK_MASK 0x00030000
  2500. +#define AR2315_IF_PCI_CLK_INPUT 0
  2501. +#define AR2315_IF_PCI_CLK_OUTPUT_LOW 1
  2502. +#define AR2315_IF_PCI_CLK_OUTPUT_CLK 2
  2503. +#define AR2315_IF_PCI_CLK_OUTPUT_HIGH 3
  2504. +#define AR2315_IF_PCI_CLK_SHIFT 16
  2505. +
  2506. +/*
  2507. + * APB Interrupt control
  2508. + */
  2509. +
  2510. +#define AR2315_ISR (AR2315_DSLBASE + 0x0020)
  2511. +#define AR2315_IMR (AR2315_DSLBASE + 0x0024)
  2512. +#define AR2315_GISR (AR2315_DSLBASE + 0x0028)
  2513. +
  2514. +#define AR2315_ISR_UART0 0x0001 /* high speed UART */
  2515. +#define AR2315_ISR_I2C_RSVD 0x0002 /* I2C bus */
  2516. +#define AR2315_ISR_SPI 0x0004 /* SPI bus */
  2517. +#define AR2315_ISR_AHB 0x0008 /* AHB error */
  2518. +#define AR2315_ISR_APB 0x0010 /* APB error */
  2519. +#define AR2315_ISR_TIMER 0x0020 /* timer */
  2520. +#define AR2315_ISR_GPIO 0x0040 /* GPIO */
  2521. +#define AR2315_ISR_WD 0x0080 /* watchdog */
  2522. +#define AR2315_ISR_IR_RSVD 0x0100 /* IR */
  2523. +
  2524. +#define AR2315_GISR_MISC 0x0001
  2525. +#define AR2315_GISR_WLAN0 0x0002
  2526. +#define AR2315_GISR_MPEGTS_RSVD 0x0004
  2527. +#define AR2315_GISR_LOCALPCI 0x0008
  2528. +#define AR2315_GISR_WMACPOLL 0x0010
  2529. +#define AR2315_GISR_TIMER 0x0020
  2530. +#define AR2315_GISR_ETHERNET 0x0040
  2531. +
  2532. +/*
  2533. + * Interrupt routing from IO to the processor IP bits
  2534. + * Define our inter mask and level
  2535. + */
  2536. +#define AR2315_INTR_MISCIO SR_IBIT3
  2537. +#define AR2315_INTR_WLAN0 SR_IBIT4
  2538. +#define AR2315_INTR_ENET0 SR_IBIT5
  2539. +#define AR2315_INTR_LOCALPCI SR_IBIT6
  2540. +#define AR2315_INTR_WMACPOLL SR_IBIT7
  2541. +#define AR2315_INTR_COMPARE SR_IBIT8
  2542. +
  2543. +/*
  2544. + * Timers
  2545. + */
  2546. +#define AR2315_TIMER (AR2315_DSLBASE + 0x0030)
  2547. +#define AR2315_RELOAD (AR2315_DSLBASE + 0x0034)
  2548. +#define AR2315_WD (AR2315_DSLBASE + 0x0038)
  2549. +#define AR2315_WDC (AR2315_DSLBASE + 0x003c)
  2550. +
  2551. +#define AR2315_WDC_IGNORE_EXPIRATION 0x00000000
  2552. +#define AR2315_WDC_NMI 0x00000001 /* NMI on watchdog */
  2553. +#define AR2315_WDC_RESET 0x00000002 /* reset on watchdog */
  2554. +
  2555. +/*
  2556. + * CPU Performance Counters
  2557. + */
  2558. +#define AR2315_PERFCNT0 (AR2315_DSLBASE + 0x0048)
  2559. +#define AR2315_PERFCNT1 (AR2315_DSLBASE + 0x004c)
  2560. +
  2561. +#define AR2315_PERF0_DATAHIT 0x0001 /* Count Data Cache Hits */
  2562. +#define AR2315_PERF0_DATAMISS 0x0002 /* Count Data Cache Misses */
  2563. +#define AR2315_PERF0_INSTHIT 0x0004 /* Count Instruction Cache Hits */
  2564. +#define AR2315_PERF0_INSTMISS 0x0008 /* Count Instruction Cache Misses */
  2565. +#define AR2315_PERF0_ACTIVE 0x0010 /* Count Active Processor Cycles */
  2566. +#define AR2315_PERF0_WBHIT 0x0020 /* Count CPU Write Buffer Hits */
  2567. +#define AR2315_PERF0_WBMISS 0x0040 /* Count CPU Write Buffer Misses */
  2568. +
  2569. +#define AR2315_PERF1_EB_ARDY 0x0001 /* Count EB_ARdy signal */
  2570. +#define AR2315_PERF1_EB_AVALID 0x0002 /* Count EB_AValid signal */
  2571. +#define AR2315_PERF1_EB_WDRDY 0x0004 /* Count EB_WDRdy signal */
  2572. +#define AR2315_PERF1_EB_RDVAL 0x0008 /* Count EB_RdVal signal */
  2573. +#define AR2315_PERF1_VRADDR 0x0010 /* Count valid read address cycles */
  2574. +#define AR2315_PERF1_VWADDR 0x0020 /* Count valid write address cycles */
  2575. +#define AR2315_PERF1_VWDATA 0x0040 /* Count valid write data cycles */
  2576. +
  2577. +/*
  2578. + * AHB Error Reporting.
  2579. + */
  2580. +#define AR2315_AHB_ERR0 (AR2315_DSLBASE + 0x0050) /* error */
  2581. +#define AR2315_AHB_ERR1 (AR2315_DSLBASE + 0x0054) /* haddr */
  2582. +#define AR2315_AHB_ERR2 (AR2315_DSLBASE + 0x0058) /* hwdata */
  2583. +#define AR2315_AHB_ERR3 (AR2315_DSLBASE + 0x005c) /* hrdata */
  2584. +#define AR2315_AHB_ERR4 (AR2315_DSLBASE + 0x0060) /* status */
  2585. +
  2586. +#define AHB_ERROR_DET 1 /* AHB Error has been detected, */
  2587. + /* write 1 to clear all bits in ERR0 */
  2588. +#define AHB_ERROR_OVR 2 /* AHB Error overflow has been detected */
  2589. +#define AHB_ERROR_WDT 4 /* AHB Error due to wdt instead of hresp */
  2590. +
  2591. +#define AR2315_PROCERR_HMAST 0x0000000f
  2592. +#define AR2315_PROCERR_HMAST_DFLT 0
  2593. +#define AR2315_PROCERR_HMAST_WMAC 1
  2594. +#define AR2315_PROCERR_HMAST_ENET 2
  2595. +#define AR2315_PROCERR_HMAST_PCIENDPT 3
  2596. +#define AR2315_PROCERR_HMAST_LOCAL 4
  2597. +#define AR2315_PROCERR_HMAST_CPU 5
  2598. +#define AR2315_PROCERR_HMAST_PCITGT 6
  2599. +
  2600. +#define AR2315_PROCERR_HMAST_S 0
  2601. +#define AR2315_PROCERR_HWRITE 0x00000010
  2602. +#define AR2315_PROCERR_HSIZE 0x00000060
  2603. +#define AR2315_PROCERR_HSIZE_S 5
  2604. +#define AR2315_PROCERR_HTRANS 0x00000180
  2605. +#define AR2315_PROCERR_HTRANS_S 7
  2606. +#define AR2315_PROCERR_HBURST 0x00000e00
  2607. +#define AR2315_PROCERR_HBURST_S 9
  2608. +
  2609. +/*
  2610. + * Clock Control
  2611. + */
  2612. +#define AR2315_PLLC_CTL (AR2315_DSLBASE + 0x0064)
  2613. +#define AR2315_PLLV_CTL (AR2315_DSLBASE + 0x0068)
  2614. +#define AR2315_CPUCLK (AR2315_DSLBASE + 0x006c)
  2615. +#define AR2315_AMBACLK (AR2315_DSLBASE + 0x0070)
  2616. +#define AR2315_SYNCCLK (AR2315_DSLBASE + 0x0074)
  2617. +#define AR2315_DSL_SLEEP_CTL (AR2315_DSLBASE + 0x0080)
  2618. +#define AR2315_DSL_SLEEP_DUR (AR2315_DSLBASE + 0x0084)
  2619. +
  2620. +/* PLLc Control fields */
  2621. +#define PLLC_REF_DIV_M 0x00000003
  2622. +#define PLLC_REF_DIV_S 0
  2623. +#define PLLC_FDBACK_DIV_M 0x0000007C
  2624. +#define PLLC_FDBACK_DIV_S 2
  2625. +#define PLLC_ADD_FDBACK_DIV_M 0x00000080
  2626. +#define PLLC_ADD_FDBACK_DIV_S 7
  2627. +#define PLLC_CLKC_DIV_M 0x0001c000
  2628. +#define PLLC_CLKC_DIV_S 14
  2629. +#define PLLC_CLKM_DIV_M 0x00700000
  2630. +#define PLLC_CLKM_DIV_S 20
  2631. +
  2632. +/* CPU CLK Control fields */
  2633. +#define CPUCLK_CLK_SEL_M 0x00000003
  2634. +#define CPUCLK_CLK_SEL_S 0
  2635. +#define CPUCLK_CLK_DIV_M 0x0000000c
  2636. +#define CPUCLK_CLK_DIV_S 2
  2637. +
  2638. +/* AMBA CLK Control fields */
  2639. +#define AMBACLK_CLK_SEL_M 0x00000003
  2640. +#define AMBACLK_CLK_SEL_S 0
  2641. +#define AMBACLK_CLK_DIV_M 0x0000000c
  2642. +#define AMBACLK_CLK_DIV_S 2
  2643. +
  2644. +/*
  2645. + * GPIO
  2646. + */
  2647. +#define AR2315_GPIO_DI (AR2315_DSLBASE + 0x0088)
  2648. +#define AR2315_GPIO_DO (AR2315_DSLBASE + 0x0090)
  2649. +#define AR2315_GPIO_CR (AR2315_DSLBASE + 0x0098)
  2650. +#define AR2315_GPIO_INT (AR2315_DSLBASE + 0x00a0)
  2651. +
  2652. +#define AR2315_GPIO_CR_M(x) (1 << (x)) /* mask for i/o */
  2653. +#define AR2315_GPIO_CR_O(x) (1 << (x)) /* output */
  2654. +#define AR2315_GPIO_CR_I(x) (0) /* input */
  2655. +
  2656. +#define AR2315_GPIO_INT_S(x) (x) /* interrupt enable */
  2657. +#define AR2315_GPIO_INT_M (0x3F) /* mask for int */
  2658. +#define AR2315_GPIO_INT_LVL(x) ((x) << 6) /* interrupt level */
  2659. +#define AR2315_GPIO_INT_LVL_M ((0x3) << 6) /* mask for int level */
  2660. +
  2661. +#define AR2315_GPIO_INT_MAX_Y 1 /* Maximum value of Y for AR5313_GPIO_INT_* macros */
  2662. +#define AR2315_GPIO_INT_LVL_OFF 0 /* Triggerring off */
  2663. +#define AR2315_GPIO_INT_LVL_LOW 1 /* Low Level Triggered */
  2664. +#define AR2315_GPIO_INT_LVL_HIGH 2 /* High Level Triggered */
  2665. +#define AR2315_GPIO_INT_LVL_EDGE 3 /* Edge Triggered */
  2666. +
  2667. +#define AR2315_RESET_GPIO 5
  2668. +#define AR2315_NUM_GPIO 22
  2669. +
  2670. +/*
  2671. + * PCI Clock Control
  2672. + */
  2673. +#define AR2315_PCICLK (AR2315_DSLBASE + 0x00a4)
  2674. +
  2675. +#define AR2315_PCICLK_INPUT_M 0x3
  2676. +#define AR2315_PCICLK_INPUT_S 0
  2677. +
  2678. +#define AR2315_PCICLK_PLLC_CLKM 0
  2679. +#define AR2315_PCICLK_PLLC_CLKM1 1
  2680. +#define AR2315_PCICLK_PLLC_CLKC 2
  2681. +#define AR2315_PCICLK_REF_CLK 3
  2682. +
  2683. +#define AR2315_PCICLK_DIV_M 0xc
  2684. +#define AR2315_PCICLK_DIV_S 2
  2685. +
  2686. +#define AR2315_PCICLK_IN_FREQ 0
  2687. +#define AR2315_PCICLK_IN_FREQ_DIV_6 1
  2688. +#define AR2315_PCICLK_IN_FREQ_DIV_8 2
  2689. +#define AR2315_PCICLK_IN_FREQ_DIV_10 3
  2690. +
  2691. +/*
  2692. + * Observation Control Register
  2693. + */
  2694. +#define AR2315_OCR (AR2315_DSLBASE + 0x00b0)
  2695. +#define OCR_GPIO0_IRIN 0x0040
  2696. +#define OCR_GPIO1_IROUT 0x0080
  2697. +#define OCR_GPIO3_RXCLR 0x0200
  2698. +
  2699. +/*
  2700. + * General Clock Control
  2701. + */
  2702. +
  2703. +#define AR2315_MISCCLK (AR2315_DSLBASE + 0x00b4)
  2704. +#define MISCCLK_PLLBYPASS_EN 0x00000001
  2705. +#define MISCCLK_PROCREFCLK 0x00000002
  2706. +
  2707. +/*
  2708. + * SDRAM Controller
  2709. + * - No read or write buffers are included.
  2710. + */
  2711. +#define AR2315_MEM_CFG (AR2315_SDRAMCTL + 0x00)
  2712. +#define AR2315_MEM_CTRL (AR2315_SDRAMCTL + 0x0c)
  2713. +#define AR2315_MEM_REF (AR2315_SDRAMCTL + 0x10)
  2714. +
  2715. +#define SDRAM_DATA_WIDTH_M 0x00006000
  2716. +#define SDRAM_DATA_WIDTH_S 13
  2717. +
  2718. +#define SDRAM_COL_WIDTH_M 0x00001E00
  2719. +#define SDRAM_COL_WIDTH_S 9
  2720. +
  2721. +#define SDRAM_ROW_WIDTH_M 0x000001E0
  2722. +#define SDRAM_ROW_WIDTH_S 5
  2723. +
  2724. +#define SDRAM_BANKADDR_BITS_M 0x00000018
  2725. +#define SDRAM_BANKADDR_BITS_S 3
  2726. +
  2727. +/*
  2728. + * SPI Flash Interface Registers
  2729. + */
  2730. +
  2731. +#define AR2315_SPI_CTL (AR2315_SPI + 0x00)
  2732. +#define AR2315_SPI_OPCODE (AR2315_SPI + 0x04)
  2733. +#define AR2315_SPI_DATA (AR2315_SPI + 0x08)
  2734. +
  2735. +#define SPI_CTL_START 0x00000100
  2736. +#define SPI_CTL_BUSY 0x00010000
  2737. +#define SPI_CTL_TXCNT_MASK 0x0000000f
  2738. +#define SPI_CTL_RXCNT_MASK 0x000000f0
  2739. +#define SPI_CTL_TX_RX_CNT_MASK 0x000000ff
  2740. +#define SPI_CTL_SIZE_MASK 0x00060000
  2741. +
  2742. +#define SPI_CTL_CLK_SEL_MASK 0x03000000
  2743. +#define SPI_OPCODE_MASK 0x000000ff
  2744. +
  2745. +/*
  2746. + * PCI Bus Interface Registers
  2747. + */
  2748. +#define AR2315_PCI_1MS_REG (AR2315_PCI + 0x0008)
  2749. +#define AR2315_PCI_1MS_MASK 0x3FFFF /* # of AHB clk cycles in 1ms */
  2750. +
  2751. +#define AR2315_PCI_MISC_CONFIG (AR2315_PCI + 0x000c)
  2752. +#define AR2315_PCIMISC_TXD_EN 0x00000001 /* Enable TXD for fragments */
  2753. +#define AR2315_PCIMISC_CFG_SEL 0x00000002 /* mem or config cycles */
  2754. +#define AR2315_PCIMISC_GIG_MASK 0x0000000C /* bits 31-30 for pci req */
  2755. +#define AR2315_PCIMISC_RST_MODE 0x00000030
  2756. +#define AR2315_PCIRST_INPUT 0x00000000 /* 4:5=0 rst is input */
  2757. +#define AR2315_PCIRST_LOW 0x00000010 /* 4:5=1 rst to GND */
  2758. +#define AR2315_PCIRST_HIGH 0x00000020 /* 4:5=2 rst to VDD */
  2759. +#define AR2315_PCIGRANT_EN 0x00000000 /* 6:7=0 early grant en */
  2760. +#define AR2315_PCIGRANT_FRAME 0x00000040 /* 6:7=1 grant waits 4 frame */
  2761. +#define AR2315_PCIGRANT_IDLE 0x00000080 /* 6:7=2 grant waits 4 idle */
  2762. +#define AR2315_PCIGRANT_GAP 0x00000000 /* 6:7=2 grant waits 4 idle */
  2763. +#define AR2315_PCICACHE_DIS 0x00001000 /* PCI external access cache disable */
  2764. +
  2765. +#define AR2315_PCI_OUT_TSTAMP (AR2315_PCI + 0x0010)
  2766. +
  2767. +#define AR2315_PCI_UNCACHE_CFG (AR2315_PCI + 0x0014)
  2768. +
  2769. +#define AR2315_PCI_IN_EN (AR2315_PCI + 0x0100)
  2770. +#define AR2315_PCI_IN_EN0 0x01 /* Enable chain 0 */
  2771. +#define AR2315_PCI_IN_EN1 0x02 /* Enable chain 1 */
  2772. +#define AR2315_PCI_IN_EN2 0x04 /* Enable chain 2 */
  2773. +#define AR2315_PCI_IN_EN3 0x08 /* Enable chain 3 */
  2774. +
  2775. +#define AR2315_PCI_IN_DIS (AR2315_PCI + 0x0104)
  2776. +#define AR2315_PCI_IN_DIS0 0x01 /* Disable chain 0 */
  2777. +#define AR2315_PCI_IN_DIS1 0x02 /* Disable chain 1 */
  2778. +#define AR2315_PCI_IN_DIS2 0x04 /* Disable chain 2 */
  2779. +#define AR2315_PCI_IN_DIS3 0x08 /* Disable chain 3 */
  2780. +
  2781. +#define AR2315_PCI_IN_PTR (AR2315_PCI + 0x0200)
  2782. +
  2783. +#define AR2315_PCI_OUT_EN (AR2315_PCI + 0x0400)
  2784. +#define AR2315_PCI_OUT_EN0 0x01 /* Enable chain 0 */
  2785. +
  2786. +#define AR2315_PCI_OUT_DIS (AR2315_PCI + 0x0404)
  2787. +#define AR2315_PCI_OUT_DIS0 0x01 /* Disable chain 0 */
  2788. +
  2789. +#define AR2315_PCI_OUT_PTR (AR2315_PCI + 0x0408)
  2790. +
  2791. +#define AR2315_PCI_INT_STATUS (AR2315_PCI + 0x0500) /* write one to clr */
  2792. +#define AR2315_PCI_TXINT 0x00000001 /* Desc In Completed */
  2793. +#define AR2315_PCI_TXOK 0x00000002 /* Desc In OK */
  2794. +#define AR2315_PCI_TXERR 0x00000004 /* Desc In ERR */
  2795. +#define AR2315_PCI_TXEOL 0x00000008 /* Desc In End-of-List */
  2796. +#define AR2315_PCI_RXINT 0x00000010 /* Desc Out Completed */
  2797. +#define AR2315_PCI_RXOK 0x00000020 /* Desc Out OK */
  2798. +#define AR2315_PCI_RXERR 0x00000040 /* Desc Out ERR */
  2799. +#define AR2315_PCI_RXEOL 0x00000080 /* Desc Out EOL */
  2800. +#define AR2315_PCI_TXOOD 0x00000200 /* Desc In Out-of-Desc */
  2801. +#define AR2315_PCI_MASK 0x0000FFFF /* Desc Mask */
  2802. +#define AR2315_PCI_EXT_INT 0x02000000
  2803. +#define AR2315_PCI_ABORT_INT 0x04000000
  2804. +
  2805. +#define AR2315_PCI_INT_MASK (AR2315_PCI + 0x0504) /* same as INT_STATUS */
  2806. +
  2807. +#define AR2315_PCI_INTEN_REG (AR2315_PCI + 0x0508)
  2808. +#define AR2315_PCI_INT_DISABLE 0x00 /* disable pci interrupts */
  2809. +#define AR2315_PCI_INT_ENABLE 0x01 /* enable pci interrupts */
  2810. +
  2811. +#define AR2315_PCI_HOST_IN_EN (AR2315_PCI + 0x0800)
  2812. +#define AR2315_PCI_HOST_IN_DIS (AR2315_PCI + 0x0804)
  2813. +#define AR2315_PCI_HOST_IN_PTR (AR2315_PCI + 0x0810)
  2814. +#define AR2315_PCI_HOST_OUT_EN (AR2315_PCI + 0x0900)
  2815. +#define AR2315_PCI_HOST_OUT_DIS (AR2315_PCI + 0x0904)
  2816. +#define AR2315_PCI_HOST_OUT_PTR (AR2315_PCI + 0x0908)
  2817. +
  2818. +
  2819. +/*
  2820. + * Local Bus Interface Registers
  2821. + */
  2822. +#define AR2315_LB_CONFIG (AR2315_LOCAL + 0x0000)
  2823. +#define AR2315_LBCONF_OE 0x00000001 /* =1 OE is low-true */
  2824. +#define AR2315_LBCONF_CS0 0x00000002 /* =1 first CS is low-true */
  2825. +#define AR2315_LBCONF_CS1 0x00000004 /* =1 2nd CS is low-true */
  2826. +#define AR2315_LBCONF_RDY 0x00000008 /* =1 RDY is low-true */
  2827. +#define AR2315_LBCONF_WE 0x00000010 /* =1 Write En is low-true */
  2828. +#define AR2315_LBCONF_WAIT 0x00000020 /* =1 WAIT is low-true */
  2829. +#define AR2315_LBCONF_ADS 0x00000040 /* =1 Adr Strobe is low-true */
  2830. +#define AR2315_LBCONF_MOT 0x00000080 /* =0 Intel, =1 Motorola */
  2831. +#define AR2315_LBCONF_8CS 0x00000100 /* =1 8 bits CS, 0= 16bits */
  2832. +#define AR2315_LBCONF_8DS 0x00000200 /* =1 8 bits Data S, 0=16bits */
  2833. +#define AR2315_LBCONF_ADS_EN 0x00000400 /* =1 Enable ADS */
  2834. +#define AR2315_LBCONF_ADR_OE 0x00000800 /* =1 Adr cap on OE, WE or DS */
  2835. +#define AR2315_LBCONF_ADDT_MUX 0x00001000 /* =1 Adr and Data share bus */
  2836. +#define AR2315_LBCONF_DATA_OE 0x00002000 /* =1 Data cap on OE, WE, DS */
  2837. +#define AR2315_LBCONF_16DATA 0x00004000 /* =1 Data is 16 bits wide */
  2838. +#define AR2315_LBCONF_SWAPDT 0x00008000 /* =1 Byte swap data */
  2839. +#define AR2315_LBCONF_SYNC 0x00010000 /* =1 Bus synchronous to clk */
  2840. +#define AR2315_LBCONF_INT 0x00020000 /* =1 Intr is low true */
  2841. +#define AR2315_LBCONF_INT_CTR0 0x00000000 /* GND high-Z, Vdd is high-Z */
  2842. +#define AR2315_LBCONF_INT_CTR1 0x00040000 /* GND drive, Vdd is high-Z */
  2843. +#define AR2315_LBCONF_INT_CTR2 0x00080000 /* GND high-Z, Vdd drive */
  2844. +#define AR2315_LBCONF_INT_CTR3 0x000C0000 /* GND drive, Vdd drive */
  2845. +#define AR2315_LBCONF_RDY_WAIT 0x00100000 /* =1 RDY is negative of WAIT */
  2846. +#define AR2315_LBCONF_INT_PULSE 0x00200000 /* =1 Interrupt is a pulse */
  2847. +#define AR2315_LBCONF_ENABLE 0x00400000 /* =1 Falcon respond to LB */
  2848. +
  2849. +#define AR2315_LB_CLKSEL (AR2315_LOCAL + 0x0004)
  2850. +#define AR2315_LBCLK_EXT 0x0001 /* use external clk for lb */
  2851. +
  2852. +#define AR2315_LB_1MS (AR2315_LOCAL + 0x0008)
  2853. +#define AR2315_LB1MS_MASK 0x3FFFF /* # of AHB clk cycles in 1ms */
  2854. +
  2855. +#define AR2315_LB_MISCCFG (AR2315_LOCAL + 0x000C)
  2856. +#define AR2315_LBM_TXD_EN 0x00000001 /* Enable TXD for fragments */
  2857. +#define AR2315_LBM_RX_INTEN 0x00000002 /* Enable LB ints on RX ready */
  2858. +#define AR2315_LBM_MBOXWR_INTEN 0x00000004 /* Enable LB ints on mbox wr */
  2859. +#define AR2315_LBM_MBOXRD_INTEN 0x00000008 /* Enable LB ints on mbox rd */
  2860. +#define AR2315_LMB_DESCSWAP_EN 0x00000010 /* Byte swap desc enable */
  2861. +#define AR2315_LBM_TIMEOUT_MASK 0x00FFFF80
  2862. +#define AR2315_LBM_TIMEOUT_SHFT 7
  2863. +#define AR2315_LBM_PORTMUX 0x07000000
  2864. +
  2865. +
  2866. +#define AR2315_LB_RXTSOFF (AR2315_LOCAL + 0x0010)
  2867. +
  2868. +#define AR2315_LB_TX_CHAIN_EN (AR2315_LOCAL + 0x0100)
  2869. +#define AR2315_LB_TXEN_0 0x01
  2870. +#define AR2315_LB_TXEN_1 0x02
  2871. +#define AR2315_LB_TXEN_2 0x04
  2872. +#define AR2315_LB_TXEN_3 0x08
  2873. +
  2874. +#define AR2315_LB_TX_CHAIN_DIS (AR2315_LOCAL + 0x0104)
  2875. +#define AR2315_LB_TX_DESC_PTR (AR2315_LOCAL + 0x0200)
  2876. +
  2877. +#define AR2315_LB_RX_CHAIN_EN (AR2315_LOCAL + 0x0400)
  2878. +#define AR2315_LB_RXEN 0x01
  2879. +
  2880. +#define AR2315_LB_RX_CHAIN_DIS (AR2315_LOCAL + 0x0404)
  2881. +#define AR2315_LB_RX_DESC_PTR (AR2315_LOCAL + 0x0408)
  2882. +
  2883. +#define AR2315_LB_INT_STATUS (AR2315_LOCAL + 0x0500)
  2884. +#define AR2315_INT_TX_DESC 0x0001
  2885. +#define AR2315_INT_TX_OK 0x0002
  2886. +#define AR2315_INT_TX_ERR 0x0004
  2887. +#define AR2315_INT_TX_EOF 0x0008
  2888. +#define AR2315_INT_RX_DESC 0x0010
  2889. +#define AR2315_INT_RX_OK 0x0020
  2890. +#define AR2315_INT_RX_ERR 0x0040
  2891. +#define AR2315_INT_RX_EOF 0x0080
  2892. +#define AR2315_INT_TX_TRUNC 0x0100
  2893. +#define AR2315_INT_TX_STARVE 0x0200
  2894. +#define AR2315_INT_LB_TIMEOUT 0x0400
  2895. +#define AR2315_INT_LB_ERR 0x0800
  2896. +#define AR2315_INT_MBOX_WR 0x1000
  2897. +#define AR2315_INT_MBOX_RD 0x2000
  2898. +
  2899. +/* Bit definitions for INT MASK are the same as INT_STATUS */
  2900. +#define AR2315_LB_INT_MASK (AR2315_LOCAL + 0x0504)
  2901. +
  2902. +#define AR2315_LB_INT_EN (AR2315_LOCAL + 0x0508)
  2903. +#define AR2315_LB_MBOX (AR2315_LOCAL + 0x0600)
  2904. +
  2905. +/*
  2906. + * IR Interface Registers
  2907. + */
  2908. +#define AR2315_IR_PKTDATA (AR2315_IR + 0x0000)
  2909. +
  2910. +#define AR2315_IR_PKTLEN (AR2315_IR + 0x07fc) /* 0 - 63 */
  2911. +
  2912. +#define AR2315_IR_CONTROL (AR2315_IR + 0x0800)
  2913. +#define AR2315_IRCTL_TX 0x00000000 /* use as tranmitter */
  2914. +#define AR2315_IRCTL_RX 0x00000001 /* use as receiver */
  2915. +#define AR2315_IRCTL_SAMPLECLK_MASK 0x00003ffe /* Sample clk divisor mask */
  2916. +#define AR2315_IRCTL_SAMPLECLK_SHFT 1
  2917. +#define AR2315_IRCTL_OUTPUTCLK_MASK 0x03ffc000 /* Output clk divisor mask */
  2918. +#define AR2315_IRCTL_OUTPUTCLK_SHFT 14
  2919. +
  2920. +#define AR2315_IR_STATUS (AR2315_IR + 0x0804)
  2921. +#define AR2315_IRSTS_RX 0x00000001 /* receive in progress */
  2922. +#define AR2315_IRSTS_TX 0x00000002 /* transmit in progress */
  2923. +
  2924. +#define AR2315_IR_CONFIG (AR2315_IR + 0x0808)
  2925. +#define AR2315_IRCFG_INVIN 0x00000001 /* invert input polarity */
  2926. +#define AR2315_IRCFG_INVOUT 0x00000002 /* invert output polarity */
  2927. +#define AR2315_IRCFG_SEQ_START_WIN_SEL 0x00000004 /* 1 => 28, 0 => 7 */
  2928. +#define AR2315_IRCFG_SEQ_START_THRESH 0x000000f0 /* */
  2929. +#define AR2315_IRCFG_SEQ_END_UNIT_SEL 0x00000100 /* */
  2930. +#define AR2315_IRCFG_SEQ_END_UNIT_THRESH 0x00007e00 /* */
  2931. +#define AR2315_IRCFG_SEQ_END_WIN_SEL 0x00008000 /* */
  2932. +#define AR2315_IRCFG_SEQ_END_WIN_THRESH 0x001f0000 /* */
  2933. +#define AR2315_IRCFG_NUM_BACKOFF_WORDS 0x01e00000 /* */
  2934. +
  2935. +#define HOST_PCI_DEV_ID 3
  2936. +#define HOST_PCI_MBAR0 0x10000000
  2937. +#define HOST_PCI_MBAR1 0x20000000
  2938. +#define HOST_PCI_MBAR2 0x30000000
  2939. +
  2940. +#define HOST_PCI_SDRAM_BASEADDR HOST_PCI_MBAR1
  2941. +#define PCI_DEVICE_MEM_SPACE 0x800000
  2942. +
  2943. +#endif /* __AR2315_REG_H */
  2944. diff -Nur linux-2.6.39-rc7.orig/arch/mips/include/asm/mach-ar231x/ar2315_spiflash.h linux-2.6.39-rc7/arch/mips/include/asm/mach-ar231x/ar2315_spiflash.h
  2945. --- linux-2.6.39-rc7.orig/arch/mips/include/asm/mach-ar231x/ar2315_spiflash.h 1970-01-01 01:00:00.000000000 +0100
  2946. +++ linux-2.6.39-rc7/arch/mips/include/asm/mach-ar231x/ar2315_spiflash.h 2011-05-15 21:34:57.000000000 +0200
  2947. @@ -0,0 +1,116 @@
  2948. +/*
  2949. + * SPI Flash Memory support header file.
  2950. + *
  2951. + * Copyright (c) 2005, Atheros Communications Inc.
  2952. + * Copyright (C) 2006 FON Technology, SL.
  2953. + * Copyright (C) 2006 Imre Kaloz <kaloz@openwrt.org>
  2954. + * Copyright (C) 2006-2009 Felix Fietkau <nbd@openwrt.org>
  2955. + *
  2956. + * This code is free software; you can redistribute it and/or modify
  2957. + * it under the terms of the GNU General Public License version 2 as
  2958. + * published by the Free Software Foundation.
  2959. + *
  2960. + */
  2961. +#ifndef __AR2315_SPIFLASH_H
  2962. +#define __AR2315_SPIFLASH_H
  2963. +
  2964. +#define STM_PAGE_SIZE 256
  2965. +
  2966. +#define SFI_WRITE_BUFFER_SIZE 4
  2967. +#define SFI_FLASH_ADDR_MASK 0x00ffffff
  2968. +
  2969. +#define STM_8MBIT_SIGNATURE 0x13
  2970. +#define STM_M25P80_BYTE_COUNT 1048576
  2971. +#define STM_M25P80_SECTOR_COUNT 16
  2972. +#define STM_M25P80_SECTOR_SIZE 0x10000
  2973. +
  2974. +#define STM_16MBIT_SIGNATURE 0x14
  2975. +#define STM_M25P16_BYTE_COUNT 2097152
  2976. +#define STM_M25P16_SECTOR_COUNT 32
  2977. +#define STM_M25P16_SECTOR_SIZE 0x10000
  2978. +
  2979. +#define STM_32MBIT_SIGNATURE 0x15
  2980. +#define STM_M25P32_BYTE_COUNT 4194304
  2981. +#define STM_M25P32_SECTOR_COUNT 64
  2982. +#define STM_M25P32_SECTOR_SIZE 0x10000
  2983. +
  2984. +#define STM_64MBIT_SIGNATURE 0x16
  2985. +#define STM_M25P64_BYTE_COUNT 8388608
  2986. +#define STM_M25P64_SECTOR_COUNT 128
  2987. +#define STM_M25P64_SECTOR_SIZE 0x10000
  2988. +
  2989. +#define STM_128MBIT_SIGNATURE 0x17
  2990. +#define STM_M25P128_BYTE_COUNT 16777216
  2991. +#define STM_M25P128_SECTOR_COUNT 256
  2992. +#define STM_M25P128_SECTOR_SIZE 0x10000
  2993. +
  2994. +#define STM_1MB_BYTE_COUNT STM_M25P80_BYTE_COUNT
  2995. +#define STM_1MB_SECTOR_COUNT STM_M25P80_SECTOR_COUNT
  2996. +#define STM_1MB_SECTOR_SIZE STM_M25P80_SECTOR_SIZE
  2997. +#define STM_2MB_BYTE_COUNT STM_M25P16_BYTE_COUNT
  2998. +#define STM_2MB_SECTOR_COUNT STM_M25P16_SECTOR_COUNT
  2999. +#define STM_2MB_SECTOR_SIZE STM_M25P16_SECTOR_SIZE
  3000. +#define STM_4MB_BYTE_COUNT STM_M25P32_BYTE_COUNT
  3001. +#define STM_4MB_SECTOR_COUNT STM_M25P32_SECTOR_COUNT
  3002. +#define STM_4MB_SECTOR_SIZE STM_M25P32_SECTOR_SIZE
  3003. +#define STM_8MB_BYTE_COUNT STM_M25P64_BYTE_COUNT
  3004. +#define STM_8MB_SECTOR_COUNT STM_M25P64_SECTOR_COUNT
  3005. +#define STM_8MB_SECTOR_SIZE STM_M25P64_SECTOR_SIZE
  3006. +#define STM_16MB_BYTE_COUNT STM_M25P128_BYTE_COUNT
  3007. +#define STM_16MB_SECTOR_COUNT STM_M25P128_SECTOR_COUNT
  3008. +#define STM_16MB_SECTOR_SIZE STM_M25P128_SECTOR_SIZE
  3009. +
  3010. +/*
  3011. + * ST Microelectronics Opcodes for Serial Flash
  3012. + */
  3013. +
  3014. +#define STM_OP_WR_ENABLE 0x06 /* Write Enable */
  3015. +#define STM_OP_WR_DISABLE 0x04 /* Write Disable */
  3016. +#define STM_OP_RD_STATUS 0x05 /* Read Status */
  3017. +#define STM_OP_WR_STATUS 0x01 /* Write Status */
  3018. +#define STM_OP_RD_DATA 0x03 /* Read Data */
  3019. +#define STM_OP_FAST_RD_DATA 0x0b /* Fast Read Data */
  3020. +#define STM_OP_PAGE_PGRM 0x02 /* Page Program */
  3021. +#define STM_OP_SECTOR_ERASE 0xd8 /* Sector Erase */
  3022. +#define STM_OP_BULK_ERASE 0xc7 /* Bulk Erase */
  3023. +#define STM_OP_DEEP_PWRDOWN 0xb9 /* Deep Power-Down Mode */
  3024. +#define STM_OP_RD_SIG 0xab /* Read Electronic Signature */
  3025. +
  3026. +#define STM_STATUS_WIP 0x01 /* Write-In-Progress */
  3027. +#define STM_STATUS_WEL 0x02 /* Write Enable Latch */
  3028. +#define STM_STATUS_BP0 0x04 /* Block Protect 0 */
  3029. +#define STM_STATUS_BP1 0x08 /* Block Protect 1 */
  3030. +#define STM_STATUS_BP2 0x10 /* Block Protect 2 */
  3031. +#define STM_STATUS_SRWD 0x80 /* Status Register Write Disable */
  3032. +
  3033. +/*
  3034. + * SPI Flash Interface Registers
  3035. + */
  3036. +#define AR531XPLUS_SPI_READ 0x08000000
  3037. +#define AR531XPLUS_SPI_MMR 0x11300000
  3038. +#define AR531XPLUS_SPI_MMR_SIZE 12
  3039. +
  3040. +#define AR531XPLUS_SPI_CTL 0x00
  3041. +#define AR531XPLUS_SPI_OPCODE 0x04
  3042. +#define AR531XPLUS_SPI_DATA 0x08
  3043. +
  3044. +#define SPI_FLASH_READ AR531XPLUS_SPI_READ
  3045. +#define SPI_FLASH_MMR AR531XPLUS_SPI_MMR
  3046. +#define SPI_FLASH_MMR_SIZE AR531XPLUS_SPI_MMR_SIZE
  3047. +#define SPI_FLASH_CTL AR531XPLUS_SPI_CTL
  3048. +#define SPI_FLASH_OPCODE AR531XPLUS_SPI_OPCODE
  3049. +#define SPI_FLASH_DATA AR531XPLUS_SPI_DATA
  3050. +
  3051. +#define SPI_CTL_START 0x00000100
  3052. +#define SPI_CTL_BUSY 0x00010000
  3053. +#define SPI_CTL_TXCNT_MASK 0x0000000f
  3054. +#define SPI_CTL_RXCNT_MASK 0x000000f0
  3055. +#define SPI_CTL_TX_RX_CNT_MASK 0x000000ff
  3056. +#define SPI_CTL_SIZE_MASK 0x00060000
  3057. +
  3058. +#define SPI_CTL_CLK_SEL_MASK 0x03000000
  3059. +#define SPI_OPCODE_MASK 0x000000ff
  3060. +
  3061. +#define SPI_STATUS_WIP STM_STATUS_WIP
  3062. +
  3063. +#endif
  3064. diff -Nur linux-2.6.39-rc7.orig/arch/mips/include/asm/mach-ar231x/ar231x.h linux-2.6.39-rc7/arch/mips/include/asm/mach-ar231x/ar231x.h
  3065. --- linux-2.6.39-rc7.orig/arch/mips/include/asm/mach-ar231x/ar231x.h 1970-01-01 01:00:00.000000000 +0100
  3066. +++ linux-2.6.39-rc7/arch/mips/include/asm/mach-ar231x/ar231x.h 2011-05-15 21:34:57.000000000 +0200
  3067. @@ -0,0 +1,54 @@
  3068. +#ifndef __AR531X_H
  3069. +#define __AR531X_H
  3070. +
  3071. +#define AR531X_MISC_IRQ_BASE 0x20
  3072. +#define AR531X_GPIO_IRQ_BASE 0x30
  3073. +
  3074. +/* Software's idea of interrupts handled by "CPU Interrupt Controller" */
  3075. +#define AR531X_IRQ_NONE MIPS_CPU_IRQ_BASE+0
  3076. +#define AR531X_IRQ_CPU_CLOCK MIPS_CPU_IRQ_BASE+7 /* C0_CAUSE: 0x8000 */
  3077. +
  3078. +/* Miscellaneous interrupts, which share IP6 */
  3079. +#define AR531X_MISC_IRQ_NONE AR531X_MISC_IRQ_BASE+0
  3080. +#define AR531X_MISC_IRQ_TIMER AR531X_MISC_IRQ_BASE+1
  3081. +#define AR531X_MISC_IRQ_AHB_PROC AR531X_MISC_IRQ_BASE+2
  3082. +#define AR531X_MISC_IRQ_AHB_DMA AR531X_MISC_IRQ_BASE+3
  3083. +#define AR531X_MISC_IRQ_GPIO AR531X_MISC_IRQ_BASE+4
  3084. +#define AR531X_MISC_IRQ_UART0 AR531X_MISC_IRQ_BASE+5
  3085. +#define AR531X_MISC_IRQ_UART0_DMA AR531X_MISC_IRQ_BASE+6
  3086. +#define AR531X_MISC_IRQ_WATCHDOG AR531X_MISC_IRQ_BASE+7
  3087. +#define AR531X_MISC_IRQ_LOCAL AR531X_MISC_IRQ_BASE+8
  3088. +#define AR531X_MISC_IRQ_SPI AR531X_MISC_IRQ_BASE+9
  3089. +#define AR531X_MISC_IRQ_COUNT 10
  3090. +
  3091. +/* GPIO Interrupts [0..7], share AR531X_MISC_IRQ_GPIO */
  3092. +#define AR531X_GPIO_IRQ_NONE AR531X_GPIO_IRQ_BASE+0
  3093. +#define AR531X_GPIO_IRQ(n) AR531X_GPIO_IRQ_BASE+n
  3094. +#define AR531X_GPIO_IRQ_COUNT 22
  3095. +
  3096. +static inline u32
  3097. +ar231x_read_reg(u32 reg)
  3098. +{
  3099. + return __raw_readl((u32 *) KSEG1ADDR(reg));
  3100. +}
  3101. +
  3102. +static inline void
  3103. +ar231x_write_reg(u32 reg, u32 val)
  3104. +{
  3105. + __raw_writel(val, (u32 *) KSEG1ADDR(reg));
  3106. +}
  3107. +
  3108. +static inline u32
  3109. +ar231x_mask_reg(u32 reg, u32 mask, u32 val)
  3110. +{
  3111. + u32 ret;
  3112. +
  3113. + ret = ar231x_read_reg(reg);
  3114. + ret &= ~mask;
  3115. + ret |= val;
  3116. + ar231x_write_reg(reg, ret);
  3117. +
  3118. + return ret;
  3119. +}
  3120. +
  3121. +#endif
  3122. diff -Nur linux-2.6.39-rc7.orig/arch/mips/include/asm/mach-ar231x/ar231x_platform.h linux-2.6.39-rc7/arch/mips/include/asm/mach-ar231x/ar231x_platform.h
  3123. --- linux-2.6.39-rc7.orig/arch/mips/include/asm/mach-ar231x/ar231x_platform.h 1970-01-01 01:00:00.000000000 +0100
  3124. +++ linux-2.6.39-rc7/arch/mips/include/asm/mach-ar231x/ar231x_platform.h 2011-05-15 21:34:57.000000000 +0200
  3125. @@ -0,0 +1,83 @@
  3126. +#ifndef __AR531X_PLATFORM_H
  3127. +#define __AR531X_PLATFORM_H
  3128. +
  3129. +/*
  3130. + * This is board-specific data that is stored in a "fixed" location in flash.
  3131. + * It is shared across operating systems, so it should not be changed lightly.
  3132. + * The main reason we need it is in order to extract the ethernet MAC
  3133. + * address(es).
  3134. + */
  3135. +struct ar231x_boarddata {
  3136. + u32 magic; /* board data is valid */
  3137. +#define AR531X_BD_MAGIC 0x35333131 /* "5311", for all 531x platforms */
  3138. + u16 cksum; /* checksum (starting with BD_REV 2) */
  3139. + u16 rev; /* revision of this struct */
  3140. +#define BD_REV 4
  3141. + char boardName[64]; /* Name of board */
  3142. + u16 major; /* Board major number */
  3143. + u16 minor; /* Board minor number */
  3144. + u32 flags; /* Board configuration */
  3145. +#define BD_ENET0 0x00000001 /* ENET0 is stuffed */
  3146. +#define BD_ENET1 0x00000002 /* ENET1 is stuffed */
  3147. +#define BD_UART1 0x00000004 /* UART1 is stuffed */
  3148. +#define BD_UART0 0x00000008 /* UART0 is stuffed (dma) */
  3149. +#define BD_RSTFACTORY 0x00000010 /* Reset factory defaults stuffed */
  3150. +#define BD_SYSLED 0x00000020 /* System LED stuffed */
  3151. +#define BD_EXTUARTCLK 0x00000040 /* External UART clock */
  3152. +#define BD_CPUFREQ 0x00000080 /* cpu freq is valid in nvram */
  3153. +#define BD_SYSFREQ 0x00000100 /* sys freq is set in nvram */
  3154. +#define BD_WLAN0 0x00000200 /* Enable WLAN0 */
  3155. +#define BD_MEMCAP 0x00000400 /* CAP SDRAM @ memCap for testing */
  3156. +#define BD_DISWATCHDOG 0x00000800 /* disable system watchdog */
  3157. +#define BD_WLAN1 0x00001000 /* Enable WLAN1 (ar5212) */
  3158. +#define BD_ISCASPER 0x00002000 /* FLAG for AR2312 */
  3159. +#define BD_WLAN0_2G_EN 0x00004000 /* FLAG for radio0_2G */
  3160. +#define BD_WLAN0_5G_EN 0x00008000 /* FLAG for radio0_2G */
  3161. +#define BD_WLAN1_2G_EN 0x00020000 /* FLAG for radio0_2G */
  3162. +#define BD_WLAN1_5G_EN 0x00040000 /* FLAG for radio0_2G */
  3163. + u16 resetConfigGpio; /* Reset factory GPIO pin */
  3164. + u16 sysLedGpio; /* System LED GPIO pin */
  3165. +
  3166. + u32 cpuFreq; /* CPU core frequency in Hz */
  3167. + u32 sysFreq; /* System frequency in Hz */
  3168. + u32 cntFreq; /* Calculated C0_COUNT frequency */
  3169. +
  3170. + u8 wlan0_mac[6];
  3171. + u8 enet0_mac[6];
  3172. + u8 enet1_mac[6];
  3173. +
  3174. + u16 pciId; /* Pseudo PCIID for common code */
  3175. + u16 memCap; /* cap bank1 in MB */
  3176. +
  3177. + /* version 3 */
  3178. + u8 wlan1_mac[6]; /* (ar5212) */
  3179. +};
  3180. +
  3181. +#define BOARD_CONFIG_BUFSZ 0x1000
  3182. +
  3183. +/*
  3184. + * Platform device information for the Wireless MAC
  3185. + */
  3186. +struct ar231x_board_config {
  3187. + u16 devid;
  3188. +
  3189. + /* board config data */
  3190. + struct ar231x_boarddata *config;
  3191. +
  3192. + /* radio calibration data */
  3193. + const char *radio;
  3194. +};
  3195. +
  3196. +/*
  3197. + * Platform device information for the Ethernet MAC
  3198. + */
  3199. +struct ar231x_eth {
  3200. + u32 reset_base;
  3201. + u32 reset_mac;
  3202. + u32 reset_phy;
  3203. + u32 phy_base;
  3204. + struct ar231x_board_config *config;
  3205. + char *macaddr;
  3206. +};
  3207. +
  3208. +#endif /* __AR531X_PLATFORM_H */
  3209. diff -Nur linux-2.6.39-rc7.orig/arch/mips/include/asm/mach-ar231x/ar5312_regs.h linux-2.6.39-rc7/arch/mips/include/asm/mach-ar231x/ar5312_regs.h
  3210. --- linux-2.6.39-rc7.orig/arch/mips/include/asm/mach-ar231x/ar5312_regs.h 1970-01-01 01:00:00.000000000 +0100
  3211. +++ linux-2.6.39-rc7/arch/mips/include/asm/mach-ar231x/ar5312_regs.h 2011-05-15 21:34:57.000000000 +0200
  3212. @@ -0,0 +1,236 @@
  3213. +/*
  3214. + * This file is subject to the terms and conditions of the GNU General Public
  3215. + * License. See the file "COPYING" in the main directory of this archive
  3216. + * for more details.
  3217. + *
  3218. + * Copyright (C) 2003 Atheros Communications, Inc., All Rights Reserved.
  3219. + * Copyright (C) 2006 Imre Kaloz <kaloz@openwrt.org>
  3220. + * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
  3221. + */
  3222. +
  3223. +#ifndef AR5312_H
  3224. +#define AR5312_H
  3225. +
  3226. +#include <asm/addrspace.h>
  3227. +
  3228. +/*
  3229. + * IRQs
  3230. + */
  3231. +
  3232. +#define AR5312_IRQ_WLAN0_INTRS MIPS_CPU_IRQ_BASE+2 /* C0_CAUSE: 0x0400 */
  3233. +#define AR5312_IRQ_ENET0_INTRS MIPS_CPU_IRQ_BASE+3 /* C0_CAUSE: 0x0800 */
  3234. +#define AR5312_IRQ_ENET1_INTRS MIPS_CPU_IRQ_BASE+4 /* C0_CAUSE: 0x1000 */
  3235. +#define AR5312_IRQ_WLAN1_INTRS MIPS_CPU_IRQ_BASE+5 /* C0_CAUSE: 0x2000 */
  3236. +#define AR5312_IRQ_MISC_INTRS MIPS_CPU_IRQ_BASE+6 /* C0_CAUSE: 0x4000 */
  3237. +
  3238. +
  3239. +/* Address Map */
  3240. +#define AR531X_WLAN0 0x18000000
  3241. +#define AR531X_WLAN1 0x18500000
  3242. +#define AR531X_ENET0 0x18100000
  3243. +#define AR531X_ENET1 0x18200000
  3244. +#define AR531X_SDRAMCTL 0x18300000
  3245. +#define AR531X_FLASHCTL 0x18400000
  3246. +#define AR531X_APBBASE 0x1c000000
  3247. +#define AR531X_FLASH 0x1e000000
  3248. +#define AR531X_UART0 0xbc000003 /* UART MMR */
  3249. +
  3250. +/*
  3251. + * AR531X_NUM_ENET_MAC defines the number of ethernet MACs that
  3252. + * should be considered available. The AR5312 supports 2 enet MACS,
  3253. + * even though many reference boards only actually use 1 of them
  3254. + * (i.e. Only MAC 0 is actually connected to an enet PHY or PHY switch.
  3255. + * The AR2312 supports 1 enet MAC.
  3256. + */
  3257. +#define AR531X_NUM_ENET_MAC 2
  3258. +
  3259. +/*
  3260. + * Need these defines to determine true number of ethernet MACs
  3261. + */
  3262. +#define AR5212_AR5312_REV2 0x0052 /* AR5312 WMAC (AP31) */
  3263. +#define AR5212_AR5312_REV7 0x0057 /* AR5312 WMAC (AP30-040) */
  3264. +#define AR5212_AR2313_REV8 0x0058 /* AR2313 WMAC (AP43-030) */
  3265. +#define AR531X_RADIO_MASK_OFF 0xc8
  3266. +#define AR531X_RADIO0_MASK 0x0003
  3267. +#define AR531X_RADIO1_MASK 0x000c
  3268. +#define AR531X_RADIO1_S 2
  3269. +
  3270. +/*
  3271. + * AR531X_NUM_WMAC defines the number of Wireless MACs that\
  3272. + * should be considered available.
  3273. + */
  3274. +#define AR531X_NUM_WMAC 2
  3275. +
  3276. +/* Reset/Timer Block Address Map */
  3277. +#define AR531X_RESETTMR (AR531X_APBBASE + 0x3000)
  3278. +#define AR531X_TIMER (AR531X_RESETTMR + 0x0000) /* countdown timer */
  3279. +#define AR531X_WD_CTRL (AR531X_RESETTMR + 0x0008) /* watchdog cntrl */
  3280. +#define AR531X_WD_TIMER (AR531X_RESETTMR + 0x000c) /* watchdog timer */
  3281. +#define AR531X_ISR (AR531X_RESETTMR + 0x0010) /* Intr Status Reg */
  3282. +#define AR531X_IMR (AR531X_RESETTMR + 0x0014) /* Intr Mask Reg */
  3283. +#define AR531X_RESET (AR531X_RESETTMR + 0x0020)
  3284. +#define AR5312_CLOCKCTL1 (AR531X_RESETTMR + 0x0064)
  3285. +#define AR5312_SCRATCH (AR531X_RESETTMR + 0x006c)
  3286. +#define AR531X_PROCADDR (AR531X_RESETTMR + 0x0070)
  3287. +#define AR531X_PROC1 (AR531X_RESETTMR + 0x0074)
  3288. +#define AR531X_DMAADDR (AR531X_RESETTMR + 0x0078)
  3289. +#define AR531X_DMA1 (AR531X_RESETTMR + 0x007c)
  3290. +#define AR531X_ENABLE (AR531X_RESETTMR + 0x0080) /* interface enb */
  3291. +#define AR531X_REV (AR531X_RESETTMR + 0x0090) /* revision */
  3292. +
  3293. +/* AR531X_WD_CTRL register bit field definitions */
  3294. +#define AR531X_WD_CTRL_IGNORE_EXPIRATION 0x0000
  3295. +#define AR531X_WD_CTRL_NMI 0x0001
  3296. +#define AR531X_WD_CTRL_RESET 0x0002
  3297. +
  3298. +/* AR531X_ISR register bit field definitions */
  3299. +#define AR531X_ISR_NONE 0x0000
  3300. +#define AR531X_ISR_TIMER 0x0001
  3301. +#define AR531X_ISR_AHBPROC 0x0002
  3302. +#define AR531X_ISR_AHBDMA 0x0004
  3303. +#define AR531X_ISR_GPIO 0x0008
  3304. +#define AR531X_ISR_UART0 0x0010
  3305. +#define AR531X_ISR_UART0DMA 0x0020
  3306. +#define AR531X_ISR_WD 0x0040
  3307. +#define AR531X_ISR_LOCAL 0x0080
  3308. +
  3309. +/* AR531X_RESET register bit field definitions */
  3310. +#define AR531X_RESET_SYSTEM 0x00000001 /* cold reset full system */
  3311. +#define AR531X_RESET_PROC 0x00000002 /* cold reset MIPS core */
  3312. +#define AR531X_RESET_WLAN0 0x00000004 /* cold reset WLAN MAC and BB */
  3313. +#define AR531X_RESET_EPHY0 0x00000008 /* cold reset ENET0 phy */
  3314. +#define AR531X_RESET_EPHY1 0x00000010 /* cold reset ENET1 phy */
  3315. +#define AR531X_RESET_ENET0 0x00000020 /* cold reset ENET0 mac */
  3316. +#define AR531X_RESET_ENET1 0x00000040 /* cold reset ENET1 mac */
  3317. +#define AR531X_RESET_UART0 0x00000100 /* cold reset UART0 (high speed) */
  3318. +#define AR531X_RESET_WLAN1 0x00000200 /* cold reset WLAN MAC/BB */
  3319. +#define AR531X_RESET_APB 0x00000400 /* cold reset APB (ar5312) */
  3320. +#define AR531X_RESET_WARM_PROC 0x00001000 /* warm reset MIPS core */
  3321. +#define AR531X_RESET_WARM_WLAN0_MAC 0x00002000 /* warm reset WLAN0 MAC */
  3322. +#define AR531X_RESET_WARM_WLAN0_BB 0x00004000 /* warm reset WLAN0 BaseBand */
  3323. +#define AR531X_RESET_NMI 0x00010000 /* send an NMI to the processor */
  3324. +#define AR531X_RESET_WARM_WLAN1_MAC 0x00020000 /* warm reset WLAN1 mac */
  3325. +#define AR531X_RESET_WARM_WLAN1_BB 0x00040000 /* warm reset WLAN1 baseband */
  3326. +#define AR531X_RESET_LOCAL_BUS 0x00080000 /* reset local bus */
  3327. +#define AR531X_RESET_WDOG 0x00100000 /* last reset was a watchdog */
  3328. +
  3329. +#define AR531X_RESET_WMAC0_BITS \
  3330. + AR531X_RESET_WLAN0 |\
  3331. + AR531X_RESET_WARM_WLAN0_MAC |\
  3332. + AR531X_RESET_WARM_WLAN0_BB
  3333. +
  3334. +#define AR531X_RESERT_WMAC1_BITS \
  3335. + AR531X_RESET_WLAN1 |\
  3336. + AR531X_RESET_WARM_WLAN1_MAC |\
  3337. + AR531X_RESET_WARM_WLAN1_BB
  3338. +
  3339. +/* AR5312_CLOCKCTL1 register bit field definitions */
  3340. +#define AR5312_CLOCKCTL1_PREDIVIDE_MASK 0x00000030
  3341. +#define AR5312_CLOCKCTL1_PREDIVIDE_SHIFT 4
  3342. +#define AR5312_CLOCKCTL1_MULTIPLIER_MASK 0x00001f00
  3343. +#define AR5312_CLOCKCTL1_MULTIPLIER_SHIFT 8
  3344. +#define AR5312_CLOCKCTL1_DOUBLER_MASK 0x00010000
  3345. +
  3346. +/* Valid for AR5312 and AR2312 */
  3347. +#define AR5312_CLOCKCTL1_PREDIVIDE_MASK 0x00000030
  3348. +#define AR5312_CLOCKCTL1_PREDIVIDE_SHIFT 4
  3349. +#define AR5312_CLOCKCTL1_MULTIPLIER_MASK 0x00001f00
  3350. +#define AR5312_CLOCKCTL1_MULTIPLIER_SHIFT 8
  3351. +#define AR5312_CLOCKCTL1_DOUBLER_MASK 0x00010000
  3352. +
  3353. +/* Valid for AR2313 */
  3354. +#define AR2313_CLOCKCTL1_PREDIVIDE_MASK 0x00003000
  3355. +#define AR2313_CLOCKCTL1_PREDIVIDE_SHIFT 12
  3356. +#define AR2313_CLOCKCTL1_MULTIPLIER_MASK 0x001f0000
  3357. +#define AR2313_CLOCKCTL1_MULTIPLIER_SHIFT 16
  3358. +#define AR2313_CLOCKCTL1_DOUBLER_MASK 0x00000000
  3359. +
  3360. +
  3361. +/* AR531X_ENABLE register bit field definitions */
  3362. +#define AR531X_ENABLE_WLAN0 0x0001
  3363. +#define AR531X_ENABLE_ENET0 0x0002
  3364. +#define AR531X_ENABLE_ENET1 0x0004
  3365. +#define AR531X_ENABLE_UART_AND_WLAN1_PIO 0x0008 /* UART, and WLAN1 PIOs */
  3366. +#define AR531X_ENABLE_WLAN1_DMA 0x0010 /* WLAN1 DMAs */
  3367. +#define AR531X_ENABLE_WLAN1 \
  3368. + (AR531X_ENABLE_UART_AND_WLAN1_PIO | AR531X_ENABLE_WLAN1_DMA)
  3369. +
  3370. +/* AR531X_REV register bit field definitions */
  3371. +#define AR531X_REV_WMAC_MAJ 0xf000
  3372. +#define AR531X_REV_WMAC_MAJ_S 12
  3373. +#define AR531X_REV_WMAC_MIN 0x0f00
  3374. +#define AR531X_REV_WMAC_MIN_S 8
  3375. +#define AR531X_REV_MAJ 0x00f0
  3376. +#define AR531X_REV_MAJ_S 4
  3377. +#define AR531X_REV_MIN 0x000f
  3378. +#define AR531X_REV_MIN_S 0
  3379. +#define AR531X_REV_CHIP (AR531X_REV_MAJ|AR531X_REV_MIN)
  3380. +
  3381. +/* Major revision numbers, bits 7..4 of Revision ID register */
  3382. +#define AR531X_REV_MAJ_AR5312 0x4
  3383. +#define AR531X_REV_MAJ_AR2313 0x5
  3384. +
  3385. +/* Minor revision numbers, bits 3..0 of Revision ID register */
  3386. +#define AR5312_REV_MIN_DUAL 0x0 /* Dual WLAN version */
  3387. +#define AR5312_REV_MIN_SINGLE 0x1 /* Single WLAN version */
  3388. +
  3389. +/* AR531X_FLASHCTL register bit field definitions */
  3390. +#define FLASHCTL_IDCY 0x0000000f /* Idle cycle turn around time */
  3391. +#define FLASHCTL_IDCY_S 0
  3392. +#define FLASHCTL_WST1 0x000003e0 /* Wait state 1 */
  3393. +#define FLASHCTL_WST1_S 5
  3394. +#define FLASHCTL_RBLE 0x00000400 /* Read byte lane enable */
  3395. +#define FLASHCTL_WST2 0x0000f800 /* Wait state 2 */
  3396. +#define FLASHCTL_WST2_S 11
  3397. +#define FLASHCTL_AC 0x00070000 /* Flash address check (added) */
  3398. +#define FLASHCTL_AC_S 16
  3399. +#define FLASHCTL_AC_128K 0x00000000
  3400. +#define FLASHCTL_AC_256K 0x00010000
  3401. +#define FLASHCTL_AC_512K 0x00020000
  3402. +#define FLASHCTL_AC_1M 0x00030000
  3403. +#define FLASHCTL_AC_2M 0x00040000
  3404. +#define FLASHCTL_AC_4M 0x00050000
  3405. +#define FLASHCTL_AC_8M 0x00060000
  3406. +#define FLASHCTL_AC_RES 0x00070000 /* 16MB is not supported */
  3407. +#define FLASHCTL_E 0x00080000 /* Flash bank enable (added) */
  3408. +#define FLASHCTL_BUSERR 0x01000000 /* Bus transfer error status flag */
  3409. +#define FLASHCTL_WPERR 0x02000000 /* Write protect error status flag */
  3410. +#define FLASHCTL_WP 0x04000000 /* Write protect */
  3411. +#define FLASHCTL_BM 0x08000000 /* Burst mode */
  3412. +#define FLASHCTL_MW 0x30000000 /* Memory width */
  3413. +#define FLASHCTL_MWx8 0x00000000 /* Memory width x8 */
  3414. +#define FLASHCTL_MWx16 0x10000000 /* Memory width x16 */
  3415. +#define FLASHCTL_MWx32 0x20000000 /* Memory width x32 (not supported) */
  3416. +#define FLASHCTL_ATNR 0x00000000 /* Access type == no retry */
  3417. +#define FLASHCTL_ATR 0x80000000 /* Access type == retry every */
  3418. +#define FLASHCTL_ATR4 0xc0000000 /* Access type == retry every 4 */
  3419. +
  3420. +/* ARM Flash Controller -- 3 flash banks with either x8 or x16 devices. */
  3421. +#define AR531X_FLASHCTL0 (AR531X_FLASHCTL + 0x00)
  3422. +#define AR531X_FLASHCTL1 (AR531X_FLASHCTL + 0x04)
  3423. +#define AR531X_FLASHCTL2 (AR531X_FLASHCTL + 0x08)
  3424. +
  3425. +/* ARM SDRAM Controller -- just enough to determine memory size */
  3426. +#define AR531X_MEM_CFG1 (AR531X_SDRAMCTL + 0x04)
  3427. +#define MEM_CFG1_AC0 0x00000700 /* bank 0: SDRAM addr check (added) */
  3428. +#define MEM_CFG1_AC0_S 8
  3429. +#define MEM_CFG1_AC1 0x00007000 /* bank 1: SDRAM addr check (added) */
  3430. +#define MEM_CFG1_AC1_S 12
  3431. +
  3432. +/* GPIO Address Map */
  3433. +#define AR531X_GPIO (AR531X_APBBASE + 0x2000)
  3434. +#define AR531X_GPIO_DO (AR531X_GPIO + 0x00) /* output register */
  3435. +#define AR531X_GPIO_DI (AR531X_GPIO + 0x04) /* intput register */
  3436. +#define AR531X_GPIO_CR (AR531X_GPIO + 0x08) /* control register */
  3437. +
  3438. +/* GPIO Control Register bit field definitions */
  3439. +#define AR531X_GPIO_CR_M(x) (1 << (x)) /* mask for i/o */
  3440. +#define AR531X_GPIO_CR_O(x) (0 << (x)) /* mask for output */
  3441. +#define AR531X_GPIO_CR_I(x) (1 << (x)) /* mask for input */
  3442. +#define AR531X_GPIO_CR_INT(x) (1 << ((x)+8)) /* mask for interrupt */
  3443. +#define AR531X_GPIO_CR_UART(x) (1 << ((x)+16)) /* uart multiplex */
  3444. +#define AR531X_NUM_GPIO 8
  3445. +
  3446. +
  3447. +#endif
  3448. +
  3449. diff -Nur linux-2.6.39-rc7.orig/arch/mips/include/asm/mach-ar231x/cpu-feature-overrides.h linux-2.6.39-rc7/arch/mips/include/asm/mach-ar231x/cpu-feature-overrides.h
  3450. --- linux-2.6.39-rc7.orig/arch/mips/include/asm/mach-ar231x/cpu-feature-overrides.h 1970-01-01 01:00:00.000000000 +0100
  3451. +++ linux-2.6.39-rc7/arch/mips/include/asm/mach-ar231x/cpu-feature-overrides.h 2011-05-15 21:34:57.000000000 +0200
  3452. @@ -0,0 +1,84 @@
  3453. +/*
  3454. + * Atheros SoC specific CPU feature overrides
  3455. + *
  3456. + * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
  3457. + *
  3458. + * This file was derived from: include/asm-mips/cpu-features.h
  3459. + * Copyright (C) 2003, 2004 Ralf Baechle
  3460. + * Copyright (C) 2004 Maciej W. Rozycki
  3461. + *
  3462. + * This program is free software; you can redistribute it and/or modify it
  3463. + * under the terms of the GNU General Public License version 2 as published
  3464. + * by the Free Software Foundation.
  3465. + *
  3466. + */
  3467. +#ifndef __ASM_MACH_ATHEROS_CPU_FEATURE_OVERRIDES_H
  3468. +#define __ASM_MACH_ATHEROS_CPU_FEATURE_OVERRIDES_H
  3469. +
  3470. +/*
  3471. + * The ATHEROS SoCs have MIPS 4Kc/4KEc core.
  3472. + */
  3473. +#define cpu_has_tlb 1
  3474. +#define cpu_has_4kex 1
  3475. +#define cpu_has_3k_cache 0
  3476. +#define cpu_has_4k_cache 1
  3477. +#define cpu_has_tx39_cache 0
  3478. +#define cpu_has_sb1_cache 0
  3479. +#define cpu_has_fpu 0
  3480. +#define cpu_has_32fpr 0
  3481. +#define cpu_has_counter 1
  3482. +/* #define cpu_has_watch ? */
  3483. +/* #define cpu_has_divec ? */
  3484. +/* #define cpu_has_vce ? */
  3485. +/* #define cpu_has_cache_cdex_p ? */
  3486. +/* #define cpu_has_cache_cdex_s ? */
  3487. +/* #define cpu_has_prefetch ? */
  3488. +/* #define cpu_has_mcheck ? */
  3489. +#define cpu_has_ejtag 1
  3490. +
  3491. +#if !defined(CONFIG_ATHEROS_AR5312)
  3492. +# define cpu_has_llsc 1
  3493. +#else
  3494. +/*
  3495. + * The MIPS 4Kc V0.9 core in the AR5312/AR2312 have problems with the
  3496. + * ll/sc instructions.
  3497. + */
  3498. +# define cpu_has_llsc 0
  3499. +#endif
  3500. +
  3501. +#define cpu_has_mips16 0
  3502. +#define cpu_has_mdmx 0
  3503. +#define cpu_has_mips3d 0
  3504. +#define cpu_has_smartmips 0
  3505. +
  3506. +/* #define cpu_has_vtag_icache ? */
  3507. +/* #define cpu_has_dc_aliases ? */
  3508. +/* #define cpu_has_ic_fills_f_dc ? */
  3509. +/* #define cpu_has_pindexed_dcache ? */
  3510. +
  3511. +/* #define cpu_icache_snoops_remote_store ? */
  3512. +
  3513. +#define cpu_has_mips32r1 1
  3514. +
  3515. +#if !defined(CONFIG_ATHEROS_AR5312)
  3516. +# define cpu_has_mips32r2 1
  3517. +#endif
  3518. +
  3519. +#define cpu_has_mips64r1 0
  3520. +#define cpu_has_mips64r2 0
  3521. +
  3522. +#define cpu_has_dsp 0
  3523. +#define cpu_has_mipsmt 0
  3524. +
  3525. +/* #define cpu_has_nofpuex ? */
  3526. +#define cpu_has_64bits 0
  3527. +#define cpu_has_64bit_zero_reg 0
  3528. +#define cpu_has_64bit_gp_regs 0
  3529. +#define cpu_has_64bit_addresses 0
  3530. +
  3531. +/* #define cpu_has_inclusive_pcaches ? */
  3532. +
  3533. +/* #define cpu_dcache_line_size() ? */
  3534. +/* #define cpu_icache_line_size() ? */
  3535. +
  3536. +#endif /* __ASM_MACH_ATHEROS_CPU_FEATURE_OVERRIDES_H */
  3537. diff -Nur linux-2.6.39-rc7.orig/arch/mips/include/asm/mach-ar231x/dma-coherence.h linux-2.6.39-rc7/arch/mips/include/asm/mach-ar231x/dma-coherence.h
  3538. --- linux-2.6.39-rc7.orig/arch/mips/include/asm/mach-ar231x/dma-coherence.h 1970-01-01 01:00:00.000000000 +0100
  3539. +++ linux-2.6.39-rc7/arch/mips/include/asm/mach-ar231x/dma-coherence.h 2011-05-15 21:41:19.000000000 +0200
  3540. @@ -0,0 +1,76 @@
  3541. +/*
  3542. + * This file is subject to the terms and conditions of the GNU General Public
  3543. + * License. See the file "COPYING" in the main directory of this archive
  3544. + * for more details.
  3545. + *
  3546. + * Copyright (C) 2006 Ralf Baechle <ralf@linux-mips.org>
  3547. + * Copyright (C) 2007 Felix Fietkau <nbd@openwrt.org>
  3548. + *
  3549. + */
  3550. +#ifndef __ASM_MACH_GENERIC_DMA_COHERENCE_H
  3551. +#define __ASM_MACH_GENERIC_DMA_COHERENCE_H
  3552. +
  3553. +#define PCI_DMA_OFFSET 0x20000000
  3554. +
  3555. +#include <linux/device.h>
  3556. +
  3557. +static inline dma_addr_t ar231x_dev_offset(struct device *dev)
  3558. +{
  3559. +#ifdef CONFIG_PCI
  3560. + extern struct bus_type pci_bus_type;
  3561. +
  3562. + if (dev && dev->bus == &pci_bus_type)
  3563. + return PCI_DMA_OFFSET;
  3564. + else
  3565. +#endif
  3566. + return 0;
  3567. +}
  3568. +
  3569. +static inline dma_addr_t plat_map_dma_mem(struct device *dev, void *addr, size_t size)
  3570. +{
  3571. + return virt_to_phys(addr) + ar231x_dev_offset(dev);
  3572. +}
  3573. +
  3574. +static inline dma_addr_t plat_map_dma_mem_page(struct device *dev, struct page *page)
  3575. +{
  3576. + return page_to_phys(page) + ar231x_dev_offset(dev);
  3577. +}
  3578. +
  3579. +static inline unsigned long plat_dma_addr_to_phys(struct device *dev,
  3580. + dma_addr_t dma_addr)
  3581. +{
  3582. + return dma_addr - ar231x_dev_offset(dev);
  3583. +}
  3584. +
  3585. +static inline void plat_unmap_dma_mem(struct device *dev, dma_addr_t dma_addr,
  3586. + size_t size, enum dma_data_direction direction)
  3587. +{
  3588. +}
  3589. +
  3590. +static inline int plat_dma_supported(struct device *dev, u64 mask)
  3591. +{
  3592. + return 1;
  3593. +}
  3594. +
  3595. +static inline void plat_extra_sync_for_device(struct device *dev)
  3596. +{
  3597. + return;
  3598. +}
  3599. +
  3600. +static inline int plat_dma_mapping_error(struct device *dev,
  3601. + dma_addr_t dma_addr)
  3602. +{
  3603. + return 0;
  3604. +}
  3605. +
  3606. +static inline int plat_device_is_coherent(struct device *dev)
  3607. +{
  3608. +#ifdef CONFIG_DMA_COHERENT
  3609. + return 1;
  3610. +#endif
  3611. +#ifdef CONFIG_DMA_NONCOHERENT
  3612. + return 0;
  3613. +#endif
  3614. +}
  3615. +
  3616. +#endif /* __ASM_MACH_GENERIC_DMA_COHERENCE_H */
  3617. diff -Nur linux-2.6.39-rc7.orig/arch/mips/include/asm/mach-ar231x/gpio.h linux-2.6.39-rc7/arch/mips/include/asm/mach-ar231x/gpio.h
  3618. --- linux-2.6.39-rc7.orig/arch/mips/include/asm/mach-ar231x/gpio.h 1970-01-01 01:00:00.000000000 +0100
  3619. +++ linux-2.6.39-rc7/arch/mips/include/asm/mach-ar231x/gpio.h 2011-05-15 21:34:57.000000000 +0200
  3620. @@ -0,0 +1,84 @@
  3621. +#ifndef _ATHEROS_GPIO_H_
  3622. +#define _ATHEROS_GPIO_H_
  3623. +
  3624. +#include <ar231x.h>
  3625. +
  3626. +struct ar231x_gpiodev {
  3627. + u32 valid_mask;
  3628. + u32 (*get_output)(void);
  3629. + u32 (*set_output)(u32 mask, u32 val);
  3630. + u32 (*get)(void);
  3631. + u32 (*set)(u32 mask, u32 val);
  3632. +};
  3633. +
  3634. +extern const struct ar231x_gpiodev *ar231x_gpiodev;
  3635. +
  3636. +/*
  3637. + * Wrappers for the generic GPIO layer
  3638. + */
  3639. +
  3640. +static inline int gpio_direction_input(unsigned gpio) {
  3641. + u32 mask = 1 << gpio;
  3642. +
  3643. + if (!(ar231x_gpiodev->valid_mask & mask))
  3644. + return -ENXIO;
  3645. +
  3646. + ar231x_gpiodev->set_output(mask, 0);
  3647. + return 0;
  3648. +}
  3649. +
  3650. +static inline void gpio_set_value(unsigned gpio, int value) {
  3651. + u32 mask = 1 << gpio;
  3652. +
  3653. + if (!(ar231x_gpiodev->valid_mask & mask))
  3654. + return;
  3655. +
  3656. + ar231x_gpiodev->set(mask, (!!value) * mask);
  3657. +}
  3658. +
  3659. +static inline int gpio_direction_output(unsigned gpio, int value) {
  3660. + u32 mask = 1 << gpio;
  3661. +
  3662. + if (!(ar231x_gpiodev->valid_mask & mask))
  3663. + return -ENXIO;
  3664. +
  3665. + ar231x_gpiodev->set_output(mask, mask);
  3666. + ar231x_gpiodev->set(mask, (!!value) * mask);
  3667. + return 0;
  3668. +}
  3669. +
  3670. +/* Reads the gpio pin. Unchecked function */
  3671. +static inline int gpio_get_value(unsigned gpio) {
  3672. + u32 mask = 1 << gpio;
  3673. +
  3674. + if (!(ar231x_gpiodev->valid_mask & mask))
  3675. + return 0;
  3676. +
  3677. + return !!(ar231x_gpiodev->get() & mask);
  3678. +}
  3679. +
  3680. +static inline int gpio_request(unsigned gpio, const char *label) {
  3681. + return 0;
  3682. +}
  3683. +
  3684. +static inline void gpio_free(unsigned gpio) {
  3685. +}
  3686. +
  3687. +/* Returns IRQ to attach for gpio. Unchecked function */
  3688. +static inline int gpio_to_irq(unsigned gpio) {
  3689. + return AR531X_GPIO_IRQ(gpio);
  3690. +}
  3691. +
  3692. +/* Returns gpio for IRQ attached. Unchecked function */
  3693. +static inline int irq_to_gpio(unsigned irq) {
  3694. + return (irq - (AR531X_GPIO_IRQ(0)));
  3695. +}
  3696. +
  3697. +static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
  3698. +{
  3699. + return -ENOSYS;
  3700. +}
  3701. +
  3702. +#include <asm-generic/gpio.h> /* cansleep wrappers */
  3703. +
  3704. +#endif
  3705. diff -Nur linux-2.6.39-rc7.orig/arch/mips/include/asm/mach-ar231x/reset.h linux-2.6.39-rc7/arch/mips/include/asm/mach-ar231x/reset.h
  3706. --- linux-2.6.39-rc7.orig/arch/mips/include/asm/mach-ar231x/reset.h 1970-01-01 01:00:00.000000000 +0100
  3707. +++ linux-2.6.39-rc7/arch/mips/include/asm/mach-ar231x/reset.h 2011-05-15 21:34:57.000000000 +0200
  3708. @@ -0,0 +1,6 @@
  3709. +#ifndef __AR531X_RESET_H
  3710. +#define __AR531X_RESET_H
  3711. +
  3712. +void ar531x_disable_reset_button(void);
  3713. +
  3714. +#endif /* __AR531X_RESET_H */
  3715. diff -Nur linux-2.6.39-rc7.orig/arch/mips/include/asm/mach-ar231x/war.h linux-2.6.39-rc7/arch/mips/include/asm/mach-ar231x/war.h
  3716. --- linux-2.6.39-rc7.orig/arch/mips/include/asm/mach-ar231x/war.h 1970-01-01 01:00:00.000000000 +0100
  3717. +++ linux-2.6.39-rc7/arch/mips/include/asm/mach-ar231x/war.h 2011-05-15 21:34:57.000000000 +0200
  3718. @@ -0,0 +1,25 @@
  3719. +/*
  3720. + * This file is subject to the terms and conditions of the GNU General Public
  3721. + * License. See the file "COPYING" in the main directory of this archive
  3722. + * for more details.
  3723. + *
  3724. + * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
  3725. + */
  3726. +#ifndef __ASM_MIPS_MACH_ATHEROS_WAR_H
  3727. +#define __ASM_MIPS_MACH_ATHEROS_WAR_H
  3728. +
  3729. +#define R4600_V1_INDEX_ICACHEOP_WAR 0
  3730. +#define R4600_V1_HIT_CACHEOP_WAR 0
  3731. +#define R4600_V2_HIT_CACHEOP_WAR 0
  3732. +#define R5432_CP0_INTERRUPT_WAR 0
  3733. +#define BCM1250_M3_WAR 0
  3734. +#define SIBYTE_1956_WAR 0
  3735. +#define MIPS4K_ICACHE_REFILL_WAR 0
  3736. +#define MIPS_CACHE_SYNC_WAR 0
  3737. +#define TX49XX_ICACHE_INDEX_INV_WAR 0
  3738. +#define RM9000_CDEX_SMP_WAR 0
  3739. +#define ICACHE_REFILLS_WORKAROUND_WAR 0
  3740. +#define R10000_LLSC_WAR 0
  3741. +#define MIPS34K_MISSED_ITLB_WAR 0
  3742. +
  3743. +#endif /* __ASM_MIPS_MACH_ATHEROS_WAR_H */
  3744. diff -Nur linux-2.6.39-rc7.orig/arch/mips/kernel/cevt-r4k.c linux-2.6.39-rc7/arch/mips/kernel/cevt-r4k.c
  3745. --- linux-2.6.39-rc7.orig/arch/mips/kernel/cevt-r4k.c 2011-05-10 04:33:54.000000000 +0200
  3746. +++ linux-2.6.39-rc7/arch/mips/kernel/cevt-r4k.c 2011-05-15 21:34:57.000000000 +0200
  3747. @@ -168,20 +168,23 @@
  3748. struct clock_event_device *cd;
  3749. unsigned int irq;
  3750. - if (!cpu_has_counter || !mips_hpt_frequency)
  3751. - return -ENXIO;
  3752. -
  3753. - if (!c0_compare_int_usable())
  3754. - return -ENXIO;
  3755. -
  3756. /*
  3757. * With vectored interrupts things are getting platform specific.
  3758. * get_c0_compare_int is a hook to allow a platform to return the
  3759. * interrupt number of it's liking.
  3760. */
  3761. irq = MIPS_CPU_IRQ_BASE + cp0_compare_irq;
  3762. - if (get_c0_compare_int)
  3763. + if (get_c0_compare_int) {
  3764. irq = get_c0_compare_int();
  3765. + if ((irq >= MIPS_CPU_IRQ_BASE) && (irq < MIPS_CPU_IRQ_BASE + 8))
  3766. + cp0_compare_irq = irq - MIPS_CPU_IRQ_BASE;
  3767. + }
  3768. +
  3769. + if (!cpu_has_counter || !mips_hpt_frequency)
  3770. + return -ENXIO;
  3771. +
  3772. + if (!c0_compare_int_usable())
  3773. + return -ENXIO;
  3774. cd = &per_cpu(mips_clockevent_device, cpu);
  3775. diff -Nur linux-2.6.39-rc7.orig/drivers/mtd/devices/Kconfig linux-2.6.39-rc7/drivers/mtd/devices/Kconfig
  3776. --- linux-2.6.39-rc7.orig/drivers/mtd/devices/Kconfig 2011-05-10 04:33:54.000000000 +0200
  3777. +++ linux-2.6.39-rc7/drivers/mtd/devices/Kconfig 2011-05-15 21:34:57.000000000 +0200
  3778. @@ -112,6 +112,10 @@
  3779. Set up your spi devices with the right board-specific platform data,
  3780. if you want to specify device partitioning.
  3781. +config MTD_AR2315
  3782. + tristate "Atheros AR2315+ SPI Flash support"
  3783. + depends on ATHEROS_AR2315
  3784. +
  3785. config MTD_SLRAM
  3786. tristate "Uncached system RAM"
  3787. help
  3788. diff -Nur linux-2.6.39-rc7.orig/drivers/mtd/devices/Makefile linux-2.6.39-rc7/drivers/mtd/devices/Makefile
  3789. --- linux-2.6.39-rc7.orig/drivers/mtd/devices/Makefile 2011-05-10 04:33:54.000000000 +0200
  3790. +++ linux-2.6.39-rc7/drivers/mtd/devices/Makefile 2011-05-15 21:34:57.000000000 +0200
  3791. @@ -17,3 +17,4 @@
  3792. obj-$(CONFIG_MTD_DATAFLASH) += mtd_dataflash.o
  3793. obj-$(CONFIG_MTD_M25P80) += m25p80.o
  3794. obj-$(CONFIG_MTD_SST25L) += sst25l.o
  3795. +obj-$(CONFIG_MTD_AR2315) += ar2315.o
  3796. diff -Nur linux-2.6.39-rc7.orig/drivers/mtd/devices/ar2315.c linux-2.6.39-rc7/drivers/mtd/devices/ar2315.c
  3797. --- linux-2.6.39-rc7.orig/drivers/mtd/devices/ar2315.c 1970-01-01 01:00:00.000000000 +0100
  3798. +++ linux-2.6.39-rc7/drivers/mtd/devices/ar2315.c 2011-05-15 21:34:57.000000000 +0200
  3799. @@ -0,0 +1,517 @@
  3800. +
  3801. +/*
  3802. + * MTD driver for the SPI Flash Memory support on Atheros AR2315
  3803. + *
  3804. + * Copyright (c) 2005-2006 Atheros Communications Inc.
  3805. + * Copyright (C) 2006-2007 FON Technology, SL.
  3806. + * Copyright (C) 2006-2007 Imre Kaloz <kaloz@openwrt.org>
  3807. + * Copyright (C) 2006-2009 Felix Fietkau <nbd@openwrt.org>
  3808. + *
  3809. + * This code is free software; you can redistribute it and/or modify
  3810. + * it under the terms of the GNU General Public License version 2 as
  3811. + * published by the Free Software Foundation.
  3812. + *
  3813. + */
  3814. +
  3815. +#include <linux/kernel.h>
  3816. +#include <linux/module.h>
  3817. +#include <linux/types.h>
  3818. +#include <linux/version.h>
  3819. +#include <linux/errno.h>
  3820. +#include <linux/slab.h>
  3821. +#include <linux/mtd/mtd.h>
  3822. +#include <linux/mtd/partitions.h>
  3823. +#include <linux/platform_device.h>
  3824. +#include <linux/sched.h>
  3825. +#include <linux/root_dev.h>
  3826. +#include <linux/delay.h>
  3827. +#include <asm/delay.h>
  3828. +#include <asm/io.h>
  3829. +
  3830. +#include <ar2315_spiflash.h>
  3831. +#include <ar231x_platform.h>
  3832. +#include <ar231x.h>
  3833. +
  3834. +
  3835. +#define SPIFLASH "spiflash: "
  3836. +#define busy_wait(_priv, _condition, _wait) do { \
  3837. + while (_condition) { \
  3838. + spin_unlock_bh(&_priv->lock); \
  3839. + if (_wait > 1) \
  3840. + msleep(_wait); \
  3841. + else if ((_wait == 1) && need_resched()) \
  3842. + schedule(); \
  3843. + else \
  3844. + udelay(1); \
  3845. + spin_lock_bh(&_priv->lock); \
  3846. + } \
  3847. +} while (0)
  3848. +
  3849. +enum {
  3850. + FLASH_NONE,
  3851. + FLASH_1MB,
  3852. + FLASH_2MB,
  3853. + FLASH_4MB,
  3854. + FLASH_8MB,
  3855. + FLASH_16MB,
  3856. +};
  3857. +
  3858. +/* Flash configuration table */
  3859. +struct flashconfig {
  3860. + u32 byte_cnt;
  3861. + u32 sector_cnt;
  3862. + u32 sector_size;
  3863. +};
  3864. +
  3865. +const struct flashconfig flashconfig_tbl[] = {
  3866. + [FLASH_NONE] = { 0, 0, 0},
  3867. + [FLASH_1MB] = { STM_1MB_BYTE_COUNT, STM_1MB_SECTOR_COUNT, STM_1MB_SECTOR_SIZE},
  3868. + [FLASH_2MB] = { STM_2MB_BYTE_COUNT, STM_2MB_SECTOR_COUNT, STM_2MB_SECTOR_SIZE},
  3869. + [FLASH_4MB] = { STM_4MB_BYTE_COUNT, STM_4MB_SECTOR_COUNT, STM_4MB_SECTOR_SIZE},
  3870. + [FLASH_8MB] = { STM_8MB_BYTE_COUNT, STM_8MB_SECTOR_COUNT, STM_8MB_SECTOR_SIZE},
  3871. + [FLASH_16MB] = { STM_16MB_BYTE_COUNT, STM_16MB_SECTOR_COUNT, STM_16MB_SECTOR_SIZE}
  3872. +};
  3873. +
  3874. +/* Mapping of generic opcodes to STM serial flash opcodes */
  3875. +enum {
  3876. + SPI_WRITE_ENABLE,
  3877. + SPI_WRITE_DISABLE,
  3878. + SPI_RD_STATUS,
  3879. + SPI_WR_STATUS,
  3880. + SPI_RD_DATA,
  3881. + SPI_FAST_RD_DATA,
  3882. + SPI_PAGE_PROGRAM,
  3883. + SPI_SECTOR_ERASE,
  3884. + SPI_BULK_ERASE,
  3885. + SPI_DEEP_PWRDOWN,
  3886. + SPI_RD_SIG,
  3887. +};
  3888. +
  3889. +struct opcodes {
  3890. + __u16 code;
  3891. + __s8 tx_cnt;
  3892. + __s8 rx_cnt;
  3893. +};
  3894. +const struct opcodes stm_opcodes[] = {
  3895. + [SPI_WRITE_ENABLE] = {STM_OP_WR_ENABLE, 1, 0},
  3896. + [SPI_WRITE_DISABLE] = {STM_OP_WR_DISABLE, 1, 0},
  3897. + [SPI_RD_STATUS] = {STM_OP_RD_STATUS, 1, 1},
  3898. + [SPI_WR_STATUS] = {STM_OP_WR_STATUS, 1, 0},
  3899. + [SPI_RD_DATA] = {STM_OP_RD_DATA, 4, 4},
  3900. + [SPI_FAST_RD_DATA] = {STM_OP_FAST_RD_DATA, 5, 0},
  3901. + [SPI_PAGE_PROGRAM] = {STM_OP_PAGE_PGRM, 8, 0},
  3902. + [SPI_SECTOR_ERASE] = {STM_OP_SECTOR_ERASE, 4, 0},
  3903. + [SPI_BULK_ERASE] = {STM_OP_BULK_ERASE, 1, 0},
  3904. + [SPI_DEEP_PWRDOWN] = {STM_OP_DEEP_PWRDOWN, 1, 0},
  3905. + [SPI_RD_SIG] = {STM_OP_RD_SIG, 4, 1},
  3906. +};
  3907. +
  3908. +/* Driver private data structure */
  3909. +struct spiflash_priv {
  3910. + struct mtd_info mtd;
  3911. + void *readaddr; /* memory mapped data for read */
  3912. + void *mmraddr; /* memory mapped register space */
  3913. + wait_queue_head_t wq;
  3914. + spinlock_t lock;
  3915. + int state;
  3916. +};
  3917. +
  3918. +#define to_spiflash(_mtd) container_of(_mtd, struct spiflash_priv, mtd)
  3919. +
  3920. +enum {
  3921. + FL_READY,
  3922. + FL_READING,
  3923. + FL_ERASING,
  3924. + FL_WRITING
  3925. +};
  3926. +
  3927. +/***************************************************************************************************/
  3928. +
  3929. +static u32
  3930. +spiflash_read_reg(struct spiflash_priv *priv, int reg)
  3931. +{
  3932. + return ar231x_read_reg((u32) priv->mmraddr + reg);
  3933. +}
  3934. +
  3935. +static void
  3936. +spiflash_write_reg(struct spiflash_priv *priv, int reg, u32 data)
  3937. +{
  3938. + ar231x_write_reg((u32) priv->mmraddr + reg, data);
  3939. +}
  3940. +
  3941. +static u32
  3942. +spiflash_wait_busy(struct spiflash_priv *priv)
  3943. +{
  3944. + u32 reg;
  3945. +
  3946. + busy_wait(priv, (reg = spiflash_read_reg(priv, SPI_FLASH_CTL)) &
  3947. + SPI_CTL_BUSY, 0);
  3948. + return reg;
  3949. +}
  3950. +
  3951. +static u32
  3952. +spiflash_sendcmd (struct spiflash_priv *priv, int opcode, u32 addr)
  3953. +{
  3954. + const struct opcodes *op;
  3955. + u32 reg, mask;
  3956. +
  3957. + op = &stm_opcodes[opcode];
  3958. + reg = spiflash_wait_busy(priv);
  3959. + spiflash_write_reg(priv, SPI_FLASH_OPCODE,
  3960. + ((u32) op->code) | (addr << 8));
  3961. +
  3962. + reg &= ~SPI_CTL_TX_RX_CNT_MASK;
  3963. + reg |= SPI_CTL_START | op->tx_cnt | (op->rx_cnt << 4);
  3964. +
  3965. + spiflash_write_reg(priv, SPI_FLASH_CTL, reg);
  3966. + spiflash_wait_busy(priv);
  3967. +
  3968. + if (!op->rx_cnt)
  3969. + return 0;
  3970. +
  3971. + reg = spiflash_read_reg(priv, SPI_FLASH_DATA);
  3972. +
  3973. + switch (op->rx_cnt) {
  3974. + case 1:
  3975. + mask = 0x000000ff;
  3976. + break;
  3977. + case 2:
  3978. + mask = 0x0000ffff;
  3979. + break;
  3980. + case 3:
  3981. + mask = 0x00ffffff;
  3982. + break;
  3983. + default:
  3984. + mask = 0xffffffff;
  3985. + break;
  3986. + }
  3987. + reg &= mask;
  3988. +
  3989. + return reg;
  3990. +}
  3991. +
  3992. +
  3993. +/*
  3994. + * Probe SPI flash device
  3995. + * Function returns 0 for failure.
  3996. + * and flashconfig_tbl array index for success.
  3997. + */
  3998. +static int
  3999. +spiflash_probe_chip (struct spiflash_priv *priv)
  4000. +{
  4001. + u32 sig;
  4002. + int flash_size;
  4003. +
  4004. + /* Read the signature on the flash device */
  4005. + spin_lock_bh(&priv->lock);
  4006. + sig = spiflash_sendcmd(priv, SPI_RD_SIG, 0);
  4007. + spin_unlock_bh(&priv->lock);
  4008. +
  4009. + switch (sig) {
  4010. + case STM_8MBIT_SIGNATURE:
  4011. + flash_size = FLASH_1MB;
  4012. + break;
  4013. + case STM_16MBIT_SIGNATURE:
  4014. + flash_size = FLASH_2MB;
  4015. + break;
  4016. + case STM_32MBIT_SIGNATURE:
  4017. + flash_size = FLASH_4MB;
  4018. + break;
  4019. + case STM_64MBIT_SIGNATURE:
  4020. + flash_size = FLASH_8MB;
  4021. + break;
  4022. + case STM_128MBIT_SIGNATURE:
  4023. + flash_size = FLASH_16MB;
  4024. + break;
  4025. + default:
  4026. + printk (KERN_WARNING SPIFLASH "Read of flash device signature failed!\n");
  4027. + return 0;
  4028. + }
  4029. +
  4030. + return flash_size;
  4031. +}
  4032. +
  4033. +
  4034. +/* wait until the flash chip is ready and grab a lock */
  4035. +static int spiflash_wait_ready(struct spiflash_priv *priv, int state)
  4036. +{
  4037. + DECLARE_WAITQUEUE(wait, current);
  4038. +
  4039. +retry:
  4040. + spin_lock_bh(&priv->lock);
  4041. + if (priv->state != FL_READY) {
  4042. + set_current_state(TASK_UNINTERRUPTIBLE);
  4043. + add_wait_queue(&priv->wq, &wait);
  4044. + spin_unlock_bh(&priv->lock);
  4045. + schedule();
  4046. + remove_wait_queue(&priv->wq, &wait);
  4047. +
  4048. + if(signal_pending(current))
  4049. + return 0;
  4050. +
  4051. + goto retry;
  4052. + }
  4053. + priv->state = state;
  4054. +
  4055. + return 1;
  4056. +}
  4057. +
  4058. +static inline void spiflash_done(struct spiflash_priv *priv)
  4059. +{
  4060. + priv->state = FL_READY;
  4061. + spin_unlock_bh(&priv->lock);
  4062. + wake_up(&priv->wq);
  4063. +}
  4064. +
  4065. +static void
  4066. +spiflash_wait_complete(struct spiflash_priv *priv, unsigned int timeout)
  4067. +{
  4068. + busy_wait(priv, spiflash_sendcmd(priv, SPI_RD_STATUS, 0) &
  4069. + SPI_STATUS_WIP, timeout);
  4070. + spiflash_done(priv);
  4071. +}
  4072. +
  4073. +
  4074. +
  4075. +static int
  4076. +spiflash_erase (struct mtd_info *mtd, struct erase_info *instr)
  4077. +{
  4078. + struct spiflash_priv *priv = to_spiflash(mtd);
  4079. + const struct opcodes *op;
  4080. + u32 temp, reg;
  4081. +
  4082. + if (instr->addr + instr->len > mtd->size)
  4083. + return -EINVAL;
  4084. +
  4085. + if (!spiflash_wait_ready(priv, FL_ERASING))
  4086. + return -EINTR;
  4087. +
  4088. + spiflash_sendcmd(priv, SPI_WRITE_ENABLE, 0);
  4089. + reg = spiflash_wait_busy(priv);
  4090. +
  4091. + op = &stm_opcodes[SPI_SECTOR_ERASE];
  4092. + temp = ((u32)instr->addr << 8) | (u32)(op->code);
  4093. + spiflash_write_reg(priv, SPI_FLASH_OPCODE, temp);
  4094. +
  4095. + reg &= ~SPI_CTL_TX_RX_CNT_MASK;
  4096. + reg |= op->tx_cnt | SPI_CTL_START;
  4097. + spiflash_write_reg(priv, SPI_FLASH_CTL, reg);
  4098. +
  4099. + spiflash_wait_complete(priv, 20);
  4100. +
  4101. + instr->state = MTD_ERASE_DONE;
  4102. + mtd_erase_callback(instr);
  4103. +
  4104. + return 0;
  4105. +}
  4106. +
  4107. +static int
  4108. +spiflash_read (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
  4109. +{
  4110. + struct spiflash_priv *priv = to_spiflash(mtd);
  4111. + u8 *read_addr;
  4112. +
  4113. + if (!len)
  4114. + return 0;
  4115. +
  4116. + if (from + len > mtd->size)
  4117. + return -EINVAL;
  4118. +
  4119. + *retlen = len;
  4120. +
  4121. + if (!spiflash_wait_ready(priv, FL_READING))
  4122. + return -EINTR;
  4123. +
  4124. + read_addr = (u8 *)(priv->readaddr + from);
  4125. + memcpy_fromio(buf, read_addr, len);
  4126. + spiflash_done(priv);
  4127. +
  4128. + return 0;
  4129. +}
  4130. +
  4131. +static int
  4132. +spiflash_write (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u8 *buf)
  4133. +{
  4134. + struct spiflash_priv *priv = to_spiflash(mtd);
  4135. + u32 opcode, bytes_left;
  4136. +
  4137. + *retlen = 0;
  4138. +
  4139. + if (!len)
  4140. + return 0;
  4141. +
  4142. + if (to + len > mtd->size)
  4143. + return -EINVAL;
  4144. +
  4145. + bytes_left = len;
  4146. +
  4147. + do {
  4148. + u32 read_len, reg, page_offset, spi_data = 0;
  4149. +
  4150. + read_len = min(bytes_left, sizeof(u32));
  4151. +
  4152. + /* 32-bit writes cannot span across a page boundary
  4153. + * (256 bytes). This types of writes require two page
  4154. + * program operations to handle it correctly. The STM part
  4155. + * will write the overflow data to the beginning of the
  4156. + * current page as opposed to the subsequent page.
  4157. + */
  4158. + page_offset = (to & (STM_PAGE_SIZE - 1)) + read_len;
  4159. +
  4160. + if (page_offset > STM_PAGE_SIZE)
  4161. + read_len -= (page_offset - STM_PAGE_SIZE);
  4162. +
  4163. + if (!spiflash_wait_ready(priv, FL_WRITING))
  4164. + return -EINTR;
  4165. +
  4166. + spiflash_sendcmd(priv, SPI_WRITE_ENABLE, 0);
  4167. + spi_data = 0;
  4168. + switch (read_len) {
  4169. + case 4:
  4170. + spi_data |= buf[3] << 24;
  4171. + /* fall through */
  4172. + case 3:
  4173. + spi_data |= buf[2] << 16;
  4174. + /* fall through */
  4175. + case 2:
  4176. + spi_data |= buf[1] << 8;
  4177. + /* fall through */
  4178. + case 1:
  4179. + spi_data |= buf[0] & 0xff;
  4180. + break;
  4181. + default:
  4182. + break;
  4183. + }
  4184. +
  4185. + spiflash_write_reg(priv, SPI_FLASH_DATA, spi_data);
  4186. + opcode = stm_opcodes[SPI_PAGE_PROGRAM].code |
  4187. + (to & 0x00ffffff) << 8;
  4188. + spiflash_write_reg(priv, SPI_FLASH_OPCODE, opcode);
  4189. +
  4190. + reg = spiflash_read_reg(priv, SPI_FLASH_CTL);
  4191. + reg &= ~SPI_CTL_TX_RX_CNT_MASK;
  4192. + reg |= (read_len + 4) | SPI_CTL_START;
  4193. + spiflash_write_reg(priv, SPI_FLASH_CTL, reg);
  4194. +
  4195. + spiflash_wait_complete(priv, 1);
  4196. +
  4197. + bytes_left -= read_len;
  4198. + to += read_len;
  4199. + buf += read_len;
  4200. +
  4201. + *retlen += read_len;
  4202. + } while (bytes_left != 0);
  4203. +
  4204. + return 0;
  4205. +}
  4206. +
  4207. +
  4208. +#ifdef CONFIG_MTD_PARTITIONS
  4209. +static const char *part_probe_types[] = { "cmdlinepart", "RedBoot", "MyLoader", NULL };
  4210. +#endif
  4211. +
  4212. +
  4213. +static int
  4214. +spiflash_probe(struct platform_device *pdev)
  4215. +{
  4216. + struct spiflash_priv *priv;
  4217. + struct mtd_partition *parts;
  4218. + struct mtd_info *mtd;
  4219. + int index, num_parts;
  4220. + int result = 0;
  4221. +
  4222. + priv = kzalloc(sizeof(struct spiflash_priv), GFP_KERNEL);
  4223. + spin_lock_init(&priv->lock);
  4224. + init_waitqueue_head(&priv->wq);
  4225. + priv->state = FL_READY;
  4226. + mtd = &priv->mtd;
  4227. +
  4228. + priv->mmraddr = ioremap_nocache(SPI_FLASH_MMR, SPI_FLASH_MMR_SIZE);
  4229. + if (!priv->mmraddr) {
  4230. + printk(KERN_WARNING SPIFLASH "Failed to map flash device\n");
  4231. + goto error;
  4232. + }
  4233. +
  4234. + index = spiflash_probe_chip(priv);
  4235. + if (!index) {
  4236. + printk (KERN_WARNING SPIFLASH "Found no serial flash device\n");
  4237. + goto error;
  4238. + }
  4239. +
  4240. + priv->readaddr = ioremap_nocache(SPI_FLASH_READ, flashconfig_tbl[index].byte_cnt);
  4241. + if (!priv->readaddr) {
  4242. + printk (KERN_WARNING SPIFLASH "Failed to map flash device\n");
  4243. + goto error;
  4244. + }
  4245. +
  4246. + platform_set_drvdata(pdev, priv);
  4247. + mtd->name = "spiflash";
  4248. + mtd->type = MTD_NORFLASH;
  4249. + mtd->flags = (MTD_CAP_NORFLASH|MTD_WRITEABLE);
  4250. + mtd->size = flashconfig_tbl[index].byte_cnt;
  4251. + mtd->erasesize = flashconfig_tbl[index].sector_size;
  4252. + mtd->writesize = 1;
  4253. + mtd->numeraseregions = 0;
  4254. + mtd->eraseregions = NULL;
  4255. + mtd->erase = spiflash_erase;
  4256. + mtd->read = spiflash_read;
  4257. + mtd->write = spiflash_write;
  4258. + mtd->owner = THIS_MODULE;
  4259. +
  4260. +#ifdef CONFIG_MTD_PARTITIONS
  4261. + /* parse redboot partitions */
  4262. + num_parts = parse_mtd_partitions(mtd, part_probe_types, &parts, 0);
  4263. + if (!num_parts)
  4264. + goto error;
  4265. +
  4266. + result = add_mtd_partitions(mtd, parts, num_parts);
  4267. +#endif
  4268. +
  4269. + return result;
  4270. +
  4271. +error:
  4272. + if (priv->mmraddr)
  4273. + iounmap(priv->mmraddr);
  4274. + kfree(priv);
  4275. + return -ENXIO;
  4276. +}
  4277. +
  4278. +static int
  4279. +spiflash_remove (struct platform_device *pdev)
  4280. +{
  4281. + struct spiflash_priv *priv = platform_get_drvdata(pdev);
  4282. + struct mtd_info *mtd = &priv->mtd;
  4283. +
  4284. + del_mtd_partitions(mtd);
  4285. + iounmap(priv->mmraddr);
  4286. + iounmap(priv->readaddr);
  4287. + kfree(priv);
  4288. +
  4289. + return 0;
  4290. +}
  4291. +
  4292. +struct platform_driver spiflash_driver = {
  4293. + .driver.name = "spiflash",
  4294. + .probe = spiflash_probe,
  4295. + .remove = spiflash_remove,
  4296. +};
  4297. +
  4298. +int __init
  4299. +spiflash_init (void)
  4300. +{
  4301. + return platform_driver_register(&spiflash_driver);
  4302. +}
  4303. +
  4304. +void __exit
  4305. +spiflash_exit (void)
  4306. +{
  4307. + return platform_driver_unregister(&spiflash_driver);
  4308. +}
  4309. +
  4310. +module_init (spiflash_init);
  4311. +module_exit (spiflash_exit);
  4312. +
  4313. +MODULE_LICENSE("GPL");
  4314. +MODULE_AUTHOR("OpenWrt.org, Atheros Communications Inc");
  4315. +MODULE_DESCRIPTION("MTD driver for SPI Flash on Atheros SOC");
  4316. +
  4317. diff -Nur linux-2.6.39-rc7.orig/drivers/mtd/redboot.c linux-2.6.39-rc7/drivers/mtd/redboot.c
  4318. --- linux-2.6.39-rc7.orig/drivers/mtd/redboot.c 2011-05-10 04:33:54.000000000 +0200
  4319. +++ linux-2.6.39-rc7/drivers/mtd/redboot.c 2011-05-15 21:34:57.000000000 +0200
  4320. @@ -55,6 +55,22 @@
  4321. return 1;
  4322. }
  4323. +static uint32_t mtd_get_offset_erasesize(struct mtd_info *mtd, uint64_t offset)
  4324. +{
  4325. + struct mtd_erase_region_info *regions = mtd->eraseregions;
  4326. + int i;
  4327. +
  4328. + for (i = 0; i < mtd->numeraseregions; i++) {
  4329. + if (regions[i].offset +
  4330. + regions[i].numblocks * regions[i].erasesize <= offset)
  4331. + continue;
  4332. +
  4333. + return regions[i].erasesize;
  4334. + }
  4335. +
  4336. + return mtd->erasesize;
  4337. +}
  4338. +
  4339. static int parse_redboot_partitions(struct mtd_info *master,
  4340. struct mtd_partition **pparts,
  4341. unsigned long fis_origin)
  4342. @@ -70,36 +86,38 @@
  4343. int namelen = 0;
  4344. int nulllen = 0;
  4345. int numslots;
  4346. + int first_slot;
  4347. unsigned long offset;
  4348. #ifdef CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED
  4349. static char nullstring[] = "unallocated";
  4350. #endif
  4351. + buf = vmalloc(master->erasesize);
  4352. + if (!buf)
  4353. + return -ENOMEM;
  4354. +
  4355. + restart:
  4356. if ( directory < 0 ) {
  4357. offset = master->size + directory * master->erasesize;
  4358. - while (master->block_isbad &&
  4359. + while (master->block_isbad &&
  4360. master->block_isbad(master, offset)) {
  4361. if (!offset) {
  4362. nogood:
  4363. printk(KERN_NOTICE "Failed to find a non-bad block to check for RedBoot partition table\n");
  4364. + vfree(buf);
  4365. return -EIO;
  4366. }
  4367. offset -= master->erasesize;
  4368. }
  4369. } else {
  4370. offset = directory * master->erasesize;
  4371. - while (master->block_isbad &&
  4372. + while (master->block_isbad &&
  4373. master->block_isbad(master, offset)) {
  4374. offset += master->erasesize;
  4375. if (offset == master->size)
  4376. goto nogood;
  4377. }
  4378. }
  4379. - buf = vmalloc(master->erasesize);
  4380. -
  4381. - if (!buf)
  4382. - return -ENOMEM;
  4383. -
  4384. printk(KERN_NOTICE "Searching for RedBoot partition table in %s at offset 0x%lx\n",
  4385. master->name, offset);
  4386. @@ -171,13 +189,21 @@
  4387. }
  4388. if (i == numslots) {
  4389. /* Didn't find it */
  4390. + if (offset + master->erasesize < master->size) {
  4391. + /* not at the end of the flash yet, maybe next block :) */
  4392. + directory++;
  4393. + goto restart;
  4394. + }
  4395. printk(KERN_NOTICE "No RedBoot partition table detected in %s\n",
  4396. master->name);
  4397. ret = 0;
  4398. goto out;
  4399. }
  4400. - for (i = 0; i < numslots; i++) {
  4401. + first_slot = (buf[i].flash_base & (master->erasesize - 1)) /
  4402. + sizeof(struct fis_image_desc);
  4403. +
  4404. + for (i = first_slot; i < first_slot + numslots; i++) {
  4405. struct fis_list *new_fl, **prev;
  4406. if (buf[i].name[0] == 0xff) {
  4407. diff -Nur linux-2.6.39-rc7.orig/drivers/net/Kconfig linux-2.6.39-rc7/drivers/net/Kconfig
  4408. --- linux-2.6.39-rc7.orig/drivers/net/Kconfig 2011-05-10 04:33:54.000000000 +0200
  4409. +++ linux-2.6.39-rc7/drivers/net/Kconfig 2011-05-15 21:34:57.000000000 +0200
  4410. @@ -251,6 +251,12 @@
  4411. help
  4412. Select this if your platform comes with an external 93CX6 eeprom.
  4413. +config AR231X_ETHERNET
  4414. + tristate "AR231x Ethernet support"
  4415. + depends on ATHEROS_AR231X
  4416. + help
  4417. + Support for the AR231x/531x ethernet controller
  4418. +
  4419. config MACE
  4420. tristate "MACE (Power Mac ethernet) support"
  4421. depends on PPC_PMAC && PPC32
  4422. diff -Nur linux-2.6.39-rc7.orig/drivers/net/Makefile linux-2.6.39-rc7/drivers/net/Makefile
  4423. --- linux-2.6.39-rc7.orig/drivers/net/Makefile 2011-05-10 04:33:54.000000000 +0200
  4424. +++ linux-2.6.39-rc7/drivers/net/Makefile 2011-05-15 21:34:57.000000000 +0200
  4425. @@ -226,6 +226,7 @@
  4426. obj-$(CONFIG_KORINA) += korina.o
  4427. obj-$(CONFIG_MIPS_JAZZ_SONIC) += jazzsonic.o
  4428. obj-$(CONFIG_MIPS_AU1X00_ENET) += au1000_eth.o
  4429. +obj-$(CONFIG_AR231X_ETHERNET) += ar231x.o
  4430. obj-$(CONFIG_MIPS_SIM_NET) += mipsnet.o
  4431. obj-$(CONFIG_SGI_IOC3_ETH) += ioc3-eth.o
  4432. obj-$(CONFIG_DECLANCE) += declance.o
  4433. diff -Nur linux-2.6.39-rc7.orig/drivers/net/ar231x.c linux-2.6.39-rc7/drivers/net/ar231x.c
  4434. --- linux-2.6.39-rc7.orig/drivers/net/ar231x.c 1970-01-01 01:00:00.000000000 +0100
  4435. +++ linux-2.6.39-rc7/drivers/net/ar231x.c 2011-05-15 21:34:57.000000000 +0200
  4436. @@ -0,0 +1,1293 @@
  4437. +/*
  4438. + * ar231x.c: Linux driver for the Atheros AR231x Ethernet device.
  4439. + *
  4440. + * Copyright (C) 2004 by Sameer Dekate <sdekate@arubanetworks.com>
  4441. + * Copyright (C) 2006 Imre Kaloz <kaloz@openwrt.org>
  4442. + * Copyright (C) 2006-2009 Felix Fietkau <nbd@openwrt.org>
  4443. + *
  4444. + * Thanks to Atheros for providing hardware and documentation
  4445. + * enabling me to write this driver.
  4446. + *
  4447. + * This program is free software; you can redistribute it and/or modify
  4448. + * it under the terms of the GNU General Public License as published by
  4449. + * the Free Software Foundation; either version 2 of the License, or
  4450. + * (at your option) any later version.
  4451. + *
  4452. + * Additional credits:
  4453. + * This code is taken from John Taylor's Sibyte driver and then
  4454. + * modified for the AR2313.
  4455. + */
  4456. +
  4457. +#include <linux/module.h>
  4458. +#include <linux/version.h>
  4459. +#include <linux/types.h>
  4460. +#include <linux/errno.h>
  4461. +#include <linux/ioport.h>
  4462. +#include <linux/pci.h>
  4463. +#include <linux/netdevice.h>
  4464. +#include <linux/etherdevice.h>
  4465. +#include <linux/skbuff.h>
  4466. +#include <linux/init.h>
  4467. +#include <linux/delay.h>
  4468. +#include <linux/mm.h>
  4469. +#include <linux/highmem.h>
  4470. +#include <linux/sockios.h>
  4471. +#include <linux/pkt_sched.h>
  4472. +#include <linux/mii.h>
  4473. +#include <linux/phy.h>
  4474. +#include <linux/ethtool.h>
  4475. +#include <linux/ctype.h>
  4476. +#include <linux/platform_device.h>
  4477. +
  4478. +#include <net/sock.h>
  4479. +#include <net/ip.h>
  4480. +
  4481. +#include <asm/system.h>
  4482. +#include <asm/io.h>
  4483. +#include <asm/irq.h>
  4484. +#include <asm/byteorder.h>
  4485. +#include <asm/uaccess.h>
  4486. +#include <asm/bootinfo.h>
  4487. +
  4488. +#define AR2313_MTU 1692
  4489. +#define AR2313_PRIOS 1
  4490. +#define AR2313_QUEUES (2*AR2313_PRIOS)
  4491. +#define AR2313_DESCR_ENTRIES 64
  4492. +
  4493. +
  4494. +#ifndef min
  4495. +#define min(a,b) (((a)<(b))?(a):(b))
  4496. +#endif
  4497. +
  4498. +#ifndef SMP_CACHE_BYTES
  4499. +#define SMP_CACHE_BYTES L1_CACHE_BYTES
  4500. +#endif
  4501. +
  4502. +#define AR2313_MBOX_SET_BIT 0x8
  4503. +
  4504. +#include "ar231x.h"
  4505. +
  4506. +/*
  4507. + * New interrupt handler strategy:
  4508. + *
  4509. + * An old interrupt handler worked using the traditional method of
  4510. + * replacing an skbuff with a new one when a packet arrives. However
  4511. + * the rx rings do not need to contain a static number of buffer
  4512. + * descriptors, thus it makes sense to move the memory allocation out
  4513. + * of the main interrupt handler and do it in a bottom half handler
  4514. + * and only allocate new buffers when the number of buffers in the
  4515. + * ring is below a certain threshold. In order to avoid starving the
  4516. + * NIC under heavy load it is however necessary to force allocation
  4517. + * when hitting a minimum threshold. The strategy for alloction is as
  4518. + * follows:
  4519. + *
  4520. + * RX_LOW_BUF_THRES - allocate buffers in the bottom half
  4521. + * RX_PANIC_LOW_THRES - we are very low on buffers, allocate
  4522. + * the buffers in the interrupt handler
  4523. + * RX_RING_THRES - maximum number of buffers in the rx ring
  4524. + *
  4525. + * One advantagous side effect of this allocation approach is that the
  4526. + * entire rx processing can be done without holding any spin lock
  4527. + * since the rx rings and registers are totally independent of the tx
  4528. + * ring and its registers. This of course includes the kmalloc's of
  4529. + * new skb's. Thus start_xmit can run in parallel with rx processing
  4530. + * and the memory allocation on SMP systems.
  4531. + *
  4532. + * Note that running the skb reallocation in a bottom half opens up
  4533. + * another can of races which needs to be handled properly. In
  4534. + * particular it can happen that the interrupt handler tries to run
  4535. + * the reallocation while the bottom half is either running on another
  4536. + * CPU or was interrupted on the same CPU. To get around this the
  4537. + * driver uses bitops to prevent the reallocation routines from being
  4538. + * reentered.
  4539. + *
  4540. + * TX handling can also be done without holding any spin lock, wheee
  4541. + * this is fun! since tx_csm is only written to by the interrupt
  4542. + * handler.
  4543. + */
  4544. +
  4545. +/*
  4546. + * Threshold values for RX buffer allocation - the low water marks for
  4547. + * when to start refilling the rings are set to 75% of the ring
  4548. + * sizes. It seems to make sense to refill the rings entirely from the
  4549. + * intrrupt handler once it gets below the panic threshold, that way
  4550. + * we don't risk that the refilling is moved to another CPU when the
  4551. + * one running the interrupt handler just got the slab code hot in its
  4552. + * cache.
  4553. + */
  4554. +#define RX_RING_SIZE AR2313_DESCR_ENTRIES
  4555. +#define RX_PANIC_THRES (RX_RING_SIZE/4)
  4556. +#define RX_LOW_THRES ((3*RX_RING_SIZE)/4)
  4557. +#define CRC_LEN 4
  4558. +#define RX_OFFSET 2
  4559. +
  4560. +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
  4561. +#define VLAN_HDR 4
  4562. +#else
  4563. +#define VLAN_HDR 0
  4564. +#endif
  4565. +
  4566. +#define AR2313_BUFSIZE (AR2313_MTU + VLAN_HDR + ETH_HLEN + CRC_LEN + RX_OFFSET)
  4567. +
  4568. +#ifdef MODULE
  4569. +MODULE_LICENSE("GPL");
  4570. +MODULE_AUTHOR("Sameer Dekate <sdekate@arubanetworks.com>, Imre Kaloz <kaloz@openwrt.org>, Felix Fietkau <nbd@openwrt.org>");
  4571. +MODULE_DESCRIPTION("AR231x Ethernet driver");
  4572. +#endif
  4573. +
  4574. +#define virt_to_phys(x) ((u32)(x) & 0x1fffffff)
  4575. +
  4576. +// prototypes
  4577. +static void ar231x_halt(struct net_device *dev);
  4578. +static void rx_tasklet_func(unsigned long data);
  4579. +static void rx_tasklet_cleanup(struct net_device *dev);
  4580. +static void ar231x_multicast_list(struct net_device *dev);
  4581. +static void ar231x_tx_timeout(struct net_device *dev);
  4582. +
  4583. +static int ar231x_mdiobus_read(struct mii_bus *bus, int phy_addr, int regnum);
  4584. +static int ar231x_mdiobus_write(struct mii_bus *bus, int phy_addr, int regnum, u16 value);
  4585. +static int ar231x_mdiobus_reset(struct mii_bus *bus);
  4586. +static int ar231x_mdiobus_probe (struct net_device *dev);
  4587. +static void ar231x_adjust_link(struct net_device *dev);
  4588. +
  4589. +#ifndef ERR
  4590. +#define ERR(fmt, args...) printk("%s: " fmt, __func__, ##args)
  4591. +#endif
  4592. +
  4593. +#ifdef CONFIG_NET_POLL_CONTROLLER
  4594. +static void
  4595. +ar231x_netpoll(struct net_device *dev)
  4596. +{
  4597. + unsigned long flags;
  4598. +
  4599. + local_irq_save(flags);
  4600. + ar231x_interrupt(dev->irq, dev);
  4601. + local_irq_restore(flags);
  4602. +}
  4603. +#endif
  4604. +
  4605. +static const struct net_device_ops ar231x_ops = {
  4606. + .ndo_open = ar231x_open,
  4607. + .ndo_stop = ar231x_close,
  4608. + .ndo_start_xmit = ar231x_start_xmit,
  4609. + .ndo_set_multicast_list = ar231x_multicast_list,
  4610. + .ndo_do_ioctl = ar231x_ioctl,
  4611. + .ndo_change_mtu = eth_change_mtu,
  4612. + .ndo_validate_addr = eth_validate_addr,
  4613. + .ndo_set_mac_address = eth_mac_addr,
  4614. + .ndo_tx_timeout = ar231x_tx_timeout,
  4615. +#ifdef CONFIG_NET_POLL_CONTROLLER
  4616. + .ndo_poll_controller = ar231x_netpoll,
  4617. +#endif
  4618. +};
  4619. +
  4620. +int __init ar231x_probe(struct platform_device *pdev)
  4621. +{
  4622. + struct net_device *dev;
  4623. + struct ar231x_private *sp;
  4624. + struct resource *res;
  4625. + unsigned long ar_eth_base;
  4626. + char buf[64];
  4627. +
  4628. + dev = alloc_etherdev(sizeof(struct ar231x_private));
  4629. +
  4630. + if (dev == NULL) {
  4631. + printk(KERN_ERR
  4632. + "ar231x: Unable to allocate net_device structure!\n");
  4633. + return -ENOMEM;
  4634. + }
  4635. +
  4636. + platform_set_drvdata(pdev, dev);
  4637. +
  4638. + sp = netdev_priv(dev);
  4639. + sp->dev = dev;
  4640. + sp->cfg = pdev->dev.platform_data;
  4641. +
  4642. + sprintf(buf, "eth%d_membase", pdev->id);
  4643. + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, buf);
  4644. + if (!res)
  4645. + return -ENODEV;
  4646. +
  4647. + sp->link = 0;
  4648. + ar_eth_base = res->start;
  4649. +
  4650. + sprintf(buf, "eth%d_irq", pdev->id);
  4651. + dev->irq = platform_get_irq_byname(pdev, buf);
  4652. +
  4653. + spin_lock_init(&sp->lock);
  4654. +
  4655. + dev->features |= NETIF_F_HIGHDMA;
  4656. + dev->netdev_ops = &ar231x_ops;
  4657. +
  4658. + tasklet_init(&sp->rx_tasklet, rx_tasklet_func, (unsigned long) dev);
  4659. + tasklet_disable(&sp->rx_tasklet);
  4660. +
  4661. + sp->eth_regs =
  4662. + ioremap_nocache(virt_to_phys(ar_eth_base), sizeof(*sp->eth_regs));
  4663. + if (!sp->eth_regs) {
  4664. + printk("Can't remap eth registers\n");
  4665. + return (-ENXIO);
  4666. + }
  4667. +
  4668. + /*
  4669. + * When there's only one MAC, PHY regs are typically on ENET0,
  4670. + * even though the MAC might be on ENET1.
  4671. + * Needto remap PHY regs separately in this case
  4672. + */
  4673. + if (virt_to_phys(ar_eth_base) == virt_to_phys(sp->phy_regs))
  4674. + sp->phy_regs = sp->eth_regs;
  4675. + else {
  4676. + sp->phy_regs =
  4677. + ioremap_nocache(virt_to_phys(sp->cfg->phy_base),
  4678. + sizeof(*sp->phy_regs));
  4679. + if (!sp->phy_regs) {
  4680. + printk("Can't remap phy registers\n");
  4681. + return (-ENXIO);
  4682. + }
  4683. + }
  4684. +
  4685. + sp->dma_regs =
  4686. + ioremap_nocache(virt_to_phys(ar_eth_base + 0x1000),
  4687. + sizeof(*sp->dma_regs));
  4688. + dev->base_addr = (unsigned int) sp->dma_regs;
  4689. + if (!sp->dma_regs) {
  4690. + printk("Can't remap DMA registers\n");
  4691. + return (-ENXIO);
  4692. + }
  4693. +
  4694. + sp->int_regs = ioremap_nocache(virt_to_phys(sp->cfg->reset_base), 4);
  4695. + if (!sp->int_regs) {
  4696. + printk("Can't remap INTERRUPT registers\n");
  4697. + return (-ENXIO);
  4698. + }
  4699. +
  4700. + strncpy(sp->name, "Atheros AR231x", sizeof(sp->name) - 1);
  4701. + sp->name[sizeof(sp->name) - 1] = '\0';
  4702. + memcpy(dev->dev_addr, sp->cfg->macaddr, 6);
  4703. +
  4704. + if (ar231x_init(dev)) {
  4705. + /*
  4706. + * ar231x_init() calls ar231x_init_cleanup() on error.
  4707. + */
  4708. + kfree(dev);
  4709. + return -ENODEV;
  4710. + }
  4711. +
  4712. + if (register_netdev(dev)) {
  4713. + printk("%s: register_netdev failed\n", __func__);
  4714. + return -1;
  4715. + }
  4716. +
  4717. + printk("%s: %s: %02x:%02x:%02x:%02x:%02x:%02x, irq %d\n",
  4718. + dev->name, sp->name,
  4719. + dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
  4720. + dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5], dev->irq);
  4721. +
  4722. + sp->mii_bus = mdiobus_alloc();
  4723. + if (sp->mii_bus == NULL)
  4724. + return -1;
  4725. +
  4726. + sp->mii_bus->priv = dev;
  4727. + sp->mii_bus->read = ar231x_mdiobus_read;
  4728. + sp->mii_bus->write = ar231x_mdiobus_write;
  4729. + sp->mii_bus->reset = ar231x_mdiobus_reset;
  4730. + sp->mii_bus->name = "ar231x_eth_mii";
  4731. + snprintf(sp->mii_bus->id, MII_BUS_ID_SIZE, "%d", pdev->id);
  4732. + sp->mii_bus->irq = kmalloc(sizeof(int), GFP_KERNEL);
  4733. + *sp->mii_bus->irq = PHY_POLL;
  4734. +
  4735. + mdiobus_register(sp->mii_bus);
  4736. +
  4737. + if (ar231x_mdiobus_probe(dev) != 0) {
  4738. + printk(KERN_ERR "%s: mdiobus_probe failed\n", dev->name);
  4739. + rx_tasklet_cleanup(dev);
  4740. + ar231x_init_cleanup(dev);
  4741. + unregister_netdev(dev);
  4742. + kfree(dev);
  4743. + return -ENODEV;
  4744. + }
  4745. +
  4746. + /* start link poll timer */
  4747. + ar231x_setup_timer(dev);
  4748. +
  4749. + return 0;
  4750. +}
  4751. +
  4752. +
  4753. +static void ar231x_multicast_list(struct net_device *dev)
  4754. +{
  4755. + struct ar231x_private *sp = netdev_priv(dev);
  4756. + unsigned int filter;
  4757. +
  4758. + filter = sp->eth_regs->mac_control;
  4759. +
  4760. + if (dev->flags & IFF_PROMISC)
  4761. + filter |= MAC_CONTROL_PR;
  4762. + else
  4763. + filter &= ~MAC_CONTROL_PR;
  4764. + if ((dev->flags & IFF_ALLMULTI) || (netdev_mc_count(dev) > 0))
  4765. + filter |= MAC_CONTROL_PM;
  4766. + else
  4767. + filter &= ~MAC_CONTROL_PM;
  4768. +
  4769. + sp->eth_regs->mac_control = filter;
  4770. +}
  4771. +
  4772. +static void rx_tasklet_cleanup(struct net_device *dev)
  4773. +{
  4774. + struct ar231x_private *sp = netdev_priv(dev);
  4775. +
  4776. + /*
  4777. + * Tasklet may be scheduled. Need to get it removed from the list
  4778. + * since we're about to free the struct.
  4779. + */
  4780. +
  4781. + sp->unloading = 1;
  4782. + tasklet_enable(&sp->rx_tasklet);
  4783. + tasklet_kill(&sp->rx_tasklet);
  4784. +}
  4785. +
  4786. +static int __devexit ar231x_remove(struct platform_device *pdev)
  4787. +{
  4788. + struct net_device *dev = platform_get_drvdata(pdev);
  4789. + struct ar231x_private *sp = netdev_priv(dev);
  4790. + rx_tasklet_cleanup(dev);
  4791. + ar231x_init_cleanup(dev);
  4792. + unregister_netdev(dev);
  4793. + mdiobus_unregister(sp->mii_bus);
  4794. + mdiobus_free(sp->mii_bus);
  4795. + kfree(dev);
  4796. + return 0;
  4797. +}
  4798. +
  4799. +
  4800. +/*
  4801. + * Restart the AR2313 ethernet controller.
  4802. + */
  4803. +static int ar231x_restart(struct net_device *dev)
  4804. +{
  4805. + /* disable interrupts */
  4806. + disable_irq(dev->irq);
  4807. +
  4808. + /* stop mac */
  4809. + ar231x_halt(dev);
  4810. +
  4811. + /* initialize */
  4812. + ar231x_init(dev);
  4813. +
  4814. + /* enable interrupts */
  4815. + enable_irq(dev->irq);
  4816. +
  4817. + return 0;
  4818. +}
  4819. +
  4820. +static struct platform_driver ar231x_driver = {
  4821. + .driver.name = "ar231x-eth",
  4822. + .probe = ar231x_probe,
  4823. + .remove = __devexit_p(ar231x_remove),
  4824. +};
  4825. +
  4826. +int __init ar231x_module_init(void)
  4827. +{
  4828. + return platform_driver_register(&ar231x_driver);
  4829. +}
  4830. +
  4831. +void __exit ar231x_module_cleanup(void)
  4832. +{
  4833. + platform_driver_unregister(&ar231x_driver);
  4834. +}
  4835. +
  4836. +module_init(ar231x_module_init);
  4837. +module_exit(ar231x_module_cleanup);
  4838. +
  4839. +
  4840. +static void ar231x_free_descriptors(struct net_device *dev)
  4841. +{
  4842. + struct ar231x_private *sp = netdev_priv(dev);
  4843. + if (sp->rx_ring != NULL) {
  4844. + kfree((void *) KSEG0ADDR(sp->rx_ring));
  4845. + sp->rx_ring = NULL;
  4846. + sp->tx_ring = NULL;
  4847. + }
  4848. +}
  4849. +
  4850. +
  4851. +static int ar231x_allocate_descriptors(struct net_device *dev)
  4852. +{
  4853. + struct ar231x_private *sp = netdev_priv(dev);
  4854. + int size;
  4855. + int j;
  4856. + ar231x_descr_t *space;
  4857. +
  4858. + if (sp->rx_ring != NULL) {
  4859. + printk("%s: already done.\n", __FUNCTION__);
  4860. + return 0;
  4861. + }
  4862. +
  4863. + size =
  4864. + (sizeof(ar231x_descr_t) * (AR2313_DESCR_ENTRIES * AR2313_QUEUES));
  4865. + space = kmalloc(size, GFP_KERNEL);
  4866. + if (space == NULL)
  4867. + return 1;
  4868. +
  4869. + /* invalidate caches */
  4870. + dma_cache_inv((unsigned int) space, size);
  4871. +
  4872. + /* now convert pointer to KSEG1 */
  4873. + space = (ar231x_descr_t *) KSEG1ADDR(space);
  4874. +
  4875. + memset((void *) space, 0, size);
  4876. +
  4877. + sp->rx_ring = space;
  4878. + space += AR2313_DESCR_ENTRIES;
  4879. +
  4880. + sp->tx_ring = space;
  4881. + space += AR2313_DESCR_ENTRIES;
  4882. +
  4883. + /* Initialize the transmit Descriptors */
  4884. + for (j = 0; j < AR2313_DESCR_ENTRIES; j++) {
  4885. + ar231x_descr_t *td = &sp->tx_ring[j];
  4886. + td->status = 0;
  4887. + td->devcs = DMA_TX1_CHAINED;
  4888. + td->addr = 0;
  4889. + td->descr =
  4890. + virt_to_phys(&sp->
  4891. + tx_ring[(j + 1) & (AR2313_DESCR_ENTRIES - 1)]);
  4892. + }
  4893. +
  4894. + return 0;
  4895. +}
  4896. +
  4897. +
  4898. +/*
  4899. + * Generic cleanup handling data allocated during init. Used when the
  4900. + * module is unloaded or if an error occurs during initialization
  4901. + */
  4902. +static void ar231x_init_cleanup(struct net_device *dev)
  4903. +{
  4904. + struct ar231x_private *sp = netdev_priv(dev);
  4905. + struct sk_buff *skb;
  4906. + int j;
  4907. +
  4908. + ar231x_free_descriptors(dev);
  4909. +
  4910. + if (sp->eth_regs)
  4911. + iounmap((void *) sp->eth_regs);
  4912. + if (sp->dma_regs)
  4913. + iounmap((void *) sp->dma_regs);
  4914. +
  4915. + if (sp->rx_skb) {
  4916. + for (j = 0; j < AR2313_DESCR_ENTRIES; j++) {
  4917. + skb = sp->rx_skb[j];
  4918. + if (skb) {
  4919. + sp->rx_skb[j] = NULL;
  4920. + dev_kfree_skb(skb);
  4921. + }
  4922. + }
  4923. + kfree(sp->rx_skb);
  4924. + sp->rx_skb = NULL;
  4925. + }
  4926. +
  4927. + if (sp->tx_skb) {
  4928. + for (j = 0; j < AR2313_DESCR_ENTRIES; j++) {
  4929. + skb = sp->tx_skb[j];
  4930. + if (skb) {
  4931. + sp->tx_skb[j] = NULL;
  4932. + dev_kfree_skb(skb);
  4933. + }
  4934. + }
  4935. + kfree(sp->tx_skb);
  4936. + sp->tx_skb = NULL;
  4937. + }
  4938. +}
  4939. +
  4940. +static int ar231x_setup_timer(struct net_device *dev)
  4941. +{
  4942. + struct ar231x_private *sp = netdev_priv(dev);
  4943. +
  4944. + init_timer(&sp->link_timer);
  4945. +
  4946. + sp->link_timer.function = ar231x_link_timer_fn;
  4947. + sp->link_timer.data = (int) dev;
  4948. + sp->link_timer.expires = jiffies + HZ;
  4949. +
  4950. + add_timer(&sp->link_timer);
  4951. + return 0;
  4952. +
  4953. +}
  4954. +
  4955. +static void ar231x_link_timer_fn(unsigned long data)
  4956. +{
  4957. + struct net_device *dev = (struct net_device *) data;
  4958. + struct ar231x_private *sp = netdev_priv(dev);
  4959. +
  4960. + // see if the link status changed
  4961. + // This was needed to make sure we set the PHY to the
  4962. + // autonegotiated value of half or full duplex.
  4963. + ar231x_check_link(dev);
  4964. +
  4965. + // Loop faster when we don't have link.
  4966. + // This was needed to speed up the AP bootstrap time.
  4967. + if (sp->link == 0) {
  4968. + mod_timer(&sp->link_timer, jiffies + HZ / 2);
  4969. + } else {
  4970. + mod_timer(&sp->link_timer, jiffies + LINK_TIMER);
  4971. + }
  4972. +}
  4973. +
  4974. +static void ar231x_check_link(struct net_device *dev)
  4975. +{
  4976. + struct ar231x_private *sp = netdev_priv(dev);
  4977. + u16 phyData;
  4978. +
  4979. + phyData = ar231x_mdiobus_read(sp->mii_bus, sp->phy, MII_BMSR);
  4980. + if (sp->phyData != phyData) {
  4981. + if (phyData & BMSR_LSTATUS) {
  4982. + /* link is present, ready link partner ability to deterine
  4983. + duplexity */
  4984. + int duplex = 0;
  4985. + u16 reg;
  4986. +
  4987. + sp->link = 1;
  4988. + reg = ar231x_mdiobus_read(sp->mii_bus, sp->phy, MII_BMCR);
  4989. + if (reg & BMCR_ANENABLE) {
  4990. + /* auto neg enabled */
  4991. + reg = ar231x_mdiobus_read(sp->mii_bus, sp->phy, MII_LPA);
  4992. + duplex = (reg & (LPA_100FULL | LPA_10FULL)) ? 1 : 0;
  4993. + } else {
  4994. + /* no auto neg, just read duplex config */
  4995. + duplex = (reg & BMCR_FULLDPLX) ? 1 : 0;
  4996. + }
  4997. +
  4998. + printk(KERN_INFO "%s: Configuring MAC for %s duplex\n",
  4999. + dev->name, (duplex) ? "full" : "half");
  5000. +
  5001. + if (duplex) {
  5002. + /* full duplex */
  5003. + sp->eth_regs->mac_control =
  5004. + ((sp->eth_regs->
  5005. + mac_control | MAC_CONTROL_F) & ~MAC_CONTROL_DRO);
  5006. + } else {
  5007. + /* half duplex */
  5008. + sp->eth_regs->mac_control =
  5009. + ((sp->eth_regs->
  5010. + mac_control | MAC_CONTROL_DRO) & ~MAC_CONTROL_F);
  5011. + }
  5012. + } else {
  5013. + /* no link */
  5014. + sp->link = 0;
  5015. + }
  5016. + sp->phyData = phyData;
  5017. + }
  5018. +}
  5019. +
  5020. +static int ar231x_reset_reg(struct net_device *dev)
  5021. +{
  5022. + struct ar231x_private *sp = netdev_priv(dev);
  5023. + unsigned int ethsal, ethsah;
  5024. + unsigned int flags;
  5025. +
  5026. + *sp->int_regs |= sp->cfg->reset_mac;
  5027. + mdelay(10);
  5028. + *sp->int_regs &= ~sp->cfg->reset_mac;
  5029. + mdelay(10);
  5030. + *sp->int_regs |= sp->cfg->reset_phy;
  5031. + mdelay(10);
  5032. + *sp->int_regs &= ~sp->cfg->reset_phy;
  5033. + mdelay(10);
  5034. +
  5035. + sp->dma_regs->bus_mode = (DMA_BUS_MODE_SWR);
  5036. + mdelay(10);
  5037. + sp->dma_regs->bus_mode =
  5038. + ((32 << DMA_BUS_MODE_PBL_SHIFT) | DMA_BUS_MODE_BLE);
  5039. +
  5040. + /* enable interrupts */
  5041. + sp->dma_regs->intr_ena = (DMA_STATUS_AIS |
  5042. + DMA_STATUS_NIS |
  5043. + DMA_STATUS_RI |
  5044. + DMA_STATUS_TI | DMA_STATUS_FBE);
  5045. + sp->dma_regs->xmt_base = virt_to_phys(sp->tx_ring);
  5046. + sp->dma_regs->rcv_base = virt_to_phys(sp->rx_ring);
  5047. + sp->dma_regs->control =
  5048. + (DMA_CONTROL_SR | DMA_CONTROL_ST | DMA_CONTROL_SF);
  5049. +
  5050. + sp->eth_regs->flow_control = (FLOW_CONTROL_FCE);
  5051. + sp->eth_regs->vlan_tag = (0x8100);
  5052. +
  5053. + /* Enable Ethernet Interface */
  5054. + flags = (MAC_CONTROL_TE | /* transmit enable */
  5055. + MAC_CONTROL_PM | /* pass mcast */
  5056. + MAC_CONTROL_F | /* full duplex */
  5057. + MAC_CONTROL_HBD); /* heart beat disabled */
  5058. +
  5059. + if (dev->flags & IFF_PROMISC) { /* set promiscuous mode */
  5060. + flags |= MAC_CONTROL_PR;
  5061. + }
  5062. + sp->eth_regs->mac_control = flags;
  5063. +
  5064. + /* Set all Ethernet station address registers to their initial values */
  5065. + ethsah = ((((u_int) (dev->dev_addr[5]) << 8) & (u_int) 0x0000FF00) |
  5066. + (((u_int) (dev->dev_addr[4]) << 0) & (u_int) 0x000000FF));
  5067. +
  5068. + ethsal = ((((u_int) (dev->dev_addr[3]) << 24) & (u_int) 0xFF000000) |
  5069. + (((u_int) (dev->dev_addr[2]) << 16) & (u_int) 0x00FF0000) |
  5070. + (((u_int) (dev->dev_addr[1]) << 8) & (u_int) 0x0000FF00) |
  5071. + (((u_int) (dev->dev_addr[0]) << 0) & (u_int) 0x000000FF));
  5072. +
  5073. + sp->eth_regs->mac_addr[0] = ethsah;
  5074. + sp->eth_regs->mac_addr[1] = ethsal;
  5075. +
  5076. + mdelay(10);
  5077. +
  5078. + return (0);
  5079. +}
  5080. +
  5081. +
  5082. +static int ar231x_init(struct net_device *dev)
  5083. +{
  5084. + struct ar231x_private *sp = netdev_priv(dev);
  5085. + int ecode = 0;
  5086. +
  5087. + /*
  5088. + * Allocate descriptors
  5089. + */
  5090. + if (ar231x_allocate_descriptors(dev)) {
  5091. + printk("%s: %s: ar231x_allocate_descriptors failed\n",
  5092. + dev->name, __FUNCTION__);
  5093. + ecode = -EAGAIN;
  5094. + goto init_error;
  5095. + }
  5096. +
  5097. + /*
  5098. + * Get the memory for the skb rings.
  5099. + */
  5100. + if (sp->rx_skb == NULL) {
  5101. + sp->rx_skb =
  5102. + kmalloc(sizeof(struct sk_buff *) * AR2313_DESCR_ENTRIES,
  5103. + GFP_KERNEL);
  5104. + if (!(sp->rx_skb)) {
  5105. + printk("%s: %s: rx_skb kmalloc failed\n",
  5106. + dev->name, __FUNCTION__);
  5107. + ecode = -EAGAIN;
  5108. + goto init_error;
  5109. + }
  5110. + }
  5111. + memset(sp->rx_skb, 0, sizeof(struct sk_buff *) * AR2313_DESCR_ENTRIES);
  5112. +
  5113. + if (sp->tx_skb == NULL) {
  5114. + sp->tx_skb =
  5115. + kmalloc(sizeof(struct sk_buff *) * AR2313_DESCR_ENTRIES,
  5116. + GFP_KERNEL);
  5117. + if (!(sp->tx_skb)) {
  5118. + printk("%s: %s: tx_skb kmalloc failed\n",
  5119. + dev->name, __FUNCTION__);
  5120. + ecode = -EAGAIN;
  5121. + goto init_error;
  5122. + }
  5123. + }
  5124. + memset(sp->tx_skb, 0, sizeof(struct sk_buff *) * AR2313_DESCR_ENTRIES);
  5125. +
  5126. + /*
  5127. + * Set tx_csm before we start receiving interrupts, otherwise
  5128. + * the interrupt handler might think it is supposed to process
  5129. + * tx ints before we are up and running, which may cause a null
  5130. + * pointer access in the int handler.
  5131. + */
  5132. + sp->rx_skbprd = 0;
  5133. + sp->cur_rx = 0;
  5134. + sp->tx_prd = 0;
  5135. + sp->tx_csm = 0;
  5136. +
  5137. + /*
  5138. + * Zero the stats before starting the interface
  5139. + */
  5140. + memset(&dev->stats, 0, sizeof(dev->stats));
  5141. +
  5142. + /*
  5143. + * We load the ring here as there seem to be no way to tell the
  5144. + * firmware to wipe the ring without re-initializing it.
  5145. + */
  5146. + ar231x_load_rx_ring(dev, RX_RING_SIZE);
  5147. +
  5148. + /*
  5149. + * Init hardware
  5150. + */
  5151. + ar231x_reset_reg(dev);
  5152. +
  5153. + /*
  5154. + * Get the IRQ
  5155. + */
  5156. + ecode =
  5157. + request_irq(dev->irq, &ar231x_interrupt,
  5158. + IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
  5159. + dev->name, dev);
  5160. + if (ecode) {
  5161. + printk(KERN_WARNING "%s: %s: Requested IRQ %d is busy\n",
  5162. + dev->name, __FUNCTION__, dev->irq);
  5163. + goto init_error;
  5164. + }
  5165. +
  5166. +
  5167. + tasklet_enable(&sp->rx_tasklet);
  5168. +
  5169. + return 0;
  5170. +
  5171. + init_error:
  5172. + ar231x_init_cleanup(dev);
  5173. + return ecode;
  5174. +}
  5175. +
  5176. +/*
  5177. + * Load the rx ring.
  5178. + *
  5179. + * Loading rings is safe without holding the spin lock since this is
  5180. + * done only before the device is enabled, thus no interrupts are
  5181. + * generated and by the interrupt handler/tasklet handler.
  5182. + */
  5183. +static void ar231x_load_rx_ring(struct net_device *dev, int nr_bufs)
  5184. +{
  5185. +
  5186. + struct ar231x_private *sp = netdev_priv(dev);
  5187. + short i, idx;
  5188. +
  5189. + idx = sp->rx_skbprd;
  5190. +
  5191. + for (i = 0; i < nr_bufs; i++) {
  5192. + struct sk_buff *skb;
  5193. + ar231x_descr_t *rd;
  5194. +
  5195. + if (sp->rx_skb[idx])
  5196. + break;
  5197. +
  5198. + skb = netdev_alloc_skb(dev, AR2313_BUFSIZE);
  5199. + if (!skb) {
  5200. + printk("\n\n\n\n %s: No memory in system\n\n\n\n",
  5201. + __FUNCTION__);
  5202. + break;
  5203. + }
  5204. +
  5205. + /*
  5206. + * Make sure IP header starts on a fresh cache line.
  5207. + */
  5208. + skb->dev = dev;
  5209. + skb_reserve(skb, RX_OFFSET);
  5210. + sp->rx_skb[idx] = skb;
  5211. +
  5212. + rd = (ar231x_descr_t *) & sp->rx_ring[idx];
  5213. +
  5214. + /* initialize dma descriptor */
  5215. + rd->devcs = ((AR2313_BUFSIZE << DMA_RX1_BSIZE_SHIFT) |
  5216. + DMA_RX1_CHAINED);
  5217. + rd->addr = virt_to_phys(skb->data);
  5218. + rd->descr =
  5219. + virt_to_phys(&sp->
  5220. + rx_ring[(idx + 1) & (AR2313_DESCR_ENTRIES - 1)]);
  5221. + rd->status = DMA_RX_OWN;
  5222. +
  5223. + idx = DSC_NEXT(idx);
  5224. + }
  5225. +
  5226. + if (i)
  5227. + sp->rx_skbprd = idx;
  5228. +
  5229. + return;
  5230. +}
  5231. +
  5232. +#define AR2313_MAX_PKTS_PER_CALL 64
  5233. +
  5234. +static int ar231x_rx_int(struct net_device *dev)
  5235. +{
  5236. + struct ar231x_private *sp = netdev_priv(dev);
  5237. + struct sk_buff *skb, *skb_new;
  5238. + ar231x_descr_t *rxdesc;
  5239. + unsigned int status;
  5240. + u32 idx;
  5241. + int pkts = 0;
  5242. + int rval;
  5243. +
  5244. + idx = sp->cur_rx;
  5245. +
  5246. + /* process at most the entire ring and then wait for another interrupt
  5247. + */
  5248. + while (1) {
  5249. +
  5250. + rxdesc = &sp->rx_ring[idx];
  5251. + status = rxdesc->status;
  5252. + if (status & DMA_RX_OWN) {
  5253. + /* SiByte owns descriptor or descr not yet filled in */
  5254. + rval = 0;
  5255. + break;
  5256. + }
  5257. +
  5258. + if (++pkts > AR2313_MAX_PKTS_PER_CALL) {
  5259. + rval = 1;
  5260. + break;
  5261. + }
  5262. +
  5263. + if ((status & DMA_RX_ERROR) && !(status & DMA_RX_LONG)) {
  5264. + dev->stats.rx_errors++;
  5265. + dev->stats.rx_dropped++;
  5266. +
  5267. + /* add statistics counters */
  5268. + if (status & DMA_RX_ERR_CRC)
  5269. + dev->stats.rx_crc_errors++;
  5270. + if (status & DMA_RX_ERR_COL)
  5271. + dev->stats.rx_over_errors++;
  5272. + if (status & DMA_RX_ERR_LENGTH)
  5273. + dev->stats.rx_length_errors++;
  5274. + if (status & DMA_RX_ERR_RUNT)
  5275. + dev->stats.rx_over_errors++;
  5276. + if (status & DMA_RX_ERR_DESC)
  5277. + dev->stats.rx_over_errors++;
  5278. +
  5279. + } else {
  5280. + /* alloc new buffer. */
  5281. + skb_new = netdev_alloc_skb(dev, AR2313_BUFSIZE + RX_OFFSET);
  5282. + if (skb_new != NULL) {
  5283. +
  5284. + skb = sp->rx_skb[idx];
  5285. + /* set skb */
  5286. + skb_put(skb,
  5287. + ((status >> DMA_RX_LEN_SHIFT) & 0x3fff) - CRC_LEN);
  5288. +
  5289. + dev->stats.rx_bytes += skb->len;
  5290. + skb->protocol = eth_type_trans(skb, dev);
  5291. + /* pass the packet to upper layers */
  5292. + netif_rx(skb);
  5293. +
  5294. + skb_new->dev = dev;
  5295. + /* 16 bit align */
  5296. + skb_reserve(skb_new, RX_OFFSET);
  5297. + /* reset descriptor's curr_addr */
  5298. + rxdesc->addr = virt_to_phys(skb_new->data);
  5299. +
  5300. + dev->stats.rx_packets++;
  5301. + sp->rx_skb[idx] = skb_new;
  5302. + } else {
  5303. + dev->stats.rx_dropped++;
  5304. + }
  5305. + }
  5306. +
  5307. + rxdesc->devcs = ((AR2313_BUFSIZE << DMA_RX1_BSIZE_SHIFT) |
  5308. + DMA_RX1_CHAINED);
  5309. + rxdesc->status = DMA_RX_OWN;
  5310. +
  5311. + idx = DSC_NEXT(idx);
  5312. + }
  5313. +
  5314. + sp->cur_rx = idx;
  5315. +
  5316. + return rval;
  5317. +}
  5318. +
  5319. +
  5320. +static void ar231x_tx_int(struct net_device *dev)
  5321. +{
  5322. + struct ar231x_private *sp = netdev_priv(dev);
  5323. + u32 idx;
  5324. + struct sk_buff *skb;
  5325. + ar231x_descr_t *txdesc;
  5326. + unsigned int status = 0;
  5327. +
  5328. + idx = sp->tx_csm;
  5329. +
  5330. + while (idx != sp->tx_prd) {
  5331. + txdesc = &sp->tx_ring[idx];
  5332. +
  5333. + if ((status = txdesc->status) & DMA_TX_OWN) {
  5334. + /* ar231x dma still owns descr */
  5335. + break;
  5336. + }
  5337. + /* done with this descriptor */
  5338. + dma_unmap_single(NULL, txdesc->addr,
  5339. + txdesc->devcs & DMA_TX1_BSIZE_MASK,
  5340. + DMA_TO_DEVICE);
  5341. + txdesc->status = 0;
  5342. +
  5343. + if (status & DMA_TX_ERROR) {
  5344. + dev->stats.tx_errors++;
  5345. + dev->stats.tx_dropped++;
  5346. + if (status & DMA_TX_ERR_UNDER)
  5347. + dev->stats.tx_fifo_errors++;
  5348. + if (status & DMA_TX_ERR_HB)
  5349. + dev->stats.tx_heartbeat_errors++;
  5350. + if (status & (DMA_TX_ERR_LOSS | DMA_TX_ERR_LINK))
  5351. + dev->stats.tx_carrier_errors++;
  5352. + if (status & (DMA_TX_ERR_LATE |
  5353. + DMA_TX_ERR_COL |
  5354. + DMA_TX_ERR_JABBER | DMA_TX_ERR_DEFER))
  5355. + dev->stats.tx_aborted_errors++;
  5356. + } else {
  5357. + /* transmit OK */
  5358. + dev->stats.tx_packets++;
  5359. + }
  5360. +
  5361. + skb = sp->tx_skb[idx];
  5362. + sp->tx_skb[idx] = NULL;
  5363. + idx = DSC_NEXT(idx);
  5364. + dev->stats.tx_bytes += skb->len;
  5365. + dev_kfree_skb_irq(skb);
  5366. + }
  5367. +
  5368. + sp->tx_csm = idx;
  5369. +
  5370. + return;
  5371. +}
  5372. +
  5373. +
  5374. +static void rx_tasklet_func(unsigned long data)
  5375. +{
  5376. + struct net_device *dev = (struct net_device *) data;
  5377. + struct ar231x_private *sp = netdev_priv(dev);
  5378. +
  5379. + if (sp->unloading) {
  5380. + return;
  5381. + }
  5382. +
  5383. + if (ar231x_rx_int(dev)) {
  5384. + tasklet_hi_schedule(&sp->rx_tasklet);
  5385. + } else {
  5386. + unsigned long flags;
  5387. + spin_lock_irqsave(&sp->lock, flags);
  5388. + sp->dma_regs->intr_ena |= DMA_STATUS_RI;
  5389. + spin_unlock_irqrestore(&sp->lock, flags);
  5390. + }
  5391. +}
  5392. +
  5393. +static void rx_schedule(struct net_device *dev)
  5394. +{
  5395. + struct ar231x_private *sp = netdev_priv(dev);
  5396. +
  5397. + sp->dma_regs->intr_ena &= ~DMA_STATUS_RI;
  5398. +
  5399. + tasklet_hi_schedule(&sp->rx_tasklet);
  5400. +}
  5401. +
  5402. +static irqreturn_t ar231x_interrupt(int irq, void *dev_id)
  5403. +{
  5404. + struct net_device *dev = (struct net_device *) dev_id;
  5405. + struct ar231x_private *sp = netdev_priv(dev);
  5406. + unsigned int status, enabled;
  5407. +
  5408. + /* clear interrupt */
  5409. + /*
  5410. + * Don't clear RI bit if currently disabled.
  5411. + */
  5412. + status = sp->dma_regs->status;
  5413. + enabled = sp->dma_regs->intr_ena;
  5414. + sp->dma_regs->status = status & enabled;
  5415. +
  5416. + if (status & DMA_STATUS_NIS) {
  5417. + /* normal status */
  5418. + /*
  5419. + * Don't schedule rx processing if interrupt
  5420. + * is already disabled.
  5421. + */
  5422. + if (status & enabled & DMA_STATUS_RI) {
  5423. + /* receive interrupt */
  5424. + rx_schedule(dev);
  5425. + }
  5426. + if (status & DMA_STATUS_TI) {
  5427. + /* transmit interrupt */
  5428. + ar231x_tx_int(dev);
  5429. + }
  5430. + }
  5431. +
  5432. + /* abnormal status */
  5433. + if (status & (DMA_STATUS_FBE | DMA_STATUS_TPS)) {
  5434. + ar231x_restart(dev);
  5435. + }
  5436. + return IRQ_HANDLED;
  5437. +}
  5438. +
  5439. +
  5440. +static int ar231x_open(struct net_device *dev)
  5441. +{
  5442. + struct ar231x_private *sp = netdev_priv(dev);
  5443. + unsigned int ethsal, ethsah;
  5444. +
  5445. + /* reset the hardware, in case the MAC address changed */
  5446. + ethsah = ((((u_int) (dev->dev_addr[5]) << 8) & (u_int) 0x0000FF00) |
  5447. + (((u_int) (dev->dev_addr[4]) << 0) & (u_int) 0x000000FF));
  5448. +
  5449. + ethsal = ((((u_int) (dev->dev_addr[3]) << 24) & (u_int) 0xFF000000) |
  5450. + (((u_int) (dev->dev_addr[2]) << 16) & (u_int) 0x00FF0000) |
  5451. + (((u_int) (dev->dev_addr[1]) << 8) & (u_int) 0x0000FF00) |
  5452. + (((u_int) (dev->dev_addr[0]) << 0) & (u_int) 0x000000FF));
  5453. +
  5454. + sp->eth_regs->mac_addr[0] = ethsah;
  5455. + sp->eth_regs->mac_addr[1] = ethsal;
  5456. +
  5457. + mdelay(10);
  5458. +
  5459. + dev->mtu = 1500;
  5460. + netif_start_queue(dev);
  5461. +
  5462. + sp->eth_regs->mac_control |= MAC_CONTROL_RE;
  5463. +
  5464. + return 0;
  5465. +}
  5466. +
  5467. +static void ar231x_tx_timeout(struct net_device *dev)
  5468. +{
  5469. + struct ar231x_private *sp = netdev_priv(dev);
  5470. + unsigned long flags;
  5471. +
  5472. + spin_lock_irqsave(&sp->lock, flags);
  5473. + ar231x_restart(dev);
  5474. + spin_unlock_irqrestore(&sp->lock, flags);
  5475. +}
  5476. +
  5477. +static void ar231x_halt(struct net_device *dev)
  5478. +{
  5479. + struct ar231x_private *sp = netdev_priv(dev);
  5480. + int j;
  5481. +
  5482. + tasklet_disable(&sp->rx_tasklet);
  5483. +
  5484. + /* kill the MAC */
  5485. + sp->eth_regs->mac_control &= ~(MAC_CONTROL_RE | /* disable Receives */
  5486. + MAC_CONTROL_TE); /* disable Transmits */
  5487. + /* stop dma */
  5488. + sp->dma_regs->control = 0;
  5489. + sp->dma_regs->bus_mode = DMA_BUS_MODE_SWR;
  5490. +
  5491. + /* place phy and MAC in reset */
  5492. + *sp->int_regs |= (sp->cfg->reset_mac | sp->cfg->reset_phy);
  5493. +
  5494. + /* free buffers on tx ring */
  5495. + for (j = 0; j < AR2313_DESCR_ENTRIES; j++) {
  5496. + struct sk_buff *skb;
  5497. + ar231x_descr_t *txdesc;
  5498. +
  5499. + txdesc = &sp->tx_ring[j];
  5500. + txdesc->descr = 0;
  5501. +
  5502. + skb = sp->tx_skb[j];
  5503. + if (skb) {
  5504. + dev_kfree_skb(skb);
  5505. + sp->tx_skb[j] = NULL;
  5506. + }
  5507. + }
  5508. +}
  5509. +
  5510. +/*
  5511. + * close should do nothing. Here's why. It's called when
  5512. + * 'ifconfig bond0 down' is run. If it calls free_irq then
  5513. + * the irq is gone forever ! When bond0 is made 'up' again,
  5514. + * the ar231x_open () does not call request_irq (). Worse,
  5515. + * the call to ar231x_halt() generates a WDOG reset due to
  5516. + * the write to 'sp->int_regs' and the box reboots.
  5517. + * Commenting this out is good since it allows the
  5518. + * system to resume when bond0 is made up again.
  5519. + */
  5520. +static int ar231x_close(struct net_device *dev)
  5521. +{
  5522. +#if 0
  5523. + /*
  5524. + * Disable interrupts
  5525. + */
  5526. + disable_irq(dev->irq);
  5527. +
  5528. + /*
  5529. + * Without (or before) releasing irq and stopping hardware, this
  5530. + * is an absolute non-sense, by the way. It will be reset instantly
  5531. + * by the first irq.
  5532. + */
  5533. + netif_stop_queue(dev);
  5534. +
  5535. + /* stop the MAC and DMA engines */
  5536. + ar231x_halt(dev);
  5537. +
  5538. + /* release the interrupt */
  5539. + free_irq(dev->irq, dev);
  5540. +
  5541. +#endif
  5542. + return 0;
  5543. +}
  5544. +
  5545. +static int ar231x_start_xmit(struct sk_buff *skb, struct net_device *dev)
  5546. +{
  5547. + struct ar231x_private *sp = netdev_priv(dev);
  5548. + ar231x_descr_t *td;
  5549. + u32 idx;
  5550. +
  5551. + idx = sp->tx_prd;
  5552. + td = &sp->tx_ring[idx];
  5553. +
  5554. + if (td->status & DMA_TX_OWN) {
  5555. + /* free skbuf and lie to the caller that we sent it out */
  5556. + dev->stats.tx_dropped++;
  5557. + dev_kfree_skb(skb);
  5558. +
  5559. + /* restart transmitter in case locked */
  5560. + sp->dma_regs->xmt_poll = 0;
  5561. + return 0;
  5562. + }
  5563. +
  5564. + /* Setup the transmit descriptor. */
  5565. + td->devcs = ((skb->len << DMA_TX1_BSIZE_SHIFT) |
  5566. + (DMA_TX1_LS | DMA_TX1_IC | DMA_TX1_CHAINED));
  5567. + td->addr = dma_map_single(NULL, skb->data, skb->len, DMA_TO_DEVICE);
  5568. + td->status = DMA_TX_OWN;
  5569. +
  5570. + /* kick transmitter last */
  5571. + sp->dma_regs->xmt_poll = 0;
  5572. +
  5573. + sp->tx_skb[idx] = skb;
  5574. + idx = DSC_NEXT(idx);
  5575. + sp->tx_prd = idx;
  5576. +
  5577. + return 0;
  5578. +}
  5579. +
  5580. +static int ar231x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  5581. +{
  5582. + struct mii_ioctl_data *data = (struct mii_ioctl_data *) &ifr->ifr_data;
  5583. + struct ar231x_private *sp = netdev_priv(dev);
  5584. + int ret;
  5585. +
  5586. + switch (cmd) {
  5587. +
  5588. + case SIOCETHTOOL:
  5589. + spin_lock_irq(&sp->lock);
  5590. + ret = phy_ethtool_ioctl(sp->phy_dev, (void *) ifr->ifr_data);
  5591. + spin_unlock_irq(&sp->lock);
  5592. + return ret;
  5593. +
  5594. + case SIOCSIFHWADDR:
  5595. + if (copy_from_user
  5596. + (dev->dev_addr, ifr->ifr_data, sizeof(dev->dev_addr)))
  5597. + return -EFAULT;
  5598. + return 0;
  5599. +
  5600. + case SIOCGIFHWADDR:
  5601. + if (copy_to_user
  5602. + (ifr->ifr_data, dev->dev_addr, sizeof(dev->dev_addr)))
  5603. + return -EFAULT;
  5604. + return 0;
  5605. +
  5606. + case SIOCGMIIPHY:
  5607. + case SIOCGMIIREG:
  5608. + case SIOCSMIIREG:
  5609. + return phy_mii_ioctl(sp->phy_dev, data, cmd);
  5610. +
  5611. + default:
  5612. + break;
  5613. + }
  5614. +
  5615. + return -EOPNOTSUPP;
  5616. +}
  5617. +
  5618. +static void ar231x_adjust_link(struct net_device *dev)
  5619. +{
  5620. + struct ar231x_private *sp = netdev_priv(dev);
  5621. + unsigned int mc;
  5622. +
  5623. + if (!sp->phy_dev->link)
  5624. + return;
  5625. +
  5626. + if (sp->phy_dev->duplex != sp->oldduplex) {
  5627. + mc = readl(&sp->eth_regs->mac_control);
  5628. + mc &= ~(MAC_CONTROL_F | MAC_CONTROL_DRO);
  5629. + if (sp->phy_dev->duplex)
  5630. + mc |= MAC_CONTROL_F;
  5631. + else
  5632. + mc |= MAC_CONTROL_DRO;
  5633. + writel(mc, &sp->eth_regs->mac_control);
  5634. + sp->oldduplex = sp->phy_dev->duplex;
  5635. + }
  5636. +}
  5637. +
  5638. +#define MII_ADDR(phy, reg) \
  5639. + ((reg << MII_ADDR_REG_SHIFT) | (phy << MII_ADDR_PHY_SHIFT))
  5640. +
  5641. +static int
  5642. +ar231x_mdiobus_read(struct mii_bus *bus, int phy_addr, int regnum)
  5643. +{
  5644. + struct net_device *const dev = bus->priv;
  5645. + struct ar231x_private *sp = netdev_priv(dev);
  5646. + volatile ETHERNET_STRUCT *ethernet = sp->phy_regs;
  5647. +
  5648. + ethernet->mii_addr = MII_ADDR(phy_addr, regnum);
  5649. + while (ethernet->mii_addr & MII_ADDR_BUSY);
  5650. + return (ethernet->mii_data >> MII_DATA_SHIFT);
  5651. +}
  5652. +
  5653. +static int
  5654. +ar231x_mdiobus_write(struct mii_bus *bus, int phy_addr, int regnum,
  5655. + u16 value)
  5656. +{
  5657. + struct net_device *const dev = bus->priv;
  5658. + struct ar231x_private *sp = netdev_priv(dev);
  5659. + volatile ETHERNET_STRUCT *ethernet = sp->phy_regs;
  5660. +
  5661. + while (ethernet->mii_addr & MII_ADDR_BUSY);
  5662. + ethernet->mii_data = value << MII_DATA_SHIFT;
  5663. + ethernet->mii_addr = MII_ADDR(phy_addr, regnum) | MII_ADDR_WRITE;
  5664. +
  5665. + return 0;
  5666. +}
  5667. +
  5668. +static int ar231x_mdiobus_reset(struct mii_bus *bus)
  5669. +{
  5670. + struct net_device *const dev = bus->priv;
  5671. +
  5672. + ar231x_reset_reg(dev);
  5673. +
  5674. + return 0;
  5675. +}
  5676. +
  5677. +static int ar231x_mdiobus_probe (struct net_device *dev)
  5678. +{
  5679. + struct ar231x_private *const sp = netdev_priv(dev);
  5680. + struct phy_device *phydev = NULL;
  5681. + int phy_addr;
  5682. +
  5683. + /* find the first (lowest address) PHY on the current MAC's MII bus */
  5684. + for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++)
  5685. + if (sp->mii_bus->phy_map[phy_addr]) {
  5686. + phydev = sp->mii_bus->phy_map[phy_addr];
  5687. + sp->phy = phy_addr;
  5688. + break; /* break out with first one found */
  5689. + }
  5690. +
  5691. + if (!phydev) {
  5692. + printk (KERN_ERR "ar231x: %s: no PHY found\n", dev->name);
  5693. + return -1;
  5694. + }
  5695. +
  5696. + /* now we are supposed to have a proper phydev, to attach to... */
  5697. + BUG_ON(!phydev);
  5698. + BUG_ON(phydev->attached_dev);
  5699. +
  5700. + phydev = phy_connect(dev, dev_name(&phydev->dev), &ar231x_adjust_link, 0,
  5701. + PHY_INTERFACE_MODE_MII);
  5702. +
  5703. + if (IS_ERR(phydev)) {
  5704. + printk(KERN_ERR "%s: Could not attach to PHY\n", dev->name);
  5705. + return PTR_ERR(phydev);
  5706. + }
  5707. +
  5708. + /* mask with MAC supported features */
  5709. + phydev->supported &= (SUPPORTED_10baseT_Half
  5710. + | SUPPORTED_10baseT_Full
  5711. + | SUPPORTED_100baseT_Half
  5712. + | SUPPORTED_100baseT_Full
  5713. + | SUPPORTED_Autoneg
  5714. + /* | SUPPORTED_Pause | SUPPORTED_Asym_Pause */
  5715. + | SUPPORTED_MII
  5716. + | SUPPORTED_TP);
  5717. +
  5718. + phydev->advertising = phydev->supported;
  5719. +
  5720. + sp->oldduplex = -1;
  5721. + sp->phy_dev = phydev;
  5722. +
  5723. + printk(KERN_INFO "%s: attached PHY driver [%s] "
  5724. + "(mii_bus:phy_addr=%s)\n",
  5725. + dev->name, phydev->drv->name, dev_name(&phydev->dev));
  5726. +
  5727. + return 0;
  5728. +}
  5729. +
  5730. diff -Nur linux-2.6.39-rc7.orig/drivers/net/ar231x.h linux-2.6.39-rc7/drivers/net/ar231x.h
  5731. --- linux-2.6.39-rc7.orig/drivers/net/ar231x.h 1970-01-01 01:00:00.000000000 +0100
  5732. +++ linux-2.6.39-rc7/drivers/net/ar231x.h 2011-05-15 21:34:57.000000000 +0200
  5733. @@ -0,0 +1,302 @@
  5734. +/*
  5735. + * ar231x.h: Linux driver for the Atheros AR231x Ethernet device.
  5736. + *
  5737. + * Copyright (C) 2004 by Sameer Dekate <sdekate@arubanetworks.com>
  5738. + * Copyright (C) 2006 Imre Kaloz <kaloz@openwrt.org>
  5739. + * Copyright (C) 2006-2009 Felix Fietkau <nbd@openwrt.org>
  5740. + *
  5741. + * Thanks to Atheros for providing hardware and documentation
  5742. + * enabling me to write this driver.
  5743. + *
  5744. + * This program is free software; you can redistribute it and/or modify
  5745. + * it under the terms of the GNU General Public License as published by
  5746. + * the Free Software Foundation; either version 2 of the License, or
  5747. + * (at your option) any later version.
  5748. + */
  5749. +
  5750. +#ifndef _AR2313_H_
  5751. +#define _AR2313_H_
  5752. +
  5753. +#include <generated/autoconf.h>
  5754. +#include <linux/bitops.h>
  5755. +#include <asm/bootinfo.h>
  5756. +#include <ar231x_platform.h>
  5757. +
  5758. +/*
  5759. + * probe link timer - 5 secs
  5760. + */
  5761. +#define LINK_TIMER (5*HZ)
  5762. +
  5763. +#define IS_DMA_TX_INT(X) (((X) & (DMA_STATUS_TI)) != 0)
  5764. +#define IS_DMA_RX_INT(X) (((X) & (DMA_STATUS_RI)) != 0)
  5765. +#define IS_DRIVER_OWNED(X) (((X) & (DMA_TX_OWN)) == 0)
  5766. +
  5767. +#define AR2313_TX_TIMEOUT (HZ/4)
  5768. +
  5769. +/*
  5770. + * Rings
  5771. + */
  5772. +#define DSC_RING_ENTRIES_SIZE (AR2313_DESCR_ENTRIES * sizeof(struct desc))
  5773. +#define DSC_NEXT(idx) ((idx + 1) & (AR2313_DESCR_ENTRIES - 1))
  5774. +
  5775. +#define AR2313_MBGET 2
  5776. +#define AR2313_MBSET 3
  5777. +#define AR2313_PCI_RECONFIG 4
  5778. +#define AR2313_PCI_DUMP 5
  5779. +#define AR2313_TEST_PANIC 6
  5780. +#define AR2313_TEST_NULLPTR 7
  5781. +#define AR2313_READ_DATA 8
  5782. +#define AR2313_WRITE_DATA 9
  5783. +#define AR2313_GET_VERSION 10
  5784. +#define AR2313_TEST_HANG 11
  5785. +#define AR2313_SYNC 12
  5786. +
  5787. +#define DMA_RX_ERR_CRC BIT(1)
  5788. +#define DMA_RX_ERR_DRIB BIT(2)
  5789. +#define DMA_RX_ERR_MII BIT(3)
  5790. +#define DMA_RX_EV2 BIT(5)
  5791. +#define DMA_RX_ERR_COL BIT(6)
  5792. +#define DMA_RX_LONG BIT(7)
  5793. +#define DMA_RX_LS BIT(8) /* last descriptor */
  5794. +#define DMA_RX_FS BIT(9) /* first descriptor */
  5795. +#define DMA_RX_MF BIT(10) /* multicast frame */
  5796. +#define DMA_RX_ERR_RUNT BIT(11) /* runt frame */
  5797. +#define DMA_RX_ERR_LENGTH BIT(12) /* length error */
  5798. +#define DMA_RX_ERR_DESC BIT(14) /* descriptor error */
  5799. +#define DMA_RX_ERROR BIT(15) /* error summary */
  5800. +#define DMA_RX_LEN_MASK 0x3fff0000
  5801. +#define DMA_RX_LEN_SHIFT 16
  5802. +#define DMA_RX_FILT BIT(30)
  5803. +#define DMA_RX_OWN BIT(31) /* desc owned by DMA controller */
  5804. +
  5805. +#define DMA_RX1_BSIZE_MASK 0x000007ff
  5806. +#define DMA_RX1_BSIZE_SHIFT 0
  5807. +#define DMA_RX1_CHAINED BIT(24)
  5808. +#define DMA_RX1_RER BIT(25)
  5809. +
  5810. +#define DMA_TX_ERR_UNDER BIT(1) /* underflow error */
  5811. +#define DMA_TX_ERR_DEFER BIT(2) /* excessive deferral */
  5812. +#define DMA_TX_COL_MASK 0x78
  5813. +#define DMA_TX_COL_SHIFT 3
  5814. +#define DMA_TX_ERR_HB BIT(7) /* hearbeat failure */
  5815. +#define DMA_TX_ERR_COL BIT(8) /* excessive collisions */
  5816. +#define DMA_TX_ERR_LATE BIT(9) /* late collision */
  5817. +#define DMA_TX_ERR_LINK BIT(10) /* no carrier */
  5818. +#define DMA_TX_ERR_LOSS BIT(11) /* loss of carrier */
  5819. +#define DMA_TX_ERR_JABBER BIT(14) /* transmit jabber timeout */
  5820. +#define DMA_TX_ERROR BIT(15) /* frame aborted */
  5821. +#define DMA_TX_OWN BIT(31) /* descr owned by DMA controller */
  5822. +
  5823. +#define DMA_TX1_BSIZE_MASK 0x000007ff
  5824. +#define DMA_TX1_BSIZE_SHIFT 0
  5825. +#define DMA_TX1_CHAINED BIT(24) /* chained descriptors */
  5826. +#define DMA_TX1_TER BIT(25) /* transmit end of ring */
  5827. +#define DMA_TX1_FS BIT(29) /* first segment */
  5828. +#define DMA_TX1_LS BIT(30) /* last segment */
  5829. +#define DMA_TX1_IC BIT(31) /* interrupt on completion */
  5830. +
  5831. +#define RCVPKT_LENGTH(X) (X >> 16) /* Received pkt Length */
  5832. +
  5833. +#define MAC_CONTROL_RE BIT(2) /* receive enable */
  5834. +#define MAC_CONTROL_TE BIT(3) /* transmit enable */
  5835. +#define MAC_CONTROL_DC BIT(5) /* Deferral check */
  5836. +#define MAC_CONTROL_ASTP BIT(8) /* Auto pad strip */
  5837. +#define MAC_CONTROL_DRTY BIT(10) /* Disable retry */
  5838. +#define MAC_CONTROL_DBF BIT(11) /* Disable bcast frames */
  5839. +#define MAC_CONTROL_LCC BIT(12) /* late collision ctrl */
  5840. +#define MAC_CONTROL_HP BIT(13) /* Hash Perfect filtering */
  5841. +#define MAC_CONTROL_HASH BIT(14) /* Unicast hash filtering */
  5842. +#define MAC_CONTROL_HO BIT(15) /* Hash only filtering */
  5843. +#define MAC_CONTROL_PB BIT(16) /* Pass Bad frames */
  5844. +#define MAC_CONTROL_IF BIT(17) /* Inverse filtering */
  5845. +#define MAC_CONTROL_PR BIT(18) /* promiscuous mode (valid frames only) */
  5846. +#define MAC_CONTROL_PM BIT(19) /* pass multicast */
  5847. +#define MAC_CONTROL_F BIT(20) /* full-duplex */
  5848. +#define MAC_CONTROL_DRO BIT(23) /* Disable Receive Own */
  5849. +#define MAC_CONTROL_HBD BIT(28) /* heart-beat disabled (MUST BE SET) */
  5850. +#define MAC_CONTROL_BLE BIT(30) /* big endian mode */
  5851. +#define MAC_CONTROL_RA BIT(31) /* receive all (valid and invalid frames) */
  5852. +
  5853. +#define MII_ADDR_BUSY BIT(0)
  5854. +#define MII_ADDR_WRITE BIT(1)
  5855. +#define MII_ADDR_REG_SHIFT 6
  5856. +#define MII_ADDR_PHY_SHIFT 11
  5857. +#define MII_DATA_SHIFT 0
  5858. +
  5859. +#define FLOW_CONTROL_FCE BIT(1)
  5860. +
  5861. +#define DMA_BUS_MODE_SWR BIT(0) /* software reset */
  5862. +#define DMA_BUS_MODE_BLE BIT(7) /* big endian mode */
  5863. +#define DMA_BUS_MODE_PBL_SHIFT 8 /* programmable burst length 32 */
  5864. +#define DMA_BUS_MODE_DBO BIT(20) /* big-endian descriptors */
  5865. +
  5866. +#define DMA_STATUS_TI BIT(0) /* transmit interrupt */
  5867. +#define DMA_STATUS_TPS BIT(1) /* transmit process stopped */
  5868. +#define DMA_STATUS_TU BIT(2) /* transmit buffer unavailable */
  5869. +#define DMA_STATUS_TJT BIT(3) /* transmit buffer timeout */
  5870. +#define DMA_STATUS_UNF BIT(5) /* transmit underflow */
  5871. +#define DMA_STATUS_RI BIT(6) /* receive interrupt */
  5872. +#define DMA_STATUS_RU BIT(7) /* receive buffer unavailable */
  5873. +#define DMA_STATUS_RPS BIT(8) /* receive process stopped */
  5874. +#define DMA_STATUS_ETI BIT(10) /* early transmit interrupt */
  5875. +#define DMA_STATUS_FBE BIT(13) /* fatal bus interrupt */
  5876. +#define DMA_STATUS_ERI BIT(14) /* early receive interrupt */
  5877. +#define DMA_STATUS_AIS BIT(15) /* abnormal interrupt summary */
  5878. +#define DMA_STATUS_NIS BIT(16) /* normal interrupt summary */
  5879. +#define DMA_STATUS_RS_SHIFT 17 /* receive process state */
  5880. +#define DMA_STATUS_TS_SHIFT 20 /* transmit process state */
  5881. +#define DMA_STATUS_EB_SHIFT 23 /* error bits */
  5882. +
  5883. +#define DMA_CONTROL_SR BIT(1) /* start receive */
  5884. +#define DMA_CONTROL_ST BIT(13) /* start transmit */
  5885. +#define DMA_CONTROL_SF BIT(21) /* store and forward */
  5886. +
  5887. +
  5888. +typedef struct {
  5889. + volatile unsigned int status; // OWN, Device control and status.
  5890. + volatile unsigned int devcs; // pkt Control bits + Length
  5891. + volatile unsigned int addr; // Current Address.
  5892. + volatile unsigned int descr; // Next descriptor in chain.
  5893. +} ar231x_descr_t;
  5894. +
  5895. +
  5896. +
  5897. +//
  5898. +// New Combo structure for Both Eth0 AND eth1
  5899. +//
  5900. +typedef struct {
  5901. + volatile unsigned int mac_control; /* 0x00 */
  5902. + volatile unsigned int mac_addr[2]; /* 0x04 - 0x08 */
  5903. + volatile unsigned int mcast_table[2]; /* 0x0c - 0x10 */
  5904. + volatile unsigned int mii_addr; /* 0x14 */
  5905. + volatile unsigned int mii_data; /* 0x18 */
  5906. + volatile unsigned int flow_control; /* 0x1c */
  5907. + volatile unsigned int vlan_tag; /* 0x20 */
  5908. + volatile unsigned int pad[7]; /* 0x24 - 0x3c */
  5909. + volatile unsigned int ucast_table[8]; /* 0x40-0x5c */
  5910. +
  5911. +} ETHERNET_STRUCT;
  5912. +
  5913. +/********************************************************************
  5914. + * Interrupt controller
  5915. + ********************************************************************/
  5916. +
  5917. +typedef struct {
  5918. + volatile unsigned int wdog_control; /* 0x08 */
  5919. + volatile unsigned int wdog_timer; /* 0x0c */
  5920. + volatile unsigned int misc_status; /* 0x10 */
  5921. + volatile unsigned int misc_mask; /* 0x14 */
  5922. + volatile unsigned int global_status; /* 0x18 */
  5923. + volatile unsigned int reserved; /* 0x1c */
  5924. + volatile unsigned int reset_control; /* 0x20 */
  5925. +} INTERRUPT;
  5926. +
  5927. +/********************************************************************
  5928. + * DMA controller
  5929. + ********************************************************************/
  5930. +typedef struct {
  5931. + volatile unsigned int bus_mode; /* 0x00 (CSR0) */
  5932. + volatile unsigned int xmt_poll; /* 0x04 (CSR1) */
  5933. + volatile unsigned int rcv_poll; /* 0x08 (CSR2) */
  5934. + volatile unsigned int rcv_base; /* 0x0c (CSR3) */
  5935. + volatile unsigned int xmt_base; /* 0x10 (CSR4) */
  5936. + volatile unsigned int status; /* 0x14 (CSR5) */
  5937. + volatile unsigned int control; /* 0x18 (CSR6) */
  5938. + volatile unsigned int intr_ena; /* 0x1c (CSR7) */
  5939. + volatile unsigned int rcv_missed; /* 0x20 (CSR8) */
  5940. + volatile unsigned int reserved[11]; /* 0x24-0x4c (CSR9-19) */
  5941. + volatile unsigned int cur_tx_buf_addr; /* 0x50 (CSR20) */
  5942. + volatile unsigned int cur_rx_buf_addr; /* 0x50 (CSR21) */
  5943. +} DMA;
  5944. +
  5945. +/*
  5946. + * Struct private for the Sibyte.
  5947. + *
  5948. + * Elements are grouped so variables used by the tx handling goes
  5949. + * together, and will go into the same cache lines etc. in order to
  5950. + * avoid cache line contention between the rx and tx handling on SMP.
  5951. + *
  5952. + * Frequently accessed variables are put at the beginning of the
  5953. + * struct to help the compiler generate better/shorter code.
  5954. + */
  5955. +struct ar231x_private {
  5956. + struct net_device *dev;
  5957. + int version;
  5958. + u32 mb[2];
  5959. +
  5960. + volatile ETHERNET_STRUCT *phy_regs;
  5961. + volatile ETHERNET_STRUCT *eth_regs;
  5962. + volatile DMA *dma_regs;
  5963. + volatile u32 *int_regs;
  5964. + struct ar231x_eth *cfg;
  5965. +
  5966. + spinlock_t lock; /* Serialise access to device */
  5967. +
  5968. + /*
  5969. + * RX and TX descriptors, must be adjacent
  5970. + */
  5971. + ar231x_descr_t *rx_ring;
  5972. + ar231x_descr_t *tx_ring;
  5973. +
  5974. +
  5975. + struct sk_buff **rx_skb;
  5976. + struct sk_buff **tx_skb;
  5977. +
  5978. + /*
  5979. + * RX elements
  5980. + */
  5981. + u32 rx_skbprd;
  5982. + u32 cur_rx;
  5983. +
  5984. + /*
  5985. + * TX elements
  5986. + */
  5987. + u32 tx_prd;
  5988. + u32 tx_csm;
  5989. +
  5990. + /*
  5991. + * Misc elements
  5992. + */
  5993. + char name[48];
  5994. + struct {
  5995. + u32 address;
  5996. + u32 length;
  5997. + char *mapping;
  5998. + } desc;
  5999. +
  6000. +
  6001. + struct timer_list link_timer;
  6002. + unsigned short phy; /* merlot phy = 1, samsung phy = 0x1f */
  6003. + unsigned short mac;
  6004. + unsigned short link; /* 0 - link down, 1 - link up */
  6005. + u16 phyData;
  6006. +
  6007. + struct tasklet_struct rx_tasklet;
  6008. + int unloading;
  6009. +
  6010. + struct phy_device *phy_dev;
  6011. + struct mii_bus *mii_bus;
  6012. + int oldduplex;
  6013. +};
  6014. +
  6015. +
  6016. +/*
  6017. + * Prototypes
  6018. + */
  6019. +static int ar231x_init(struct net_device *dev);
  6020. +#ifdef TX_TIMEOUT
  6021. +static void ar231x_tx_timeout(struct net_device *dev);
  6022. +#endif
  6023. +static int ar231x_restart(struct net_device *dev);
  6024. +static void ar231x_load_rx_ring(struct net_device *dev, int bufs);
  6025. +static irqreturn_t ar231x_interrupt(int irq, void *dev_id);
  6026. +static int ar231x_open(struct net_device *dev);
  6027. +static int ar231x_start_xmit(struct sk_buff *skb, struct net_device *dev);
  6028. +static int ar231x_close(struct net_device *dev);
  6029. +static int ar231x_ioctl(struct net_device *dev, struct ifreq *ifr,
  6030. + int cmd);
  6031. +static void ar231x_init_cleanup(struct net_device *dev);
  6032. +static int ar231x_setup_timer(struct net_device *dev);
  6033. +static void ar231x_link_timer_fn(unsigned long data);
  6034. +static void ar231x_check_link(struct net_device *dev);
  6035. +#endif /* _AR2313_H_ */
  6036. diff -Nur linux-2.6.39-rc7.orig/drivers/watchdog/Kconfig linux-2.6.39-rc7/drivers/watchdog/Kconfig
  6037. --- linux-2.6.39-rc7.orig/drivers/watchdog/Kconfig 2011-05-10 04:33:54.000000000 +0200
  6038. +++ linux-2.6.39-rc7/drivers/watchdog/Kconfig 2011-05-15 21:34:57.000000000 +0200
  6039. @@ -990,6 +990,12 @@
  6040. To compile this driver as a loadable module, choose M here.
  6041. The module will be called bcm63xx_wdt.
  6042. +config ATHEROS_WDT
  6043. + tristate "Atheros wisoc Watchdog Timer"
  6044. + depends on ATHEROS_AR231X
  6045. + help
  6046. + Hardware driver for the Atheros wisoc Watchdog Timer.
  6047. +
  6048. # PARISC Architecture
  6049. # POWERPC Architecture
  6050. diff -Nur linux-2.6.39-rc7.orig/drivers/watchdog/Makefile linux-2.6.39-rc7/drivers/watchdog/Makefile
  6051. --- linux-2.6.39-rc7.orig/drivers/watchdog/Makefile 2011-05-10 04:33:54.000000000 +0200
  6052. +++ linux-2.6.39-rc7/drivers/watchdog/Makefile 2011-05-15 21:34:57.000000000 +0200
  6053. @@ -120,6 +120,7 @@
  6054. obj-$(CONFIG_PNX833X_WDT) += pnx833x_wdt.o
  6055. obj-$(CONFIG_SIBYTE_WDOG) += sb_wdog.o
  6056. obj-$(CONFIG_AR7_WDT) += ar7_wdt.o
  6057. +obj-$(CONFIG_ATHEROS_WDT) += ar2315-wtd.o
  6058. obj-$(CONFIG_TXX9_WDT) += txx9wdt.o
  6059. obj-$(CONFIG_OCTEON_WDT) += octeon-wdt.o
  6060. octeon-wdt-y := octeon-wdt-main.o octeon-wdt-nmi.o
  6061. diff -Nur linux-2.6.39-rc7.orig/drivers/watchdog/ar2315-wtd.c linux-2.6.39-rc7/drivers/watchdog/ar2315-wtd.c
  6062. --- linux-2.6.39-rc7.orig/drivers/watchdog/ar2315-wtd.c 1970-01-01 01:00:00.000000000 +0100
  6063. +++ linux-2.6.39-rc7/drivers/watchdog/ar2315-wtd.c 2011-05-15 21:34:57.000000000 +0200
  6064. @@ -0,0 +1,200 @@
  6065. +/*
  6066. + * This program is free software; you can redistribute it and/or modify
  6067. + * it under the terms of the GNU General Public License as published by
  6068. + * the Free Software Foundation; either version 2 of the License, or
  6069. + * (at your option) any later version.
  6070. + *
  6071. + * This program is distributed in the hope that it will be useful,
  6072. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6073. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6074. + * GNU General Public License for more details.
  6075. + *
  6076. + * You should have received a copy of the GNU General Public License
  6077. + * along with this program; if not, write to the Free Software
  6078. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6079. + *
  6080. + * Copyright (C) 2008 John Crispin <blogic@openwrt.org>
  6081. + * Based on EP93xx and ifxmips wdt driver
  6082. + */
  6083. +
  6084. +#include <linux/interrupt.h>
  6085. +#include <linux/module.h>
  6086. +#include <linux/moduleparam.h>
  6087. +#include <linux/types.h>
  6088. +#include <linux/miscdevice.h>
  6089. +#include <linux/watchdog.h>
  6090. +#include <linux/fs.h>
  6091. +#include <linux/ioport.h>
  6092. +#include <linux/notifier.h>
  6093. +#include <linux/reboot.h>
  6094. +#include <linux/init.h>
  6095. +#include <linux/platform_device.h>
  6096. +
  6097. +#include <asm/io.h>
  6098. +#include <asm/uaccess.h>
  6099. +#include <asm/system.h>
  6100. +#include <asm/addrspace.h>
  6101. +#include <ar231x_platform.h>
  6102. +#include <ar2315_regs.h>
  6103. +#include <ar231x.h>
  6104. +
  6105. +#define CLOCK_RATE 40000000
  6106. +#define HEARTBEAT(x) (x < 1 || x > 90)?(20):(x)
  6107. +
  6108. +static int wdt_timeout = 20;
  6109. +static int started = 0;
  6110. +static int in_use = 0;
  6111. +
  6112. +static void
  6113. +ar2315_wdt_enable(void)
  6114. +{
  6115. + ar231x_write_reg(AR2315_WD, wdt_timeout * CLOCK_RATE);
  6116. + ar231x_write_reg(AR2315_ISR, 0x80);
  6117. +}
  6118. +
  6119. +static ssize_t
  6120. +ar2315_wdt_write(struct file *file, const char __user *data, size_t len, loff_t *ppos)
  6121. +{
  6122. + if(len)
  6123. + ar2315_wdt_enable();
  6124. + return len;
  6125. +}
  6126. +
  6127. +static int
  6128. +ar2315_wdt_open(struct inode *inode, struct file *file)
  6129. +{
  6130. + if(in_use)
  6131. + return -EBUSY;
  6132. + ar2315_wdt_enable();
  6133. + in_use = started = 1;
  6134. + return nonseekable_open(inode, file);
  6135. +}
  6136. +
  6137. +static int
  6138. +ar2315_wdt_release(struct inode *inode, struct file *file)
  6139. +{
  6140. + in_use = 0;
  6141. + return 0;
  6142. +}
  6143. +
  6144. +static irqreturn_t
  6145. +ar2315_wdt_interrupt(int irq, void *dev_id)
  6146. +{
  6147. + if(started)
  6148. + {
  6149. + printk(KERN_CRIT "watchdog expired, rebooting system\n");
  6150. + emergency_restart();
  6151. + } else {
  6152. + ar231x_write_reg(AR2315_WDC, 0);
  6153. + ar231x_write_reg(AR2315_WD, 0);
  6154. + ar231x_write_reg(AR2315_ISR, 0x80);
  6155. + }
  6156. + return IRQ_HANDLED;
  6157. +}
  6158. +
  6159. +static struct watchdog_info ident = {
  6160. + .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
  6161. + .identity = "ar2315 Watchdog",
  6162. +};
  6163. +
  6164. +static int
  6165. +ar2315_wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
  6166. +{
  6167. + int new_wdt_timeout;
  6168. + int ret = -ENOIOCTLCMD;
  6169. +
  6170. + switch(cmd)
  6171. + {
  6172. + case WDIOC_GETSUPPORT:
  6173. + ret = copy_to_user((struct watchdog_info __user *)arg, &ident, sizeof(ident)) ? -EFAULT : 0;
  6174. + break;
  6175. +
  6176. + case WDIOC_KEEPALIVE:
  6177. + ar2315_wdt_enable();
  6178. + ret = 0;
  6179. + break;
  6180. +
  6181. + case WDIOC_SETTIMEOUT:
  6182. + if((ret = get_user(new_wdt_timeout, (int __user *)arg)))
  6183. + break;
  6184. + wdt_timeout = HEARTBEAT(new_wdt_timeout);
  6185. + ar2315_wdt_enable();
  6186. + break;
  6187. +
  6188. + case WDIOC_GETTIMEOUT:
  6189. + ret = put_user(wdt_timeout, (int __user *)arg);
  6190. + break;
  6191. + }
  6192. + return ret;
  6193. +}
  6194. +
  6195. +static struct file_operations ar2315_wdt_fops = {
  6196. + .owner = THIS_MODULE,
  6197. + .llseek = no_llseek,
  6198. + .write = ar2315_wdt_write,
  6199. + .unlocked_ioctl = ar2315_wdt_ioctl,
  6200. + .open = ar2315_wdt_open,
  6201. + .release = ar2315_wdt_release,
  6202. +};
  6203. +
  6204. +static struct miscdevice ar2315_wdt_miscdev = {
  6205. + .minor = WATCHDOG_MINOR,
  6206. + .name = "watchdog",
  6207. + .fops = &ar2315_wdt_fops,
  6208. +};
  6209. +
  6210. +static int
  6211. +ar2315_wdt_probe(struct platform_device *dev)
  6212. +{
  6213. + int ret = 0;
  6214. +
  6215. + ar2315_wdt_enable();
  6216. + ret = request_irq(AR531X_MISC_IRQ_WATCHDOG, ar2315_wdt_interrupt, IRQF_DISABLED, "ar2315_wdt", NULL);
  6217. + if(ret)
  6218. + {
  6219. + printk(KERN_ERR "ar2315wdt: failed to register inetrrupt\n");
  6220. + goto out;
  6221. + }
  6222. +
  6223. + ret = misc_register(&ar2315_wdt_miscdev);
  6224. + if(ret)
  6225. + printk(KERN_ERR "ar2315wdt: failed to register miscdev\n");
  6226. +
  6227. +out:
  6228. + return ret;
  6229. +}
  6230. +
  6231. +static int
  6232. +ar2315_wdt_remove(struct platform_device *dev)
  6233. +{
  6234. + misc_deregister(&ar2315_wdt_miscdev);
  6235. + free_irq(AR531X_MISC_IRQ_WATCHDOG, NULL);
  6236. + return 0;
  6237. +}
  6238. +
  6239. +static struct platform_driver ar2315_wdt_driver = {
  6240. + .probe = ar2315_wdt_probe,
  6241. + .remove = ar2315_wdt_remove,
  6242. + .driver = {
  6243. + .name = "ar2315_wdt",
  6244. + .owner = THIS_MODULE,
  6245. + },
  6246. +};
  6247. +
  6248. +static int __init
  6249. +init_ar2315_wdt(void)
  6250. +{
  6251. + int ret = platform_driver_register(&ar2315_wdt_driver);
  6252. + if(ret)
  6253. + printk(KERN_INFO "ar2315_wdt: error registering platfom driver!");
  6254. + return ret;
  6255. +}
  6256. +
  6257. +static void __exit
  6258. +exit_ar2315_wdt(void)
  6259. +{
  6260. + platform_driver_unregister(&ar2315_wdt_driver);
  6261. +}
  6262. +
  6263. +module_init(init_ar2315_wdt);
  6264. +module_exit(exit_ar2315_wdt);