atheros.patch 184 KB

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